<?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
{
$has_nav_link = false;
$sys_request[3] = isset($sys_request[3]) && !empty($sys_request[3]) ? intval($sys_request[3]) : 0;
$result = $sys_db->query('SELECT p.* FROM '.DB_PREFIX.'pages AS p WHERE p.id='.$sys_request[3].' LIMIT 1') or error($sys_db->error(), __FILE__, __LINE__);
// Check if this page has a link in the main navigation
$result_link = $sys_db->query('SELECT n.* FROM '.DB_PREFIX.'navigation AS n WHERE n.url=\'p/'.$sys_request[3].URI_SUFFIX.'\'') or error($sys_db->error(), __FILE__, __LINE__);
if ($sys_db->num_rows($result_link) > 0)
$has_nav_link = true;
if ($sys_db->num_rows($result) > 0)
{
$page = $sys_db->fetch_assoc($result);
if ((isset($_POST['frm-submit']) || isset($_POST['frm-submit-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('UPDATE '.DB_PREFIX.'pages SET title=\''.$sys_db->escape($form['title']).'\', content=\''.$sys_db->escape($form['content']).'\', parser=\''.$sys_db->escape($form['markup_parser']).'\', edit_date='.$now.', status='.$form['status'].', show_extra_info='.$form['show_extra_info'].', private='.$form['private_page'].' WHERE id='.$sys_request[3]) or error($sys_db->error(), __FILE__, __LINE__);
if (file_exists(SYS_CACHE_DIR.'.cache_page_'.$sys_request[3]))
unlink(SYS_CACHE_DIR.'.cache_page_'.$sys_request[3]);
// Add, update or remove a link to the page to the main navigation
if ($sys_user['p_manage_nav'] == 1)
{
if (isset($_POST['frm-submit-link']))
{
if ($has_nav_link === false)
{
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']).'\', \'p/'.$sys_request[3].URI_SUFFIX.'\')') or error($sys_db->error(), __FILE__, __LINE__);
generate_navigation(true);
}
else if ($has_nav_link === true)
{
$sys_db->query('DELETE FROM '.DB_PREFIX.'navigation WHERE url=\'p/'.$sys_request[3].URI_SUFFIX.'\'') or error($sys_db->error(), __FILE__, __LINE__);
generate_navigation(true);
}
header('location: '.ADMIN_URL.URI_PREFIX.'pages/edit/'.$sys_request[3].'/'.($has_nav_link === false ? 'add_navigation' : 'del_navigation').'/'.URI_SUFFIX); exit;
}
else if ($has_nav_link === true)
{
if (utf8_strlen($form['title']) > 50)
$form['title'] = utf8_substr($form['title'], 0, 50);
$sys_db->query('UPDATE '.DB_PREFIX.'navigation SET name=\''.$sys_db->escape($form['title']).'\' WHERE url=\'p/'.$sys_request[3].URI_SUFFIX.'\'') or error($sys_db->error(), __FILE__, __LINE__);
generate_navigation(true);
}
}
header('location: '.ADMIN_URL.URI_PREFIX.'pages/manage/edited'.URI_SUFFIX); exit;
}
}
// Set page title
$sys_tpl->assign('page_title', 'Edit page - '.$sys_config['website_title'].' Admin');
if (isset($sys_request[4]) && $sys_request[4] === 'add_navigation')
$sys_tpl->add('main_content', '<div class="success">Link succesfully added.</div>');
else if (isset($sys_request[4]) && $sys_request[4] === 'del_navigation')
$sys_tpl->add('main_content', '<div class="success">Link succesfully removed.</div>');
?>
<h2>Edit page: <?php echo $page['title'] ?></h2>
<p>Created on <strong><?php echo format_time($page['create_date'], true) ?></strong>.<?php echo $page['edit_date'] != 0 ? ' Last edited on <strong>'.format_time($page['edit_date'], true).'</strong>.' : null ?></p>
<form method="post" accept-charset="utf-8" action="<?php echo ADMIN_URL, URI_PREFIX, 'pages/edit/', $sys_request[3], 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" value="<?php echo $page['title'] ?>" /></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"<?php echo $page['status'] == 0 ? ' selected="selected"' : null ?>>Draft</option>
<option value="1"<?php echo $page['status'] == 1 ? ' selected="selected"' : null ?>>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"<?php echo 'xhtml' == $page['parser'] ? ' selected="selected"' : null ?>>xHTML/PHP</option>
<?php
$markup_parsers = get_markup_parsers();
foreach ($markup_parsers as $markup_parser)
echo '<option value="', $markup_parser, '"', ($markup_parser == $page['parser'] ? ' selected="selected"' : null), '>', $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"><?php echo utf8_htmlencode($page['content']) ?></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" <?php echo $page['show_extra_info'] == 1 ? 'checked="checked"' : null ?>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" <?php echo $page['private'] == 1 ? 'checked="checked"' : null ?>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"> </div>
<div class="fld-input">
<input type="submit" value="Save page" name="frm-submit" />
<?php if ($sys_user['p_manage_nav'] == 1): if ($has_nav_link === false): ?>
<input type="submit" value="Add to navigation" name="frm-submit-link" title="Add a link to the navigation and continue editing" />
<?php else: ?>
<input type="submit" value="Remove from navigation" name="frm-submit-link" title="Remove the link from the navigation and continue editing" />
<?php endif; endif ?>
<input type="button" onclick="window.location='<?php echo ADMIN_URL, URI_PREFIX, 'pages/manage', URI_SUFFIX ?>'" value="Cancel" name="frm-cancel" />
</div>
</li>
</ul>
</form>
<?php
}
}
?>