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 createPlans($grouplist, $plans) { $db = JFactory::getDBO(); if (!$_POST['create_plans']) { $query = 'SELECT MIN(id)' . ' FROM #__acctexp_plans'; $db->setQuery($query); $this->range['plans']['start'] = $db->loadResult(); $query = 'SELECT MAX(id)' . ' FROM #__acctexp_plans'; $db->setQuery($query); $this->range['plans']['end'] = $db->loadResult(); return; } $class = array('diamond', 'copper', 'silver', 'titanium', 'gold', 'platinum'); $color = array('', 'azure ', 'scarlet ', 'jade ', 'lavender ', 'mustard '); $pricerange = array((int) $_POST['mincost'] * 100, (int) $_POST['maxcost'] * 100); for ($i = 1; $i <= $plans; $i++) { if (isset($color[(int) floor($i / 6)]) && isset($class[$i % 6])) { $name = ucfirst($color[(int) floor($i / 6)]) . ucfirst($class[$i % 6]) . " Plan"; } else { $name = "Plan " . $i; } $row = new SubscriptionPlan(); $post = array('active' => 1, 'visible' => 0, 'name' => $name, 'desc' => "Buy " . $name . " now!", 'processors' => '', 'full_amount' => round(rand($pricerange[0], $pricerange[1]) / 100, 2), 'full_free' => 0, 'full_period' => rand(1, 14), 'trial_free' => 0, 'trial_amount' => 0); $row->savePOSTsettings($post); $row->storeload(); ItemGroupHandler::setChildren(rand($this->range['groups']['start'], $this->range['groups']['end']), array($row->id), $type = 'item'); if ($i == 1) { $this->range['plans']['start'] = $row->id; } elseif ($i == $plans) { $this->range['plans']['end'] = $row->id; } } }