<?php

#############################################################################
#                              Site@School Download module
# Site@School is a website management system designed for schools.
# This is a download module which can be used in Site@School.
#
# coded by Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# admin.php: last changed 12/10/2006  version 2.4.10
#                  by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: admin.php,v 1.2 2006/10/15 19:08:54 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
# Copyright (C) 2002 - 2006 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['addownload']))
{
	$addownload = $_GET['addownload'];
}
if (IsSet ($_GET['addcategory']))
{
	$addcategory = $_GET['addcategory'];
}
if (IsSet ($_GET['editdownload']))
{
	$editdownload = $_GET['editdownload'];
}
if (IsSet ($_GET['savedownload']))
{
	$savedownload = $_GET['savedownload'];
}
if (IsSet ($_GET['savecategory']))
{
	$savecategory = $_GET['savecategory'];
}
if (IsSet ($_GET['deletedownload']))
{
	$deletedownload = $_GET['deletedownload'];
}
if (IsSet ($_GET['deletecategory']))
{
	$deletecategory = $_GET['deletecategory'];
}
if (IsSet ($_GET['editcategory']))
{
	$editcategory = $_GET['editcategory'];
}
if (IsSet ($_GET['modoption']))
{
	$modoption = $_GET['modoption'];
}
if (IsSet ($_GET['category']))
{
	$category = $_GET['category'];
}

if (IsSet ($_POST['category']))
{
	$category = $_POST['category'];
}

if (!get_magic_quotes_gpc())
{
	$description = addslashes($_POST['description']);
	$welcometext = addslashes($_POST['welcometext']);
	$welcometext_prot = addslashes($_POST['welcometext_prot']);
}
else
{
	$description = $_POST['description'];
	$welcometext = $_POST['welcometext'];
	$welcometext_prot = $_POST['welcometext_prot'];
}

if (IsSet ($_POST['creator']))
{
	$creator = $_POST['creator'];
}
if (IsSet ($_POST['category_title']))
{
	$category_title = $_POST['category_title'];
}
if (IsSet ($_POST['newtemplate']))
{
	$newtemplate = $_POST['newtemplate'];
}
if (IsSet ($_POST['ispage']))
{
	$ispage = $_POST['ispage'];
}
if (IsSet ($_POST['is_public']))
{
	$is_public = $_POST['is_public'];
}

load_language('', 'sn_downloads'); //load language file

$query = "SELECT name FROM $table_modules WHERE id=$module"; //get the module name                
$result = mysql_query($query) or die_script($query, mysql_error());
$modulename = mysql_result($result, 0);
unset ($query);
unset ($result);

$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_categorytable = "$moduletables[1]";

include ("interface/header.inc.php");
include ("interface/menubar.inc.php");
include ("interface/menustart.inc.php");
print "<span class=heading>" . $sas_lang['filemanager_menu'] . "</span><p>";
print "<span class=link><a href=index.php?option=modulemanager&module=$module>" . $sas_lang['manage'] . "</a><p>
       <a href=index.php?option=modulemanager&module=$module&modoption=configuration>" . $sas_lang['configuration'] . "</a><p></span>";
include ("interface/menuend.inc.php");
include ("interface/pagestart.inc.php");
print "<span class=\"heading\">$modulename<p></span>";

if ($modoption == "saveconfig")
{
	mysql_query("UPDATE $table_configuration SET config_value='$welcometext' WHERE config_key='download_welcome_text'");
	mysql_query("UPDATE $table_configuration SET config_value='$welcometext_prot' WHERE config_key='download_welcome_text_prot'");
	print "<span class=\"text\">" . $sas_lang['download_module_saved'] . "</span>";
	exit;
}

if (IsSet ($editcategory))
{
	$query = "SELECT title, ispage, public FROM $downloads_categorytable WHERE id=$editcategory"; // getting the category     
	$result = mysql_query($query) or die_script($query, mysql_error());
	$category_title = mysql_result($result, 0, 0);
	$ispage_check = mysql_result($result, 0, 1);
	$is_public = mysql_result($result, 0, 2);
	unset ($query);
	unset ($result);
	print "<FORM METHOD=\"POST\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=$modoption&savecategory=$editcategory\">
				<span class=\"text\">" . $sas_lang['title'] . ":<br>
				<input type=text name=\"category_title\" size=40 class=\"textfield\" value=\"$category_title\">&nbsp;
				<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['download_module_categorytitle_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";
	print $sas_lang['download_module_category_is_page'] . "  &nbsp;" . $sas_lang['yes'] . "";
	if ($ispage_check == "1")
	{
		print "<input type=\"radio\" value=\"1\" name=\"ispage\" checked>";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"ispage\" value=\"0\">";
	}
	else
	{
		print "<input type=\"radio\" value=\"1\" name=\"ispage\">";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"ispage\" value=\"0\" checked>";
	}

	print "<p>" . $sas_lang['download_module_category_is_public'] . "  &nbsp;" . $sas_lang['yes'] . "";
	if ($is_public == "1")
	{
		print "<input type=\"radio\" value=\"1\" name=\"is_public\" checked>";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"is_public\" value=\"0\">";
	}
	else
	{
		print "<input type=\"radio\" value=\"1\" name=\"is_public\">";
		print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
		print "<input type=\"radio\" name=\"is_public\" value=\"0\" checked>";
	}

	print "<p><br><span class=text>" . $sas_lang['download_module_category_directory'] . "<br>
				<b> " . $sas_config['serverpath'] . $sas_config['user_path'] . "/" . $sas_config['media_dir'] . "/downloads/" . $editcategory . "</b></span>";
	print "<p><br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['cancel'] . "\" name=\"backbutton\" onClick=\"javascript:history.go(-1)\" class=\"cancelbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</span></form>";
	exit;
}

if (IsSet ($addownload))
{
	print "<span class=\"heading\">" . $sas_lang['download_module_add'] . "<br></span>";
	print "<FORM METHOD=\"POST\" enctype=\"multipart/form-data\" ACTION=\"index.php?option=modulemanager&module=$module&savedownload=new\"><br>";

	print "<span class=\"text\">" . $sas_lang['category'] . "<br><select size=\"1\" name=\"category\">";
	$query = "SELECT id, title FROM $downloads_categorytable";
	$result = mysql_query($query) or die_script($query, mysql_error());
	while ($category_list = mysql_fetch_array($result))
	{
		print "<option value=\"$category_list[0]\">$category_list[1]</option>";
	}
	print "</select>&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['download_module_categorytitle_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";

	print "<span class=\"text\">" . $sas_lang['download_module_creator'] . "<br>
				<input type=text name=\"creator\" size=40 class=\"textfield\">&nbsp;<img src=graphics/help.gif 
				ONMOUSEOVER=\"popup('" . $sas_lang['download_module_creator_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";
	print "" . $sas_lang['download_module_description'] . "<br><textarea name=\"description\" ROWS=2 COLS=60></textarea><br><br>";
	print "<span class=text>" . $sas_lang['uploadfile'] . ":</span><br><input type=file name=file size=50 class=textfield><br><br>";

	print "<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['cancel'] . "\" name=\"backbutton\"
				onClick=\"javascript:parent.location='index.php?option=modulemanager&module=$module';\" class=\"cancelbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</span></form>";

	include ("interface/pageend.inc.php");
	include ("interface/footer.inc.php");
	exit;
}

if (IsSet ($editdownload))
{
	$query2 = "SELECT id, description, category, creator, filename FROM $downloads_table WHERE id='$editdownload'";
	$result2 = mysql_query($query2) or die_script($query2, mysql_error());
	$download_list = mysql_fetch_array($result2);
	$query2 = "SELECT public FROM $downloads_categorytable WHERE id='$download_list[2]'";
	$result2 = mysql_query($query2) or die_script($query2, mysql_error());
	$is_public = mysql_result($result2, 0, 0);
	print "<span class=\"text\"><b>" . $sas_lang['download_module_edit'] . "</b><br></span><br>";
	print "<span class=\"text\"><b>" . $sas_lang['download_module_filename'] . " $download_list[4]";
	if ($is_public == 1)
	{
		print " (*)";
	}
	print "</b></span><br>";
	print "<FORM METHOD=\"POST\" enctype=\"multipart/form-data\" ACTION=\"index.php?option=modulemanager&module=$module&savedownload=$editdownload\"><br>";

	print "<span class=\"text\">" . $sas_lang['category'] . ":<br><select size=\"1\" name=\"category\">";
	if ($is_public == 1)
	{
		$query = "SELECT id, title FROM $downloads_categorytable WHERE public = 1";
	}
	else
	{
		$query = "SELECT id, title FROM $downloads_categorytable WHERE public = 0";
	}
	$result = mysql_query($query) or die_script($query, mysql_error());

	while ($category_list = mysql_fetch_array($result))
	{
		if ($category_list[0] == $download_list[2])
		{
			print "<option selected value=\"$category_list[0]\">$category_list[1]</option>";
		}
		else
		{
			print "<option value=\"$category_list[0]\">$category_list[1]</option>";
		}
	}

	print "</select>&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['download_module_categorytitle_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";

	print "<span class=\"text\">" . $sas_lang['download_module_creator'] . "<br>
				<input type=text value=\"$download_list[3]\" name=\"creator\" size=40 class=\"textfield\">&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['download_module_creator_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";
	print "" . $sas_lang['download_module_description'] . "<br><textarea name=\"description\" ROWS=4 COLS=60>$download_list[1]</textarea><br><br>";
	print "<span class=text>" . $sas_lang['uploadfile'] . ":</span><br><input type=file name=file size=50 class=textfield><br><br>";
	if ($is_public == 1)
	{
		print "<br><span class=\"text\">(*) " . $sas_lang['protected_area'] . "</span><p>";
	}
	print "<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['cancel'] . "\" name=\"backbutton\"
				onClick=\"javascript:parent.location='index.php?option=modulemanager&module=$module';\" class=\"cancelbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</span></form>";

	include ("interface/pageend.inc.php");
	include ("interface/footer.inc.php");
	exit;
}

if (IsSet ($addcategory))
{
	print "<span class=\"heading\">" . $sas_lang['download_module_add_category'] . "<p></span>";
	print "<FORM METHOD=\"POST\" id=newdownload ACTION=\"index.php?option=modulemanager&module=$module&savecategory=new\">
				<span class=\"text\">" . $sas_lang['title'] . ":<br>
				<input type=text name=\"category_title\" size=40 class=\"textfield\">&nbsp;<img src=graphics/help.gif 
				ONMOUSEOVER=\"popup('" . $sas_lang['categorytitle_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";
	print $sas_lang['download_module_category_is_page'] . "  &nbsp;" . $sas_lang['yes'] . "";
	print "<input type=\"radio\" value=\"1\" name=\"ispage\">";
	print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"ispage\" value=\"0\" checked>";
	print "<p>" . $sas_lang['download_module_category_is_public'] . "  &nbsp;" . $sas_lang['yes'] . "";
	print "<input type=\"radio\" value=\"1\" name=\"is_public\">";
	print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"is_public\" value=\"0\" checked>";

	print "<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['cancel'] . "\" name=\"backbutton\" onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</span></form>";

	include ("interface/pageend.inc.php");
	include ("interface/footer.inc.php");
	exit;
}

if (IsSet ($savedownload))
{
	$result = mysql_query("SELECT public FROM $downloads_categorytable WHERE id='$category'");
	$is_public = mysql_result($result, 0);
	$exists = 0; // 0 is doesn't exists, 1 = exists , 2 = exists in category, 3 = edit existing file without new file upload
	$filename = $_FILES["file"]["name"];
	$store_filename = md5($filename);
	$write_path = "$serverpath/$media/downloads/" . $category . "/" . $store_filename;

	if (IsSet ($_FILES["file"]["name"]))
	{
		$temp_file = $_FILES["file"]["tmp_name"];
	}

	if (file_exists($write_path)) //file exists in downloads directory on server?
	{
		$exists = 1;
	}

	//does it exist in the category saved?
	if ($filename != "")
	{
		$result1 = mysql_query("SELECT id FROM $downloads_table WHERE filename = '$filename' AND category = '$category'");

		if (mysql_num_rows($result1) > 0) //does file already exists in category?
		{
			$exists = 2;
		}
	}
	else
	{
		$exists = 3; //no file upload, but we need to save the file properties
	}

	if (($exists == 0) AND ($filename != "")) //does file already exists , if no save as new?
	{
		$write_path = $media . "/downloads/" . $category;
		if (!sas_move_uploaded_file($write_path, $filename, $temp_file))
		{
			print "<b>There has been an error uploading the file.</b><br>";
		}
		else
		{
			$file_rename = remove_special_characters($filename); //we remove special characters from filename
			rename($serverpath . "/" . $media . "/downloads/" . $category . "/" . $file_rename, $serverpath . "/" . $media . "/downloads/" . $category . "/" . $store_filename);
			print $sas_lang['download_module_filename'] . " <b>" . $filename . "</b> " . $sas_lang['download_module_file_saved'] . "<p>";

			//make entry in downloads table for new file.
			mysql_query("INSERT INTO $downloads_table (id, description, category, creator, filename, date, stored_file) 
								VALUES (NULL, '$description', '$category', '$creator', '$filename', NOW(), md5('$filename'))");
		}
	}
	elseif (($exists == 2) OR ($exists == 3)) //does file already exists in category : overwrite?
	{
		mysql_query("UPDATE $downloads_table SET description = '$description',
																	creator = '$creator',
																	category = '$category',
																	date = NOW() 
																	WHERE id = '$savedownload'");
		if ($filename != "")
		{
			print $sas_lang['download_module_filename'] . " <b>" . $filename . "</b><br>" . $sas_lang['download_module_file_replaced'];
		}
		else
		{
			print $sas_lang['download_module_info_save'];
		}
	}
	else
	{
		print "<span class=\"error\"><b>" . $sas_lang['download_module_file_exists'] . "</b></span>";
	}

	print "\n<br><br><input type=\"button\" value=\"&nbsp;$sas_lang[goback]\" onClick=\"javascript:history.go(-1)\">";
	include ("interface/pageend.inc.php");
	include ("interface/footer.inc.php");

	$result = mysql_query("SELECT title FROM $downloads_categorytable WHERE id='$category'"); //get page name
	$page_name = addslashes(mysql_result($result, 0));
	$result2 = mysql_query("SELECT id, section, lastupdate, name FROM $table_pages WHERE module = 'sn_downloads/download_pag.php' AND name = '$page_name' ");
	if (mysql_num_rows($result2) == 0)
	{
		$result2 = mysql_query("SELECT id, section, lastupdate, name FROM $table_pages WHERE module = 'sn_downloads/downloads.php' ");
	}
	if (mysql_num_rows($result2) > 0)
	{
		$d = date("Y-m-d"); //todays date
		$change_date = mysql_result($result2, 0, 2);
		$savepage = mysql_result($result2, 0, 0);
		$section = mysql_result($result2, 0, 1);
		$title = mysql_result($result2, 0, 3);
		if ($change_date < $d) //send alerts only the first time on a date 
		{
			include ("core/send_alerts.php"); //check to see if need to send alerts  
		}
	}
	$date1 = date("Y-m-d H:i:s"); //set the lastupdate date
	mysql_query("UPDATE $table_pages SET lastupdate = '$date1' WHERE module = 'sn_downloads/download_pag.php' AND name = '$page_name' ");
	mysql_query("UPDATE $table_pages SET lastupdate = '$date1' WHERE module = 'sn_downloads/downloads.php'");
	exit;
}

if (IsSet ($savecategory) && $category_title != "")
{

	if ($savecategory == "new")
	{
		$query = "SELECT title FROM $downloads_categorytable WHERE title = '$category_title'";
		$result = mysql_query($query) or die_script($query1, mysql_error());
		if (mysql_num_rows($result) == 0)
		{
			mysql_query("INSERT INTO $downloads_categorytable (id, title, ispage, public) VALUES (NULL, '$category_title', $ispage, $is_public)");
			$cat_id = mysql_insert_id();
			$cat_dir = "$sas_config[serverpath]$sas_config[user_path]/$sas_config[media_dir]/downloads/" . $cat_id;

			if (!file_exists($cat_dir))
			{
				$perm = $sas_config['file_permissions'];
				mkdir($cat_dir, 0755); //create category directory 
				chmod($cat_dir, octdec($perm)); //chmod it with permissions stored in configuration table.
				$handle = fopen($cat_dir . "/index.html", 'w'); //write an empty index.html in the directory
				fwrite($handle, "");
			}
		}
		else
		{
			print "<span class=\"error\"><b>" . $sas_lang['download_module_category_exists'] . "</b></span><p>";
		}
	}
	else
	{
		$query = "SELECT title FROM $downloads_categorytable WHERE title = '$category_title' AND id != '$savecategory'";
		$result = mysql_query($query) or die_script($query1, mysql_error());
		if (mysql_num_rows($result) == 0)
		{
			mysql_query("UPDATE $downloads_categorytable SET title='$category_title' WHERE id='$savecategory'");
			mysql_query("UPDATE $downloads_categorytable SET ispage='$ispage' WHERE id='$savecategory'");
			mysql_query("UPDATE $downloads_categorytable SET public='$is_public' WHERE id='$savecategory'");
		}
		else
		{
			print "<span class=\"error\"><b>" . $sas_lang['download_module_category_exists'] . "</b></span><p>";
		}
	}
}

if (IsSet ($deletedownload))
{
	$result = mysql_query("SELECT category FROM $downloads_table WHERE id='$deletedownload'");
	$category = mysql_result($result, 0);

	$query1 = "SELECT stored_file FROM $downloads_table WHERE id = '$deletedownload'";
	$result1 = mysql_query($query1) or die_script($query1, mysql_error());
	$filename = mysql_result($result1, 0);
	$file_path = $serverpath . "/$media/downloads/$category/$filename";
	//try to delete it if it exists
	if (file_exists($file_path))
	{
		unlink($file_path);
	}

	mysql_query("DELETE FROM $downloads_table WHERE id = '$deletedownload' AND category = '$category'");
}

if (IsSet ($deletecategory))
{
	$query2 = "SELECT stored_file FROM $downloads_table WHERE category = '$deletecategory'";
	$result2 = mysql_query($query2) or die_script($query2, mysql_error());
	while ($file_list = mysql_fetch_array($result2))
	{
		$custompath = $serverpath . "/$media/downloads/$deletecategory/$file_list[0]";
		unlink($custompath);
	}
	unlink($serverpath . "/$media/downloads/$deletecategory/index.html"); //delete index.html
	rmdir($serverpath . "/$media/downloads/" . $deletecategory); //remove category directory
	mysql_query("DELETE from $downloads_table WHERE category = '$deletecategory'");
	mysql_query("DELETE from $downloads_categorytable WHERE id = '$deletecategory'");
}

if ($modoption == "configuration")
{
	print "<span class=\"text\"><b>" . $sas_lang['configuration'] . ":</b><p></span>";
	print "<FORM METHOD=\"POST\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=saveconfig\">
				<span class=\"text\">" . $sas_lang['download_module_welcome'] . "<br>";
	print "<textarea cols=\"70\" rows=\"8\" name=\"welcometext\">" . $sas_config['download_welcome_text'] . "</textarea><br><br>\n";
	print "<span class=\"text\">" . $sas_lang['download_module_welcome_text_prot'] . ":<br>";
	print "<textarea cols=\"70\" rows=\"8\" name=\"welcometext_prot\">" . $sas_config['download_welcome_text_prot'] . "</textarea><br><br>\n";

	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['cancel'] . "\" name=\"backbutton\" onClick=\"javascript:parent.location='index.php?option=modulemanager&module=$module';\" class=\"cancelbutton\">";
	print "\n&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</span></form>";
}
else
{
	$query = "SELECT id, title, public FROM $downloads_categorytable ORDER BY public, title";
	$result = mysql_query($query) or die_script($query, mysql_error());
	if (mysql_num_rows($result) > 0)
	{
		while ($cat_list = mysql_fetch_array($result))
		{
			print "<br><table border=\"0\">
									<tr>
									<td><img border=\"0\" src=\"graphics/delete.gif\" alt=\"" . $sas_lang['delete'] . "\" width=\"16\" height=\"16\" onClick=\"if(confirm('" . $sas_lang['download_module_deletecategory_confirm'] . "')) parent.location='index.php?option=modulemanager&module=$module&deletecategory=$cat_list[0]';\">
									<img border=\"0\" src=\"graphics/edit.gif\" alt=\"" . $sas_lang['edit'] . "\" width=\"16\" height=\"16\" onClick=\"parent.location='index.php?option=modulemanager&module=$module&editcategory=$cat_list[0]'\">
									</td>
									<td><span class=link>" . $sas_lang['category'] . ": <a href=\"index.php?option=modulemanager&module=$module&category=$cat_list[0]\">$cat_list[1]";
			if ($cat_list[2] == 1)
			{
				print " (*)";
			}
			print "</a></span></td>
									</tr></table>";

			print "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\">";
			if ($cat_list[0] == $category)
			{
				$query1 = "SELECT id, date_format(date, '%d-%m-%Y  %H:%i') AS Readable_Date, filename, counter, date_format(last_download, '%d-%m-%Y') AS Readable_Date FROM $downloads_table WHERE category = '$cat_list[0]' ORDER BY date DESC";
				$result1 = mysql_query($query1) or die_script($query1, mysql_error());

				while ($doc_list = mysql_fetch_array($result1))
				{
					print "<tr>
															  <td>&nbsp;</td>
															  <td>
															  <img border=\"0\" src=\"graphics/delete.gif\" alt=\"" . $sas_lang['delete'] . "\" width=\"16\" height=\"16\" onClick=\"if(confirm('" . $sas_lang['delete_file_confirmation'] . "')) 
															  parent.location='index.php?option=modulemanager&module=$module&deletedownload=$doc_list[0]';\">
															  </td>
															  <td>
															  <img border=\"0\" src=\"graphics/document.gif\">
															  </td>
															  <td><span class=\"link\"><a href=\"index.php?option=modulemanager&module=$module&editdownload=$doc_list[0]\">$doc_list[1] - $doc_list[2]</a></td>
															  <td><span class=\"link\"><b>&nbsp;&nbsp;(downloads: $doc_list[3] : $doc_list[4])</span></b></span>
															  </td>
															</tr>";
				}
			}
			print "</table>";
		}
		print "<br><span class=\"text\">(*) " . $sas_lang['protected_area'] . "</span><p>";
		print "<p><img border=\"0\" src=\"graphics/document.gif\">
							<span class=\"link\"><a href=\"index.php?option=modulemanager&module=$module&addownload=1\">" . $sas_lang['download_module_add'] . "</a></span>";
	}
	else
	{
		print "<span class=text>" . $sas_lang['download_module_add_category_warning'] . "</span><br>";
	}
	print "<br><img border=\"0\" src=\"graphics/folder_closed.gif\">
				<span class=\"link\"><a href=\"index.php?option=modulemanager&module=$module&addcategory=1\">" . $sas_lang['download_module_add_category'] . "</a></span>";
	print "\n<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['goback'] . "\" name=\"backbutton\" onClick=\"javascript:parent.location='index.php?option=modulemanager';\" class=\"backbutton\">";

}
include ("interface/pageend.inc.php");
include ("interface/footer.inc.php");
?>
