<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/

	incoh();
	include("modules/$module_name/l_config.php");
	menu(1);
	br('1');
	Max_OpenTable();
	echo "<table border=\"0\" width=\"100%\"><tr><td align=\"center\">";
	if ($ratenum != "" && $ratetype != "") {
		$toplinks = $ratenum;
		if ($ratetype == "percent") {
			$toplinkspercentrigger = 1;
		}
	}
	if ($toplinkspercentrigger == 1) {
		$toplinkspercent = $toplinks;
		$totalratedlinks = $db->sql_numrows($db->sql_query("SELECT * from ".TABLE_LINKS_LINKS." where linkratingsummary != '0'"));
		$toplinks = $toplinks / 100;
		$toplinks = $totalratedlinks * $toplinks;
		$toplinks = round($toplinks);
	}
	if ($toplinkspercentrigger == 1) {
		echo "<center><font class=\"option\"><b>"._BESTRATED." $toplinkspercent% ("._OF." $totalratedlinks "._TRATEDLINKS.")</b></font></center><br />";
	} else {
		echo "<center><font class=\"option\"><b>"._BESTRATED." ".htmlentities($toplinks)." </b></font></center><br />";
	}
	echo "</td></tr>"
	."<tr><td><center>"._NOTE." $linkvotemin "._TVOTESREQ."<br />"
	.""._SHOWTOP.":  [ <a href=\"modules.php?name=$module_name&amp;l_op=TopRated&amp;ratenum=10&amp;ratetype=num\">10</a> - "
	."<a href=\"modules.php?name=$module_name&amp;l_op=TopRated&amp;ratenum=25&amp;ratetype=num\">25</a> - "
	."<a href=\"modules.php?name=$module_name&amp;l_op=TopRated&amp;ratenum=50&amp;ratetype=num\">50</a> | "
	."<a href=\"modules.php?name=$module_name&amp;l_op=TopRated&amp;ratenum=1&amp;ratetype=percent\">1%</a> - "
	."<a href=\"modules.php?name=$module_name&amp;l_op=TopRated&amp;ratenum=5&amp;ratetype=percent\">5%</a> - "
	."<a href=\"modules.php?name=$module_name&amp;l_op=TopRated&amp;ratenum=10&amp;ratetype=percent\">10%</a> ]</center><br /><br /></td></tr>";
	$result = $db->sql_query("SELECT lid, cid, sid, title, description, date, hits, linkratingsummary, totalvotes, totalcomments from ".TABLE_LINKS_LINKS." where linkratingsummary != '0' and totalvotes >= $linkvotemin order by linkratingsummary DESC limit 0,$toplinks");
	echo "<tr><td>";
	while ($row = $db->sql_fetchrow($result)) {
		$lid = $db->XMFnum($row['lid']);
		$cid = $db->XMFnum($row['cid']);
		$sid = $db->XMFnum($row['sid']);
		$title = stripslashes(check_html($row['title'], "nohtml"));
		$description = stripslashes($row['description']);
		$time = $row['date'];
		$hits = $db->XMFnum($row['hits']);
		$linkratingsummary = $row['linkratingsummary'];
		$totalvotes = $db->XMFnum($row['totalvotes']);
		$totalcomments = $row['totalcomments'];
		$linkratingsummary = number_format($linkratingsummary, $mainvotedecimal);
		echo "<a href=\"modules.php?name=$module_name&amp;l_op=visit&amp;lid=$lid\" target=\"new\">$title</a>";
		newlinkgraphic($datetime, $time);
		popgraphic($hits);
		br('1');
		echo ""._DESCRIPTION.": $description<br />";
		setlocale (LC_TIME, $locale);
		ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
		$datetime = strftime(""._LINKSDATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
		$datetime = ucfirst($datetime);
		echo ""._ADDEDON.": $datetime "._HITS.": $hits";
		$transfertitle = str_replace (" ", "_", $title);
		/* voting & comments stats */
		if ($totalvotes == 1) {
			$votestring = _VOTE;
		} else {
			$votestring = _VOTES;
		}
		if ($linkratingsummary!="0" || $linkratingsummary!="0.0") {
			echo " "._RATING.": <b> $linkratingsummary </b> ($totalvotes $votestring)";
		}
		echo "<br /><a href=\"modules.php?name=$module_name&amp;l_op=ratelink&amp;lid=$lid&amp;ttitle=$transfertitle\">"._RATESITE."</a>";
		if (defined('USER_ALLOW')) {
			echo " | <a href=\"modules.php?name=$module_name&amp;l_op=brokenlink&amp;lid=$lid\">"._REPORTBROKEN."</a>";
		}
		if ($totalvotes != 0) {
			echo " | <a href=\"modules.php?name=$module_name&amp;l_op=viewlinkdetails&amp;lid=$lid&amp;ttitle=$transfertitle\">"._DETAILS."</a>";
		}
		if ($totalcomments != 0) {
			echo " | <a href=\"modules.php?name=$module_name&amp;l_op=viewlinkcomments&amp;lid=$lid&amp;ttitle=$transfertitle\">"._SCOMMENTS." ($totalcomments)</a>";
		}
		detecteditorial($lid, $transfertitle);
		br('1');
		$row2 = $db->sql_fetchrow($db->sql_query("SELECT title from ".TABLE_LINKS_CATEGORIES." where cid='$cid'"));
		$ctitle = $row2['title'];
		$ctitle = getparent($cid,$ctitle);
		echo ""._CATEGORY.": $ctitle";
		br('2');
		br('2');
	}
	echo "</font></td></tr></table>";
	Max_CloseTable();
	incof();