<?PHP

#############################################################################
#                              FAgenda
# FAgenda is a website agenda designed for and integrated in Site@School.
# (http://siteatschool.sourceforge.net)
#
# About FAgenda:
# Original idea: Dirk Schouten and Fred Stuurman
# Coding: Fred Stuurman (fc.stuurman@hccnet.nl)
#############################################################################
# config.inc.php  last changed 07/09/2006, S@S version: 2.4.10                                        
#             by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: config.inc.php,v 1.2 2006/10/15 19:08:53 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
# Copyright (C) 2004 Fred Stuurman (fc.stuurman@hccnet.nl)
#
# FAgenda is an integrated part of the Site@School Content Management System.
# FAgenda may not be modified, taken out of Site@School and/or distributed 
# without the written permission of the author.
# 
# FAgenda is free to use for Educational use and may be used free-of-charge 
# by members of eucational institutions, but must be purchased by all others.
# Contact the author, F. Stuurman (fc.stuurman@hccnet.nl), for 
# non-educational use or adapting FAgenda to your requirements.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# FITNESS FOR A PARTICULAR PURPOSE.
#
#                   DO NOT REMOVE THIS COPYRIGHT NOTICE
##############################################################################
if (!defined('IN_SAS'))
{
	die("Hacking attempt");
}

define('SAS_VERSION', '2.4.03');
$cmsdir = 'starnet';

function error_exit($conditioncode, $ttl = "Error")
{
	/*---------------------------------
	 * Show a 'cryptic' condition code + exit
	 */
	echo "<html>\n<head>\n<title>$ttl</title>\n</head>\n<body>\n" .
	"<h1>$ttl</h1>\n" .
	"<b>There is a problem with this site.</b>\n<p>\n" .
	"Please contact the site owner mentioning the " .
	"following condition code:\n<p>\n<b>" .
	SAS_VERSION . '/' . $conditioncode . "</b>\n<p>\n" .
	"Thank you for your cooperation!\n</body>\n</html>\n";
	exit;
} /* error_exit() */

// SANITY CHECK #1 - is there an existing installation at the location we expect?
if (!file_exists('../' . $cmsdir . '/configuration/database.inc.php'))
{
	error_exit('010');
}

// SANITY CHECK #2 - do we have a connection to a working database?
include ('../' . $cmsdir . '/configuration/database.inc.php');
if (!($db = mysql_connect($db_server, $db_username, $db_password)))
{
	error_exit('020');
}

// SANITY CHECK #3 - do we have access to our own database?
if (!mysql_select_db($db_name))
{
	error_exit('030');
}

/*
 * Still here? Must have valid database in our hands then. Carry on...
 */
error_reporting($old_error_reporting); // switch on error reporting after sanity checks

require ("../$cmsdir/core/session.php"); //build a session

$query = "SELECT config_value FROM $table_configuration WHERE config_key='sessioncode'";
if ($result = mysql_query($query))
{
	$check_sessioncode = mysql_result($result, 0);
	unset ($query);
	unset ($result);
}
if ($_SESSION['sessioncode'] != $check_sessioncode)
{
	//if we don't have a session exit
	exit;
}

if (IsSet ($_SESSION['userid']))
{
	$userid = $_SESSION['userid'];
}
else
{
	$userid = "";
}

$usertype = $_SESSION['usertype'];

if (IsSet ($userid) AND $usertype == "teacher")
{
	$query = "SELECT dbtables FROM $table_modules WHERE location='sn_agenda'"; //get the table names for the agenda 
	$result = mysql_query($query);
	$moduletables = mysql_result($result, 0);
	unset ($query);
	unset ($result);
	$moduletables = explode(",", $moduletables);
	$table_agenda_events = "$moduletables[0]";
	$table_agenda_name = "$moduletables[1]";

	$query = "SELECT config_value FROM $table_configuration WHERE config_key='agenda_options'";
	$result = mysql_query($query);
	$agenda_options = mysql_result($result, 0, 0);
	$agenda_options = explode(",", $agenda_options);

	$busy_color = $agenda_options[0];
	$busy_color_edit = $agenda_options[1];
	$bgcolor = $agenda_options[2];
	$months_bgcolor = $agenda_options[3];
	$months_font_color = $agenda_options[4];
	$weekend_color = $agenda_options[5];
	$day_color = $agenda_options[6];
	$timeslots_header_color = $agenda_options[7];
	$week_days_bgcolor = $agenda_options[8];
	$week_number_bgcolor = $agenda_options[9];
	$active_day_color = $agenda_options[10];
	$mouse_over_color = $agenda_options[11];

	$query = "SELECT config_value FROM $table_configuration WHERE config_key='url'";
	$result = mysql_query($query);
	$pa_link = mysql_result($result, 0, 0);
}
else
{
	print $sas_lang['agenda_noaccess'];
	exit;
}
?>
