<?php
/*
 * This file is part of pluck, the easy content management system
 * Copyright (c) pluck team
 * http://www.pluck-cms.org

 * Pluck 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 3 of the License, or
 * (at your option) any later version.

 * See docs/COPYING for the complete license.
*/

//Make sure the file isn't accessed directly.
defined('IN_PLUCK') or exit('Access denied!');

//Include page information, if we're editing a page.
if (isset($_GET['page']) && file_exists(PAGE_DIR.'/'.get_page_filename($_GET['page'])))
	require_once (PAGE_DIR.'/'.get_page_filename($_GET['page']));

//If form is posted...
if (isset($_POST['save']) || isset($_POST['save_exit'])) {
	//Allow modules to add data to page
	$module_additional_data = null;
	run_hook('admin_save_page_afterpost', array(&$module_additional_data));

	if (!isset($_POST['hidden']))
		$_POST['hidden'] = 'yes';

	//Save the page, but only if a title has been entered.
	if (!empty($_POST['title'])) {
		//If we are editing an existing page, pass current seo-name.
		if (isset($_GET['page'])) {
			$seoname = save_page($_POST['title'], $_POST['content'], $_POST['hidden'], $_POST['sub_page'], $_POST['description'], $_POST['keywords'], $module_additional_data, $_GET['page']);
		}
		//If we are creating a new page, don't pass seo-name.
		else
			$seoname = save_page($_POST['title'], $_POST['content'], $_POST['hidden'], $_POST['sub_page'], $_POST['description'], $_POST['keywords'], $module_additional_data);
	}
	//If no title has been chosen, set error.
	else
		$error = show_error($lang['page']['no_title'], 1, true);

	//Redirect to the new title only if it is a plain save.
	if (isset($_POST['save']) && !isset($error)) {
		redirect('?action=editpage&page='.$seoname, 0);
		include_once ('data/inc/footer.php');
		exit;
	}

	//Redirect the user. only if they are doing a save_exit.
	elseif (isset($_POST['save_exit']) && !isset($error)) {
		redirect('?action=page', 0);
		include_once ('data/inc/footer.php');
		exit;
	}
}
?>
<?php
if (isset($error))
	echo $error;
?>
<div class="rightmenu">
<p><?php echo $lang['page']['items']; ?></p>
<?php
	show_module_insert_box();
	show_link_insert_box();
	show_image_insert_box('images');
	run_hook('admin_save_page_sidebar');
?>
</div>
<form name="page_form" method="post" action="">
	<p>
		<label class="kop2" for="title"><?php echo $lang['general']['title']; ?></label>
		<input name="title" id="title" type="text" value="<?php if (isset($_GET['page'])) echo $title; ?>" />
	</p>
	<label class="kop2" for="content-form"><?php echo $lang['general']['contents']; ?></label>
	<textarea class="<?php if (defined('WYSIWYG_TEXTAREA_CLASS')) echo WYSIWYG_TEXTAREA_CLASS; ?>" name="content" id="content-form" cols="70" rows="20"><?php if (isset($_GET['page'])) echo htmlspecialchars($content); ?></textarea>


	<div class="menudiv" style="width: 588px; margin-<?php if (DIRECTION_RTL) echo 'right'; else echo 'left'; ?>: 0;">
		<p><a href="#" class="kop2" onclick="return kadabra('meta-options');"><?php echo $lang['editmeta']['title']; ?></a></p>
		<p class="kop4" style="margin-bottom: 5px;"><?php echo $lang['editmeta']['descr']; ?></p>

		<div id="meta-options" style="display: none;">
			<label for="description"><?php echo $lang['general']['description']; ?></label></tr>
			<br />
			<textarea id="description" name="description" rows="2" cols="40" class="white"><?php if (isset($description)) echo $description; ?></textarea>
			<br />

			<label for="keywords"><?php echo $lang['editmeta']['keywords']; ?></label>
			<br />
			<span class="kop4"><?php echo $lang['editmeta']['comma']; ?></span>
			<br />
			<textarea id="keywords" name="keywords" rows="1" cols="40" class="white"><?php if (isset($keywords)) echo $keywords; ?></textarea>
		</div>
	</div>

	<div class="menudiv" style="width: 588px; margin-<?php if (DIRECTION_RTL) echo 'right'; else echo 'left'; ?>: 0;">
		<p><a href="#" class="kop2" onclick="return kadabra('other-options');"><?php echo $lang['general']['other_options']; ?></a></p>
		<p class="kop4" style="margin-bottom: 5px;"><?php echo $lang['page']['options']; ?></p>

		<div id="other-options" style="display: block;">
			<table>
			<tr>
				<td><label for="hidden"><?php echo $lang['page']['in_menu']; ?></label><br /></td>
				<td><input type="checkbox" name="hidden" id="hidden" <?php if (!isset($_GET['page']) || $hidden == 'no') echo'checked="checked"'; ?> value="no" /></td>
			</tr>

			<tr>
				<td><label for="sub_page"><?php echo $lang['page']['sub_page']; ?></label></td>
				<td> <?php if (isset($_GET['page'])) show_subpage_select('sub_page', $_GET['page']); else show_subpage_select('sub_page'); ?></td>
			</tr>

			<?php run_hook('admin_save_page_beforepost'); ?>
			</table>
		</div>
	</div>
	<?php show_common_submits('?action=page', true); ?>
</form>