示例#1
0
 public function edit($id)
 {
     $lists = array();
     $mi = new microIntegration();
     $mi->load($id);
     $aecHTML = null;
     $attached = array();
     $mi_gsettings = $mi->getGeneralSettings();
     if (!$mi->id) {
         // Create MI Selection List
         $mi_handler = new microIntegrationHandler();
         $mi_list = $mi_handler->getIntegrationList();
         $drilldown = array('all' => array());
         $mi_gsettings['class_name'] = array('hidden');
         $mi_gsettings['class_list'] = array('list');
         if (count($mi_list) > 0) {
             foreach ($mi_list as $name) {
                 $mi_item = new microIntegration();
                 if ($mi_item->callDry($name)) {
                     $handle = str_replace('mi_', '', $mi_item->class_name);
                     if (isset($mi_item->info['type'])) {
                         foreach ($mi_item->info['type'] as $type) {
                             $drill = explode('.', $type);
                             $cursor =& $drilldown;
                             $mi_item->name = str_replace(array(' AEC ', ' MI '), ' ', $mi_item->name);
                             foreach ($drill as $i => $k) {
                                 if (!isset($cursor[$k])) {
                                     $cursor[$k] = array();
                                 }
                                 if ($i == count($drill) - 1) {
                                     $cursor[$k][] = '<a href="#' . $handle . '" class="mi-menu-mi"><span class="mi-menu-mi-name">' . $mi_item->name . '</span><span class="mi-menu-mi-desc">' . $mi_item->desc . '</span></a>';
                                 } else {
                                     $cursor =& $cursor[$k];
                                 }
                             }
                         }
                     }
                     $drilldown['all'][] = '<a href="#' . $handle . '" class="mi-menu-mi"><span class="mi-menu-mi-name">' . $mi_item->name . '</span><span class="mi-menu-mi-desc">' . $mi_item->desc . '</span></a>';
                 }
             }
             deep_ksort($drilldown);
             $lists['class_list'] = '<a tabindex="0" href="#mi-select-list" class="btn btn-primary" id="drilldown">Select an Integration</a>';
             $lists['class_list'] .= '<div id="mi-select-list" class="hidden"><ul>';
             foreach ($drilldown as $lin => $li) {
                 if ($this->lang->hasKey('AEC_MI_LIST_' . strtoupper($lin))) {
                     $kkey = JText::_('AEC_MI_LIST_' . strtoupper($lin));
                 } else {
                     $kkey = ucwords(str_replace('_', ' ', $lin));
                 }
                 $lists['class_list'] .= '<li><a href="#">' . $kkey . '</a><ul>';
                 foreach ($li as $lixn => $lix) {
                     if (is_array($lix)) {
                         if ($this->lang->hasKey('AEC_MI_LIST_' . strtoupper($lixn))) {
                             $xkey = JText::_('AEC_MI_LIST_' . strtoupper($lixn));
                         } else {
                             $xkey = ucwords(str_replace('_', ' ', $lixn));
                         }
                         $lists['class_list'] .= '<li><a href="#">' . $xkey . '</a><ul>';
                         foreach ($lix as $mix) {
                             $lists['class_list'] .= '<li>' . $mix . '</li>';
                         }
                         $lists['class_list'] .= '</ul></li>';
                     } else {
                         $lists['class_list'] .= '<li>' . $lix . '</li>';
                     }
                 }
                 $lists['class_list'] .= '</ul></li>';
             }
             $lists['class_list'] .= '</ul></div>';
         } else {
             $lists['class_list'] = '';
         }
     }
     if ($mi->id) {
         // Call MI (override active check) and Settings
         if ($mi->callIntegration(true)) {
             $attached['plans'] = microIntegrationHandler::getPlansbyMI($mi->id, false, true);
             $attached['groups'] = microIntegrationHandler::getGroupsbyMI($mi->id, false, true);
             $set = array();
             foreach ($mi_gsettings as $n => $v) {
                 if (!isset($mi->{$n})) {
                     if (isset($mi->settings[$n])) {
                         $set[$n] = $mi->settings[$n];
                     } else {
                         $set[$n] = null;
                     }
                 } else {
                     $set[$n] = $mi->{$n};
                 }
             }
             $restrictionHelper = new aecRestrictionHelper();
             $mi_gsettings['restr_remaps'] = array('subarea_change', 'restrictions');
             $mi_gsettings = array_merge($mi_gsettings, $restrictionHelper->getParams());
             if (empty($mi->restrictions)) {
                 $mi->restrictions = array();
             }
             $lists = array_merge($lists, $restrictionHelper->getLists($set, $mi->restrictions));
             $mi_gsettings[$mi->id . 'remap'] = array('area_change', 'MI');
             $mi_gsettings[$mi->id . 'remaps'] = array('subarea_change', $mi->class_name);
             $mi_settings = $mi->getSettings();
             // Get lists supplied by the MI
             if (!empty($mi_settings['lists'])) {
                 $lists = array_merge($lists, $mi_settings['lists']);
                 unset($mi_settings['lists']);
             }
             $available_plans = SubscriptionPlanHandler::getPlanList(false, false, true, null, true);
             $selected_plans = array();
             foreach ($attached['plans'] as $p) {
                 $selected_plans[] = (object) array('value' => $p->id, 'text' => $p->name);
             }
             $lists['attach_to_plans'] = JHTML::_('select.genericlist', $available_plans, 'attach_to_plans[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', $selected_plans);
             $available_groups = ItemGroupHandler::getGroups(null, true);
             $selected_groups = array();
             foreach ($attached['groups'] as $g) {
                 $selected_groups[] = (object) array('value' => $g->id, 'text' => $g->name);
             }
             $lists['attach_to_groups'] = JHTML::_('select.genericlist', $available_groups, 'attach_to_groups[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', $selected_groups);
             $gsettings = new aecSettings('MI', 'E');
             $gsettings->fullSettingsArray($mi_gsettings, array_merge($set, $mi->restrictions), $lists);
             $settings = new aecSettings('MI', $mi->class_name);
             $settings->fullSettingsArray($mi_settings, $set, $lists);
             // Call HTML Class
             $aecHTML = new aecHTML(array_merge($gsettings->settings, $settings->settings), array_merge($gsettings->lists, $settings->lists));
             $aecHTML->hasHacks = method_exists($mi->mi_class, 'hacks');
             $aecHTML->customparams = array();
             foreach ($mi_settings as $n => $v) {
                 $aecHTML->customparams[] = $n;
             }
             $aecHTML->hasSettings = true;
             $aecHTML->hasRestrictions = !empty($mi->settings['has_restrictions']);
         } else {
             $short = 'microIntegration loading failure';
             $event = 'When trying to load microIntegration: ' . $mi->id . ', callIntegration failed';
             $tags = 'microintegration,loading,error';
             $params = array();
             $eventlog = new eventLog();
             $eventlog->issue($short, $tags, $event, 128, $params);
         }
     } else {
         $settings = new aecSettings('MI', 'E');
         $settings->fullSettingsArray($mi_gsettings, array(), $lists);
         // Call HTML Class
         $aecHTML = new aecHTML($settings->settings, $settings->lists);
         $aecHTML->hasSettings = false;
         $aecHTML->hasRestrictions = false;
         $available_plans = SubscriptionPlanHandler::getPlanList(false, false, true, null, true);
         $lists['attach_to_plans'] = JHTML::_('select.genericlist', $available_plans, 'attach_to_plans[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', null);
         $available_groups = ItemGroupHandler::getGroups(null, true);
         $lists['attach_to_groups'] = JHTML::_('select.genericlist', $available_groups, 'attach_to_groups[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', null);
     }
     HTML_AcctExp::editMicroIntegration($mi, $lists, $aecHTML, $attached);
 }