<?php

#############################################################################
#           			                   Site@School
# Site@School is a website management system designed for primary schools.
#
# About Site@School:
# Comissioned by: City District 'de Baarsjes', Amsterdam, Netherlands
# Original idea, coding (version 1.0) and design : Mark de Haan (mark@starwave.nl)
# Ideas, improvements, expansions (version 1.1 - 2.4): Fred Stuurman 
# Current coder & maintainer: Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# filemanager.inc.php: last changed 04/10/2006    version 2.4.10                                   
#                      by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: filemanager.inc.php,v 1.2 2006/10/15 19:08:53 fstuurman Exp $
# Multiple file upload applet postlet used is from http://sourceforge.net/projects/postlet/
############################################################################
#                        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 ($rootpath))
{
	$rootpath = "$media";
}
if (IsSet ($_POST['newdirectory']))
{
	$newdirectory = $_POST['newdirectory'];
}
if (IsSet ($_POST['subpath']))
{
	$subpath = $_POST['subpath'];
}
if (IsSet ($_GET['path']))
{
	$path = $_GET['path'];
}
if (IsSet ($_GET['deletefile']))
{
	$deletefile = $_GET['deletefile'];
}
if (IsSet ($_GET['checkfiles']))
{
	$checkfiles = $_GET['checkfiles'];
}
if (IsSet ($_GET['deletedirectory']))
{
	$deletedirectory = $_GET['deletedirectory'];
}
if (IsSet ($_GET['go']))
{
	$go = $_GET['go'];
}
if (IsSet ($_GET['fileupload']))
{
	$fileupload = $_GET['fileupload'];
}
if (IsSet ($_GET['option']))
{
	$option = $_GET['option'];
}
if (IsSet ($_GET['rootpath']))
{
	$rootpath = $_GET['rootpath'];
}
if (IsSet ($_GET['class1']))
{
	$class1 = $_GET['class1'];
}

/* get a list of the files + dirs and turn the list into an array */
function file_list($dir)
{
	//  global $sort;
	global $file_file_count;
	if (is_dir($dir))
	{
		$fd = @ opendir($dir);
		while (($part = @ readdir($fd)) == true)
		{
			clearstatcache();
			if ($part != "." && $part != "..")
			{
				$file_array[] = $part;
			}
		}

		if ($fd == true)
		{
			closedir($fd);
		}

		if (is_array($file_array))
		{
			//order the files naterually
			$array_lowercase = array_map('strtolower', $file_array); //convert to lowercase first
			array_multisort($array_lowercase, SORT_ASC, SORT_STRING, $file_array); //do the sorting
			$file_file_count = count($file_array);
			return $file_array;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}

/* function to convert to Mb, Kb and bytes */
function file_size($size)
{
	$megabyte = 1024 * 1024;
	if ($size > $megabyte)
	{ /* literal.float */
		$re_sized = sprintf("%01.2f", $size / $megabyte) . " Mb";
	}
	elseif ($size > 1024)
	{
		$re_sized = sprintf("%01.2f", $size / 1024) . " Kb";
	}
	else
	{
		$re_sized = $size . " bytes";
	}
	return $re_sized;
}

/* get a list of the files/dirs, put them into a table. */
function generate_file_list($path)
{
	global $download_path;
	global $sas_lang;
	global $media;
	global $rootpath;
	global $site_url;
	global $table_pages;
	global $table_sections;
	global $checkfiles;
	global $userpath;
	global $class1;
	$final_path = str_replace("//", "/", str_replace("..", "", urldecode($path)));
	$file_array = file_list("$download_path/$final_path/");
	$bgcolor = "E7E7EF";
	echo "<br>\n";

	if ($file_array == false) /* check if the dir is an array before we process it to foreach(); */
	{
		echo "";
	}
	else
	{
		print "<table width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
				  <tr><td colspan=\"2\">&nbsp;</td>
				  <td><span class=\"text\">" . $sas_lang['file'] . "</span></td>         
				  <td><span class=\"text\">" . $sas_lang['filesize'] . "</span></td>";
		if ($rootpath == "$media")
		{
			print "<td><span class=\"text\">" . $sas_lang['section'] . " -> " . $sas_lang['category'] . " -> " . $sas_lang['page'] . ":</span></td>
							 <td><form method=post action=index.php?option=filemanager&rootpath=$media&go=list&path=$path&checkfiles=yes>
							 <input type=submit value=\"" . $sas_lang['location'] . "\"></a></form></td></tr>\n";
		}
		foreach ($file_array as $file_name)
		{
			$is_file = "$download_path/$final_path/$file_name";
			$final_dir_name = urlencode($final_path); /* urlencode(); to prevent any broken links - decode on do_download(); */
			$final_file_name = urlencode($file_name);
			$file_size = filesize("$download_path/$final_path/$file_name");
			$final_file_size = file_size($file_size);
			$page_name = "&nbsp;";

			if ($checkfiles == "yes")
			{
				$query = "SELECT section, name, category FROM $table_pages WHERE content like '%$final_path/$file_name%'"; //see if picture is used in S@S
				$result = mysql_query($query) or die_script($query, mysql_error());
				$num_rows = mysql_num_rows($result);
				if ($num_rows > 0)
				{
					$row = mysql_fetch_array($result);
					$query2 = "SELECT name FROM $table_sections WHERE id='$row[section]'"; //get the section name
					$result2 = mysql_query($query2) or die_script($query2, mysql_error());
					$section_name = mysql_result($result2, 0);
					if ($row[category] != "")
					{
						$page_name = "$section_name -> $row[category] -> $row[name]";
					}
					else
					{
						$page_name = "$section_name -> $row[name]";
					}
				}
				else
				{
					$page_name = " -  -  -"; //blank page name
				}
			}

			if (is_file($is_file))
			{
				$file_date = date("d-m-Y", filemtime("$download_path/$final_path/$file_name"));

				if (IsSet ($_GET[go]))
				{
					print "<tr bgcolor=\"$bgcolor\"><td width=\"18\" height=\"18\">
									 <img border=\"0\" src=\"graphics/delete.gif\" alt=\"" . $sas_lang['delete'] . "\" title=\"" . $sas_lang['delete'] . "\" width=\"16\" height=\"16\" 
									 onClick=\"if(confirm('" . $sas_lang['delete_file_confirmation'] . "')) parent.location='index.php?option=filemanager&deletefile=$final_file_name&class1=$class1&rootpath=$rootpath&path=$path&go=" . $_GET['go'] . "';\"></td>
									<td width=18 height=18><img border=\"0\" src=\"graphics/document.gif\" width=\"16\" height=\"16\"></td>
									<td><span class=\"text\"><a href=\"$rootpath$final_path/$final_file_name\" target=\"_blank\">$file_name</a></span></td>
									<td><span class=\"text\">$file_date ($final_file_size)&nbsp;</span></td>
									<td colspan=\"2\"><span class=\"text\">$page_name</span></td></tr>\n";
				}
				else
				{
					print "<tr bgcolor=\"$bgcolor\"><td width=\"18\" height=\"18\">
									<img border=\"0\" src=\"graphics/delete.gif\" alt=\"" . $sas_lang['delete'] . "\" title=\"" . $sas_lang['delete'] . "\" width=\"16\" height=\"16\" 
									onClick=\"if(confirm('" . $sas_lang['delete_file_confirmation'] . "')) parent.location='index.php?option=filemanager&deletefile=$final_file_name&class1=$class1&rootpath=$rootpath';\"></td>
									<td width=18 height=18><img border=\"0\" src=\"graphics/document.gif\" width=\"16\" height=\"16\"></td>
									<td><span class=\"text\"><a href=\"$rootpath$final_path/$final_file_name\" target=\"_blank\">$file_name</a></span></td>
									<td><span class=\"text\">$file_date ($final_file_size)&nbsp;</span></td>
									<td colspan=\"2\"><span class=\"text\">$page_name</span></td></tr>\n";
				}

				if ($bgcolor == "#FFFFFF")
				{
					$bgcolor = "#E7E7EF";
				}
				else
				{
					$bgcolor = "#FFFFFF";
				}
			}
		}
		echo "</table>\n";
	}
}

function generate_dir_list($path)
{
	global $download_path;
	global $sas_lang;
	global $rootpath;
	global $class1;
	$final_path = str_replace("//", "/", str_replace("..", "", urldecode($path)));
	$file_array = file_list("$download_path/$final_path/");
	$pos = strrpos($final_path, "/");
	$previous_path = substr($final_path, 0, $pos); //previous path for the go back button

	echo "<br><img border=\"0\" src=\"graphics/folder_open.gif\" width=\"16\" height=\"16\">&nbsp;<span class=text><b>$download_path$final_path</b></span>\n";
	echo "<table width=\"75%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";

	if ($file_array == false) /* check if the dir is an array before we process it to foreach(); */
	{
		print "<tr><td width=\"18\" height=\"18\"><a href=\"index.php?option=filemanager&rootpath=$rootpath&class1=$class1\">
					<img border=\"0\" src=\"graphics/button_back.png\" width=\"16\" height=\"16\"></a></td>
					<td colspan=3><span class=\"text\">
					<a href=\"index.php?option=filemanager&rootpath=$rootpath&path=$previous_path&go=list&class1=$class1\">" . $sas_lang['goback'] . "</a></span></td></tr>\n"; /* we don't need a size for a directory */
		echo "</table>\n";
		echo "<p><span class=text>" . $sas_lang['emptydir'] . "</span>\n";

	}
	else
	{
		if ($final_path != "")
			print "<tr><td width=\"18\" height=\"18\"><a href=\"index.php?option=filemanager&rootpath=$rootpath&path=$previous_path&go=list&class1=$class1\">
								<img border=\"0\" src=\"graphics/button_back.png\" width=\"16\" height=\"16\"></a></td>
								<td colspan=3><span class=\"text\">
								<a href=\"index.php?option=filemanager&rootpath=$rootpath&path=$previous_path&go=list&class1=$class1\">" . $sas_lang['goback'] . "</a></span></td></tr>\n"; /* we don't need a size for a directory */
		foreach ($file_array as $file_name)
		{
			$is_file = "$download_path$final_path/$file_name";
			$final_dir_name = urlencode($final_path); /* urlencode(); to prevent any broken links - decode on do_download(); */
			$final_file_name = urlencode($file_name);
			$file_size = filesize("$download_path/$final_path/$file_name");
			$final_file_size = file_size($file_size);

			if (is_dir($is_file))
			{
				if ($rootpath == "studentpages") //we need a different link for studentpages
				{
					print "<tr><td width=\"18\" height=\"18\"><img border=\"0\" src=\"graphics/delete.gif\" alt=\"" . $sas_lang['delete'] . "\" title=\"" . $sas_lang['delete'] . "\" width=\"16\" height=\"16\"
										   onClick=\"if(confirm('" . $sas_lang['delete_file_confirmation'] . "')) parent.location='index.php?option=filemanager&rootpath=$rootpath&go=list&class1=$class1&path=$path&deletedirectory=$is_file';\"></td>\n
										  <td width=\"18\" height=\"18\"><img border=\"0\" src=\"graphics/folder_closed.gif\" width=\"16\" height=\"16\"></td>
										  <td colspan=\"2\"><span class=\"text\">
										  <a href=\"index.php?option=filemanager&rootpath=$rootpath&go=list&class1=$class1&path=$final_dir_name/$final_file_name\">$file_name</a></span></td>
										  </tr>\n"; /* we don't need a size for a directory */
				}
				else
				{
					print "<tr><td width=18 height=18><img border=\"0\" src=\"graphics/delete.gif\" alt=\"" . $sas_lang['delete'] . "\" title=\"" . $sas_lang['delete'] . "\" width=\"16\" height=\"16\"
										   onClick=\"if(confirm('" . $sas_lang['delete_file_confirmation'] . "')) parent.location='index.php?option=filemanager&rootpath=$rootpath&go=list&path=$path&deletedirectory=$is_file';\"></td>\n
										  <td width=\"18\" height=\"18\"><img border=\"0\" src=\"graphics/folder_closed.gif\" width=\"16\" height=\"16\"></td>
										  <td colspan=\"2\"><span class=\"text\">
										  <a href=\"index.php?option=filemanager&rootpath=$rootpath&go=list&path=$final_dir_name/$final_file_name\">$file_name</a></span></td>
										  </tr>\n"; /* we don't need a size for a directory */
				}
			}
		}
		echo "</table>\n";
	}
}

function list_suspicious_files($target)
{

	global $sas_config;

	$exceptions = array (
		".",
		".."
	); //skip those
	$suspicious_ext = array (
		"php",
		"php3",
		"php5",
		"phtml",
		"asp",
		"aspx",
		"ascx",
		"jsp",
		"cfm",
		"cfc",
		"pl",
		"bat",
		"exe",
		"dll",
		"reg",
		"cgi"
	);

	$sas_path = $sas_config['serverpath'] . $sas_config['user_path'] . "/";

	$dh = opendir($sas_path . $target);

	while (false !== ($file_name = readdir($dh)))
	{
		if (!in_array($file_name, $exceptions))
		{
			if (is_dir($sas_path . $target . "/" . $file_name))
			{
				// recurse subdirectory; call of function recursive
				list_suspicious_files($target . "/" . $file_name);
			}
			else
				if (is_file($sas_path . $target . "/" . $file_name))
				{
					$tmp = explode(".", $file_name); //get the picture extention.
					$ext = array_pop($tmp);
					if (in_array($ext, $suspicious_ext))
						//if((strtoupper($ext) == "PHP") OR (strtoupper($ext) == "CGI") OR (strtoupper($ext) == "PL"))
					{
						print "<span class=text><b>" . $target . "/" . $file_name . "</b></span><br>";
					}
				}
		}
	}

	closedir($dh);
	return true;
} // end of the 'list_files()' function

if (IsSet ($newdirectory))
{
	$newdirectory = remove_special_characters($newdirectory); //replace special characters with underscore
	if (IsSet ($subpath))
	{
		$newdirectory = "$serverpath/$rootpath" . "$subpath/$newdirectory";
	}
	else
	{
		$newdirectory = "$serverpath/$rootpath/$newdirectory";
	}

	$perm = $sas_config['file_permissions'];
	mkdir($newdirectory, 0755);
	chmod($newdirectory, octdec($perm)); //chmod it with permissions stored in configuration table.

}

if (IsSet ($fileupload))
{
	if (IsSet ($_FILES["file"]["name"]))
	{
		$file_name = $_FILES["file"]["name"];
	}
	if (IsSet ($subpath))
	{
		$write_path = $rootpath . $subpath;
	}
	else
	{
		$write_path = $rootpath;
	}
	// moveupload the file to $write_path, function is in core/common.inc.php
	$temp_file = $_FILES["file"]["tmp_name"]; //this is temporary uploaded file.	
	sas_move_uploaded_file($write_path, $file_name, $temp_file);
}

If (IsSet ($deletefile))
{
	if (isSet ($path))
	{
		$file_id = "$serverpath/$rootpath$path/$deletefile";
		$thumb = "$serverpath/$rootpath$path/zz_thumb_" . $deletefile;
	}
	else
	{
		$file_id = "$serverpath/$rootpath/$deletefile";
		$thumb = "$serverpath/$rootpath/zz_thumb_" . $deletefile;
	}

	unlink($file_id);

	if (file_exists($thumb)) //if thumb exists, delete it too.
	{
		unlink($thumb);
	}

}

If (IsSet ($deletedirectory))
{
	rmdir($deletedirectory);
}

include ("interface/header.inc.php");
include ("interface/menubar.inc.php");
include ("interface/menustart.inc.php");
print "<span class=heading>" . $sas_lang['filemanager_menu'] . "</span><br><br>";
print "<span class=link><a href=index.php?option=filemanager&rootpath=$media>" . $sas_lang['filemanager'] . "</a>
       <p><a href=index.php?option=filemanager&rootpath=studentpages>" . $sas_lang['student_pages'] . "</a><p>
	   <a href=index.php?option=filemanager&rootpath=studentpages&go=check>File check</a>
       <br></span>";
include ("interface/menuend.inc.php");
include ("interface/pagestart.inc.php");

if (substr("$access", 0, 1) == "0") //bit 1 off the accessrights
{
	print "<span class=\"heading\">" . $sas_lang['noaccess'] . "<br></span>\n";
	print "<span class=\"text\">" . $sas_lang['noaccess_introduction'] . "</span><p>\n";
	include ("interface/pageend.inc.php");
	include ("interface/footer.inc.php");
	exit;
}

print "<span class=\"heading\">" . $sas_lang['filemanager'] . "<br></span>\n";
print "<span class=\"text\">" . $sas_lang['filemanager_introduction'] . "</span><p>\n";

if ($go == "check")
{
	print "<span class=\"text\">" .  $sas_lang['file_check']."<p></span>\n";
	list_suspicious_files("media");
	list_suspicious_files("studentpages");
	exit;
}

if (($go == "list") OR ($rootpath == "$media") AND ($go != "upload")) // in de root of studentpages we don't need fileupload, also skip when multiple file upload
{
	if (IsSet ($path)) //are we in root or in a subdirectory 
	{
		print "<form method=post enctype=\"multipart/form-data\" action=index.php?option=filemanager&fileupload=1&rootpath=$rootpath&go=list&path=$path&class1=$class1>\n";
		print "<input type=hidden name=subpath value=$path>\n";
	}
	else
	{
		print "<form method=post enctype=\"multipart/form-data\" action=index.php?option=filemanager&fileupload=1&rootpath=$rootpath>\n";
	}

	print "<span class=text>" . $sas_lang['uploadfile'] . ":</span><br><input type=file name=file size=40 class=textfield>\n
	       &nbsp;<input type=submit value=&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . " name=B1 class=savebutton></form>";

}

if (($rootpath != "studentpages") AND ($go != "upload")) //no directory creation for studentpages
{
	print "<form method=post action=index.php?option=filemanager>";
	print "<span class=text>" . $sas_lang['createdir'] . ":</span><br><input type=text name=newdirectory size=20 class=textfield>
	       &nbsp;<input type=submit value=&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . " name=B1 class=savebutton>";

	print "&nbsp;&nbsp;&nbsp;<input type=\"button\" value=\"&nbsp;" . $sas_lang['multiple_upload'] . "\" 
		onClick=\"parent.location='index.php?option=filemanager&rootpath=$rootpath&go=upload&path=$path'\">\n";

	if (IsSet ($path))
	{
		print "<form method=post action=index.php?option=filemanager&rootpath=$rootpath&go=list&path=$path>";
		print "<input type=hidden name=subpath value=$path>";
	}
	print "</form>";
}

if ($rootpath == "$media")
{
	/* config for the script */
	$download_path = "$serverpath/$media"; /* path to your files, NB: no slash at the end */
	//$sort = "asort"; /* array sorting - alphabetical sorting for the array */

	if (!isset ($go))
	{
		$go = "dirlist";
	}

	if ($go == "dirlist")
	{
		print "<table width=100%><tr><td valign=top width=30%>\n";
		generate_dir_list(""); /* null, so we get a list for the root directory */
		generate_file_list(""); /* null, so we get a list for the root directory */
		print "</td></tr></table>";
	}
	elseif ($go == "list" && isset ($path))
	{
		if (isset ($path)) /* if the path is null - it returns a list for the root directory */
		{
			print "<table width=100%><tr><td valign=top width=30%>\n";
			generate_dir_list($path); /* get a list for the path specified */
			generate_file_list($path); /* get a list for the path specified */
			print "</td></tr></table>";
		}
		else
		{
			generate_dir_list("");
			generate_file_list("");
		}
	}
}

if ($go == "upload")
{
	$sess_id = session_id();

	print "<p>
		<table>
		<tr><td><span class=\"heading\">" . $sas_lang['multiple_upload'] . ":</span></td></tr>
		<tr><td>
		<APPLET CODE =\"Main.class\" ARCHIVE =\"core/Postlet.jar\" WIDTH =\"600\" HEIGHT =\"200\" NAME =\"Postlet\">
		<PARAM NAME =\"CODE\" VALUE =\"Main.class\" >
		<PARAM NAME =\"ARCHIVE\" VALUE =\"core/Postlet.jar\" >
		<PARAM NAME =\"NAME\" VALUE =\"Multiple file uploader\" >
		<PARAM NAME =\"type\" VALUE =\"application/x-java-applet;version=1.4\">
		<PARAM NAME=\"language\" VALUE=\"" . $sas_config['language'] . "\"/>
		<PARAM NAME =\"scriptable\" VALUE =\"false\">
		<PARAM NAME =\"destination\" VALUE=\"" . $sas_config['url'] . "starnet/core/javaUpload.php?store_path=" . $path . "&PHPsessid=" . $sess_id . "\">
		<PARAM NAME =\"endpage\" VALUE=\"" . $sas_config['url'] . "starnet/index.php?option=filemanager&go=list&rootpath=" . $media . "&path=" . $path . "\">
		<PARAM NAME =\"red\" VALUE=\"212\">
		<PARAM NAME =\"green\" VALUE=\"208\">
		<PARAM NAME =\"blue\" VALUE=\"200\">
		<PARAM NAME =\"redheader\" VALUE=\"200\">
		<PARAM NAME =\"greenheader\" VALUE=\"200\">
		<PARAM NAME =\"blueheader\" VALUE=\"200\"> 
		</applet>
		</td></tr>
		</table>";
	exit;
}

if ($rootpath == "studentpages")
{

	$download_path = "$serverpath/studentpages";
	//$sort = "asort";

	if (!isset ($go))
	{
		$go = "dirlist";
	}

	if (isset ($class1)) //if we have a class list the directories
	{
		$query = "SELECT name FROM $table_classes WHERE id='$class1'"; //get the classname
		$result = mysql_query($query) or die_script($query, mysql_error());
		$class_name = stripslashes(mysql_result($result, 0, "name"));

		if ($go == "dirlist")
		{
			print "<table width=\"100%\"><tr><td valign=\"top\" width=\"30%\">";
			$final_path = str_replace("//", "/", str_replace("..", "", urldecode($path)));
			$file_array = file_list("$download_path/$final_path/");

			print "<br><span class=\"link\">$class_name</span>";
			if ($file_array == false)
			{
				print "<table width=\"75%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
				print "<tr><td width=18 height=18><a href=\"index.php?option=filemanager&rootpath=$rootpath\">
								   <img border=\"0\" src=\"graphics/button_back.png\" width=\"16\" height=\"16\"></a></td>
								   <td colspan=2><span class=\"text\"><a href=\"index.php?option=filemanager&rootpath=$rootpath\">" . $sas_lang['goback'] . "</a></span></td>
								   <td></td></tr>n";
				print "</table>";
				print "<p><span class=text>" . $sas_lang['emptydir'] . "</span>";

			}
			else
			{
				print "<table width=\"75%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
				if ($final_path != "")
					print "<tr><td width=18 height=18><a href=\"index.php?option=filemanager&rootpath=$rootpath\">
									   <img border=\"0\" src=\"graphics/button_back.png\" width=\"16\" height=\"16\"></a></td>
									   <td colspan=2><span class=\"text\"><a href=\"index.php?option=filemanager&rootpath=$rootpath\">" . $sas_lang['goback'] . "
									   </a></span></td><td></td></tr>\n"; /* we don't need a size for a directory */

				foreach ($file_array as $file_name)
				{
					$is_file = "$download_path/$final_path$file_name";
					$final_dir_name = urlencode($final_path);
					$final_file_name = urlencode($file_name);
					$file_size = filesize("$download_path/$final_path/$file_name");
					$final_file_size = file_size($file_size);
					if (is_dir($is_file))
					{
						$query1 = "SELECT name, class FROM $table_users WHERE id='$file_name'";
						$result1 = mysql_query($query1) or die_script($query1, mysql_error());
						if (mysql_num_rows($result1) > 0)
						{
							$student_name = mysql_result($result1, 0, "name");
							$student_class = mysql_result($result1, 0, "class");
						}
						else
						{
							$student_name = "";
						}
						if ($student_class == $class1)
						{
							print "<tr><td width=18 height=18>
														   <img border=\"0\" src=\"graphics/delete.gif\" alt=\"" . $sas_lang['delete'] . "\" title=\"" . $sas_lang['delete'] . "\" width=\"16\" height=\"16\"
														   onClick=\"if(confirm('" . $sas_lang['delete_file_confirmation'] . "')) parent.location='index.php?option=filemanager&rootpath=$rootpath&go=dirlist&path=$path&deletedirectory=$is_file&class1=$class1';\"></td>
														  <td width=18 height=18><a href=\"index.php?option=filemanager&rootpath=$rootpath&go=list&class1=$class1&path=$final_dir_name/$final_file_name\"><img border=\"0\" src=\"graphics/folder_closed.gif\" width=\"16\" height=\"16\"></a></td>
														  <td><span class=\"text\"><a href=\"index.php?option=filemanager&rootpath=$rootpath&go=list&class1=$class1&path=$final_dir_name/$final_file_name\">$file_name</a></span></td>
														  <td><b><a href=\"index.php?option=filemanager&rootpath=$rootpath&go=list&class1=$class1&path=$final_dir_name/$final_file_name\">$student_name</a></b></td></tr>";
						}
					}
				}
				print "</table>\n";
			}
			print "</td></tr></table>";
		}
		elseif ($go == "list" && isset ($path))
		{
			$query = "SELECT name FROM $table_classes WHERE id='$class1'"; //get the classname
			$result = mysql_query($query) or die_script($query, mysql_error());
			$class_name = stripslashes(mysql_result($result, 0, "name"));
			if (isset ($path))
			{
				$student_path = substr($path, 1);
				$query1 = "SELECT name FROM $table_users WHERE id='$student_path'";
				$result1 = mysql_query($query1) or die_script($query1, mysql_error());
				if (mysql_num_rows($result1) > 0)
				{
					$student_name = mysql_result($result1, 0, "name");
				}
				print "<p><b>&nbsp;&nbsp;$student_name ($class_name)</b><table width=100%><tr><td valign=top width=30%>";
				generate_dir_list($path);
				generate_file_list($path);
				print "</td></tr></table>";
			}
			else
			{
				generate_dir_list("");
				generate_file_list("");
			}
		}
	}
	print "<p><span class=\"link\">" . $sas_lang['student_pages'] . ":</span><br>\n";
	$query = "SELECT id, name FROM $table_classes WHERE name != '--------' ORDER BY name"; //get the classes
	$result = mysql_query($query) or die_script($query, mysql_error());

	if ($result)
	{
		while ($class_list = mysql_fetch_array($result))
		{
			$class_name = stripslashes($class_list[1]);
			print "&nbsp;<span class=link><a href=index.php?option=filemanager&rootpath=$rootpath&class1=$class_list[0]>$class_name</a></span><br>";
		}
	}
}
print "</form>";
?>
