<?php

/*-------------------------------------------------------+

| PHP-Fusion Content Management System

| Copyright (C) 2002 - 2008 Nick Jones

| http://www.php-fusion.co.uk/

+--------------------------------------------------------+

| Filename: downloads.php

| Author: Nick Jones (Digitanium)

+--------------------------------------------------------+

| This program is released as free software under the

| Affero GPL license. You can redistribute it and/or

| modify it under the terms of this license which you

| can read by viewing the included agpl.txt or online

| at www.gnu.org/licenses/agpl.html. Removal of this

| copyright header is strictly prohibited without

| written permission from the original author(s).

+--------------------------------------------------------*/

require_once "maincore.php";

require_once THEMES."templates/header.php";

include LOCALE.LOCALESET."downloads.php";



add_to_title($locale['global_200'].$locale['400']);



[color=#ff0033]$type_id= $_GET['type_id'];

$cat_id= $_GET['cat_id'];

[/color]

if (isset($_GET['download_id']) && isnum($_GET['download_id'])) {

        $res = 0;

        if ($data = dbarray(dbquery("SELECT download_url,download_cat FROM ".DB_DOWNLOADS." WHERE download_id='".$_GET['download_id']."'"))) {

                $cdata = dbarray(dbquery("SELECT * FROM ".DB_DOWNLOAD_CATS." WHERE download_cat_id='".$data['download_cat']."'"));

                if (checkgroup($cdata['download_cat_access'])) {

                        $res = 1;

                        $result = dbquery("UPDATE ".DB_DOWNLOADS." SET download_count=download_count+1 WHERE download_id='".$_GET['download_id']."'");

                        redirect($data['download_url']);

                }

        }

        if ($res == 0) { redirect("downloads.php"); }

}



if (!isset($_GET['cat_id']) || !isnum($_GET['cat_id'])) {

        opentable($locale['400']);

        $result = dbquery("SELECT * FROM ".DB_DOWNLOAD_CATS." WHERE ".groupaccess('download_cat_access')." ORDER BY download_cat_name");

        $rows = dbrows($result);

        if ($rows) {

                $counter = 0; $columns = 2; 

                echo "<table cellpadding='0' cellspacing='0' width='100%'><img style='margin:5px' align='left' src='".IMAGES."download1.png' height='48' width='48'><a href='".BASEDIR."forum/viewthread.php?forum_id=9&thread_id=9'><b>".$locale['401']."</b></a><br><span class='small'>".$locale['402']."</span><hr>\n<tr>\n";

                echo "<table cellpadding='0' cellspacing='0' width='100%'>\n<tr>\n";

                while ($data = dbarray($result)) {

                        if ($counter != 0 && ($counter % $columns == 0)) { echo "</tr>\n<tr>\n"; }

                        $num = dbcount("(download_cat)", DB_DOWNLOADS, "download_cat='".$data['download_cat_id']."'");

                        echo "<td valign='top' width='50%' class='tbl'><img style='margin:3px' align='left' src='".IMAGES."download.png' height='32' width='32'> <a href='".FUSION_SELF."?cat_id=".$data['download_cat_id']."'>".$data['download_cat_name']."</a> <span class='small2'>($num)</span>";

                        if ($data['download_cat_description'] != "") { echo "<br />\n<span class='small'>".$data['download_cat_description']."</span>"; }

                        echo "</td>\n" ;

                        $counter++;

                }

                echo "</tr>\n<div align='right'><b>RSS</b> <a href='".BASEDIR."download_feed/news.php'><img style='vertical-align:middle' src='".BASEDIR."images/feed.png' border='0' title='rss feed' alt='' /></a></div></table>\n";

        } else {

                echo "<div style='text-align:center'><br />\n".$locale['430']."<br /><br />\n</div>\n";

        }

        closetable();

} else {

        $res = 0;

        $result = dbquery("SELECT * FROM ".DB_DOWNLOAD_CATS." WHERE download_cat_id='".$_GET['cat_id']."'");

        if (dbrows($result) != 0) {

                $cdata = dbarray($result);

                if (checkgroup($cdata['download_cat_access'])) {

                        $res = 1;

                        add_to_title($locale['global_201'].$cdata['download_cat_name']);



[color=#ff0033]                echo "<table width='100%' align='center' cellspacing='0' cellpadding='0' border='0'>\n";

                echo "<form name='' method='post' action='".FUSION_SELF."?cat_id=".$_GET['cat_id']."&rowstart=".$_GET['rowstart']."'>\n";

                echo "<tr><td valign=top class='tbl'>\n";

                echo "<input type='submit' name='type' value='Order by' class='button'>&nbsp;&nbsp;\n";

                echo "<input type='radio' name='type_id' value='2'".($type_id == "2" ? " checked" : "")."> Popularity&nbsp;&nbsp;\n";

                echo "<input type='radio' name='type_id' value='3'".($type_id == "3" ? " checked" : "")."> Date&nbsp;&nbsp;\n";

                echo "<input type='radio' name='type_id' value='1'".($type_id == "1" ? " checked" : "")."> Name\n";

            echo "</td></tr>\n";

                echo "</form></table>\n";

                if ($cat_id > 0) { $where = " WHERE download_cat='".$cat_id."'";} else { $where = "";}

                if ($type_id == 2) { $order = " download_count DESC";}

                elseif ($type_id == 3) { $order = " download_datestamp DESC";}

                else { $order = " download_title ASC";}

                

                        opentable($locale['400'].": ".$cdata['download_cat_name']);

                        echo" <div align='right'><a href='javascript:history.back()'><img src='".BASEDIR."images/back.gif' border='0' alt=''></a></div>";

                        $rows = dbcount("(*)", DB_DOWNLOADS, "download_cat='".$_GET['cat_id']."'");

                        if (!isset($_GET['rowstart']) || !isnum($_GET['rowstart'])) { $_GET['rowstart'] = 0; }

                        if ($rows != 0) {



                                if ($cat_id > 0) { $where2 = " AND download_cat ='".$cat_id."'";} else { $where2 = "";}

                                $myquery =" SELECT tu.*, tn.*, download_cat_id, download_cat_name FROM ".$db_prefix."download_cats tn

                                        LEFT JOIN ".$db_prefix."downloads tu ON tn.download_cat_id=tu.download_cat

                                        WHERE download_id!=''".$where2." ORDER BY download_title ASC,".$order." LIMIT ".$_GET['rowstart'].",15";

                                $result = dbquery($myquery);[/color]



                                //$result = dbquery("SELECT * FROM ".DB_DOWNLOADS." WHERE download_cat='".$_GET['cat_id']."' ORDER BY ".$order." LIMIT ".$_GET['rowstart'].",15");

                                $numrows = dbrows($result); $i = 1;

                                while ($data = dbarray($result)) {

                                        if ($data['download_datestamp'] + 604800 > time() + ($settings['timeoffset'] * 3600)) {

                                                $new = " <span class='small'>".$locale['410']."</span>";

                                        } else {

                                                $new = "";

                                        }

                                        echo "<table width='100%' cellpadding='0' cellspacing='1' class='tbl-border'>\n";

                                        echo "<tr>\n<td colspan='3' class='forum-caption'><strong>".$data['download_title']."</strong> $new</td>\n</tr>\n";

                                        if ($data['download_description']) { echo "<tr>\n<td colspan='3' class='tbl1'>".nl2br(stripslashes($data['download_description']))."</td>\n</tr>\n"; }

                                        echo "<tr>\n<td width='30%' class='tbl2'><strong>".$locale['411']."</strong> ".$data['download_license']."</td>\n<td width='30%' class='tbl1'><strong>".$locale['412']."</strong> ".$data['download_os']."</td>\n";

                                        echo "<td width='40%' class='tbl2'><strong>".$locale['413']."</strong> ".$data['download_version']."</td>\n</tr>\n<tr>\n<td width='30%' class='tbl2'><strong>".$locale['414']."</strong> ".showdate("shortdate", $data['download_datestamp'])."</td>\n";

                                        echo "<td width='30%' class='tbl1'><strong>".$locale['415']."</strong> ".$data['download_count']."</td>\n<td width='40%' class='tbl2'>";



if (iMEMBER){

echo "<a href='".FUSION_SELF."?cat_id=".$_GET['cat_id']."&download_id=".$data['download_id']."' target='_blank'>".$locale['416']."</a> (".$data['download_filesize'].")";



}else{



echo "<a href='".BASEDIR."register.php'><b>".$locale['417']."</b></a>";



}







echo"</td>\n</tr>\n";

                                        echo "</table>\n";

                                        if ($i != $numrows) { echo "<div style='text-align:center'><img src='".get_image("blank")."' alt='' height='15' width='1' /></div>\n"; $i++; }

                                }

echo" <div align='right'><a href='javascript:history.back()'><img src='".BASEDIR."images/back.gif' border='0' alt=''></a></div>";

                                closetable();

                                if ($rows > 15) { echo "<div align='center' style=';margin-top:5px;'>\n".makepagenav($_GET['rowstart'], 15, $rows, 3, FUSION_SELF."?cat_id=".$_GET['cat_id']."&")."\n</div>\n"; }

                        } else {

                                echo $locale['431']."\n";

                                closetable();

                        }

                }

        }

        if ($res == 0) { redirect(FUSION_SELF); }

}



require_once THEMES."templates/footer.php";

?>