public function import() { $show_form = false; $done = false; $temp_dir = JPATH_SITE . '/tmp'; $file_list = xJUtility::getFileArray($temp_dir, 'csv', false, true); $params = array(); $lists = array(); if (!empty($_FILES)) { if (strpos($_FILES['import_file']['name'], '.csv') === false) { $last = strrpos($_FILES['import_file']['name'], '.'); $filename = substr($_FILES['import_file']['name'], 0, $last) . '.csv'; } else { $filename = $_FILES['import_file']['name']; } $destination = $temp_dir . '/' . $filename; if (move_uploaded_file($_FILES['import_file']['tmp_name'], $destination)) { $file_select = $filename; } } if (empty($file_select)) { $file_select = aecGetParam('file_select', ''); } if (empty($file_select)) { $show_form = true; $params['file_select'] = array('list', ''); $params['MAX_FILE_SIZE'] = array('hidden', '5120000'); $params['import_file'] = array('file', 'Upload', 'Upload a file and select it for importing', ''); $file_htmllist = array(); $file_htmllist[] = JHTML::_('select.option', '', JText::_('AEC_CMN_NONE_SELECTED')); if (!empty($file_list)) { foreach ($file_list as $name) { $file_htmllist[] = JHTML::_('select.option', $name, $name); } } $lists['file_select'] = JHTML::_('select.genericlist', $file_htmllist, 'file_select', 'size="' . min(count($file_htmllist) + 1, 25) . '"', 'value', 'text', 0); } else { $options = array(); if (!empty($_POST['assign_plan'])) { $options['assign_plan'] = $_POST['assign_plan']; } $import = new aecImport($temp_dir . '/' . $file_select, $options); if (!$import->read()) { die('could not read file'); } $import->parse(); if (empty($import->rows)) { die('could not find any entries in this file'); } $params['file_select'] = array('hidden', $file_select); if (!isset($_POST['convert_field_0'])) { $fields = array('id' => 'User ID', 'name' => 'User Full Name', 'username' => 'Username', 'email' => 'User Email', 'password' => 'Password', 'plan_id' => 'Payment Plan ID', 'invoice_number' => 'Invoice Number', 'expiration' => 'Membership Expiration'); $mis = array_merge(microIntegrationHandler::getMIList(false, false, false, false, 'mi_aecuserdetails')); foreach ($mis as $entry) { $mi = new microIntegration(); $mi->load($entry->id); if ($mi->callIntegration()) { $fields = array_merge($fields, $mi->mi_class->getCustomFields()); } } $field_htmllist = array(); $field_htmllist[] = JHTML::_('select.option', 0, 'Ignore'); foreach ($fields as $name => $longname) { $field_htmllist[] = JHTML::_('select.option', $name, $longname); } $cols = count($import->rows[0]); $columns = array(); for ($i = 0; $i < $cols; $i++) { $columns[] = 'convert_field_' . $i; $params['convert_field_' . $i] = array('list', '', '', ''); $lists['convert_field_' . $i] = JHTML::_('select.genericlist', $field_htmllist, 'convert_field_' . $i, 'size="1" class="select2-bootstrap"', 'value', 'text', 0); } $rows_count = count($import->rows); $rowcount = min($rows_count, 5); $rows = array(); for ($i = 0; $i < $rowcount; $i++) { $rows[] = $import->rows[$i]; } $params['assign_plan'] = array('list', 'Assign Plan', 'Assign users to a specific payment plan. Is overridden if you provide an individual plan ID with the "Payment Plan ID" field assignment.'); $params['skip_first'] = array('toggle', 'Skip First Line', 'Do not import the first line (use this if you have column names in the first line).'); $available_plans = SubscriptionPlanHandler::getActivePlanList(); $lists['assign_plan'] = JHTML::_('select.genericlist', $available_plans, 'assign_plan', 'size="5"', 'value', 'text', 0); } else { $import->getConversionList(); $import->import(array('skip_first' => $_POST['skip_first'])); $done = true; } } $settingsparams = array(); $settings = new aecSettings('import', 'general'); $settings->fullSettingsArray($params, $settingsparams, $lists); // Call HTML Class $aecHTML = new aecHTML($settings->settings, $settings->lists); $aecHTML->form = $show_form; $aecHTML->done = $done; if (!empty($import->errors)) { $aecHTML->errors = $import->errors; } if (!$show_form && !$done) { $aecHTML->user_rows = $rows; $aecHTML->user_rows_count = $rows_count; $aecHTML->columns = $columns; } HTML_AcctExp::import($aecHTML); }
public function action($request) { $location = $this->getLocation($request); if (empty($location['mi'])) { return true; } $db = JFactory::getDBO(); $mi = new microIntegration(); if (!$mi->mi_exists($location['mi'])) { return true; } $mi->load($location['mi']); if (!$mi->callIntegration()) { return null; } global $aecConfig; $action = 'action'; $exchange = null; if ($mi->relayAction($request->metaUser, $exchange, $request->invoice, null, $action, $request->add) === false) { if ($aecConfig->cfg['breakon_mi_error']) { return false; } } return true; }
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; }
public function userchange($row, $post, $trace = '') { $db = JFactory::getDBO(); $mi_list = $this->getUserChangeIntegrations(); if (is_int($row)) { $userid = $row; } elseif (is_string($row)) { $query = 'SELECT id' . ' FROM #__users' . ' WHERE username = \'' . $row . '\''; $db->setQuery($query); $userid = $db->loadResult(); } elseif (is_array($row)) { $userid = $row['id']; } elseif (!is_object($row)) { $userid = $row; } if (!is_object($row)) { $row = new cmsUser(); $row->load($userid); } if (!empty($mi_list)) { foreach ($mi_list as $mi_id) { if (!is_null($mi_id) && $mi_id != '' && $mi_id) { $mi = new microIntegration(); $mi->load($mi_id); if ($mi->callIntegration()) { $mi->on_userchange_action($row, $post, $trace); } } } } }
public function triggerPreExpiration($metaUser, $mi_pexp) { // No actions on expired, trial or recurring if ($this->isExpired() || $this->isTrial() || $this->recurring) { return false; } $plan = $this->getPlan(); $micro_integrations = $plan->getMicroIntegrations(); $actions = 0; if (empty($micro_integrations)) { return $actions; } foreach ($micro_integrations as $mi_id) { if (!in_array($mi_id, $mi_pexp)) { continue; } $mi = new microIntegration(); if (!$mi->mi_exists($mi_id)) { continue; } $mi->load($mi_id); if (!$mi->callIntegration()) { continue; } // Do the actual pre expiration check on this MI if ($this->isExpired($mi->pre_exp_check)) { $result = $mi->pre_expiration_action($metaUser, $plan); if ($result) { $actions++; } } unset($mi); } return $actions; }
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 cmdApply($metaUser, $params) { global $aecConfig; $db = JFactory::getDBO(); switch (strtolower($params[0])) { case 'plan': $plans = explode(',', $params[1]); foreach ($plans as $planid) { $plan = new SubscriptionPlan(); $plan->load($planid); $metaUser->establishFocus($plan); $metaUser->focusSubscription->applyUsage($planid, 'none', 1); } break; case 'mi': $micro_integrations = explode(',', $params[1]); if (is_array($micro_integrations)) { foreach ($micro_integrations as $mi_id) { $mi = new microIntegration(); if (!$mi->mi_exists($mi_id)) { continue; } $mi->load($mi_id); if (!$mi->callIntegration()) { continue; } if (isset($params[2])) { $action = $params[2]; } else { $action = 'action'; } $invoice = $exchange = $add = null; if ($mi->relayAction($metaUser, $exchange, $invoice, null, $action, $add) === false) { if ($aecConfig->cfg['breakon_mi_error']) { return false; } } unset($mi); } } break; } }
public function overloadByPlan($plan) { // Get list of service MIs $mis = microIntegrationHandler::getMIsbyPlan($plan); if (empty($mis)) { return; } foreach ($mis as $miid) { $mi = new microIntegration(); $mi->load($miid); if (!$mi->callIntegration()) { continue; } if (method_exists($mi->mi_class, 'overrideService')) { $mi->mi_class->overrideService($this); } } }
public function readMIs() { $db = JFactory::getDBO(); $lang = JFactory::getLanguage(); $r = array(); $r['head'] = "Micro Integration"; $r['type'] = ""; $micursor = ''; foreach ($this->milist as $miobj) { $mi = new microIntegration(); $mi->load($miobj->id); $mi->callIntegration(true); if ($miobj->class_name != $micursor) { $readout[] = $r; unset($r); $r = array(); if (!empty($mi->info)) { $r['head'] = $mi->info['name']; } else { $r['head'] = $miobj->class_name; } $r['type'] = "table"; $r['sub'] = true; $r['set'] = array(); $r['def'] = array("ID" => array('id'), "Published" => array('active', 'bool'), "Visible" => array('visible', 'bool'), "Name" => array('name', 'smartlimit haslink', 'editMicroIntegration', 'id'), "Desc" => array('desc', 'notags smartlimit'), "Exp Action" => array('auto_check', 'bool'), "PreExp Action" => array('pre_exp_check'), "UserChange Action" => array('on_userchange', 'bool')); $settings = $mi->getSettings(); if (isset($settings['lists'])) { unset($settings['lists']); } if (!empty($settings)) { foreach ($settings as $sname => $setting) { if (is_numeric($sname) || strpos($sname, 'aectab_') !== false) { continue; } $name = 'MI_' . strtoupper($miobj->class_name) . '_' . strtoupper($sname) . '_NAME'; if ($lang->hasKey($name)) { $r['def'][JText::_($name)] = array(array('settings', $sname), 'notags smartlimit'); } else { $r['def'][$sname] = array(array('settings', $sname), 'notags smartlimit'); } } } } $ps = array(); foreach ($r['def'] as $nn => $def) { $ps = array_merge($ps, $this->conversionHelper($def, $mi)); } $r['set'][] = $ps; $micursor = $miobj->class_name; } $readout[] = $r; return $readout; }
/** * @param Invoice $invoice */ public function triggerMIs($metaUser, $invoice, $new_plan) { global $aecConfig; // See whether this coupon has micro integrations if (empty($this->coupon->micro_integrations)) { return null; } foreach ($this->coupon->micro_integrations as $mi_id) { $mi = new microIntegration(); // Only call if it exists if (!$mi->mi_exists($mi_id)) { continue; } $mi->load($mi_id); // Check whether we can really call if (!$mi->callIntegration()) { continue; } $add = $params = false; if (is_object($metaUser)) { if ($mi->action($metaUser, null, $invoice, $new_plan) === false) { if ($aecConfig->cfg['breakon_mi_error']) { return false; } } if ($mi->relayAction($metaUser, null, $invoice, $this, 'afteraction', $add, $params) === false) { if ($aecConfig->cfg['breakon_mi_error']) { return false; } } } else { $metaUser = false; if ($mi->action($metaUser, null, $invoice, $new_plan) === false) { if ($aecConfig->cfg['breakon_mi_error']) { return false; } } if ($mi->relayAction($metaUser, null, $invoice, $this, 'afteraction', $add, $params) === false) { if ($aecConfig->cfg['breakon_mi_error']) { return false; } } } } }
public function relayAction($request) { if (!($request->area == 'afteraction')) { return null; } $options = $this->getOption($request); foreach ($options as $option) { if (empty($option['mi'])) { continue; } $mi = new microIntegration(); if (!$mi->mi_exists($option['mi'])) { return true; } $mi->load($option['mi']); if ($mi->callIntegration()) { $exchange = $params = null; if ($mi->relayAction($request->metaUser, $exchange, $request->invoice, null, 'action', $request->add, $params) === false) { global $aecConfig; if ($aecConfig->cfg['breakon_mi_error']) { return false; } } if ($mi->relayAction($request->metaUser, $exchange, $request->invoice, null, 'afteraction', $request->add, $params) === false) { global $aecConfig; if ($aecConfig->cfg['breakon_mi_error']) { return false; } } } } return true; }