[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/include/admin/ -> category.inc.php (source)

   1  <?php # $Id: category.inc.php 1816 2007-08-06 10:18:39Z garvinhicking $
   2  # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
   3  # All rights reserved.  See LICENSE file for licensing details
   4  
   5  if (IN_serendipity !== true) {
   6      die ("Don't hack!");
   7  }
   8  
   9  if (!serendipity_checkPermission('adminCategories')) {
  10      return;
  11  }
  12  
  13  $admin_category = (!serendipity_checkPermission('adminCategoriesMaintainOthers') ? "AND (authorid = 0 OR authorid = " . (int)$serendipity['authorid'] . ")" : '');
  14  
  15  /* Add a new category */
  16  if (isset($_POST['SAVE']) && serendipity_checkFormToken()) {
  17      $name     = $serendipity['POST']['cat']['name'];
  18      $desc     = $serendipity['POST']['cat']['description'];
  19  
  20      if (is_array($serendipity['POST']['cat']['write_authors']) && in_array(0, $serendipity['POST']['cat']['write_authors'])) {
  21          $authorid = 0;
  22      } else {
  23          $authorid = $serendipity['authorid'];
  24      }
  25  
  26      $icon     = $serendipity['POST']['cat']['icon'];
  27      $parentid = (isset($serendipity['POST']['cat']['parent_cat']) && is_numeric($serendipity['POST']['cat']['parent_cat'])) ? $serendipity['POST']['cat']['parent_cat'] : 0;
  28  
  29      if ($serendipity['GET']['adminAction'] == 'new') {
  30          if ($parentid != 0) {
  31              // TODO: This doesn't seem to work as expected, serendipity_rebuildCategoryTree(); is still needed! Only activate this optimization function when it's really working :)
  32              // TODO: This works if only one subcategory exists.  Otherwise, the first query will return an array.
  33              /*
  34              $res = serendipity_db_query("SELECT category_right FROM {$serendipity['dbPrefix']}category WHERE parentid={$parentid}");
  35              serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category SET category_left=category_left+2, category_right=category_right+2 WHERE category_right>{$res}");
  36              */
  37          }
  38  
  39          $catid = serendipity_addCategory($name, $desc, $authorid, $icon, $parentid);
  40          serendipity_ACLGrant($catid, 'category', 'read', $serendipity['POST']['cat']['read_authors']);
  41          serendipity_ACLGrant($catid, 'category', 'write', $serendipity['POST']['cat']['write_authors']);
  42  
  43          echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . CATEGORY_SAVED .'</div>';
  44  
  45      } elseif ($serendipity['GET']['adminAction'] == 'edit') {
  46              if (!serendipity_checkPermission('adminCategoriesMaintainOthers') && !serendipity_ACLCheck($serendipity['authorid'], $serendipity['GET']['cid'], 'category', 'write')) {
  47                  echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />'. PERM_DENIED .'</div>';
  48              } else {
  49                  /* Check to make sure parent is not a child of self */
  50                  $r = serendipity_db_query("SELECT categoryid FROM {$serendipity['dbPrefix']}category c
  51                                                  WHERE c.categoryid = ". (int)$parentid ."
  52                                                      AND c.category_left BETWEEN " . implode(' AND ', serendipity_fetchCategoryRange((int)$serendipity['GET']['cid'])));
  53                  if (is_array($r)) {
  54                      $r = serendipity_db_query("SELECT category_name FROM {$serendipity['dbPrefix']}category
  55                                                          WHERE categoryid = ". (int)$parentid);
  56                      echo sprintf(ALREADY_SUBCATEGORY, htmlspecialchars($r[0]['category_name']), htmlspecialchars($name));
  57                  } else {
  58                      serendipity_updateCategory($serendipity['GET']['cid'], $name, $desc, $authorid, $icon, $parentid, $serendipity['POST']['cat']['sort_order'], $serendipity['POST']['cat']['hide_sub']);
  59                      serendipity_ACLGrant($serendipity['GET']['cid'], 'category', 'read', $serendipity['POST']['cat']['read_authors']);
  60                      serendipity_ACLGrant($serendipity['GET']['cid'], 'category', 'write', $serendipity['POST']['cat']['write_authors']);
  61                      echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . CATEGORY_SAVED .'</div>';
  62                  }
  63              }
  64      }
  65  
  66      serendipity_rebuildCategoryTree();
  67      $serendipity['GET']['adminAction'] = 'view';
  68  }
  69  
  70  /* Delete a category */
  71  if ($serendipity['GET']['adminAction'] == 'doDelete' && serendipity_checkFormToken()) {
  72      if ($serendipity['GET']['cid'] != 0) {
  73          $remaining_cat = (int)$serendipity['POST']['cat']['remaining_catid'];
  74          $category_ranges = serendipity_fetchCategoryRange((int)$serendipity['GET']['cid']);
  75          $category_range  = implode(' AND ', $category_ranges);
  76          if ($serendipity['dbType'] == 'postgres' || $serendipity['dbType'] == 'sqlite' || $serendipity['dbType'] == 'sqlite3') {
  77              $query = "UPDATE {$serendipity['dbPrefix']}entrycat
  78                          SET categoryid={$remaining_cat} WHERE entryid IN
  79                          (
  80                            SELECT DISTINCT(e.id) FROM {$serendipity['dbPrefix']}entries e,
  81                            {$serendipity['dbPrefix']}category c,
  82                            {$serendipity['dbPrefix']}entrycat ec
  83                            WHERE e.id=ec.entryid AND c.categoryid=ec.categoryid
  84                            AND c.category_left BETWEEN {$category_range} {$admin_category}
  85                          )";
  86          } else {
  87              $query = "UPDATE {$serendipity['dbPrefix']}entries e,
  88                          {$serendipity['dbPrefix']}entrycat ec,
  89                          {$serendipity['dbPrefix']}category c
  90                        SET ec.categoryid={$remaining_cat}
  91                          WHERE e.id = ec.entryid
  92                            AND c.categoryid = ec.categoryid
  93                            AND c.category_left BETWEEN {$category_range}
  94                            {$admin_category}";
  95          }
  96          if ( serendipity_db_query($query) ) {
  97              if (serendipity_deleteCategory($category_range, $admin_category) ) {
  98  
  99                  foreach($category_ranges AS $cid) {
 100                      if (serendipity_ACLCheck($serendipity['authorid'], $cid, 'category', 'write')) {
 101                          serendipity_ACLGrant($cid, 'category', 'read', array());
 102                          serendipity_ACLGrant($cid, 'category', 'write', array());
 103                      }
 104                  }
 105  
 106                  echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . ($remaining_cat ? sprintf(CATEGORY_DELETED_ARTICLES_MOVED, (int)$serendipity['GET']['cid'], $remaining_cat) : sprintf(CATEGORY_DELETED,(int)$serendipity['GET']['cid'])) .'</div>';
 107                  $serendipity['GET']['adminAction'] = 'view';
 108              }
 109          }
 110      } else {
 111          echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />'. INVALID_CATEGORY .'</div>';
 112      }
 113  }
 114  ?>
 115  
 116  <?php
 117      if ( $serendipity['GET']['adminAction'] == 'delete' ) {
 118          $this_cat = serendipity_fetchCategoryInfo($serendipity['GET']['cid']);
 119          if (   (serendipity_checkPermission('adminCategoriesDelete') && serendipity_checkPermission('adminCategoriesMaintainOthers'))
 120              || (serendipity_checkPermission('adminCategoriesDelete') && ($serendipity['authorid'] == $this_cat['authorid'] || $this_cat['authorid'] == '0'))
 121              || (serendipity_checkPermission('adminCategoriesDelete') && serendipity_ACLCheck($serendipity['authorid'], $serendipity['GET']['cid'], 'category', 'write'))) {
 122  ?>
 123          <form method="POST" name="serendipityCategory" action="?serendipity[adminModule]=category&amp;serendipity[adminAction]=doDelete&amp;serendipity[cid]=<?php echo $serendipity['GET']['cid'] ?>">
 124          <?php echo serendipity_setFormToken(); ?>
 125              <h3><?php echo $this_cat['category_name']; ?></h3>
 126              <?php echo CATEGORY_REMAINING ?>:
 127              <select name="serendipity[cat][remaining_catid]">
 128                  <option value="0">- <?php echo NO_CATEGORY ?> -</option>
 129  <?php
 130      $cats = serendipity_fetchCategories('all');
 131      /* TODO, show dropdown as nested categories */
 132      foreach ($cats as $cat_data) {
 133          if ($cat_data['categoryid'] != $serendipity['GET']['cid'] && (serendipity_checkPermission('adminCategoriesMaintainOthers') || $cat_data['authorid'] == '0' || $cat_data['authorid'] == $serendipity['authorid'])) {
 134              echo '<option value="' . $cat_data['categoryid'] . '">' . htmlspecialchars($cat_data['category_name']) . '</option>' . "\n";
 135          }
 136      }
 137  ?>
 138              </select>
 139              <input type="submit" name="REMOVE" value="<?php echo GO ?>" class="serendipityPrettyButton input_button">
 140          </form>
 141  <?php
 142          }
 143      }
 144  ?>
 145  
 146  
 147  
 148  <?php if ( $serendipity['GET']['adminAction'] == 'edit' || $serendipity['GET']['adminAction'] == 'new' ) {
 149          if ( $serendipity['GET']['adminAction'] == 'edit' ) {
 150              $cid = (int)$serendipity['GET']['cid'];
 151              $this_cat = serendipity_fetchCategoryInfo($cid);
 152              echo '<strong>'. sprintf(EDIT_THIS_CAT, htmlspecialchars($this_cat['category_name'])) .'</strong>';
 153              $save = SAVE;
 154              $read_groups  = serendipity_ACLGet($cid, 'category', 'read');
 155              $write_groups = serendipity_ACLGet($cid, 'category', 'write');
 156          } else {
 157              $cid = false;
 158              $this_cat = array();
 159              echo '<strong>'. CREATE_NEW_CAT .'</strong>';
 160              $save = CREATE;
 161              $read_groups  = array(0 => 0);
 162              $write_groups = array(0 => 0);
 163          }
 164  
 165          $groups = serendipity_getAllGroups();
 166  ?>
 167  <form method="POST" name="serendipityCategory">
 168  <?php echo serendipity_setFormToken(); ?>
 169  <table cellpadding="5" width="100%">
 170      <tr>
 171          <td><?php echo NAME; ?></td>
 172          <td><input class="input_textbox" type="text" name="serendipity[cat][name]" value="<?php echo isset($this_cat['category_name']) ? htmlspecialchars($this_cat['category_name']) : ''; ?>" /></td>
 173          <td rowspan="5" align="center" valign="middle" width="200" style="border: 1px solid #ccc"><img src="<?php echo isset($this_cat['category_icon']) ? $this_cat['category_icon'] : '' ?>" id="imagepreview" <?php echo empty($this_cat['category_icon']) ? 'style="display: none"' : '' ?> /></td>
 174      </tr>
 175  
 176      <tr>
 177          <td><?php echo DESCRIPTION; ?></td>
 178          <td><input class="input_textbox" type="text" name="serendipity[cat][description]" value="<?php echo isset($this_cat['category_description']) ? htmlspecialchars($this_cat['category_description']) : ''; ?>" /></td>
 179      </tr>
 180  
 181      <tr>
 182          <td><?php echo IMAGE; ?></td>
 183          <td>
 184              <script type="text/javascript" language="JavaScript" src="serendipity_editor.js"></script>
 185              <input class="input_textbox" type="text" id="img_icon" name="serendipity[cat][icon]" value="<?php echo isset($this_cat['category_icon']) ? htmlspecialchars($this_cat['category_icon']) : ''; ?>" onchange="document.getElementById('imagepreview').src = this.value; document.getElementById('imagepreview').style.display = '';" />
 186              <script type="text/javascript" language="JavaScript">document.write('<input type="button" name="insImage" value="<?php echo IMAGE ; ?>" onclick="window.open(\'serendipity_admin_image_selector.php?serendipity[htmltarget]=img_icon&amp;serendipity[filename_only]=true\', \'ImageSel\', \'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1\');" class="serendipityPrettyButton input_button" />');</script><!-- noscript>FIXXME: Emit a warning if JS is disabled</noscript -->
 187          </td>
 188      </tr>
 189  
 190      <tr>
 191          <td><label for="read_authors"><?php echo PERM_READ; ?></label></td>
 192          <td>
 193              <select size="6" id="read_authors" multiple="multiple" name="serendipity[cat][read_authors][]">
 194                  <option value="0" <?php echo (!is_array($this_cat) || (isset($this_cat['authorid']) && $this_cat['authorid'] == '0') || isset($read_groups[0])) ? 'selected="selected"' : ''; ?>><?php echo ALL_AUTHORS; ?></option>
 195  <?php
 196          foreach($groups AS $group) {
 197              echo '<option value="' . $group['confkey'] . '" ' . (isset($read_groups[$group['confkey']]) ? 'selected="selected"' : '') . '>' . htmlspecialchars($group['confvalue']) . '</option>' . "\n";
 198          }
 199  ?>
 200              </select>
 201          </td>
 202      </tr>
 203  
 204      <tr>
 205          <td><label for="write_authors"><?php echo PERM_WRITE; ?></label></td>
 206          <td>
 207              <select size="6" id="write_authors" multiple="multiple" name="serendipity[cat][write_authors][]">
 208                  <option value="0" <?php echo (!is_array($this_cat) || (isset($this_cat['authorid']) && $this_cat['authorid'] == '0') || isset($write_groups[0])) ? 'selected="selected"' : ''; ?>><?php echo ALL_AUTHORS; ?></option>
 209  <?php
 210          foreach($groups AS $group) {
 211              echo '<option value="' . $group['confkey'] . '" ' . (isset($write_groups[$group['confkey']]) ? 'selected="selected"' : '') . '>' . htmlspecialchars($group['confvalue']) . '</option>' . "\n";
 212          }
 213  ?>
 214              </select>
 215          </td>
 216      </tr>
 217  
 218      <tr>
 219          <td><label for="parent_cat"><?php echo PARENT_CATEGORY; ?></label></td>
 220          <td>
 221              <select id="parent_cat" name="serendipity[cat][parent_cat]">
 222                  <option value="0"<?php if ( (int)$serendipity['GET']['cid'] == 0 ) echo ' selected="selected"'; ?>>[ <?php echo NO_CATEGORY; ?> ]</option>
 223  <?php
 224          $categories = serendipity_fetchCategories('all');
 225          $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED);
 226          foreach ( $categories as $cat ) {
 227              /* We can't be our own parent, the universe will collapse */
 228              if ( $cat['categoryid'] == $serendipity['GET']['cid'] ) {
 229                  continue;
 230              }
 231              echo '<option value="'. $cat['categoryid'] .'"'. ($this_cat['parentid'] == $cat['categoryid'] ? ' selected="selected"' : '') .'>'. str_repeat('&nbsp;', $cat['depth']) . $cat['category_name'] .'</option>' . "\n";
 232          }
 233  ?>
 234              </select>
 235          </td>
 236      </tr>
 237  
 238      <tr>
 239          <td><?php echo CATEGORY_HIDE_SUB ?><br /><em><?php echo CATEGORY_HIDE_SUB_DESC; ?></em></td>
 240          <td valign="top">
 241              <input class="input_radio" type="radio" name="serendipity[cat][hide_sub]" value="0" <?php echo ($this_cat['hide_sub'] == 0 ? 'checked="checked"' : ''); ?> id="hide_sub_no" /> <label for="hide_sub_no"><?php echo NO; ?></label>
 242              <input class="input_radio" type="radio" name="serendipity[cat][hide_sub]" value="1" <?php echo ($this_cat['hide_sub'] == 1 ? 'checked="checked"' : ''); ?> id="hide_sub_yes" /> <label for="hide_sub_yes"><?php echo YES; ?></label>
 243          </td>
 244      </tr>
 245  
 246      <?php serendipity_plugin_api::hook_event('backend_category_showForm', $cid, $this_cat); ?>
 247  </table>
 248      <div><input type="submit" name="SAVE" value="<?php echo $save; ?>" class="serendipityPrettyButton input_button" /></div>
 249  </form>
 250  <?php } ?>
 251  
 252  
 253  
 254  
 255  <?php
 256  if ( $serendipity['GET']['adminAction'] == 'view' ) {
 257      if (empty($admin_category)) {
 258          $cats = serendipity_fetchCategories('all');
 259      } else {
 260          $cats = serendipity_fetchCategories(null, null, null, 'write');
 261      }
 262  
 263      if ( is_array($cats) && sizeof($cats) > 0 ) {
 264          echo CATEGORY_INDEX .':';
 265      } else {
 266          echo '<div align="center">- '. NO_CATEGORIES .' -</div>';
 267      }
 268  ?>
 269  <br /><br />
 270  <table cellspacing="0" cellpadding="4" width="100%" border=0>
 271  <?php
 272              if ( is_array($cats) ) {
 273                  $categories = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
 274                  foreach ( $categories as $category ) {
 275  ?>
 276              <tr>
 277                  <td width="16"><a title="<?php echo EDIT ?>" href="?serendipity[adminModule]=category&amp;serendipity[adminAction]=edit&amp;serendipity[cid]=<?php echo $category['categoryid'] ?>"><img src="<?php echo serendipity_getTemplateFile('admin/img/edit.png') ?>" border="0" alt="<?php echo EDIT ?>" /></a></td>
 278                  <td width="16"><a title="<?php echo DELETE ?>" href="?serendipity[adminModule]=category&amp;serendipity[adminAction]=delete&amp;serendipity[cid]=<?php echo $category['categoryid'] ?>"><img src="<?php echo serendipity_getTemplateFile('admin/img/delete.png') ?>" border="0" alt="<?php echo DELETE ?>" /></a></td>
 279                  <td width="16"><?php if ( !empty($category['category_icon']) ) {?><img src="<?php echo serendipity_getTemplateFile('admin/img/thumbnail.png') ?>" alt="" /><?php } else echo '&nbsp;' ?></td>
 280                  <td width="300" style="padding-left: <?php echo ($category['depth']*15)+20 ?>px"><img src="<?php echo serendipity_getTemplateFile('admin/img/folder.png') ?>" style="vertical-align: bottom;"> <?php echo htmlspecialchars($category['category_name']) ?></td>
 281                  <td><?php echo htmlspecialchars($category['category_description']) ?></td>
 282                  <td align="right"><?php echo ($category['authorid'] == '0' ? ALL_AUTHORS : $category['realname']); ?></td>
 283              </tr>
 284  <?php           }
 285              } ?>
 286              <tr>
 287                  <td colspan="6" align="right">
 288                      <a href="?serendipity[adminModule]=category&serendipity[adminAction]=new" class="serendipityPrettyButton input_button"><?php echo CREATE_NEW_CAT ?></a>
 289                  </td>
 290              </tr>
 291  </table>
 292  <?php }
 293  
 294  /* vim: set sts=4 ts=4 expandtab : */


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics