public function edit($id) { $lists = array(); $mi = new microIntegration(); $mi->load($id); $aecHTML = null; $attached = array(); $mi_gsettings = $mi->getGeneralSettings(); if (!$mi->id) { // Create MI Selection List $mi_handler = new microIntegrationHandler(); $mi_list = $mi_handler->getIntegrationList(); $drilldown = array('all' => array()); $mi_gsettings['class_name'] = array('hidden'); $mi_gsettings['class_list'] = array('list'); if (count($mi_list) > 0) { foreach ($mi_list as $name) { $mi_item = new microIntegration(); if ($mi_item->callDry($name)) { $handle = str_replace('mi_', '', $mi_item->class_name); if (isset($mi_item->info['type'])) { foreach ($mi_item->info['type'] as $type) { $drill = explode('.', $type); $cursor =& $drilldown; $mi_item->name = str_replace(array(' AEC ', ' MI '), ' ', $mi_item->name); foreach ($drill as $i => $k) { if (!isset($cursor[$k])) { $cursor[$k] = array(); } if ($i == count($drill) - 1) { $cursor[$k][] = '<a href="#' . $handle . '" class="mi-menu-mi"><span class="mi-menu-mi-name">' . $mi_item->name . '</span><span class="mi-menu-mi-desc">' . $mi_item->desc . '</span></a>'; } else { $cursor =& $cursor[$k]; } } } } $drilldown['all'][] = '<a href="#' . $handle . '" class="mi-menu-mi"><span class="mi-menu-mi-name">' . $mi_item->name . '</span><span class="mi-menu-mi-desc">' . $mi_item->desc . '</span></a>'; } } deep_ksort($drilldown); $lists['class_list'] = '<a tabindex="0" href="#mi-select-list" class="btn btn-primary" id="drilldown">Select an Integration</a>'; $lists['class_list'] .= '<div id="mi-select-list" class="hidden"><ul>'; foreach ($drilldown as $lin => $li) { if ($this->lang->hasKey('AEC_MI_LIST_' . strtoupper($lin))) { $kkey = JText::_('AEC_MI_LIST_' . strtoupper($lin)); } else { $kkey = ucwords(str_replace('_', ' ', $lin)); } $lists['class_list'] .= '<li><a href="#">' . $kkey . '</a><ul>'; foreach ($li as $lixn => $lix) { if (is_array($lix)) { if ($this->lang->hasKey('AEC_MI_LIST_' . strtoupper($lixn))) { $xkey = JText::_('AEC_MI_LIST_' . strtoupper($lixn)); } else { $xkey = ucwords(str_replace('_', ' ', $lixn)); } $lists['class_list'] .= '<li><a href="#">' . $xkey . '</a><ul>'; foreach ($lix as $mix) { $lists['class_list'] .= '<li>' . $mix . '</li>'; } $lists['class_list'] .= '</ul></li>'; } else { $lists['class_list'] .= '<li>' . $lix . '</li>'; } } $lists['class_list'] .= '</ul></li>'; } $lists['class_list'] .= '</ul></div>'; } else { $lists['class_list'] = ''; } } if ($mi->id) { // Call MI (override active check) and Settings if ($mi->callIntegration(true)) { $attached['plans'] = microIntegrationHandler::getPlansbyMI($mi->id, false, true); $attached['groups'] = microIntegrationHandler::getGroupsbyMI($mi->id, false, true); $set = array(); foreach ($mi_gsettings as $n => $v) { if (!isset($mi->{$n})) { if (isset($mi->settings[$n])) { $set[$n] = $mi->settings[$n]; } else { $set[$n] = null; } } else { $set[$n] = $mi->{$n}; } } $restrictionHelper = new aecRestrictionHelper(); $mi_gsettings['restr_remaps'] = array('subarea_change', 'restrictions'); $mi_gsettings = array_merge($mi_gsettings, $restrictionHelper->getParams()); if (empty($mi->restrictions)) { $mi->restrictions = array(); } $lists = array_merge($lists, $restrictionHelper->getLists($set, $mi->restrictions)); $mi_gsettings[$mi->id . 'remap'] = array('area_change', 'MI'); $mi_gsettings[$mi->id . 'remaps'] = array('subarea_change', $mi->class_name); $mi_settings = $mi->getSettings(); // Get lists supplied by the MI if (!empty($mi_settings['lists'])) { $lists = array_merge($lists, $mi_settings['lists']); unset($mi_settings['lists']); } $available_plans = SubscriptionPlanHandler::getPlanList(false, false, true, null, true); $selected_plans = array(); foreach ($attached['plans'] as $p) { $selected_plans[] = (object) array('value' => $p->id, 'text' => $p->name); } $lists['attach_to_plans'] = JHTML::_('select.genericlist', $available_plans, 'attach_to_plans[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', $selected_plans); $available_groups = ItemGroupHandler::getGroups(null, true); $selected_groups = array(); foreach ($attached['groups'] as $g) { $selected_groups[] = (object) array('value' => $g->id, 'text' => $g->name); } $lists['attach_to_groups'] = JHTML::_('select.genericlist', $available_groups, 'attach_to_groups[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', $selected_groups); $gsettings = new aecSettings('MI', 'E'); $gsettings->fullSettingsArray($mi_gsettings, array_merge($set, $mi->restrictions), $lists); $settings = new aecSettings('MI', $mi->class_name); $settings->fullSettingsArray($mi_settings, $set, $lists); // Call HTML Class $aecHTML = new aecHTML(array_merge($gsettings->settings, $settings->settings), array_merge($gsettings->lists, $settings->lists)); $aecHTML->hasHacks = method_exists($mi->mi_class, 'hacks'); $aecHTML->customparams = array(); foreach ($mi_settings as $n => $v) { $aecHTML->customparams[] = $n; } $aecHTML->hasSettings = true; $aecHTML->hasRestrictions = !empty($mi->settings['has_restrictions']); } else { $short = 'microIntegration loading failure'; $event = 'When trying to load microIntegration: ' . $mi->id . ', callIntegration failed'; $tags = 'microintegration,loading,error'; $params = array(); $eventlog = new eventLog(); $eventlog->issue($short, $tags, $event, 128, $params); } } else { $settings = new aecSettings('MI', 'E'); $settings->fullSettingsArray($mi_gsettings, array(), $lists); // Call HTML Class $aecHTML = new aecHTML($settings->settings, $settings->lists); $aecHTML->hasSettings = false; $aecHTML->hasRestrictions = false; $available_plans = SubscriptionPlanHandler::getPlanList(false, false, true, null, true); $lists['attach_to_plans'] = JHTML::_('select.genericlist', $available_plans, 'attach_to_plans[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', null); $available_groups = ItemGroupHandler::getGroups(null, true); $lists['attach_to_groups'] = JHTML::_('select.genericlist', $available_groups, 'attach_to_groups[]', 'size="1" multiple="multiple" class="select2-bootstrap"', 'value', 'text', null); } HTML_AcctExp::editMicroIntegration($mi, $lists, $aecHTML, $attached); }
public function cmdHas($params) { switch (strtolower($params[0])) { case 'subscriptionid': return explode(',', $params[1]); break; case 'userid': $db = JFactory::getDBO(); $query = 'SELECT `id`' . ' FROM #__users' . ' WHERE `userid` IN (' . $params[1] . ')'; $db->setQuery($query); return xJ::getDBArray($db); break; case 'username': $db = JFactory::getDBO(); $query = 'SELECT `id`' . ' FROM #__users' . ' WHERE LOWER( `username` ) LIKE \'%' . $params[1] . '%\''; $db->setQuery($query); $ids = xJ::getDBArray($db); $p = array(); $p[0] = 'userid'; $p[1] = implode(',', $ids); return $this->cmdHas($p); break; case 'plan': $db = JFactory::getDBO(); $query = 'SELECT ' . ($this->focus == 'users' ? 'DISTINCT `userid`' : '`id`') . ' FROM #__acctexp_subscr' . ' WHERE `plan` IN (' . $params[1] . ')' . ' AND `status` != \'Expired\'' . ' AND `status` != \'Closed\'' . ' AND `status` != \'Hold\''; $db->setQuery($query); return xJ::getDBArray($db); break; case 'mi': $mis = explode(',', $params[1]); $plans = array(); foreach ($mis as $mi) { $plans = array_merge($plans, microIntegrationHandler::getPlansbyMI($mi)); } $plans = array_unique($plans); $p = array(); $p[0] = 'plan'; $p[1] = implode(',', $plans); return $this->cmdHas($p); break; } }
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; }
public function beat() { $this->processors = array(); $this->proc_prepare = array(); $this->result = array('fail_expired' => 0, 'fallback' => 0, 'skipped' => 0, 'expired' => 0, 'pre_expired' => 0, 'pre_exp_actions' => 0); // Some cleanup $this->deleteTempTokens(); // Receive maximum pre expiration time $pre_expiration = microIntegrationHandler::getMaxPreExpirationTime(); $subscription_list = $this->getSubscribers($pre_expiration); // Efficient way to check for expired users without checking on each one if (empty($subscription_list)) { return $this->endBeat(); } foreach ($subscription_list as $sid => $sub_id) { $subscription = new Subscription(); $subscription->load($sub_id); if (!aecUserHelper::UserExists($subscription->userid)) { unset($subscription_list[$sid]); continue; } // Check whether this user really is expired // If this check fails, the following subscriptions might still be pre-expiration events if ($subscription->isExpired()) { // If we don't have any validation response, expire $validate = $this->processorValidation($subscription, $subscription_list); if ($validate === false) { // There was some kind of fatal error, return. return false; } elseif ($validate !== true) { $expire = $subscription->expire(); if ($expire) { $this->result['expired']++; } elseif ($expire === false) { $this->result['fail_expired']++; } elseif (is_null($expire)) { $this->result['fallback']++; } else { $this->result['skipped']++; } } unset($subscription_list[$sid]); } elseif (!$subscription->recurring) { break; } } // Only go for pre expiration action if we have at least one user for it if (empty($pre_expiration) || empty($subscription_list)) { return $this->endBeat(); } // Get all the MIs which have a pre expiration check $mi_pexp = microIntegrationHandler::getPreExpIntegrations(); // Find plans which have the MIs assigned $expmi_plans = microIntegrationHandler::getPlansbyMI($mi_pexp); // Filter out the users which dont have the correct plan $query = 'SELECT `id`, `userid`' . ' FROM #__acctexp_subscr' . ' WHERE `id` IN (' . implode(',', $subscription_list) . ')' . ' AND `plan` IN (' . implode(',', $expmi_plans) . ')'; $this->_db->setQuery($query); $sub_list = $this->_db->loadObjectList(); if (!empty($sub_list)) { foreach ($sub_list as $sl) { $metaUser = new metaUser($sl->userid); $metaUser->moveFocus($sl->id); $res = $metaUser->focusSubscription->triggerPreExpiration($metaUser, $mi_pexp); if ($res) { $this->result['pre_exp_actions'] += $res; $this->result['pre_expired']++; } } } return $this->endBeat(); }