<?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.3): Fred Stuurman 
# Current coder & maintainer: Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# admin.php: last changed 27/04/2004  , version: 2.3
#            by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: admin.php,v 1.1 2006/10/03 08:54:49 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
# Copyright (C) 2002 - 2005 Municipality of Amsterdam, City District
#  'de Baarsjes', Amsterdam, the Netherlands.
#
# 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");
}
include ("interface/header.inc.php");
include ("interface/menubar.inc.php");
include ("interface/menustart.inc.php");
include ("interface/menuend.inc.php");
include ("interface/pagestart.inc.php");
if (file_exists("languages/" . $language . "/dgs_search/" . $language . ".php"))
{
	include ("languages/" . $language . "/dgs_search/" . $language . ".php");
}
else
{
	include ("languages/EN/dgs_search/EN.php");
}

$query = "SELECT name FROM $table_modules WHERE id=$module";
$result = mysql_query($query) or die_script($query, mysql_error());
$modulename = mysql_result($result, 0);
unset ($query);
unset ($result);

print "<span class=\"heading\">$modulename " . $sas_lang['configuration'] . "<br></span>";

if ($modoption == "saveconfig")
{
	if (IsSet ($_POST['pageid']))
	{
		$pageid = $_POST['pageid'];
	}
	if (IsSet ($_POST['sectionid']))
	{
		$sectionid = $_POST['sectionid'];
	}
	if (IsSet ($_POST['active']))
	{
		$active = $_POST['active'];
	}
	if (IsSet ($_POST['pageid_p']))
	{
		$pageid_p = $_POST['pageid_p'];
	}
	if (IsSet ($_POST['sectionid_p']))
	{
		$sectionid_p = $_POST['sectionid_p'];
	}
	if (IsSet ($_POST['active_p']))
	{
		$active_p = $_POST['active_p'];
	}
	if (IsSet ($_POST['max']))
	{
		$max = $_POST['max'];
	}
	if (IsSet ($_POST['invisible']))
	{
		$invisible = $_POST['invisible'];
	}

	if (!get_magic_quotes_gpc())
	{
		$welcome = addslashes($_POST['welcome']);
	}
	else
	{
		$welcome = $_POST['welcome'];
	}

	for ($i = 1; $i < count($pageid) + 1; $i++)
	{
		$section = $sectionid[$i -1];
		$page = $pageid[$i -1];
		$section_p = $sectionid_p[$i -1];
		$page_p = $pageid_p[$i -1];
		mysql_query("UPDATE $table_configuration SET config_value='$section,$page,$section_p,$page_p' WHERE config_key='search_module_pageid$i'");
		$query = "SELECT config_value FROM $table_configuration WHERE config_key='search_module_name$i'";
		$result = mysql_query($query) or die_script($query, mysql_error());
		$search_options = substr(mysql_result($result, 0), 0, -4);
		if ($active[$i -1] == 1)
		{
			$act = 1;
		}
		else
		{
			$act = 0;
		}

		if ($active_p[$i -1] == 1)
		{
			$act_p = 1;
		}
		else
		{
			$act_p = 0;
		}
		mysql_query("UPDATE $table_configuration SET config_value='$search_options,$act,$act_p' WHERE config_key='search_module_name$i'");

	}
	mysql_query("UPDATE $table_configuration SET config_value='$welcome' WHERE config_key='search_module_welcome'");
	mysql_query("UPDATE $table_configuration SET config_value='$max' WHERE config_key='search_module_results'");
	mysql_query("UPDATE $table_configuration SET config_value='$invisible' WHERE config_key='search_module_invisible'");
	print "<p><span class=\"text\"><b>" . $sas_lang['search_module_config_saved'] . "</b></span>";
	print "<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"javascript:parent.location='index.php?option=modulemanager&module=$module';\" class=\"backbutton\">";

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

$welcome = $sas_config['search_module_welcome'];
$max = $sas_config['search_module_results'];
$invisible = $sas_config['search_module_invisible'];

print "<span class=\"text\">" . $sas_lang['search_module_intro'] . "</span>";
print "<FORM METHOD=\"POST\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=saveconfig\"><br><span class=\"text\">" . $sas_lang['gbook_module_welcome_text'] . "<br>";
print "<span class=\"text\">" . $sas_lang['search_module_invisible'] . ":&nbsp;</span><span class=text>" . $sas_lang['yes'] . "</span>";
if ($invisible == 1)
{
	print "<input type=\"radio\" value=\"1\" name=\"invisible\" checked>";
	print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"invisible\" value=\"0\"><p>";
}
else
{
	print "<input type=\"radio\" value=\"1\" name=\"invisible\">";
	print "<span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"invisible\" value=\"0\" checked><p>";
}
print "<span class=\"text\">" . $sas_lang['search_module_results_per_page'] . ":&nbsp;</span><input type=text size=3 class=\"textfield\" name=\"max\" value=\"$max\">&nbsp;<br><br>";
print "<span class=\"text\"><b>" . $sas_lang['search_module_welcome_text'] . ":</b><br>";
print "<textarea cols=\"70\" rows=\"4\" name=\"welcome\">$welcome</textarea><p>\n";

$result = mysql_query("SELECT config_value FROM $table_configuration WHERE config_key LIKE 'search_module_name%'");
$result1 = mysql_query("SELECT config_value FROM $table_configuration WHERE config_key LIKE 'search_module_pageid%'");
$i = 0;
print "<table width=\"600\">
        <tr><td>&nbsp;</td><td colspan=\"3\" align=\"center\"><span class=\"text\"><b>Public site:</b></span></td>
        <td colspan=\"3\" align=\"center\"><span class=\"text\"><b>Protected site:</b></span></td></tr>
        <tr><td><span class=\"text\"><b>" . $sas_lang['module_name'] . "</b></span></td>       
        <td align=\"right\"><span class=\"text\"><b>" . $sas_lang['search_module_sectionid'] . ":</b></span></td>
        <td align=\"right\"><span class=\"text\"><b>" . $sas_lang['search_module_pageid'] . ":</b></span></td>
        <td align=\"right\"><span class=\"text\"><b>" . $sas_lang['search_module_active'] . ":</b></span></td>
        <td align=\"right\"><span class=\"text\"><b>" . $sas_lang['search_module_sectionid'] . ":</b></span></td>
        <td align=\"right\"><span class=\"text\"><b>" . $sas_lang['search_module_pageid'] . ":</b></span></td>        
        <td align=\"right\"><span class=\"text\"><b>" . $sas_lang['search_module_active'] . ":</b></span></td></tr>
        <tr><td colspan=\"7\">&nbsp;</td></tr>";
while ($mod_list = mysql_fetch_array($result))
{
	$search_modules = explode(",", $mod_list[0]);
	$location = $search_modules[0];
	$module_table = $dbprefix . $search_modules[1];
	//skip $search_modules[2] is 0 or 1 for using the public fields yes or no
	$search_active = $search_modules[3];
	$search_active_p = $search_modules[4];
	$result2 = mysql_query("SELECT name FROM $table_modules WHERE location = '$location'");

	if (mysql_num_rows($result2) > 0)
	{
		$module_name = mysql_result($result2, 0);
	}
	else
	{
		$module_name = "-";
	}

	$pag_sec = explode(",", mysql_result($result1, $i));
	$sectionid = $pag_sec[0];
	$pageid = $pag_sec[1];
	$sectionid_p = $pag_sec[2];
	$pageid_p = $pag_sec[3];
	print "<tr><td><span class=\"link\"><b>" . $module_name . "</b></span></td>          
	           <td align=\"right\"><input type=\"text\" size=3 class=\"textfield\" name=\"sectionid[$i]\" value=\"$sectionid\"></td>
	           <td align=\"right\"><input type=\"text\" size=3 class=\"textfield\" name=\"pageid[$i]\" value=\"$pageid\"></td>";
	if ($search_active == 1)
	{
		print "<td align=\"right\"><input type=\"checkbox\" name=\"active[$i]\" value=1 checked></td>";
	}
	else
	{
		print "<td align=\"right\"><input type=\"checkbox\" name=\"active[$i]\" value=1 ></td>";
	}
	print "<td align=\"right\"><input type=\"text\" size=3 class=\"textfield\" name=\"sectionid_p[$i]\" value=\"$sectionid_p\"></td>
	         <td align=\"right\"><input type=\"text\" size=3 class=\"textfield\" name=\"pageid_p[$i]\" value=\"$pageid_p\"></td>
	           ";
	if ($search_active_p == 1)
	{
		print "<td align=\"right\"><input type=\"checkbox\" name=\"active_p[$i]\" value=1 checked></td></tr>";
	}
	else
	{
		print "<td align=\"right\"><input type=\"checkbox\" name=\"active_p[$i]\" value=1 ></td></tr>";
	}

	$i++;
}

print "</table>";

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

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