[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  // $Id: main.php 912 2007-08-03 01:11:22Z dugris $

   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  include_once  XOOPS_ROOT_PATH.'/class/xoopsblock.php';
  36  include_once XOOPS_ROOT_PATH."/modules/system/admin/modulesadmin/modulesadmin.php";
  37  $op = "list";
  38  if ( isset($_POST) ) {
  39      foreach ( $_POST as $k => $v ) {
  40          ${$k} = $v;
  41      }
  42  }
  43  
  44  if (isset($_GET['op'])) {
  45      $op = $_GET['op'];
  46      $module = $_GET['module'];
  47  }
  48  
  49  if (in_array($op, array('submit', 'install_ok', 'update_ok', 'uninstall_ok'))) {
  50      if (!$GLOBALS['xoopsSecurity']->check()) {
  51          $op = 'list';
  52      }
  53  }
  54  
  55  if ( $op == "list" ) {
  56      xoops_module_list();
  57      exit();
  58  }
  59  
  60  if ( $op == "confirm" ) {
  61      xoops_cp_header();
  62      //OpenTable();

  63      $error = array();
  64      if ( !is_writable(XOOPS_CACHE_PATH.'/') ) {
  65          // attempt to chmod 666

  66          if ( !chmod(XOOPS_CACHE_PATH.'/', 0777) ) {
  67              $error[] = sprintf(_MUSTWABLE, "<b>".XOOPS_CACHE_PATH.'/</b>');
  68          }
  69      }
  70      if ( count($error) > 0 ) {
  71          xoops_error($error);
  72          echo "<p><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a></p>";
  73          xoops_cp_footer();
  74          exit();
  75      }
  76      echo "<h4 style='text-align:left;'>"._MD_AM_PCMFM."</h4>
  77      <form action='admin.php' method='post'>
  78      <input type='hidden' name='fct' value='modulesadmin' />
  79      <input type='hidden' name='op' value='submit' />
  80      <table width='100%' border='0' cellspacing='1' class='outer'>
  81      <tr align='center'><th>"._MD_AM_MODULE."</th><th>"._MD_AM_ACTION."</th><th>"._MD_AM_ORDER."</th></tr>";
  82      $mcount = 0;
  83      $myts =& MyTextsanitizer::getInstance();
  84      foreach ($module as $mid) {
  85          if ($mcount % 2 != 0) {
  86              $class = 'odd';
  87          } else {
  88              $class = 'even';
  89          }
  90          echo '<tr class="'.$class.'"><td align="center">'.$myts->stripSlashesGPC($oldname[$mid]);
  91          $newname[$mid] = trim($myts->stripslashesGPC($newname[$mid]));
  92          if ($newname[$mid] != $oldname[$mid]) {
  93              echo '&nbsp;&raquo;&raquo;&nbsp;<span style="color:#ff0000;font-weight:bold;">'.$newname[$mid].'</span>';
  94          }
  95          echo '</td><td align="center">';
  96          if (isset($newstatus[$mid]) && $newstatus[$mid] ==1) {
  97              if ($oldstatus[$mid] == 0) {
  98                  echo "<span style='color:#ff0000;font-weight:bold;'>"._MD_AM_ACTIVATE."</span>";
  99              } else {
 100                  echo _MD_AM_NOCHANGE;
 101              }
 102          } else {
 103              $newstatus[$mid] = 0;
 104              if ($oldstatus[$mid] == 1) {
 105                  echo "<span style='color:#ff0000;font-weight:bold;'>"._MD_AM_DEACTIVATE."</span>";
 106              } else {
 107                  echo _MD_AM_NOCHANGE;
 108              }
 109          }
 110          echo "</td><td align='center'>";
 111          if ($oldweight[$mid] != $weight[$mid]) {
 112              echo "<span style='color:#ff0000;font-weight:bold;'>".$weight[$mid]."</span>";
 113          } else {
 114              echo $weight[$mid];
 115          }
 116          echo "
 117          <input type='hidden' name='module[]' value='".$mid."' />
 118          <input type='hidden' name='oldname[".$mid."]' value='".htmlspecialchars($oldname[$mid], ENT_QUOTES)."' />
 119          <input type='hidden' name='newname[".$mid."]' value='".htmlspecialchars($newname[$mid], ENT_QUOTES)."' />
 120          <input type='hidden' name='oldstatus[".$mid."]' value='".$oldstatus[$mid]."' />
 121          <input type='hidden' name='newstatus[".$mid."]' value='".$newstatus[$mid]."' />
 122          <input type='hidden' name='oldweight[".$mid."]' value='".intval($oldweight[$mid])."' />
 123          <input type='hidden' name='weight[".$mid."]' value='".intval($weight[$mid])."' />
 124          </td></tr>";
 125      }
 126      echo "
 127      <tr class='foot' align='center'><td colspan='3'><input type='submit' value='"._MD_AM_SUBMIT."' />&nbsp;<input type='button' value='"._MD_AM_CANCEL."' onclick='location=\"admin.php?fct=modulesadmin\"' />".$GLOBALS['xoopsSecurity']->getTokenHTML()."</td></tr>
 128      </table>
 129      </form>";
 130      xoops_cp_footer();
 131      exit();
 132  }
 133  if ( $op == "submit" ) {
 134      $ret = array();
 135      $write = false;
 136      foreach ($module as $mid) {
 137          if (isset($newstatus[$mid]) && $newstatus[$mid] ==1) {
 138              if ($oldstatus[$mid] == 0) {
 139                  $ret[] = xoops_module_activate($mid);
 140              }
 141          } else {
 142              if ($oldstatus[$mid] == 1) {
 143                  $ret[] = xoops_module_deactivate($mid);
 144              }
 145          }
 146          $newname[$mid] = trim($newname[$mid]);
 147          if ($oldname[$mid] != $newname[$mid] || $oldweight[$mid] != $weight[$mid]) {
 148              $ret[] = xoops_module_change($mid, $weight[$mid], $newname[$mid]);
 149              $write = true;
 150          }
 151          flush();
 152      }
 153      if ( $write ) {
 154          $contents = xoops_module_get_admin_menu();
 155          if (!xoops_module_write_admin_menu($contents)) {
 156              $ret[] = "<p>"._MD_AM_FAILWRITE."</p>";
 157          }
 158      }
 159      xoops_cp_header();
 160      if ( count($ret) > 0 ) {
 161          foreach ($ret as $msg) {
 162              if ($msg != '') {
 163                  echo $msg;
 164              }
 165          }
 166      }
 167      echo "<br /><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a>";
 168      xoops_cp_footer();
 169      exit();
 170  }
 171  
 172  if ($op == 'install') {
 173      $module_handler =& xoops_gethandler('module');
 174      $mod =& $module_handler->create();
 175      $mod->loadInfoAsVar($module);
 176      if ($mod->getInfo('image') != false && trim($mod->getInfo('image')) != '') {
 177          $msgs ='<img src="'.XOOPS_URL.'/modules/'.$mod->getVar('dirname').'/'.trim($mod->getInfo('image')).'" alt="" />';
 178      }
 179      $msgs .= '<br /><span style="font-size:smaller;";>'.$mod->getVar('name').'</span><br /><br />'._MD_AM_RUSUREINS;
 180      xoops_cp_header();
 181      xoops_confirm(array('module' => $module, 'op' => 'install_ok', 'fct' => 'modulesadmin'), 'admin.php', $msgs, _MD_AM_INSTALL);
 182      xoops_cp_footer();
 183      exit();
 184  }
 185  
 186  if ($op == 'install_ok') {
 187      $ret = array();
 188      $ret[] = xoops_module_install($module);
 189      $contents = xoops_module_get_admin_menu();
 190      if (!xoops_module_write_admin_menu($contents)) {
 191          $ret[] = "<p>"._MD_AM_FAILWRITE."</p>";
 192      }
 193      xoops_cp_header();
 194      if (count($ret) > 0) {
 195          foreach ($ret as $msg) {
 196              if ($msg != '') {
 197                  echo $msg;
 198              }
 199          }
 200      }
 201      echo "<br /><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a>";
 202      xoops_cp_footer();
 203      exit();
 204  }
 205  
 206  if ($op == 'uninstall') {
 207      $module_handler =& xoops_gethandler('module');
 208      $mod =& $module_handler->getByDirname($module);
 209      if ($mod->getInfo('image') != false && trim($mod->getInfo('image')) != '') {
 210          $msgs ='<img src="'.XOOPS_URL.'/modules/'.$mod->getVar('dirname').'/'.trim($mod->getInfo('image')).'" alt="" />';
 211      }
 212      $msgs .= '<br /><span style="font-size:smaller;";>'.$mod->getVar('name').'</span><br /><br />'._MD_AM_RUSUREUNINS;
 213      xoops_cp_header();
 214      xoops_confirm(array('module' => $module, 'op' => 'uninstall_ok', 'fct' => 'modulesadmin'), 'admin.php', $msgs, _YES);
 215      xoops_cp_footer();
 216      exit();
 217  }
 218  
 219  if ($op == 'uninstall_ok') {
 220      $ret = array();
 221      $ret[] = xoops_module_uninstall($module);
 222      $contents = xoops_module_get_admin_menu();
 223      if (!xoops_module_write_admin_menu($contents)) {
 224          $ret[] = "<p>"._MD_AM_FAILWRITE."</p>";
 225      }
 226      xoops_cp_header();
 227      if (count($ret) > 0) {
 228          foreach ($ret as $msg) {
 229              if ($msg != '') {
 230                  echo $msg;
 231              }
 232          }
 233      }
 234      echo "<a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a>";
 235      xoops_cp_footer();
 236      exit();
 237  }
 238  
 239  if ($op == 'update') {
 240      $module_handler =& xoops_gethandler('module');
 241      $mod =& $module_handler->getByDirname($module);
 242      if ($mod->getInfo('image') != false && trim($mod->getInfo('image')) != '') {
 243          $msgs ='<img src="'.XOOPS_URL.'/modules/'.$mod->getVar('dirname').'/'.trim($mod->getInfo('image')).'" alt="" />';
 244      }
 245      $msgs .= '<br /><span style="font-size:smaller;";>'.$mod->getVar('name').'</span><br /><br />'._MD_AM_RUSUREUPD;
 246      xoops_cp_header();
 247      xoops_confirm(array('dirname' => $module, 'op' => 'update_ok', 'fct' => 'modulesadmin'), 'admin.php', $msgs, _MD_AM_UPDATE);
 248      xoops_cp_footer();
 249      exit();
 250  }
 251  
 252  if ($op == 'update_ok') {
 253      $dirname = trim($dirname);
 254      $module_handler =& xoops_gethandler('module');
 255      $module =& $module_handler->getByDirname($dirname);
 256      // Save current version for use in the update function

 257      $prev_version = $module->getVar('version');
 258      include_once  XOOPS_ROOT_PATH.'/class/template.php';
 259      xoops_template_clear_module_cache($module->getVar('mid'));
 260      // we dont want to change the module name set by admin

 261      $temp_name = $module->getVar('name');
 262      $module->loadInfoAsVar($dirname);
 263      $module->setVar('name', $temp_name);
 264      xoops_cp_header();
 265      if (!$module_handler->insert($module)) {
 266          echo '<p>Could not update '.$module->getVar('name').'</p>';
 267          echo "<br /><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a>";
 268      } else {
 269          $newmid = $module->getVar('mid');
 270          $msgs = array();
 271          $msgs[] = 'Module data updated.';
 272          $tplfile_handler =& xoops_gethandler('tplfile');
 273          $deltpl =& $tplfile_handler->find('default', 'module', $module->getVar('mid'));
 274          $delng = array();
 275          if (is_array($deltpl)) {
 276              $xoopsTpl = new XoopsTpl();
 277              // clear cache files

 278              $xoopsTpl->clear_cache(null, 'mod_'.$dirname);
 279              // delete template file entry in db

 280              $dcount = count($deltpl);
 281              for ($i = 0; $i < $dcount; $i++) {
 282                  if (!$tplfile_handler->delete($deltpl[$i])) {
 283                      $delng[] = $deltpl[$i]->getVar('tpl_file');
 284                  }
 285              }
 286          }
 287          $templates = $module->getInfo('templates');
 288          if ($templates != false) {
 289              $msgs[] = 'Updating templates...';
 290              foreach ($templates as $tpl) {
 291                  $tpl['file'] = trim($tpl['file']);
 292                  if (!in_array($tpl['file'], $delng)) {
 293                      $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']);
 294                      $tplfile =& $tplfile_handler->create();
 295                      $tplfile->setVar('tpl_refid', $newmid);
 296                      $tplfile->setVar('tpl_lastimported', 0);
 297                      $tplfile->setVar('tpl_lastmodified', time());
 298                      if (preg_match("/\.css$/i", $tpl['file'])) {
 299                          $tplfile->setVar('tpl_type', 'css');
 300                      } else {
 301                          $tplfile->setVar('tpl_type', 'module');
 302                      }
 303                      $tplfile->setVar('tpl_source', $tpldata, true);
 304                      $tplfile->setVar('tpl_module', $dirname);
 305                      $tplfile->setVar('tpl_tplset', 'default');
 306                      $tplfile->setVar('tpl_file', $tpl['file'], true);
 307                      $tplfile->setVar('tpl_desc', $tpl['description'], true);
 308                      if (!$tplfile_handler->insert($tplfile)) {
 309                          $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>'.$tpl['file'].'</b> to the database.</span>';
 310                      } else {
 311                          $newid = $tplfile->getVar('tpl_id');
 312                          $msgs[] = '&nbsp;&nbsp;Template <b>'.$tpl['file'].'</b> inserted to the database.';
 313                          if ($xoopsConfig['template_set'] == 'default') {
 314                              if (!xoops_template_touch($newid)) {
 315                                  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not recompile template <b>'.$tpl['file'].'</b>.</span>';
 316                              } else {
 317                                  $msgs[] = '&nbsp;&nbsp;Template <b>'.$tpl['file'].'</b> recompiled.</span>';
 318                              }
 319                          }
 320                      }
 321                      unset($tpldata);
 322                  } else {
 323                      $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete old template <b>'.$tpl['file'].'</b>. Aborting update of this file.</span>';
 324                  }
 325              }
 326          }
 327          $contents = xoops_module_get_admin_menu();
 328          if (!xoops_module_write_admin_menu($contents)) {
 329              $msgs[] = '<p><span style="color:#ff0000;">'._MD_AM_FAILWRITE.'</span></p>';
 330          }
 331          $blocks = $module->getInfo('blocks');
 332          $msgs[] = 'Rebuilding blocks...';
 333          if ($blocks != false) {
 334              $showfuncs = array();
 335              $funcfiles = array();
 336                  foreach ($blocks as $i => $block) {
 337                  if (isset($block['show_func']) && $block['show_func'] != '' && isset($block['file']) && $block['file'] != '') {
 338                      $editfunc = isset($block['edit_func']) ? $block['edit_func'] : '';
 339                      $showfuncs[] = $block['show_func'];
 340                      $funcfiles[] = $block['file'];
 341                      $template = '';
 342                      if ((isset($block['template']) && trim($block['template']) != '')) {
 343                          $content =& xoops_module_gettemplate($dirname, $block['template'], true);
 344                      }
 345                      if (!$content) {
 346                          $content = '';
 347                      } else {
 348                          $template = $block['template'];
 349                      }
 350                      $options = '';
 351                      if (!empty($block['options'])) {
 352                          $options = $block['options'];
 353                      }
 354                      $sql = "SELECT bid, name FROM ".$xoopsDB->prefix('newblocks')." WHERE mid=".$module->getVar('mid')." AND func_num=".$i." AND show_func='".addslashes($block['show_func'])."' AND func_file='".addslashes($block['file'])."'";
 355                      $fresult = $xoopsDB->query($sql);
 356                      $fcount = 0;
 357                      while ($fblock = $xoopsDB->fetchArray($fresult)) {
 358                          $fcount++;
 359                          $sql = "UPDATE ".$xoopsDB->prefix("newblocks")." SET name='".addslashes($block['name'])."', edit_func='".addslashes($editfunc)."', content='', template='".$template."', last_modified=".time()." WHERE bid=".$fblock['bid'];
 360                          $result = $xoopsDB->query($sql);
 361                          if (!$result) {
 362                              $msgs[] = '&nbsp;&nbsp;ERROR: Could not update '.$fblock['name'];
 363                          } else {
 364                              $msgs[] = '&nbsp;&nbsp;Block <b>'.$fblock['name'].'</b> updated. Block ID: <b>'.$fblock['bid'].'</b>';
 365                              if ($template != '') {
 366                                  $tplfile =& $tplfile_handler->find('default', 'block', $fblock['bid']);
 367                                  if (count($tplfile) == 0) {
 368                                      $tplfile_new =& $tplfile_handler->create();
 369                                      $tplfile_new->setVar('tpl_module', $dirname);
 370                                      $tplfile_new->setVar('tpl_refid', $fblock['bid']);
 371                                      $tplfile_new->setVar('tpl_tplset', 'default');
 372                                      $tplfile_new->setVar('tpl_file', $block['template'], true);
 373                                      $tplfile_new->setVar('tpl_type', 'block');
 374                                  }
 375                                  else {
 376                                      $tplfile_new = $tplfile[0];
 377                                  }
 378                                  $tplfile_new->setVar('tpl_source', $content, true);
 379                                  $tplfile_new->setVar('tpl_desc', $block['description'], true);
 380                                  $tplfile_new->setVar('tpl_lastmodified', time());
 381                                  $tplfile_new->setVar('tpl_lastimported', 0);
 382                                  if (!$tplfile_handler->insert($tplfile_new)) {
 383                                      $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not update template <b>'.$block['template'].'</b>.</span>';
 384                                  } else {
 385                                      $msgs[] = '&nbsp;&nbsp;Template <b>'.$block['template'].'</b> updated.';
 386                                      if ($xoopsConfig['template_set'] == 'default') {
 387                                          if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) {
 388                                              $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not recompile template <b>'.$block['template'].'</b>.</span>';
 389                                          } else {
 390                                              $msgs[] = '&nbsp;&nbsp;Template <b>'.$block['template'].'</b> recompiled.';
 391                                          }
 392                                      }
 393  
 394                                  }
 395                              }
 396                          }
 397                      }
 398                      if ($fcount == 0) {
 399                          $newbid = $xoopsDB->genId($xoopsDB->prefix('newblocks').'_bid_seq');
 400                          $block_name = addslashes($block['name']);
 401                          $sql = "INSERT INTO ".$xoopsDB->prefix("newblocks")." (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, isactive, dirname, func_file, show_func, edit_func, template, last_modified) VALUES (".$newbid.", ".$module->getVar('mid').", ".$i.",'".addslashes($options)."','".$block_name."', '".$block_name."', '', 0, 0, 0, 'M', 1, '".addslashes($dirname)."', '".addslashes($block['file'])."', '".addslashes($block['show_func'])."', '".addslashes($editfunc)."', '".$template."', ".time().")";
 402                          $result = $xoopsDB->query($sql);
 403                          if (!$result) {
 404                              $msgs[] = '&nbsp;&nbsp;ERROR: Could not create '.$block['name'];echo $sql;
 405                          } else {
 406                              if (empty($newbid)) {
 407                                  $newbid = $xoopsDB->getInsertId();
 408                              }
 409                              if ($module->getInfo('hasMain')) {
 410                                  $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
 411                              } else {
 412                                  $groups = array(XOOPS_GROUP_ADMIN);
 413                              }
 414                              $gperm_handler =& xoops_gethandler('groupperm');
 415                              foreach ($groups as $mygroup) {
 416                                  $bperm =& $gperm_handler->create();
 417                                  $bperm->setVar('gperm_groupid', $mygroup);
 418                                  $bperm->setVar('gperm_itemid', $newbid);
 419                                  $bperm->setVar('gperm_name', 'block_read');
 420                                  $bperm->setVar('gperm_modid', 1);
 421                                  if (!$gperm_handler->insert($bperm)) {
 422                                      $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add block access right. Block ID: <b>'.$newbid.'</b> Group ID: <b>'.$mygroup.'</b></span>';
 423                                  } else {
 424                                      $msgs[] = '&nbsp;&nbsp;Added block access right. Block ID: <b>'.$newbid.'</b> Group ID: <b>'.$mygroup.'</b>';
 425                                  }
 426                              }
 427  
 428                              if ($template != '') {
 429                                  $tplfile =& $tplfile_handler->create();
 430                                  $tplfile->setVar('tpl_module', $dirname);
 431                                  $tplfile->setVar('tpl_refid', $newbid);
 432                                  $tplfile->setVar('tpl_source', $content, true);
 433                                  $tplfile->setVar('tpl_tplset', 'default');
 434                                  $tplfile->setVar('tpl_file', $block['template'], true);
 435                                  $tplfile->setVar('tpl_type', 'block');
 436                                  $tplfile->setVar('tpl_lastimported', 0);
 437                                  $tplfile->setVar('tpl_lastmodified', time());
 438                                  $tplfile->setVar('tpl_desc', $block['description'], true);
 439                                  if (!$tplfile_handler->insert($tplfile)) {
 440                                      $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>'.$block['template'].'</b> to the database.</span>';
 441                                  } else {
 442                                      $newid = $tplfile->getVar('tpl_id');
 443                                      $msgs[] = '&nbsp;&nbsp;Template <b>'.$block['template'].'</b> added to the database.';
 444                                      if ($xoopsConfig['template_set'] == 'default') {
 445                                          if (!xoops_template_touch($newid)) {
 446                                              $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Template <b>'.$block['template'].'</b> recompile failed.</span>';
 447                                          } else {
 448                                              $msgs[] = '&nbsp;&nbsp;Template <b>'.$block['template'].'</b> recompiled.';
 449                                          }
 450                                      }
 451                                  }
 452                              }
 453                              $msgs[] = '&nbsp;&nbsp;Block <b>'.$block['name'].'</b> created. Block ID: <b>'.$newbid.'</b>';
 454                              $sql = 'INSERT INTO '.$xoopsDB->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newbid.', -1)';
 455                              $xoopsDB->query($sql);
 456                          }
 457                      }
 458                  }
 459              }
 460              $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
 461              foreach ($block_arr as $block) {
 462                  if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) {
 463                      $sql = sprintf("DELETE FROM %s WHERE bid = %u", $xoopsDB->prefix('newblocks'), $block->getVar('bid'));
 464                      if(!$xoopsDB->query($sql)) {
 465                          $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete block <b>'.$block->getVar('name').'</b>. Block ID: <b>'.$block->getVar('bid').'</b></span>';
 466                      } else {
 467                          $msgs[] = '&nbsp;&nbsp;Block <b>'.$block->getVar('name').' deleted. Block ID: <b>'.$block->getVar('bid').'</b>';
 468                          if ($block->getVar('template') != '') {
 469                              $tplfiles =& $tplfile_handler->find(null, 'block', $block->getVar('bid'));
 470                              if (is_array($tplfiles)) {
 471                                  $btcount = count($tplfiles);
 472                                  for ($k = 0; $k < $btcount; $k++) {
 473                                      if (!$tplfile_handler->delete($tplfiles[$k])) {
 474                                          $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not remove deprecated block template. (ID: <b>'.$tplfiles[$k]->getVar('tpl_id').'</b>)</span>';
 475                                      } else {
 476                                          $msgs[] = '&nbsp;&nbsp;Block template <b>'.$tplfiles[$k]->getVar('tpl_file').'</b> deprecated.';
 477                                      }
 478                                  }
 479                              }
 480                          }
 481                      }
 482                  }
 483              }
 484          }
 485  
 486          // first delete all config entries

 487          $config_handler =& xoops_gethandler('config');
 488          $configs =& $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
 489          $confcount = count($configs);
 490          $config_delng = array();
 491          if ($confcount > 0) {
 492              $msgs[] = 'Deleting module config options...';
 493              for ($i = 0; $i < $confcount; $i++) {
 494                  if (!$config_handler->deleteConfig($configs[$i])) {
 495                      $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete config data from the database. Config ID: <b>'.$configs[$i]->getvar('conf_id').'</b></span>';
 496                      // save the name of config failed to delete for later use

 497                      $config_delng[] = $configs[$i]->getvar('conf_name');
 498                  } else {
 499                      $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N');
 500                      $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype');
 501                      $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
 502                      $msgs[] = '&nbsp;&nbsp;Config data deleted from the database. Config ID: <b>'.$configs[$i]->getVar('conf_id').'</b>';
 503                  }
 504              }
 505          }
 506  
 507          // now reinsert them with the new settings

 508          $configs = $module->getInfo('config');
 509          if ($configs != false) {
 510              if ($module->getVar('hascomments') != 0) {
 511                  include_once(XOOPS_ROOT_PATH.'/include/comment_constants.php');
 512                  array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)));
 513                  array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0));
 514              }
 515          } else {
 516              if ($module->getVar('hascomments') != 0) {
 517                  $configs = array();
 518                  include_once(XOOPS_ROOT_PATH.'/include/comment_constants.php');
 519                  $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN));
 520                  $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0);
 521              }
 522          }
 523          // RMV-NOTIFY

 524          if ($module->getVar('hasnotification') != 0) {
 525              if (empty($configs)) {
 526                  $configs = array();
 527              }
 528              // Main notification options

 529              include_once  XOOPS_ROOT_PATH . '/include/notification_constants.php';
 530              include_once  XOOPS_ROOT_PATH . '/include/notification_functions.php';
 531              $options = array();
 532              $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
 533              $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
 534              $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
 535              $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
 536  
 537              //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);

 538              $configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options'=>$options);
 539              // Event specific notification options

 540              // FIXME: for some reason the default doesn't come up properly

 541              //  initially is ok, but not when 'update' module..

 542              $options = array();
 543              $categories =& notificationCategoryInfo('',$module->getVar('mid'));
 544              foreach ($categories as $category) {
 545                  $events =& notificationEvents ($category['name'], false, $module->getVar('mid'));
 546                  foreach ($events as $event) {
 547                      if (!empty($event['invisible'])) {
 548                          continue;
 549                      }
 550                      $option_name = $category['title'] . ' : ' . $event['title'];
 551                      $option_value = $category['name'] . '-' . $event['name'];
 552                      $options[$option_name] = $option_value;
 553                      //$configs[] = array ('name' => notificationGenerateConfig($category,$event,'name'), 'title' => notificationGenerateConfig($category,$event,'title_constant'), 'description' => notificationGenerateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);

 554                  }
 555              }
 556              $configs[] = array ('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options);
 557          }
 558  
 559          if ($configs != false) {
 560              $msgs[] = 'Adding module config data...';
 561              $config_handler =& xoops_gethandler('config');
 562              $order = 0;
 563              foreach ($configs as $config) {
 564                  // only insert ones that have been deleted previously with success

 565                  if (!in_array($config['name'], $config_delng)) {
 566                      $confobj =& $config_handler->createConfig();
 567                      $confobj->setVar('conf_modid', $newmid);
 568                      $confobj->setVar('conf_catid', 0);
 569                      $confobj->setVar('conf_name', $config['name']);
 570                      $confobj->setVar('conf_title', $config['title'], true);
 571                      $confobj->setVar('conf_desc', $config['description'], true);
 572                      $confobj->setVar('conf_formtype', $config['formtype']);
 573                      $confobj->setVar('conf_valuetype', $config['valuetype']);
 574                      if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) {
 575                          // preserver the old value if any

 576                          // form type and value type must be the same

 577                          $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true);
 578                      } else {
 579                          $confobj->setConfValueForInput($config['default'], true);
 580  
 581                          //$confobj->setVar('conf_value', $config['default'], true);

 582                      }
 583                      $confobj->setVar('conf_order', $order);
 584                      $confop_msgs = '';
 585                      if (isset($config['options']) && is_array($config['options'])) {
 586                          foreach ($config['options'] as $key => $value) {
 587                              $confop =& $config_handler->createConfigOption();
 588                              $confop->setVar('confop_name', $key, true);
 589                              $confop->setVar('confop_value', $value, true);
 590                              $confobj->setConfOptions($confop);
 591                              $confop_msgs .= '<br />&nbsp;&nbsp;&nbsp;&nbsp;Config option added. Name: <b>'.$key.'</b> Value: <b>'.$value.'</b>';
 592                              unset($confop);
 593                          }
 594                      }
 595                      $order++;
 596                      if (false != $config_handler->insertConfig($confobj)) {
 597                          $msgs[] = '&nbsp;&nbsp;Config <b>'.$config['name'].'</b> added to the database.'.$confop_msgs;
 598                      } else {
 599                          $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert config <b>'.$config['name'].'</b> to the database.</span>';
 600                      }
 601                      unset($confobj);
 602                  }
 603              }
 604              unset($configs);
 605          }
 606  
 607          // execute module specific update script if any

 608          $update_script = $module->getInfo('onUpdate');
 609          if (false != $update_script && trim($update_script) != '') {
 610              include_once XOOPS_ROOT_PATH.'/modules/'.$dirname.'/'.trim($update_script);
 611              if (function_exists('xoops_module_update_'.$dirname)) {
 612                  $func = 'xoops_module_update_'.$dirname;
 613                  if (!$func($module, $prev_version)) {
 614                      $msgs[] = 'Failed to execute '.$func;
 615                  } else {
 616                      $msgs[] = '<b>'.$func.'</b> executed successfully.';
 617                  }
 618              }
 619          }
 620  
 621          foreach ($msgs as $msg) {
 622              echo '<code>'.$msg.'</code><br />';
 623          }
 624          echo "<p>".sprintf(_MD_AM_OKUPD, "<b>".$module->getVar('name')."</b>")."</p>";
 625      }
 626      echo "<br /><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a>";
 627      xoops_cp_footer();
 628  }
 629  
 630  ?>


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