[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  // $Id: blocksadmin.php 844 2007-07-04 14:08:48Z malanciault $

   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  }
  35  // check if the user is authorised

  36  if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
  37      include_once  XOOPS_ROOT_PATH.'/class/xoopsblock.php';
  38  
  39      function list_blocks()
  40      {
  41          global $xoopsUser, $xoopsConfig;
  42          include_once XOOPS_ROOT_PATH.'/class/xoopslists.php';
  43          //OpenTable();

  44          $selmod = isset($_GET['selmod']) ? intval($_GET['selmod']) : 0;
  45          $selvis = isset($_GET['selvis']) ? intval($_GET['selvis']) : 2;
  46          $selgrp = isset($_GET['selgrp']) ? intval($_GET['selgrp']) : XOOPS_GROUP_USERS;
  47          echo "
  48          <h4 style='text-align:left;'>"._AM_BADMIN."</h4>";
  49          echo '<form action="admin.php" method="get">';
  50          $form = "<select size=\"1\" name=\"selmod\" onchange=\"location='".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin&amp;selvis=$selvis&amp;selgrp=$selgrp&amp;selmod='+this.options[this.selectedIndex].value\">";
  51          $module_handler =& xoops_gethandler('module');
  52          $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
  53          $criteria->add(new Criteria('isactive', 1));
  54          $module_list =& $module_handler->getList($criteria);
  55          $toponlyblock = false;
  56          $module_list[-1] = _AM_TOPPAGE;
  57          $selmod = isset($_GET['selmod']) ? intval($_GET['selmod']) : -1;
  58          ksort($module_list);
  59          foreach ($module_list as $k => $v) {
  60              $sel = '';
  61              if ($k == $selmod) {
  62                  $sel = ' selected="selected"';
  63              }
  64              $form .= '<option value="'.$k.'"'.$sel.'>'.$v.'</option>';
  65          }
  66          $form .= '</select>&nbsp;<input type="hidden" name="fct" value="blocksadmin" />';
  67          printf(_AM_SVISIBLEIN, $form);
  68          $member_handler =& xoops_gethandler('member');
  69          $group_list =& $member_handler->getGroupList();
  70          $group_sel = _AM_GROUP." <select size=\"1\" name=\"selgrp\" onchange=\"location='".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin&amp;selvis=$selvis&amp;selmod=$selmod&amp;selgrp='+this.options[this.selectedIndex].value\">";
  71          $group_list[0] = '#'._AM_UNASSIGNED; // fix for displaying blocks unassigned to any group

  72          foreach ($group_list as $k => $v) {
  73              $sel = '';
  74              if ($k == $selgrp) {
  75                  $sel = ' selected="selected"';
  76              }
  77              $group_sel .= '<option value="'.$k.'"'.$sel.'>'.$v.'</option>';
  78          }
  79          $group_sel .= '</select> ';
  80          echo $group_sel;
  81          echo _AM_VISIBLE." <select size=\"1\" name=\"selvis\" onchange=\"location='".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin&amp;selmod=$selmod&amp;selgrp=$selgrp&amp;selvis='+this.options[this.selectedIndex].value\">";
  82          $selvis0 = $selvis1 = $selvis2 = "";
  83          switch($selvis){
  84          case 0:
  85              $selvis0 = 'selected="selected"';
  86              break;
  87          case 1:
  88              $selvis1 = 'selected="selected"';
  89              break;
  90          case 2:
  91          default:
  92              $selvis2 = 'selected="selected"';
  93              break;
  94          }
  95          echo '<option value="0" '.$selvis0.'>'._NO.'</option>';
  96          echo '<option value="1" '.$selvis1.'>'._YES.'</option>';
  97          echo '<option value="2" '.$selvis2.'>'._ALL.'</option>';
  98          echo '</select> <input type="submit" value="'._GO.'" name="selsubmit" />';
  99          echo '</form>';
 100          echo "<form action='admin.php' name='blockadmin' method='post'>
 101          <table width='100%' class='outer' cellpadding='4' cellspacing='1'>
 102          <tr valign='middle'><th width='20%'>"._AM_BLKDESC."</th><th>"._AM_TITLE."</th><th>"._AM_MODULE."</th><th align='center' nowrap='nowrap'>"._AM_SIDE."<br />"._LEFT."-"._CENTER."-"._RIGHT."</th><th align='center'>"._AM_WEIGHT."</th><th align='center'>"._AM_VISIBLE."</th><th align='right'>"._AM_ACTION."</th></tr>
 103          ";
 104          if ($selvis == 2) $selvis = null;
 105          if ($selgrp == 0) {
 106              // get blocks that are not assigned to any groups

 107              $block_arr =& XoopsBlock::getNonGroupedBlocks($selmod, $toponlyblock, $selvis, 'b.side,b.weight,b.bid');
 108          } else {
 109              $block_arr =& XoopsBlock::getAllByGroupModule($selgrp, $selmod, $toponlyblock, $selvis, 'b.side,b.weight,b.bid');
 110          }
 111          $block_count = count($block_arr);
 112          $class = 'even';
 113          $module_list2 =& $module_handler->getList();
 114          // for custom blocks

 115          $module_list2[0] = '&nbsp;';
 116          foreach (array_keys($block_arr) as $i) {
 117              $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = "";
 118              if ( $block_arr[$i]->getVar("visible") == 1 ) {
 119                  $sel1 = " checked='checked'";
 120              } else {
 121                  $sel0 = " checked='checked'";
 122              }
 123              if ( $block_arr[$i]->getVar("side") == XOOPS_SIDEBLOCK_LEFT){
 124                  $ssel0 = " checked='checked'";
 125              } elseif ( $block_arr[$i]->getVar("side") == XOOPS_SIDEBLOCK_RIGHT ){
 126                  $ssel1 = " checked='checked'";
 127              } elseif ( $block_arr[$i]->getVar("side") == XOOPS_CENTERBLOCK_LEFT ){
 128                  $ssel2 = " checked='checked'";
 129              } elseif ( $block_arr[$i]->getVar("side") == XOOPS_CENTERBLOCK_RIGHT ){
 130                  $ssel4 = " checked='checked'";
 131              } elseif ( $block_arr[$i]->getVar("side") == XOOPS_CENTERBLOCK_CENTER ){
 132                  $ssel3 = " checked='checked'";
 133              } elseif ( $block_arr[$i]->getVar("side") == XOOPS_CENTERBLOCK_BOTTOMLEFT ){
 134                  $ssel5 = " checked='checked'";
 135              } elseif ( $block_arr[$i]->getVar("side") == XOOPS_CENTERBLOCK_BOTTOMRIGHT ){
 136                  $ssel6 = " checked='checked'";
 137              } elseif ( $block_arr[$i]->getVar("side") == XOOPS_CENTERBLOCK_BOTTOM ){
 138                  $ssel7 = " checked='checked'";
 139              }
 140              if ( $block_arr[$i]->getVar("title") == "" ) {
 141                  $title = "&nbsp;";
 142              } else {
 143                  $title = $block_arr[$i]->getVar("title");
 144              }
 145              $name = $block_arr[$i]->getVar("name");
 146              //echo "<tr valign='top'><td class='$class'>".$name."</td><td class='$class'>".$title."</td><td class='$class'>".$module_list2[$block_arr[$i]->getVar('mid')]."</td><td class='$class' align='center' nowrap='nowrap'><input type='radio' name='side[$i]' value='".XOOPS_SIDEBLOCK_LEFT."'$ssel0 />-<input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_LEFT."'$ssel2 /><input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_CENTER."'$ssel3 /><input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_RIGHT."'$ssel4 />-<input type='radio' name='side[$i]' value='".XOOPS_SIDEBLOCK_RIGHT."'$ssel1 /></td><td class='$class' align='center'><input type='text' name='weight[$i]' value='".$block_arr[$i]->getVar("weight")."' size='5' maxlength='5' /></td><td class='$class' align='center' nowrap><input type='radio' name='visible[$i]' value='1'$sel1>"._YES."&nbsp;<input type='radio' name='visible[$i]' value='0'$sel0>"._NO."</td><td class='$class' align='right'><a href='admin.php?fct=blocksadmin&amp;op=edit&amp;bid=".$block_arr[$i]->getVar("bid")."'>"._EDIT."</a>";

 147              echo "<tr valign='top'><td class='$class'>".$name."</td><td class='$class'>".$title."</td><td class='$class'>".$module_list2[$block_arr[$i]->getVar('mid')]."</td><td class='$class' align='center' nowrap='nowrap'>
 148                      <div align='center' >
 149                      <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_LEFT."'$ssel2 />
 150                          <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_CENTER."'$ssel3 />
 151                      <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_RIGHT."'$ssel4 />
 152                      </div>
 153                      <div>
 154                          <span style='float:right'><input type='radio' name='side[$i]' value='".XOOPS_SIDEBLOCK_RIGHT."'$ssel1 /></span>
 155                      <div align='left'><input type='radio' name='side[$i]' value='".XOOPS_SIDEBLOCK_LEFT."'$ssel0 /></div>
 156                      </div>
 157                      <div align='center'>
 158                      <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_BOTTOMLEFT."'$ssel5 />
 159                          <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_BOTTOM."'$ssel7 />
 160                      <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_BOTTOMRIGHT."'$ssel6 />
 161                      </div>
 162                  </td><td class='$class' align='center'><input type='text' name='weight[$i]' value='".$block_arr[$i]->getVar("weight")."' size='5' maxlength='5' /></td><td class='$class' align='center' nowrap><input type='radio' name='visible[$i]' value='1'$sel1>"._YES."&nbsp;<input type='radio' name='visible[$i]' value='0'$sel0>"._NO."</td><td class='$class' align='right'><a href='admin.php?fct=blocksadmin&amp;op=edit&amp;bid=".$block_arr[$i]->getVar("bid")."'>"._EDIT."</a>";
 163              
 164              
 165              if ($block_arr[$i]->getVar('block_type') != 'S') {
 166                  echo "&nbsp;<a href='admin.php?fct=blocksadmin&amp;op=delete&amp;bid=".$block_arr[$i]->getVar("bid")."'>"._DELETE."</a>";
 167              }
 168              echo "
 169              <input type='hidden' name='oldside[$i]' value='".$block_arr[$i]->getVar('side')."' />
 170              <input type='hidden' name='oldweight[$i]' value='".$block_arr[$i]->getVar('weight')."' />
 171              <input type='hidden' name='oldvisible[$i]' value='".$block_arr[$i]->getVar('visible')."' />
 172              <input type='hidden' name='bid[$i]' value='".$i."' />
 173              </td></tr>
 174              ";
 175              $class = ($class == 'even') ? 'odd' : 'even';
 176          }
 177          echo "<tr><td class='foot' align='center' colspan='7'>
 178          <input type='hidden' name='fct' value='blocksadmin' />
 179          <input type='hidden' name='op' value='order' />
 180          ".$GLOBALS['xoopsSecurity']->getTokenHTML()."
 181          <input type='submit' name='submit' value='"._SUBMIT."' />
 182          </td></tr></table>
 183          </form>
 184          <br /><br />";
 185  
 186          $block = array('form_title' => _AM_ADDBLOCK, 'side' => 0, 'weight' => 0, 'visible' => 1, 'title' => '', 'content' => '', 'modules' => array(-1), 'is_custom' => true, 'ctype' => 'H', 'cachetime' => 0, 'op' => 'save', 'edit_form' => false);
 187          include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php';
 188          $form->display();
 189      }
 190  
 191      function save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bmodule, $bcachetime)
 192      {
 193          global $xoopsUser;
 194          if (empty($bmodule)) {
 195              xoops_cp_header();
 196              xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
 197              xoops_cp_footer();
 198              exit();
 199          }
 200          $myblock = new XoopsBlock();
 201          $myblock->setVar('side', $bside);
 202          $myblock->setVar('weight', $bweight);
 203          $myblock->setVar('visible', $bvisible);
 204          $myblock->setVar('weight', $bweight);
 205          $myblock->setVar('title', $btitle);
 206          $myblock->setVar('content', $bcontent);
 207          $myblock->setVar('c_type', $bctype);
 208          $myblock->setVar('block_type', 'C');
 209          $myblock->setVar('bcachetime', $bcachetime);
 210          switch ($bctype) {
 211          case 'H':
 212              $name = _AM_CUSTOMHTML;
 213              break;
 214          case 'P':
 215              $name = _AM_CUSTOMPHP;
 216              break;
 217          case 'S':
 218              $name = _AM_CUSTOMSMILE;
 219              break;
 220          default:
 221              $name = _AM_CUSTOMNOSMILE;
 222              break;
 223          }
 224          $myblock->setVar('name', $name);
 225          $newid = $myblock->store();
 226          if (!$newid) {
 227              xoops_cp_header();
 228              $myblock->getHtmlErrors();
 229              xoops_cp_footer();
 230              exit();
 231          }
 232          $db =& Database::getInstance();
 233          foreach ($bmodule as $bmid) {
 234              $sql = 'INSERT INTO '.$db->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newid.', '.intval($bmid).')';
 235              $db->query($sql);
 236          }
 237          $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
 238          $count = count($groups);
 239          for ($i = 0; $i < $count; $i++) {
 240              $sql = "INSERT INTO ".$db->prefix('group_permission')." (gperm_groupid, gperm_itemid, gperm_name, gperm_modid) VALUES (".$groups[$i].", ".$newid.", 'block_read', 1)";
 241              $db->query($sql);
 242          }
 243          redirect_header('admin.php?fct=blocksadmin&amp;t='.time(),1,_AM_DBUPDATED);
 244          exit();
 245      }
 246  
 247      function edit_block($bid)
 248      {
 249          $myblock = new XoopsBlock($bid);
 250          $db =& Database::getInstance();
 251          $sql = 'SELECT module_id FROM '.$db->prefix('block_module_link').' WHERE block_id='.intval($bid);
 252          $result = $db->query($sql);
 253          $modules = array();
 254          while ($row = $db->fetchArray($result)) {
 255              $modules[] = intval($row['module_id']);
 256          }
 257          $is_custom = ($myblock->getVar('block_type') == 'C' || $myblock->getVar('block_type') == 'E') ? true : false;
 258          $block = array('form_title' => _AM_EDITBLOCK, 'name' => $myblock->getVar('name'), 'side' => $myblock->getVar('side'), 'weight' => $myblock->getVar('weight'), 'visible' => $myblock->getVar('visible'), 'title' => $myblock->getVar('title', 'E'), 'content' => $myblock->getVar('content', 'E'), 'modules' => $modules, 'is_custom' => $is_custom, 'ctype' => $myblock->getVar('c_type'), 'cachetime' => $myblock->getVar('bcachetime'), 'op' => 'update', 'bid' => $myblock->getVar('bid'), 'edit_form' => $myblock->getOptions(), 'template' => $myblock->getVar('template'), 'options' => $myblock->getVar('options'));
 259          echo '<a href="admin.php?fct=blocksadmin">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'._AM_EDITBLOCK.'<br /><br />';
 260          include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php';
 261          $form->display();
 262      }
 263  
 264      function update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options=array())
 265      {
 266          global $xoopsConfig;
 267          if (empty($bmodule)) {
 268              xoops_cp_header();
 269              xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
 270              xoops_cp_footer();
 271              exit();
 272          }
 273          $myblock = new XoopsBlock($bid);
 274          $myblock->setVar('side', $bside);
 275          $myblock->setVar('weight', $bweight);
 276          $myblock->setVar('visible', $bvisible);
 277          $myblock->setVar('title', $btitle);
 278          $myblock->setVar('content', $bcontent);
 279          $myblock->setVar('bcachetime', $bcachetime);
 280          if (isset($options)) {
 281              $options_count = count($options);
 282              if ($options_count > 0) {
 283                  //Convert array values to comma-separated

 284                  for ( $i = 0; $i < $options_count; $i++ ) {
 285                      if (is_array($options[$i])) {
 286                          $options[$i] = implode(',', $options[$i]);
 287                      }
 288                  }
 289                  $options = implode('|', $options);
 290                  $myblock->setVar('options', $options);
 291              }
 292          }
 293          if ($myblock->getVar('block_type') == 'C') {
 294              switch ($bctype) {
 295              case 'H':
 296                  $name = _AM_CUSTOMHTML;
 297                  break;
 298              case 'P':
 299                  $name = _AM_CUSTOMPHP;
 300                  break;
 301              case 'S':
 302                  $name = _AM_CUSTOMSMILE;
 303                  break;
 304              default:
 305                  $name = _AM_CUSTOMNOSMILE;
 306                  break;
 307              }
 308              $myblock->setVar('name', $name);
 309              $myblock->setVar('c_type', $bctype);
 310          } else {
 311              $myblock->setVar('c_type', 'H');
 312          }
 313          $msg = _AM_DBUPDATED;
 314          if ($myblock->store() != false) {
 315              $db =& Database::getInstance();
 316              $sql = sprintf("DELETE FROM %s WHERE block_id = %u", $db->prefix('block_module_link'), $bid);
 317              $db->query($sql);
 318              foreach ($bmodule as $bmid) {
 319                  $sql = sprintf("INSERT INTO %s (block_id, module_id) VALUES (%u, %d)", $db->prefix('block_module_link'), $bid, intval($bmid));
 320                  $db->query($sql);
 321              }
 322              include_once  XOOPS_ROOT_PATH.'/class/template.php';
 323              $xoopsTpl = new XoopsTpl();
 324              $xoopsTpl->xoops_setCaching(2);
 325              if ($myblock->getVar('template') != '') {
 326                  if ($xoopsTpl->is_cached('db:'.$myblock->getVar('template'), 'blk_'.$myblock->getVar('bid'))) {
 327                      if (!$xoopsTpl->clear_cache('db:'.$myblock->getVar('template'), 'blk_'.$myblock->getVar('bid'))) {
 328                          $msg = 'Unable to clear cache for block ID '.$bid;
 329                      }
 330                  }
 331              } else {
 332                  if ($xoopsTpl->is_cached('db:system_dummy.html', 'blk_'.$bid)) {
 333                      if (!$xoopsTpl->clear_cache('db:system_dummy.html', 'blk_'.$bid)) {
 334                          $msg = 'Unable to clear cache for block ID '.$bid;
 335                      }
 336                  }
 337              }
 338          } else {
 339              $msg = 'Failed update of block. ID:'.$bid;
 340          }
 341          redirect_header('admin.php?fct=blocksadmin&amp;t='.time(),1,$msg);
 342          exit();
 343      }
 344  
 345      function delete_block($bid)
 346      {
 347          $myblock = new XoopsBlock($bid);
 348          if ( $myblock->getVar('block_type') == 'S' ) {
 349              $message = _AM_SYSTEMCANT;
 350              redirect_header('admin.php?fct=blocksadmin',4,$message);
 351              exit();
 352          } elseif ($myblock->getVar('block_type') == 'M') {
 353              // Fix for duplicated blocks created in 2.0.9 module update

 354              // A module block can be deleted if there is more than 1 that

 355              // has the same func_num/show_func which is mostly likely

 356              // be the one that was duplicated in 2.0.9

 357              if (1 >= $count = XoopsBlock::countSimilarBlocks($myblock->getVar('mid'), $myblock->getVar('func_num'), $myblock->getVar('show_func'))) {
 358                  $message = _AM_MODULECANT;
 359                  redirect_header('admin.php?fct=blocksadmin',4,$message);
 360                  exit();
 361              }
 362          }
 363          xoops_confirm(array('fct' => 'blocksadmin', 'op' => 'delete_ok', 'bid' => $myblock->getVar('bid')), 'admin.php', sprintf(_AM_RUSUREDEL,$myblock->getVar('title')));
 364      }
 365  
 366      function delete_block_ok($bid)
 367      {
 368          $myblock = new XoopsBlock($bid);
 369          $myblock->delete();
 370          if ($myblock->getVar('template') != '') {
 371              $tplfile_handler =& xoops_gethandler('tplfile');
 372              $btemplate =& $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
 373              if (count($btemplate) > 0) {
 374                  $tplfile_handler->delete($btemplate[0]);
 375              }
 376          }
 377          redirect_header('admin.php?fct=blocksadmin&amp;t='.time(),1,_AM_DBUPDATED);
 378          exit();
 379      }
 380  
 381      function order_block($bid, $weight, $visible, $side)
 382      {
 383          $myblock = new XoopsBlock($bid);
 384          $myblock->setVar('weight', $weight);
 385          $myblock->setVar('visible', $visible);
 386          $myblock->setVar('side', $side);
 387          $myblock->store();
 388      }
 389  
 390      function clone_block($bid)
 391      {
 392          global $xoopsConfig;
 393          xoops_cp_header();
 394          $myblock = new XoopsBlock($bid);
 395          $db =& Database::getInstance();
 396          $sql = 'SELECT module_id FROM '.$db->prefix('block_module_link').' WHERE block_id='.intval($bid);
 397          $result = $db->query($sql);
 398          $modules = array();
 399          while ($row = $db->fetchArray($result)) {
 400              $modules[] = intval($row['module_id']);
 401          }
 402          $is_custom = ($myblock->getVar('block_type') == 'C' || $myblock->getVar('block_type') == 'E') ? true : false;
 403          $block = array('form_title' => _AM_CLONEBLOCK, 'name' => $myblock->getVar('name'), 'side' => $myblock->getVar('side'), 'weight' => $myblock->getVar('weight'), 'visible' => $myblock->getVar('visible'), 'content' => $myblock->getVar('content', 'N'), 'modules' => $modules, 'is_custom' => $is_custom, 'ctype' => $myblock->getVar('c_type'), 'cachetime' => $myblock->getVar('bcachetime'), 'op' => 'clone_ok', 'bid' => $myblock->getVar('bid'), 'edit_form' => $myblock->getOptions(), 'template' => $myblock->getVar('template'), 'options' => $myblock->getVar('options'));
 404          echo '<a href="admin.php?fct=blocksadmin">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'._AM_CLONEBLOCK.'<br /><br />';
 405          include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php';
 406          $form->display();
 407          xoops_cp_footer();
 408          exit();
 409      }
 410  
 411      function clone_block_ok($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options)
 412      {
 413          global $xoopsUser;
 414          $block = new XoopsBlock($bid);
 415          $clone =& $block->xoopsClone();
 416          if (empty($bmodule)) {
 417              xoops_cp_header();
 418              xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
 419              xoops_cp_footer();
 420              exit();
 421          }
 422          $clone->setVar('side', $bside);
 423          $clone->setVar('weight', $bweight);
 424          $clone->setVar('visible', $bvisible);
 425          $clone->setVar('content', $bcontent);
 426          //$clone->setVar('title', $btitle);

 427          $clone->setVar('bcachetime', $bcachetime);
 428          if ( isset($options) && (count($options) > 0) ) {
 429              $options = implode('|', $options);
 430              $clone->setVar('options', $options);
 431          }
 432          $clone->setVar('bid', 0);
 433          if ($block->getVar('block_type') == 'C' || $block->getVar('block_type') == 'E') {
 434              $clone->setVar('block_type', 'E');
 435          } else {
 436              $clone->setVar('block_type', 'D');
 437          }
 438          $newid = $clone->store();
 439          if (!$newid) {
 440              xoops_cp_header();
 441              $clone->getHtmlErrors();
 442              xoops_cp_footer();
 443              exit();
 444          }
 445          if ($clone->getVar('template') != '') {
 446              $tplfile_handler =& xoops_gethandler('tplfile');
 447              $btemplate =& $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
 448              if (count($btemplate) > 0) {
 449                  $tplclone =& $btemplate[0]->xoopsClone();
 450                  $tplclone->setVar('tpl_id', 0);
 451                  $tplclone->setVar('tpl_refid', $newid);
 452                  $tplman->insert($tplclone);
 453              }
 454          }
 455          $db =& Database::getInstance();
 456          foreach ($bmodule as $bmid) {
 457              $sql = 'INSERT INTO '.$db->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newid.', '.$bmid.')';
 458              $db->query($sql);
 459          }
 460          $groups =& $xoopsUser->getGroups();
 461          $count = count($groups);
 462          for ($i = 0; $i < $count; $i++) {
 463              $sql = "INSERT INTO ".$db->prefix('group_permission')." (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (".$groups[$i].", ".$newid.", 1, 'block_read')";
 464              $db->query($sql);
 465          }
 466          redirect_header('admin.php?fct=blocksadmin&amp;t='.time(),1,_AM_DBUPDATED);
 467      }
 468  } else {
 469      echo "Access Denied";
 470  }
 471  ?>


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