[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/modules/system/admin/images/ -> main.php (source)

   1  <?php
   2  // $Id: main.php 2 2005-11-02 18:23:29Z skalpa $

   3  //  ------------------------------------------------------------------------ //

   4  //                XOOPS - PHP Content Management System                      //

   5  //                    Copyright (c) 2000 XOOPS.org                           //

   6  //                       <http://www.xoops.org/>                             //

   7  //  ------------------------------------------------------------------------ //

   8  //  This program is free software; you can redistribute it and/or modify     //

   9  //  it under the terms of the GNU General Public License as published by     //

  10  //  the Free Software Foundation; either version 2 of the License, or        //

  11  //  (at your option) any later version.                                      //

  12  //                                                                           //

  13  //  You may not change or alter any portion of this comment or credits       //

  14  //  of supporting developers from this source code or any supporting         //

  15  //  source code which is considered copyrighted (c) material of the          //

  16  //  original comment or credit authors.                                      //

  17  //                                                                           //

  18  //  This program is distributed in the hope that it will be useful,          //

  19  //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //

  20  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //

  21  //  GNU General Public License for more details.                             //

  22  //                                                                           //

  23  //  You should have received a copy of the GNU General Public License        //

  24  //  along with this program; if not, write to the Free Software              //

  25  //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //

  26  //  ------------------------------------------------------------------------ //

  27  // Author: Kazumi Ono (AKA onokazu)                                          //

  28  // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //

  29  // Project: The XOOPS Project                                                //

  30  // ------------------------------------------------------------------------- //

  31  
  32  if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
  33      exit("Access Denied");
  34  } else {
  35      $op = 'list';
  36      if (isset($_POST)) {
  37          foreach ( $_POST as $k => $v ) {
  38              ${$k} = $v;
  39          }
  40      }
  41      if (isset($_GET['op'])) {
  42          $op = trim($_GET['op']);
  43      }
  44      if (isset($_GET['image_id'])) {
  45          $image_id = intval($_GET['image_id']);
  46      }
  47      if (isset($_GET['imgcat_id'])) {
  48          $imgcat_id = intval($_GET['imgcat_id']);
  49      }
  50      if ($op == 'list') {
  51          $imgcat_handler = xoops_gethandler('imagecategory');
  52          $imagecategorys =& $imgcat_handler->getObjects();
  53          xoops_cp_header();
  54          echo '<h4 style="text-align:left">'._IMGMANAGER.'</h4><ul>';
  55          $catcount = count($imagecategorys);
  56          $image_handler =& xoops_gethandler('image');
  57          for ($i = 0; $i < $catcount; $i++) {
  58              $count = $image_handler->getCount(new Criteria('imgcat_id', $imagecategorys[$i]->getVar('imgcat_id')));
  59              echo '<li>'.$imagecategorys[$i]->getVar('imgcat_name').' ('.sprintf(_NUMIMAGES, '<b>'.$count.'</b>').') [<a href="admin.php?fct=images&amp;op=listimg&amp;imgcat_id='.$imagecategorys[$i]->getVar('imgcat_id').'">'._LIST.'</a>] [<a href="admin.php?fct=images&amp;op=editcat&amp;imgcat_id='.$imagecategorys[$i]->getVar('imgcat_id').'">'._EDIT.'</a>]';
  60              if ($imagecategorys[$i]->getVar('imgcat_type') == 'C') {
  61                  echo ' [<a href="admin.php?fct=images&amp;op=delcat&amp;imgcat_id='.$imagecategorys[$i]->getVar('imgcat_id').'">'._DELETE.'</a>]';
  62              }
  63              echo '</li>';
  64          }
  65          echo '</ul>';
  66          include_once  XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
  67          if (!empty($catcount)) {
  68              $form = new XoopsThemeForm(_ADDIMAGE, 'image_form', 'admin.php', 'post', true);
  69              $form->setExtra('enctype="multipart/form-data"');
  70              $form->addElement(new XoopsFormText(_IMAGENAME, 'image_nicename', 50, 255), true);
  71              $select = new XoopsFormSelect(_IMAGECAT, 'imgcat_id');
  72              $select->addOptionArray($imgcat_handler->getList());
  73              $form->addElement($select, true);
  74              $form->addElement(new XoopsFormFile(_IMAGEFILE, 'image_file', 5000000));
  75              $form->addElement(new XoopsFormText(_IMGWEIGHT, 'image_weight', 3, 4, 0));
  76              $form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'image_display', 1, _YES, _NO));
  77              $form->addElement(new XoopsFormHidden('op', 'addfile'));
  78              $form->addElement(new XoopsFormHidden('fct', 'images'));
  79              $form->addElement(new XoopsFormButton('', 'img_button', _SUBMIT, 'submit'));
  80              $form->display();
  81          }
  82          $form = new XoopsThemeForm(_MD_ADDIMGCAT, 'imagecat_form', 'admin.php', 'post', true);
  83          $form->addElement(new XoopsFormText(_MD_IMGCATNAME, 'imgcat_name', 50, 255), true);
  84          $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATRGRP, 'readgroup', true, XOOPS_GROUP_ADMIN, 5, true));
  85          $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATWGRP, 'writegroup', true, XOOPS_GROUP_ADMIN, 5, true));
  86          $form->addElement(new XoopsFormText(_IMGMAXSIZE, 'imgcat_maxsize', 10, 10, 50000));
  87          $form->addElement(new XoopsFormText(_IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, 120));
  88          $form->addElement(new XoopsFormText(_IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, 120));
  89          $form->addElement(new XoopsFormText(_MD_IMGCATWEIGHT, 'imgcat_weight', 3, 4, 0));
  90          $form->addElement(new XoopsFormRadioYN(_MD_IMGCATDISPLAY, 'imgcat_display', 1, _YES, _NO));
  91          $storetype = new XoopsFormRadio(_MD_IMGCATSTRTYPE.'<br /><span style="color:#ff0000;">'._MD_STRTYOPENG.'</span>', 'imgcat_storetype', 'file');
  92          $storetype->addOptionArray(array('file' => _MD_ASFILE, 'db' => _MD_INDB));
  93          $form->addElement($storetype);
  94          $form->addElement(new XoopsFormHidden('op', 'addcat'));
  95          $form->addElement(new XoopsFormHidden('fct', 'images'));
  96          $form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit'));
  97          $form->display();
  98          xoops_cp_footer();
  99          exit();
 100      }
 101  
 102      if ($op == 'listimg') {
 103          $imgcat_id = intval($imgcat_id);
 104          if ($imgcat_id <= 0) {
 105              redirect_header('admin.php?fct=images',1);
 106          }
 107          $imgcat_handler = xoops_gethandler('imagecategory');
 108          $imagecategory =& $imgcat_handler->get($imgcat_id);
 109          if (!is_object($imagecategory)) {
 110              redirect_header('admin.php?fct=images',1);
 111          }
 112          $image_handler = xoops_gethandler('image');
 113          xoops_cp_header();
 114          echo '<a href="admin.php?fct=images">'. _MD_IMGMAIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.$imagecategory->getVar('imgcat_name').'<br /><br />';
 115          $criteria = new Criteria('imgcat_id', $imgcat_id);
 116          $imgcount = $image_handler->getCount($criteria);
 117          $start = isset($_GET['start']) ? intval($_GET['start']) : 0;
 118          $criteria->setStart($start);
 119          $criteria->setLimit(20);
 120          $images =& $image_handler->getObjects($criteria, true, false);
 121          echo '<form action="admin.php" method="post">';
 122          foreach (array_keys($images) as $i) {
 123  
 124              echo '<table width="100%" class="outer"><tr><td width="30%" rowspan="6">';
 125              if ($imagecategory->getVar('imgcat_storetype') == 'db') {
 126                  echo '<img src="'.XOOPS_URL.'/image.php?id='.$i.'" alt="" />';
 127              } else {
 128                  echo '<img src="'.XOOPS_UPLOAD_URL.'/'.$images[$i]->getVar('image_name').'" alt="" />';
 129              }
 130              echo '</td><td class="head">'._IMAGENAME,'</td><td class="even"><input type="hidden" name="image_id[]" value="'.$i.'" /><input type="text" name="image_nicename[]" value="'.$images[$i]->getVar('image_nicename', 'E').'" size="20" maxlength="255" /></td></tr><tr><td class="head">'._IMAGEMIME.'</td><td class="odd">'.$images[$i]->getVar('image_mimetype').'</td></tr><tr><td class="head">'._IMAGECAT.'</td><td class="even"><select name="imgcat_id[]" size="1">';
 131              $list =& $imgcat_handler->getList(array(), null, null, $imagecategory->getVar('imgcat_storetype'));
 132              foreach ($list as $value => $name) {
 133                  $sel = '';
 134                  if ($value == $images[$i]->getVar('imgcat_id')) {
 135                      $sel = ' selected="selected"';
 136                  }
 137                  echo '<option value="'.$value.'"'.$sel.'>'.$name.'</option>';
 138              }
 139              echo '</select></td></tr><tr><td class="head">'._IMGWEIGHT.'</td><td class="odd"><input type="text" name="image_weight[]" value="'.$images[$i]->getVar('image_weight').'" size="3" maxlength="4" /></td></tr><tr><td class="head">'._IMGDISPLAY.'</td><td class="even"><input type="checkbox" name="image_display[]" value="1"';
 140              if ($images[$i]->getVar('image_display') == 1) {
 141                  echo ' checked="checked"';
 142              }
 143              echo ' /></td></tr><tr><td class="head">&nbsp;</td><td class="odd"><a href="admin.php?fct=images&amp;op=delfile&amp;image_id='.$i.'">'._DELETE.'</a></td></tr></table><br />';
 144          }
 145          if ($imgcount > 0) {
 146              if ($imgcount > 20) {
 147                  include_once  XOOPS_ROOT_PATH.'/class/pagenav.php';
 148                  $nav = new XoopsPageNav($imgcount, 20, $start, 'start', 'fct=images&amp;op=listimg&amp;imgcat_id='.$imgcat_id);
 149                  echo '<div text-align="right">'.$nav->renderNav().'</div>';
 150              }
 151              echo '<div style="text-align:center;"><input type="hidden" name="op" value="save" /><input type="hidden" name="fct" value="images" />'.$GLOBALS['xoopsSecurity']->getTokenHTML().'<input type="submit" name="submit" value="'._SUBMIT.'" /></div></form>';
 152          }
 153          xoops_cp_footer();
 154          exit();
 155      }
 156  
 157      if ($op == 'save') {
 158          if (!$GLOBALS['xoopsSecurity']->check()) {
 159              redirect_header('admin.php?fct=images', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
 160          }
 161          $count = count($image_id);
 162          if ($count > 0) {
 163              $image_handler =& xoops_gethandler('image');
 164              $error = array();
 165              for ($i = 0; $i < $count; $i++) {
 166                  $image =& $image_handler->get($image_id[$i]);
 167                  if (!is_object($image)) {
 168                      $error[] = sprintf(_FAILGETIMG, $image_id[$i]);
 169                      continue;
 170                  }
 171                  $image_display[$i] = empty($image_display[$i]) ? 0 : 1;
 172                  $image->setVar('image_display', $image_display[$i]);
 173                  $image->setVar('image_weight', $image_weight[$i]);
 174                  $image->setVar('image_nicename', $image_nicename[$i]);
 175                  $image->setVar('imgcat_id', $imgcat_id[$i]);
 176                  if (!$image_handler->insert($image)) {
 177                      $error[] = sprintf(_FAILSAVEIMG, $image_id[$i]);
 178                  }
 179              }
 180              if (count($error) > 0) {
 181                  xoops_cp_header();
 182                  foreach ($error as $err) {
 183                      echo $err.'<br />';
 184                  }
 185                  xoops_cp_footer();
 186                  exit();
 187              }
 188          }
 189          redirect_header('admin.php?fct=images',2,_MD_AM_DBUPDATED);
 190      }
 191  
 192      if ($op == 'addfile') {
 193          if (!$GLOBALS['xoopsSecurity']->check()) {
 194              redirect_header('admin.php?fct=images', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
 195          }
 196          $imgcat_handler =& xoops_gethandler('imagecategory');
 197          $imagecategory =& $imgcat_handler->get(intval($imgcat_id));
 198          if (!is_object($imagecategory)) {
 199              redirect_header('admin.php?fct=images',1);
 200          }
 201          include_once  XOOPS_ROOT_PATH.'/class/uploader.php';
 202          $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/bmp'), $imagecategory->getVar('imgcat_maxsize'), $imagecategory->getVar('imgcat_maxwidth'), $imagecategory->getVar('imgcat_maxheight'));
 203          $uploader->setPrefix('img');
 204          $err = array();
 205          $ucount = count($_POST['xoops_upload_file']);
 206          for ($i = 0; $i < $ucount; $i++) {
 207              if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) {
 208                  if (!$uploader->upload()) {
 209                      $err[] = $uploader->getErrors();
 210                  } else {
 211                      $image_handler =& xoops_gethandler('image');
 212                      $image =& $image_handler->create();
 213                      $image->setVar('image_name', $uploader->getSavedFileName());
 214                      $image->setVar('image_nicename', $image_nicename);
 215                      $image->setVar('image_mimetype', $uploader->getMediaType());
 216                      $image->setVar('image_created', time());
 217                      $image_display = empty($image_display) ? 0 : 1;
 218                      $image->setVar('image_display', $image_display);
 219                      $image->setVar('image_weight', $image_weight);
 220                      $image->setVar('imgcat_id', $imgcat_id);
 221                      if ($imagecategory->getVar('imgcat_storetype') == 'db') {
 222                          $fp = @fopen($uploader->getSavedDestination(), 'rb');
 223                          $fbinary = @fread($fp, filesize($uploader->getSavedDestination()));
 224                          @fclose($fp);
 225                          $image->setVar('image_body', $fbinary, true);
 226                          @unlink($uploader->getSavedDestination());
 227                      }
 228                      if (!$image_handler->insert($image)) {
 229                          $err[] = sprintf(_FAILSAVEIMG, $image->getVar('image_nicename'));
 230                      }
 231                  }
 232              } else {
 233                  $err[] = sprintf(_FAILFETCHIMG, $i);
 234                  $err = array_merge($err, $uploader->getErrors(false));
 235              }
 236          }
 237          if (count($err) > 0) {
 238              xoops_cp_header();
 239              xoops_error($err);
 240              xoops_cp_footer();
 241              exit();
 242          }
 243          redirect_header('admin.php?fct=images',2,_MD_AM_DBUPDATED);
 244      }
 245  
 246      if ($op == 'addcat') {
 247          if (!$GLOBALS['xoopsSecurity']->check()) {
 248              redirect_header('admin.php?fct=images', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
 249          }
 250          $imgcat_handler =& xoops_gethandler('imagecategory');
 251          $imagecategory =& $imgcat_handler->create();
 252          $imagecategory->setVar('imgcat_name', $imgcat_name);
 253          $imagecategory->setVar('imgcat_maxsize', $imgcat_maxsize);
 254          $imagecategory->setVar('imgcat_maxwidth', $imgcat_maxwidth);
 255          $imagecategory->setVar('imgcat_maxheight', $imgcat_maxheight);
 256          $imgcat_display = empty($imgcat_display) ? 0 : 1;
 257          $imagecategory->setVar('imgcat_display', $imgcat_display);
 258          $imagecategory->setVar('imgcat_weight', $imgcat_weight);
 259          $imagecategory->setVar('imgcat_storetype', $imgcat_storetype);
 260          $imagecategory->setVar('imgcat_type', 'C');
 261          if (!$imgcat_handler->insert($imagecategory)) {
 262              exit();
 263          }
 264          $newid = $imagecategory->getVar('imgcat_id');
 265          $imagecategoryperm_handler =& xoops_gethandler('groupperm');
 266          if (!isset($readgroup)) {
 267              $readgroup = array();
 268          }
 269          if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
 270              array_push($readgroup, XOOPS_GROUP_ADMIN);
 271          }
 272          foreach ($readgroup as $rgroup) {
 273              $imagecategoryperm =& $imagecategoryperm_handler->create();
 274              $imagecategoryperm->setVar('gperm_groupid', $rgroup);
 275              $imagecategoryperm->setVar('gperm_itemid', $newid);
 276              $imagecategoryperm->setVar('gperm_name', 'imgcat_read');
 277              $imagecategoryperm->setVar('gperm_modid', 1);
 278              $imagecategoryperm_handler->insert($imagecategoryperm);
 279              unset($imagecategoryperm);
 280          }
 281          if (!isset($writegroup)) {
 282              $writegroup = array();
 283          }
 284          if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
 285              array_push($writegroup, XOOPS_GROUP_ADMIN);
 286          }
 287          foreach ($writegroup as $wgroup) {
 288              $imagecategoryperm =& $imagecategoryperm_handler->create();
 289              $imagecategoryperm->setVar('gperm_groupid', $wgroup);
 290              $imagecategoryperm->setVar('gperm_itemid', $newid);
 291              $imagecategoryperm->setVar('gperm_name', 'imgcat_write');
 292              $imagecategoryperm->setVar('gperm_modid', 1);
 293              $imagecategoryperm_handler->insert($imagecategoryperm);
 294              unset($imagecategoryperm);
 295          }
 296          redirect_header('admin.php?fct=images',2,_MD_AM_DBUPDATED);
 297      }
 298  
 299      if ($op == 'editcat') {
 300          if ($imgcat_id <= 0) {
 301              redirect_header('admin.php?fct=images',1);
 302          }
 303          $imgcat_handler = xoops_gethandler('imagecategory');
 304          $imagecategory =& $imgcat_handler->get($imgcat_id);
 305          if (!is_object($imagecategory)) {
 306              redirect_header('admin.php?fct=images',1);
 307          }
 308          include_once  XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
 309          $imagecategoryperm_handler =& xoops_gethandler('groupperm');
 310          $form = new XoopsThemeForm(_MD_EDITIMGCAT, 'imagecat_form', 'admin.php', 'post', true);
 311          $form->addElement(new XoopsFormText(_MD_IMGCATNAME, 'imgcat_name', 50, 255, $imagecategory->getVar('imgcat_name')), true);
 312          $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATRGRP, 'readgroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_read', $imgcat_id), 5, true));
 313          $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATWGRP, 'writegroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_write', $imgcat_id), 5, true));
 314          $form->addElement(new XoopsFormText(_IMGMAXSIZE, 'imgcat_maxsize', 10, 10, $imagecategory->getVar('imgcat_maxsize')));
 315          $form->addElement(new XoopsFormText(_IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, $imagecategory->getVar('imgcat_maxwidth')));
 316          $form->addElement(new XoopsFormText(_IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, $imagecategory->getVar('imgcat_maxheight')));
 317          $form->addElement(new XoopsFormText(_MD_IMGCATWEIGHT, 'imgcat_weight', 3, 4, $imagecategory->getVar('imgcat_weight')));
 318          $form->addElement(new XoopsFormRadioYN(_MD_IMGCATDISPLAY, 'imgcat_display', $imagecategory->getVar('imgcat_display'), _YES, _NO));
 319          $storetype = array('db' => _MD_INDB, 'file' => _MD_ASFILE);
 320          $form->addElement(new XoopsFormLabel(_MD_IMGCATSTRTYPE, $storetype[$imagecategory->getVar('imgcat_storetype')]));
 321          $form->addElement(new XoopsFormHidden('imgcat_id', $imgcat_id));
 322          $form->addElement(new XoopsFormHidden('op', 'updatecat'));
 323          $form->addElement(new XoopsFormHidden('fct', 'images'));
 324          $form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit'));
 325          xoops_cp_header();
 326          echo '<a href="admin.php?fct=images">'. _MD_IMGMAIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.$imagecategory->getVar('imgcat_name').'<br /><br />';
 327          $form->display();
 328          xoops_cp_footer();
 329          exit();
 330      }
 331  
 332      if ($op == 'updatecat') {
 333          if (!$GLOBALS['xoopsSecurity']->check() || $imgcat_id <= 0) {
 334              redirect_header('admin.php?fct=images',1, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
 335          }
 336          $imgcat_handler = xoops_gethandler('imagecategory');
 337          $imagecategory =& $imgcat_handler->get($imgcat_id);
 338          if (!is_object($imagecategory)) {
 339              redirect_header('admin.php?fct=images',1);
 340          }
 341          $imagecategory->setVar('imgcat_name', $imgcat_name);
 342          $imgcat_display = empty($imgcat_display) ? 0 : 1;
 343          $imagecategory->setVar('imgcat_display', $imgcat_display);
 344          $imagecategory->setVar('imgcat_maxsize', $imgcat_maxsize);
 345          $imagecategory->setVar('imgcat_maxwidth', $imgcat_maxwidth);
 346          $imagecategory->setVar('imgcat_maxheight', $imgcat_maxheight);
 347          $imagecategory->setVar('imgcat_weight', $imgcat_weight);
 348          if (!$imgcat_handler->insert($imagecategory)) {
 349              exit();
 350          }
 351          $imagecategoryperm_handler =& xoops_gethandler('groupperm');
 352          $criteria = new CriteriaCompo(new Criteria('gperm_itemid', $imgcat_id));
 353          $criteria->add(new Criteria('gperm_modid', 1));
 354          $criteria2 = new CriteriaCompo(new Criteria('gperm_name', 'imgcat_write'));
 355          $criteria2->add(new Criteria('gperm_name', 'imgcat_read'), 'OR');
 356          $criteria->add($criteria2);
 357          $imagecategoryperm_handler->deleteAll($criteria);
 358          if (!isset($readgroup)) {
 359              $readgroup = array();
 360          }
 361          if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
 362              array_push($readgroup, XOOPS_GROUP_ADMIN);
 363          }
 364          foreach ($readgroup as $rgroup) {
 365              $imagecategoryperm =& $imagecategoryperm_handler->create();
 366              $imagecategoryperm->setVar('gperm_groupid', $rgroup);
 367              $imagecategoryperm->setVar('gperm_itemid', $imgcat_id);
 368              $imagecategoryperm->setVar('gperm_name', 'imgcat_read');
 369              $imagecategoryperm->setVar('gperm_modid', 1);
 370              $imagecategoryperm_handler->insert($imagecategoryperm);
 371              unset($imagecategoryperm);
 372          }
 373          if (!isset($writegroup)) {
 374              $writegroup = array();
 375          }
 376          if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
 377              array_push($writegroup, XOOPS_GROUP_ADMIN);
 378          }
 379          foreach ($writegroup as $wgroup) {
 380              $imagecategoryperm =& $imagecategoryperm_handler->create();
 381              $imagecategoryperm->setVar('gperm_groupid', $wgroup);
 382              $imagecategoryperm->setVar('gperm_itemid', $imgcat_id);
 383              $imagecategoryperm->setVar('gperm_name', 'imgcat_write');
 384              $imagecategoryperm->setVar('gperm_modid', 1);
 385              $imagecategoryperm_handler->insert($imagecategoryperm);
 386              unset($imagecategoryperm);
 387          }
 388          redirect_header('admin.php?fct=images',2,_MD_AM_DBUPDATED);
 389      }
 390  
 391      if ($op == 'delfile') {
 392          xoops_cp_header();
 393          xoops_confirm(array('op' => 'delfileok', 'image_id' => $image_id, 'fct' => 'images'), 'admin.php', _MD_RUDELIMG);
 394          xoops_cp_footer();
 395          exit();
 396      }
 397  
 398      if ($op == 'delfileok') {
 399          if (!$GLOBALS['xoopsSecurity']->check()) {
 400              redirect_header('admin.php?fct=images', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
 401          }
 402          $image_id = intval($image_id);
 403          if ($image_id <= 0) {
 404              redirect_header('admin.php?fct=images',1);
 405          }
 406          $image_handler =& xoops_gethandler('image');
 407          $image =& $image_handler->get($image_id);
 408          if (!is_object($image)) {
 409              redirect_header('admin.php?fct=images',1);
 410          }
 411          if (!$image_handler->delete($image)) {
 412              xoops_cp_header();
 413              xoops_error(sprintf(_MD_FAILDEL, $image->getVar('image_id')));
 414              xoops_cp_footer();
 415              exit();
 416          }
 417          @unlink(XOOPS_UPLOAD_PATH.'/'.$image->getVar('image_name'));
 418          redirect_header('admin.php?fct=images',2,_MD_AM_DBUPDATED);
 419      }
 420  
 421      if ($op == 'delcat') {
 422          xoops_cp_header();
 423          xoops_confirm(array('op' => 'delcatok', 'imgcat_id' => $imgcat_id, 'fct' => 'images'), 'admin.php', _MD_RUDELIMGCAT);
 424          xoops_cp_footer();
 425          exit();
 426      }
 427  
 428      if ($op == 'delcatok') {
 429          if (!$GLOBALS['xoopsSecurity']->check()) {
 430              redirect_header('admin.php?fct=images', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
 431          }
 432          $imgcat_id = intval($imgcat_id);
 433          if ($imgcat_id <= 0) {
 434              redirect_header('admin.php?fct=images',1);
 435          }
 436          $imgcat_handler = xoops_gethandler('imagecategory');
 437          $imagecategory =& $imgcat_handler->get($imgcat_id);
 438          if (!is_object($imagecategory)) {
 439              redirect_header('admin.php?fct=images',1);
 440          }
 441          if ($imagecategory->getVar('imgcat_type') != 'C') {
 442              xoops_cp_header();
 443              xoops_error(_MD_SCATDELNG);
 444              xoops_cp_footer();
 445              exit();
 446          }
 447          $image_handler =& xoops_gethandler('image');
 448          $images =& $image_handler->getObjects(new Criteria('imgcat_id', $imgcat_id), true, false);
 449          $errors = array();
 450          foreach (array_keys($images) as $i) {
 451              if (!$image_handler->delete($images[$i])) {
 452                  $errors[] = sprintf(_MD_FAILDEL, $i);
 453              } else {
 454                  if (file_exists(XOOPS_UPLOAD_PATH.'/'.$images[$i]->getVar('image_name')) && !unlink(XOOPS_UPLOAD_PATH.'/'.$images[$i]->getVar('image_name'))) {
 455                      $errors[] = sprintf(_MD_FAILUNLINK, $i);
 456                  }
 457              }
 458          }
 459          if (!$imgcat_handler->delete($imagecategory)) {
 460              $errors[] = sprintf(_MD_FAILDELCAT, $imagecategory->getVar('imgcat_name'));
 461          }
 462          if (count($errors) > 0) {
 463              xoops_cp_header();
 464              xoops_error($errors);
 465              xoops_cp_footer();
 466              exit();
 467          }
 468          redirect_header('admin.php?fct=images',2,_MD_AM_DBUPDATED);
 469      }
 470  }
 471  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics