Skip to content
Snippets Groups Projects
Commit 8cddeda5 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #1778 from greezybacon/issue/1775


access: Allow empty staff banner. Show update errors

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents 3ee84a84 c94d56da
No related branches found
No related tags found
No related merge requests found
......@@ -136,6 +136,7 @@ class ContentAjaxAPI extends AjaxController {
Http::response(403, 'Login Required');
$content = Page::lookup($id, $lang);
$info = $content->getHashtable();
include STAFFINC_DIR . 'templates/content-manage.tmpl.php';
}
......@@ -146,6 +147,7 @@ class ContentAjaxAPI extends AjaxController {
Http::response(403, 'Login Required');
$content = Page::lookup(Page::getIdByType($type, $lang));
$info = $content->getHashtable();
include STAFFINC_DIR . 'templates/content-manage.tmpl.php';
}
......@@ -154,19 +156,25 @@ class ContentAjaxAPI extends AjaxController {
if (!$thisstaff)
Http::response(403, 'Login Required');
elseif (!$_POST['name'] || !$_POST['body'])
Http::response(422, 'Please submit name and body');
elseif (!($content = Page::lookup($id)))
Http::response(404, 'No such content');
if (!isset($_POST['body']))
$_POST['body'] = '';
$vars = array_merge($content->getHashtable(), $_POST);
$errors = array();
if (!$content->save($id, $vars, $errors)) {
if ($errors['err'])
Http::response(422, $errors['err']);
else
Http::response(500, 'Unable to update content: '.print_r($errors, true));
// Allow empty content for the staff banner
if ($content->save($id, $vars, $errors,
$content->getType() == 'banner-staff')
) {
Http::response(201, 'Have a great day!');
}
if (!$errors['err'])
$errors['err'] = __('Correct the error(s) below and try again!');
$info = $_POST;
$errors = Format::htmlchars($errors);
include STAFFINC_DIR . 'templates/content-manage.tmpl.php';
}
}
?>
......@@ -229,7 +229,7 @@ class Page {
? $p : null;
}
function save($id, $vars, &$errors) {
function save($id, $vars, &$errors, $allowempty=false) {
//Cleanup.
$vars['name']=Format::striptags(trim($vars['name']));
......@@ -246,7 +246,7 @@ class Page {
elseif(($pid=self::getIdByName($vars['name'])) && $pid!=$id)
$errors['name'] = __('Name already exists');
if(!$vars['body'])
if(!$vars['body'] && !$allowempty)
$errors['body'] = __('Page body is required');
if($errors) return false;
......
......@@ -170,14 +170,19 @@ $manage_content = function($title, $content) use ($contents) {
?><tr><td colspan="2">
<a href="#ajax.php/content/<?php echo $id; ?>/manage"
onclick="javascript:
$.dialog($(this).attr('href').substr(1), 200);
return false;"><i class="icon-file-text pull-left icon-2x"
style="color:#bbb;"></i> <?php
$.dialog($(this).attr('href').substr(1), 201);
return false;" class="pull-left"><i class="icon-file-text icon-2x"
style="color:#bbb;"></i> </a>
<span style="display:inline-block;width:90%;padding-left:10px;line-height:1.2em">
<a href="#ajax.php/content/<?php echo $id; ?>/manage"
onclick="javascript:
$.dialog($(this).attr('href').substr(1), 201);
return false;"><?php
echo Format::htmlchars($title); ?></a><br/>
<span class="faded" style="display:inline-block;width:90%"><?php
<span class="faded"><?php
echo Format::display($notes); ?>
<em>(<?php echo sprintf(__('Last Updated %s'), Format::db_datetime($upd));
?>)</em></span></td></tr><?php
?>)</em></span></span></td></tr><?php
}; ?>
<tr>
<th colspan="2">
......
<h3><?php echo __('Manage Content'); ?> &mdash; <?php echo Format::htmlchars($content->getName()); ?></h3>
<a class="close" href=""><i class="icon-remove-circle"></i></a>
<hr/>
<form method="post" action="#content/<?php echo $content->getId(); ?>">
<?php if ($errors['err']) { ?>
<div class="error-banner">
<?php echo $errors['err']; ?>
</div>
<?php } ?>
<form method="post" action="#content/<?php echo $info['id']; ?>">
<div class="error"><?php echo $errors['name']; ?></div>
<input type="text" style="width: 100%; font-size: 14pt" name="name" value="<?php
echo Format::htmlchars($content->getName()); ?>" />
echo Format::htmlchars($info['name']); ?>" />
<div style="margin-top: 5px">
<div class="error"><?php echo $errors['body']; ?></div>
<textarea class="richtext no-bar" name="body"><?php
echo Format::viewableImages($content->getBody());
echo Format::viewableImages($info['body']);
?></textarea>
</div>
<div id="msg_info" style="margin-top:7px"><?php
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment