Exemplo n.º 1
0
 /**
  * handle registration
  * 
  */
 function register()
 {
     if (JRequest::getVar('cancel', '', 'post')) {
         return $this->cancelreg();
     }
     $app =& JFactory::getApplication();
     $msg = 'OK';
     $xref = JRequest::getInt('xref');
     $pricegroups = JRequest::getVar('pricegroup_id', array(), 'post', 'array');
     $review = JRequest::getVar('hasreview', 0);
     $isedit = JRequest::getVar('isedit', 0);
     JArrayHelper::toInteger($pricegroups);
     if (!$xref) {
         $msg = JText::_('COM_REDEVENT_REGISTRATION_MISSING_XREF');
         $this->setRedirect('index.php', $msg, 'error');
         return;
     }
     $status = redEVENTHelper::canRegister($xref);
     if (!$status->canregister) {
         $msg = $status->status;
         $this->setRedirect('index.php', $msg, 'error');
         return false;
     }
     $model = $this->getModel('registration');
     $model->setXref($xref);
     $details = $model->getSessionDetails();
     // get prices associated to pricegroups
     $prices = array();
     foreach ($pricegroups as $p) {
         $price = $model->getRegistrationPrice($p);
         if ($price === false) {
             $msg = JText::_('COM_REDEVENT_REGISTRATION_MISSING_PRICE');
             $this->setRedirect('index.php', $msg, 'error');
             return;
         }
         $prices[] = $price;
     }
     // first, ask redform to save it's fields, and return the corresponding sids.
     $options = array('baseprice' => $prices);
     if ($review) {
         $options['savetosession'] = 1;
     }
     $rfcore = new redFormCore();
     $result = $rfcore->saveAnswers('redevent', $options);
     if (!$result) {
         $msg = JText::_('COM_REDEVENT_REGISTRATION_REDFORM_SAVE_FAILED') . ' - ' . $rfcore->getError();
         $this->setRedirect(JRoute::_(RedeventHelperRoute::getDetailsRoute($details->did, $xref)), $msg, 'error');
         return;
     }
     $submit_key = $result->submit_key;
     JRequest::setVar('submit_key', $submit_key);
     if ($review) {
         // remember set prices groups
         $app->setUserState('pgids' . $submit_key, $pricegroups);
     } else {
         $app->setUserState('pgids' . $submit_key, null);
     }
     if (!$isedit && !$review) {
         // redform saved fine, now add the attendees
         $user = JFactory::getUser();
         if (!$user->get('id') && $details->juser) {
             if ($new = $this->_createUser($result->posts[0]['sid'])) {
                 $user = $new;
             }
         }
         $attendees = array();
         $k = 0;
         foreach ($result->posts as $rfpost) {
             if (!($res = $model->register($user, $rfpost['sid'], $result->submit_key, $pricegroups[$k++]))) {
                 $msg = JText::_('COM_REDEVENT_REGISTRATION_REGISTRATION_FAILED');
                 $this->setRedirect(JRoute::_(RedeventHelperRoute::getDetailsRoute($details->did, $xref)), $msg, 'error');
                 return;
             }
             $attendees[] = $res;
         }
         JPluginHelper::importPlugin('redevent');
         $dispatcher =& JDispatcher::getInstance();
         $res = $dispatcher->trigger('onEventUserRegistered', array($xref));
         if ($details->notify) {
             $mail = $model->sendNotificationEmail($submit_key);
         }
         $mail = $model->notifyManagers($submit_key);
     }
     if (!$review) {
         $cache = JFactory::getCache('com_redevent');
         $cache->clean();
         $rfredirect = $rfcore->getFormRedirect($details->redform_id);
         if ($rfredirect) {
             $link = $rfredirect;
         } else {
             $link = RedeventHelperRoute::getRegistrationRoute($xref, 'confirm', $submit_key);
         }
     } else {
         $link = RedeventHelperRoute::getRegistrationRoute($xref, 'review', $submit_key);
     }
     // redirect to prevent resending the form on refresh
     $this->setRedirect(JRoute::_($link, false));
 }
Exemplo n.º 2
0
 /**
  * returns form
  * 
  * @return string
  */
 function getForm()
 {
     $app =& JFactory::getApplication();
     $submit_key = JRequest::getVar('submit_key');
     $details = $this->getEvent()->getData();
     $prices = $this->getEvent()->getPrices();
     $options = array('extrafields' => array());
     $user =& JFactory::getUser();
     $rfcore = $this->_getRFCore();
     if (!$rfcore->getFormStatus($this->getEvent()->getData()->redform_id)) {
         $error = $rfcore->getError();
         return '<span class="redform_error">' . $error . '</span>';
     }
     $form = $rfcore->getForm($this->getEvent()->getData()->redform_id);
     $action = JRoute::_(RedeventHelperRoute::getRegistrationRoute($this->getEvent()->getData()->xslug, 'register'));
     // multiple signup ?
     $single = JRequest::getInt('single', 0);
     $max = $this->getEvent()->getData()->max_multi_signup;
     if ($max && !$single && $user->get('id')) {
         $multi = $max;
         // we must deduce current registrations of this user !
         $nbregs = $this->_getCurrentRegs();
         $multi = $max - $nbregs;
         if ($multi < 1) {
             return JText::_('COM_REDEVENT_USER_MAX_REGISTRATION_REACHED');
         }
     } else {
         // single signup
         $multi = 1;
     }
     // multiple pricegroup handling
     $selpg = null;
     if (count($prices)) {
         $currency = current($prices)->currency ? current($prices)->currency : null;
         // is pricegroup already selected ?
         // if a review, we already have pricegroup_id in session
         $pgids = $app->getUserState('pgids' . $submit_key);
         if (!empty($pgids)) {
             $pg = intval($pgids[0]);
         } else {
             $pg = JRequest::getInt('pg');
         }
         if (count($prices) == 1) {
             $selpg = current($prices);
         } else {
             if ($pg) {
                 foreach ($prices as $p) {
                     if ($p->pricegroup_id == $pg) {
                         $selpg = $p;
                         break;
                     }
                 }
             }
         }
         if ($multi > 1 && count($prices) > 1 || !$selpg) {
             $field = array();
             $field['label'] = '<label for="pricegroup_id">' . JText::_('COM_REDEVENT_REGISTRATION_PRICE') . ($currency ? ' <span class="price-currency">(' . $currency . ')</span>' : '') . '</label>';
             $field['field'] = redEVENTHelper::getRfPricesSelect($prices);
             $field['class'] = 'reg-price';
             $options['extrafields'][] = $field;
         } else {
             $field = array();
             $field['label'] = '<label for="pricegroup_id">' . JText::_('COM_REDEVENT_REGISTRATION_PRICE') . '</label>';
             $field['field'] = REOutput::formatprice($selpg->price, $currency) . (count($prices) > 1 ? ' (' . $selpg->name . ')' : '') . '<input type="hidden" name="pricegroup_id[]" class="fixedprice" value="' . $selpg->pricegroup_id . '" price="' . $selpg->price . '" />';
             $field['class'] = 'reg-price pg' . $selpg->id;
             $options['extrafields'][] = $field;
         }
     }
     $details->course_price = null;
     $options['booking'] = $details;
     $html = '<form action="' . $action . '" method="post" name="redform" enctype="multipart/form-data" onsubmit="return CheckSubmit(this);">';
     $html .= $rfcore->getFormFields($this->getEvent()->getData()->redform_id, $submit_key, $multi, $options);
     $html .= '<input type="hidden" name="xref" value="' . $this->_xref . '"/>';
     if ($this->getOption('hasreview')) {
         $html .= '<input type="hidden" name="hasreview" value="1"/>';
     }
     $html .= '<div id="submit_button" style="display: block;" class="submitform' . $form->classname . '">';
     if (empty($submit_key)) {
         $html .= '<input type="submit" id="regularsubmit" name="submit" value="' . JText::_('COM_REDEVENT_Submit') . '" />';
     } else {
         $html .= '<input type="submit" id="redformsubmit" name="submit" value="' . JText::_('COM_REDEVENT_Confirm') . '" />';
         $html .= '<input type="submit" id="redformcancel" name="cancel" value="' . JText::_('COM_REDEVENT_Cancel') . '" />';
     }
     $html .= '</div>';
     $html .= '</form>';
     return $html;
 }
Exemplo n.º 3
0
 function _displayEdit($tpl = null)
 {
     $user =& JFactory::getUser();
     $acl = new UserAcl();
     $xref = JRequest::getInt('xref');
     $submitter_id = JRequest::getInt('submitter_id');
     if (!$submitter_id) {
         JError::raise(0, 'Registration id required');
         return false;
     }
     $model = $this->getModel();
     $model->setXref($xref);
     $course = $this->get('SessionDetails');
     $registration = $model->getRegistration($submitter_id);
     if (!$registration) {
         JError::raise(0, $model->getError);
         return false;
     }
     if ($acl->canManageAttendees($registration->xref) && JRequest::getVar('task') == 'manageredit') {
         $action = JRoute::_(RedeventHelperRoute::getRegistrationRoute($xref, 'managerupdate'));
     } else {
         if ($registration->uid == $user->get('id')) {
             $action = JRoute::_(RedeventHelperRoute::getRegistrationRoute($xref, 'update'));
         } else {
             JError::raiseError(403, 'NOT AUTHORIZED');
             return false;
         }
     }
     $rfoptions = array();
     $prices = $this->get('Pricegroups');
     $field = array();
     $field['label'] = '<label for="pricegroup_id">' . JText::_('COM_REDEVENT_REGISTRATION_PRICE') . '</label>';
     $field['field'] = redEVENTHelper::getRfPricesSelect($prices, $registration->pricegroup_id);
     $rfoptions['extrafields'][] = $field;
     $rfcore = new RedformCore();
     $rfields = $rfcore->getFormFields($course->redform_id, array($submitter_id), 1, $rfoptions);
     $this->assign('action', $action);
     $this->assign('rfields', $rfields);
     $this->assign('xref', $xref);
     parent::display($tpl);
 }