Пример #1
0
 public function getItem($pk = null)
 {
     $id = $pk ? $pk : $this->getState($this->getName() . '.id');
     // $item = parent::getItem($id);
     // if transaction is made and user is not created
     $transaction = JTable::getInstance('Transaction', 'RSMembershipTable');
     $transaction->load($id);
     /// get the user data
     $data = $transaction->user_data ? (object) unserialize($transaction->user_data) : (object) array();
     if (!$transaction->user_id) {
         $user = (object) array('id' => 0, 'username' => isset($data->username) && !empty($data->username) ? $data->username : JText::_('COM_RSMEMBERSHIP_SUBSCRIBERNAME_EMPTY'), 'name' => isset($data->name) ? $data->name : '', 'email' => $transaction->user_email);
     } else {
         $user = JFactory::getUser($transaction->user_id);
     }
     $params = RSMembershipHelper::parseParams($transaction->params);
     $membership_id = 0;
     if (isset($params['membership_id'])) {
         $membership_id = $params['membership_id'];
     }
     if (isset($params['to_id'])) {
         $membership_id = $params['to_id'];
     }
     $membership_info = array();
     if ($membership_id) {
         if ($membership_fields = RSMembership::getCustomMembershipFields($membership_id)) {
             $selected = isset($data->membership_fields) ? $data->membership_fields : array();
             foreach ($membership_fields as $field) {
                 $membership_info[] = RSMembershipHelper::showCustomField($field, $selected, false, false, 'membership');
             }
         }
     }
     $item = (object) array('user_id' => $user->id, 'username' => $user->username, 'email' => $user->email, 'name' => $user->name, 'transaction' => $id, 'transaction_data' => $transaction, 'membership_info' => $membership_info);
     return $item;
 }
Пример #2
0
 protected function getPlaceholders($type)
 {
     $placeholders = array();
     switch ($type) {
         case 'thankyou':
             $placeholders = array('{membership}', '{extras}', '{email}', '{name}', '{username}', '{continue}', '{price}', '{coupon}', '{payment}', '{transaction_id}');
             break;
         case 'admin_email_new':
         case 'admin_email_renew':
         case 'admin_email_addextra':
         case 'user_email_new':
         case 'user_email_renew':
         case 'user_email_addextra':
             $placeholders = array('{membership}', '{extras}', '{email}', '{name}', '{username}', '{price}', '{coupon}', '{payment}', '{transaction_id}');
             break;
         case 'admin_email_upgrade':
         case 'user_email_upgrade':
             $placeholders = array('{membership}', '{membership_from}', '{extras}', '{email}', '{name}', '{username}', '{price}', '{coupon}', '{payment}', '{transaction_id}');
             break;
         case 'admin_email_expire':
         case 'user_email_expire':
             $placeholders = array('{membership}', '{membership_end}', '{extras}', '{email}', '{name}', '{username}', '{interval}');
             break;
         case 'admin_email_denied':
         case 'user_email_denied':
             $placeholders = array('{membership}', '{email}', '{username}', '{name}', '{price}', '{coupon}', '{payment}', '{transaction_id}');
             break;
         case 'admin_email_approved':
         case 'user_email_approved':
             $placeholders = array('{membership}', '{price}', '{extras}', '{email}', '{username}', '{name}', '{membership_start}', '{membership_end}', '{transaction_id}', '{transaction_hash}');
             break;
     }
     // Get cached custom fields
     static $fields = array();
     static $membership_fields = array();
     if (!$fields) {
         $fields = RSMembership::getCustomFields();
     }
     if (!$membership_fields) {
         $membership_fields = RSMembership::getCustomMembershipFields($this->item->id);
     }
     // Add custom fields
     foreach ($fields as $field) {
         $placeholders[] = '{' . $field->name . '}';
     }
     // Add membership fields
     foreach ($membership_fields as $membership_field) {
         $placeholders[] = '{' . $membership_field->name . '}';
     }
     return implode(', ', $placeholders);
 }
Пример #3
0
 public function renewPaymentRedirect()
 {
     //$payment = JFactory::getApplication()->input->get('payment', 'none', 'string');
     $jinput = JFactory::getApplication()->input;
     $payment = $jinput->get('payment', 'none', 'string');
     $cid = $jinput->get('cid', 0, 'int');
     $model = $this->getModel('renew');
     $membership = $model->getMembership();
     $all_fields = RSMembership::getCustomFields();
     $membership_fields = RSMembership::getCustomMembershipFields($membership->id);
     $all_fields = array_merge($all_fields, $membership_fields);
     if (count($all_fields)) {
         $verifyFieldsMembership = $jinput->get('rsm_membership_fields', array(), 'array');
         $verifyFieldsUser = $jinput->get('rsm_fields', array(), 'array');
         $verifyFields = array_merge($verifyFieldsUser, $verifyFieldsMembership);
         $fields = $all_fields;
         foreach ($fields as $field) {
             if ($field->required && empty($verifyFields[$field->name]) || $field->rule && !empty($verifyFields[$field->name]) && is_callable('RSMembershipValidation', $field->rule) && !call_user_func(array('RSMembershipValidation', $field->rule), $verifyFields[$field->name])) {
                 $message = JText::_($field->validation);
                 if (empty($message)) {
                     $message = JText::sprintf('COM_RSMEMBERSHIP_VALIDATION_DEFAULT_ERROR', JText::_($field->label));
                 }
                 JError::raiseWarning(500, $message);
                 return $this->setRedirect(JRoute::_('index.php?option=com_rsmembership&task=renew&cid=' . $cid, false));
             }
         }
         $model->storeData(array('membership_fields' => $verifyFieldsMembership, 'custom_fields' => $verifyFieldsUser));
     }
     $this->setRedirect(JRoute::_('index.php?option=com_rsmembership&task=renewpayment&payment=' . $payment, false));
 }
Пример #4
0
 public function checkMembershipFields($verifyFields, $last_transaction_id, $membership_id)
 {
     if (count($verifyFields)) {
         require_once JPATH_ADMINISTRATOR . '/components/com_rsmembership/helpers/validation.php';
         $membership_fields = RSMembership::getCustomMembershipFields($membership_id);
         if (count($membership_fields)) {
             $fields = $membership_fields;
             foreach ($fields as $field) {
                 if ($field->required && empty($verifyFields[$field->name]) || $field->rule && is_callable('RSMembershipValidation', $field->rule) && !call_user_func(array('RSMembershipValidation', $field->rule), $verifyFields[$field->name])) {
                     $message = JText::_($field->validation);
                     if (empty($message)) {
                         $message = JText::sprintf('COM_RSMEMBERSHIP_VALIDATION_DEFAULT_ERROR', JText::_($field->label));
                     }
                     return $message;
                 }
             }
         }
     }
     return '';
 }
Пример #5
0
 public function bindData($data)
 {
     $membership = $this->getMembership();
     $db =& $this->db;
     $user = JFactory::getUser();
     $guest = $user->guest;
     // Create the empty data
     $this->data = new stdClass();
     // Bind username
     if (RSMembershipHelper::getConfig('choose_username')) {
         $username = isset($data['username']) ? $data['username'] : '';
         if ($guest) {
             if (empty($username) || strlen(utf8_decode($username)) < 2) {
                 $this->setError(JText::_('COM_RSMEMBERSHIP_PLEASE_TYPE_USERNAME'));
                 return false;
             }
             $query = $db->getQuery(true);
             $query->select($db->qn('id'))->from($db->qn('#__users'))->where($db->qn('username') . ' = ' . $db->q($username));
             $db->setQuery($query);
             if ($db->loadResult()) {
                 $this->setError(JText::_('COM_RSMEMBERSHIP_USERNAME_NOT_OK'));
                 return false;
             }
         }
         $this->data->username = $guest ? $username : $user->username;
     }
     // Bind password
     if (RSMembershipHelper::getConfig('choose_password')) {
         $password = isset($data['password']) ? $data['password'] : '';
         $password2 = isset($data['password2']) ? $data['password2'] : '';
         if ($guest) {
             $version = new JVersion();
             // 3.x password strength
             if ($version->isCompatible('3.1.4')) {
                 JFactory::getLanguage()->load('com_users', JPATH_SITE);
                 $rule = JFormHelper::loadRuleType('password');
                 $field = new SimpleXMLElement('<field></field>');
                 if (!$rule->test($field, $password)) {
                     return false;
                 }
             } else {
                 if (!strlen($password)) {
                     $this->setError(JText::_('COM_RSMEMBERSHIP_PLEASE_TYPE_PASSWORD'));
                     return false;
                 } elseif (strlen($password) < 6) {
                     $this->setError(JText::_('COM_RSMEMBERSHIP_PLEASE_TYPE_PASSWORD_6'));
                     return false;
                 }
             }
             if ($password != $password2) {
                 $this->setError(JText::_('COM_RSMEMBERSHIP_PLEASE_CONFIRM_PASSWORD'));
                 return false;
             }
         }
         $this->data->password = $guest ? md5($password) : '';
     }
     // Bind email
     $email = isset($data['email']) ? $data['email'] : '';
     if ($guest) {
         jimport('joomla.mail.helper');
         if (empty($email) || !JMailHelper::isEmailAddress($email)) {
             $this->setError(JText::_('COM_RSMEMBERSHIP_PLEASE_TYPE_EMAIL'));
             return false;
         }
     }
     $this->data->email = $guest ? $email : $user->email;
     // Bind name
     $name = isset($data['name']) ? $data['name'] : '';
     if ($guest && empty($name)) {
         $this->setError(JText::_('COM_RSMEMBERSHIP_PLEASE_TYPE_NAME'));
         return false;
     }
     $this->data->name = $guest ? $name : $user->name;
     $sentFields = isset($data['fields']) ? $data['fields'] : array();
     $sentMembershipFields = isset($data['membership_fields']) ? $data['membership_fields'] : array();
     if (isset($data['membership_fields'])) {
         $verifyFields = array_merge($sentFields, $sentMembershipFields);
     }
     $fields = RSMembership::getCustomFields();
     $membership_fields = RSMembership::getCustomMembershipFields($membership->id);
     $fields = array_merge($fields, $membership_fields);
     foreach ($fields as $field) {
         if ($field->required && empty($verifyFields[$field->name]) || $field->rule && !empty($verifyFields[$field->name]) && is_callable('RSMembershipValidation', $field->rule) && !call_user_func(array('RSMembershipValidation', $field->rule), $verifyFields[$field->name])) {
             $message = JText::_($field->validation);
             if (empty($message)) {
                 $message = JText::sprintf('COM_RSMEMBERSHIP_VALIDATION_DEFAULT_ERROR', JText::_($field->label));
             }
             $this->setError($message);
             return false;
         }
     }
     $this->data->fields = $sentFields;
     $this->data->membership_fields = $sentMembershipFields;
     // Bind an empty coupon for legacy reasons
     $this->data->coupon = '';
     return true;
 }
Пример #6
0
 public static function sendNotifications($memberships, $cid = null, $resend = false)
 {
     // Get custom fields
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $date = JFactory::getDate();
     $fields = RSMembership::getCustomFields();
     $config = RSMembershipConfig::getInstance();
     $update_ids = array();
     foreach ($memberships as $membership) {
         $date = JFactory::getDate();
         $interval = $membership->expire_notify_interval;
         $date->modify("+{$interval} days");
         // Select all the subscriptions that match (about to expire)
         $query->clear();
         $query->select($db->qn('u.id', 'user_id'))->select($db->qn('u.email', 'user_email'))->select($db->qn('u.name', 'user_name'))->select($db->qn('u.username', 'user_username'))->select($db->qn('mu.id', 'muid'))->select($db->qn('mu.extras'))->select($db->qn('mu.membership_end'))->select($db->qn('mu.from_transaction_id'))->from($db->qn('#__rsmembership_membership_subscribers', 'mu'))->join('left', $db->qn('#__users', 'u') . ' ON ' . $db->qn('mu.user_id') . ' = ' . $db->qn('u.id'))->where($db->qn('mu.status') . ' = ' . $db->q(MEMBERSHIP_STATUS_ACTIVE))->where($db->qn('mu.published') . ' = ' . $db->q(1));
         if (!$resend) {
             $query->where($db->qn('mu.notified') . ' = ' . $db->q($db->getNullDate()));
         }
         $query->where($db->qn('mu.membership_end') . ' != ' . $db->q($db->getNulldate()))->where($db->qn('mu.membership_end') . ' < ' . $db->q($date->toSql()))->where($db->qn('mu.membership_id') . ' = ' . $db->q($membership->id));
         if ($cid != null && is_array($cid) && count($cid) > 0) {
             $ids = implode($db->q(','), $cid);
             $query->where($db->qn('mu.id') . ' IN (' . $ids . ')');
         }
         $db->setQuery($query, 0, $config->get('expire_emails'));
         $results = $db->loadObjectList();
         // No results, next membership
         if (empty($results)) {
             continue;
         }
         $now = JFactory::getDate()->toUnix();
         $sentToUser = false;
         $sentToAdmin = false;
         foreach ($results as $result) {
             $extras = '';
             // Performance check
             if ($result->extras && (strpos($membership->user_email_expire_text . $membership->user_email_expire_subject, '{extras}') !== false || strpos($membership->admin_email_expire_text . $membership->admin_email_expire_subject, '{extras}') !== false)) {
                 $extras = RSMembershipHelper::getExtrasNames($result->extras);
             }
             $expireDate = JFactory::getDate($result->membership_end);
             $expireIn = ceil(($expireDate->toUnix() - $now) / 86400);
             $placeholders = array('{membership}' => $membership->name, '{membership_end}' => RSMembershipHelper::showDate($result->membership_end), '{extras}' => $extras, '{email}' => $result->user_email, '{name}' => $result->user_name, '{username}' => $result->user_username, '{interval}' => $expireIn);
             $replace = array_keys($placeholders);
             $with = array_values($placeholders);
             $query->clear();
             $query->select('*')->from($db->qn('#__rsmembership_subscribers'))->where($db->qn('user_id') . ' = ' . $db->q($result->user_id));
             $db->setQuery($query);
             $user_data_tmp = $db->loadObject();
             $user_data = array();
             foreach ($fields as $field) {
                 $field_id = 'f' . $field->id;
                 $user_data[$field->name] = isset($user_data_tmp->{$field_id}) ? $user_data_tmp->{$field_id} : '';
             }
             unset($user_data_tmp);
             foreach ($fields as $field) {
                 $name = $field->name;
                 $replace[] = '{' . $name . '}';
                 if (isset($user_data[$name])) {
                     $with[] = is_array($user_data[$name]) ? implode("\n", $user_data[$name]) : $user_data[$name];
                 } else {
                     $with[] = '';
                 }
             }
             $membership_fields = RSMembership::getCustomMembershipFields($membership->id);
             $transaction_user_data = RSMembership::getUserData($result->from_transaction_id);
             foreach ($membership_fields as $field) {
                 $name = $field->name;
                 $replace[] = '{' . $name . '}';
                 if (isset($transaction_user_data->membership_fields[$name])) {
                     $with[] = is_array($transaction_user_data->membership_fields[$name]) ? implode("\n", $transaction_user_data->membership_fields[$name]) : $transaction_user_data->membership_fields[$name];
                 } else {
                     $with[] = '';
                 }
             }
             $jconfig = JFactory::getConfig();
             if ($membership->user_email_expire_subject) {
                 $message = str_replace($replace, $with, $membership->user_email_expire_text);
                 // from address
                 $from = $membership->user_email_use_global ? $jconfig->get('mailfrom') : $membership->user_email_from_addr;
                 // from name
                 $fromName = $membership->user_email_use_global ? $jconfig->get('fromname') : $membership->user_email_from;
                 // recipient
                 $recipient = $result->user_email;
                 // user email
                 // subject
                 $subject = str_replace($replace, $with, $membership->user_email_expire_subject);
                 // body
                 $body = $message;
                 // mode
                 $mode = $membership->user_email_mode;
                 // cc
                 $cc = null;
                 // bcc
                 $bcc = null;
                 // attachments
                 $query->clear();
                 $query->select($db->qn('path'))->from($db->qn('#__rsmembership_membership_attachments'))->where($db->qn('membership_id') . ' = ' . $db->q($membership->id))->where($db->qn('email_type') . ' = ' . $db->q('user_email_expire'))->where($db->qn('published') . '=' . $db->q('1'))->order($db->qn('ordering') . ' ASC');
                 $db->setQuery($query);
                 $attachment = $db->loadColumn();
                 // reply to
                 $replyto = $from;
                 // reply to name
                 $replytoname = $fromName;
                 // send to user
                 RSMembershipHelper::sendMail($from, $fromName, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);
                 $sentToUser = true;
                 self::syslog('expiry-notification', "Membership: " . $membership->name . " (" . $membership->id . ") | Email sent to {$recipient} (Subject: {$subject})");
             }
             // admin emails
             if ($membership->admin_email_expire_subject) {
                 $message = str_replace($replace, $with, $membership->admin_email_expire_text);
                 // from address
                 $from = trim($membership->admin_email_from_addr) != '' ? $membership->admin_email_from_addr : $result->user_email;
                 // from name
                 $fromName = $result->user_name;
                 // recipient
                 $recipient = $membership->admin_email_to_addr;
                 // subject
                 $subject = str_replace($replace, $with, $membership->admin_email_expire_subject);
                 // body
                 $body = $message;
                 // mode
                 $mode = $membership->admin_email_mode;
                 // cc
                 $cc = null;
                 // bcc
                 $bcc = null;
                 // attachments
                 $attachment = null;
                 // reply to
                 $replyto = $from;
                 // reply to name
                 $replytoname = $fromName;
                 // send to admin
                 if ($subject != '') {
                     RSMembershipHelper::sendMail($from, $fromName, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);
                     $sentToAdmin = true;
                     self::syslog('expiry-notification', "Membership: " . $membership->name . " (" . $membership->id . ") | Admin email sent to {$recipient} (Subject: {$subject})");
                 }
             }
             if ($sentToUser || $sentToAdmin) {
                 $update_ids[] = $result->muid;
             }
         }
     }
     if (!empty($update_ids)) {
         $query->clear();
         $query->update($db->qn('#__rsmembership_membership_subscribers'))->set($db->qn('notified') . ' = ' . $db->q($date->toSql()))->where($db->qn('id') . ' IN (\'' . implode($db->q(','), $update_ids) . '\')');
         $db->setQuery($query);
         $db->execute();
         return true;
     } else {
         return false;
     }
 }
Пример #7
0
 public static function getFieldsValidation($membership_id = null, $upgrade = null)
 {
     $return = array();
     if (is_null($upgrade)) {
         $fields = RSMembership::getCustomFields(array('published' => 1, 'required' => 1));
     } else {
         $fields = array();
     }
     if (!is_null($membership_id)) {
         $membership_fields = RSMembership::getCustomMembershipFields($membership_id, array('published' => 1, 'required' => 1));
         $fields = array_merge($fields, $membership_fields);
     }
     foreach ($fields as $field) {
         $js = '';
         switch ($field->type) {
             case 'select':
             case 'multipleselect':
             case 'textarea':
             case 'textbox':
             case 'calendar':
                 $element = 'rsm_' . $field->name;
                 $js .= "if (document.getElementById('" . $element . "').value.length == 0)" . "\n";
                 break;
             case 'checkbox':
             case 'radio':
                 $field->values = RSMembershipHelper::isCode($field->values);
                 $field->values = str_replace("\r\n", "\n", $field->values);
                 $field->values = explode("\n", $field->values);
                 $ids = array();
                 foreach ($field->values as $i => $value) {
                     $element = 'rsm_field_' . $field->id . '_' . $i;
                     $ids[] = "!document.getElementById('" . $element . "').checked";
                 }
                 $element = '';
                 $js .= "if (" . implode(" && ", $ids) . ")" . "\n";
                 break;
         }
         $validation_message = JText::_($field->validation);
         if (empty($validation_message)) {
             $validation_message = JText::sprintf('COM_RSMEMBERSHIP_VALIDATION_DEFAULT_ERROR', JText::_($field->label));
         }
         $validation_message = str_replace(array("\r\n", "\r"), "\n", $validation_message);
         $validation_message = str_replace("\n", '\\n', $validation_message);
         $js .= "{\n";
         $js .= "msg.push('" . JText::_($validation_message, true) . "');" . "\n";
         if (@$element) {
             $js .= "document.getElementById('" . $element . "').className += ' rsm_field_error';\n";
         }
         $js .= "}\n";
         $return[] = $js;
     }
     return $return;
 }