[ 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/ -> modulesadmin.php (source)

   1  <?php
   2  // $Id: modulesadmin.php 988 2007-08-13 07:36:31Z phppp $

   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  
  36  function xoops_module_list()
  37  {
  38      xoops_cp_header();
  39      echo "
  40      <h4 style='text-align:left'>"._MD_AM_MODADMIN."</h4>
  41      <form action='admin.php' method='post' name='moduleadmin' id='moduleadmin'>
  42      <table class='outer' width='100%' cellpadding='4' cellspacing='1'>
  43      <tr align='center'><th>"._MD_AM_MODULE."</th><th>"._MD_AM_VERSION."</th><th>"._MD_AM_LASTUP."</th><th>"._MD_AM_ACTIVE."</th><th>"._MD_AM_ORDER."<br /><small>"._MD_AM_ORDER0."</small></th><th>"._MD_AM_ACTION."</th></tr>
  44      ";
  45      $module_handler =& xoops_gethandler('module');
  46      $installed_mods =& $module_handler->getObjects();
  47      $listed_mods = array();
  48      $count = 0;
  49      foreach ( $installed_mods as $module ) {
  50          if ($count % 2 == 0) {
  51              $class = 'even';
  52          } else {
  53              $class = 'odd';
  54          }
  55          $count++;
  56          echo "<tr class='$class' align='center' valign='middle'>\n";
  57          echo "<td valign='bottom'>";
  58          if ( $module->getVar('hasadmin') == 1 && $module->getVar('isactive') == 1) {
  59              echo '<a href="'.XOOPS_URL.'/modules/'.$module->getVar('dirname').'/'.$module->getInfo('adminindex').'"><img src="'.XOOPS_URL.'/modules/'.$module->getVar('dirname').'/'.$module->getInfo('image').'" alt="'.$module->getVar('name', 'E').'" border="0" /></a><br /><input type="text" name="newname['.$module->getVar('mid').']" value="'.$module->getVar('name', 'E').'" maxlength="150" size="20" />';
  60          } else {
  61              echo '<img src="'.XOOPS_URL.'/modules/'.$module->getVar('dirname').'/'.$module->getInfo('image').'" alt="'.$module->getVar('name', 'E').'" border="0" /><br /><input type="text" name="newname['.$module->getVar('mid').']" value="'.$module->getVar('name', 'E').'" maxlength="150" size="20" />';
  62          }
  63          echo '<input type="hidden" name="oldname['.$module->getVar('mid').']" value="' .$module->getVar('name').'" /></td>';
  64          echo "<td align='center'>".round($module->getVar('version') / 100, 2)."</td><td align='center'>".formatTimestamp($module->getVar('last_update'),'m')."<br />";
  65          if ($module->getVar('dirname') != 'system' && $module->getVar('isactive') == 1) {
  66              echo '</td><td><input type="checkbox" name="newstatus['.$module->getVar('mid').']" value="1" checked="checked" /><input type="hidden" name="oldstatus['.$module->getVar('mid').']" value="1" />';
  67              $extra = '<a href="'.XOOPS_URL.'/modules/system/admin.php?fct=modulesadmin&amp;op=update&amp;module='.$module->getVar('dirname').'"><img src="'.XOOPS_URL.'/modules/system/images/update.gif" alt="'._MD_AM_UPDATE.'" /></a>';
  68          } elseif ($module->getVar('dirname') != 'system') {
  69              echo '</td><td><input type="checkbox" name="newstatus['.$module->getVar('mid').']" value="1" /><input type="hidden" name="oldstatus['.$module->getVar('mid').']" value="0" />';
  70              $extra = '<a href="'.XOOPS_URL.'/modules/system/admin.php?fct=modulesadmin&amp;op=update&amp;module='.$module->getVar('dirname').'"><img src="'.XOOPS_URL.'/modules/system/images/update.gif" alt="'._MD_AM_UPDATE.'" /></a>&nbsp;<a href="'.XOOPS_URL.'/modules/system/admin.php?fct=modulesadmin&amp;op=uninstall&amp;module='.$module->getVar('dirname').'"><img src="'.XOOPS_URL.'/modules/system/images/uninstall.gif" alt="'._MD_AM_UNINSTALL.'" /></a>';
  71          } else {
  72              echo '</td><td><input type="checkbox" name="newstatus['.$module->getVar('mid').']" value="1" checked="checked" /><input type="hidden" name="oldstatus['.$module->getVar('mid').']" value="1" />';
  73              $extra = '<a href="'.XOOPS_URL.'/modules/system/admin.php?fct=modulesadmin&amp;op=update&amp;module='.$module->getVar('dirname').'"><img src="'.XOOPS_URL.'/modules/system/images/update.gif" alt="'._MD_AM_UPDATE.'" /></a>';
  74          }
  75          echo "</td><td>";
  76          if ($module->getVar('hasmain') == 1) {
  77              echo '<input type="hidden" name="oldweight['.$module->getVar('mid').']" value="'.$module->getVar('weight').'" /><input type="text" name="weight['.$module->getVar('mid').']" size="3" maxlength="5" value="'.$module->getVar('weight').'" />';
  78          } else {
  79              echo '<input type="hidden" name="oldweight['.$module->getVar('mid').']" value="0" /><input type="hidden" name="weight['.$module->getVar('mid').']" value="0" />';
  80          }
  81          echo "
  82          </td>
  83          <td>".$extra."&nbsp;<a href='javascript:openWithSelfMain(\"".XOOPS_URL."/modules/system/admin.php?fct=version&amp;mid=".$module->getVar('mid')."\",\"Info\",300,230);'>";
  84          echo '<img src="'.XOOPS_URL.'/modules/system/images/info.gif" alt="'._INFO.'" /></a><input type="hidden" name="module[]" value="'.$module->getVar('mid').'" /></td>
  85          </tr>
  86          ';
  87          $listed_mods[] = $module->getVar('dirname');
  88      }
  89      echo "<tr class='foot'><td colspan='6' align='center'><input type='hidden' name='fct' value='modulesadmin' />
  90      <input type='hidden' name='op' value='confirm' />
  91      <input type='submit' name='submit' value='"._MD_AM_SUBMIT."' />
  92      </td></tr></table>
  93      </form>
  94      <br />
  95      <table width='100%' border='0' class='outer' cellpadding='4' cellspacing='1'>
  96      <tr align='center'><th>"._MD_AM_MODULE."</th><th>"._MD_AM_VERSION."</th><th>"._MD_AM_ACTION."</th></tr>
  97      ";
  98      require_once XOOPS_ROOT_PATH."/class/xoopslists.php";
  99      $dirlist = XoopsLists::getModulesList();
 100      $count = 0;
 101      foreach($dirlist as $file){
 102          clearstatcache();
 103          $file = trim($file);
 104          if ( !in_array($file, $listed_mods) ) {
 105              $module =& $module_handler->create();
 106              if (!$module->loadInfo($file, false)) {
 107                  continue;
 108              }
 109              if ($count % 2 == 0) {
 110                  $class = 'even';
 111              } else {
 112                  $class = 'odd';
 113              }
 114              echo '<tr class="'.$class.'" align="center" valign="middle">
 115              <td align="center" valign="bottom"><img src="'.XOOPS_URL.'/modules/'.$module->getInfo('dirname').'/'.$module->getInfo('image').'" alt="'.htmlspecialchars($module->getInfo('name')).'" border="0" /></td>
 116              <td align="center">'.round($module->getInfo('version'), 2).'</td>
 117              <td>
 118              <a href="'.XOOPS_URL.'/modules/system/admin.php?fct=modulesadmin&amp;op=install&amp;module='.$module->getInfo('dirname').'"><img src="'.XOOPS_URL.'/modules/system/images/install.gif" alt="'._MD_AM_INSTALL.'" /></a>';
 119              echo "&nbsp;<a href='javascript:openWithSelfMain(\"".XOOPS_URL."/modules/system/admin.php?fct=version&amp;mid=".$module->getInfo('dirname')."\",\"Info\",300,230);'>";
 120              echo '<img src="'.XOOPS_URL.'/modules/system/images/info.gif" alt="'._INFO.'" /></a></td></tr>
 121              ';
 122              unset($module);
 123              $count++;
 124          }
 125      }
 126      echo "</table>";
 127      xoops_cp_footer();
 128  }
 129  
 130  function xoops_module_install($dirname)
 131  {
 132      global $xoopsUser, $xoopsConfig;
 133      $dirname = trim($dirname);
 134      $db =& Database::getInstance();
 135      $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups','groups_users_link','group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
 136      $module_handler =& xoops_gethandler('module');
 137      if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) {
 138          $module =& $module_handler->create();
 139          $module->loadInfoAsVar($dirname);
 140          $module->setVar('weight', 1);
 141          $error = false;
 142          $errs = array();
 143          $sqlfile =& $module->getInfo('sqlfile');
 144          $msgs = array();
 145          $msgs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing '.$module->getInfo('name').'</h4>';
 146          if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
 147              $msgs[] ='<img src="'.XOOPS_URL.'/modules/'.$dirname.'/'.trim($module->getInfo('image')).'" alt="" />';
 148          }
 149          $msgs[] ='<b>Version:</b> '.$module->getInfo('version');
 150          if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
 151              $msgs[] ='<b>Author:</b> '.trim($module->getInfo('author'));
 152          }
 153          $msgs[] = '';
 154          $errs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing '.$module->getInfo('name').'</h4>';
 155          if ($sqlfile != false && is_array($sqlfile)) {
 156  
 157              $sql_file_path = XOOPS_ROOT_PATH."/modules/".$dirname."/".$sqlfile[XOOPS_DB_TYPE];
 158              if (!file_exists($sql_file_path)) {
 159                  $errs[] = "SQL file not found at <b>$sql_file_path</b>";
 160                  $error = true;
 161              } else {
 162                  $msgs[] = "SQL file found at <b>$sql_file_path</b>.<br  /> Creating tables...";
 163                  include_once XOOPS_ROOT_PATH.'/class/database/sqlutility.php';
 164                  $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
 165                  $sql_query = trim($sql_query);
 166                  SqlUtility::splitMySqlFile($pieces, $sql_query);
 167                  $created_tables = array();
 168                  foreach ($pieces as $piece) {
 169                      // [0] contains the prefixed query

 170                      // [4] contains unprefixed table name

 171                      $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
 172                      if (!$prefixed_query) {
 173                          $errs[] = "<b>$piece</b> is not a valid SQL!";
 174                          $error = true;
 175                          break;
 176                      }
 177                      // check if the table name is reserved

 178                      if (!in_array($prefixed_query[4], $reservedTables)) {
 179                          // not reserved, so try to create one

 180                          if (!$db->query($prefixed_query[0])) {
 181                              $errs[] = $db->error();
 182                              $error = true;
 183                              break;
 184                          } else {
 185  
 186                              if (!in_array($prefixed_query[4], $created_tables)) {
 187                                  $msgs[] = '&nbsp;&nbsp;Table <b>'.$db->prefix($prefixed_query[4]).'</b> created.';
 188                                  $created_tables[] = $prefixed_query[4];
 189                              } else {
 190                                  $msgs[] = '&nbsp;&nbsp;Data inserted to table <b>'.$db->prefix($prefixed_query[4]).'</b>.';
 191                              }
 192                          }
 193                      } else {
 194                          // the table name is reserved, so halt the installation

 195                          $errs[] = '<b>'.$prefixed_query[4]."</b> is a reserved table!";
 196                          $error = true;
 197                          break;
 198                      }
 199                  }
 200                  // if there was an error, delete the tables created so far, so the next installation will not fail

 201                  if ($error == true) {
 202                      foreach ($created_tables as $ct) {
 203                          //echo $ct;

 204                          $db->query("DROP TABLE ".$db->prefix($ct));
 205                      }
 206                  }
 207              }
 208          }
 209          // if no error, save the module info and blocks info associated with it

 210          if ($error == false) {
 211              if (!$module_handler->insert($module)) {
 212                  $errs[] = 'Could not insert <b>'.$module->getVar('name').'</b> to database.';
 213                  foreach ($created_tables as $ct) {
 214                      $db->query("DROP TABLE ".$db->prefix($ct));
 215                  }
 216                  $ret = "<p>".sprintf(_MD_AM_FAILINS, "<b>".$module->name()."</b>")."&nbsp;"._MD_AM_ERRORSC."<br />";
 217                  foreach ( $errs as $err ) {
 218                      $ret .= " - ".$err."<br />";
 219                  }
 220                  $ret .= "</p>";
 221                  unset($module);
 222                  unset($created_tables);
 223                  unset($errs);
 224                  unset($msgs);
 225                  return $ret;
 226              } else {
 227                  $newmid = $module->getVar('mid');
 228                  unset($created_tables);
 229                  $msgs[] = 'Module data inserted successfully. Module ID: <b>'.$newmid.'</b>';
 230                  $tplfile_handler =& xoops_gethandler('tplfile');
 231                  $templates = $module->getInfo('templates');
 232                  if ($templates != false) {
 233                      $msgs[] = 'Adding templates...';
 234                      foreach ($templates as $tpl) {
 235                          $tplfile =& $tplfile_handler->create();
 236                          $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']);
 237                          $tplfile->setVar('tpl_source', $tpldata, true);
 238                          $tplfile->setVar('tpl_refid', $newmid);
 239  
 240                          $tplfile->setVar('tpl_tplset', 'default');
 241                          $tplfile->setVar('tpl_file', $tpl['file']);
 242                          $tplfile->setVar('tpl_desc', $tpl['description'], true);
 243                          $tplfile->setVar('tpl_module', $dirname);
 244                          $tplfile->setVar('tpl_lastmodified', time());
 245                          $tplfile->setVar('tpl_lastimported', 0);
 246                          $tplfile->setVar('tpl_type', 'module');
 247                          if (!$tplfile_handler->insert($tplfile)) {
 248                              $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>'.$tpl['file'].'</b> to the database.</span>';
 249                          } else {
 250                              $newtplid = $tplfile->getVar('tpl_id');
 251                              $msgs[] = '&nbsp;&nbsp;Template <b>'.$tpl['file'].'</b> added to the database. (ID: <b>'.$newtplid.'</b>)';
 252                              // generate compiled file

 253                              include_once  XOOPS_ROOT_PATH.'/class/template.php';
 254                              if (!xoops_template_touch($newtplid)) {
 255                                  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.$tpl['file'].'</b>.</span>';
 256                              } else {
 257                                  $msgs[] = '&nbsp;&nbsp;Template <b>'.$tpl['file'].'</b> compiled.</span>';
 258                              }
 259                          }
 260                          unset($tpldata);
 261                      }
 262                  }
 263                  include_once  XOOPS_ROOT_PATH.'/class/template.php';
 264                  xoops_template_clear_module_cache($newmid);
 265                  $blocks = $module->getInfo('blocks');
 266                  if ($blocks != false) {
 267                      $msgs[] = 'Adding blocks...';
 268                      foreach ($blocks as $blockkey => $block) {
 269                          // break the loop if missing block config

 270                          if (!isset($block['file']) || !isset($block['show_func'])) {
 271                              break;
 272                          }
 273                          $options = '';
 274                          if (!empty($block['options'])) {
 275                              $options = trim($block['options']);
 276                          }
 277                          $newbid = $db->genId($db->prefix('newblocks').'_bid_seq');
 278                          $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : '';
 279                          $template = '';
 280                          if ((isset($block['template']) && trim($block['template']) != '')) {
 281                              $content =& xoops_module_gettemplate($dirname, $block['template'], true);
 282                          }
 283                          if (empty($content)) {
 284                              $content = '';
 285                          } else {
 286                              $template = trim($block['template']);
 287                          }
 288                          $block_name = addslashes(trim($block['name']));
 289                          $sql = "INSERT INTO ".$db->prefix("newblocks")." (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ($newbid, $newmid, ".intval($blockkey).", '$options', '".$block_name."','".$block_name."', '', 0, 0, 0, 'M', 'H', 1, '".addslashes($dirname)."', '".addslashes(trim($block['file']))."', '".addslashes(trim($block['show_func']))."', '".addslashes($edit_func)."', '".$template."', 0, ".time().")";
 290                          if (!$db->query($sql)) {
 291                              $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add block <b>'.$block['name'].'</b> to the database! Database error: <b>'.$db->error().'</b></span>';
 292                          } else {
 293                              if (empty($newbid)) {
 294                                  $newbid = $db->getInsertId();
 295                              }
 296                              $msgs[] = '&nbsp;&nbsp;Block <b>'.$block['name'].'</b> added. Block ID: <b>'.$newbid.'</b>';
 297                              $sql = 'INSERT INTO '.$db->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newbid.', -1)';
 298                              $db->query($sql);
 299                              if ($template != '') {
 300                                  $tplfile =& $tplfile_handler->create();
 301                                  $tplfile->setVar('tpl_refid', $newbid);
 302                                  $tplfile->setVar('tpl_source', $content, true);
 303                                  $tplfile->setVar('tpl_tplset', 'default');
 304                                  $tplfile->setVar('tpl_file', $block['template']);
 305                                  $tplfile->setVar('tpl_module', $dirname);
 306                                  $tplfile->setVar('tpl_type', 'block');
 307                                  $tplfile->setVar('tpl_desc', $block['description'], true);
 308                                  $tplfile->setVar('tpl_lastimported', 0);
 309                                  $tplfile->setVar('tpl_lastmodified', time());
 310                                  if (!$tplfile_handler->insert($tplfile)) {
 311                                      $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>'.$block['template'].'</b> to the database.</span>';
 312                                  } else {
 313                                      $newtplid = $tplfile->getVar('tpl_id');
 314                                      $msgs[] = '&nbsp;&nbsp;Template <b>'.$block['template'].'</b> added to the database. (ID: <b>'.$newtplid.'</b>)';
 315                                      // generate compiled file

 316                                      include_once  XOOPS_ROOT_PATH.'/class/template.php';
 317                                      if (!xoops_template_touch($newtplid)) {
 318                                          $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.$block['template'].'</b>.</span>';
 319                                      } else {
 320                                          $msgs[] = '&nbsp;&nbsp;Template <b>'.$block['template'].'</b> compiled.</span>';
 321                                      }
 322                                  }
 323                              }
 324                          }
 325                          unset($content);
 326                      }
 327                      unset($blocks);
 328                  }
 329                  $configs = $module->getInfo('config');
 330                  if ($configs != false) {
 331                      if ($module->getVar('hascomments') != 0) {
 332                          include_once(XOOPS_ROOT_PATH.'/include/comment_constants.php');
 333                          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)));
 334                          array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0));
 335                      }
 336                  } else {
 337                      if ($module->getVar('hascomments') != 0) {
 338                          $configs = array();
 339                          include_once(XOOPS_ROOT_PATH.'/include/comment_constants.php');
 340                          $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));
 341                          $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0);
 342                      }
 343                  }
 344                  // RMV-NOTIFY

 345                  if ($module->getVar('hasnotification') != 0) {
 346                      if (empty($configs)) {
 347                          $configs = array();
 348                      }
 349                      // Main notification options

 350                      include_once  XOOPS_ROOT_PATH . '/include/notification_constants.php';
 351                      include_once  XOOPS_ROOT_PATH . '/include/notification_functions.php';
 352                      $options = array();
 353                      $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
 354                      $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
 355                      $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
 356                      $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
 357  
 358                      //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);

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

 361                      // FIXME: doesn't work when update module... can't read back the array of options properly...  " changing to &quot;

 362                      $options = array();
 363                      $categories =& notificationCategoryInfo('',$module->getVar('mid'));
 364                      foreach ($categories as $category) {
 365                          $events =& notificationEvents ($category['name'], false, $module->getVar('mid'));
 366                          foreach ($events as $event) {
 367                              if (!empty($event['invisible'])) {
 368                                  continue;
 369                              }
 370                              $option_name = $category['title'] . ' : ' . $event['title'];
 371                              $option_value = $category['name'] . '-' . $event['name'];
 372                              $options[$option_name] = $option_value;
 373                          }
 374                      }
 375                      $configs[] = array ('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options);
 376                  }
 377  
 378                  if ($configs != false) {
 379                      $msgs[] = 'Adding module config data...';
 380                      $config_handler =& xoops_gethandler('config');
 381                      $order = 0;
 382                      foreach ($configs as $config) {
 383                          $confobj =& $config_handler->createConfig();
 384                          $confobj->setVar('conf_modid', $newmid);
 385                          $confobj->setVar('conf_catid', 0);
 386                          $confobj->setVar('conf_name', $config['name']);
 387                          $confobj->setVar('conf_title', $config['title'], true);
 388                          $confobj->setVar('conf_desc', $config['description'], true);
 389                          $confobj->setVar('conf_formtype', $config['formtype']);
 390                          $confobj->setVar('conf_valuetype', $config['valuetype']);
 391                          $confobj->setConfValueForInput($config['default'], true);
 392                          //$confobj->setVar('conf_value', $config['default'], true);

 393                          $confobj->setVar('conf_order', $order);
 394                          $confop_msgs = '';
 395                          if (isset($config['options']) && is_array($config['options'])) {
 396                              foreach ($config['options'] as $key => $value) {
 397                                  $confop =& $config_handler->createConfigOption();
 398                                  $confop->setVar('confop_name', $key, true);
 399                                  $confop->setVar('confop_value', $value, true);
 400                                  $confobj->setConfOptions($confop);
 401                                  $confop_msgs .= '<br />&nbsp;&nbsp;&nbsp;&nbsp;Config option added. Name: <b>'.$key.'</b> Value: <b>'.$value.'</b>';
 402                                  unset($confop);
 403                              }
 404                          }
 405                          $order++;
 406                          if ($config_handler->insertConfig($confobj) != false) {
 407                              $msgs[] = '&nbsp;&nbsp;Config <b>'.$config['name'].'</b> added to the database.'.$confop_msgs;
 408                          } else {
 409                              $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert config <b>'.$config['name'].'</b> to the database.</span>';
 410                          }
 411                          unset($confobj);
 412                      }
 413                      unset($configs);
 414                  }
 415              }
 416                  if ($module->getInfo('hasMain')) {
 417                      $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
 418                  } else {
 419                      $groups = array(XOOPS_GROUP_ADMIN);
 420                  }
 421              // retrieve all block ids for this module

 422              $blocks =& XoopsBlock::getByModule($newmid, false);
 423              $msgs[] = 'Setting group rights...';
 424              $gperm_handler =& xoops_gethandler('groupperm');
 425              foreach ($groups as $mygroup) {
 426                  if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) {
 427                      $mperm =& $gperm_handler->create();
 428                      $mperm->setVar('gperm_groupid', $mygroup);
 429                      $mperm->setVar('gperm_itemid', $newmid);
 430                      $mperm->setVar('gperm_name', 'module_admin');
 431                      $mperm->setVar('gperm_modid', 1);
 432                      if (!$gperm_handler->insert($mperm)) {
 433                          $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add admin access right for Group ID <b>'.$mygroup.'</b></span>';
 434                      } else {
 435                          $msgs[] = '&nbsp;&nbsp;Added admin access right for Group ID <b>'.$mygroup.'</b>';
 436                      }
 437                      unset($mperm);
 438                  }
 439                  $mperm =& $gperm_handler->create();
 440                  $mperm->setVar('gperm_groupid', $mygroup);
 441                  $mperm->setVar('gperm_itemid', $newmid);
 442                  $mperm->setVar('gperm_name', 'module_read');
 443                  $mperm->setVar('gperm_modid', 1);
 444                  if (!$gperm_handler->insert($mperm)) {
 445                      $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add user access right for Group ID: <b>'.$mygroup.'</b></span>';
 446                  } else {
 447                      $msgs[] = '&nbsp;&nbsp;Added user access right for Group ID: <b>'.$mygroup.'</b>';
 448                  }
 449                  unset($mperm);
 450                  foreach ($blocks as $blc) {
 451                      $bperm =& $gperm_handler->create();
 452                      $bperm->setVar('gperm_groupid', $mygroup);
 453                      $bperm->setVar('gperm_itemid', $blc);
 454                      $bperm->setVar('gperm_name', 'block_read');
 455                      $bperm->setVar('gperm_modid', 1);
 456                      if (!$gperm_handler->insert($bperm)) {
 457                          $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add block access right. Block ID: <b>'.$blc.'</b> Group ID: <b>'.$mygroup.'</b></span>';
 458                      } else {
 459                          $msgs[] = '&nbsp;&nbsp;Added block access right. Block ID: <b>'.$blc.'</b> Group ID: <b>'.$mygroup.'</b>';
 460                      }
 461                      unset($bperm);
 462                  }
 463              }
 464              unset($blocks);
 465              unset($groups);
 466  
 467              // execute module specific install script if any

 468              $install_script = $module->getInfo('onInstall');
 469              if (false != $install_script && trim($install_script) != '') {
 470                  include_once XOOPS_ROOT_PATH.'/modules/'.$dirname.'/'.trim($install_script);
 471                  if (function_exists('xoops_module_install_'.$dirname)) {
 472                      $func = 'xoops_module_install_'.$dirname;
 473                      if ( !( $lastmsg = $func($module) ) ) {
 474                          $msgs[] = 'Failed to execute '.$func;
 475                      } else {
 476                          $msgs[] = '<b>'.$func.'</b> executed successfully.';
 477                          if ( is_string( $lastmsg ) ) {
 478                              $msgs[] = $lastmsg;
 479                          }
 480                      }
 481                  }
 482              }
 483  
 484              $ret = '<p><code>';
 485              foreach ($msgs as $m) {
 486                  $ret .= $m.'<br />';
 487              }
 488              unset($msgs);
 489              unset($errs);
 490              $ret .= '</code><br />'.sprintf(_MD_AM_OKINS, "<b>".$module->getVar('name')."</b>").'</p>';
 491              unset($module);
 492              return $ret;
 493          } else {
 494              $ret = '<p>';
 495              foreach ($errs as $er) {
 496                  $ret .= '&nbsp;&nbsp;'.$er.'<br />';
 497              }
 498              unset($msgs);
 499              unset($errs);
 500              $ret .= '<br />'.sprintf(_MD_AM_FAILINS, '<b>'.$dirname.'</b>').'&nbsp;'._MD_AM_ERRORSC.'</p>';
 501              return $ret;
 502          }
 503      }
 504      else {
 505          return "<p>".sprintf(_MD_AM_FAILINS, "<b>".$dirname."</b>")."&nbsp;"._MD_AM_ERRORSC."<br />&nbsp;&nbsp;".sprintf(_MD_AM_ALEXISTS, $dirname)."</p>";
 506      }
 507  }
 508  
 509  function &xoops_module_gettemplate($dirname, $template, $block=false)
 510  {
 511      global $xoopsConfig;
 512      $ret = '';
 513      if ($block) {
 514          $path = XOOPS_ROOT_PATH.'/modules/'.$dirname.'/templates/blocks/'.$template;
 515      } else {
 516          $path = XOOPS_ROOT_PATH.'/modules/'.$dirname.'/templates/'.$template;
 517      }
 518      if (!file_exists($path)) {
 519          return $ret;
 520      } else {
 521          $lines = file($path);
 522      }
 523      if (!$lines) {
 524          return $ret;
 525      }
 526      $count = count($lines);
 527      for ($i = 0; $i < $count; $i++) {
 528          $ret .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $lines[$i]));
 529      }
 530      return $ret;
 531  }
 532  
 533  function xoops_module_uninstall($dirname)
 534  {
 535      global $xoopsConfig;
 536      $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups','groups_users_link','group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
 537      $db =& Database::getInstance();
 538      $module_handler =& xoops_gethandler('module');
 539      $module =& $module_handler->getByDirname($dirname);
 540      include_once  XOOPS_ROOT_PATH.'/class/template.php';
 541      xoops_template_clear_module_cache($module->getVar('mid'));
 542      if ($module->getVar('dirname') == 'system') {
 543          return "<p>".sprintf(_MD_AM_FAILUNINS, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br /> - "._MD_AM_SYSNO."</p>";
 544      } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
 545          return "<p>".sprintf(_MD_AM_FAILUNINS, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br /> - "._MD_AM_STRTNO."</p>";
 546      } else {
 547          $msgs = array();
 548          if (!$module_handler->delete($module)) {
 549              $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete '.$module->getVar('name').'</span>';
 550          } else {
 551  
 552              // delete template files

 553              $tplfile_handler = xoops_gethandler('tplfile');
 554              $templates =& $tplfile_handler->find(null, 'module', $module->getVar('mid'));
 555              $tcount = count($templates);
 556              if ($tcount > 0) {
 557                  $msgs[] = 'Deleting templates...';
 558                  for ($i = 0; $i < $tcount; $i++) {
 559                      if (!$tplfile_handler->delete($templates[$i])) {
 560                          $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete template '.$templates[$i]->getVar('tpl_file').' from the database. Template ID: <b>'.$templates[$i]->getVar('tpl_id').'</b></span>';
 561                      } else {
 562                          $msgs[] = '&nbsp;&nbsp;Template <b>'.$templates[$i]->getVar('tpl_file').'</b> deleted from the database. Template ID: <b>'.$templates[$i]->getVar('tpl_id').'</b>';
 563                      }
 564                  }
 565              }
 566              unset($templates);
 567  
 568              // delete blocks and block tempalte files

 569              $block_arr =& XoopsBlock::getByModule($module->getVar('mid'));
 570              if (is_array($block_arr)) {
 571                  $bcount = count($block_arr);
 572                  $msgs[] = 'Deleting block...';
 573                  for ($i = 0; $i < $bcount; $i++) {
 574                      if (!$block_arr[$i]->delete()) {
 575                          $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete block <b>'.$block_arr[$i]->getVar('name').'</b> Block ID: <b>'.$block_arr[$i]->getVar('bid').'</b></span>';
 576                      } else {
 577                          $msgs[] = '&nbsp;&nbsp;Block <b>'.$block_arr[$i]->getVar('name').'</b> deleted. Block ID: <b>'.$block_arr[$i]->getVar('bid').'</b>';
 578                      }
 579                      if ($block_arr[$i]->getVar('template') != ''){
 580                          $templates =& $tplfile_handler->find(null, 'block', $block_arr[$i]->getVar('bid'));
 581                          $btcount = count($templates);
 582                          if ($btcount > 0) {
 583                              for ($j = 0; $j < $btcount; $j++) {
 584                                  if (!$tplfile_handler->delete($templates[$j])) {
 585                                  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete block template '.$templates[$j]->getVar('tpl_file').' from the database. Template ID: <b>'.$templates[$j]->getVar('tpl_id').'</b></span>';
 586                                  } else {
 587                                  $msgs[] = '&nbsp;&nbsp;Block template <b>'.$templates[$j]->getVar('tpl_file').'</b> deleted from the database. Template ID: <b>'.$templates[$j]->getVar('tpl_id').'</b>';
 588                                  }
 589                              }
 590                          }
 591                          unset($templates);
 592                      }
 593                  }
 594              }
 595  
 596              // delete tables used by this module

 597              $modtables = $module->getInfo('tables');
 598              if ($modtables != false && is_array($modtables)) {
 599                  $msgs[] = 'Deleting module tables...';
 600                  foreach ($modtables as $table) {
 601                      // prevent deletion of reserved core tables!

 602                      if (!in_array($table, $reservedTables)) {
 603                          $sql = 'DROP TABLE '.$db->prefix($table);
 604                          if (!$db->query($sql)) {
 605                              $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not drop table <b>'.$db->prefix($table).'<b>.</span>';
 606                          } else {
 607                              $msgs[] = '&nbsp;&nbsp;Table <b>'.$db->prefix($table).'</b> dropped.</span>';
 608                          }
 609                      } else {
 610                          $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Not allowed to drop table <b>'.$db->prefix($table).'</b>!</span>';
 611                      }
 612                  }
 613              }
 614  
 615              // delete comments if any

 616              if ($module->getVar('hascomments') != 0) {
 617                  $msgs[] = 'Deleting comments...';
 618                  $comment_handler =& xoops_gethandler('comment');
 619                  if (!$comment_handler->deleteByModule($module->getVar('mid'))) {
 620                      $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete comments</span>';
 621                  } else {
 622                      $msgs[] = '&nbsp;&nbsp;Comments deleted';
 623                  }
 624              }
 625  
 626              // RMV-NOTIFY

 627              // delete notifications if any

 628              if ($module->getVar('hasnotification') != 0) {
 629                  $msgs[] = 'Deleting notifications...';
 630                  if (!xoops_notification_deletebymodule($module->getVar('mid'))) {
 631                      $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete notifications</span>';
 632                  } else {
 633                      $msgs[] = '&nbsp;&nbsp;Notifications deleted';
 634                  }
 635              }
 636  
 637              // delete permissions if any

 638              $gperm_handler =& xoops_gethandler('groupperm');
 639              if (!$gperm_handler->deleteByModule($module->getVar('mid'))) {
 640                  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete group permissions</span>';
 641              } else {
 642                  $msgs[] = '&nbsp;&nbsp;Group permissions deleted';
 643              }
 644  
 645              // delete module config options if any

 646              if ($module->getVar('hasconfig') != 0 || $module->getVar('hascomments') != 0) {
 647                  $config_handler =& xoops_gethandler('config');
 648                  $configs =& $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
 649                  $confcount = count($configs);
 650                  if ($confcount > 0) {
 651                      $msgs[] = 'Deleting module config options...';
 652                      for ($i = 0; $i < $confcount; $i++) {
 653                          if (!$config_handler->deleteConfig($configs[$i])) {
 654                              $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>';
 655                          } else {
 656                              $msgs[] = '&nbsp;&nbsp;Config data deleted from the database. Config ID: <b>'.$configs[$i]->getVar('conf_id').'</b>';
 657                          }
 658                      }
 659                  }
 660              }
 661  
 662              // execute module specific install script if any

 663              $uninstall_script = $module->getInfo('onUninstall');
 664              if (false != $uninstall_script && trim($uninstall_script) != '') {
 665                  include_once XOOPS_ROOT_PATH.'/modules/'.$dirname.'/'.trim($uninstall_script);
 666                  if (function_exists('xoops_module_uninstall_'.$dirname)) {
 667                      $func = 'xoops_module_uninstall_'.$dirname;
 668                      if (!$func($module)) {
 669                          $msgs[] = 'Failed to execute <b>'.$func.'</b>';
 670                      } else {
 671                          $msgs[] = '<b>'.$func.'</b> executed successfully.';
 672                      }
 673                  }
 674              }
 675  
 676              $msgs[] = '</code><p>'.sprintf(_MD_AM_OKUNINS, "<b>".$module->getVar('name')."</b>").'</p>';
 677          }
 678          $ret = '<code>';
 679          foreach ($msgs as $msg) {
 680              $ret .= $msg.'<br />';
 681          }
 682          return $ret;
 683      }
 684  }
 685  
 686  function xoops_module_activate($mid)
 687  {
 688      $module_handler =& xoops_gethandler('module');
 689      $module =& $module_handler->get($mid);
 690      include_once  XOOPS_ROOT_PATH.'/class/template.php';
 691      xoops_template_clear_module_cache($module->getVar('mid'));
 692      $module->setVar('isactive', 1);
 693      if (!$module_handler->insert($module)) {
 694          $ret = "<p>".sprintf(_MD_AM_FAILACT, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br />".$module->getHtmlErrors();
 695          return $ret."</p>";
 696      }
 697      $blocks =& XoopsBlock::getByModule($module->getVar('mid'));
 698      $bcount = count($blocks);
 699      for ($i = 0; $i < $bcount; $i++) {
 700          $blocks[$i]->setVar('isactive', 1);
 701          $blocks[$i]->store();
 702      }
 703      return "<p>".sprintf(_MD_AM_OKACT, "<b>".$module->getVar('name')."</b>")."</p>";
 704  }
 705  
 706  function xoops_module_deactivate($mid)
 707  {
 708      global $xoopsConfig;
 709      $module_handler =& xoops_gethandler('module');
 710      $module =& $module_handler->get($mid);
 711      include_once  XOOPS_ROOT_PATH.'/class/template.php';
 712      xoops_template_clear_module_cache($mid);
 713      $module->setVar('isactive', 0);
 714      if ($module->getVar('dirname') == "system") {
 715          return "<p>".sprintf(_MD_AM_FAILDEACT, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br /> - "._MD_AM_SYSNO."</p>";
 716      } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
 717          return "<p>".sprintf(_MD_AM_FAILDEACT, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br /> - "._MD_AM_STRTNO."</p>";
 718      } else {
 719          if (!$module_handler->insert($module)) {
 720              $ret = "<p>".sprintf(_MD_AM_FAILDEACT, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br />".$module->getHtmlErrors();
 721              return $ret."</p>";
 722          }
 723          $blocks =& XoopsBlock::getByModule($module->getVar('mid'));
 724          $bcount = count($blocks);
 725          for ($i = 0; $i < $bcount; $i++) {
 726              $blocks[$i]->setVar('isactive', 0);
 727              $blocks[$i]->store();
 728          }
 729          return "<p>".sprintf(_MD_AM_OKDEACT, "<b>".$module->getVar('name')."</b>")."</p>";
 730      }
 731  }
 732  
 733  function xoops_module_change($mid, $weight, $name)
 734  {
 735      $module_handler =& xoops_gethandler('module');
 736      $module =& $module_handler->get($mid);
 737      $module->setVar('weight', $weight);
 738      $module->setVar('name', $name);
 739      $myts =& MyTextSanitizer::getInstance();
 740      if (!$module_handler->insert($module)) {
 741          $ret = "<p>".sprintf(_MD_AM_FAILORDER, "<b>".$myts->stripSlashesGPC($name)."</b>")."&nbsp;"._MD_AM_ERRORSC."<br />";
 742          $ret .= $module->getHtmlErrors()."</p>";
 743          return $ret;
 744      }
 745      return "<p>".sprintf(_MD_AM_OKORDER, "<b>".$myts->stripSlashesGPC($name)."</b>")."</p>";
 746  }
 747  
 748  ?>


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