Beispiel #1
0
 protected function updateMemberships()
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $config = RSMembershipConfig::getInstance();
     $date = JFactory::getDate();
     $unixDate = $date->toUnix();
     if ($config->get('last_check') + $config->get('interval') * 60 > $unixDate) {
         return;
     }
     // update config value Last Check
     $config->set('last_check', $unixDate);
     $offset = $config->get('delete_pending_after');
     if ($offset < 1) {
         $offset = 1;
     }
     $offset = $offset * 3600;
     // delete pending transactions
     $date->modify("-{$offset} seconds");
     $query->delete()->from($db->qn('#__rsmembership_transactions'))->where($db->qn('status') . ' = ' . $db->q('pending'))->where($db->qn('date') . ' < ' . $db->q($date->toSql()));
     $db->setQuery($query);
     $db->execute();
     $query->clear();
     // Limit 10 so we don't overload the server
     $query->select($db->qn('mu.id'))->select($db->qn('m.gid_enable'))->select($db->qn('m.gid_expire'))->select($db->qn('m.disable_expired_account'))->select($db->qn('mu.user_id'))->from($db->qn('#__rsmembership_membership_subscribers', 'mu'))->join('left', $db->qn('#__rsmembership_memberships', 'm') . ' ON ' . $db->qn('mu.membership_id') . ' = ' . $db->qn('m.id'))->where($db->qn('mu.status') . ' = ' . $db->q('0'))->where($db->qn('mu.membership_end') . ' != ' . $db->q($db->getNullDate()))->where($db->qn('mu.membership_end') . ' < ' . $db->q(JFactory::getDate()->toSql()));
     $db->setQuery($query, 0, 10);
     $updates = $db->loadObjectList('id');
     $query->clear();
     $to_update = array_keys($updates);
     if (!empty($to_update)) {
         $query->update($db->qn('#__rsmembership_membership_subscribers'))->set($db->qn('status') . ' = ' . $db->q(MEMBERSHIP_STATUS_EXPIRED))->where($db->qn('id') . ' IN (\'' . implode($db->q(','), $to_update) . '\')');
         $db->setQuery($query);
         $db->execute();
         $query->clear();
     }
     foreach ($updates as $update) {
         if ($update->gid_enable) {
             RSMembership::updateGid($update->user_id, $update->gid_expire, false, 'remove');
         }
         if ($update->disable_expired_account) {
             // Do not disable the user if he has active subscriptions.
             list($memberships, $extras) = RSMembershipHelper::getUserSubscriptions($update->user_id);
             if (!$memberships) {
                 RSMembership::disableUser($update->user_id);
             }
         }
     }
 }
 function onAfterInitialise()
 {
     if (class_exists('RSMembershipHelper')) {
         $this->loadLanguage('plg_system_rsmembership');
         $db = JFactory::getDBO();
         $date = JFactory::getDate();
         $date = $date->toUnix();
         if (RSMembershipHelper::getConfig('last_check') + RSMembershipHelper::getConfig('interval') * 60 > $date) {
             return;
         }
         $db->setQuery("UPDATE #__rsmembership_configuration SET value='" . $date . "' WHERE name='last_check' LIMIT 1");
         $db->query();
         $offset = RSMembershipHelper::getConfig('delete_pending_after');
         if ($offset < 1) {
             $offset = 1;
         }
         $offset = $offset * 3600;
         $db->setQuery("DELETE FROM #__rsmembership_transactions WHERE `status`='pending' AND `date` < '" . ($date - $offset) . "'");
         $db->query();
         // Limit 10 so we don't overload the server
         $db->setQuery("SELECT mu.id, m.gid_enable, m.gid_expire, m.disable_expired_account, mu.user_id FROM #__rsmembership_membership_users mu LEFT JOIN #__rsmembership_memberships m ON (mu.membership_id=m.id) WHERE  mu.`status`='0' AND mu.`membership_end` > 0 AND mu.`membership_end` < '" . $date . "' LIMIT 10");
         $updates = $db->loadObjectList();
         $to_update = array();
         foreach ($updates as $update) {
             $to_update[] = $update->id;
             if ($update->gid_enable) {
                 RSMembership::updateGid($update->user_id, $update->gid_expire);
             }
             if ($update->disable_expired_account) {
                 RSMembership::disableUser($update->user_id);
             }
         }
         if (!empty($to_update)) {
             $db->setQuery("UPDATE #__rsmembership_membership_users SET `status`='2' WHERE `id` IN (" . implode(',', $to_update) . ")");
             $db->query();
         }
         RSMembershipHelper::checkShared();
         RSMembershipHelper::sendExpirationEmails();
     }
 }
Beispiel #3
0
 public function save($data)
 {
     $membership_fields = JRequest::getVar('rsm_membership_fields', array(), 'post', 'array');
     $last_transaction_id = JRequest::getVar('last_transaction_id', '', 'post');
     if (count($membership_fields)) {
         $transaction = JTable::getInstance('Transaction', 'RSMembershipTable');
         $transaction->load($last_transaction_id);
         $user_data = $transaction->user_data ? (object) unserialize($transaction->user_data) : (object) array();
         $user_data->membership_fields = $membership_fields;
         $transaction->user_data = serialize($user_data);
         if ($transaction->check()) {
             $transaction->store();
         }
     }
     if (!isset($data['extras'])) {
         $data['extras'] = '';
     } else {
         $data['extras'] = implode(',', $data['extras']);
     }
     // Updating ? Make sure we check the status
     if ($data['id']) {
         $current = $this->getTable();
         $current->load($data['id']);
         if ($current->status == MEMBERSHIP_STATUS_ACTIVE && $data['status'] != MEMBERSHIP_STATUS_ACTIVE) {
             $data['notified'] = 0;
         }
     }
     // Handle dates
     $offset = JFactory::getApplication()->getCfg('offset');
     $data['membership_start'] = JFactory::getDate($data['membership_start'], $offset)->toSql();
     if (isset($data['unlimited'])) {
         $data['membership_end'] = JFactory::getDbo()->getNullDate();
         unset($data['unlimited']);
     } else {
         $data['membership_end'] = JFactory::getDate($data['membership_end'], $offset)->toSql();
     }
     $result = parent::save($data);
     // Save was successful
     if ($result) {
         $membership = JTable::getInstance('Membership', 'RSMembershipTable');
         $membership->load($data['membership_id']);
         if ($data['status'] == MEMBERSHIP_STATUS_ACTIVE) {
             if ($membership->gid_enable) {
                 RSMembership::updateGid($data['user_id'], $membership->gid_subscribe, true);
             }
             if ($membership->disable_expired_account) {
                 RSMembership::enableUser($data['user_id']);
             }
         } elseif ($data['status'] == MEMBERSHIP_STATUS_EXPIRED || $data['status'] == MEMBERSHIP_STATUS_CANCELLED) {
             if ($membership->gid_enable) {
                 RSMembership::updateGid($data['user_id'], $membership->gid_expire, false, 'remove');
             }
             if ($membership->disable_expired_account) {
                 RSMembership::disableUser($data['user_id']);
             }
         }
     }
     return $result;
 }
 function cancel()
 {
     $user = JFactory::getUser();
     $id = $user->get('id');
     $cid = $this->getCid();
     $this->_db->setQuery("SELECT * FROM #__rsmembership_transactions WHERE `id`='" . $this->_data->from_transaction_id . "'");
     $transaction = $this->_db->loadObject();
     $this->_db->setQuery("SELECT * FROM #__rsmembership_memberships WHERE `id`='" . $this->_data->membership_id . "'");
     $membership = $this->_db->loadObject();
     if ($transaction->gateway == 'Authorize.Net') {
         $className = 'plgSystemRSMembershipAuthorize';
         if (class_exists($className)) {
             $dispatcher =& JDispatcher::getInstance();
             $plugin = new $className($dispatcher, array());
             $args = array('plugin' => 'rsmembershipauthorize', 'data' => &$this->_data, 'membership' => $membership, 'transaction' => &$transaction);
             if (method_exists($plugin, 'onMembershipCancelPayment')) {
                 call_user_func_array(array($plugin, 'onMembershipCancelPayment'), $args);
             }
         }
     }
     $this->_db->setQuery("UPDATE #__rsmembership_membership_users SET `status`='3' WHERE `id`='" . $cid . "' LIMIT 1");
     $this->_db->query();
     if ($membership->gid_enable) {
         RSMembership::updateGid($user->get('id'), $membership->gid_expire);
     }
     if ($membership->disable_expired_account) {
         RSMembership::disableUser($user->get('id'));
         $mainframe =& JFactory::getApplication();
         $mainframe->logout();
     }
 }
Beispiel #5
0
 public function cancel()
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $id = $this->user->id;
     $cid = $this->getCid();
     $transaction = JTable::getInstance('Transaction', 'RSMembershiptable');
     $transaction->load($this->_data->from_transaction_id);
     $membership = JTable::getInstance('Membership', 'RSMembershiptable');
     $membership->load($this->_data->membership_id);
     $plugins = RSMembership::getPlugins();
     // Keep a legacy mode for Authorize.net
     if (in_array($transaction->gateway, $plugins) || $transaction->gateway == 'Authorize.Net') {
         $plugin = array_search($transaction->gateway, $plugins);
         if ($plugin === false) {
             $plugin = 'rsmembershipauthorize';
         }
         $args = array('plugin' => $plugin, 'data' => &$this->_data, 'membership' => $membership, 'transaction' => &$transaction);
         JFactory::getApplication()->triggerEvent('onMembershipCancelPayment', $args);
     }
     $query->clear();
     $query->update($db->qn('#__rsmembership_membership_subscribers'))->set($db->qn('status') . ' = ' . $db->q('3'))->where($db->qn('id') . ' = ' . $db->q($cid));
     $db->setQuery($query);
     $db->execute();
     if (!is_array($membership->gid_expire)) {
         $membership->gid_expire = explode(',', $membership->gid_expire);
     }
     if ($membership->gid_enable) {
         RSMembership::updateGid($id, $membership->gid_expire, false, 'remove');
     }
     if ($membership->disable_expired_account) {
         list($memberships, $extras) = RSMembershipHelper::getUserSubscriptions($id);
         if (!$memberships) {
             RSMembership::disableUser($id);
             $app = JFactory::getApplication();
             $app->logout();
         }
     }
 }
Beispiel #6
0
 function membershipSave()
 {
     $row =& JTable::getInstance('RSMembership_Membership_Users', 'Table');
     $post = JRequest::get('post', JREQUEST_ALLOWHTML);
     if (!empty($post['noextra'])) {
         $post['extras'] = '';
     } elseif (isset($post['extras'])) {
         $post['extras'] = implode(',', $post['extras']);
     }
     if (!empty($post['unlimited'])) {
         $post['membership_end'] = 0;
     }
     if (!$row->bind($post)) {
         return JError::raiseWarning(500, $row->getError());
     }
     // Updating ?
     if ($row->id > 0) {
         $this->_db->setQuery("SELECT status FROM #__rsmembership_membership_users WHERE id='" . (int) $row->id . "'");
         $status = $this->_db->loadResult();
         if ($status > 0 && $row->status == 0) {
             $row->notified = 0;
         }
     }
     $this->_db->setQuery("SELECT gid_enable, gid_subscribe, gid_expire, disable_expired_account FROM #__rsmembership_memberships WHERE `id`='" . (int) $row->membership_id . "'");
     $membership = $this->_db->loadObject();
     if ($row->status == 0) {
         if ($membership->gid_enable) {
             RSMembership::updateGid($row->user_id, $membership->gid_subscribe, true);
         }
     } else {
         if ($membership->gid_enable) {
             RSMembership::updateGid($row->user_id, $membership->gid_expire);
         }
         if (($row->status == 2 || $row->status == 3) && $membership->disable_expired_account) {
             RSMembership::disableUser($row->user_id);
         }
     }
     if (strpos($row->membership_start, '.') !== false) {
         unset($row->membership_start);
     }
     if (strpos($row->membership_end, '.') !== false) {
         unset($row->membership_end);
     }
     if ($row->store()) {
         $this->_id = $row->id;
         return true;
     } else {
         JError::raiseWarning(500, $row->getError());
         return false;
     }
 }