Example #1
0
/**
 * Function icms_cp_header
 *
 * @since ImpressCMS 1.2
 * @version $Id: cp_functions.php 12115 2012-11-18 16:10:55Z fiammy $
 *
 * @author rowd (from the XOOPS Community)
 * @author nekro (aka Gustavo Pilla)<*****@*****.**>
 */
function icms_cp_header()
{
    global $icmsConfig, $icmsConfigPlugins, $icmsConfigPersona, $icmsModule, $xoopsModule, $xoopsTpl, $xoopsOption, $icmsTheme, $xoTheme, $icmsConfigMultilang, $icmsAdminTpl;
    icms::$logger->stopTime('Module init');
    icms::$logger->startTime('ImpressCMS CP Output Init');
    if (!headers_sent()) {
        header('Content-Type:text/html; charset=' . _CHARSET);
        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        header('Cache-Control: no-store, no-cache, must-revalidate');
        header("Cache-Control: post-check=0, pre-check=0", false);
        header("Pragma: no-cache");
    }
    $icmsAdminTpl = new icms_view_Tpl();
    $icmsAdminTpl->assign('xoops_url', ICMS_URL);
    $icmsAdminTpl->assign('icms_sitename', $icmsConfig['sitename']);
    if (@$xoopsOption['template_main']) {
        if (false === strpos($xoopsOption['template_main'], ':')) {
            $xoopsOption['template_main'] = 'db:' . $xoopsOption['template_main'];
        }
    }
    $xoopsThemeFactory = new icms_view_theme_Factory();
    $xoopsThemeFactory->allowedThemes = $icmsConfig['theme_set_allowed'];
    // The next 2 lines are for compatibility only... to implement the admin theme ;)
    // TODO: Remove all this after a few versions!!
    if (isset($icmsConfig['theme_admin_set'])) {
        $xoopsThemeFactory->defaultTheme = $icmsConfig['theme_admin_set'];
    }
    $icmsTheme = $xoTheme =& $xoopsThemeFactory->createInstance(array('contentTemplate' => @$xoopsOption['template_main'], 'canvasTemplate' => 'theme' . (file_exists(ICMS_THEME_PATH . '/' . $icmsConfig['theme_admin_set'] . '/theme_admin.html') || file_exists(ICMS_MODULES_PATH . '/system/themes/' . $icmsConfig['theme_admin_set'] . '/theme_admin.html') ? '_admin' : '') . '.html', 'plugins' => array('icms_view_PageBuilder'), 'folderName' => $icmsConfig['theme_admin_set']));
    $icmsAdminTpl = $xoTheme->template;
    // ################# Preload Trigger startOutputInit ##############
    icms::$preload->triggerEvent('adminHeader');
    $xoTheme->addScript(ICMS_URL . '/include/xoops.js', array('type' => 'text/javascript'));
    $xoTheme->addScript('', array('type' => 'text/javascript'), 'startList = function() {
						if (document.all&&document.getElementById) {
							navRoot = document.getElementById("nav");
							for (i=0; i<navRoot.childNodes.length; i++) {
								node = navRoot.childNodes[i];
								if (node.nodeName=="LI") {
									node.onmouseover=function() {
										this.className+=" over";
									}
									node.onmouseout=function() {
										this.className=this.className.replace(" over", "");
									}
								}
							}
						}
					}
					window.onload=startList;');
    /** @todo	Remove icms.css in 2.0 */
    icms_core_Debug::setDeprecated("Elements from icms.css need to be moved to your theme", sprintf(_CORE_REMOVE_IN_VERSION, '2.0'));
    $xoTheme->addStylesheet(ICMS_URL . '/icms' . (defined('_ADM_USE_RTL') && _ADM_USE_RTL ? '_rtl' : '') . '.css', array('media' => 'screen'));
    // JQuery UI Dialog
    $xoTheme->addScript(ICMS_URL . '/libraries/jquery/jquery.js', array('type' => 'text/javascript'));
    if (!empty($_SESSION['redirect_message'])) {
        $xoTheme->addScript(ICMS_URL . '/libraries/jquery/jgrowl.js', array('type' => 'text/javascript'));
        $xoTheme->addStylesheet(ICMS_URL . '/libraries/jquery/jgrowl' . (defined('_ADM_USE_RTL') && _ADM_USE_RTL ? '_rtl' : '') . '.css', array('media' => 'screen'));
        $xoTheme->addScript('', array('type' => 'text/javascript'), '
	if (!window.console || !console.firebug) {
		var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
		window.console = {};

		for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
	}

	(function($) {
		$(document).ready(function() {
			$.jGrowl("' . $_SESSION['redirect_message'] . '", {  life:5000 , position: "center", speed: "slow" });
		});
	})(jQuery);
	');
        unset($_SESSION['redirect_message']);
    }
    $xoTheme->addScript(ICMS_URL . '/libraries/jquery/ui/ui.min.js', array('type' => 'text/javascript'));
    $xoTheme->addScript(ICMS_URL . '/libraries/jquery/helptip.js', array('type' => 'text/javascript'));
    $xoTheme->addStylesheet(ICMS_URL . '/libraries/jquery/ui/css/ui-smoothness/ui.css', array('media' => 'screen'));
    $xoTheme->addStylesheet(ICMS_LIBRARIES_URL . '/jquery/colorbox/colorbox.css');
    $xoTheme->addScript(ICMS_LIBRARIES_URL . '/jquery/colorbox/jquery.colorbox-min.js');
    /*	$jscript = '';
    	 if(class_exists('icms_form_elements_Dhtmltextarea')){
    		foreach ($icmsConfigPlugins['sanitizer_plugins'] as $key) {
    		if( empty( $key ) )
    		continue;
    		if(file_exists(ICMS_ROOT_PATH.'/plugins/textsanitizer/'.$key.'/'.$key.'.js')){
    		$xoTheme->addScript(ICMS_URL.'/plugins/textsanitizer/'.$key.'/'.$key.'.js', array('type' => 'text/javascript'));
    		}else{
    		$extension = include_once ICMS_ROOT_PATH.'/plugins/textsanitizer/'.$key.'/'.$key.'.php';
    		$func = 'render_'.$key;
    		if ( function_exists($func) ) {
    		@list($encode, $jscript) = $func($ele_name);
    		if (!empty($jscript)) {
    		if(!file_exists(ICMS_ROOT_PATH.'/'.$jscript)){
    		$xoTheme->addScript('', array('type' => 'text/javascript'), $jscript);
    		}else{
    		$xoTheme->addScript($jscript, array('type' => 'text/javascript'));
    		}
    		}
    		}
    		}
    		}
    		}
    		*/
    $style_info = '';
    if (!empty($icmsConfigPlugins['sanitizer_plugins'])) {
        foreach ($icmsConfigPlugins['sanitizer_plugins'] as $key) {
            if (empty($key)) {
                continue;
            }
            if (file_exists(ICMS_ROOT_PATH . '/plugins/textsanitizer/' . $key . '/' . $key . '.css')) {
                $xoTheme->addStylesheet(ICMS_URL . '/plugins/textsanitizer/' . $key . '/' . $key . '.css', array('media' => 'screen'));
            } else {
                $extension = (include_once ICMS_ROOT_PATH . '/plugins/textsanitizer/' . $key . '/' . $key . '.php');
                $func = 'style_' . $key;
                if (function_exists($func)) {
                    $style_info = $func();
                    if (!empty($style_info)) {
                        if (!file_exists(ICMS_ROOT_PATH . '/' . $style_info)) {
                            $xoTheme->addStylesheet('', array('media' => 'screen'), $style_info);
                        } else {
                            $xoTheme->addStylesheet($style_info, array('media' => 'screen'));
                        }
                    }
                }
            }
        }
    }
    /**
     * Loading admin dropdown menus
     */
    if (!file_exists(ICMS_CACHE_PATH . '/adminmenu_' . $icmsConfig['language'] . '.php')) {
        xoops_module_write_admin_menu(impresscms_get_adminmenu());
    }
    $file = file_get_contents(ICMS_CACHE_PATH . "/adminmenu_" . $icmsConfig['language'] . ".php");
    $admin_menu = eval('return ' . $file . ';');
    $moduleperm_handler = icms::handler('icms_member_groupperm');
    $module_handler = icms::handler('icms_module');
    foreach ($admin_menu as $k => $navitem) {
        //Getting array of allowed modules to use in admin home
        if ($navitem['id'] == 'modules') {
            $perm_itens = array();
            foreach ($navitem['menu'] as $item) {
                $module = $module_handler->getByDirname($item['dir']);
                $admin_perm = $moduleperm_handler->checkRight('module_admin', $module->getVar('mid'), icms::$user->getGroups());
                if ($admin_perm) {
                    if ($item['dir'] != 'system') {
                        $perm_itens[] = $item;
                    }
                }
            }
            $navitem['menu'] = $mods = $perm_itens;
        }
        //end
        if ($navitem['id'] == 'opsystem') {
            $groups = icms::$user->getGroups();
            $all_ok = false;
            if (!in_array(ICMS_GROUP_ADMIN, $groups)) {
                $sysperm_handler = icms::handler('icms_member_groupperm');
                $ok_syscats =& $sysperm_handler->getItemIds('system_admin', $groups);
            } else {
                $all_ok = true;
            }
            $perm_itens = array();
            /**
             * Allow easely change the order of system dropdown menu.
             * $adminmenuorder = 1; Alphabetically order;
             * $adminmenuorder = 0; Indice key order;
             * To change the order when using Indice key order just change the order of the array in the file modules/system/menu.php and after update the system module
             *
             * @todo: Create a preference option to set this value and improve the way to change the order.
             */
            $adminmenuorder = 1;
            $adminsubmenuorder = 1;
            $adminsubsubmenuorder = 1;
            if ($adminmenuorder == 1) {
                foreach ($navitem['menu'] as $k => $sortarray) {
                    $column[] = $sortarray['title'];
                    if (isset($sortarray['subs']) && count($sortarray['subs']) > 0 && $adminsubmenuorder) {
                        asort($navitem['menu'][$k]['subs']);
                    }
                    if (isset($sortarray['subs']) && count($sortarray['subs']) > 0) {
                        foreach ($sortarray['subs'] as $k2 => $sortarray2) {
                            if (isset($sortarray2['subs']) && count($sortarray2['subs']) > 0 && $adminsubsubmenuorder) {
                                asort($navitem['menu'][$k]['subs'][$k2]['subs']);
                                //Sorting submenus of preferences
                            }
                        }
                    }
                }
                //sort arrays after loop
                array_multisort($column, SORT_ASC, $navitem['menu']);
            }
            foreach ($navitem['menu'] as $item) {
                foreach ($item['subs'] as $key => $subitem) {
                    if ($all_ok == false && !in_array($subitem['id'], $ok_syscats)) {
                        // remove the subitem
                        unset($item['subs'][$key]);
                    }
                }
                // only add the item (first layer: groups) if it has subitems
                if (count($item['subs']) > 0) {
                    $perm_itens[] = $item;
                }
            }
            //Getting array of allowed system prefs
            $navitem['menu'] = $sysprefs = $perm_itens;
        }
        $icmsAdminTpl->append('navitems', $navitem);
    }
    if (count($sysprefs) > 0) {
        $icmsAdminTpl->assign('systemadm', 1);
    } else {
        $icmsAdminTpl->assign('systemadm', 0);
    }
    if (count($mods) > 0) {
        $icmsAdminTpl->assign('modulesadm', 1);
    } else {
        $icmsAdminTpl->assign('modulesadm', 0);
    }
    /**
     * Loading options of the current module.
     */
    if ($icmsModule) {
        if ($icmsModule->getVar('dirname') == 'system') {
            if (isset($sysprefs) && count($sysprefs) > 0) {
                // remove the grouping for the system module preferences (first layer)
                $sysprefs_tmp = array();
                foreach ($sysprefs as $pref) {
                    $sysprefs_tmp = array_merge($sysprefs_tmp, $pref['subs']);
                }
                $sysprefs = $sysprefs_tmp;
                unset($sysprefs_tmp);
                for ($i = count($sysprefs) - 1; $i >= 0; $i = $i - 1) {
                    if (isset($sysprefs[$i])) {
                        $reversed_sysprefs[] = $sysprefs[$i];
                    }
                }
                foreach ($reversed_sysprefs as $k) {
                    $icmsAdminTpl->append('mod_options', array('title' => $k['title'], 'link' => $k['link'], 'icon' => isset($k['icon']) && $k['icon'] != '' ? $k['icon'] : ''));
                }
            }
        } else {
            foreach ($mods as $mod) {
                if ($mod['dir'] == $icmsModule->getVar('dirname')) {
                    $m = $mod;
                    //Getting info of the current module
                    break;
                }
            }
            if (isset($m['subs']) && count($m['subs']) > 0) {
                for ($i = count($m['subs']) - 1; $i >= 0; $i = $i - 1) {
                    if (isset($m['subs'][$i])) {
                        $reversed_module_admin_menu[] = $m['subs'][$i];
                    }
                }
                foreach ($reversed_module_admin_menu as $k) {
                    $icmsAdminTpl->append('mod_options', array('title' => $k['title'], 'link' => $k['link'], 'icon' => isset($k['icon']) && $k['icon'] != '' ? $k['icon'] : ''));
                }
            }
        }
        $icmsAdminTpl->assign('modpath', ICMS_URL . '/modules/' . $icmsModule->getVar('dirname'));
        $icmsAdminTpl->assign('modname', $icmsModule->getVar('name'));
        $icmsAdminTpl->assign('modid', $icmsModule->getVar('mid'));
        $icmsAdminTpl->assign('moddir', $icmsModule->getVar('dirname'));
        $icmsAdminTpl->assign('lang_prefs', _PREFERENCES);
    }
    if (@is_object($xoTheme->plugins['icms_view_PageBuilder'])) {
        $aggreg =& $xoTheme->plugins['icms_view_PageBuilder'];
        $icmsAdminTpl->assign_by_ref('xoAdminBlocks', $aggreg->blocks);
        // Backward compatibility code for pre 2.0.14 themes
        $icmsAdminTpl->assign_by_ref('xoops_lblocks', $aggreg->blocks['canvas_left']);
        $icmsAdminTpl->assign_by_ref('xoops_rblocks', $aggreg->blocks['canvas_right']);
        $icmsAdminTpl->assign_by_ref('xoops_ccblocks', $aggreg->blocks['page_topcenter']);
        $icmsAdminTpl->assign_by_ref('xoops_clblocks', $aggreg->blocks['page_topleft']);
        $icmsAdminTpl->assign_by_ref('xoops_crblocks', $aggreg->blocks['page_topright']);
        $icmsAdminTpl->assign('xoops_showlblock', !empty($aggreg->blocks['canvas_left']));
        $icmsAdminTpl->assign('xoops_showrblock', !empty($aggreg->blocks['canvas_right']));
        $icmsAdminTpl->assign('xoops_showcblock', !empty($aggreg->blocks['page_topcenter']) || !empty($aggreg->blocks['page_topleft']) || !empty($aggreg->blocks['page_topright']));
        /**
         * Send to template some ml infos
         */
        $icmsAdminTpl->assign('lang_prefs', _PREFERENCES);
        $icmsAdminTpl->assign('ml_is_enabled', $icmsConfigMultilang['ml_enable']);
        $icmsAdminTpl->assign('adm_left_logo', $icmsConfigPersona['adm_left_logo']);
        $icmsAdminTpl->assign('adm_left_logo_url', $icmsConfigPersona['adm_left_logo_url']);
        $icmsAdminTpl->assign('adm_left_logo_alt', $icmsConfigPersona['adm_left_logo_alt']);
        $icmsAdminTpl->assign('adm_right_logo', $icmsConfigPersona['adm_right_logo']);
        $icmsAdminTpl->assign('adm_right_logo_url', $icmsConfigPersona['adm_right_logo_url']);
        $icmsAdminTpl->assign('adm_right_logo_alt', $icmsConfigPersona['adm_right_logo_alt']);
        $icmsAdminTpl->assign('show_impresscms_menu', $icmsConfigPersona['show_impresscms_menu']);
    }
}
Example #2
0
 /**
  * Displays the (good old) adminmenu
  *
  * @param int  $currentoption  The current option of the admin menu
  * @param string  $breadcrumb  The breadcrumb trail
  * @param bool  $submenus  Show the submenus!
  * @param int  $currentsub  The current submenu
  *
  * @return datatype  description
  */
 public function displayAdminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1)
 {
     global $icmsModule, $icmsConfig;
     icms_loadLanguageFile($icmsModule->getVar('dirname'), 'modinfo');
     icms_loadLanguageFile($icmsModule->getVar('dirname'), 'admin');
     $tpl = new icms_view_Tpl();
     $tpl->assign(array('headermenu' => $this->getAdminHeaderMenu(), 'adminmenu' => $this->getAdminMenu(), 'current' => $currentoption, 'breadcrumb' => $breadcrumb, 'headermenucount' => count($this->getAdminHeaderMenu()), 'submenus' => $submenus, 'currentsub' => $currentsub, 'submenuscount' => count($submenus)));
     $tpl->display(ICMS_ROOT_PATH . '/modules/system/templates/admin/system_adm_modulemenu.html');
 }
function icms_module_update($dirname)
{
    $dirname = trim($dirname);
    $db =& icms_db_Factory::instance();
    $module_handler = icms::handler('icms_module');
    $module =& $module_handler->getByDirname($dirname);
    // Save current version for use in the update function
    $prev_version = $module->getVar('version');
    $prev_dbversion = $module->getVar('dbversion');
    xoops_template_clear_module_cache($module->getVar('mid'));
    // we dont want to change the module name set by admin
    $temp_name = $module->getVar('name');
    $module->loadInfoAsVar($dirname);
    $module->setVar('name', $temp_name);
    if (!$module_handler->insert($module)) {
        echo '<p>Could not update ' . $module->getVar('name') . '</p>';
        echo "<br /><a href='admin.php?fct=modulesadmin'>" . _MD_AM_BTOMADMIN . "</a>";
    } else {
        $newmid = $module->getVar('mid');
        $msgs = array();
        $msgs[] = _MD_AM_MOD_DATA_UPDATED;
        $tplfile_handler =& icms::handler('icms_view_template_file');
        $deltpl =& $tplfile_handler->find('default', 'module', $module->getVar('mid'));
        $delng = array();
        if (is_array($deltpl)) {
            $xoopsDelTpl = new icms_view_Tpl();
            // clear cache files
            $xoopsDelTpl->clear_cache(null, 'mod_' . $dirname);
            // delete template file entry in db
            $dcount = count($deltpl);
            for ($i = 0; $i < $dcount; $i++) {
                if (!$tplfile_handler->delete($deltpl[$i])) {
                    $delng[] = $deltpl[$i]->getVar('tpl_file');
                }
            }
        }
        $templates = $module->getInfo('templates');
        if ($templates != false) {
            $msgs[] = _MD_AM_MOD_UP_TEM;
            foreach ($templates as $tpl) {
                $tpl['file'] = trim($tpl['file']);
                if (!in_array($tpl['file'], $delng)) {
                    $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']);
                    $tplfile =& $tplfile_handler->create();
                    $tplfile->setVar('tpl_refid', $newmid);
                    $tplfile->setVar('tpl_lastimported', 0);
                    $tplfile->setVar('tpl_lastmodified', time());
                    if (preg_match("/\\.css\$/i", $tpl['file'])) {
                        $tplfile->setVar('tpl_type', 'css');
                    } else {
                        $tplfile->setVar('tpl_type', 'module');
                    }
                    $tplfile->setVar('tpl_source', $tpldata, true);
                    $tplfile->setVar('tpl_module', $dirname);
                    $tplfile->setVar('tpl_tplset', 'default');
                    $tplfile->setVar('tpl_file', $tpl['file'], true);
                    $tplfile->setVar('tpl_desc', $tpl['description'], true);
                    if (!$tplfile_handler->insert($tplfile)) {
                        $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_INSERT_FAIL . '</span>', '<strong>' . $tpl['file'] . '</strong>');
                    } else {
                        $newid = $tplfile->getVar('tpl_id');
                        $msgs[] = sprintf('&nbsp;&nbsp;<span>' . _MD_AM_TEMPLATE_INSERTED . '</span>', '<strong>' . $tpl['file'] . '</strong>', '<strong>' . $newid . '</strong>');
                        if ($icmsConfig['template_set'] == 'default') {
                            if (!icms_view_Tpl::template_touch($newid)) {
                                $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>', '<strong>' . $tpl['file'] . '</strong>');
                            } else {
                                $msgs[] = sprintf('&nbsp;&nbsp;<span>' . _MD_AM_TEMPLATE_RECOMPILED . '</span>', '<strong>' . $tpl['file'] . '</strong>');
                            }
                        }
                    }
                    unset($tpldata);
                } else {
                    $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_DELETE_FAIL . '</span>', $tpl['file']);
                }
            }
        }
        $blocks = $module->getInfo('blocks');
        $msgs[] = _MD_AM_MOD_REBUILD_BLOCKS;
        if ($blocks != false) {
            $count = count($blocks);
            $showfuncs = array();
            $funcfiles = array();
            for ($i = 1; $i <= $count; $i++) {
                if (isset($blocks[$i]['show_func']) && $blocks[$i]['show_func'] != '' && isset($blocks[$i]['file']) && $blocks[$i]['file'] != '') {
                    $editfunc = isset($blocks[$i]['edit_func']) ? $blocks[$i]['edit_func'] : '';
                    $showfuncs[] = $blocks[$i]['show_func'];
                    $funcfiles[] = $blocks[$i]['file'];
                    $template = '';
                    if (isset($blocks[$i]['template']) && trim($blocks[$i]['template']) != '') {
                        $content =& xoops_module_gettemplate($dirname, $blocks[$i]['template'], true);
                    }
                    if (!$content) {
                        $content = '';
                    } else {
                        $template = $blocks[$i]['template'];
                    }
                    $options = '';
                    if (!empty($blocks[$i]['options'])) {
                        $options = $blocks[$i]['options'];
                    }
                    $sql = "SELECT bid, name FROM " . $db->prefix('newblocks') . " WHERE mid='" . (int) $module->getVar('mid') . "' AND func_num='" . (int) $i . "' AND show_func='" . addslashes($blocks[$i]['show_func']) . "' AND func_file='" . addslashes($blocks[$i]['file']) . "'";
                    $fresult = $db->query($sql);
                    $fcount = 0;
                    while ($fblock = $db->fetchArray($fresult)) {
                        $fcount++;
                        $sql = "UPDATE " . $db->prefix("newblocks") . " SET name='" . addslashes($blocks[$i]['name']) . "', edit_func='" . addslashes($editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . " WHERE bid='" . (int) $fblock['bid'] . "'";
                        $result = $db->query($sql);
                        if (!$result) {
                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_UPDATE_FAIL, $fblock['name']);
                        } else {
                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_UPDATED, '<strong>' . $fblock['name'] . '</strong>', '<strong>' . icms_conv_nr2local($fblock['bid']) . '</strong>');
                            if ($template != '') {
                                $tplfile =& $tplfile_handler->find('default', 'block', $fblock['bid']);
                                if (count($tplfile) == 0) {
                                    $tplfile_new =& $tplfile_handler->create();
                                    $tplfile_new->setVar('tpl_module', $dirname);
                                    $tplfile_new->setVar('tpl_refid', (int) $fblock['bid']);
                                    $tplfile_new->setVar('tpl_tplset', 'default');
                                    $tplfile_new->setVar('tpl_file', $blocks[$i]['template'], true);
                                    $tplfile_new->setVar('tpl_type', 'block');
                                } else {
                                    $tplfile_new = $tplfile[0];
                                }
                                $tplfile_new->setVar('tpl_source', $content, true);
                                $tplfile_new->setVar('tpl_desc', $blocks[$i]['description'], true);
                                $tplfile_new->setVar('tpl_lastmodified', time());
                                $tplfile_new->setVar('tpl_lastimported', 0);
                                if (!$tplfile_handler->insert($tplfile_new)) {
                                    $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_UPDATE_FAIL . '</span>', '<strong>' . $blocks[$i]['template'] . '</strong>');
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;Template <b>' . $blocks[$i]['template'] . '</b> updated.';
                                    if ($icmsConfig['template_set'] == 'default') {
                                        if (!icms_view_Tpl::template_touch($tplfile_new->getVar('tpl_id'))) {
                                            $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>', '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        } else {
                                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_RECOMPILED, '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if ($fcount == 0) {
                        $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq');
                        $block_name = addslashes($blocks[$i]['name']);
                        $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 ('" . (int) $newbid . "', '" . (int) $module->getVar('mid') . "', '" . (int) $i . "','" . addslashes($options) . "','" . $block_name . "', '" . $block_name . "', '', '1', '0', '0', 'M', 'H', '1', '" . addslashes($dirname) . "', '" . addslashes($blocks[$i]['file']) . "', '" . addslashes($blocks[$i]['show_func']) . "', '" . addslashes($editfunc) . "', '" . $template . "', '0', '" . time() . "')";
                        $result = $db->query($sql);
                        if (!$result) {
                            $msgs[] = '&nbsp;&nbsp;ERROR: Could not create ' . $blocks[$i]['name'];
                            echo $sql;
                        } else {
                            if (empty($newbid)) {
                                $newbid = $db->getInsertId();
                            }
                            $groups =& icms::$user->getGroups();
                            $gperm_handler = icms::handler('icms_member_groupperm');
                            foreach ($groups as $mygroup) {
                                $bperm =& $gperm_handler->create();
                                $bperm->setVar('gperm_groupid', (int) $mygroup);
                                $bperm->setVar('gperm_itemid', (int) $newbid);
                                $bperm->setVar('gperm_name', 'block_read');
                                $bperm->setVar('gperm_modid', 1);
                                if (!$gperm_handler->insert($bperm)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add block access right. Block ID: <b>' . $newbid . '</b> Group ID: <b>' . $mygroup . '</b></span>';
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;Added block access right. Block ID: <b>' . $newbid . '</b> Group ID: <b>' . $mygroup . '</b>';
                                }
                            }
                            if ($template != '') {
                                $tplfile =& $tplfile_handler->create();
                                $tplfile->setVar('tpl_module', $dirname);
                                $tplfile->setVar('tpl_refid', (int) $newbid);
                                $tplfile->setVar('tpl_source', $content, true);
                                $tplfile->setVar('tpl_tplset', 'default');
                                $tplfile->setVar('tpl_file', $blocks[$i]['template'], true);
                                $tplfile->setVar('tpl_type', 'block');
                                $tplfile->setVar('tpl_lastimported', 0);
                                $tplfile->setVar('tpl_lastmodified', time());
                                $tplfile->setVar('tpl_desc', $blocks[$i]['description'], true);
                                if (!$tplfile_handler->insert($tplfile)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>' . $blocks[$i]['template'] . '</b> to the database.</span>';
                                } else {
                                    $newid = $tplfile->getVar('tpl_id');
                                    $msgs[] = '&nbsp;&nbsp;Template <b>' . $blocks[$i]['template'] . '</b> added to the database.';
                                    if ($icmsConfig['template_set'] == 'default') {
                                        if (!icms_view_Tpl::template_touch($newid)) {
                                            $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>', '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        } else {
                                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_RECOMPILED, '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        }
                                    }
                                }
                            }
                            $msgs[] = '&nbsp;&nbsp;Block <b>' . $blocks[$i]['name'] . '</b> created. Block ID: <b>' . $newbid . '</b>';
                            $sql = "INSERT INTO " . $db->prefix('block_module_link') . " (block_id, module_id, page_id) VALUES ('" . (int) $newbid . "', '0', '1')";
                            $db->query($sql);
                        }
                    }
                }
            }
            $icms_block_handler = icms::handler('icms_view_block');
            $block_arr = $icms_block_handler->getByModule($module->getVar('mid'));
            foreach ($block_arr as $block) {
                if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) {
                    $sql = sprintf("DELETE FROM %s WHERE bid = '%u'", $db->prefix('newblocks'), (int) $block->getVar('bid'));
                    if (!$db->query($sql)) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete block <b>' . $block->getVar('name') . '</b>. Block ID: <b>' . $block->getVar('bid') . '</b></span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;Block <b>' . $block->getVar('name') . ' deleted. Block ID: <b>' . $block->getVar('bid') . '</b>';
                        if ($block->getVar('template') != '') {
                            $tplfiles =& $tplfile_handler->find(null, 'block', $block->getVar('bid'));
                            if (is_array($tplfiles)) {
                                $btcount = count($tplfiles);
                                for ($k = 0; $k < $btcount; $k++) {
                                    if (!$tplfile_handler->delete($tplfiles[$k])) {
                                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not remove deprecated block template. (ID: <b>' . $tplfiles[$k]->getVar('tpl_id') . '</b>)</span>';
                                    } else {
                                        $msgs[] = '&nbsp;&nbsp;Block template <b>' . $tplfiles[$k]->getVar('tpl_file') . '</b> deprecated.';
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // first delete all config entries
        $config_handler = icms::handler('icms_config');
        $configs =& $config_handler->getConfigs(new icms_db_criteria_Item('conf_modid', $module->getVar('mid')));
        $confcount = count($configs);
        $config_delng = array();
        if ($confcount > 0) {
            $msgs[] = 'Deleting module config options...';
            for ($i = 0; $i < $confcount; $i++) {
                if (!$config_handler->deleteConfig($configs[$i])) {
                    $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>';
                    // save the name of config failed to delete for later use
                    $config_delng[] = $configs[$i]->getvar('conf_name');
                } else {
                    $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N');
                    $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype');
                    $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
                    $msgs[] = '&nbsp;&nbsp;Config data deleted from the database. Config ID: <b>' . $configs[$i]->getVar('conf_id') . '</b>';
                }
            }
        }
        // now reinsert them with the new settings
        $configs = $module->getInfo('config');
        if ($configs != false) {
            if ($module->getVar('hascomments') != 0) {
                include_once ICMS_ROOT_PATH . '/include/comment_constants.php';
                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)));
                array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0));
            }
        } else {
            if ($module->getVar('hascomments') != 0) {
                $configs = array();
                include_once ICMS_ROOT_PATH . '/include/comment_constants.php';
                $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));
                $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0);
            }
        }
        // RMV-NOTIFY
        if ($module->getVar('hasnotification') != 0) {
            if (empty($configs)) {
                $configs = array();
            }
            // Main notification options
            include_once ICMS_ROOT_PATH . '/include/notification_constants.php';
            include_once ICMS_ROOT_PATH . '/include/notification_functions.php';
            $options = array();
            $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
            $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
            $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
            $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
            //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
            $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options);
            // Event specific notification options
            // FIXME: for some reason the default doesn't come up properly
            //  initially is ok, but not when 'update' module..
            $options = array();
            $categories =& icms_data_notification_Handler::categoryInfo('', $module->getVar('mid'));
            foreach ($categories as $category) {
                $events =& icms_data_notification_Handler::categoryEvents($category['name'], false, $module->getVar('mid'));
                foreach ($events as $event) {
                    if (!empty($event['invisible'])) {
                        continue;
                    }
                    $option_name = $category['title'] . ' : ' . $event['title'];
                    $option_value = $category['name'] . '-' . $event['name'];
                    $options[$option_name] = $option_value;
                    //$configs[] = array ('name' => icms_data_notification_Handler::generateConfig($category,$event,'name'), 'title' => icms_data_notification_Handler::generateConfig($category,$event,'title_constant'), 'description' => icms_data_notification_Handler::generateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
                }
            }
            $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options);
        }
        if ($configs != false) {
            $msgs[] = 'Adding module config data...';
            $config_handler = icms::handler('icms_config');
            $order = 0;
            foreach ($configs as $config) {
                // only insert ones that have been deleted previously with success
                if (!in_array($config['name'], $config_delng)) {
                    $confobj =& $config_handler->createConfig();
                    $confobj->setVar('conf_modid', (int) $newmid);
                    $confobj->setVar('conf_catid', 0);
                    $confobj->setVar('conf_name', $config['name']);
                    $confobj->setVar('conf_title', $config['title'], true);
                    $confobj->setVar('conf_desc', $config['description'], true);
                    $confobj->setVar('conf_formtype', $config['formtype']);
                    $confobj->setVar('conf_valuetype', $config['valuetype']);
                    if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) {
                        // preserver the old value if any
                        // form type and value type must be the same
                        $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true);
                    } else {
                        $confobj->setConfValueForInput($config['default'], true);
                        //$confobj->setVar('conf_value', $config['default'], true);
                    }
                    $confobj->setVar('conf_order', $order);
                    $confop_msgs = '';
                    if (isset($config['options']) && is_array($config['options'])) {
                        foreach ($config['options'] as $key => $value) {
                            $confop =& $config_handler->createConfigOption();
                            $confop->setVar('confop_name', $key, true);
                            $confop->setVar('confop_value', $value, true);
                            $confobj->setConfOptions($confop);
                            $confop_msgs .= '<br />&nbsp;&nbsp;&nbsp;&nbsp;Config option added. Name: <b>' . $key . '</b> Value: <b>' . $value . '</b>';
                            unset($confop);
                        }
                    }
                    $order++;
                    if (false != $config_handler->insertConfig($confobj)) {
                        $msgs[] = '&nbsp;&nbsp;Config <b>' . $config['name'] . '</b> added to the database.' . $confop_msgs;
                    } else {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert config <b>' . $config['name'] . '</b> to the database.</span>';
                    }
                    unset($confobj);
                }
            }
            unset($configs);
        }
        // add module specific tasks to system autotasks list
        $atasks = $module->getInfo('autotasks');
        $atasks_handler =& icms_getModuleHandler('autotasks', 'system');
        if (count($atasks) > 0) {
            $msgs[] = 'Updating autotasks...';
            $criteria = new icms_db_criteria_Compo();
            $criteria->add(new icms_db_criteria_Item('sat_type', 'addon/' . $module->getInfo('dirname')));
            $items_atasks = $atasks_handler->getObjects($criteria, false);
            foreach ($items_atasks as $task) {
                $taskID = (int) $task->getVar('sat_addon_id');
                $atasks[$taskID]['enabled'] = $task->getVar('sat_enabled');
                $atasks[$taskID]['repeat'] = $task->getVar('sat_repeat');
                $atasks[$taskID]['interval'] = $task->getVar('sat_interval');
                $atasks[$taskID]['name'] = $task->getVar('sat_name');
            }
            $atasks_handler->deleteAll($criteria);
            foreach ($atasks as $taskID => $taskData) {
                if (!isset($taskData['code']) || trim($taskData['code']) == '') {
                    continue;
                }
                $task =& $atasks_handler->create();
                if (isset($taskData['enabled'])) {
                    $task->setVar('sat_enabled', $taskData['enabled']);
                }
                if (isset($taskData['repeat'])) {
                    $task->setVar('sat_repeat', $taskData['repeat']);
                }
                if (isset($taskData['interval'])) {
                    $task->setVar('sat_interval', $taskData['interval']);
                }
                if (isset($taskData['onfinish'])) {
                    $task->setVar('sat_onfinish', $taskData['onfinish']);
                }
                $task->setVar('sat_name', $taskData['name']);
                $task->setVar('sat_code', sprintf("require ICMS_ROOT_PATH . \"/modules/%s/%s\";", $module->getInfo('dirname'), addslashes($taskData['code'])));
                $task->setVar('sat_type', 'addon/' . $module->getInfo('dirname'));
                $task->setVar('sat_addon_id', (int) $taskID);
                if (!$atasks_handler->insert($task)) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert autotask to db. Name: <b>' . $taskData['name'] . '</b></span>';
                } else {
                    $msgs[] = '&nbsp;&nbsp;Updated task from autotasks list. Task Name: <b>' . $taskData['name'] . '</b>';
                }
            }
            unset($atasks, $atasks_handler, $task, $taskData, $criteria, $items, $taskID);
        }
        // execute module specific update script if any
        $update_script = $module->getInfo('onUpdate');
        $ModName = $module->getInfo('modname') != '' ? trim($module->getInfo('modname')) : $dirname;
        if (false != $update_script && trim($update_script) != '') {
            include_once ICMS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($update_script);
            $is_IPF = $module->getInfo('object_items');
            if (!empty($is_IPF)) {
                $icmsDatabaseUpdater = icms_db_legacy_Factory::getDatabaseUpdater();
                $icmsDatabaseUpdater->moduleUpgrade($module, true);
                foreach ($icmsDatabaseUpdater->_messages as $msg) {
                    $msgs[] = $msg;
                }
            }
            if (function_exists('xoops_module_update_' . $ModName)) {
                $func = 'xoops_module_update_' . $ModName;
                if (!$func($module, $prev_version, $prev_dbversion)) {
                    $msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
                } else {
                    $msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
                }
            } elseif (function_exists('icms_module_update_' . $ModName)) {
                $func = 'icms_module_update_' . $ModName;
                if (!$func($module, $prev_version, $prev_dbversion)) {
                    $msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
                } else {
                    $msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
                }
            }
        }
        $msgs[] = '</code><p>' . sprintf(_MD_AM_OKUPD, '<b>' . $module->getVar('name') . '</b>') . '</p>';
    }
    $ret = '<code>';
    foreach ($msgs as $msg) {
        $ret .= $msg . '<br />';
    }
    return $ret;
}
Example #4
0
			echo $err;
		}
		echo '</code><br /><a href="admin.php?fct=tplsets">' . _MD_AM_BTOTADMIN . '</a>';
		icms_cp_footer();
		break;

	case 'previewtpl':
		if (!icms::$security->check()) {
			redirect_header('admin.php?fct=tplsets', 3, implode('<br />', icms::$security->getErrors()));
		}

			
		$html = icms_core_DataFilter::stripSlashesGPC($html);
		$tpltpl_handler =& icms::handler('icms_view_template_file');
		$tplfile =& $tpltpl_handler->get($id, TRUE);
		$xoopsTpl = new icms_view_Tpl();

		if (is_object($tplfile)) {
			$dummylayout = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
			. '<html><head><meta http-equiv="content-type" content="text/html; charset=' . _CHARSET 
			. '" /><meta http-equiv="content-language" content="' . _LANGCODE 
			. '" /><title>' . $icmsConfig['sitename'] . '</title>'
			. '<link rel="stylesheet" type="text/css" media="screen" href="' . ICMS_URL . '/icms' 
				. (( defined('_ADM_USE_RTL') && _ADM_USE_RTL ) 
					? '_rtl'
					:'') 
				. '.css" /><link rel="stylesheet" type="text/css" media="screen" href="' 
				. xoops_getcss($icmsConfig['theme_set']) . '" />';

			$css =& $tpltpl_handler->find($icmsConfig['template_set'], 'css', 0, NULL, NULL, TRUE);
			$csscount = count($css);
Example #5
0
 public function __construct()
 {
     parent::__construct();
     $this->_deprecated = icms_core_Debug::setDeprecated('icms_view_Tpl', sprintf(_CORE_REMOVE_IN_VERSION, '1.4'));
 }
Example #6
0
		if (isset($iconbig) && $iconbig == FALSE) {
			echo '<div class="CPbigTitle" style="background-image: url(' . ICMS_MODULES_URL . '/system/admin/preferences/images/preferences_big.png);">' . $modlink . ' &raquo; ' . _PREFERENCES . '</div>';

		}
		if (isset($iconbig) && $iconbig == TRUE) {
			echo '<div class="CPbigTitle" style="background-image: url(' . ICMS_MODULES_URL . '/' . $module->getVar('dirname') . '/' . $iconbig . ')">' . $modlink . ' &raquo; ' . _PREFERENCES . '</div>';
		}
		$form->display();
		icms_cp_footer();
		break;

	case 'save':
		if (!icms::$security->check()) {
			redirect_header('admin.php?fct=preferences', 3, implode('<br />', icms::$security->getErrors()));
		}
		$xoopsTpl = new icms_view_Tpl();
		$count = count($conf_ids);
		$tpl_updated = FALSE;
		$theme_updated = FALSE;
		$startmod_updated = FALSE;
		$lang_updated = FALSE;
		$encryption_updated = FALSE;
		$purifier_style_updated = FALSE;
		$saved_config_items = array();
		if ($count > 0) {
			for ($i = 0; $i < $count; $i++) {
				$config = & $config_handler->getConfig($conf_ids[$i]);
				$new_value = & ${$config->getVar('conf_name')};
				$old_value = $config->getVar('conf_value');
				icms::$preload->triggerEvent('savingSystemAdminPreferencesItem', array((int) $config->getVar('conf_catid'), $config->getVar('conf_name'), $config->getVar('conf_value')));
Example #7
0
 /**
  * Render the feed and display it directly
  */
 public function render()
 {
     icms::$logger->disableLogger();
     //header ('Content-Type:text/xml; charset='._CHARSET);
     $xoopsOption['template_main'] = "db:system_rss.html";
     $tpl = new icms_view_Tpl();
     $tpl->assign('channel_title', $this->title);
     $tpl->assign('channel_link', $this->url);
     $tpl->assign('channel_desc', $this->description);
     $tpl->assign('channel_webmaster', $this->webMaster);
     $tpl->assign('channel_editor', $this->channelEditor);
     $tpl->assign('channel_category', $this->category);
     $tpl->assign('channel_generator', $this->generator);
     $tpl->assign('channel_language', $this->language);
     $tpl->assign('channel_lastbuild', $this->lastbuild);
     $tpl->assign('channel_copyright', $this->copyright);
     $tpl->assign('channel_width', $this->width);
     $tpl->assign('channel_height', $this->height);
     $tpl->assign('channel_ttl', $this->ttl);
     $tpl->assign('image_url', $this->image['url']);
     foreach ($this->feeds as $feed) {
         $tpl->append('items', $feed);
     }
     $tpl->display('db:system_rss.html');
 }
Example #8
0
 function protector_oninstall_base($module, $mydirname)
 {
     // transations on module install
     global $ret;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'protector_message_append_oninstall');
         $ret = array();
     } else {
         if (!is_array($ret)) {
             $ret = array();
         }
     }
     $db =& icms_db_Factory::instance();
     $mid = $module->getVar('mid');
     // TABLES (loading mysql.sql)
     $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
     $prefix_mod = $db->prefix() . '_' . $mydirname;
     if (file_exists($sql_file_path)) {
         $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br /> Creating tables...";
         $sqlutil = new icms_db_legacy_mysql_Utility();
         $sql_query = trim(file_get_contents($sql_file_path));
         $sqlutil->splitMySqlFile($pieces, $sql_query);
         $created_tables = array();
         foreach ($pieces as $piece) {
             $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
             if (!$prefixed_query) {
                 $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />";
                 return false;
             }
             if (!$db->query($prefixed_query[0])) {
                 $ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />';
                 //var_dump( $db->error() ) ;
                 return false;
             } else {
                 if (!in_array($prefixed_query[4], $created_tables)) {
                     $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />';
                     $created_tables[] = $prefixed_query[4];
                 } else {
                     $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />';
                 }
             }
         }
     }
     // TEMPLATES
     $tplfile_handler =& new icms_view_template_file_Handler(icms::$xoopsDB);
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />';
                     // generate compiled file
                     if (!icms_view_Tpl::template_touch($tplid)) {
                         $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />';
                     } else {
                         $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />';
                     }
                 }
             }
         }
         closedir($handler);
     }
     /*
     Fixes Bug #619 : parse Error
     */
     if (defined('ICMS_PRELOAD_PATH') && !file_exists(ICMS_PRELOAD_PATH . '/protector.php') && (!defined('PROTECTOR_POSTCHECK_INCLUDED') || !defined('PROTECTOR_PRECHECK_INCLUDED'))) {
         if (icms_core_Filesystem::copyRecursive(ICMS_TRUST_PATH . '/modules/protector/patches/ImpressCMS1.1/preload_protector.php', ICMS_PRELOAD_PATH . '/protector.php')) {
             $ret[] = 'Successfully moved protector preload<br />';
         } else {
             $ret[] = icms_core_Message::error("Failed to move protector preload - your site is not protected.", "", FALSE);
         }
     }
     icms_view_Tpl::template_clear_module_cache($mid);
     return true;
 }
Example #9
0
 /**
  * Clear the module cache
  *
  * Prior to PHP5.3.0, when refering to the class with a variable, like $icmsAdminTpl, you
  * still need to use the arrow operator instead of ::
  * http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php
  *
  * The proper way to use this would be
  * icms_view_Tpl::template_clear_module_cache($tplid);
  * or
  * $icmsAdminTpl->template_clear_module_cache($tplid);
  *
  * @param   int $mid    Module ID
  * @return
  **/
 public static function template_clear_module_cache($mid)
 {
     $icms_block_handler = icms::handler('icms_view_block');
     $block_arr = $icms_block_handler->getByModule($mid);
     $count = count($block_arr);
     if ($count > 0) {
         $xoopsTpl = new icms_view_Tpl();
         $xoopsTpl->caching = 2;
         for ($i = 0; $i < $count; $i++) {
             if ($block_arr[$i]->getVar('template') != '') {
                 $xoopsTpl->clear_cache('db:' . $block_arr[$i]->getVar('template'), 'blk_' . $block_arr[$i]->getVar('bid'));
             }
         }
     }
 }
Example #10
0
 function protector_onupdate_base($module, $mydirname)
 {
     // transations on module update
     global $msgs;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'protector_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& icms_db_Factory::instance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] == 'varchar(30)') {
         $db->queryF("ALTER TABLE " . $db->prefix("config") . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     list(, $create_string) = $db->fetchRow($db->query("SHOW CREATE TABLE " . $db->prefix("config")));
     foreach (explode('KEY', $create_string) as $line) {
         if (preg_match('/(\\`conf\\_title_\\d+\\`) \\(\\`conf\\_title\\`\\)/', $line, $regs)) {
             $db->query("ALTER TABLE " . $db->prefix("config") . " DROP KEY " . $regs[1]);
         }
     }
     $db->query("ALTER TABLE " . $db->prefix("config") . " ADD KEY `conf_title` (`conf_title`)");
     // 2.x -> 3.0
     list(, $create_string) = $db->fetchRow($db->query("SHOW CREATE TABLE " . $db->prefix($mydirname . "_log")));
     if (preg_match('/timestamp\\(/i', $create_string)) {
         $db->query("ALTER TABLE " . $db->prefix($mydirname . "_log") . " MODIFY `timestamp` DATETIME");
     }
     // TEMPLATES (all templates have been already removed by modulesadmin)
     $tplfile_handler =& icms::handler('icms_view_template_file');
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                     // generate compiled file
                     if (!icms_view_Tpl::template_touch($tplid)) {
                         $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
                     }
                 }
             }
         }
         closedir($handler);
     }
     if (defined(ICMS_PRELOAD_PATH) && !file_exists(ICMS_PRELOAD_PATH . '/protector.php') && (!defined('PROTECTOR_POSTCHECK_INCLUDED') || !defined('PROTECTOR_PRECHECK_INCLUDED')) && function_exists('icms_copyr')) {
         icms_core_Filesystem::copyRecursive(ICMS_TRUST_PATH . '/modules/protector/patches/ImpressCMS1.1/preload_protector.php', ICMS_PRELOAD_PATH . '/protector.php');
     }
     icms_view_Tpl::template_clear_module_cache($mid);
     return true;
 }
Example #11
0
 *
 * @copyright	The ImpressCMS Project http://www.impresscms.org/
 * @license		http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
 * @package		core
 * @since		1.2
 * @author		Rodrigo Pereira Lima (AKA TheRplima) <*****@*****.**>
 * @version		$Id: image-edit.php 1244 2008-03-18 17:09:11Z real_therplima $
 */
$xoopsOption['nodebug'] = 1;
if (file_exists('../../mainfile.php')) {
    include_once '../../mainfile.php';
}
defined('ICMS_ROOT_PATH') or die('ImpressCMS root path not defined');
include_once ICMS_LIBRARIES_PATH . '/wideimage/lib/WideImage.php';
icms_loadLanguageFile('system', 'images', true);
$icmsTpl = new icms_view_Tpl();
$icmsTpl->assign('icms_url', ICMS_URL);
$icmsTpl->assign('icms_root_path', ICMS_ROOT_PATH);
$icmsTpl->assign('icms_lib_path', ICMS_LIBRARIES_PATH);
$icmsTpl->assign('icms_lib_url', ICMS_LIBRARIES_URL);
$icmsTpl->assign('icms_imanager_temp_path', ICMS_IMANAGER_FOLDER_PATH . '/temp');
$icmsTpl->assign('icms_imanager_temp_url', ICMS_IMANAGER_FOLDER_URL . '/temp');
$image_id = isset($_GET['image_id']) ? (int) $_GET['image_id'] : (isset($_POST['image_id']) ? (int) $_POST['image_id'] : null);
$uniq = isset($_GET['uniq']) ? $_GET['uniq'] : (isset($_POST['uniq']) ? $_POST['uniq'] : null);
$type = isset($_GET['type']) ? filter_input(INPUT_GET, 'type') : (isset($_POST['type']) ? filter_input(INPUT_POST, 'type') : null);
$target = isset($_GET['target']) ? filter_input(INPUT_GET, 'target') : (isset($_POST['target']) ? filter_input(INPUT_POST, 'target') : null);
$op = isset($_GET['op']) ? filter_input(INPUT_GET, 'op') : (isset($_POST['op']) ? filter_input(INPUT_POST, 'op') : null);
if (!file_exists(ICMS_IMANAGER_FOLDER_PATH . '/temp/')) {
    if (!@mkdir(ICMS_IMANAGER_FOLDER_PATH . '/temp', 0777)) {
        echo '<script>alert("Temporary folder doesn\'t exist and cannot be created. Create it manually and try again. Folder: ' . str_ireplace(ICMS_ROOT_PATH, "", ICMS_IMANAGER_FOLDER_PATH) . '/temp/' . '");window.close();</script>';
        exit;
Example #12
0
/**
 * Logic for updating a module
 *
 * @todo	add installation_notify(), only if the version of the module changes
 *
 * @param 	str $dirname
 * @return	str	Result messages from the module update
 */
function icms_module_update($dirname) {
	global $icmsConfig, $icmsAdminTpl;

	$msgs = array();

	$dirname = trim($dirname);
	$module_handler = icms::handler('icms_module');
	$module =& $module_handler->getByDirname($dirname);

	// Save current version for use in the update function
	$prev_version = $module->getVar('version');
	$prev_dbversion = $module->getVar('dbversion');
	/**
	 * http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php
	 * @todo PHP5.3.0 supports $icmsAdminTpl::template_clear_module_cache($module->getVar('mid'));
	 */
	$icmsAdminTpl->template_clear_module_cache($module->getVar('mid'));
	// we dont want to change the module name set by admin
	$temp_name = $module->getVar('name');
	$module->loadInfoAsVar($dirname);
	$module->setVar('name', $temp_name);

	/*
	 * ensure to only update those fields that are currently available in the database
	 * this is required to allow structural updates for the module table
	 */
	$table = new icms_db_legacy_updater_Table("modules");
	foreach (array_keys($module->vars) as $k) {
		if (!$table->fieldExists($k)) {
			unset($module->vars[$k]);
		}
	}

	if (!$module_handler->insert($module)) {
		$msgs[] = sprintf('<p>' . _MD_AM_UPDATE_FAIL . '</p>', $module->getVar('name'));
	} else {
		$newmid = $module->getVar('mid');
		$msgs[] = _MD_AM_MOD_DATA_UPDATED;
		$tplfile_handler =& icms::handler('icms_view_template_file');
		$deltpl =& $tplfile_handler->find('default', 'module', $module->getVar('mid'));
		$delng = array();
		if (is_array($deltpl)) {
			$xoopsDelTpl = new icms_view_Tpl();
			// clear cache files
			$xoopsDelTpl->clear_cache(NULL, 'mod_' . $dirname);
			// delete template file entry in db
			$dcount = count($deltpl);
			for ($i = 0; $i < $dcount; $i++) {
				if (!$tplfile_handler->delete($deltpl[$i])) {
					$delng[] = $deltpl[$i]->getVar('tpl_file');
				}
			}
		}

		$templates = $module->getInfo('templates');
		if ($templates !== FALSE) {
			$msgs[] = _MD_AM_MOD_UP_TEM;
			foreach ($templates as $tpl) {
				$tpl['file'] = trim($tpl['file']);
				if (!in_array($tpl['file'], $delng)) {
					$tpldata =& xoops_module_gettemplate($dirname, $tpl['file']);
					$tplfile =& $tplfile_handler->create();
					$tplfile->setVar('tpl_refid', $newmid);
					$tplfile->setVar('tpl_lastimported', 0);
					$tplfile->setVar('tpl_lastmodified', time());
					if (preg_match("/\.css$/i", $tpl['file'])) {
						$tplfile->setVar('tpl_type', 'css');
					} else {
						$tplfile->setVar('tpl_type', 'module');
					}
					$tplfile->setVar('tpl_source', $tpldata, TRUE);
					$tplfile->setVar('tpl_module', $dirname);
					$tplfile->setVar('tpl_tplset', 'default');
					$tplfile->setVar('tpl_file', $tpl['file'], TRUE);
					$tplfile->setVar('tpl_desc', $tpl['description'], TRUE);
					if (!$tplfile_handler->insert($tplfile)) {
						$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">'
						. _MD_AM_TEMPLATE_INSERT_FAIL . '</span>', '<strong>' . $tpl['file'] . '</strong>');
					} else {
						$newid = $tplfile->getVar('tpl_id');
						$msgs[] = sprintf('&nbsp;&nbsp;<span>' . _MD_AM_TEMPLATE_INSERTED . '</span>', '<strong>' . $tpl['file'] . '</strong>', '<strong>' . $newid . '</strong>');
						if ($icmsConfig['template_set'] == 'default') {
							if (!$icmsAdminTpl->template_touch($newid)) {
								$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">'
								. _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>', '<strong>' . $tpl['file'] . '</strong>');
							} else {
								$msgs[] = sprintf('&nbsp;&nbsp;<span>' . _MD_AM_TEMPLATE_RECOMPILED . '</span>', '<strong>' . $tpl['file'] . '</strong>');
							}
						}
					}
					unset($tpldata);
				} else {
					$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_DELETE_FAIL . '</span>', $tpl['file']);
				}
			}
		}
		$blocks = $module->getInfo('blocks');
		$msgs[] = _MD_AM_MOD_REBUILD_BLOCKS;
		if ($blocks !== FALSE) {
			$count = count($blocks);
			$showfuncs = array();
			$funcfiles = array();
			for ($i = 1; $i <= $count; $i++) {
				if (isset($blocks[$i]['show_func']) && $blocks[$i]['show_func'] != '' && isset($blocks[$i]['file']) && $blocks[$i]['file'] != '') {
					$editfunc = isset($blocks[$i]['edit_func']) ? $blocks[$i]['edit_func'] : '';
					$showfuncs[] = $blocks[$i]['show_func'];
					$funcfiles[] = $blocks[$i]['file'];
					$template = $content = '';
					if ((isset($blocks[$i]['template']) && trim($blocks[$i]['template']) != '')) {
						$content =& xoops_module_gettemplate($dirname, $blocks[$i]['template'], TRUE);
					}
					if (!$content) {
						$content = '';
					} else {
						$template = $blocks[$i]['template'];
					}
					$options = '';
					if (!empty($blocks[$i]['options'])) {
						$options = $blocks[$i]['options'];
					}
					$sql = "SELECT bid, name FROM " . icms::$xoopsDB->prefix('newblocks')
						. " WHERE mid='" . (int) $module->getVar('mid')
						. "' AND func_num='". (int) $i
						. "' AND show_func='" . addslashes($blocks[$i]['show_func'])
						. "' AND func_file='" . addslashes($blocks[$i]['file']) . "'";
					$fresult = icms::$xoopsDB->query($sql);
					$fcount = 0;
					while ($fblock = icms::$xoopsDB->fetchArray($fresult)) {
						$fcount++;
						$sql = "UPDATE " . icms::$xoopsDB->prefix("newblocks")
							. " SET name='" . addslashes($blocks[$i]['name'])
							. "', edit_func='" . addslashes($editfunc)
							. "', content='', template='" . $template
							. "', last_modified=" . time()
							. " WHERE bid='". (int) $fblock['bid'] . "'";
						$result = icms::$xoopsDB->query($sql);
						if (!$result) {
							$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_UPDATE_FAIL, $fblock['name']);
						} else {
							$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_UPDATED,
								'<strong>' . $fblock['name'] . '</strong>',
								'<strong>' . icms_conv_nr2local($fblock['bid']) . '</strong>');
							if ($template != '') {
								$tplfile =& $tplfile_handler->find('default', 'block', $fblock['bid']);
								if (count($tplfile) == 0) {
									$tplfile_new =& $tplfile_handler->create();
									$tplfile_new->setVar('tpl_module', $dirname);
									$tplfile_new->setVar('tpl_refid', (int) $fblock['bid']);
									$tplfile_new->setVar('tpl_tplset', 'default');
									$tplfile_new->setVar('tpl_file', $blocks[$i]['template'], TRUE);
									$tplfile_new->setVar('tpl_type', 'block');
								}
								else {
									$tplfile_new = $tplfile[0];
								}
								$tplfile_new->setVar('tpl_source', $content, TRUE);
								$tplfile_new->setVar('tpl_desc', $blocks[$i]['description'], TRUE);
								$tplfile_new->setVar('tpl_lastmodified', time());
								$tplfile_new->setVar('tpl_lastimported', 0);
								if (!$tplfile_handler->insert($tplfile_new)) {
									$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">'
										. _MD_AM_TEMPLATE_UPDATE_FAIL . '</span>', '<strong>' . $blocks[$i]['template'] . '</strong>');
								} else {
									$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_UPDATED, '<strong>' . $blocks[$i]['template'] . '</strong>');
									if ($icmsConfig['template_set'] == 'default') {
										if (!$icmsAdminTpl->template_touch($tplfile_new->getVar('tpl_id'))) {
											$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">'
												. _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>', '<strong>' . $blocks[$i]['template'] . '</strong>');
										} else {
											$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_RECOMPILED, '<strong>' . $blocks[$i]['template'] . '</strong>');
										}
									}
								}
							}
						}
					}

					if ($fcount == 0) {
						$newbid = icms::$xoopsDB->genId(icms::$xoopsDB->prefix('newblocks') . '_bid_seq');
						$block_name = addslashes($blocks[$i]['name']);
						/* @todo properly handle the block_type when updating the system module */
						$sql = "INSERT INTO " . icms::$xoopsDB->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 ('"
							. (int) $newbid . "', '". (int) $module->getVar('mid') . "', '". (int) $i . "', '" . addslashes($options) . "', '" . $block_name . "', '" . $block_name . "', '', '1', '0', '0', 'M', 'H', '1', '" . addslashes($dirname) . "', '" . addslashes($blocks[$i]['file']) . "', '" . addslashes($blocks[$i]['show_func']) . "', '" . addslashes($editfunc) . "', '" . $template . "', '0', '" . time() . "')";
						$result = icms::$xoopsDB->query($sql);
						if (!$result) {
							$msgs[] = sprintf('&nbsp;&nbsp;' .  _MD_AM_CREATE_FAIL, $blocks[$i]['name']);
							echo $sql;
						} else {
							if (empty($newbid)) {
								$newbid = icms::$xoopsDB->getInsertId();
							}
							$groups =& icms::$user->getGroups();
							$gperm_handler = icms::handler('icms_member_groupperm');
							foreach ($groups as $mygroup) {
								$bperm =& $gperm_handler->create();
								$bperm->setVar('gperm_groupid', (int) $mygroup);
								$bperm->setVar('gperm_itemid', (int) $newbid);
								$bperm->setVar('gperm_name', 'block_read');
								$bperm->setVar('gperm_modid', 1);
								if (!$gperm_handler->insert($bperm)) {
									$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_BLOCK_ACCESS_FAIL . '</span>',
										'<strong>' . $newbid . '</strong>',
										'<strong>' . $mygroup . '</strong>');
								} else {
									$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_ACCESS_ADDED,
										'<strong>' . $newbid . '</strong>',
										'<strong>' . $mygroup . '</strong>');
								}
							}

							if ($template != '') {
								$tplfile =& $tplfile_handler->create();
								$tplfile->setVar('tpl_module', $dirname);
								$tplfile->setVar('tpl_refid', (int) $newbid);
								$tplfile->setVar('tpl_source', $content, TRUE);
								$tplfile->setVar('tpl_tplset', 'default');
								$tplfile->setVar('tpl_file', $blocks[$i]['template'], TRUE);
								$tplfile->setVar('tpl_type', 'block');
								$tplfile->setVar('tpl_lastimported', 0);
								$tplfile->setVar('tpl_lastmodified', time());
								$tplfile->setVar('tpl_desc', $blocks[$i]['description'], TRUE);
								if (!$tplfile_handler->insert($tplfile)) {
									$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_INSERT_FAIL . '</span>',
										'<strong>' . $blocks[$i]['template'] . '</strong>');
								} else {
									$newid = $tplfile->getVar('tpl_id');
									$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_INSERTED,
										'<strong>' . $blocks[$i]['template'] . '</strong>', '<strong>' . $newid . '</strong>');
									if ($icmsConfig['template_set'] == 'default') {
										if (!$icmsAdminTpl->template_touch($newid)) {
											$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>',
												'<strong>' . $blocks[$i]['template'] . '</strong>');
										} else {
											$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_RECOMPILED, '<strong>' . $blocks[$i]['template'] . '</strong>');
										}
									}
								}
							}
							$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_CREATED,
								'<strong>' . $blocks[$i]['name'] . '</strong>',
								'<strong>' . $newbid . '</strong>');
							$sql = "INSERT INTO " . icms::$xoopsDB->prefix('block_module_link')
								. " (block_id, module_id, page_id) VALUES ('"
								. (int) $newbid . "', '0', '1')";
							icms::$xoopsDB->query($sql);
						}
					}
				}
			}

			$icms_block_handler = icms::handler('icms_view_block');
			$block_arr = $icms_block_handler->getByModule($module->getVar('mid'));
			foreach ($block_arr as $block) {
				if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) {
					$sql = sprintf("DELETE FROM %s WHERE bid = '%u'", icms::$xoopsDB->prefix('newblocks'), (int) $block->getVar('bid'));
					if (!icms::$xoopsDB->query($sql)) {
						$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_BLOCK_DELETE_FAIL . '</span>',
							'<strong>' . $block->getVar('name') . '</strong>',
							'<strong>' . $block->getVar('bid') . '</strong>');
					} else {
						$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_DELETED,
							'<strong>' . $block->getVar('name') . '</strong>',
							'<strong>' . $block->getVar('bid') . '</strong>');
						if ($block->getVar('template') != '') {
							$tplfiles =& $tplfile_handler->find(NULL, 'block', $block->getVar('bid'));
							if (is_array($tplfiles)) {
								$btcount = count($tplfiles);
								for ($k = 0; $k < $btcount; $k++) {
									if (!$tplfile_handler->delete($tplfiles[$k])) {
										$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_BLOCK_TMPLT_DELETE_FAILED . '</span>',
											'<strong>' . $tplfiles[$k]->getVar('tpl_file') . '</strong>',
											'<strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>');
									} else {
										$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_TMPLT_DELETED,
											'<strong>' . $tplfiles[$k]->getVar('tpl_file') . '</strong>',
											'<strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>');
									}
								}
							}
						}
					}
				}
			}
		}

		// first delete all config entries
		$config_handler = icms::handler('icms_config');
		$configs =& $config_handler->getConfigs(new icms_db_criteria_Item('conf_modid', $module->getVar('mid')));
		$confcount = count($configs);
		$config_delng = array();
		if ($confcount > 0) {
			$msgs[] = _MD_AM_CONFIGOPTION_DELETED;
			for ($i = 0; $i < $confcount; $i++) {
				if (!$config_handler->deleteConfig($configs[$i])) {
					$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_CONFIGOPTION_DELETE_FAIL . '</span>',
						'<strong>' . $configs[$i]->getvar('conf_id') . '</strong>');
					// save the name of config failed to delete for later use
					$config_delng[] = $configs[$i]->getvar('conf_name');
				} else {
					$config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N');
					$config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype');
					$config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
					$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_CONFIGOPTION_DELETED,
						'<strong>' . $configs[$i]->getVar('conf_id') . '</strong>');
				}
			}
		}

		// now reinsert them with the new settings
		$configs = $module->getInfo('config');
		if ($configs !== FALSE) {
			if ($module->getVar('hascomments') != 0) {
				include_once ICMS_INCLUDE_PATH . '/comment_constants.php' ;
				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)
					)
				);
				array_push($configs, array(
					'name' => 'com_anonpost',
					'title' => '_CM_COMANONPOST',
					'description' => '',
					'formtype' => 'yesno',
					'valuetype' => 'int',
					'default' => 0
					)
				);
			}
		} else {
			if ($module->getVar('hascomments') != 0) {
				include_once ICMS_INCLUDE_PATH . '/comment_constants.php' ;
				$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
					)
				);
				$configs[] = array(
					'name' => 'com_anonpost',
					'title' => '_CM_COMANONPOST',
					'description' => '',
					'formtype' => 'yesno',
					'valuetype' => 'int',
					'default' => 0
				);
			}
		}

		if ($module->getVar('hasnotification') != 0) {
			if (empty($configs)) {
				$configs = array();
			}
			// Main notification options
			include_once ICMS_INCLUDE_PATH . '/notification_constants.php';
			$options = array(
				'_NOT_CONFIG_DISABLE' => XOOPS_NOTIFICATION_DISABLE,
				'_NOT_CONFIG_ENABLEBLOCK' => XOOPS_NOTIFICATION_ENABLEBLOCK,
				'_NOT_CONFIG_ENABLEINLINE' => XOOPS_NOTIFICATION_ENABLEINLINE,
				'_NOT_CONFIG_ENABLEBOTH' => XOOPS_NOTIFICATION_ENABLEBOTH,
			);

			$configs[] = array(
				'name' => 'notification_enabled',
				'title' => '_NOT_CONFIG_ENABLE',
				'description' => '_NOT_CONFIG_ENABLEDSC',
				'formtype' => 'select',
				'valuetype' => 'int',
				'default' => XOOPS_NOTIFICATION_ENABLEBOTH,
				'options'=>$options
			);
			// Event specific notification options
			// FIXME: for some reason the default doesn't come up properly
			//  initially is ok, but not when 'update' module..
			$options = array();
			$notification_handler = icms::handler('icms_data_notification');
			$categories =& $notification_handler->categoryInfo('', $module->getVar('mid'));
			foreach ($categories as $category) {
				$events =& $notification_handler->categoryEvents($category['name'], FALSE, $module->getVar('mid'));
				foreach ($events as $event) {
					if (!empty($event['invisible'])) {
						continue;
					}
					$option_name = $category['title'] . ' : ' . $event['title'];
					$option_value = $category['name'] . '-' . $event['name'];
					$options[$option_name] = $option_value;
				}
			}
			$configs[] = array(
				'name' => 'notification_events',
				'title' => '_NOT_CONFIG_EVENTS',
				'description' => '_NOT_CONFIG_EVENTSDSC',
				'formtype' => 'select_multi',
				'valuetype' => 'array',
				'default' => array_values($options),
				'options' => $options
			);
		}

		if ($configs !== FALSE) {
			$msgs[] = _MD_AM_CONFIG_ADDING;
			$config_handler = icms::handler('icms_config');
			$order = 0;
			foreach ($configs as $config) {
				// only insert ones that have been deleted previously with success
				if (!in_array($config['name'], $config_delng)) {
					$confobj =& $config_handler->createConfig();
					$confobj->setVar('conf_modid', (int) $newmid);
					$confobj->setVar('conf_catid', 0);
					$confobj->setVar('conf_name', $config['name']);
					$confobj->setVar('conf_title', $config['title'], TRUE);
					$confobj->setVar('conf_desc', $config['description'], TRUE);
					$confobj->setVar('conf_formtype', $config['formtype']);
					$confobj->setVar('conf_valuetype', $config['valuetype']);
					if (isset($config_old[$config['name']]['value'])
						&& $config_old[$config['name']]['formtype'] == $config['formtype']
						&& $config_old[$config['name']]['valuetype'] == $config['valuetype']
					) {
						// preserve the old value if any
						// form type and value type must be the same
						// need to deal with arrays, because getInfo('config') doesn't convert arrays
						if (is_array($config_old[$config['name']]['value'])) {
							$confobj->setVar('conf_value', serialize($config_old[$config['name']]['value']), TRUE);
						} else {
							$confobj->setVar('conf_value', $config_old[$config['name']]['value'], TRUE);
						}
					} else {
						$confobj->setConfValueForInput($config['default'], TRUE);
					}
					$confobj->setVar('conf_order', $order);
					$confop_msgs = '';
					if (isset($config['options']) && is_array($config['options'])) {
						foreach ($config['options'] as $key => $value) {
							$confop =& $config_handler->createConfigOption();
							$confop->setVar('confop_name', $key, TRUE);
							$confop->setVar('confop_value', $value, TRUE);
							$confobj->setConfOptions($confop);
							$confop_msgs .= sprintf('<br />&nbsp;&nbsp;&nbsp;&nbsp;' . _MD_AM_CONFIGOPTION_ADDED,
								'<strong>' . $key . '</strong>',
								'<strong>' . $value . '</strong>');
							unset($confop);
						}
					}
					$order++;
					if (FALSE !== $config_handler->insertConfig($confobj)) {
						$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_CONFIG_ADDED, '<strong>' . $config['name'] . '</strong>. ')
						. $confop_msgs;
					} else {
						$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_CONFIG_ADD_FAIL . '</span>',
						'<strong>' . $config['name'] . '</strong>. ');
					}
					unset($confobj);
				}
			}
			unset($configs);
		}

		// add module specific tasks to system autotasks list
		$atasks = $module->getInfo('autotasks');
		$atasks_handler = &icms_getModuleHandler('autotasks', 'system');
		if (isset($atasks) && is_array($atasks) && (count($atasks) > 0)) {
			$msgs[] = _MD_AM_AUTOTASK_UPDATE;
			$criteria = new icms_db_criteria_Compo();
			$criteria->add(new icms_db_criteria_Item('sat_type', 'addon/' . $module->getInfo('dirname')));
			$items_atasks = $atasks_handler->getObjects($criteria, FALSE);
			foreach ($items_atasks as $task) {
				$taskID = (int) $task->getVar('sat_addon_id');
				$atasks[$taskID]['enabled'] = $task->getVar('sat_enabled');
				$atasks[$taskID]['repeat'] = $task->getVar('sat_repeat');
				$atasks[$taskID]['interval'] = $task->getVar('sat_interval');
				$atasks[$taskID]['name'] = $task->getVar('sat_name');
			}
			$atasks_handler->deleteAll($criteria);
			if (is_array($atasks)) {
				foreach ($atasks as $taskID => $taskData) {
					if (!isset($taskData['code']) || trim($taskData['code']) == '') continue;
					$task = &$atasks_handler->create();
					if (isset($taskData['enabled'])) $task->setVar('sat_enabled', $taskData['enabled']);
					if (isset($taskData['repeat'])) $task->setVar('sat_repeat', $taskData['repeat']);
					if (isset($taskData['interval'])) $task->setVar('sat_interval', $taskData['interval']);
					if (isset($taskData['onfinish'])) $task->setVar('sat_onfinish', $taskData['onfinish']);
					$task->setVar('sat_name', $taskData['name']);
					$task->setVar('sat_code', $taskData['code']);
					$task->setVar('sat_type', 'addon/' . $module->getInfo('dirname'));
					$task->setVar('sat_addon_id', (int) $taskID);
					if (!($atasks_handler->insert($task))) {
						$msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_AUTOTASK_FAIL . '</span>',
							'<strong>' . $taskData['name'] . '</strong>');
					} else {
						$msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_AUTOTASK_ADDED,
							'<strong>' . $taskData['name'] . '</strong>');
					}
				}
			}
			unset($atasks, $atasks_handler, $task, $taskData, $criteria, $items, $taskID);
		}

		// execute module specific update script if any
		$update_script = $module->getInfo('onUpdate');
		$ModName = ($module->getInfo('modname') != '') ? trim($module->getInfo('modname')) : $dirname;
		if (FALSE !== $update_script && trim($update_script) != '') {
			include_once ICMS_MODULES_PATH . '/' . $dirname . '/' . trim($update_script);

			$is_IPF = $module->getInfo('object_items');
			if (!empty($is_IPF)) {
				$icmsDatabaseUpdater = icms_db_legacy_Factory::getDatabaseUpdater();
				$icmsDatabaseUpdater->moduleUpgrade($module, TRUE);
				array_merge($msgs, $icmsDatabaseUpdater->_messages);
			}

			if (function_exists('xoops_module_update_' . $ModName)) {
				$func = 'xoops_module_update_' . $ModName;
				if (!$func($module, $prev_version, $prev_dbversion)) {
					$msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
				} else {
					$msgs[] = $module->messages;
					$msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
				}
			} elseif (function_exists('icms_module_update_' . $ModName)) {
				$func = 'icms_module_update_' . $ModName;
				if (!$func($module, $prev_version, $prev_dbversion)) {
					$msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
				} else {
					$msgs[] = $module->messages;
					$msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
				}
			}
		}

		$msgs[] = '</code><p>' . sprintf(_MD_AM_OKUPD, '<strong>' . $module->getVar('name') . '</strong>') . '</p>';
	}
	$ret = '<code>' . implode('<br />', $msgs);
	return $ret;
}