XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
main.php
Go to the documentation of this file.
1 <?php
2 // $Id: main.php 10981 2013-02-04 19:37:48Z trabis $
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 // Check users rights
33 if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit(_NOPERM);
34 
35 include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
36 include_once XOOPS_ROOT_PATH . '/modules/system/admin/modulesadmin/modulesadmin.php';
37 
38 if ( isset($_POST) ) {
39  foreach ( $_POST as $k => $v ) {
40  ${$k} = $v;
41  }
42 }
43 
44 // Get Action type
45 $op = system_CleanVars ( $_REQUEST, 'op', 'list', 'string' );
46 $module = system_CleanVars ( $_REQUEST, 'module', '', 'string' );
47 
48 if (in_array($op, array('confirm', 'submit', 'install_ok', 'update_ok', 'uninstall_ok'))) {
49  if (!$GLOBALS['xoopsSecurity']->check()) {
50  $op = 'list';
51  }
52 }
53 $myts =& MyTextsanitizer::getInstance();
54 
55 switch ($op) {
56 
57  case 'list':
58  // Define main template
59  $xoopsOption['template_main'] = 'system_modules.html';
60  // Call Header
62  // Define Stylesheet
63  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
64  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
65  // Define scripts
66  $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
67  $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
68  $xoTheme->addScript('modules/system/js/admin.js');
69  $xoTheme->addScript('modules/system/js/module.js');
70  // Define Breadcrumb and tips
71  $xoBreadCrumb->addLink( _AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath') );
72  $xoBreadCrumb->addHelp( system_adminVersion('modulesadmin', 'help') );
74  $xoBreadCrumb->render();
75  // Get Module Handler
76  $module_handler =& xoops_gethandler('module');
77  $criteria = new CriteriaCompo();
78  $criteria->setSort('weight');
79  $criteria->setOrder('ASC');
80  // Get all installed modules
81  $installed_mods = $module_handler->getObjects( $criteria );
82  $listed_mods = array();
83  $i = 0;
84  $install_mods = array();
85  foreach ( $installed_mods as $module ) {
86  $listed_mods[$i] = $module->toArray();
87  $listed_mods[$i]['image'] = $module->getInfo('image');
88  $listed_mods[$i]['adminindex'] = $module->getInfo('adminindex');
89  $listed_mods[$i]['version'] = round( $module->getVar('version') / 100, 2 );
90  $listed_mods[$i]['last_update'] = formatTimestamp( $module->getVar('last_update'), 'm' );
91  $listed_mods[$i]['author'] = $module->getInfo('author');
92  $listed_mods[$i]['credits'] = $module->getInfo('credits');
93  $listed_mods[$i]['license'] = $module->getInfo('license');
94  $listed_mods[$i]['description'] = $module->getInfo('description');
95  if ( round( $module->getInfo( 'version' ), 2 ) != $listed_mods[$i]['version']){
96  $listed_mods[$i]['warning_update'] = true;
97  }else{
98  $listed_mods[$i]['warning_update'] = false;
99  }
100  $install_mods[] = $module->getInfo('dirname');
101  unset($module);
102  $i++;
103  }
104  // Get module to install
105  $dirlist = XoopsLists::getModulesList();
106  $toinstall_mods = array();
107  $i=0;
108  foreach ($dirlist as $file) {
109  if ( file_exists( XOOPS_ROOT_PATH . '/modules/' . $file . '/xoops_version.php' ) ) {
110  clearstatcache();
111  $file = trim($file);
112  if ( !in_array($file, $install_mods) ) {
113  $i++;
114  }
115  }
116  }
117  $xoopsTpl->assign('toinstall_nb', $i);
118 
119  $xoopsTpl->assign('install_mods', $listed_mods);
120  $xoopsTpl->assign('mods_popup', $listed_mods);
121 
122  // Call Footer
123  xoops_cp_footer();
124  break;
125 
126  case 'installlist':
127  // Define main template
128  $xoopsOption['template_main'] = 'system_modules.html';
129  // Call Header
130  xoops_cp_header();
131  // Define Stylesheet
132  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
133  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
134  // Define scripts
135  $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
136  $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
137  $xoTheme->addScript('modules/system/js/admin.js');
138  // Define Breadcrumb and tips
139  $xoBreadCrumb->addLink( _AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath') );
141  $xoBreadCrumb->addHelp( system_adminVersion('modulesadmin', 'help') . '#install' );
143  $xoBreadCrumb->render();
144  // Get Module Handler
145  $module_handler =& xoops_gethandler('module');
146  // Get all installed modules
147  $installed_mods = $module_handler->getObjects();
148  foreach ( $installed_mods as $module ) {
149  $install_mods[] = $module->getInfo('dirname');
150  }
151  // Get module to install
152  $dirlist = XoopsLists::getModulesList();
153  $toinstall_mods = array();
154  $i=0;
155  foreach ($dirlist as $file) {
156  if ( file_exists( XOOPS_ROOT_PATH . '/modules/' . $file . '/xoops_version.php' ) ) {
157  clearstatcache();
158  $file = trim($file);
159  if ( !in_array($file, $install_mods) ) {
160  $module =& $module_handler->create();
161  $module->loadInfo($file);
162  $toinstall_mods[$i]['name'] = $module->getInfo('name');
163  $toinstall_mods[$i]['dirname'] = $module->getInfo('dirname');
164  $toinstall_mods[$i]['image'] = $module->getInfo('image');
165  $toinstall_mods[$i]['version'] = round($module->getInfo('version'), 2);
166  $toinstall_mods[$i]['author'] = $module->getInfo('author');
167  $toinstall_mods[$i]['credits'] = $module->getInfo('credits');
168  $toinstall_mods[$i]['license'] = $module->getInfo('license');
169  $toinstall_mods[$i]['description'] = $module->getInfo('description');
170  $toinstall_mods[$i]['mid'] = $i; // Use only for display popup
171  unset($module);
172  $i++;
173  }
174  }
175  }
176  $xoopsTpl->assign('toinstall_mods', $toinstall_mods);
177  $xoopsTpl->assign('mods_popup', $toinstall_mods);
178  // Call Footer
179  xoops_cp_footer();
180  //xoops_module_list();
181  break;
182 
183  case 'order':
184  // Get Module Handler
185  $module_handler =& xoops_gethandler('module');
186  if ( isset($_POST['mod']) ) {
187  $i=1;
188  foreach ($_POST['mod'] as $order) {
189  if( $order > 0 ) {
190  $module = $module_handler->get($order);
191  //Change order only for visible modules
192  if ($module->getVar('weight') != 0) {
193  $module->setVar('weight', $i);
194  if (!$module_handler->insert($module)) {
195  $error=true;
196  }
197  $i++;
198  }
199  }
200  }
201  }
202  exit;
203  break;
204 
205  case 'confirm':
206  // Define main template
207  $xoopsOption['template_main'] = 'system_modules_confirm.html';
208  // Call Header
209  xoops_cp_header();
210  // Define Stylesheet
211  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
212  // Define Breadcrumb and tips
213  $xoBreadCrumb->addLink( _AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath') );
215  $xoBreadCrumb->addHelp( system_adminVersion('modulesadmin', 'help') . '#confirm' );
217  $xoBreadCrumb->render();
218  $error = array();
219  if ( !is_writable(XOOPS_CACHE_PATH.'/') ) {
220  // attempt to chmod 666
221  if ( !chmod(XOOPS_CACHE_PATH.'/', 0777) ) {
222  $error[] = sprintf(_MUSTWABLE, "<strong>".XOOPS_CACHE_PATH.'/</strong>');
223  }
224  }
225  if ( count($error) > 0 ) {
226  // Display Error
228  // Call Footer
229  xoops_cp_footer();
230  exit();
231  }
232  $i = 0;
233  $modifs_mods = array();
234  $module = empty($_POST['module']) ? array() : $_POST['module'];
235  foreach ($module as $mid) {
236  $mid = (int) $mid;
237  $modifs_mods[$i]['mid'] = $mid;
238  $modifs_mods[$i]['oldname'] = $myts->htmlspecialchars($myts->stripSlashesGPC($oldname[$mid]));
239  $modifs_mods[$i]['newname'] = $myts->htmlspecialchars(trim($myts->stripslashesGPC($newname[$mid])));
240  $modifs_mods[$i]['newstatus'] = (isset($newstatus[$mid])) ? $myts->htmlspecialchars($newstatus[$mid]) : 0;
241  $i++;
242  }
243  $xoopsTpl->assign('modifs_mods', $modifs_mods);
244  $xoopsTpl->assign('input_security', $GLOBALS['xoopsSecurity']->getTokenHTML());
245  // Call Footer
246  xoops_cp_footer();
247  break;
248 
249  case 'display':
250  // Get module handler
251  $module_handler =& xoops_gethandler('module');
252  $module_id = system_CleanVars ( $_POST, 'mid', 0, 'int' );
253  if ( $module_id > 0 ) {
254  $module =& $module_handler->get( $module_id );
255  $old = $module->getVar('isactive');
256  // Set value
257  $module->setVar('isactive', !$old );
258  if (!$module_handler->insert($module)) {
259  $error=true;
260  }
262  $bcount = count($blocks);
263  for ($i = 0; $i < $bcount; $i++) {
264  $blocks[$i]->setVar('isactive', !$old);
265  $blocks[$i]->store();
266  }
267  //Set active modules in cache folder
269  }
270  break;
271 
272  case 'display_in_menu':
273  // Get module handler
274  $module_handler =& xoops_gethandler('module');
275  $module_id = system_CleanVars ( $_POST, 'mid', 0, 'int' );
276  if ( $module_id > 0 ) {
277  $module =& $module_handler->get($module_id);
278  $old = $module->getVar('weight');
279  // Set value
280  $module->setVar('weight', !$old );
281  if (!$module_handler->insert($module)) {
282  $error=true;
283  }
284  }
285  break;
286 
287  case 'submit':
288  $ret = array();
289  $write = false;
290  $module = empty($_POST['module']) ? array() : $_POST['module'];
291  foreach ($module as $mid) {
292  if (isset($newstatus[$mid]) && $newstatus[$mid] ==1) {
293  if ($oldstatus[$mid] == 0) {
294  $ret[] = xoops_module_activate($mid);
295  }
296  } else {
297  if ($oldstatus[$mid] == 1) {
298  $ret[] = xoops_module_deactivate($mid);
299  }
300  }
301  $newname[$mid] = trim($newname[$mid]);
302  if ($oldname[$mid] != $newname[$mid] ) {
303  $ret[] = xoops_module_change($mid, $newname[$mid]);
304  $write = true;
305  }
306  }
307  if ( $write ) {
308  // Flush cache files for cpanel GUIs
309  xoops_load('cpanel', 'system');
311  }
312 
313  //Set active modules in cache folder
315  // Define main template
316  $xoopsOption['template_main'] = 'system_modules_confirm.html';
317  // Call Header
318  xoops_cp_header();
319  // Define Stylesheet
320  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
321  // Define Breadcrumb and tips
322  $xoBreadCrumb->addLink( _AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath') );
324  $xoBreadCrumb->addHelp( system_adminVersion('modulesadmin', 'help') . '#submit' );
325  $xoBreadCrumb->render();
326  if ( count($ret) > 0 ) {
327  $xoopsTpl->assign('result', $ret);
328  }
329  // Call Footer
330  xoops_cp_footer();
331  break;
332 
333  case 'install':
334  $module = $myts->htmlspecialchars($module);
335  // Get module handler
336  $module_handler =& xoops_gethandler('module');
337  $mod =& $module_handler->create();
338  $mod->loadInfoAsVar($module);
339  // Construct message
340  if ($mod->getInfo('image') != false && trim($mod->getInfo('image')) != '') {
341  $msgs ='<img src="' . XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . trim($mod->getInfo('image')) . '" alt="" />';
342  }
343  $msgs .= '<br /><span style="font-size:smaller;">' . $mod->getVar('name', 's') . '</span><br /><br />' . _AM_SYSTEM_MODULES_RUSUREINS;
344  // Call Header
345  xoops_cp_header();
346  // Define Stylesheet
347  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
348  // Define Breadcrumb and tips
349  $xoBreadCrumb->addLink( _AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath') );
351  $xoBreadCrumb->addHelp( system_adminVersion('modulesadmin', 'help') . '#install' );
352  $xoBreadCrumb->render();
353  // Display question message
354  xoops_confirm(array('module' => $module, 'op' => 'install_ok', 'fct' => 'modulesadmin'), 'admin.php', $msgs, _AM_SYSTEM_MODULES_INSTALL);
355  // Call Footer
356  xoops_cp_footer();
357  break;
358 
359  case 'install_ok':
360  $ret = array();
361  $ret[] = xoops_module_install($module);
362  // Flush cache files for cpanel GUIs
363  xoops_load('cpanel', 'system');
365  //Set active modules in cache folder
367  // Define main template
368  $xoopsOption['template_main'] = 'system_header.html';
369  // Call Header
370  xoops_cp_header();
371  // Define Stylesheet
372  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
373  // Define Breadcrumb and tips
374  $xoBreadCrumb->addLink( _AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath') );
376  $xoBreadCrumb->addHelp( system_adminVersion('modulesadmin', 'help') . '#install' );
377  $xoBreadCrumb->render();
378  if (count($ret) > 0) {
379  foreach ($ret as $msg) {
380  if ($msg != '') {
381  echo $msg;
382  }
383  }
384  }
385  // Call Footer
386  xoops_cp_footer();
387  break;
388 
389  case 'uninstall':
390  $module = $myts->htmlspecialchars($module);
391  // Get module handler
392  $module_handler =& xoops_gethandler('module');
393  $mod =& $module_handler->getByDirname($module);
394  // Construct message
395  if ($mod->getInfo('image') != false && trim($mod->getInfo('image')) != '') {
396  $msgs ='<img src="' . XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . trim($mod->getInfo('image')) . '" alt="" />';
397  }
398  $msgs .= '<br /><span style="font-size:smaller;">' . $mod->getVar('name') . '</span><br /><br />' . _AM_SYSTEM_MODULES_RUSUREUNINS;
399  // Call Header
400  xoops_cp_header();
401  // Define Stylesheet
402  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
403  // Define Breadcrumb and tips
404  $xoBreadCrumb->addLink( _AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath') );
406  $xoBreadCrumb->addHelp( system_adminVersion('modulesadmin', 'help') . '#delete' );
407  $xoBreadCrumb->render();
408  // Display Question
409  xoops_confirm(array('module' => $module, 'op' => 'uninstall_ok', 'fct' => 'modulesadmin'), 'admin.php', $msgs, _AM_SYSTEM_MODULES_UNINSTALL);
410  // Call Footer
411  xoops_cp_footer();
412  break;
413 
414  case 'uninstall_ok':
415  $ret = array();
416  $ret[] = xoops_module_uninstall($module);
417  // Flush cache files for cpanel GUIs
418  xoops_load("cpanel", "system");
420  //Set active modules in cache folder
422  // Define main template
423  $xoopsOption['template_main'] = 'system_header.html';
424  // Call Header
425  xoops_cp_header();
426  // Define Stylesheet
427  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
428  // Define Breadcrumb and tips
429  $xoBreadCrumb->addLink( _AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath') );
431  $xoBreadCrumb->addHelp( system_adminVersion('modulesadmin', 'help') . '#delete' );
432  $xoBreadCrumb->render();
433  if (count($ret) > 0) {
434  foreach ($ret as $msg) {
435  if ($msg != '') {
436  echo $msg;
437  }
438  }
439  }
440  // Call Footer
441  xoops_cp_footer();
442  break;
443 
444  case 'update':
445  $module = $myts->htmlspecialchars($module);
446  // Get module handler
447  $module_handler =& xoops_gethandler('module');
448  $mod =& $module_handler->getByDirname($module);
449  // Construct message
450  if ($mod->getInfo('image') != false && trim($mod->getInfo('image')) != '') {
451  $msgs ='<img src="' . XOOPS_URL . '/modules/' . $mod->getVar('dirname', 'n') . '/' . trim($mod->getInfo('image')) . '" alt="" />';
452  }
453  $msgs .= '<br /><span style="font-size:smaller;">' . $mod->getVar('name', 's') . '</span><br /><br />' . _AM_SYSTEM_MODULES_RUSUREUPD;
454  // Call Header
455  xoops_cp_header();
456  // Define Stylesheet
457  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
458  // Define Breadcrumb and tips
459  $xoBreadCrumb->addLink( _AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath') );
461  $xoBreadCrumb->addHelp( system_adminVersion('modulesadmin', 'help') . '#update' );
462  $xoBreadCrumb->render();
463  // Display message
464  xoops_confirm(array('dirname' => $module, 'op' => 'update_ok', 'fct' => 'modulesadmin'), 'admin.php', $msgs, _AM_SYSTEM_MODULES_UPDATE);
465  // Call Footer
466  xoops_cp_footer();
467  break;
468 
469  case 'update_ok':
470  $dirname = $myts->htmlspecialchars(trim($dirname));
471  $module_handler =& xoops_gethandler('module');
472  $module =& $module_handler->getByDirname($dirname);
473  // Save current version for use in the update function
474  $prev_version = $module->getVar('version');
475  $clearTpl = new XoopsTpl();
476  $clearTpl->clearCache($dirname);
477  // we dont want to change the module name set by admin
478  $temp_name = $module->getVar('name');
479  $module->loadInfoAsVar($dirname);
480  $module->setVar('name', $temp_name);
481  $module->setVar('last_update', time() );
482  // Call Header
483  // Define main template
484  $xoopsOption['template_main'] = 'system_header.html';
485  // Call Header
486  xoops_cp_header();
487  // Define Stylesheet
488  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
489  // Define Breadcrumb and tips
490  $xoBreadCrumb->addLink( _AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath') );
492  $xoBreadCrumb->addHelp( system_adminVersion('modulesadmin', 'help') . '#update' );
493  $xoBreadCrumb->render();
494  if (!$module_handler->insert($module)) {
495  echo '<p>Could not update '.$module->getVar('name').'</p>';
496  echo "<br /><div class='center'><a href='admin.php?fct=modulesadmin'>" . _AM_SYSTEM_MODULES_BTOMADMIN . "</a></div>";
497  } else {
498  $newmid = $module->getVar('mid');
499  $msgs = array();
500  $msgs[] = '<div id="xo-module-log"><div class="header">';
501  $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UPDATING . $module->getInfo('name', 's') . '</h4>';
502  if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
503  $msgs[] ='<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
504  }
505  $msgs[] ='<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version');
506  if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
507  $msgs[] ='<strong>' . _AUTHOR . ':</strong> ' . $myts->htmlspecialchars(trim($module->getInfo('author')));
508  }
509  $msgs[] = '</div><div class="logger">';
511  $tplfile_handler =& xoops_gethandler('tplfile');
512  $deltpl = $tplfile_handler->find('default', 'module', $module->getVar('mid'));
513  $delng = array();
514  if (is_array($deltpl)) {
515  // delete template file entry in db
516  $dcount = count($deltpl);
517  for ($i = 0; $i < $dcount; $i++) {
518  if ( !$tplfile_handler->delete( $deltpl[$i] ) ) {
519  $delng[] = $deltpl[$i]->getVar('tpl_file');
520  }
521  }
522  }
523  $templates = $module->getInfo('templates');
524  if ($templates != false) {
526  foreach ($templates as $tpl) {
527  $tpl['file'] = trim($tpl['file']);
528  if (!in_array($tpl['file'], $delng)) {
529  $type = (isset($tpl['type']) ? $tpl['type'] : 'module');
530  $tpldata =& xoops_module_gettemplate($dirname, $tpl['file'], $type);
531  $tplfile =& $tplfile_handler->create();
532  $tplfile->setVar('tpl_refid', $newmid);
533  $tplfile->setVar('tpl_lastimported', 0);
534  $tplfile->setVar('tpl_lastmodified', time());
535 
536  if (preg_match("/\.css$/i", $tpl['file'])) {
537  $tplfile->setVar('tpl_type', 'css');
538  } else {
539  $tplfile->setVar('tpl_type', $type );
540  }
541  $tplfile->setVar('tpl_source', $tpldata, true);
542  $tplfile->setVar('tpl_module', $dirname);
543  $tplfile->setVar('tpl_tplset', 'default');
544  $tplfile->setVar('tpl_file', $tpl['file'], true);
545  $tplfile->setVar('tpl_desc', $tpl['description'], true);
546  if (!$tplfile_handler->insert($tplfile)) {
547  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, "<strong>".$tpl['file']."</strong>").'</span>';
548  } else {
549  $newid = $tplfile->getVar('tpl_id');
550  $msgs[] = '&nbsp;&nbsp;'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_INSERT_DATA, "<strong>".$tpl['file']."</strong>");
551  if ($xoopsConfig['template_set'] == 'default') {
552  if (!xoops_template_touch($newid)) {
553  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, "<strong>".$tpl['file']."</strong>").'</span>';
554  } else {
555  $msgs[] = '&nbsp;&nbsp;<span>'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, "<strong>".$tpl['file']."</strong>").'</span>';
556  }
557  }
558  }
559  unset($tpldata);
560  } else {
561  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_OLD_ERROR, "<strong>".$tpl['file']."</strong>").'</span>';
562  }
563  }
564  }
565  $blocks = $module->getInfo('blocks');
567  if ($blocks != false) {
568  $showfuncs = array();
569  $funcfiles = array();
570  foreach ($blocks as $i => $block) {
571  if (isset($block['show_func']) && $block['show_func'] != '' && isset($block['file']) && $block['file'] != '') {
572  $editfunc = isset($block['edit_func']) ? $block['edit_func'] : '';
573  $showfuncs[] = $block['show_func'];
574  $funcfiles[] = $block['file'];
575  $template = '';
576  if ((isset($block['template']) && trim($block['template']) != '')) {
577  $content = xoops_module_gettemplate($dirname, $block['template'], 'blocks');
578  }
579  if (!$content) {
580  $content = '';
581  } else {
582  $template = $block['template'];
583  }
584  $options = '';
585  if (!empty($block['options'])) {
586  $options = $block['options'];
587  }
588  $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'])."'";
589  $fresult = $xoopsDB->query($sql);
590  $fcount = 0;
591  while ($fblock = $xoopsDB->fetchArray($fresult)) {
592  $fcount++;
593  $sql = "UPDATE ".$xoopsDB->prefix("newblocks")." SET name='".addslashes($block['name'])."', edit_func='".addslashes($editfunc)."', content='', template='".$template."', last_modified=".time()." WHERE bid=".$fblock['bid'];
594  $result = $xoopsDB->query($sql);
595  if (!$result) {
596  $msgs[] = "&nbsp;&nbsp;".sprintf(_AM_SYSTEM_MODULES_UPDATE_ERROR, $fblock['name']);
597  } else {
598  $msgs[] = "&nbsp;&nbsp;".sprintf(_AM_SYSTEM_MODULES_BLOCK_UPDATE, $fblock['name']).sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>".$fblock['bid']."</strong>");
599  if ($template != '') {
600  $tplfile = $tplfile_handler->find('default', 'block', $fblock['bid']);
601  if (count($tplfile) == 0) {
602  $tplfile_new =& $tplfile_handler->create();
603  $tplfile_new->setVar('tpl_module', $dirname);
604  $tplfile_new->setVar('tpl_refid', $fblock['bid']);
605  $tplfile_new->setVar('tpl_tplset', 'default');
606  $tplfile_new->setVar('tpl_file', $block['template'], true);
607  $tplfile_new->setVar('tpl_type', 'block');
608  } else {
609  $tplfile_new = $tplfile[0];
610  }
611  $tplfile_new->setVar('tpl_source', $content, true);
612  $tplfile_new->setVar('tpl_desc', $block['description'], true);
613  $tplfile_new->setVar('tpl_lastmodified', time());
614  $tplfile_new->setVar('tpl_lastimported', 0);
615  if (!$tplfile_handler->insert($tplfile_new)) {
616  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE_ERROR, "<strong>".$block['template']."</strong>").'</span>';
617  } else {
618  $msgs[] = "&nbsp;&nbsp;".sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE, "<strong>".$block['template']."</strong>");
619  if ($xoopsConfig['template_set'] == 'default') {
620  if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) {
621  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, "<strong>".$block['template']."</strong>").'</span>';
622  } else {
623  $msgs[] = "&nbsp;&nbsp;".sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, "<strong>".$block['template']."</strong>");
624  }
625  }
626 
627  }
628  }
629  }
630  }
631  if ($fcount == 0) {
632  $newbid = $xoopsDB->genId($xoopsDB->prefix('newblocks').'_bid_seq');
633  $block_name = addslashes($block['name']);
634  $block_type = ($module->getVar('dirname') == 'system') ? 'S' : 'M';
635  $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, '{$block_type}', 1, '".addslashes($dirname)."', '".addslashes($block['file'])."', '".addslashes($block['show_func'])."', '".addslashes($editfunc)."', '".$template."', ".time().")";
636  $result = $xoopsDB->query($sql);
637  if (!$result) {
638  $msgs[] = '&nbsp;&nbsp;'.sprintf(_AM_SYSTEM_MODULES_SQL_NOT_CREATE, $block['name']);echo $sql;
639  } else {
640  if (empty($newbid)) {
641  $newbid = $xoopsDB->getInsertId();
642  }
643  if ($module->getInfo('hasMain')) {
644  $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
645  } else {
646  $groups = array(XOOPS_GROUP_ADMIN);
647  }
648  $gperm_handler =& xoops_gethandler('groupperm');
649  foreach ($groups as $mygroup) {
650  $bperm =& $gperm_handler->create();
651  $bperm->setVar('gperm_groupid', $mygroup);
652  $bperm->setVar('gperm_itemid', $newbid);
653  $bperm->setVar('gperm_name', 'block_read');
654  $bperm->setVar('gperm_modid', 1);
655  if (!$gperm_handler->insert($bperm)) {
656  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'._AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR .sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>".$newbid."</strong>"). sprintf(_AM_SYSTEM_MODULES_GROUP_ID, "<strong>".$mygroup."</strong>").'</span>';
657  } else {
658  $msgs[] = '&nbsp;&nbsp;'._AM_SYSTEM_MODULES_BLOCK_ACCESS. sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>".$newbid."</strong>") . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, "<strong>".$mygroup."</strong>");
659  }
660  }
661 
662  if ($template != '') {
663  $tplfile =& $tplfile_handler->create();
664  $tplfile->setVar('tpl_module', $dirname);
665  $tplfile->setVar('tpl_refid', $newbid);
666  $tplfile->setVar('tpl_source', $content, true);
667  $tplfile->setVar('tpl_tplset', 'default');
668  $tplfile->setVar('tpl_file', $block['template'], true);
669  $tplfile->setVar('tpl_type', 'block');
670  $tplfile->setVar('tpl_lastimported', time());
671  $tplfile->setVar('tpl_lastmodified', time());
672  $tplfile->setVar('tpl_desc', $block['description'], true);
673  if (!$tplfile_handler->insert($tplfile)) {
674  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, "<strong>".$block['template']."</strong>").'</span>';
675  } else {
676  $newid = $tplfile->getVar('tpl_id');
677  $msgs[] = '&nbsp;&nbsp;'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, "<strong>".$block['template']."</strong>");
678  if ($xoopsConfig['template_set'] == 'default') {
679  if (!xoops_template_touch($newid)) {
680  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_FAILD, "<strong>".$block['template']."</strong>").'</span>';
681  } else {
682  $msgs[] = '&nbsp;&nbsp;'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, "<strong>".$block['template']."</strong>");
683  }
684  }
685  }
686  }
687  $msgs[] = '&nbsp;&nbsp;'.sprintf(_AM_SYSTEM_MODULES_BLOCK_CREATED, "<strong>".$block['name']."</strong>").sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>".$newbid."</strong>");
688  $sql = 'INSERT INTO '.$xoopsDB->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newbid.', -1)';
689  $xoopsDB->query($sql);
690  }
691  }
692  }
693  }
694  $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
695  foreach ($block_arr as $block) {
696  if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) {
697  $sql = sprintf("DELETE FROM %s WHERE bid = %u", $xoopsDB->prefix('newblocks'), $block->getVar('bid'));
698  if(!$xoopsDB->query($sql)) {
699  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, "<strong>".$block->getVar('name')."</strong>").sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>".$block->getVar('bid')."</strong>").'</span>';
700  } else {
701  $msgs[] = '&nbsp;&nbsp;Block <strong>'.$block->getVar('name').' deleted. Block ID: <strong>'.$block->getVar('bid').'</strong>';
702  if ($block->getVar('template') != '') {
703  $tplfiles = $tplfile_handler->find(null, 'block', $block->getVar('bid'));
704  if (is_array($tplfiles)) {
705  $btcount = count($tplfiles);
706  for ($k = 0; $k < $btcount; $k++) {
707  if (!$tplfile_handler->delete($tplfiles[$k])) {
708  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'._AM_SYSTEM_MODULES_BLOCK_DEPRECATED_ERROR. '(ID: <strong>'.$tplfiles[$k]->getVar('tpl_id').'</strong>)</span>';
709  } else {
710  $msgs[] = '&nbsp;&nbsp;'.sprintf(_AM_SYSTEM_MODULES_BLOCK_DEPRECATED, "<strong>".$tplfiles[$k]->getVar('tpl_file')."</strong>");
711  }
712  }
713  }
714  }
715  }
716  }
717  }
718  }
719 
720  // reset compile_id
721  $xoopsTpl->setCompileId();
722 
723  // first delete all config entries
724  $config_handler =& xoops_gethandler('config');
725  $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
726  $confcount = count($configs);
727  $config_delng = array();
728  if ($confcount > 0) {
730  for ($i = 0; $i < $confcount; $i++) {
731  if (!$config_handler->deleteConfig($configs[$i])) {
732  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'._AM_SYSTEM_MODULES_GONFIG_DATA_DELETE_ERROR. sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, "<strong>".$configs[$i]->getvar('conf_id')."</strong>").'</span>';
733  // save the name of config failed to delete for later use
734  $config_delng[] = $configs[$i]->getvar('conf_name');
735  } else {
736  $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N');
737  $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype');
738  $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
739  $msgs[] = "&nbsp;&nbsp;"._AM_SYSTEM_MODULES_GONFIG_DATA_DELETE. sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, "<strong>".$configs[$i]->getVar('conf_id')."</strong>");
740  }
741  }
742  }
743 
744  // now reinsert them with the new settings
745  $configs = $module->getInfo('config');
746  if ($configs != false) {
747  if ($module->getVar('hascomments') != 0) {
748  include_once(XOOPS_ROOT_PATH.'/include/comment_constants.php');
749  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)));
750  array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0));
751  }
752  } else {
753  if ($module->getVar('hascomments') != 0) {
754  $configs = array();
755  include_once(XOOPS_ROOT_PATH.'/include/comment_constants.php');
756  $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));
757  $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0);
758  }
759  }
760  // RMV-NOTIFY
761  if ($module->getVar('hasnotification') != 0) {
762  if (empty($configs)) {
763  $configs = array();
764  }
765  // Main notification options
766  include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
767  include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
768  $options = array();
769  $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
770  $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
771  $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
772  $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
773 
774  //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
775  $configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options'=>$options);
776  // Event specific notification options
777  // FIXME: for some reason the default doesn't come up properly
778  // initially is ok, but not when 'update' module..
779  $options = array();
780  $categories =& notificationCategoryInfo('',$module->getVar('mid'));
781  foreach ($categories as $category) {
782  $events =& notificationEvents ($category['name'], false, $module->getVar('mid'));
783  foreach ($events as $event) {
784  if (!empty($event['invisible'])) {
785  continue;
786  }
787  $option_name = $category['title'] . ' : ' . $event['title'];
788  $option_value = $category['name'] . '-' . $event['name'];
789  $options[$option_name] = $option_value;
790  //$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);
791  }
792  }
793  $configs[] = array ('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options);
794  }
795 
796  if ($configs != false) {
797  $msgs[] = 'Adding module config data...';
798  $config_handler =& xoops_gethandler('config');
799  $order = 0;
800  foreach ($configs as $config) {
801  // only insert ones that have been deleted previously with success
802  if (!in_array($config['name'], $config_delng)) {
803  $confobj =& $config_handler->createConfig();
804  $confobj->setVar('conf_modid', $newmid);
805  $confobj->setVar('conf_catid', 0);
806  $confobj->setVar('conf_name', $config['name']);
807  $confobj->setVar('conf_title', $config['title'], true);
808  $confobj->setVar('conf_desc', $config['description'], true);
809  $confobj->setVar('conf_formtype', $config['formtype']);
810  if (isset( $config['valuetype']))
811  $confobj->setVar('conf_valuetype', $config['valuetype']);
812  if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) {
813  // preserver the old value if any
814  // form type and value type must be the same
815  $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true);
816  } else {
817  $confobj->setConfValueForInput($config['default'], true);
818 
819  //$confobj->setVar('conf_value', $config['default'], true);
820  }
821  $confobj->setVar('conf_order', $order);
822  $confop_msgs = '';
823  if (isset($config['options']) && is_array($config['options'])) {
824  foreach ($config['options'] as $key => $value) {
825  $confop =& $config_handler->createConfigOption();
826  $confop->setVar('confop_name', $key, true);
827  $confop->setVar('confop_value', $value, true);
828  $confobj->setConfOptions($confop);
829  $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> ';
830  unset($confop);
831  }
832  }
833  $order++;
834  if (false != $config_handler->insertConfig($confobj)) {
835  //$msgs[] = '&nbsp;&nbsp;Config <strong>'.$config['name'].'</strong> added to the database.'.$confop_msgs;
836  $msgs[] = "&nbsp;&nbsp;".sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, "<strong>" . $config['name'] . "</strong>") . $confop_msgs;
837  } else {
838  $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, "<strong>" . $config['name'] . "</strong>") . '</span>';
839  }
840  unset($confobj);
841  }
842  }
843  unset($configs);
844  }
845 
846  // execute module specific update script if any
847  $update_script = $module->getInfo('onUpdate');
848  if (false != $update_script && trim($update_script) != '') {
849  include_once XOOPS_ROOT_PATH.'/modules/'.$dirname.'/'.trim($update_script);
850  if (function_exists('xoops_module_update_'.$dirname)) {
851  $func = 'xoops_module_update_'.$dirname;
852  if (!$func($module, $prev_version)) {
853  $msgs[] = "<p>".sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func)."</p>";
854  $msgs = array_merge($msgs, $module->getErrors());
855  } else {
856  $msgs[] = "<p>".sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>".$func."</strong>")."</p>";
857  $msgs += $module->getErrors();
858  }
859  }
860  }
861  $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKUPD, '<strong>' . $module->getVar('name', 's') . '</strong>');
862  $msgs[] = '</div></div>';
863  $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
864  foreach ($msgs as $msg) {
865  echo $msg.'<br />';
866  }
867  }
868  // Call Footer
869  xoops_cp_footer();
870  // Flush cache files for cpanel GUIs
871  xoops_load("cpanel", "system");
873 
874  require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php';
875  $maintenance = new SystemMaintenance();
876  $folder = array(1,3);
877  $maintenance->CleanCache($folder);
878  //Set active modules in cache folder
880  break;
881 }
882 
883 ?>