Beispiel #1
0
 public function simple_setup()
 {
     Base_ActionBarCommon::add('settings', __('Advanced view'), $this->create_confirm_callback_href(__('Switch to advanced view?'), array($this, 'switch_simple'), false));
     $module_dirs = $this->get_module_dirs();
     $is_required = ModuleManager::required_modules(true);
     $structure = array();
     foreach ($module_dirs as $entry => $versions) {
         $installed = ModuleManager::is_installed($entry);
         $module_install_class = $entry . 'Install';
         $func_simple = array($module_install_class, 'simple_setup');
         if (is_callable($func_simple)) {
             $simple_module = call_user_func($func_simple);
         } else {
             $simple_module = false;
         }
         if ($simple_module === false) {
             continue;
         }
         if ($simple_module === true) {
             $simple_module = array('package' => __('Uncategorized'), 'option' => $entry);
         }
         if (is_string($simple_module)) {
             $simple_module = array('package' => $simple_module);
         }
         if (!isset($simple_module['option'])) {
             $simple_module['option'] = null;
         }
         $simple_module['module'] = $entry;
         $simple_module['installed'] = $installed >= 0;
         $simple_module['key'] = $simple_module['package'] . ($simple_module['option'] ? '|' . $simple_module['option'] : '');
         $structure[$entry] = $simple_module;
     }
     $packages = array();
     foreach ($structure as $s) {
         if (!isset($packages[$s['key']])) {
             $packages[$s['key']] = array('also_uninstall' => array(), 'modules' => array(), 'is_required' => array(), 'installed' => null, 'icon' => false, 'version' => null, 'url' => null, 'core' => 0);
         }
         $package =& $packages[$s['key']];
         $package['modules'][] = $s['module'];
         $package['name'] = $s['package'];
         $package['option'] = $s['option'];
         if (isset($s['core'])) {
             $package['core'] = $s['core'];
         }
         if ($package['installed'] === null) {
             $package['installed'] = $s['installed'];
         } else {
             if ($s['installed'] && !$package['installed'] || !$s['installed'] && $package['installed']) {
                 $package['installed'] = 'partial';
             }
         }
         if (!isset($is_required[$s['module']])) {
             $is_required[$s['module']] = array();
         }
         foreach ($is_required[$s['module']] as $r) {
             if (!isset($structure[$r])) {
                 $package['also_uninstall'][] = $r;
                 continue;
             }
             if ($structure[$r]['package'] == $s['package']) {
                 continue;
             }
             $package['is_required'][$structure[$r]['key']] = $structure[$r]['key'];
         }
         if (isset($s['icon'])) {
             $package['icon'] = Base_ThemeCommon::get_template_file($s['module'], 'package-icon.png');
         }
         if (isset($s['version'])) {
             $package['version'] = $s['version'];
         }
         if (isset($s['url'])) {
             $package['url'] = $s['url'];
         }
     }
     $sorted = array();
     foreach ($packages as $key => $p) {
         if ($key === 0) {
             continue;
         }
         $name = $p['name'];
         $option = $p['option'];
         if (!isset($sorted[$name])) {
             $sorted[$name] = array();
             $sorted[$name]['name'] = $name;
             $sorted[$name]['modules'] = array();
             $sorted[$name]['buttons'] = array();
             $sorted[$name]['options'] = array();
             $sorted[$name]['status'] = __('Options only');
             $sorted[$name]['filter'] = array('available');
             $sorted[$name]['style'] = 'disabled';
             $sorted[$name]['installed'] = null;
             $sorted[$name]['instalable'] = 0;
             $sorted[$name]['uninstalable'] = 0;
             $sorted[$name]['core'] = 0;
         }
         $sorted[$name]['core'] |= $p['core'];
         $buttons = array();
         $status = '';
         if ($p['installed'] === true || $p['installed'] === 'partial') {
             if (!$p['core'] && empty($p['is_required'])) {
                 $mods = $p['modules'];
                 foreach ($p['also_uninstall'] as $pp) {
                     $mods[] = $pp;
                 }
                 if ($p['option'] === null) {
                     // also add all options as available for uninstall
                     foreach ($packages as $pp) {
                         if ($pp['name'] === $p['name']) {
                             $mods = array_merge($mods, $pp['modules']);
                         }
                     }
                 }
                 $buttons[] = array('label' => __('Uninstall'), 'style' => 'uninstall', 'href' => $this->create_confirm_callback_href(__('Are you sure you want to uninstall this package and remove all associated data?'), array($this, 'simple_uninstall'), array($mods)));
             } else {
                 if ($p['core']) {
                     $message = __('EPESI Core can not be uninstalled');
                 } elseif (empty($p['is_required'])) {
                     $message = __('This package can not be uninstalled');
                 } else {
                     $required = array();
                     foreach ($p['is_required'] as $v) {
                         $required[] = str_replace('|', ' / ', $v);
                     }
                     $message = __('This package is required by the following packages: %s', array('<br>' . implode('<br>', $required)));
                 }
                 $buttons[] = array('label' => __('Uninstall'), 'style' => 'disabled', 'href' => Utils_TooltipCommon::open_tag_attrs($message, false));
             }
         }
         if ($p['installed'] === false || $p['installed'] === 'partial') {
             $buttons[] = array('label' => __('Install'), 'style' => 'install', 'href' => $this->create_callback_href(array($this, 'simple_install'), array($p['modules'])));
         }
         switch (true) {
             case $p['installed'] === false:
                 $style = 'available';
                 $filter = array('available');
                 $status = __('Available');
                 break;
             case $p['installed'] === true:
                 $style = 'install';
                 $filter = array('installed');
                 $status = __('Installed');
                 break;
             case $p['installed'] === 'partial':
                 $style = 'partial-install';
                 $filter = array('installed');
                 $status = __('Partially');
                 break;
         }
         if ($option === null) {
             $sorted[$name]['modules'] = $p['modules'];
             $sorted[$name]['buttons'] = $buttons;
             $sorted[$name]['status'] = $status;
             $sorted[$name]['style'] = $style;
             $sorted[$name]['installed'] = $p['installed'];
             $sorted[$name]['instalable'] = 1;
             $sorted[$name]['uninstalable'] = empty($p['is_required']);
             $sorted[$name]['filter'] = $filter;
             $sorted[$name]['icon'] = $p['icon'];
             $sorted[$name]['version'] = $p['version'];
             $sorted[$name]['url'] = $p['url'];
         } else {
             $sorted[$name]['options'][$option] = array('name' => $option, 'buttons' => $buttons, 'status' => $status, 'style' => $style);
         }
     }
     $filters = array(__('All') => array('arg' => ''), __('Installed') => array('arg' => 'installed'), __('Available') => array('arg' => 'available'));
     if (ModuleManager::is_installed('Base_EpesiStore') >= 0) {
         $store_visible = Base_SetupCommon::is_store_visible();
         if ($store_visible) {
             $this->add_store_products($sorted, $filters);
         }
         $icon = $store_visible ? 'delete' : 'add';
         $text = $store_visible ? __('Disable EPESI Store') : __('Enable EPESI Store');
         $href = $this->create_callback_href(array('Base_SetupCommon', 'set_store_visibility'), array(!$store_visible));
         $desc = $store_visible ? __('Disabling communication with EPESI Store will improve processing speed, but will not update the list of additional modules in the store.') : '';
         Base_ActionBarCommon::add($icon, $text, $href, $desc);
     }
     foreach ($sorted as $name => $v) {
         ksort($sorted[$name]['options']);
         $buttons_tooltip =& $sorted[$name]['buttons_tooltip'];
         $buttons_tooltip = $buttons_tooltip ? Utils_TooltipCommon::open_tag_attrs($buttons_tooltip, false) : '';
     }
     uasort($sorted, array($this, 'simple_setup_sort'));
     $t = $this->init_module('Base/Theme');
     $t->assign('packages', $sorted);
     $t->assign('filters', $filters);
     $t->assign('version_label', __('Ver. '));
     $t->assign('labels', array('options' => __('Optional')));
     $t->display();
 }