<script type="text/javascript">

function View(color) {                  // preview color
  document.getElementById("ColorPreview").style.backgroundColor = '#' + color;
  document.getElementById("ColorHex").value = '#' + color;
}

function Set(string) {                   // select color
  var color = ValidateColor(string);
  if (color == null) { alert("Invalid color code: " + string); }        // invalid color
  else {                                                                // valid color
    View(color);                          // show selected color
    __dlg_close(color);
  }
}

</script>
<?php

#############################################################################
#                              Site@School Forms module
# Site@School is a website management system designed for schools.
# This is a calendar module which can be used in Site@School.
#
# idea and design by by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: admin.php,v 1.1 2006/10/03 08:57:53 fstuurman Exp $
############################################################################
# admin.php: last changed 13/10/2004  version 1.1
#                  by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: admin.php,v 1.1 2006/10/03 08:57:53 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['saveconfig']))
{
	$saveconfig = $_GET['saveconfig'];
}
if (IsSet ($_GET['addagenda']))
{
	$addagenda = $_GET['addagenda'];
}
if (IsSet ($_GET['editagenda']))
{
	$editagenda = $_GET['editagenda'];
}
if (IsSet ($_GET['saveagenda']))
{
	$saveagenda = $_GET['saveagenda'];
}
if (IsSet ($_GET['deleteagenda']))
{
	$deleteagenda = $_GET['deleteagenda'];
}
if (IsSet ($_POST['timeslot']))
{
	$timeslot = $_POST['timeslot'];
}
if (IsSet ($_POST['agenda_name']))
{
	$agenda_name = $_POST['agenda_name'];
}
if (IsSet ($_POST['agenda_sort']))
{
	$agenda_sort = $_POST['agenda_sort'];
}
if (IsSet ($_POST['agenda_user']))
{
	$agenda_user = $_POST['agenda_user'];
}
if (IsSet ($_POST['agenda_options']))
{
	$agenda_options = $_POST['agenda_options'];
}

load_language('', 'sn_agenda'); //load language file

$query = "SELECT name, dbtables FROM $table_modules where id=$module"; //get the module name                
$result = mysql_query($query) or die_script($query, mysql_error());
$modulename = mysql_result($result, 0, 0);
$moduletables = mysql_result($result, 0, 1);
unset ($query);
unset ($result);
$moduletables = explode(",", $moduletables);
$table_agenda_events = "$moduletables[0]";
$table_agenda_name = "$moduletables[1]";

include ("interface/header.inc.php");
include ("interface/menubar.inc.php");
include ("interface/menustart.inc.php");
print "<span class=heading>" . $sas_lang['filemanager_menu'] . "</span><br><br>";
print "<span class=link><a href=index.php?option=modulemanager&module=$module>" . $sas_lang['manage'] . "</a><p>
<a href=index.php?option=modulemanager&module=$module&modoption=configuration>" . $sas_lang['configuration'] . "</a><p></span>";
include ("interface/menuend.inc.php");
include ("interface/pagestart.inc.php");
print "<span class=\"heading\">$modulename<br></span>";
print "<span class=\"text\">" . $sas_lang['agenda_introduction'] . "</span><p>";

if ($saveconfig == "yes")
{
	$comma_separated = implode(",", $agenda_options);
	for ($i = 1; $i < 46; $i++)
	{
		if ($i < 10)
		{
			mysql_query("UPDATE $table_configuration SET config_value='$timeslot[$i]' WHERE config_key='agenda_time0$i'");
		}
		else
		{
			mysql_query("UPDATE $table_configuration SET config_value='$timeslot[$i]' WHERE config_key='agenda_time$i'");
		}
	}
	mysql_query("UPDATE $table_configuration SET config_value='$comma_separated' WHERE config_key='agenda_options'");
}

if (IsSet ($saveagenda))
{

	if ($saveagenda == "new")
	{
		mysql_query("INSERT INTO $table_agenda_name (id, name, sort, username) VALUES (NULL, '$agenda_name', '$agenda_sort', '$agenda_user')");
	}
	else
	{
		mysql_query("UPDATE $table_agenda_name SET name='$agenda_name' WHERE id='$saveagenda'");
		mysql_query("UPDATE $table_agenda_name SET sort='$agenda_sort' WHERE id='$saveagenda'");
		mysql_query("UPDATE $table_agenda_name SET username='$agenda_user' WHERE id='$saveagenda'");
	}
}

if (IsSet ($deleteagenda))
{
	mysql_query("DELETE FROM $table_agenda_name WHERE id='$deleteagenda'");
	mysql_query("DELETE FROM $table_agenda_events WHERE agenda='$deleteagenda'"); //delete all events
}

if (IsSet ($addagenda))
{
	print "<FORM METHOD=\"POST\" enctype=\"multipart/form-data\" ACTION=\"index.php?option=modulemanager&module=$module&saveagenda=new\">";
	print "
	<p><table cellspacing=\"3\">
	<tr><td><span class=\"text\">" . $sas_lang['agenda_name'] . ": </span></td>
	<td><input tabindex=\"48\" type=text size=50 class=\"textfield\" name=\"agenda_name\"></td></tr>
	<tr><td><span class=\"text\">" . $sas_lang['agenda_sort'] . ": </span></td>
	<td><input tabindex=\"48\" type=text size=5 class=\"textfield\" name=\"agenda_sort\"></td></tr>
	<tr><td><span class=\"text\">" . $sas_lang['username'] . ": </span></td>
	<td><input tabindex=\"50\" type=text size=20 class=\"textfield\" name=\"agenda_user\"></td>
	</tr>
	
	</table>";

	print "<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[cancel]\" name=\"backbutton\" onClick=\"javascript:parent.location='index.php?option=modulemanager&module=$module';\" class=\"cancelbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" class=\"savebutton\"></form>";

	include ("interface/pageend.inc.php");
	include ("interface/footer.inc.php");
	exit;
}

if (IsSet ($editagenda))
{
	$query = "SELECT name, sort, username FROM $table_agenda_name WHERE id='$editagenda'";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$agenda_name = mysql_result($result, 0, 0);
	$agenda_sort = mysql_result($result, 0, 1);
	$agenda_user = mysql_result($result, 0, 2);

	print "<FORM METHOD=\"POST\" enctype=\"multipart/form-data\" ACTION=\"index.php?option=modulemanager&module=$module&saveagenda=$editagenda\">";
	print "
	<p><table cellspacing=\"3\">   
	<tr><td><span class=\"text\">" . $sas_lang['agenda_name'] . ": </span></td>
	<td><input tabindex=\"48\" type=text size=50 class=\"textfield\" name=\"agenda_name\" value=\"$agenda_name\"></td></tr>
	<tr><td><span class=\"text\">" . $sas_lang['agenda_sort'] . ": </span></td>
	<td><input tabindex=\"49\" type=text size=5 class=\"textfield\" name=\"agenda_sort\" value=\"$agenda_sort\"><td></tr>
	<tr><td><span class=\"text\">" . $sas_lang['username'] . ": </span></td>    
	<td><input tabindex=\"50\" type=text size=20 class=\"textfield\" name=\"agenda_user\" value=\"$agenda_user\"></td></tr>
	</tr>
	
	</table>";

	print "<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[cancel]\" name=\"backbutton\" onClick=\"javascript:parent.location='index.php?option=modulemanager&module=$module';\" class=\"cancelbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" onClick=\"javascript:save()\" class=\"savebutton\"></form>";

	include ("interface/pageend.inc.php");
	include ("interface/footer.inc.php");
	exit;
}

$agenda_options = explode(",", $sas_config['agenda_options']);
//print $sas_config['agenda_options'] ;

if ($modoption == "configuration")
{
	$query = "SELECT config_value FROM $table_configuration WHERE config_key LIKE 'agenda_time%' ORDER BY config_key";
	$result = mysql_query($query) or die_script($query, mysql_error());
	print "<form METHOD=\"POST\" ACTION=\"index.php?option=modulemanager&module=$module&saveconfig=yes\">
	       <table><tr><td colspan=\"14\"><span class=\"text\"><b>" . $sas_lang['agenda_timeslots'] . "</b></span></td></tr><tr>";
	$i = 1;
	$k = 0;
	while ($time_list = mysql_fetch_array($result))
	{
		if ($k == 9)
		{
			print "</tr><tr>";
			$k = 0;
		}
		print "<td align=\"right\"><span class=\"text\">$i :</span></td>
		           <td><input tabindex=\"$i\" class=\"textfield\" size=\"5\" name=\"timeslot[$i]\" value=\"$time_list[0]\"></td>";

		$k++;
		$i++;
	}
	print "</tr></table>";
	print "<p><table>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_busy_color'] . ": </span></td>
	      <td><input tabindex=\"46\" type=text size=8 class=\"textfield\" name=\"agenda_options[0]\" value=\"$agenda_options[0]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[0]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td>
	      <td valign=\"top\" rowspan=\"11\">";

	include ("interface/color_table.html");

	print "</td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_busy_color_edit'] . ": </span></td>
	      <td><input tabindex=\"47\" type=text size=8 class=\"textfield\" name=\"agenda_options[1]\" value=\"$agenda_options[1]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[1]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_bgcolor'] . ": </span></td>
	      <td><input tabindex=\"48\" type=text size=8 class=\"textfield\" name=\"agenda_options[2]\" value=\"$agenda_options[2]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[2]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_months_bgcolor'] . ": </span></td>
	      <td><input tabindex=\"49\" type=text size=8 class=\"textfield\" name=\"agenda_options[3]\" value=\"$agenda_options[3]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[3]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_months_font_color'] . ": </span></td>
	      <td><input tabindex=\"50\" type=text size=8 class=\"textfield\" name=\"agenda_options[4]\" value=\"$agenda_options[4]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[4]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_weekend_color'] . ": </span></td>
	      <td><input tabindex=\"51\" type=text size=8 class=\"textfield\" name=\"agenda_options[5]\" value=\"$agenda_options[5]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[5]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_day_color'] . ": </span></td>
	      <td><input tabindex=\"52\" type=text size=8 class=\"textfield\" name=\"agenda_options[6]\" value=\"$agenda_options[6]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[6]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_timeslots_header_color'] . ": </span></td>
	      <td><input tabindex=\"53\" type=text size=8 class=\"textfield\" name=\"agenda_options[7]\" value=\"$agenda_options[7]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[7]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_week_days_bgcolor'] . ": </span></td>
	      <td><input tabindex=\"54\" type=text size=8 class=\"textfield\" name=\"agenda_options[8]\" value=\"$agenda_options[8]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[8]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_week_number_bgcolor'] . ": </span></td>
	      <td><input tabindex=\"55\" type=text size=8 class=\"textfield\" name=\"agenda_options[9]\" value=\"$agenda_options[9]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[9]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_active_day_color'] . ": </span></td>
	      <td><input tabindex=\"56\" type=text size=8 class=\"textfield\" name=\"agenda_options[10]\" value=\"$agenda_options[10]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[10]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['agenda_mouse_over_color'] . ": </span></td>
	      <td><input tabindex=\"56\" type=text size=8 class=\"textfield\" name=\"agenda_options[11]\" value=\"$agenda_options[11]\"></td>
	      <td width=\"50\"><table bgcolor=\"$agenda_options[11]\" height=\"20\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"1\"><tr><td>&nbsp;</td></tr></table></td></tr>";
	print "</table>";

	print "</table><br>&nbsp;<input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[cancel]\" name=\"backbutton\" onClick=\"javascript:parent.location='index.php?option=modulemanager';\" class=\"cancelbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" onClick=\"javascript:save()\" class=\"savebutton\"></form>";
}
else
{
	$query = "SELECT id, name, sort FROM $table_agenda_name ORDER BY sort";
	$result = mysql_query($query) or die_script($query, mysql_error());
	if (mysql_num_rows($result) > 0)
	{
		while ($agenda_list = mysql_fetch_array($result))
		{
			print "<table>
			        <tr>
			        <td><img border=\"0\" src=\"graphics/delete.gif\" alt=\"" . $sas_lang['delete'] . "\" title=\"" . $sas_lang['delete'] . "\" width=\"16\" height=\"16\" onClick=\"if(confirm('" . $sas_lang['agenda_delete_agenda_confirm'] . "'))
			        parent.location='index.php?option=modulemanager&module=$module&deleteagenda=$agenda_list[0]';\">
			        <img border=\"0\" src=\"graphics/edit.gif\" alt=\"" . $sas_lang['edit'] . "\" title=\"" . $sas_lang['edit'] . "\" width=\"16\" height=\"16\" onClick=\"parent.location='index.php?option=modulemanager&module=$module&editagenda=$agenda_list[0]'\">
			        </td>
			        <td><span class=link><a href=\"index.php?option=modulemanager&module=$module&editagenda=$agenda_list[0]\">($agenda_list[2]) $agenda_list[1]</a></span></td>
			        </tr>";
			print "</table>";
		}
	}
	print "<br><img border=\"0\" src=\"graphics/document.gif\">
	       <span class=\"link\"><a href=\"index.php?option=modulemanager&module=$module&addagenda=new\">" . $sas_lang['agenda_add'] . "</a></span>";
	print "<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['goback'] . "\" name=\"backbutton\" onClick=\"javascript:parent.location='index.php?option=modulemanager';\" class=\"backbutton\">";
}

include ("interface/pageend.inc.php");
include ("interface/footer.inc.php");
?>