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