コード例 #1
0
ファイル: acctexp.user.class.php プロジェクト: Ibrahim1/aec
 public function establishFocus($payment_plan, $processor = 'none', $silent = false, $bias = null)
 {
     if (!is_object($payment_plan)) {
         $planid = $payment_plan;
         $payment_plan = new SubscriptionPlan();
         $payment_plan->load($planid);
         if (empty($payment_plan->id)) {
             return false;
         }
     }
     if (is_object($this->focusSubscription)) {
         if ($this->focusSubscription->plan == $payment_plan->id) {
             return 'existing';
         }
     }
     $plan_params = $payment_plan->params;
     if (!isset($plan_params['make_primary'])) {
         $plan_params['make_primary'] = 1;
     }
     if ($plan_params['make_primary'] && $this->hasSubscription) {
         if ($this->objSubscription->primary) {
             $this->focusSubscription = $this->objSubscription;
             return 'existing';
         } else {
             $existing_record = $this->objSubscription->getSubscriptionID($this->userid);
             if ($existing_record) {
                 $this->objSubscription = new Subscription();
                 $this->objSubscription->load($existing_record);
                 $this->focusSubscription = $this->objSubscription;
                 return 'existing';
             }
         }
     }
     // If we are not dealing with a primary (or an otherwise unclear situation),
     // we need to figure out how to prepare the switch
     $existing_record = 0;
     $existing_status = false;
     // Check whether a record exists
     if ($this->hasSubscription) {
         $existing_record = $this->focusSubscription->getSubscriptionID($this->userid, $payment_plan->id, $plan_params['make_primary'], false, $bias);
         if (!empty($existing_record)) {
             $db = JFactory::getDBO();
             $query = 'SELECT `status`' . ' FROM #__acctexp_subscr' . ' WHERE `id` = \'' . (int) $existing_record . '\'';
             $db->setQuery($query);
             $existing_status = $db->loadResult();
         }
     }
     $return = false;
     // To be failsafe, a new subscription may have to be added in here
     if (empty($this->hasSubscription) || !$plan_params['make_primary'] || $plan_params['update_existing']) {
         if (!empty($existing_record) && ($existing_status == 'Trial' || $existing_status == 'Pending' || $plan_params['update_existing'] || $plan_params['make_primary'])) {
             // Update existing non-primary subscription
             if ($this->focusSubscription->id !== $existing_record) {
                 $this->focusSubscription = new Subscription();
                 $this->focusSubscription->load($existing_record);
             }
             $return = 'existing';
         } else {
             if (!empty($this->hasSubscription)) {
                 $existing_parent = $this->focusSubscription->getSubscriptionID($this->userid, $plan_params['standard_parent'], null);
             } else {
                 $existing_parent = false;
             }
             // Create a root new subscription
             if (empty($this->hasSubscription) && !$plan_params['make_primary'] && !empty($plan_params['standard_parent']) && empty($existing_parent)) {
                 $this->objSubscription = new Subscription();
                 $this->objSubscription->load(0);
                 if ($this->objSubscription->createNew($this->userid, 'none', 1, 1, $plan_params['standard_parent'])) {
                     $this->objSubscription->applyUsage($plan_params['standard_parent'], 'none', $silent, 0);
                 }
             } elseif (!$plan_params['make_primary'] && !empty($plan_params['standard_parent']) && $existing_parent) {
                 $this->objSubscription = new Subscription();
                 $this->objSubscription->load($existing_parent);
                 if ($this->objSubscription->isExpired()) {
                     $this->objSubscription->applyUsage($plan_params['standard_parent'], 'none', $silent, 0);
                 }
             }
             // Create new subscription
             $this->focusSubscription = new Subscription();
             $this->focusSubscription->load(0);
             $this->focusSubscription->createNew($this->userid, $processor, 1, $plan_params['make_primary'], $payment_plan->id);
             $this->hasSubscription = 1;
             if ($plan_params['make_primary']) {
                 $this->objSubscription = clone $this->focusSubscription;
             }
             $return = 'new';
         }
     }
     if (empty($this->objSubscription) && !empty($this->focusSubscription)) {
         $this->objSubscription = clone $this->focusSubscription;
     }
     $this->temporaryRFIX();
     return $return;
 }
コード例 #2
0
ファイル: admin.acctexp.php プロジェクト: Ibrahim1/aec
 public function index($subscriptionid, $userid = array())
 {
     $groups = $this->state->filter->status;
     if (is_array($groups) && count($groups) === 1) {
         if ($this->state->filter->status[0] == 'all') {
             $groups = array('active', 'excluded', 'expired', 'pending', 'cancelled', 'hold', 'closed');
         }
     }
     if (is_array($groups)) {
         foreach ($groups as $k => $v) {
             $groups[$k] = strtolower($v);
         }
     }
     if (array_search('notconfig', $this->state->filter->status)) {
         $set_group = 'notconfig';
     } else {
         $set_group = strtolower($this->state->filter->status[0]);
     }
     if (!empty($orderby)) {
         if ($set_group == 'notconfig') {
             $forder = array('name ASC', 'name DESC', 'lastname ASC', 'lastname DESC', 'username ASC', 'username DESC', 'signup_date ASC', 'signup_date DESC', 'lastpay_date ASC', 'lastpay_date DESC');
         } else {
             $forder = array('expiration ASC', 'expiration DESC', 'lastpay_date ASC', 'lastpay_date DESC', 'name ASC', 'name DESC', 'lastname ASC', 'lastname DESC', 'username ASC', 'username DESC', 'signup_date ASC', 'signup_date DESC', 'lastpay_date ASC', 'lastpay_date DESC', 'plan_name ASC', 'plan_name DESC', 'status ASC', 'status DESC', 'type ASC', 'type DESC');
         }
         if (!in_array($orderby, $forder)) {
             $this->state->sort = 'name ASC';
         }
     }
     // define displaying at html
     $action = array();
     switch ($set_group) {
         case 'active':
             $action[0] = 'active';
             $action[1] = JText::_('AEC_HEAD_ACTIVE_SUBS');
             break;
         case 'excluded':
             $action[0] = 'excluded';
             $action[1] = JText::_('AEC_HEAD_EXCLUDED_SUBS');
             break;
         case 'expired':
             $action[0] = 'expired';
             $action[1] = JText::_('AEC_HEAD_EXPIRED_SUBS');
             break;
         case 'pending':
             $action[0] = 'pending';
             $action[1] = JText::_('AEC_HEAD_PENDING_SUBS');
             break;
         case 'cancelled':
             $action[0] = 'cancelled';
             $action[1] = JText::_('AEC_HEAD_CANCELLED_SUBS');
             break;
         case 'hold':
             $action[0] = 'hold';
             $action[1] = JText::_('AEC_HEAD_HOLD_SUBS');
             break;
         case 'closed':
             $action[0] = 'closed';
             $action[1] = JText::_('AEC_HEAD_CLOSED_SUBS');
             break;
         case 'manual':
         case 'notconfig':
             $action[0] = 'manual';
             $action[1] = JText::_('AEC_HEAD_MANUAL_SUBS');
             break;
     }
     $where = array();
     $where_or = array();
     $notconfig = false;
     $planid = trim(aecGetParam('assign_planid', null));
     $users_selected = is_array($subscriptionid) && count($subscriptionid) || is_array($userid) && count($userid);
     if (!empty($planid) && $users_selected) {
         $plan = new SubscriptionPlan();
         $plan->load($planid);
         if (!empty($subscriptionid)) {
             foreach ($subscriptionid as $sid) {
                 $metaUser = new metaUser(false, $sid);
                 $metaUser->establishFocus($plan);
                 $metaUser->focusSubscription->applyUsage($planid, 'none', 1);
             }
         }
         if (!empty($userid)) {
             foreach ($userid as $uid) {
                 $metaUser = new metaUser($uid);
                 $metaUser->establishFocus($plan);
                 $metaUser->focusSubscription->applyUsage($planid, 'none', 1);
                 $subscriptionid[] = $metaUser->focusSubscription->id;
             }
         }
         // Also show active users now
         if (!in_array('active', $groups)) {
             $groups[] = 'active';
         }
     }
     $set_status = trim(aecGetParam('set_status', null));
     $add_or_set_expiration = trim(aecGetParam('add_or_set_expiration', null));
     $set_time = trim(aecGetParam('set_time', null));
     $set_time_unit = trim(aecGetParam('set_time_unit', null));
     if ((!empty($set_status) || !empty($add_or_set_expiration)) && is_array($subscriptionid) && count($subscriptionid) > 0) {
         foreach ($subscriptionid as $k) {
             $subscriptionHandler = new Subscription();
             if (!empty($k)) {
                 $subscriptionHandler->load($k);
             } else {
                 $subscriptionHandler->createNew($k, '', 1);
             }
             if (strcmp($set_status, 'now') === 0) {
                 $subscriptionHandler->expire();
                 if (!in_array('expired', $groups)) {
                     $groups[] = 'expired';
                 }
             } elseif (strcmp($set_status, 'exclude') === 0) {
                 $subscriptionHandler->setStatus('Excluded');
                 if (!in_array('excluded', $groups)) {
                     $groups[] = 'excluded';
                 }
             } elseif (strcmp($set_status, 'close') === 0) {
                 $subscriptionHandler->setStatus('Closed');
                 if (!in_array('closed', $groups)) {
                     $groups[] = 'closed';
                 }
             } elseif (strcmp($set_status, 'hold') === 0) {
                 $subscriptionHandler->setStatus('Hold');
                 if (!in_array('hold', $groups)) {
                     $groups[] = 'hold';
                 }
             } elseif (strcmp($set_status, 'include') === 0) {
                 $subscriptionHandler->setStatus('Active');
                 if (!in_array('active', $groups)) {
                     $groups[] = 'active';
                 }
             } elseif (strcmp($set_status, 'lifetime') === 0) {
                 if (!$subscriptionHandler->isLifetime()) {
                     $subscriptionHandler->expiration = '9999-12-31 00:00:00';
                     $subscriptionHandler->lifetime = 1;
                 }
                 $subscriptionHandler->setStatus('Active');
                 if (!in_array('active', $groups)) {
                     $groups[] = 'active';
                 }
             }
             if ($set_status !== 'lifetime' && !empty($add_or_set_expiration) && !empty($set_time) && !empty($set_time_unit)) {
                 if ($add_or_set_expiration == 'set') {
                     $subscriptionHandler->setExpiration($set_time_unit, $set_time, 0);
                     $subscriptionHandler->lifetime = 0;
                     $subscriptionHandler->storeload();
                     if (!in_array('active', $groups)) {
                         $groups[] = 'active';
                     }
                 } elseif ($add_or_set_expiration == 'add') {
                     if ($subscriptionHandler->lifetime) {
                         $subscriptionHandler->setExpiration($set_time_unit, $set_time, 0);
                     } else {
                         $subscriptionHandler->setExpiration($set_time_unit, $set_time, 1);
                     }
                     $subscriptionHandler->lifetime = 0;
                     $subscriptionHandler->storeload();
                     if (!in_array('active', $groups)) {
                         $groups[] = 'active';
                     }
                 }
             }
         }
     }
     if (is_array($groups)) {
         if (in_array('notconfig', $groups)) {
             $notconfig = true;
             $groups = array('notconfig');
         } else {
             if (in_array('excluded', $groups)) {
                 $where_or[] = "a.status = 'Excluded'";
             }
             if (in_array('expired', $groups)) {
                 $where_or[] = "a.status = 'Expired'";
             }
             if (in_array('active', $groups)) {
                 $where_or[] = "(a.status = 'Active' || a.status = 'Trial')";
             }
             if (in_array('pending', $groups)) {
                 $where_or[] = "a.status = 'Pending'";
             }
             if (in_array('cancelled', $groups)) {
                 $where_or[] = "a.status = 'Cancelled'";
             }
             if (in_array('hold', $groups)) {
                 $where_or[] = "a.status = 'Hold'";
             }
             if (in_array('closed', $groups)) {
                 $where_or[] = "a.status = 'Closed'";
             }
         }
     }
     if (isset($search) && $search != '') {
         if ($notconfig) {
             $where[] = "(username LIKE '%{$search}%' OR name LIKE '%{$search}%')";
         } else {
             $where[] = "(b.username LIKE '%{$search}%' OR b.name LIKE '%{$search}%')";
         }
     }
     $group_plans = ItemGroupHandler::getChildren($this->state->filter->group, 'item');
     if (!empty($this->state->filter->plan) || !empty($group_plans)) {
         $plan_selection = array();
         if (!empty($this->state->filter->plan)) {
             $plan_selection = $this->state->filter->plan;
         }
         if (!empty($group_plans)) {
             $plan_selection = array_merge($plan_selection, $group_plans);
         }
         if (empty($plan_selection[0])) {
             unset($plan_selection[0]);
         }
         $plan_selection = array_unique($plan_selection);
         if (!$notconfig && !empty($plan_selection)) {
             $where[] = "a.plan IN (" . implode(',', $plan_selection) . ")";
         }
     }
     // get the total number of records
     if ($notconfig) {
         $where[] = 'b.status is null';
         $query = 'SELECT count(*)' . ' FROM #__users AS a' . ' LEFT JOIN #__acctexp_subscr AS b ON a.id = b.userid' . (count($where) ? ' WHERE ' . implode(' AND ', $where) : '');
     } else {
         $query = 'SELECT count(*)' . ' FROM #__acctexp_subscr AS a' . ' INNER JOIN #__users AS b ON a.userid = b.id';
         if (count($where_or)) {
             $where[] = count($where_or) ? '(' . implode(' OR ', $where_or) . ')' : '';
         }
         $query .= count($where) ? ' WHERE ' . implode(' AND ', $where) : '';
     }
     $this->db->setQuery($query);
     $nav = $this->getPagination($this->db->loadResult());
     $orderby = $this->state->sort;
     // get the subset (based on limits) of required records
     if ($notconfig) {
         $forder = array('name ASC', 'name DESC', 'lastname ASC', 'lastname DESC', 'username ASC', 'username DESC', 'signup_date ASC', 'signup_date DESC');
         if (!in_array($this->state->sort, $forder)) {
             $orderby = 'name ASC';
         }
         if (strpos($orderby, 'lastname') !== false) {
             $orderby = str_replace('lastname', 'SUBSTRING_INDEX(name, \' \', -1)', $orderby);
         }
         $query = 'SELECT a.id, a.name, a.username, a.registerDate as signup_date' . ' FROM #__users AS a' . ' LEFT JOIN #__acctexp_subscr AS b ON a.id = b.userid' . (count($where) ? ' WHERE ' . implode(' AND ', $where) : '') . ' ORDER BY ' . str_replace('signup_date', 'registerDate', $orderby) . ' LIMIT ' . $nav->limitstart . ',' . $nav->limit;
         if (strpos($orderby, 'SUBSTRING_INDEX') !== false) {
             $orderby = str_replace('SUBSTRING_INDEX(name, \' \', -1)', 'lastname', $orderby);
         }
     } else {
         if (strpos($orderby, 'lastname') !== false) {
             $orderby = str_replace('lastname', 'SUBSTRING_INDEX(b.name, \' \', -1)', $orderby);
         }
         $query = 'SELECT a.*, b.name, b.username, b.email, c.name AS plan_name' . ' FROM #__acctexp_subscr AS a' . ' INNER JOIN #__users AS b ON a.userid = b.id' . ' LEFT JOIN #__acctexp_plans AS c ON a.plan = c.id' . (count($where) ? ' WHERE ' . implode(' AND ', $where) : '') . ' ORDER BY ' . $orderby . ' LIMIT ' . $nav->limitstart . ',' . $nav->limit;
         if (strpos($orderby, 'SUBSTRING_INDEX') !== false) {
             $orderby = str_replace('SUBSTRING_INDEX(b.name, \' \', -1)', 'lastname', $orderby);
         }
     }
     $this->state->sort = $orderby;
     $this->db->setQuery('SET SQL_BIG_SELECTS=1');
     $this->db->query();
     $this->db->setQuery($query);
     $rows = $this->db->loadObjectList();
     if ($this->db->getErrorNum()) {
         echo $this->db->stderr();
         return false;
     }
     $this->db->setQuery('SET SQL_BIG_SELECTS=0');
     $this->db->query();
     $processors = PaymentProcessorHandler::getObjectList(PaymentProcessorHandler::getProcessorList());
     $procs = array('free' => 'Free', 'none' => 'None');
     foreach ($processors as $processor) {
         $procs[$processor->processor_name] = $processor->processor->info['longname'];
     }
     foreach ($rows as $k => $row) {
         if (!isset($rows[$k]->type)) {
             continue;
         }
         $rows[$k]->type = $procs[$rows[$k]->type];
     }
     // Get list of plans for filter
     $query = 'SELECT `id`, `name`' . ' FROM #__acctexp_plans' . ' ORDER BY `ordering`';
     $this->db->setQuery($query);
     $db_plans = $this->db->loadObjectList();
     $plans2[] = JHTML::_('select.option', '0', JText::_('BIND_USER'), 'id', 'name');
     if (is_array($db_plans)) {
         $plans2 = array_merge($plans2, $db_plans);
     }
     $lists['set_plan'] = JHTML::_('select.genericlist', $plans2, 'assign_planid', 'class="form-control inputbox" size="1"', 'id', 'name', 0);
     $lists['filter_plan'] = '<select id="plan-filter-select" name="plan[]" multiple="multiple" size="5">';
     foreach ($db_plans as $plan) {
         $lists['filter_plan'] .= '<option value="' . $plan->id . '"' . (in_array($plan->id, $this->state->filter->plan) ? ' selected="selected"' : '') . '>' . $plan->name . '</option>';
     }
     $lists['filter_plan'] .= '</select>';
     $grouplist = ItemGroupHandler::getTree();
     $lists['filter_group'] = '<select id="group-filter-select" name="group[]" multiple="multiple" size="5">';
     foreach ($grouplist as $glisti) {
         if (defined('JPATH_MANIFESTS')) {
             $lists['filter_group'] .= '<option value="' . $glisti[0] . '"' . (in_array($glisti[0], $this->state->filter->group) ? ' selected="selected"' : '') . '>' . str_replace('&nbsp;', ' ', $glisti[1]) . '</option>';
         } else {
             $lists['filter_group'] .= '<option value="' . $glisti[0] . '"' . (in_array($glisti[0], $this->state->filter->group) ? ' selected="selected"' : '') . '>' . $glisti[1] . '</option>';
         }
     }
     $lists['filter_group'] .= '</select>';
     $status = array('excluded' => JText::_('AEC_SEL_EXCLUDED'), 'pending' => JText::_('AEC_SEL_PENDING'), 'active' => JText::_('AEC_SEL_ACTIVE'), 'expired' => JText::_('AEC_SEL_EXPIRED'), 'closed' => JText::_('AEC_SEL_CLOSED'), 'cancelled' => JText::_('AEC_SEL_CANCELLED'), 'hold' => JText::_('AEC_SEL_HOLD'), 'notconfig' => JText::_('AEC_SEL_NOT_CONFIGURED'));
     $lists['filter_status'] = '<select id="status-group-select" name="status[]" multiple="multiple" size="5">';
     foreach ($status as $id => $txt) {
         $lists['filter_status'] .= '<option value="' . $id . '"' . (in_array($id, $groups) ? ' selected="selected"' : '') . '>' . $txt . '</option>';
     }
     $lists['filter_status'] .= '</select>';
     $group_selection = array();
     $group_selection[] = JHTML::_('select.option', '', JText::_('Set Status'));
     $group_selection[] = JHTML::_('select.option', 'now', JText::_('EXPIRE_NOW'));
     $group_selection[] = JHTML::_('select.option', 'exclude', JText::_('EXPIRE_EXCLUDE'));
     $group_selection[] = JHTML::_('select.option', 'lifetime', JText::_('AEC_CMN_LIFETIME'));
     $group_selection[] = JHTML::_('select.option', 'include', JText::_('EXPIRE_INCLUDE'));
     $group_selection[] = JHTML::_('select.option', 'close', JText::_('EXPIRE_CLOSE'));
     $group_selection[] = JHTML::_('select.option', 'hold', JText::_('EXPIRE_HOLD'));
     $lists['set_status'] = JHTML::_('select.genericlist', $group_selection, 'set_status', 'class="form-control inputbox" size="1"', 'value', 'text', "");
     $group_selection = array();
     $group_selection[] = JHTML::_('select.option', 'add', JText::_('Add'));
     $group_selection[] = JHTML::_('select.option', 'set', JText::_('Set'));
     $lists['add_or_set_expiration'] = JHTML::_('select.genericlist', $group_selection, 'add_or_set_expiration', 'class="form-control inputbox" size="1"', 'value', 'text', "");
     // make the select list for first trial period units
     $perunit[] = JHTML::_('select.option', 'D', JText::_('PAYPLAN_PERUNIT1'));
     $perunit[] = JHTML::_('select.option', 'W', JText::_('PAYPLAN_PERUNIT2'));
     $perunit[] = JHTML::_('select.option', 'M', JText::_('PAYPLAN_PERUNIT3'));
     $perunit[] = JHTML::_('select.option', 'Y', JText::_('PAYPLAN_PERUNIT4'));
     $lists['set_time_unit'] = JHTML::_('select.genericlist', $perunit, 'set_time_unit', 'class="form-control inputbox" size="1"', 'value', 'text');
     HTML_AcctExp::listSubscriptions($rows, $nav, $this->state, $lists, $subscriptionid, $action);
 }