Exemplo n.º 1
0
function main_sitemodules($eventData)
{
    global $env, $hui_mainframe, $amp_locale, $hui_mainstatus, $hui_titlebar;
    $site_query =& $env['ampdb']->execute('SELECT * FROM sites WHERE id=' . $eventData['siteid']);
    $site_data = $site_query->Fields();
    $modules_query =& $env['ampdb']->Execute('SELECT * FROM modules WHERE onlyextension <> ' . $env['ampdb']->Format_Text($env['ampdb']->fmttrue) . ' ORDER BY modid');
    if ($modules_query) {
        if ($modules_query->NumRows()) {
            $headers[0]['label'] = $amp_locale->GetStr('status_header');
            $headers[1]['label'] = $amp_locale->GetStr('moduleid_header');
            $headers[2]['label'] = $amp_locale->GetStr('modactivationdate_header');
            $headers[4]['label'] = $amp_locale->GetStr('moddeps_header');
            $row = 0;
            $hui_sitemodules_table = new HuiTable('sitemodulestable', array('headers' => $headers));
            OpenLibrary('modulesbase.library');
            while (!$modules_query->eof) {
                $modules_data = $modules_query->Fields();
                if ($modules_data['modid'] != 'ampoliros') {
                    $act_query =& $env['ampdb']->Execute('SELECT * FROM activemodules WHERE siteid = ' . $eventData['siteid'] . ' AND moduleid = ' . $modules_data['id']);
                    $hui_en_group[$row] = new HuiVertGroup('enable');
                    $hui_sitemodules_toolbar[$row] = new HuiToolBar('sitemodulestoolbar' . $row);
                    $mod_dep = new ModuleDep($env['ampdb']);
                    if ($act_query->NumRows()) {
                        // Module is enabled
                        //
                        $act_data = $act_query->Fields();
                        $hui_sitemodules_table->AddChild(new HuiImage('status' . $row, array('imageurl' => $hui_mainframe->mThemeHandler->mStyle['greenball'])), $row, 0);
                        $hui_sitemodules_table->AddChild(new HuiLabel('modid' . $row, array('label' => $modules_data['modid'], 'compact' => 'true')), $row, 1);
                        $hui_sitemodules_table->AddChild(new HuiLabel('actdate' . $row, array('label' => $act_data['activationdate'], 'compact' => 'true')), $row, 2);
                        $site_depending_modules = $mod_dep->CheckSiteDependingModules($modules_data['modid'], $site_data['siteid']);
                        $module = new Module($env['ampdb'], $modules_data['id']);
                        $sub_modules = $module->GetSubModules();
                        if (!$site_depending_modules) {
                            // No modules depends on this one
                            //
                            $disable_action[$row] = new HuiEventsCall();
                            $disable_action[$row]->AddEvent(new HuiEvent('main', 'sitemodules', array('siteid' => $eventData['siteid'])));
                            $disable_action[$row]->AddEvent(new HuiEvent('pass', 'deactivatemodule', array('siteid' => $eventData['siteid'], 'modid' => $modules_data['id'])));
                            $hui_disable_button[$row] = new HuiButton('disablebutton' . $row, array('label' => $amp_locale->GetStr('deactivatemodule_label'), 'compact' => 'true', 'horiz' => 'true', 'themeimage' => 'stop', 'themeimagetype' => 'mini', 'action' => $disable_action[$row]->GetEventsCallString()));
                            $hui_sitemodules_toolbar[$row]->AddChild($hui_disable_button[$row]);
                            $hui_en_group[$row]->AddChild($hui_sitemodules_toolbar[$row]);
                        } else {
                            // At least one module depends on this one
                            //
                            $mod_dep_list_str = '';
                            while (list(, $dep) = each($site_depending_modules)) {
                                $mod_dep_list_str .= $dep . '<br>';
                            }
                            $hui_sitemodules_table->AddChild(new HuiLabel('moddeps' . $row, array('label' => $mod_dep_list_str)), $row, 4);
                        }
                        if (count($sub_modules)) {
                            $toolbar = array();
                            while (list(, $name) = each($sub_modules)) {
                                $enabled = $module->CheckIfSubModuleEnabled($name, $eventData['siteid']);
                                $toolbar['main']['enable'] = array('label' => sprintf($amp_locale->GetStr(($enabled ? 'disable' : 'enable') . '_submodule.button'), ucfirst($name)), 'themeimage' => $enabled ? 'stop' : 'reload', 'compact' => 'true', 'themeimagetype' => 'mini', 'horiz' => 'true', 'action' => build_events_call_string('', array(array('main', 'sitemodules', array('siteid' => $eventData['siteid'])), array('pass', $enabled ? 'disablesubmodule' : 'enablesubmodule', array('moduleid' => $modules_data['id'], 'siteid' => $eventData['siteid'], 'submodule' => $name)))));
                                $hui_en_group[$row]->AddChild(new HuiAmpToolBar('main', array('frame' => 'false', 'toolbars' => $toolbar)));
                            }
                        }
                        $hui_sitemodules_table->AddChild($hui_en_group[$row], $row, 3);
                    } else {
                        // Module is not enabled
                        //
                        $hui_sitemodules_table->AddChild(new HuiImage('status' . $row, array('imageurl' => $hui_mainframe->mThemeHandler->mStyle['redball'])), $row, 0);
                        $hui_sitemodules_table->AddChild(new HuiLabel('modid' . $row, array('label' => $modules_data['modid'])), $row, 1);
                        $site_module_deps = $mod_dep->CheckSiteModuleDeps($modules_data['modid'], $site_data['siteid'], DEPTYPE_DEP);
                        if (!is_array($site_module_deps)) {
                            // All module dependecies are met
                            //
                            $enable_action[$row] = new HuiEventsCall();
                            $enable_action[$row]->AddEvent(new HuiEvent('main', 'sitemodules', array('siteid' => $eventData['siteid'])));
                            $enable_action[$row]->AddEvent(new HuiEvent('pass', 'activatemodule', array('siteid' => $eventData['siteid'], 'modid' => $modules_data['id'])));
                            $hui_enable_button[$row] = new HuiButton('enablebutton' . $row, array('label' => $amp_locale->GetStr('activatemodule_label'), 'compact' => 'true', 'horiz' => 'true', 'themeimage' => 'reload', 'themeimagetype' => 'mini', 'action' => $enable_action[$row]->GetEventsCallString()));
                            $hui_sitemodules_toolbar[$row]->AddChild($hui_enable_button[$row]);
                        } else {
                            // At least one module dependency is not met
                            //
                            $mod_dep_list_str = '';
                            while (list(, $dep) = each($site_module_deps)) {
                                $mod_dep_list_str .= $dep . '<br>';
                            }
                            $hui_sitemodules_table->AddChild(new HuiLabel('moddeps' . $row, array('label' => $mod_dep_list_str)), $row, 4);
                        }
                        $hui_sitemodules_table->AddChild($hui_sitemodules_toolbar[$row], $row, 3);
                    }
                    $row++;
                }
                $modules_query->MoveNext();
            }
            $xml_def = '<toolbar>
              <children>
            
                <button>
                  <args>
                    <themeimage>reload</themeimage>
                    <label type="encoded">' . urlencode($amp_locale->GetStr('enable_all_modules.button')) . '</label>
                    <horiz>true</horiz>
                    <action type="encoded">' . urlencode(build_events_call_string('', array(array('main', 'sitemodules', array('siteid' => $eventData['siteid'])), array('pass', 'activateallmodules', array('siteid' => $eventData['siteid']))))) . '</action>
                  </args>
                </button>
            
                <button>
                  <args>
                    <themeimage>stop</themeimage>
                    <label type="encoded">' . urlencode($amp_locale->GetStr('disable_all_modules.button')) . '</label>
                    <horiz>true</horiz>
                    <needconfirm>true</needconfirm>
                    <confirmmessage type="encoded">' . urlencode($amp_locale->GetStr('disable_all_modules.confirm')) . '</confirmmessage>
                    <action type="encoded">' . urlencode(build_events_call_string('', array(array('main', 'sitemodules', array('siteid' => $eventData['siteid'])), array('pass', 'deactivateallmodules', array('siteid' => $eventData['siteid']))))) . '</action>
                  </args>
                </button>
            
              </children>
            </toolbar>';
            $hui_mainvgroup = new HuiVertGroup();
            $hui_mainvgroup->AddChild($hui_sitemodules_table);
            $hui_mainvgroup->AddChild(new HuiHorizBar());
            $hui_mainvgroup->AddChild(new HuiXml('', array(definition => $xml_def)));
            $hui_mainframe->AddChild($hui_mainvgroup);
        }
    }
    $hui_titlebar->mTitle .= ' - ' . $site_data['siteid'] . ' (' . $site_data['sitename'] . ') - ' . $amp_locale->GetStr('sitemodules_title');
}
Exemplo n.º 2
0
 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;
 }