public function savePostParams($array) { // Strip out params that we don't need $params = $this->stripNonParams($array); // Filter out restrictions $fixed = aecRestrictionHelper::paramList(); $fixed[] = 'has_restrictions'; $fixed[] = 'sticky_permissions'; $restrictions = array(); foreach ($fixed as $varname) { if (!isset($array[$varname])) { continue; } $restrictions[$varname] = $array[$varname]; unset($array[$varname]); } $this->restrictions = $restrictions; // Check whether there is a custom function for saving params $new_params = $this->functionProxy('saveparams', $params, $params); $this->name = $array['name']; $this->desc = $array['desc']; $this->active = $array['active']; $this->auto_check = $array['auto_check']; $this->on_userchange = $array['on_userchange']; $this->pre_exp_check = $array['pre_exp_check']; if (!empty($new_params['rebuild'])) { $planlist = MicroIntegrationHandler::getPlansbyMI($this->id); foreach ($planlist as $planid) { $plan = new SubscriptionPlan(); $plan->load($planid); $userlist = SubscriptionPlanHandler::getPlanUserlist($planid); foreach ($userlist as $userid) { $metaUser = new metaUser($userid); if ($metaUser->cmsUser->id) { $this->action($metaUser, $params, null, $plan); } } } $newparams['rebuild'] = 0; } if (!empty($new_params['remove'])) { $planlist = MicroIntegrationHandler::getPlansbyMI($this->id); foreach ($planlist as $planid) { $plan = new SubscriptionPlan(); $plan->load($planid); $userlist = SubscriptionPlanHandler::getPlanUserlist($planid); foreach ($userlist as $userid) { $metaUser = new metaUser($userid); $this->expiration_action($metaUser, $plan); } } $newparams['remove'] = 0; } $this->params = $new_params; return true; }
public function savePOSTsettings($post) { // Fake knowing the planid if is zero. if (!empty($post['id'])) { $groupid = $post['id']; } else { $groupid = $this->getMax() + 1; } if (isset($post['id'])) { unset($post['id']); } if (isset($post['inherited_micro_integrations'])) { unset($post['inherited_micro_integrations']); } if (!empty($post['add_group'])) { ItemGroupHandler::setChildren($post['add_group'], array($groupid), 'group'); } if ($this->id == 1) { $post['active'] = 1; $post['visible'] = 1; $post['name'] = JText::_('AEC_INST_ROOT_GROUP_NAME'); $post['desc'] = JText::_('AEC_INST_ROOT_GROUP_DESC'); $post['reveal_child_items'] = 1; } // Filter out fixed variables $fixed = array('active', 'visible', 'name', 'desc'); foreach ($fixed as $varname) { $this->{$varname} = $post[$varname]; unset($post[$varname]); } foreach ($post['micro_integrations'] as $k => $v) { if ($v) { $post['micro_integrations'][$k] = $v; } else { unset($post['micro_integrations'][$k]); } } // Filter out params $fixed = array('color', 'reveal_child_items', 'symlink', 'symlink_userid', 'notauth_redirect', 'micro_integrations', 'meta'); $params = array(); foreach ($fixed as $varname) { if (!isset($post[$varname])) { continue; } if ($varname == 'color') { if (strpos($post[$varname], '#') !== false) { $post[$varname] = substr($post[$varname], 1); } } $params[$varname] = $post[$varname]; unset($post[$varname]); } $this->saveParams($params); // Filter out restrictions $fixed = aecRestrictionHelper::paramList(); $restrictions = array(); foreach ($fixed as $varname) { if (!isset($post[$varname])) { continue; } $restrictions[$varname] = $post[$varname]; unset($post[$varname]); } $this->restrictions = $restrictions; // There might be deletions set for groups foreach ($post as $varname => $content) { if (strpos($varname, 'group_delete_') !== false && $content) { $parentid = (int) str_replace('group_delete_', '', $varname); ItemGroupHandler::removeChildren($groupid, array($parentid), 'group'); unset($post[$varname]); } } // The rest of the vars are custom params $custom_params = array(); foreach ($post as $varname => $content) { if (substr($varname, 0, 4) != 'mce_') { $custom_params[$varname] = $content; } unset($post[$varname]); } $this->custom_params = $custom_params; }
public function savePOSTsettings($post) { if (!empty($post['id'])) { $planid = $post['id']; } else { // Fake knowing the planid if is zero. $planid = $this->getMax() + 1; } if (isset($post['id'])) { unset($post['id']); } if (isset($post['inherited_micro_integrations'])) { unset($post['inherited_micro_integrations']); } if (!empty($post['add_group'])) { ItemGroupHandler::setChildren($post['add_group'], array($planid)); unset($post['add_group']); } if (empty($post['micro_integrations'])) { $post['micro_integrations'] = array(); } if (!empty($post['micro_integrations_plan'])) { foreach ($post['micro_integrations_plan'] as $miname) { // Create new blank MIs $mi = new microIntegration(); $mi->load(0); $mi->class_name = $miname; if (!$mi->callIntegration(true)) { continue; } $mi->hidden = 1; $mi->storeload(); // Add in new MI id $post['micro_integrations'][] = $mi->id; } $mi->reorder(); unset($post['micro_integrations_plan']); } if (!empty($post['micro_integrations_hidden'])) { // Recover hidden MI relation to full list $post['micro_integrations'] = array_merge($post['micro_integrations'], $post['micro_integrations_hidden']); unset($post['micro_integrations_hidden']); } if (!empty($post['micro_integrations_inherited'])) { unset($post['micro_integrations_inherited']); } // Update MI settings foreach ($post['micro_integrations'] as $miid) { $mi = new microIntegration(); $mi->load($miid); // Only act special on hidden MIs if (!$mi->hidden) { continue; } $prefix = 'MI_' . $miid . '_'; // Get Settings from post array $settings = array(); foreach ($post as $name => $value) { if (strpos($name, $prefix) === 0) { $rname = str_replace($prefix, '', $name); $settings[$rname] = $value; unset($post[$name]); } } // If we indeed HAVE settings, more to come here if (empty($settings)) { continue; } $mi->savePostParams($settings); // First, check whether there is already an MI with the exact same settings $similarmis = microIntegrationHandler::getMIList(false, false, true, false, $mi->classname); $similarmi = false; if (!empty($similarmis)) { foreach ($similarmis as $miobj) { if ($miobj->id == $mi->id) { continue; } if (microIntegrationHandler::compareMIs($mi, $miobj->id)) { $similarmi = $miobj->id; } } } if ($similarmi) { // We have a similar MI - unset old reference $ref = array_search($mi->id, $post['micro_integrations']); unset($post['micro_integrations'][$ref]); // No MI is similar, lets check for other plans $plans = microIntegrationHandler::getPlansbyMI($mi->id); foreach ($plans as $cid => $pid) { if ($pid == $this->id) { unset($plans[$cid]); } } if (count($plans) <= 1) { // No other plan depends on this MI, just delete it $mi->delete(); } // Set new MI $post['micro_integrations'][] = $similarmi; } else { // No MI is similar, lets check for other plans $plans = microIntegrationHandler::getPlansbyMI($mi->id); foreach ($plans as $cid => $pid) { if ($pid == $this->id) { unset($plans[$cid]); } } if (count($plans) > 1) { // We have other plans depending on THIS setup of the MI, unset original reference $ref = array_search($mi->id, $post['micro_integrations']); unset($post['micro_integrations'][$ref]); // And create new MI $mi->id = 0; $mi->storeload(); // Set new MI $post['micro_integrations'][] = $mi->id; } else { $mi->storeload(); } } } // Filter out fixed variables $fixed = array('active', 'visible', 'name', 'desc', 'email_desc', 'micro_integrations'); foreach ($fixed as $varname) { if (isset($post[$varname])) { $this->{$varname} = $post[$varname]; unset($post[$varname]); } else { $this->{$varname} = ''; } } // Get selected processors ( have to be filtered out ) $processors = array(); foreach ($post as $key => $value) { if ($key == 'processor_selectmode') { continue; } if (strpos($key, 'processor_') === 0 && $value) { $ppid = str_replace('processor_', '', $key); if (!in_array($ppid, $processors)) { $processors[] = $ppid; unset($post[$key]); } } } // Filter out params $fixed = array('full_free', 'full_amount', 'full_period', 'full_periodunit', 'trial_free', 'trial_amount', 'trial_period', 'trial_periodunit', 'gid_enabled', 'gid', 'lifetime', 'standard_parent', 'fallback', 'fallback_req_parent', 'similarplans', 'equalplans', 'make_active', 'make_primary', 'update_existing', 'customthanks', 'customtext_thanks_keeporiginal', 'customamountformat', 'customtext_thanks', 'override_activation', 'override_regmail', 'notauth_redirect', 'fixed_redirect', 'hide_duration_checkout', 'addtocart_redirect', 'addtocart_max', 'cart_behavior', 'notes', 'meta', 'processor_selectmode'); $params = array(); foreach ($fixed as $varname) { if (!isset($post[$varname])) { continue; } $params[$varname] = $post[$varname]; unset($post[$varname]); } $params['processors'] = $processors; $this->saveParams($params); // Filter out restrictions $fixed = aecRestrictionHelper::paramList(); $fixed = array_merge($fixed, array('inventory_amount_enabled', 'inventory_amount', 'inventory_amount_used')); $restrictions = array(); foreach ($fixed as $varname) { if (!isset($post[$varname])) { continue; } $restrictions[$varname] = $post[$varname]; unset($post[$varname]); } $this->restrictions = $restrictions; // There might be deletions set for groups foreach ($post as $varname => $content) { if (strpos($varname, 'group_delete_') !== false && $content) { $parentid = (int) str_replace('group_delete_', '', $varname); ItemGroupHandler::removeChildren($planid, array($parentid)); unset($post[$varname]); } } // The rest of the vars are custom params $custom_params = array(); foreach ($post as $varname => $content) { if (substr($varname, 0, 4) != 'mce_') { $custom_params[$varname] = $content; } unset($post[$varname]); } $this->custom_params = $custom_params; }