<?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                                 */
/************************************************************************/

	$show = $db->XMFnum($show);
	if (empty($show))
	{
		$show = '';
	}
	if (isset($orderby)) {
		$orderby = htmlspecialchars($orderby);
	}
	$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();
	if (!isset($min)) $min=0;
	if (!isset($max)) $max=$min+$perpage;
	if(isset($orderby)) {
		$orderby = convertorderbyin($orderby);
	} else {
		$orderby = "title ASC";
	}
	if ($show!="") {
		$perpage = $show;
	} else {
		$show=$perpage;
	}
	menu(1);
	br('1');
	Max_OpenTable();
	$cid = $db->XMFnum($cid);
	$row_two = $db->sql_fetchrow($db->sql_query("SELECT title,parentid FROM ".TABLE_LINKS_CATEGORIES." WHERE cid='$cid'"));
	$title = stripslashes(check_html($row_two['title'], "nohtml"));
	$parentid = $db->XMFnum($row_two['parentid']);
	$title=getparentlink($parentid,$title);
	$title="<a href='modules.php?name=$module_name'>"._MAIN."</a>/$title";
	echo "<center><font class=\"option\"><b>"._CATEGORY.": $title</b></font></center><br />";
	echo "<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\" align=\"center\"><tr>";
	$cid = $db->XMFnum($cid);
	$result2 = $db->sql_query("SELECT cid, title, cdescription from ".TABLE_LINKS_CATEGORIES." where parentid='$cid' order by title");
	$count = 0;
	while($row2 = $db->sql_fetchrow($result2)) {
		$cid2 = $db->XMFnum($row2['cid']);
		$title2 = stripslashes(check_html($row2['title'], "nohtml"));
		$cdescription2 = stripslashes($row2['cdescription']);
		echo "<td><font class=\"option\"><strong><big></big></strong> <a href=\"modules.php?name=Web_Links&amp;l_op=viewlink&amp;cid=$cid2\"><b>$title2</b></a></font>";
		categorynewlinkgraphic($cid2);
		if ($description) {
			echo "<font class=\"content\">$cdescription2</font><br />";
		} else {
			br('1');
		}
		$result3 = $db->sql_query("SELECT cid, title from ".TABLE_LINKS_CATEGORIES." where parentid='$cid2' order by title limit 0,3");
		$space = 0;
		while($row3 = $db->sql_fetchrow($result3)) {
			$cid3 = $db->XMFnum($row3['cid']);
			$title3 = stripslashes(check_html($row3['title'], "nohtml"));
			if ($space>0) {
				echo ",&nbsp;";
			}
			echo "<font class=\"content\"><a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid3\">$title3</a></font>";
			$space++;
		}
		if ($count<1) {
			echo "</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
			$dum = 1;
		}
		$count++;
		if ($count==2) {
			echo "</td></tr><tr>";
			$count = 0;
			$dum = 0;
		}
	}
	if ($dum == 1) {
		echo "</tr></table>";
	} elseif ($dum == 0) {
		echo "<td></td></tr></table>";
	}

	echo "<hr noshade size=\"1\">";
	$orderbyTrans = convertorderbytrans($orderby);
	echo "<center><font class=\"content\">"._SORTLINKSBY.": "
	.""._TITLE." (<a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid&amp;orderby=titleA\">A</a>\<a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid&amp;orderby=titleD\">D</a>) "
	.""._DATE." (<a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid&amp;orderby=dateA\">A</a>\<a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid&amp;orderby=dateD\">D</a>) "
	.""._RATING." (<a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid&amp;orderby=ratingA\">A</a>\<a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid&amp;orderby=ratingD\">D</a>) "
	.""._POPULARITY." (<a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid&amp;orderby=hitsA\">A</a>\<a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid&amp;orderby=hitsD\">D</a>)"
	."<br /><b>"._SITESSORTED.": $orderbyTrans</b></font></center><br /><br />";
	if(!is_numeric($min)){
	$min=0;
	}
	$result4 = $db->sql_query("SELECT lid, title, description, date, hits, linkratingsummary, totalvotes, totalcomments from ".TABLE_LINKS_LINKS." where cid='$cid' order by $orderby limit $min,$perpage");
	$fullcountresult = $db->sql_query("SELECT lid, title, description, date, hits, linkratingsummary, totalvotes, totalcomments from ".TABLE_LINKS_LINKS." where cid='$cid'");
	$totalselectedlinks = $db->sql_numrows($fullcountresult);
	echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"10\" border=\"0\"><tr><td><font class=\"content\">";
	$x=0;
	while($row4 = $db->sql_fetchrow($result4)) {
		$lid = $db->XMFnum($row4['lid']);
		$title = stripslashes(check_html($row4['title'], "nohtml"));
		$description = stripslashes($row4['description']);
		$time = $row4['date'];
		$hits = $db->XMFnum($row4['hits']);
		$linkratingsummary = $row4['linkratingsummary'];
		$totalvotes = $db->XMFnum($row4['totalvotes']);
		$totalcomments = $db->XMFnum($row4['totalcomments']);
		$linkratingsummary = number_format($linkratingsummary, $mainvotedecimal);
		echo "<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);
		/* INSERT code for *editor review* here */
		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.": $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('2');
		$x++;
	}
	echo "</font>";
	$orderby = convertorderbyout($orderby);
	/* Calculates how many pages exist. Which page one should be on, etc... */
	$linkpagesint = ($totalselectedlinks / $perpage);
	$linkpageremainder = ($totalselectedlinks % $perpage);
	if ($linkpageremainder != 0) {
		$linkpages = ceil($linkpagesint);
		if ($totalselectedlinks < $perpage) {
			$linkpageremainder = 0;
		}
	} else {
		$linkpages = $linkpagesint;
	}
	/* Page Numbering */
	if ($linkpages!=1 && $linkpages!=0) {
		br('2');
		echo ""._SELECTPAGE.": ";
		$prev=$min-$perpage;
		if ($prev>=0) {
			echo "&nbsp;&nbsp;<b>[ <a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid&amp;min=$prev&amp;orderby=$orderby&amp;show=$show\">";
			echo " &lt;&lt; "._PREVIOUS."</a> ]</b> ";
		}
		$counter = 1;
		$currentpage = ($max / $perpage);
		while ($counter<=$linkpages ) {
			$cpage = $counter;
			$mintemp = ($perpage * $counter) - $perpage;
			if ($counter == $currentpage) {
				echo "<b>$counter</b>&nbsp;";
			} else {
				echo "<a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid&amp;min=$mintemp&amp;orderby=$orderby&amp;show=$show\">$counter</a> ";
			}
			$counter++;
		}
		$next=$min+$perpage;
		if ($x>=$perpage) {
			echo "&nbsp;&nbsp;<b>[ <a href=\"modules.php?name=$module_name&amp;l_op=viewlink&amp;cid=$cid&amp;min=$max&amp;orderby=$orderby&amp;show=$show\">";
			echo " "._NEXT." &gt;&gt;</a> ]</b> ";
		}
	}
	echo "</td></tr></table>";
	Max_CloseTable();
	incof();