<?php

#############################################################################
#                              Site@School
# Site@School is a website management system designed for schools.
#
############################################################################
# category theme
# main.inc.php: last changed 13/06/2005
#            by F.C. Stuurman (fc.stuurman@hccnet.nl)
#$Id: main.inc.php,v 1.1 2006/10/03 11:13:25 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");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $sas_lang['lang_charset']?>">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
<?php

print "<title>$sitename - $pagetitle</title>";
?>
<style>
A:link, A:active
	{	text-decoration	:	none;
		color		:	#000000;
		background	:	transparent;
		}
A:visited {	color		:	#0000FF;
		background	:	transparent;
		text-decoration	:	none;
		}		
A:hover {	color		:	#000000;
		background	:	#transparent;
                text-decoration	:	none;
		}
.buttonlink {
	FONT-WEIGHT: normal; COLOR: #000000; FONT-SIZE: 10pt; FONT-FAMILY: Verdana, Arial
}
.text {
	FONT-SIZE: 10pt; FONT-FAMILY: Verdana, Arial
}
.colortext {
	FONT-WEIGHT: bold; COLOR: #638ab9; FONT-SIZE: 10pt; FONT-FAMILY: Verdana, Arial
}

.menulink {
font-family: verdana, arial, helvetica, sans-serif;
color: #000000;
}

.menulink A:link {
color: #000000;
text-decoration: none;
}

.menulink A:visited {
color: #000000;
text-decoration: none;
}

.menulink A:hover {
color: #5B7EC4;
text-decoration: none;
}
.heading {
	FONT-WEIGHT: bold; COLOR: #5B7EC4; FONT-FAMILY: Verdana, Arial,sans-serif
}

BODY {
	FONT-SIZE: 10pt; FONT-FAMILY: verdana,sans-serif
}
TD {
	FONT-SIZE: 10pt; FONT-FAMILY: verdana,sans-serif
}
TH {
	FONT-SIZE: 10pt; FONT-FAMILY: verdana,sans-serif
}
UL {
	FONT-SIZE: 10pt; FONT-FAMILY: verdana,sans-serif
}
P {
	FONT-SIZE: 10pt; FONT-FAMILY: verdana,sans-serif
}
</style>
</head>
<body marginwidth="0" marginheight="0" rightmargin="0" topmargin="0" bottommargin="0" leftmargin="0" background="<?php echo $cmsdir ?>/themes/<?php echo $themelocation ?>/background.gif" style="font-family: Verdana, Arial, Helvetica; font-size: 10pt"link="#000000" vlink="#000000" alink="#466C9B">

<table border="0" cellpadding="0" cellspacing="0" width="100%" height="45" background="<?php echo $cmsdir ?>/themes/<?php echo $themelocation ?>/banner-bg.gif">
  <tr>
    <td width="5%" align="left">
    <img border="0" src="<?php echo $cmsdir ?>/themes/<?php echo $themelocation ?>/banner-left.gif" width="1" height="45"></td>
    <td width="70%" align="center" valign="middle"><font face=verdana size=5 color=FFFFFF><b><?php echo $sitename ?></b></font><br>
    </td>
    <td align="right">
    <img border="0" src="<?php echo $cmsdir ?>/themes/<?php echo $themelocation ?>/logo.gif"></td>
    <td width="5%">&nbsp;</td>
   </tr>
</table>
<table border="0" width="100%" cellpadding="0" cellspacing="0" height="18" background="<?php echo $cmsdir ?>/themes/<?php echo $themelocation ?>/bar-bg.gif">
  <tr>
     <td width="160">&nbsp;</td>
     <td width="55%" align="left"><font face="Verdana" size="1">&nbsp;
<?php

$query = "SELECT name FROM $table_sections WHERE id = $section"; // getting the section name
$result = mysql_query($query) or die_script($query, mysql_error());
$sectionname = mysql_result($result, 0);
unset ($query);
unset ($result);
if (!empty ($category)) //only print category when not empty
{
	print "Location: $sectionname -> $category -> $pagetitle";
}
else
{
	print "Location: $sectionname -> $pagetitle";
}

print "</font></td>
     <td align=\"right\"><font size=1>&nbsp;";

if ($_SESSION['site'] == "protected")
{
	print "<a href=\"index.php?section=$_SESSION[section_came_from]&page=$_SESSION[page_came_from]&site=public\">" . $sas_lang['public_area'] . "&nbsp;/</a>";
}

if (IsSet ($_SESSION['userid']))
{
	print "<a href=\"index.php?section=$section&page=$page&logout=yes\">" . $sas_lang['logout'] . "&nbsp;&nbsp;&nbsp;&nbsp;</a>";
}
?>
		  </font>
		 </td>
   </tr>
</table>      
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3">
  <tr>
    <td width="160" bgcolor="#F7F7F7" valign="top">
<?php

print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\">
<tr height=\"30\"><td>&nbsp</td></tr>";

$query = "SELECT id, name FROM $table_sections WHERE invisible != 'yes' ORDER BY sort";
$result = mysql_query($query) or die_script($query, mysql_error());

if (!IsSet ($category))
{
	$query1 = "SELECT category FROM $table_pages WHERE section = '$section' AND id = '$page'"; // getting category of startpage
	$result1 = mysql_query($query1) or die_script($query1, mysql_error());
	$category = mysql_result($result1, 0, 0);
}
while ($sectionmenu = mysql_fetch_array($result))
{
	print "<tr><td align=\"right\">";
	if ($sectionmenu[0] == $section)
	{
		print "<a href=index.php?section=$sectionmenu[0]><img border=\"0\" src=\"$cmsdir/themes/$themelocation/tree_collapse.gif\"></a>";
	}
	else
	{
		print "<a href=index.php?section=$sectionmenu[0]><img border=\"0\" src=\"$cmsdir/themes/$themelocation/tree_expand.gif\"></a>";
	}

	print "</td><td height=\"20\"><b>
	        <span class=\"menulink\"><a href=index.php?section=$sectionmenu[0]>$sectionmenu[1] </a></b></td>
	        </tr>";
	if ($sectionmenu[0] == $section)
	{
		$query1 = "SELECT id, category FROM $table_pages WHERE section = '$section' AND invisible != 'yes' GROUP BY category"; // getting catlist
		$result1 = mysql_query($query1) or die_script($query1, mysql_error());
		print "<tr><td align=\"center\">&nbsp;</td><td>";
		while ($cat_list = mysql_fetch_array($result1))
		{
			$category1 = htmlspecialchars(rawurlencode($cat_list[1]));

			print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
			if (!empty ($cat_list[1])) //only display when category has no blanks
			{
				if ($cat_list[1] == $category)
				{
					print "<tr><td height=\"20\" align=\"right\"><img src=\"$cmsdir/themes/$themelocation/tree_collapse.gif\"></td>";
				}
				else
				{
					print "<tr><td height=\"20\" align=\"right\"><img src=\"$cmsdir/themes/$themelocation/tree_expand.gif\"></td>";
				}
				$query2 = "SELECT id FROM $table_pages WHERE category = '$cat_list[1]' and section = '$section' and invisible != 'yes' ORDER BY sort";
				// getting startpage category
				$result2 = mysql_query($query2) or die_script($query2, mysql_error());
				$startpage = mysql_result($result2, 0, 0);
				print "<td><b><span class=\"menulink\"><a href=index.php?section=$sectionmenu[0]&category=$category1&page=$startpage>$cat_list[1]</a><br>
							   </span></b></td></tr>";
			}
			if ($cat_list[1] == $category)
			{
				$query2 = "SELECT id, name, module, invisible FROM $table_pages WHERE category = '$category' and section = '$section' and invisible != 'yes' ORDER BY sort"; // getting pagelist
				$result2 = mysql_query($query2) or die_script($query2, mysql_error());
				print "<tr><td>&nbsp;</td><td><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
				while ($page_list = mysql_fetch_array($result2)) //loop through pages
				{
					if ($page_list[0] == $page)
					{
						print "<tr><td height=\"20\"><img src=\"$cmsdir/themes/$themelocation/leaf_selected.gif\"></td>";
					}
					else
					{
						print "<tr><td height=\"20\"><img src=\"$cmsdir/themes/$themelocation/leaf.gif\"></td>";
					}

					if (substr($page_list[2], 0, 5) == "http:")
					{
						print "<td><b><span class=\"menulink\"><a href=$page_list[2] target=\"_blank\"><font color=\"blue\">$page_list[1]</font></a><br>
											   </span></b></td></tr>";
					}
					elseif (substr($page_list[2], 0, 5) == "file:")
					{
						$link = substr($page_list[2], 7);
						print "<td><b><span class=\"menulink\"><a href=$link target=\"_blank\"><font color=\"blue\">$page_list[1]</font></a><br>
											   </span></b></td></tr>";
					}
					else
					{
						print "<td><b><span class=\"menulink\"><a href=index.php?section=$sectionmenu[0]&category=$category1&page=$page_list[0]><font color=\"blue\">$page_list[1]</font></a><br>
											   </span></b></td></tr>";
					}
				}
				print "</table></td></tr>";
			}
			print "</td></tr></table>";
		}
	}
}
print "</table>";
?>         

    </td>
    <td valign="top">
<?php

$query = "SELECT module FROM $table_pages WHERE id='$page'";
$result = mysql_query($query) or die_script($query, mysql_error());
$module = mysql_result($result, 0);
unset ($query);
unset ($result);
if ($module != '')
{
	print "<table height=\"490\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\"><tr>
	        <td valign=\"top\" width=\"100%\">";

	include ($cmsdir . "/modules/" . $module);
	print "</td></tr>";
}
else
{
	print "<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($query, mysql_error());
	$content = mysql_result($result, 0);
	unset ($query);
	unset ($result);
	$content = str_replace("../", "", $content);
	print "$content";
}
print "</td></tr>";

$query = "SELECT UNIX_TIMESTAMP(lastupdate) FROM $table_pages where id='$page'";
$result = mysql_query($query) or die_script($query, mysql_error());
$date = mysql_result($result, 0);
unset ($query);
unset ($result);

$date = strftime($sas_config['dateformat'], $date);
?>
<tr>
    <td align="center"><font face="Verdana" size="1">&copy; <?php echo $sitename ?>, last changed on <?php echo $date ?></font></td>
  </tr>
</table>
    </td>
    </tr></table>
</body>
</html>
