[0] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @package Dotclear |
---|
| 4 | * @subpackage Backend |
---|
| 5 | * |
---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 7 | * @copyright GPL-2.0-only |
---|
| 8 | */ |
---|
[0] | 9 | |
---|
[3703] | 10 | require dirname(__FILE__) . '/../inc/admin/prepend.php'; |
---|
[0] | 11 | |
---|
| 12 | dcPage::check('categories'); |
---|
| 13 | |
---|
[3703] | 14 | $cat_id = ''; |
---|
| 15 | $cat_title = ''; |
---|
| 16 | $cat_url = ''; |
---|
| 17 | $cat_desc = ''; |
---|
[0] | 18 | $cat_position = ''; |
---|
| 19 | |
---|
| 20 | # Getting existing category |
---|
[3703] | 21 | if (!empty($_REQUEST['id'])) { |
---|
| 22 | try { |
---|
| 23 | $rs = $core->blog->getCategory($_REQUEST['id']); |
---|
| 24 | } catch (Exception $e) { |
---|
| 25 | $core->error->add($e->getMessage()); |
---|
| 26 | } |
---|
[2566] | 27 | |
---|
[3703] | 28 | if (!$core->error->flag() && !$rs->isEmpty()) { |
---|
| 29 | $cat_id = (integer) $rs->cat_id; |
---|
| 30 | $cat_title = $rs->cat_title; |
---|
| 31 | $cat_url = $rs->cat_url; |
---|
| 32 | $cat_desc = $rs->cat_desc; |
---|
| 33 | } |
---|
| 34 | unset($rs); |
---|
[2566] | 35 | |
---|
[3703] | 36 | # Getting hierarchy information |
---|
| 37 | $parents = $core->blog->getCategoryParents($cat_id); |
---|
| 38 | $rs = $core->blog->getCategoryParent($cat_id); |
---|
| 39 | $cat_parent = $rs->isEmpty() ? 0 : (integer) $rs->cat_id; |
---|
| 40 | unset($rs); |
---|
[2566] | 41 | |
---|
[3703] | 42 | # Allowed parents list |
---|
| 43 | $children = $core->blog->getCategories(array('start' => $cat_id)); |
---|
| 44 | $allowed_parents = array(__('Top level') => 0); |
---|
[2566] | 45 | |
---|
[3703] | 46 | $p = array(); |
---|
| 47 | while ($children->fetch()) { |
---|
| 48 | $p[$children->cat_id] = 1; |
---|
| 49 | } |
---|
[2566] | 50 | |
---|
[3703] | 51 | $rs = $core->blog->getCategories(); |
---|
| 52 | while ($rs->fetch()) { |
---|
| 53 | if (!isset($p[$rs->cat_id])) { |
---|
| 54 | $allowed_parents[] = new formSelectOption( |
---|
| 55 | str_repeat(' ', $rs->level - 1) . ($rs->level - 1 == 0 ? '' : '• ') . html::escapeHTML($rs->cat_title), |
---|
| 56 | $rs->cat_id |
---|
| 57 | ); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | unset($rs); |
---|
[2566] | 61 | |
---|
[3703] | 62 | # Allowed siblings list |
---|
| 63 | $siblings = array(); |
---|
| 64 | $rs = $core->blog->getCategoryFirstChildren($cat_parent); |
---|
| 65 | while ($rs->fetch()) { |
---|
| 66 | if ($rs->cat_id != $cat_id) { |
---|
| 67 | $siblings[html::escapeHTML($rs->cat_title)] = $rs->cat_id; |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | unset($rs); |
---|
[0] | 71 | } |
---|
| 72 | |
---|
| 73 | # Changing parent |
---|
[3703] | 74 | if ($cat_id && isset($_POST['cat_parent'])) { |
---|
| 75 | $new_parent = (integer) $_POST['cat_parent']; |
---|
| 76 | if ($cat_parent != $new_parent) { |
---|
| 77 | try { |
---|
| 78 | $core->blog->setCategoryParent($cat_id, $new_parent); |
---|
| 79 | dcPage::addSuccessNotice(__('The category has been successfully moved')); |
---|
| 80 | $core->adminurl->redirect("admin.categories"); |
---|
| 81 | } catch (Exception $e) { |
---|
| 82 | $core->error->add($e->getMessage()); |
---|
| 83 | } |
---|
| 84 | } |
---|
[0] | 85 | } |
---|
| 86 | |
---|
| 87 | # Changing sibling |
---|
[3703] | 88 | if ($cat_id && isset($_POST['cat_sibling'])) { |
---|
| 89 | try { |
---|
| 90 | $core->blog->setCategoryPosition($cat_id, (integer) $_POST['cat_sibling'], $_POST['cat_move']); |
---|
| 91 | dcPage::addSuccessNotice(__('The category has been successfully moved')); |
---|
| 92 | $core->adminurl->redirect("admin.categories"); |
---|
| 93 | } catch (Exception $e) { |
---|
| 94 | $core->error->add($e->getMessage()); |
---|
| 95 | } |
---|
[0] | 96 | } |
---|
| 97 | |
---|
| 98 | # Create or update a category |
---|
[3703] | 99 | if (isset($_POST['cat_title'])) { |
---|
| 100 | $cur = $core->con->openCursor($core->prefix . 'category'); |
---|
[2566] | 101 | |
---|
[3703] | 102 | $cur->cat_title = $cat_title = $_POST['cat_title']; |
---|
[2566] | 103 | |
---|
[3703] | 104 | if (isset($_POST['cat_desc'])) { |
---|
| 105 | $cur->cat_desc = $cat_desc = $_POST['cat_desc']; |
---|
| 106 | } |
---|
[2566] | 107 | |
---|
[3703] | 108 | if (isset($_POST['cat_url'])) { |
---|
| 109 | $cur->cat_url = $cat_url = $_POST['cat_url']; |
---|
| 110 | } else { |
---|
| 111 | $cur->cat_url = $cat_url; |
---|
| 112 | } |
---|
[2566] | 113 | |
---|
[3703] | 114 | try |
---|
| 115 | { |
---|
| 116 | # Update category |
---|
| 117 | if ($cat_id) { |
---|
| 118 | # --BEHAVIOR-- adminBeforeCategoryUpdate |
---|
| 119 | $core->callBehavior('adminBeforeCategoryUpdate', $cur, $cat_id); |
---|
[2566] | 120 | |
---|
[3703] | 121 | $core->blog->updCategory($_POST['id'], $cur); |
---|
[2566] | 122 | |
---|
[3703] | 123 | # --BEHAVIOR-- adminAfterCategoryUpdate |
---|
| 124 | $core->callBehavior('adminAfterCategoryUpdate', $cur, $cat_id); |
---|
[2566] | 125 | |
---|
[3703] | 126 | dcPage::addSuccessNotice(__('The category has been successfully updated.')); |
---|
[2189] | 127 | |
---|
[3703] | 128 | $core->adminurl->redirect("admin.category", array('id' => $_POST['id'])); |
---|
| 129 | } |
---|
| 130 | # Create category |
---|
| 131 | else { |
---|
| 132 | # --BEHAVIOR-- adminBeforeCategoryCreate |
---|
| 133 | $core->callBehavior('adminBeforeCategoryCreate', $cur); |
---|
[2566] | 134 | |
---|
[3703] | 135 | $id = $core->blog->addCategory($cur, (integer) $_POST['new_cat_parent']); |
---|
[2566] | 136 | |
---|
[3703] | 137 | # --BEHAVIOR-- adminAfterCategoryCreate |
---|
| 138 | $core->callBehavior('adminAfterCategoryCreate', $cur, $id); |
---|
[2566] | 139 | |
---|
[3703] | 140 | dcPage::addSuccessNotice(sprintf(__('The category "%s" has been successfully created.'), |
---|
| 141 | html::escapeHTML($cur->cat_title))); |
---|
| 142 | $core->adminurl->redirect("admin.categories"); |
---|
| 143 | } |
---|
| 144 | } catch (Exception $e) { |
---|
| 145 | $core->error->add($e->getMessage()); |
---|
| 146 | } |
---|
[0] | 147 | } |
---|
| 148 | |
---|
| 149 | $title = $cat_id ? html::escapeHTML($cat_title) : __('New category'); |
---|
| 150 | |
---|
[1332] | 151 | $elements = array( |
---|
[3703] | 152 | html::escapeHTML($core->blog->name) => '', |
---|
| 153 | __('Categories') => $core->adminurl->get("admin.categories") |
---|
| 154 | ); |
---|
[1332] | 155 | if ($cat_id) { |
---|
[3703] | 156 | while ($parents->fetch()) { |
---|
| 157 | $elements[html::escapeHTML($parents->cat_title)] = $core->adminurl->get("admin.category", array('id' => $parents->cat_id)); |
---|
| 158 | } |
---|
[0] | 159 | } |
---|
[2166] | 160 | $elements[$title] = ''; |
---|
[1358] | 161 | |
---|
[2891] | 162 | $category_editor = $core->auth->getOption('editor'); |
---|
[3703] | 163 | $rte_flag = true; |
---|
| 164 | $rte_flags = @$core->auth->user_prefs->interface->rte_flags; |
---|
| 165 | if (is_array($rte_flags) && in_array('cat_descr', $rte_flags)) { |
---|
| 166 | $rte_flag = $rte_flags['cat_descr']; |
---|
[3330] | 167 | } |
---|
[2891] | 168 | |
---|
[1358] | 169 | dcPage::open($title, |
---|
[3703] | 170 | dcPage::jsConfirmClose('category-form') . |
---|
| 171 | dcPage::jsLoad('js/_category.js') . |
---|
| 172 | ($rte_flag ? $core->callBehavior('adminPostEditor', $category_editor['xhtml'], 'category', array('#cat_desc'), 'xhtml') : ''), |
---|
| 173 | dcPage::breadcrumb($elements) |
---|
[1358] | 174 | ); |
---|
| 175 | |
---|
| 176 | if (!empty($_GET['upd'])) { |
---|
[3703] | 177 | dcPage::success(__('Category has been successfully updated.')); |
---|
[1358] | 178 | } |
---|
[0] | 179 | |
---|
| 180 | echo |
---|
[3703] | 181 | '<form action="' . $core->adminurl->get("admin.category") . '" method="post" id="category-form">' . |
---|
| 182 | '<h3>' . __('Category information') . '</h3>' . |
---|
| 183 | '<p><label class="required" for="cat_title"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Name:') . '</label> ' . |
---|
[3725] | 184 | form::field('cat_title', 40, 255, array( |
---|
| 185 | 'default' => html::escapeHTML($cat_title), |
---|
| 186 | 'extra_html' => 'required placeholder="' . __('Name') . '"' |
---|
| 187 | )) . |
---|
[3730] | 188 | '</p>'; |
---|
[3703] | 189 | if (!$cat_id) { |
---|
| 190 | $rs = $core->blog->getCategories(); |
---|
| 191 | echo |
---|
| 192 | '<p><label for="new_cat_parent">' . __('Parent:') . ' ' . |
---|
| 193 | '<select id="new_cat_parent" name="new_cat_parent" >' . |
---|
| 194 | '<option value="0">' . __('(none)') . '</option>'; |
---|
| 195 | while ($rs->fetch()) { |
---|
| 196 | echo '<option value="' . $rs->cat_id . '" ' . (!empty($_POST['new_cat_parent']) && $_POST['new_cat_parent'] == $rs->cat_id ? 'selected="selected"' : '') . '>' . |
---|
| 197 | str_repeat(' ', $rs->level - 1) . ($rs->level - 1 == 0 ? '' : '• ') . html::escapeHTML($rs->cat_title) . '</option>'; |
---|
| 198 | } |
---|
| 199 | echo |
---|
| 200 | '</select></label></p>'; |
---|
| 201 | unset($rs); |
---|
[0] | 202 | } |
---|
| 203 | echo |
---|
[3703] | 204 | '<div class="lockable">' . |
---|
| 205 | '<p><label for="cat_url">' . __('URL:') . '</label> ' |
---|
| 206 | . form::field('cat_url', 40, 255, html::escapeHTML($cat_url)) . |
---|
| 207 | '</p>' . |
---|
| 208 | '<p class="form-note warn" id="note-cat-url">' . |
---|
| 209 | __('Warning: If you set the URL manually, it may conflict with another category.') . '</p>' . |
---|
| 210 | '</div>' . |
---|
[0] | 211 | |
---|
[3703] | 212 | '<p class="area"><label for="cat_desc">' . __('Description:') . '</label> ' . |
---|
| 213 | form::textarea('cat_desc', 50, 8, html::escapeHTML($cat_desc)) . |
---|
| 214 | '</p>' . |
---|
[0] | 215 | |
---|
[3703] | 216 | '<p><input type="submit" accesskey="s" value="' . __('Save') . '" />' . |
---|
| 217 | ($cat_id ? form::hidden('id', $cat_id) : '') . |
---|
| 218 | $core->formNonce() . |
---|
| 219 | '</p>' . |
---|
| 220 | '</form>'; |
---|
[0] | 221 | |
---|
[3703] | 222 | if ($cat_id) { |
---|
| 223 | echo |
---|
| 224 | '<h3 class="border-top">' . __('Move this category') . '</h3>' . |
---|
| 225 | '<div class="two-cols">' . |
---|
| 226 | '<div class="col">' . |
---|
[2566] | 227 | |
---|
[3703] | 228 | '<form action="' . $core->adminurl->get("admin.category") . '" method="post" class="fieldset">' . |
---|
| 229 | '<h4>' . __('Category parent') . '</h4>' . |
---|
| 230 | '<p><label for="cat_parent" class="classic">' . __('Parent:') . '</label> ' . |
---|
| 231 | form::combo('cat_parent', $allowed_parents, $cat_parent) . '</p>' . |
---|
| 232 | '<p><input type="submit" accesskey="s" value="' . __('Save') . '" />' . |
---|
| 233 | form::hidden(array('id'), $cat_id) . $core->formNonce() . '</p>' . |
---|
| 234 | '</form>' . |
---|
| 235 | '</div>'; |
---|
[2566] | 236 | |
---|
[3703] | 237 | if (count($siblings) > 0) { |
---|
| 238 | echo |
---|
| 239 | '<div class="col">' . |
---|
| 240 | '<form action="' . $core->adminurl->get("admin.category") . '" method="post" class="fieldset">' . |
---|
| 241 | '<h4>' . __('Category sibling') . '</h4>' . |
---|
| 242 | '<p><label class="classic" for="cat_sibling">' . __('Move current category') . '</label> ' . |
---|
| 243 | form::combo('cat_move', array(__('before') => 'before', __('after') => 'after'), |
---|
| 244 | array('extra_html' => 'title="' . __('position: ') . '"')) . ' ' . |
---|
| 245 | form::combo('cat_sibling', $siblings) . '</p>' . |
---|
| 246 | '<p><input type="submit" accesskey="s" value="' . __('Save') . '" />' . |
---|
| 247 | form::hidden(array('id'), $cat_id) . $core->formNonce() . '</p>' . |
---|
| 248 | '</form>' . |
---|
| 249 | '</div>'; |
---|
| 250 | } |
---|
[2566] | 251 | |
---|
[3703] | 252 | echo '</div>'; |
---|
[0] | 253 | } |
---|
| 254 | |
---|
[2314] | 255 | dcPage::helpBlock('core_category'); |
---|
[0] | 256 | dcPage::close(); |
---|