Пример #1
0
 public function touchMIs()
 {
     // Make sure mi language files are updated
     $milist = microIntegrationHandler::getMIList();
     $midone = array();
     foreach ($milist as $miobj) {
         if (in_array($miobj->class_name, $midone)) {
             continue;
         }
         $mifobj = new microIntegration();
         if ($mifobj->load($miobj->id)) {
             $mifobj->copyAssets();
             $midone[] = $miobj->class_name;
         }
     }
 }
 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;
 }
Пример #3
0
 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);
 }
Пример #4
0
 /**
  * @param string $method
  */
 public function aecReadout($optionlist, $method)
 {
     $this->optionlist = $optionlist;
     $this->method = "conversionHelper" . strtoupper($method);
     $this->lists = array();
     $this->acllist = xJACLhandler::aclList();
     foreach ($this->acllist as $aclitem) {
         $this->lists['gid'][$aclitem->group_id] = $aclitem->name;
     }
     $this->planlist = SubscriptionPlanHandler::getFullPlanList();
     foreach ($this->planlist as $planitem) {
         $this->lists['plan'][$planitem->id] = $planitem->name;
     }
     $this->milist = microIntegrationHandler::getMIList(null, null, isset($_POST['use_ordering']), true);
     foreach ($this->milist as $miitem) {
         $this->lists['mi'][$miitem->id] = $miitem->name;
     }
 }