Exemplo n.º 1
0
 public function displaySubscriptions($tab, $user, $ui)
 {
     $db = JFactory::getDBO();
     include_once JPATH_SITE . '/components/com_acctexp/acctexp.class.php';
     $dateFormat = $this->params->get('dateFormat', "m/d/Y");
     $meta_user = new metaUser($user->id);
     $html_return = '' . '<table class="aeceventlog_table" style="border-collapse: collapse">' . '<tr class="aeceventlog_row_header">' . '<th width="30%" class="text-center">Plan</th>' . '<th width="10%" class="text-center">Primary</th>' . '<th width="10%" class="text-center">Status</th>' . '<th width="10%" class="text-center">Started</th>' . '<th width="20%" class="text-center">Ends</th>' . '</tr>';
     $subscriptions = $meta_user->getAllSubscriptions();
     $subscr_info = $this->getAllCurrentSubscriptionsInfoComplete($user->id);
     foreach ($subscriptions as $i => $subscriptionid) {
         $subscription = new Subscription();
         $subscription->load($subscriptionid);
         $plan_name = $subscr_info[$i]->name == '' ? "Excluded" : $subscr_info[$i]->name;
         $html_return .= '<tr>' . '<td width="30%" class="text-center">' . $plan_name . '</td>' . '<td width="10%" class="text-center">' . ($subscription->primary ? "Yes" : "No") . '</td>' . '<td width="10%" class="text-center">' . $this->getIconHtml($subscription->status) . ' ' . $subscription->status . '</td>' . '<td width="10%" class="text-center">' . date($dateFormat, strtotime($subscription->signup_date)) . '</td>';
         $html_return .= '<td width="10%" class="text-center">';
         if (!empty($subscription->lifetime)) {
             $html_return .= JText::_('AEC_ISLIFETIME');
         } else {
             if ($subscription->recurring && in_array($subscription->status, array('Active', 'Trial'))) {
                 $html_return .= JText::_('AEC_WILLRENEW') . ': ' . date($dateFormat, strtotime($subscription->expiration));
             } else {
                 $html_return .= date($dateFormat, strtotime($subscription->expiration));
             }
         }
         $html_return .= '</td></tr>';
     }
     $html_return .= '</table>';
     return $html_return;
 }
Exemplo n.º 2
0
 public function Action()
 {
     $return = '';
     if (!empty($_POST['invoices'])) {
         $notfound = array();
         $updated = array();
         $db = JFactory::getDBO();
         $list = explode("\n", $_POST['invoices']);
         foreach ($list as $li) {
             $invoice = new Invoice();
             $invoice->loadInvoiceNumber(trim($li));
             if (empty($invoice->id)) {
                 $notfound[] = trim($li);
                 continue;
             }
             if (!is_numeric($invoice->usage)) {
                 $notfound[] = trim($li);
                 continue;
             }
             $metaUser = new metaUser($invoice->userid);
             $cfid = $metaUser->focusSubscription->id;
             if ($cfid != $invoice->subscr_id) {
                 if (!$metaUser->moveFocus($invoice->subscr_id)) {
                     $notfound[] = trim($li);
                     continue;
                 }
             }
             if ($metaUser->focusSubscription->status == 'Active') {
                 $metaUser->focusSubscription->expiration = date('Y-m-d H:i:s', (int) gmdate('U') - 60);
                 $metaUser->focusSubscription->plan = $invoice->usage;
                 $metaUser->focusSubscription->type = $invoice->method;
                 $metaUser->focusSubscription->recurring = 1;
                 $metaUser->focusSubscription->check();
                 $metaUser->focusSubscription->store();
                 $updated[] = $invoice->invoice_number;
             } else {
                 $metaUser->focusSubscription->status = 'Active';
                 $metaUser->focusSubscription->expiration = date('Y-m-d H:i:s', (int) gmdate('U') - 60);
                 $metaUser->focusSubscription->plan = $invoice->usage;
                 $metaUser->focusSubscription->type = $invoice->method;
                 $metaUser->focusSubscription->recurring = 1;
                 $metaUser->focusSubscription->check();
                 $metaUser->focusSubscription->store();
                 $updated[] = $invoice->invoice_number;
             }
         }
         $return = '<p>Provided ' . count($list) . ' Invoice Numbers.</p>';
         if (count($updated)) {
             $return .= '<p>Updated ' . count($updated) . ' Invoices:</p>';
             $return .= '<p>' . implode(', ', $updated) . '</p>';
         }
         if (count($notfound)) {
             $return .= '<p>Failed to process the following ' . count($notfound) . ' Invoices:</p>';
             $return .= '<p>' . implode(', ', $notfound) . '</p>';
         }
     } elseif (isset($_POST['invoices'])) {
         $return = '<p>Please enter invoice numbers.</p>';
     }
     return $return;
 }
Exemplo n.º 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);
     $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);
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
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);
         }
     }
 }
Exemplo n.º 6
0
 public function save($userid, $subscriptionid, $assignto_plan)
 {
     $post = $_POST;
     if (!empty($assignto_plan)) {
         if ($assignto_plan[0] == 0) {
             unset($assignto_plan[0]);
         }
     }
     $metaUser = new metaUser($userid);
     if ($metaUser->hasSubscription && !empty($subscriptionid)) {
         $metaUser->moveFocus($subscriptionid);
     }
     $ck_primary = aecGetParam('ck_primary');
     if ($ck_primary && !$metaUser->focusSubscription->primary) {
         $metaUser->focusSubscription->makePrimary();
     }
     if (!empty($assignto_plan) && is_array($assignto_plan)) {
         foreach ($assignto_plan as $assign_planid) {
             $plan = new SubscriptionPlan();
             $plan->load($assign_planid);
             $metaUser->establishFocus($plan);
             $metaUser->focusSubscription->applyUsage($assign_planid, 'none', 1);
             // We have to reload the metaUser object because of the changes
             $metaUser = new metaUser($userid);
         }
     }
     $ck_lifetime = aecGetParam('ck_lifetime');
     $set_status = trim(aecGetParam('set_status', null));
     if (!$metaUser->hasSubscription) {
         if ($set_status == 'excluded') {
             $metaUser->focusSubscription = new Subscription();
             $metaUser->focusSubscription->createNew($metaUser->userid, 'none', 0);
             $metaUser->hasSubscription = true;
         } else {
             echo "<script> alert('" . JText::_('AEC_ERR_NO_SUBSCRIPTION') . "'); window.history.go(-1); </script>\n";
             exit;
         }
     }
     if (empty($assignto_plan)) {
         if ($ck_lifetime) {
             $metaUser->focusSubscription->expiration = '9999-12-31 00:00:00';
             $metaUser->focusSubscription->status = 'Active';
             $metaUser->focusSubscription->lifetime = 1;
         } elseif (!empty($post['expiration'])) {
             if ($post['expiration'] != $post['expiration_check']) {
                 if (strpos($post['expiration'], ':') === false) {
                     $metaUser->focusSubscription->expiration = $post['expiration'] . ' 00:00:00';
                 } else {
                     $metaUser->focusSubscription->expiration = $post['expiration'];
                 }
                 if ($metaUser->focusSubscription->status == 'Trial') {
                     $metaUser->focusSubscription->status = 'Trial';
                 } else {
                     $metaUser->focusSubscription->status = 'Active';
                 }
                 $metaUser->focusSubscription->lifetime = 0;
             }
         }
     }
     if (!empty($set_status)) {
         switch ($set_status) {
             case 'expired':
                 $metaUser->focusSubscription->expire();
                 break;
             case 'cancelled':
                 $metaUser->focusSubscription->cancel();
                 break;
             default:
                 $metaUser->focusSubscription->setStatus(ucfirst($set_status));
                 break;
         }
     }
     if (!empty($post['notes'])) {
         $metaUser->focusSubscription->customparams['notes'] = $post['notes'];
         unset($post['notes']);
     }
     if ($metaUser->hasSubscription) {
         $metaUser->focusSubscription->storeload();
     }
     $userMIs = $metaUser->getUserMIs();
     if (!empty($userMIs)) {
         foreach ($userMIs as $m) {
             $params = array();
             $pref = 'mi_' . $m->id . '_';
             $uf = $m->profile_form($metaUser);
             if (!empty($uf)) {
                 foreach ($uf as $k => $v) {
                     if (isset($post[$pref . $k])) {
                         $params[$k] = $post[$pref . $k];
                     }
                 }
                 $m->profile_form_save($metaUser, $params);
             }
             $admin_params = array();
             $af = $m->admin_form($metaUser);
             if (!empty($af)) {
                 foreach ($af as $k => $v) {
                     if (isset($post[$pref . $k])) {
                         $admin_params[$k] = $post[$pref . $k];
                     }
                 }
                 $m->admin_form_save($metaUser, $admin_params);
             }
             if (empty($params)) {
                 continue;
             }
             $metaUser->meta->setMIParams($m->id, null, $params, true);
         }
         $metaUser->meta->storeload();
     }
 }
Exemplo n.º 7
0
 static function saveUserRegistration($var, $internal = false, $overrideActivation = false, $overrideEmails = false, $overrideJS = false)
 {
     $db = JFactory::getDBO();
     global $task, $aecConfig;
     $app = JFactory::getApplication();
     ob_start();
     // Let CB/JUSER think that everything is going fine
     if (aecComponentHelper::detect_component('anyCB')) {
         if (aecComponentHelper::detect_component('CBE') || $overrideActivation) {
             global $ueConfig;
         }
         $savetask = $task;
         $_REQUEST['task'] = 'done';
         include_once JPATH_SITE . '/components/com_comprofiler/comprofiler.php';
         $task = $savetask;
         if ($overrideActivation) {
             $ueConfig['reg_confirmation'] = 0;
         }
         if ($overrideEmails) {
             $ueConfig['reg_welcome_sub'] = '';
             // Only disable "Pending Approval / Confirmation" emails if it makes sense
             if (!$ueConfig['reg_confirmation'] || !$ueConfig['reg_admin_approval']) {
                 $ueConfig['reg_pend_appr_sub'] = '';
             }
         }
     } elseif (aecComponentHelper::detect_component('JUSER')) {
         $savetask = $task;
         $task = 'blind';
         include_once JPATH_SITE . '/components/com_juser/juser.php';
         include_once JPATH_SITE . '/administrator/components/com_juser/juser.class.php';
         $task = $savetask;
     } elseif (aecComponentHelper::detect_component('JOMSOCIAL')) {
     }
     // For joomla and CB, we must filter out some internal variables before handing over the POST data
     $badbadvars = array('userid', 'method_name', 'usage', 'processor', 'recurring', 'currency', 'amount', 'invoice', 'id', 'gid');
     foreach ($badbadvars as $badvar) {
         if (isset($var[$badvar])) {
             unset($var[$badvar]);
         }
     }
     if (empty($var['name']) && !empty($var['jform'])) {
         // Must be K2
         $var['name'] = aecEscape($var['jform']['name'], array('string', 'clear_nonalnum'));
         unset($var['jform']);
     }
     $_POST = $var;
     $var['username'] = aecEscape($var['username'], array('string', 'badchars'));
     $savepwd = aecEscape($var['password'], array('string', 'badchars'));
     if (aecComponentHelper::detect_component('anyCB')) {
         // This is a CB registration, borrowing their code to save the user
         if ($internal && !aecComponentHelper::detect_component('CBE')) {
             include_once JPATH_SITE . '/components/com_acctexp/lib/codeofshame/cbregister.php';
             if (empty($_POST['firstname']) && !empty($_POST['name'])) {
                 $name = metaUser::_explodeName($_POST['name']);
                 $_POST['firstname'] = $name['first'];
                 if (empty($name['last'])) {
                     $_POST['lastname'] = $name['first'];
                 } else {
                     $_POST['lastname'] = $name['last'];
                 }
             }
             $_POST['password__verify'] = $_POST['password2'];
             unset($_POST['password2']);
             @saveRegistrationNOCHECKSLOL('com_acctexp');
         } else {
             @saveRegistration('com_acctexp');
             $cbreply = ob_get_contents();
             $indicator = '<script type="text/javascript">alert(\'';
             $alertstart = strpos($cbreply, $indicator);
             // Emergency fallback
             if ($alertstart !== false) {
                 ob_clean();
                 $alertend = strpos($cbreply, '\'); </script>', $alertstart);
                 $alert = substr($cbreply, $alertstart + strlen($indicator), $alertend - $alertstart - strlen($indicator));
                 if ($aecConfig->cfg['plans_first']) {
                     aecErrorAlert($alert, $action = 'window.history.go(-2);');
                 } else {
                     aecErrorAlert($alert, $action = 'window.history.go(-3);');
                 }
             }
         }
     } elseif (aecComponentHelper::detect_component('JUSER')) {
         // This is a JUSER registration, borrowing their code to save the user
         saveRegistration('com_acctexp');
         $query = 'SELECT `id`' . ' FROM #__users' . ' WHERE `username` = \'' . $var['username'] . '\'';
         $db->setQuery($query);
         $uid = $db->loadResult();
         JUser::saveUser_ext($uid);
         //synchronize dublicate user data
         $query = 'SELECT `id`' . ' FROM #__juser_integration' . ' WHERE `published` = \'1\'' . ' AND `export_status` = \'1\'';
         $db->setQuery($query);
         $components = $db->loadObjectList();
         if (!empty($components)) {
             foreach ($components as $component) {
                 $synchronize = require_integration($component->id);
                 $synchronize->synchronizeFrom($uid);
             }
         }
     } elseif (aecComponentHelper::detect_component('JOMSOCIAL') && !$overrideJS) {
     } else {
         $data = array('username' => $var['username'], 'password' => $var['password'], 'password2' => $var['password2'], 'email' => $var['email'], 'name' => $var['name']);
         if (isset($var['jform']['profile'])) {
             $data['profile'] = $var['jform']['profile'];
         }
         if (defined('JPATH_MANIFESTS')) {
             $params = JComponentHelper::getParams('com_users');
             // Initialise the table with JUser.
             JUser::getTable('User', 'JTable');
             $user = new JUser();
             // Prepare the data for the user object.
             $useractivation = $params->get('useractivation');
             // Check if the user needs to activate their account.
             if (($useractivation == 1 || $useractivation == 2) && !$overrideActivation) {
                 jimport('joomla.user.helper');
                 $data['activation'] = xJ::getHash();
                 $data['block'] = 1;
             }
             $usersConfig = JComponentHelper::getParams('com_users');
             $system = $usersConfig->get('new_usertype', 2);
             $data['groups'][] = $system;
             // Bind the data.
             if (!$user->bind($data)) {
                 JError::raiseWarning(500, JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
                 return false;
             }
             // Load the users plugin group.
             JPluginHelper::importPlugin('users');
             // Store the data.
             if (!$user->save()) {
                 JError::raiseWarning(500, JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
                 return false;
             }
         } else {
             // This is a joomla registration, borrowing their code to save the user
             // Check for request forgeries
             if (!$internal) {
                 JRequest::checkToken() or die('Invalid Token');
             }
             // Get required system objects
             $user = clone JFactory::getUser();
             //$pathway 	=& $app->getPathway();
             $config = JFactory::getConfig();
             $authorize = JFactory::getACL();
             $document = JFactory::getDocument();
             // If user registration is not allowed, show 403 not authorized.
             $usersConfig = JComponentHelper::getParams('com_users');
             if ($usersConfig->get('allowUserRegistration') == '0') {
                 JError::raiseError(403, JText::_('Access Forbidden'));
                 return;
             }
             // Initialize new usertype setting
             $newUsertype = $usersConfig->get('new_usertype');
             if (!$newUsertype) {
                 $newUsertype = 'Registered';
             }
             // Bind the post array to the user object
             if (!$user->bind($data)) {
                 JError::raiseError(500, $user->getError());
                 unset($_POST);
                 subscribe('com_acctexp');
                 return false;
             }
             // Set some initial user values
             $user->set('id', 0);
             $user->set('usertype', '');
             $user->set('gid', $authorize->get_group_id('', $newUsertype, 'ARO'));
             $user->set('sendEmail', 0);
             $user->set('registerDate', date('Y-m-d H:i:s', (int) gmdate('U')));
             // If user activation is turned on, we need to set the activation information
             $useractivation = $usersConfig->get('useractivation');
             if ($useractivation == '1' && !$overrideActivation) {
                 jimport('joomla.user.helper');
                 $user->set('activation', md5(JUserHelper::genRandomPassword()));
                 $user->set('block', '1');
             }
             // If there was an error with registration, set the message and display form
             if (!$user->save()) {
                 JError::raiseWarning('', JText::_($user->getError()));
                 echo JText::_($user->getError());
                 return false;
             }
         }
         $row = $user;
         $name = $row->name;
         $email = $row->email;
         $username = $row->username;
         $subject = sprintf(JText::_('AEC_SEND_SUB'), $name, $app->getCfg('sitename'));
         $subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8');
         $usersConfig = JComponentHelper::getParams('com_users');
         $activation = $usersConfig->get('useractivation');
         if ($activation > 0 && !$overrideActivation) {
             $atext = JText::_('AEC_USEND_MSG_ACTIVATE');
             if (defined('JPATH_MANIFESTS')) {
                 $activation_link = JURI::root() . 'index.php?option=com_users&amp;task=registration.activate&amp;token=' . $row->activation;
                 if ($activation == 2) {
                     $atext = JText::_('COM_USERS_MSG_ADMIN_ACTIVATE');
                 }
             } else {
                 $activation_link = JURI::root() . 'index.php?option=com_user&amp;task=activate&amp;activation=' . $row->activation;
             }
             $message = sprintf($atext, $name, $app->getCfg('sitename'), $activation_link, JURI::root(), $username, $savepwd);
         } else {
             $message = sprintf(JText::_('AEC_USEND_MSG'), $name, $app->getCfg('sitename'), JURI::root());
         }
         $message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
         // check if Global Config `mailfrom` and `fromname` values exist
         if ($app->getCfg('mailfrom') != '' && $app->getCfg('fromname') != '') {
             $adminName2 = $app->getCfg('fromname');
             $adminEmail2 = $app->getCfg('mailfrom');
         } else {
             // use email address and name of first superadmin for use in email sent to user
             $rows = xJACLhandler::getSuperAdmins();
             $row2 = $rows[0];
             $adminName2 = $row2->name;
             $adminEmail2 = $row2->email;
         }
         // Send email to user
         if (!($aecConfig->cfg['nojoomlaregemails'] || $overrideEmails)) {
             xJ::sendMail($adminEmail2, $adminEmail2, $email, $subject, $message);
         }
         // Send notification to all administrators
         $aecUser = AECToolbox::aecIP();
         $subject2 = sprintf(JText::_('AEC_SEND_SUB'), $name, $app->getCfg('sitename'));
         $message2 = sprintf(JText::_('AEC_ASEND_MSG_NEW_REG'), $adminName2, $app->getCfg('sitename'), $row->name, $email, $username, $aecUser['ip'], $aecUser['isp']);
         $subject2 = html_entity_decode($subject2, ENT_QUOTES, 'UTF-8');
         $message2 = html_entity_decode($message2, ENT_QUOTES, 'UTF-8');
         // get email addresses of all admins and superadmins set to recieve system emails
         $admins = AECToolbox::getAdminEmailList();
         foreach ($admins as $adminemail) {
             if (!empty($adminemail)) {
                 xJ::sendMail($adminEmail2, $adminEmail2, $adminemail, $subject2, $message2);
             }
         }
     }
     ob_clean();
     // We need the new userid, so we're fetching it from the newly created entry here
     $query = 'SELECT `id`' . ' FROM #__users' . ' WHERE `username` = \'' . $var['username'] . '\'';
     $db->setQuery($query);
     return $db->loadResult();
 }
Exemplo n.º 8
0
 public function addTargetUser($user_ident)
 {
     global $aecConfig;
     if (empty($aecConfig->cfg['checkout_as_gift'])) {
         return false;
     }
     if (!empty($aecConfig->cfg['checkout_as_gift_access'])) {
         $metaUser = new metaUser($this->userid);
         if (!$metaUser->hasGroup($aecConfig->cfg['checkout_as_gift_access'])) {
             return false;
         }
     }
     $queries = array();
     // Try username and name
     $queries[] = 'FROM #__users' . ' WHERE LOWER( `username` ) LIKE \'%' . $user_ident . '%\'';
     // If its not that, how about the user email?
     $queries[] = 'FROM #__users' . ' WHERE LOWER( `email` ) = \'' . $user_ident . '\'';
     // Try to find this as a userid
     $queries[] = 'FROM #__users' . ' WHERE `id` = \'' . $user_ident . '\'';
     // Try to find this as a full name
     $queries[] = 'FROM #__users' . ' WHERE LOWER( `name` ) LIKE \'%' . $user_ident . '%\'';
     foreach ($queries as $base_query) {
         $query = 'SELECT `id`, `username`, `email` ' . $base_query;
         $this->_db->setQuery($query);
         $res = $this->_db->loadObject();
         if (!empty($res)) {
             $this->params['target_user'] = $res->id;
             $this->params['target_username'] = $user_ident;
             return true;
         }
     }
     return false;
 }
 public function applyPlan($user, $processor = 'none', $silent = 0, $multiplicator = 1, $invoice = null, $tempparams = null)
 {
     global $aecConfig;
     $forcelifetime = false;
     if (is_string($multiplicator)) {
         if (strcmp($multiplicator, 'lifetime') === 0) {
             $forcelifetime = true;
         }
     } elseif (is_int($multiplicator) && $multiplicator < 1) {
         $multiplicator = 1;
     }
     if (empty($user)) {
         return false;
     }
     if (is_object($user)) {
         if (is_a($user, 'metaUser')) {
             $metaUser = $user;
         } elseif (is_a($user, 'Subscription')) {
             $metaUser = new metaUser($user->userid);
             $metaUser->focusSubscription = $user;
         }
     } else {
         $metaUser = new metaUser($user);
     }
     if (!isset($this->params['make_primary'])) {
         $this->params['make_primary'] = 1;
     }
     $fstatus = $metaUser->establishFocus($this, $processor, false);
     // TODO: Figure out why $status returns 'existing' - even on a completely fresh subscr
     if ($fstatus != 'existing') {
         $is_pending = $metaUser->focusSubscription->isPending();
         $is_trial = $metaUser->focusSubscription->isTrial();
     } else {
         $is_pending = false;
         $is_trial = $metaUser->focusSubscription->isTrial();
     }
     $comparison = $this->doPlanComparison($metaUser->focusSubscription);
     $renew = $metaUser->is_renewing();
     $lifetime = $metaUser->focusSubscription->lifetime;
     if ($comparison['total_comparison'] === false || $is_pending) {
         // If user is using global trial period he still can use the trial period of a plan
         if ($this->params['trial_period'] > 0 && !$is_trial) {
             $trial = true;
             $value = $this->params['trial_period'];
             $perunit = $this->params['trial_periodunit'];
             $this->params['lifetime'] = 0;
             // We are entering the trial period. The lifetime will come at the renew.
             $amount = $this->params['trial_amount'];
         } else {
             $trial = false;
             $value = $this->params['full_period'];
             $perunit = $this->params['full_periodunit'];
             $amount = $this->params['full_amount'];
         }
     } elseif (!$is_pending) {
         $trial = false;
         $value = $this->params['full_period'];
         $perunit = $this->params['full_periodunit'];
         $amount = $this->params['full_amount'];
     } else {
         return false;
     }
     if ($this->params['lifetime'] || $forcelifetime) {
         $metaUser->focusSubscription->expiration = '9999-12-31 00:00:00';
         $metaUser->focusSubscription->lifetime = 1;
     } else {
         $metaUser->focusSubscription->lifetime = 0;
         $value *= $multiplicator;
         if ($comparison['comparison'] == 2 && !$lifetime) {
             $metaUser->focusSubscription->setExpiration($perunit, $value, 1);
         } else {
             $metaUser->focusSubscription->setExpiration($perunit, $value, 0);
         }
     }
     if ($is_pending) {
         // Is new = set signup date
         $metaUser->focusSubscription->signup_date = date('Y-m-d H:i:s', (int) gmdate('U'));
         if ($this->params['trial_period'] > 0 && !$is_trial) {
             $status = 'Trial';
         } else {
             if ($this->params['full_period'] || $this->params['lifetime']) {
                 if (!isset($this->params['make_active'])) {
                     $status = 'Active';
                 } else {
                     $status = $this->params['make_active'] ? 'Active' : 'Pending';
                 }
             } else {
                 // This should not happen
                 $status = 'Pending';
             }
         }
     } else {
         // Renew subscription - Do NOT set signup_date
         if (!isset($this->params['make_active'])) {
             $status = $trial ? 'Trial' : 'Active';
         } else {
             $status = $this->params['make_active'] ? $trial ? 'Trial' : 'Active' : 'Pending';
         }
     }
     $metaUser->focusSubscription->status = $status;
     $metaUser->focusSubscription->plan = $this->id;
     $metaUser->temporaryRFIX();
     $metaUser->focusSubscription->lastpay_date = date('Y-m-d H:i:s', (int) gmdate('U'));
     $metaUser->focusSubscription->type = $processor;
     if (is_object($invoice)) {
         if (!empty($invoice->params)) {
             $tempparam = array();
             if (!empty($invoice->params['creator_ip'])) {
                 $tempparam['creator_ip'] = $invoice->params['creator_ip'];
             }
             if (!empty($tempparam)) {
                 $metaUser->focusSubscription->addParams($tempparam, 'params', false);
                 $metaUser->focusSubscription->storeload();
             }
         }
     }
     $pp = new PaymentProcessor();
     if ($pp->loadName(strtolower($processor))) {
         $pp->init();
         $pp->getInfo();
         $recurring_choice = null;
         if (is_object($invoice)) {
             if (!empty($invoice->params)) {
                 if (isset($invoice->params["userselect_recurring"])) {
                     $recurring_choice = $invoice->params["userselect_recurring"];
                 }
             }
         }
         // Check whether we have a custome choice set
         if (!is_null($recurring_choice)) {
             $metaUser->focusSubscription->recurring = $pp->is_recurring($recurring_choice);
         } else {
             $metaUser->focusSubscription->recurring = $pp->is_recurring();
         }
     } else {
         $metaUser->focusSubscription->recurring = 0;
     }
     $metaUser->focusSubscription->storeload();
     if (empty($invoice->id)) {
         $invoice = new stdClass();
         $invoice->amount = $amount;
     }
     $exchange = $add = null;
     $result = $this->triggerMIs('action', $metaUser, $exchange, $invoice, $add, $silent);
     if ($result === false) {
         return false;
     } elseif ($result === true) {
         // MIs might have changed the subscription. Reload it.
         $metaUser->focusSubscription->reload();
     }
     if ($this->params['gid_enabled']) {
         $metaUser->instantGIDchange($this->params['gid']);
     }
     $metaUser->focusSubscription->storeload();
     if (!($silent || $aecConfig->cfg['noemails']) || $aecConfig->cfg['noemails_adminoverride']) {
         $adminonly = $this->id == $aecConfig->cfg['entry_plan'] || $aecConfig->cfg['noemails'] && $aecConfig->cfg['noemails_adminoverride'];
         $metaUser->focusSubscription->sendEmailRegistered($renew, $adminonly, $invoice);
     }
     $metaUser->meta->addPlanID($this->id);
     $result = $this->triggerMIs('afteraction', $metaUser, $exchange, $invoice, $add, $silent);
     if ($result === false) {
         return false;
     }
     $this->incrementInventory();
     return $renew;
 }
Exemplo n.º 10
0
 public function expireNow()
 {
     $this->expiration = gmdate('Y-m-d H:i:s', (int) gmdate('U'));
     $metaUser = new metaUser($this->userid);
     $metaUser->killSession();
 }
Exemplo n.º 11
0
 * @package AEC - Account Control Expiration - Subscription component for Joomla! OS CMS
 * @subpackage Module Default Template
 * @copyright 2012 Copyright (C) David Deutsch
 * @author David Deutsch <*****@*****.**> & Team AEC - http://www.valanx.org
 * @license GNU/GPL v.3 http://www.gnu.org/licenses/gpl.html or, at your option, any later version
 */
// Dont allow direct linking
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
?>
<div class="aec_module_inner<?php 
echo $class_sfx;
?>
">
<?php 
echo $pretext;
$metaUser = new metaUser($user->id);
$subscriptions = $metaUser->getAllCurrentSubscriptionsInfo();
if (!empty($subscriptions)) {
    foreach ($subscriptions as $subscription) {
        ?>
			<div class="aec_module_subscription aec_module_subscriptionid_<?php 
        echo $subscription->plan;
        ?>
">
				<h4><?php 
        echo $subscription->name;
        ?>
</h4>
				<?php 
        if ($showExpiration) {
            ?>
Exemplo n.º 12
0
 public function exportMembers()
 {
     $db = JFactory::getDBO();
     foreach ($this->filter as $k => $v) {
         if (empty($v)) {
             $this->filter[$k] = array();
         }
     }
     // Assemble Database call
     if (!in_array('notconfig', $this->filter['status'])) {
         $where = array();
         if (!empty($this->filter['planid'])) {
             $where[] = '`plan` IN (' . implode(',', $this->filter['planid']) . ')';
         }
         $query = 'SELECT a.id, a.userid' . ' FROM #__acctexp_subscr AS a' . ' INNER JOIN #__users AS b ON a.userid = b.id';
         if (!empty($where)) {
             $query .= ' WHERE ( ' . implode(' OR ', $where) . ' )';
         }
         if (!empty($this->filter['status'])) {
             $stati = array();
             foreach ($this->filter['status'] as $status) {
                 $stati[] = 'LOWER( `status` ) = \'' . strtolower($status) . '\'';
             }
             if (!empty($where)) {
                 $query .= ' AND (' . implode(' OR ', $stati) . ')';
             } else {
                 $query .= ' WHERE (' . implode(' OR ', $stati) . ')';
             }
         }
         if (!empty($this->filter['orderby'])) {
             $query .= ' ORDER BY ' . $this->filter['orderby'] . '';
         }
     } else {
         $query = 'SELECT DISTINCT b.id AS `userid`' . ' FROM #__users as b' . ' WHERE b.id NOT IN (' . ' SELECT a.userid' . ' FROM #__acctexp_subscr as a);';
     }
     $db->setQuery($query);
     $descriptions = AECToolbox::rewriteEngineExplain($this->options['rewrite_rule']);
     $descarray = explode(';', $descriptions);
     $this->exphandler->putDescription($descarray);
     // Fetch Userlist
     $userlist = $db->loadObjectList();
     // Plans Array
     $plans = array();
     // Iterate through userlist
     if (!empty($userlist)) {
         foreach ($userlist as $entry) {
             $metaUser = new metaUser($entry->userid);
             if (!empty($entry->id)) {
                 $metaUser->moveFocus($entry->id);
             }
             if ($metaUser->hasSubscription) {
                 $planid = $metaUser->focusSubscription->plan;
                 if (!isset($plans[$planid])) {
                     $plans[$planid] = new SubscriptionPlan();
                     $plans[$planid]->load($planid);
                 }
                 $invoiceid = aecInvoiceHelper::lastClearedInvoiceIDbyUserID($metaUser->userid, $planid);
                 if ($invoiceid) {
                     $invoice = new Invoice();
                     $invoice->load($invoiceid);
                     $line = AECToolbox::rewriteEngine($this->options['rewrite_rule'], $metaUser, $plans[$planid], $invoice);
                 } else {
                     $line = AECToolbox::rewriteEngine($this->options['rewrite_rule'], $metaUser, $plans[$planid]);
                 }
             } else {
                 $line = AECToolbox::rewriteEngine($this->options['rewrite_rule'], $metaUser);
             }
             $larray = explode(';', $line);
             // Remove whitespaces and newlines
             foreach ($larray as $larrid => $larrval) {
                 $larray[$descarray[$larrid]] = trim($larrval);
                 unset($larray[$larrid]);
             }
             $this->exphandler->putln($larray);
         }
     }
 }
Exemplo n.º 13
0
 public function beat()
 {
     $this->processors = array();
     $this->proc_prepare = array();
     $this->result = array('fail_expired' => 0, 'fallback' => 0, 'skipped' => 0, 'expired' => 0, 'pre_expired' => 0, 'pre_exp_actions' => 0);
     // Some cleanup
     $this->deleteTempTokens();
     // Receive maximum pre expiration time
     $pre_expiration = microIntegrationHandler::getMaxPreExpirationTime();
     $subscription_list = $this->getSubscribers($pre_expiration);
     // Efficient way to check for expired users without checking on each one
     if (empty($subscription_list)) {
         return $this->endBeat();
     }
     foreach ($subscription_list as $sid => $sub_id) {
         $subscription = new Subscription();
         $subscription->load($sub_id);
         if (!aecUserHelper::UserExists($subscription->userid)) {
             unset($subscription_list[$sid]);
             continue;
         }
         // Check whether this user really is expired
         // If this check fails, the following subscriptions might still be pre-expiration events
         if ($subscription->isExpired()) {
             // If we don't have any validation response, expire
             $validate = $this->processorValidation($subscription, $subscription_list);
             if ($validate === false) {
                 // There was some kind of fatal error, return.
                 return false;
             } elseif ($validate !== true) {
                 $expire = $subscription->expire();
                 if ($expire) {
                     $this->result['expired']++;
                 } elseif ($expire === false) {
                     $this->result['fail_expired']++;
                 } elseif (is_null($expire)) {
                     $this->result['fallback']++;
                 } else {
                     $this->result['skipped']++;
                 }
             }
             unset($subscription_list[$sid]);
         } elseif (!$subscription->recurring) {
             break;
         }
     }
     // Only go for pre expiration action if we have at least one user for it
     if (empty($pre_expiration) || empty($subscription_list)) {
         return $this->endBeat();
     }
     // Get all the MIs which have a pre expiration check
     $mi_pexp = microIntegrationHandler::getPreExpIntegrations();
     // Find plans which have the MIs assigned
     $expmi_plans = microIntegrationHandler::getPlansbyMI($mi_pexp);
     // Filter out the users which dont have the correct plan
     $query = 'SELECT `id`, `userid`' . ' FROM #__acctexp_subscr' . ' WHERE `id` IN (' . implode(',', $subscription_list) . ')' . ' AND `plan` IN (' . implode(',', $expmi_plans) . ')';
     $this->_db->setQuery($query);
     $sub_list = $this->_db->loadObjectList();
     if (!empty($sub_list)) {
         foreach ($sub_list as $sl) {
             $metaUser = new metaUser($sl->userid);
             $metaUser->moveFocus($sl->id);
             $res = $metaUser->focusSubscription->triggerPreExpiration($metaUser, $mi_pexp);
             if ($res) {
                 $this->result['pre_exp_actions'] += $res;
                 $this->result['pre_expired']++;
             }
         }
     }
     return $this->endBeat();
 }
Exemplo n.º 14
0
function subscribe($option)
{
    $db = JFactory::getDBO();
    $user = JFactory::getUser();
    if (defined('JPATH_MANIFESTS') && !empty($_REQUEST['jform'])) {
        foreach ($_REQUEST['jform'] as $k => $v) {
            $map = array('password1' => 'password', 'email1' => 'email');
            if (isset($map[$k])) {
                $_POST[$map[$k]] = $v;
            } else {
                $_POST[$k] = $v;
            }
        }
    }
    $intro = aecGetParam('intro', 0, true, array('word', 'int'));
    $usage = aecGetParam('usage', 0, true, array('word', 'string', 'clear_nonalnum'));
    $group = aecGetParam('group', 0, true, array('word', 'int'));
    $processor = aecGetParam('processor', '', true, array('word', 'string', 'clear_nonalnum'));
    $userid = aecGetParam('userid', 0, true, array('word', 'int'));
    $username = aecGetParam('username', '', true, array('string', 'clear_nonalnumwhitespace'));
    $email = aecGetParam('email', '', true, array('string', 'clear_nonemail'));
    $token = aecGetParam('aectoken', 0, true, array('string'));
    $forget = aecGetParam('forget', '', true, array('string'));
    $k2mode = false;
    if ($token) {
        $temptoken = new aecTempToken();
        $temptoken->getComposite();
        if (!empty($temptoken->content['handler'])) {
            if ($temptoken->content['handler'] == 'k2') {
                $k2mode = true;
            }
        }
        if (!empty($temptoken->content)) {
            $password = null;
            $details = array();
            if ($forget == 'usage') {
                $details[] = 'usage';
                $details[] = 'processor';
                $details[] = 'recurring';
            }
            if ($forget == 'userdetails') {
                $details[] = 'username';
                $details[] = 'email';
                $details[] = 'password';
                $details[] = 'password2';
            }
            foreach ($temptoken->content as $k => $v) {
                if (!in_array($k, $details)) {
                    ${$k} = $v;
                    $_POST[$k] = $v;
                }
            }
            if (!empty($username)) {
                $query = 'SELECT id' . ' FROM #__users' . ' WHERE username = \'' . $username . '\'';
                $db->setQuery($query);
                $id = $db->loadResult();
                if (!empty($id)) {
                    $userid = $id;
                    $metaUser = new metaUser($id);
                    $metaUser->setTempAuth($password);
                }
            }
        }
    }
    if (!empty($username) && $usage) {
        $CB = aecComponentHelper::detect_component('anyCB');
        $AL = aecComponentHelper::detect_component('ALPHA');
        $JS = aecComponentHelper::detect_component('JOMSOCIAL');
        if (!$AL && !$CB && !$JS && !$k2mode) {
            // Joomla 1.6+ Sanity Check
            if (isset($_POST['email2']) && isset($_POST['email'])) {
                if ($_POST['email2'] !== $_POST['email']) {
                    aecErrorAlert(JText::_('AEC_WARNREG_EMAIL_NOMATCH'));
                    return JText::_('AEC_WARNREG_EMAIL_NOMATCH');
                }
            }
            if (isset($_POST['password2']) && isset($_POST['password'])) {
                if ($_POST['password2'] !== $_POST['password']) {
                    aecErrorAlert(JText::_('AEC_WARNREG_PASSWORD_NOMATCH'));
                    return JText::_('AEC_WARNREG_PASSWORD_NOMATCH');
                }
            }
            // Joomla 1.5 Sanity Check
            // Get required system objects
            $user = clone JFactory::getUser();
            $duplicationcheck = checkUsernameEmail($username, $email);
            $usertype = JRequest::get('post');
            // Bind the post array to the user object
            if (!$user->bind($usertype, 'usertype') || $duplicationcheck !== true) {
                $binderror = $user->getError();
                if (!empty($binderror)) {
                    JError::raiseError(500, $user->getError());
                } else {
                    JError::raiseError(500, $duplicationcheck);
                }
                unset($_POST);
                subscribe($option);
                return false;
            }
            JRequest::checkToken() or die('Invalid Token');
        } elseif (empty($token)) {
            if (isset($_POST['username']) && isset($_POST['email'])) {
                $check = checkUsernameEmail($username, $email);
                if ($check !== true) {
                    return $check;
                }
            }
        }
        $iFactory = new InvoiceFactory($userid, $usage, $group, $processor);
        $iFactory->confirm();
    } else {
        if ($user->id) {
            $userid = $user->id;
            $passthrough = array();
        } elseif (!empty($userid) && !isset($_POST['username'])) {
            $passthrough = array();
        } elseif (empty($userid)) {
            if (!empty($_POST['username']) && !empty($_POST['email'])) {
                $check = checkUsernameEmail($username, $email);
                if ($check !== true) {
                    return $check;
                }
            }
            $nopass = array('option', 'task', 'intro', 'usage', 'group', 'processor', 'recurring', 'Itemid', 'submit_x', 'submit_y', 'userid', 'id', 'gid');
            $passthrough = array();
            foreach ($_POST as $k => $v) {
                if (in_array($k, $nopass)) {
                    unset($_POST[$k]);
                } else {
                    $passthrough[$k] = $v;
                }
            }
        }
        if (!empty($userid)) {
            $passthrough['userid'] = $userid;
            $password = aecGetParam('password', '', true, array('string'));
            if (!empty($password)) {
                $passthrough['password'] = $password;
            }
        }
        $iFactory = new InvoiceFactory($userid, $usage, $group, $processor, null, $passthrough, false);
        if (!$iFactory->authed) {
            if (!$iFactory->checkAuth()) {
                return false;
            }
        }
        if (!empty($iFactory->passthrough['invoice'])) {
            repeatInvoice($option, $iFactory->passthrough['invoice'], null, $userid);
        } else {
            $iFactory->create($intro, $usage, $group, $processor, 0);
        }
    }
}