/** * 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); }
/** * 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); }
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>"; }
$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)) { // Double check whether we have a history entry
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; }
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; }
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; }
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); } } }
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')); }
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'; } }
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(); } } }
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; }
$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')); $usage = aecGetParam('usage', 0, true, array('word', 'int'));
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; } }
static function getTotalAllowedChildItems($gids, $metaUser, $list = array()) { $groups = ItemGroupHandler::getChildren($gids, 'group'); if (!empty($groups)) { foreach ($groups as $groupid) { $group = new ItemGroup(); $group->load($groupid); if (!$group->checkVisibility($metaUser)) { continue; } if (!empty($group->params['reveal_child_items']) && empty($group->params['symlink'])) { $list = ItemGroupHandler::getTotalAllowedChildItems($groupid, $metaUser, $list); } else { if (ItemGroupHandler::hasVisibleChildren($group, $metaUser)) { $list[] = ItemGroupHandler::getGroupListItem($group); } } } } $items = ItemGroupHandler::getChildren($gids, 'item'); if (!empty($items)) { foreach ($items as $itemid) { $plan = new SubscriptionPlan(); $plan->load($itemid); if (!$plan->checkVisibility($metaUser)) { continue; } $list[] = ItemGroupHandler::getItemListItem($plan); } } return $list; }
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; }
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)"; } } }
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); } } }
/** * @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; }
public function createPayments() { if (!$_POST['create_payments']) { return; } $db = JFactory::getDBO(); $amountlist = array(); for ($i = $this->range['plans']['start']; $i <= $this->range['plans']['end']; $i++) { $amountlist[$i] = array(); $modlist[$i]['sin'] = rand(0, 360); $modlist[$i]['speed'] = rand(0, 1000) / 100; $modlist[$i]['multi'] = rand(0, 100) / 50; } $start_date = strtotime($_POST['start'] . '-01-01 00:00:00'); $years = (int) date('Y') - $_POST['start']; $days = $years * 365 + date('z') + 1; $saleslist = $this->stream_layers($amountlist, $days + 2, 1); $plandetails = array(); $query = 'SELECT MIN(id)' . ' FROM #__acctexp_log_history'; $db->setQuery($query); $this->range['payments']['start'] = $db->loadResult() + 1; for ($i = 1; $i <= $days; $i++) { $dtime = strtotime("+" . $i . " days", $start_date); foreach ($modlist as $k => $v) { $modlist[$k]['sin'] += $modlist[$k]['speed']; $modlist[$k]['sin'] = $modlist[$k] % 360; } foreach ($saleslist as $plan => $dayslist) { if (!isset($plandetails[$plan])) { $splan = new SubscriptionPlan(); $splan->load($plan); $plandetails[$plan] = array('name' => $splan->name, 'cost' => $splan->params['full_amount']); } // Add some sine modification $dsales = (int) ($dayslist[$i] * ((1 + sin($modlist[$plan]['sin'])) * $modlist[$plan]['multi'])); // Less sales on the weekends if (date('N', $dtime) > 5) { $dsales = (int) ($dsales / rand(1, 4)); } for ($j = 0; $j < $dsales; $j++) { $found = false; while (!$found) { $userid = rand($this->range['users']['start'], $this->range['users']['end']); $db->setQuery('SELECT id FROM #__users WHERE `id` = \'' . $userid . '\''); $check = $db->loadResult(); $found = !empty($check); } $invoice = new Invoice(); $invoice->userid = $userid; $invoice->usage = $plan; $invoice->method = 'none'; $invoice->invoice_number = $invoice->generateInvoiceNumber(); $invoice->storeload(); $invoice->computeAmount(); $invoice->pay(); $invoice->transaction_date = date('Y-m-d H:i:s', $dtime + rand(0, 86400)); $invoice->check(); $invoice->store(); $pp = new stdClass(); $pp->id = 0; $pp->processor_name = 'none'; $history = new logHistory(); $history->entryFromInvoice($invoice, array("dummy" => "data"), $pp); $history->transaction_date = date('Y-m-d H:i:s', $dtime + rand(0, 86400)); $history->check(); $history->store(); } } } $query = 'SELECT MAX(id)' . ' FROM #__acctexp_log_history'; $db->setQuery($query); $this->range['payments']['end'] = $db->loadResult(); }
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; }
/** * @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; }
static function SubscriptionName($subscriptionid) { $subscription = new SubscriptionPlan(); $subscription->load($subscriptionid); return $subscription->name; }