示例#1
0
 function display($tpl = null)
 {
     $db = JFactory::getDbo();
     $item = $this->get('Data');
     //Get list of subscription records
     $sql = 'SELECT a.*, b.title AS plan_title, b.lifetime_membership, b.enable_renewal, b.recurring_subscription' . ' FROM #__osmembership_subscribers  AS a' . ' INNER JOIN #__osmembership_plans AS b' . ' ON a.plan_id = b.id' . ' WHERE a.profile_id=' . $item->id . ' ORDER BY a.id DESC ';
     $db->setQuery($sql);
     $items = $db->loadObjectList();
     //Form fields
     $rowFields = OSMembershipHelper::getProfileFields(0, true, $item->language);
     $data = OSMembershipHelper::getProfileData($item, 0, $rowFields);
     $form = new RADForm($rowFields);
     $form->setData($data)->bindData();
     //Trigger third party add-on
     JPluginHelper::importPlugin('osmembership');
     $dispatcher = JDispatcher::getInstance();
     //Trigger plugins
     $results = $dispatcher->trigger('onProfileDisplay', array($item));
     $this->item = $item;
     $this->config = OSMembershipHelper::getConfig();
     $this->plugins = $results;
     $this->items = $items;
     $this->form = $form;
     parent::display($tpl);
 }
示例#2
0
 function _buildListArray(&$lists, $item)
 {
     $db = JFactory::getDbo();
     $config = OSMembershipHelper::getConfig();
     $sql = 'SELECT id, title FROM #__osmembership_plans WHERE published = 1 ORDER BY ordering ';
     $db->setQuery($sql);
     $options = array();
     $options[] = JHtml::_('select.option', 0, JText::_('OSM_ALL_PLANS'), 'id', 'title');
     $options = array_merge($options, $db->loadObjectList());
     $lists['plan_id'] = JHtml::_('select.genericlist', $options, 'plan_id', ' class="inputbox" ', 'id', 'title', $item->plan_id);
     //Subscription status
     $options = array();
     $options[] = JHtml::_('select.option', -1, JText::_('OSM_ALL'));
     $options[] = JHtml::_('select.option', 0, JText::_('OSM_PENDING'));
     $options[] = JHtml::_('select.option', 1, JText::_('OSM_ACTIVE'));
     $options[] = JHtml::_('select.option', 2, JText::_('OSM_EXPIRED'));
     $options[] = JHtml::_('select.option', 3, JText::_('OSM_CANCELLED_PENDING'));
     $options[] = JHtml::_('select.option', 4, JText::_('OSM_CANCELLED_REFUNDED'));
     $lists['published'] = JHtml::_('select.genericlist', $options, 'published', ' class="inputbox" ', 'value', 'text', $item->published);
     //Get list of payment methods
     $sql = 'SELECT name, title FROM #__osmembership_plugins WHERE published=1 ORDER BY ordering';
     $db->setQuery($sql);
     $options = array();
     $options[] = JHtml::_('select.option', '', JText::_('OSM_PAYMENT_METHOD'), 'name', 'title');
     $options = array_merge($options, $db->loadObjectList());
     $lists['payment_method'] = JHtml::_('select.genericlist', $options, 'payment_method', ' class="inputbox" ', 'name', 'title', $item->payment_method);
     $rowFields = OSMembershipHelper::getProfileFields($item->plan_id, true, $item->language);
     $data = array();
     if ($item->id) {
         $data = OSMembershipHelper::getProfileData($item, $item->plan_id, $rowFields);
         $setDefault = false;
     } else {
         $setDefault = true;
     }
     if (!isset($data['country']) || !$data['country']) {
         $data['country'] = $config->default_country;
     }
     $form = new RADForm($rowFields);
     $form->setData($data)->bindData($setDefault);
     //Custom fields processing goes here
     if ($item->plan_id) {
         $sql = 'SELECT lifetime_membership FROM #__osmembership_plans WHERE id=' . $item->plan_id;
         $db->setQuery($sql);
         $item->lifetime_membership = (int) $db->loadResult();
     } else {
         $item->lifetime_membership = 0;
     }
     $this->config = $config;
     $this->form = $form;
     return true;
 }
示例#3
0
 function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $this->depart = $app->getUserStateFromRequest('booking.depart', 'depart', '');
     $input = JFactory::getApplication()->input;
     $this->tour_id = $input->get('id', '', 'int');
     $tourModel = new BookProModelTour();
     $this->tour = $tourModel->getItem($this->tour_id);
     $this->document = JFactory::getDocument();
     $user = JFactory::getUser();
     $this->document->setTitle(JText::_('COM_BOOKPRO_REGISTER_VIEW'));
     $rowFields = TourHelper::getCustomfieldsByInquiry();
     $form = new RADForm($rowFields, null, '');
     $this->fields = $form->getFields();
     parent::display($tpl);
 }
示例#4
0
 function store(&$data)
 {
     $db = $this->getDbo();
     $row = $this->getTable('OsMembership', 'Subscriber');
     $row->load($data['id']);
     if (isset($data['password'])) {
         $userData = array();
         $query = $db->getQuery(true);
         $query->select('COUNT(*)')->from('#__users')->where('email=' . $db->quote($data['email']))->where('id!=' . (int) $row->user_id);
         $db->setQuery($query);
         $total = $db->loadResult();
         if (!$total) {
             $userData['email'] = $data['email'];
         }
         if ($data['password']) {
             $userData['password2'] = $userData['password'] = $data['password'];
         }
         if (count($userData)) {
             $user = JFactory::getUser($row->user_id);
             $user->bind($userData);
             $user->save(true);
         }
     }
     if (!$row->bind($data)) {
         $this->setError($db->getErrorMsg());
         return false;
     }
     if (!$row->check()) {
         $this->setError($db->getErrorMsg());
         return false;
     }
     if (!$row->store()) {
         $this->setError($db->getErrorMsg());
         return false;
     }
     //Store custom field data for this profile record
     $rowFields = OSMembershipHelper::getProfileFields(0, false);
     $form = new RADForm($rowFields);
     $form->storeData($row->id, $data);
     //Syncronize profile data of other subscription records from this subscriber
     OSMembershipHelper::syncronizeProfileData($row, $data);
     //Trigger event	onProfileUpdate event
     JPluginHelper::importPlugin('osmembership');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onProfileUpdate', array($row));
     return true;
 }
示例#5
0
 function display($tpl = null)
 {
     $user = JFactory::getUser();
     $config = OSMembershipHelper::getConfig();
     $Itemid = JRequest::getInt('Itemid', 0);
     $item = $this->get('Data');
     if ($item->user_id != $user->get('id')) {
         $app = JFactory::getApplication();
         $app->redirect('index.php', JText::_('OSM_INVALID_ACTION'));
     }
     //Form
     $rowFields = OSMembershipHelper::getProfileFields($item->plan_id, true, $item->language);
     $data = OSMembershipHelper::getProfileData($item, $item->plan_id, $rowFields);
     $form = new RADForm($rowFields);
     $form->setData($data)->bindData();
     $this->Itemid = $Itemid;
     $this->config = $config;
     $this->item = $item;
     $this->form = $form;
     parent::display($tpl);
 }
示例#6
0
 /**
  * Re-calculate subscription fee when subscribers choose a fee option on subscription form
  *
  * Called by ajax request. After calculation, the system will update the fee displayed on end users on subscription sign up form
  */
 public function calculate_subscription_fee()
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $config = OSMembershipHelper::getConfig();
     $planId = JRequest::getInt('plan_id', 0);
     $query->select('*')->from('#__osmembership_plans')->where('id=' . $planId);
     $db->setQuery($query);
     $rowPlan = $db->loadObject();
     $rowFields = OSMembershipHelper::getProfileFields($planId);
     $data = JRequest::get('post', JREQUEST_ALLOWHTML);
     $form = new RADForm($rowFields);
     $form->setData($data)->bindData(true);
     $fees = OSMembershipHelper::calculateSubscriptionFee($rowPlan, $form, $data, $config, JFactory::getApplication()->input->get('payment_method', '', 'none'));
     echo json_encode($fees);
     JFactory::getApplication()->close();
 }
示例#7
0
 /**
  * Get detail information of the subscription
  *
  * @param object $config
  * @param object $row
  *
  * @return string
  */
 public static function getEmailContent($config, $row, $toAdmin = false)
 {
     $db = JFactory::getDbo();
     $sql = 'SELECT lifetime_membership, title FROM #__osmembership_plans WHERE id=' . $row->plan_id;
     $db->setQuery($sql);
     $plan = $db->loadObject();
     $data = array();
     $data['planTitle'] = $plan->title;
     $data['lifetimeMembership'] = $plan->lifetime_membership;
     $data['config'] = $config;
     $data['row'] = $row;
     $data['toAdmin'] = $toAdmin;
     if ($row->payment_method == 'os_creditcard') {
         $cardNumber = JRequest::getVar('x_card_num', '');
         $last4Digits = substr($cardNumber, strlen($cardNumber) - 4);
         $data['last4Digits'] = $last4Digits;
     }
     if ($row->user_id) {
         $sql = 'SELECT username FROM #__users WHERE id=' . $row->user_id;
         $db->setQuery($sql);
         $username = $db->loadResult();
         $data['username'] = $username;
     }
     if ($row->username && $row->user_password) {
         $data['username'] = $row->username;
         //Password
         $privateKey = md5(JFactory::getConfig()->get('secret'));
         $key = new JCryptKey('simple', $privateKey, $privateKey);
         $crypt = new JCrypt(new JCryptCipherSimple(), $key);
         $data['password'] = $crypt->decrypt($row->user_password);
     }
     $rowFields = OSMembershipHelper::getProfileFields($row->plan_id);
     $formData = OSMembershipHelper::getProfileData($row, $row->plan_id, $rowFields);
     $form = new RADForm($rowFields);
     $form->setData($formData)->bindData();
     $data['form'] = $form;
     return OSMembershipHelperHtml::loadCommonLayout(JPATH_ROOT . '/components/com_osmembership/emailtemplates/email.php', $data);
 }
示例#8
0
 /**
  * Override store function to perform specific saving
  * @see OSModel::store()
  */
 function store(&$data)
 {
     $row = $this->getTable('OsMembership', 'Subscriber');
     $isNew = true;
     if (!$data['id'] && $data['username'] && $data['password']) {
         //Store this account into the system and get the username
         jimport('joomla.user.helper');
         $params = JComponentHelper::getParams('com_users');
         $newUserType = $params->get('new_usertype', 2);
         $data['groups'] = array();
         $data['groups'][] = $newUserType;
         $data['block'] = 0;
         $data['name'] = $data['first_name'] . ' ' . $data['last_name'];
         $data['password1'] = $data['password2'] = $data['password'];
         $data['email1'] = $data['email2'] = $data['email'];
         $user = new JUser();
         $user->bind($data);
         if (!$user->save()) {
             JFactory::getApplication()->redirect('index.php?option=com_osmembership&view=subscribers', $user->getError(), 'error');
         }
         $data['user_id'] = $user->id;
     }
     if ($data['id']) {
         $isNew = false;
         $row->load($data['id']);
         $published = $row->published;
     } else {
         $published = 0;
         //Default is pending
     }
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (!$row->check()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $row->user_id = (int) $row->user_id;
     $db = $this->getDbo();
     $sql = "SELECT id FROM #__osmembership_subscribers WHERE is_profile=1 AND ((user_id={$row->user_id} AND user_id>0) OR email='{$row->email}')";
     $db->setQuery($sql);
     $profileId = $db->loadResult();
     if ($profileId && $profileId != $row->id) {
         $row->is_profile = 0;
         $row->profile_id = $profileId;
     } else {
         $row->is_profile = 1;
     }
     $sql = ' SELECT lifetime_membership FROM #__osmembership_plans WHERE id=' . (int) $data['plan_id'];
     $db->setQuery($sql);
     $lifetimeMembership = $db->loadResult();
     if ($lifetimeMembership == 1 && $data['to_date'] == '') {
         $row->to_date = "2099-31-12 00:00:00";
     }
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (!$row->profile_id) {
         $row->profile_id = $row->id;
         $row->store();
     }
     $rowFields = OSMembershipHelper::getProfileFields($row->plan_id, false);
     $form = new RADForm($rowFields);
     $form->storeData($row->id, $data);
     JPluginHelper::importPlugin('osmembership');
     $dispatcher = JDispatcher::getInstance();
     if ($isNew) {
         $dispatcher->trigger('onAfterStoreSubscription', array($row));
     }
     if ($published != 1 && $row->published == 1) {
         //Membership active, trigger plugin
         $dispatcher->trigger('onMembershipActive', array($row));
         OSMembershipHelper::sendMembershipApprovedEmail($row);
     } elseif ($published == 1) {
         if ($row->published != 1) {
             $dispatcher->trigger('onMembershipExpire', array($row));
         }
     }
     $data['id'] = $row->id;
     if (!$isNew) {
         $dispatcher->trigger('onMembershipUpdate', array($row));
     }
     OSMembershipHelper::syncronizeProfileData($row, $data);
     return true;
 }
示例#9
0
 /**
  * Process Subscription 
  *
  * @param array $data
  */
 function processSubscription($data)
 {
     jimport('joomla.user.helper');
     $db = JFactory::getDbo();
     $row = JTable::getInstance('OsMembership', 'Subscriber');
     $query = $db->getQuery(true);
     $config = OSMembershipHelper::getConfig();
     $user = JFactory::getUser();
     $userId = $user->get('id');
     $nullDate = $db->getNullDate();
     $fieldSuffix = OSMembershipHelper::getFieldSuffix();
     if (!$userId && $config->registration_integration) {
         //Store user account into Joomla users database
         if ($config->create_account_when_membership_active !== '1') {
             $userId = OSMembershipHelper::saveRegistration($data);
         } else {
             //Encrypt the password and store into  #__osmembership_subscribers table and create the account layout
             $privateKey = md5(JFactory::getConfig()->get('secret'));
             $key = new JCryptKey('simple', $privateKey, $privateKey);
             $crypt = new JCrypt(new JCryptCipherSimple(), $key);
             $data['user_password'] = $crypt->encrypt($data['password1']);
         }
     }
     $data['transaction_id'] = strtoupper(JUserHelper::genRandomPassword(16));
     $row->bind($data);
     $row->published = 0;
     $row->created_date = JFactory::getDate()->toSql();
     $row->user_id = $userId;
     while (true) {
         $subscriptionCode = JUserHelper::genRandomPassword(10);
         $query->select('COUNT(*)')->from('#__osmembership_subscribers')->where('subscription_code=' . $db->quote($subscriptionCode));
         $db->setQuery($query);
         $total = $db->loadResult();
         if (!$total) {
             break;
         }
     }
     $row->subscription_code = $subscriptionCode;
     $query->clear();
     $query->select('id')->from('#__osmembership_subscribers')->where("is_profile=1 AND ((user_id={$userId} AND user_id>0) OR email='{$row->email}')");
     $db->setQuery($query);
     $profileId = $db->loadResult();
     if ($profileId) {
         $row->is_profile = 0;
         $row->profile_id = $profileId;
     } else {
         $row->is_profile = 1;
     }
     $row->language = JFactory::getLanguage()->getTag();
     $query->clear();
     $query->select('*, title' . $fieldSuffix . ' AS title')->from('#__osmembership_plans')->where('id=' . (int) $data['plan_id']);
     $db->setQuery($query);
     $rowPlan = $db->loadObject();
     $rowFields = OSMembershipHelper::getProfileFields($row->plan_id, false);
     $form = new RADForm($rowFields);
     $form->setData($data)->bindData(true);
     $fees = OSMembershipHelper::calculateSubscriptionFee($rowPlan, $form, $data, $config, $row->payment_method);
     $action = $data['act'];
     if ($action == 'renew') {
         $renewOptionId = (int) $data['renew_option_id'];
         if ($renewOptionId == OSM_DEFAULT_RENEW_OPTION_ID) {
             $dateIntervalSpec = 'P' . $rowPlan->subscription_length . $rowPlan->subscription_length_unit;
         } else {
             $query->clear();
             $query->select('number_days')->from('#__osmembership_renewrates')->where('id=' . (int) $data['renew_option_id']);
             $db->setQuery($query);
             $numberDays = (int) $db->loadResult();
             $dateIntervalSpec = 'P' . $numberDays . 'D';
         }
     } elseif ($action == 'upgrade') {
         $dateIntervalSpec = 'P' . $rowPlan->subscription_length . $rowPlan->subscription_length_unit;
     } else {
         if ($rowPlan->recurring_subscription && $rowPlan->trial_duration) {
             $dateIntervalSpec = 'P' . $rowPlan->trial_duration . $rowPlan->trial_duration_unit;
         } else {
             $dateIntervalSpec = 'P' . $rowPlan->subscription_length . $rowPlan->subscription_length_unit;
         }
     }
     $maxDate = null;
     if ($row->user_id > 0) {
         //Subscriber, user existed
         $query->clear();
         $query->select('MAX(to_date)')->from('#__osmembership_subscribers')->where('user_id=' . $row->user_id . ' AND plan_id=' . $row->plan_id . ' AND (published=1 OR (published = 0 AND payment_method LIKE "os_offline%"))');
         $db->setQuery($query);
         $maxDate = $db->loadResult();
     }
     if ($maxDate) {
         $date = JFactory::getDate($maxDate);
         $row->from_date = $date->add(new DateInterval('P1D'))->toSql();
     } else {
         $date = JFactory::getDate();
         $row->from_date = $date->toSql();
     }
     if ($rowPlan->expired_date && $rowPlan->expired_date != $nullDate) {
         $expiredDate = JFactory::getDate($rowPlan->expired_date);
         $expiredDate->setTime(0, 0, 0);
         $startDate = clone $date;
         $startDate->setTime(0, 0, 0);
         if ($startDate >= $expiredDate) {
             $date->setDate($date->year + 1, $expiredDate->month, $expiredDate->day);
             $row->to_date = $date->toSql();
         } else {
             $row->to_date = $rowPlan->expired_date;
         }
     } else {
         if ($rowPlan->lifetime_membership) {
             $row->to_date = '2099-12-31 23:59:59';
         } else {
             $row->to_date = $date->add(new DateInterval($dateIntervalSpec))->toSql();
         }
     }
     $couponCode = JRequest::getVar('coupon_code', '');
     $couponId = 0;
     if ($couponCode && $fees['coupon_valid']) {
         $query->clear();
         $query->select('id')->from('#__osmembership_coupons')->where('code=' . $db->quote($couponCode));
         $db->setQuery($query);
         $couponId = (int) $db->loadResult();
         $query->clear();
         $query->update('#__osmembership_coupons')->set('used=used+1')->where('id=' . $couponId);
         $db->setQuery($query);
         $db->execute();
     }
     $row->amount = $fees['amount'];
     $row->discount_amount = $fees['discount_amount'];
     $row->tax_amount = $fees['tax_amount'];
     $row->payment_processing_fee = $fees['payment_processing_fee'];
     $row->coupon_id = $couponId;
     $row->gross_amount = $fees['gross_amount'];
     $row->store();
     if (!$row->profile_id) {
         $row->profile_id = $row->id;
         $row->store();
     }
     $data['amount'] = $fees['gross_amount'];
     //Store custom field data
     $form->storeData($row->id, $data);
     //Syncronize profile data for other records
     OSMembershipHelper::syncronizeProfileData($row, $data);
     JPluginHelper::importPlugin('osmembership');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterStoreSubscription', array($row));
     $data['regular_price'] = $fees['regular_gross_amount'];
     $data['trial_amount'] = $fees['trial_gross_amount'];
     if ($data['amount'] > 0 || $rowPlan->recurring_subscription) {
         switch ($action) {
             case 'renew':
                 $itemName = JText::_('OSM_PAYMENT_FOR_RENEW_SUBSCRIPTION');
                 $itemName = str_replace('[PLAN_TITLE]', $rowPlan->title, $itemName);
                 break;
             case 'upgrade':
                 $itemName = JText::_('OSM_PAYMENT_FOR_UPGRADE_SUBSCRIPTION');
                 $itemName = str_replace('[PLAN_TITLE]', $rowPlan->title, $itemName);
                 //Get from Plan Title
                 $query->clear();
                 $query->select('a.title')->from('#__osmembership_plans AS a')->innerJoin('#__osmembership_upgraderules AS b ON a.id=b.from_plan_id')->where('b.id=' . $row->upgrade_option_id);
                 $db->setQuery($query);
                 $fromPlanTitle = $db->loadResult();
                 $itemName = str_replace('[FROM_PLAN_TITLE]', $fromPlanTitle, $itemName);
                 break;
             default:
                 $itemName = JText::_('OSM_PAYMENT_FOR_SUBSCRIPTION');
                 $itemName = str_replace('[PLAN_TITLE]', $rowPlan->title, $itemName);
                 break;
         }
         $data['item_name'] = $itemName;
         $paymentMethod = $data['payment_method'];
         require_once JPATH_COMPONENT . '/plugins/' . $paymentMethod . '.php';
         $query->clear();
         $query->select('params, support_recurring_subscription')->from('#__osmembership_plugins')->where('name=' . $db->quote($paymentMethod));
         $db->setQuery($query);
         $plugin = $db->loadObject();
         $params = $plugin->params;
         $supportRecurring = $plugin->support_recurring_subscription;
         $params = new JRegistry($params);
         $paymentClass = new $paymentMethod($params);
         if ($rowPlan->recurring_subscription && $supportRecurring) {
             if ($paymentMethod == 'os_authnet') {
                 $paymentMethod = 'os_authnet_arb';
                 require_once JPATH_COMPONENT . '/plugins/' . $paymentMethod . '.php';
                 $paymentClass = new $paymentMethod($params);
             }
             $paymentClass->processRecurringPayment($row, $data);
         } else {
             $paymentClass->processPayment($row, $data);
         }
     } else {
         $Itemid = JRequest::getInt('Itemid');
         $row->published = 1;
         $row->store();
         if ($row->act == 'upgrade') {
             OSMembershipHelper::processUpgradeMembership($row);
         }
         OSMembershipHelper::sendEmails($row, $config);
         JPluginHelper::importPlugin('osmembership');
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onMembershipActive', array($row));
         $query->clear();
         $query->select('subscription_complete_url')->from('#__osmembership_plans')->where('id=' . $row->plan_id);
         //Get subscription complete UR
         $db->setQuery($query);
         $subscriptionCompleteURL = $db->loadResult();
         if ($subscriptionCompleteURL) {
             JFactory::getApplication()->redirect($subscriptionCompleteURL);
         } else {
             JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_osmembership&view=complete&act=' . $row->act . '&subscription_code=' . $row->subscription_code . '&Itemid=' . $Itemid, false));
         }
     }
 }
示例#10
0
 function display($tpl = null)
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $user = JFactory::getUser();
     $config = OSMembershipHelper::getConfig();
     $messageObj = OSMembershipHelper::getMessages();
     $fieldSuffix = OSMembershipHelper::getFieldSuffix();
     JFactory::getDocument()->addScript(JUri::base(true) . '/components/com_osmembership/assets/js/paymentmethods.js');
     $userId = $user->get('id');
     $Itemid = JRequest::getInt('Itemid', 0);
     if (!$Itemid) {
         $Itemid = OSMembershipHelper::getItemid();
     }
     $planId = JRequest::getInt('id', 0);
     // Check to see whether this is a valid form or not
     if (!$planId) {
         JFactory::getApplication()->redirect('index.php', JText::_('OSM_INVALID_MEMBERSHIP_PLAN'));
     }
     $query->select('*, title' . $fieldSuffix . ' AS title')->from('#__osmembership_plans')->where('id=' . $planId);
     $db->setQuery($query);
     $plan = $db->loadObject();
     if ($plan->published == 0 || !$plan) {
         JFactory::getApplication()->redirect('index.php', JText::_('OSM_CANNOT_ACCESS_UNPUBLISHED_PLAN'));
         return;
     }
     if (!in_array($plan->access, $user->getAuthorisedViewLevels())) {
         JFactory::getApplication()->redirect('index.php', JText::_('OSM_NOT_ALLOWED_PLAN'));
     }
     // Check if user can subscribe to the plan
     if (!OSMembershipHelper::canSubscribe($plan)) {
         if ($config->number_days_before_renewal) {
             // Redirect to memberhsip profile page
             $app = JFactory::getApplication();
             $app->enqueueMessage(JText::sprintf('OSM_COULD_NOT_RENEWAL', $config->number_days_before_renewal), 'message');
             $profileItemId = OSMembershipHelperRoute::findView('profile', $Itemid);
             $app->redirect(JRoute::_('index.php?option=com_osmembership&view=profile&Itemid=' . $profileItemId));
         } else {
             $app = JFactory::getApplication();
             $app->enqueueMessage(JText::_('OSM_YOU_ARE_NOT_ALLOWED_TO_SIGNUP'), 'message');
             $app->redirect('index.php');
         }
     }
     $paymentMethod = JRequest::getVar('payment_method', os_payments::getDefautPaymentMethod(), 'post');
     if (!$paymentMethod) {
         $paymentMethod = os_payments::getDefautPaymentMethod();
     }
     $renewOptionId = JRequest::getInt('renew_option_id', 0);
     $upgradeOptionId = JRequest::getInt('upgrade_option_id', 0);
     if ($renewOptionId) {
         $action = 'renew';
     } elseif ($upgradeOptionId) {
         $action = 'upgrade';
     } else {
         $action = 'subscribe';
     }
     ###############Payment Methods parameters###############################
     $lists['exp_month'] = JHtml::_('select.integerlist', 1, 12, 1, 'exp_month', ' id="exp_month" class="input-small" ', JRequest::getVar('exp_month', date('m'), 'post'), '%02d');
     $currentYear = date('Y');
     $lists['exp_year'] = JHtml::_('select.integerlist', $currentYear, $currentYear + 10, 1, 'exp_year', ' id="exp_year" class="input-small" ', JRequest::getVar('exp_year', date('Y'), 'post'));
     $options = array();
     $cardTypes = explode(',', $config->enable_cardtypes);
     if (in_array('Visa', $cardTypes)) {
         $options[] = JHtml::_('select.option', 'Visa', JText::_('OSM_VISA_CARD'));
     }
     if (in_array('MasterCard', $cardTypes)) {
         $options[] = JHtml::_('select.option', 'MasterCard', JText::_('OSM_MASTER_CARD'));
     }
     if (in_array('Discover', $cardTypes)) {
         $options[] = JHtml::_('select.option', 'Discover', JText::_('OSM_DISCOVER'));
     }
     if (in_array('Amex', $cardTypes)) {
         $options[] = JHtml::_('select.option', 'Amex', JText::_('OSM_AMEX'));
     }
     $lists['card_type'] = JHtml::_('select.genericlist', $options, 'card_type', ' class="inputbox" ', 'value', 'text', JRequest::getVar('card_type', null, 'post'));
     $options = array();
     $options[] = JHtml::_('select.option', 'CHECKING', JText::_('OSM_BANK_TYPE_CHECKING'));
     $options[] = JHtml::_('select.option', 'BUSINESSCHECKING', JText::_('OSM_BANK_TYPE_BUSINESSCHECKING'));
     $options[] = JHtml::_('select.option', 'SAVINGS', JText::_('OSM_BANK_TYPE_SAVINGS'));
     $lists['x_bank_acct_type'] = JHtml::_('select.genericlist', $options, 'x_bank_acct_type', ' class="inputbox" ', 'value', 'text', JRequest::getVar('x_bank_acct_type', null, 'post'));
     // IDEAL Mollie payment plugin support
     $idealEnabled = OSMembershipHelper::idealEnabled();
     if ($idealEnabled) {
         $bankLists = OSMembershipHelper::getBankLists();
         $options = array();
         foreach ($bankLists as $bankId => $bankName) {
             $options[] = JHtml::_('select.option', $bankId, $bankName);
         }
         $lists['bank_id'] = JHtml::_('select.genericlist', $options, 'bank_id', ' class="inputbox" ', 'value', 'text', JRequest::getInt('bank_id'));
     }
     if ($plan->recurring_subscription) {
         $onlyRecurring = 1;
     } else {
         $onlyRecurring = 0;
     }
     if ($action == 'renew' || $action == 'upgrade') {
         $methods = os_payments::getPaymentMethods(true, $onlyRecurring);
     } else {
         $methods = os_payments::getPaymentMethods(true, $onlyRecurring);
     }
     if (count($methods) == 0) {
         JFactory::getApplication()->redirect('index.php', JText::_('OSM_NEED_TO_PUBLISH_PLUGIN'));
     }
     // Check to see if there is payment processing fee or not
     $showPaymentFee = false;
     foreach ($methods as $method) {
         if ($method->paymentFee) {
             $showPaymentFee = true;
             break;
         }
     }
     $this->showPaymentFee = $showPaymentFee;
     $rowFields = OSMembershipHelper::getProfileFields($planId, true, null, $action);
     if (isset($_POST['first_name'])) {
         $data = JRequest::get('post', JREQUEST_ALLOWHTML);
     } else {
         $data = array();
         if ($userId) {
             // Check to see if this user has profile data already
             $query->clear();
             $query->select('*')->from('#__osmembership_subscribers')->where('user_id=' . $userId . ' AND is_profile=1');
             $db->setQuery($query);
             $rowProfile = $db->loadObject();
             if ($rowProfile) {
                 $data = OSMembershipHelper::getProfileData($rowProfile, $planId, $rowFields);
             } elseif (JPluginHelper::isEnabled('user', 'profile')) {
                 $syncronizer = new RADSynchronizerJoomla();
                 $mappings = array();
                 foreach ($rowFields as $rowField) {
                     if ($rowField->profile_field_mapping) {
                         $mappings[$rowField->name] = $rowField->profile_field_mapping;
                     }
                 }
                 $data = $syncronizer->getData($userId, $mappings);
             } else {
                 // Trigger plugin to get data
                 $mappings = array();
                 foreach ($rowFields as $rowField) {
                     if ($rowField->field_mapping) {
                         $mappings[$rowField->name] = $rowField->field_mapping;
                     }
                 }
                 JPluginHelper::importPlugin('osmembership');
                 $dispatcher = JDispatcher::getInstance();
                 $results = $dispatcher->trigger('onGetProfileData', array($userId, $mappings));
                 if (count($results)) {
                     foreach ($results as $res) {
                         if (is_array($res) && count($res)) {
                             $data = $res;
                             break;
                         }
                     }
                 }
             }
         }
     }
     if ($userId && !isset($data['first_name'])) {
         // Load the name from Joomla default name
         $name = $user->name;
         if ($name) {
             $pos = strpos($name, ' ');
             if ($pos !== false) {
                 $data['first_name'] = substr($name, 0, $pos);
                 $data['last_name'] = substr($name, $pos + 1);
             } else {
                 $data['first_name'] = $name;
                 $data['last_name'] = '';
             }
         }
     }
     if ($userId && !isset($data['email'])) {
         $data['email'] = $user->email;
     }
     if (!isset($data['country']) || !$data['country']) {
         $data['country'] = $config->default_country;
     }
     $countryCode = OSMembershipHelper::getCountryCode($data['country']);
     // Get data
     $form = new RADForm($rowFields);
     $form->setData($data)->bindData(true);
     $form->prepareFormFields('calculateSubscriptionFee();');
     $data['renew_option_id'] = $renewOptionId;
     $data['upgrade_option_id'] = $upgradeOptionId;
     $data['act'] = $action;
     $fees = OSMembershipHelper::calculateSubscriptionFee($plan, $form, $data, $config, $paymentMethod);
     $amount = $fees['amount'];
     if ($action == 'renew') {
         if (strlen(strip_tags($messageObj->{'subscription_renew_form_msg' . $fieldSuffix}))) {
             $message = $messageObj->{'subscription_renew_form_msg' . $fieldSuffix};
         } else {
             $message = $messageObj->subscription_renew_form_msg;
         }
         if ($renewOptionId == OSM_DEFAULT_RENEW_OPTION_ID) {
             switch ($plan->subscription_length_unit) {
                 case 'D':
                     $text = $plan->subscription_length > 1 ? JText::_('OSM_DAYS') : JText::_('OSM_DAY');
                     break;
                 case 'W':
                     $text = $plan->subscription_length > 1 ? JText::_('OSM_WEEKS') : JText::_('OSM_WEEK');
                     break;
                 case 'M':
                     $text = $plan->subscription_length > 1 ? JText::_('OSM_MONTHS') : JText::_('OSM_MONTH');
                     break;
                 case 'Y':
                     $text = $plan->subscription_length > 1 ? JText::_('OSM_YEARS') : JText::_('OSM_YEAR');
                     break;
             }
             $message = str_replace('[NUMBER_DAYS] days', $plan->subscription_length . ' ' . $text, $message);
         } else {
             $query->clear();
             $query->select('number_days')->from('#__osmembership_renewrates')->where('id=' . $renewOptionId);
             $db->setQuery($query);
             $numberDays = $db->loadResult();
             $message = str_replace('[NUMBER_DAYS]', $numberDays, $message);
         }
         $message = str_replace('[PLAN_TITLE]', $plan->title, $message);
         $message = str_replace('[AMOUNT]', OSMembershipHelper::formatCurrency($amount, $config), $message);
     } elseif ($action == 'upgrade') {
         if (strlen(strip_tags($messageObj->{'subscription_upgrade_form_msg' . $fieldSuffix}))) {
             $message = $messageObj->{'subscription_upgrade_form_msg' . $fieldSuffix};
         } else {
             $message = $messageObj->subscription_upgrade_form_msg;
         }
         $query->clear();
         $query->select('b.title')->from('#__osmembership_upgraderules AS a')->innerJoin('#__osmembership_plans AS b ON a.from_plan_id=b.id')->where('a.id=' . $upgradeOptionId);
         $db->setQuery($query);
         $fromPlan = $db->loadResult();
         $message = str_replace('[PLAN_TITLE]', $plan->title, $message);
         $message = str_replace('[AMOUNT]', OSMembershipHelper::formatCurrency($amount, $config), $message);
         $message = str_replace('[FROM_PLAN_TITLE]', $fromPlan, $message);
     } else {
         if (strlen(strip_tags($plan->{'subscription_form_message' . $fieldSuffix})) || strlen(strip_tags($plan->subscription_form_message))) {
             if (strlen(strip_tags($plan->{'subscription_form_message' . $fieldSuffix}))) {
                 $message = $plan->{'subscription_form_message' . $fieldSuffix};
             } else {
                 $message = $plan->subscription_form_message;
             }
         } else {
             if (strlen(strip_tags($messageObj->{'subscription_form_msg' . $fieldSuffix}))) {
                 $message = $messageObj->{'subscription_form_msg' . $fieldSuffix};
             } else {
                 $message = $messageObj->subscription_form_msg;
             }
         }
         if ($plan->recurring_subscription) {
             //We will first need to detect regular duration
             if ($plan->trial_duration) {
                 $trialPeriorText = JText::_('OSM_TRIAL_RECURRING_SUBSCRIPTION_PERIOR');
                 $trialPeriorText = str_replace('[TRIAL_DURATION]', $plan->trial_duration, $trialPeriorText);
                 switch ($plan->trial_duration_unit) {
                     case 'D':
                         $trialPeriorText = str_replace('[TRIAL_DURATION_UNIT]', $plan->trial_duration > 1 ? JText::_('OSM_DAYS') : JText::_('OSM_DAY'), $trialPeriorText);
                         break;
                     case 'W':
                         $trialPeriorText = str_replace('[TRIAL_DURATION_UNIT]', $plan->trial_duration > 1 ? JText::_('OSM_WEEKS') : JText::_('OSM_WEEK'), $trialPeriorText);
                         break;
                     case 'M':
                         $trialPeriorText = str_replace('[TRIAL_DURATION_UNIT]', $plan->trial_duration > 1 ? JText::_('OSM_MONTHS') : JText::_('OSM_MONTH'), $trialPeriorText);
                         break;
                     case 'Y':
                         $trialPeriorText = str_replace('[TRIAL_DURATION_UNIT]', $plan->trial_duration > 1 ? JText::_('OSM_YEARS') : JText::_('OSM_YEAR'), $trialPeriorText);
                         break;
                     default:
                         $trialPeriorText = str_replace('[TRIAL_DURATION_UNIT]', $plan->trial_duration > 1 ? JText::_('OSM_DAYS') : JText::_('OSM_DAY'), $trialPeriorText);
                         break;
                 }
                 $this->trialPeriorText = $trialPeriorText;
             }
             $length = $plan->subscription_length;
             $regularPeriorText = JText::_('OSM_REGULAR_SUBSCRIPTION_PERIOR');
             $regularPeriorText = str_replace('[REGULAR_DURATION]', $length, $regularPeriorText);
             switch ($plan->subscription_length_unit) {
                 case 'D':
                     $regularPeriorText = str_replace('[REGULAR_DURATION_UNIT]', $length > 1 ? JText::_('OSM_DAYS') : JText::_('OSM_DAY'), $regularPeriorText);
                     break;
                 case 'W':
                     $regularPeriorText = str_replace('[REGULAR_DURATION_UNIT]', $length > 1 ? JText::_('OSM_WEEKS') : JText::_('OSM_WEEK'), $regularPeriorText);
                     break;
                 case 'M':
                     $regularPeriorText = str_replace('[REGULAR_DURATION_UNIT]', $length > 1 ? JText::_('OSM_MONTHS') : JText::_('OSM_MONTH'), $regularPeriorText);
                     break;
                 case 'Y':
                     $regularPeriorText = str_replace('[REGULAR_DURATION_UNIT]', $length > 1 ? JText::_('OSM_YEARS') : JText::_('OSM_YEAR'), $regularPeriorText);
                     break;
                 default:
                     $regularPeriorText = str_replace('[REGULAR_DURATION_UNIT]', $length > 1 ? JText::_('OSM_DAYS') : JText::_('OSM_DAY'), $regularPeriorText);
                     break;
             }
             $this->regularPeriorText = $regularPeriorText;
             $message = str_replace('[PLAN_TITLE]', $plan->title, $message);
             $message = str_replace('[AMOUNT]', OSMembershipHelper::formatCurrency($amount, $config), $message);
         } else {
             $message = str_replace('[PLAN_TITLE]', $plan->title, $message);
             $message = str_replace('[AMOUNT]', OSMembershipHelper::formatCurrency($amount, $config), $message);
         }
     }
     // Implement Joomla core recpatcha
     $showCaptcha = 0;
     if ($config->enable_captcha) {
         $captchaPlugin = JFactory::getApplication()->getParams()->get('captcha', JFactory::getConfig()->get('captcha'));
         if ($captchaPlugin) {
             $showCaptcha = 1;
             $this->captcha = JCaptcha::getInstance($captchaPlugin)->display('dynamic_recaptcha_1', 'dynamic_recaptcha_1', 'required');
         } else {
             JFactory::getApplication()->enqueueMessage(JText::_('OSM_CAPTCHA_NOT_ACTIVATED_IN_YOUR_SITE'), 'error');
         }
     }
     // Assign variables to template
     $this->userId = $userId;
     $this->paymentMethod = $paymentMethod;
     $this->lists = $lists;
     $this->Itemid = $Itemid;
     $this->config = $config;
     $this->plan = $plan;
     $this->methods = $methods;
     $this->idealEnabled = $idealEnabled;
     $this->action = $action;
     $this->renewOptionId = $renewOptionId;
     $this->upgradeOptionId = $upgradeOptionId;
     $this->message = $message;
     $this->form = $form;
     $this->fees = $fees;
     $this->showCaptcha = $showCaptcha;
     $this->countryBaseTax = (int) OSMembershipHelper::isCountryBaseTax();
     $this->taxRate = OSMembershipHelper::calculateTaxRate($planId);
     $this->countryCode = $countryCode;
     parent::display($tpl);
 }
示例#11
0
<?php

/**
 * @package 	Bookpro
 * @author 		Ngo Van Quan
 * @link 		http://joombooking.com
 * @copyright 	Copyright (C) 2011 - 2012 Ngo Van Quan
 * @license 	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 * @version 	$Id$
 **/
AImporter::helper('tour');
defined('_JEXEC') or die('Restricted access');
$order = $displayData;
$order_id = $order->id;
$rowFields = TourHelper::getCustomfieldsByOrderid($order_id);
$form = new RADForm($rowFields, null, '');
$fields = $form->getFields();
//var_dump($rowFields); die;
?>
	<legend>
		<span><?php 
echo JText::_('COM_BOOKPRO_CUSTOM_FIELDS');
?>
 </span>
	</legend>
<div class="form-horizontal">
	<?php 
foreach ($fields as $field) {
    echo $field->getControlGroup();
}
?>
示例#12
0
 function display($tpl = null)
 {
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     if (!$user->id) {
         $return = JRoute::_('index.php?option=com_osmembership&view=profile&Itemid=' . JRequest::getInt('Itemid'));
         JFactory::getApplication()->redirect('index.php?option=com_users&view=login&return=' . base64_encode($return), JText::_('OSM_LOGIN_TO_EDIT_PROFILE'));
     }
     $config = OSMembershipHelper::getConfig();
     $Itemid = JRequest::getInt('Itemid');
     $item = $this->get('Data');
     if (!$item) {
         $redirectURL = OSMembershipHelper::getViewUrl(array('categories', 'plans', 'plan', 'register'));
         if (!$redirectURL) {
             $redirectURL = 'index.php';
         }
         JFactory::getApplication()->redirect('index.php', JText::_('OSM_DONOT_HAVE_SUBSCRIPTION_RECORD'));
     }
     //Get subscriptions history
     require_once JPATH_COMPONENT . '/models/subscriptions.php';
     $model = JModelLegacy::getInstance('Subscriptions', 'OSMembershipModel');
     $items = $model->getData();
     //Form
     $rowFields = OSMembershipHelper::getProfileFields(0, true, $item->language);
     $data = OSMembershipHelper::getProfileData($item, 0, $rowFields);
     $form = new RADForm($rowFields);
     $form->setData($data)->bindData();
     //Trigger third party add-on
     JPluginHelper::importPlugin('osmembership');
     $dispatcher = JDispatcher::getInstance();
     $results = $dispatcher->trigger('onProfileDisplay', array($item));
     //Get renew and upgrade options, only allow renew for active or expired subscriptions
     $sql = 'SELECT DISTINCT plan_id FROM #__osmembership_subscribers WHERE profile_id=' . $item->id . ' AND (published = 1 OR published = 2)';
     $db->setQuery($sql);
     $planIds = $db->loadColumn();
     //Check to see whether the user can renew or not
     $canRenew = false;
     foreach ($planIds as $planId) {
         $sql = 'SELECT recurring_subscription, enable_renewal FROM #__osmembership_plans WHERE id=' . $planId;
         $db->setQuery($sql);
         $plan = $db->loadObject();
         if (!$plan->recurring_subscription && $plan->enable_renewal) {
             $canRenew = true;
             break;
         }
     }
     //Load js file to support state field dropdown
     JFactory::getDocument()->addScript(JUri::base(true) . '/components/com_osmembership/assets/js/paymentmethods.js');
     //Need to get subscriptions information of the user
     $plans = OSMembershipHelper::getSubscriptions($item->profile_id);
     $renewOptions = array();
     $this->item = $item;
     $this->config = $config;
     $this->items = $items;
     $this->form = $form;
     $this->Itemid = $Itemid;
     $this->plugins = $results;
     $this->planIds = $planIds;
     $this->plans = $plans;
     $this->canRenew = $canRenew;
     parent::display($tpl);
 }