<?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.4): Fred Stuurman 
# Current coder & maintainer: Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# editor.php: last changed 20/08/2006  , version: 2.4.03
#                  by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: editor.php,v 1.1 2006/10/03 12:46:52 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");

include ("editors/fckeditor/fckeditor.php");
print "<FORM METHOD=\"POST\" ACTION=\"index.php?option=pagemanager&savepage=$pageid&section=$section&site=$site\">";
?>
<TABLE class="ToolBar" id="idToolbar" cellSpacing="0" cellPadding="0"  width="780" border="1">
<TBODY>
<TR style="background:ButtonFace">
<TD colSpan=18 height="28" valign="bottom">
<?php


if (IsSet ($_GET['template']))
{
	$template_path = $sas_config['serverpath'] . $sas_config['user_path'] . "/" . $media . "/templates";
	$filename = $template_path . "/" . $_GET['template'];
	if (file_exists($filename))
	{
		$handle = fopen($filename, "r");
		$content = fread($handle, filesize($filename));
		fclose($handle);
	}
}

print "<span class=text>&nbsp;" . $sas_lang['title'] . ":&nbsp;</span><input type=\"text\" name=\"title\" size=\"27\" value=\"$title\">
       <span class=text>&nbsp;" . $sas_lang['category'] . ":&nbsp;</span><input type=\"text\" name=\"category\" size=\"17\" value=\"$category\">
       <span class=text>&nbsp;" . $sas_lang['order'] . ":&nbsp;</span><input type=\"text\" name=\"sort\" size=\"1\" value=\"$sort\">";
print "<span class=text>&nbsp;" . $sas_lang['section'] . ":&nbsp;</span><select class=text size=\"1\" name=\"newsection\">\n";
$query = "SELECT id, name FROM $table_sections";
$result = mysql_query($query) or die_script($query, mysql_error());
while ($section_list = mysql_fetch_array($result))
{
	if ((in_array($section_list[0], $user_sections)) OR ($user_sections[0] == "")) //is user allowed to edit this section?
	{
		if ($section_list[0] == $section)
		{
			print "<option selected value=\"$section_list[0]\">$section_list[1]</option>\n";
		}
		else
		{
			print "<option value=\"$section_list[0]\">$section_list[1]</option>\n";
		}
	}
}
print "</select></td></tr><tr style=\"background:ButtonFace\"><td>";

$template_path = $sas_config['serverpath'] . $sas_config['user_path'] . "/" . $media . "/templates";
if (is_dir($template_path))
{
	print "<span class=text>&nbsp;" . $sas_lang['template'] . ":&nbsp;&nbsp;</span><select class=text size=\"1\" name=\"template\" 
		onchange=\"parent.location.href='index.php?option=pagemanager&suboption=editpage&page=$pageid&section=$section&template=' + this.options[this.selectedIndex].value\">>\n";
	$dir_handle = @ opendir($template_path);
	print "<option value=\"" . $sas_lang['choose_one'] . "\">" . $sas_lang['choose_one'] . "</option>";
	while ($file = readdir($dir_handle))
	{
		//if($file != ".." AND $file != "." AND $file != "/")
		if ((eregi('.html', $file)) OR (eregi('.htm', $file)))
		{
			echo "<option value=\"$file\">$file</option>";
		}

	}
	closedir($dir_handle);
	print "</select>";
}
if ($invisible == "yes")
{
	print "&nbsp;<input type=\"checkbox\" name=\"invisible\" value=\"yes\" checked><span class=\"text\">" .
	$sas_lang['invisible'] . "&nbsp;</span><img align=\"middle\" src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['invisible_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br>";
}
else
{
	print "&nbsp;<input type=\"checkbox\" name=\"invisible\" value=\"yes\"><span class=\"text\">" .
	$sas_lang['invisible'] . "&nbsp;</span><img align=\"middle\" src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['invisible_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br>";
}

$theme_css = $sas_config['url'] . $cmsdir . "/themes/" . $sas_config[theme] . "/style.css";
print "</td></tr>
  <tr vAlign=center><td>";
$height = $sas_config['htmlarea_editor_rows'] * 20;
$fck_lang = strtolower($sas_config[language]);
$oFCKeditor = new FCKeditor('content');
$oFCKeditor->BasePath = 'editors/fckeditor/';
$oFCKeditor->BaseHref = '$site_url';
$oFCKeditor->Config['EditorAreaCSS'] = $theme_css;
$oFCKeditor->Config['DefaultLanguage'] = "$fck_lang";
$oFCKeditor->Width = '100%';
$oFCKeditor->Height = $height;
$oFCKeditor->Value = $content;
$oFCKeditor->Create();

print "</td><tr></table>";
print "<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['cancel'] . "\" name=\"backbutton\" onClick=\"javascript:parent.location='index.php?option=pagemanager&section=$section&site=$site';\" class=\"backbutton\">";
print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">
		&nbsp;<input type=\"checkbox\" name=\"return_to_editor\" value=\"yes\"><span class=\"text\">" . $sas_lang['return_to_editor'] . "</span>
		<br><br></form>";

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