<?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('WebLinks', 'html',  "".CACHE_VLINKS."", '1');
	$mainlink = 0;
	menu($mainlink);
	br('1');
	Max_OpenTable();
	echo "<center><font class='title'><b>"._LINKSMAINCAT."</b></font></center><br />";
	echo "<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\" align=\"center\"><tr>";
	$sql = "select `cid`, `title`, `cdescription` from `".TABLE_LINKS_CATEGORIES."` where `parentid`='0' order by `title`";
	if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain _links_categories', '', __LINE__, __FILE__, $sql);}
	$count = 0;
	while ($row = $GLOBALS['db']->sql_fetchrow($result)) {
		$cid          = $GLOBALS['db']->XMFnum($row['cid']);
		$title        = stripslashes(check_html($row['title'], "nohtml"));
		$cdescription = stripslashes($row['cdescription']);
		echo "<td><font class=\"option\"><strong><big>&middot;</big></strong> <a href=\"modules.php?name=Web_Links&amp;l_op=viewlink&amp;cid=$cid\"><b>$title</b></a></font>";
		categorynewlinkgraphic($cid);
		if ($cdescription) {
			echo "<br /><font class=\"content\">$cdescription</font><br />";
		} else {
			br('1');
		}
		$sql2 = "SELECT `cid`, `title` from `".TABLE_LINKS_CATEGORIES."` where `parentid`='$cid' order by `title` limit 0,3";
		if ( !($result2 = $GLOBALS['db']->sql_query($sql2)) )
	{ query_die(GENERAL_ERROR, 'Could not obtain _links_categories', '', __LINE__, __FILE__, $sql2);}
		$space = 0;
		while ($row2 = $GLOBALS['db']->sql_fetchrow($result2)) {
			$cid = $GLOBALS['db']->XMFnum($row2['cid']);
			$stitle = stripslashes(check_html($row2['title'], "nohtml"));
			if ($space>0) {
				echo ",&nbsp;";
			}
			echo "<font class=\"content\"><a href=\"modules.php?name=Web_Links&amp;l_op=viewlink&amp;cid=$cid\">$stitle</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>";
	}
	$result3 = $GLOBALS['db']->sql_query("SELECT * from `".TABLE_LINKS_LINKS."`");
	$numrows = $GLOBALS['db']->sql_numrows($result3);
	$result4 = $GLOBALS['db']->sql_query("SELECT * from `".TABLE_LINKS_CATEGORIES."`");
	$catnum  = $GLOBALS['db']->sql_numrows($result4);
	$numrows = $GLOBALS['db']->XMFnum($numrows);
	$catnum  = $GLOBALS['db']->XMFnum($catnum);
	echo "<br /><br /><center><font class=\"content\">"._THEREARE." <b>$numrows</b> "._LINKS." "._AND." <b>$catnum</b> "._CATEGORIES." "._INDB."</font></center>";
	Max_CloseTable();
	incof('WebLinks', 'html',  "".CACHE_VLINKS."", '1');