public function save() { $row = new ItemGroup(); $row->load($_POST['id']); $post = AECToolbox::cleanPOST($_POST, false); $row->savePOSTsettings($post); if (!$row->check()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-2); </script>\n"; exit; } if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-2); </script>\n"; exit; } $row->reorder(); if ($_POST['id']) { $id = $_POST['id']; } else { $id = $row->getMax(); } if (empty($_POST['id'])) { ItemGroupHandler::setChildren(1, array($id), 'group'); } $this->setMessage(JText::_('AEC_MSG_SUCESSFULLY_SAVED')); }
* @package AEC - Account Control Expiration - Membership Manager * @subpackage Install Includes * @copyright 2006-2015 Copyright (C) David Deutsch * @author David Deutsch <*****@*****.**> & Team AEC - http://www.valanx.org * @license GNU/GPL v.3 http://www.gnu.org/licenses/gpl.html or, at your option, any later version */ // Dont allow direct linking defined('_JEXEC') or die('Direct Access to this location is not allowed.'); // Check for a root group $db->setQuery("SELECT id FROM #__acctexp_itemgroups WHERE id='1'"); // Create root group completely out of thin air (tadaa!) if ($db->loadResult() != 1) { $rootgroup = new ItemGroup(); $rootgroup->id = 0; $rootgroup->active = 1; $rootgroup->visible = 1; $rootgroup->name = JText::_('AEC_INST_ROOT_GROUP_NAME'); $rootgroup->desc = JText::_('AEC_INST_ROOT_GROUP_DESC'); $rootgroup->params = array('color' => 'bbddff', 'icon' => 'flag_blue', 'reveal_child_items' => 1); $rootgroup->storeload(); if ($rootgroup->id != 1) { $db->setQuery("UPDATE #__acctexp_itemgroups SET id='1' WHERE id='" . $rootgroup->id . "'"); $db->query(); } // Adding in root group relation for all plans $planlist = SubscriptionPlanHandler::listPlans(); $db->setQuery("SELECT count(*) FROM #__acctexp_itemxgroup"); if (count($planlist) > $db->loadResult()) { ItemGroupHandler::setChildren(1, $planlist); } }
public function createGroups($amount) { $db = JFactory::getDBO(); if (!$_POST['create_groups']) { $query = 'SELECT MIN(id)' . ' FROM #__acctexp_itemgroups' . ' WHERE `id` > 1'; $db->setQuery($query); $this->range['groups']['start'] = $db->loadResult(); $query = 'SELECT MAX(id)' . ' FROM #__acctexp_itemgroups'; $db->setQuery($query); $this->range['groups']['end'] = $db->loadResult(); return array(); } $colors = array('1f77b4', 'aec7e8', 'ff7f0e', 'ffbb78', '2ca02c', '98df8a', 'd62728', 'ff9896', '9467bd', 'c5b0d5', '8c564b', 'c49c94', 'e377c2', 'f7b6d2', '7f7f7f', 'c7c7c7', 'bcbd22', 'dbdb8d', '17becf', '9edae5', 'BBDDFF', '5F8BC4', 'A2BE72', 'DDFF99', 'D07C30', 'C43C42', 'AA89BB', 'B7B7B7', '808080'); $grouplist = array(); for ($i = 0; $i <= $amount; $i++) { $row = new ItemGroup(); $post = array('active' => 1, 'visible' => 0, 'name' => 'Group ' . ($i + 1), 'desc' => 'Group ' . ($i + 1), 'color' => $colors[$i % 29]); $row->savePOSTsettings($post); $row->storeload(); ItemGroupHandler::setChildren(1, array($row->id), $type = 'group'); if ($i == 0) { $this->range['groups']['start'] = $row->id; } elseif ($i == $amount) { $this->range['groups']['end'] = $row->id; } $grouplist[] = $row->id; } return $grouplist; }
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; }