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

$lid     = $GLOBALS['db']->XMFnum($lid);
$result  = $GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE `lid`='$lid' AND `active`>'0'");
$lidinfo = $GLOBALS['db']->sql_fetchrow($result);
$pagetitle = "- "._DOWNLOADPROFILE.": ".stripslashes($lidinfo['title']);
incoh();
$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') {
  if ($lidinfo['lid'] == "" OR $lidinfo['active'] == 0) {
    title(_DOWNLOADPROFILE.": "._INVALIDDOWNLOAD);
    Max_OpenTable();
    echo "<center><b>"._INVALIDDOWNLOAD."</b></center>\n";
  } else {
    $fetchid = base64_encode($lidinfo['url']);
    $title = stripslashes($lidinfo['title']);
    title(_DOWNLOADPROFILE.": $title");
    Max_OpenTable();
    mt_srand ((double)microtime()*1000000);
    $maxran = 1000000;
    $random_num = mt_rand(0, $maxran);
    $lidinfo['description'] = stripslashes($lidinfo['description']);
    $lidinfo['description'] = ereg_replace ("\r\n", "<br />", $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 "<font class='title'>"._DOWNLOADPROFILE.": $title</font><br /><hr>";
    echo "".$lidinfo['description']."<br /><hr>";
    echo "<b>"._VERSION.":</b> ".$lidinfo['version']."<br />\n";
    echo "<b>"._FILESIZE.":</b> ".CoolSize($lidinfo['filesize'])."<br />";
    echo "<b>"._ADDEDON.":</b> ".CoolDate($lidinfo['date'])."<br />\n";
    echo "<b>"._DOWNLOADS.":</b> ".$lidinfo['hits']."<br />";
    echo "<b>"._HOMEPAGE.":</b> ";
    if ($lidinfo['homepage'] == "" || $lidinfo['homepage'] == "http://") {
      echo _DL_NOTLIST;
    } else {
      echo "<a href='".$lidinfo['homepage']."' target='new'>".$lidinfo['homepage']."</a>";
    }
    echo "<hr>";
    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))) {
      echo _DL_DIRECTIONS." "._DL_DLNOTES1."$title"._DL_DLNOTES2."</font><br /><br />";
      echo "<center><table border='0'>";
      echo "<form action='modules.php?name=$module_name' method='POST'>";
      echo "<input type='hidden' name='op' value='go' />";
      echo "<input type='hidden' name='lid' value='".$lidinfo['lid']."' />";
      echo "<input type='hidden' name='fetchid' value='$fetchid' />";
      if ($dl_config['usegfxcheck'] == 1 ) {
        if (extension_loaded("gd")) {
          echo "<tr><td><b>"._DL_YOURPASS.":</b></td><td><img src='./?gfx=gfx&amp;random_num=$random_num' height='20' width='80' border='0' alt='"._DL_YOURPASS."' title='"._DL_YOURPASS."' /></td></tr>";
          echo "<tr><td><b>"._DL_TYPEPASS.":</b></td><td><input type='text' name='passcode' size='10' maxlength='10' /></td></tr>";
          echo "<input type='hidden' NAME='checkpass' value='$random_num' />";
        } else {
          $datekey = date("F j");
          $rcode = hexdec(md5($_SERVER[HTTP_USER_AGENT] . $sitekey . $random_num . $datekey));
          $code = substr($rcode, 2, 6);
          $ThemeSel = get_theme();
          if (file_exists("themes/$ThemeSel/images/downloads/code_bg.png")) {
            $imgpath = "themes/$ThemeSel/images";
          } else {
            $imgpath = "images";
          }
          echo "<tr><td><b>"._DL_YOURPASS.":</b></td><td height='20' width='80' background='$imgpath/code_bg.png' class='storytitle' align='center'><b>$code</b></td></tr>";
          echo "<tr><td><b>"._DL_TYPEPASS.":</b></td><td><input type='text' name='passcode' size='10' maxlength='10' /></td></tr>";
          echo "<input type='hidden' name='checkpass' value='$code'>";
        }
      }
      echo "<tr><td colspan='2' align='center'><input type='submit' name='"._DL_GOGET."' value='"._DL_GOGET."'></td></tr>";
      echo "</form>";
      echo "</table></center><br />";
      echo "<center><font class='content'>[ <a href='modules.php?name=$module_name&amp;op=modifydownloadrequest&amp;lid=$lid'>"._MODIFY."</a> ]</font></center>\n";
    } else {
      restricted($lidinfo['sid']);
    }
  }
  Max_CloseTable();
} else {
  Max_OpenTable();
  restricted($lidinfo['sid']);
  Max_CloseTable();
}
incof();