XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
modulesadmin.php
Go to the documentation of this file.
1 <?php
2 // $Id: modulesadmin.php 8995 2012-02-15 13:21:30Z forxoops $
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 /*
33 if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
34  exit("Access Denied");
35 }
36 */
37 
38 
40 {
41  global $xoopsUser, $xoopsConfig;
42  $dirname = trim($dirname);
43  $db =& $GLOBALS["xoopsDB"];
44  $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');
45  $module_handler =& xoops_gethandler('module');
46  if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) {
47  $module =& $module_handler->create();
48  $module->loadInfoAsVar($dirname);
49  $module->setVar('weight', 1);
50  $module->setVar('isactive', 1);
51  $module->setVar('last_update', time() );
52  $error = false;
53  $errs = array();
54  $msgs = array();
55 
56  $msgs[] = '<div id="xo-module-log"><div class="header">';
57  $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_INSTALLING . $module->getInfo('name', 's') . '</h4>';
58  if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
59  $msgs[] ='<a href="'.XOOPS_URL.'/modules/'.$module->getInfo('dirname', 'e').'/'.$module->getInfo('adminindex').'"><img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" /></a>';
60  }
61  $msgs[] ='<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version');
62  if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
63  $msgs[] ='<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')));
64  }
65  $msgs[] = '</div><div class="logger">';
66  // Load module specific install script if any
67  $install_script = $module->getInfo('onInstall');
68  if ($install_script && trim($install_script) != '') {
69  include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($install_script);
70  }
71  $func = "xoops_module_pre_install_{$dirname}";
72  // If pre install function is defined, execute
73  if (function_exists($func)) {
74  $result = $func($module);
75  if (!$result) {
76  $error = true;
77  $errs[] = '<p>' . sprintf( _AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
78  $errs = array_merge($errs, $module->getErrors());
79  } else {
80  $msgs[] = '<p>' . sprintf( _AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>';
81  $msgs += $module->getErrors();
82  }
83  }
84 
85  if ($error == false) {
86  $sqlfile = $module->getInfo('sqlfile');
87  if (is_array($sqlfile) && !empty($sqlfile[XOOPS_DB_TYPE])) {
88 
89  $sql_file_path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . $sqlfile[XOOPS_DB_TYPE];
90  if (!file_exists($sql_file_path)) {
91  $errs[] = "<p>" . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_FOUND, "<strong>{$sql_file_path}</strong>");
92  $error = true;
93  } else {
94  $msgs[] = "<p>" . sprintf(_AM_SYSTEM_MODULES_SQL_FOUND, "<strong>{$sql_file_path}</strong>") . "<br />" . _AM_SYSTEM_MODULES_CREATE_TABLES;
95  include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
96  $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
97  $sql_query = trim($sql_query);
98  SqlUtility::splitMySqlFile($pieces, $sql_query);
99  $created_tables = array();
100  foreach ($pieces as $piece) {
101  // [0] contains the prefixed query
102  // [4] contains unprefixed table name
103  $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
104  if (!$prefixed_query) {
105  $errs[] ="<p>" . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_VALID, "<strong>" . $piece . "</strong>");
106  $error = true;
107  break;
108  }
109  // check if the table name is reserved
110  if (!in_array($prefixed_query[4], $reservedTables)) {
111  // not reserved, so try to create one
112  if (!$db->query($prefixed_query[0])) {
113  $errs[] = $db->error();
114  $error = true;
115  break;
116  } else {
117 
118  if (!in_array($prefixed_query[4], $created_tables)) {
119  $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_TABLE_CREATED, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>");
120  $created_tables[] = $prefixed_query[4];
121  } else {
122  $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_INSERT_DATA, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>");
123  }
124  }
125  } else {
126  // the table name is reserved, so halt the installation
127  $errs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_TABLE_RESERVED, "<strong>" . $prefixed_query[4] . "</strong>");
128  $error = true;
129  break;
130  }
131  }
132  // if there was an error, delete the tables created so far, so the next installation will not fail
133  if ($error == true) {
134  foreach ($created_tables as $ct) {
135  $db->query("DROP TABLE " . $db->prefix($ct));
136  }
137  }
138  }
139  }
140  }
141  // if no error, save the module info and blocks info associated with it
142  if ($error == false) {
143  if (!$module_handler->insert($module)) {
144  $errs[] = "<p>" . sprintf(_AM_SYSTEM_MODULES_INSERT_DATA_FAILD, "<strong>" . $module->getVar('name') . "</strong>");
145  foreach ($created_tables as $ct) {
146  $db->query("DROP TABLE " . $db->prefix($ct));
147  }
148  $ret = "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILINS, "<strong>" . $module->name() . "</strong>") . "&nbsp;" . _AM_SYSTEM_MODULES_ERRORSC . "<br />";
149  foreach ($errs as $err) {
150  $ret .= " - " . $err . "<br />";
151  }
152  $ret .= "</p>";
153  unset($module);
154  unset($created_tables);
155  unset($errs);
156  unset($msgs);
157  return $ret;
158  } else {
159  $newmid = $module->getVar('mid');
160  unset($created_tables);
161  $msgs[] = "<p>" . _AM_SYSTEM_MODULES_INSERT_DATA_DONE . sprintf(_AM_SYSTEM_MODULES_MODULEID, "<strong>" . $newmid . "</strong>");
162  $tplfile_handler =& xoops_gethandler('tplfile');
163  $templates = $module->getInfo('templates');
164  if ($templates != false) {
166  foreach ($templates as $tpl) {
167  $tplfile =& $tplfile_handler->create();
168  $type = (isset($tpl['type']) ? $tpl['type'] : 'module');
169  $tpldata =& xoops_module_gettemplate($dirname, $tpl['file'], $type);
170  $tplfile->setVar('tpl_source', $tpldata, true);
171  $tplfile->setVar('tpl_refid', $newmid);
172 
173  $tplfile->setVar('tpl_tplset', 'default');
174  $tplfile->setVar('tpl_file', $tpl['file']);
175  $tplfile->setVar('tpl_desc', $tpl['description'], true);
176  $tplfile->setVar('tpl_module', $dirname);
177  $tplfile->setVar('tpl_lastmodified', time());
178  $tplfile->setVar('tpl_lastimported', time());
179  $tplfile->setVar('tpl_type', $type);
180  if (!$tplfile_handler->insert($tplfile)) {
181  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, "<strong>" . $tpl['file'] . "</strong>") . "</span>";
182  } else {
183  $newtplid = $tplfile->getVar('tpl_id');
184  $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, "<strong>" . $tpl['file'] . "</strong>") . "(ID: <strong>" . $newtplid . "</strong>)";
185  // generate compiled file
186  include_once XOOPS_ROOT_PATH . '/class/template.php';
187  if (!xoops_template_touch($newtplid)) {
188  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED_FAILED, "<strong>" . $tpl['file'] . "</strong>") . "</span>";
189  } else {
190  $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED, "<strong>" . $tpl['file'] . "</strong>");
191  }
192  }
193  unset($tplfile, $tpldata);
194  }
195  }
196  include_once XOOPS_ROOT_PATH . '/class/template.php';
198  $blocks = $module->getInfo('blocks');
199  if ($blocks != false) {
201  foreach ($blocks as $blockkey => $block) {
202  // break the loop if missing block config
203  if (!isset($block['file']) || !isset($block['show_func'])) {
204  break;
205  }
206  $options = '';
207  if (!empty($block['options'])) {
208  $options = trim($block['options']);
209  }
210  $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq');
211  $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : '';
212  $template = '';
213  if ((isset($block['template']) && trim($block['template']) != '')) {
214  $content =& xoops_module_gettemplate($dirname, $block['template'], 'blocks');
215  }
216  if (empty($content)) {
217  $content = '';
218  } else {
219  $template = trim($block['template']);
220  }
221  $block_name = addslashes(trim($block['name']));
222  $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() . ")";
223  if (!$db->query($sql)) {
224  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD_ERROR, "<strong>" . $block['name'] . "</strong>") . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD_ERROR_DATABASE, "<strong>" . $db->error() . "</strong>") . "</span>";
225  } else {
226  if (empty($newbid)) {
227  $newbid = $db->getInsertId();
228  }
229  $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD, "<strong>" . $block['name'] . "</strong>") . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>" . $newbid . "</strong>");
230  $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
231  $db->query($sql);
232  if ($template != '') {
233  $tplfile =& $tplfile_handler->create();
234  $tplfile->setVar('tpl_refid', $newbid);
235  $tplfile->setVar('tpl_source', $content, true);
236  $tplfile->setVar('tpl_tplset', 'default');
237  $tplfile->setVar('tpl_file', $block['template']);
238  $tplfile->setVar('tpl_module', $dirname);
239  $tplfile->setVar('tpl_type', 'block');
240  $tplfile->setVar('tpl_desc', $block['description'], true);
241  $tplfile->setVar('tpl_lastimported', 0);
242  $tplfile->setVar('tpl_lastmodified', time());
243  if (!$tplfile_handler->insert($tplfile)) {
244  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, "<strong>" . $block['template'] . "</strong>") . "</span>";
245  } else {
246  $newtplid = $tplfile->getVar('tpl_id');
247  $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, "<strong>" . $block['template'] . "</strong>") . " (ID: <strong>" . $newtplid . "</strong>)";
248  // generate compiled file
249  include_once XOOPS_ROOT_PATH . '/class/template.php';
250  if (!xoops_template_touch($newtplid)) {
251  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED_FAILED, "<strong>" . $block['template'] . "</strong>") . "</span>";
252 
253  } else {
254  $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED, "<strong>" . $block['template'] . "</strong>");
255  }
256  }
257  unset($tplfile);
258  }
259  }
260  unset($content);
261  }
262  unset($blocks);
263  }
264  $configs = $module->getInfo('config');
265  if ($configs != false) {
266  if ($module->getVar('hascomments') != 0) {
267  include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
268  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)));
269  array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0));
270  }
271  } else {
272  if ($module->getVar('hascomments') != 0) {
273  $configs = array();
274  include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
275  $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));
276  $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0);
277  }
278  }
279  // RMV-NOTIFY
280  if ($module->getVar('hasnotification') != 0) {
281  if (empty($configs)) {
282  $configs = array();
283  }
284  // Main notification options
285  include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
286  include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
287  $options = array();
288  $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
289  $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
290  $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
291  $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
292 
293  $configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options);
294  // Event-specific notification options
295  // FIXME: doesn't work when update module... can't read back the array of options properly... " changing to &quot;
296  $options = array();
297  $categories =& notificationCategoryInfo('', $module->getVar('mid'));
298  foreach ($categories as $category) {
299  $events =& notificationEvents ($category['name'], false, $module->getVar('mid'));
300  foreach ($events as $event) {
301  if (!empty($event['invisible'])) {
302  continue;
303  }
304  $option_name = $category['title'] . ' : ' . $event['title'];
305  $option_value = $category['name'] . '-' . $event['name'];
306  $options[$option_name] = $option_value;
307  }
308  unset($events);
309  }
310  unset($categories);
311  $configs[] = array ('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options);
312  }
313 
314  if ($configs != false) {
316  $config_handler =& xoops_gethandler('config');
317  $order = 0;
318  foreach ($configs as $config) {
319  $confobj =& $config_handler->createConfig();
320  $confobj->setVar('conf_modid', $newmid);
321  $confobj->setVar('conf_catid', 0);
322  $confobj->setVar('conf_name', $config['name']);
323  $confobj->setVar('conf_title', $config['title'], true);
324  $confobj->setVar('conf_desc', $config['description'], true);
325  $confobj->setVar('conf_formtype', $config['formtype']);
326  $confobj->setVar('conf_valuetype', $config['valuetype']);
327  $confobj->setConfValueForInput($config['default'], true);
328  $confobj->setVar('conf_order', $order);
329  $confop_msgs = '';
330  if (isset($config['options']) && is_array($config['options'])) {
331  foreach ($config['options'] as $key => $value) {
332  $confop =& $config_handler->createConfigOption();
333  $confop->setVar('confop_name', $key, true);
334  $confop->setVar('confop_value', $value, true);
335  $confobj->setConfOptions($confop);
336  $confop_msgs .= '<br />&nbsp;&nbsp;&nbsp;&nbsp; ' . _AM_SYSTEM_MODULES_CONFIG_ADD . _AM_SYSTEM_MODULES_NAME . ' <strong>' . ( defined($key) ? constant($key) : $key ) . '</strong> ' . _AM_SYSTEM_MODULES_VALUE . ' <strong>' . $value . '</strong> ';
337  unset($confop);
338  }
339  }
340  $order++;
341  if ($config_handler->insertConfig($confobj) != false) {
342  $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, "<strong>" . $config['name'] . "</strong>") . $confop_msgs;
343 
344  } else {
345  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, "<strong>" . $config['name'] . "</strong>") . "</span>";
346  }
347  unset($confobj);
348  }
349  unset($configs);
350  }
351  }
352  if ($module->getInfo('hasMain')) {
353  $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
354  } else {
355  $groups = array(XOOPS_GROUP_ADMIN);
356  }
357  // retrieve all block ids for this module
358  $blocks = XoopsBlock::getByModule($newmid, false);
360  $gperm_handler =& xoops_gethandler('groupperm');
361  foreach ($groups as $mygroup) {
362  if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) {
363  $mperm =& $gperm_handler->create();
364  $mperm->setVar('gperm_groupid', $mygroup);
365  $mperm->setVar('gperm_itemid', $newmid);
366  $mperm->setVar('gperm_name', 'module_admin');
367  $mperm->setVar('gperm_modid', 1);
368  if (!$gperm_handler->insert($mperm)) {
369  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_ADMIN_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>";
370  } else {
371  $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_ACCESS_ADMIN_ADD, "<strong>" . $mygroup . "</strong>");
372  }
373  unset($mperm);
374  }
375  $mperm =& $gperm_handler->create();
376  $mperm->setVar('gperm_groupid', $mygroup);
377  $mperm->setVar('gperm_itemid', $newmid);
378  $mperm->setVar('gperm_name', 'module_read');
379  $mperm->setVar('gperm_modid', 1);
380  if (!$gperm_handler->insert($mperm)) {
381  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_USER_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>";
382  } else {
383  $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_ACCESS_USER_ADD_ERROR, "<strong>" . $mygroup . "</strong>");
384  }
385  unset($mperm);
386  foreach ($blocks as $blc) {
387  $bperm =& $gperm_handler->create();
388  $bperm->setVar('gperm_groupid', $mygroup);
389  $bperm->setVar('gperm_itemid', $blc);
390  $bperm->setVar('gperm_name', 'block_read');
391  $bperm->setVar('gperm_modid', 1);
392  if (!$gperm_handler->insert($bperm)) {
393  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR . ' Block ID: <strong>' . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>';
394  } else {
395  $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_BLOCK_ACCESS . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>" . $blc . "</strong>") . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, "<strong>" . $mygroup . "</strong>");
396  }
397  unset($bperm);
398  }
399  }
400  unset($blocks);
401  unset($groups);
402 
403  // execute module specific install script if any
404  $func = "xoops_module_install_{$dirname}";
405  if (function_exists($func)) {
406  if (!$lastmsg = $func($module)) {
407  $msgs[] = "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . "</p>";
408  } else {
409  $msgs[] = "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>";
410  if (is_string($lastmsg)) {
411  $msgs[] = $lastmsg;
412  }
413  }
414  }
415 
416  $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKINS, '<strong>' . $module->getVar('name', 's') . '</strong>');
417  $msgs[] = '</div></div>';
418 
419  $blocks = $module->getInfo('blocks');
420  $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a> |
421  <a href="admin.php?fct=modulesadmin&op=installlist">' . _AM_SYSTEM_MODULES_TOINSTALL . '</a> | ';
422  $msgs[] = '<br /><span class="red bold">' . _AM_SYSTEM_MODULES_MODULE . ' ' . $module->getInfo('name') . ': </span></div>';
423  if ($blocks != false) {
424  $msgs[] = '<div class="center"><a href="admin.php?fct=blocksadmin&op=list&filter=1&selgen=' . $newmid . '&selmod=-2&selgrp=-1&selvis=-1&filsave=1">' . _AM_SYSTEM_BLOCKS . '</a></div>';
425  }
426  ;
427  $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=preferences&op=showmod&mod=' . $newmid . '">' . _AM_SYSTEM_PREF . '</a>';
428  $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a></div>';
429 
430  $ret = implode('<br />', $msgs);
431  unset($blocks);
432  unset($msgs);
433  unset($errs);
434  unset($module);
435  return $ret;
436  } else {
437  $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $dirname . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br />' . implode("<br />", $errs) . '</p>';
438  unset($msgs);
439  unset($errs);
440  return $ret;
441  }
442  }
443  else {
444  return "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILINS, "<strong>" . $dirname . "</strong>") . "&nbsp;" . _AM_SYSTEM_MODULES_ERRORSC . "<br />&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_ALEXISTS, $dirname) . "</p>";
445  }
446 }
447 
448 function &xoops_module_gettemplate($dirname, $template, $type = '')
449 {
450  global $xoopsConfig;
451  $ret = '';
452  switch ($type) {
453  case 'blocks': case 'admin':
454  $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/' . $type . '/' . $template;
455  break;
456  default:
457  $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/' . $template;
458  break;
459  }
460  if (!file_exists($path)) {
461  return $ret;
462  } else {
463  $lines = file($path);
464  }
465  if (!$lines) {
466  return $ret;
467  }
468  $count = count($lines);
469  for ($i = 0; $i < $count; $i++) {
470  $ret .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $lines[$i]));
471  }
472  return $ret;
473 }
474 
476 {
477  global $xoopsConfig;
478  $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');
480  $module_handler =& xoops_gethandler('module');
481  $module = $module_handler->getByDirname($dirname);
482  include_once XOOPS_ROOT_PATH . '/class/template.php';
484  if ($module->getVar('dirname') == 'system') {
485  return "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, "<strong>" . $module->getVar('name') . "</strong>") . "&nbsp;" . _AM_SYSTEM_MODULES_ERRORSC . "<br /> - " . _AM_SYSTEM_MODULES_SYSNO . "</p>";
486  } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
487  return "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, "<strong>" . $module->getVar('name') . "</strong>") . "&nbsp;" . _AM_SYSTEM_MODULES_ERRORSC . "<br /> - " . _AM_SYSTEM_MODULES_STRTNO . "</p>";
488  } else {
489  $msgs = array();
490  $msgs[] = '<div id="xo-module-log"><div class="header">';
491  $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UNINSTAL . $module->getInfo('name', 's') . '</h4>';
492  if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
493  $msgs[] ='<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
494  }
495  $msgs[] ='<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version');
496  if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
497  $msgs[] ='<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')));
498  }
499  $msgs[] = '</div><div class="logger">';
500  // Load module specific install script if any
501  $uninstall_script = $module->getInfo('onUninstall');
502  if ($uninstall_script && trim($uninstall_script) != '') {
503  include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($uninstall_script);
504  }
505  $func = "xoops_module_pre_uninstall_{$dirname}";
506  // If pre uninstall function is defined, execute
507  if (function_exists($func)) {
508  $result = $func($module);
509  if (false === $result) {
510  $errs = $module->getErrors();
511  $errs[] = sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func);
512  return "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, "<strong>" . $module->getVar('name') . "</strong>") . "&nbsp;" . _AM_SYSTEM_MODULES_ERRORSC . "<br />" . implode("<br />", $errs) . "</p>";
513  } else {
514  $msgs = $module->getErrors();
515  array_unshift($msgs, "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>");
516  }
517  }
518 
519  if (false === $module_handler->delete($module)) {
520  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_DELETE_ERROR, $module->getVar('name')) . '</span>';
521  } else {
522 
523  // delete template files
524  $tplfile_handler = xoops_gethandler('tplfile');
525  $templates = $tplfile_handler->find(null, 'module', $module->getVar('mid'));
526  $tcount = count($templates);
527  if ($tcount > 0) {
529  for ($i = 0; $i < $tcount; $i++) {
530  if (false === $tplfile_handler->delete($templates[$i])) {
531  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_DATA_FAILD, $templates[$i]->getVar('tpl_file')) . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, "<strong>" . $templates[$i]->getVar('tpl_id') . "</strong>") . '</span>';
532  } else {
533  $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_DATA, "<strong>" . $templates[$i]->getVar('tpl_file') . "</strong>") . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, "<strong>" . $templates[$i]->getVar('tpl_id') . "</strong>");
534  }
535  }
536  }
537  unset($templates);
538 
539  // delete blocks and block tempalte files
540  $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
541  if (is_array($block_arr)) {
542  $bcount = count($block_arr);
544  for ($i = 0; $i < $bcount; $i++) {
545  if (false === $block_arr[$i]->delete()) {
546  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, "<strong>" . $block_arr[$i]->getVar('name') . "</strong>") . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>" . $block_arr[$i]->getVar('bid') . "</strong>") . '</span>';
547  } else {
548  $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE,"<strong>" . $block_arr[$i]->getVar('name') . "</strong>") . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>" . $block_arr[$i]->getVar('bid') . "</strong>");
549  }
550  if ($block_arr[$i]->getVar('template') != '') {
551  $templates = $tplfile_handler->find(null, 'block', $block_arr[$i]->getVar('bid'));
552  $btcount = count($templates);
553  if ($btcount > 0) {
554  for ($j = 0; $j < $btcount; $j++) {
555  if (!$tplfile_handler->delete($templates[$j])) {
556  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_TEMPLATE_ERROR, $templates[$j]->getVar('tpl_file')).sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, "<strong>".$templates[$j]->getVar('tpl_id') . "</strong>") . '</span>';
557  } else {
558  $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_DATA, "<strong>" . $templates[$j]->getVar('tpl_file') . "</strong>") . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, "<strong>" . $templates[$j]->getVar('tpl_id') . "</strong>");
559  }
560  }
561  }
562  unset($templates);
563  }
564  }
565  }
566 
567  // delete tables used by this module
568  $modtables = $module->getInfo('tables');
569  if ($modtables != false && is_array($modtables)) {
571  foreach ($modtables as $table) {
572  // prevent deletion of reserved core tables!
573  if (!in_array($table, $reservedTables)) {
574  $sql = 'DROP TABLE ' . $db->prefix($table);
575  if (!$db->query($sql)) {
576  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED_ERROR, "<strong>" . $db->prefix($table) . "<strong>") . "</span>";
577  } else {
578  $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED, "<strong>" . $db->prefix($table) . "</strong>");
579  }
580  } else {
581  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED_FAILDED, "<strong>" . $db->prefix($table) . "</strong>") . "</span>";
582  }
583  }
584  }
585 
586  // delete comments if any
587  if ($module->getVar('hascomments') != 0) {
589  $comment_handler =& xoops_gethandler('comment');
590  if (false === $comment_handler->deleteByModule($module->getVar('mid'))) {
591  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_COMMENTS_DELETE_ERROR . '</span>';
592  } else {
593  $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_COMMENTS_DELETED;
594  }
595  }
596 
597  // RMV-NOTIFY
598  // delete notifications if any
599  if ($module->getVar('hasnotification') != 0) {
601  if (false === xoops_notification_deletebymodule($module->getVar('mid'))) {
602  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETE_ERROR . '</span>';
603  } else {
604  $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETED;
605  }
606  }
607 
608  // delete permissions if any
609  $gperm_handler =& xoops_gethandler('groupperm');
610  if (false === $gperm_handler->deleteByModule($module->getVar('mid'))) {
611  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_GROUP_PERMS_DELETE_ERROR . '</span>';
612  } else {
613  $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GROUP_PERMS_DELETED;
614  }
615 
616  // delete module config options if any
617  if ($module->getVar('hasconfig') != 0 || $module->getVar('hascomments') != 0) {
618  $config_handler =& xoops_gethandler('config');
619  $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
620  $confcount = count($configs);
621  if ($confcount > 0) {
623  for ($i = 0; $i < $confcount; $i++) {
624  if (false === $config_handler->deleteConfig($configs[$i])) {
625  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_CONFIG_DATA_DELETE_ERROR . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, "<strong>" . $configs[$i]->getvar('conf_id') . "</strong>") . '</span>';
626  } else {
627  $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, "<strong>" . $configs[$i]->getvar('conf_id') . "</strong>");
628  }
629  }
630  }
631  }
632 
633  // execute module specific install script if any
634  $func = 'xoops_module_uninstall_' . $dirname;
635  if (function_exists($func)) {
636  if (!$func($module)) {
637  $msgs[] = "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . "</p>";
638  } else {
639  $msgs[] = "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>";
640  }
641  }
642  $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKUNINS, "<strong>" . $module->getVar('name') . "</strong>") . '</p>';
643  }
644  $msgs[] = '</div></div>';
645  $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
646  $ret = implode("<br />", $msgs);
647  return $ret;
648  }
649 }
650 
652 {
653  // Get module handler
654  $module_handler =& xoops_gethandler('module');
655  $module = $module_handler->get($mid);
656  include_once XOOPS_ROOT_PATH . '/class/template.php';
658  // Display header
659  $msgs[] = '<div id="xo-module-log">';
661  // Change value
662  $module->setVar('isactive', 1);
663  if (!$module_handler->insert($module)) {
664  $msgs[] = '<p>' . sprintf( _AM_SYSTEM_MODULES_FAILACT, '<strong>' . $module->getVar('name', 's') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br />' . $module->getHtmlErrors() . '</p>';
665  } else {
666  $blocks = XoopsBlock::getByModule($module->getVar('mid'));
667  $bcount = count($blocks);
668  for ($i = 0; $i < $bcount; $i++) {
669  $blocks[$i]->setVar('isactive', 1);
670  $blocks[$i]->store();
671  }
672  $msgs[] = '<p>' . sprintf( _AM_SYSTEM_MODULES_OKACT, '<strong>' . $module->getVar('name', 's') . '</strong>') . '</p></div>';
673  }
674  //$msgs[] = '</div>';
675  $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
676  $ret = implode('<br />', $msgs);
677  return $ret;
678 }
679 
681 {
682  global $xoopsConfig;
683  // Get module handler
684  $module_handler =& xoops_gethandler('module');
685  $module = $module_handler->get($mid);
686  include_once XOOPS_ROOT_PATH . '/class/template.php';
688  // Display header
689  $msgs[] = '<div id="xo-module-log">';
691  // Change value
692  $module->setVar('isactive', 0);
693  if ($module->getVar('dirname') == "system") {
694  $msgs[] = '<p>' . sprintf( _AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br /> - ' . _AM_SYSTEM_MODULES_SYSNO . '</p>';
695  } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
696  $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br /> - ' . _AM_SYSTEM_MODULES_STRTNO . '</p>';
697  } else {
698  if (!$module_handler->insert($module)) {
699  $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br />' . $module->getHtmlErrors() . '</p>';
700  } else {
701  $blocks = XoopsBlock::getByModule($module->getVar('mid'));
702  $bcount = count($blocks);
703  for ($i = 0; $i < $bcount; $i++) {
704  $blocks[$i]->setVar('isactive', 0);
705  $blocks[$i]->store();
706  }
707  $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '</p>';
708  }
709  }
710  $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
711  $ret = implode('<br />', $msgs);
712  return $ret;
713 }
714 
715 function xoops_module_change($mid, $name)
716 {
717  $module_handler =& xoops_gethandler('module');
718  $module = $module_handler->get($mid);
719  $module->setVar('name', $name);
721  if (!$module_handler->insert($module)) {
722  $ret = "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILORDER, "<strong>" . $myts->stripSlashesGPC($name) . "</strong>") . "&nbsp;" . _AM_SYSTEM_MODULES_ERRORSC . "<br />";
723  $ret .= $module->getHtmlErrors() . "</p>";
724  return $ret;
725  }
726  return "<p>" . sprintf(_AM_SYSTEM_MODULES_OKORDER, "<strong>" . $myts->stripSlashesGPC($name) . "</strong>") . "</p>";
727 }
728 
730 {
731  $msgs[] = '<div class="header">';
732  $msgs[] = $errs[] = '<h4>' . $title . $module->getInfo('name', 's') . '</h4>';
733  if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
734  $msgs[] ='<img src="' . XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/' . trim($module->getInfo('image')) . '" alt="" />';
735  }
736  $msgs[] ='<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version');
737  if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
738  $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')));
739  }
740  $msgs[] = '</div>';
741 
742  return $msgs;
743 }
744 
745 ?>