<?php
/**
 * $Source: /home/cvs/nukescripts/modules/Web_Links/includes/MostPopular.php,v $
 * $Revision: 1.0.1-1 $
 * $Author: cyril $
 * $Date: 2006/06/24 22:44:02 $
 * Fix frenatus ligne 76 - Bug 112
 */
/************************************************************************/
/* 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                                 */
/************************************************************************/

	$admin = base64_decode($admin);
	$admin = addslashes($admin);
	$admin = explode(":", $admin);
	$aid = "$admin[0]";
	$row = $db->sql_fetchrow($db->sql_query("SELECT `radminsuper` from `".TABLE_AUTHORS."` where `aid`='$aid'"));
	$radminsuper = $db->XMFnum($row['radminsuper']);
	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 != "") {
		$mostpoplinks = $ratenum;
		if ($ratetype == "percent") $mostpoplinkspercentrigger = 1;
	}
	if ($mostpoplinkspercentrigger == 1) {
		$toplinkspercent = $mostpoplinks;
		$result2 = $db->sql_query("SELECT * from ".TABLE_LINKS_LINKS."");
		$totalmostpoplinks = $db->sql_numrows($result2);
		$mostpoplinks = $mostpoplinks / 100;
		$mostpoplinks = $totalmostpoplinks * $mostpoplinks;
		$mostpoplinks = round($mostpoplinks);
	}
	if ($mostpoplinkspercentrigger == 1) {
		echo "<center><font class=\"option\"><b>"._MOSTPOPULAR." $toplinkspercent% ("._OFALL." $totalmostpoplinks "._LINKS.")</b></font></center>";
	} else {
		echo "<center><font class=\"option\"><b>"._MOSTPOPULAR." ".htmlentities($mostpoplinks)."</b></font></center>";
	}
	echo "<tr><td><center>"._SHOWTOP.": [ <a href=\"modules.php?name=$module_name&amp;l_op=MostPopular&amp;ratenum=10&amp;ratetype=num\">10</a> - "
	."<a href=\"modules.php?name=$module_name&amp;l_op=MostPopular&amp;ratenum=25&amp;ratetype=num\">25</a> - "
	."<a href=\"modules.php?name=$module_name&amp;l_op=MostPopular&amp;ratenum=50&amp;ratetype=num\">50</a> | "
	."<a href=\"modules.php?name=$module_name&amp;l_op=MostPopular&amp;ratenum=1&amp;ratetype=percent\">1%</a> - "
	."<a href=\"modules.php?name=$module_name&amp;l_op=MostPopular&amp;ratenum=5&amp;ratetype=percent\">5%</a> - "
	."<a href=\"modules.php?name=$module_name&amp;l_op=MostPopular&amp;ratenum=10&amp;ratetype=percent\">10%</a> ]</center><br /><br /></td></tr>";
	if(!is_numeric($mostpoplinks)) {
	$mostpoplinks=10;
	}
	$result3 = $db->sql_query("SELECT `lid`, `cid`, `sid`, `title`, `description`, `date`, `hits`, `linkratingsummary`, `totalvotes`, `totalcomments` from `".TABLE_LINKS_LINKS."` order by `hits` DESC limit 0,$mostpoplinks");
	echo "<tr><td>";
	while($row3 = $db->sql_fetchrow($result3)) {
		$lid               = $db->XMFnum($row3['lid']);
		$cid               = $db->XMFnum($row3['cid']);
		$sid               = $db->XMFnum($row3['sid']);
		$title             = stripslashes(check_html($row3['title'], "nohtml"));
		$description       = stripslashes($row3['description']);
		$time              = stripslashes($row3['date']);
		$hits              = $db->XMFnum($row3['hits']);
		$linkratingsummary = stripslashes($row3['linkratingsummary']);
		$totalvotes        = $db->XMFnum($row3['totalvotes']);
		$totalcomments     = stripslashes($row3['totalcomments']);
		$linkratingsummary = number_format($linkratingsummary, $mainvotedecimal);
		echo "<font class=\"content\"><a href=\"modules.php?name=$module_name&amp;l_op=visit&amp;lid=$lid\" target='new'><b>$title</b></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.": <b>$hits</b>";
		$transfertitle = str_replace (" ", "_", $title);
		/* voting & comments stats */
		if ($totalvotes == 1) {
			$votestring = _VOTE;
		} else {
			$votestring = _VOTES;
		}
		if ($linkratingsummary!="0" || $linkratingsummary!="0.0") {
			echo " "._RATING.": $linkratingsummary ($totalvotes $votestring)";
		}
		br('1');
		if ($radminsuper == 1) {
			echo "<a href=\"".$admin_file.".php?op=LinksModLink&amp;lid=$lid\">"._EDIT."</a> | ";
		}
		echo "<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');
		$row4 = $db->sql_fetchrow($db->sql_query("SELECT `title` from `".TABLE_LINKS_CATEGORIES."` where `cid`='$cid'"));
		$ctitle = stripslashes(check_html($row4['title'], "nohtml"));
		$ctitle=getparent($cid,$ctitle);
		echo ""._CATEGORY.": $ctitle";
		br('4');
		echo "</font>";
	}
	echo "</font></td></tr></table>";
	Max_CloseTable();
	incof();