<?php

#############################################################################
#                              Site@School Download module
# Site@School is a website management system designed for schools.
# This is a downloads module which can be used in Site@School.
#
# coded by Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# download_cat.php: last changed 15/09/2005  version 1.0.4
#                   by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: download_cat.php,v 1.1 2006/10/03 09:08:00 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
# Copyright (C) 2002 - 2005 Municipality of Amsterdam, City District
#  'de Baarsjes', Amsterdam, the Netherlands.
#
# 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, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
##############################################################################
if (!defined('IN_SAS'))
{
	die("Hacking attempt");
}

if (IsSet ($_GET['dwnl_category']))
{
	$dwnl_category = $_GET['dwnl_category'];
}

load_language($cmsdir . '/', 'sn_downloads'); //load language file

$date_format = $sas_config['dateformat'];

$query = "SELECT dbtables FROM $table_modules WHERE location='sn_downloads'";
$result = mysql_query($query) or die_script($query, mysql_error());
$moduletables = mysql_result($result, 0);
unset ($query);
unset ($result);
$moduletables = explode(",", $moduletables);
$downloads_table = "$moduletables[0]";
$downloads_cattable = "$moduletables[1]";

if ($_SESSION['site'] == "protected")
{
	print $sas_config['download_welcome_text_prot'] . "<br>";
	$query = "SELECT id, title FROM $downloads_cattable WHERE ispage= '0' AND public = '1' ORDER BY title";
}
else
{
	print $sas_config['download_welcome_text'] . "<br>";
	$query = "SELECT id, title FROM $downloads_cattable WHERE ispage= '0' AND public = '0' ORDER BY title";
}

$result = mysql_query($query) or die_script($query, mysql_error());
while ($download_list = mysql_fetch_array($result))
{
	if ($download_list[0] == $dwnl_category)
	{
		$query1 = "SELECT title FROM $downloads_cattable where id='$dwnl_category'"; // get category name
		$result1 = mysql_query($query1) or die_script($query1, mysql_error());
		$category_name = mysql_result($result1, 0);
		unset ($query1);
		unset ($result1);
		print $sas_lang['download_module_available_files'] . " <b>$category_name</b> <p>";
		$query3 = "SELECT id, description, category, creator, filename, date_format(date,'$date_format  %H:%i') AS Readable_Date 
						   FROM $downloads_table WHERE category='$dwnl_category' ORDER BY date DESC";
		$result3 = mysql_query($query3) or die_script($query3, mysql_error());
		print "<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\">
				  <tr>
				  <td width=20%><font size=2><b>" . $sas_lang['download_module_filename'] . "</b></font></td>
				  <td width=50%><font size=2><b>" . $sas_lang['download_module_description'] . "</b></font></td>
				  <td width=12%><font size=2><b>" . $sas_lang['download_module_creator'] . "</b></font></td>
				  <td width=18%><font size=2><b>" . $sas_lang['download_module_updated'] . "</b></font></td>
				  </tr>";
		while ($download_list = mysql_fetch_array($result3))
		{
			$download_list[1] = str_replace("\n", "<br>", $download_list[1]);
			print "<tr><td valign=top>
						<a href=\"$cmsdir/modules/sn_downloads/download.php?dwnl_id=$download_list[0]&cat_id=$download_list[2]\"><b><font size=2>$download_list[4]</font></b></a></td>";

			print "<td valign=top><font size=2>$download_list[1]</td>
						<td valign=top><font size=2>$download_list[3]</td>
						<td valign=top><font size=2>$download_list[5]</td>
					  </tr>";

		}
		print "</table><p>";
	}
	else
	{
		$query2 = "SELECT id FROM $downloads_table WHERE category='$download_list[0]'";
		$result2 = mysql_query($query2) or die_script($query2, mysql_error());
		$num_rows = mysql_num_rows($result2);
		print "<font size=\"3\"><a href=index.php?section=$section&page=$page&dwnl_category=$download_list[0]><b>$download_list[1]";
		print " ($num_rows) </b></a></font>";
		print "<img src=\"$cmsdir/modules/sn_downloads/arrow.gif\"><p>";
	}
}
//     print "<br><br><br><br>";
?>
