diff --git a/include/ajax.content.php b/include/ajax.content.php index d7863cb880c48e781059e4db60049341bd48154e..eeb5b426cbe2a9767625eeb68d80c84fe491c5cc 100644 --- a/include/ajax.content.php +++ b/include/ajax.content.php @@ -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'; } } ?> diff --git a/include/class.page.php b/include/class.page.php index a6faf5f019762ef075005a1e48f2d911c03e5613..7b11830897697a140adfded1e6611bacbddeda2e 100644 --- a/include/class.page.php +++ b/include/class.page.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; diff --git a/include/staff/settings-access.inc.php b/include/staff/settings-access.inc.php index fa6fc607e77d84f5383723785966311a5a8c3005..156507f2e031f28c6bda2feeba09a705538542c9 100644 --- a/include/staff/settings-access.inc.php +++ b/include/staff/settings-access.inc.php @@ -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"> diff --git a/include/staff/templates/content-manage.tmpl.php b/include/staff/templates/content-manage.tmpl.php index ddf9892ad4a5eef850ac4927571538f7580ec9c0..7170aeb291e9f8b626099ac32f0d6c0438fc7c3e 100644 --- a/include/staff/templates/content-manage.tmpl.php +++ b/include/staff/templates/content-manage.tmpl.php @@ -1,12 +1,19 @@ <h3><?php echo __('Manage Content'); ?> — <?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