<?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                                 */
/************************************************************************/
/********************************************************/
/* NSN GR Downloads                                     */
/* By: NukeScripts Network (webmaster@nukescripts.net)  */
/* http://www.nukescripts.net                           */
/* Copyright  2000-2005 by NukeScripts Network         */
/********************************************************/
defined('MAXIMUS') or Header("Location: index.php");

if (!isset($cid)) { $cid = 0; }
$cid = $GLOBALS['db']->XMFnum($cid);
if (!isset($min)) $min=0;
if (!isset($max)) $max=$min+$dl_config['perpage'];

if (defined('ADMIN_ALLOW')) {
	$news_retention = CACHE_ADOWNLOADS;
	$name_homenews  = "DLHomeAdmin$min$cid";
	$news_extension = "php";
} elseif ( defined('USER_ALLOW') ) {
	$news_retention = CACHE_UDOWNLOADS;
	$name_homenews  = "DLHome$min$cid";
	$news_extension = "html";
} else {
	$news_retention = CACHE_VDOWNLOADS;
	$name_homenews  = "DLHome$min$cid";
	$news_extension = "html";
}
incoh( "".$name_homenews."", "".$news_extension."", "".$news_retention."", '1' );


if(isset($orderby)) { $orderby = convertorderbyin($orderby); } else { $orderby = "title ASC"; }
if ($cid == 0) {
  menu('0');
  $title = ""._MAIN."";
} else {
  menu('1');
  $cidinfo = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `cid`='$cid' AND `active`>'0'"));
  $title = getparentlink($cidinfo['parentid'], $cidinfo['title']);
  $title = "<a href='modules.php?name=$module_name'>"._MAIN."</a> -&gt; $title";
}
br('1');
Max_OpenTable();
echo "<table align='center'><tr><td><font class='option'><b>"._CATEGORY.": $title</b></font></td></tr></table>";
$result2 = $GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `parentid`='$cid' ORDER BY `title`");
$numrows2 = $GLOBALS['db']->sql_numrows($result2);
if ($numrows2 > 0) {
  echo "<table align='center' border='0' cellpadding='10' cellspacing='1' width='100%'>\n";
  $count = 0;
  while($cidinfo2 = $GLOBALS['db']->sql_fetchrow($result2)) {
    if ($count == 0) { echo "<tr>\n"; }
    if ($dl_config['show_links_num'] == 1) {
      $cnumrows = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE `cid`='".$cidinfo2['cid']."' AND `active`>'0'"));
      $categoryinfo = getcategoryinfo($cidinfo2['cid']);
      $cnumm = " (".$cnumrows."/".$categoryinfo['downloads'].")";
    } else {
      $cnumm = "";
    }
    echo "<td valign='top' width='33%'><font class='option'>";
    $myimage = myimage("icon-.png");
    echo "<img align='middle' src='$myimage' border='0' height='16' width='16' alt='' title='' />";
    echo "<a href='modules.php?name=$module_name&amp;cid=".$cidinfo2['cid']."'><b>".$cidinfo2['title']."</b></a>$cnumm</font>";
    newcategorygraphic($cidinfo2['cid']);
    if ($cidinfo2['cdescription']) {
      echo "<font class='content'>".$cidinfo2['cdescription']."</font><br />";
    } else {
      br('1');
    }
    $space = 0;
    $result3 = $GLOBALS['db']->sql_query("SELECT `cid`, `title` FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `parentid`='".$cidinfo2['cid']."' AND `active`>'0' ORDER BY `title`");
    while($cidinfo3 = $GLOBALS['db']->sql_fetchrow($result3)) {
      if ($dl_config['show_links_num'] == 1) {
        $snumrows = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE `cid`='".$cidinfo3['cid']."' AND `active`>'0'"));
        $categoryinfosub = getcategoryinfo($cidinfo3['cid']);
        $cnum = " (".$snumrows."/".$categoryinfosub['downloads'].")";
      } else {
        $cnum = "";
      }
      $myimage = myimage("icon+.png");
      echo "&nbsp;&nbsp;<img align='middle' src='$myimage' border='0' height='16' width='16' alt='' title='' />";
      echo "<font class='content'><a href='modules.php?name=$module_name&amp;cid=".$cidinfo3['cid']."'>".$cidinfo3['title']."</a>$cnum</font>";
      newcategorygraphic($cidinfo3['cid']);
      echo "<br />\n";
      $space++;
    }
    echo "</td>\n";
    if ($count < 2) { $dum = 1; }
    $count++;
    if ($count == 3) { echo "</tr>\n"; $count = 0; $dum = 0; }
  }
  if ($dum == 1 && $count == 2) {
    echo "<td>&nbsp;</td>\n</tr>\n</table>\n";
  } elseif ($dum == 1 && $count == 1) {
    echo "<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n</table>\n";
  } elseif ($dum == 0) {
    echo "</tr>\n</table>\n";
  }
}
$listrows = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE `active`>'0' AND `cid`='$cid'"));
if ($listrows > 0) {
  $op = $query = "";
  $orderbyTrans = convertorderbytrans($orderby);
  echo "<table border='0' cellpadding='0' cellspacing='4' width='100%'>";
  echo "<tr><td colspan='2'><hr noshade size='1'></td></tr>";
  echo "<tr><td align='center' colspan='2'><font class='content'>"._SORTDOWNLOADSBY.": ";
  echo ""._TITLE." (<a href='modules.php?name=$module_name&amp;cid=$cid&amp;orderby=titleA'>A</a>\<a href='modules.php?name=$module_name&amp;cid=$cid&amp;orderby=titleD'>D</a>) ";
  echo ""._DATE." (<a href='modules.php?name=$module_name&amp;cid=$cid&amp;orderby=dateA'>A</a>\<a href='modules.php?name=$module_name&amp;cid=$cid&amp;orderby=dateD'>D</a>) ";
  echo ""._POPULARITY." (<a href='modules.php?name=$module_name&amp;cid=$cid&amp;orderby=hitsA'>A</a>\<a href='modules.php?name=$module_name&amp;cid=$cid&amp;orderby=hitsD'>D</a>)";
  echo "<br /><b>"._RESSORTED.": $orderbyTrans</b></font></td></tr>\n";
  echo "</table>";
  $totalselected = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE `active`='1' AND `cid`='$cid' "));
  pagenums($cid, $query, $orderby, $op, $totalselected, $dl_config['perpage'], $max);
  echo "<table border='0' cellpadding='0' cellspacing='4' width='100%'>";
  // START LISTING
  $x = 0;
  $a = 0;
  $result=$GLOBALS['db']->sql_query("SELECT `lid` FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE `active`>'0' AND `cid`='$cid' ORDER BY $orderby LIMIT $min,".$dl_config['perpage']);
  while($raw =$GLOBALS['db']->sql_fetchrow($result)) {
  $lid = $raw['lid'];
    if ($a == 0) { echo "<tr>"; }
    echo "<td valign='top' width='50%'><font class='content'>";
    showlisting($lid);
    echo "</font></td>";
    $a++;
    if ($a == 2) { echo "</tr>"; $a = 0; }
    $x++;
  }
  if ($a == 1) { echo "<td width=\"50%\">&nbsp;</td></tr>"; } else { echo "</tr>"; }
  echo "</table>";
  // END LISTING
  $orderby = convertorderbyout($orderby);
  pagenums($cid, $query, $orderby, $op, $totalselected, $dl_config['perpage'], $max);
}
Max_CloseTable();
incof( "".$name_homenews."", "".$news_extension."", "".$news_retention."", '1' );