public function save() { unset($_POST['option']); unset($_POST['task']); $id = $_POST['id'] ? $_POST['id'] : 0; $mi = new microIntegration(); $mi->load($id); if (!empty($_POST['class_name'])) { $load = $mi->callDry($_POST['class_name']); } else { $load = $mi->callIntegration(1); } if ($load) { $save = array('attach_to_plans' => array(), 'attached_to_plans' => array(), 'attach_to_groups' => array(), 'attached_to_groups' => array()); foreach ($save as $pid => $v) { if (isset($_POST[$pid])) { $save[$pid] = $_POST[$pid]; unset($_POST[$pid]); } else { $save[$pid] = array(); } } $mi->savePostParams($_POST); $mi->storeload(); $all_groups = array_unique(array_merge($save['attach_to_groups'], $save['attached_to_groups'])); if (!empty($all_groups)) { foreach ($all_groups as $groupid) { $group = new ItemGroup(); $group->load($groupid); if (in_array($groupid, $save['attach_to_groups']) && !in_array($groupid, $save['attached_to_groups'])) { $group->params['micro_integrations'][] = $mi->id; $group->storeload(); } elseif (!in_array($groupid, $save['attach_to_groups']) && in_array($groupid, $save['attached_to_groups'])) { unset($group->params['micro_integrations'][array_search($mi->id, $group->params['micro_integrations'])]); $group->storeload(); } } } $all_plans = array_unique(array_merge($save['attach_to_plans'], $save['attached_to_plans'])); if (!empty($all_plans)) { foreach ($all_plans as $planid) { $plan = new SubscriptionPlan(); $plan->load($planid); if (in_array($planid, $save['attach_to_plans']) && !in_array($planid, $save['attached_to_plans'])) { $plan->micro_integrations[] = $mi->id; $plan->storeload(); } elseif (!in_array($planid, $save['attach_to_plans']) && in_array($planid, $save['attached_to_plans'])) { unset($plan->micro_integrations[array_search($mi->id, $plan->micro_integrations)]); $plan->storeload(); } } } } else { $short = 'microIntegration storing failure'; if (!empty($_POST['class_name'])) { $event = 'When trying to store microIntegration: ' . $_POST['class_name'] . ', callIntegration failed'; } else { $event = 'When trying to store microIntegration: ' . $mi->id . ', callIntegration failed'; } $tags = 'microintegration,loading,error'; $params = array(); $eventlog = new eventLog(); $eventlog->issue($short, $tags, $event, 128, $params); } $mi->reorder(); $this->setMessage(JText::_('AEC_MSG_SUCESSFULLY_SAVED')); }
public function getMicroIntegrationsSeparate($strip_inherited = false) { if (empty($this->params['micro_integrations'])) { $milist = array(); } else { $milist = $this->params['micro_integrations']; } // Find parent ItemGroups to attach their MIs $parents = ItemGroupHandler::getParents($this->id, 'group'); $gmilist = array(); if (!empty($parents)) { foreach ($parents as $parent) { $g = new ItemGroup(); $g->load($parent); if (!empty($g->params['micro_integrations'])) { $gmilist = array_merge($gmilist, $g->params['micro_integrations']); } } } if (empty($milist) && empty($gmilist)) { return array('group' => array(), 'inherited' => array()); } $milist = microIntegrationHandler::getActiveListbyList($milist); $gmilist = microIntegrationHandler::getActiveListbyList($gmilist); if (empty($milist) && empty($gmilist)) { return array('group' => array(), 'inherited' => array()); } if ($this->id > 1) { // Remove entries from the group MIs that are already inherited if (!empty($gmilist) && !empty($milist) && $strip_inherited) { $theintersect = array_intersect($gmilist, $milist); if (!empty($theintersect)) { foreach ($theintersect as $value) { // STAY IN THE CAR unset($milist[array_search($value, $milist)]); } } } } else { $gmilist = array(); } return array('group' => $milist, 'inherited' => $gmilist); }
/** * @param integer $mi_id */ static function getGroupsbyMI($mi_id, $inherited = true, $extended = false) { $db = JFactory::getDBO(); $query = 'SELECT `id`' . ' FROM #__acctexp_itemgroups'; $db->setQuery($query); $groups = xJ::getDBArray($db); $group_list = array(); foreach ($groups as $groupid) { $group = new ItemGroup(); $group->load($groupid); if ($inherited) { $mis = $group->getMicroIntegrations(); } else { $misx = $group->getMicroIntegrationsSeparate(); $mis = $misx['group']; } if (!empty($mis)) { if (is_array($mi_id)) { if (array_intersect($mi_id, $mis)) { if ($extended) { $group_list[] = $group; } else { $group_list[] = $groupid; } } } else { if (in_array($mi_id, $mis)) { if ($extended) { $group_list[] = $group; } else { $group_list[] = $groupid; } } } } } return $group_list; }
public function actionRestrictionCheck() { $this->response->result = false; if (!empty($this->request->details->plan)) { $plan = new SubscriptionPlan(); $plan->load($this->request->details->plan); if ($plan->id != $this->request->details->plan) { $this->error = 'could not find plan to check restrictions for'; return; } $restrictions = $plan->getRestrictionsArray(); if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) !== false) { if (!ItemGroupHandler::checkParentRestrictions($plan, 'item', $this->metaUser)) { $this->error = 'user is denied permission - plans parent group is restricted from this user'; } } else { $this->error = 'user is denied permission - plan is restricted from this user'; } unset($this->request->details->plan); } if (!empty($this->request->details->group)) { $group = new ItemGroup(); $group->load($this->request->details->group); if ($group->id != $this->request->details->group) { $this->error = 'could not find group to check restrictions for'; return; } $restrictions = $group->getRestrictionsArray(); if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) !== false) { if (!ItemGroupHandler::checkParentRestrictions($group, 'group', $this->metaUser)) { $this->error = 'user is denied permission - groups parent group is restricted from this user'; } } else { $this->error = 'user is denied permission - group is restricted from this user'; } unset($this->request->details->group); } if (!empty($this->request->details)) { $re = get_object_vars($this->request->details); $restrictions = aecRestrictionHelper::getRestrictionsArray($re); if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) === false) { $this->error = 'user is denied permission - at least one restriction result was negative'; } } if (empty($this->error)) { $this->response->result = true; } }
public function create($intro = 0, $usage = 0, $group = 0, $processor = null, $invoice = 0, $autoselect = false) { global $aecConfig; $register = !$this->loadMetaUser(true); $this->getPassthrough(); // Reset $register if we seem to have all data if ($register && !empty($this->passthrough['username']) || !empty($aecConfig->cfg['skip_registration'])) { $register = 0; } if ($intro && $this->metaUser->hasSubscription && !$aecConfig->cfg['customintro_always']) { $intro = false; } if (empty($this->usage) && empty($group) && !$intro && !empty($aecConfig->cfg['customintro'])) { if (!empty($aecConfig->cfg['customintro_userid'])) { aecRedirect($aecConfig->cfg['customintro'], $this->userid, "aechidden"); } else { aecRedirect($aecConfig->cfg['customintro']); } } $this->recurring = aecGetParam('recurring', null); $planlist = new SubscriptionPlanList($usage, $group, $this->metaUser, $this->recurring); $nochoice = false; // There is no choice if we have only one group or only one item with one payment option if (count($planlist->list) === 1) { if ($planlist->list[0]['type'] == 'item') { if (count($planlist->list[0]['gw']) === 1) { $nochoice = true; } elseif (!empty($processor)) { foreach ($planlist->list[0]['gw'] as $gw) { if ($gw->processor_name == $processor) { $nochoice = true; } } if ($nochoice) { $first = 0; foreach ($planlist->list[0]['gw'] as $gwid => $gw) { if ($gw->processor_name != $processor) { unset($planlist->list[0]['gw'][$gwid]); } else { $first = $gwid; } } if (!empty($first)) { $planlist->list[0]['gw'][0] = $planlist->list[0]['gw'][$first]; unset($planlist->list[0]['gw'][$first]); } } } } else { // Jump back and use the only group we've found return $this->create($intro, 0, $planlist->list[0]['id'], null, 0, true); } } // If we have only one processor on one plan, there is no need for a decision if ($nochoice && !($aecConfig->cfg['show_fixeddecision'] && empty($processor))) { // If the user also needs to register, we need to guide him there after the selection has now been made if ($register && empty($aecConfig->cfg['skip_registration'])) { aecRegistration::registerRedirect($intro, $planlist->list[0]); } else { // Existing user account - so we need to move on to the confirmation page with the details $this->usage = $planlist->list[0]['id']; if (isset($planlist->list[0]['gw'][0]->recurring)) { $this->recurring = $planlist->list[0]['gw'][0]->recurring; } else { $this->recurring = 0; } $this->processor = $planlist->list[0]['gw'][0]->processor_name; if ($invoice != 0 && !is_null($invoice)) { $this->invoice_number = $invoice; } return $this->confirm(); } } if ($group) { $g = new ItemGroup(); $g->load($group); $planlist->list['group'] = ItemGroupHandler::getGroupListItem($g); } $cart = $this->userid ? aecCartHelper::getCartidbyUserid($this->userid) : false; $selected = (!empty($group) || !empty($usage)) && !$autoselect; if (!$selected && !empty($planlist->list['group'])) { unset($planlist->list['group']); } $passthrough = $this->getPassthrough(); $csslist = $planlist->addButtons($register, $passthrough); return getView('plans', array('userid' => $this->userid, 'list' => $planlist->list, 'passthrough' => $passthrough, 'register' => $register, 'cart' => $cart, 'selected' => $selected, 'group' => $group, 'csslist' => $csslist)); }