<?PHP

#############################################################################
#                              FAgenda
# FAgenda is a website agenda designed for Site@School
# (http://siteatschool.sourceforge.net)
#
# About FAgenda:
# Original idea: Dirk Schouten and Fred Stuurman
# Coding: Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# FILENAME search.php last changed 07/09/2006, S@S version: 2.4.10                                      
#                     by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: search.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
##############################################################################
define('IN_SAS', true);

include ("config.inc.php"); //connect to mysql database
?>
<html>
<head>
<script type="text/javascript">
function popupform(f) {
	var url = ""
	var width = 300; 
	var height = 200;
	var screenX = (screen.width/2 - width/2);
	var screenY = (screen.height/2 - height/2);
	var features= "width=" + width + ",height=" + height;
	features += ",screenX=" + screenX + ",left=" + screenX;
	features += ",screenY=" + screenY  +",top=" + screenY+", resizable=1";
	var mywin=window.open(url, "popup", features);
	mywin.focus();
	f.submit();
}
</script>
</head>
<body BGCOLOR="#B29D78">
<form method="post" action="search.php" target="popup">
<?PHP

if (IsSet ($_POST['searchstring']))
{
	if (!get_magic_quotes_gpc())
	{
		$user = strip_tags(addslashes($_POST['searchstring']));
	}
	else
	{
		$user = strip_tags($_POST['searchstring']);
	}
}

if (IsSet ($_POST[a]))
{
	$a = $_POST[a];
}

$language = "";
$query = "SELECT config_value FROM $table_configuration WHERE config_key='language'"; //get language
$result = mysql_query($query);
$language = mysql_result($result, 0);
if (file_exists("../$cmsdir/languages/" . $language . "/sn_agenda/" . $language . ".php"))
{
	include ("../$cmsdir/languages/" . $language . "/sn_agenda/" . $language . ".php");
}
else
{
	include ("../$cmsdir/languages/EN/sn_agenda/EN.php");
}

$query = "SELECT id, name FROM $table_agenda_name ORDER BY sort"; //get agenda's
$result = mysql_query($query);
$i = 0;
while ($row = mysql_fetch_array($result))
{
	$agenda[$i] = $row[1];
	$agenda_id[$i] = $row[0];
	$i++;
}

$where_clause = "";
$i = 0;
if (count($a) > 0)
{
	foreach ($a as $value)
	{
		if ($value != "")
		{
			$where_clause .= " OR agenda = $value"; //create where clause of agenda id's
			print "<input type=\"hidden\" name=\"a[$i]\" value=\"$value\">";
			$i++;
		}
	}
	$where_clause = substr($where_clause, 3); //strip the first OR           
}
else
{
	$where_clause = "agenda = $agenda_id[0]"; //no agenda selected , use first one
}
?>

<table><tr><td><b><?PHP echo $sas_lang['agenda_search_arg'] ?></b></td></tr>
<td><input type="text" size="50" name="searchstring" value="<?PHP echo $searchstring ?>"></td><td>&nbsp;</td>
<td><input type="button" value="<?PHP echo $sas_lang['agenda_search'] ?>" onclick="popupform(this.form)" ></td>
<td><input type="button" value="<?PHP echo $sas_lang['agenda_goback'] ?>" onClick="javascript:history.go(-1)"></td></tr>
<?PHP

/*
for ($k=0;$k < count($agenda);$k++) {                                 //loop through the agenda's
   
  if ($agenda_id[$k] == $a[$k]) {
   $checked = "checked"; } else {
   $checked = "" ;
   }
print "<tr><td>$agenda[$k]</td>
<td colspan=\"3\"><input TYPE=CHECKBOX NAME=\"a[$k]\" $checked value=\"$agenda_id[$k]\"></td></tr>" ;    
} */
?>

</table></form>
<table bgcolor="#C0DCC0" style="border-style: solid; border-width: 1px;" cellspacing="2" cellpadding="2">
<tr bgcolor='#BDBAFF' style="border-style: solid; border-width: 1px;">
<td colspan="4" align="center"><?PHP echo $sas_lang['agenda_search_results']." <b>".$searchstring ?></b></td></tr>
<tr bgcolor='#FFFFFF'><td><b><?PHP echo $sas_lang['agenda_date'] ?>:</b></td>
                     <td><b><?PHP echo $sas_lang['agenda_time'] ?>:</b></td>
                     <td width=\"400\"><b><?PHP echo $sas_lang['agenda_descr'] ?>:</b></td>
                     <td><b><?PHP echo $sas_lang['agenda_agenda'] ?>:</b></td></tr>

<?PHP


$query = "SELECT a.adate, d.config_value , a.descr, c.name
			FROM $table_agenda_events a 
			LEFT JOIN $table_agenda_name c ON a.agenda=c.id 
			LEFT JOIN $table_configuration d ON a.timeslot = substring(d.config_key,12,14)
			WHERE a.descr LIKE '%$searchstring%' AND ($where_clause)";

$result = mysql_query($query);
$numRows = mysql_num_rows($result);
if ($numRows > 0)
{
	while ($search_list = mysql_fetch_array($result))
	{
		print "<tr bgcolor='#FFFFFF'><td>" . $search_list[0] . "</td>
				<td>" . $search_list[1] . "</td>
				<td>" . $search_list[2] . "</td>
				<td>" . $search_list[3] . "</td></tr>";
	}
}
else
{
	print "<tr bgcolor='#FFFFFF'><td colspan=\"4\">" . $sas_lang['agenda_no_results'] . "</td></tr>";
}
?>
</table>
</body>
</html>
