<?php

// ***************************************************************************
// * Copyright © 2003 - Thomas Egtvedt - www.evaria.com - thomas@evaria.com  *
// *                                                                         *
// *      ECMS - Content Management System - Support: forum.evaria.com       *
// *                                                                         *
// * This program is commercial software; you can not redistribute/reproduce *
// * it and/or sell it without the prior written consent of www.evaria.com   *
// *                                                                         *
// * This program is distributed in the hope that it will be useful,         *
// * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                    *
// ***************************************************************************

$sql_admin = "SELECT nb_sites_in_topvotes, nb_days2benew FROM $T_infos "; 
$lk = connection_BD();
$res_admin = send_sql($sql_admin,"finding number of links to display in popular");
$result_admin = mysql_fetch_array($res_admin,MYSQL_ASSOC);

$nb_sites_top_votes = $result_admin["nb_sites_in_topvotes"];
$nb_days2benew = $result_admin["nb_days2benew"];

$sql = "SELECT s.id, id_cat, titre, description, url, date_validation, nb_votes, moyenne_votes, cat_name, TO_DAYS(CURRENT_DATE) - TO_DAYS(date_validation) AS dif_days FROM $T_sites AS s, $T_categories AS c WHERE s.id_cat = c.id AND s.activation = 1 AND c.activation = 1 ";
if (empty($type))
{
	$sql .= "AND nb_votes > 0 ORDER BY moyenne_votes DESC, nb_votes DESC, titre LIMIT 0,$nb_sites_top_votes ";
	$titre_page = "Top $nb_sites_top_votes links based on rating";
}
else // $type = nb 
{
	$sql .= "AND nb_votes > 0 ORDER BY nb_votes DESC, moyenne_votes DESC, titre LIMIT 0,$nb_sites_top_votes ";
	$titre_page = "Top $nb_sites_top_votes links based on votes";
}
$res = send_sql($sql,"finding the popular links");
mysql_close($lk);

?>

<TABLE align="center" width="<? echo $table_width; ?>" cellspacing="0" cellpadding="0" border="0">
  <TR>
	<TD class="link_m_head"><img src="./img/h_stats.gif" width="32" height="32" alt="Top Links" border="0" align="absmiddle">&nbsp;&nbsp;<? echo $titre_page; ?> &raquo;</TD>
  </TR>
</TABLE>
<br><br>

<?
if (mysql_num_rows($res))
{
	echo "<TABLE border=\"0\" width=\"" . $table_width . "\" cellpadding=\"0\" cellspacing=\"0\">\n  <TR>\n    <TD>\n";
	$position=1;
	while ($resultat = mysql_fetch_array($res))
	{
		affiche_site($resultat,"topv");
		$position++;
	}
	echo "    </TD>\n  </TR>\n</TABLE>\n";
}
else // If votes = 0
{
	?>
	<center><br><br><br><br>
	<span class="link_error">
	No votes recorded yet...
	</span>
	</center>
	<?
}
?>

