<?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)
############################################################################
# page_slideshow.php: last changed 20/08/2006  , version: 2.4.10
#              by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: page_slideshow.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);
$loc_id = 0;

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

include ("../configuration/database.inc.php"); //connect to mysql
mysql_connect("$db_server", "$db_username", "$db_password");
mysql_select_db("$db_name");

$table_scripts = $dbprefix . "m_scripts";
$query = "SELECT value1, value2 FROM $table_scripts WHERE active = '1' AND loc_id = '" . $loc_id . "'";

$result = mysql_query($query) or die_script(mysql_error());
$pages = mysql_result($result, 0, 0); //get the pages to display
$speed = mysql_result($result, 0, 1); //get the speed
unset ($query);
unset ($result);

$pages_array = explode(",", $pages); //create an array
$count = count($pages_array) - 1;

if ((IsSet ($page)) OR ($page != 0)) //select startpage of section if no page was selected           		
{
	$key = array_search($_GET[page], $pages_array);

	if ($count == $key)
	{
		$page_next = $pages_array[0]; //last page , next page is first in array
	}
	else
	{
		$page_next = $pages_array[$key +1];
	}
	$page = $_GET[page];
}
else
{
	$page_next = $pages_array[1];
	$page = $pages_array[0];
}

print "<html>
		<head>
		<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">
		<meta http-equiv=\"refresh\" content=\"$speed;url=tv.php?loc_id=$_GET[loc_id]&page=$page_next\">
		</head>
		<body>";

$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>";
?>
