<?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");

function of_group($gid) {
    global $cookie;
    /*if (is_admin($admin)) {
        return 1;
    } else*/if (defined('USER_ALLOW')) {
        cookiedecode($user);
        $guid     = $cookie[0];
        $currdate = time();
        $ingroup  = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGR_USERS."` WHERE `gid`='$gid' AND `uid`='$guid' AND (`edate`>'$currdate' OR `edate`='0')"));
        if ($ingroup > 0) { return 1; }
    }
    return 0;
}

global $admin_file;
if(empty($admin_file)) { $admin_file= "admin"; }

function myimage($imgfile) {
    global $module_name;
    $ThemeSel = get_theme();
    if (file_exists("themes/$ThemeSel/images/downloads/$imgfile")) {
        $myimage = "themes/$ThemeSel/images/downloads/$imgfile";
    } else {
        $myimage = "modules/$module_name/images/$imgfile";
    }
    return($myimage);
}

// Copyright (c) 2003 --- NukeScripts Network ---
// Can not be reproduced in whole or in part without
// written consent from NukeScripts Network CEO
function gdget_configs(){
    $configresult = $GLOBALS['db']->sql_query("SELECT `config_name`, `config_value` FROM `".TABLE_NSNGD_CONFIG."`");
    while (list($config_name, $config_value) = $GLOBALS['db']->sql_fetchrow($configresult)) {
        $config[$config_name] = $config_value;
    }
    return $config;
}

// Copyright (c) 2003 --- NukeScripts Network ---
// Can not be reproduced in whole or in part without
// written consent from NukeScripts Network CEO
function gdsave_config($config_name, $config_value){
    $GLOBALS['db']->sql_query("UPDATE `".TABLE_NSNGD_CONFIG."` SET `config_value`='$config_value' WHERE `config_name`='$config_name'");
}

// Copyright (c) 2003 --- NukeScripts Network ---
// Can not be reproduced in whole or in part without
// written consent from NukeScripts Network CEO
function CrawlLevelR($parentid) {
    global $crawler;
    $bresult = $GLOBALS['db']->sql_query("SELECT `parentid` FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `cid`='$parentid' ORDER BY `title`");
    while(list($parentid2)=$GLOBALS['db']->sql_fetchrow($bresult)){
        array_push($crawler,$parentid2);
        CrawlLevelR($parentid2);
    }
    return $crawler;
}

// Copyright (c) 2003 --- NukeScripts Network ---
// Can not be reproduced in whole or in part without
// written consent from NukeScripts Network CEO
function CrawlLevel($cid) {
    global $crawled;
    $bresult = $GLOBALS['db']->sql_query("SELECT `cid` FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `parentid`='$cid' ORDER BY `title`");
    while(list($cid2)=$GLOBALS['db']->sql_fetchrow($bresult)){
        array_push($crawled,$cid2);
        CrawlLevel($cid2);
    }
    return $crawled;
}

function CoolSize($size) {
    $mb = 1024*1024;
    $gb = $mb*1024;
    if ( $size > $gb ) {
        $mysize = sprintf ("%01.2f",$size/$gb)." "._GB;
    } elseif ( $size > $mb ) {
        $mysize = sprintf ("%01.2f",$size/$mb)." "._MB;
    } elseif ( $size >= 1024 ) {
        $mysize = sprintf ("%01.2f",$size/1024)." "._KB;
    } else {
        $mysize = $size." "._BYTES;
    }
    return $mysize;
}

// Copyright (c) 2003 --- NukeScripts Network ---
// Can not be reproduced in whole or in part without
// written consent from NukeScripts Network CEO
function CoolDate($date) {
    global $dl_config;
    $mydate = date ($dl_config['dateformat'], strtotime ("$date"));
    return $mydate;
}

// Copyright (c) 2003 --- Michael K. Squires ---
// Can not be reproduced in whole or in part without
// written consent from Michael K. Squires
function getcategoryinfo($catID){
    $category = array($catID);
    $cats_detected = 0;
    $downloads_detected = 0;
    while(count($category) != 0){
        sort($category, SORT_STRING);
        reset($category);
        $curr_category = end($category);
        $dresult = $GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE `cid`='$curr_category'");
        $catdownloads = $GLOBALS['db']->sql_numrows($dresult);
        $downloads_detected += $catdownloads;
        $cresult = $GLOBALS['db']->sql_query("SELECT `cid` FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `parentid`='$curr_category'");
        while (list($cid) = $GLOBALS['db']->sql_fetchrow($cresult)){
            array_unshift($category, "$cid");
            $cats_detected++;
        }
        array_pop($category);
    }
    $categoryinfo['categories'] = $cats_detected;
    $categoryinfo['downloads'] = $downloads_detected;
    return $categoryinfo;
}

function getparent($parentid,$title) {
    $result  = $GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `cid`='$parentid'");
    $cidinfo = $GLOBALS['db']->sql_fetchrow($result);
    if ($cidinfo['title'] != "") $title = $cidinfo['title']." -> ".$title;
    if ($cidinfo['parentid'] != 0) { $title=getparent($cidinfo['parentid'], $title); }
    return $title;
}

function getparentlink($parentid,$title) {
    global $module_name;
    $parentid = $GLOBALS['db']->XMFnum($parentid);
    $cidinfo  = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `cid`=$parentid"));
    if ($cidinfo['title'] != "") $title = "<a href='modules.php?name=$module_name&amp;cid=".$cidinfo['cid']."'>".$cidinfo['title']."</a> -&gt; ".$title;
    if ($cidinfo['parentid'] != 0) { $title = getparentlink($cidinfo['parentid'],$title); }
    return $title;
}

// Copyright (c) 2003 --- NukeScripts Network ---
// Can not be reproduced in whole or in part without
// written consent from NukeScripts Network CEO
function restricted($perm) {
    global $module_name;
    if ($perm == 1) {
        $who_view = _DL_USERS;
    } elseif ($perm == 2) {
        $who_view = _DL_ADMIN;
    } elseif ($perm >2) {
        $newView = $perm - 2;
        list($who_view) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `gname` FROM `".TABLE_NSNGR_GROUPS."` WHERE `gid`='$newView' "));
        $who_view = $who_view." "._DL_ONLY;
    }
    $myimage = myimage("restricted.png");
    echo "<center><img src='$myimage' alt='' /></center><br />\n";
    echo "<center>"._DL_DENIED."!</center><br />\n";
    echo "<center>"._DL_CANBEDOWN." $who_view</center><br />\n";
    echo "<center>"._GOBACK."</center>\n";
}

// Copyright (c) 2003 --- NukeScripts Network ---
// Can not be reproduced in whole or in part without
// written consent from NukeScripts Network CEO
function restricted2($perm) {
    global $module_name;
    if ($perm == 1) {
        $who_view = _DL_USERS;
    } elseif ($perm == 2) {
        $who_view = _DL_ADMIN;
    } elseif ($perm >2) {
        $newView = $perm - 2;
        list($who_view) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `gname` FROM `".TABLE_NSNGR_GROUPS."` WHERE `gid`='$newView' "));
        $who_view = $who_view." "._DL_ONLY;
    }
    echo "<center>"._DL_DENIED."!<br />\n";
    echo ""._DL_CANBEVIEW."<br /><b>$who_view</b></center>\n";
}

function newdownloadgraphic($datetime, $time) {
    global $module_name;
    echo "&nbsp;";
    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);
    $startdate = time();
    $count = 0;
    while ($count <= 14) {
        $daysold = date("d-m-Y", $startdate);
        if ("$daysold" == "$datetime") {
            $myimage = myimage("new_01.png");
            if ($count<=1) { echo "<img align='middle' src='$myimage' alt='"._NEWTODAY."' title='"._NEWTODAY."' />"; }
            $myimage = myimage("new_03.png");
            if ($count<=3 && $count>1) { echo "<img align='middle' src='$myimage' alt='"._NEWLAST3DAYS."' title='"._NEWLAST3DAYS."' />"; }
            $myimage = myimage("new_07.png");
            if ($count<=7 && $count>3) { echo "<img align='middle' src='$myimage' alt='"._NEWTHISWEEK."' title='"._NEWTHISWEEK."' />"; }
            $myimage = myimage("new_14.png");
            if ($count<=14 && $count>7) { echo "<img align='middle' src='$myimage' alt='"._NEWLAST2WEEKS."' title='"._NEWLAST2WEEKS."' />"; }
        }
        $count++;
        $startdate = (time()-(86400 * $count));
    }
}

function newcategorygraphic($cat) {
    global $module_name;
    $cat = $GLOBALS['db']->XMFnum($cat);
    $newresult = $GLOBALS['db']->sql_query("SELECT `date` FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE `cid`='$cat' ORDER BY `date` DESC LIMIT 1");
    list($time)=$GLOBALS['db']->sql_fetchrow($newresult);
    echo "&nbsp;";
    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);
    $startdate = time();
    $count = 0;
    while ($count <= 14) {
        $daysold = date("d-m-Y", $startdate);
        if ("$daysold" == "$datetime") {
            $myimage = myimage("new_01.png");
            if ($count<=1) { echo "<img align='middle' src='$myimage' alt='"._DCATNEWTODAY."' title='"._DCATNEWTODAY."' />"; }
            $myimage = myimage("new_03.png");
            if ($count<=3 && $count>1) { echo "<img align='middle' src='$myimage' alt='"._DCATLAST3DAYS."' title='"._DCATLAST3DAYS."' />"; }
            $myimage = myimage("new_07.png");
            if ($count<=7 && $count>3) { echo "<img align='middle' src='$myimage' alt='"._DCATTHISWEEK."' title='"._DCATTHISWEEK."' />"; }
            $myimage = myimage("new_14.png");
            if ($count<=14 && $count>7) { echo "<img align='middle' src='$myimage' alt='"._DCATLAST2WEEKS."' title='"._DCATLAST2WEEKS."' />"; }
        }
        $count++;
        $startdate = (time()-(86400 * $count));
    }
}

function popgraphic($hits) {
    global $module_name, $dl_config;
    $hits    = $GLOBALS['db']->XMFnum($hits);
    $myimage = myimage("popular.png");
    if ($hits >= $dl_config['popular']) { echo "&nbsp;<img align='middle' src='$myimage' alt='"._POPULAR."' title='"._POPULAR."' />"; }
}

function DLadminmain() {
    global $admin_file, $module_name, $textcolor1, $bgcolor1, $bgcolor2;
    $brokendownloads = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_MODS."` WHERE `brokendownload`='1'"));
    $modrequests = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_MODS."` WHERE `brokendownload`='0'"));
    $newdownloads = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_NEW."`"));
    Max_OpenTable();
    echo "<table align=\"center\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n";
    echo "<tr>\n";
    echo "<td align=\"center\" width=\"25%\"><b>"._DOWNLOADS."</b></td>\n";
    echo "<td align=\"center\" width=\"25%\"><b>"._CATEGORIES."</b></td>\n";
    echo "<td align=\"center\" width=\"25%\"><b>"._EXTENSIONS."</b></td>\n";
    echo "<td align=\"center\" width=\"25%\"><b>"._OTHERS."</b></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=DownloadAdd\">"._ADDDOWNLOAD."</a></td>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=CategoryAdd\">"._ADDCATEGORY."</a></td>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=ExtensionAdd\">"._ADDEXTENSION."</a></td>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=DLConfig\">"._DOWNCONFIG."</a></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=Downloads\">"._DOWNLOADSLIST."</a></td>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=Categories\">"._CATEGORIESLIST."</a></td>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=Extensions\">"._EXTENSIONSLIST."</a></td>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php\">"._MAINADMIN."</a></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=DownloadCheck\">"._VALIDATEDOWNLOADS."</a></td>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=CategoryTransfer\">"._CATTRANS."</a></td>\n";
    echo "<td align=\"center\" width=\"25%\">&nbsp;</td>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=DownloadBroken\">"._BROKENREP."</a> ($brokendownloads)</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=FilesizeCheck\">"._VALIDATESIZES."</a></td>\n";
    echo "<td align=\"center\" width=\"25%\">&nbsp;</td>\n";
    echo "<td align=\"center\" width=\"25%\">&nbsp;</td>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=DownloadModifyRequests\">"._MODREQUEST."</a> ($modrequests)</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td align=\"center\" width=\"25%\">&nbsp;</td>\n";
    echo "<td align=\"center\" width=\"25%\">&nbsp;</td>\n";
    echo "<td align=\"center\" width=\"25%\">&nbsp;</td>\n";
    echo "<td align=\"center\" width=\"25%\"><a href=\"".$admin_file.".php?op=DownloadNew\">"._WAITINGDOWNLOADS."</a> ($newdownloads)</td>\n";
    echo "</tr>\n";
    echo "</table>\n";
    Max_CloseTable();
}

function convertorderbyin($orderby) {
    if ($orderby == "titleA") $orderby = "title ASC";
    if ($orderby == "dateA") $orderby = "date ASC";
    if ($orderby == "hitsA") $orderby = "hits ASC";
    if ($orderby == "titleD") $orderby = "title DESC";
    if ($orderby == "dateD") $orderby = "date DESC";
    if ($orderby == "hitsD") $orderby = "hits DESC";
    return $orderby;
}

function convertorderbytrans($orderby) {
    if ($orderby == "hits ASC") $orderbyTrans = _POPULARITY1;
    if ($orderby == "hits DESC") $orderbyTrans = _POPULARITY2;
    if ($orderby == "title ASC") $orderbyTrans = _TITLEAZ;
    if ($orderby == "title DESC") $orderbyTrans = _TITLEZA;
    if ($orderby == "date ASC") $orderbyTrans = _DDATE1;
    if ($orderby == "date DESC") $orderbyTrans = _DDATE2;
    return $orderbyTrans;
}

function convertorderbyout($orderby) {
    if ($orderby == "title ASC") $orderby = "titleA";
    if ($orderby == "date ASC") $orderby = "dateA";
    if ($orderby == "hits ASC") $orderby = "hitsA";
    if ($orderby == "title DESC") $orderby = "titleD";
    if ($orderby == "date DESC") $orderby = "dateD";
    if ($orderby == "hits DESC") $orderby = "hitsD";
    return $orderby;
}

function menu($maindownload) {
    global $module_name;
    Max_OpenTable();
    $myimage = myimage("logo.png");
    echo "<center><a href=\"modules.php?name=$module_name\"><img src=\"$myimage\" border=\"0\" alt=\"\" title=\"\" /></a></center><br />\n";
    SearchForm();
    echo "<br /><center><font class=\"content\">[ ";
    if ($maindownload>0) { echo "<a href=\"modules.php?name=$module_name\">"._DOWNLOADSMAIN."</a> | "; }
    echo "<a href=\"modules.php?name=Submit_Downloads\">"._DL_ADD."</a>";
    echo " | <a href=\"modules.php?name=$module_name&amp;op=NewDownloads\">"._NEW."</a>";
    echo " | <a href=\"modules.php?name=$module_name&amp;op=MostPopular\">"._POPULAR."</a>";
    echo " ]</font></center>\n";
    Max_CloseTable();
    br('1');
    Max_OpenTable();
    echo "<table align=\"center\" cellpadding=\"2\" cellspacing=\"2\" border=\"0\" width=\"100%\">\n";
    echo "<tr><td align=\"center\" colspan=\"3\"><b>"._DL_LEGEND."</b></td></tr>\n";
    echo "<tr>\n";
    $myimage = myimage("new_01.png");
    echo "<td align=\"center\" width=\"33%\"><img align=\"middle\" src=\"$myimage\" alt=\"\" title=\"\" /> = "._NEWTODAY."</td>\n";
    $myimage = myimage("new_03.png");
    echo "<td align=\"center\" width=\"34%\"><img align=\"middle\" src=\"$myimage\" alt=\"\" title=\"\" /> = "._NEWLAST3DAYS."</td>\n";
    $myimage = myimage("new_07.png");
    echo "<td align=\"center\" width=\"33%\"><img align=\"middle\" src=\"$myimage\" alt=\"\" title=\"\" /> = "._NEWTHISWEEK."</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    $myimage = myimage("new_14.png");
    echo "<td align=\"center\" width=\"33%\"><img align=\"middle\" src=\"$myimage\" alt=\"\" title=\"\" /> = "._NEWLAST2WEEKS."</td>\n";
    echo "<td align=\"center\" width=\"34%\">&nbsp;</td>\n";
    $myimage = myimage("popular.png");
    echo "<td align=\"center\" width=\"33%\"><img align=\"middle\" src=\"$myimage\" alt=\"\" title=\"\" /> = "._POPULAR."</td>\n";
    echo "</tr>\n";
    echo "</table>\n";
    Max_CloseTable();
}

function SearchForm() {
    global $module_name, $query;
    echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n";
    echo "<form action=\"modules.php?name=$module_name&amp;op=search&amp;query=$query\" method=\"post\">\n";
    echo "<tr><td><font class=\"content\"><input type=\"text\" size=\"25\" name=\"query\" value=\"$query\" /> <input type=\"submit\" value=\""._DL_SEARCH."\" /></td></tr>\n";
    echo "</form>\n";
    echo "</table>\n";
}

// Copyright (c) 2003 --- NukeScripts Network ---
// Can not be reproduced in whole or in part without
// written consent from NukeScripts Network CEO
function showlisting($lid) {
    global $admin_file, $module_name, $dl_config;
    $lid     = $GLOBALS['db']->XMFnum($lid);
    $result  = $GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE `lid`='$lid' ");
    $lidinfo = $GLOBALS['db']->sql_fetchrow($result);
    Max_OpenTable();
    $priv = $lidinfo['sid'] - 2;
    if (($lidinfo['sid'] == 0) || ($lidinfo['sid'] == 1 AND defined('USER_ALLOW'))  || ($lidinfo['sid'] == 2 AND defined('ADMIN_ALLOW')) || ($lidinfo['sid'] > 2 AND of_group($priv)) || $dl_config['show_download'] == '1') {
        $lidinfo['title']       = stripslashes($lidinfo['title']);
        $lidinfo['description'] = stripslashes($lidinfo['description']);
        if (defined('ADMIN_ALLOW')) {
            $myimage = myimage("edit.png");
            echo "<a href=\"".$admin_file.".php?op=DownloadModify&amp;lid=$lid\" target=\"$lid\"><img align=\"middle\" src=\"$myimage\" border=\"0\" alt=\""._DL_EDIT."\" /></a>&nbsp;";
        } else {
            $myimage = myimage("show.png");
            echo "<img align=\"middle\" src=\"$myimage\" border=\"0\" alt=\"\" />&nbsp;";
        }
        echo "<a href=\"modules.php?name=$module_name&amp;op=getit&amp;lid=$lid\"><b>".$lidinfo['title']."</b></a>";
        newdownloadgraphic($datetime, $lidinfo['date']);
        popgraphic($lidinfo['hits']);
        br('1');
        if ($lidinfo['sid'] == 0) {
            $who_view = _DL_ALL;
        } elseif ($lidinfo['sid'] == 1) {
            $who_view = _DL_USERS;
        } elseif ($lidinfo['sid'] == 2) {
            $who_view = _DL_ADMIN;
        } elseif ($lidinfo['sid'] >2) {
            $newView = $lidinfo['sid'] - 2;
            list($who_view) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `gname` FROM `".TABLE_NSNGR_GROUPS."` WHERE `gid`='$newView' "));
            $who_view = $who_view." "._DL_ONLY;
        }
        echo "<b>"._DL_PERM.":</b> $who_view<br />\n";
        echo "<b>"._VERSION.":</b> ".$lidinfo['version']."<br />\n";
        echo "<b>"._FILESIZE.":</b> ".CoolSize($lidinfo['filesize'])."<br />\n";
        echo "<b>"._ADDEDON.":</b> ".CoolDate($lidinfo['date'])."<br />\n";
        echo "<b>"._DOWNLOADS.":</b> ".$lidinfo['hits']."<br />\n";
        echo "<b>"._HOMEPAGE.":</b> ";
        if ($lidinfo['homepage'] == "" || $lidinfo['homepage'] == "http://") {
            echo _DL_NOTLIST;
        } else {
            echo "<a href=\"".$lidinfo['homepage']."\" target=\"new\">".$lidinfo['homepage']."</a>";
        }
    } else {
        restricted2($lidinfo['sid']);
    }
    Max_CloseTable();
}

// Copyright (c) 2003 --- NukeScripts Network ---
// Can not be reproduced in whole or in part without
// written consent from NukeScripts Network CEO
function showresulting($lid) {
    global $admin_file, $module_name, $dl_config;
    $lid     = $GLOBALS['db']->XMFnum($lid);
    $lidinfo = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE `lid`='$lid' "));
    Max_OpenTable();
    $priv = $lidinfo['sid'] - 2;
    if (($lidinfo['sid'] == 0) || ($lidinfo['sid'] == 1 AND defined('USER_ALLOW'))  || ($lidinfo['sid'] == 2 AND defined('ADMIN_ALLOW')) || ($lidinfo['sid'] > 2 AND of_group($priv)) || $dl_config['show_download'] == '1') {
        $lidinfo['title']       = stripslashes($lidinfo['title']);
        $lidinfo['description'] = stripslashes($lidinfo['description']);
        if (defined('ADMIN_ALLOW')) {
            $myimage = myimage("edit.png");
            echo "<a href='".$admin_file.".php?op=DownloadModify&amp;lid=$lid' target='$lid'><img align='middle' src='$myimage' border='0' alt='"._DL_EDIT."' title='"._DL_EDIT."' /></a>&nbsp;";
        } else {
            $myimage = myimage("show.png");
            echo "<img align='middle' src='$myimage' border='0' alt='' title='' />&nbsp;";
        }
        echo "<a href='modules.php?name=$module_name&amp;op=getit&amp;lid=$lid'><b>".$lidinfo['title']."</b></a>";
        newdownloadgraphic($datetime, $lidinfo['date']);
        popgraphic($lidinfo['hits']);
        br('1');
        if ($lidinfo['sid'] == 0) {
            $who_view = _DL_ALL;
        } elseif ($lidinfo['sid'] == 1) {
            $who_view = _DL_USERS;
        } elseif ($lidinfo['sid'] == 2) {
            $who_view = _DL_ADMIN;
        } elseif ($lidinfo['sid'] >2) {
            $newView = $lidinfo['sid'] - 2;
            list($who_view) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `gname` FROM `".TABLE_NSNGR_GROUPS."` WHERE `gid`='$newView' "));
            $who_view = $who_view." "._DL_ONLY;
        }
        echo "<b>"._DL_PERM.":</b> $who_view<br />\n";
        echo "<b>"._VERSION.":</b> ".$lidinfo['version']."<br />\n";
        echo "<b>"._FILESIZE.":</b> ".CoolSize($lidinfo['filesize'])."<br />\n";
        echo "<b>"._ADDEDON.":</b> ".CoolDate($lidinfo['date'])."<br />\n";
        echo "<b>"._DOWNLOADS.":</b> ".$lidinfo['hits']."<br />\n";
        echo "<b>"._HOMEPAGE.":</b> ";
        if ($lidinfo['homepage'] == "" || $lidinfo['homepage'] == "http://") {
            echo _DL_NOTLIST."<br />\n";
        } else {
            echo "<a href='".$lidinfo['homepage']."' target='new'>".$lidinfo['homepage']."</a><br />\n";
        }
        $result2 = $GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `cid`='".$lidinfo['cid']."'");
        $cidinfo = $GLOBALS['db']->sql_fetchrow($result2);
        $cidinfo['title'] = "<a href='modules.php?name=$module_name&amp;cid=".$lidinfo['cid']."'>".$cidinfo['title']."</a>";
        $cidinfo['title'] = getparentlink($cidinfo['parentid'], $cidinfo['title']);
        echo "<b>"._CATEGORY.":</b> ".$cidinfo['title']."\n";
    } else {
        restricted2($lidinfo['sid']);
    }
    Max_CloseTable();
}

// Copyright (c) 2003 --- NukeScripts Network ---
// Can not be reproduced in whole or in part without
// written consent from NukeScripts Network CEO
function pagenums_admin($op, $totalselected, $perpage, $max) {
    global $admin_file;
    $pagesint = ($totalselected / $perpage);
    $pageremainder = ($totalselected % $perpage);
    if ($pageremainder != 0) {
        $pages = ceil($pagesint);
        if ($totalselected < $perpage) { $pageremainder = 0; }
    } else {
        $pages = $pagesint;
    }
    if ($pages != 1 && $pages != 0) {
        $counter = 1;
        $currentpage = ($max / $perpage);
        echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n";
        echo "<tr><form action=\"".$admin_file.".php\" method=\"post\">\n";
        echo "<td align=\"right\"><b>"._DL_SELECTPAGE.": </b><select name=\"min\" onChange=\"top.location.href=this.options[this.selectedIndex].value\">\n";
        while ($counter <= $pages ) {
            $cpage = $counter;
            $mintemp = ($perpage * $counter) - $perpage;
            if ($counter == $currentpage) {
                echo "<option selected>$counter</option>\n";
            } else {
                echo "<option value='".$admin_file.".php?op=$op&amp;min=$mintemp";
                if ($op > "" ) { echo "&amp;op=$op"; }
                if ($query > "") { echo "&amp;query=$query"; }
                if (isset($cid)) { echo "&amp;cid=$cid"; }
                echo "'>$counter</option>\n";
            }
            $counter++;
        }
        echo "</select><b> "._DL_OF." $pages "._DL_PAGES."</b></td>\n</form>\n</tr>\n";
        echo "</table>\n";
    }
}

// Copyright (c) 2003 --- NukeScripts Network ---
// Can not be reproduced in whole or in part without
// written consent from NukeScripts Network CEO
function pagenums($cid, $query, $orderby, $op, $totalselected, $perpage, $max) {
    global $module_name;
    $pagesint = ($totalselected / $perpage);
    $pageremainder = ($totalselected % $perpage);
    if ($pageremainder != 0) {
        $pages = ceil($pagesint);
        if ($totalselected < $perpage) { $pageremainder = 0; }
    } else {
        $pages = $pagesint;
    }
    if ($pages != 1 && $pages != 0) {
        $counter = 1;
        $currentpage = ($max / $perpage);
        echo "<table border='0' cellpadding='2' cellspacing='2' width='100%'>\n";
        echo "<tr><form action='modules.php?name=$module_name' method='post'>\n";
        echo "<td align='right'><b>"._DL_SELECTPAGE.": </b><select name='min' onChange='top.location.href=this.options[this.selectedIndex].value'>\n";
        while ($counter <= $pages ) {
            $cpage = $counter;
            $mintemp = ($perpage * $counter) - $perpage;
            if ($counter == $currentpage) {
                echo "<option selected>$counter</option>\n";
            } else {
                echo "<option value='modules.php?name=$module_name&amp;min=$mintemp";
                if ($op > "" ) { echo "&amp;op=$op"; }
                if ($query > "") { echo "&amp;query=$query"; }
                if (isset($cid)) { echo "&amp;cid=$cid"; }
                echo "'>$counter</option>\n";
            }
            $counter++;
        }
        echo "</select><b> "._DL_OF." $pages "._DL_PAGES."</b></td>\n</form>\n</tr>\n";
        echo "</table>\n";
    }
}