<?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_pag.php: last changed 25/08/2005  version 1.0.5
#                   by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: download_pag.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");
}

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>";
	$query1 = "SELECT id FROM $downloads_cattable WHERE title='$pagetitle' AND ispage = '1' AND public = 1"; // get category id
}
else
{
	print $sas_config['download_welcome_text'] . "<br>";
	$query1 = "SELECT id FROM $downloads_cattable WHERE title='$pagetitle' AND ispage = '1'  AND public = 0"; // get category id
}
$result1 = mysql_query($query1) or die_script($query1, mysql_error());
$RecordCount = mysql_num_rows($result1);
if ($RecordCount == 1)
{
	$dwnl_category_id = mysql_result($result1, 0);
	unset ($query1);
	unset ($result1);
	print $sas_lang['download_module_available_files'] . " <b>$pagetitle</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_id' 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></td>
			  <td width=50%><font size=2><b>" . $sas_lang['download_module_description'] . "</b></td>
			  <td width=12%><font size=2><b>" . $sas_lang['download_module_creator'] . "</b></td>
			  <td width=18%><font size=2><b>" . $sas_lang['download_module_updated'] . "</b></td>
			  </tr>";
	while ($download_list = mysql_fetch_array($result3))
	{
		$download_list[6] = str_replace("\n", "<br>", $download_list[6]);
		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>";
}
?>
