public function save() { $row = new SubscriptionPlan(); $row->load($_POST['id']); $post = AECToolbox::cleanPOST($_POST, false); $row->savePOSTsettings($post); $row->storeload(); if ($_POST['id']) { $id = $_POST['id']; } else { $id = $row->getMax(); } if (empty($_POST['id'])) { ItemGroupHandler::setChildren(1, array($id), 'item'); } if (!empty($row->params['lifetime']) && !empty($row->params['full_period'])) { $this->log("Plan Warning", "You have selected a regular period for a plan that" . " already has the 'lifetime' (i.e. 'non expiring') flag set." . " The period you have set will be overridden by" . " that setting.", 'settings,plan'); } $terms = $row->getTerms(); if (!$terms->checkFree() && empty($row->params['processors'])) { $this->log("Plan Warning", "You have set a plan to be non-free, yet did not select a payment processor." . " Without a processor assigned, the plan will not show up on the frontend.", 'settings,plan'); } if (!empty($row->params['lifetime']) && !empty($row->params['processors'])) { $fcount = 0; $found = 0; foreach ($row->params['processors'] as $procid) { $fcount++; if (isset($row->custom_params[$procid . '_recurring'])) { if (0 < $row->custom_params[$procid . '_recurring'] && $row->custom_params[$procid . '_recurring'] < 2) { $found++; } elseif ($row->custom_params[$procid . '_recurring'] == 2) { $fcount++; } } else { $pp = new PaymentProcessor(); if (0 < $pp->is_recurring() && $pp->is_recurring() < 2) { $found++; } elseif ($pp->is_recurring() == 2) { $fcount++; } } } if ($found) { if ($found < $fcount && $fcount > 1) { $event = "You have selected one or more processors that only support recurring payments" . ", yet the plan is set to a lifetime period." . " This is not possible and the processors will not be displayed as options."; } else { $event = "You have selected a processor that only supports recurring payments" . ", yet the plan is set to a lifetime period." . " This is not possible and the plan will not be displayed."; } $short = "Plan Warning"; $tags = 'settings,plan'; $params = array(); $eventlog = new eventLog(); $eventlog->issue($short, $tags, $event, 32, $params); } } $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; } } }