<?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)
############################################################################
# teacher_page.php: last changed 12/03/2006 2.4
#               by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: teacher_page.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");
}
if (IsSet ($_GET['student']))
{
	$student = $_GET['student'];
}
if (IsSet ($_GET['viewclass']))
{
	$viewclass = $_GET['viewclass'];
}

if (!IsSet ($student))
{

	print "<center><h3>" . $sas_lang['teacher_pages'] . ":</h3></center><p>";

	print "<table border=\"0\"><tr>";
	$query1 = "SELECT id, name, class FROM $table_users 
	              WHERE (type = 2 OR type = 22) ORDER BY name";

	$result1 = mysql_query($query1) or die_script($query1, mysql_error());
	$i = 0;
	while ($student_list = mysql_fetch_array($result1)) //list the teachers
	{
		$query2 = "SELECT studentid, title, dir_number FROM $table_studentpages 
		                 WHERE dir_number='$student_list[0]' AND content != '' AND (pcheck = 1 OR pcheck = 2) 
		                 ORDER BY title";
		$result2 = mysql_query($query2) or die_script($query2, mysql_error());
		$num_rows = mysql_num_rows($result2);
		if ($num_rows > 0)
		{
			print "<tr>
				 	          <td>&nbsp;&nbsp</td>
			                 <td>$student_list[1]</td>";
			while ($page_list = mysql_fetch_array($result2))
			{
				print "<td>&nbsp;</td><td><a href=index.php?section=$section&page=$page&student=$page_list[0]>$page_list[1]</a></td>";
			}
			print "</tr>";
			$i++;
		}
	}
	print "</table>";

}

else
{
	$query = "SELECT title, dir_number, content FROM $table_studentpages WHERE studentid='$student'"; // getting the title and content
	$result = mysql_query($query) or die_script($query, mysql_error());
	$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 ($query);
	unset ($result);
	$query2 = "SELECT studentid, title FROM $table_studentpages WHERE dir_number='$studentid' AND studentid!='$student'  AND content != '' ORDER BY title"; // getting the title of other pages
	$result2 = mysql_query($query2) or die_script($query2, mysql_error());
	$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>";
		}
	}
	print "<td align=\"right\"><a href=index.php?section=$section&page=$page&viewclass=$viewclass><< " . $sas_lang['goback'] . "</a></td></tr></table>";
}
?>
