<?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.3): Fred Stuurman 
# Current coder & maintainer: Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# viewpage.php: last changed 12/03/2006 2.4
#               by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: viewpage_last_changed.php,v 1.1 2006/10/03 10:47:24 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
#
# 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");
}

$limit = 10;

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

if (!IsSet ($student))
{
	print "<center><h3>" . $sas_lang['student_pages'] . ":</h3></center><p>";

	$query = "SELECT id FROM $table_classes WHERE name = '$pagetitle'"; //get the classid for the class with pagename
	$result = mysql_query($query) or die_script($query, mysql_error());
	if (mysql_num_rows($result) > 0)
	{

		$query1 = "SELECT s.studentid, s.title, s.dir_number, s.change_date, u.name, u.class , c.name
						FROM $table_studentpages s 
						LEFT JOIN $table_users u ON s.dir_number=u.id 
						LEFT JOIN $table_classes c ON c.id = u.class
						WHERE c.name = '$pagetitle'
						ORDER BY change_date DESC LIMIT $limit";

		$result1 = mysql_query($query1) or die_script($query1, mysql_error());

		print "<table border=\"0\">
							<tr>
							<td colspan=\"5\">
							<b>Recent changed pages: $pagetitle</b><br><br>
							</td>
							</tr>";
		while ($student_list = mysql_fetch_array($result1)) //list the students
		{
			print "<tr><td>$student_list[4]</td><td>$student_list[3]</td><td><a href=index.php?section=$section&page=$page&student=$student_list[0]>$student_list[1]</a></td></tr>";
		}

		print "</table>";
	}
}
else
{
	$query = "SELECT title, dir_number, content FROM $table_studentpages WHERE studentid='$student'";
	$result = mysql_query($query) or die_script($query, mysql_error()); // getting the title and content
	$title = mysql_result($result, 0, 0);
	$studentid = mysql_result($result, 0, 1);
	$content = mysql_result($result, 0, 2);
	unset ($query);
	unset ($result);
	$query1 = "SELECT name FROM $table_users WHERE id='$studentid'"; // getting the student name
	$result1 = mysql_query($query1) or die_script($query1, mysql_error());
	$name = mysql_result($result1, 0, 0);
	unset ($query1);
	unset ($result1);
	$query2 = "SELECT studentid, title FROM $table_studentpages WHERE dir_number='$studentid' AND studentid!='$student' AND content != '' ORDER BY sort";
	$result2 = mysql_query($query2) or die_script($query2, mysql_error()); // getting the title of other pages
	$count = mysql_num_rows($result2);

	print "<center><h3>" . $sas_lang['student_header'] . " $name <p>" . $sas_lang['title'] . ": <b>$title</b></h3></center><p>";
	print "$content";

	print "<br><hr><table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" width=\"100%\"><tr>";
	if ($count > 0)
	{
		print "<td>" . $sas_lang['other_pupilpages'] . " $name :</td>";
		while ($title_list = mysql_fetch_array($result2))
		{
			print "<td><a href=index.php?section=$section&page=$page&viewclass=$viewclass&student=$title_list[0]><b>$title_list[1]</b></a></td>";
		}
	}

	if ($viewclass != "")
	{
		print "<td align=\"right\"><a href=index.php?section=$section&page=$page&viewclass=$viewclass><< " . $sas_lang['goback'] . "</a></td></tr></table>";
	}
	else
	{
		print "<td align=\"right\"><a href=index.php?section=$section&page=$page><< " . $sas_lang['goback'] . "</a></td></tr></table>";
	}
}
?>
