source: temp/test-xoops.ec-cube.net/html/modules/system/admin/modulesadmin/modulesadmin.php @ 405

Revision 405, 44.3 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: modulesadmin.php,v 1.5 2006/05/01 02:37:30 onokazu Exp $
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
32if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
33    exit("Access Denied");
34}
35
36/**
37 * @brief display error message & exit (Tentative)
38 */
39function system_modulesadmin_error($message)
40{
41    xoops_cp_header();
42    xoops_error($message);
43    xoops_cp_footer();
44    exit();
45}
46
47function xoops_module_list()
48{
49        xoops_cp_header();
50    //OpenTable();
51    echo "
52    <h4 style='text-align:left'>"._MD_AM_MODADMIN."</h4>
53    <form action='admin.php' method='post' name='moduleadmin' id='moduleadmin'>
54    <table class='outer' width='100%' cellpadding='4' cellspacing='1'>
55    <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>
56    ";
57    $module_handler =& xoops_gethandler('module');
58    $installed_mods =& $module_handler->getObjects(new CriteriaCompo());
59    $listed_mods = array();
60    $count = 0;
61    foreach ( $installed_mods as $module ) {
62        if ($count % 2 == 0) {
63            $class = 'even';
64        } else {
65            $class = 'odd';
66        }
67        $count++;
68        echo "<tr class='$class' align='center' valign='middle'>\n";
69        echo "<td valign='bottom'>";
70        if ( $module->getVar('hasadmin') == 1 && $module->getVar('isactive') == 1) {
71            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" />';
72        } else {
73            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" />';
74        }
75        echo '<input type="hidden" name="oldname['.$module->getVar('mid').']" value="' .$module->getVar('name').'" /></td>';
76        echo "<td align='center'>".round($module->getVar('version') / 100, 2)."</td><td align='center'>".formatTimestamp($module->getVar('last_update'),'m')."<br />";
77        if ($module->getVar('dirname') != 'system' && $module->getVar('isactive') == 1) {
78            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" />';
79            $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>';
80        } elseif ($module->getVar('dirname') != 'system') {
81            echo '</td><td><input type="checkbox" name="newstatus['.$module->getVar('mid').']" value="1" /><input type="hidden" name="oldstatus['.$module->getVar('mid').']" value="0" />';
82            $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>';
83        } else {
84            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" />';
85            $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>';
86        }
87        echo "</td><td>";
88        if ($module->getVar('hasmain') == 1) {
89            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').'" />';
90        } else {
91            echo '<input type="hidden" name="oldweight['.$module->getVar('mid').']" value="0" /><input type="hidden" name="weight['.$module->getVar('mid').']" value="0" />';
92        }
93        echo "
94        </td>
95        <td>".$extra."&nbsp;<a href='javascript:openWithSelfMain(\"".XOOPS_URL."/modules/system/admin.php?fct=version&amp;mid=".$module->getVar('mid')."\",\"Info\",300,230);'>";
96        echo '<img src="'.XOOPS_URL.'/modules/system/images/info.gif" alt="'._INFO.'" /></a><input type="hidden" name="module[]" value="'.$module->getVar('mid').'" /></td>
97        </tr>
98        ';
99        $listed_mods[] = $module->getVar('dirname');
100    }
101    echo "<tr class='foot'><td colspan='6' align='center'><input type='hidden' name='fct' value='modulesadmin' />
102    <input type='hidden' name='op' value='confirm' />
103    <input type='submit' name='submit' value='"._MD_AM_SUBMIT."' />
104    </td></tr></table>
105    </form>
106    <br />
107    <table width='100%' border='0' class='outer' cellpadding='4' cellspacing='1'>
108    <tr align='center'><th>"._MD_AM_MODULE."</th><th>"._MD_AM_VERSION."</th><th>"._MD_AM_ACTION."</th></tr>
109    ";
110    $modules_dir = XOOPS_ROOT_PATH."/modules";
111    $handle = opendir($modules_dir);
112    $count = 0;
113    while ($file = readdir($handle)) {
114        clearstatcache();
115        $file = trim($file);
116        if ($file != '' && strtolower($file) != 'cvs' && !preg_match("/^\..*$/",$file) && is_dir($modules_dir.'/'.$file)) {
117            if ( !in_array($file, $listed_mods) ) {
118                $module =& $module_handler->create();
119                $module->loadInfo($file);
120                if ($count % 2 == 0) {
121                    $class = 'even';
122                } else {
123                    $class = 'odd';
124                }
125                echo '<tr class="'.$class.'" align="center" valign="middle">
126                <td align="center" valign="bottom"><img src="'.XOOPS_URL.'/modules/'.$module->getInfo('dirname').'/'.$module->getInfo('image').'" alt="'.htmlspecialchars($module->getInfo('name')).'" border="0" /></td>
127                <td align="center">'.round($module->getInfo('version'), 2).'</td>
128                <td>
129                <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>';
130                echo "&nbsp;<a href='javascript:openWithSelfMain(\"".XOOPS_URL."/modules/system/admin.php?fct=version&amp;mid=".$module->getInfo('dirname')."\",\"Info\",300,230);'>";
131                echo '<img src="'.XOOPS_URL.'/modules/system/images/info.gif" alt="'._INFO.'" /></a></td></tr>
132                ';
133                unset($module);
134                $count++;
135            }
136        }
137    }
138    echo "</table>";
139    //CloseTable();
140    xoops_cp_footer();
141}
142
143function xoops_module_install($dirname)
144{
145    global $xoopsUser, $xoopsConfig;
146    $dirname = trim($dirname);
147    $db =& Database::getInstance();
148 $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');
149    $module_handler =& xoops_gethandler('module');
150    if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) {
151        $module =& $module_handler->create();
152        $module->loadInfoAsVar($dirname);
153        $module->setVar('weight', 1);
154        $error = false;
155        $errs = array();
156        $sqlfile =& $module->getInfo('sqlfile');
157        $msgs = array();
158        $msgs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing '.$module->getInfo('name').'</h4>';
159        if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
160            $msgs[] ='<img src="'.XOOPS_URL.'/modules/'.$dirname.'/'.trim($module->getInfo('image')).'" alt="" />';
161        }
162        $msgs[] ='<b>Version:</b> '.$module->getInfo('version');
163        if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
164            $msgs[] ='<b>Author:</b> '.trim($module->getInfo('author'));
165        }
166        $msgs[] = '';
167        $errs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing '.$module->getInfo('name').'</h4>';
168        if ($sqlfile != false && is_array($sqlfile)) {
169
170            $sql_file_path = XOOPS_ROOT_PATH."/modules/".$dirname."/".$sqlfile[XOOPS_DB_TYPE];
171            if (!file_exists($sql_file_path)) {
172                $errs[] = "SQL file not found at <b>$sql_file_path</b>";
173                $error = true;
174            } else {
175                $msgs[] = "SQL file found at <b>$sql_file_path</b>.<br  /> Creating tables...";
176                include_once XOOPS_ROOT_PATH.'/class/database/sqlutility.php';
177                $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
178                $sql_query = trim($sql_query);
179                SqlUtility::splitMySqlFile($pieces, $sql_query);
180                $created_tables = array();
181                foreach ($pieces as $piece) {
182                    // [0] contains the prefixed query
183                    // [4] contains unprefixed table name
184                    $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
185                    if (!$prefixed_query) {
186                        $errs[] = "<b>$piece</b> is not a valid SQL!";
187                        $error = true;
188                        break;
189                    }
190                    // check if the table name is reserved
191                    if (!in_array($prefixed_query[4], $reservedTables)) {
192                        // not reserved, so try to create one
193                        if (!$db->query($prefixed_query[0])) {
194                            $errs[] = $db->error();
195                            $error = true;
196                            break;
197                        } else {
198
199                            if (!in_array($prefixed_query[4], $created_tables)) {
200                                $msgs[] = '&nbsp;&nbsp;Table <b>'.$db->prefix($prefixed_query[4]).'</b> created.';
201                                $created_tables[] = $prefixed_query[4];
202                            } else {
203                                $msgs[] = '&nbsp;&nbsp;Data inserted to table <b>'.$db->prefix($prefixed_query[4]).'</b>.';
204                            }
205                        }
206                    } else {
207                        // the table name is reserved, so halt the installation
208                        $errs[] = '<b>'.$prefixed_query[4]."</b> is a reserved table!";
209                        $error = true;
210                        break;
211                    }
212                }
213                // if there was an error, delete the tables created so far, so the next installation will not fail
214                if ($error == true) {
215                    foreach ($created_tables as $ct) {
216                        //echo $ct;
217                        $db->query("DROP TABLE ".$db->prefix($ct));
218                    }
219                }
220            }
221        }
222        // if no error, save the module info and blocks info associated with it
223        if ($error == false) {
224            if (!$module_handler->insert($module)) {
225                $errs[] = 'Could not insert <b>'.$module->getVar('name').'</b> to database.';
226                foreach ($created_tables as $ct) {
227                    $db->query("DROP TABLE ".$db->prefix($ct));
228                }
229                $ret = "<p>".sprintf(_MD_AM_FAILINS, "<b>".$module->name()."</b>")."&nbsp;"._MD_AM_ERRORSC."<br />";
230                foreach ( $errs as $err ) {
231                    $ret .= " - ".$err."<br />";
232                }
233                $ret .= "</p>";
234                unset($module);
235                unset($created_tables);
236                unset($errs);
237                unset($msgs);
238                return $ret;
239            } else {
240                $newmid = $module->getVar('mid');
241                unset($created_tables);
242                $msgs[] = 'Module data inserted successfully. Module ID: <b>'.$newmid.'</b>';
243                $tplfile_handler =& xoops_gethandler('tplfile');
244                $templates = $module->getInfo('templates');
245                if ($templates != false) {
246                    $msgs[] = 'Adding templates...';
247                    foreach ($templates as $tpl) {
248                        $tplfile =& $tplfile_handler->create();
249                        $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']);
250                        $tplfile->setVar('tpl_source', $tpldata, true);
251                        $tplfile->setVar('tpl_refid', $newmid);
252
253                        $tplfile->setVar('tpl_tplset', 'default');
254                        $tplfile->setVar('tpl_file', $tpl['file']);
255                        $tplfile->setVar('tpl_desc', $tpl['description'], true);
256                        $tplfile->setVar('tpl_module', $dirname);
257                        $tplfile->setVar('tpl_lastmodified', time());
258                        $tplfile->setVar('tpl_lastimported', 0);
259                        $tplfile->setVar('tpl_type', 'module');
260                        if (!$tplfile_handler->insert($tplfile)) {
261                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>'.$tpl['file'].'</b> to the database.</span>';
262                        } else {
263                            $newtplid = $tplfile->getVar('tpl_id');
264                            $msgs[] = '&nbsp;&nbsp;Template <b>'.$tpl['file'].'</b> added to the database. (ID: <b>'.$newtplid.'</b>)';
265                            // generate compiled file
266                            include_once XOOPS_ROOT_PATH.'/class/template.php';
267                            if (!xoops_template_touch($newtplid)) {
268                                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.$tpl['file'].'</b>.</span>';
269                            } else {
270                                $msgs[] = '&nbsp;&nbsp;Template <b>'.$tpl['file'].'</b> compiled.</span>';
271                            }
272                        }
273                        unset($tpldata);
274                    }
275                }
276                include_once XOOPS_ROOT_PATH.'/class/template.php';
277                xoops_template_clear_module_cache($newmid);
278                $blocks = $module->getInfo('blocks');
279                if ($blocks != false) {
280                    $msgs[] = 'Adding blocks...';
281                    foreach ($blocks as $blockkey => $block) {
282                        // break the loop if missing block config
283                        if (!isset($block['file']) || !isset($block['show_func'])) {
284                            break;
285                        }
286                        $options = '';
287                        if (!empty($block['options'])) {
288                            $options = trim($block['options']);
289                        }
290                        $newbid = $db->genId($db->prefix('newblocks').'_bid_seq');
291                        $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : '';
292                        $template = '';
293                        if ((isset($block['template']) && trim($block['template']) != '')) {
294                            $content =& xoops_module_gettemplate($dirname, $block['template'], true);
295                        }
296                        if (!isset($content)) {
297                            $content = '';
298                        } else {
299                            $template = trim($block['template']);
300                        }
301                        $block_name = addslashes(trim($block['name']));
302                        $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().")";
303                        if (!$db->query($sql)) {
304                            $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>';
305                        } else {
306                            if (empty($newbid)) {
307                                $newbid = $db->getInsertId();
308                            }
309                            $msgs[] = '&nbsp;&nbsp;Block <b>'.$block['name'].'</b> added. Block ID: <b>'.$newbid.'</b>';
310                            $sql = 'INSERT INTO '.$db->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newbid.', -1)';
311                            $db->query($sql);
312                            if ($template != '') {
313                                $tplfile =& $tplfile_handler->create();
314                                $tplfile->setVar('tpl_refid', $newbid);
315                                $tplfile->setVar('tpl_source', $content, true);
316                                $tplfile->setVar('tpl_tplset', 'default');
317                                $tplfile->setVar('tpl_file', $block['template']);
318                                $tplfile->setVar('tpl_module', $dirname);
319                                $tplfile->setVar('tpl_type', 'block');
320                                $tplfile->setVar('tpl_desc', $block['description'], true);
321                                $tplfile->setVar('tpl_lastimported', 0);
322                                $tplfile->setVar('tpl_lastmodified', time());
323                                if (!$tplfile_handler->insert($tplfile)) {
324                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>'.$block['template'].'</b> to the database.</span>';
325                                } else {
326                                    $newtplid = $tplfile->getVar('tpl_id');
327                                    $msgs[] = '&nbsp;&nbsp;Template <b>'.$block['template'].'</b> added to the database. (ID: <b>'.$newtplid.'</b>)';
328                                    // generate compiled file
329                                    include_once XOOPS_ROOT_PATH.'/class/template.php';
330                                    if (!xoops_template_touch($newtplid)) {
331                                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.$block['template'].'</b>.</span>';
332                                    } else {
333                                        $msgs[] = '&nbsp;&nbsp;Template <b>'.$block['template'].'</b> compiled.</span>';
334                                    }
335                                }
336                            }
337                        }
338                        unset($content);
339                    }
340                    unset($blocks);
341                }
342                $configs = $module->getInfo('config');
343                if ($configs != false) {
344                    if ($module->getVar('hascomments') != 0) {
345                        include_once(XOOPS_ROOT_PATH.'/include/comment_constants.php');
346                        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)));
347                        array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0));
348                    }
349                } else {
350                    if ($module->getVar('hascomments') != 0) {
351                        $configs = array();
352                        include_once(XOOPS_ROOT_PATH.'/include/comment_constants.php');
353                        $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));
354                        $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0);
355                    }
356                }
357                // RMV-NOTIFY
358                if ($module->getVar('hasnotification') != 0) {
359                    if (empty($configs)) {
360                        $configs = array();
361                    }
362                    // Main notification options
363                    include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
364                    include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
365                    $options = array();
366                    $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
367                    $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
368                    $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
369                    $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
370
371                    //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
372                    $configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options);
373                    // Event-specific notification options
374                    // FIXME: doesn't work when update module... can't read back the array of options properly...  " changing to &quot;
375                    $options = array();
376                    $categories =& notificationCategoryInfo('',$module->getVar('mid'));
377                    foreach ($categories as $category) {
378                        $events =& notificationEvents ($category['name'], false, $module->getVar('mid'));
379                        foreach ($events as $event) {
380                            if (!empty($event['invisible'])) {
381                                continue;
382                            }
383                            $option_name = $category['title'] . ' : ' . $event['title'];
384                            $option_value = $category['name'] . '-' . $event['name'];
385                            $options[$option_name] = $option_value;
386                        }
387                    }
388                    $configs[] = array ('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options);
389                }
390
391                if ($configs != false) {
392                    $msgs[] = 'Adding module config data...';
393                    $config_handler =& xoops_gethandler('config');
394                    $order = 0;
395                    foreach ($configs as $config) {
396                        $confobj =& $config_handler->createConfig();
397                        $confobj->setVar('conf_modid', $newmid);
398                        $confobj->setVar('conf_catid', 0);
399                        $confobj->setVar('conf_name', $config['name']);
400                        $confobj->setVar('conf_title', $config['title'], true);
401                        $confobj->setVar('conf_desc', $config['description'], true);
402                        $confobj->setVar('conf_formtype', $config['formtype']);
403                        $confobj->setVar('conf_valuetype', $config['valuetype']);
404                        $confobj->setConfValueForInput($config['default'], true);
405                        //$confobj->setVar('conf_value', $config['default'], true);
406                        $confobj->setVar('conf_order', $order);
407                        $confop_msgs = '';
408                        if (isset($config['options']) && is_array($config['options'])) {
409                            foreach ($config['options'] as $key => $value) {
410                                $confop =& $config_handler->createConfigOption();
411                                $confop->setVar('confop_name', $key, true);
412                                $confop->setVar('confop_value', $value, true);
413                                $confobj->setConfOptions($confop);
414                                $confop_msgs .= '<br />&nbsp;&nbsp;&nbsp;&nbsp;Config option added. Name: <b>'.$key.'</b> Value: <b>'.$value.'</b>';
415                                unset($confop);
416                            }
417                        }
418                        $order++;
419                        if ($config_handler->insertConfig($confobj) != false) {
420                            $msgs[] = '&nbsp;&nbsp;Config <b>'.$config['name'].'</b> added to the database.'.$confop_msgs;
421                        } else {
422                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert config <b>'.$config['name'].'</b> to the database.</span>';
423                        }
424                        unset($confobj);
425                    }
426                    unset($configs);
427                }
428            }
429
430            $groups = $xoopsUser->getGroups();
431            // retrieve all block ids for this module
432            $blocks =& XoopsBlock::getByModule($newmid, false);
433            $msgs[] = 'Setting group rights...';
434            $gperm_handler =& xoops_gethandler('groupperm');
435            foreach ($groups as $mygroup) {
436                if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) {
437                    $mperm =& $gperm_handler->create();
438                    $mperm->setVar('gperm_groupid', $mygroup);
439                    $mperm->setVar('gperm_itemid', $newmid);
440                    $mperm->setVar('gperm_name', 'module_admin');
441                    $mperm->setVar('gperm_modid', 1);
442                    if (!$gperm_handler->insert($mperm)) {
443                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add admin access right for Group ID <b>'.$mygroup.'</b></span>';
444                    } else {
445                        $msgs[] = '&nbsp;&nbsp;Added admin access right for Group ID <b>'.$mygroup.'</b>';
446                    }
447                    unset($mperm);
448                }
449                $mperm =& $gperm_handler->create();
450                $mperm->setVar('gperm_groupid', $mygroup);
451                $mperm->setVar('gperm_itemid', $newmid);
452                $mperm->setVar('gperm_name', 'module_read');
453                $mperm->setVar('gperm_modid', 1);
454                if (!$gperm_handler->insert($mperm)) {
455                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add user access right for Group ID: <b>'.$mygroup.'</b></span>';
456                } else {
457                    $msgs[] = '&nbsp;&nbsp;Added user access right for Group ID: <b>'.$mygroup.'</b>';
458                }
459                unset($mperm);
460                foreach ($blocks as $blc) {
461                    $bperm =& $gperm_handler->create();
462                    $bperm->setVar('gperm_groupid', $mygroup);
463                    $bperm->setVar('gperm_itemid', $blc);
464                    $bperm->setVar('gperm_name', 'block_read');
465                    $bperm->setVar('gperm_modid', 1);
466                    if (!$gperm_handler->insert($bperm)) {
467                        $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>';
468                    } else {
469                        $msgs[] = '&nbsp;&nbsp;Added block access right. Block ID: <b>'.$blc.'</b> Group ID: <b>'.$mygroup.'</b>';
470                    }
471                    unset($bperm);
472                }
473            }
474            unset($blocks);
475            unset($groups);
476
477            // execute module specific install script if any
478            $install_script = $module->getInfo('onInstall');
479            if (false != $install_script && trim($install_script) != '') {
480                include_once XOOPS_ROOT_PATH.'/modules/'.$dirname.'/'.trim($install_script);
481                if (function_exists('xoops_module_install_'.$dirname)) {
482                    $func = 'xoops_module_install_'.$dirname;
483                    if (!$func($module)) {
484                        $msgs[] = 'Failed to execute '.$func;
485                    } else {
486                        $msgs[] = '<b>'.$func.'</b> executed successfully.';
487                    }
488                }
489            }
490
491            $ret = '<p><code>';
492            foreach ($msgs as $m) {
493                $ret .= $m.'<br />';
494            }
495            unset($msgs);
496            unset($errs);
497            $ret .= '</code><br />'.sprintf(_MD_AM_OKINS, "<b>".$module->getVar('name')."</b>").'</p>';
498            unset($module);
499            return $ret;
500        } else {
501            $ret = '<p>';
502            foreach ($errs as $er) {
503                $ret .= '&nbsp;&nbsp;'.$er.'<br />';
504            }
505            unset($msgs);
506            unset($errs);
507            $ret .= '<br />'.sprintf(_MD_AM_FAILINS, '<b>'.$dirname.'</b>').'&nbsp;'._MD_AM_ERRORSC.'</p>';
508            return $ret;
509        }
510    }
511    else {
512        return "<p>".sprintf(_MD_AM_FAILINS, "<b>".$dirname."</b>")."&nbsp;"._MD_AM_ERRORSC."<br />&nbsp;&nbsp;".sprintf(_MD_AM_ALEXISTS, $dirname)."</p>";
513    }
514}
515
516function &xoops_module_gettemplate($dirname, $template, $block=false)
517{
518    global $xoopsConfig;
519    if ($block) {
520        $path = XOOPS_ROOT_PATH.'/modules/'.$dirname.'/templates/blocks/'.$template;
521    } else {
522        $path = XOOPS_ROOT_PATH.'/modules/'.$dirname.'/templates/'.$template;
523    }
524    if (!file_exists($path)) {
525        return false;
526    } else {
527        $lines = file($path);
528    }
529    if (!$lines) {
530        return false;
531    }
532    $ret = '';
533    $count = count($lines);
534    for ($i = 0; $i < $count; $i++) {
535        $ret .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $lines[$i]));
536    }
537    return $ret;
538}
539
540function xoops_module_uninstall($dirname)
541{
542    global $xoopsConfig;
543    $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');
544    $db =& Database::getInstance();
545    $module_handler =& xoops_gethandler('module');
546    $module =& $module_handler->getByDirname($dirname);
547    include_once XOOPS_ROOT_PATH.'/class/template.php';
548    xoops_template_clear_module_cache($module->getVar('mid'));
549    if ($module->getVar('dirname') == 'system') {
550        return "<p>".sprintf(_MD_AM_FAILUNINS, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br /> - "._MD_AM_SYSNO."</p>";
551    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
552        return "<p>".sprintf(_MD_AM_FAILUNINS, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br /> - "._MD_AM_STRTNO."</p>";
553    } else {
554        $msgs = array();
555        if (!$module_handler->delete($module)) {
556            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete '.$module->getVar('name').'</span>';
557        } else {
558
559            // delete template files
560            $tplfile_handler = xoops_gethandler('tplfile');
561            $templates =& $tplfile_handler->find(null, 'module', $module->getVar('mid'));
562            $tcount = count($templates);
563            if ($tcount > 0) {
564                $msgs[] = 'Deleting templates...';
565                for ($i = 0; $i < $tcount; $i++) {
566                    if (!$tplfile_handler->delete($templates[$i])) {
567                        $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>';
568                    } else {
569                        $msgs[] = '&nbsp;&nbsp;Template <b>'.$templates[$i]->getVar('tpl_file').'</b> deleted from the database. Template ID: <b>'.$templates[$i]->getVar('tpl_id').'</b>';
570                    }
571                }
572            }
573            unset($templates);
574
575            // delete blocks and block tempalte files
576            $block_arr =& XoopsBlock::getByModule($module->getVar('mid'));
577            if (is_array($block_arr)) {
578                $bcount = count($block_arr);
579                $msgs[] = 'Deleting block...';
580                for ($i = 0; $i < $bcount; $i++) {
581                    if (!$block_arr[$i]->delete()) {
582                        $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>';
583                    } else {
584                        $msgs[] = '&nbsp;&nbsp;Block <b>'.$block_arr[$i]->getVar('name').'</b> deleted. Block ID: <b>'.$block_arr[$i]->getVar('bid').'</b>';
585                    }
586                    if ($block_arr[$i]->getVar('template') != ''){
587                        $templates =& $tplfile_handler->find(null, 'block', $block_arr[$i]->getVar('bid'));
588                        $btcount = count($templates);
589                        if ($btcount > 0) {
590                            for ($j = 0; $j < $btcount; $j++) {
591                                if (!$tplfile_handler->delete($templates[$j])) {
592                                $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>';
593                                } else {
594                                $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>';
595                                }
596                            }
597                        }
598                        unset($templates);
599                    }
600                }
601            }
602
603            // delete tables used by this module
604            $modtables = $module->getInfo('tables');
605            if ($modtables != false && is_array($modtables)) {
606                $msgs[] = 'Deleting module tables...';
607                foreach ($modtables as $table) {
608                    // prevent deletion of reserved core tables!
609                    if (!in_array($table, $reservedTables)) {
610                        $sql = 'DROP TABLE '.$db->prefix($table);
611                        if (!$db->query($sql)) {
612                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not drop table <b>'.$db->prefix($table).'<b>.</span>';
613                        } else {
614                            $msgs[] = '&nbsp;&nbsp;Table <b>'.$db->prefix($table).'</b> dropped.</span>';
615                        }
616                    } else {
617                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Not allowed to drop table <b>'.$db->prefix($table).'</b>!</span>';
618                    }
619                }
620            }
621
622            // delete comments if any
623            if ($module->getVar('hascomments') != 0) {
624                $msgs[] = 'Deleting comments...';
625                $comment_handler =& xoops_gethandler('comment');
626                if (!$comment_handler->deleteByModule($module->getVar('mid'))) {
627                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete comments</span>';
628                } else {
629                    $msgs[] = '&nbsp;&nbsp;Comments deleted';
630                }
631            }
632
633            // RMV-NOTIFY
634            // delete notifications if any
635            if ($module->getVar('hasnotification') != 0) {
636                $msgs[] = 'Deleting notifications...';
637                if (!xoops_notification_deletebymodule($module->getVar('mid'))) {
638                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete notifications</span>';
639                } else {
640                    $msgs[] = '&nbsp;&nbsp;Notifications deleted';
641                }
642            }
643
644            // delete permissions if any
645            $gperm_handler =& xoops_gethandler('groupperm');
646            if (!$gperm_handler->deleteByModule($module->getVar('mid'))) {
647                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete group permissions</span>';
648            } else {
649                $msgs[] = '&nbsp;&nbsp;Group permissions deleted';
650            }
651
652            // delete module config options if any
653            if ($module->getVar('hasconfig') != 0 || $module->getVar('hascomments') != 0) {
654                $config_handler =& xoops_gethandler('config');
655                $configs =& $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
656                $confcount = count($configs);
657                if ($confcount > 0) {
658                    $msgs[] = 'Deleting module config options...';
659                    for ($i = 0; $i < $confcount; $i++) {
660                        if (!$config_handler->deleteConfig($configs[$i])) {
661                            $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>';
662                        } else {
663                            $msgs[] = '&nbsp;&nbsp;Config data deleted from the database. Config ID: <b>'.$configs[$i]->getVar('conf_id').'</b>';
664                        }
665                    }
666                }
667            }
668
669            // execute module specific install script if any
670            $uninstall_script = $module->getInfo('onUninstall');
671            if (false != $uninstall_script && trim($uninstall_script) != '') {
672                include_once XOOPS_ROOT_PATH.'/modules/'.$dirname.'/'.trim($uninstall_script);
673                if (function_exists('xoops_module_uninstall_'.$dirname)) {
674                    $func = 'xoops_module_uninstall_'.$dirname;
675                    if (!$func($module)) {
676                        $msgs[] = 'Failed to execute <b>'.$func.'</b>';
677                    } else {
678                        $msgs[] = '<b>'.$func.'</b> executed successfully.';
679                    }
680                }
681            }
682
683            $msgs[] = '</code><p>'.sprintf(_MD_AM_OKUNINS, "<b>".$module->getVar('name')."</b>").'</p>';
684        }
685        $ret = '<code>';
686        foreach ($msgs as $msg) {
687            $ret .= $msg.'<br />';
688        }
689        return $ret;
690    }
691}
692
693function xoops_module_activate($mid)
694{
695    $module_handler =& xoops_gethandler('module');
696    $module =& $module_handler->get($mid);
697    include_once XOOPS_ROOT_PATH.'/class/template.php';
698    xoops_template_clear_module_cache($module->getVar('mid'));
699    $module->setVar('isactive', 1);
700    if (!$module_handler->insert($module)) {
701        $ret = "<p>".sprintf(_MD_AM_FAILACT, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br />".$module->getHtmlErrors();
702        return $ret."</p>";
703    }
704    $blocks =& XoopsBlock::getByModule($module->getVar('mid'));
705    $bcount = count($blocks);
706    for ($i = 0; $i < $bcount; $i++) {
707        $blocks[$i]->setVar('isactive', 1);
708        $blocks[$i]->store();
709    }
710    return "<p>".sprintf(_MD_AM_OKACT, "<b>".$module->getVar('name')."</b>")."</p>";
711}
712
713function xoops_module_deactivate($mid)
714{
715    global $xoopsConfig;
716    $module_handler =& xoops_gethandler('module');
717    $module =& $module_handler->get($mid);
718    include_once XOOPS_ROOT_PATH.'/class/template.php';
719    xoops_template_clear_module_cache($mid);
720    $module->setVar('isactive', 0);
721    if ($module->getVar('dirname') == "system") {
722        return "<p>".sprintf(_MD_AM_FAILDEACT, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br /> - "._MD_AM_SYSNO."</p>";
723    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
724        return "<p>".sprintf(_MD_AM_FAILDEACT, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br /> - "._MD_AM_STRTNO."</p>";
725    } else {
726        if (!$module_handler->insert($module)) {
727            $ret = "<p>".sprintf(_MD_AM_FAILDEACT, "<b>".$module->getVar('name')."</b>")."&nbsp;"._MD_AM_ERRORSC."<br />".$module->getHtmlErrors();
728            return $ret."</p>";
729        }
730        $blocks =& XoopsBlock::getByModule($module->getVar('mid'));
731        $bcount = count($blocks);
732        for ($i = 0; $i < $bcount; $i++) {
733            $blocks[$i]->setVar('isactive', 0);
734            $blocks[$i]->store();
735        }
736        return "<p>".sprintf(_MD_AM_OKDEACT, "<b>".$module->getVar('name')."</b>")."</p>";
737    }
738}
739
740function xoops_module_change($mid, $weight, $name)
741{
742    $module_handler =& xoops_gethandler('module');
743    $module =& $module_handler->get($mid);
744    $module->setVar('weight', $weight);
745    $module->setVar('name', $name);
746    $myts =& MyTextSanitizer::getInstance();
747    if (!$module_handler->insert($module)) {
748        $ret = "<p>".sprintf(_MD_AM_FAILORDER, "<b>".$myts->stripSlashesGPC($name)."</b>")."&nbsp;"._MD_AM_ERRORSC."<br />";
749        $ret .= $module->getHtmlErrors()."</p>";
750        return $ret;
751    }
752    return "<p>".sprintf(_MD_AM_OKORDER, "<b>".$myts->stripSlashesGPC($name)."</b>")."</p>";
753}
754
755?>
Note: See TracBrowser for help on using the repository browser.