function main_situation($eventData) { global $hui_mainframe, $amp_locale, $hui_titlebar; OpenLibrary('modules.library'); $sites_query =& $GLOBALS['gEnv']['root']['db']->Execute('SELECT siteid ' . 'FROM sites ' . 'ORDER BY siteid'); $modules_query =& $GLOBALS['gEnv']['root']['db']->Execute('SELECT modid ' . 'FROM modules ' . 'WHERE onlyextension=' . $GLOBALS['gEnv']['root']['db']->Format_Text($GLOBALS['gEnv']['root']['db']->fmtfalse) . ' ' . 'ORDER BY modid'); $headers = array(); $cont = 1; while (!$modules_query->eof) { $orig_label = $modules_query->Fields('modid'); $label = ''; for ($i = 0; $i < strlen($orig_label); $i++) { if ($i) { $label .= '<br>'; } $label .= $orig_label[$i]; } $headers[$cont++]['label'] = $label; $modules_query->MoveNext(); } $xml_def = '<table><name>situation</name> <args> <headers type="array">' . huixml_encode($headers) . '</headers> </args> <children>'; $row = 0; $mod_deps = new ModuleDep($GLOBALS['gEnv']['root']['db']); while (!$sites_query->eof) { $xml_def .= '<label row="' . $row . '" col="0"> <args> <label type="encoded">' . urlencode($sites_query->Fields('siteid')) . '</label> <compact>true</compact> </args> </label>'; $col = 1; $modules_query->MoveFirst(); while (!$modules_query->eof) { $enabled = $mod_deps->IsEnabled($modules_query->Fields('modid'), $sites_query->Fields('siteid')); $xml_def .= '<image row="' . $row . '" col="' . $col . '" halign="center" valign="middle"> <args> <imageurl>' . ($enabled ? $hui_mainframe->mThemeHandler->mStyle['greenball'] : $hui_mainframe->mThemeHandler->mStyle['redball']) . '</imageurl> </args> </image>'; $col++; $modules_query->MoveNext(); } $row++; $sites_query->MoveNext(); } $xml_def .= ' </children> </table>'; $hui_mainframe->AddChild(new HuiXml('', array(definition => $xml_def))); }
function main_moduleversions($eventData) { global $gEnv, $gLocale, $gXml_def, $gPage_title, $gToolbars; OpenLibrary('modules.library'); $ac_remote = new AmpCentralRemoteServer($gEnv['root']['db'], $eventData['id']); $avail_reps = $ac_remote->ListAvailableRepositories(isset($eventData['refresh']) ? true : false); $avail_mods = $ac_remote->ListAvailableModules($eventData['repid'], isset($eventData['refresh']) ? true : false); $mod_versions = $ac_remote->ListAvailableModuleVersions($eventData['repid'], $eventData['moduleid'], isset($eventData['refresh']) ? true : false); $x_account = new XmlRpcAccount($gEnv['root']['db'], $ac_remote->mAccountId); $headers[0]['label'] = $gLocale->GetStr('version.header'); $headers[1]['label'] = $gLocale->GetStr('dependencies.header'); $headers[2]['label'] = $gLocale->GetStr('installed_version.header'); $gXml_def = '<vertgroup><name>modules</name> <children> <label><name>title</name> <args> <bold>true</bold> <label type="encoded">' . urlencode($x_account->mName . ' - ' . $avail_reps[$eventData['repid']]['name'] . ' - ' . $avail_mods[$eventData['moduleid']]['modid']) . '</label> </args> </label> <table><name>modules</name> <args> <headers type="array">' . huixml_encode($headers) . '</headers> <rowsperpage>10</rowsperpage> <pagesactionfunction>repmodules_list_action_builder</pagesactionfunction> <pagenumber>' . (isset($eventData['pagenumber']) ? $eventData['pagenumber'] : '') . '</pagenumber> <sessionobjectusername>' . $eventData['id'] . '-' . $eventData['repid'] . '-' . $eventData['moduleid'] . '</sessionobjectusername> </args> <children>'; $row = 0; $mod_query =& $gEnv['root']['db']->Execute('SELECT modversion ' . 'FROM modules ' . 'WHERE modid=' . $gEnv['root']['db']->Format_Text($avail_mods[$eventData['moduleid']]['modid'])); while (list($version, $data) = each($mod_versions)) { if (strlen($data['dependencies'])) { $mod_deps = new ModuleDep($gEnv['root']['db']); $dep_check = $mod_deps->CheckModuleDeps(0, '', $mod_deps->ExplodeDeps($data['dependencies'])); } else { $dep_check = false; } if ($mod_query->NumRows()) { $current_version = $mod_query->Fields('modversion'); } else { $current_version = $gLocale->GetStr('none_version.label'); } if ($dep_check == false) { $mod_installable = true; $missing_deps = ''; if ($mod_query->NumRows()) { switch (CompareVersionNumbers($version, $current_version)) { case AMPOLIROS_VERSIONCOMPARE_EQUAL: $label = $gLocale->GetStr('reinstall_module.button'); $icon = 'reload'; break; case AMPOLIROS_VERSIONCOMPARE_MORE: $label = $gLocale->GetStr('update_module.button'); $icon = 'folder_new'; break; case AMPOLIROS_VERSIONCOMPARE_LESS: $label = $gLocale->GetStr('downgrade_module.button'); $icon = 'down'; break; } } else { $label = $gLocale->GetStr('install_module.button'); $icon = 'folder'; } } else { $mod_installable = false; $missing_deps = '<br><strong>' . $gLocale->GetStr('missing_deps.label') . '</strong>'; while (list(, $dep) = each($dep_check)) { $missing_deps .= '<br>' . $dep; } } $toolbars = array(); if ($mod_installable) { $toolbars['main']['install'] = array('label' => $label, 'themeimage' => $icon, 'horiz' => 'true', 'action' => build_events_call_string('', array(array('main', 'repositorymodules', array('id' => $eventData['id'], 'repid' => $eventData['repid'])), array('action', 'installmodule', array('id' => $eventData['id'], 'repid' => $eventData['repid'], 'moduleid' => $eventData['moduleid'], 'version' => $version))))); } $gXml_def .= '<label row="' . $row . '" col="0"><name>version</name> <args> <label type="encoded">' . urlencode($version) . '</label> </args> </label> <label row="' . $row . '" col="1"><name>dependencies</name> <args> <label type="encoded">' . urlencode(str_replace(',', '<br>', $data['dependencies']) . (strlen($data['suggestions']) ? '<br><br><strong>' . $gLocale->GetStr('suggestions.label') . '</strong><br>' . str_replace(',', '<br>', $data['suggestions']) . '<br>' : '') . $missing_deps) . '</label> </args> </label> <label row="' . $row . '" col="2"><name>current</name> <args> <label type="encoded">' . urlencode($current_version) . '</label> </args> </label> <amptoolbar row="' . $row . '" col="3"><name>tb</name> <args> <frame>false</frame> <toolbars type="array">' . huixml_encode($toolbars) . '</toolbars> </args> </amptoolbar>'; $row++; } $gXml_def .= ' </children> </table> </children> </vertgroup>'; $gToolbars['reptools'] = array('refresh' => array('label' => $gLocale->GetStr('refresh.button'), 'themeimage' => 'reload', 'horiz' => 'true', 'action' => build_events_call_string('', array(array('main', 'moduleversions', array('id' => $eventData['id'], 'repid' => $eventData['repid'], 'moduleid' => $eventData['moduleid'], 'refresh' => '1')))))); $gPage_title .= ' - ' . $gLocale->GetStr('moduleversions.title'); }
function Disable($siteid) { $result = FALSE; import('com.solarix.ampoliros.util.Hook'); $hook = new Hook($this->ampdb, 'ampoliros', 'module.disable'); if ($hook->CallHooks('calltime', $this, array('siteserial' => $siteid, 'modserial' => $this->serial)) == HOOK_RESULT_OK) { if ($this->serial) { // Checks if the module exists in modules table // $modquery =& $this->ampdb->Execute('SELECT * FROM modules WHERE id=' . (int) $this->serial); if ($modquery->NumRows() == 1) { $moddata = $modquery->Fields(); if ($moddata['onlyextension'] != $this->ampdb->fmttrue) { // Checks if the structure file still exists // if (file_exists(MODULE_PATH . $moddata['modid'] . '/' . Module::STRUCTURE_FILE)) { $this->modname = $moddata['modid']; $sitequery = $this->ampdb->Execute('SELECT * FROM sites WHERE id=' . $this->ampdb->Format_Text((int) $siteid)); $sitedata = $sitequery->Fields(); $args['dbtype'] = $sitedata['sitedbtype']; $args['dbname'] = $sitedata['sitedbname']; $args['dbhost'] = $sitedata['sitedbhost']; $args['dbport'] = $sitedata['sitedbport']; $args['dbuser'] = $sitedata['sitedbuser']; $args['dbpass'] = $sitedata['sitedbpassword']; $args['dblog'] = $sitedata['sitedblog']; import('com.solarix.ampoliros.db.DBLayerFactory'); $db_fact = new DBLayerFactory(); $this->sitedb = $db_fact->NewDBLayer($args); $this->sitedb->Connect($args); // Dependencies check // $this->unmetdeps = array(); $this->unmetsuggs = array(); $moddeps = new ModuleDep($this->ampdb); $pendingdeps = $moddeps->CheckSiteDependingModules($this->modname, $sitedata['siteid'], FALSE); $modenabled = $moddeps->IsEnabled($this->modname, $sitedata['siteid']); // If dependencies are ok, go on // if ($pendingdeps == FALSE and $modenabled == TRUE) { $result = $this->HandleStructure(MODULE_PATH . $moddata['modid'] . '/' . Module::STRUCTURE_FILE, Module::INSTALL_MODE_DISABLE, MODULE_PATH . $moddata['modid'] . '/', $siteid); $modquery = $this->ampdb->Execute('SELECT id FROM modules WHERE modid=' . $this->ampdb->Format_Text($this->modname)); $this->ampdb->Execute('DELETE FROM activemodules WHERE moduleid=' . (int) $this->serial . ' AND siteid=' . $this->ampdb->Format_Text($siteid)); $this->ampdb->Execute('DELETE FROM disabledsubmodules WHERE moduleid=' . (int) $this->serial . ' AND siteid=' . (int) $siteid); if ($GLOBALS['gEnv']['core']['config']->Value('ALERT_ON_MODULE_SITE_OPERATION') == '1') { Carthag::import('com.solarix.ampoliros.security.SecurityLayer'); $amp_security = new SecurityLayer(); $amp_security->SendAlert('Module ' . $moddata['modid'] . ' has been disabled from site ' . $sitedata['siteid']); unset($amp_security); } if ($hook->CallHooks('moduledisabled', $this, array('siteserial' => $siteid, 'modserial' => $this->serial)) != HOOK_RESULT_OK) { $result = false; } } else { if ($modenabled == FALSE) { } else { $this->unmetdeps = $pendingdeps; } } //if ( $result == TRUE ) $this->mLog->LogEvent( 'Ampoliros', 'Uninstalled module '.$this->modname, LOGGER_NOTICE ); $sitequery->Free(); } else { import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger(AMP_LOG); $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'Structure file ' . MODULE_PATH . $moddata['modid'] . '/' . Module::STRUCTURE_FILE . ' for module ' . $moddata['modid'] . ' was not found', LOGGER_ERROR); } } else { import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger(AMP_LOG); $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'Tried to disable module ' . $moddata['modid'] . ', but it is an extension only module', LOGGER_ERROR); } } else { import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger(AMP_LOG); $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'A module with serial ' . $this->serial . ' was not found in modules table', LOGGER_ERROR); } $modquery->Free(); } else { import('com.solarix.ampoliros.io.log.Logger'); $log = new Logger(AMP_LOG); $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'Empty module serial', LOGGER_ERROR); } } return $result; }
function main_dependencies($eventData) { global $env, $hui_mainframe, $amp_locale, $hui_titlebar; $query =& $env['ampdb']->execute('SELECT modid ' . 'FROM modules ' . 'WHERE id=' . $eventData['modid'] . ' '); $module_data = $query->Fields(); $hui_vgroup = new HuiVertGroup('vgroup'); $hui_hgroup1 = new HuiHorizGroup('hgroup1'); $hui_hgroup2 = new HuiHorizGroup('hgroup2'); $temp_deps = new ModuleDep($env['ampdb']); $module_deps = array(); $module_suggs = array(); $depending_mods = array(); $suggesting_mods = array(); $enabled_sites = array(); $module_deps_array = $temp_deps->DependsOn($module_data['modid']); if (is_array($module_deps_array)) { while (list($key, $val) = each($module_deps_array)) { if ($val['deptype'] == DEPTYPE_DEP) { $module_deps[$val['moddep']] = $val['moddep'] . ' ' . $val['version']; } else { $module_suggs[$val['moddep']] = $val['moddep'] . ' ' . $val['version']; } } } $depending_mods_array = $temp_deps->CheckDependingModules($module_data['modid'], DEPTYPE_DEP); if (is_array($depending_mods_array)) { while (list($key, $val) = each($depending_mods_array)) { $depending_mods[$val] = $val; } } $suggesting_mods_array = $temp_deps->CheckDependingModules($module_data['modid'], DEPTYPE_SUGG); if (is_array($suggesting_mods_array)) { while (list($key, $val) = each($suggesting_mods_array)) { $suggesting_mods[$val] = $val; } } $enabled_sites_array = $temp_deps->CheckEnabledSites($eventData['modid']); if (is_array($enabled_sites_array)) { asort($enabled_sites_array); while (list($key, $val) = each($enabled_sites_array)) { $enabled_sites[$val] = $val; } } $xml_def = '<grid><name>deps</name><children> <vertframe row="0" col="0"> <name>deps</name> <children> <label> <name>deps</name> <args> <label>' . $amp_locale->GetStr('moddeps_label') . '</label> </args> </label> <listbox> <name>deps</name> <args> <disp>pass</disp> <readonly>true</readonly> <elements type="array">' . huixml_encode($module_deps) . '</elements> <size>5</size> </args> </listbox> </children> </vertframe> <vertframe row="0" col="1"><name>suggs</name><children> <label><name>suggs</name><args><label>' . $amp_locale->GetStr('modsuggs_label') . '</label></args></label> <listbox><name>suggs</name><args><disp>pass</disp><readonly>true</readonly><elements type="array">' . huixml_encode($module_suggs) . '</elements><size>5</size></args></listbox> </children></vertframe>'; if (strcmp($module_data['modid'], 'ampoliros')) { $xml_def .= ' <vertframe row="1" col="0"><name>depending</name><children> <label><name>depending</name><args><label>' . sprintf($amp_locale->GetStr('dependingmods_label'), $module_data['modid']) . '</label></args></label> <listbox><name>depending</name><args><disp>pass</disp><readonly>true</readonly><elements type="array">' . huixml_encode($depending_mods) . '</elements><size>5</size></args></listbox> </children></vertframe> <vertframe row="1" col="1"><name>suggesting</name><children> <label><name>suggesting</name><args><label>' . sprintf($amp_locale->GetStr('suggestingmods_label'), $module_data['modid']) . '</label></args></label> <listbox><name>suggesting</name><args><disp>pass</disp><readonly>true</readonly><elements type="array">' . huixml_encode($suggesting_mods) . '</elements><size>5</size></args></listbox> </children></vertframe> <vertframe row="2" col="0"><name>enabled</name><children> <label><name>enabled</name><args><label>' . $amp_locale->GetStr('enabledsites_label') . '</label></args></label> <listbox><name>enabled</name><args><disp>pass</disp><readonly>true</readonly><elements type="array">' . huixml_encode($enabled_sites) . '</elements><size>5</size></args></listbox> </children></vertframe>'; } $xml_def .= '</children></grid>'; $hui_mainframe->AddChild(new HuiXml('deps', array('definition' => $xml_def))); $hui_titlebar->mTitle .= ' - ' . $module_data['modid'] . ' - ' . $amp_locale->GetStr('moduledeps_title'); }