Example #1
0
 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;
 }
Example #2
0
 public function edit($id)
 {
     $lists = array();
     $cph = new couponHandler();
     if (empty($id)) {
         $cph->coupon = new Coupon();
         $cph->coupon->createNew();
         $params_values = array();
         $discount_values = array();
         $restrictions_values = array();
     } else {
         $idx = explode(".", $id[0]);
         $cph->coupon = new Coupon($idx[0]);
         $cph->coupon->load($idx[1]);
         $params_values = $cph->coupon->params;
         $discount_values = $cph->coupon->discount;
         $restrictions_values = $cph->coupon->restrictions;
     }
     // We need to convert the values that are set as object properties
     $params_values['active'] = $cph->coupon->active;
     $params_values['type'] = $cph->coupon->type;
     $params_values['name'] = $cph->coupon->name;
     $params_values['desc'] = $cph->coupon->desc;
     $params_values['coupon_code'] = $cph->coupon->coupon_code;
     $params_values['usecount'] = $cph->coupon->usecount;
     $params_values['micro_integrations'] = $cph->coupon->micro_integrations;
     // params and their type values
     $params['active'] = array('toggle', 1);
     $params['type'] = array('toggle', 1);
     $params['name'] = array('inputC', '');
     $params['desc'] = array('inputE', '');
     $params['coupon_code'] = array('inputC', '');
     $params['micro_integrations'] = array('list', '');
     $params['params_remap'] = array('subarea_change', 'params');
     $params['amount_use'] = array('toggle', '');
     $params['amount'] = array('inputB', '');
     $params['amount_percent_use'] = array('toggle', '');
     $params['amount_percent'] = array('inputB', '');
     $params['percent_first'] = array('toggle', '');
     $params['useon_trial'] = array('toggle', '');
     $params['useon_full'] = array('toggle', '1');
     $params['useon_full_all'] = array('toggle', '1');
     $params['has_start_date'] = array('toggle', 1);
     $params['start_date'] = array('list_date', date('Y-m-d', (int) gmdate('U')));
     $params['has_expiration'] = array('toggle', 0);
     $params['expiration'] = array('list_date', date('Y-m-d', (int) gmdate('U')));
     $params['has_max_reuse'] = array('toggle', 0);
     $params['max_reuse'] = array('inputA', 1);
     $params['has_max_peruser_reuse'] = array('toggle', 1);
     $params['max_peruser_reuse'] = array('inputA', 1);
     $params['usecount'] = array('inputA', 0);
     $params['usage_plans_enabled'] = array('toggle', 0);
     $params['usage_plans'] = array('list', 0);
     $params['usage_cart_full'] = array('toggle', 0);
     $params['cart_multiple_items'] = array('toggle', 0);
     $params['cart_multiple_items_amount'] = array('inputB', '');
     $params['restr_remap'] = array('subarea_change', 'restrictions');
     $params['depend_on_subscr_id'] = array('toggle', 0);
     $params['subscr_id_dependency'] = array('inputB', '');
     $params['allow_trial_depend_subscr'] = array('toggle', 0);
     $params['restrict_combination'] = array('toggle', 0);
     $params['bad_combinations'] = array('list', '');
     $params['allow_combination'] = array('toggle', 0);
     $params['good_combinations'] = array('list', '');
     $params['restrict_combination_cart'] = array('toggle', 0);
     $params['bad_combinations_cart'] = array('list', '');
     $params['allow_combination_cart'] = array('toggle', 0);
     $params['good_combinations_cart'] = array('list', '');
     $restrictionHelper = new aecRestrictionHelper();
     $params = array_merge($params, $restrictionHelper->getParams());
     // get available plans
     $available_plans = array();
     $this->db->setQuery('SELECT `id` as value, `name` as text' . ' FROM #__acctexp_plans');
     $plans = $this->db->loadObjectList();
     if (is_array($plans)) {
         $all_plans = array_merge($available_plans, $plans);
     } else {
         $all_plans = $available_plans;
     }
     $total_all_plans = min(max(count($all_plans) + 1, 4), 20);
     // get usages
     if (!empty($restrictions_values['usage_plans'])) {
         $query = 'SELECT `id` AS value, `name` as text' . ' FROM #__acctexp_plans' . ' WHERE `id` IN (' . implode(',', $restrictions_values['usage_plans']) . ')';
         $this->db->setQuery($query);
         $sel_usage_plans = $this->db->loadObjectList();
     } else {
         $sel_usage_plans = 0;
     }
     $lists['usage_plans'] = JHTML::_('select.genericlist', $all_plans, 'usage_plans[]', 'size="' . $total_all_plans . '" multiple="multiple"', 'value', 'text', $sel_usage_plans);
     // get available micro integrations
     $available_mi = array();
     $query = 'SELECT `id` AS value, CONCAT(`name`, " - ", `desc`) AS text' . ' FROM #__acctexp_microintegrations' . ' WHERE `active` = 1' . ' ORDER BY `ordering`';
     $this->db->setQuery($query);
     $mi_list = $this->db->loadObjectList();
     $mis = array();
     if (!empty($mi_list) && !empty($params_values['micro_integrations'])) {
         foreach ($mi_list as $mi_item) {
             if (in_array($mi_item->value, $params_values['micro_integrations'])) {
                 $mis[] = $mi_item->value;
             }
         }
     }
     if (!empty($mis)) {
         $query = 'SELECT `id` AS value, CONCAT(`name`, " - ", `desc`) AS text' . ' FROM #__acctexp_microintegrations' . (!empty($mis) ? ' WHERE `id` IN (' . implode(',', $mis) . ')' : '');
         $this->db->setQuery($query);
         $selected_mi = $this->db->loadObjectList();
     } else {
         $selected_mi = array();
     }
     $lists['micro_integrations'] = JHTML::_('select.genericlist', $mi_list, 'micro_integrations[]', 'size="' . min(count($mi_list) + 1, 25) . '" multiple="multiple"', 'value', 'text', $selected_mi);
     $query = 'SELECT count(*)' . ' FROM #__acctexp_coupons';
     $this->db->setQuery($query);
     $ccount = $this->db->loadResult();
     if ($ccount > 50) {
         $coupons = array();
     } else {
         $query = 'SELECT `coupon_code` as value, `coupon_code` as text' . ' FROM #__acctexp_coupons' . ' WHERE `coupon_code` != \'' . $cph->coupon->coupon_code . '\'';
         $this->db->setQuery($query);
         $coupons = $this->db->loadObjectList();
     }
     $query = 'SELECT `coupon_code` as value, `coupon_code` as text' . ' FROM #__acctexp_coupons_static' . ' WHERE `coupon_code` != \'' . $cph->coupon->coupon_code . '\'';
     $this->db->setQuery($query);
     $coupons = array_merge($this->db->loadObjectList(), $coupons);
     $cpl = array('bad_combinations', 'good_combinations', 'bad_combinations_cart', 'good_combinations_cart');
     foreach ($cpl as $cpn) {
         $cur = array();
         if (!empty($restrictions_values[$cpn])) {
             if ($ccount > 50) {
                 $cur = array();
             } else {
                 $query = 'SELECT `coupon_code` as value, `coupon_code` as text' . ' FROM #__acctexp_coupons' . ' WHERE `coupon_code` IN (\'' . implode('\',\'', $restrictions_values[$cpn]) . '\')';
                 $this->db->setQuery($query);
                 $cur = $this->db->loadObjectList();
             }
             $query = 'SELECT `coupon_code` as value, `coupon_code` as text' . ' FROM #__acctexp_coupons_static' . ' WHERE `coupon_code` IN (\'' . implode('\',\'', $restrictions_values[$cpn]) . '\')';
             $this->db->setQuery($query);
             $nc = $this->db->loadObjectList();
             if (!empty($nc)) {
                 $cur = array_merge($nc, $cur);
             }
         }
         $lists[$cpn] = JHTML::_('select.genericlist', $coupons, $cpn . '[]', 'size="' . min(count($coupons) + 1, 25) . '" multiple="multiple"', 'value', 'text', $cur);
     }
     $lists = array_merge($lists, $restrictionHelper->getLists($params_values, $restrictions_values));
     $settings = new aecSettings('coupon', 'general');
     if (is_array($discount_values) && is_array($restrictions_values)) {
         $settingsparams = array_merge($params_values, $discount_values, $restrictions_values);
     } else {
         $settingsparams = $params_values;
     }
     $settings->fullSettingsArray($params, $settingsparams, $lists);
     // Call HTML Class
     $aecHTML = new aecHTML($settings->settings, $settings->lists);
     // Lets grab the data and fill it in.
     $this->db->setQuery('SELECT id' . ' FROM #__acctexp_invoices' . ' WHERE `coupons` <> \'\'' . ' ORDER BY `created_date` DESC');
     $rows = $this->db->loadObjectList();
     if ($this->db->getErrorNum()) {
         echo $this->db->stderr();
         return false;
     }
     $aecHTML->invoices = array();
     foreach ($rows as $row) {
         $invoice = new Invoice();
         $invoice->load($row->id);
         if (!in_array($cph->coupon->coupon_code, $invoice->coupons)) {
             continue;
         }
         $in_formatted = $invoice->formatInvoiceNumber();
         $invoice->invoice_number_formatted = $invoice->invoice_number . ($in_formatted != $invoice->invoice_number ? "\n" . '(' . $in_formatted . ')' : '');
         $invoice->usage = '<a href="index.php?option=com_acctexp&amp;task=edit&amp;entity=SubscriptionPlan&amp;id=' . $invoice->usage . '">' . $invoice->usage . '</a>';
         $query = 'SELECT username' . ' FROM #__users' . ' WHERE `id` = \'' . $invoice->userid . '\'';
         $this->db->setQuery($query);
         $username = $this->db->loadResult();
         $invoice->username = '******' . $invoice->userid . '">';
         if (!empty($username)) {
             $invoice->username .= $username . '</a>';
         } else {
             $invoice->username .= $invoice->userid;
         }
         $invoice->username .= '</a>';
         $aecHTML->invoices[] = $invoice;
     }
     HTML_AcctExp::editCoupon($aecHTML, $cph->coupon);
 }
 public function savePostParams($array)
 {
     // Strip out params that we don't need
     $params = $this->stripNonParams($array);
     // Filter out restrictions
     $fixed = aecRestrictionHelper::paramList();
     $fixed[] = 'has_restrictions';
     $fixed[] = 'sticky_permissions';
     $restrictions = array();
     foreach ($fixed as $varname) {
         if (!isset($array[$varname])) {
             continue;
         }
         $restrictions[$varname] = $array[$varname];
         unset($array[$varname]);
     }
     $this->restrictions = $restrictions;
     // Check whether there is a custom function for saving params
     $new_params = $this->functionProxy('saveparams', $params, $params);
     $this->name = $array['name'];
     $this->desc = $array['desc'];
     $this->active = $array['active'];
     $this->auto_check = $array['auto_check'];
     $this->on_userchange = $array['on_userchange'];
     $this->pre_exp_check = $array['pre_exp_check'];
     if (!empty($new_params['rebuild'])) {
         $planlist = MicroIntegrationHandler::getPlansbyMI($this->id);
         foreach ($planlist as $planid) {
             $plan = new SubscriptionPlan();
             $plan->load($planid);
             $userlist = SubscriptionPlanHandler::getPlanUserlist($planid);
             foreach ($userlist as $userid) {
                 $metaUser = new metaUser($userid);
                 if ($metaUser->cmsUser->id) {
                     $this->action($metaUser, $params, null, $plan);
                 }
             }
         }
         $newparams['rebuild'] = 0;
     }
     if (!empty($new_params['remove'])) {
         $planlist = MicroIntegrationHandler::getPlansbyMI($this->id);
         foreach ($planlist as $planid) {
             $plan = new SubscriptionPlan();
             $plan->load($planid);
             $userlist = SubscriptionPlanHandler::getPlanUserlist($planid);
             foreach ($userlist as $userid) {
                 $metaUser = new metaUser($userid);
                 $this->expiration_action($metaUser, $plan);
             }
         }
         $newparams['remove'] = 0;
     }
     $this->params = $new_params;
     return true;
 }
Example #4
0
 public function actionRestrictionCheck()
 {
     $this->response->result = false;
     if (!empty($this->request->details->plan)) {
         $plan = new SubscriptionPlan();
         $plan->load($this->request->details->plan);
         if ($plan->id != $this->request->details->plan) {
             $this->error = 'could not find plan to check restrictions for';
             return;
         }
         $restrictions = $plan->getRestrictionsArray();
         if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) !== false) {
             if (!ItemGroupHandler::checkParentRestrictions($plan, 'item', $this->metaUser)) {
                 $this->error = 'user is denied permission - plans parent group is restricted from this user';
             }
         } else {
             $this->error = 'user is denied permission - plan is restricted from this user';
         }
         unset($this->request->details->plan);
     }
     if (!empty($this->request->details->group)) {
         $group = new ItemGroup();
         $group->load($this->request->details->group);
         if ($group->id != $this->request->details->group) {
             $this->error = 'could not find group to check restrictions for';
             return;
         }
         $restrictions = $group->getRestrictionsArray();
         if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) !== false) {
             if (!ItemGroupHandler::checkParentRestrictions($group, 'group', $this->metaUser)) {
                 $this->error = 'user is denied permission - groups parent group is restricted from this user';
             }
         } else {
             $this->error = 'user is denied permission - group is restricted from this user';
         }
         unset($this->request->details->group);
     }
     if (!empty($this->request->details)) {
         $re = get_object_vars($this->request->details);
         $restrictions = aecRestrictionHelper::getRestrictionsArray($re);
         if (aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser) === false) {
             $this->error = 'user is denied permission - at least one restriction result was negative';
         }
     }
     if (empty($this->error)) {
         $this->response->result = true;
     }
 }
Example #5
0
 public function verifyUsage()
 {
     if (empty($this->usage)) {
         return null;
     }
     $this->loadMetaUser();
     $plan = new SubscriptionPlan();
     $plan->load($this->usage);
     $restrictions = $plan->getRestrictionsArray();
     if (!aecRestrictionHelper::checkRestriction($restrictions, $this->metaUser)) {
         return getView('access_denied');
     }
     if (!ItemGroupHandler::checkParentRestrictions($plan, 'item', $this->metaUser)) {
         return getView('access_denied');
     }
     return true;
 }
 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;
 }
 static function getRestrictionsArray($restrictions)
 {
     $newrest = array();
     // Check for a fixed GID - this certainly overrides the others
     if (!empty($restrictions['fixgid_enabled'])) {
         $newrest['fixgid'] = (int) $restrictions['fixgid'];
     } else {
         // No fixed GID, check for min GID
         if (!empty($restrictions['mingid_enabled'])) {
             $newrest['mingid'] = (int) $restrictions['mingid'];
         }
         // Check for max GID
         if (!empty($restrictions['maxgid_enabled'])) {
             $newrest['maxgid'] = (int) $restrictions['maxgid'];
         }
     }
     // First we sort out the group restrictions and convert them into plan restrictions
     // Check for a directly previously used group
     if (!empty($restrictions['previousgroup_req_enabled'])) {
         if (!empty($restrictions['previousgroup_req'])) {
             $restrictions = aecRestrictionHelper::addGroupPlans($restrictions, 'previousgroup_req', 'previousplan_req');
             $restrictions['previousplan_req_enabled'] = true;
         }
     }
     // Check for a directly previously used group
     if (!empty($restrictions['previousgroup_req_enabled_excluded'])) {
         if (!empty($restrictions['previousgroup_req_excluded'])) {
             $restrictions = aecRestrictionHelper::addGroupPlans($restrictions, 'previousgroup_req_excluded', 'previousplan_req_excluded');
             $restrictions['previousplan_req_enabled_excluded'] = true;
         }
     }
     // Check for a currently used group
     if (!empty($restrictions['currentgroup_req_enabled'])) {
         if (!empty($restrictions['currentgroup_req'])) {
             $restrictions = aecRestrictionHelper::addGroupPlans($restrictions, 'currentgroup_req', 'currentplan_req');
             $restrictions['currentplan_req_enabled'] = true;
         }
     }
     // Check for a currently used group
     if (!empty($restrictions['currentgroup_req_enabled_excluded'])) {
         if (!empty($restrictions['currentgroup_req_excluded'])) {
             $restrictions = aecRestrictionHelper::addGroupPlans($restrictions, 'currentgroup_req_excluded', 'currentplan_req_excluded');
             $restrictions['currentplan_req_enabled_excluded'] = true;
         }
     }
     // Check for a overall used group
     if (!empty($restrictions['overallgroup_req_enabled'])) {
         if (!empty($restrictions['overallgroup_req'])) {
             $restrictions = aecRestrictionHelper::addGroupPlans($restrictions, 'overallgroup_req', 'overallplan_req');
             $restrictions['overallplan_req_enabled'] = true;
         }
     }
     // Check for a overall used group
     if (!empty($restrictions['overallgroup_req_enabled_excluded'])) {
         if (!empty($restrictions['overallgroup_req_excluded'])) {
             $restrictions = aecRestrictionHelper::addGroupPlans($restrictions, 'overallgroup_req_excluded', 'overallplan_req_excluded');
             $restrictions['overallplan_req_enabled_excluded'] = true;
         }
     }
     // And now we prepare the individual plan restrictions
     // Check for a directly previously used plan
     if (!empty($restrictions['previousplan_req_enabled'])) {
         if (!empty($restrictions['previousplan_req'])) {
             $newrest['plan_previous'] = $restrictions['previousplan_req'];
         }
     }
     // Check for a directly previously used plan
     if (!empty($restrictions['previousplan_req_enabled_excluded'])) {
         if (!empty($restrictions['previousplan_req_excluded'])) {
             $newrest['plan_previous_excluded'] = $restrictions['previousplan_req_excluded'];
         }
     }
     // Check for a currently used plan
     if (!empty($restrictions['currentplan_req_enabled'])) {
         if (!empty($restrictions['currentplan_req'])) {
             $newrest['plan_present'] = $restrictions['currentplan_req'];
         }
     }
     // Check for a currently used plan
     if (!empty($restrictions['currentplan_req_enabled_excluded'])) {
         if (!empty($restrictions['currentplan_req_excluded'])) {
             $newrest['plan_present_excluded'] = $restrictions['currentplan_req_excluded'];
         }
     }
     // Check for a overall used plan
     if (!empty($restrictions['overallplan_req_enabled'])) {
         if (!empty($restrictions['overallplan_req'])) {
             $newrest['plan_overall'] = $restrictions['overallplan_req'];
         }
     }
     // Check for a overall used plan
     if (!empty($restrictions['overallplan_req_enabled_excluded'])) {
         if (!empty($restrictions['overallplan_req_excluded'])) {
             $newrest['plan_overall_excluded'] = $restrictions['overallplan_req_excluded'];
         }
     }
     if (!empty($restrictions['used_plan_min_enabled'])) {
         if (!empty($restrictions['used_plan_min_amount']) && isset($restrictions['used_plan_min'])) {
             if (!isset($newrest['plan_amount_min'])) {
                 $newrest['plan_amount_min'] = array();
             }
             if (is_array($restrictions['used_plan_min'])) {
                 foreach ($restrictions['used_plan_min'] as $planid) {
                     if ($planid) {
                         $newrest['plan_amount_min'][] = (int) $planid . ',' . (int) $restrictions['used_plan_min_amount'];
                     }
                 }
             } else {
                 $newrest['plan_amount_min'][] = array((int) $restrictions['used_plan_min'] . ',' . (int) $restrictions['used_plan_min_amount']);
             }
         }
     }
     // Check for a overall used group with amount minimum
     if (!empty($restrictions['used_group_min_enabled'])) {
         if (!empty($restrictions['used_group_min_amount']) && isset($restrictions['used_group_min'])) {
             $temp = aecRestrictionHelper::addGroupPlans($restrictions, 'used_group_min', 'used_plan_min', array());
             $ps = array();
             foreach ($temp['used_plan_min'] as $planid) {
                 if ($planid) {
                     $newrest['plan_amount_min'][] = (int) $planid . ',' . (int) $restrictions['used_group_min_amount'];
                 }
             }
         }
     }
     // Check for a overall used plan with amount maximum
     if (!empty($restrictions['used_plan_max_enabled'])) {
         if (!empty($restrictions['used_plan_max_amount']) && isset($restrictions['used_plan_max'])) {
             if (!isset($newrest['plan_amount_max'])) {
                 $newrest['plan_amount_max'] = array();
             }
             if (is_array($restrictions['used_plan_max'])) {
                 foreach ($restrictions['used_plan_max'] as $planid) {
                     if ($planid) {
                         $newrest['plan_amount_max'][] = (int) $planid . ',' . (int) $restrictions['used_plan_max_amount'];
                     }
                 }
             } else {
                 $newrest['plan_amount_max'][] = (int) $restrictions['used_plan_max'] . ',' . (int) $restrictions['used_plan_max_amount'];
             }
         }
     }
     // Check for a overall used group with amount maximum
     if (!empty($restrictions['used_group_max_enabled'])) {
         if (!empty($restrictions['used_group_max_amount']) && isset($restrictions['used_group_max'])) {
             $temp = aecRestrictionHelper::addGroupPlans($restrictions, 'used_group_max', 'used_plan_max', array());
             $ps = array();
             foreach ($temp['used_plan_max'] as $planid) {
                 if ($planid) {
                     $newrest['plan_amount_max'][] = (int) $planid . ',' . (int) $restrictions['used_group_max_amount'];
                 }
             }
         }
     }
     // Check for custom restrictions
     if (!empty($restrictions['custom_restrictions_enabled'])) {
         if (!empty($restrictions['custom_restrictions'])) {
             $newrest['custom_restrictions'] = aecRestrictionHelper::transformCustomRestrictions($restrictions['custom_restrictions']);
         }
     }
     return $newrest;
 }
Example #8
0
 public function checkRestrictions($metaUser, $terms = null, $usage = null)
 {
     if (empty($metaUser)) {
         return false;
     }
     $restrictionHelper = new aecRestrictionHelper();
     // Load Restrictions and resulting Permissions
     $restrictions = $restrictionHelper->getRestrictionsArray($this->restrictions);
     $permissions = $metaUser->permissionResponse($restrictions);
     // Check for a set usage
     if (!empty($this->restrictions['usage_plans_enabled']) && !is_null($usage)) {
         if (!empty($this->restrictions['usage_plans'])) {
             // Check whether this usage is restricted
             $plans = $this->restrictions['usage_plans'];
             if (in_array($usage, $plans)) {
                 $permissions['usage'] = true;
             } else {
                 $permissions['usage'] = false;
             }
         }
     }
     // Check for Trial only
     if ($this->discount['useon_trial'] && !$this->discount['useon_full'] && is_object($terms)) {
         $permissions['trial_only'] = false;
         if ($terms->nextterm->type == 'trial') {
             $permissions['trial_only'] = true;
         }
     }
     // Check for max reuse per user
     if (!empty($this->restrictions['has_max_peruser_reuse']) && !empty($this->restrictions['max_peruser_reuse'])) {
         $used = $metaUser->usedCoupon($this->coupon->id, $this->type);
         if ($used == false) {
             $permissions['max_peruser_reuse'] = true;
         } elseif ((int) $used <= (int) $this->restrictions['max_peruser_reuse']) {
             // use count was set immediately before, so <= is accurate
             $permissions['max_peruser_reuse'] = true;
         } else {
             $permissions['max_peruser_reuse'] = false;
         }
     }
     // Plot out error messages
     if (count($permissions)) {
         foreach ($permissions as $name => $status) {
             if (!$status) {
                 $errors = array('fixgid' => 'permission', 'mingid' => 'permission', 'maxgid' => 'permission', 'setgid' => 'permission', 'usage' => 'wrong_usage', 'trial_only' => 'trial_only', 'plan_previous' => 'wrong_plan_previous', 'plan_present' => 'wrong_plan', 'plan_overall' => 'wrong_plans_overall', 'plan_amount_min' => 'wrong_plan', 'plan_amount_max' => 'wrong_plans_overall', 'max_reuse' => 'max_reuse', 'max_peruser_reuse' => 'max_reuse');
                 if (isset($errors[$name])) {
                     $this->setError(JText::_(strtoupper('coupon_error_' . $errors[$name])));
                 } else {
                     $this->status = false;
                 }
                 return false;
             }
         }
     }
     return true;
 }
Example #9
0
    /**
     * @param aecHTML $aecHTML
     * @param Coupon $row
     */
    static function editCoupon($aecHTML, $row)
    {
        HTML_myCommon::startCommon('aec-wrap-cream', 'aec-wrap-inner-light');
        JHTML::_('behavior.calendar');
        HTML_myCommon::startForm();
        HTML_myCommon::getHeader('AEC_COUPON', 'coupons', $row->id ? $row->name : JText::_('AEC_CMN_NEW'), false, 'edit', 'Coupon');
        ?>
<div class="col-sm-12"><?php 
        $tabs = new bsPaneTabs();
        $tabs->startTabs();
        $tabs->newTab('coupon', JText::_('COUPON_DETAIL_TITLE'));
        $tabs->newTab('restrictions', JText::_('COUPON_RESTRICTIONS_TITLE'));
        $tabs->newTab('mis', JText::_('COUPON_MI'));
        $tabs->newTab('invoices', JText::_('Invoices'));
        $tabs->endTabs();
        $tabs->startPanes();
        $tabs->nextPane('coupon');
        ?>
		<div class="row">
			<div class="col-sm-6">
				<section class="paper">
					<h4>General</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('name');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('coupon_code');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('active');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('type');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('desc');
        ?>
				</section>
				<section class="paper">
					<h4>Terms</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('amount_use');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('amount');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('amount_percent_use');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('amount_percent');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('percent_first');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('useon_trial');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('useon_full');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('useon_full_all');
        ?>
				</section>
			</div>
			<div class="col-sm-6">
				<section class="paper">
					<h4>Date &amp; User Restrictions</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('has_start_date');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('start_date');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('has_expiration');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('expiration');
        ?>
					<hr />
					<?php 
        echo $aecHTML->createSettingsParticle('has_max_reuse');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('max_reuse');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('usecount');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('has_max_peruser_reuse');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('max_peruser_reuse');
        ?>
					<hr />
					<?php 
        echo $aecHTML->createSettingsParticle('usage_plans_enabled');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('usage_plans');
        ?>
					<hr />
					<?php 
        echo $aecHTML->createSettingsParticle('usage_cart_full');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('cart_multiple_items');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('cart_multiple_items_amount');
        ?>
				</section>
			</div>
		</div>
		<?php 
        $tabs->nextPane('restrictions');
        ?>
		<div class="col-sm-8 col-sm-offset-2">
			<section class="paper">
				<h4>Restrict Combinations</h4>
				<?php 
        echo $aecHTML->createSettingsParticle('depend_on_subscr_id');
        ?>
				<?php 
        echo $aecHTML->createSettingsParticle('subscr_id_dependency');
        ?>
				<?php 
        echo $aecHTML->createSettingsParticle('allow_trial_depend_subscr');
        ?>
				<hr />
				<?php 
        echo $aecHTML->createSettingsParticle('restrict_combination');
        ?>
				<?php 
        echo $aecHTML->createSettingsParticle('bad_combinations');
        ?>
				<?php 
        echo $aecHTML->createSettingsParticle('allow_combination');
        ?>
				<?php 
        echo $aecHTML->createSettingsParticle('good_combinations');
        ?>
				<hr />
				<?php 
        echo $aecHTML->createSettingsParticle('restrict_combination_cart');
        ?>
				<?php 
        echo $aecHTML->createSettingsParticle('bad_combinations_cart');
        ?>
				<hr />
				<?php 
        echo $aecHTML->createSettingsParticle('allow_combination_cart');
        ?>
				<?php 
        echo $aecHTML->createSettingsParticle('good_combinations_cart');
        ?>
			</section>
		</div>
		<?php 
        aecRestrictionHelper::echoSettings($aecHTML);
        ?>
		<?php 
        $tabs->nextPane('mis');
        ?>
		<div class="row">
			<div class="col-sm-12">
				<section class="paper">
					<h4>Micro Integrations</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('micro_integrations');
        ?>
				</section>
			</div>
		</div>
		<?php 
        $tabs->nextPane('invoices');
        ?>
		<div class="row">
			<div class="col-sm-12">
				<section class="paper">
					<h4><?php 
        echo JText::_('Invoices');
        ?>
</h4>
					<table class="table table-hover table-striped table-selectable">
						<thead><tr>
							<th>#</th>
							<th><?php 
        echo JText::_('INVOICE_USERID');
        ?>
</th>
							<th class="text-center"><?php 
        echo JText::_('INVOICE_INVOICE_NUMBER');
        ?>
</th>
							<th class="text-center"><?php 
        echo JText::_('INVOICE_SECONDARY_IDENT');
        ?>
</th>
							<th class="text-center"><?php 
        echo JText::_('INVOICE_CREATED_DATE');
        ?>
</th>
							<th class="text-center"><?php 
        echo JText::_('INVOICE_TRANSACTION_DATE');
        ?>
</th>
							<th class="text-center"><?php 
        echo JText::_('USERPLAN');
        ?>
</th>
							<th class="text-center"><?php 
        echo JText::_('INVOICE_METHOD');
        ?>
</th>
							<th class="text-center"><?php 
        echo JText::_('INVOICE_AMOUNT');
        ?>
</th>
							<th><?php 
        echo JText::_('INVOICE_CURRENCY');
        ?>
</th>
						</tr></thead>
						<tbody>
						<?php 
        foreach ($aecHTML->invoices as $i => $invoice) {
            ?>
							<tr>
								<td><?php 
            echo $i + 1;
            ?>
</td>
								<td><a href="index.php?option=com_acctexp&amp;task=edit&amp;entity=Membership&amp;userid=<?php 
            echo $invoice->userid;
            ?>
"><?php 
            echo $invoice->username;
            ?>
</a></td>
								<td><a href="<?php 
            echo 'index.php?option=com_acctexp&amp;task=edit&amp;entity=Invoice&amp;id=' . $invoice->id;
            ?>
" target="_blank" title="<?php 
            echo JText::_('AEC_CMN_CLICK_TO_EDIT');
            ?>
"><?php 
            echo $row->invoice_number_formatted;
            ?>
</a></td>
								<td><?php 
            echo $invoice->secondary_ident;
            ?>
</td>
								<td><?php 
            echo $invoice->created_date;
            ?>
</td>
								<td><?php 
            echo $invoice->transaction_date;
            ?>
</td>
								<td><?php 
            echo $invoice->usage;
            ?>
</td>
								<td><?php 
            echo $invoice->method;
            ?>
</td>
								<td><?php 
            echo $invoice->amount;
            ?>
</td>
								<td><?php 
            echo $invoice->currency;
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
						</tbody>
					</table>
				</section>
			</div>
		</div>
		<?php 
        $tabs->endPanes();
        ?>
		<input type="hidden" name="id" value="<?php 
        echo $row->id;
        ?>
" />
		<input type="hidden" name="oldtype" value="<?php 
        echo $row->type;
        ?>
" />
		<input type="hidden" name="option" value="com_acctexp" />
		<input type="hidden" name="entity" value="Coupon" />
		<input type="hidden" name="task" value="save" />
		</form>

		</div>

		<?php 
        HTML_myCommon::endCommon();
    }