<?php

@( (bool)FALSE === strpos( $_SERVER['REQUEST_URI'], basename( __FILE__ ) ) ) OR exit( '!! ACCESS DENIED !!' );
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: download.php,v 1.9.2.11 2004/08/15 12:58:17 kirilt Exp $




/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
/* http://phpnuke.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.       */
/************************************************************************/

/*********************************************************/
/* Downloads Modified Web Downloads                      */
/*********************************************************/

function downloads() {
    global $hlpfile, $mpnTables;
    include ("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    $result=mysql_query("select * from ".$mpnTables['downloads_downloads']."");
    $numrows = mysql_num_rows($result);
    echo "<font class=\"content\">".translate("There are")." <b>$numrows</b> ".translate("Downloads in the Database.")."</font></center>";
    CloseTable();
    echo "<br />";

/* Temporarily 'homeless' downloads functions (to be revised in admin.php breakup) */

    $result = mysql_query("select * from ".$mpnTables['downloads_modrequest']." where brokendownload=1");
    $totalbrokendownloads = mysql_num_rows($result);
    $result2 = mysql_query("select * from ".$mpnTables['downloads_modrequest']." where brokendownload=0");
    $totalmodrequests = mysql_num_rows($result2);

/* List Downloads waiting for validation */

    $result = mysql_query("select lid, cid, sid, title, url, description, name, email, submitter, filesize, version, homepage from ".$mpnTables['downloads_newdownload']." order by lid");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    OpenTable();
    echo "<center><font class=\"option\"><b>".translate("Downloads Waiting for Validation")."</b></font></center><br /><br />";
    while(list($lid, $cid, $sid, $title, $url, $description, $name, $email, $submitter, $filesize, $version, $homepage) = mysql_fetch_row($result)) {

        // Kiril: Start New Sanitizer

        $sanity_ary = compact( 'title', 'url', 'description', 'name', 'email', 'submitter', 'version', 'homepage' );
        $_SERVER['SAN'] -> slashIT( $sanity_ary );
        extract( $sanity_ary );
        unset( $sanity_ary );

        // End New Sanitizer

        if ($submitter == "") {
	        $submitter = translate("None");
        }
        $homepage = ereg_replace("http://","",$homepage);
        echo "<form action=\"admin.php?fct=download\" method=\"post\">"
		."<table border=0>"
        ."<tr><td class='w30'><b>".translate("Download ID").":</td><td>$lid</b></td></tr>"
        ."<tr><td>".translate("Submitter").":</td><td><b>$submitter</b></td></tr>"
        ."<tr><td>".translate("Program Name").":</td><td><input type=\"text\" name=\"title\" value=\"$title\" size=\"60\" maxlength=\"100\"></td></tr>\n"
        ."<tr><td>".translate("File Link").":</td><td><input type=\"text\" name=\"url\" value=\"$url\" size=\"60\" maxlength=\"100\">&nbsp;[ <a target=\"_blank\" href=\"$url\">".translate("Check")."</a> ]</td></tr>\n"
        ."<tr><td valign='top'>".translate("Description").":</td><td><textarea name=\"description\" cols=\"60\" rows=\"10\">$description</textarea></td></tr>\n"
        ."<tr><td>".translate("Author's Name").":</td><td><input type=\"text\" name=\"name\" size=\"60\" maxlength=\"100\" value=\"$name\"></td></tr>\n"
        ."<tr><td>".translate("Author's Email").":</td><td><input type=\"text\" name=\"email\" size=\"60\" maxlength=\"100\" value=\"$email\"></td></tr>\n"
        ."<tr><td>".translate("Filesize").":</td><td><input type=\"text\" name=\"filesize\" size=\"12\" maxlength=\"11\" value=\"$filesize\"></td></tr>\n"
        ."<tr><td>".translate("Version").":</td><td><input type=\"text\" name=\"Version\" size=\"11\" maxlength=\"10\" value=\"$version\"></td></tr>\n"
        ."<tr><td>".translate("HomePage").":</td><td><input type=\"text\" name=\"homepage\" size=\"60\" maxlength=\"200\" value=\"http://$homepage\"> [ <a href=\"http://$homepage\">".translate("Visit")."</a> ]</td></tr>\n";

        $result2 = mysql_query("select cid, title from ".$mpnTables['downloads_categories']." order by title");

        echo "<tr><td>".translate("Category").":</td><td><select name=\"cat\">";
        while(list($ccid, $ctitle) = mysql_fetch_row($result2)) {
	        $ctitle = stripslashes( $ctitle );

	        $sel = "";
	        if ($cid==$ccid AND $sid==0) {
	            $sel = "selected";
	        }
	        echo "<option value=\"$ccid\" $sel>$ctitle</option>\n";
	        $result3=mysql_query("select sid, title from ".$mpnTables['downloads_subcategories']." where cid=$ccid order by title");
	        while(list($ssid, $stitle) = mysql_fetch_row($result3)) {
	            $stitle = stripslashes( $stitle );
	            $sel = "";
	            if ($sid == $ssid) {
		            $sel = "selected";
	            }
	            echo "<option value=\"$ccid-$ssid\" $sel>$ctitle / $stitle</option>\n";
	        }

        }
	    echo "</select></td></tr>\n"
		."</table>\n<br />\n";
        echo "<input type=\"hidden\" name=\"new\" value=\"1\">";
        echo "<input type=\"hidden\" name=\"hits\" value=\"0\">";
        echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">";
        echo "<input type=\"hidden\" name=\"submitter\" value=\"$submitter\">";

        // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='title|url|description|name|email|filesize|Version|homepage' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

        // End Sanitizer


        echo "<input type=\"hidden\" name=\"submitter\" value=\"$submitter\">";
        echo "</select><input type=\"hidden\" name=\"op\" value=\"DownloadsAddDownload\"><br /><br /><input class=\"button\" type=\"submit\" value=".translate("Add")."> [ <a href=\"admin.php?fct=download&op=DownloadsDelNew&amp;lid=$lid\">".translate("Delete")."</a> ]</form><br /><hr noshade><br />";
    }
    CloseTable();
    echo "<br />";
    } else {
    }

/* Add a New Main Category */

    OpenTable();
    echo "<center><font class=\"content\">[ <a href=\"admin.php?fct=download&op=DownloadsCleanVotes\">".translate("Clean Downloads Votes")."</a> | "
    ."<a href=\"admin.php?fct=download&op=DownloadsListBrokenDownloads\">".translate("Broken Downloads Reports")." ($totalbrokendownloads)</a> | "
    ."<a href=\"admin.php?fct=download&op=DownloadsListModRequests\">".translate("Download Modification Requests")." ($totalmodrequests)</a> | "
    ."<a href=\"admin.php?fct=download&op=DownloadsDownloadCheck\">".translate("Validate Downloads")."</a> ]</font></center>";
    CloseTable();
    echo "<br />";
    OpenTable();
    echo "<form method=\"post\" action=\"admin.php?fct=download\">"
    ."<font class=\"option\"><b>".translate("Add a MAIN Category")."</b><br /><br />"
	."<table border=0>"
    ."<tr><td class='w30'>".translate("Name").":</td><td><input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\"></td>"
    ."<tr><td valign='top'>".translate("Description").":</td><td><textarea name=\"cdescription\" cols=\"60\" rows=\"10\"></textarea></tr>\n</table>";

    // Kiril: New Sanitizer

    echo "<input type='hidden' name='stripit_form' value='title|cdescription' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    echo "<input type=\"hidden\" name=\"op\" value=\"DownloadsAddCat\"><br />\n"
    ."<input class=\"button\" type=\"submit\" value=\"".translate("Add")."\"><br />\n"
    ."</form>\n";
    CloseTable();
    echo "<br />\n";

// Add a New Sub-Category

    $result = mysql_query("select * from ".$mpnTables['downloads_categories']."");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    OpenTable();
    echo "<form method=\"post\" action=\"admin.php?fct=download\">"
        ."<font class=\"option\"><b>".translate("Add Sub Category")."</b></font><br /><br />"
        ."".translate("Name").": <input type=\"text\" name=\"title\" size=\"30\" maxlength=\"100\">&nbsp;".translate("in")."&nbsp;";
    $result = mysql_query("select cid, title from ".$mpnTables['downloads_categories']." order by title");
    echo "<select name=\"cid\">";
    while(list($ccid, $ctitle) = mysql_fetch_row($result)) {
        $ctitle = stripslashes( $ctitle );
        echo "<option value=\"$ccid\">$ctitle</option>";
    }
    echo "</select>\n";

    // Kiril: New Sanitizer

    echo "<input type='hidden' name='stripit_form' value='title' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    echo "<input type=\"hidden\" name=\"op\" value=\"DownloadsAddSubCat\">"
        ."<input class=\"button\" type=\"submit\" value=\"".translate("Add")."\"><br />"
        ."</form>";
    CloseTable();
    echo "<br />";
//    } else {
    }

// Add a New Download to Database

    $result = mysql_query("select cid, title from ".$mpnTables['downloads_categories']."");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    OpenTable();
    echo "<form method=\"post\" action=\"admin.php?fct=download\">"
        ."<font class=\"option\"><b>".translate("Add a New Download")."</b><br /><br />"
		."<table border=0>"
        ."<tr><td class='w30'>".translate("Program Name").":</td><td><input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\"></td></tr>\n"
        ."<tr><td>".translate("File Link").":</td><td><input type=\"text\" name=\"url\" size=\"60\" maxlength=\"100\" value=\"http://\"></td></tr>\n";
    $result = mysql_query("select cid, title from ".$mpnTables['downloads_categories']." order by title");
    echo "<tr><td>".translate("Category").":</td><td><select name=\"cat\">";
    while(list($cid, $title) = mysql_fetch_row($result)) {
        $title = stripslashes( $title );
        echo "<option value=\"$cid\">$title</option>";
        $result2 = mysql_query("select sid, title from ".$mpnTables['downloads_subcategories']." where cid=$cid order by title");
        while(list($sid, $stitle) = mysql_fetch_row($result2)) {
            $stitle = stripslashes( $stitle );
            echo "<option value=\"$cid-$sid\">$title / $stitle</option>";
        }
    }
    echo "</select></td></tr>\n"
        ."<tr><td valign='top'>".translate("Description:<br />(255 characters max)")."</td><td><textarea name=\"description\" cols=\"60\" rows=\"5\"></textarea></td></tr>\n"
        ."<tr><td>".translate("Author's Name").":</td><td><input type=\"text\" name=\"name\" size=\"60\" maxlength=\"60\"></td></tr>\n"
        ."<tr><td>".translate("Author's Email").":</td><td><input type=\"text\" name=\"email\" size=\"60\" maxlength=\"60\"></td></tr>\n"
        ."<tr><td>".translate("Filesize").":</td><td><input type=\"text\" name=\"filesize\" size=\"12\" maxlength=\"11\"> (".translate("in bytes").")</td></tr>\n"
        ."<tr><td>".translate("Version").":</td><td><input type=\"text\" name=\"Version\" size=\"11\" maxlength=\"10\"></td></tr>\n"
        ."<tr><td>".translate("HomePage").":</td><td><input type=\"text\" name=\"homepage\" size=\"60\" maxlength=\"200\" value=\"http://\"></td></tr>\n"
        ."<tr><td>".translate("Hits").":</td><td><input type=\"text\" name=\"hits\" size=\"12\" maxlength=\"11\"></td></tr>\n"
		."</table>\n<br />\n"
        ."<input type=\"hidden\" name=\"op\" value=\"DownloadsAddDownload\">"
            ."<input type=\"hidden\" name=\"new\" value=\"0\">"
        ."<input type=\"hidden\" name=\"lid\" value=\"0\">";

        // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='title|url|description|name|email|filesize|Version|homepage|hits' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

        // End Sanitizer

        echo "<input class=\"button\" type=\"submit\" value=\"".translate("Add this URL")."\"><br />"
        ."</form>";
    CloseTable();
    echo "<br />";
//    } else {
    }

// Modify Category

    $result = mysql_query("select * from ".$mpnTables['downloads_categories']."");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    OpenTable();
    echo "<form method=\"post\" action=\"admin.php?fct=download\">"
        ."<font class=\"option\"><b>".translate("Modify a Category")."</b></font><br /><br />";
    $result = mysql_query("select cid, title from ".$mpnTables['downloads_categories']." order by title");
    echo "".translate("Category").": <select name=\"cat\">";
    while(list($cid, $title) = mysql_fetch_row($result)) {
        $title = stripslashes( $title );

        echo "<option value=\"$cid\">$title</option>";
        $result2 = mysql_query("select sid, title from ".$mpnTables['downloads_subcategories']." where cid=$cid order by title");
        while(list($sid, $stitle) = mysql_fetch_row($result2)) {
            $stitle = stripslashes( $stitle );
            echo "<option value=\"$cid-$sid\">$title / $stitle</option>";
        }
    }
    echo "</select>";

    echo "<input type=\"hidden\" name=\"op\" value=\"DownloadsModCat\">"
        ."<input class=\"button\" type=\"submit\" value=\"".translate("Modify")."\">"
        ."</form>";
    CloseTable();
    echo "<br />";
//    } else {
    }

// Modify Downloads

    $result = mysql_query("select * from ".$mpnTables['downloads_downloads']."");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    OpenTable();
    echo "<form method=\"post\" action=\"admin.php?fct=download\">"
    ."<font class=\"option\"><b>".translate("Modify a Download")."</b><br /><br />"
    ."".translate("Download ID").": <input type=\"text\" name=\"lid\" size=\"12\" maxlength=\"11\">&nbsp;&nbsp;";

    // Kiril: New Sanitizer

    echo "<input type='hidden' name='stripit_form' value='lid' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer


    echo "<input type=\"hidden\" name=\"op\" value=\"DownloadsModDownload\">"
    ."<input class=\"button\" type=\"submit\" value=\"".translate("Modify")."\">"
    ."</form>";
    CloseTable();
    echo "<br />";
//    } else {
    }

/*// Configure Downloads

    include("admin/download/config.inc.php");
    OpenTable();
      echo "<form method=\"post\" action=\"admin.php?fct=download\">"
        ."<font class=\"option\"><b>".translate("Configure Downloads")."</b><br /><br />"
    ."<table width = \"80%\" border = \"0\">"
    ."<tr><td>".translate("Allow user to add to downloads : ")."</td><td>".translate("Yes")."<input type=\"radio\" name=\"con_downadd\" value=\"1\""; if ($user_adddownload == "1") echo "checked"; echo ">&nbsp;"
    ."".translate("No")."<input type=\"radio\" name=\"con_downadd\" value=\"0\""; if ($user_adddownload == "0") echo "checked"; echo "></td></tr>"
    ."<tr><td>".translate("Downloads per Page : ")."</td><td><input type=\"text\" name=\"con_page\" value=\"".$Perpage."\" size=\"3\" maxlength=\"2\"></td></tr>"
    ."<tr><td>".translate("Hits to be Popular : ")."</td><td><input type=\"text\" name=\"con_popular\" value=\"".$popular."\" size=\"4\" maxlength=\"3\"></td></tr>"
    ."<tr><td>".translate("Display in New Downloads : ")."</td><td><input type=\"text\" name=\"con_newdown\" value=\"".$newdownloads."\" size=\"3\" maxlength=\"2\"></td></tr>"
    ."<tr><td>".translate("Downloads to display in Best Downloads Page : ")."</td><td><input type=\"text\" name=\"con_topdown\" value=\"".$topdownloads."\" size=\"3\" maxlength=\"2\"></td></tr>"
    ."<tr><td>".translate("Downloads displayed in Search Page : ")."</td><td><input type=\"text\" name=\"con_search\" value=\"".$downloadsresults."\" size=\"4\" maxlength=\"3\"></td></tr>"
    ."<tr><td>".translate("Block Unregistered users from Suggesting New Downloads : ")."</td><td>".translate("Yes")."<input type=\"radio\" name=\"con_anonblock\" value=\"1\""; if ($downloads_anonadddownloadlock == "1") echo "checked"; echo ">&nbsp;"
    ."".translate("No")."<input type=\"radio\" name=\"con_anonblock\" value=\"0\""; if ($downloads_anonadddownloadlock == "0") echo "checked"; echo "></td></tr>"
    ."<tr><td>".translate("Number votes needed to make the 'top 10' list : ")."</td><td><input type=\"text\" name=\"con_top10\" value=\"".$downloadvotemin."\" size=\"3\" maxlength=\"2\"></td></tr>"
    ."<tr><td>".translate("Block unregistered users from suggesting downloads changes : ")."</td><td>".translate("Yes")."<input type=\"radio\" name=\"con_regmod\" value=\"1\""; if ($blockunregmodify == "1") echo "checked"; echo ">&nbsp;"
    ."".translate("No")."<input type=\"radio\" name=\"con_regmod\" value=\"0\""; if ($blockunregmodify == "0") echo "checked"; echo "></td></tr>"
    ."</table><br />"
    ."<input type=\"hidden\" name=\"op\" value=\"DownloadsConfig\">"
        ."<input class=\"button\" type=\"submit\" value=\"".translate("Save")."\">";

        // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='con_page|con_popular|con_newdown|con_topdown|con_search|con_top10' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='1' />\n";

        // End Sanitizer

        echo "</form>";
    CloseTable();*/
    echo "<br />";
    include ("footer.php");
}

function DownloadConfigEdit()
{
    include("admin/download/config.inc.php");
    OpenTable();
      echo "<form method=\"post\" action=\"admin.php?fct=download\">"
        ."<font class=\"option\"><b>".translate("Configure Downloads")."</b><br /><br />"
    ."<table width = \"80%\" border = \"0\">"
    ."<tr><td>".translate("Allow user to add to downloads : ")."</td><td>".translate("Yes")."<input type=\"radio\" name=\"con_downadd\" value=\"1\""; if ($user_adddownload == "1") echo "checked"; echo ">&nbsp;"
    ."".translate("No")."<input type=\"radio\" name=\"con_downadd\" value=\"0\""; if ($user_adddownload == "0") echo "checked"; echo "></td></tr>"
    ."<tr><td>".translate("Downloads per Page : ")."</td><td><input type=\"text\" name=\"con_page\" value=\"".$Perpage."\" size=\"3\" maxlength=\"2\"></td></tr>"
    ."<tr><td>".translate("Hits to be Popular : ")."</td><td><input type=\"text\" name=\"con_popular\" value=\"".$popular."\" size=\"4\" maxlength=\"3\"></td></tr>"
    ."<tr><td>".translate("Display in New Downloads : ")."</td><td><input type=\"text\" name=\"con_newdown\" value=\"".$newdownloads."\" size=\"3\" maxlength=\"2\"></td></tr>"
    ."<tr><td>".translate("Downloads to display in Best Downloads Page : ")."</td><td><input type=\"text\" name=\"con_topdown\" value=\"".$topdownloads."\" size=\"3\" maxlength=\"2\"></td></tr>"
    ."<tr><td>".translate("Downloads displayed in Search Page : ")."</td><td><input type=\"text\" name=\"con_search\" value=\"".$downloadsresults."\" size=\"4\" maxlength=\"3\"></td></tr>"
    ."<tr><td>".translate("Block Unregistered users from Suggesting New Downloads : ")."</td><td>".translate("Yes")."<input type=\"radio\" name=\"con_anonblock\" value=\"1\""; if ($downloads_anonadddownloadlock == "1") echo "checked"; echo ">&nbsp;"
    ."".translate("No")."<input type=\"radio\" name=\"con_anonblock\" value=\"0\""; if ($downloads_anonadddownloadlock == "0") echo "checked"; echo "></td></tr>"
    ."<tr><td>".translate("Number votes needed to make the 'top 10' list : ")."</td><td><input type=\"text\" name=\"con_top10\" value=\"".$downloadvotemin."\" size=\"3\" maxlength=\"2\"></td></tr>"
    ."<tr><td>".translate("Block unregistered users from suggesting downloads changes : ")."</td><td>".translate("Yes")."<input type=\"radio\" name=\"con_regmod\" value=\"1\""; if ($blockunregmodify == "1") echo "checked"; echo ">&nbsp;"
    ."".translate("No")."<input type=\"radio\" name=\"con_regmod\" value=\"0\""; if ($blockunregmodify == "0") echo "checked"; echo "></td></tr>"
    ."</table><br />"
    ."<input type=\"hidden\" name=\"op\" value=\"DownloadsConfig\">"
        ."<input class=\"button\" type=\"submit\" value=\"".translate("Save")."\">";

    // Kiril: New Sanitizer

    echo "<input type='hidden' name='stripit_form' value='con_page|con_popular|con_newdown|con_topdown|con_search|con_top10' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='1' />\n";

    // End Sanitizer

    echo "</form>";
    CloseTable();

}

function DownloadsConfig($con_downadd, $con_page, $con_popular, $con_newdown, $con_topdown, $con_search, $con_anonblock, $con_top10, $con_regmod) {

    $check_ary = array( $_POST['con_page'], $_POST['con_popular'], $_POST['con_newdown'], $_POST['con_topdown'], $_POST['con_search'], $_POST['con_top10'] );

    $verify_check_ary = $_SERVER['SAN'] -> verifyContent( $check_ary, 5 );

    // Check Num Only

    if ( in_array( (bool)FALSE, $verify_check_ary ) )
    {
        goBack( translate( 'Please Make Sure You Have Numbers In Number Only Fields' ) );
        exit;
    }

    $anonwaitdays = 1;
    $outsidewaitdays = 1;
    $useoutsidevoting = 1;
    $anonweight = 10;
    $outsideweight = 20;
    $detailvotedecimal = 2;
    $mainvotedecimal = 1;
    $featurebox = 1;
    $blockunregmodify = 1;
    $topdownloadspercentrigger = 0;
    $mostpopdownloadspercentrigger = 0;
    $topdownloads = 25;
    $mostpopdownloads = 25;

    if ($con_page == "") $con_page = 10;
    if ($con_popular == "") $con_popular = 500;
    if ($con_newdown == "") $con_newdown = 10;
    if ($con_topdown == "") $con_topdown = 25;
    if ($con_search == "") $con_search = 10;
    if ($con_anonblock == "") $con_anonblock = 1;
    if ($con_downadd == "") $con_downadd = 1;
    if ($con_top10 == "") $contop10 = 5;
    if ($con_regmod == "") $con_regmod = 1;

    $config = array(
    '<?php',
    ' ',
    require('./admin/configs_header.php'),
    '/**************************************/',
    '/* Configuration for download section */',
    '/*     Adapted from php-nuke 5.3      */',
    '/*         Do not edit here           */',
    '/*     Make changes in Admin GUI      */',
    '/**************************************/',
    ' ',
    '$Perpage = '.$con_page.';',
    '$popular = '.$con_popular.';',
    '$outsidewaitdays = '.$outsidewaitdays.';',
    '$useoutsidevoting = '.$useoutsidevoting.';',
    '$anonweight = '.$anonweight.';',
    '$outsideweight = '.$outsideweight.';',
    '$detailvotedecimal = '.$detailvotedecimal.';',
    '$mainvotedecimal = '.$mainvotedecimal.';',
    '$featurebox = '.$featurebox.';',
    '$blockunregmodify = '.$blockunregmodify.';',
    '$newdownloads = '.$con_newdown.';',
    '$topdownloads = '.$con_topdown.';',
    '$downloadsresults = '.$con_search.';',
    '$downloads_anonadddownloadlock = '.$con_anonblock.';',
    '$user_adddownload = '.$con_downadd.';',
    '$topdownloadspercentrigger = '.$topdownloadspercentrigger.';',
    '$topdownloads = '.$topdownloads.';',
    '$mostpopdownloadspercentrigger = '.$mostpopdownloadspercentrigger.';',
    '$mostpopdownloads = '.$mostpopdownloads.';',
    '$downloadvotemin = '.$con_top10.';',
    '$blockunregmodify = '.$con_regmod.';',
    '?>');

    $filename = 'admin/download/config.inc.php';

    if ( ! $_SERVER['F_LIB'] -> writeFile( $filename, 'w+b', $config ) )
    {
        goBack( translate( 'File Write Error.  Check Permissions On ' ) . $filename );
        exit;
    }

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download' );

    /*$file = "";

    if ($fp = fopen($file, "wb")) {
        foreach ($config as $line) {
            fwrite($fp, "$line\n");
        }
        fclose($fp);


        Header("Location: admin.php?fct=download");

    } else {
    echo translate("Error: Unable to Save Download Configuration");
    }*/
}

function DownloadsModDownload($lid) {
    global $mpnTables, $sitename;
    include ("header.php");
    admin_menu();
    echo "<br />";
    global $anonymous;
    $result = mysql_query("select cid, sid, title, url, description, name, email, hits, filesize, version, homepage from ".$mpnTables['downloads_downloads']." where lid=$lid");
    OpenTable();
    echo "<center><font class=\"title\"><b>".translate("Web Downloads Administration")."</b></font></center>";
    CloseTable();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"option\"><b>".translate("Modify a Download")."</b></font></center><br /><br />";
    while(list($cid, $sid, $title, $url, $description, $name, $email, $hits, $filesize, $version, $homepage) = @mysql_fetch_row($result)) {

        // Kiril: Start New Sanitizer

        $sanity_ary = compact( 'title', 'url', 'description', 'name', 'email', 'hits', 'version', 'homepage' );
        $_SERVER['SAN'] -> slashIT( $sanity_ary );
        extract( $sanity_ary );
        unset( $sanity_ary );

        // End New Sanitizer

        //$title = stripslashes($title); $description = stripslashes($description);

        echo "<form action=\"admin.php?fct=download\" method=post>\n"
        ."<table border=0>\n"
        ."<tr><td class='w30'>".translate("Download ID").":</td><td><b>$lid</b></td></tr>\n"
        ."<tr><td>".translate("Page Title").":</td><td><input type=\"text\" name=\"title\" value=\"$title\" size=\"50\" maxlength=\"100\"></td></tr>\n"
        ."<tr><td>".translate("Page URL").":</td><td><input type=\"text\" name=\"url\" value=\"$url\" size=\"50\" maxlength=\"100\">&nbsp;[ <a href=\"$url\">".translate("Check")."</a> ]</td></tr>\n"
        ."<tr><td valign='top'>".translate("Description").":</td><td><textarea name=\"description\" cols=\"60\" rows=\"10\">$description</textarea></td></tr>\n"
        ."<tr><td>".translate("Author's Name").":</td><td><input type=\"text\" name=\"name\" size=\"50\" maxlength=\"100\" value=\"$name\"></td></tr>\n"
        ."<tr><td>".translate("Author's Email").":</td><td><input type=\"text\" name=\"email\" size=\"50\" maxlength=\"100\" value=\"$email\"></td></tr>\n"
        ."<tr><td>".translate("Filesize").":</td><td><input type=\"text\" name=\"filesize\" size=\"12\" maxlength=\"11\" value=\"$filesize\"></td></tr>\n"
        ."<tr><td>".translate("Version").":</td><td><input type=\"text\" name=\"Version\" size=\"11\" maxlength=\"10\" value=\"$version\"></td></tr>\n"
        ."<tr><td>".translate("HomePage").":</td><td><input type=\"text\" name=\"homepage\" size=\"50\" maxlength=\"200\" value=\"$homepage\">&nbsp;[ <a href=\"$homepage\">".translate("Visit")."</a> ]</td></tr>\n"
        ."<tr><td>".translate("Hits").":</td><td><input type=\"text\" name=\"hits\" value=\"$hits\" size=\"12\" maxlength=\"11\"></td></tr>\n";
    $result2 = mysql_query("select cid, title from ".$mpnTables['downloads_categories']." order by title");
    echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">"
        ."<tr><td>".translate("Category").":</td><td><select name=\"cat\">\n";
    while(list($ccid, $ctitle) = mysql_fetch_row($result2)) {
        $ctitle = stripslashes( $ctitle );
        $sel = "";
        if ($cid==$ccid AND $sid==0) {
        $sel = "selected";
        }
        echo "<option value=\"$ccid\" $sel>$ctitle</option>\n";
        $result3 = mysql_query("select sid, title from ".$mpnTables['downloads_subcategories']." where cid=$ccid order by title");
        while(list($ssid, $stitle) = mysql_fetch_row($result3)) {
            $stitle = stripslashes( $stitle );
                $sel = "";
        if ($sid==$ssid) {
            $sel = "selected";
        }
        echo "<option value=\"$ccid-$ssid\" $sel>$ctitle / $stitle</option>\n";
        }
    }

    echo "</select></td></tr>\n";
    echo "</table>\n<br />\n";
    // Kiril: New Sanitizer

    echo "<input type='hidden' name='stripit_form' value='title|url|description|name|email|filesize|Version|homepage|hits' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    echo "<input type=\"hidden\" name=\"op\" value=\"DownloadsModDownloadS\">"
    ."<input class=\"button\" type=\"submit\" value=\"".translate("Modify")."\"> [ <a href=\"admin.php?fct=download&op=DownloadsDelDownload&amp;lid=$lid\">".translate("Delete")."</a> ]</form><br />";
    CloseTable();
    echo "<br />";
    /* Modify or Add Editorial */

        $resulted2 = mysql_query("select adminid, editorialtimestamp, editorialtext, editorialtitle from ".$mpnTables['downloads_editorials']." where downloadid=$lid");
        $recordexist = mysql_num_rows($resulted2);
    OpenTable();
    /* if returns 'bad query' status 0 (add editorial) */
        if ($recordexist == 0)
        {

            echo "<center><font class=\"option\"><b>".translate("Add Editorial")."</b></font></center><br /><br />"
            ."<form action=\"admin.php?fct=download\" method=\"post\">\n"
            ."<input type=\"hidden\" name=\"downloadid\" value=\"$lid\">\n"
            ."<table border=0>\n"
            ."<tr><td class='w30'>".translate("Editorial Title").":</td><td><input type=\"text\" name=\"editorialtitle\" value=\"\" size=\"50\" maxlength=\"100\"></td></tr>\n"
            ."<tr><td valign='top'>".translate("Editorial Text").":</td><td><textarea name=\"editorialtext\" cols=\"60\" rows=\"10\"></textarea></td></tr>\n";
            echo "</table>\n<br />\n";

            // Kiril: New Sanitizer

            echo "<input type='hidden' name='stripit_form' value='editorialtitle|editorialtext' />\n";
            echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

            // End Sanitizer


            echo "<input type=\"hidden\" name=\"op\" value=\"DownloadsAddEditorial\"><input class=\"button\" type=\"submit\" value=\"Add\">";
        }
        else
        {
            /* if returns 'cool' then status 1 (modify editorial) */

            while(list($adminid, $editorialtimestamp, $editorialtext, $editorialtitle) = mysql_fetch_row($resulted2)) {

            $editorialtitle = stripslashes($editorialtitle);
            $editorialtext = stripslashes($editorialtext);

            ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $editorialtimestamp, $editorialtime);
        $editorial_month = translate(strftime("%B",mktime($editorialtime[4],$editorialtime[5],$editorialtime[6],$editorialtime[2],$editorialtime[3],$editorialtime[1])));
            $formatted_date = $editorial_month." ".$editorialtime[3].", ".$editorialtime[1];
            echo "<center><font class=\"option\"><b>Modify Editorial</b></font></center><br /><br />"
                ."<form action=\"admin.php?fct=download\" method=\"post\">\n"
                ."<table border=0>\n"
                ."<tr><td class='w30'>".translate("Author").":</td><td>$adminid</td></tr>\n"
                ."<tr><td>".translate("Date written").":</td><td>$formatted_date</td></tr>\n"
                ."<input type=\"hidden\" name=\"downloadid\" value=\"$lid\">"
                ."<tr><td>".translate("Editorial Title").":</td><td><input type=\"text\" name=\"editorialtitle\" value=\"$editorialtitle\" size=\"50\" maxlength=\"100\"></td></tr>\n"
                ."<tr><td valign='top'>".translate("Editorial Text").":</td><td><textarea name=\"editorialtext\" cols=\"60\" rows=\"10\">$editorialtext</textarea></td></tr>\n";
                echo "</table>\n<br />\n";

                // Kiril: New Sanitizer

                echo "<input type='hidden' name='stripit_form' value='editorialtitle|editorialtext' />\n";
                echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

                // End Sanitizer

                echo "<input type=\"hidden\" name=\"op\" value=\"DownloadsModEditorial\"><input class=\"button\" type=\"submit\" value=\"".translate("Modify")."\"> [ <a href=\"admin.php?fct=download&op=DownloadsDelEditorial&amp;downloadid=$lid\">".translate("Delete")."</a> ]";
                }
        }
    CloseTable();
    echo "<br />";
    OpenTable();

    /* Show Comments */

    $result5 = mysql_query("SELECT ratingdbid, ratinguser, ratingcomments, ratingtimestamp FROM ".$mpnTables['downloads_votedata']." WHERE ratinglid = $lid AND ratingcomments != '' ORDER BY ratingtimestamp DESC");
    $totalcomments = mysql_num_rows($result5);
    echo "<table valign=top width=100%>";
    echo "<tr><td colspan=7><b>Download Comments (total comments: $totalcomments)</b><br /><br /></td></tr>";
    echo "<tr><td width=20 colspan=1><b>User  </b></td><td colspan=5><b>Comment  </b></td><td><b><center>Delete</center></b></td><br /></tr>";
    if ($totalcomments == 0) echo "<tr><td colspan=7><center><font color=cccccc>No Comments<br /></font></center></td></tr>";
    $x=0;
    $colorswitch="dddddd";
    while(list($ratingdbid, $ratinguser, $ratingcomments, $ratingtimestamp) = mysql_fetch_row($result5)) {
        $ratingcomments = stripslashes($ratingcomments);
        echo "<tr><td valign=top bgcolor=$colorswitch>$ratinguser</td><td valign=top colspan=5 bgcolor=$colorswitch>$ratingcomments</td><td bgcolor=$colorswitch><center><b><a href=admin.php?fct=download&op=DownloadsDelComment&lid=$lid&rid=$ratingdbid>X</a></b></center></td><br /></tr>";
        $x++;
        if ($colorswitch=="dddddd") $colorswitch="ffffff";
            else $colorswitch="dddddd";
        }

    // Show Registered Users Votes
    $result5 = mysql_query("SELECT ratingdbid, ratinguser, rating, ratinghostname, ratingtimestamp FROM ".$mpnTables['downloads_votedata']." WHERE ratinglid = $lid AND ratinguser != 'outside' AND ratinguser != '$anonymous' ORDER BY ratingtimestamp DESC");
    $totalvotes = mysql_num_rows($result5);
    echo "<tr><td colspan=7><br /><br /><b>Registered User Votes (total votes: $totalvotes)</b><br /><br /></td></tr>";
    echo "<tr><td><b>User  </b></td><td><b>IP Address  </b></td><td><b>Rating  </b></td><td><b>User AVG Rating  </b></td><td><b>Total Ratings  </b></td><td><b>Date  </b></td></font></b><td><b><center>Delete</center></b></td><br /></tr>";
    if ($totalvotes == 0) echo "<tr><td colspan=7><center><font color=cccccc>No Registered User Votes<br /></font></center></td></tr>";
    $x=0;
    $colorswitch="dddddd";
    while(list($ratingdbid, $ratinguser, $rating, $ratinghostname, $ratingtimestamp) = mysql_fetch_row($result5)) {
        ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $ratingtimestamp, $ratingtime);
        $rating_month = translate(strftime("%B",mktime($ratingtime[4],$ratingtime[5],$ratingtime[6],$ratingtime[2],$ratingtime[3],$ratingtime[1])));
    $formatted_date = $rating_month." ".$ratingtime[3].", ".$ratingtime[1];

        //Individual user information
        $result2 = mysql_query("SELECT rating FROM ".$mpnTables['downloads_votedata']." WHERE ratinguser = '$ratinguser'");
            $usertotalcomments = mysql_num_rows($result2);
            $useravgrating = 0;
            while(list($rating2) = mysql_fetch_row($result2))   $useravgrating = $useravgrating + $rating2;
            $useravgrating = $useravgrating / $usertotalcomments;
            $useravgrating = number_format($useravgrating, 1);
            echo "<tr><td bgcolor=$colorswitch>$ratinguser</td><td bgcolor=$colorswitch>$ratinghostname</td><td bgcolor=$colorswitch>$rating</td><td bgcolor=$colorswitch>$useravgrating</td><td bgcolor=$colorswitch>$usertotalcomments</td><td bgcolor=$colorswitch>$formatted_date  </font></b></td><td bgcolor=$colorswitch><center><b><a href=admin.php?fct=download&op=DownloadsDelVote&lid=$lid&rid=$ratingdbid>X</a></b></center></td></tr><br />";
        $x++;
        if ($colorswitch=="dddddd") $colorswitch="ffffff";
            else $colorswitch="dddddd";
        }

    // Show Unregistered Users Votes
    $result5 = mysql_query("SELECT ratingdbid, rating, ratinghostname, ratingtimestamp FROM ".$mpnTables['downloads_votedata']." WHERE ratinglid = $lid AND ratinguser = '$anonymous' ORDER BY ratingtimestamp DESC");
    $totalvotes = mysql_num_rows($result5);
    echo "<tr><td colspan=7><b><br /><br />Unregistered User Votes (total votes: $totalvotes)</b><br /><br /></td></tr>";
    echo "<tr><td colspan=2><b>IP Address  </b></td><td colspan=3><b>Rating  </b></td><td><b>Date  </b></font></td><td><b><center>Delete</center></b></td><br /></tr>";
    if ($totalvotes == 0) echo "<tr><td colspan=7><center><font color=cccccc>No Unregistered User Votes<br /></font></center></td></tr>";
    $x=0;
    $colorswitch="dddddd";
    while(list($ratingdbid, $rating, $ratinghostname, $ratingtimestamp) = mysql_fetch_row($result5)) {
        ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $ratingtimestamp, $ratingtime);
        $rating_month = translate(strftime("%B",mktime($ratingtime[4],$ratingtime[5],$ratingtime[6],$ratingtime[2],$ratingtime[3],$ratingtime[1])));
        $formatted_date = $rating_month." ".$ratingtime[3].", ".$ratingtime[1];
        echo "<td colspan=2 bgcolor=$colorswitch>$ratinghostname</td><td colspan=3 bgcolor=$colorswitch>$rating</td><td bgcolor=$colorswitch>$formatted_date  </font></b></td><td bgcolor=$colorswitch><center><b><a href=admin.php?fct=download&op=DownloadsDelVote&lid=$lid&rid=$ratingdbid>X</a></b></center></td></tr><br />";
        $x++;
        if ($colorswitch=="dddddd") $colorswitch="ffffff";
            else $colorswitch="dddddd";
        }

    // Show Outside Users Votes
    $result5 = mysql_query("SELECT ratingdbid, rating, ratinghostname, ratingtimestamp FROM ".$mpnTables['downloads_votedata']." WHERE ratinglid = $lid AND ratinguser = 'outside' ORDER BY ratingtimestamp DESC");
    $totalvotes = mysql_num_rows($result5);
    echo "<tr><td colspan=7><b><br /><br />Outside User Votes (total votes: $totalvotes)</b><br /><br /></td></tr>";
    echo "<tr><td colspan=2><b>IP Address  </b></td><td colspan=3><b>Rating  </b></td><td><b>Date  </b></td></font></b><td><b><center>Delete</center></b></td><br /></tr>";
    if ($totalvotes == 0) echo "<tr><td colspan=7><center><font color=cccccc>No Votes from Outside $sitename<br /></font></center></td></tr>";
    $x=0;
    $colorswitch="dddddd";
    while(list($ratingdbid, $rating, $ratinghostname, $ratingtimestamp) = mysql_fetch_row($result5)) {
        ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $ratingtimestamp, $ratingtime);
        $rating_month = translate(strftime("%B",mktime($ratingtime[4],$ratingtime[5],$ratingtime[6],$ratingtime[2],$ratingtime[3],$ratingtime[1])));
        $formatted_date = $rating_month." ".$ratingtime[3].", ".$ratingtime[1];
        echo "<tr><td colspan=2 bgcolor=$colorswitch>$ratinghostname</td><td colspan=3 bgcolor=$colorswitch>$rating</td><td bgcolor=$colorswitch>$formatted_date  </font></b></td><td bgcolor=$colorswitch><center><b><a href=admin.php?fct=download&op=DownloadsDelVote&lid=$lid&rid=$ratingdbid>X</a></b></center></td></tr><br />";
        $x++;
        if ($colorswitch=="dddddd") $colorswitch="ffffff";
            else $colorswitch="dddddd";
        }

    echo "<tr><td colspan=6><br /></td></tr>";
    echo "</table>";

    }
    echo "</form>";
    CloseTable();
    echo "<br />";
    include ("footer.php");
}

function DownloadsDelComment($lid, $rid) {
    global $mpnTables;
    mysql_query("UPDATE ".$mpnTables['downloads_votedata']." SET ratingcomments='' WHERE ratingdbid = $rid");
    mysql_query("UPDATE ".$mpnTables['downloads_downloads']." SET totalcomments = (totalcomments - 1) WHERE lid = $lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=DownloadsModDownload&lid=' . $lid );

}

function DownloadsDelVote($lid, $rid) {
    global $mpnTables;
    mysql_query("delete from ".$mpnTables['downloads_votedata']." where ratingdbid=$rid");
    $voteresult = mysql_query("select rating, ratinguser, ratingcomments FROM ".$mpnTables['downloads_votedata']." WHERE ratinglid = $lid");
    $totalvotesDB = mysql_num_rows($voteresult);
    include ("voteinclude.php");
    mysql_query("UPDATE ".$mpnTables['downloads_downloads']." SET downloadratingsummary=$finalrating,totalvotes=$totalvotesDB,totalcomments=$truecomments WHERE lid = $lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=DownloadsModDownload&lid=' . $lid );

}

function DownloadsListBrokenDownloads() {
    global $bgcolor1, $bgcolor2, $mpnTables;
    include ("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"title\"><b>".translate("Web Downloads Administration")."</b></font></center>";
    CloseTable();
    echo "<br />";
    OpenTable();
    $result = mysql_query("select requestid, lid, modifysubmitter from ".$mpnTables['downloads_modrequest']." where brokendownload=1 order by requestid");
    $totalbrokendownloads = mysql_num_rows($result);
    echo "<center><font class=\"option\"><b>".translate("User Reported Broken Downloads")." ($totalbrokendownloads)</b></font></center><br /><br /><center>"
    ."".translate("Ignore (Deletes all <b><i>requests</i></b> for a given download)")."<br />"
    ."".translate("Delete (Deletes <b><i>broken download</i></b> and <b><i>requests</i></b> for a given download)")."</center><br /><br /><br />"
    ."<table align=\"center\" width=\"450\">";
    if ($totalbrokendownloads==0) {
    echo "<center><font class=\"option\">".translate("No reported broken downloads")."</font></center><br /><br /><br />";
    } else {
        $colorswitch = $bgcolor2;
        echo "<tr>"
            ."<td><b>".translate("Download")."</b></td>"
            ."<td><b>".translate("Submmitter")."</b></td>"
            ."<td><b>".translate("Download Owner")."</b></td>"
            ."<td><b>".translate("Ignore")."</b></td>"
            ."<td><b>".translate("Delete")."</b></td>"
            ."<td><b>".translate("Edit")."</b></td>"
            ."</tr>";
        while(list($requestid, $lid, $modifysubmitter) = mysql_fetch_row($result)) {

            $modifysubmitter = stripslashes( $modifysubmitter );

        $result2 = mysql_query("select title, url, submitter from ".$mpnTables['downloads_downloads']." where lid=$lid");

        if ($modifysubmitter != $anonymous)
        {
            $result3 = mysql_query("select email from ".$mpnTables['users']." where uname='$modifysubmitter' && uid > 1");
            list($email) = mysql_fetch_row($result3);

            $email = stripslashes( $email );
        }
            list($title, $url, $owner) = mysql_fetch_row($result2);

            $title = stripslashes( $title );
            $url = stripslashes( $url );
            $owner = stripslashes( $owner );

            $result4 = mysql_query("select email from ".$mpnTables['users']." where uname='$owner' && uid > 1");
            list($owneremail) = mysql_fetch_row($result4);
            $owneremail = stripslashes( $owneremail );

            echo "<tr>"
            ."<td bgcolor=\"$colorswitch\"><a href=\"$url\">$title</a>"
            ."</td>";
            if ( ! isset( $email ) || $email == '' )
            {
                echo "<td bgcolor=\"$colorswitch\">$modifysubmitter";
            }
            else
            {
                echo "<td bgcolor=\"$colorswitch\"><a href=\"mailto:$email\">$modifysubmitter</a>";
            }

            echo "</td>";
            if ( ! isset( $owneremail ) || $owneremail == '') {
        echo "<td bgcolor=\"$colorswitch\">$owner";
        } else {
        echo "<td bgcolor=\"$colorswitch\"><a href=\"mailto:$owneremail\">$owner</a>";
        }
            echo "</td>"
            ."<td bgcolor=\"$colorswitch\"><center><a href=\"admin.php?fct=download&op=DownloadsIgnoreBrokenDownloads&amp;lid=$lid\">X</a></center>"
            ."</td>"
            ."<td bgcolor=\"$colorswitch\"><center><a href=\"admin.php?fct=download&op=DownloadsDelBrokenDownloads&amp;lid=$lid\">X</a></center>"
            ."</td>"
            ."<td bgcolor=\"$colorswitch\"><center><a href=\"admin.php?fct=download&op=DownloadsModDownload&amp;lid=$lid\">X</a></center>"
            ."</td>"
        ."</tr>";
            if ($colorswitch == $bgcolor2) {
        $colorswitch = $bgcolor1;
            } else {
        $colorswitch = $bgcolor2;
        }
        }
    }
    echo "</table>";
    CloseTable();
    include ("footer.php");
}

function DownloadsDelBrokenDownloads($lid) {
    global $mpnTables;
    mysql_query("delete from ".$mpnTables['downloads_modrequest']." where lid=$lid");
    mysql_query("delete from ".$mpnTables['downloads_downloads']." where lid=$lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=DownloadsListBrokenDownloads' );

}

function DownloadsIgnoreBrokenDownloads($lid) {
    global $mpnTables;
    mysql_query("delete from ".$mpnTables['downloads_modrequest']." where lid=$lid and brokendownload=1");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=DownloadsListBrokenDownloads' );
}

function DownloadsListModRequests() {
    global $bgcolor2, $mpnTables;
    include ("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"title\"><b>".translate("Web Downloads Administration")."</b></font></center>";
    CloseTable();
    echo "<br />";
    OpenTable();
    $result = mysql_query("select requestid, lid, cid, sid, title, url, description, modifysubmitter, name, email, filesize, version, homepage from ".$mpnTables['downloads_modrequest']." where brokendownload=0 order by requestid");
    $totalmodrequests = mysql_num_rows($result);
    echo "<center><font class=\"option\"><b>".translate("User Download Modification Requests")." ($totalmodrequests)</b></font></center><br /><br /><br />";
    echo "<table width=\"95%\"><tr><td>";
    while(list($requestid, $lid, $cid, $sid, $title, $url, $description, $modifysubmitter, $name, $email, $filesize, $version, $homepage) = mysql_fetch_row($result)) {
    $result2 = mysql_query("select cid, sid, title, url, description, name, email, submitter, filesize, version, homepage from ".$mpnTables['downloads_downloads']." where lid=$lid");
    list($origcid, $origsid, $origtitle, $origurl, $origdescription, $origname, $origemail, $owner, $origfilesize, $origversion, $orighomepage) = mysql_fetch_row($result2);
    $result3 = mysql_query("select title from ".$mpnTables['downloads_categories']." where cid=$cid");
    $result4 = mysql_query("select title from ".$mpnTables['downloads_subcategories']." where cid=$cid and sid=$sid");
    $result5 = mysql_query("select title from ".$mpnTables['downloads_categories']." where cid=$origcid");
    $result6 = mysql_query("select title from ".$mpnTables['downloads_subcategories']." where cid=$origcid and sid=$origsid");
    $result7 = mysql_query("select email from ".$mpnTables['users']." where uname='$modifysubmitter' && uid > 1");
    $result8 = mysql_query("select email from ".$mpnTables['users']." where uname='$owner' && uid > 1");
    list($cidtitle) = mysql_fetch_row($result3);
    list($sidtitle) = mysql_fetch_row($result4);
    list($origcidtitle) = mysql_fetch_row($result5);
    list($origsidtitle) = mysql_fetch_row($result6);
    list($modifysubmitteremail) = mysql_fetch_row($result7);
    list($owneremail) = mysql_fetch_row($result8);

    // Kiril: Start New Sanitizer

    $sanity_ary = compact( 'title', 'url', 'description', 'modifysubmitter', 'name', 'email', 'filesize', 'version', 'homepage', 'origtitle', 'origurl', 'origdescription', 'origname', 'origemail', 'owner', 'origfilesize', 'origversion', 'orighomepage', 'cidtitle', 'sidtitle', 'origcidtitle', 'origsidtitle', 'modifysubmitteremail', 'owneremail' );
    $_SERVER['SAN'] -> slashIT( $sanity_ary );
    extract( $sanity_ary );
    unset( $sanity_ary );

    // End New Sanitizer


       /* $title = stripslashes($title);
        $description = stripslashes($description);*/
        if ($owner=="") {
        $owner="administration";
    }
        if ($origsidtitle=="") {
        $origsidtitle= "-----";
    }
        if ($sidtitle=="") {
        $sidtitle= "-----";
    }
        echo "<table border=\"1\" bordercolor=\"black\" cellpadding=\"5\" cellspacing=\"0\" align=\"center\" width=\"450\">"
            ."<tr>"
            ."<td>"
            ."<table width=\"100%\" bgcolor=\"$bgcolor2\">"
            ."<tr>"
            ."<td valign=\"top\" width=\"45%\"><b>".translate("Original")."</b></td>"
            ."<td rowspan=\"10\" valign=\"top\" align=\"left\"><font class=\"tiny\"><br />".translate("Description").":<br />$origdescription</font></td>"
            ."</tr>"
            ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Title").": $origtitle</td></tr>"
            ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("URL").": <a href=\"$origurl\">$origurl</a></td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Category").": $origcidtitle</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Sub Category").": $origsidtitle</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Author's Name").": $origname</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Author's Email").": $origemail</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Filesize").": $origfilesize</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Version").": $origversion</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("HomePage").": <a href=\"$orighomepage\" target=\"new\">$orighomepage</a></td></tr>"
            ."</table>"
            ."</td>"
            ."</tr>"
            ."<tr>"
            ."<td>"
            ."<table width=\"100%\">"
            ."<tr>"
            ."<td valign=\"top\" width=\"45%\"><b>".translate("Proposed")."</b></td>"
            ."<td rowspan=\"10\" valign=\"top\" align=\"left\"><font class=\"tiny\"><br />".translate("Description").":<br />$description</font></td>"
            ."</tr>"
            ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Title").": $title</td></tr>"
            ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("URL").": <a href=\"$url\">$url</a></td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Category").": $cidtitle</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Sub Category").": $sidtitle</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Author's Name").": $name</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Author's Email").": $email</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Filesize").": $filesize</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("Version").": $version</td></tr>"
        ."<tr><td valign=\"top\" width=\"45%\"><font class=\"tiny\">".translate("HomePage").": <a href=\"$homepage\" target=\"new\">$homepage</a></td></tr>"
            ."</table>"
            ."</td>"
            ."</tr>"
            ."</table>"
            ."<table align=\"center\" width=\"450\">"
            ."<tr>";
        if ($modifysubmitteremail=="") {
        echo "<td align=\"left\"><font class=\"tiny\">".translate("Submitter").":  $modifysubmitter</font></td>";
    } else {
        echo "<td align=\"left\"><font class=\"tiny\">".translate("Submitter").":  <a href=\"mailto:$modifysubmitteremail\">$modifysubmitter</a></font></td>";
    }
        if ($owneremail=="") {
        echo "<td align=\"center\"><font class=\"tiny\">".translate("Owner").":  $owner</font></td>";
    } else {
        echo "<td align=\"center\"><font class=\"tiny\">".translate("Owner").": <a href=\"mailto:$owneremail\">$owner</a></font></td>";
    }
        echo "<td align=\"right\"><font class=\"tiny\">( <a href=\"admin.php?fct=download&op=DownloadsChangeModRequests&amp;requestid=$requestid\">".translate("Accept")."</a> / <a href=\"admin.php?fct=download&op=DownloadsChangeIgnoreRequests&amp;requestid=$requestid\">".translate("Ignore")."</a> )</font></td></tr></table><br /><br />";
    }
    if ($totalmodrequests == 0) {
    echo "<center>".translate("There aren't any modification requests right now")."<br /><br />"
        ."[ <a href=\"javascript:history.go(-1)\">".translate("Go Back")."</a> ]<br /><br /></center>";
    }
    echo "</td></tr></table>";
    CloseTable();
    include ("footer.php");
}

function DownloadsChangeModRequests($requestid) {
    global $mpnTables;
    $result = mysql_query("select requestid, lid, cid, sid, title, url, description, name, email, filesize, version, homepage from ".$mpnTables['downloads_modrequest']." where requestid=$requestid");
    while(list($requestid, $lid, $cid, $sid, $title, $url, $description, $name, $email, $filesize, $version, $homepage) = mysql_fetch_row($result)) {


        mysql_query("UPDATE ".$mpnTables['downloads_downloads']." SET cid=$cid, sid=$sid, title='$title', url='$url', description='$description', name='$name', email='$email', filesize='$filesize', version='$version', homepage='$homepage' WHERE lid = $lid");
    mysql_query("delete from ".$mpnTables['downloads_modrequest']." where requestid=$requestid");
    }

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=DownloadsListModRequests' );

}

function DownloadsChangeIgnoreRequests($requestid) {
    global $mpnTables;
    mysql_query("delete from ".$mpnTables['downloads_modrequest']." where requestid=$requestid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=DownloadsListModRequests' );
}

function DownloadsCleanVotes() {
    global $mpnTables;
    $totalvoteresult = mysql_query("select distinct ratinglid FROM ".$mpnTables['downloads_votedata']."");
    while(list($lid) = mysql_fetch_row($totalvoteresult)) {
    $voteresult = mysql_query("select rating, ratinguser, ratingcomments FROM ".$mpnTables['downloads_votedata']." WHERE ratinglid = $lid");
    $totalvotesDB = mysql_num_rows($voteresult);
    include ("voteinclude.php");
        mysql_query("UPDATE ".$mpnTables['downloads_downloads']." SET downloadratingsummary=$finalrating,totalvotes=$totalvotesDB,totalcomments=$truecomments WHERE lid = $lid");
    }

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=downloads' );

}

function DownloadsModDownloadS($lid, $title, $url, $description, $name, $email, $hits, $cat, $filesize, $Version, $homepage) {
    global $mpnTables;
    $cat = explode("-", $cat);
    if ($cat[1]=="") {
        $cat[1] = 0;
    }


    /*$title = stripslashes(FixQuotes($title));
    $url = stripslashes(FixQuotes($url));
    $description = stripslashes(FixQuotes($description));
    $name = stripslashes(FixQuotes($name));
    $email = stripslashes(FixQuotes($email));*/
    mysql_query("update ".$mpnTables['downloads_downloads']." set cid='$cat[0]', sid='$cat[1]', title='$title', url='$url', description='$description', name='$name', email='$email', hits='$hits', filesize='$filesize', version='$Version', homepage='$homepage' where lid=$lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=downloads' );
}

function DownloadsDelDownload($lid) {
    global $mpnTables;
    mysql_query("delete from ".$mpnTables['downloads_downloads']." where lid=$lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=downloads' );
}

function DownloadsModCat($cat) {
    global $mpnTables;
    include ("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"title\"><b>".translate("Web Downloads Administration")."</b></font></center>";
    CloseTable();
    echo "<br />";
    $cat = explode("-", $cat);
    if ($cat[1]=="") {
        $cat[1] = 0;
    }
    OpenTable();
    echo "<center><font class=\"option\"><b>".translate("Modify a Category")."</b></font></center><br /><br />";
    if ($cat[1]==0) {
    $result = mysql_query("select title, cdescription from ".$mpnTables['downloads_categories']." where cid=$cat[0]");
    list($title,$cdescription) = mysql_fetch_row($result);

    $cdescription = stripslashes($cdescription);
    $title = stripslashes($title);

    echo "<form action=\"admin.php?fct=download\" method=\"post\">"
		."<table border=0>"
        ."<tr><td>".translate("Name").":</td><td><input type=\"text\" name=\"title\" value=\"$title\" size=\"51\" maxlength=\"50\"></td></tr>\n"
        ."<tr><td valign='top'>".translate("Description").":</td><td><textarea name=\"cdescription\" cols=\"60\" rows=\"10\">$cdescription</textarea></td></tr>\n"
		."</table>\n<br />\n"
        ."<input type=\"hidden\" name=\"sub\" value=\"0\">"
        ."<input type=\"hidden\" name=\"cid\" value=\"$cat[0]\">"
        ."<input type=\"hidden\" name=\"op\" value=\"DownloadsModCatS\">";

        // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='title|cdescription' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

        // End Sanitizer

        echo "<table border=\"0\"><tr><td>"
        ."<input class=\"button\" type=\"submit\" value=\"".translate("Save Changes")."\"></form></td><td>"
        ."<form action=\"admin.php?fct=download\" method=\"post\">"
        ."<input type=\"hidden\" name=\"sub\" value=\"0\">"
        ."<input type=\"hidden\" name=\"cid\" value=\"$cat[0]\">"
        ."<input type=\"hidden\" name=\"op\" value=\"DownloadsDelCat\">"
        ."<input class=\"button\" type=\"submit\" value=\"".translate("Delete")."\"></form></td></tr></table>";
    } else {
    $result = mysql_query("select title from ".$mpnTables['downloads_categories']." where cid=$cat[0]");
    list($ctitle) = mysql_fetch_row($result);
    $ctitle = stripslashes($ctitle);

    $result2 = mysql_query("select title from ".$mpnTables['downloads_subcategories']." where sid=$cat[1]");
    list($stitle) = mysql_fetch_row($result2);

    $stitle = stripslashes($stitle);

    echo "<form action=\"admin.php?fct=download\" method=\"post\">"
        ."".translate("Category").": $ctitle<br />"
        ."".translate("Sub Category").": <input type=\"text\" name=\"title\" value=\"$stitle\" size=\"51\" maxlength=\"50\"><br />"
        ."<input type=\"hidden\" name=\"sub\" value=\"1\">"
        ."<input type=\"hidden\" name=\"cid\" value=\"$cat[0]\">"
        ."<input type=\"hidden\" name=\"sid\" value=\"$cat[1]\">"
        ."<input type=\"hidden\" name=\"op\" value=\"DownloadsModCatS\">";

        // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='title' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

        // End Sanitizer


        echo "<table border=\"0\"><tr><td>"
        ."<input class=\"button\" type=\"submit\" value=\"".translate("Save Changes")."\"></form></td><td>"
        ."<form action=\"admin.php?fct=download\" method=\"post\">"
        ."<input type=\"hidden\" name=\"sub\" value=\"1\">"
        ."<input type=\"hidden\" name=\"cid\" value=\"$cat[0]\">"
        ."<input type=\"hidden\" name=\"sid\" value=\"$cat[1]\">"
        ."<input type=\"hidden\" name=\"op\" value=\"DownloadsDelCat\">"
        ."<input class=\"button\" type=\"submit\" value=\"".translate("Delete")."\"></form></td></tr></table>";
    }
    CloseTable();
    include("footer.php");
}

function DownloadsModCatS($cid, $sid, $sub, $title, $cdescription) {
    global $mpnTables;
    if ($sub==0) {
    mysql_query("update ".$mpnTables['downloads_categories']." set title='$title', cdescription='$cdescription' where cid=$cid");
    } else {
    mysql_query("update ".$mpnTables['downloads_subcategories']." set title='$title' where sid=$sid");
    }

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=downloads' );
}

function DownloadsDelCat($cid, $sid, $sub, $ok=0) {
    global $mpnTables;
    if($ok==1) {
    if ($sub>0) {
            mysql_query("delete from ".$mpnTables['downloads_subcategories']." where sid=$sid");
        mysql_query("delete from ".$mpnTables['downloads_downloads']." where sid=$sid");
    } else {
        mysql_query("delete from ".$mpnTables['downloads_categories']." where cid=$cid");
        mysql_query("delete from ".$mpnTables['downloads_subcategories']." where cid=$cid");
        mysql_query("delete from ".$mpnTables['downloads_downloads']." where cid=$cid AND sid=0");
    }

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=downloads' );

    } else {
    include("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<br /><center><font class=\"option\">";
    echo "<b>".translate("WARNING: Are you sure you want to delete this Category and ALL its Downloads!")."</b><br /><br />";
    }
    echo "[ <a href=\"admin.php?fct=download&op=DownloadsDelCat&amp;cid=$cid&amp;sid=$sid&amp;sub=$sub&amp;ok=1\">".translate("Yes")."</a> | <a href=\"admin.php?fct=download&op=downloads\">".translate("No")."</a> ]<br /><br />";
    CloseTable();
    include("footer.php");
}

function DownloadsDelNew($lid) {
    global $mpnTables;
    mysql_query("delete from ".$mpnTables['downloads_newdownload']." where lid=$lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=downloads' );
}

function DownloadsAddCat($title, $cdescription) {
    global $mpnTables;
    $result = mysql_query("select cid from ".$mpnTables['downloads_categories']." where title='$title'");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    include("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<br /><center><font class=\"option\">"
        ."<b>".translate("ERROR: The Category")." $title ".translate("already exist!")."</b><br /><br />"
        ."[ <a href=\"javascript:history.go(-1)\">".translate("Go Back")."</a> ]<br /><br />";
    CloseTable();
    include("footer.php");
    } else {
    mysql_query("insert into ".$mpnTables['downloads_categories']." values (NULL, '$title', '$cdescription')");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=downloads' );

    }
}

function DownloadsAddSubCat($cid, $title) {
    global $mpnTables;
    $result = mysql_query("select cid from ".$mpnTables['downloads_subcategories']." where title='$title' AND cid='$cid'");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    include("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<br /><center>";
    echo "<font class=\"option\">"
        ."<b>".translate("ERROR: The Sub-Category")." $title ".translate("already exist!")."</b><br /><br />"
        ."[ <a href=\"javascript:history.go(-1)\">".translate("Go Back")."</a> ]<br /><br />";
    include("footer.php");
    } else {
    mysql_query("insert into ".$mpnTables['downloads_subcategories']." values (NULL, '$cid', '$title')");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=download&op=downloads' );

    }
}

function DownloadsAddEditorial($downloadid, $editorialtitle, $editorialtext) {
    global $aid, $mpnTables;
    //$editorialtext = stripslashes(FixQuotes($editorialtext));
    mysql_query("insert into ".$mpnTables['downloads_editorials']." values ($downloadid, '$aid', now(), '$editorialtext', '$editorialtitle')");
    include("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<center><br />"
    ."<font class=option>"
    ."".translate("Editorial added to the Database")."<br /><br />"
    ."[ <a href=\"admin.php?fct=download&op=downloads\">".translate("Web Downloads Administration")."</a> ]<br /><br />";
    echo "$downloadid  $adminid, $editorialtitle, $editorialtext";
    CloseTable();
    include("footer.php");
}

function DownloadsModEditorial($downloadid, $editorialtitle, $editorialtext) {
    global $mpnTables;
    //$editorialtext = stripslashes(FixQuotes($editorialtext));
    mysql_query("update ".$mpnTables['downloads_editorials']." set editorialtext='$editorialtext', editorialtitle='$editorialtitle' where downloadid=$downloadid");
    include("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<br /><center>"
    ."<font class=\"option\">"
    ."".translate("Editorial Modified")."<br /><br />"
    ."[ <a href=\"admin.php?fct=download&op=downloads\">".translate("Web Downloads Administration")."</a> ]<br /><br />";
    CloseTable();
    include("footer.php");
}

function DownloadsDelEditorial($downloadid) {
    global $mpnTables;
    mysql_query("delete from ".$mpnTables['downloads_editorials']." where downloadid=$downloadid");
    include("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<br /><center>"
    ."<font class=\"option\">"
    ."".translate("Editorial removed from the Database")."<br /><br />"
    ."[ <a href=\"admin.php?fct=download&op=downloads\">".translate("Web Downloads Administration")."</a> ]<br /><br />";
    CloseTable();
    include("footer.php");
}

function DownloadsDownloadCheck() {
    global $mpnTables;
    include ("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"title\"><b>".translate("Web Downloads Administration")."</b></font></center>";
    CloseTable();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"option\"><b>".translate("Download Validation")."</b></font></center><br />"
    ."<table width=\"100%\" align=\"center\"><tr><td colspan=\"2\" align=\"center\">"
    ."<a href=\"admin.php?fct=download&op=DownloadsValidate&amp;cid=0&amp;sid=0\">".translate("Check all downloads")."</a><br /><br /></td></tr>"
    ."<tr><td valign=\"top\"><center><b>".translate("Check Categories")."</b><br />".translate("(include Sub-Categories)")."<br /><br /><font class=\"tiny\">";
    $result = mysql_query("select cid, title from ".$mpnTables['downloads_categories']." order by title");
    while(list($cid, $title) = mysql_fetch_row($result)) {
        $transfertitle = str_replace (" ", "_", stripslashes( $title ) );
        echo "<a href=\"admin.php?fct=download&op=DownloadsValidate&amp;cid=$cid&amp;sid=0\">$title</a><br />";
    }
    echo "</font></center></td>";
    echo "<td valign=\"top\"><center><b>".translate("Check Sub-Categories")."</b><br /><br /><br /><font class=\"tiny\">";
    $result = mysql_query("select sid, cid, title from ".$mpnTables['downloads_subcategories']." order by title");
    while(list($sid, $cid, $title) = mysql_fetch_row($result)) {
        $transfertitle = str_replace (" ", "_", stripslashes( $title ));
        $result2 = mysql_query("select title from ".$mpnTables['downloads_categories']." where cid = $cid");
        while(list($ctitle) = mysql_fetch_row($result2)) {
        echo "<a href=\"admin.php?fct=download&op=DownloadsValidate&amp;cid=0&amp;sid=$sid\">$ctitle</a>";
    }
    echo " / <a href=\"admin.php?fct=download&op=DownloadsValidate&amp;cid=0&amp;sid=$sid\">$title</a><br />";
    }
    echo "</font></center></td></tr></table>";
    CloseTable();
    include ("footer.php");
}

function DownloadsValidate($cid, $sid)
{
    global $bgcolor2, $mpnTables;

    include ("header.php");

    $snoopy = new Snoopy;

    admin_menu();
    echo "<br />";

    echo "<h1>" . translate ( 'Web Downloads Administration' ) . "</h1>\n";
    echo "<br />";

    OpenTable();

    echo "<h2>" . translate ( 'Validating Download Links' ) . "</h2>\n";

    /* Check ALL Downloads */



    if ($cid==0 && $sid==0)
    {
        echo "<center><b>".translate("Check all downloads")."</b><br />".translate("please be patient")."</center><br /><br />";

        $result = mysql_query("select lid, title, url, name, email, submitter from ".$mpnTables['downloads_downloads']." order by title");
    }

    /* Check Categories & Subcategories */

    if ($cid!=0 && $sid==0)
    {
        $ttitle = getTitle( $cid, 'cid', translate( 'Category' ) );
        $transfertitle = str_replace ("_", "", $ttitle);

       echo "<center><b>$transfertitle</b><br />".translate("(please be patient)")."</center><br /><br />";
        $result = mysql_query("select lid, title, url, name, email, submitter from ".$mpnTables['downloads_downloads']." where cid=$cid order by title");
    }

    /* Check Only Subcategory */

    if ($cid==0 && $sid!=0)
    {
        $ttitle = getTitle( $sid, 'sid', translate( 'Sub-Category' ) );
        $transfertitle = str_replace ("_", "", $ttitle);

        echo "<center><b>$transfertitle</b><br />".translate("(please be patient)")."</center><br /><br />";
        $result = mysql_query("select lid, title, url, name, email, submitter from ".$mpnTables['downloads_downloads']." where sid=$sid order by title");
    }

    echo "<table width=100% border=0>";

    echo "<tr><td bgcolor=\"$bgcolor2\" align=\"center\"><b>".translate("Status")."</b></td><td bgcolor=\"$bgcolor2\" width=\"100%\"><b>".translate("Download Title")."</b></td><td bgcolor=\"$bgcolor2\" align=\"center\"><b>".translate("Functions")."</b></td></tr>";

    while(list($lid, $title, $url, $name, $email, $submitter) = mysql_fetch_row($result))
    {
        // Kiril: Start New Sanitizer

        $sanity_ary = compact( 'title', 'url', 'name', 'email', 'submitter' );
        $_SERVER['SAN'] -> slashIT( $sanity_ary );
        extract( $sanity_ary );
        unset( $sanity_ary );

        // End New Sanitizer

        $fp = (bool)FALSE;

        if ( (bool)FALSE !== $snoopy -> fetch( $url ) )
        {
            $fp = (bool)TRUE;
        }


        if ( ! $fp )
        {
            echo "<tr><td align=\"center\"><b>&nbsp;&nbsp;".translate("Failed")."&nbsp;&nbsp;</b></td>"
            ."<td>&nbsp;&nbsp;<a href=\"$url\" target=\"new\">$title</a>&nbsp;&nbsp;</td>"
            ."<td align=\"center\"><font class=\"content\">&nbsp;&nbsp;[ <a href=\"admin.php?fct=download&op=DownloadsModDownload&amp;lid=$lid\">".translate("Edit")."</a> | <a href=\"admin.php?fct=download&op=DownloadsDelDownload&amp;lid=$lid\">".translate("Delete")."</a> ]&nbsp;&nbsp;</font>"
            ."</td></tr>";
        }
        else
        {
            echo "<tr><td align=\"center\">&nbsp;&nbsp;".translate("OK")."&nbsp;&nbsp;</td>"
            ."<td>&nbsp;&nbsp;<a href=\"$url\" target=\"new\">$title</a>&nbsp;&nbsp;</td>"
            ."<td align=\"center\"><font class=\"content\">&nbsp;&nbsp;".translate("None")."&nbsp;&nbsp;</font>"
            ."</td></tr>";
        }
    }

    echo "</table>";

    CloseTable();

    include ("footer.php");
}

function DownloadsAddDownload($new, $lid, $title, $url, $cat, $description, $name, $email, $submitter, $filesize, $Version, $homepage, $hits) {
    global $mpnTables;
    $result = mysql_query("select url from ".$mpnTables['downloads_downloads']." where url='$url'");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    include("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"title\"><b>".translate("Web Downloads Administration")."</b></font></center>";
    CloseTable();
    echo "<br />";
    OpenTable();
    echo "<br /><center>"
        ."<font class=\"option\">"
        ."<b>".translate("ERROR: This URL is already listed in the Database!")."</b><br /><br />"
        ."[ <a href=\"javascript:history.go(-1)\">".translate("Go Back")."</a> ]<br /><br />";
    CloseTable();
    include("footer.php");
    } else {

    // Check For Empty

    $check_ary = array( $_POST['title'], $_POST['url'], $_POST['description'], $_POST['email'] );

    $verify_check_ary = $_SERVER['SAN'] -> verifyContent( $check_ary, 3 );

    if ( in_array( (bool)FALSE, $verify_check_ary ) )
    {
        goBack( translate( 'You Failed To Include Required Information' ) );
        exit;
    }

    // Check URL

    if ( ! $_SERVER['SAN'] -> verifyContent( $_POST['url'], 1 ) )
    {
        goBack( translate( 'Invalid URL' ) );
        exit;
    }

    // Check Email

    if ( ! $_SERVER['SAN'] -> verifyContent( $_POST['email'], 2 ) )
    {
        goBack( translate( 'Invalid Email' ) );
        exit;
    }

    // Check Num Only

    if ( ! $_SERVER['SAN'] -> verifyContent( $_POST['filesize'], 5 ) )
    {
        goBack( translate( 'File Size Can Only Contain Numbers' ) );
        exit;
    }

    unset( $check_ary, $verify_check_ary );


/* Check if Title exist
    if ($title=="") {
    include("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"title\"><b>".translate("Web Downloads Administration")."</b></font></center>";
    CloseTable();
    echo "<br />";
    OpenTable();
    echo "<br /><center>"
        ."<font class=\"option\">"
        ."<b>".translate("ERROR: You need to type a TITLE for your URL!")."</b><br /><br />"
        ."[ <a href=\"javascript:history.go(-1)\">".translate("Go Back")."</a> ]<br /><br />";
    CloseTable();
    include("footer.php");
    }
/* Check if URL exist
    if ($url=="") {
    include("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"title\"><b>".translate("Web Downloads Administration")."</b></font></center>";
    CloseTable();
    echo "<br />";
    OpenTable();
    echo "<br /><center>"
        ."<font class=\"option\">"
        ."<b>".translate("ERROR: You need to type a URL for your URL!")."</b><br /><br />"
        ."[ <a href=\"javascript:history.go(-1)\">".translate("Go Back")."</a> ]<br /><br />";
    CloseTable();
    include("footer.php");
    }
// Check if Description exist
    if ($description=="") {
    include("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"title\"><b>".translate("Web Downloads Administration")."</b></font></center>";
    CloseTable();
    echo "<br />";
    OpenTable();
    echo "<br /><center>"
        ."<font class=\"option\">"
        ."<b>".translate("ERROR: You need to type a DESCRIPTION for your URL!")."</b><br /><br />"
        ."[ <a href=\"javascript:history.go(-1)\">".translate("Go Back")."</a> ]<br /><br />";
    CloseTable();
    include("footer.php");
    }
    $title = stripslashes(FixQuotes($title));
    $url = stripslashes(FixQuotes($url));
    $description = stripslashes(FixQuotes($description));
    $name = stripslashes(FixQuotes($name));
    $email = stripslashes(FixQuotes($email));*/

    $cat = explode("-", $cat);
    if ($cat[1]=="") {
    $cat[1] = 0;
    }

    mysql_query("insert into ".$mpnTables['downloads_downloads']." values (NULL, '$cat[0]', '$cat[1]', '$title', '$url', '$description', now(), '$name', '$email', '$hits','$submitter',0,0,0, '$filesize', '$Version', '$homepage')");
    global $nukeurl, $sitename;
    include("header.php");
    admin_menu();
    echo "<br />";
    OpenTable();
    echo "<br /><center>";
    echo "<font class=\"option\">";
    echo "".translate("New Download added to the Database")."<br /><br />";
    echo "[ <a href=\"admin.php?fct=download&op=downloads\">".translate("Web Downloads Administration")."</a> ]</center><br /><br />";
    CloseTable();
    if ($new==1) {
    mysql_query("delete from ".$mpnTables['downloads_newdownload']." where lid=$lid");
    }
    include("footer.php");
    }
}

function getTitle( $id, $cond_field, $prefix )
{
    global $mpnTables;

    if ( $cond_field == 'sid' )
    {
        $table = 'downloads_subcategories';
    }
    else
    {
        $table = 'downloads_categories';
    }

    $sql = "SELECT title FROM " . $mpnTables[ $table ] . " WHERE $cond_field = '$id'";

    $result = mysql_query( $sql );

    if ( ! ( $tmp = mysql_fetch_row( $result ) ) )
    {
        $title = $prefix;
    }
    else
    {
        $title = $prefix . ': <i>' . $tmp[0] . '</i>';
    }

    mysql_free_result( $result );

    return stripslashes( $title );
}

?>
