<?PHP

#############################################################################
#                              Site@School
# Site@School is a website management system designed for schools.
#
############################################################################
# admin.php: last changed 13/06/2005  , version: 1.0
#            by F.C. 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");
}

if (IsSet ($_GET['modoption']))
{
	$modoption = $_GET['modoption'];
}
if (IsSet ($_GET['script_id']))
{
	$script_id = $_GET['script_id'];
}
if (IsSet ($_POST['script_id']))
{
	$script_id = $_POST['script_id'];
}
if (IsSet ($_POST['script_name']))
{
	$script_name = $_POST['script_name'];
}
if (IsSet ($_POST['welcome_text']))
{
	$welcome_text = $_POST['welcome_text'];
}
if (IsSet ($_POST['script_active']))
{
	$script_active = $_POST['script_active'];
}
if (IsSet ($_POST['script_welcome']))
{
	$script_welcome = $_POST['script_welcome'];
}
if (IsSet ($_POST['ip_tv_module']))
{
	$ip_tv_module = $_POST['ip_tv_module'];
}
if (IsSet ($_POST['var1']))
{
	$var1 = $_POST['var1'];
}
if (IsSet ($_POST['var2']))
{
	$var2 = $_POST['var2'];
}
if (IsSet ($_POST['var3']))
{
	$var3 = $_POST['var3'];
}
if (IsSet ($_POST['loc_id']))
{
	$loc_id = $_POST['loc_id'];
}
if (IsSet ($_GET['script_name']))
{
	$script_name = $_GET['script_name'];
}

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

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

$scripts_table = $dbprefix . "m_scripts";

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

print "<span class=\"heading\">$modulename<br></span>"; //print the module name
print "<span class=\"text\">" . $sas_lang['tv_module_intro'] . "<br></span><br>";

if ($modoption == "add_script")
{

	$loc_id = "0";

	if ($script_name == "scroll_page.php")
	{
		mysql_query("INSERT INTO $scripts_table VALUES (NULL, 'Scrollscript', 'scroll_page.php', 0, 'Page number', '' , 'Speed' , '5', '', '', '', '$loc_id')");
	}
	if ($script_name == "slideshow_full.php")
	{
		mysql_query("INSERT INTO $scripts_table VALUES (NULL, 'Slideshow', 'slideshow_full.php', 0, 'Album name', '' , 'Speed' , '5', 'Width', '', '', '$loc_id')");
	}
	if ($script_name == "show_page.php")
	{
		mysql_query("INSERT INTO $scripts_table VALUES (NULL, 'Showpage', 'show_page.php', 0, 'Page number', '' , '' , '', '', '', '', '$loc_id')");
	}
	if ($script_name == "page_slideshow.php")
	{
		mysql_query("INSERT INTO $scripts_table VALUES (NULL, 'Page slideshow', 'page_slideshow.php', 0, 'Pages', '' , 'Speed' , '5', '', '', '', '$loc_id')");
	}
}

if ($modoption == "delete_script")
{
	mysql_query("DELETE FROM $scripts_table WHERE id = '$script_id'");
}

if ($modoption == "save_script")
{
	mysql_query("UPDATE $scripts_table SET name = '$script_name' WHERE id='$script_id'");
	mysql_query("UPDATE $scripts_table SET value1 = '$var1' WHERE id='$script_id'");
	mysql_query("UPDATE $scripts_table SET value2 = '$var2' WHERE id='$script_id'");
	mysql_query("UPDATE $scripts_table SET value3 = '$var3' WHERE id='$script_id'");
	mysql_query("UPDATE $scripts_table SET welcome = '$script_welcome' WHERE id='$script_id'");
	mysql_query("UPDATE $scripts_table SET loc_id = '$loc_id' WHERE id='$script_id'");
}

if ($modoption == "save_active")
{
	$i = 0;
	mysql_query("UPDATE $scripts_table SET active = 0 WHERE id > 0");

	foreach ($script_active as $value)
	{
		mysql_query("UPDATE $scripts_table SET active = 1 WHERE id='$value'");
	}
}

if ($modoption == "edit_script")
{

	$query = "SELECT name, varname1, value1, varname2, value2, varname3, value3, script, welcome, loc_id FROM $scripts_table WHERE id='$script_id'";
	$result = mysql_query($query);
	$script_name = mysql_result($result, 0, 0);
	$parm_name1 = mysql_result($result, 0, 1);
	$value1 = mysql_result($result, 0, 2);
	$parm_name2 = mysql_result($result, 0, 3);
	$value2 = mysql_result($result, 0, 4);
	$parm_name3 = mysql_result($result, 0, 5);
	$value3 = mysql_result($result, 0, 6);
	$script = mysql_result($result, 0, 7);
	$script_welcome = mysql_result($result, 0, 8);
	$loc_id = mysql_result($result, 0, 9);

	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=save_script&script_id=$script_id\">\n";
	print "<table cellpadding=\"2\"><tr><td><span class=\"text\">" . $sas_lang['tv_module_script_type'] . ":</span></td>
	<td><span class=\"text\"><b>$script</span></td></tr>
	<tr><td colspan=\"2\">&nbsp;</td></tr><tr>
	<td><span class=\"text\">" . $sas_lang['tv_module_script_name'] . "</span></td>
	<td><input size=\"40\" name=\"script_name\" value=\"$script_name\"></td></tr>\n";
	print "</tr><tr><td colspan=\"2\">&nbsp;</td></tr>";
	if ($parm_name1 != "")
	{
		print "<tr><td><span class=\"text\">$parm_name1:</span></td><td><input name=\"var1\" value=\"$value1\"></td></tr>\n";
		print "</tr><tr><td colspan=\"2\">&nbsp;</td></tr>";
	}
	if ($parm_name2 != "")
	{
		print "<tr><td><span class=\"text\">$parm_name2:</span></td><td><input name=\"var2\" value=\"$value2\"></td></tr>\n";
		print "</tr><tr><td colspan=\"2\">&nbsp;</td></tr>";
	}

	if ($parm_name3 != "")
	{
		print "<tr><td><span class=\"text\">$parm_name3:</span></td><td><input name=\"var3\" value=\"$value3\"></td></tr>\n";
		print "</tr><tr><td colspan=\"2\">&nbsp;</td></tr>";
	}
	print "<tr><td valign=\"top\"><span class=\"text\">" . $sas_lang['tv_module_welcome'] . ":</span></td>
	<td><textarea cols=\"70\" rows=\"8\" name=\"script_welcome\">" . $script_welcome . "</textarea></td></tr>\n";
	print "<tr><td><span class=\"text\">" . $sas_lang['tv_module_location_id'] . ":</span></td><td><input name=\"loc_id\" size=\"4\" value=\"$loc_id\"></td></tr>\n";
	print "</table>";

	print "<p></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\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" class=\"savebutton\">";
	print "</span></form>";
}
else
{
	$query = "SELECT id, name, active, varname1, value1, script, loc_id FROM $scripts_table ORDER BY loc_id";
	$result = mysql_query($query);
	print "<form><span class=\"text\"><b>" . $sas_lang['tv_module_add'] . ":</b></span>&nbsp;<select size=\"1\" name=\"script\" 
			onchange=\"parent.location.href='index.php?option=modulemanager&module=$module&modoption=add_script&script_name=' + this.options[this.selectedIndex].value\">";
	print "<option value=\"\">" . $sas_lang['tv_module_select'] . "</option>\n";
	print "<option value=\"page_slideshow.php\">Page slideshow</option>\n";
	print "<option value=\"scroll_page.php\">Scrollscript</option>\n";
	print "<option value=\"slideshow_full.php\">Slideshow</option>\n";
	print "<option value=\"show_page.php\">Showpage</option>\n";
	print "</select></form><p>";

	print "<FORM METHOD=\"POST\" NAME=\"myform\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=save_active\">\n";
	print "<table cellpadding=\"2\"><tr><td>&nbsp;</td>
	<td><span class=\"text\"><b>" . $sas_lang['tv_module_script_name'] . "</b></span></td><td>&nbsp;</td>
	<td><span class=\"text\"><b>" . $sas_lang['tv_module_active'] . "</b></span></td></tr>\n";

	$i = 0;
	$k = 0;
	while ($script_list = mysql_fetch_array($result))
	{
		if (($loc_id_prev != $script_list[6]) AND ($i > 0))
		{
			print "<tr><td colspan=\"4\">&nbsp;</td></tr>"; //print extra line
			$k++;
		}
		$loc_id_prev = $script_list[6];
		print "<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[tv_module_delete_confirm]'))
					 parent.location='index.php?option=modulemanager&module=$module&modoption=delete_script&script_id=$script_list[0]';\">";
		if ($script_list[5] == "slideshow_full.php")
		{
			print "&nbsp;<a href=\"addons/$script_list[5]?album_name=$script_list[4]&speed=4&w=300\" target=\"_blank\"><img src=\"graphics/view.gif\" border=\"0\" 
						   title=\"" . $sas_lang['student_view'] . "\" alt=\"" . $sas_lang['student_view'] . "\"></a></td>";
		}
		else
		{
			print "&nbsp;<a href=\"addons/$script_list[5]?page=$script_list[4]\" target=\"_blank\"><img src=\"graphics/view.gif\" border=\"0\" 
						   title=\"" . $sas_lang['student_view'] . "\" alt=\"" . $sas_lang['student_view'] . "\"></a></td>";
		}
		print "<td><span class=\"text\"><b>
			<a href=\"index.php?option=modulemanager&module=$module&modoption=edit_script&script_id=$script_list[0]\">($script_list[6]) $script_list[1] </a></b></span></td>
			<td>&nbsp;&nbsp;<span class=\"text\">$script_list[3]: <b>$script_list[4]</b></span></td>";
		if ($script_list[2] == 0)
		{
			print "<td align=\"right\"><input type=\"radio\" name=\"script_active[$k]\" value=\"$script_list[0]\">&nbsp;</td></tr>";
		}
		else
		{
			print "<td align=\"right\"><input type=\"radio\" name=\"script_active[$k]\" value=\"$script_list[0]\" checked>&nbsp;</td></tr>\n";
		}
		print "<INPUT type=\"hidden\" size=5 name=script_id[$i] value=\"$script_list[0]\">\n";
		$i++;
	}

	print "</table>";
	print "<p></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\">";
	print "</span></form>";

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