Location: PHPKode > projects > Shinobu > admin/pages/pages/add.php
<?php

/* ---

	Copyright (C) 2008-2009 Frank Smit
	http://shinobu.61924.nl/

	This file is part of Shinobu.

	Shinobu 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.

	Shinobu 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 Shinobu. If not, see <http://www.gnu.org/licenses/>.

--- */

(!defined('SHINOBU_ADMIN')) ? exit : null;

if ($sys_user['p_manage_pages'] == 0)
{
	// Set page title
	$sys_tpl->assign('page_title', $sys_lang['e_error'].' - '.$sys_config['website_title'].' Admin');

	?>

<h2><span><?php echo $sys_lang['e_error'] ?></span></h2>

<p>You have no permission to access this page</p>

	<?php
}
else
{
	if ((isset($_POST['frm-submit']) || isset($_POST['frm-submit-add-link'])) && check_token())
	{
		$form = array_map('system_trim', $_POST['form']);
		$errors = false;

		$form['title'] = utf8_htmlencode($form['title']);
		$form['content'] = convert_linebreaks($form['content']);

		if (empty($form['title']))
			$errors['title'] = 'No title entered.';
		else if ($form['title'] > 255)
			$errors['title'] = 'The title is too long.';

		$form['status'] = $form['status'] == 1 ? 1 : 0;
		$form['show_extra_info'] = isset($form['show_extra_info']) && $form['show_extra_info'] == 1 ? 1 : 0;
		$form['private_page'] = isset($form['private_page']) && $form['private_page'] == 1 ? 1 : 0;

		if (empty($form['content']))
			$errors['content'] = 'No content entered.';
		else if (utf8_strlen($form['content']) > 65535)
			$errors['content'] = 'The content is too long.';

		if ($errors === false)
		{
			$now = time();

			$sys_db->query('INSERT INTO '.DB_PREFIX.'pages (title, author, content, parser, create_date, status, show_extra_info, private) VALUES(\''.$sys_db->escape($form['title']).'\', '.intval($sys_user['id']).', \''.$sys_db->escape($form['content']).'\', \''.$sys_db->escape($form['markup_parser']).'\', '.$now.', '.$form['status'].', '.$form['show_extra_info'].', '.$form['private_page'].')') or error($sys_db->error(), __FILE__, __LINE__);
			$page_id = intval($sys_db->insert_id());

			// Add a link to the page to the main navigation
			if ($sys_user['p_manage_nav'] == 1 && isset($_POST['frm-submit-add-link']))
			{
				if (utf8_strlen($form['title']) > 50)
					$form['title'] = utf8_substr($form['title'], 0, 50);

				$sys_db->query('INSERT INTO '.DB_PREFIX.'navigation (name, url) VALUES(\''.$sys_db->escape($form['title']).'\', \''.$sys_db->escape('p/'.$page_id.URI_SUFFIX).'\')') or error($sys_db->error(), __FILE__, __LINE__);
				generate_navigation(true);
			}

			header('location: '.ADMIN_URL.URI_PREFIX.'pages/manage/added'.URI_SUFFIX); exit;
		}
	}

	// Set page title
	$sys_tpl->assign('page_title', 'Add new page - '.$sys_config['website_title'].' Admin');

	?>

	<h2>Add new page</h2>

	<form method="post" accept-charset="utf-8" action="<?php echo ADMIN_URL, URI_PREFIX, 'pages/add', URI_SUFFIX ?>">

		<div>
			<input type="hidden" name="token" value="<?php echo SYS_TOKEN ?>" />
		</div>

		<ul class="frm-hc">
			<li class="frm-block<?php echo isset($errors['title']) ? ' form-error' : NULL ?>">
				<div class="fld-label"><label for="fld-0">Title:</label></div>
				<div class="fld-input"><input class="text" type="text" name="form[title]" id="fld-0" maxlength="255" /></div>
				<?php echo isset($errors['title']) ? '<span class="fld-error-message">'.$errors['title'].'</span>' : NULL ?>
			</li>

			<li class="frm-block">
				<div class="fld-label"><label for="fld-1">Status:</label></div>
				<div class="fld-input">
					<select name="form[status]" id="fld-1">
						<option value="0" selected="selected">Draft</option>
						<option value="1">Published</option>
					</select>
				</div>
			</li>

			<li class="frm-block">
				<div class="fld-label"><label for="fld-2">Markup parser:</label></div>
				<div class="fld-input">
					<select name="form[markup_parser]" id="fld-2">
						<option value="xhtml" selected="selected">xHTML/PHP</option>

						<?php

						$markup_parsers = get_markup_parsers();
						foreach ($markup_parsers as $markup_parser)
							echo '<option value="', $markup_parser, '">', $markup_parser, '</option>', "\n";

						?>

					</select>
				</div>
			</li>
		</ul>

		<ul class="frm-avc">
			<li class="frm-block<?php echo isset($errors['content']) ? ' form-error' : NULL ?>">
				<div class="fld-label"><label for="fld-3">Content:</label></div>
				<div class="fld-input"><textarea name="form[content]" id="fld-3" class="big pre" rows="10" cols="50"></textarea></div>
				<?php echo isset($errors['content']) ? '<span class="fld-error-message">'.$errors['content'].'</span>' : NULL ?>
			</li>

			<li class="frm-block">
				<div class="fld-label"><label>Page options:</label></div>
				<div class="fld-input">
					<label for="fld-show_extra_info">
						<input type="checkbox" name="form[show_extra_info]" id="fld-show_extra_info" checked="checked" value="1" />
						Show "Created by ... Edited on ..." at the bottom of the page?
					</label>
				</div>
				<div class="fld-input">
					<label for="fld-private_page">
						<input type="checkbox" name="form[private_page]" id="fld-private_page" value="1" />
						Private page: only registered users can access to this page.
					</label>
				</div>
			</li>

			<li class="frm-block frm-buttons">
				<div class="fld-label">&nbsp;</div>
				<div class="fld-input">
					<input type="submit" value="Add Page" name="frm-submit" />
					<?php if ($sys_user['p_manage_nav'] == 1): ?>
					<input type="submit" value="Add Page &amp; Add to navigation" name="frm-submit-add-link" title="Add a link to the navigation and add the page to the database" />
					<?php endif ?>
				</div>
			</li>
		</ul>
	</form>

	<?php
}

?>
Return current item: Shinobu