<?php

#############################################################################
#                              Site@School Template editor module
# Site@School is a website management system designed for schools.
# This is a Template editor module which can be used in Site@School.
#
# idea and design Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# admin.php: last changed 12/03/2005 1.0.1
#                    by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: admin.php,v 1.1 2006/10/03 10:49:08 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");
}
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['public_area'] . "</a></span><p>
       <span class=link><a href=index.php?option=modulemanager&module=$module&modoption=protected>" . $sas_lang['protected_area'] . "</a><br></span><p>
       <span class=link><a href=modules/sn_templates/export.php>Export</a><br></span><p>
       <span class=link><a href=index.php?option=modulemanager&module=$module&modoption=import>Import</a><br></span>";
include ("interface/menuend.inc.php");
include ("interface/pagestart.inc.php");

load_language('', 'sn_templates'); //load language file
?>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function popUp(URL) 
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=550,left = 550,top = 325');");
}
// End -->
</script>

<?php

if (IsSet ($_POST['header']))
{
	$header = $_POST['header'];
}
if (IsSet ($_POST['section']))
{
	$section = $_POST['section'];
}
if (IsSet ($_POST['status']))
{
	$status = $_POST['status'];
}
if (IsSet ($_POST['menu']))
{
	$menu = $_POST['menu'];
}
if (IsSet ($_POST['content']))
{
	$content = $_POST['content'];
}
//if (!get_magic_quotes_gpc())
//{
//if(IsSet($_POST['footer']))                {$footer_new =  addslashes($_POST['footer']);}
//}
//else
//{
if (IsSet ($_POST['footer']))
{
	$footer_new = $_POST['footer'];
}
//}
if (IsSet ($_GET['site']))
{
	$site = $_GET['site'];
}
if (IsSet ($_POST['general']))
{
	$general = $_POST['general'];
}

$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);

$template_table = $dbprefix . "m_template";

print "<SCRIPT LANGUAGE=\"Javascript\" SRC=\"interface/ColorPicker2.js\"></SCRIPT>
<SCRIPT LANGUAGE=\"JavaScript\">
var cp = new ColorPicker('window'); // Popup window
</SCRIPT>";

$fonts_array = array (
	'Arial',
	'Century Schoolbook',
	'Comic Sans MS',
	'Courier New',
	'Georgia',
	'Times New Roman',
	'Tahoma',
	'Verdana'
);

if ($modoption == "saveimport")
{
	if (file_exists($_FILES["file"]["tmp_name"]))
	{
		$temp = $_FILES["file"]["tmp_name"];
		$import_string = fread(fopen($temp, 'r'), filesize($temp)); //read the uploaded temp file into a string
		$import_string = explode(";", $import_string); //create an array
		$key = array (
			'template_content',
			'template_content_prot',
			'template_footer',
			'template_footer_prot',
			'template_general',
			'template_general_prot',
			'template_header',
			'template_header_prot',
			'template_menu',
			'template_menu_prot',
			'template_section',
			'template_section_prot',
			'template_status',
			'template_status_prot'
		);
		// config_key array
		$i = 0;
		foreach ($import_string as $value)
		{
			if ($value != "")
			{
				mysql_query("UPDATE $table_configuration SET config_value = '$value' WHERE config_key = '$key[$i]' "); //update each config key
				$sas_config[$key[$i]] = $value; //get the new value in the config array
			}
			$i++;
		}
	}

}

if ($modoption == "saveconfig")
{
	ksort($header);
	$comma_separated_header = implode(",", $header);
	ksort($section);
	$comma_separated_section = implode(",", $section);
	ksort($status);
	$comma_separated_status = implode(",", $status);
	ksort($menu);
	$comma_separated_menu = implode(",", $menu);
	ksort($content);
	$comma_separated_content = implode(",", $content);
	ksort($footer_new);
	$comma_separated_footer = implode(",", $footer_new);
	ksort($general);
	$comma_separated_general = implode(",", $general);

	if ($site == "protected")
	{
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_header' WHERE config_key='template_header_prot'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_section' WHERE config_key='template_section_prot'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_status' WHERE config_key='template_status_prot'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_menu' WHERE config_key='template_menu_prot'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_content' WHERE config_key='template_content_prot'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_footer' WHERE config_key='template_footer_prot'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_general' WHERE config_key='template_general_prot'");
		$sas_config['template_header_prot'] = $comma_separated_header; //get the new saved values
		$sas_config['template_section_prot'] = $comma_separated_section;
		$sas_config['template_status_prot'] = $comma_separated_status;
		$sas_config['template_content_prot'] = $comma_separated_content;
		$sas_config['template_menu_prot'] = $comma_separated_menu;
		$sas_config['template_footer_prot'] = $comma_separated_footer;
		$sas_config['template_general_prot'] = $comma_separated_general;
		$modoption = "protected";
	}
	else
	{
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_header' WHERE config_key='template_header'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_section' WHERE config_key='template_section'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_status' WHERE config_key='template_status'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_menu' WHERE config_key='template_menu'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_content' WHERE config_key='template_content'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_footer' WHERE config_key='template_footer'");
		mysql_query("UPDATE $table_configuration SET config_value='$comma_separated_general' WHERE config_key='template_general'");
		$sas_config['template_header'] = $comma_separated_header; //get the new saved values
		$sas_config['template_section'] = $comma_separated_section;
		$sas_config['template_status'] = $comma_separated_status;
		$sas_config['template_content'] = $comma_separated_content;
		$sas_config['template_menu'] = $comma_separated_menu;
		$sas_config['template_footer'] = $comma_separated_footer;
		$sas_config['template_general'] = $comma_separated_general;
	}

	print "<span class=\"text\">" . $sas_lang['configuration_saved'] . "</span><p>";
}
print "<span class=\"heading\">$modulename</span>&nbsp;";

if ($modoption == "import")
{
	print "<p><span class=\"heading\">Import</span><p><span class=text><b>Please select a saved template configuration file and press the save button.</b></span><p>";
	print "<p><form method=post enctype=\"multipart/form-data\" action=\"index.php?option=modulemanager&module=$module&modoption=saveimport\">";
	print "<span class=text>" . $sas_lang['uploadfile'] . ":</span><br><input type=file name=file size=40 class=textfield>
	       &nbsp;<input type=submit value=&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . " name=B1 class=savebutton></form>";
	exit;
}
if ($modoption == "protected")
{
	print "<span class=\"text\"><b>(" . $sas_lang['protected_area'] . ")</b></span><p>";
}
else
{
	print "<span class=\"text\"><b>(" . $sas_lang['public_area'] . ")</b></span><p>";
}

if ($modoption == "protected")
{
	$header = explode(",", $sas_config['template_header_prot']);
	$section = explode(",", $sas_config['template_section_prot']);
	$status = explode(",", $sas_config['template_status_prot']);
	$content = explode(",", $sas_config['template_content_prot']);
	$menu = explode(",", $sas_config['template_menu_prot']);
	$footer_new = explode(",", $sas_config['template_footer_prot']);
	$general = explode(",", $sas_config['template_general_prot']);
	print "<form METHOD=\"POST\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=saveconfig&site=protected\">
	   <table border=\"0\" width=\"650\">
	   <tr><td colspan=\"4\"> <hr style=\"border:solid ; border-width:1px 0 0;\"></td></tr>";

}
else
{
	$header = explode(",", $sas_config['template_header']);
	$section = explode(",", $sas_config['template_section']);
	$status = explode(",", $sas_config['template_status']);
	$content = explode(",", $sas_config['template_content']);
	$menu = explode(",", $sas_config['template_menu']);
	$footer_new = explode(",", $sas_config['template_footer']);
	$general = explode(",", $sas_config['template_general']);
	print "<form METHOD=\"POST\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=saveconfig\">
	   <table border=\"0\" width=\"650\">
	   <tr><td colspan=\"4\"> <hr style=\"border:solid ; border-width:1px 0 0;\"></td></tr>";
}

$custompath = $serverpath . "/themes/editable";
//------------------------------ general ---------------------------------------------------
print "<tr><td colspan=\"4\"><span class=\"header\"><b>" . $sas_lang['general_options'] . ": </b></span></td></tr>";
print "<tr><td><span class=\"text\">" . $sas_lang['center_page'] . ": </span></td><td colspan=\"3\"><span class=\"text\">" . $sas_lang['yes'];
if ($general[0] == "1")
{
	print "<input type=\"radio\" value=\"1\" name=\"general[0]\" checked>";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"general[0]\" value=\"0\">";
}
else
{
	print "<input type=\"radio\" value=\"1\" name=\"general[0]\">";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"general[0]\" value=\"0\" checked>";
}

print "</td></tr><tr><td><span class=\"text\">" . $sas_lang['background_color'] . " :</span></td><td>
<input type=text size=10 class=\"textfield\" name=\"general[1]\" id=\"general1\" value=\"" . $general[1] . "\"></td>
<td bgcolor=\"$general[1]\" style=\"border:solid 1px #000000\">&nbsp;</td>
<td><A HREF=\"#\" onClick=\"cp.select(document.forms[0].general1,'pick');return false;\" NAME=\"pick\" ID=\"pick\">
<img src=\"graphics/ColorPicker.gif\" border=\"0\"></A></td></tr>";
print "<tr><td><span class=\"text\">" . $sas_lang['page_size'] . " :</span></td><td colspan=\"3\">
<input type=text size=5 class=\"textfield\" name=\"general[2]\" value=\"" . $general[2] . "\"></td></tr>";

print "<tr><td><span class=\"text\">" . $sas_lang['border_in_px'] . " :</span></td><td colspan=\"3\">
<input type=text size=5 class=\"textfield\" name=\"general[3]\" value=\"" . $general[3] . "\"></td></tr>";

print "</td></tr><tr><td><span class=\"text\">" . $sas_lang['border_color'] . " :</span></td><td>
<input type=text size=10 class=\"textfield\" name=\"general[4]\" id=\"general4\" value=\"" . $general[4] . "\"></td>
<td bgcolor=\"$general[4]\" style=\"border:solid 1px #000000\">&nbsp;</td>
<td><A HREF=\"#\" onClick=\"cp.select(document.forms[0].general4,'pick');return false;\" NAME=\"pick\" ID=\"pick\">
<img src=\"graphics/ColorPicker.gif\" border=\"0\"></A></td></tr>";

print "<tr><td colspan=\"4\"> <hr style=\"border:solid ; border-width:1px 0 0;\"></td></tr>";
//------------------------------ header ---------------------------------------------------
//$header = explode(",", $sas_config['template_header']);

$query = "SELECT * FROM $template_table WHERE script='$header[1]'";
$result = mysql_query($query) or die_script($query, mysql_error());

$header_list = mysql_fetch_array($result);
print "<tr><td colspan=\"4\"><span class=\"header\"><b>" . $sas_lang['header_options'] . ":</b></span></td></tr>";
print "<tr><td width=\"35%\"><span class=\"text\">" . $sas_lang['script_name'] . " :</span></td><td colspan=\"3\">";
print "<select size=\"1\" class=\"text\" name=\"header[1]\" onChange=\"this.form.submit();\">\n";
$dir_handle = @ opendir($custompath);
while ($file = readdir($dir_handle))
{
	if ($file != ".." AND $file != "." AND $file != "/" AND substr($file, 0, 6) == "header")
	{
		$name = substr($file, 0, strpos($file, "."));
		if ($file == $header[1])
		{
			echo "<option selected value=\"$file\">$name</option>";
		}
		else
		{
			echo "<option value=\"$file\">$name</option>";
		}
	}
}
closedir($dir_handle);
print "</select>
         &nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $header_list[1] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
$k = 2;
for ($i = 2; $i < 10; $i++)
{
	$p = $k +1;
	switch ($header_list[$k])
	{

		case "p" : //picture parameter
			print "<tr><td><span class=\"text\">$header_list[$p] :</span></td><td colspan=\"3\">
				<input type=text size=\"60\" class=\"textfield\" name=\"header[$i]\" value=\"" . $header[$i] . "\"></td></tr>";
			break;

		case "c" : //color parameter
			if (substr($header[$i], 0, 1) != "#") //if not starting with # reset it to #000000
			{
				$header[$i] = "#000000";
			}
			print "<tr><td><span class=\"text\">$header_list[$p] :</span></td><td>
				<input type=text size=10 class=\"textfield\" name=\"header[$i]\" id=\"header$i\" value=\"" . $header[$i] . "\"></td>
				<td name=\"cell$i\" id=\"cell$i\" bgcolor=\"$header[$i]\" style=\"border:solid 1px #000000\">&nbsp;</td>
				<td><A HREF=\"#\" onClick=\"cp.select(document.forms[0].header$i,'pick'); return false;\" NAME=\"pick\" ID=\"pick\">
				<img src=\"graphics/ColorPicker.gif\" border=\"0\"></A>
				</td></tr>";
			break;

		case "s" : //size parameter
			if (!is_numeric($header[$i])) //if not a number reset it to 0
			{
				$header[$i] = 0;
			}
			print "<tr><td><span class=\"text\">$header_list[$p] :</span></td><td colspan=\"3\">
				<input type=text size=5 class=\"textfield\" name=\"header[$i]\" value=\"" . $header[$i] . "\"></td></tr>";
			break;

		case "f" : //font name parameter
			print "<tr><td><span class=\"text\">$header_list[$p] :</span></td><td colspan=\"3\">";
			print "<select size=\"1\" class=\"text\" name=\"header[$i]\">\n";
			foreach ($fonts_array as $font)
			{
				if ($font == $header[$i])
				{
					echo "<option selected value=\"$font\">$font</option>";
				}
				else
				{
					echo "<option value=\"$font\">$font</option>";
				}
			}
			print "</select></td></tr>";
			break;
	}
	$k = $k +2;
}
print "<tr><td><span class=\"text\">" . $sas_lang['active'] . ": </span></td><td colspan=\"3\"><span class=\"text\">" . $sas_lang['yes'];
if ($header[0] == "1")
{
	print "<input type=\"radio\" value=\"1\" name=\"header[0]\" checked>";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"header[0]\" value=\"0\">";
}
else
{
	print "<input type=\"radio\" value=\"1\" name=\"header[0]\">";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"header[0]\" value=\"0\" checked>";
}
print "</td></tr><tr><td colspan=\"4\"> <hr style=\"border:solid ; border-width:1px 0 0;\"></td></tr>";
//------------------------------ section ---------------------------------------------------
//$section = explode(",", $sas_config['template_section']);
$query = "SELECT * FROM $template_table WHERE script='$section[1]'";
$result = mysql_query($query) or die_script($query, mysql_error());
$section_list = mysql_fetch_array($result);
print "<tr><td colspan=\"4\"><span class=\"header\"><b>" . $sas_lang['section_options'] . ":</b></span></td></tr>";

print "<tr><td width=\"35%\"><span class=\"text\">" . $sas_lang['script_name'] . " : </span></td><td colspan=\"3\">";
print "<select size=\"1\" class=\"text\" name=\"section[1]\" onChange=\"this.form.submit();\">\n";
$dir_handle = @ opendir($custompath);
while ($file = readdir($dir_handle))
{
	if ($file != ".." AND $file != "." AND $file != "/" AND substr($file, 0, 7) == "section")
	{
		$name = substr($file, 0, strpos($file, "."));
		if ($file == $section[1])
		{
			echo "<option selected value=\"$file\">$name</option>";
		}
		else
		{
			echo "<option value=\"$file\">$name</option>";
		}
	}
}
closedir($dir_handle);
print "</select>
         &nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $section_list[1] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
$k = 2;
for ($i = 2; $i < 10; $i++)
{
	$p = $k +1;
	switch ($section_list[$k])
	{

		case "p" : //picture parameter
			print "<tr><td><span class=\"text\">$section_list[$p] :</span></td><td colspan=\"3\">
				<input type=text size=\"60\" class=\"textfield\" name=\"section[$i]\" value=\"" . $section[$i] . "\"></td></tr>";
			break;

		case "c" : //color parameter
			if (substr($section[$i], 0, 1) != "#") //if not starting with # reset it to #000000
			{
				$section[$i] = "#000000";
			}
			print "<tr><td><span class=\"text\">$section_list[$p] :</span></td><td>
				<input type=text size=10 class=\"textfield\" name=\"section[$i]\" id=\"section$i\" value=\"" . $section[$i] . "\"></td>
				<td bgcolor=\"$section[$i]\" style=\"border:solid 1px #000000\">&nbsp;</td>
				<td><A HREF=\"#\" onClick=\"cp.select(document.forms[0].section$i,'pick');return false;\" NAME=\"pick\" ID=\"pick\">
				<img src=\"graphics/ColorPicker.gif\" border=\"0\"></A></td></tr>";
			break;

		case "s" : //size parameter
			if (!is_numeric($section[$i])) //if not a number reset it to 0
			{
				$header[$i] = 0;
			}
			print "<tr><td><span class=\"text\">$section_list[$p] :</span></td><td colspan=\"3\">
				<input type=text size=5 class=\"textfield\" name=\"section[$i]\" value=\"" . $section[$i] . "\"></td></tr>";
			break;

		case "f" : //font name parameter
			print "<tr><td><span class=\"text\">$section_list[$p] :</span></td><td colspan=\"3\">";
			print "<select size=\"1\" class=\"text\" name=\"section[$i]\">\n";
			foreach ($fonts_array as $font)
			{
				if ($font == $section[$i])
				{
					echo "<option selected value=\"$font\">$font</option>";
				}
				else
				{
					echo "<option value=\"$font\">$font</option>";
				}
			}
			print "</select></td></tr>";
			break;
	}
	$k = $k +2;
}

print "<tr><td><span class=\"text\">" . $sas_lang['active'] . ": </span></td><td colspan=\"3\"><span class=\"text\">" . $sas_lang['yes'];
if ($section[0] == "1")
{
	print "<input type=\"radio\" value=\"1\" name=\"section[0]\" checked>";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"section[0]\" value=\"0\">";
}
else
{
	print "<input type=\"radio\" value=\"1\" name=\"section[0]\">";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"section[0]\" value=\"0\" checked>";
}
print "</td></tr><tr><td colspan=\"4\"> <hr style=\"border:solid ; border-width:1px 0 0;\"></td></tr>";

//------------------------------ status ---------------------------------------------------
//$status = explode(",", $sas_config['template_status']);
$query = "SELECT * FROM $template_table WHERE script='$status[1]'";
$result = mysql_query($query) or die_script($query, mysql_error());
$status_list = mysql_fetch_array($result);
print "<tr><td colspan=\"4\"><span class=\"header\"><b>" . $sas_lang['status_line_options'] . ":</b></span></td></tr>";
print "<tr><td width=\"35%\"><span class=\"text\">" . $sas_lang['script_name'] . " : </span></td><td colspan=\"3\">";
print "<select size=\"1\" class=\"text\" name=\"status[1]\" onChange=\"this.form.submit();\">\n";
$dir_handle = @ opendir($custompath);
while ($file = readdir($dir_handle))
{
	if ($file != ".." AND $file != "." AND $file != "/" AND substr($file, 0, 6) == "status")
	{
		$name = substr($file, 0, strpos($file, "."));
		if ($file == $status[1])
		{
			echo "<option selected value=\"$file\">$name</option>";
		}
		else
		{
			echo "<option value=\"$file\">$name</option>";
		}
	}
}
closedir($dir_handle);
print "</select>
       &nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $status_list[1] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
$k = 2;
for ($i = 2; $i < 10; $i++)
{
	$p = $k +1;

	switch ($status_list[$k])
	{

		case "p" : //picture parameter
			print "<tr><td><span class=\"text\">$status_list[$p] :</span></td><td colspan=\"3\">
				<input type=text size=\"60\" class=\"textfield\" name=\"status[$i]\" value=\"" . $status[$i] . "\"></td></tr>";
			break;

		case "c" : //color parameter
			if (substr($status[$i], 0, 1) != "#")
			{ //if not starting with # reset it to #000000
				$status[$i] = "#000000";
			}
			print "<tr><td><span class=\"text\">$status_list[$p] :</span></td><td>
				<input type=text size=10 class=\"textfield\" name=\"status[$i]\" id=\"status$i\" value=\"" . $status[$i] . "\"></td>
				<td bgcolor=\"$status[$i]\" style=\"border:solid 1px #000000\">&nbsp;</td>
				<td><A HREF=\"#\" onClick=\"cp.select(document.forms[0].status$i,'pick');return false;\" NAME=\"pick\" ID=\"pick\">
				<img src=\"graphics/ColorPicker.gif\" border=\"0\"></A></td></tr>";
			break;

		case "s" : //size parameter
			if (!is_numeric($status[$i]))
			{ //if not a number reset it to 0
				$header[$i] = 0;
			}
			print "<tr><td><span class=\"text\">$status_list[$p] :</span></td colspan=\"3\"><td colspan=\"3\">
				<input type=text size=5 class=\"textfield\" name=\"status[$i]\" value=\"" . $status[$i] . "\"></td></tr>";
			break;

		case "f" : //font name parameter
			print "<tr><td><span class=\"text\">$status_list[$p] :</span></td><td colspan=\"3\">";
			print "<select size=\"1\" class=\"text\" name=\"status[$i]\">\n";
			foreach ($fonts_array as $font)
			{
				if ($font == $status[$i])
				{
					echo "<option selected value=\"$font\">$font</option>";
				}
				else
				{
					echo "<option value=\"$font\">$font</option>";
				}
			}
			print "</select></td></tr>";
			break;
	}
	$k = $k +2;
}

print "<tr><td><span class=\"text\">" . $sas_lang['active'] . ": </span></td><td colspan=\"3\"><span class=\"text\">" . $sas_lang['yes'];
if ($status[0] == "1")
{
	print "<input type=\"radio\" value=\"1\" name=\"status[0]\" checked>";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"status[0]\" value=\"0\">";
}
else
{
	print "<input type=\"radio\" value=\"1\" name=\"status[0]\">";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"status[0]\" value=\"0\" checked>";
}
print "</td></tr><tr><td colspan=\"4\"> <hr style=\"border:solid ; border-width:1px 0 0;\"></td></tr>";

//------------------------------ menu ---------------------------------------------------
//$menu = explode(",", $sas_config['template_menu']);
$query = "SELECT * FROM $template_table WHERE script='$menu[1]'";
$result = mysql_query($query) or die_script($query, mysql_error());
$menu_list = mysql_fetch_array($result);
print "<tr><td colspan=\"4\"><span class=\"header\"><b>" . $sas_lang['menu_options'] . ":</b></span></td></tr>";
print "<tr><td width=\"35%\"><span class=\"text\">" . $sas_lang['script_name'] . " : </span></td><td colspan=\"3\">";
print "<select size=\"1\" class=\"text\" name=\"menu[1]\" onChange=\"this.form.submit();\">\n";
$dir_handle = @ opendir($custompath);
while ($file = readdir($dir_handle))
{
	if ($file != ".." AND $file != "." AND $file != "/" AND substr($file, 0, 4) == "menu")
	{
		$name = substr($file, 0, strpos($file, "."));
		if ($file == $menu[1])
		{
			echo "<option selected value=\"$file\">$name</option>";
		}
		else
		{
			echo "<option value=\"$file\">$name</option>";
		}
	}
}
closedir($dir_handle);
print "</select>
        &nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $menu_list[1] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
$k = 2;
for ($i = 2; $i < 10; $i++)
{
	$p = $k +1;

	switch ($menu_list[$k])
	{

		case "p" : //picture parameter
			if (substr($menu[$i], 0, 1) == "#") //if starts with # it is old info so clear it
			{
				$menu[$i] = "";
			}
			print "<tr><td><span class=\"text\">$menu_list[$p] :</span></td><td colspan=\"3\">
				<input type=text size=\"60\" class=\"textfield\" name=\"menu[$i]\" value=\"" . $menu[$i] . "\"></td></tr>";
			break;

		case "c" : //color parameter
			if (substr($menu[$i], 0, 1) != "#") //if not starting with # reset it to #000000
			{
				$menu[$i] = "#000000";
			}
			print "<tr><td><span class=\"text\">$menu_list[$p] :</span></td><td>
				<input type=text size=10 class=\"textfield\" name=\"menu[$i]\" id=\"menu$i\" value=\"" . $menu[$i] . "\"></td>
				<td bgcolor=\"$menu[$i]\" style=\"border:solid 1px #000000\">&nbsp;</td>
				<td><A HREF=\"#\" onClick=\"cp.select(document.forms[0].menu$i,'pick');return false;\" NAME=\"pick\" ID=\"pick\">
				<img src=\"graphics/ColorPicker.gif\" border=\"0\"></A></td></tr>";
			break;

		case "s" : //size parameter
			if (!is_numeric($menu[$i])) //if not a number reset it to 0
			{
				$menu[$i] = 0;
			}
			print "<tr><td><span class=\"text\">$menu_list[$p] :</span></td><td colspan=\"3\">
				<input type=text size=5 class=\"textfield\" name=\"menu[$i]\" value=\"" . $menu[$i] . "\"></td></tr>";
			break;

		case "f" : //font name parameter
			print "<tr><td><span class=\"text\">$menu_list[$p] :</span></td><td colspan=\"3\">";
			print "<select size=\"1\" class=\"text\" name=\"menu[$i]\">\n";
			foreach ($fonts_array as $font)
			{
				if ($font == $menu[$i])
				{
					echo "<option selected value=\"$font\">$font</option>";
				}
				else
				{
					echo "<option value=\"$font\">$font</option>";
				}
			}
			print "</select></td></tr>";
			break;
	}
	$k = $k +2;
}
print "<tr><td><span class=\"text\">" . $sas_lang['active'] . ": </span></td><td colspan=\"3\"><span class=\"text\">" . $sas_lang['yes'];
if ($menu[0] == "1")
{
	print "<input type=\"radio\" value=\"1\" name=\"menu[0]\" checked>";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"menu[0]\" value=\"0\">";
}
else
{
	print "<input type=\"radio\" value=\"1\" name=\"menu[0]\">";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"menu[0]\" value=\"0\" checked>";
}
print "</td></tr><tr><td colspan=\"4\"> <hr style=\"border:solid ; border-width:1px 0 0;\"></td></tr>";
//------------------------------ content ---------------------------------------------------
//$content = explode(",", $sas_config['template_content']);
$query = "SELECT * FROM $template_table WHERE script='$content[0]'";
$result = mysql_query($query) or die_script($query, mysql_error());
$content_list = mysql_fetch_array($result);

print "<tr><td colspan=\"4\"><span class=\"header\"><b>" . $sas_lang['content_options'] . ":</b></span></td></tr>";
print "<tr><td width=\"35%\"><span class=\"text\">" . $sas_lang['script_name'] . " : </span></td><td colspan=\"3\">";
print "<select size=\"1\" class=\"text\" name=\"content[0]\" onChange=\"this.form.submit();\">\n";
$dir_handle = @ opendir($custompath);
while ($file = readdir($dir_handle))
{
	if ($file != ".." AND $file != "." AND $file != "/" AND substr($file, 0, 7) == "content")
	{
		$name = substr($file, 0, strpos($file, "."));
		if ($file == $content[0])
		{
			echo "<option selected value=\"$file\">$name</option>";
		}
		else
		{
			echo "<option value=\"$file\">$name</option>";
		}
	}
}
closedir($dir_handle);
print "</select>
         &nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $content_list[1] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
$k = 2;
for ($i = 1; $i < 10; $i++)
{
	$p = $k +1;

	switch ($content_list[$k])
	{

		case "p" : //picture parameter
			print "<tr><td><span class=\"text\">$content_list[$p] :</span></td><td colspan=\"3\">
				<input type=text size=\"60\" class=\"textfield\" name=\"content[$i]\" value=\"" . $content[$i] . "\"></td></tr>";
			break;

		case "c" : //color parameter
			if (substr($content[$i], 0, 1) != "#") //if not starting with # reset it to #000000
			{
				$content[$i] = "#000000";
			}
			print "<tr><td><span class=\"text\">$content_list[$p] :</span></td><td>
				<input type=text size=10 class=\"textfield\" name=\"content[$i]\" id=\"content$i\" value=\"" . $content[$i] . "\"></td>
				<td bgcolor=\"$content[$i]\" style=\"border:solid 1px #000000\">&nbsp;</td>
				<td><A HREF=\"#\" onClick=\"cp.select(document.forms[0].content$i,'pick');return false;\" NAME=\"pick\" ID=\"pick\">
				<img src=\"graphics/ColorPicker.gif\" border=\"0\"></A></td></tr>";
			break;

		case "s" : //size parameter
			if (!is_numeric($content[$i])) //if not a number reset it to 0
			{
				$header[$i] = 0;
			}
			print "<tr><td><span class=\"text\">$content_list[$p] :</span></td><td colspan=\"3\">
				<input type=text size=5 class=\"textfield\" name=\"content[$i]\" value=\"" . $content[$i] . "\"></td></tr>";
			break;

		case "f" : //font name parameter
			print "<tr><td><span class=\"text\">$content_list[$p] :</span></td><td colspan=\"3\">";
			print "<select size=\"1\" class=\"text\" name=\"content[$i]\">\n";
			foreach ($fonts_array as $font)
			{
				if ($font == $content[$i])
				{
					echo "<option selected value=\"$font\">$font</option>";
				}
				else
				{
					echo "<option value=\"$font\">$font</option>";
				}
			}
			print "</select></td></tr>";
			break;
	}
	$k = $k +2;
}
print "<tr><td colspan=\"4\"> <hr style=\"border:solid ; border-width:1px 0 0;\"></td></tr>";

//------------------------------ footer ---------------------------------------------------
//$footer_new = explode(",", $sas_config['template_footer']);
$query = "SELECT * FROM $template_table WHERE script='$footer_new[1]'";
$result = mysql_query($query) or die_script($query, mysql_error());
$footer_new_list = mysql_fetch_array($result);
print "<tr><td colspan=\"4\"><span class=\"header\"><b>" . $sas_lang['footer_options'] . ":</b></span></td></tr>";
print "<tr><td width=\"35%\"><span class=\"text\">" . $sas_lang['script_name'] . " : </span></td><td colspan=\"3\">";
print "<select size=\"1\" class=\"text\" name=\"footer[1]\" onChange=\"this.form.submit();\">\n";
$dir_handle = @ opendir($custompath);
while ($file = readdir($dir_handle))
{
	if ($file != ".." AND $file != "." AND $file != "/" AND substr($file, 0, 6) == "footer")
	{
		$name = substr($file, 0, strpos($file, "."));
		if ($file == $footer_new[1])
		{
			echo "<option selected value=\"$file\">$name</option>";
		}
		else
		{
			echo "<option value=\"$file\">$name</option>";
		}
	}
}
closedir($dir_handle);
print "</select>
         &nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $footer_new_list[1] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
$k = 2;
for ($i = 2; $i < 10; $i++)
{
	$p = $k +1;
	switch ($footer_new_list[$k])
	{

		case "p" : //picture parameter
			//print "<tr><td><span class=\"text\">$footer_new_list[$p] :</span></td><td colspan=\"3\">
			//<input type=text size=\"60\" class=\"textfield\" name=\"footer[$i]\" value=\"".$footer_new[$i]."\"></td></tr>";
			$text = stripslashes($footer_new[$i]);
			print "<tr><td><span class=\"text\">$footer_new_list[$p] :</span></td><td colspan=\"3\">
				<textarea cols=\"50\" name=\"footer[$i]\">" . $text . "</textarea></td></tr>";
			break;

		case "c" : //color parameter
			if (substr($footer_new[$i], 0, 1) != "#") //if not starting with # reset it to #000000
			{
				$footer_new[$i] = "#000000";
			}
			print "<tr><td><span class=\"text\">$footer_new_list[$p] :</span></td><td>
				<input type=text size=10 class=\"textfield\" name=\"footer[$i]\" id=\"footer$i\" value=\"" . $footer_new[$i] . "\"></td>
				<td bgcolor=\"$footer_new[$i]\" style=\"border:solid 1px #000000\">&nbsp;</td>
				<td><A HREF=\"#\" onClick=\"cp.select(document.forms[0].footer$i,'pick');return false;\" NAME=\"pick\" ID=\"pick\">
				<img src=\"graphics/ColorPicker.gif\" border=\"0\"></A></td></tr>";
			break;

		case "s" : //size parameter
			if (!is_numeric($footer_new[$i])) //if not a number reset it to 0
			{
				$header[$i] = 0;
			}
			print "<tr><td><span class=\"text\">$footer_new_list[$p] :</span></td><td colspan=\"3\">
				<input type=text size=5 class=\"textfield\" name=\"footer[$i]\" value=\"" . $footer_new[$i] . "\"></td></tr>";
			break;

		case "f" : //font name parameter
			print "<tr><td><span class=\"text\">$footer_new_list[$p] :</span></td><td colspan=\"3\">";
			print "<select size=\"1\" class=\"text\" name=\"footer[$i]\">\n";
			foreach ($fonts_array as $font)
			{
				if ($font == $footer_new[$i])
				{
					echo "<option selected value=\"$font\">$font</option>";
				}
				else
				{
					echo "<option value=\"$font\">$font</option>";
				}
			}
			print "</select></td></tr>";
			break;
	}
	$k = $k +2;
}
print "<tr><td><span class=\"text\">" . $sas_lang['active'] . ": </span></td><td colspan=\"3\"><span class=\"text\">" . $sas_lang['yes'];
if ($footer_new[0] == "1")
{
	print "<input type=\"radio\" value=\"1\" name=\"footer[0]\" checked>";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"footer[0]\" value=\"0\">";
}
else
{
	print "<input type=\"radio\" value=\"1\" name=\"footer[0]\">";
	print "<span class=\"text\">&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span>";
	print "<input type=\"radio\" name=\"footer[0]\" value=\"0\" checked>";
}
print "</td></tr><tr><td colspan=\"4\"> <hr style=\"border:solid ; border-width:1px 0 0;\"></td></tr></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 "&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");
?>