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 pay($multiplicator = 1, $noclear = false) { $metaUser = false; $new_plan = false; $plans = array(); if (!empty($this->userid)) { $metaUser = new metaUser($this->userid); } if (!empty($this->params['target_user'])) { $targetUser = new metaUser($this->params['target_user']); } else { $targetUser =& $metaUser; } if (!empty($this->params['aec_pickup'])) { if (is_array($this->params['aec_pickup'])) { foreach ($this->params['aec_pickup'] as $key) { if (isset($this->params[$key])) { unset($this->params[$key]); } } } unset($this->params['aec_pickup']); } $override_permissioncheck = $this->isRecurring() && $this->counter > 1; if (!empty($this->usage)) { $usage = explode('.', $this->usage); // Update old notation if (!isset($usage[1])) { $temp = $usage[0]; $usage[0] = 'p'; $usage[1] = $temp; } switch (strtolower($usage[0])) { case 'c': case 'cart': if (empty($this->params['cart']->content)) { $this->params['cart'] = new aecCart(); $this->params['cart']->load($usage[1]); if (!empty($this->params['cart']->content)) { foreach ($this->params['cart']->content as $c) { $new_plan = new SubscriptionPlan(); $new_plan->load($c['id']); for ($i = 0; $i < $c['quantity']; $i++) { $plans[] = $new_plan; } } } $this->params['cart']->clear(); $this->storeload(); // Load and delete original entry $cart = new aecCart(); $cart->load($usage[1]); if ($cart->id) { $cart->delete(); } } else { foreach ($this->params['cart']->content as $c) { $new_plan = new SubscriptionPlan(); $new_plan->load($c['id']); if (!$override_permissioncheck) { if ($new_plan->checkPermission($metaUser) === false) { return false; } } for ($i = 0; $i < $c['quantity']; $i++) { $plans[] = $new_plan; } } } break; case 'p': case 'plan': default: $new_plan = new SubscriptionPlan(); $new_plan->load($this->usage); if (!$override_permissioncheck) { if ($new_plan->checkPermission($metaUser) === false) { return false; } } $plans[] = $new_plan; break; } } if (is_object($metaUser)) { if (!empty($this->params['userMIParams'])) { foreach ($this->params['userMIParams'] as $plan => $mis) { foreach ($mis as $mi_id => $content) { $metaUser->meta->setMIParams($mi_id, $plan, $content); if ($metaUser->userid !== $targetUser->userid) { $targetUser->meta->setMIParams($mi_id, $plan, $content); } } } $metaUser->meta->storeload(); if ($metaUser->userid !== $targetUser->userid) { $targetUser->meta->storeload(); } } } foreach ($plans as $plan) { if (is_object($targetUser) && is_object($plan)) { if ($targetUser->userid) { if (!empty($this->subscr_id)) { $targetUser->establishFocus($plan, $this->method, false, $this->subscr_id); } else { $targetUser->establishFocus($plan, $this->method); } $this->subscr_id = $targetUser->focusSubscription->id; // Apply the Plan $application = $targetUser->focusSubscription->applyUsage($plan->id, $this->method, 0, $multiplicator, $this); } else { $application = $plan->applyPlan(0, $this->method, 0, $multiplicator, $this); } } } $micro_integrations = false; if (!empty($this->conditions)) { if (strpos($this->conditions, 'mi_attendevents')) { $start_position = strpos($this->conditions, '<registration_id>') + strlen('<registration_id>'); $end_position = strpos($this->conditions, '</registration_id>'); $micro_integration['name'] = 'mi_attendevents'; $micro_integration['parameters'] = array('registration_id' => substr($this->conditions, $start_position, $end_position - $start_position)); $micro_integrations = array(); $micro_integrations[] = $micro_integration; } } // Reload the meta- & targetUser since they have been updated if (!empty($this->userid)) { $metaUser = new metaUser($this->userid); } if (!empty($this->params['target_user'])) { $targetUser = new metaUser($this->params['target_user']); } else { $targetUser =& $metaUser; } if (!empty($micro_integrations)) { if (is_array($micro_integrations)) { foreach ($micro_integrations as $micro_int) { $mi = new microIntegration(); if (isset($micro_integration['parameters'])) { $exchange = $micro_integration['parameters']; } else { $exchange = null; } if (isset($micro_int['name'])) { if ($mi->callDry($micro_int['name'])) { if (is_object($targetUser)) { $mi->action($targetUser, $exchange, $this, $new_plan); } else { $mi->action($targetUser, $exchange, $this, $new_plan); } } } elseif (isset($micro_int['id'])) { if ($mi->mi_exists($micro_int['id'])) { $mi->load($micro_int['id']); if ($mi->callIntegration()) { if (is_object($metaUser)) { $mi->action($targetUser, $exchange, $this, $new_plan); } else { $mi->action($targetUser, $exchange, $this, $new_plan); } } } } unset($mi); } } } if ($this->coupons) { foreach ($this->coupons as $coupon_code) { $cph = new couponHandler(); $cph->load($coupon_code); $cph->triggerMIs($targetUser, $this, $plans[0]); } } // We need to at least warn the admin if there is an invoice with nothing to do if (empty($this->usage) && empty($this->conditions) && empty($this->coupons)) { $short = 'Nothing to do'; $event = JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_VALID_APPFAIL'); $tags = 'invoice,application,payment,action_failed'; $params = array('invoice_number' => $this->invoice_number); $eventlog = new eventLog(); $eventlog->issue($short, $tags, $event, 32, $params); } if (!$noclear) { $this->setTransactionDate(); } return true; }