/**
  * @param $post
  * @return SubscriptionPlan
  * @throws Exception
  */
 public function getSubscriptionPlan($post)
 {
     $customData = $this->getCustomData($post);
     $serviceProvider = $customData['service_provider'];
     $serviceName = $customData['service_name'];
     $subscriptionPlan = new SubscriptionPlan();
     $subscriptionPlan->loadByServiceName($serviceProvider, $serviceName);
     return $subscriptionPlan;
 }
Example #2
0
 /**
  * This is not the best example to follow
  * Please see the category plugin for a better example
  */
 public function post()
 {
     require_once JPATH_SITE . '/components/com_acctexp/acctexp.class.php';
     $db =& JFactory::getDBO();
     $app = JFactory::getApplication();
     $userid = JRequest::getInt('user_id', 0);
     $planid = JRequest::getInt('plan_id', 0);
     //$new_expiry = JRequest::getString('date',0);
     $obj = new stdClass();
     //validate plan
     $plans = SubscriptionPlanHandler::getPlanList();
     $muser = metaUserDB::getIDbyUserid($userid);
     //$pplan = metaUserDB::getPreviousPlan($muser);
     //$uplan = metaUserDB::getUsedPlans($muser);
     //print_r($new_expiry);die;
     if (!$userid) {
         $obj->success = 0;
         $obj->code = 21;
         $obj->message = "invalid user id";
     } elseif (!$plans[array_search($planid, $plans)]) {
         $obj->success = 0;
         $obj->code = 22;
         $obj->message = "invalid plan id";
     } else {
         $plan = new SubscriptionPlan($db);
         $plan->load($planid);
         //print_r($plan->params['full_period']);die;
         //check user is metauser
         /*if ( is_a( $user, 'metaUser' ) ) {
         			$metaUser = $user;
         			} elseif( is_a( $user, 'Subscription' ) ) {
         			$metaUser = new metaUser( $user->userid );
         
         			$metaUser->focusSubscription = $user;
         			}*/
         $metaUser = new metaUser($userid);
         $renew = $metaUser->is_renewing();
         //$metaUser->focusSubscription->lifetime;
         $metaUser->focusSubscription->plan = $planid;
         $metaUser->focusSubscription->status = 'Active';
         $metaUser->temporaryRFIX();
         //$metaUser->focusSubscription->lifetime = 1;
         //set expiration
         $now = (int) gmdate('U');
         //$current = strtotime($new_expiry);
         //$metaUser->focusSubscription->expiration = $new_expiry;
         //$metaUser->objSubscription->expiration = $new_expiry;
         $reply = $metaUser->focusSubscription->storeload();
         if ($reply && $planid) {
             $history = new logHistory($db);
             $obj->success = 1;
             $obj->message = "User added to plan";
         }
     }
     $this->plugin->setResponse($obj);
 }
Example #3
0
 /**
  * This is not the best example to follow
  * Please see the category plugin for a better example
  */
 public function post()
 {
     require_once JPATH_SITE . '/components/com_acctexp/acctexp.class.php';
     $db =& JFactory::getDBO();
     $app = JFactory::getApplication();
     $userid = JRequest::getInt('user_id', 0);
     $planid = JRequest::getInt('plan_id', 0);
     $new_expiry = JRequest::getString('date', 0);
     //convert date in format
     $new_expiry = date("Y-m-d h:i:s", strtotime($new_expiry));
     $obj = new stdClass();
     //validate plan
     $plans = SubscriptionPlanHandler::getPlanList();
     $muser = metaUserDB::getIDbyUserid($userid);
     $plnuser = SubscriptionPlanHandler::getPlanUserlist($planid);
     if (!$userid) {
         $obj->success = 0;
         $obj->code = 21;
         $obj->message = "invalid user id";
     } elseif (!$plans[array_search($planid, $plans)]) {
         $obj->success = 0;
         $obj->code = 22;
         $obj->message = "invalid plan id";
     } elseif ($userid == $plnuser[array_search($userid, $plnuser)]) {
         $plan = new SubscriptionPlan($db);
         $plan->load($planid);
         $metaUser = new metaUser($userid);
         $renew = $metaUser->is_renewing();
         $lifetime = $metaUser->focusSubscription->lifetime;
         $metaUser->focusSubscription->plan = $planid;
         $metaUser->focusSubscription->status = 'Active';
         $metaUser->temporaryRFIX();
         $metaUser->focusSubscription->lifetime = 0;
         //set expiration
         //$now = (int) gmdate('U');
         $metaUser->focusSubscription->expiration = $new_expiry;
         //$metaUser->objSubscription->expiration = $new_expiry;
         $reply = $metaUser->focusSubscription->storeload();
         if ($reply && $planid) {
             $obj->success = 1;
             $obj->message = "Expiry updated";
         }
     } else {
         $obj->success = 0;
         $obj->code = 31;
         $obj->message = "Plan not assigned to user";
     }
     $this->plugin->setResponse($obj);
 }
Example #4
0
 public function Action()
 {
     if (empty($_POST['delete'])) {
         return '<p>Please select a processor to remove.</p>';
     }
     if (empty($_POST['replace'])) {
         return '<p>Please select a processor to replace the removed processor with.</p>';
     }
     $db = JFactory::getDBO();
     $replacepp = new PaymentProcessor();
     $replacepp->loadName($_POST['replace']);
     $deletepp = new PaymentProcessor();
     $deletepp->loadName($_POST['delete']);
     $query = 'UPDATE #__acctexp_invoices' . ' SET `method` = \'' . $replacepp->processor_name . '\'' . ' WHERE `method` = \'' . $deletepp->processor_name . '\'';
     $db->setQuery($query);
     $db->query();
     $query = 'UPDATE #__acctexp_subscr' . ' SET `type` = \'' . $replacepp->processor_name . '\'' . ' WHERE `type` = \'' . $deletepp->processor_name . '\'';
     $db->setQuery($query);
     $db->query();
     $query = 'UPDATE #__acctexp_log_history' . ' SET `proc_id` = \'' . $replacepp->id . '\', `proc_name` = \'' . $replacepp->processor_name . '\'' . ' WHERE `proc_name` = \'' . $replacepp->processor_name . '\'';
     $db->setQuery($query);
     $db->query();
     $planlist = SubscriptionPlanHandler::getPlanList();
     foreach ($planlist as $planid) {
         $plan = new SubscriptionPlan();
         $plan->load($planid);
         if (empty($plan->params['processors'])) {
             continue;
         }
         if (in_array($deletepp->id, $plan->params['processors'])) {
             unset($plan->params['processors'][array_search($deletepp->id, $plan->params['processors'])]);
             if (!in_array($replacepp->id, $plan->params['processors'])) {
                 $plan->params['processors'][] = $replacepp->id;
             }
             $plan->check();
             $plan->store();
         }
     }
     $query = 'DELETE FROM #__acctexp_config_processors' . ' WHERE `id` = \'' . $deletepp->id . '\'';
     $db->setQuery($query);
     $db->query();
     return "<p>Alright, replaced and deleted!</p>";
 }
Example #5
0
    $meta->check();
    $meta->store();
}
$eucaInstalldb->dropColifExists('processors', 'plans');
// Fixing stupid mistake - creating all processors at once for no good reason
$db->setQuery("SELECT count(*) FROM  #__acctexp_config_processors");
$procnum = $db->loadResult();
$db->setQuery("SELECT count(*) FROM  #__acctexp_plans");
$plannum = $db->loadResult();
if ($procnum > 20 && $plannum > 0) {
    $allprocs = array();
    $query = 'SELECT id FROM #__acctexp_plans';
    $db->setQuery($query);
    $plans = xJ::getDBArray($db);
    foreach ($plans as $planid) {
        $plan = new SubscriptionPlan();
        $plan->load($planid);
        if (!empty($plan->params['processors'])) {
            foreach ($plan->params['processors'] as $pi) {
                if (!in_array($pi, $allprocs)) {
                    $allprocs[] = $pi;
                }
            }
        }
    }
    $query = 'SELECT id FROM #__acctexp_config_processors';
    $db->setQuery($query);
    $procs = xJ::getDBArray($db);
    foreach ($procs as $procid) {
        // Check whether the processor has a plan it is applied to
        if (!in_array($procid, $allprocs)) {
 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 #7
0
 public function getObjUsage()
 {
     $usage = null;
     if (!empty($this->usage)) {
         $usage = $this->usage;
     }
     if (empty($usage)) {
         return null;
     }
     $u = explode('.', $usage);
     switch (strtolower($u[0])) {
         case 'c':
         case 'cart':
             if (isset($this->params['cart'])) {
                 $objUsage = $this->params['cart'];
             } else {
                 $objUsage = new aecCart();
                 $objUsage->load($u[1]);
             }
             break;
         case 'p':
         case 'plan':
         default:
             if (!isset($u[1])) {
                 $u[1] = $u[0];
             }
             $objUsage = new SubscriptionPlan();
             $objUsage->load($u[1]);
             break;
     }
     return $objUsage;
 }
Example #8
0
 public function relayAction($request)
 {
     if ($request->action == 'action') {
         // Do NOT act on regular action call
         return null;
     }
     if ($request->area == 'afteraction') {
         // But on after action
         $request->area = '';
         // Or maybe this is a first plan?
         if (!empty($this->settings['plan_apply_first'])) {
             if (!empty($this->settings['first_plan_not_membership'])) {
                 $used_plans = $request->metaUser->meta->getUsedPlans();
                 if (empty($used_plans)) {
                     $request->area = '_first';
                 } else {
                     if (!in_array($request->plan->id, $used_plans)) {
                         $request->area = '_first';
                     }
                 }
             } else {
                 if (empty($request->metaUser->objSubscription->previous_plan)) {
                     $request->area = '_first';
                 }
             }
         }
     }
     if (!isset($this->settings['plan_apply' . $request->area])) {
         return null;
     }
     if (empty($this->settings['plan_apply' . $request->area])) {
         return null;
     }
     if ($request->action == 'action') {
         if (!empty($this->settings['plan_apply_first'])) {
             if (empty($request->metaUser->objSubscription->previous_plan)) {
                 $request->area = '_first';
             }
         }
     }
     $expiration = $request->metaUser->focusSubscription->expiration;
     $db = JFactory::getDBO();
     $new_plan = new SubscriptionPlan();
     $new_plan->load($this->settings['plan_apply' . $request->area]);
     $request->metaUser->establishFocus($new_plan, 'none', false);
     $new_plan->applyPlan($request->metaUser);
     if ($request->area == '_first' && !empty($this->settings['first_plan_copy_expiration']) || empty($request->area) && !empty($this->settings['plan_copy_expiration'])) {
         $request->metaUser->focusSubscription->expiration = $expiration;
         $request->metaUser->focusSubscription->storeload();
     }
     return true;
 }
 public function getOptions()
 {
     $gsSubscriptions = Subscription::getActiveSubscriptions();
     $sessionManager = new SessionManager();
     $userInfo = $sessionManager->getUserInfo($_SESSION['user_id']);
     $subscriptionsTempStatus = Subscription::getSubscriptionTemporaryStatus();
     $result = [];
     if (count($gsSubscriptions)) {
         $planId = $gsSubscriptions[0]['plan_id'];
         $subscriptionPlan = new SubscriptionPlan();
         $subscriptionPlan->load($planId);
         $subscriptionPlanOptions = $subscriptionPlan->getSubscriptionPlanOptions();
         $result['subscription_status'] = Subscription::STATUS_ACTIVE;
         $result['options'] = $subscriptionPlanOptions;
     } elseif ($subscriptionsTempStatus == Subscription::STATUS_PROCESSING) {
         $result['subscription_status'] = Subscription::STATUS_PROCESSING;
         $result['options'] = [];
     } elseif ($subscriptionsTempStatus == Subscription::STATUS_UPDATING) {
         $gsSubscriptions = Subscription::getGetScorecardSubscriptions();
         if (isset($gsSubscriptions[0])) {
             $planId = $gsSubscriptions[0]['plan_id'];
             $subscriptionPlan = new SubscriptionPlan();
             $subscriptionPlan->load($planId);
             $subscriptionPlanOptions = $subscriptionPlan->getSubscriptionPlanOptions();
             $result['subscription_status'] = Subscription::STATUS_UPDATING;
             $result['options'] = $subscriptionPlanOptions;
         } else {
             $result['subscription_status'] = Subscription::STATUS_NOT_EXIST;
             $result['options'] = [];
         }
     } elseif ($userInfo['dummy_data_live']) {
         $result['subscription_status'] = Subscription::STATUS_TRIAL;
         $result['options'] = [];
     } else {
         $result['subscription_status'] = Subscription::STATUS_NOT_EXIST;
         $result['options'] = [];
     }
     return $result;
 }
Example #10
0
     $invoice = aecGetParam('invoice', 0, true, array('word', 'string', 'clear_nonalnum'));
     $processor = aecGetParam('processor', 0, true, array('word', 'string', 'clear_nonalnum'));
     $userid = aecGetParam('userid', 0, true, array('word', 'int'));
     internalCheckout($option, $invoice, $processor, $userid);
     break;
 case 'thanks':
     $renew = aecGetParam('renew', 0, true, array('word', 'int'));
     $free = aecGetParam('free', 0, true, array('word', 'int'));
     $usage = aecGetParam('usage', 0, true, array('word', 'string', 'clear_nonalnum'));
     if (empty($usage)) {
         $usage = aecGetParam('u', 0, true, array('word', 'string', 'clear_nonalnum'));
     }
     $iFactory = new InvoiceFactory();
     if (!empty($usage)) {
         $db = JFactory::getDBO();
         $plan = new SubscriptionPlan();
         $plan->load($usage);
         getView('thanks', array('renew' => $renew, 'free' => $free, 'plan' => $plan));
     } else {
         getView('thanks', array('renew' => $renew, 'free' => $free));
     }
     break;
 case 'subscriptiondetails':
     $sub = aecGetParam('sub', 'overview', true, array('word', 'string'));
     $page = aecGetParam('page', '0', true, array('word', 'int'));
     getView('subscriptiondetails', array('sub' => $sub, 'page' => $page));
     break;
 case 'renewsubscription':
     JRequest::checkToken() or die('Invalid Token');
     $userid = aecGetParam('userid', 0, true, array('word', 'int'));
     $intro = aecGetParam('intro', 0, true, array('word', 'int'));
Example #11
0
 public function save()
 {
     unset($_POST['option']);
     unset($_POST['task']);
     $id = $_POST['id'] ? $_POST['id'] : 0;
     $mi = new microIntegration();
     $mi->load($id);
     if (!empty($_POST['class_name'])) {
         $load = $mi->callDry($_POST['class_name']);
     } else {
         $load = $mi->callIntegration(1);
     }
     if ($load) {
         $save = array('attach_to_plans' => array(), 'attached_to_plans' => array(), 'attach_to_groups' => array(), 'attached_to_groups' => array());
         foreach ($save as $pid => $v) {
             if (isset($_POST[$pid])) {
                 $save[$pid] = $_POST[$pid];
                 unset($_POST[$pid]);
             } else {
                 $save[$pid] = array();
             }
         }
         $mi->savePostParams($_POST);
         $mi->storeload();
         $all_groups = array_unique(array_merge($save['attach_to_groups'], $save['attached_to_groups']));
         if (!empty($all_groups)) {
             foreach ($all_groups as $groupid) {
                 $group = new ItemGroup();
                 $group->load($groupid);
                 if (in_array($groupid, $save['attach_to_groups']) && !in_array($groupid, $save['attached_to_groups'])) {
                     $group->params['micro_integrations'][] = $mi->id;
                     $group->storeload();
                 } elseif (!in_array($groupid, $save['attach_to_groups']) && in_array($groupid, $save['attached_to_groups'])) {
                     unset($group->params['micro_integrations'][array_search($mi->id, $group->params['micro_integrations'])]);
                     $group->storeload();
                 }
             }
         }
         $all_plans = array_unique(array_merge($save['attach_to_plans'], $save['attached_to_plans']));
         if (!empty($all_plans)) {
             foreach ($all_plans as $planid) {
                 $plan = new SubscriptionPlan();
                 $plan->load($planid);
                 if (in_array($planid, $save['attach_to_plans']) && !in_array($planid, $save['attached_to_plans'])) {
                     $plan->micro_integrations[] = $mi->id;
                     $plan->storeload();
                 } elseif (!in_array($planid, $save['attach_to_plans']) && in_array($planid, $save['attached_to_plans'])) {
                     unset($plan->micro_integrations[array_search($mi->id, $plan->micro_integrations)]);
                     $plan->storeload();
                 }
             }
         }
     } else {
         $short = 'microIntegration storing failure';
         if (!empty($_POST['class_name'])) {
             $event = 'When trying to store microIntegration: ' . $_POST['class_name'] . ', callIntegration failed';
         } else {
             $event = 'When trying to store microIntegration: ' . $mi->id . ', callIntegration failed';
         }
         $tags = 'microintegration,loading,error';
         $params = array();
         $eventlog = new eventLog();
         $eventlog->issue($short, $tags, $event, 128, $params);
     }
     $mi->reorder();
     $this->setMessage(JText::_('AEC_MSG_SUCESSFULLY_SAVED'));
 }
 public function sendEmailRegistered($renew, $adminonly = false, $invoice = null)
 {
     global $aecConfig;
     $app = JFactory::getApplication();
     $free = strcmp(strtolower($this->type), 'none') == 0 || strcmp(strtolower($this->type), 'free') == 0;
     $urow = new cmsUser();
     $urow->load($this->userid);
     $plan = new SubscriptionPlan();
     $plan->load($this->plan);
     $name = $urow->name;
     $email = $urow->email;
     $username = $urow->username;
     $pwd = $urow->password;
     $activationcode = $urow->activation;
     $message = sprintf(JText::_('ACCTEXP_MAILPARTICLE_GREETING'), $name);
     // Assemble E-Mail Subject & Message
     if ($renew) {
         $subject = sprintf(JText::_('ACCTEXP_SEND_MSG_RENEW'), $name, $app->getCfg('sitename'));
         $message .= sprintf(JText::_('ACCTEXP_MAILPARTICLE_THANKSREN'), $app->getCfg('sitename'));
         if ($plan->email_desc) {
             $message .= "\n\n" . $plan->email_desc . "\n\n";
         } else {
             $message .= " ";
         }
         if ($free) {
             $message .= sprintf(JText::_('ACCTEXP_MAILPARTICLE_LOGIN'), JURI::root());
         } else {
             $message .= JText::_('ACCTEXP_MAILPARTICLE_PAYREC') . " " . sprintf(JText::_('ACCTEXP_MAILPARTICLE_LOGIN'), JURI::root());
         }
     } else {
         $subject = sprintf(JText::_('ACCTEXP_SEND_MSG'), $name, $app->getCfg('sitename'));
         $message .= sprintf(JText::_('ACCTEXP_MAILPARTICLE_THANKSREG'), $app->getCfg('sitename'));
         if ($plan->email_desc) {
             $message .= "\n\n" . $plan->email_desc . "\n\n";
         } else {
             $message .= " ";
         }
         if ($free) {
             $message .= sprintf(JText::_('ACCTEXP_MAILPARTICLE_LOGIN'), JURI::root());
         } else {
             $message .= JText::_('ACCTEXP_MAILPARTICLE_PAYREC') . " " . sprintf(JText::_('ACCTEXP_MAILPARTICLE_LOGIN'), JURI::root());
         }
     }
     $message .= JText::_('ACCTEXP_MAILPARTICLE_FOOTER');
     $subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8');
     $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
     // Send email to user
     if ($app->getCfg('mailfrom') != '' && $app->getCfg('fromname') != '') {
         $adminName2 = $app->getCfg('fromname');
         $adminEmail2 = $app->getCfg('mailfrom');
     } else {
         $rows = xJACLhandler::getSuperAdmins();
         $row2 = $rows[0];
         $adminName2 = $row2->name;
         $adminEmail2 = $row2->email;
     }
     if (!$adminonly) {
         xJ::sendMail($adminEmail2, $adminEmail2, $email, $subject, $message);
     }
     $aecUser = array();
     if (is_object($invoice)) {
         if (!empty($invoice->params['creator_ip'])) {
             $aecUser['ip'] = $invoice->params['creator_ip'];
             // user Hostname (if not deactivated)
             if ($aecConfig->cfg['gethostbyaddr']) {
                 $aecUser['isp'] = gethostbyaddr($invoice->params['creator_ip']);
             } else {
                 $aecUser['isp'] = 'deactivated';
             }
         }
     }
     if (empty($aecUser)) {
         $aecUser = AECToolbox::aecIP();
     }
     // Send notification to all administrators
     if ($renew) {
         $subject2 = sprintf(JText::_('ACCTEXP_SEND_MSG_RENEW'), $name, $app->getCfg('sitename'));
         $message2 = sprintf(JText::_('ACCTEXP_ASEND_MSG_RENEW'), $adminName2, $app->getCfg('sitename'), $name, $email, $username, $plan->id, $plan->name, $aecUser['ip'], $aecUser['isp']);
     } else {
         $subject2 = sprintf(JText::_('ACCTEXP_SEND_MSG'), $name, $app->getCfg('sitename'));
         $message2 = sprintf(JText::_('ACCTEXP_ASEND_MSG'), $adminName2, $app->getCfg('sitename'), $name, $email, $username, $plan->id, $plan->name, $aecUser['ip'], $aecUser['isp']);
     }
     $subject2 = html_entity_decode($subject2, ENT_QUOTES, 'UTF-8');
     $message2 = html_entity_decode($message2, ENT_QUOTES, 'UTF-8');
     $admins = AECToolbox::getAdminEmailList();
     foreach ($admins as $adminemail) {
         if (!empty($adminemail)) {
             xJ::sendMail($adminEmail2, $adminEmail2, $adminemail, $subject2, $message2);
         }
     }
 }
Example #13
0
 public function getCheckout($metaUser, $counter = 0, $InvoiceFactory = null)
 {
     $c = array();
     $totalcost = 0;
     if (empty($this->content)) {
         return array();
     }
     $return = array();
     foreach ($this->content as $cid => $content) {
         // Cache items
         if (!isset($c[$content['type']][$content['id']])) {
             switch ($content['type']) {
                 case 'plan':
                     $obj = new SubscriptionPlan();
                     $obj->load($content['id']);
                     $o = array();
                     $o['obj'] = $obj;
                     $o['name'] = $obj->getProperty('name');
                     $o['desc'] = $obj->getProperty('desc');
                     $terms = $obj->getTermsForUser(false, $metaUser);
                     if ($counter) {
                         $terms->incrementPointer($counter);
                     }
                     $o['terms'] = $terms;
                     $o['cost'] = $terms->nextterm->renderCost();
                     $c[$content['type']][$content['id']] = $o;
                     break;
             }
         }
         $entry = array();
         $entry['obj'] = $c[$content['type']][$content['id']]['obj'];
         $entry['fullamount'] = $c[$content['type']][$content['id']]['cost'];
         $entry['name'] = $c[$content['type']][$content['id']]['name'];
         $entry['desc'] = $c[$content['type']][$content['id']]['desc'];
         $entry['terms'] = $c[$content['type']][$content['id']]['terms'];
         $item = array('item' => array('obj' => $entry['obj']), 'terms' => $entry['terms']);
         if (!empty($content['coupons'])) {
             $cpsh = new couponsHandler($metaUser, false, $content['coupons']);
             $item = $cpsh->applyAllToItems(0, $item);
             $entry['terms'] = $item['terms'];
         }
         $entry['cost'] = $entry['terms']->nextterm->renderTotal();
         if ($entry['cost'] > 0) {
             $total = $content['quantity'] * $entry['cost'];
             $entry['cost_total'] = AECToolbox::correctAmount($total);
         } else {
             $entry['cost_total'] = AECToolbox::correctAmount('0.00');
         }
         if ($entry['cost_total'] == '0.00') {
             $entry['free'] = true;
         } else {
             $entry['free'] = false;
         }
         $entry['cost'] = AECToolbox::correctAmount($entry['cost']);
         $entry['quantity'] = $content['quantity'];
         $totalcost += $entry['cost_total'];
         $return[$cid] = $entry;
     }
     if (!empty($this->params['overall_coupons'])) {
         $cpsh = new couponsHandler($metaUser, $InvoiceFactory, $this->params['overall_coupons']);
         $totalcost_ncp = $totalcost;
         $totalcost = $cpsh->applyToAmount($totalcost);
     } else {
         $totalcost_ncp = $totalcost;
     }
     // Append total cost
     $return[] = array('name' => '', 'count' => '', 'cost' => AECToolbox::correctAmount($totalcost_ncp), 'cost_total' => AECToolbox::correctAmount($totalcost), 'is_total' => true, 'obj' => false);
     return $return;
 }
Example #14
0
 static function VerifyMetaUser($metaUser)
 {
     global $aecConfig;
     if (!$aecConfig->cfg['require_subscription']) {
         return true;
     }
     if ($metaUser->hasSubscription) {
         $result = $metaUser->objSubscription->verify($metaUser);
         if ($result == 'expired' || $result == 'pending') {
             $metaUser->setTempAuth();
         }
         return $result;
     }
     if (!empty($aecConfig->cfg['entry_plan'])) {
         $payment_plan = new SubscriptionPlan();
         $payment_plan->load($aecConfig->cfg['entry_plan']);
         $metaUser->establishFocus($payment_plan, 'free', false);
         $metaUser->focusSubscription->applyUsage($payment_plan->id, 'free', 1, 0);
         return AECToolbox::VerifyUser($metaUser->cmsUser->username);
     } else {
         $invoices = aecInvoiceHelper::InvoiceCountbyUserID($metaUser->userid);
         $metaUser->setTempAuth();
         if ($invoices) {
             $invoice = aecInvoiceHelper::lastUnclearedInvoiceIDbyUserID($metaUser->userid);
             if ($invoice) {
                 return 'open_invoice';
             }
         }
         return 'subscribe';
     }
 }
Example #15
0
 public function import($options = array())
 {
     $db = JFactory::getDBO();
     $stdfields = array('id', 'name', 'username', 'email', 'password', 'plan_id', 'invoice_number', 'expiration');
     foreach ($this->rows as $k => $row) {
         // Skip first line, if desired
         if ($k === 0 && !empty($options['skip_first'])) {
             continue;
         }
         $userid = null;
         $user = $this->convertRow($row);
         if (empty($user['username']) && empty($user['id'])) {
             continue;
         }
         if (!empty($user['id'])) {
             $query = 'SELECT `id`' . ' FROM #__users' . ' WHERE `id` = \'' . $user['id'] . '\'';
             $db->setQuery($query);
             $userid = $db->loadResult();
         }
         if (empty($userid)) {
             $query = 'SELECT `id`' . ' FROM #__users' . ' WHERE `username` = \'' . $user['username'] . '\'';
             $db->setQuery($query);
             $userid = $db->loadResult();
         }
         if (!$userid) {
             // We cannot find any user by this id or name, create one
             if (!empty($user['email']) && !empty($user['username'])) {
                 if (empty($user['password'])) {
                     $user['password'] = AECToolbox::randomstring(8, true);
                 }
                 if (empty($user['name'])) {
                     $user['name'] = $user['username'];
                 }
                 if (!empty($user['password'])) {
                     $user['password2'] = $user['password'];
                 }
                 $fields = $user;
                 $excludefields = array('plan_id', 'invoice_number', 'expiration');
                 foreach ($excludefields as $field) {
                     if (isset($fields[$field])) {
                         unset($fields[$field]);
                     }
                 }
                 $userid = $this->createUser($fields);
             } else {
                 continue;
             }
         }
         if (empty($userid)) {
             $this->errors++;
         }
         $metaUser = new metaUser($userid);
         $custom_params = array();
         foreach ($user as $i => $v) {
             if (!in_array($i, $stdfields)) {
                 $custom_params[$i] = $v;
             }
         }
         if (!empty($custom_params)) {
             $metaUser->meta->addCustomParams($custom_params);
             $metaUser->meta->storeload();
         }
         if (!empty($user['plan_id'])) {
             $pid = $user['plan_id'];
         } else {
             $pid = $this->options['assign_plan'];
         }
         $subscr_action = false;
         if (!empty($pid)) {
             $plan = new SubscriptionPlan();
             $plan->load($pid);
             $metaUser->establishFocus($plan, 'none', true);
             $metaUser->focusSubscription->applyUsage($pid, 'none', 1);
             $subscr_action = true;
         }
         if (!empty($user['expiration']) && !empty($metaUser->focusSubscription->id)) {
             $metaUser->focusSubscription->expiration = date('Y-m-d H:i:s', strtotime($user['expiration']));
             if ($metaUser->focusSubscription->status == 'Trial') {
                 $metaUser->focusSubscription->status = 'Trial';
             } else {
                 $metaUser->focusSubscription->status = 'Active';
             }
             $metaUser->focusSubscription->lifetime = 0;
             $metaUser->focusSubscription->storeload();
             $subscr_action = true;
         }
         if (!empty($user['invoice_number']) && !empty($pid)) {
             // Create Invoice
             $invoice = new Invoice();
             $invoice->create($userid, $pid, 'none', $user['invoice_number']);
             if ($subscr_action) {
                 $invoice->subscr_id = $metaUser->focusSubscription->id;
             }
             $invoice->setTransactionDate();
         }
     }
 }
Example #16
0
    $eucaInstalldb->addColifNotExists('expiration', "datetime NULL default '0000-00-00 00:00:00'", 'subscr');
    // All Subscriptions are primary
    $query = 'UPDATE #__acctexp_subscr' . ' SET `primary` = \'1\'';
    $db->setQuery($query);
    $db->query();
    // copy expiration date
    $query = 'UPDATE #__acctexp_subscr as a' . ' INNER JOIN #__acctexp as b ON a.userid = b.userid' . ' SET a.expiration = b.expiration';
    $db->setQuery($query);
    $db->query();
    // Get plans
    $query = 'SELECT `id`' . ' FROM #__acctexp_plans';
    $db->setQuery($query);
    $pplans = xJ::getDBArray($db);
    // Assign new make_primary flag to all old plans
    foreach ($pplans as $planid) {
        $subscription_plan = new SubscriptionPlan();
        $subscription_plan->addParams(array('make_primary' => 1));
    }
    // delete old expiration table
    $eucaInstalldb->dropTableifExists('acctexp', false);
}
// fix for 0.12.4.15f mistake
$eucaInstalldb->addColifNotExists('primary', "int(1) NOT NULL default '0'", 'subscr');
$eucaInstalldb->addColifNotExists('subscr_id', "int(11) NULL", 'invoices');
$eucaInstalldb->addColifNotExists('conditions', "text NULL", 'invoices');
$eucaInstalldb->addColifNotExists('subscr_id', "int(11) NULL", 'invoices');
$eucaInstalldb->addColifNotExists('conditions', "text NULL", 'invoices');
$eucaInstalldb->addColifNotExists('invoice_number_format', "varchar(64)", 'invoices');
// update remository and docman MI tables for unlimited downloads if they exist
if (in_array($app->getCfg('dbprefix') . "acctexp_mi_remository", $tables)) {
    $eucaInstalldb->addColifNotExists('unlimited_downloads', "int(3) NULL", 'mi_remository');
Example #17
0
 public function readPlanMIrel()
 {
     $db = JFactory::getDBO();
     $r = array();
     $r['head'] = "Payment Plan - MicroIntegration relationships";
     $r['type'] = "table";
     $r['def'] = array("ID" => array('id'), "Published" => array('active', 'bool'), "Visible" => array('visible', 'bool'), "Name" => array('name', 'smartlimit'));
     $micursor = '';
     $mis = array();
     foreach ($this->milist as $miobj) {
         $mi = new microIntegration();
         $mi->load($miobj->id);
         if (!$mi->callIntegration()) {
             continue;
         }
         if ($miobj->class_name != $micursor) {
             if (!empty($mi->info)) {
                 $miname = $mi->info['name'];
             } else {
                 $miname = $miobj->class_name;
             }
             $r['def'][$miname] = array($miobj->class_name, 'list', 'mi');
             $micursor = $miobj->class_name;
         }
         $mis[$mi->id] = array($miobj->class_name, $mi->name);
     }
     $r['set'] = array();
     foreach ($this->planlist as $planid => $planobj) {
         $plan = new SubscriptionPlan();
         $plan->load($planobj->id);
         if (!empty($plan->micro_integrations)) {
             foreach ($plan->micro_integrations as $pmi) {
                 if (isset($mis[$pmi])) {
                     $plan->{$mis[$pmi][0]}[] = $pmi;
                 }
             }
         }
         $ps = array();
         foreach ($r['def'] as $nn => $def) {
             $ps = array_merge($ps, $this->conversionHelper($def, $plan));
         }
         $r['set'][] = $ps;
     }
     return $r;
 }
Example #18
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 #19
0
 /**
  * @param SubscriptionPlan $plan
  */
 static function getItemListItem($plan)
 {
     if (empty($plan->params['processor_selectmode'])) {
         $select_mode = '0';
     } else {
         $select_mode = $plan->params['processor_selectmode'];
     }
     $details = array('type' => 'item', 'id' => $plan->id, 'plan' => $plan, 'name' => $plan->getProperty('name'), 'desc' => $plan->getProperty('desc'), 'ordering' => $plan->ordering, 'lifetime' => $plan->params['lifetime'], 'select_mode' => $select_mode, 'meta' => array());
     if (!empty($plan->params['meta'])) {
         $details['meta'] = parameterHandler::decode($plan->params['meta']);
     }
     return $details;
 }
Example #20
0
 public function invoiceCreationAction($objInvoice)
 {
     if ($this->settings['email_info']) {
         $metaUser = new metaUser($objInvoice->userid);
         $request = new stdClass();
         $request->metaUser =& $metaUser;
         $request->invoice =& $objInvoice;
         $request->plan =& $objInvoice->getObjUsage();
         $message = AECToolbox::rewriteEngineRQ($this->settings['text'], $request);
         $subject = AECToolbox::rewriteEngineRQ($this->settings['subject'], $request);
         if (!empty($message)) {
             $recipients = AECToolbox::rewriteEngineRQ($this->settings['recipient'], $request);
             $recips = explode(',', $recipients);
             $recipients2 = array();
             foreach ($recips as $k => $email) {
                 $recipients2[$k] = trim($email);
             }
             $recipients = $recipients2;
             $bccipients = AECToolbox::rewriteEngineRQ($this->settings['bcc'], $request);
             $bccips = explode(',', $bccipients);
             $bccipients2 = array();
             foreach ($bccips as $k => $email) {
                 $bccipients2[$k] = trim($email);
             }
             $bccipients = $bccipients2;
             if (!empty($bccipients2)) {
                 $bcc = $bccipients;
             } else {
                 $bcc = null;
             }
             xJ::sendMail($this->settings['sender'], $this->settings['sender_name'], $recipients, $subject, $message, $this->settings['text_html'], null, $bcc);
         }
     }
     if ($this->settings['waitingplan']) {
         $db = JFactory::getDBO();
         $metaUser = new metaUser($objInvoice->userid);
         if (!$metaUser->hasSubscription || in_array($metaUser->objSubscription->status, array('Expired', 'Closed'))) {
             if (!$metaUser->hasSubscription) {
                 $payment_plan = new SubscriptionPlan();
                 $payment_plan->load($this->settings['waitingplan']);
                 $metaUser->establishFocus($payment_plan, 'offline_payment3', false);
             }
             $metaUser->objSubscription->applyUsage($this->settings['waitingplan'], 'none', 0);
             $short = 'waiting plan';
             $event = 'Offline Payment waiting plan assigned for ' . $objInvoice->invoice_number;
             $tags = 'processor,waitingplan';
             $params = array('invoice_number' => $objInvoice->invoice_number);
             $eventlog = new eventLog();
             $eventlog->issue($short, $tags, $event, 2, $params);
         }
     }
 }
Example #21
0
 public function Action()
 {
     $db = JFactory::getDBO();
     $entries = 0;
     $planlist = array();
     $pplist = array();
     $processors = array('authorize_arb', 'google_checkout', 'hsbc', 'iats', 'paypal_wpp', 'sparkassen_internetkasse', 'usaepay');
     $query = 'SELECT `id`' . ' FROM #__acctexp_invoices' . ' WHERE `method` IN (' . implode(',', $processors) . ')';
     $db->setQuery($query);
     $invoices = xJ::getDBArray($db);
     foreach ($invoices as $id) {
         $invoice = new Invoice();
         $invoice->load($id);
         // Skip non-rebilled
         if (count($invoice->transactions) < 2) {
             continue;
         }
         foreach ($invoice->transactions as $tid => $transaction) {
             if (!$tid) {
                 // Skip first entry
                 continue;
             }
             if (!empty($_POST['safe'])) {
                 $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date = \'' . $transaction->timestamp . '\'' . ' AND proc_name = \'' . $transaction->processor . '\'' . ' AND invoice_number = \'' . $invoice->invoice_number . '\'';
                 $db->setQuery($query);
                 $hasentry = $db->loadResult();
                 if ($hasentry) {
                     continue;
                 }
             }
             $entries++;
             if (!empty($_POST['create'])) {
                 $entry = new logHistory();
                 $user = new cmsUser();
                 $user->load($invoice->userid);
                 if (!isset($planlist[$invoice->usage])) {
                     $plan = new SubscriptionPlan();
                     $plan->load($invoice->usage);
                     $planlist[$invoice->usage] = $plan;
                 }
                 if (!isset($pplist[$invoice->method])) {
                     $pp = new SubscriptionPlan();
                     $pp->load($invoice->method);
                     $pplist[$invoice->method] = $pp;
                 }
                 if ($pplist[$invoice->method]->id) {
                     $entry->proc_id = $pplist[$invoice->method]->id;
                     $entry->proc_name = $pplist[$invoice->method]->processor_name;
                 }
                 $entry->user_id = $user->id;
                 $entry->user_name = $user->username;
                 if ($planlist[$invoice->usage]->id) {
                     $entry->plan_id = $planlist[$invoice->usage]->id;
                     $entry->plan_name = $planlist[$invoice->usage]->name;
                 }
                 $entry->transaction_date = $transaction->timestamp;
                 $entry->amount = $transaction->amount;
                 $entry->invoice_number = $invoice->invoice_number;
                 $entry->response = 'Created by the Rebuild Rebills Tool';
                 $entry->cleanup();
                 $entry->check();
                 $entry->store();
             }
         }
     }
     if (empty($entries)) {
         if ($_POST['create']) {
             return "No Invoices found to create History Entries from.";
         } else {
             return "No Invoices with data found.";
         }
     } else {
         if ($_POST['create']) {
             return $entries . " History Entries created.";
         } else {
             return "No History Entries created, found " . $entries . " that can be converted (select 'Create' from the settings above and carry out the query again)";
         }
     }
 }
Example #22
0
 public function getUserMIs()
 {
     if (empty($this->focusSubscription->id)) {
         return array();
     }
     $focus = $this->focusSubscription->id;
     $return = array();
     if (!empty($this->objSubscription->plan)) {
         $selected_plan = new SubscriptionPlan();
         $selected_plan->load($this->objSubscription->plan);
         $mis = $selected_plan->getMicroIntegrations();
         if (empty($mis)) {
             $mis = array();
         }
         $sec = $this->getSecondarySubscriptions(true);
         if (!empty($sec)) {
             foreach ($sec as $pid) {
                 if ($this->moveFocus($pid)) {
                     $selected_plan = new SubscriptionPlan();
                     $selected_plan->load($this->focusSubscription->plan);
                     $miis = $selected_plan->getMicroIntegrations();
                     if (!empty($miis)) {
                         $mis = array_merge($mis, $miis);
                     }
                 }
             }
         }
         if (count($mis)) {
             $mis = array_unique($mis);
             foreach ($mis as $mi_id) {
                 if ($mi_id) {
                     $mi = new MicroIntegration();
                     $mi->load($mi_id);
                     if (!$mi->callIntegration()) {
                         continue;
                     }
                     $return[] = $mi;
                 }
             }
         }
     }
     // Go back to initial focus, if it has been changed
     if ($this->focusSubscription->id != $focus) {
         $this->moveFocus($focus);
     }
     return $return;
 }
Example #23
0
 /**
  * @param Invoice $objInvoice
  */
 public function entryFromInvoice($objInvoice, $response, $pp)
 {
     $user = new cmsUser();
     $user->load($objInvoice->userid);
     $plan = new SubscriptionPlan();
     $plan->load($objInvoice->usage);
     if ($pp->id) {
         $this->proc_id = $pp->id;
         $this->proc_name = $pp->processor_name;
     }
     $this->user_id = $user->id;
     $this->user_name = $user->username;
     if ($plan->id) {
         $this->plan_id = $plan->id;
         $this->plan_name = $plan->name;
     }
     $this->transaction_date = date('Y-m-d H:i:s', (int) gmdate('U'));
     $this->amount = $objInvoice->amount;
     $this->invoice_number = $objInvoice->invoice_number;
     $this->response = $response;
     $this->cleanup();
     $short = 'history entry';
     $event = 'Processor (' . $pp->processor_name . ') notification for ' . $objInvoice->invoice_number;
     $tags = 'history,processor,payment';
     $params = array('invoice_number' => $objInvoice->invoice_number);
     $eventlog = new eventLog();
     $eventlog->issue($short, $tags, $event, 2, $params);
     $this->check();
     $this->store();
 }
 public function doPlanComparison($user_subscription)
 {
     $return['total_comparison'] = false;
     $return['comparison'] = false;
     $return['full_comparison'] = true;
     if (empty($user_subscription->plan)) {
         return $return;
     }
     if (!empty($user_subscription->used_plans) && is_array($user_subscription->used_plans)) {
         $plans_comparison = false;
         foreach ($user_subscription->used_plans as $planid => $pusage) {
             if (!$planid) {
                 continue;
             }
             if (empty($planid)) {
                 continue;
             }
             $used_subscription = new SubscriptionPlan();
             $used_subscription->load($planid);
             if ($this->id === $used_subscription->id) {
                 $used_comparison = 2;
             } elseif (empty($this->params['similarplans']) && empty($this->params['equalplans'])) {
                 $used_comparison = false;
             } else {
                 $used_comparison = $this->compareToPlan($used_subscription);
             }
             if ($used_comparison > $plans_comparison) {
                 $plans_comparison = $used_comparison;
             }
             unset($used_subscription);
         }
         $return['total_comparison'] = $plans_comparison;
     }
     $last_subscription = new SubscriptionPlan();
     $last_subscription->load($user_subscription->plan);
     if ($this->id === $last_subscription->id) {
         $return['comparison'] = 2;
     } else {
         $return['comparison'] = $this->compareToPlan($last_subscription);
     }
     $return['full_comparison'] = $return['comparison'] === false && $return['total_comparison'] === false;
     return $return;
 }
Example #25
0
<?php

$config = Config::get();
$payPal = new PaypalSubscription($config);
$userService = new UserService();
//get selected user
$userId = $userService->getSelectedUserId();
$service_provider = 'getscorecard';
$activeSubscription = Subscription::getActiveSubscriptions($userId, $service_provider);
$subscriptionsArchive = Subscription::getSubscriptionsArchive($userId, $service_provider);
//$subscriptionPlan = new GetscorecardSubscriptionPlanPro();
$subscriptionPlan = new SubscriptionPlan();
//@TODO remake
//$service_provider = 'getscorecard';
//$plans = SubscriptionPlan::getGetscorecardSubscriptionPlans($service_provider);
$plans = SubscriptionPlan::getSubscriptionPlans($service_provider);
//$subscriptionsTempStatus = Subscription::getSubscriptionTemporaryStatus();
$usersCountDefault = 2;
$usersCount = $activeSubscription != null ? $activeSubscription['items_count'] : $usersCountDefault;
?>


<script type="text/javascript">
var subscriptionPlans = <?php 
echo json_encode($plans);
?>
;
var serviceProvider = '<?php 
echo $service_provider;
?>
';
Example #26
0
 public function createPlans($grouplist, $plans)
 {
     $db = JFactory::getDBO();
     if (!$_POST['create_plans']) {
         $query = 'SELECT MIN(id)' . ' FROM #__acctexp_plans';
         $db->setQuery($query);
         $this->range['plans']['start'] = $db->loadResult();
         $query = 'SELECT MAX(id)' . ' FROM #__acctexp_plans';
         $db->setQuery($query);
         $this->range['plans']['end'] = $db->loadResult();
         return;
     }
     $class = array('diamond', 'copper', 'silver', 'titanium', 'gold', 'platinum');
     $color = array('', 'azure ', 'scarlet ', 'jade ', 'lavender ', 'mustard ');
     $pricerange = array((int) $_POST['mincost'] * 100, (int) $_POST['maxcost'] * 100);
     for ($i = 1; $i <= $plans; $i++) {
         if (isset($color[(int) floor($i / 6)]) && isset($class[$i % 6])) {
             $name = ucfirst($color[(int) floor($i / 6)]) . ucfirst($class[$i % 6]) . " Plan";
         } else {
             $name = "Plan " . $i;
         }
         $row = new SubscriptionPlan();
         $post = array('active' => 1, 'visible' => 0, 'name' => $name, 'desc' => "Buy " . $name . " now!", 'processors' => '', 'full_amount' => round(rand($pricerange[0], $pricerange[1]) / 100, 2), 'full_free' => 0, 'full_period' => rand(1, 14), 'trial_free' => 0, 'trial_amount' => 0);
         $row->savePOSTsettings($post);
         $row->storeload();
         ItemGroupHandler::setChildren(rand($this->range['groups']['start'], $this->range['groups']['end']), array($row->id), $type = 'item');
         if ($i == 1) {
             $this->range['plans']['start'] = $row->id;
         } elseif ($i == $plans) {
             $this->range['plans']['end'] = $row->id;
         }
     }
 }
Example #27
0
 /**
  * @param string $customData
  * @return bool|mixed
  * @throws Exception
  */
 public function createFreeSubscription($userId, $planId, $itemsCount)
 {
     $subscriptionPlan = new SubscriptionPlan();
     $subscriptionPlan->load($planId);
     $activeSubscriptions = Subscription::getActiveSubscriptions($userId, $subscriptionPlan->service_provider);
     if (count($activeSubscriptions) > 0) {
         return false;
     }
     $subscription = new Subscription();
     $subscription->user_id = $userId;
     $subscription->plan_id = $planId;
     $subscription->subscription_id = '';
     $subscription->created_date = date("Y-m-d H:i:s");
     $subscription->updated_date = date('Y-m-d H:i:s');
     $subscription->payment_date = '';
     $subscription->items_count = $itemsCount;
     $subscription->status = Subscription::STATUS_ACTIVE;
     $subscriptionId = $subscription->save();
     return $subscriptionId;
 }
Example #28
0
    /**
     * @param aecHTML $aecHTML
     * @param SubscriptionPlan $row
     * @param boolean $hasrecusers
     */
    static function editSubscriptionPlan($aecHTML, $row, $hasrecusers)
    {
        global $aecConfig;
        jimport('joomla.html.editor');
        $editor = JFactory::getEditor();
        HTML_myCommon::startCommon('aec-wrap-squary', 'aec-wrap-inner-light');
        $buttons = array('apply' => array('style' => 'info', 'text' => JText::_('APPLY'), 'actionable' => true, 'icon' => 'ok-sign'), 'save' => array('style' => 'success', 'text' => JText::_('SAVE'), 'actionable' => true, 'icon' => 'ok'), 'hl1' => array(), 'cancel' => array('style' => 'danger', 'text' => JText::_('CANCEL'), 'icon' => 'remove'));
        HTML_myCommon::startForm();
        HTML_myCommon::getHeader('', 'plans', $row->id ? $row->getProperty('name') : JText::_('AEC_HEAD_PLAN_INFO') . JText::_('AEC_CMN_NEW'), false, $buttons, 'SubscriptionPlan');
        ?>
<div class="col-sm-12"><?php 
        $tabs = new bsPaneTabs();
        $tabs->startTabs();
        $tabs->newTab('plan', JText::_('PAYPLAN_DETAIL_TITLE'));
        $tabs->newTab('processors', JText::_('PAYPLAN_PROCESSORS_TITLE'));
        $tabs->newTab('text', JText::_('PAYPLAN_TEXT_TITLE'));
        $tabs->newTab('restrictions', JText::_('PAYPLAN_RESTRICTIONS_TITLE'));
        $tabs->newTab('trial', JText::_('PAYPLAN_TRIAL_TITLE'));
        $tabs->newTab('relations', JText::_('PAYPLAN_RELATIONS_TITLE'));
        $tabs->newTab('mis', JText::_('PAYPLAN_MI'));
        $tabs->endTabs();
        $tabs->startPanes();
        $tabs->nextPane('plan', true);
        ?>
		<div class="row">
			<div class="col-sm-6 col-md-4">
				<section class="paper">
					<h4>General</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('name');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('active');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('visible');
        ?>
					<div>
						<?php 
        if ($row->id) {
            ?>
							<p style="text-align: center;">
								<a href="<?php 
            echo str_replace("/administrator/", "/", AECToolbox::deadsureURL('index.php?option=com_acctexp&task=subscribe&usage=' . $row->id));
            ?>
" title="<?php 
            echo JText::_('AEC_CGF_LINK_ABO_FRONTEND');
            ?>
" target="_blank">
									<?php 
            echo JText::_('AEC_CGF_LINK_ABO_FRONTEND');
            ?>
								</a>
								&nbsp;|&nbsp;<a href="<?php 
            echo str_replace("/administrator/", "/", AECToolbox::deadsureURL('index.php?option=com_acctexp&task=addtocart&usage=' . $row->id));
            ?>
" title="<?php 
            echo JText::_('AEC_CGF_LINK_CART_FRONTEND');
            ?>
" target="_blank">
									<?php 
            echo JText::_('AEC_CGF_LINK_CART_FRONTEND');
            ?>
								</a>
							</p>
							<?php 
            if (!$aecConfig->cfg['plans_first']) {
                ?>
								<div class="alert alert-info">
									<p><span class="label label-info"><?php 
                echo JText::_('Please Note');
                ?>
:</span> <?php 
                echo JText::_('A direct frontend link only works for existing users who are logged in, or with the Plans First setting');
                ?>
.</p>
								</div>
							<?php 
            }
        }
        ?>
					</div>
				</section>
				<section class="paper">
					<h4>Details</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('make_active');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('make_primary');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('update_existing');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('fixed_redirect');
        ?>
				</section>

				<section class="paper">
					<h4><?php 
        echo JText::_('ITEMGROUPS_TITLE');
        ?>
</h4>
					<?php 
        if ($row->id) {
            ?>
						<table style="width:100%;" class="table table-striped table-hover table-condensed aec-grouplist">
							<thead>
							<tr>
								<th>Group</th>
								<th class="text-right text-muted">Remove</th>
							</tr>
							</thead>
							<tbody>
							<?php 
            if (!empty($aecHTML->customparams->groups)) {
                foreach ($aecHTML->customparams->groups as $id => $group) {
                    HTML_AcctExp::groupRow('item', $group);
                }
            }
            ?>
							</tbody>
							<tfoot>
							<tr>
								<td><?php 
            echo $aecHTML->createSettingsParticle('add_group');
            ?>
</td>
								<td>
									<a class="btn btn-success pull-right" id="addgroup-btn" onClick="addGroup('item','addgroup-btn')"><?php 
            echo aecHTML::Icon('plus');
            ?>
</a>
								</td>
							</tr>
							</tfoot>
						</table>
					<?php 
        } else {
            ?>
						<p>You can select groups after saving this plan for the first time.</p>
					<?php 
        }
        ?>
				</section>
			</div>
			<div class="col-sm-6 col-md-4">
				<section class="paper">
					<h4>Cost&amp;Details</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('full_free');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('full_amount');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('lifetime');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('full_period');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('full_periodunit');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('hide_duration_checkout');
        ?>
					<?php 
        if ($hasrecusers) {
            ?>
						<div class="alert alert-danger">
							<strong><?php 
            echo JText::_('PAYPLAN_AMOUNT_EDITABLE_NOTICE');
            ?>
</strong>
						</div>
					<?php 
        }
        ?>
				</section>
				<section class="paper">
					<h4>Joomla User</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('gid_enabled');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('gid');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('override_activation');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('override_regmail');
        ?>
				</section>
			</div>
			<div class="col-sm-6 col-md-4">
				<section class="paper">
					<h4>Plan Relation</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('fallback');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('fallback_req_parent');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('standard_parent');
        ?>
				</section>
				<section class="paper">
					<h4>Shopping Cart</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('cart_behavior');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('addtocart_max');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('addtocart_redirect');
        ?>
				</section>
				<section class="paper">
					<h4><?php 
        echo 'Notes';
        ?>
</h4>
					<div style="text-align: left;">
						<?php 
        echo $aecHTML->createSettingsParticle('notes');
        ?>
					</div>
				</section>
			</div>
		</div>
		<?php 
        $tabs->nextPane('processors');
        ?>
		<div class="row">
			<div class="col-sm-8 col-sm-offset-2">
				<div class="row">
					<div class="col-sm-4 col-sm-offset-4">
						<br/>
						<?php 
        echo $aecHTML->createSettingsParticle('processor_selectmode');
        ?>
						<br/>
						<input type="button" class="btn btn-success btn-block enable-sorting" value="Unlock Sorting"/>
						<p>&nbsp;</p>
						<p class="text-center">
							You can unlock the processor sorting to rearrange them via drag&amp;drop.
						</p>
					</div>
				</div>
				<ul class="sortable">
					<?php 
        if (!empty($aecHTML->customparams->pp)) {
            foreach ($aecHTML->customparams->pp as $id => $processor) {
                ?>
							<li>
								<section class="paper">
									<h2><?php 
                echo $processor['name'];
                ?>
</h2>
									<p><a href="<?php 
                echo str_replace("/administrator/", "/", AECToolbox::deadsureURL('index.php?option=com_acctexp&task=subscribe&usage=' . $row->id . '&processor=' . $processor['handle']));
                ?>
" title="<?php 
                echo JText::_('AEC_CGF_LINK_ABO_FRONTEND');
                ?>
" target="_blank"><?php 
                echo JText::_('AEC_CGF_LINK_ABO_FRONTEND');
                ?>
</a></p>
									<?php 
                foreach ($processor['params'] as $customparam) {
                    echo $aecHTML->createSettingsParticle($customparam);
                }
                ?>
								</section>
							</li>
						<?php 
            }
        }
        ?>
				</ul>
			</div>
		</div>
		<?php 
        $tabs->nextPane('text');
        ?>
		<div class="row">
			<div class="col-sm-6">
				<section class="paper">
					<h4><?php 
        echo JText::_('Customize');
        ?>
</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('customamountformat');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('desc');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('email_desc');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('meta');
        ?>
				</section>
			</div>
			<div class="col-sm-6">
				<section class="paper">
					<h4><?php 
        echo JText::_('Custom Thanks');
        ?>
</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('customthanks');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('customtext_thanks_keeporiginal');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('customtext_thanks');
        ?>
				</section>
			</div>
		</div>
		<?php 
        $tabs->nextPane('restrictions');
        ?>
		<div class="row">
			<div class="col-sm-6">
				<section class="paper">
					<h4><?php 
        echo JText::_('AEC_RESTRICTIONS_INVENTORY_HEADER');
        ?>
</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('inventory_amount_enabled');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('inventory_amount');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('inventory_amount_used');
        ?>
				</section>
			</div>
			<div class="col-sm-6">
				<section class="paper">
					<h4><?php 
        echo JText::_('AEC_RESTRICTIONS_REDIRECT_HEADER');
        ?>
</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('notauth_redirect');
        ?>
				</section>
			</div>
		</div>
		<?php 
        aecRestrictionHelper::echoSettings($aecHTML);
        ?>
		<?php 
        $tabs->nextPane('trial');
        ?>
		<div class="row">
			<div class="col-sm-8 col-sm-offset-2">
				<section class="paper">
					<h4><?php 
        echo JText::_('PAYPLAN_TRIAL_TITLE');
        ?>
</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('trial_free');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('trial_amount');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('trial_period');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('trial_periodunit');
        ?>
					<div class="alert alert-danger">
						<?php 
        echo JText::_('PAYPLAN_AMOUNT_NOTICE_TEXT');
        ?>
					</div>
				</section>
			</div>
		</div>
		<?php 
        $tabs->nextPane('relations');
        ?>
		<div class="row">
			<div class="col-sm-8 col-sm-offset-2">
				<section class="paper">
					<h4><?php 
        echo JText::_('PAYPLAN_RELATIONS_TITLE');
        ?>
</h4>
					<?php 
        echo $aecHTML->createSettingsParticle('similarplans');
        ?>
					<?php 
        echo $aecHTML->createSettingsParticle('equalplans');
        ?>
				</section>
			</div>
		</div>
		<?php 
        $tabs->nextPane('mis');
        ?>
		<div class="row">
			<div class="col-sm-6">
				<section class="paper">
					<h4><?php 
        echo JText::_('Inherited Micro Integrations');
        ?>
</h4>
					<?php 
        if (!empty($aecHTML->customparams->mi['inherited'])) {
            echo '<p>' . JText::_('These MIs were inherited from groups that this subscription plan is in') . '</p>';
            echo '<ul>';
            foreach ($aecHTML->customparams->mi['inherited'] as $id => $mi) {
                ?>
							<li>
								<p>
									<input type="checkbox" name="inherited_micro_integrations[]" value="<?php 
                echo $mi->id;
                ?>
" checked="checked" disabled="disabled" />
									<strong><?php 
                echo $mi->name;
                ?>
</strong> (#<?php 
                echo $mi->id;
                ?>
)
									(<a href="index.php?option=com_acctexp&amp;task=edit&amp;entity=microintegration&amp;id=<?php 
                echo $mi->id;
                ?>
" target="_blank"><?php 
                echo JText::_('edit');
                ?>
</a>)
								</p>
								<p><?php 
                echo $mi->desc;
                ?>
</p>
							</li>
						<?php 
            }
            echo '</ul>';
        } else {
            echo '<p>' . JText::_('No inherited MIs - A subscription plan can inherit MIs from groups that it is in') . '</p>';
        }
        ?>
				</section>
			</div>
			<div class="col-sm-6">
				<section class="paper">
					<h4><?php 
        echo JText::_('Attached Micro Integrations');
        ?>
</h4>
					<?php 
        if (!empty($aecHTML->customparams->mi['attached'])) {
            echo '<table style="margin: 0 auto;">';
            foreach ($aecHTML->customparams->mi['attached'] as $id => $mi) {
                ?>
							<tr>
								<td>
									<h5>
										<strong><?php 
                echo $mi->name;
                ?>
</strong>
										(#<?php 
                echo $mi->id;
                ?>
)
										<?php 
                echo $mi->inherited ? ' (' . JText::_('inherited from parent group') . '!)' : '';
                ?>
										(<a href="index.php?option=com_acctexp&amp;task=edit&amp;entity=microintegration&amp;id=<?php 
                echo $mi->id;
                ?>
" target="_blank"><?php 
                echo JText::_('edit');
                ?>
</a>)
									</h5>
								</td>
								<td>
									<input id="micro_integrations_<?php 
                echo $mi->id;
                ?>
" class="bootstrap-toggle" type="checkbox" name="micro_integrations[]"<?php 
                echo $mi->attached ? ' checked="checked"' : '';
                ?>
 value="<?php 
                echo $mi->id;
                ?>
" data-state="<?php 
                echo $mi->attached ? '1' : '0';
                ?>
"/>
								</td>
							</tr>
							<tr>
								<td colspan="2" style="border-bottom: 1px dashed #999;">
									<p><?php 
                echo $mi->desc;
                ?>
</p>
								</td>
							</tr>
						<?php 
            }
            echo '</table>';
        } else {
            echo '<p>' . JText::_('No MIs to attach') . '<a href="index.php?option=com_acctexp&amp;task=edit&amp;entity=microintegration" target="_blank">(' . JText::_('create one now?') . ')</a></p>';
        }
        ?>
				</section>
			</div>
		</div>
		<?php 
        if (!empty($aecHTML->customparams->hasperplanmi)) {
            ?>
		<div class="row">
			<div class="col-sm-6">
				<section class="paper">
					<?php 
            echo $aecHTML->createSettingsParticle('micro_integrations_plan');
            ?>
					<?php 
            echo $aecHTML->createSettingsParticle('micro_integrations_hidden');
            ?>
				</section>
			</div>
		</div>
	<?php 
        }
        ?>
		<?php 
        if (!empty($aecHTML->customparams->mi['custom'])) {
            ?>
			<div class="row">
				<?php 
            foreach ($aecHTML->customparams->mi['custom'] as $id => $mi) {
                ?>
					<div class="col-sm-8 col-sm-offset-2">
						<section class="paper">
							<h2><?php 
                echo $mi['name'];
                ?>
</h2>
							<?php 
                foreach ($mi['params'] as $customparam) {
                    echo $aecHTML->createSettingsParticle($customparam);
                }
                ?>
						</section>
					</div>
				<?php 
            }
            ?>
			</div>
		<?php 
        }
        ?>
		<?php 
        $tabs->endPanes();
        ?>
		<input type="hidden" name="id" value="<?php 
        echo $row->id;
        ?>
" />
		<input type="hidden" name="option" value="com_acctexp" />
		<input type="hidden" name="entity" value="SubscriptionPlan" />
		<input type="hidden" name="task" value="save" />
		</form>

		</div>

		<?php 
        HTML_myCommon::endCommon();
    }