Changeset 1525:c30081595436 for admin/categories.php
- Timestamp:
- 08/22/13 20:14:09 (11 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/categories.php
r1468 r1525 15 15 dcPage::check('categories'); 16 16 17 # Remove a category 18 if (!empty($_POST['del_cat'])) 19 { 20 try 21 { 17 # Remove a categories 18 if (!empty($_POST['categories'])) { 19 $error = false; 20 foreach ($_POST['categories'] as $cat_id) { 22 21 # Check if category to delete exists 23 $c = $core->blog->getCategory((integer) $ _POST['del_cat']);22 $c = $core->blog->getCategory((integer) $cat_id); 24 23 if ($c->isEmpty()) { 25 throw new Exception(__('This category does not exist.'));24 continue; 26 25 } 27 26 unset($c); 28 29 # Check if category where to move posts exists 30 $mov_cat = (integer) $_POST['mov_cat']; 31 $mov_cat = $mov_cat ? $mov_cat : null; 32 if ($mov_cat !== null) { 33 $c = $core->blog->getCategory((integer) $_POST['mov_cat']); 34 if ($c->isEmpty()) { 35 throw new Exception(__('This category does not exist.')); 36 } 37 if ($mov_cat == $_POST['del_cat']) { 38 throw new Exception(__('The entries cannot be moved to the category you choose to delete.')); 39 } 40 unset($c); 27 28 try { 29 # Delete category 30 $core->blog->delCategory($cat_id); 31 } catch (Exception $e) { 32 $error = true; 41 33 } 42 43 # Move posts44 $core->blog->changePostsCategory($_POST['del_cat'],$mov_cat);45 46 # Delete category47 $core->blog->delCategory($_POST['del_cat']);48 49 http::redirect('categories.php?del=1');50 34 } 51 catch (Exception $e) 52 { 53 $core->error->add($e->getMessage()); 35 if (!$error) { 36 http::redirect('categories.php?del='.count($_POST['categories'])); 54 37 } 55 38 } … … 69 52 } 70 53 54 # Actions combo box 55 $combo_action = array(); 56 if ($core->auth->check('categories',$core->blog->id)) { 57 $combo_action[__('Delete')] = 'delete'; 58 } 59 60 # --BEHAVIOR-- adminCategoriesActionsCombo 61 $core->callBehavior('adminCategoriesActionsCombo',array(&$combo_action)); 62 63 71 64 /* Display 72 65 -------------------------------------------------------- */ … … 85 78 } 86 79 if (!empty($_GET['del'])) { 87 dcPage::message(__('The category has been successfully removed.')); 80 dcPage::message(__('The category has been successfully removed.', 81 'The categories have been successfully removed.', 82 (int) $_GET['del'] 83 ) 84 ); 88 85 } 89 86 if (!empty($_GET['reord'])) { … … 95 92 96 93 $rs = $core->blog->getCategories(array('post_type'=>'post')); 97 98 echo99 '<div class="two-cols">'.100 '<div class="col">';101 if ($rs->isEmpty())102 {103 echo '<p>'.__('No category yet.').'</p>';104 }105 else106 {107 echo108 '<h3>'.__('Categories list').'</h3>'.109 '<div id="categories">';110 111 $ref_level = $level = $rs->level-1;112 while ($rs->fetch())113 {114 $attr = 'id="cat'.$rs->cat_id.'"';115 if ($rs->nb_total == 0) {116 $attr .= ' class="deletable"';117 }118 119 if ($rs->level > $level) {120 echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level);121 } elseif ($rs->level < $level) {122 echo str_repeat('</li></ul>',-($rs->level - $level));123 }124 125 if ($rs->level <= $level) {126 echo '</li><li '.$attr.'>';127 }128 129 echo130 '<p><strong><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></strong>'.131 ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'.132 sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'.133 ', '.__('total:').' '.$rs->nb_total.')</p>'.134 '<p>'.__('URL:').' '.html::escapeHTML($rs->cat_url).'</p>';135 136 $level = $rs->level;137 }138 139 if ($ref_level - $level < 0) {140 echo str_repeat('</li></ul>',-($ref_level - $level));141 }142 echo '</div>';143 }144 echo '</div>';145 94 146 95 $categories_combo = array(); … … 155 104 } 156 105 157 echo '<div class="col">'. 106 echo 107 '<p class="top-add"><a class="button add" href="category.php">'.__('New category').'</a></p>'; 158 108 159 '<form action="category.php" method="post">'. 160 '<h3>'.__('Add a new category').'</h3>'. 161 '<p><label class="required" for="cat_title"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label> '. 162 form::field('cat_title',30,255,'','maximal').'</p>'. 163 '<p><label for="new_cat_parent">'.__('Parent:').'</label> '. 164 form::combo('new_cat_parent',array_merge(array(__('(No cat)') => 0),$categories_combo),'','maximal'). 165 '</p>'. 166 '<p><input type="submit" value="'.__('Create').'" />'. 167 $core->formNonce().'</p>'. 168 169 '</form>'; 170 171 if (!$rs->isEmpty()) 109 echo 110 '<div class="col">'; 111 if ($rs->isEmpty()) 112 { 113 echo '<p>'.__('No category yet.').'</p>'; 114 } 115 else 172 116 { 173 117 echo 174 '<form action="categories.php" method="post" id="delete-category">'. 175 '<h3>'.__('Remove a category').'</h3>'. 176 '<p><label for="del_cat">'.__('Choose a category to remove:').'</label> '. 177 form::combo('del_cat',$categories_combo,'','maximal').'</p> '. 178 '<p><label for="mov_cat">'.__('And choose the category which will receive its entries:').'</label> '. 179 form::combo('mov_cat',array_merge(array(__('(No cat)') => ''),$categories_combo),'','maximal').'</p> '. 180 '<p><input type="submit" value="'.__('Delete').'" class="delete" />'. 181 $core->formNonce().'</p>'. 118 '<form action="categories.php" method="post" id="form-categories">'. 119 '<h3>'.__('Categories list').'</h3>'. 120 '<div id="categories">'; 182 121 183 '</form>'; 184 122 $ref_level = $level = $rs->level-1; 123 while ($rs->fetch()) 124 { 125 $attr = 'id="cat'.$rs->cat_id.'"'; 126 if ($rs->nb_total == 0) { 127 $attr .= ' class="deletable"'; 128 } 129 130 if ($rs->level > $level) { 131 echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level); 132 } elseif ($rs->level < $level) { 133 echo str_repeat('</li></ul>',-($rs->level - $level)); 134 } 135 136 if ($rs->level <= $level) { 137 echo '</li><li '.$attr.'>'; 138 } 139 140 echo 141 '<p>'; 142 if ($rs->nb_total == 0) { 143 echo form::checkbox(array('categories[]'),$rs->cat_id); 144 } 145 146 echo 147 '<strong><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></strong>'. 148 ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'. 149 sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'. 150 ', '.__('total:').' '.$rs->nb_total.')</p>'. 151 '<p>'.__('URL:').' '.html::escapeHTML($rs->cat_url).'</p>'; 152 153 $level = $rs->level; 154 } 155 156 if ($ref_level - $level < 0) { 157 echo str_repeat('</li></ul>',-($ref_level - $level)); 158 } 185 159 echo 186 '<form action="categories.php" method="post" id="reset-order" class="border-top">'. 160 '</div>'; 161 162 if (count($combo_action)>0) { 163 echo 164 '<div class="two-cols">'. 165 '<p class="col checkboxes-helpers"></p>'. 166 '<p class="col right"><label for="action" class="classic">'.__('Selected categories action:').'</label> '. 167 form::combo('action',$combo_action). 168 $core->formNonce(). 169 '<input type="submit" value="'.__('ok').'" /></p>'. 170 '</div>'. 171 '</form>'; 172 } 173 174 echo 175 '<div class="col clear">'. 176 '<form action="categories.php" method="post" id="reset-order">'. 187 177 '<h3>'.__('Reorder categories').'</h3>'. 188 178 '<p>'.__('This will relocate all categories on the top level').'</p> '. 189 '<p><input type="submit" value="'.__('Reorder').'" />'.179 '<p><input class="reset" type="submit" value="'.__('Reorder').'" />'. 190 180 form::hidden(array('reset'),1). 191 181 $core->formNonce().'</p>'. 192 '</form>'; 182 '</form>'. 183 '</div>'; 193 184 } 194 echo '</div>'; 185 195 186 echo '</div>'; 196 187
Note: See TracChangeset
for help on using the changeset viewer.