<?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)
############################################################################
# index.php: last changed 04/10/2004  , version: 2.4.10
#              by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: show_page.php,v 1.2 2006/10/15 19:08:54 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.
##############################################################################
define('IN_SAS', true);
include ("../configuration/database.inc.php"); //connect to mysql
mysql_connect("$db_server", "$db_username", "$db_password");
mysql_select_db("$db_name");

$cmsdir = "starnet";
$loc_id = 0;
$page = 0;
$section = 0;

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

if ((IsSet ($_GET['page'])) AND (!IsSet ($_GET['loc_id'])))
{
	$page = intval($_GET['page']);
}
else
{
	$scripts_table = $dbprefix . "m_scripts";

	$query = "SELECT value1 FROM $scripts_table WHERE active = '1' AND loc_id = '" . $loc_id . "'";
	$result = mysql_query($query) or die_script(mysql_error());
	$page = mysql_result($result, 0, 0); //get the page to display
	unset ($query);
	unset ($result);
}

unset ($sas_config);
$query = "SELECT config_key,config_value FROM $table_configuration WHERE config_key NOT LIKE 'agenda%'"; //read all the configuration items
$result = mysql_query($query) or die_script(mysql_error());
while ($config_list = mysql_fetch_array($result))
{
	$sas_config[$config_list[0]] = $config_list[1]; //put them in the config array
}

if (IsSet ($_SESSION['userid']) AND ($_SESSION['usertype'] == "teacher" OR $_SESSION['user_type'] > 19) and $site == "protected")
	//are we allowed to get intranet access, then switch to the protected tables
{
	$table_sections = $dbprefix . "prot_sections";
	$table_pages = $dbprefix . "prot_pages";
}

if ((!IsSet ($section)) OR ($section == 0)) //select startsection if no section was selected
{
	if ($site == "protected")
	{
		$section = $sas_config['protected_startsection'];
	}
	else
	{
		$section = $sas_config['startsection'];
	}
}

if ((!IsSet ($page)) OR ($page == 0)) //select startpage of section if no page was selected
{
	$query = "SELECT frontpage FROM $table_sections WHERE id = '" . $section . "'";
	$result = mysql_query($query) or die_script(mysql_error());
	$page = mysql_result($result, 0);
	unset ($query);
	unset ($result);
}
$query = "SELECT name FROM $table_pages WHERE id = '" . $page . "'"; //selecting the title of the page
$result = mysql_query($query) or die_script(mysql_error());
if (!@ $pagetitle = mysql_result($result, 0))
{
	print "No page was set as startpage for this section of the site";
	exit;
}

$query = "SELECT module FROM $table_pages WHERE id = '" . $page . "'";
$result = mysql_query($query) or die_script(mysql_error());
$module = mysql_result($result, 0);
unset ($query);
unset ($result);

if ($module != '')
{
	print "Pages with modules are not supported via the showpage script!<br>";

	//include("../modules/$module");
}
else
{
	print "<body bgcolor=\"#000000\" text=\"#FFFFFF\" link=\"#FFFFFF\" vlink=\"#FFFFFF\" alink=\"#FFFFFF\" leftmargin=\"0\" topmargin=\"3\">
					<table height=\"490\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\">
					<tr><td valign=\"top\" width=\"100%\">";
	$query = "SELECT content FROM $table_pages WHERE id = '" . $page . "'";
	$result = mysql_query($query) or die_script(mysql_error());
	$content = mysql_result($result, 0);
	unset ($query);
	unset ($result);
	$content = str_replace("../", "", $content);
	print $content;
}
print "</td></tr>";
?>
</table>
</body>
</html>