Exemplo n.º 1
0
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     $config =& CRM_Core_Config::singleton();
     $button = substr($this->controller->getButtonName(), -4);
     $this->add('hidden', 'scriptFee', null);
     $this->add('hidden', 'scriptArray', null);
     if ($this->_values['event']['is_monetary']) {
         require_once 'CRM/Event/Form/Registration/Register.php';
         CRM_Event_Form_Registration_Register::buildAmount($this);
     }
     $first_name = $last_name = null;
     foreach (array('pre', 'post') as $keys) {
         if (isset($this->_values['additional_custom_' . $keys . '_id'])) {
             $this->buildCustom($this->_values['additional_custom_' . $keys . '_id'], 'additionalCustom' . ucfirst($keys), true);
             ${$keys} = CRM_Core_BAO_UFGroup::getFields($this->_values['additional_custom_' . $keys . '_id']);
         }
         foreach (array('first_name', 'last_name') as $name) {
             if (CRM_Utils_Array::value($name, ${$keys}) && CRM_Utils_Array::value('is_required', CRM_Utils_Array::value($name, ${$keys}))) {
                 ${$name} = 1;
             }
         }
     }
     $required = $button == 'skip' || $this->_values['event']['allow_same_participant_emails'] == 1 && ($first_name && $last_name) ? false : true;
     $this->add('text', "email-{$this->_bltID}", ts('Email Address'), array('size' => 30, 'maxlength' => 60), $required);
     //add buttons
     $js = null;
     if ($this->isLastParticipant(true) && !CRM_Utils_Array::value('is_monetary', $this->_values['event'])) {
         $js = array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');");
     }
     //handle case where user might sart with waiting by group
     //registration and skip some people and now group fit to
     //become registered so need to take payment from user.
     //this case only occurs at dynamic waiting status, CRM-4320
     $statusMessage = null;
     $allowToProceed = true;
     $includeSkipButton = true;
     $this->_resetAllowWaitlist = false;
     if ($this->_lastParticipant && !$this->_allowConfirmation && CRM_Utils_Array::value('bypass_payment', $this->_params[0])) {
         require_once 'CRM/Event/BAO/Participant.php';
         $spaces = CRM_Event_BAO_Participant::eventFull($this->_values['event']['id'], true);
         $processedCnt = 0;
         //need to check current participant present in params.
         $currentParticipantNum = substr($this->_name, 12);
         foreach ($this->_params as $key => $value) {
             if ($value == 'skip' || $key == $currentParticipantNum) {
                 continue;
             }
             $processedCnt++;
         }
         //we might did reset allow waiting in case of dynamic calculation
         if (CRM_Utils_Array::value('bypass_payment', $this->_params[0]) && is_numeric($spaces) && CRM_Utils_Array::value('additional_participants', $this->_params[0]) >= $spaces) {
             $this->_allowWaitlist = true;
             $this->set('allowWaitlist', true);
         }
         //lets allow to become a part of runtime waiting list, if primary selected pay later.
         $realPayLater = false;
         if (CRM_Utils_Array::value('is_monetary', $this->_values['event']) && CRM_Utils_Array::value('is_pay_later', $this->_values['event'])) {
             $realPayLater = CRM_Utils_Array::value('is_pay_later', $this->_params[0]);
         }
         //truly spaces are greater than required.
         if (is_numeric($spaces) && $spaces >= $processedCnt + 1) {
             if (CRM_Utils_Array::value('amount', $this->_params[0], 0) == 0 || $this->_requireApproval) {
                 $this->_allowWaitlist = false;
                 $this->set('allowWaitlist', $this->_allowWaitlist);
                 if ($this->_requireApproval) {
                     $statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.", array(1 => ++$processedCnt, 2 => $spaces));
                 } else {
                     $statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed).", array(1 => ++$processedCnt, 2 => $spaces));
                 }
             } else {
                 $statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed). Please go back to the main registration page and reduce the number of additional people. You will also need to complete payment information.", array(1 => ++$processedCnt, 2 => $spaces));
                 $allowToProceed = false;
             }
             CRM_Core_Session::setstatus($status);
         } else {
             if ($processedCnt == $spaces) {
                 if (CRM_Utils_Array::value('amount', $this->_params[0], 0) == 0 || $realPayLater || $this->_requireApproval) {
                     $this->_resetAllowWaitlist = true;
                     if ($this->_requireApproval) {
                         $statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.");
                     } else {
                         $statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed).");
                     }
                 } else {
                     //hey there is enough space and we require payment.
                     $statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed). Please go back to the main registration page and reduce the number of additional people. You will also need to complete payment information.");
                     $includeSkipButton = false;
                 }
             }
         }
     }
     $this->assign('statusMessage', $statusMessage);
     $buttons = array(array('type' => 'back', 'name' => ts('<< Go Back'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp'));
     //CRM-4320
     if ($allowToProceed) {
         $buttons = array_merge($buttons, array(array('type' => 'next', 'name' => ts('Continue >>'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true, 'js' => $js)));
         if ($includeSkipButton) {
             $buttons = array_merge($buttons, array(array('type' => 'next', 'name' => ts('Skip Participant >>|'), 'subName' => 'skip')));
         }
     }
     $this->addButtons($buttons);
     $this->addFormRule(array('CRM_Event_Form_Registration_AdditionalParticipant', 'formRule'), $this);
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $config = CRM_Core_Config::singleton();
     $button = substr($this->controller->getButtonName(), -4);
     $this->add('hidden', 'scriptFee', NULL);
     $this->add('hidden', 'scriptArray', NULL);
     if ($this->_values['event']['is_monetary']) {
         CRM_Event_Form_Registration_Register::buildAmount($this);
     }
     $first_name = $last_name = NULL;
     $pre = $post = array();
     foreach (array('pre', 'post') as $keys) {
         if (isset($this->_values['additional_custom_' . $keys . '_id'])) {
             $this->buildCustom($this->_values['additional_custom_' . $keys . '_id'], 'additionalCustom' . ucfirst($keys), TRUE);
             ${$keys} = CRM_Core_BAO_UFGroup::getFields($this->_values['additional_custom_' . $keys . '_id']);
         }
         foreach (array('first_name', 'last_name') as $name) {
             if (CRM_Utils_Array::value($name, ${$keys}) && CRM_Utils_Array::value('is_required', CRM_Utils_Array::value($name, ${$keys}))) {
                 ${$name} = 1;
             }
         }
     }
     $required = $button == 'skip' || $this->_values['event']['allow_same_participant_emails'] == 1 && ($first_name && $last_name) ? FALSE : TRUE;
     //add buttons
     $js = NULL;
     if ($this->isLastParticipant(TRUE) && !CRM_Utils_Array::value('is_monetary', $this->_values['event'])) {
         $js = array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');");
     }
     //handle case where user might sart with waiting by group
     //registration and skip some people and now group fit to
     //become registered so need to take payment from user.
     //this case only occurs at dynamic waiting status, CRM-4320
     $statusMessage = NULL;
     $allowToProceed = TRUE;
     $includeSkipButton = TRUE;
     $this->_resetAllowWaitlist = FALSE;
     $pricesetFieldsCount = CRM_Price_BAO_Set::getPricesetCount($this->_priceSetId);
     if ($this->_lastParticipant || $pricesetFieldsCount) {
         //get the participant total.
         $processedCnt = self::getParticipantCount($this, $this->_params, TRUE);
     }
     if (!$this->_allowConfirmation && CRM_Utils_Array::value('bypass_payment', $this->_params[0]) && $this->_lastParticipant) {
         //get the event spaces.
         $spaces = $this->_availableRegistrations;
         $currentPageMaxCount = 1;
         if ($pricesetFieldsCount) {
             $currentPageMaxCount = $pricesetFieldsCount;
         }
         //we might did reset allow waiting in case of dynamic calculation
         if (CRM_Utils_Array::value('bypass_payment', $this->_params[0]) && is_numeric($spaces) && $processedCnt > $spaces) {
             $this->_allowWaitlist = TRUE;
             $this->set('allowWaitlist', TRUE);
         }
         //lets allow to become a part of runtime waiting list, if primary selected pay later.
         $realPayLater = FALSE;
         if (CRM_Utils_Array::value('is_monetary', $this->_values['event']) && CRM_Utils_Array::value('is_pay_later', $this->_values['event'])) {
             $realPayLater = CRM_Utils_Array::value('is_pay_later', $this->_params[0]);
         }
         //truly spaces are greater than required.
         if (is_numeric($spaces) && $spaces >= $processedCnt + $currentPageMaxCount) {
             if (CRM_Utils_Array::value('amount', $this->_params[0], 0) == 0 || $this->_requireApproval) {
                 $this->_allowWaitlist = FALSE;
                 $this->set('allowWaitlist', $this->_allowWaitlist);
                 if ($this->_requireApproval) {
                     $statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.", array(1 => ++$processedCnt, 2 => $spaces));
                 } else {
                     $statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed).", array(1 => ++$processedCnt, 2 => $spaces));
                 }
             } else {
                 $statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed). Please go back to the main registration page and reduce the number of additional people. You will also need to complete payment information.", array(1 => ++$processedCnt, 2 => $spaces));
                 $allowToProceed = FALSE;
             }
             CRM_Core_Session::setstatus($status);
         } elseif ($processedCnt == $spaces) {
             if (CRM_Utils_Array::value('amount', $this->_params[0], 0) == 0 || $realPayLater || $this->_requireApproval) {
                 $this->_resetAllowWaitlist = TRUE;
                 if ($this->_requireApproval) {
                     $statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.");
                 } else {
                     $statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed).");
                 }
             } else {
                 //hey there is enough space and we require payment.
                 $statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed). Please go back to the main registration page and reduce the number of additional people. You will also need to complete payment information.");
                 $includeSkipButton = FALSE;
             }
         }
     }
     // for priceset with count
     if ($pricesetFieldsCount && CRM_Utils_Array::value('has_waitlist', $this->_values['event']) && !$this->_allowConfirmation) {
         if ($this->_isEventFull) {
             $statusMessage = ts('This event is currently full. You are registering for the waiting list. You will be notified if spaces become available.');
         } elseif ($this->_allowWaitlist || !$this->_allowWaitlist && $processedCnt + $pricesetFieldsCount > $this->_availableRegistrations) {
             $waitingMsg = ts('It looks like you are registering more participants then there are spaces available. All participants will be added to the waiting list. You will be notified if spaces become available.');
             $confirmedMsg = ts('It looks like there are enough spaces in this event for your group (you will not be wait listed).');
             if ($this->_requireApproval) {
                 $waitingMsg = ts('It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.');
                 $confirmedMsg = ts('It looks there are enough spaces in this event for your group (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.');
             }
             $this->assign('waitingMsg', $waitingMsg);
             $this->assign('confirmedMsg', $confirmedMsg);
             $this->assign('availableRegistrations', $this->_availableRegistrations);
             $this->assign('currentParticipantCount', $processedCnt);
             $this->assign('allowGroupOnWaitlist', TRUE);
             $paymentBypassed = NULL;
             if (CRM_Utils_Array::value('bypass_payment', $this->_params[0]) && !$this->_allowWaitlist && !$realPayLater && !$this->_requireApproval && !(CRM_Utils_Array::value('amount', $this->_params[0], 0) == 0)) {
                 $paymentBypassed = ts('Please go back to the main registration page, to complete payment information.');
             }
             $this->assign('paymentBypassed', $paymentBypassed);
         }
     }
     $this->assign('statusMessage', $statusMessage);
     $buttons = array(array('type' => 'back', 'name' => ts('<< Go Back'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp'));
     //CRM-4320
     if ($allowToProceed) {
         $buttons = array_merge($buttons, array(array('type' => 'next', 'name' => ts('Continue >>'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE, 'js' => $js)));
         if ($includeSkipButton) {
             $buttons = array_merge($buttons, array(array('type' => 'next', 'name' => ts('Skip Participant >>|'), 'subName' => 'skip')));
         }
     }
     $this->addButtons($buttons);
     $this->addFormRule(array('CRM_Event_Form_Registration_AdditionalParticipant', 'formRule'), $this);
 }