<?php

require_once './mainfile.php';

/* 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.15.2.6 2004/08/01 17:04:16 kirilt Exp $




/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* Based on Journey Links Hack                                          */
/* Copyright (c) 2000 by James Knickelbein                              */
/* Journey Milwaukee (http://www.journeymilwaukee.com)                  */
/*                                                                      */
/* 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.       */
/************************************************************************/


require_once("./admin/download/config.inc.php");

function menu()
{
    global $mpnTables, $user_adddownload, $sitename;

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

    echo "<div class='center'>\n";

        echo "[  <a href=\"download.php\">".translate("Main")."</a>\n"
            ." | <a href=\"download.php?op=NewDownloads\">".translate("New")."</a>\n"
            ." | <a href=\"download.php?op=MostPopular\">".translate("Popular")."</a>\n"
            ." | <a href=\"download.php?op=TopRated\">".translate("Top Rated")."</a>\n";

        if ( $user_adddownload == 1 )
        {
            echo " | <a href=\"download.php?op=AddDownload\">".translate("Add Download")."</a>\n";
        }

        echo " ]\n";

        echo "<br /><br />\n";

        echo "<form action=\"download.php?op=search\" method=\"post\">\n"
            ."<input type=\"text\" size=\"25\" name=\"query\"> <input class=\"button\" type=\"submit\" value=\"".translate("Search")."\">";

        // Kiril: New Sanitizer

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

        // End Sanitizer


        echo "</form>\n";

    echo "</div>\n";
}


function downloadinfomenu($lid)
{
    echo "<br />[ "
    ."<a href=\"download.php?op=viewdownloadcomments&amp;lid=$lid\">".translate("Download Comments")."</a>"
    ." | <a href=\"download.php?op=viewdownloaddetails&amp;lid=$lid\">".translate("Additional Details")."</a>"
    ." | <a href=\"download.php?op=viewdownloadeditorial&amp;lid=$lid\">".translate("Editor Review")."</a>"
    ." | <a href=\"download.php?op=modifydownloadrequest&amp;lid=$lid\">".translate("Modify")."</a>"
    ." | <a href=\"download.php?op=brokendownload&amp;lid=$lid\">".translate("Report Broken Link")."</a> ]</font>";
}

function index()
{
    global $mpnTables;
    include("header.php");

    menu();

    echo "<h2>" . translate ( 'Downloads Main Categories' ) . "</h2>\n";
    echo "<br />";

    OpenTable();

    echo "<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\" align=\"center\"><tr>";
    $result = mysql_query("select cid, title, cdescription from ".$mpnTables['downloads_categories']." order by title");
    $count = 0;
    while(list($cid, $title, $cdescription) = mysql_fetch_row($result))
    {
        // Kiril: Start New Sanitizer

        $sanity_ary = compact( 'title', 'cdescription' );
        $_SERVER['SAN'] -> slashIT( $sanity_ary );
        extract( $sanity_ary );
        unset( $sanity_ary );

        // End New Sanitizer

    $cresult = mysql_query("select * from ".$mpnTables['downloads_downloads']." where cid=$cid");
    $cnumrows = mysql_num_rows($cresult);
    echo "<td><font class=\"option\"><strong><big>&middot;</big></strong> <a href=\"download.php?op=viewdownload&amp;cid=$cid\"><b>$title</b></a> ($cnumrows)</font>";
    categorynewdownloadgraphic($cid);

    if ($cdescription) {
        echo "<font class=\"content\">$cdescription</font><br />";
    } else {
        echo "<br />";
    }
    $result2 = mysql_query("select sid, title from ".$mpnTables['downloads_subcategories']." where cid=$cid order by title limit 0,3");
    $space = 0;
    while(list($sid, $stitle) = mysql_fetch_row($result2))
    {
        $stitle = stripslashes( $stitle );

            if ($space>0) {
        echo ",&nbsp;";
        }
        echo "<font class=\"content\"><a href=\"download.php?op=viewsdownload&amp;sid=$sid\">$stitle</a></font>";
        $space++;
    }

    if ($count<1) {
        echo "</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
        $dum = 1;
    }
    $count++;
    if ($count==2) {
        echo "</td></tr><tr>";
        $count = 0;
        $dum = 0;
    }
    }

    if (isset($dum) && $dum == 1) {
    echo "</tr></table>";
    } elseif (isset($dum) && $dum == 0) {
    echo "<td></td></tr></table>";
    }
    else
    {
        echo '<td></td></tr></table>';
    }

    $result = mysql_query("select * from ".$mpnTables['downloads_downloads']."");
    $numrows = mysql_num_rows($result);
    $result = mysql_query("select * from ".$mpnTables['downloads_categories']."");
    $catnum1 = mysql_num_rows($result);
    $result = mysql_query("select * from ".$mpnTables['downloads_subcategories']."");
    $catnum2 = mysql_num_rows($result);
    $catnum = $catnum1+$catnum2;
    echo "<br /><br /><center><font class=\"content\">".translate("There are")." <b>$numrows</b> ".translate("downloads")." ".translate("and")." <b>$catnum</b> ".translate("Categories")." ".translate("in our database.")."</font></center>";
    CloseTable();
    include("footer.php");
}

function AddDownload()
{
    global $mpnTables, $user, $downloads_anonadddownloadlock, $userinfo;
    include("header.php");

    menu();

    echo "<h1>" . translate ( 'Add a New Download' ) . "</h1>\n";
    echo "<br />";

    OpenTable();

    if (_MPN_USER || $downloads_anonadddownloadlock != 1) {
        echo "<b>".translate("Instructions").":</b><br />"
        ."<strong><big>&middot;</big></strong> ".translate("Submit a unique download only once.")."<br />"
        ."<strong><big>&middot;</big></strong> ".translate("All downloads are posted pending verification.")."<br />"
        ."<strong><big>&middot;</big></strong> ".translate("Username and IP are recorded, so please don't abuse the system.")."<br />"
        ."<form method=\"post\" action=\"download.php?op=Add\">"
		."<table border=1>"
        ."<tr><td class=w30>".translate("Program Name").":</td><td><input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\"></td></tr>"
        ."<tr><td>".translate("File Link").":</td><td><input type=\"text\" name=\"url\" size=\"60\" maxlength=\"100\" value=\"http://\"></td></tr>";
        $result = mysql_query("select cid, title from ".$mpnTables['downloads_categories']." order by title");
        echo "<tr><td>".translate("Category").":</td><td><select name=\"cat\">\n";
        while(list($cid, $title) = mysql_fetch_row($result))
        {
        echo "<option value=\"$cid\">$title</option>\n";
        $result2 = mysql_query("select sid, title from ".$mpnTables['downloads_subcategories']." where cid=$cid order by title");
        while(list($sid, $stitle) = mysql_fetch_row($result2))
        {
            $title = stripslashes( $title );
            $stitle = stripslashes( $stitle );

            echo "<option value=\"$cid-$sid\">$title / $stitle</option>\n";
        }
        }
        echo "</select></td></tr>"
        ."<tr><td valign='top'>".translate("Description:<br />(255 characters max)")."</td><td><textarea name=\"description\" cols=\"60\" rows=\"8\"></textarea></td></tr>"
        ."<tr><td>".translate("Author's Name").":</td><td><input type=\"text\" name=\"auth_name\" size=\"60\" value=\"".$userinfo[uname]."\" maxlength=\"60\"></td></tr>"
        ."<tr><td>".translate("Author's Email").":</td><td><input type=\"text\" name=\"email\" size=\"60\" value=\"".$userinfo[email]."\" maxlength=\"60\"></td></tr>"
        ."<tr><td>".translate("Filesize").":</td><td><input type=\"text\" name=\"filesize\" size=\"12\" maxlength=\"11\"> (".translate("in bytes").")</td></tr>"
        ."<tr><td>".translate("Version").":</td><td><input type=\"text\" name=\"Version\" size=\"11\" maxlength=\"10\"></td></tr>"
        ."<tr><td>".translate("HomePage").":</td><td><input type=\"text\" name=\"homepage\" size=\"60\" maxlength=\"200\" value=\"http://\"></td></tr>"
		."</table>\n<br />\n"
        ."<input type=\"hidden\" name=\"op\" value=\"Add\">";

        // Kiril: New Sanitizer

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

        // End Sanitizer

        echo "<input class=\"button\" type=\"submit\" value=\"".translate("Add this File")."\"> [ <a href=\"javascript:history.go(-1)\">".translate("Go Back")."</a> ]<br /><br />"
            ."</form>";
    } else {
        echo "<center>".translate("You are not a registered user or you have not logged in.")."<br />"
        ."".translate("If you were registered you could add downloads on this website.")."<br /><br />"
            ."".translate("Becoming a registered user is a quick and easy process.")."<br />"
            ."".translate("Why do we require registration for access to certain features?")."<br />"
            ."".translate("So we can offer you only the highest quality content, ")."<br />"
            ."".translate("each item is individually reviewed and approved by our staff.")."<br />"
            ."".translate("We hope to offer you only valuable information.")."<br /><br />"
            ."<a href=\"user.php\">".translate("Register for an Account")."</a>";
    }
    CloseTable();
    include("footer.php");
}

function Add($title, $url, $auth_name, $cat, $description, $email, $filesize, $Version, $homepage)
{
    global $mpnTables, $user;

    $result = mysql_query("select url from ".$mpnTables['downloads_downloads']." where url='$url'");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    include("header.php");
    menu();
    echo "<br />";
    OpenTable();
    echo "<center><b>".translate("ERROR: This URL is already listed in the Database!")."</b><br /><br />"
        ."[ <a href=\"javascript:history.go(-1)\">".translate("Go Back")."</a> ]";
    CloseTable();
    include("footer.php");
    } else {
    if ( _MPN_USER )
    {
        $cookie = cookiedecode($user);
        $submitter = $cookie[1];
    }

    // 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 );

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

    mysql_query("insert into ".$mpnTables['downloads_newdownload']." values (NULL, '$cat[0]', '$cat[1]', '$title', '$url', '$description', '$auth_name', '$email', '$submitter', '$filesize', '$Version', '$homepage')");

    include("header.php");
    menu();
    echo "<br />";

    echo "<h2>" . translate ( 'We received your Download submission. Thanks!' ) . "</h2>\n";

    include("footer.php");
    }
}

function NewDownloads($newdownloadshowdays) {
    global $mpnTables;
    include("header.php");
    menu();

    echo "<h2>" . translate ( 'New Downloads' ) . "</h2>\n";
    echo "<br />";

    $counter = 0;
    $allmonthdownloads = $allweekdownloads = 0;
    while ($counter <= 7-1){
    $newdownloaddayRaw = (time()-(86400 * $counter));
    $newdownloadday = date("d-M-Y", $newdownloaddayRaw);
    $newdownloadView = date("F d, Y", $newdownloaddayRaw);
    $newdownloadDB = Date("Y-m-d", $newdownloaddayRaw);
    $result = mysql_query("select * FROM ".$mpnTables['downloads_downloads']." WHERE date LIKE '%$newdownloadDB%'");
    $totaldownloads = mysql_num_rows($result);
    $counter++;
    $allweekdownloads = $allweekdownloads + $totaldownloads;
    }
    $counter = 0;
    while ($counter <=30-1){
        $newdownloaddayRaw = (time()-(86400 * $counter));
        $newdownloadDB = Date("Y-m-d", $newdownloaddayRaw);
        $result = mysql_query("select * FROM ".$mpnTables['downloads_downloads']." WHERE date LIKE '%$newdownloadDB%'");
        $totaldownloads = mysql_num_rows($result);
        $allmonthdownloads = $allmonthdownloads + $totaldownloads;
        $counter++;
    }
    echo "<center><b>".translate("Total New Downloads").":</b> ".translate("Last Week")." - $allweekdownloads \ ".translate("Last 30 days")." - $allmonthdownloads<br />"
    ."".translate("Show").": <a href=\"download.php?op=NewDownloads&amp;newdownloadshowdays=7\">".translate("1 Week")."</a> - <a href=\"download.php?op=NewDownloads&amp;newdownloadshowdays=14\">".translate("2 weeks")."</a> - <a href=\"download.php?op=NewDownloads&amp;newdownloadshowdays=30\">".translate("30 Days")."</a>"
    ."</center><br />";

    OpenTable();

    /* List Last VARIABLE Days of Downloads */
    if (!isset($newdownloadshowdays)) {
    $newdownloadshowdays = 7;
    }
    echo "<br /><center><b>".translate("Total new downloads for last")." $newdownloadshowdays ".translate("Days").":</b><br /><br />";
    $counter = 0;
    $allweekdownloads = 0;
    while ($counter <= $newdownloadshowdays-1) {
    $newdownloaddayRaw = (time()-(86400 * $counter));
    $newdownloadday = date("d-M-Y", $newdownloaddayRaw);
    $newdownloadView = date("F d, Y", $newdownloaddayRaw);
    $newdownloadDB = Date("Y-m-d", $newdownloaddayRaw);
    $result = mysql_query("select * FROM ".$mpnTables['downloads_downloads']." WHERE date LIKE '%$newdownloadDB%'");
    $totaldownloads = mysql_num_rows($result);
    $counter++;
    $allweekdownloads = $allweekdownloads + $totaldownloads;
    echo "<strong><big>&middot;</big></strong> <a href=\"download.php?op=NewDownloadsDate&amp;selectdate=$newdownloaddayRaw\">$newdownloadView</a>&nbsp($totaldownloads)<br />";
    }
    $counter = 0;
    $allmonthdownloads = 0;
    echo "</center>";
    CloseTable();
    include("footer.php");
}

function NewDownloadsDate($selectdate) {
    global $mpnTables;
    $dateDB = (date("d-M-Y", $selectdate));
    $dateView = (date("F d, Y", $selectdate));
    include("header.php");
    menu();
    echo "<br />";
    OpenTable();
    $newdownloadDB = Date("Y-m-d", $selectdate);
    $result = mysql_query("select * FROM ".$mpnTables['downloads_downloads']." WHERE date LIKE '%$newdownloadDB%'");
    $totaldownloads = mysql_num_rows($result);
    echo "<font class=\"option\"><b>$dateView - $totaldownloads ".translate("New Downloads")."</b></font>"
    ."<table width=\"100%\" cellspacing=\"0\" cellpadding=\"10\" border=\"0\"><tr><td><font class=\"content\">";
    $result = mysql_query("select lid, cid, sid, title, description, date, hits, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage from ".$mpnTables['downloads_downloads']." where date LIKE '%$newdownloadDB%' order by title ASC");
    while(list($lid, $cid, $sid, $title, $description, $time, $hits, $downloadratingsummary, $totalvotes, $totalcomments, $filesize, $version, $homepage) = mysql_fetch_row($result))
    {
    $downloadratingsummary = number_format($downloadratingsummary, $mainvotedecimal);

    // Kiril: Start New Sanitizer

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

    // End New Sanitizer


    //$title = stripslashes($title); $description = stripslashes($description);
        global $mpnTables;
    if (_MPN_ADMIN) {
        echo "<a href=\"admin.php?fct=download&op=DownloadsModDownload&amp;lid=$lid\"><img src=\"images/download/lwin.gif\" border=\"0\" alt=\"".translate("Edit")."\"></a>&nbsp;&nbsp;";
    } else {
        echo "<img src=\"images/download/lwin.gif\" border=\"0\" alt=\"\">&nbsp;&nbsp;";
    }
    echo "<a href=\"download.php?op=getit&amp;lid=$lid\">$title</a>";
    newdownloadgraphic($datetime, $time);
    popgraphic($hits);
    detecteditorial($lid, $transfertitle, 1);
    echo "<br /><b>".translate("Description").":</b> $description<br />";
    setlocale (LC_TIME, "$locale");
    /* INSERT code for *editor review* here */
    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("%d-%b-%Y", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    $datetime = ucfirst($datetime);
    echo "<b>".translate("Version").":</b> $version <b>".translate("Filesize").":</b> ".CoolSize($filesize)."<br />";
    echo "<b>".translate("Added on").":</b> <b>$datetime</b> <b>".translate("Downloads").":</b> $hits";
        $transfertitle = str_replace (" ", "_", $title);
        /* voting & comments stats */
        if ($totalvotes == 1) {
        $votestring = translate("Vote");
        } else {
        $votestring = translate("Votes");
    }
        if ($downloadratingsummary!="0" || $downloadratingsummary!="0.0") {
        echo " <b>".translate("Rating").":</b> $downloadratingsummary ($totalvotes $votestring)";
    }
        if ($homepage == "") {
        echo "<br />";
    } else {
        echo "<br /><a href=\"$homepage\" target=\"new\">".translate("HomePage")."</a> | ";
    }
    echo "<a href=\"download.php?op=ratedownload&amp;lid=$lid\">".translate("Rate Resource")."</a>";
        echo " | <a href=\"download.php?op=brokendownload&amp;lid=$lid\">".translate("Report Broken Link")."</a>";
    echo " | <a href=\"download.php?op=viewdownloaddetails&amp;lid=$lid\">".translate("Details")."</a>";

        if ($totalcomments != 0) {
        echo " | <a href=\"download.php?op=viewdownloadcomments&amp;lid=$lid\">".translate("Comments")." ($totalcomments)</a>";
    }
    $result2 = mysql_query("select title from ".$mpnTables['downloads_categories']." where cid=$cid");
    detecteditorial($lid, $transfertitle, 0);
    echo "<br />";
    list($ctitle) = mysql_fetch_row($result2);
    echo "<b>".translate("Category").":</b> $ctitle";
    $result3 = mysql_query("select title from ".$mpnTables['downloads_subcategories']." where sid=$sid");
    while(list($stitle) = mysql_fetch_row($result3)) {
        echo " / $stitle";
    }
    echo "<br /><br />";
    }
    echo "</font></td></tr></table>";
    CloseTable();
    include("footer.php");
}

function TopRated($ratenum, $ratetype) {
    global $mpnTables, $admin, $locale;
    include("header.php");
    include("admin/download/config.inc.php");
    menu();
    echo "<br />";

    if ($ratenum != "" && $ratetype != "") {
        $topdownloads = $ratenum;
        if ($ratetype == "percent") {
        $topdownloadspercentrigger = 1;
    }
    }
    if ($topdownloadspercentrigger == 1) {
        $topdownloadspercent = $topdownloads;
        $result = mysql_query("select * from ".$mpnTables['downloads_downloads']." where downloadratingsummary != 0");
        $totalrateddownloads = mysql_num_rows($result);
        $topdownloads = $topdownloads / 100;
        $topdownloads = $totalrateddownloads * $topdownloads;
        $topdownloads = round($topdownloads);
    }
    if ($topdownloadspercentrigger == 1)
    {

    echo "<h2>" . translate ( 'Best Rated Downloads - Top' ) . " $topdownloadspercent% (".translate("of")." $totalrateddownloads ".translate("total rated downloads").")</h2>\n";

    } else {

    echo "<h2>" . translate ( 'Best Rated Downloads - Top' ) . " $topdownloads</h2>\n";

    }
    echo "<center>".translate("Note:")." $downloadvotemin ".translate("minimum votes required")."<br /><br />"
    ."".translate("Show Top").":  [ <a href=\"download.php?op=TopRated&amp;ratenum=10&amp;ratetype=num\">10</a> - "
    ."<a href=\"download.php?op=TopRated&amp;ratenum=25&amp;ratetype=num\">25</a> - "
        ."<a href=\"download.php?op=TopRated&amp;ratenum=50&amp;ratetype=num\">50</a> | "
        ."<a href=\"download.php?op=TopRated&amp;ratenum=1&amp;ratetype=percent\">1%</a> - "
        ."<a href=\"download.php?op=TopRated&amp;ratenum=5&amp;ratetype=percent\">5%</a> - "
        ."<a href=\"download.php?op=TopRated&amp;ratenum=10&amp;ratetype=percent\">10%</a> ]</center><br /><br />";

    $result = mysql_query("select lid, cid, sid, title, description, date, hits, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage from ".$mpnTables['downloads_downloads']." where downloadratingsummary != 0 and totalvotes >= $downloadvotemin order by downloadratingsummary DESC limit 0,$topdownloads ");


    OpenTable();

    echo "<table summary=''><tr><td>";

    while(list($lid, $cid, $sid, $title, $description, $time, $hits, $downloadratingsummary, $totalvotes, $totalcomments, $filesize, $version, $homepage) = mysql_fetch_row($result))
    {

    $downloadratingsummary = number_format($downloadratingsummary, $mainvotedecimal);

    // Kiril: Start New Sanitizer

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

    // End New Sanitizer

        global $mpnTables;
    if (_MPN_ADMIN) {
        echo "<a href=\"admin.php?fct=download&op=DownloadsModDownload&amp;lid=$lid\"><img src=\"images/download/lwin.gif\" border=\"0\" alt=\"".translate("Edit")."\"></a>&nbsp;&nbsp;";
    } else {
        echo "<img src=\"images/download/lwin.gif\" border=\"0\" alt=\"\">&nbsp;&nbsp;";
    }
        echo "<a href=\"download.php?op=getit&amp;lid=$lid\">$title</a>";
    if (!isset($datetime))
    {
        $datetime = null;
    }

    newdownloadgraphic($datetime, $time);
    popgraphic($hits);
//    detecteditorial($lid, $transfertitle, 1);
    detecteditorial($lid, $title, 1);
    echo "<br />";
    echo "<b>".translate("Description").":</b> $description<br />";
    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("%d-%b-%Y", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    $datetime = ucfirst($datetime);
    echo "<b>".translate("Version").":</b> $version <b>".translate("Filesize").":</b> ".CoolSize($filesize)."<br />";
    echo "<b>".translate("Added on").":</b> $datetime <b>".translate("Downloads").":</b> $hits";
    $transfertitle = str_replace (" ", "_", $title);
    /* voting & comments stats */
        if ($totalvotes == 1) {
        $votestring = translate("Vote");
        } else {
        $votestring = translate("Votes");
    }
    if ($downloadratingsummary!="0" || $downloadratingsummary!="0.0") {
        echo " <b>".translate("Rating").":</b> <b>$downloadratingsummary</b> ($totalvotes $votestring)";
    }
        if ($homepage == "") {
        echo "<br />";
    } else {
        echo "<br /><a href=\"$homepage\" target=\"new\">".translate("HomePage")."</a> | ";
    }
    echo "<a href=\"download.php?op=ratedownload&amp;lid=$lid\">".translate("Rate Resource")."</a>";
    echo " | <a href=\"download.php?op=brokendownload&amp;lid=$lid\">".translate("Report Broken Link")."</a>";
    echo " | <a href=\"download.php?op=viewdownloaddetails&amp;lid=$lid\">".translate("Details")."</a>";
    if ($totalcomments != 0) {
        echo " | <a href=\"download.php?op=viewdownloadcomments&amp;lid=$lid\">".translate("Comments")." ($totalcomments)</a>";
    }
    detecteditorial($lid, $transfertitle, 0);
    echo "<br />";
    $result2 = mysql_query("select title from ".$mpnTables['downloads_categories']." where cid=$cid");
    list($ctitle) = mysql_fetch_row($result2);

    $ctitle = stripslashes($ctitle);

    echo "<b>".translate("Category").":</b> $ctitle";
    $result3 = mysql_query("select title from ".$mpnTables['downloads_subcategories']." where sid=$sid");
    while(list($stitle) = mysql_fetch_row($result3)) {
        $stitle = stripslashes($stitle);
        echo " / $stitle";
    }
    echo "<br /><br />";
    }
    echo "</font></td></tr></table>";
    CloseTable();
    include("footer.php");
}

function MostPopular($ratenum, $ratetype) {
    global $mpnTables, $admin, $locale;
    include("header.php");
    include("admin/download/config.inc.php");
    menu();
    echo "<br />";


    if ($ratenum != "" && $ratetype != "") {
        $mostpopdownloads = $ratenum;
        if ($ratetype == "percent") $mostpopdownloadspercentrigger = 1;
    }
    if ($mostpopdownloadspercentrigger == 1) {
        $topdownloadspercent = $mostpopdownloads;
        $result = mysql_query("select * from ".$mpnTables['downloads_downloads']."");
        $totalmostpopdownloads = mysql_num_rows($result);
        $mostpopdownloads = $mostpopdownloads / 100;
        $mostpopdownloads = $totalmostpopdownloads * $mostpopdownloads;
        $mostpopdownloads = round($mostpopdownloads);
    }
    if ($mostpopdownloadspercentrigger == 1) {
    echo "<h2>" . translate ( 'Most Popular - Top' ) . " $topdownloadspercent% (".translate("of all")." $totalmostpopdownloads ".translate("Downloads").")</h2>\n";
    } else {
    echo "<h2>" . translate ( 'Most Popular - Top' ) . " $mostpopdownloads</h2>\n";
    }
 echo "<div class='center'>\n";
    echo "".translate("Show Top").": [ <a href=\"download.php?op=MostPopular&amp;ratenum=10&amp;ratetype=num\">10</a> - "
    ."<a href=\"download.php?op=MostPopular&amp;ratenum=25&amp;ratetype=num\">25</a> - "
        ."<a href=\"download.php?op=MostPopular&amp;ratenum=50&amp;ratetype=num\">50</a> | "
        ."<a href=\"download.php?op=MostPopular&amp;ratenum=1&amp;ratetype=percent\">1%</a> - "
        ."<a href=\"download.php?op=MostPopular&amp;ratenum=5&amp;ratetype=percent\">5%</a> - "
        ."<a href=\"download.php?op=MostPopular&amp;ratenum=10&amp;ratetype=percent\">10%</a> ]<br /><br />";
echo "</div>\n";

    $result = mysql_query("select lid, cid, sid, title, description, date, hits, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage from ".$mpnTables['downloads_downloads']." order by hits DESC limit 0,$mostpopdownloads ");


    OpenTable();

     echo "<table summary=''><tr><td>";
    while(list($lid, $cid, $sid, $title, $description, $time, $hits, $downloadratingsummary, $totalvotes, $totalcomments, $filesize, $version, $homepage) = mysql_fetch_row($result))
    {
    $downloadratingsummary = number_format($downloadratingsummary, $mainvotedecimal);

    // Kiril: Start New Sanitizer

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

    // End New Sanitizer

/*    $title = stripslashes($title);
    $description = stripslashes($description);*/
        global $mpnTables;
    if (_MPN_ADMIN) {
        echo "<a href=\"admin.php?fct=download&op=DownloadsModDownload&amp;lid=$lid\"><img src=\"images/download/lwin.gif\" border=\"0\" alt=\"".translate("Edit")."\"></a>&nbsp;&nbsp;";
    } else {
        echo "<img src=\"images/download/lwin.gif\" border=\"0\" alt=\"\">&nbsp;&nbsp;";
    }
        echo "<font class=\"content\"><a href=\"download.php?op=getit&amp;lid=$lid\">$title</a>";
    if (!isset($datetime))
    {
        $datetime = null;
    }

    newdownloadgraphic($datetime, $time);
    popgraphic($hits);
//    detecteditorial($lid, $transfertitle, 1);
    detecteditorial($lid, $title, 1);
    echo "<br />";
    echo "<b>".translate("Description").":</b> $description<br />";
    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("%d-%b-%Y", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    $datetime = ucfirst($datetime);
    echo "<b>".translate("Version").":</b> $version <b>".translate("Filesize").":</b> ".CoolSize($filesize)."<br />";
    echo "<b>".translate("Added on").":</b> $datetime <b>".translate("Downloads").":</b> <b>$hits</b>";
    $transfertitle = str_replace (" ", "_", $title);
    /* voting & comments stats */
        if ($totalvotes == 1) {
        $votestring = translate("Vote");
        } else {
        $votestring = translate("Votes");
    }
    if ($downloadratingsummary!="0" || $downloadratingsummary!="0.0") {
        echo " <b>".translate("Rating").":</b> $downloadratingsummary ($totalvotes $votestring)";
    }
        if ($homepage == "") {
        echo "<br />";
    } else {
        echo "<br /><a href=\"$homepage\" target=\"new\">".translate("HomePage")."</a> | ";
    }
    echo "<a href=\"download.php?op=ratedownload&amp;lid=$lid\">".translate("Rate Resource")."</a>";
    echo " | <a href=\"download.php?op=brokendownload&amp;lid=$lid\">".translate("Report Broken Link")."</a>";
    echo " | <a href=\"download.php?op=viewdownloaddetails&amp;lid=$lid\">".translate("Details")."</a>";
    if ($totalcomments != 0) {
        echo " | <a href=\"download.php?op=viewdownloadcomments&amp;lid=$lid\">".translate("Comments")." ($totalcomments)</a>";
    }
    detecteditorial($lid, $transfertitle, 0);
    echo "<br />";
    $result2 = mysql_query("select title from ".$mpnTables['downloads_categories']." where cid=$cid");
    list($ctitle) = mysql_fetch_row($result2);
    $ctitle = stripslashes( $ctitle );
    echo "<b>".translate("Category").":</b> $ctitle";
    $result3=mysql_query("select title from ".$mpnTables['downloads_subcategories']." where sid=$sid");
    while(list($stitle) = mysql_fetch_row($result3)) {
        $stitle = stripslashes( $stitle );
        echo " / $stitle";
    }
    echo "<br /><br /></font>";
    }
    echo "</font></td></tr></table>";
    CloseTable();
    include("footer.php");
}

function viewdownload($cid, $min, $orderby, $show)
{
    global $mpnTables, $Perpage, $locale;
    include("header.php");
    if (!isset($min)) $min=0;
    if (!isset($max)) $max=$min+$Perpage;
    if(isset($orderby)) {
    $orderby = convertorderbyin($orderby);
    } else {
    $orderby = "title ASC";
    }
    if ($show!="") {
    $Perpage = $show;
    } else {
    $show=$Perpage;
    }
    menu();

    $result=mysql_query("select title from ".$mpnTables['downloads_categories']." where cid=$cid");
    list($title) = mysql_fetch_row($result);
    $title = stripslashes( $title );
    echo "<center><font class=\"option\"><b>".translate("Category").": $title</b></font></center><br />";
    $carrytitle = $title;
    $subresult=mysql_query("select sid, title from ".$mpnTables['downloads_subcategories']." where cid=$cid");
    $numrows = mysql_num_rows($subresult);
    if ($numrows != 0) {
    $scount = 0;
    echo "<center><font class=\"content\">".translate("Downloads also available in")." <i>$title</i> ".translate("sub categories").":</font></center><br />";

    echo "<br />";



        echo "<table align=\"center\" border=\"0\"><tr>";

        while(list($sid, $title) = mysql_fetch_row($subresult)) {
            $title = stripslashes( $title );
        $result2 = mysql_query("select * from ".$mpnTables['downloads_downloads']." where sid=$sid");
        $numrows = mysql_num_rows($result2);
            echo "<td><a href=\"download.php?op=viewsdownload&amp;sid=$sid\">$title</a> ($numrows)&nbsp;&nbsp;</td>";
            $scount++;
            if ($scount==4) {
                echo "</tr><tr>";
                $scount = 0;
            }
        }

        if ($scount != 0) {
        echo "</tr></table>";
    } else {
        echo "<td></td></tr></table>";
    }
        echo "<hr noshade size=\"1\">";
    }
    $orderbyTrans = convertorderbytrans($orderby);
    echo "<center><font class=\"content\">".translate("Sort Downloads by").": "
        ."".translate("Title")." (<a href=\"download.php?op=viewdownload&amp;cid=$cid&amp;orderby=titleA\">A</a>\<a href=\"download.php?op=viewdownload&amp;cid=$cid&amp;orderby=titleD\">D</a>) "
        ."".translate("Date")." (<a href=\"download.php?op=viewdownload&amp;cid=$cid&amp;orderby=dateA\">A</a>\<a href=\"download.php?op=viewdownload&amp;cid=$cid&amp;orderby=dateD\">D</a>) "
        ."".translate("Rating")." (<a href=\"download.php?op=viewdownload&amp;cid=$cid&amp;orderby=ratingA\">A</a>\<a href=\"download.php?op=viewdownload&amp;cid=$cid&amp;orderby=ratingD\">D</a>) "
        ."".translate("Popularity")." (<a href=\"download.php?op=viewdownload&amp;cid=$cid&amp;orderby=hitsA\">A</a>\<a href=\"download.php?op=viewdownload&amp;cid=$cid&amp;orderby=hitsD\">D</a>)"
    ."<br /><b>".translate("Resources currently sorted by").": $orderbyTrans</b></font></center><br /><br />";


    $result=mysql_query("select lid, title, description, date, hits, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage from ".$mpnTables['downloads_downloads']." where cid=$cid AND sid=0 order by $orderby limit $min,$Perpage ");
    $fullcountresult=mysql_query("select lid, title, description, date, hits, downloadratingsummary, totalvotes, totalcomments from ".$mpnTables['downloads_downloads']." where cid=$cid AND sid=0");
    $totalselecteddownloads = mysql_num_rows($fullcountresult);

    OpenTable();

    echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"10\" border=\"0\"><tr><td><font class=\"content\">";
    $x=0;


    while(list($lid, $title, $description, $time, $hits, $downloadratingsummary, $totalvotes, $totalcomments, $filesize, $version, $homepage)=mysql_fetch_row($result)) {

//    $downloadratingsummary = number_format($downloadratingsummary, $mainvotedecimal);
    $downloadratingsummary = number_format($downloadratingsummary);

    // Kiril: Start New Sanitizer

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

    // End New Sanitizer


    /*$title = stripslashes($title);
    $description = stripslashes($description);*/
        global $mpnTables;
    if (_MPN_ADMIN) {
        echo "<a href=\"admin.php?fct=download&op=DownloadsModDownload&amp;lid=$lid\"><img src=\"images/download/lwin.gif\" border=\"0\" alt=\"".translate("Edit")."\"></a>&nbsp;&nbsp;";
    } else {
        echo "<img src=\"images/download/lwin.gif\" border=\"0\" alt=\"\">&nbsp;&nbsp;";
    }
        echo "<a href=\"download.php?op=getit&amp;lid=$lid\">$title</a>";
    if (!isset($datetime))
    {
        $datetime = null;
    }

    newdownloadgraphic($datetime, $time);
    popgraphic($hits);
    /* INSERT code for *editor review* here */
    detecteditorial($lid, $title, 1);
    echo "<br />";
    echo "<b>".translate("Description").":</b> $description<br />";
    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("%d-%b-%Y", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    $datetime = ucfirst($datetime);
    echo "<b>".translate("Version").":</b> $version <b>".translate("Filesize").":</b> ".CoolSize($filesize)."<br />";
    echo "<b>".translate("Added on").":</b> $datetime <b>".translate("Downloads").":</b> $hits";
        $transfertitle = str_replace (" ", "_", $title);
        /* voting & comments stats */
        if ($totalvotes == 1) {
        $votestring = translate("Vote");
        } else {
        $votestring = translate("Votes");
    }
        if ($downloadratingsummary!="0" || $downloadratingsummary!="0.0") {
        echo " <b>".translate("Rating").":</b> $downloadratingsummary ($totalvotes $votestring)";
    }
        if ($homepage == "") {
        echo "<br />";
    } else {
        echo "<br /><a href=\"$homepage\" target=\"new\">".translate("HomePage")."</a> | ";
    }
    echo "<a href=\"download.php?op=ratedownload&amp;lid=$lid\">".translate("Rate Resource")."</a>";
        echo " | <a href=\"download.php?op=brokendownload&amp;lid=$lid\">".translate("Report Broken Link")."</a>";
    echo " | <a href=\"download.php?op=viewdownloaddetails&amp;lid=$lid\">".translate("Details")."</a>";
        if ($totalcomments != 0) {
        echo " | <a href=\"download.php?op=viewdownloadcomments&amp;lid=$lid\">".translate("Comments")." ($totalcomments)</a>";
    }
        detecteditorial($lid, $transfertitle, 0);
    echo "<br /><br />";
    $x++;
    }
    echo "</font>";
    $orderby = convertorderbyout($orderby);
    /* Calculates how many pages exist. Which page one should be on, etc... */
    $downloadpagesint = ($totalselecteddownloads / $Perpage);
    $downloadpageremainder = ($totalselecteddownloads % $Perpage);
    if ($downloadpageremainder != 0) {
        $downloadpages = ceil($downloadpagesint);
        if ($totalselecteddownloads < $Perpage) {
            $downloadpageremainder = 0;
        }
    } else {
        $downloadpages = $downloadpagesint;
    }
    /* Page Numbering */
    if ($downloadpages!=1 && $downloadpages!=0) {
        echo "<br /><br />";
        echo "".translate("Select Page").": ";
        $prev=$min-$Perpage;
        if ($prev>=0) {
            echo "&nbsp;&nbsp;<b>[ <a href=\"download.php?op=viewdownload&amp;cid=$cid&amp;min=$prev&amp;orderby=$orderby&amp;show=$show\">";
            echo " &lt;&lt; ".translate("Previous")."</a> ]</b> ";
    }
        $counter = 1;
    $currentpage = ($max / $Perpage);
        while ($counter<=$downloadpages ) {
            $cpage = $counter;
            $mintemp = ($Perpage * $counter) - $Perpage;
            if ($counter == $currentpage) {
        echo "<b>$counter</b>&nbsp";
        } else {
        echo "<a href=\"download.php?op=viewdownload&amp;cid=$cid&amp;min=$mintemp&amp;orderby=$orderby&amp;show=$show\">$counter</a> ";
        }
            $counter++;
        }
        $next=$min+$Perpage;
        if ($x>=$Perpage) {
            echo "&nbsp;&nbsp;<b>[ <a href=\"download.php?op=viewdownload&amp;cid=$cid&amp;min=$max&amp;orderby=$orderby&amp;show=$show\">";
            echo " ".translate("Next")." &gt;&gt;</a> ]</b> ";
        }
    }
    echo "</td></tr></table>";
    CloseTable();
    include("footer.php");
}

function viewsdownload($sid, $min, $orderby, $show) {
    global $mpnTables, $locale;
    include("admin/download/config.inc.php");
    include("header.php");
    menu();
    if (!isset($min)) $min=0;
    if (!isset($max)) $max=$min+$Perpage;
    if(isset($orderby)) {
    $orderby = convertorderbyin($orderby);
    } else {
    $orderby = "title ASC";
    }
    if ($show!="") {
    $Perpage = $show;
    } else {
    $show=$Perpage;
    }
    echo "<br />";


    $result = mysql_query("select cid, title from ".$mpnTables['downloads_subcategories']." where sid=$sid");
    list($cid, $stitle) = mysql_fetch_row($result);

    $result2 = mysql_query("select cid, title from ".$mpnTables['downloads_categories']." where cid=$cid");
    list($cid, $title) = mysql_fetch_row($result2);

    $title = stripslashes( $title );
    $stitle = stripslashes( $stitle );

    echo "<center><font class=\"option\"><b><a href=\"download.php\">".translate("Main")."</a> / <a href=\"download.php?op=viewdownload&amp;cid=$cid\">$title</a> / $stitle</b></font></center>";
    $orderbyTrans = convertorderbytrans($orderby);
    echo "<br /><center><font class=\"content\">".translate("Sort Downloads by").": "
    ."".translate("Title")." (<a href=\"download.php?op=viewsdownload&amp;sid=$sid&amp;orderby=titleA\">A</a>\<a href=\"download.php?op=viewsdownload&amp;sid=$sid&amp;orderby=titleD\">D</a>)"
    ." ".translate("Date")." (<a href=\"download.php?op=viewsdownload&amp;sid=$sid&amp;orderby=dateA\">A</a>\<a href=\"download.php?op=viewsdownload&amp;sid=$sid&amp;orderby=dateD\">D</a>)"
    ." ".translate("Rating")." (<a href=\"download.php?op=viewsdownload&amp;sid=$sid&amp;orderby=ratingA\">A</a>\<a href=\"download.php?op=viewsdownload&amp;sid=$sid&amp;orderby=ratingD\">D</a>)"
        ." ".translate("Popularity")." (<a href=\"download.php?op=viewsdownload&amp;sid=$sid&amp;orderby=hitsA\">A</a>\<a href=\"download.php?op=viewsdownload&amp;sid=$sid&amp;orderby=hitsD\">D</a>)"
    ."<br /><b>".translate("Resources currently sorted by").": $orderbyTrans</b></font></center><br /><br />";
    $result=mysql_query("select lid, url, title, description, date, hits, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage from ".$mpnTables['downloads_downloads']." where sid=$sid order by $orderby limit $min,$Perpage");
    $fullcountresult=mysql_query("select lid, title, description, date, hits, downloadratingsummary, totalvotes, totalcomments from ".$mpnTables['downloads_downloads']." where sid=$sid");
    $totalselecteddownloads = mysql_num_rows($fullcountresult);

    OpenTable();


    echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"10\" border=\"0\"><tr><td><font class=\"content\">";
    $x=0;
    while(list($lid, $url, $title, $description, $time, $hits, $downloadratingsummary, $totalvotes, $totalcomments, $filesize, $version, $homepage)=mysql_fetch_row($result)) {

    $downloadratingsummary = number_format($downloadratingsummary, $mainvotedecimal);

    // Kiril: Start New Sanitizer

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

    // End New Sanitizer

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

        global $mpnTables;
    if (_MPN_ADMIN) {
        echo "<a href=\"admin.php?fct=download&op=DownloadsModDownload&amp;lid=$lid\"><img src=\"images/download/lwin.gif\" border=\"0\" alt=\"".translate("Edit")."\"></a>&nbsp;&nbsp;";
    } else {
        echo "<img src=\"images/download/lwin.gif\" border=\"0\" alt=\"\">&nbsp;&nbsp;";
    }
        echo "<a href=\"download.php?op=getit&amp;lid=$lid\">$title</a>";
    if (!isset($datetime))
    {
        $datetime = null;
    }

    newdownloadgraphic($datetime, $time);
    popgraphic($hits);
        /* code for *editor review* insert here */
    detecteditorial($lid, $title, 1);
    echo "<br /><b>".translate("Description").":</b> $description<br />";
    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("%d-%b-%Y", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    $datetime = ucfirst($datetime);
    echo "<b>".translate("Version").":</b> $version <b>".translate("Filesize").":</b> ".CoolSize($filesize)."<br />";
    echo "<b>".translate("Added on").":</b> $datetime <b>".translate("Downloads").":</b> $hits";
        $transfertitle = str_replace (" ", "_", $title);
        /* voting & comments stats */
        if ($totalvotes == 1) {
        $votestring = translate("Vote");
    } else {
        $votestring = translate("Votes");
    }
        if ($downloadratingsummary!="0" || $downloadratingsummary!="0.0") {
        echo " <b>".translate("Rating").":</b> $downloadratingsummary ($totalvotes $votestring)";
        }
        if ($homepage == "") {
        echo "<br />";
    } else {
        echo "<br /><a href=\"$homepage\" target=\"new\">".translate("HomePage")."</a> | ";
    }
    echo "<a href=\"download.php?op=ratedownload&amp;lid=$lid\">".translate("Rate Resource")."</a>";
    echo " | <a href=\"download.php?op=viewdownloaddetails&amp;lid=$lid\">".translate("Details")."</a>";
        if ($totalcomments != 0) {
        echo " | <a href=\"download.php?op=viewdownloadcomments&amp;lid=$lid\">".translate("Comments")." ($totalcomments)</a>";
    }
    detecteditorial($lid, $transfertitle, 0);
    echo "<br /><br />";
    $x++;
    }
    echo "</font>";
    $orderby = convertorderbyout($orderby);
    /* Calculates how many pages exist.  Which page one should be on, etc... */
    $downloadpagesint = ($totalselecteddownloads / $Perpage);
    $downloadpageremainder = ($totalselecteddownloads % $Perpage);
    if ($downloadpageremainder != 0) {
    $downloadpages = ceil($downloadpagesint);
        if ($totalselecteddownloads < $Perpage) {
            $downloadpageremainder = 0;
        }
    } else {
        $downloadpages = $downloadpagesint;
    }
    /* Page Numbering */
    if ($downloadpages!=1 && $downloadpages!=0) {
    echo "<br /><br />"
            ."".translate("Select Page").": ";
        $prev=$min-$Perpage;
        if ($prev>=0) {
            echo "&nbsp;&nbsp;<b>[ <a href=\"download.php?op=viewsdownload&amp;sid=$sid&amp;min=$prev&amp;orderby=$orderby&amp;show=$show\">"
            ." &lt;&lt; ".translate("Previous")."</a> ]</b> ";
        }
        $counter = 1;
        $currentpage = ($max / $Perpage);
        while ($counter<=$downloadpages ) {
            $cpage = $counter;
            $mintemp = ($Perpage * $counter) - $Perpage;
            if ($counter == $currentpage) {
        echo "<b>$counter</b>&nbsp";
        } else {
        echo "<a href=\"download.php?op=viewsdownload&amp;sid=$sid&amp;min=$mintemp&amp;orderby=$orderby&amp;show=$show\">$counter</a> ";
        }
            $counter++;
        }
        $next=$min+$Perpage;
        if ($x>=$Perpage) {
            echo "&nbsp;&nbsp;<b>[ <a href=\"download.php?op=viewsdownload&amp;sid=$sid&amp;min=$max&amp;orderby=$orderby&amp;show=$show\">"
            ." ".translate("Next")." &gt;&gt;</a> ]</b> ";
        }
    }
    echo "</td></tr></table>";
    CloseTable();
    include("footer.php");
}

function newdownloadgraphic($datetime, $time) {
    global $locale;
    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("%d-%b-%Y", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    $datetime = ucfirst($datetime);
    $startdate = time();
    $count = 0;
    while ($count <= 7) {
    $daysold = date("d-M-Y", $startdate);
        if ("$daysold" == "$datetime") {
            if ($count<=1) {
        echo "<img src=\"images/download/new_1.gif\" alt=\"".translate("New Today")."\">";
        }
            if ($count<=3 && $count>1) {
        echo "<img src=\"images/download/new_3.gif\" alt=\"".translate("New last 3 days")."\">";
        }
            if ($count<=7 && $count>3) {
        echo "<img src=\"images/download/new_7.gif\" alt=\"".translate("New this week")."\">";
        }
    }
        $count++;
        $startdate = (time()-(86400 * $count));
    }
}

function categorynewdownloadgraphic($cat) {
    global $mpnTables, $locale;
    $newresult = mysql_query("select date from ".$mpnTables['downloads_downloads']." where cid=$cat order by date desc limit 1");
    list($time)=mysql_fetch_row($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("%d-%b-%Y", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    $datetime = ucfirst($datetime);
    $startdate = time();
    $count = 0;
    while ($count <= 7) {
    $daysold = date("d-M-Y", $startdate);
        if ("$daysold" == "$datetime") {
            if ($count<=1) {
        echo "<img src=\"images/download/new_1.gif\" alt=\"".translate("New Downloads in this Category Added Today")."\">";
        }
            if ($count<=3 && $count>1) {
        echo "<img src=\"images/download/new_3.gif\" alt=\"".translate("New Downloads in this Category Added in the last 3 days")."\">";
        }
            if ($count<=7 && $count>3) {
        echo "<img src=\"images/download/new_7.gif\" alt=\"".translate("New Downloads in this Category Added this week")."\">";
        }
    }
        $count++;
        $startdate = (time()-(86400 * $count));
    }
}

function popgraphic($hits) {
    include("admin/download/config.inc.php");
    if ($hits>=$popular) {
    echo "&nbsp;<img src=\"images/download/popular.gif\" alt=\"".translate("Popular")."\">";
    }
}

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

function convertorderbytrans($orderby) {
    if ($orderby == "hits ASC")         $orderbyTrans = "".translate("Popularity (Least to Most Hits)")."";
    if ($orderby == "hits DESC")        $orderbyTrans = "".translate("Popularity (Most to Least Hits)")."";
    if ($orderby == "title ASC")        $orderbyTrans = "".translate("Title (A to Z)")."";
    if ($orderby == "title DESC")       $orderbyTrans = "".translate("Title (Z to A)")."";
    if ($orderby == "date ASC")         $orderbyTrans = "".translate("Date (Old Downloads Listed First)")."";
    if ($orderby == "date DESC")        $orderbyTrans = "".translate("Date (New Downloads Listed First)")."";
    if ($orderby == "downloadratingsummary ASC")    $orderbyTrans = "".translate("Rating")."";
    if ($orderby == "downloadratingsummary DESC")   $orderbyTrans = "".translate("Rating")."";
    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 == "downloadratingsummary ASC")    $orderby = "ratingA";
    if ($orderby == "title DESC")       $orderby = "titleD";
    if ($orderby == "date DESC")        $orderby = "dateD";
    if ($orderby == "hits DESC")        $orderby = "hitsD";
    if ($orderby == "downloadratingsummary DESC")   $orderby = "ratingD";
    return $orderby;
}

function getit($lid) {
    global $mpnTables;
    mysql_query("update ".$mpnTables['downloads_downloads']." set hits=hits+1 where lid=$lid");
    $result = mysql_query("select url from ".$mpnTables['downloads_downloads']." where lid=$lid");
    list($url) = mysql_fetch_row($result);
    $url = stripslashes( $url );
    $_SERVER['F_LIB'] -> redirectRequest( $url );
}

function search($query, $min, $orderby, $show) {
    include("admin/download/config.inc.php");
    global $mpnTables, $admin, $bgcolor2;
    if (!isset($min)) $min=0;
    if (!isset($max)) $max=$min+$downloadsresults;
    if(isset($orderby)) {
    $orderby = convertorderbyin($orderby);
    } else {
    $orderby = "title ASC";
    }
    if ($show!="") {
    $downloadsresults = $show;
    } else {
    $show=$downloadsresults;
    }
    $query = stripslashes($query);
    $result = mysql_query("select lid, cid, sid, title, url, description, date, hits, downloadratingsummary, totalvotes, totalcomments, filesize, version, homepage from ".$mpnTables['downloads_downloads']." where title LIKE '%$query%' OR description LIKE '%$query%' ORDER BY $orderby LIMIT $min,$downloadsresults");
    $fullcountresult=mysql_query("select lid, title, description, date, hits, downloadratingsummary, totalvotes, totalcomments from ".$mpnTables['downloads_downloads']." where title LIKE '%$query%' OR description LIKE '%$query%' ");
    $totalselecteddownloads = mysql_num_rows($fullcountresult);
    $nrows  = mysql_num_rows($result);
    $resultx = mysql_query("select * from ".$mpnTables['downloads_subcategories']." where title LIKE '%$query%' ORDER BY title DESC");
    $nrowsx  = mysql_num_rows($resultx);
    $x=0;
    include("header.php");
    menu();
    echo "<br />";
    OpenTable();
    if ($query != "") {
        if ($nrows>0 OR $nrowsx>0) {
        $result2 = mysql_query("select cid, sid, title from ".$mpnTables['downloads_subcategories']." where title LIKE '%$query%' ORDER BY title DESC");
        echo "<font class=\"option\">".translate("Search Results for").": <b>$query</b></font><br /><br />"
            ."<table width=\"100%\" bgcolor=\"$bgcolor2\"><tr><td><font class=\"option\"><b>".translate("Sub-Categories")."</b></font></td></tr></table>";
        while(list($cid, $sid, $stitle) = mysql_fetch_row($result2)) {
            $cate = mysql_query("select title from ".$mpnTables['downloads_categories']." where cid=$cid");
            list($ctitle) = mysql_fetch_row($cate);
            $res = mysql_query("select * from ".$mpnTables['downloads_downloads']." where sid=$sid");
            $numrows = mysql_num_rows($res);

            $ctitle = stripslashes( $ctitle );
            $stitle = stripslashes( $stitle );

            $ctitle = ereg_replace($query, "<b>$query</b>", $ctitle);
            $stitle = ereg_replace($query, "<b>$query</b>", $stitle);
            echo "<strong><big>&middot;</big></strong>&nbsp;<a href=\"download.php?op=viewsdownload&amp;sid=$sid\">$ctitle / $stitle</a> ($numrows)<br />";
        }
    echo "<br /><table width=\"100%\" bgcolor=\"$bgcolor2\"><tr><td><font class=\"option\"><b>".translate("Downloads")."</b></font></td></tr></table>";
        $orderbyTrans = convertorderbytrans($orderby);
        echo "<center><font class=\"content\">".translate("Sort Downloads by").": "
            ."".translate("Title")." (<a href=\"download.php?op=search&amp;query=$query&amp;orderby=titleA\">A</a>\<a href=\"download.php?op=search&amp;query=$query&amp;orderby=titleD\">D</a>) "
            ."".translate("Date")." (<a href=\"download.php?op=search&amp;query=$query&amp;orderby=dateA\">A</a>\<a href=\"download.php?op=search&amp;query=$query&amp;orderby=dateD\">D</a>) "
            ."".translate("Rating")." (<a href=\"download.php?op=search&amp;query=$query&amp;orderby=ratingA\">A</a>\<a href=\"download.php?op=search&amp;query=$query&amp;orderby=ratingD\">D</a>) "
            ."".Popularity." (<a href=\"download.php?op=search&amp;query=$query&amp;orderby=hitsA\">A</a>\<a href=\"download.php?op=search&amp;query=$query&amp;orderby=hitsD\">D</a>)"
            ."<br />".translate("Resources currently sorted by").": $orderbyTrans</center><br /><br /><br />";
        while(list($lid, $cid, $sid, $title, $url, $description, $time, $hits, $downloadratingsummary, $totalvotes, $totalcomments, $filesize, $version, $homepage) = mysql_fetch_row($result)) {
        $downloadratingsummary = number_format($downloadratingsummary, $mainvotedecimal);

        // Kiril: Start New Sanitizer

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

        // End New Sanitizer

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

        $transfertitle = str_replace (" ", "_", $title);
        $title = ereg_replace($query, "<b>$query</b>", $title);
            global $mpnTables;
        if (_MPN_ADMIN) {
        echo "<a href=\"admin.php?fct=download&op=DownloadsModDownload&amp;lid=$lid\"><img src=\"images/download/lwin.gif\" border=\"0\" alt=\"".translate("Edit")."\"></a>&nbsp;&nbsp;";
        } else {
        echo "<img src=\"images/download/lwin.gif\" border=\"0\" alt=\"\">&nbsp;&nbsp;";
        }
        echo "<a href=\"download.php?op=getit&amp;lid=$lid\">$title</a>";
        newdownloadgraphic($datetime, $time);
            popgraphic($hits);
        detecteditorial($lid, $transfertitle, 1);
        echo "<br />";
        $description = ereg_replace($query, "<b>$query</b>", $description);
        echo "<b>".translate("Description").":</b> $description<br />";
        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("%d-%b-%Y", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
        $datetime = ucfirst($datetime);
        echo "<b>".translate("Version").":</b> $version <b>".translate("Filesize").":</b> ".CoolSize($filesize)."<br />";
        echo "<b>".translate("Added on").":</b> $datetime <b>".translate("Downloads").":</b> $hits";
            /* voting & comments stats */
            if ($totalvotes == 1) {
        $votestring = translate("Vote");
        } else {
        $votestring = translate("Votes");
        }
            if ($downloadratingsummary!="0" || $downloadratingsummary!="0.0") {
        echo " <b>".translate("Rating").":</b> $downloadratingsummary ($totalvotes $votestring)";
        }
            if ($homepage == "") {
        echo "<br />";
        } else {
        echo "<br /><a href=\"$homepage\" target=\"new\">".translate("HomePage")."</a> | ";
        }
            echo "<a href=\"download.php?op=ratedownload&amp;lid=$lid\">".translate("Rate Resource")."</a>";
        echo " | <a href=\"download.php?op=viewdownloaddetails&amp;lid=$lid\">".translate("Details")."</a>";
            if ($totalcomments != 0) {
        echo " | <a href=\"download.php?op=viewdownloadcomments&amp;lid=$lid>".translate("Comments")." ($totalcomments)</a>";
        }
        detecteditorial($lid, $transfertitle, 0);
        echo "<br />";
        $result3 = mysql_query("select title from ".$mpnTables['downloads_categories']." where cid=$cid");
        $result4 = mysql_query("select title from ".$mpnTables['downloads_subcategories']." where sid=$sid");
        list($ctitle) = mysql_fetch_row($result3);
        list($stitle) = mysql_fetch_row($result4);

        $ctitle = stripslashes( $ctitle );
        $stitle = stripslashes( $stitle );


        if ($stitle=="") {
        $slash = "";
        } else {
        $slash = "/";
        }
        echo "".translate("Category").": $ctitle $slash $stitle<br /><br />";
        $x++;
    }
    echo "</font>";
        $orderby = convertorderbyout($orderby);
    } else {
    echo "<br /><br /><center><font class=\"option\"><b>".translate("No matches found to your query")."</b></font><br /><br />[ <a href=\"javascript:history.go(-1)\">".translate("Go Back")."</a> ]<br /></center>";
    }
    /* Calculates how many pages exist.  Which page one should be on, etc... */
    $downloadpagesint = ($totalselecteddownloads / $downloadsresults);
    $downloadpageremainder = ($totalselecteddownloads % $downloadsresults);
    if ($downloadpageremainder != 0) {
        $downloadpages = ceil($downloadpagesint);
        if ($totalselecteddownloads < $downloadsresults) {
            $downloadpageremainder = 0;
    }
    } else {
        $downloadpages = $downloadpagesint;
    }
    /* Page Numbering */
    if ($downloadpages!=1 && $downloadpages!=0) {
    echo "<br /><br />"
        ."".translate("Select Page")."";
    $prev=$min-$downloadsresults;
    if ($prev>=0) {
            echo "&nbsp;&nbsp;<b>[ <a href=\"download.php?op=search&amp;query=$query&amp;min=$prev&amp;orderby=$orderby&amp;show=$show\">"
            ." &lt;&lt; ".translate("Previous")."</a> ]</b> ";
        }
    $counter = 1;
        $currentpage = ($max / $downloadsresults);
        while ($counter<=$downloadpages ) {
            $cpage = $counter;
            $mintemp = ($Perpage * $counter) - $downloadsresults;
            if ($counter == $currentpage) {
        echo "<b>$counter</b> ";
        } else {
        echo "<a href=\"download.php?op=search&amp;query=$query&amp;min=$mintemp&amp;orderby=$orderby&amp;show=$show\">$counter</a> ";
        }
            $counter++;
        }
        $next=$min+$downloadsresults;
        if ($x>=$Perpage) {
            echo "&nbsp;&nbsp;<b>[ <a href=\"download.php?op=search&amp;query=$query&amp;min=$max&amp;orderby=$orderby&amp;show=$show\">"
            ." ".translate("Next")." &gt;&gt;</a> ]</b>";
        }
    }
    echo "<br /><br /><center><font size=2>
    ".translate("Try to search")." \"$query\" ".translate("in others Search Engines")."<br />
    <a target=\"_blank\" href=\"http://www.altavista.com/cgi-bin/query?pg=q&sc=on&hl=on&act=2006&par=0&q=$query&kl=XX&stype=stext\">Alta Vista</a> -
    <a target=\"_blank\" href=\"http://www.hotbot.com/?MT=$query&DU=days&SW=web\">HotBot</a> -
    <a target=\"_blank\" href=\"http://www.dejanews.com/dnquery.xp?QRY=$query\">Deja News</a> -
    <a target=\"_blank\" href=\"http://www.lycos.com/cgi-bin/pursuit?query=$query&maxhits=20\">Lycos</a> -
    <a target=\"_blank\" href=\"http://search.yahoo.com/bin/search?p=$query\">Yahoo</a>
    <br />
    <a target=\"_blank\" href=\"http://search.1stlinuxsearch.com/compass?scope=$query&ui=sr\">1stLinuxSearch</a> -
    <a target=\"_blank\" href=\"http://www.google.com/search?q=$query\">Google</a> -
    <a target=\"_blank\" href=\"http://freshmeat.net/search/?q=$query&section=projects&x=7&y=4\">Freshmeat</a> -
    <a target=\"_blank\" href=\"http://www.justlinux.com/forum/search.php\">JustLinux</a>
    </font>";
    } else {
    echo "<center><font class=\"option\"><b>".translate("No matches found to your query")."</b></font></center><br /><br />";
    }
    CloseTable();
    include("footer.php");
}

function viewdownloadeditorial($lid) {
    global $mpnTables, $admin;

    $ttitle = getTitle( $lid , translate( 'Editorial For' ) );

    include("header.php");
    include("admin/download/config.inc.php");
    menu();

    $result=mysql_query("SELECT adminid, editorialtimestamp, editorialtext, editorialtitle FROM ".$mpnTables['downloads_editorials']." WHERE downloadid = $lid");
    $recordexist = mysql_num_rows($result);

    $transfertitle = ereg_replace ("_", " ", $ttitle);
    $displaytitle = stripslashes($transfertitle);
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"option\"><b>".translate("Download Profile").": ".$displaytitle."</b></font><br />";
    downloadinfomenu($lid);
    if ($recordexist != 0) {
    while(list($adminid, $editorialtimestamp, $editorialtext, $editorialtitle)=mysql_fetch_row($result))
    {
            $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 "<br /><br />";
        OpenTable2();
        echo "<center><font class=\"option\"><b>'$editorialtitle'</b></font></center>"
        ."<center><font class=\"tiny\">".translate("Editorial by")." $adminid - $formatted_date</font></center><br /><br />"
        ."$editorialtext";
        CloseTable();
     }
    } else {
        echo "<br /><br /><center><font class=\"option\"><b>".translate("No editorial is currently available for this website.")."</b></font></center>";
    }
    echo "<br /><br /><center>";
    downloadfooter($lid);
    echo "</center>";
    CloseTable();
    include("footer.php");
}

function detecteditorial($lid, $img) {
    global $mpnTables;
    $resulted2 = mysql_query("select adminid from ".$mpnTables['downloads_editorials']." where downloadid=$lid");
    $recordexist = mysql_num_rows($resulted2);
    if ($recordexist != 0) {
    if ($img == 1) {
        echo "&nbsp;&nbsp;<a href=\"download.php?op=viewdownloadeditorial&amp;lid=$lid\"><img src=\"images/download/cool.gif\" alt=\"".translate("Editorial")."\" border=\"0\"></a>";
    } else {
        echo " | <a href=\"download.php?op=viewdownloadeditorial&amp;lid=$lid\">".translate("Editorial")."</a>";
    }
    }
}

function viewdownloadcomments($lid) {
    global $mpnTables, $admin, $bgcolor2;

    $ttitle = getTitle( $lid , translate( 'Comments For' ) );

    include("header.php");
    include("admin/download/config.inc.php");
    menu();
    echo "<br />";
    $result=mysql_query("SELECT ratinguser, rating, ratingcomments, ratingtimestamp FROM ".$mpnTables['downloads_votedata']." WHERE ratinglid = $lid AND ratingcomments != '' ORDER BY ratingtimestamp DESC");
    $totalcomments = mysql_num_rows($result);
    $transfertitle = ereg_replace ("_", " ", $ttitle);
    $displaytitle = stripslashes($transfertitle);
    OpenTable();
    echo "<center><font class=\"option\"><b>".translate("Download Profile").": $displaytitle</b></font><br /><br />";
    downloadinfomenu($lid);
    echo "<br /><br /><br />".translate("Total of")." $totalcomments ".translate("Comments")."</font></center><br />"
    ."<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"450\">";
    $x=0;
    while(list($ratinguser, $rating, $ratingcomments, $ratingtimestamp)=mysql_fetch_row($result)) {
        $ratingcomments = stripslashes($ratingcomments);
        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=\"$bgcolor2\">"
            ."<font class=\"content\"><b> ".translate("User").": </b><a href=\"user.php?op=userinfo&amp;uname=$ratinguser\">$ratinguser</a></font>"
        ."</td>"
        ."<td bgcolor=\"$bgcolor2\">"
        ."<font class=\"content\"><b>".translate("Rating").": </b>$rating</font>"
        ."</td>"
        ."<td bgcolor=\"$bgcolor2\" align=\"right\">"
            ."<font class=\"content\">$formatted_date</font>"
        ."</td>"
        ."</tr>"
        ."<tr>"
        ."<td valign=\"top\">"
        ."<font class=\"tiny\">".translate("User's Average Rating").": $useravgrating</font>"
        ."</td>"
        ."<td valign=\"top\" colspan=\"2\">"
        ."<font class=\"tiny\">".translate("# of Ratings").": $usertotalcomments</font>"
        ."</td>"
        ."</tr>"
            ."<tr>"
        ."<td colspan=\"3\">"
        ."<font class=\"content\">";
        if (_MPN_ADMIN) {
        echo "<a href=\"admin.php?fct=download&op=DownloadsModDownload&amp;lid=$lid\"><img src=\"images/download/editicon.gif\" border=\"0\" alt=\"".translate("Edit This Download")."\"></a>";
        }
    echo " $ratingcomments</font>"
        ."<br /><br /><br /></td></tr>";
    $x++;
    }
    echo "</table><br /><br /><center>";
    downloadfooter($lid);
    echo "</center>";
    CloseTable();
    include("footer.php");
}

function viewdownloaddetails($lid) {
    global $mpnTables, $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $anonymous;

    $ttitle = getTitle( $lid , translate( 'Details For' ) );

    include("header.php");
    include("admin/download/config.inc.php");
    menu();
    $voteresult = mysql_query("select rating, ratinguser, ratingcomments FROM ".$mpnTables['downloads_votedata']." WHERE ratinglid = $lid");
    $totalvotesDB = mysql_num_rows($voteresult);
    $anonvotes = 0;
    $anonvoteval = 0;
    $outsidevotes = 0;
    $outsidevoteeval = 0;
    $regvoteval = 0;
    $topanon = 0;
    $bottomanon = 11;
    $topreg = 0;
    $bottomreg = 11;
    $topoutside = 0;
    $bottomoutside = 11;
    $avv = array(0,0,0,0,0,0,0,0,0,0,0);
    $rvv = array(0,0,0,0,0,0,0,0,0,0,0);
    $ovv = array(0,0,0,0,0,0,0,0,0,0,0);
    $truecomments = $totalvotesDB;
    while(list($ratingDB, $ratinguserDB, $ratingcommentsDB)=mysql_fetch_row($voteresult)) {
    if ($ratingcommentsDB=="") $truecomments--;
        if ($ratinguserDB==$anonymous) {
        $anonvotes++;
        $anonvoteval += $ratingDB;
    }
    if ($useoutsidevoting == 1) {
        if ($ratinguserDB=='outside') {
        $outsidevotes++;
            $outsidevoteval += $ratingDB;
        }
    } else {
        $outsidevotes = 0;
    }
    if ($ratinguserDB!=$anonymous && $ratinguserDB!="outside") {
        $regvoteval += $ratingDB;
    }
    if ($ratinguserDB!=$anonymous && $ratinguserDB!="outside") {
        if ($ratingDB > $topreg) $topreg = $ratingDB;
        if ($ratingDB < $bottomreg) $bottomreg = $ratingDB;
        for ($rcounter=1; $rcounter<11; $rcounter++) if ($ratingDB==$rcounter) $rvv[$rcounter]++;
    }
    if ($ratinguserDB==$anonymous) {
        if ($ratingDB > $topanon) $topanon = $ratingDB;
        if ($ratingDB < $bottomanon) $bottomanon = $ratingDB;
        for ($rcounter=1; $rcounter<11; $rcounter++) if ($ratingDB==$rcounter) $avv[$rcounter]++;
    }
    if ($ratinguserDB=="outside") {
        if ($ratingDB > $topoutside) $topoutside = $ratingDB;
        if ($ratingDB < $bottomoutside) $bottomoutside = $ratingDB;
        for ($rcounter=1; $rcounter<11; $rcounter++) if ($ratingDB==$rcounter) $ovv[$rcounter]++;
    }
    }
    $regvotes = $totalvotesDB - $anonvotes - $outsidevotes;
    if ($totalvotesDB == 0) {
    $finalrating = 0;
    } else if ($anonvotes == 0 && $regvotes == 0) {
    /* Figure Outside Only Vote */
    $finalrating = $outsidevoteval / $outsidevotes;
    $finalrating = number_format($finalrating, $detailvotedecimal);
    $avgOU = $outsidevoteval / $totalvotesDB;
    $avgOU = number_format($avgOU, $detailvotedecimal);
    } else if ($outsidevotes == 0 && $regvotes == 0) {
    /* Figure Anon Only Vote */
    $finalrating = $anonvoteval / $anonvotes;
    $finalrating = number_format($finalrating, $detailvotedecimal);
    $avgAU = $anonvoteval / $totalvotesDB;
    $avgAU = number_format($avgAU, $detailvotedecimal);
    } else if ($outsidevotes == 0 && $anonvotes == 0) {
    /* Figure Reg Only Vote */
    $finalrating = $regvoteval / $regvotes;
    $finalrating = number_format($finalrating, $detailvotedecimal);
    $avgRU = $regvoteval / $totalvotesDB;
    $avgRU = number_format($avgRU, $detailvotedecimal);
    } else if ($regvotes == 0 && $useoutsidevoting == 1 && $outsidevotes != 0 && $anonvotes != 0 ) {
    /* Figure Reg and Anon Mix */
    $avgAU = $anonvoteval / $anonvotes;
    $avgOU = $outsidevoteval / $outsidevotes;
    if ($anonweight > $outsideweight ) {
        /* Anon is 'standard weight' */
        $newimpact = $anonweight / $outsideweight;
        $impactAU = $anonvotes;
        $impactOU = $outsidevotes / $newimpact;
        $finalrating = ((($avgOU * $impactOU) + ($avgAU * $impactAU)) / ($impactAU + $impactOU));
        $finalrating = number_format($finalrating, $detailvotedecimal);
    } else {
        /* Outside is 'standard weight' */
        $newimpact = $outsideweight / $anonweight;
        $impactOU = $outsidevotes;
        $impactAU = $anonvotes / $newimpact;
        $finalrating = ((($avgOU * $impactOU) + ($avgAU * $impactAU)) / ($impactAU + $impactOU));
        $finalrating = number_format($finalrating, $detailvotedecimal);
    }
    } else {
        /* REG User vs. Anonymous vs. Outside User Weight Calutions */
        $impact = $anonweight;
        $outsideimpact = $outsideweight;
        if ($regvotes == 0) {
        $avgRU = 0;
    } else {
        $avgRU = $regvoteval / $regvotes;
    }
    if ($anonvotes == 0) {
        $avgAU = 0;
    } else {
        $avgAU = $anonvoteval / $anonvotes;
    }
    if ($outsidevotes == 0 ) {
        $avgOU = 0;
    } else {
        $avgOU = $outsidevoteval / $outsidevotes;
    }
    $impactRU = $regvotes;
    $impactAU = $anonvotes / $impact;
    $impactOU = $outsidevotes / $outsideimpact;
    $finalrating = (($avgRU * $impactRU) + ($avgAU * $impactAU) + ($avgOU * $impactOU)) / ($impactRU + $impactAU + $impactOU);
    $finalrating = number_format($finalrating, $detailvotedecimal);
    }
    if (!isset($avgOU) || $avgOU == 0 || $avgOU == "") {
    $avgOU = "";
    } else {
    $avgOU = number_format($avgOU, $detailvotedecimal);
    }
    if ( ! isset( $avgRU ) || $avgRU == 0 || $avgRU == "" ) {
    $avgRU = "";
    } else {
    $avgRU = number_format($avgRU, $detailvotedecimal);
    }
    if (!isset($avgAU) || $avgAU == 0 || $avgAU == "") {
    $avgAU = "";
    } else {
    $avgAU = number_format($avgAU, $detailvotedecimal);
    }
    if ($topanon == 0) $topanon = "";
    if ($bottomanon == 11) $bottomanon = "";
    if ($topreg == 0) $topreg = "";
    if ($bottomreg == 11) $bottomreg = "";
    if ($topoutside == 0) $topoutside = "";
    if ($bottomoutside == 11) $bottomoutside = "";
    $totalchartheight = 70;
    $chartunits = $totalchartheight / 10;
    $avvper     = array(0,0,0,0,0,0,0,0,0,0,0);
    $rvvper         = array(0,0,0,0,0,0,0,0,0,0,0);
    $ovvper         = array(0,0,0,0,0,0,0,0,0,0,0);
    $avvpercent     = array(0,0,0,0,0,0,0,0,0,0,0);
    $rvvpercent     = array(0,0,0,0,0,0,0,0,0,0,0);
    $ovvpercent     = array(0,0,0,0,0,0,0,0,0,0,0);
    $avvchartheight = array(0,0,0,0,0,0,0,0,0,0,0);
    $rvvchartheight = array(0,0,0,0,0,0,0,0,0,0,0);
    $ovvchartheight = array(0,0,0,0,0,0,0,0,0,0,0);
    $avvmultiplier = 0;
    $rvvmultiplier = 0;
    $ovvmultiplier = 0;
    for ($rcounter=1; $rcounter<11; $rcounter++) {
        if ($anonvotes != 0) $avvper[$rcounter] = $avv[$rcounter] / $anonvotes;
        if ($regvotes != 0) $rvvper[$rcounter] = $rvv[$rcounter] / $regvotes;
        if ($outsidevotes != 0) $ovvper[$rcounter] = $ovv[$rcounter] / $outsidevotes;
        $avvpercent[$rcounter] = number_format($avvper[$rcounter] * 100, 1);
        $rvvpercent[$rcounter] = number_format($rvvper[$rcounter] * 100, 1);
        $ovvpercent[$rcounter] = number_format($ovvper[$rcounter] * 100, 1);
        if ($avv[$rcounter] > $avvmultiplier) $avvmultiplier = $avv[$rcounter];
        if ($rvv[$rcounter] > $rvvmultiplier) $rvvmultiplier = $rvv[$rcounter];
        if ($ovv[$rcounter] > $ovvmultiplier) $ovvmultiplier = $ovv[$rcounter];
    }
    if ($avvmultiplier != 0) $avvmultiplier = 10 / $avvmultiplier;
    if ($rvvmultiplier != 0) $rvvmultiplier = 10 / $rvvmultiplier;
    if ($ovvmultiplier != 0) $ovvmultiplier = 10 / $ovvmultiplier;
    for ($rcounter=1; $rcounter<11; $rcounter++) {
        $avvchartheight[$rcounter] = ($avv[$rcounter] * $avvmultiplier) * $chartunits;
        $rvvchartheight[$rcounter] = ($rvv[$rcounter] * $rvvmultiplier) * $chartunits;
        $ovvchartheight[$rcounter] = ($ovv[$rcounter] * $ovvmultiplier) * $chartunits;
        if ($avvchartheight[$rcounter]==0) $avvchartheight[$rcounter]=1;
        if ($rvvchartheight[$rcounter]==0) $rvvchartheight[$rcounter]=1;
        if ($ovvchartheight[$rcounter]==0) $ovvchartheight[$rcounter]=1;
    }
    $transfertitle = ereg_replace ("_", " ", $ttitle);
    $displaytitle = $transfertitle;
    $res = mysql_query("select name, email, description, filesize, version, homepage from ".$mpnTables['downloads_downloads']." where lid='$lid'");
    list($auth_name, $email, $description, $filesize, $version, $homepage) = mysql_fetch_row($res);

    // Kiril: Start New Sanitizer

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

    // End New Sanitizer

    echo "<br />";

    echo "<h2>" . translate ( 'Download Profile' ) . " ".stripslashes($displaytitle)."</h2>\n";

    downloadinfomenu($lid);

    echo "<br /><br />\n";

    OpenTable();

    if ($auth_name == "")
    {
        $auth_name = "<i>".translate("Unknown")."</i>";
    }
    else
    {
        if ($email == "") {
            $auth_name = "$auth_name";
        } else {
            $email = ereg_replace("@"," <i>at</i> ",$email);
            $email = ereg_replace("\."," <i>dot</i> ",$email);
            $auth_name = "$auth_name ($email)";
        }
    }

    echo "<b>".translate("Author's Name").":</b> $auth_name<br />"
    ."<b>".translate("Version").":</b> $version<br /><b>".translate("Filesize").":</b> ".CoolSize($filesize)."</font>";

    echo "<br /><br /><b>".translate("Download Rating Details").":</b><br /><br />";

    echo "<div class='indent15'>\n";

        echo "<b>".translate("Total Votes")."</b>: $totalvotesDB<br />"
            ."<b>".translate("Overall Rating").":</b> $finalrating<br /><br />";

    echo "</div>\n";

    echo "<b>".translate("Description").":</b><br /><br />";

    echo "<font class=\"content\">$description<br /><br />";

    echo "<div class='center'>\n";

        echo "[ <b><a href=\"download.php?op=getit&amp;lid=$lid\">".translate("Download this file Now!")."</a></b> ";
        if (($homepage == "") OR ($homepage == "http://")) {
        echo "]<br /><br />";
        } else {
        echo "| <a href=\"$homepage\" target=\"new\">".translate("HomePage")."</a> ]<br /><br />";
        }

    echo "</div>\n";

    CloseTable();

    echo "<br /><br /><br />\n";

    echo "<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"455\">"
    ."<tr><td colspan=\"2\" bgcolor=\"$bgcolor2\">"
    ."<font class=\"content\"><b>".translate("Registered Users")."</b></font>"
    ."</td></tr>"
    ."<tr>"
    ."<td bgcolor=\"$bgcolor1\">"
        ."<font class=\"content\">".translate("Number of Ratings").": $regvotes</font>"
    ."</td>"
    ."<td rowspan=\"5\" width=\"200\">";
    if ($regvotes==0) {
    echo "<center><font class=\"content\">".translate("No Registered User Votes")."</font></center>";
    } else {
        echo "<table border=\"1\" width=\"200\">"
            ."<tr>"
        ."<td valign=\"top\" align=\"center\" colspan=\"10\" bgcolor=\"$bgcolor2\"><font class=\"content\">".translate("Breakdown of Ratings by Value")."</font></td>"
        ."</tr>"
        ."<tr>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$rvv[1] ".translate("votes")." ($rvvpercent[1]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$rvvchartheight[1]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$rvv[2] ".translate("votes")." ($rvvpercent[2]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$rvvchartheight[2]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$rvv[3] ".translate("votes")." ($rvvpercent[3]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$rvvchartheight[3]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$rvv[4] ".translate("votes")." ($rvvpercent[4]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$rvvchartheight[4]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$rvv[5] ".translate("votes")." ($rvvpercent[5]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$rvvchartheight[5]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$rvv[6] ".translate("votes")." ($rvvpercent[6]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$rvvchartheight[6]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$rvv[7] ".translate("votes")." ($rvvpercent[7]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$rvvchartheight[7]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$rvv[8] ".translate("votes")." ($rvvpercent[8]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$rvvchartheight[8]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$rvv[9] ".translate("votes")." ($rvvpercent[9]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$rvvchartheight[9]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$rvv[10] ".translate("votes")." ($rvvpercent[10]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$rvvchartheight[10]\"></td>"
        ."</tr>"
        ."<tr><td colspan=\"10\" bgcolor=\"$bgcolor2\">"
        ."<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"200\"><tr>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">1</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">2</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">3</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">4</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">5</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">6</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">7</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">8</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">9</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">10</font></td>"
        ."</tr></table>"
        ."</td></tr></table>";
    }
    echo "</td>"
    ."</tr>"
    ."<tr><td bgcolor=\"$bgcolor2\"><font class=\"content\">".translate("Download Rating Details").": $avgRU</font></td></tr>"
    ."<tr><td bgcolor=\"$bgcolor1\"><font class=\"content\">".translate("High Rating").": $topreg</font></td></tr>"
    ."<tr><td bgcolor=\"$bgcolor2\"><font class=\"content\">".translate("Low Rating").": $bottomreg</font></td></tr>"
    ."<tr><td bgcolor=\"$bgcolor1\"><font class=\"content\">".translate("Number of Comments").": $truecomments</font></td></tr>"
    ."<tr><td></td></tr>"
    ."<tr><td valign=\"top\" colspan=\"2\"><font class=\"tiny\"><br /><br />".translate("* Note: This Resource weighs Registered vs. Unregistered users ratings")." $anonweight ".translate("to")." 1.</font></td></tr>"
        ."<tr><td colspan=\"2\" bgcolor=\"$bgcolor2\"><font class=\"content\"><b>".translate("Unregistered Users")."</b></font></td></tr>"
    ."<tr><td bgcolor=\"$bgcolor1\"><font class=\"content\">".translate("Number of Ratings").": $anonvotes</font></td>"
    ."<td rowspan=\"5\" width=\"200\">";
    if ($anonvotes==0) {
    echo "<center><font class=\"content\">".translate("No Unregistered User Votes")."</font></center>";
    } else {
        echo "<table border=\"1\" width=\"200\">"
            ."<tr>"
        ."<td valign=\"top\" align=\"center\" colspan=\"10\" bgcolor=\"$bgcolor2\"><font class=\"content\">".translate("Breakdown of Ratings by Value")."</font></td>"
        ."</tr>"
        ."<tr>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$avv[1] ".translate("votes")." ($avvpercent[1]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$avvchartheight[1]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$avv[2] ".translate("votes")." ($avvpercent[2]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$avvchartheight[2]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$avv[3] ".translate("votes")." ($avvpercent[3]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$avvchartheight[3]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$avv[4] ".translate("votes")." ($avvpercent[4]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$avvchartheight[4]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$avv[5] ".translate("votes")." ($avvpercent[5]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$avvchartheight[5]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$avv[6] ".translate("votes")." ($avvpercent[6]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$avvchartheight[6]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$avv[7] ".translate("votes")." ($avvpercent[7]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$avvchartheight[7]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$avv[8] ".translate("votes")." ($avvpercent[8]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$avvchartheight[8]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$avv[9] ".translate("votes")." ($avvpercent[9]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$avvchartheight[9]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$avv[10] ".translate("votes")." ($avvpercent[10]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$avvchartheight[10]\"></td>"
        ."</tr>"
        ."<tr><td colspan=\"10\" bgcolor=\"$bgcolor2\">"
        ."<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"200\"><tr>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">1</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">2</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">3</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">4</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">5</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">6</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">7</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">8</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">9</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">10</font></td>"
        ."</tr></table>"
        ."</td></tr></table>";
    }
    echo "</td>"
    ."</tr>"
    ."<tr><td bgcolor=\"$bgcolor2\"><font class=\"content\">".translate("Download Rating Details").": $avgAU</font></td></tr>"
    ."<tr><td bgcolor=\"$bgcolor1\"><font class=\"content\">".translate("High Rating").": $topanon</font></td></tr>"
    ."<tr><td bgcolor=\"$bgcolor2\"><font class=\"content\">".translate("Low Rating").": $bottomanon</font></td></tr>"
    ."<tr><td bgcolor=\"$bgcolor1\"><font class=\"content\">&nbsp;</font></td></tr>";
    if ($useoutsidevoting == 1) {
    echo "<tr><td valign=top colspan=\"2\"><font class=\"tiny\"><br /><br />".translate("* Note: This Resource weighs Registered vs. Outside voters ratings")." $outsideweight ".translate("to")." 1.</font></td></tr>"
        ."<tr><td colspan=\"2\" bgcolor=\"$bgcolor2\"><font class=\"content\"><b>".translate("Outside Voters")."</b></font></td></tr>"
        ."<tr><td bgcolor=\"$bgcolor1\"><font class=\"content\">".translate("Number of Ratings").": $outsidevotes</font></td>"
        ."<td rowspan=\"5\" width=\"200\">";
        if ($outsidevotes==0) {
        echo "<center><font class=\"content\">".translate("No Outside Votes")."</font></center>";
    } else {
        echo "<table border=\"1\" width=\"200\">"
            ."<tr>"
        ."<td valign=\"top\" align=\"center\" colspan=\"10\" bgcolor=\"$bgcolor2\"><font class=\"content\">".translate("Breakdown of Ratings by Value")."</font></td>"
        ."</tr>"
        ."<tr>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$ovv[1] ".translate("votes")." ($ovvpercent[1]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$ovvchartheight[1]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$ovv[2] ".translate("votes")." ($ovvpercent[2]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$ovvchartheight[2]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$ovv[3] ".translate("votes")." ($ovvpercent[3]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$ovvchartheight[3]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$ovv[4] ".translate("votes")." ($ovvpercent[4]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$ovvchartheight[4]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$ovv[5] ".translate("votes")." ($ovvpercent[5]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$ovvchartheight[5]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$ovv[6] ".translate("votes")." ($ovvpercent[6]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$ovvchartheight[6]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$ovv[7] ".translate("votes")." ($ovvpercent[7]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$ovvchartheight[7]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$ovv[8] ".translate("votes")." ($ovvpercent[8]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$ovvchartheight[8]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$ovv[9] ".translate("votes")." ($ovvpercent[9]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$ovvchartheight[9]\"></td>"
        ."<td bgcolor=\"$bgcolor1\" valign=\"bottom\"><img border=\"0\" alt=\"$ovv[10] ".translate("votes")." ($ovvpercent[10]% ".translate("total votes").")\" src=\"images/blackpixel.gif\" width=\"15\" height=\"$ovvchartheight[10]\"></td>"
        ."</tr>"
        ."<tr><td colspan=\"10\" bgcolor=\"$bgcolor2\">"
        ."<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"200\"><tr>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">1</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">2</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">3</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">4</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">5</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">6</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">7</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">8</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">9</font></td>"
        ."<td width=\"10%\" valign=\"bottom\" align=\"center\"><font class=\"content\">10</font></td>"
        ."</tr></table>"
        ."</td></tr></table>";
    }
    echo "</td>"
        ."</tr>"
        ."<tr><td bgcolor=\"$bgcolor2\"><font class=\"content\">".translate("Download Rating Details").": $avgOU</font></td></tr>"
        ."<tr><td bgcolor=\"$bgcolor1\"><font class=\"content\">".translate("High Rating").": $topoutside</font></td></tr>"
        ."<tr><td bgcolor=\"$bgcolor2\"><font class=\"content\">".translate("Low Rating").": $bottomoutside</font></td></tr>"
        ."<tr><td bgcolor=\"$bgcolor1\"><font class=\"content\">&nbsp;</font></td></tr>";
    }
    echo "</table><br /><br /><center>";
    downloadfooter($lid);
    echo "</center>";
    CloseTable();
    include("footer.php");
}

function downloadfooter($lid) {
    //$ttitle = stripslashes($ttitle);
    echo "<font class=\"content\">[ <a href=\"download.php?op=getit&amp;lid=$lid\">".translate("Download this file Now!")."</a> | <a
    href=\"download.php?op=ratedownload&amp;lid=$lid\">".translate("Rate this Resource")."</a> ]</font><br /><br />";
    downloadfooterchild($lid);
}

function downloadfooterchild($lid) {
    include("admin/download/config.inc.php");
    if ($useoutsidevoting = 1) {
    echo "<br /><font class=\"content\">".translate("Is this your resource?")." <a
    href=\"download.php?op=outsidedownloadsetup&amp;lid=$lid\">".translate("Allow other users to rate it from your web site!")."</a></font>";
    }
}

function outsidedownloadsetup($lid) {
    global $sitename;
    include("header.php");
    include("admin/download/config.inc.php");
    menu();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"option\"><b>".translate("Promote Your Website")."</b></font></center><br /><br />

    ".translate("Maybe you can be interested in several of the remote 'Rate a Website' options we have available. These allow you to
    place an image (or even a rating form) on your web site in order to increase the number of votes your resource receive. Please
    choose from one of the options listed below:")."<br /><br />

    <b>1) ".translate("Text Link")."</b><br /><br />

    ".translate("One way to link to the rating form is through a simple text link:")."<br /><br />
    <center><a href=\"download.php?op=ratedownload&amp;lid=$lid\">".translate("Rate this Resource")." @ $sitename</a></center><br /><br />
    <center>".translate("The HTML code you should use in this case, is the following:")."</center><br />
    <center><i>&lt;a href=\"download.php?op=ratedownload&lid=$lid\"&gt;".translate("Rate this Resource")."&lt;/a&gt;</i></center>
    <br /><br />
    ".translate("The Number")." \"$lid\" ".translate("in the HTML source references your site's ID number in $sitename database.  Be sure this number is present.")."<br /><br />

    <b>2) ".translate("Button Link")."</b><br /><br />

    ".translate("If you're looking for a little more than a basic text link, you may wish to use a small button link:")."<br /><br />

    <center>
    <form action=\"download.php\" method=\"post\">\n
    <input type=\"hidden\" name=\"lid\" value=\"$lid\">\n
    <input type=\"hidden\" name=\"op\" value=\"ratedownload\">\n
    <input class=\"button\" type=\"submit\" value=\"".translate("Rate this Site!")."\">\n
    </form>\n
    </center>

    <center>".translate("The source code for the above button is:")."</center><br /><br />

    <table border=\"0\" align=\"center\"><tr><td align=\"left\"><i>
    &lt;form action=\"download.php\" method=\"post\"&gt;<br />\n
    &nbsp;&nbsp;&lt;input type=\"hidden\" name=\"lid\" value=\"$lid\"&gt;<br />\n
    &nbsp;&nbsp;&lt;input type=\"hidden\" name=\"op\" value=\"ratedownload\"&gt;<br />\n
    &nbsp;&nbsp;&lt;input type=\"submit\" value=\"".translate("Rate this Site!")."\"&gt;<br />\n
    &lt;/form&gt;\n
    </i></td></tr></table>

    <br /><br />

    <b>3) ".translate("Remote Rating Form")."</b><br /><br />

    ".translate("If you cheat on this, we'll remove your link. Having said that, here is what the current remote rating form looks like.")."

    <center>
    <form method=\"post\" action=\"download.php\">
    <table align=\"center\" border=\"0\" width=\"175\" cellspacing=\"0\" cellpadding=\"0\">
    <tr><td align=\"center\"><b>".translate("Vote for this Site!")."</b></a></td></tr>
    <tr><td>
    <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
    <tr><td valign=\"top\">
        <select name=\"rating\">
        <option selected>--</option>
    <option>10</option>
    <option>9</option>
    <option>8</option>
    <option>7</option>
    <option>6</option>
    <option>5</option>
    <option>4</option>
    <option>3</option>
    <option>2</option>
    <option>1</option>
    </select>
    </td><td valign=\"top\">
    <input type=\"hidden\" name=\"ratinglid\" value=\"$lid\">
        <input type=\"hidden\" name=\"ratinguser\" value=\"outside\">
        <input type=\"hidden\" name=\"op value=\"addrating\">
    <input class=\"button\" type=\"submit\" value=\"".translate("Vote!")."\">
    </td></tr></table>
    </td></tr></table></form>

    <br />".translate("Using this form will allow users to rate your resource directly from your site and the rating will be recorded here. The above form is disabled, but the following source code will work if you simply cut and paste it into your web page. The source code is shown below:")."<br /><br /></center>

    <blockquote><i>
    &lt;form method=\"post\" action=\"download.php\"&gt;<br />
    &lt;table align=\"center\" border=\"0\" width=\"175\" cellspacing=\"0\" cellpadding=\"0\"&gt;<br />
        &lt;tr&gt;&lt;td align=\"center\"&gt;&lt;b&gt;".translate("Vote for this Site")."&lt;/b&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;<br />
        &lt;tr&gt;&lt;td&gt;<br />
        &lt;table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"&gt;<br />
        &lt;tr&gt;&lt;td valign=\"top\"&gt;<br />
            &lt;select name=\"rating\"&gt;<br />
            &lt;option selected&gt;--&lt;/option&gt;<br />
        &lt;option&gt;10&lt;/option&gt;<br />
        &lt;option&gt;9&lt;/option&gt;<br />
        &lt;option&gt;8&lt;/option&gt;<br />
        &lt;option&gt;7&lt;/option&gt;<br />
        &lt;option&gt;6&lt;/option&gt;<br />
        &lt;option&gt;5&lt;/option&gt;<br />
        &lt;option&gt;4&lt;/option&gt;<br />
        &lt;option&gt;3&lt;/option&gt;<br />
        &lt;option&gt;2&lt;/option&gt;<br />
        &lt;option&gt;1&lt;/option&gt;<br />
        &lt;/select&gt;<br />
        &lt;/td&gt;&lt;td valign=\"top\"&gt;<br />
        &lt;input type=\"hidden\" name=\"ratinglid\" value=\"$lid\"&gt;<br />
            &lt;input type=\"hidden\" name=\"ratinguser\" value=\"outside\"&gt;<br />
            &lt;input type=\"hidden\" name=\"op\" value=\"addrating\"&gt;<br />
        &lt;input type=\"submit\" value=\"".translate("Vote!")."\"&gt;<br />
        &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;<br />
    &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;<br />
    &lt;/form&gt;<br />
    </i></blockquote>
    <br /><br /><center>
    ".translate("Thanks! and good luck with your ratings!")."<br /><br />
    - $sitename ".translate("Staff")."
    <br /><br /></center>";
    CloseTable();
    include("footer.php");
}

function brokendownload($lid) {
    global $anonymous;
    include("header.php");
    include("admin/download/config.inc.php");
    global $mpnTables;
    if(_MPN_USER) {
    //    $user2 = base64_decode($user);
    //$cookie = explode(":", $user2);
    $cookie = cookiedecode($user);
    $ratinguser = $cookie[1];
    } else {
    $ratinguser = $anonymous;
    }
    menu();

    echo "<h2>" . translate ( 'Report Broken Link' ) . "</h2>\n";

    echo "<br />";

    OpenTable();

    echo "<div class='center'>\n";

    echo "<form action=\"download.php\" method=\"post\">";
    echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">";
    echo "<input type=\"hidden\" name=\"modifysubmitter\" value=\"$ratinguser\">";

    // Kiril: New Sanitizer

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

    // End Sanitizer

    echo "".translate("Thank you for helping to maintain this directory's integrity.")."<br />".translate("For security reasons your user name and IP address will also be temporarily recorded.")."<br /><br />";
    echo "<input type=\"hidden\" name=\"op\" value=\"brokendownloadS\"><input class=\"button\" type=\"submit\" value=\"".translate("Report Broken Link")."\"></center></form>";

    echo "</div>\n";

    CloseTable();

    include("footer.php");
}

function brokendownloadS($lid, $modifysubmitter) {
    include("admin/download/config.inc.php");
    global $mpnTables, $user, $anonymous;
    if(_MPN_USER) {
    //$user2 = base64_decode($user);
    //$cookie = explode(":", $user2);
    $cookie = cookiedecode($user);
    $ratinguser = $cookie[1];
    } else {
    $ratinguser = "$anonymous";
    }
    mysql_query("insert into ".$mpnTables['downloads_modrequest']." values (NULL, $lid, 0, 0, '', '', '', '$ratinguser', 1, '$auth_name', '$email', '$filesize', '$version', '$homepage')");
    include("header.php");
    menu();
    echo "<br />";
    OpenTable();
    echo "<br /><center>".translate("Thanks for the information.")."<br /><br />".translate("We'll look into your request shortly.")."</center><br />";
    CloseTable();
    include("footer.php");
}

function modifydownloadrequest($lid) {
    include("header.php");
    global $mpnTables, $user, $anonymous;
    if(_MPN_USER) {
        //$user2 = base64_decode($user);
    //$cookie = explode(":", $user2);
    $cookie = cookiedecode($user);
    $ratinguser = $cookie[1];
    } else {
    $ratinguser = "$anonymous";
    }
    menu();
    echo "<br />";
    OpenTable();
    $blocknow = 0;
    if (isset($blockunregmodify) && $blockunregmodify == 1 && $ratinguser=="$anonymous") {
    echo "<br /><br /><center>".translate("Only Registered Users May submit requests to Modify a Download")."</center>";
    $blocknow = 1;
    }
    if ($blocknow != 1) {
        $result = mysql_query("select cid, sid, title, url, description, name, email, filesize, version, homepage from ".$mpnTables['downloads_downloads']." where lid=$lid");
        echo "<center><font class=\"option\"><b>".translate("Request Download Modification")."</b></font><br /><font class=\"content\"></center>";
        while(list($cid, $sid, $title, $url, $description, $auth_name, $email, $filesize, $version, $homepage) = mysql_fetch_row($result)) {

            // Kiril: Start New Sanitizer

            $sanity_ary = compact( 'title', 'url', 'description', 'auth_name', 'email', '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=\"download.php\" method=\"post\">"
            ."<table border=1>"
            ."<tr><td class=w30>".translate("Download ID").":</td><td><b>$lid</b></td></tr>\n"
            ."<tr><td>".translate("Program Name").":</td><td><input type=\"text\" name=\"title\" value=\"$title\" size=\"60\" maxlength=\"100\"></td></tr>\n"
            ."<tr><td>".translate("URL").":</td><td><input type=\"text\" name=\"url\" value=\"$url\" size=\"60\" maxlength=\"100\"></td></tr>\n"
            ."<tr><td valign='top'>".translate("Description").":</td><td><textarea name=\"description\" cols=\"60\" rows=\"10\">$description</textarea></td></tr>\n";
        $result2=mysql_query("select cid, title from ".$mpnTables['downloads_categories']." order by title");
        echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">"
        ."<input type=\"hidden\" name=\"modifysubmitter\" value=\"$ratinguser\">"
        ."<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"
        ."<tr><td>".translate("Author's Name").":</td><td><input type=\"text\" name=\"auth_name\" value=\"$auth_name\" size=\"60\" maxlength=\"80\"></td></tr>\n"
        ."<tr><td>".translate("Author's Email").":</td><td><input type=\"text\" name=\"email\" value=\"$email\" size=\"60\" maxlength=\"80\"></td></tr>\n"
        ."<tr><td>".translate("Filesize").": (".translate("in bytes").")</td><td><input type=\"text\" name=\"filesize\" value=\"$filesize\" size=\"12\" maxlength=\"11\"></td></tr>\n"
        ."<tr><td>".translate("Version").":</td><td><input type=\"text\" name=\"version\" value=\"$version\" size=\"11\" maxlength=\"10\"></td></tr>\n"
        ."<tr><td>".translate("HomePage").":</td><td><input type=\"text\" name=\"homepage\" value=\"$homepage\" size=\"60\" maxlength=\"200\"></td></tr>\n"
        ."</table>\n<br />\n";
        // Kiril: New Sanitizer

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

        // End Sanitizer

        echo "<input type=\"hidden\" name=\"op\" value=\"modifydownloadrequestS\">"
        ."<input class=\"button\" type=\"submit\" value=\"".translate("Send Request")."\"></form>";
        }
    }
    CloseTable();
    include("footer.php");
}

function modifydownloadrequestS($lid, $cat, $title, $url, $description, $modifysubmitter, $auth_name, $email, $filesize, $version, $homepage) {
    include("admin/download/config.inc.php");
    global $mpnTables, $user, $anonymous;
    if(_MPN_USER) {
    //$user2 = base64_decode($user);
    //$cookie = explode(":", $user2);
    $cookie = cookiedecode($user);
    $ratinguser = $cookie[1];
    } else {
    $ratinguser = "$anonymous";
    }
    $blocknow = 0;
    if ($blockunregmodify == 1 && $ratinguser=="$anonymous") {
    include("header.php");
    menu();
    echo "<br />";
    OpenTable();
    echo "<center><font class=\"content\">".translate("Only Registered Users May submit requests to Modify a Download")."</font></center>";
    $blocknow = 1;
    CloseTable();
    include("footer.php");
    }
    if ($blocknow != 1) {
        $cat = explode("-", $cat);
        if ($cat[1]=="") {
            $cat[1] = 0;
        }

        // 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 Email

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

        unset( $check_ary, $verify_check_ary );


        /*$title = stripslashes(FixQuotes($title));
        $url = stripslashes(FixQuotes($url));
        $description = stripslashes(FixQuotes($description));*/


        mysql_query("insert into ".$mpnTables['downloads_modrequest']." values (NULL, $lid, $cat[0], $cat[1], '$title', '$url', '$description', '$ratinguser', 0, '$auth_name', '$email', '$filesize', '$version', '$homepage')");
        include("header.php");
    menu();
    echo "<br />";
    OpenTable();
        echo "<center><font class=\"content\">".translate("Thanks for the information")." ".translate("We'll look into your request shortly.")."</font></center>";
        CloseTable();
    include("footer.php");
    }
}

function rateinfo($lid) {
    global $mpnTables;
    mysql_query("update ".$mpnTables['downloads_downloads']." set hits=hits+1 where lid=$lid");
    $result = mysql_query("select url from ".$mpnTables['downloads_downloads']." where lid=$lid");
    list($url) = mysql_fetch_row($result);
    $_SERVER['F_LIB'] -> redirectRequest( $url );
}

function addrating($ratinglid, $ratinguser, $rating, $ratinghost_name, $ratingcomments) {
    global $mpnTables, $cookie, $user, $anonymous;
    $passtest = "yes";
    include("header.php");
    include("admin/download/config.inc.php");
    completevoteheader();
    if(_MPN_USER) {
    //$user2 = base64_decode($user);
    //$cookie = explode(":", $user2);
    $cookie = cookiedecode($user);
    $ratinguser = $cookie[1];
    } else if ($ratinguser=="outside") {
    $ratinguser = "outside";
    } else {
    $ratinguser = "$anonymous";
    }
    $results3 = mysql_query("SELECT title FROM ".$mpnTables['downloads_downloads']." WHERE lid=$ratinglid");
    while(list($title)=mysql_fetch_row($results3)){ $ttitle = stripslashes( $title ); }
    /* Make sure only 1 anonymous from an IP in a single day. */
    $ip = getenv("REMOTE_HOST");
    if (empty($ip)) {
       $ip = getenv("REMOTE_ADDR");
    }
    /* Check if Rating is Null */
    if ($rating=="--") {
    $error = "nullerror";
        completevote($error);
    $passtest = "no";
    }
    /* Check if Download POSTER is voting (UNLESS Anonymous users allowed to post) */
    if ($ratinguser != $anonymous && $ratinguser != "outside") {
        $result=mysql_query("select submitter from ".$mpnTables['downloads_downloads']." where lid=$ratinglid");
        while(list($ratinguserDB)=mysql_fetch_row($result)) {
            $ratinguserDB = stripslashes( $ratinguserDB );
            if ($ratinguserDB==$ratinguser) {
            $error = "postervote";
                completevote($error);
        $passtest = "no";
            }
    }
    }
    /* Check if REG user is trying to vote twice. */
    if ($ratinguser!=$anonymous && $ratinguser != "outside") {
        $result=mysql_query("select ratinguser from ".$mpnTables['downloads_votedata']." where ratinglid=$ratinglid");
        while(list($ratinguserDB)=mysql_fetch_row($result)) {
            $ratinguserDB = stripslashes( $ratinguserDB );
            if ($ratinguserDB==$ratinguser) {
                $error = "regflood";
                completevote($error);
        $passtest = "no";
        }
        }
    }
    /* Check if ANONYMOUS user is trying to vote more than once per day. */
    if ($ratinguser==$anonymous){
        $yesterdaytimestamp = (time()-(86400 * $anonwaitdays));
        $ytsDB = Date("Y-m-d H:i:s", $yesterdaytimestamp);
        $result=mysql_query("select * FROM ".$mpnTables['downloads_votedata']." WHERE ratinglid=$ratinglid AND ratinguser='$anonymous' AND ratinghostname = '$ip' AND TO_DAYS(NOW()) - TO_DAYS(ratingtimestamp) < $anonwaitdays");
        $anonvotecount = @mysql_num_rows($result);
        if ($anonvotecount >= 1) {
            $error = "anonflood";
            completevote($error);
            $passtest = "no";
        }
    }
    /* Check if OUTSIDE user is trying to vote more than once per day. */
    if ($ratinguser=="outside"){
        $yesterdaytimestamp = (time()-(86400 * $outsidewaitdays));
        $ytsDB = Date("Y-m-d H:i:s", $yesterdaytimestamp);
        $result=mysql_query("select * FROM ".$mpnTables['downloads_votedata']." WHERE ratinglid=$ratinglid AND ratinguser='outside' AND ratinghostname = '$ip' AND TO_DAYS(NOW()) - TO_DAYS(ratingtimestamp) < $outsidewaitdays");
        $outsidevotecount = mysql_num_rows($result);
        if ($outsidevotecount >= 1) {
            $error = "outsideflood";
            completevote($error);
            $passtest = "no";
        }
    }
    /* Passed Tests */
    if ($passtest == "yes") {
        //$comment = stripslashes(FixQuotes($comment));
        /* All is well.  Add to Line Item Rate to DB. */
     mysql_query("INSERT into ".$mpnTables['downloads_votedata']." values (NULL,'$ratinglid', '$ratinguser', '$rating', '$ip', '$ratingcomments', now())");
    /* All is well.  Calculate Score & Add to Summary (for quick retrieval & sorting) to DB. */
    /* NOTE: If weight is modified, ALL downloads need to be refreshed with new weight. */
    /*   Running a mysql statement with your modded calc for ALL downloads will accomplish this. */
        $voteresult = mysql_query("select rating, ratinguser, ratingcomments FROM ".$mpnTables['downloads_votedata']." WHERE ratinglid = $ratinglid");
    $totalvotesDB = mysql_num_rows($voteresult);
    include ("voteinclude.php");
        mysql_query("UPDATE ".$mpnTables['downloads_downloads']." SET downloadratingsummary=$finalrating,totalvotes=$totalvotesDB,totalcomments=$truecomments WHERE lid = $ratinglid");
        $error = "none";
        completevote($error);
    }
    completevotefooter($ratinglid, $ttitle, $ratinguser);
    include("footer.php");
}

function completevoteheader(){
    menu();
    echo "<br />";
    OpenTable();
}

function completevotefooter($lid, $ttitle, $ratinguser) {
    global $sitename, $mpnTables;
    include("admin/download/config.inc.php");
    $result = mysql_query("select url FROM ".$mpnTables['downloads_downloads']." WHERE lid=$lid");
    list($url)=mysql_fetch_row($result);
    echo "<font class=\"content\">".translate("Thank you for taking the time to rate a site here at")." $sitename. ".translate("Input from users such as yourself will help other visitors better decide which downloads to click on.")."</font><br /><br /><br />";
    if ($ratinguser=="outside") {
    echo "<center><font class=\"content\">".WEAPPREACIATE." $sitename!<br /><a href=\"$url\">".translate("Return to")." $ttitle</a></font><center><br /><br />";
        $result=mysql_query("select title FROM ".$mpnTables['downloads_downloads']." where lid=$lid");
        list($title)=mysql_fetch_row($result);
        $ttitle = ereg_replace (" ", "_", stripslashes( $title ));
    }
    echo "<center>";
    downloadinfomenu($lid);
    echo "</center>";
    CloseTable();
}

function completevote($error) {
    include("admin/download/config.inc.php");
    if ($error == "none") echo "<center><font class=\"content\"><b>".translate("Your vote is appreciated.")."</b></font></center>";
    if ($error == "anonflood") echo "<center><font class=\"option\"><b>".translate("You have already voted for this resource in the past $anonwaitdays day(s).")."</b></font></center><br />";
    if ($error == "regflood") echo "<center><font class=\"option\"><b>".translate("Vote for a resource only once.<br />All votes are logged and reviewed.")."</b></font></center><br />";
    if ($error == "postervote") echo "<center><font class=\"option\"><b>".translate("You cannot vote on a link you submitted.<br />All votes are logged and reviewed.")."</b></font></center><br />";
    if ($error == "nullerror") echo "<center><font class=\"option\"><b>".translate("No rating selected - no vote tallied")."</b></font></center><br />";
    if ($error == "outsideflood") echo "<center><font class=\"option\"><b>".translate("Only one vote per IP address allowed every $outsidewaitdays day(s).")."</b></font></center><br />";
}

function ratedownload($lid, $user )
{
    $ttitle = getTitle( $lid, translate( 'Rating' ) );

    include("header.php");
    menu();
    echo "<br />";
    OpenTable();
    $transfertitle = ereg_replace ("_", " ", $ttitle);
    $displaytitle = $transfertitle;
    global $mpnTables, $cookie, $datetime, $anonymous;
    $ip = getenv("REMOTE_HOST");
    if (empty($ip)) {
       $ip = getenv("REMOTE_ADDR");
    }
    echo "<b>".stripslashes($displaytitle)."</b>"
    ."<ul><font class=\"content\">"
    ."<li>".translate("Please do not vote for the same resource more than once.").""
    ."<li>".translate("The scale is 1 - 10, with 1 being poor and 10 being excellent.").""
    ."<li>".translate("Please be objective in your vote, if everyone receives a 1 or a 10, the ratings aren't very useful.").""
    ."<li>".translate("You can view a list of the ")."<a href=\"download.php?op=TopRated\">".translate("Top Rated Resources")."</a>."
    ."<li>".translate("Do not vote for your own resource or a competitor's.")."";
    if(_MPN_USER) {
        //$user2 = base64_decode($user);
    //$cookie = explode(":", $user2);
    echo "<li>".translate("You are a registered user and are logged in.").""
        ."<li>".translate("Feel free to add a comment about this site.")."";
    $cookie = cookiedecode($user);
    $auth_name = $cookie[1];
    } else {
    echo "<li>".translate("You are not a registered user or you have not logged in.").""
        ."<li>".translate("If you were registered you could make comments on this website.")."";
    $auth_name = "$anonymous";
    }
    echo "</ul>"
        ."<form method=\"post\" action=\"download.php\">"
        ."<table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"100%\">"
        ."<tr><td width=\"25\" nowrap></td>"
        ."<tr><td width=\"25\" nowrap></td><td width=\"550\">"
        ."<input type=\"hidden\" name=\"ratinglid\" value=\"$lid\">"
        ."<input type=\"hidden\" name=\"ratinguser\" value=\"$auth_name\">"
        ."<input type=\"hidden\" name=\"ratinghost_name\" value=\"$ip\">"
        ."<font class=content>".translate("Rate this Resource").""
        ."<select name=\"rating\">"
        ."<option>--</option>"
        ."<option>10</option>"
        ."<option>9</option>"
    ."<option>8</option>"
        ."<option>7</option>"
        ."<option>6</option>"
        ."<option>5</option>"
        ."<option>4</option>"
        ."<option>3</option>"
        ."<option>2</option>"
        ."<option>1</option>"
        ."</select></font>"
    ."<font class=\"content\"><input class=\"button\" type=\"submit\" value=\"".translate("Rate this Resource")."\"></font>"
        ."<br /><br />";
    if(_MPN_USER) {
    echo "<b>".translate("Comments").":</b><br /><textarea wrap=\"virtual\" cols=\"50\" rows=\"10\" name=\"ratingcomments\"></textarea>"
        ."<br /><br /><br />"
            ."</font>";
    } else {
    echo"<input type=\"hidden\" name=\"ratingcomments\" value=\"\">";
    }

    // Kiril: New Sanitizer

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

    // End Sanitizer

    echo "</td></tr></table></form>";
    echo "<center>";
    downloadfooterchild($lid);
    echo "</center>";
    CloseTable();
    include("footer.php");
}

function CoolSize($size) {
    $mb = 1024*1024;
    if ( $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;
}

function getTitle( $lid, $prefix )
{
    global $mpnTables;

    $sql = "SELECT title FROM " . $mpnTables['downloads_downloads'] . " WHERE lid = '$lid'";

    $result = mysql_query( $sql );

    if ( ! ( $tmp = mysql_fetch_row( $result ) ) )
    {
        $title = $prefix . translate( 'This Download' );
    }
    else
    {
        $title = $tmp[0];
    }

    mysql_free_result( $result );

    return stripslashes( $title );
}


if (isset($ratinglid) && isset ($ratinguser) && isset ($rating)) {
    $ret = addrating($ratinglid, $ratinguser, $rating, $ratinghost_name, $ratingcomments);
    exit();
}

if (!isset($op))
{
    $op = null;
}

switch($op) {

    case "menu":
    menu($maindownload);
    break;

    case "AddDownload":
    AddDownload();
    break;

    case "NewDownloads":
    if (!isset($newdownloadshowdays))
    {
        $newdownloadshowdays = null;
    }

    NewDownloads($newdownloadshowdays);
    break;

    case "NewDownloadsDate":
    NewDownloadsDate($selectdate);
    break;

    case "CoolSize":
    CoolSize($size);
    break;

    case "TopRated":
    if (!isset($ratenum))
    {
        $ratenum = null;
    }

    if (!isset($ratetype))
    {
        $ratetype = null;
    }

    TopRated($ratenum, $ratetype);
    break;

    case "MostPopular":
    if (!isset($ratenum))
    {
        $ratenum = null;
    }

    if (!isset($ratetype))
    {
        $ratetype = null;
    }

    MostPopular($ratenum, $ratetype);
    break;

    case "viewdownload":
    if (!isset($min))
    {
        $min = null;
    }

    if (!isset($orderby))
    {
        $orderby = null;
    }

    if (!isset($show))
    {
        $show = null;
    }
    viewdownload($cid, $min, $orderby, $show);
    break;

    case "viewsdownload":
    if (!isset($min))
    {
        $min = null;
    }

    if (!isset($orderby))
    {
        $orderby = null;
    }

    if (!isset($show))
    {
        $show = null;
    }

    viewsdownload($sid, $min, $orderby, $show);
    break;

    case "brokendownload":
    brokendownload($lid);
    break;

    case "modifydownloadrequest":
    modifydownloadrequest($lid);
    break;

    case "modifydownloadrequestS":
    modifydownloadrequestS($lid, $cat, $title, $url, $description, $modifysubmitter, $auth_name, $email, $filesize, $version, $homepage);
    break;

    case "brokendownloadS":
    brokendownloadS($lid, $modifysubmitter);
    break;

    case "getit":
    getit($lid);
    break;

    case "Add":
    Add($title, $url, $auth_name, $cat, $description, $email, $filesize, $Version, $homepage);
    break;

    case "search":
    if (!isset($min))
    {
        $min = null;
    }

    if (!isset($orderby))
    {
        $orderby = null;
    }

    if (!isset($show))
    {
        $show = null;
    }

    search($query, $min, $orderby, $show);
    break;

    case "rateinfo":
    rateinfo($lid);
    break;

    case "ratedownload":
    ratedownload($lid, $user);
    break;

    case "addrating":
    addrating($ratinglid, $ratinguser, $rating, $ratinghost_name, $ratingcomments, $user);
    break;

    case "viewdownloadcomments":
    viewdownloadcomments($lid);
    break;

    case "outsidedownloadsetup":
    outsidedownloadsetup($lid);
    break;

    case "viewdownloadeditorial":
    viewdownloadeditorial($lid);
    break;

    case "viewdownloaddetails":
    viewdownloaddetails($lid);
    break;

    default:
    index();
    break;

}

?>
