| 1 | <?php | 
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- | 
|---|
| 3 | # | 
|---|
| 4 | # This file is part of Dotclear 2. | 
|---|
| 5 | # | 
|---|
| 6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear | 
|---|
| 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 | # Remove a category | 
|---|
| 18 | if (!empty($_POST['del_cat'])) | 
|---|
| 19 | { | 
|---|
| 20 |      try | 
|---|
| 21 |      { | 
|---|
| 22 |           # Check if category to delete exists | 
|---|
| 23 |           $c = $core->blog->getCategory((integer) $_POST['del_cat']); | 
|---|
| 24 |           if ($c->isEmpty()) { | 
|---|
| 25 |                throw new Exception(__('This category does not exist.')); | 
|---|
| 26 |           } | 
|---|
| 27 |           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['del_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); | 
|---|
| 41 |           } | 
|---|
| 42 |            | 
|---|
| 43 |           # Move posts | 
|---|
| 44 |           $core->blog->updPostsCategory($_POST['del_cat'],$mov_cat); | 
|---|
| 45 |            | 
|---|
| 46 |           # Delete category | 
|---|
| 47 |           $core->blog->delCategory($_POST['del_cat']); | 
|---|
| 48 |            | 
|---|
| 49 |           http::redirect('categories.php?del=1'); | 
|---|
| 50 |      } | 
|---|
| 51 |      catch (Exception $e) | 
|---|
| 52 |      { | 
|---|
| 53 |           $core->error->add($e->getMessage()); | 
|---|
| 54 |      } | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | # Reset order | 
|---|
| 58 | if (!empty($_POST['reset'])) | 
|---|
| 59 | { | 
|---|
| 60 |      try | 
|---|
| 61 |      { | 
|---|
| 62 |           $core->blog->resetCategoriesOrder(); | 
|---|
| 63 |           http::redirect('categories.php?reord=1'); | 
|---|
| 64 |      } | 
|---|
| 65 |      catch (Exception $e) | 
|---|
| 66 |      { | 
|---|
| 67 |           $core->error->add($e->getMessage()); | 
|---|
| 68 |      } | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|
| 71 | /* Display | 
|---|
| 72 | -------------------------------------------------------- */ | 
|---|
| 73 | dcPage::open(__('Categories'), | 
|---|
| 74 |      dcPage::jsToolMan()."\n". | 
|---|
| 75 |      dcPage::jsLoad('js/_categories.js') | 
|---|
| 76 | ); | 
|---|
| 77 |  | 
|---|
| 78 | if (!empty($_GET['add'])) { | 
|---|
| 79 |      dcPage::message(__('The category has been successfully created.')); | 
|---|
| 80 | } | 
|---|
| 81 | if (!empty($_GET['del'])) { | 
|---|
| 82 |      dcPage::message(__('The category has been successfully removed.')); | 
|---|
| 83 | } | 
|---|
| 84 | if (!empty($_GET['reord'])) { | 
|---|
| 85 |      dcPage::message(__('Categories have been successfully reordered.')); | 
|---|
| 86 | } | 
|---|
| 87 | if (!empty($_GET['moved'])) { | 
|---|
| 88 |      dcPage::message(__('The category has been successfully moved.')); | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | echo '<h2>'.html::escapeHTML($core->blog->name).' › <span class="page-title">'.__('Categories').'</span></h2>'; | 
|---|
| 92 |  | 
|---|
| 93 | $rs = $core->blog->getCategories(array('post_type'=>'post')); | 
|---|
| 94 |  | 
|---|
| 95 | echo | 
|---|
| 96 | '<div class="two-cols">'. | 
|---|
| 97 | '<div class="col">'; | 
|---|
| 98 | if ($rs->isEmpty()) | 
|---|
| 99 | { | 
|---|
| 100 |      echo '<p>'.__('No category yet.').'</p>'; | 
|---|
| 101 | } | 
|---|
| 102 | else | 
|---|
| 103 | { | 
|---|
| 104 |      echo | 
|---|
| 105 |      '<h3>'.__('Categories list').'</h3>'. | 
|---|
| 106 |      '<div id="categories">'; | 
|---|
| 107 |       | 
|---|
| 108 |      $ref_level = $level = $rs->level-1; | 
|---|
| 109 |      while ($rs->fetch()) | 
|---|
| 110 |      { | 
|---|
| 111 |           $attr = 'id="cat'.$rs->cat_id.'"'; | 
|---|
| 112 |           if ($rs->nb_total == 0) { | 
|---|
| 113 |                $attr .= ' class="deletable"'; | 
|---|
| 114 |           } | 
|---|
| 115 |            | 
|---|
| 116 |           if ($rs->level > $level) { | 
|---|
| 117 |                echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level); | 
|---|
| 118 |           } elseif ($rs->level < $level) { | 
|---|
| 119 |                echo str_repeat('</li></ul>',-($rs->level - $level)); | 
|---|
| 120 |           } | 
|---|
| 121 |            | 
|---|
| 122 |           if ($rs->level <= $level) { | 
|---|
| 123 |                echo '</li><li '.$attr.'>'; | 
|---|
| 124 |           } | 
|---|
| 125 |            | 
|---|
| 126 |           echo | 
|---|
| 127 |           '<p><strong><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></strong>'. | 
|---|
| 128 |           ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'. | 
|---|
| 129 |           sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'. | 
|---|
| 130 |           ', '.__('total:').' '.$rs->nb_total.')</p>'. | 
|---|
| 131 |           '<p>'.__('URL:').' '.html::escapeHTML($rs->cat_url).'</p>'; | 
|---|
| 132 |            | 
|---|
| 133 |           $level = $rs->level; | 
|---|
| 134 |      } | 
|---|
| 135 |       | 
|---|
| 136 |      if ($ref_level - $level < 0) { | 
|---|
| 137 |           echo str_repeat('</li></ul>',-($ref_level - $level)); | 
|---|
| 138 |      } | 
|---|
| 139 |      echo '</div>'; | 
|---|
| 140 | } | 
|---|
| 141 | echo '</div>'; | 
|---|
| 142 |  | 
|---|
| 143 | echo '<div class="col">'. | 
|---|
| 144 |  | 
|---|
| 145 | '<form action="category.php" method="post">'. | 
|---|
| 146 | '<fieldset><legend>'.__('Add a new category').'</legend>'. | 
|---|
| 147 | '<p><label class="required" for="cat_title"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').' '. | 
|---|
| 148 | form::field('cat_title',30,255).'</label></p>'. | 
|---|
| 149 | '<p><label for="new_cat_parent">'.__('Parent:').' '. | 
|---|
| 150 | '<select id="new_cat_parent" name="new_cat_parent">'. | 
|---|
| 151 | '<option value="0">'.__('Top level').'</option>'; | 
|---|
| 152 | while ($rs->fetch()) { | 
|---|
| 153 |      echo '<option value="'.$rs->cat_id.'">'. | 
|---|
| 154 |           str_repeat('  ',$rs->level-1).($rs->level-1 == 0 ? '' : '• '). | 
|---|
| 155 |           html::escapeHTML($rs->cat_title).'</option>'; | 
|---|
| 156 | } | 
|---|
| 157 | echo | 
|---|
| 158 | '</select></label></p>'. | 
|---|
| 159 | '<p><input type="submit" value="'.__('Create').'" /></p>'. | 
|---|
| 160 | $core->formNonce(). | 
|---|
| 161 | '</fieldset>'. | 
|---|
| 162 | '</form>'; | 
|---|
| 163 |  | 
|---|
| 164 | if (!$rs->isEmpty()) | 
|---|
| 165 | { | 
|---|
| 166 |      $cats = array(); | 
|---|
| 167 |      $dest = array(' ' => ''); | 
|---|
| 168 |      $l = $rs->level; | 
|---|
| 169 |      $full_name = array($rs->cat_title); | 
|---|
| 170 |      while ($rs->fetch()) | 
|---|
| 171 |      { | 
|---|
| 172 |           if ($rs->level < $l) { | 
|---|
| 173 |                $full_name = array(); | 
|---|
| 174 |           } elseif ($rs->level == $l) { | 
|---|
| 175 |                array_pop($full_name); | 
|---|
| 176 |           } | 
|---|
| 177 |           $full_name[] = html::escapeHTML($rs->cat_title); | 
|---|
| 178 |            | 
|---|
| 179 |           $cats[implode(' / ',$full_name)] = $rs->cat_id; | 
|---|
| 180 |           $dest[implode(' / ',$full_name)] = $rs->cat_id; | 
|---|
| 181 |            | 
|---|
| 182 |           $l = $rs->level; | 
|---|
| 183 |      } | 
|---|
| 184 |       | 
|---|
| 185 |      echo | 
|---|
| 186 |      '<form action="categories.php" method="post" id="delete-category">'. | 
|---|
| 187 |      '<fieldset><legend>'.__('Remove a category').'</legend>'. | 
|---|
| 188 |      '<p><label for="del_cat">'.__('Choose a category to remove:').' '. | 
|---|
| 189 |      form::combo('del_cat',$cats).'</label></p> '. | 
|---|
| 190 |      '<p><label for="mov_cat">'.__('And choose the category which will receive its entries:').' '. | 
|---|
| 191 |      form::combo('mov_cat',$dest).'</label></p> '. | 
|---|
| 192 |      '<p><input type="submit" value="'.__('Delete').'" class="delete" /></p>'. | 
|---|
| 193 |      $core->formNonce(). | 
|---|
| 194 |      '</fieldset>'. | 
|---|
| 195 |      '</form>'; | 
|---|
| 196 |       | 
|---|
| 197 |      echo | 
|---|
| 198 |      '<form action="categories.php" method="post" id="reset-order">'. | 
|---|
| 199 |      '<fieldset><legend>'.__('Reorder categories').'</legend>'. | 
|---|
| 200 |      '<p>'.__('This will relocate all categories on the top level').'</p> '. | 
|---|
| 201 |      '<p><input type="submit" value="'.__('Reorder').'" /></p>'. | 
|---|
| 202 |      form::hidden(array('reset'),1). | 
|---|
| 203 |      $core->formNonce(). | 
|---|
| 204 |      '</fieldset>'. | 
|---|
| 205 |      '</form>'; | 
|---|
| 206 | } | 
|---|
| 207 | echo '</div>'; | 
|---|
| 208 | echo '</div>'; | 
|---|
| 209 |  | 
|---|
| 210 | dcPage::helpBlock('core_categories'); | 
|---|
| 211 | dcPage::close(); | 
|---|
| 212 | ?> | 
|---|