| 1 | <?php |
|---|
| 2 | // $Id: main.php,v 1.4 2005/08/03 12:39:16 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 | |
|---|
| 32 | if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) { |
|---|
| 33 | exit("Access Denied"); |
|---|
| 34 | } |
|---|
| 35 | include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php'; |
|---|
| 36 | include_once XOOPS_ROOT_PATH."/modules/system/admin/modulesadmin/modulesadmin.php"; |
|---|
| 37 | $op = "list"; |
|---|
| 38 | |
|---|
| 39 | if (isset($_GET['op'])) { |
|---|
| 40 | $op = $_GET['op']; |
|---|
| 41 | $module = $_GET['module']; |
|---|
| 42 | } elseif (isset($_POST['op'])) { |
|---|
| 43 | $op = $_POST['op']; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | if ( $op == "list" ) { |
|---|
| 47 | xoops_module_list(); |
|---|
| 48 | exit(); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | if ( $op == "confirm" ) { |
|---|
| 52 | $token =& XoopsSingleTokenHandler::quickCreate('modulesadmin_submit'); |
|---|
| 53 | xoops_cp_header(); |
|---|
| 54 | //OpenTable(); |
|---|
| 55 | $error = array(); |
|---|
| 56 | if ( !is_writable(XOOPS_CACHE_PATH.'/') ) { |
|---|
| 57 | // attempt to chmod 666 |
|---|
| 58 | if ( !chmod(XOOPS_CACHE_PATH.'/', 0777) ) { |
|---|
| 59 | $error[] = sprintf(_MUSTWABLE, "<b>".XOOPS_CACHE_PATH.'/</b>'); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | if ( count($error) > 0 ) { |
|---|
| 63 | xoops_error($error); |
|---|
| 64 | echo "<p><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a></p>"; |
|---|
| 65 | xoops_cp_footer(); |
|---|
| 66 | exit(); |
|---|
| 67 | } |
|---|
| 68 | echo "<h4 style='text-align:left;'>"._MD_AM_PCMFM."</h4> |
|---|
| 69 | <form action='admin.php' method='post'>"; |
|---|
| 70 | echo $token->getHtml(); |
|---|
| 71 | echo "<input type='hidden' name='fct' value='modulesadmin' /> |
|---|
| 72 | <input type='hidden' name='op' value='submit' /> |
|---|
| 73 | <table width='100%' border='0' cellspacing='1' class='outer'> |
|---|
| 74 | <tr align='center'><th>"._MD_AM_MODULE."</th><th>"._MD_AM_ACTION."</th><th>"._MD_AM_ORDER."</th></tr>"; |
|---|
| 75 | $mcount = 0; |
|---|
| 76 | $myts =& MyTextsanitizer::getInstance(); |
|---|
| 77 | foreach ($_POST['module'] as $mid) { |
|---|
| 78 | if ($mcount % 2 != 0) { |
|---|
| 79 | $class = 'odd'; |
|---|
| 80 | } else { |
|---|
| 81 | $class = 'even'; |
|---|
| 82 | } |
|---|
| 83 | echo '<tr class="'.$class.'"><td align="center">'.$myts->stripSlashesGPC($_POST['oldname'][$mid]); |
|---|
| 84 | $newname[$mid] = trim($myts->stripslashesGPC($_POST['newname'][$mid])); |
|---|
| 85 | if ($newname[$mid] != $_POST['oldname'][$mid]) { |
|---|
| 86 | echo ' »» <span style="color:#ff0000;font-weight:bold;">'.htmlspecialchars($newname[$mid]).'</span>'; |
|---|
| 87 | } |
|---|
| 88 | echo '</td><td align="center">'; |
|---|
| 89 | if (isset($_POST['newstatus'][$mid]) && $_POST['newstatus'][$mid] ==1) { |
|---|
| 90 | if ($_POST['oldstatus'][$mid] == 0) { |
|---|
| 91 | echo "<span style='color:#ff0000;font-weight:bold;'>"._MD_AM_ACTIVATE."</span>"; |
|---|
| 92 | } else { |
|---|
| 93 | echo _MD_AM_NOCHANGE; |
|---|
| 94 | } |
|---|
| 95 | } else { |
|---|
| 96 | $_POST['newstatus'][$mid] = 0; |
|---|
| 97 | if ($_POST['oldstatus'][$mid] == 1) { |
|---|
| 98 | echo "<span style='color:#ff0000;font-weight:bold;'>"._MD_AM_DEACTIVATE."</span>"; |
|---|
| 99 | } else { |
|---|
| 100 | echo _MD_AM_NOCHANGE; |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | echo "</td><td align='center'>"; |
|---|
| 104 | if ($_POST['oldweight'][$mid] != $_POST['weight'][$mid]) { |
|---|
| 105 | echo "<span style='color:#ff0000;font-weight:bold;'>".$_POST['weight'][$mid]."</span>"; |
|---|
| 106 | } else { |
|---|
| 107 | echo $_POST['weight'][$mid]; |
|---|
| 108 | } |
|---|
| 109 | echo " |
|---|
| 110 | <input type='hidden' name='module[]' value='".$mid."' /> |
|---|
| 111 | <input type='hidden' name='oldname[".$mid."]' value='".htmlspecialchars($_POST['oldname'][$mid], ENT_QUOTES)."' /> |
|---|
| 112 | <input type='hidden' name='newname[".$mid."]' value='".htmlspecialchars($newname[$mid], ENT_QUOTES)."' /> |
|---|
| 113 | <input type='hidden' name='oldstatus[".$mid."]' value='".$_POST['oldstatus'][$mid]."' /> |
|---|
| 114 | <input type='hidden' name='newstatus[".$mid."]' value='".$_POST['newstatus'][$mid]."' /> |
|---|
| 115 | <input type='hidden' name='oldweight[".$mid."]' value='".intval($_POST['oldweight'][$mid])."' /> |
|---|
| 116 | <input type='hidden' name='weight[".$mid."]' value='".intval($_POST['weight'][$mid])."' /> |
|---|
| 117 | </td></tr>"; |
|---|
| 118 | } |
|---|
| 119 | echo " |
|---|
| 120 | <tr class='foot' align='center'><td colspan='3'><input type='submit' value='"._MD_AM_SUBMIT."' /> <input type='button' value='"._MD_AM_CANCEL."' onclick='location=\"admin.php?fct=modulesadmin\"' /></td></tr> |
|---|
| 121 | </table> |
|---|
| 122 | </form>"; |
|---|
| 123 | xoops_cp_footer(); |
|---|
| 124 | exit(); |
|---|
| 125 | } |
|---|
| 126 | if ( $op == "submit" ) { |
|---|
| 127 | if(!XoopsSingleTokenHandler::quickValidate('modulesadmin_submit')) { |
|---|
| 128 | system_modulesadmin_error("Ticket Error"); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | $ret = array(); |
|---|
| 132 | $write = false; |
|---|
| 133 | foreach ($_POST['module'] as $mid) { |
|---|
| 134 | if (isset($_POST['newstatus'][$mid]) && $_POST['newstatus'][$mid] ==1) { |
|---|
| 135 | if ($_POST['oldstatus'][$mid] == 0) { |
|---|
| 136 | $ret[] = xoops_module_activate($mid); |
|---|
| 137 | } |
|---|
| 138 | } else { |
|---|
| 139 | if ($_POST['oldstatus'][$mid] == 1) { |
|---|
| 140 | $ret[] = xoops_module_deactivate($mid); |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | $newname[$mid] = trim($_POST['newname'][$mid]); |
|---|
| 144 | if ($_POST['oldname'][$mid] != $_POST['newname'][$mid] || $_POST['oldweight'][$mid] != $_POST['weight'][$mid]) { |
|---|
| 145 | $ret[] = xoops_module_change($mid, $_POST['weight'][$mid], $_POST['newname'][$mid]); |
|---|
| 146 | $write = true; |
|---|
| 147 | } |
|---|
| 148 | flush(); |
|---|
| 149 | } |
|---|
| 150 | if ( $write ) { |
|---|
| 151 | $contents = xoops_module_get_admin_menu(); |
|---|
| 152 | if (!xoops_module_write_admin_menu($contents)) { |
|---|
| 153 | $ret[] = "<p>"._MD_AM_FAILWRITE."</p>"; |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | xoops_cp_header(); |
|---|
| 157 | if ( count($ret) > 0 ) { |
|---|
| 158 | foreach ($ret as $msg) { |
|---|
| 159 | if ($msg != '') { |
|---|
| 160 | echo $msg; |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | echo "<br /><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a>"; |
|---|
| 165 | xoops_cp_footer(); |
|---|
| 166 | exit(); |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | if ($op == 'install') { |
|---|
| 170 | $module_handler =& xoops_gethandler('module'); |
|---|
| 171 | $mod =& $module_handler->create(); |
|---|
| 172 | $mod->loadInfoAsVar($module); |
|---|
| 173 | if ($mod->getInfo('image') != false && trim($mod->getInfo('image')) != '') { |
|---|
| 174 | $msgs ='<img src="'.XOOPS_URL.'/modules/'.$mod->getVar('dirname').'/'.trim($mod->getInfo('image')).'" alt="" />'; |
|---|
| 175 | } |
|---|
| 176 | $msgs .= '<br /><span style="font-size:smaller;";>'.$mod->getVar('name').'</span><br /><br />'._MD_AM_RUSUREINS; |
|---|
| 177 | xoops_cp_header(); |
|---|
| 178 | xoops_token_confirm(array('module' => $module, 'op' => 'install_ok', 'fct' => 'modulesadmin'), 'admin.php', $msgs, _MD_AM_INSTALL); |
|---|
| 179 | xoops_cp_footer(); |
|---|
| 180 | exit(); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | if ($op == 'install_ok') { |
|---|
| 184 | if(!xoops_confirm_validate()) { |
|---|
| 185 | system_modulesadmin_error("Ticket Error"); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | $ret = array(); |
|---|
| 189 | $ret[] = xoops_module_install($_POST['module']); |
|---|
| 190 | $contents = xoops_module_get_admin_menu(); |
|---|
| 191 | if (!xoops_module_write_admin_menu($contents)) { |
|---|
| 192 | $ret[] = "<p>"._MD_AM_FAILWRITE."</p>"; |
|---|
| 193 | } |
|---|
| 194 | xoops_cp_header(); |
|---|
| 195 | if (count($ret) > 0) { |
|---|
| 196 | foreach ($ret as $msg) { |
|---|
| 197 | if ($msg != '') { |
|---|
| 198 | echo $msg; |
|---|
| 199 | } |
|---|
| 200 | } |
|---|
| 201 | } |
|---|
| 202 | echo "<br /><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a>"; |
|---|
| 203 | xoops_cp_footer(); |
|---|
| 204 | exit(); |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | if ($op == 'uninstall') { |
|---|
| 208 | $module_handler =& xoops_gethandler('module'); |
|---|
| 209 | $mod =& $module_handler->getByDirname($module); |
|---|
| 210 | if ($mod->getInfo('image') != false && trim($mod->getInfo('image')) != '') { |
|---|
| 211 | $msgs ='<img src="'.XOOPS_URL.'/modules/'.$mod->getVar('dirname').'/'.trim($mod->getInfo('image')).'" alt="" />'; |
|---|
| 212 | } |
|---|
| 213 | $msgs .= '<br /><span style="font-size:smaller;";>'.$mod->getVar('name').'</span><br /><br />'._MD_AM_RUSUREUNINS; |
|---|
| 214 | xoops_cp_header(); |
|---|
| 215 | xoops_token_confirm(array('module' => $module, 'op' => 'uninstall_ok', 'fct' => 'modulesadmin'), 'admin.php', $msgs, _YES); |
|---|
| 216 | xoops_cp_footer(); |
|---|
| 217 | exit(); |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | if ($op == 'uninstall_ok') { |
|---|
| 221 | if(!xoops_confirm_validate()) { |
|---|
| 222 | system_modulesadmin_error("Ticket Error"); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | $ret = array(); |
|---|
| 226 | $ret[] = xoops_module_uninstall($_POST['module']); |
|---|
| 227 | $contents = xoops_module_get_admin_menu(); |
|---|
| 228 | if (!xoops_module_write_admin_menu($contents)) { |
|---|
| 229 | $ret[] = "<p>"._MD_AM_FAILWRITE."</p>"; |
|---|
| 230 | } |
|---|
| 231 | xoops_cp_header(); |
|---|
| 232 | if (count($ret) > 0) { |
|---|
| 233 | foreach ($ret as $msg) { |
|---|
| 234 | if ($msg != '') { |
|---|
| 235 | echo $msg; |
|---|
| 236 | } |
|---|
| 237 | } |
|---|
| 238 | } |
|---|
| 239 | echo "<a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a>"; |
|---|
| 240 | xoops_cp_footer(); |
|---|
| 241 | exit(); |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | if ($op == 'update') { |
|---|
| 245 | $module_handler =& xoops_gethandler('module'); |
|---|
| 246 | $mod =& $module_handler->getByDirname($module); |
|---|
| 247 | if ($mod->getInfo('image') != false && trim($mod->getInfo('image')) != '') { |
|---|
| 248 | $msgs ='<img src="'.XOOPS_URL.'/modules/'.$mod->getVar('dirname').'/'.trim($mod->getInfo('image')).'" alt="" />'; |
|---|
| 249 | } |
|---|
| 250 | $msgs .= '<br /><span style="font-size:smaller;";>'.$mod->getVar('name').'</span><br /><br />'._MD_AM_RUSUREUPD; |
|---|
| 251 | xoops_cp_header(); |
|---|
| 252 | xoops_token_confirm(array('dirname' => $module, 'op' => 'update_ok', 'fct' => 'modulesadmin'), 'admin.php', $msgs, _MD_AM_UPDATE); |
|---|
| 253 | xoops_cp_footer(); |
|---|
| 254 | exit(); |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | if ($op == 'update_ok') { |
|---|
| 258 | if(!xoops_confirm_validate()) { |
|---|
| 259 | system_modulesadmin_error("Ticket Error"); |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | $dirname = trim($_POST['dirname']); |
|---|
| 263 | $module_handler =& xoops_gethandler('module'); |
|---|
| 264 | $module =& $module_handler->getByDirname($dirname); |
|---|
| 265 | $prev_version = $module->getVar('version'); |
|---|
| 266 | include_once XOOPS_ROOT_PATH.'/class/template.php'; |
|---|
| 267 | xoops_template_clear_module_cache($module->getVar('mid')); |
|---|
| 268 | // we dont want to change the module name set by admin |
|---|
| 269 | $temp_name = $module->getVar('name'); |
|---|
| 270 | $module->loadInfoAsVar($dirname); |
|---|
| 271 | $module->setVar('name', $temp_name); |
|---|
| 272 | xoops_cp_header(); |
|---|
| 273 | if (!$module_handler->insert($module)) { |
|---|
| 274 | echo '<p>Could not update '.$module->getVar('name').'</p>'; |
|---|
| 275 | echo "<br /><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a>"; |
|---|
| 276 | } else { |
|---|
| 277 | $newmid = $module->getVar('mid'); |
|---|
| 278 | $msgs = array(); |
|---|
| 279 | $msgs[] = 'Module data updated.'; |
|---|
| 280 | $tplfile_handler =& xoops_gethandler('tplfile'); |
|---|
| 281 | $deltpl =& $tplfile_handler->find('default', 'module', $module->getVar('mid')); |
|---|
| 282 | $delng = array(); |
|---|
| 283 | if (is_array($deltpl)) { |
|---|
| 284 | $xoopsTpl = new XoopsTpl(); |
|---|
| 285 | // clear cache files |
|---|
| 286 | $xoopsTpl->clear_cache(null, 'mod_'.$dirname); |
|---|
| 287 | // delete template file entry in db |
|---|
| 288 | $dcount = count($deltpl); |
|---|
| 289 | for ($i = 0; $i < $dcount; $i++) { |
|---|
| 290 | if (!$tplfile_handler->delete($deltpl[$i])) { |
|---|
| 291 | $delng[] = $deltpl[$i]->getVar('tpl_file'); |
|---|
| 292 | } |
|---|
| 293 | } |
|---|
| 294 | } |
|---|
| 295 | $templates = $module->getInfo('templates'); |
|---|
| 296 | if ($templates != false) { |
|---|
| 297 | $msgs[] = 'Updating templates...'; |
|---|
| 298 | foreach ($templates as $tpl) { |
|---|
| 299 | $tpl['file'] = trim($tpl['file']); |
|---|
| 300 | if (!in_array($tpl['file'], $delng)) { |
|---|
| 301 | $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']); |
|---|
| 302 | $tplfile =& $tplfile_handler->create(); |
|---|
| 303 | $tplfile->setVar('tpl_refid', $newmid); |
|---|
| 304 | $tplfile->setVar('tpl_lastimported', 0); |
|---|
| 305 | $tplfile->setVar('tpl_lastmodified', time()); |
|---|
| 306 | if (preg_match("/\.css$/i", $tpl['file'])) { |
|---|
| 307 | $tplfile->setVar('tpl_type', 'css'); |
|---|
| 308 | } else { |
|---|
| 309 | $tplfile->setVar('tpl_type', 'module'); |
|---|
| 310 | } |
|---|
| 311 | $tplfile->setVar('tpl_source', $tpldata, true); |
|---|
| 312 | $tplfile->setVar('tpl_module', $dirname); |
|---|
| 313 | $tplfile->setVar('tpl_tplset', 'default'); |
|---|
| 314 | $tplfile->setVar('tpl_file', $tpl['file'], true); |
|---|
| 315 | $tplfile->setVar('tpl_desc', $tpl['description'], true); |
|---|
| 316 | if (!$tplfile_handler->insert($tplfile)) { |
|---|
| 317 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert template <b>'.$tpl['file'].'</b> to the database.</span>'; |
|---|
| 318 | } else { |
|---|
| 319 | $newid = $tplfile->getVar('tpl_id'); |
|---|
| 320 | $msgs[] = ' Template <b>'.$tpl['file'].'</b> inserted to the database.'; |
|---|
| 321 | if ($xoopsConfig['template_set'] == 'default') { |
|---|
| 322 | if (!xoops_template_touch($newid)) { |
|---|
| 323 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not recompile template <b>'.$tpl['file'].'</b>.</span>'; |
|---|
| 324 | } else { |
|---|
| 325 | $msgs[] = ' Template <b>'.$tpl['file'].'</b> recompiled.</span>'; |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | } |
|---|
| 329 | unset($tpldata); |
|---|
| 330 | } else { |
|---|
| 331 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not delete old template <b>'.$tpl['file'].'</b>. Aborting update of this file.</span>'; |
|---|
| 332 | } |
|---|
| 333 | } |
|---|
| 334 | } |
|---|
| 335 | $contents = xoops_module_get_admin_menu(); |
|---|
| 336 | if (!xoops_module_write_admin_menu($contents)) { |
|---|
| 337 | $msgs[] = '<p><span style="color:#ff0000;">'._MD_AM_FAILWRITE.'</span></p>'; |
|---|
| 338 | } |
|---|
| 339 | $blocks = $module->getInfo('blocks'); |
|---|
| 340 | $msgs[] = 'Rebuilding blocks...'; |
|---|
| 341 | if ($blocks != false) { |
|---|
| 342 | $count = count($blocks); |
|---|
| 343 | $showfuncs = array(); |
|---|
| 344 | $funcfiles = array(); |
|---|
| 345 | for ( $i = 1; $i <= $count; $i++ ) { |
|---|
| 346 | if (isset($blocks[$i]['show_func']) && $blocks[$i]['show_func'] != '' && isset($blocks[$i]['file']) && $blocks[$i]['file'] != '') { |
|---|
| 347 | $editfunc = isset($blocks[$i]['edit_func']) ? $blocks[$i]['edit_func'] : ''; |
|---|
| 348 | $showfuncs[] = $blocks[$i]['show_func']; |
|---|
| 349 | $funcfiles[] = $blocks[$i]['file']; |
|---|
| 350 | $template = ''; |
|---|
| 351 | if ((isset($blocks[$i]['template']) && trim($blocks[$i]['template']) != '')) { |
|---|
| 352 | $content =& xoops_module_gettemplate($dirname, $blocks[$i]['template'], true); |
|---|
| 353 | } |
|---|
| 354 | if (!$content) { |
|---|
| 355 | $content = ''; |
|---|
| 356 | } else { |
|---|
| 357 | $template = $blocks[$i]['template']; |
|---|
| 358 | } |
|---|
| 359 | $options = ''; |
|---|
| 360 | if (!empty($blocks[$i]['options'])) { |
|---|
| 361 | $options = $blocks[$i]['options']; |
|---|
| 362 | } |
|---|
| 363 | $sql = "SELECT bid, name FROM ".$xoopsDB->prefix('newblocks')." WHERE mid=".$module->getVar('mid')." AND func_num=".$i." AND show_func='".addslashes($blocks[$i]['show_func'])."' AND func_file='".addslashes($blocks[$i]['file'])."'"; |
|---|
| 364 | $fresult = $xoopsDB->query($sql); |
|---|
| 365 | $fcount = 0; |
|---|
| 366 | while ($fblock = $xoopsDB->fetchArray($fresult)) { |
|---|
| 367 | $fcount++; |
|---|
| 368 | $sql = "UPDATE ".$xoopsDB->prefix("newblocks")." SET name='".addslashes($blocks[$i]['name'])."', edit_func='".addslashes($editfunc)."', options='".addslashes($options)."', content='', template='".$template."', last_modified=".time()." WHERE bid=".$fblock['bid']; |
|---|
| 369 | $result = $xoopsDB->query($sql); |
|---|
| 370 | if (!$result) { |
|---|
| 371 | $msgs[] = ' ERROR: Could not update '.$fblock['name']; |
|---|
| 372 | } else { |
|---|
| 373 | $msgs[] = ' Block <b>'.$fblock['name'].'</b> updated. Block ID: <b>'.$fblock['bid'].'</b>'; |
|---|
| 374 | if ($template != '') { |
|---|
| 375 | $tplfile =& $tplfile_handler->find('default', 'block', $fblock['bid']); |
|---|
| 376 | if (count($tplfile) == 0) { |
|---|
| 377 | $tplfile_new =& $tplfile_handler->create(); |
|---|
| 378 | $tplfile_new->setVar('tpl_module', $dirname); |
|---|
| 379 | $tplfile_new->setVar('tpl_refid', $fblock['bid']); |
|---|
| 380 | $tplfile_new->setVar('tpl_tplset', 'default'); |
|---|
| 381 | $tplfile_new->setVar('tpl_file', $blocks[$i]['template'], true); |
|---|
| 382 | $tplfile_new->setVar('tpl_type', 'block'); |
|---|
| 383 | } |
|---|
| 384 | else { |
|---|
| 385 | $tplfile_new = $tplfile[0]; |
|---|
| 386 | } |
|---|
| 387 | $tplfile_new->setVar('tpl_source', $content, true); |
|---|
| 388 | $tplfile_new->setVar('tpl_desc', $blocks[$i]['description'], true); |
|---|
| 389 | $tplfile_new->setVar('tpl_lastmodified', time()); |
|---|
| 390 | $tplfile_new->setVar('tpl_lastimported', 0); |
|---|
| 391 | if (!$tplfile_handler->insert($tplfile_new)) { |
|---|
| 392 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not update template <b>'.$blocks[$i]['template'].'</b>.</span>'; |
|---|
| 393 | } else { |
|---|
| 394 | $msgs[] = ' Template <b>'.$blocks[$i]['template'].'</b> updated.'; |
|---|
| 395 | if ($xoopsConfig['template_set'] == 'default') { |
|---|
| 396 | if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) { |
|---|
| 397 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not recompile template <b>'.$blocks[$i]['template'].'</b>.</span>'; |
|---|
| 398 | } else { |
|---|
| 399 | $msgs[] = ' Template <b>'.$blocks[$i]['template'].'</b> recompiled.'; |
|---|
| 400 | } |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | } |
|---|
| 404 | } |
|---|
| 405 | } |
|---|
| 406 | } |
|---|
| 407 | if ($fcount == 0) { |
|---|
| 408 | $newbid = $xoopsDB->genId($xoopsDB->prefix('newblocks').'_bid_seq'); |
|---|
| 409 | $block_name = addslashes($blocks[$i]['name']); |
|---|
| 410 | $sql = "INSERT INTO ".$xoopsDB->prefix("newblocks")." (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, isactive, dirname, func_file, show_func, edit_func, template, last_modified) VALUES (".$newbid.", ".$module->getVar('mid').", ".$i.",'".addslashes($options)."','".$block_name."', '".$block_name."', '', 0, 0, 0, 'M', 1, '".addslashes($dirname)."', '".addslashes($blocks[$i]['file'])."', '".addslashes($blocks[$i]['show_func'])."', '".addslashes($editfunc)."', '".$template."', ".time().")"; |
|---|
| 411 | $result = $xoopsDB->query($sql); |
|---|
| 412 | if (!$result) { |
|---|
| 413 | $msgs[] = ' ERROR: Could not create '.$blocks[$i]['name'];echo $sql; |
|---|
| 414 | } else { |
|---|
| 415 | if (empty($newbid)) { |
|---|
| 416 | $newbid = $xoopsDB->getInsertId(); |
|---|
| 417 | } |
|---|
| 418 | $groups =& $xoopsUser->getGroups(); |
|---|
| 419 | $gperm_handler =& xoops_gethandler('groupperm'); |
|---|
| 420 | foreach ($groups as $mygroup) { |
|---|
| 421 | $bperm =& $gperm_handler->create(); |
|---|
| 422 | $bperm->setVar('gperm_groupid', $mygroup); |
|---|
| 423 | $bperm->setVar('gperm_itemid', $newbid); |
|---|
| 424 | $bperm->setVar('gperm_name', 'block_read'); |
|---|
| 425 | $bperm->setVar('gperm_modid', 1); |
|---|
| 426 | if (!$gperm_handler->insert($bperm)) { |
|---|
| 427 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add block access right. Block ID: <b>'.$newbid.'</b> Group ID: <b>'.$mygroup.'</b></span>'; |
|---|
| 428 | } else { |
|---|
| 429 | $msgs[] = ' Added block access right. Block ID: <b>'.$newbid.'</b> Group ID: <b>'.$mygroup.'</b>'; |
|---|
| 430 | } |
|---|
| 431 | } |
|---|
| 432 | |
|---|
| 433 | if ($template != '') { |
|---|
| 434 | $tplfile =& $tplfile_handler->create(); |
|---|
| 435 | $tplfile->setVar('tpl_module', $dirname); |
|---|
| 436 | $tplfile->setVar('tpl_refid', $newbid); |
|---|
| 437 | $tplfile->setVar('tpl_source', $content, true); |
|---|
| 438 | $tplfile->setVar('tpl_tplset', 'default'); |
|---|
| 439 | $tplfile->setVar('tpl_file', $blocks[$i]['template'], true); |
|---|
| 440 | $tplfile->setVar('tpl_type', 'block'); |
|---|
| 441 | $tplfile->setVar('tpl_lastimported', 0); |
|---|
| 442 | $tplfile->setVar('tpl_lastmodified', time()); |
|---|
| 443 | $tplfile->setVar('tpl_desc', $blocks[$i]['description'], true); |
|---|
| 444 | if (!$tplfile_handler->insert($tplfile)) { |
|---|
| 445 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert template <b>'.$blocks[$i]['template'].'</b> to the database.</span>'; |
|---|
| 446 | } else { |
|---|
| 447 | $newid = $tplfile->getVar('tpl_id'); |
|---|
| 448 | $msgs[] = ' Template <b>'.$blocks[$i]['template'].'</b> added to the database.'; |
|---|
| 449 | if ($xoopsConfig['template_set'] == 'default') { |
|---|
| 450 | if (!xoops_template_touch($newid)) { |
|---|
| 451 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Template <b>'.$blocks[$i]['template'].'</b> recompile failed.</span>'; |
|---|
| 452 | } else { |
|---|
| 453 | $msgs[] = ' Template <b>'.$blocks[$i]['template'].'</b> recompiled.'; |
|---|
| 454 | } |
|---|
| 455 | } |
|---|
| 456 | } |
|---|
| 457 | } |
|---|
| 458 | $msgs[] = ' Block <b>'.$blocks[$i]['name'].'</b> created. Block ID: <b>'.$newbid.'</b>'; |
|---|
| 459 | $sql = 'INSERT INTO '.$xoopsDB->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newbid.', -1)'; |
|---|
| 460 | $xoopsDB->query($sql); |
|---|
| 461 | } |
|---|
| 462 | } |
|---|
| 463 | } |
|---|
| 464 | } |
|---|
| 465 | $block_arr = XoopsBlock::getByModule($module->getVar('mid')); |
|---|
| 466 | foreach ($block_arr as $block) { |
|---|
| 467 | if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) { |
|---|
| 468 | $sql = sprintf("DELETE FROM %s WHERE bid = %u", $xoopsDB->prefix('newblocks'), $block->getVar('bid')); |
|---|
| 469 | if(!$xoopsDB->query($sql)) { |
|---|
| 470 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not delete block <b>'.$block->getVar('name').'</b>. Block ID: <b>'.$block->getVar('bid').'</b></span>'; |
|---|
| 471 | } else { |
|---|
| 472 | $msgs[] = ' Block <b>'.$block->getVar('name').' deleted. Block ID: <b>'.$block->getVar('bid').'</b>'; |
|---|
| 473 | if ($block->getVar('template') != '') { |
|---|
| 474 | $tplfiles =& $tplfile_handler->find(null, 'block', $block->getVar('bid')); |
|---|
| 475 | if (is_array($tplfiles)) { |
|---|
| 476 | $btcount = count($tplfiles); |
|---|
| 477 | for ($k = 0; $k < $btcount; $k++) { |
|---|
| 478 | if (!$tplfile_handler->delete($tplfiles[$k])) { |
|---|
| 479 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not remove deprecated block template. (ID: <b>'.$tplfiles[$k]->getVar('tpl_id').'</b>)</span>'; |
|---|
| 480 | } else { |
|---|
| 481 | $msgs[] = ' Block template <b>'.$tplfiles[$k]->getVar('tpl_file').'</b> deprecated.'; |
|---|
| 482 | } |
|---|
| 483 | } |
|---|
| 484 | } |
|---|
| 485 | } |
|---|
| 486 | } |
|---|
| 487 | } |
|---|
| 488 | } |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | // first delete all config entries |
|---|
| 492 | $config_handler =& xoops_gethandler('config'); |
|---|
| 493 | $configs =& $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid'))); |
|---|
| 494 | $confcount = count($configs); |
|---|
| 495 | $config_delng = array(); |
|---|
| 496 | if ($confcount > 0) { |
|---|
| 497 | $msgs[] = 'Deleting module config options...'; |
|---|
| 498 | for ($i = 0; $i < $confcount; $i++) { |
|---|
| 499 | if (!$config_handler->deleteConfig($configs[$i])) { |
|---|
| 500 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not delete config data from the database. Config ID: <b>'.$configs[$i]->getvar('conf_id').'</b></span>'; |
|---|
| 501 | // save the name of config failed to delete for later use |
|---|
| 502 | $config_delng[] = $configs[$i]->getvar('conf_name'); |
|---|
| 503 | } else { |
|---|
| 504 | $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N'); |
|---|
| 505 | $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype'); |
|---|
| 506 | $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype'); |
|---|
| 507 | $msgs[] = ' Config data deleted from the database. Config ID: <b>'.$configs[$i]->getVar('conf_id').'</b>'; |
|---|
| 508 | } |
|---|
| 509 | } |
|---|
| 510 | } |
|---|
| 511 | |
|---|
| 512 | // now reinsert them with the new settings |
|---|
| 513 | $configs = $module->getInfo('config'); |
|---|
| 514 | if ($configs != false) { |
|---|
| 515 | if ($module->getVar('hascomments') != 0) { |
|---|
| 516 | include_once(XOOPS_ROOT_PATH.'/include/comment_constants.php'); |
|---|
| 517 | 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))); |
|---|
| 518 | array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0)); |
|---|
| 519 | } |
|---|
| 520 | } else { |
|---|
| 521 | if ($module->getVar('hascomments') != 0) { |
|---|
| 522 | $configs = array(); |
|---|
| 523 | include_once(XOOPS_ROOT_PATH.'/include/comment_constants.php'); |
|---|
| 524 | $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)); |
|---|
| 525 | $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0); |
|---|
| 526 | } |
|---|
| 527 | } |
|---|
| 528 | // RMV-NOTIFY |
|---|
| 529 | if ($module->getVar('hasnotification') != 0) { |
|---|
| 530 | if (empty($configs)) { |
|---|
| 531 | $configs = array(); |
|---|
| 532 | } |
|---|
| 533 | // Main notification options |
|---|
| 534 | include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; |
|---|
| 535 | include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; |
|---|
| 536 | $options = array(); |
|---|
| 537 | $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; |
|---|
| 538 | $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; |
|---|
| 539 | $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; |
|---|
| 540 | $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; |
|---|
| 541 | |
|---|
| 542 | //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); |
|---|
| 543 | $configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options'=>$options); |
|---|
| 544 | // Event specific notification options |
|---|
| 545 | // FIXME: for some reason the default doesn't come up properly |
|---|
| 546 | // initially is ok, but not when 'update' module.. |
|---|
| 547 | $options = array(); |
|---|
| 548 | $categories =& notificationCategoryInfo('',$module->getVar('mid')); |
|---|
| 549 | foreach ($categories as $category) { |
|---|
| 550 | $events =& notificationEvents ($category['name'], false, $module->getVar('mid')); |
|---|
| 551 | foreach ($events as $event) { |
|---|
| 552 | if (!empty($event['invisible'])) { |
|---|
| 553 | continue; |
|---|
| 554 | } |
|---|
| 555 | $option_name = $category['title'] . ' : ' . $event['title']; |
|---|
| 556 | $option_value = $category['name'] . '-' . $event['name']; |
|---|
| 557 | $options[$option_name] = $option_value; |
|---|
| 558 | //$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); |
|---|
| 559 | } |
|---|
| 560 | } |
|---|
| 561 | $configs[] = array ('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options); |
|---|
| 562 | } |
|---|
| 563 | |
|---|
| 564 | if ($configs != false) { |
|---|
| 565 | $msgs[] = 'Adding module config data...'; |
|---|
| 566 | $config_handler =& xoops_gethandler('config'); |
|---|
| 567 | $order = 0; |
|---|
| 568 | foreach ($configs as $config) { |
|---|
| 569 | // only insert ones that have been deleted previously with success |
|---|
| 570 | if (!in_array($config['name'], $config_delng)) { |
|---|
| 571 | $confobj =& $config_handler->createConfig(); |
|---|
| 572 | $confobj->setVar('conf_modid', $newmid); |
|---|
| 573 | $confobj->setVar('conf_catid', 0); |
|---|
| 574 | $confobj->setVar('conf_name', $config['name']); |
|---|
| 575 | $confobj->setVar('conf_title', $config['title'], true); |
|---|
| 576 | $confobj->setVar('conf_desc', $config['description'], true); |
|---|
| 577 | $confobj->setVar('conf_formtype', $config['formtype']); |
|---|
| 578 | $confobj->setVar('conf_valuetype', $config['valuetype']); |
|---|
| 579 | if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) { |
|---|
| 580 | // preserver the old value if any |
|---|
| 581 | // form type and value type must be the same |
|---|
| 582 | $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true); |
|---|
| 583 | } else { |
|---|
| 584 | $confobj->setConfValueForInput($config['default'], true); |
|---|
| 585 | |
|---|
| 586 | //$confobj->setVar('conf_value', $config['default'], true); |
|---|
| 587 | } |
|---|
| 588 | $confobj->setVar('conf_order', $order); |
|---|
| 589 | $confop_msgs = ''; |
|---|
| 590 | if (isset($config['options']) && is_array($config['options'])) { |
|---|
| 591 | foreach ($config['options'] as $key => $value) { |
|---|
| 592 | $confop =& $config_handler->createConfigOption(); |
|---|
| 593 | $confop->setVar('confop_name', $key, true); |
|---|
| 594 | $confop->setVar('confop_value', $value, true); |
|---|
| 595 | $confobj->setConfOptions($confop); |
|---|
| 596 | $confop_msgs .= '<br /> Config option added. Name: <b>'.$key.'</b> Value: <b>'.$value.'</b>'; |
|---|
| 597 | unset($confop); |
|---|
| 598 | } |
|---|
| 599 | } |
|---|
| 600 | $order++; |
|---|
| 601 | if (false != $config_handler->insertConfig($confobj)) { |
|---|
| 602 | $msgs[] = ' Config <b>'.$config['name'].'</b> added to the database.'.$confop_msgs; |
|---|
| 603 | } else { |
|---|
| 604 | $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert config <b>'.$config['name'].'</b> to the database.</span>'; |
|---|
| 605 | } |
|---|
| 606 | unset($confobj); |
|---|
| 607 | } |
|---|
| 608 | } |
|---|
| 609 | unset($configs); |
|---|
| 610 | } |
|---|
| 611 | |
|---|
| 612 | // execute module specific update script if any |
|---|
| 613 | $update_script = $module->getInfo('onUpdate'); |
|---|
| 614 | if (false != $update_script && trim($update_script) != '') { |
|---|
| 615 | include_once XOOPS_ROOT_PATH.'/modules/'.$dirname.'/'.trim($update_script); |
|---|
| 616 | if (function_exists('xoops_module_update_'.$dirname)) { |
|---|
| 617 | $func = 'xoops_module_update_'.$dirname; |
|---|
| 618 | if (!$func($module, $prev_version)) { |
|---|
| 619 | $msgs[] = 'Failed to execute '.$func; |
|---|
| 620 | } else { |
|---|
| 621 | $msgs[] = '<b>'.$func.'</b> executed successfully.'; |
|---|
| 622 | } |
|---|
| 623 | } |
|---|
| 624 | } |
|---|
| 625 | |
|---|
| 626 | foreach ($msgs as $msg) { |
|---|
| 627 | echo '<code>'.$msg.'</code><br />'; |
|---|
| 628 | } |
|---|
| 629 | echo "<p>".sprintf(_MD_AM_OKUPD, "<b>".$module->getVar('name')."</b>")."</p>"; |
|---|
| 630 | } |
|---|
| 631 | echo "<br /><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a>"; |
|---|
| 632 | xoops_cp_footer(); |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | ?> |
|---|