/** 
  * global form rule 
  * 
  * @param array $fields  the input form values 
  * @param array $files   the uploaded files if any 
  * @param array $options additional user data 
  * 
  * @return true if no errors, else array of errors 
  * @access public 
  * @static 
  */
 static function formRule($fields, $files, $self)
 {
     $errors = array();
     //get the button name.
     $button = substr($self->controller->getButtonName(), -4);
     $realPayLater = false;
     if (CRM_Utils_Array::value('is_monetary', $self->_values['event']) && CRM_Utils_Array::value('is_pay_later', $self->_values['event'])) {
         $realPayLater = CRM_Utils_Array::value('is_pay_later', $self->_params[0]);
     }
     if ($button != 'skip') {
         //Additional Participant can also register for an event only once
         require_once 'CRM/Event/Form/Registration/Register.php';
         $isRegistered = CRM_Event_Form_Registration_Register::checkRegistration($fields, $self, true);
         if ($isRegistered) {
             if ($self->_values['event']['allow_same_participant_emails']) {
                 $errors['_qf_default'] = ts('A person is already registered for this event.');
             } else {
                 $errors["email-{$self->_bltID}"] = ts('A person with this email address is already registered for this event.');
             }
         }
         //get the complete params.
         $params = $self->get('params');
         //take the participant instance.
         $addParticipantNum = substr($self->_name, 12);
         if (is_array($params)) {
             foreach ($params as $key => $value) {
                 if ($key != $addParticipantNum) {
                     if (!$self->_values['event']['allow_same_participant_emails']) {
                         if ($value["email-{$self->_bltID}"] == $fields["email-{$self->_bltID}"]) {
                             $errors["email-{$self->_bltID}"] = ts('The email address must be unique for each participant.');
                             break;
                         }
                     } else {
                         // check with first_name and last_name for additional participants
                         if ($value['first_name'] == $fields['first_name'] && $value['last_name'] == $fields['last_name']) {
                             $errors['first_name'] = ts('The first name and last name must be unique for each participant.');
                             break;
                         }
                     }
                 }
             }
         }
         //check for atleast one pricefields should be selected
         if (CRM_Utils_Array::value('priceSetId', $fields)) {
             $allParticipantParams = $params;
             //format current participant params.
             $allParticipantParams[$addParticipantNum] = self::formatPriceSetParams($self, $fields);
             $totalParticipants = self::getParticipantCount($self, $allParticipantParams);
             //validate price field params.
             $priceSetErrors = self::validatePriceSet($self, $allParticipantParams);
             $errors = array_merge($errors, CRM_Utils_Array::value($addParticipantNum, $priceSetErrors, array()));
             if (!$self->_allowConfirmation && is_numeric($self->_availableRegistrations)) {
                 if (CRM_Utils_Array::value('bypass_payment', $self->_params[0]) && !$self->_allowWaitlist && !$realPayLater && !$self->_requireApproval && !(CRM_Utils_Array::value('amount', $self->_params[0], 0) == 0) && $totalParticipants < $self->_availableRegistrations) {
                     $errors['_qf_default'] = ts("Your event registration will be confirmed. Please go back to the main registration page, to complete payment information.");
                 }
                 //check for availability of registrations.
                 if (!$self->_allowConfirmation && !CRM_Utils_Array::value('has_waitlist', $self->_values['event']) && $totalParticipants > $self->_availableRegistrations) {
                     $errors['_qf_default'] = ts('It looks like event has only %2 seats available and you are trying to register %1 participants, so could you please select price options accordingly.', array(1 => $totalParticipants, 2 => $self->_availableRegistrations));
                 }
             }
         }
     }
     if ($button == 'skip' && $self->_lastParticipant && CRM_Utils_Array::value('priceSetId', $fields)) {
         require_once 'CRM/Price/BAO/Set.php';
         $pricesetFieldsCount = CRM_Price_BAO_Set::getPricesetCount($fields['priceSetId']);
         if ($pricesetFieldsCount < 1 || $self->_allowConfirmation) {
             return $errors;
         }
         if (CRM_Utils_Array::value('has_waitlist', $self->_values['event']) && CRM_Utils_Array::value('bypass_payment', $self->_params[0]) && !$self->_allowWaitlist && !$realPayLater && !$self->_requireApproval && !(CRM_Utils_Array::value('amount', $self->_params[0], 0) == 0)) {
             $errors['_qf_default'] = ts("You are goinng to skip the last participant, your event registration will be confirmed. Please go back to the main registration page, to complete payment information.");
         }
     }
     if ($button != 'skip' && $self->_values['event']['is_monetary'] && !isset($errors['_qf_default']) && !$self->validatePaymentValues($self, $fields)) {
         $errors['_qf_default'] = ts("Your payement information looks incomplete. Please go back to the main registration page, to complete payment information.");
         $self->set('forcePayement', true);
     } else {
         if ($button == 'skip') {
             $self->set('forcePayement', true);
         }
     }
     return $errors;
 }
예제 #2
0
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', true);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', true);
     $this->assign('lineItem', $this->_lineItem);
     $this->assign('totalAmount', $this->_totalAmount);
     $hookDiscount = $this->get('hookDiscount');
     if ($hookDiscount) {
         $this->assign('hookDiscount', $hookDiscount);
     }
     $this->assign('receive_date', $this->_receiveDate);
     $this->assign('trxn_id', $this->_trxnId);
     if (CRM_Utils_Array::value('amount', $this->_params[0]) == 0) {
         $this->assign('isAmountzero', 1);
     }
     $this->assign('defaultRole', false);
     if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
         $this->assign('defaultRole', true);
     }
     $defaults = array();
     $fields = array();
     if (!empty($this->_fields)) {
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
     }
     $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
     foreach ($fields as $name => $dontCare) {
         if (isset($this->_params[0][$name])) {
             $defaults[$name] = $this->_params[0][$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($this->_params[0][$timeField])) {
                     $defaults[$timeField] = $this->_params[0][$timeField];
                 }
             } else {
                 if (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && CRM_Utils_Array::value($name . '_custom', $this->_params[0])) {
                     $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
                 }
             }
         }
     }
     $this->_submitValues = array_merge($this->_submitValues, $defaults);
     $this->setDefaults($defaults);
     require_once 'CRM/Friend/BAO/Friend.php';
     $params['entity_id'] = $this->_eventId;
     $params['entity_table'] = 'civicrm_event';
     CRM_Friend_BAO_Friend::retrieve($params, $data);
     if (CRM_Utils_Array::value('is_active', $data)) {
         $friendText = $data['title'];
         $this->assign('friendText', $friendText);
         if ($this->_action & CRM_Core_Action::PREVIEW) {
             $url = CRM_Utils_System::url("civicrm/friend", "eid={$this->_eventId}&reset=1&action=preview&page=event");
         } else {
             $url = CRM_Utils_System::url("civicrm/friend", "eid={$this->_eventId}&reset=1&page=event");
         }
         $this->assign('friendURL', $url);
     }
     $this->freeze();
     //lets give meaningful status message, CRM-4320.
     $isOnWaitlist = $isRequireApproval = false;
     if ($this->_allowWaitlist && !$this->_allowConfirmation) {
         $isOnWaitlist = true;
     }
     if ($this->_requireApproval && !$this->_allowConfirmation) {
         $isRequireApproval = true;
     }
     $this->assign('isOnWaitlist', $isOnWaitlist);
     $this->assign('isRequireApproval', $isRequireApproval);
     // Assign Participant Count to Lineitem Table
     require_once "CRM/Price/BAO/Set.php";
     $this->assign('pricesetFieldsCount', CRM_Price_BAO_Set::getPricesetCount($this->_priceSetId));
     // can we blow away the session now to prevent hackery
     $this->controller->reset();
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     if ($this->_params[0]['amount'] || $this->_params[0]['amount'] == 0) {
         $this->_amount = array();
         foreach ($this->_params as $k => $v) {
             if (is_array($v)) {
                 foreach (array('first_name', 'last_name') as $name) {
                     if (isset($v['billing_' . $name]) && !isset($v[$name])) {
                         $v[$name] = $v['billing_' . $name];
                     }
                 }
                 if (CRM_Utils_Array::value('first_name', $v) && CRM_Utils_Array::value('last_name', $v)) {
                     $append = $v['first_name'] . ' ' . $v['last_name'];
                 } else {
                     //use an email if we have one
                     foreach ($v as $v_key => $v_val) {
                         if (substr($v_key, 0, 6) == 'email-') {
                             $append = $v[$v_key];
                         }
                     }
                 }
                 $this->_amount[$k]['amount'] = $v['amount'];
                 if (CRM_Utils_Array::value('discountAmount', $v)) {
                     $this->_amount[$k]['amount'] -= $v['discountAmount'];
                 }
                 $this->_amount[$k]['label'] = preg_replace('//', '', $v['amount_level']) . '  -  ' . $append;
                 $this->_part[$k]['info'] = CRM_Utils_Array::value('first_name', $v) . ' ' . CRM_Utils_Array::value('last_name', $v);
                 if (!CRM_Utils_Array::value('first_name', $v)) {
                     $this->_part[$k]['info'] = $append;
                 }
                 $this->_totalAmount = $this->_totalAmount + $this->_amount[$k]['amount'];
                 if (CRM_Utils_Array::value('is_primary', $v)) {
                     $this->set('primaryParticipantAmount', $this->_amount[$k]['amount']);
                 }
             }
         }
         $this->assign('part', $this->_part);
         $this->set('part', $this->_part);
         $this->assign('amounts', $this->_amount);
         $this->assign('totalAmount', $this->_totalAmount);
         $this->set('totalAmount', $this->_totalAmount);
     }
     $config = CRM_Core_Config::singleton();
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     }
     //display additional participants profile.
     $participantParams = $this->_params;
     $formattedValues = array();
     $count = 1;
     foreach ($participantParams as $participantNum => $participantValue) {
         if ($participantNum && $participantValue != 'skip') {
             //get the customPre profile info
             if (CRM_Utils_Array::value('additional_custom_pre_id', $this->_values)) {
                 $values = $groupName = array();
                 CRM_Event_BAO_Event::displayProfile($participantValue, $this->_values['additional_custom_pre_id'], $groupName, $values);
                 if (count($values)) {
                     $formattedValues[$count]['additionalCustomPre'] = $values;
                 }
                 $formattedValues[$count]['additionalCustomPreGroupTitle'] = CRM_Utils_Array::value('groupTitle', $groupName);
             }
             //get the customPost profile info
             if (CRM_Utils_Array::value('additional_custom_post_id', $this->_values)) {
                 $values = $groupName = array();
                 foreach ($this->_values['additional_custom_post_id'] as $gids) {
                     $val = array();
                     CRM_Event_BAO_Event::displayProfile($participantValue, $gids, $group, $val);
                     $values[$gids] = $val;
                     $groupName[$gids] = $group;
                 }
                 if (count($values)) {
                     $formattedValues[$count]['additionalCustomPost'] = $values;
                 }
                 if (isset($formattedValues[$count]['additionalCustomPre'])) {
                     $formattedValues[$count]['additionalCustomPost'] = array_diff_assoc($formattedValues[$count]['additionalCustomPost'], $formattedValues[$count]['additionalCustomPre']);
                 }
                 $formattedValues[$count]['additionalCustomPostGroupTitle'] = $groupName;
             }
             $count++;
         }
     }
     if (!empty($formattedValues) && $count > 1) {
         $this->assign('addParticipantProfile', $formattedValues);
         $this->set('addParticipantProfile', $formattedValues);
     }
     //cosider total amount.
     $this->assign('isAmountzero', $this->_totalAmount <= 0 ? TRUE : FALSE);
     if ($this->_paymentProcessor['payment_processor_type'] == 'Google_Checkout' && !CRM_Utils_Array::value('is_pay_later', $this->_params[0]) && !($this->_params[0]['amount'] == 0) && !$this->_allowWaitlist && !$this->_requireApproval) {
         $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
         $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'form-submit'));
         $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Go Back'))));
     } else {
         $contribButton = ts('Continue');
         $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'name' => ts('Go Back'))));
     }
     $defaults = array();
     $fields = array();
     if (!empty($this->_fields)) {
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
     }
     $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
     foreach ($fields as $name => $dontCare) {
         if (isset($this->_params[0][$name])) {
             $defaults[$name] = $this->_params[0][$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($this->_params[0][$timeField])) {
                     $defaults[$timeField] = $this->_params[0][$timeField];
                 }
                 if (isset($this->_params[0]["{$name}_id"])) {
                     $defaults["{$name}_id"] = $this->_params[0]["{$name}_id"];
                 }
             } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes) && !empty($this->_params[0][$name . '_custom'])) {
                 $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
             }
         }
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $this->setDefaults($defaults);
     $this->freeze();
     //lets give meaningful status message, CRM-4320.
     $this->assign('isOnWaitlist', $this->_allowWaitlist);
     $this->assign('isRequireApproval', $this->_requireApproval);
     // Assign Participant Count to Lineitem Table
     $this->assign('pricesetFieldsCount', CRM_Price_BAO_Set::getPricesetCount($this->_priceSetId));
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     // Assign the email address from a contact id lookup as in CRM_Event_BAO_Event->sendMail()
     if (isset($this->_params[0]['contact_id'])) {
         list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_params[0]['contact_id']);
         $this->assign('email', $email);
     }
     $this->assignToTemplate();
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     }
     $this->assign('totalAmount', $this->_totalAmount);
     $hookDiscount = $this->get('hookDiscount');
     if ($hookDiscount) {
         $this->assign('hookDiscount', $hookDiscount);
     }
     $this->assign('receive_date', $this->_receiveDate);
     $this->assign('trxn_id', $this->_trxnId);
     //cosider total amount.
     $this->assign('isAmountzero', $this->_totalAmount <= 0 ? TRUE : FALSE);
     $this->assign('defaultRole', FALSE);
     if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
         $this->assign('defaultRole', TRUE);
     }
     $defaults = array();
     $fields = array();
     if (!empty($this->_fields)) {
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
     }
     $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
     foreach ($fields as $name => $dontCare) {
         if (isset($this->_params[0][$name])) {
             $defaults[$name] = $this->_params[0][$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($this->_params[0][$timeField])) {
                     $defaults[$timeField] = $this->_params[0][$timeField];
                 }
             } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes) && !empty($this->_params[0][$name . '_custom'])) {
                 $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
             }
         }
     }
     $this->_submitValues = array_merge($this->_submitValues, $defaults);
     $this->setDefaults($defaults);
     $params['entity_id'] = $this->_eventId;
     $params['entity_table'] = 'civicrm_event';
     CRM_Friend_BAO_Friend::retrieve($params, $data);
     if (CRM_Utils_Array::value('is_active', $data)) {
         $friendText = $data['title'];
         $this->assign('friendText', $friendText);
         if ($this->_action & CRM_Core_Action::PREVIEW) {
             $url = CRM_Utils_System::url('civicrm/friend', "eid={$this->_eventId}&reset=1&action=preview&pcomponent=event");
         } else {
             $url = CRM_Utils_System::url('civicrm/friend', "eid={$this->_eventId}&reset=1&pcomponent=event");
         }
         $this->assign('friendURL', $url);
     }
     $this->freeze();
     //lets give meaningful status message, CRM-4320.
     $isOnWaitlist = $isRequireApproval = FALSE;
     if ($this->_allowWaitlist && !$this->_allowConfirmation) {
         $isOnWaitlist = TRUE;
     }
     if ($this->_requireApproval && !$this->_allowConfirmation) {
         $isRequireApproval = TRUE;
     }
     $this->assign('isOnWaitlist', $isOnWaitlist);
     $this->assign('isRequireApproval', $isRequireApproval);
     // find pcp info
     $eventId = $this->_eventId;
     $dao = new CRM_PCP_DAO_PCPBlock();
     $dao->entity_table = 'civicrm_event';
     $dao->entity_id = $eventId;
     $dao->is_active = 1;
     $dao->find(TRUE);
     if ($dao->id) {
         $this->assign('pcpLink', CRM_Utils_System::url('civicrm/contribute/campaign', 'action=add&reset=1&pageId=' . $eventId . '&component=event'));
         $this->assign('pcpLinkText', $dao->link_text);
     }
     // Assign Participant Count to Lineitem Table
     $this->assign('pricesetFieldsCount', CRM_Price_BAO_Set::getPricesetCount($this->_priceSetId));
     // can we blow away the session now to prevent hackery
     $this->controller->reset();
 }