Exemple #1
0
 public function edit($id)
 {
     global $aecConfig;
     $lists = array();
     $params_values = array();
     $restrictions_values = array();
     $customparams_values = array();
     $customparamsarray = new stdClass();
     $row = new SubscriptionPlan();
     $row->load($id);
     $restrictionHelper = new aecRestrictionHelper();
     if (!$row->id) {
         $row->ordering = 9999;
         $hasrecusers = false;
         $params_values['active'] = 1;
         $params_values['visible'] = 0;
         $params_values['processors'] = 0;
         $restrictions_values['gid_enabled'] = 1;
         if (defined('JPATH_MANIFESTS')) {
             $restrictions_values['gid'] = 2;
         } else {
             $restrictions_values['gid'] = 18;
         }
     } else {
         $params_values = $row->params;
         $restrictions_values = $row->restrictions;
         if (empty($restrictions_values)) {
             $restrictions_values = array();
         }
         // Clean up custom params
         if (!empty($row->customparams)) {
             foreach ($row->customparams as $n => $v) {
                 if (isset($params_values[$n]) || isset($restrictions_values[$n])) {
                     unset($row->customparams[$n]);
                 }
             }
         }
         $customparams_values = $row->custom_params;
         // We need to convert the values that are set as object properties
         $params_values['active'] = $row->active;
         $params_values['visible'] = $row->visible;
         $params_values['email_desc'] = $row->getProperty('email_desc');
         $params_values['name'] = $row->getProperty('name');
         $params_values['desc'] = $row->getProperty('desc');
         $params_values['micro_integrations'] = $row->micro_integrations;
         $params_values['processors'] = $row->params['processors'];
         // Checking if there is already a user, which disables certain actions
         $query = 'SELECT count(*)' . ' FROM #__users AS a' . ' LEFT JOIN #__acctexp_subscr AS b ON a.id = b.userid' . ' WHERE b.plan = ' . $row->id . ' AND (b.status = \'Active\' OR b.status = \'Trial\')' . ' AND b.recurring =\'1\'';
         $this->db->setQuery($query);
         $hasrecusers = $this->db->loadResult() > 0 ? true : false;
     }
     $stdformat = '{aecjson}{"cmd":"condition","vars":[{"cmd":"data","vars":"payment.freetrial"},' . '{"cmd":"concat","vars":[{"cmd":"jtext","vars":"CONFIRM_FREETRIAL"}," ",{"cmd":"data","vars":"payment.method_name"}]},' . '{"cmd":"concat","vars":[{"cmd":"data","vars":"payment.amount"},{"cmd":"data","vars":"payment.currency_symbol"}," ",{"cmd":"data","vars":"payment.method_name"}]}' . ']}{/aecjson}';
     // params and their type values
     $params['active'] = array('toggle', 1);
     $params['visible'] = array('toggle', 1);
     $params['name'] = array('inputC', '');
     $params['desc'] = array('editor', '');
     $params['customamountformat'] = array('inputD', $stdformat);
     $params['customthanks'] = array('inputC', '');
     $params['customtext_thanks_keeporiginal'] = array('toggle', 1);
     $params['customtext_thanks'] = array('editor', '');
     $params['email_desc'] = array('inputD', '');
     $params['meta'] = array('inputD', '');
     $params['micro_integrations_inherited'] = array('list', '');
     $params['micro_integrations'] = array('list', '');
     $params['micro_integrations_plan'] = array('list', '');
     $params['params_remap'] = array('subarea_change', 'groups');
     $groups = ItemGroupHandler::parentGroups($row->id, 'item');
     if (!empty($groups)) {
         $gs = array();
         foreach ($groups as $groupid) {
             $group = new ItemGroup();
             $group->load($groupid);
             $g = array();
             $g['id'] = $group->id;
             $g['name'] = $group->getProperty('name');
             $g['color'] = $group->params['color'];
             $g['group'] = '<strong>' . $groupid . '</strong>';
             $gs[$groupid] = $g;
         }
         $customparamsarray->groups = $gs;
     } else {
         $customparamsarray->groups = null;
     }
     $grouplist = ItemGroupHandler::getTree();
     $glist = array();
     $glist[] = JHTML::_('select.option', 0, '- - - - - -');
     $groupids = array();
     foreach ($grouplist as $id => $glisti) {
         if (defined('JPATH_MANIFESTS')) {
             $glist[] = JHTML::_('select.option', $glisti[0], str_replace('&nbsp;', ' ', $glisti[1]), 'value', 'text', in_array($glisti[0], $groups));
         } else {
             $glist[] = JHTML::_('select.option', $glisti[0], $glisti[1], 'value', 'text', in_array($glisti[0], $groups));
         }
         $groupids[$glisti[0]] = ItemGroupHandler::groupColor($glisti[0]);
     }
     $lists['add_group'] = JHTML::_('select.genericlist', $glist, 'add_group', 'size="1"', 'value', 'text', $row->id ? 0 : 1);
     $params['add_group'] = array('list', '', '', $row->id ? 0 : 1);
     $params['params_remap'] = array('subarea_change', 'params');
     $params['override_activation'] = array('toggle', 0);
     $params['override_regmail'] = array('toggle', 0);
     $params['full_free'] = array('toggle', '');
     $params['full_amount'] = array('inputA', '');
     $params['full_period'] = array('inputA', '');
     $params['full_periodunit'] = array('list', 'D');
     $params['trial_free'] = array('toggle', '');
     $params['trial_amount'] = array('inputA', '');
     $params['trial_period'] = array('inputA', '');
     $params['trial_periodunit'] = array('list', 'D');
     $params['gid_enabled'] = array('toggle', 1);
     $params['gid'] = array('list', defined('JPATH_MANIFESTS') ? 2 : 18);
     $params['lifetime'] = array('toggle', 0);
     $params['processors'] = array('list', '');
     $params['processor_selectmode'] = array('list', '');
     $params['standard_parent'] = array('list', '');
     $params['fallback'] = array('list', '');
     $params['fallback_req_parent'] = array('toggle', 0);
     $params['make_active'] = array('toggle', 1);
     $params['make_primary'] = array('toggle', 1);
     $params['update_existing'] = array('toggle', 1);
     $params['similarplans'] = array('list', '');
     $params['equalplans'] = array('list', '');
     $params['notauth_redirect'] = array('inputC', '');
     $params['fixed_redirect'] = array('inputC', '');
     $params['hide_duration_checkout'] = array('toggle', 0);
     $params['cart_behavior'] = array('list', 0);
     $params['addtocart_redirect'] = array('inputC', '');
     $params['addtocart_max'] = array('inputA', '');
     $params['notes'] = array('textarea', '');
     $params['restr_remap'] = array('subarea_change', 'restrictions');
     $params['inventory_amount_enabled'] = array('toggle', 0);
     $params['inventory_amount'] = array('inputB', 0);
     $params['inventory_amount_used'] = array('inputB', 0);
     $params = array_merge($params, $restrictionHelper->getParams());
     $rewriteswitches = array('cms', 'user');
     $params['rewriteInfo'] = array('fieldset', '', AECToolbox::rewriteEngineInfo($rewriteswitches));
     // make the select list for first trial period units
     $perunit[] = JHTML::_('select.option', 'D', JText::_('PAYPLAN_PERUNIT1'));
     $perunit[] = JHTML::_('select.option', 'W', JText::_('PAYPLAN_PERUNIT2'));
     $perunit[] = JHTML::_('select.option', 'M', JText::_('PAYPLAN_PERUNIT3'));
     $perunit[] = JHTML::_('select.option', 'Y', JText::_('PAYPLAN_PERUNIT4'));
     $lists['trial_periodunit'] = JHTML::_('select.genericlist', $perunit, 'trial_periodunit', 'size="4"', 'value', 'text', arrayValueDefault($params_values, 'trial_periodunit', "D"));
     $lists['full_periodunit'] = JHTML::_('select.genericlist', $perunit, 'full_periodunit', 'size="4"', 'value', 'text', arrayValueDefault($params_values, 'full_periodunit', "D"));
     // make the select list for first trial period units
     $selectmode[] = JHTML::_('select.option', '0', JText::_('PAYPLAN_PROCESSOR_SELECTMODE_LIST'));
     $selectmode[] = JHTML::_('select.option', '1', JText::_('PAYPLAN_PROCESSOR_SELECTMODE_CONFIRMATION'));
     $selectmode[] = JHTML::_('select.option', '2', JText::_('PAYPLAN_PROCESSOR_SELECTMODE_BOTH'));
     $lists['processor_selectmode'] = JHTML::_('select.genericlist', $selectmode, 'processor_selectmode', 'size="3"', 'value', 'text', arrayValueDefault($params_values, 'processor_selectmode', "0"));
     $params['processors_remap'] = array("subarea_change", "plan_params");
     $pps = PaymentProcessorHandler::getInstalledObjectList(1);
     if (empty($params_values['processors'])) {
         $plan_procs = array();
     } else {
         $plan_procs = $params_values['processors'];
     }
     if (!empty($plan_procs)) {
         foreach ($plan_procs as $proc) {
             foreach ($pps as $pk => $ppo) {
                 if ($ppo->id == $proc) {
                     $pps[] = $ppo;
                     unset($pps[$pk]);
                 }
             }
         }
     }
     $custompar = array();
     foreach ($pps as $ppobj) {
         if (!$ppobj->active) {
             continue;
         }
         $pp = new PaymentProcessor();
         if (!$pp->loadName($ppobj->name)) {
             continue;
         }
         $pp->init();
         $pp->getInfo();
         $custompar[$pp->id] = array();
         $custompar[$pp->id]['handle'] = $ppobj->name;
         $custompar[$pp->id]['name'] = $pp->info['longname'];
         $custompar[$pp->id]['params'] = array();
         $params['processor_' . $pp->id] = array('toggle', JText::_('PAYPLAN_PROCESSORS_ACTIVATE_NAME'), JText::_('PAYPLAN_PROCESSORS_ACTIVATE_DESC'));
         $custompar[$pp->id]['params'][] = 'processor_' . $pp->id;
         $params[$pp->id . '_aec_overwrite_settings'] = array('toggle', JText::_('PAYPLAN_PROCESSORS_OVERWRITE_SETTINGS_NAME'), JText::_('PAYPLAN_PROCESSORS_OVERWRITE_SETTINGS_DESC'));
         $custompar[$pp->id]['params'][] = $pp->id . '_aec_overwrite_settings';
         $customparams = $pp->getCustomPlanParams();
         if (is_array($customparams)) {
             foreach ($customparams as $customparam => $cpcontent) {
                 $naming = array($pp->getParamLang($customparam . '_NAME'), $pp->getParamLang($customparam . '_DESC'));
                 $shortname = $pp->id . "_" . $customparam;
                 $params[$shortname] = array_merge($cpcontent, $naming);
                 $custompar[$pp->id]['params'][] = $shortname;
             }
         }
         if (empty($plan_procs)) {
             continue;
         }
         if (!in_array($pp->id, $plan_procs)) {
             continue;
         }
         $params_values['processor_' . $pp->id] = 1;
         if (isset($customparams_values[$pp->id . '_aec_overwrite_settings'])) {
             if (!$customparams_values[$pp->id . '_aec_overwrite_settings']) {
                 continue;
             }
         } else {
             continue;
         }
         $settings_array = $pp->getBackendSettings();
         if (isset($settings_array['lists'])) {
             foreach ($settings_array['lists'] as $listname => $listcontent) {
                 $lists[$pp->id . '_' . $listname] = $listcontent;
             }
             unset($settings_array['lists']);
         }
         // Iterate through settings form to...
         foreach ($settings_array as $name => $values) {
             $setting_name = $pp->id . '_' . $name;
             if (isset($params[$setting_name])) {
                 continue;
             }
             if (isset($customparams_values[$setting_name])) {
                 $value = $customparams_values[$setting_name];
             } elseif (isset($pp->settings[$name])) {
                 $value = $pp->settings[$name];
             } else {
                 $value = '';
             }
             // ...assign new list fields
             switch ($settings_array[$name][0]) {
                 case 'list_yesno':
                     $arr = array(JHTML::_('select.option', 0, JText::_('no')), JHTML::_('select.option', 1, JText::_('yes')));
                     $lists[$setting_name] = JHTML::_('select.genericlist', $arr, $setting_name, '', 'value', 'text', (int) $value);
                     $settings_array[$name][0] = 'list';
                     break;
                 case 'list_currency':
                     // Get currency list
                     $currency_array = explode(',', $pp->info['currencies']);
                     // Transform currencies into OptionArray
                     $currency_code_list = array();
                     foreach ($currency_array as $currency) {
                         if ($this->lang->hasKey('CURRENCY_' . $currency)) {
                             $currency_code_list[] = JHTML::_('select.option', $currency, JText::_('CURRENCY_' . $currency));
                         }
                     }
                     // Create list
                     $lists[$setting_name] = JHTML::_('select.genericlist', $currency_code_list, $setting_name, 'size="10"', 'value', 'text', $value);
                     $settings_array[$name][0] = 'list';
                     break;
                 case 'list_language':
                     // Get language list
                     if (!is_array($pp->info['languages'])) {
                         $this->language_array = explode(',', $pp->info['languages']);
                     } else {
                         $this->language_array = $pp->info['languages'];
                     }
                     // Transform languages into OptionArray
                     $this->language_code_list = array();
                     foreach ($this->language_array as $this->language) {
                         $this->language_code_list[] = JHTML::_('select.option', $this->language, $this->lang->hasKey('LANGUAGECODE_' . $this->language) ? JText::_('LANGUAGECODE_' . $this->language) : $this->language);
                     }
                     // Create list
                     $lists[$setting_name] = JHTML::_('select.genericlist', $this->language_code_list, $setting_name, 'size="10"', 'value', 'text', $value);
                     $settings_array[$name][0] = 'list';
                     break;
                 case 'list_plan':
                     unset($settings_array[$name]);
                     break;
                 default:
                     break;
             }
             // ...put in missing language fields
             if (!isset($settings_array[$name][1])) {
                 $settings_array[$name][1] = $pp->getParamLang($name . '_NAME');
                 $settings_array[$name][2] = $pp->getParamLang($name . '_DESC');
             }
             $params[$setting_name] = $settings_array[$name];
             $custompar[$pp->id]['params'][] = $setting_name;
         }
     }
     $customparamsarray->pp = $custompar;
     // get available active plans
     $fallback_plans = array(JHTML::_('select.option', '0', JText::_('PAYPLAN_NOFALLBACKPLAN')));
     $parent_plans = array(JHTML::_('select.option', '0', JText::_('PAYPLAN_NOPARENTPLAN')));
     $query = 'SELECT `id` AS value, `name` AS text' . ' FROM #__acctexp_plans' . ' WHERE `active` = 1' . ' AND `id` != \'' . $row->id . '\'';
     $this->db->setQuery($query);
     $payment_plans = $this->db->loadObjectList();
     if (is_array($payment_plans)) {
         $fallback_plans = array_merge($fallback_plans, $payment_plans);
         $parent_plans = array_merge($parent_plans, $payment_plans);
     }
     $lists['fallback'] = JHTML::_('select.genericlist', $fallback_plans, 'fallback', 'size="1"', 'value', 'text', arrayValueDefault($params_values, 'fallback', 0));
     $lists['standard_parent'] = JHTML::_('select.genericlist', $parent_plans, 'standard_parent', 'size="1"', 'value', 'text', arrayValueDefault($params_values, 'standard_parent', 0));
     // get similar plans
     if (!empty($params_values['similarplans'])) {
         $query = 'SELECT `id` AS value, `name` As text' . ' FROM #__acctexp_plans' . ' WHERE `id` IN (' . implode(',', $params_values['similarplans']) . ')';
         $this->db->setQuery($query);
         $sel_similar_plans = $this->db->loadObjectList();
     } else {
         $sel_similar_plans = 0;
     }
     $lists['similarplans'] = JHTML::_('select.genericlist', $payment_plans, 'similarplans[]', 'size="1" multiple="multiple"', 'value', 'text', $sel_similar_plans);
     // get equal plans
     if (!empty($params_values['equalplans'])) {
         $query = 'SELECT `id` AS value, `name` AS text' . ' FROM #__acctexp_plans' . ' WHERE `id` IN (' . implode(',', $params_values['equalplans']) . ')';
         $this->db->setQuery($query);
         $sel_equal_plans = $this->db->loadObjectList();
     } else {
         $sel_equal_plans = 0;
     }
     $lists['equalplans'] = JHTML::_('select.genericlist', $payment_plans, 'equalplans[]', 'size="1" multiple="multiple"', 'value', 'text', $sel_equal_plans);
     $lists = array_merge($lists, $restrictionHelper->getLists($params_values, $restrictions_values));
     // make the select list for first trial period units
     $cartmode[] = JHTML::_('select.option', '0', JText::_('PAYPLAN_CARTMODE_INHERIT'));
     $cartmode[] = JHTML::_('select.option', '1', JText::_('PAYPLAN_CARTMODE_FORCE_CART'));
     $cartmode[] = JHTML::_('select.option', '2', JText::_('PAYPLAN_CARTMODE_FORCE_DIRECT'));
     $lists['cart_behavior'] = JHTML::_('select.genericlist', $cartmode, 'cart_behavior', 'size="1"', 'value', 'text', arrayValueDefault($params_values, 'cart_behavior', "0"));
     $mi_list = microIntegrationHandler::getDetailedList();
     $mi_settings = array('inherited' => array(), 'attached' => array(), 'custom' => array());
     $attached_mis = $row->getMicroIntegrationsSeparate(true);
     foreach ($mi_list as $mi_details) {
         $mi_details->inherited = false;
         if (!empty($attached_mis['inherited']) && in_array($mi_details->id, $attached_mis['inherited'])) {
             $mi_details->inherited = true;
             $mi_settings['inherited'][] = $mi_details;
         }
         $mi_details->attached = false;
         if (!empty($attached_mis['plan']) && in_array($mi_details->id, $attached_mis['plan'])) {
             $mi_details->attached = true;
         }
         $mi_settings['attached'][] = $mi_details;
     }
     $mi_handler = new microIntegrationHandler();
     $mi_list = $mi_handler->getIntegrationList();
     $mi_htmllist = array();
     $mi_htmllist[] = JHTML::_('select.option', '', JText::_('AEC_CMN_NONE_SELECTED'));
     foreach ($mi_list as $name) {
         $mi = new microIntegration();
         $mi->class_name = 'mi_' . $name;
         if ($mi->callIntegration()) {
             $len = 30 - AECToolbox::visualstrlen(trim($mi->name));
             $fullname = str_replace('#', '&nbsp;', str_pad($mi->name, $len, '#')) . ' - ' . substr($mi->desc, 0, 120);
             $mi_htmllist[] = JHTML::_('select.option', $name, $fullname);
         }
     }
     if (!empty($row->micro_integrations) && is_array($row->micro_integrations)) {
         $query = 'SELECT `id`' . ' FROM #__acctexp_microintegrations' . ' WHERE `id` IN (' . implode(',', $row->micro_integrations) . ')' . ' AND `hidden` = \'1\'';
         $this->db->setQuery($query);
         $hidden_mi = $this->db->loadObjectList();
     } else {
         $hidden_mi = array();
     }
     $customparamsarray->hasperplanmi = false;
     if (!empty($aecConfig->cfg['per_plan_mis']) || !empty($hidden_mi)) {
         $customparamsarray->hasperplanmi = true;
         $lists['micro_integrations_plan'] = JHTML::_('select.genericlist', $mi_htmllist, 'micro_integrations_plan[]', 'size="' . min(count($mi_list) + 1, 25) . '" multiple="multiple"', 'value', 'text', array());
         $custompar = array();
         $hidden_mi_list = array();
         if (!empty($hidden_mi)) {
             foreach ($hidden_mi as $miobj) {
                 $hidden_mi_list[] = $miobj->id;
             }
         }
         $params['micro_integrations_hidden'] = array('hidden', '');
         $params_values['micro_integrations_hidden'] = $hidden_mi_list;
         if (!empty($hidden_mi)) {
             foreach ($hidden_mi as $miobj) {
                 $mi = new microIntegration();
                 if (!$mi->load($miobj->id)) {
                     continue;
                 }
                 if (!$mi->callIntegration(1)) {
                     continue;
                 }
                 $custompar[$mi->id] = array();
                 $custompar[$mi->id]['name'] = $mi->name;
                 $custompar[$mi->id]['params'] = array();
                 $prefix = 'MI_' . $mi->id . '_';
                 $params[] = array('area_change', 'MI');
                 $params[] = array('subarea_change', 'E');
                 $params[] = array('add_prefix', $prefix);
                 $params[] = array('section_paper', JText::_('MI_E_TITLE'));
                 $generalsettings = $mi->getGeneralSettings();
                 foreach ($generalsettings as $name => $value) {
                     $params[$prefix . $name] = $value;
                     $custompar[$mi->id]['params'][] = $prefix . $name;
                     if (isset($mi->{$name})) {
                         $params_values[$prefix . $name] = $mi->{$name};
                     } else {
                         $params_values[$prefix . $name] = '';
                     }
                 }
                 $params[] = array('section_end', 0);
                 $misettings = $mi->getSettings();
                 if (isset($misettings['lists'])) {
                     foreach ($misettings['lists'] as $listname => $listcontent) {
                         $lists[$prefix . $listname] = str_replace('name="', 'name="' . $prefix, $listcontent);
                     }
                     unset($misettings['lists']);
                 }
                 $params[] = array('area_change', 'MI');
                 $params[] = array('subarea_change', $mi->class_name);
                 $params[] = array('add_prefix', $prefix);
                 $params[] = array('section_paper', JText::_('MI_E_SETTINGS'));
                 foreach ($misettings as $name => $value) {
                     $params[$prefix . $name] = $value;
                     $custompar[$mi->id]['params'][] = $prefix . $name;
                 }
                 $params[] = array('section_end', 0);
             }
         }
         if (!empty($custompar)) {
             $mi_settings['custom'] = $custompar;
         }
     }
     $customparamsarray->mi = $mi_settings;
     $settings = new aecSettings('payplan', 'general');
     if (is_array($customparams_values)) {
         $settingsparams = array_merge($params_values, $customparams_values, $restrictions_values);
     } else {
         $settingsparams = array_merge($params_values, $restrictions_values);
     }
     $settings->fullSettingsArray($params, $settingsparams, $lists);
     // Call HTML Class
     $aecHTML = new aecHTML($settings->settings, $settings->lists);
     if (!empty($customparamsarray)) {
         $aecHTML->customparams = $customparamsarray;
     }
     HTML_AcctExp::editSubscriptionPlan($aecHTML, $row, $hasrecusers);
 }