/**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param $self
  *
  *
  * @return bool|array
  *   true if no errors, else array of errors
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     //get the button name.
     $button = substr($self->controller->getButtonName(), -4);
     $realPayLater = FALSE;
     if (!empty($self->_values['event']['is_monetary']) && !empty($self->_values['event']['is_pay_later'])) {
         $realPayLater = CRM_Utils_Array::value('is_pay_later', $self->_params[0]);
     }
     if ($button != 'skip') {
         //Check that either an email or firstname+lastname is included in the form(CRM-9587)
         CRM_Event_Form_Registration_Register::checkProfileComplete($fields, $errors, $self->_eventId);
         //Additional Participant can also register for an event only once
         $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']) {
                         //collect all email fields
                         $existingEmails = array();
                         $additionalParticipantEmails = array();
                         if (is_array($value)) {
                             foreach ($value as $key => $val) {
                                 if (substr($key, 0, 6) == 'email-' && $val) {
                                     $existingEmails[] = $val;
                                 }
                             }
                         }
                         foreach ($fields as $key => $val) {
                             if (substr($key, 0, 6) == 'email-' && $val) {
                                 $additionalParticipantEmails[] = $val;
                                 $mailKey = $key;
                             }
                         }
                         //check if any emails are common to both arrays
                         if (count(array_intersect($existingEmails, $additionalParticipantEmails))) {
                             $errors[$mailKey] = ts('The email address must be unique for each participant.');
                             break;
                         }
                     } else {
                         // check with first_name and last_name for additional participants
                         if (!empty($value['first_name']) && $value['first_name'] == CRM_Utils_Array::value('first_name', $fields) && CRM_Utils_Array::value('last_name', $value) == CRM_Utils_Array::value('last_name', $fields)) {
                             $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 (!empty($fields['priceSetId'])) {
             $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 (!empty($self->_params[0]['bypass_payment']) && !$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 && empty($self->_values['event']['has_waitlist']) && $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 && !empty($fields['priceSetId'])) {
         $pricesetFieldsCount = CRM_Price_BAO_PriceSet::getPricesetCount($fields['priceSetId']);
         if ($pricesetFieldsCount < 1 || $self->_allowConfirmation) {
             return $errors;
         }
         if (!empty($self->_values['event']['has_waitlist']) && !empty($self->_params[0]['bypass_payment']) && !$self->_allowWaitlist && !$realPayLater && !$self->_requireApproval && !(CRM_Utils_Array::value('amount', $self->_params[0], 0) == 0)) {
             $errors['_qf_default'] = ts("You are going 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 payment information looks incomplete. Please go back to the main registration page, to complete payment information.");
         $self->set('forcePayement', TRUE);
     } elseif ($button == 'skip') {
         $self->set('forcePayement', TRUE);
     }
     return $errors;
 }
Example #2
0
 /**
  * Function to build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     // Assign the email address from a contact id lookup as in CRM_Event_BAO_Event->sendMail()
     $primaryContactId = $this->get('primaryContactId');
     if ($primaryContactId) {
         list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($primaryContactId);
         $this->assign('email', $email);
     }
     $this->assignToTemplate();
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $lineItemForTemplate = array();
         foreach ($this->_lineItem as $key => $value) {
             if (!empty($value)) {
                 $lineItemForTemplate[$key] = $value;
             }
         }
         if (!empty($lineItemForTemplate)) {
             $this->assign('lineItem', $lineItemForTemplate);
         }
     }
     $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';
     $data = array();
     CRM_Friend_BAO_Friend::retrieve($params, $data);
     if (!empty($data['is_active'])) {
         $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
     $dao = new CRM_PCP_DAO_PCPBlock();
     $dao->entity_table = 'civicrm_event';
     $dao->entity_id = $this->_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=' . $this->_eventId . '&component=event'));
         $this->assign('pcpLinkText', $dao->link_text);
     }
     // Assign Participant Count to Lineitem Table
     $this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId));
     // can we blow away the session now to prevent hackery
     $this->controller->reset();
 }
Example #3
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     if ($this->_values['event']['is_monetary'] && ($this->_params[0]['amount'] || $this->_params[0]['amount'] == 0)) {
         $this->_amount = array();
         $taxAmount = 0;
         foreach ($this->_params as $k => $v) {
             if ($v == 'skip') {
                 continue;
             }
             $individualTaxAmount = 0;
             //display tax amount on confirmation page
             $taxAmount += $v['tax_amount'];
             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 (!empty($v['first_name']) && !empty($v['last_name'])) {
                     $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 (!empty($v['discountAmount'])) {
                     $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 (empty($v['first_name'])) {
                     $this->_part[$k]['info'] = $append;
                 }
                 /*CRM-16320 */
                 $individual[$k]['totalAmtWithTax'] = $this->_amount[$k]['amount'];
                 $individual[$k]['totalTaxAmt'] = $individualTaxAmount + $v['tax_amount'];
                 $this->_totalAmount = $this->_totalAmount + $this->_amount[$k]['amount'];
                 if (!empty($v['is_primary'])) {
                     $this->set('primaryParticipantAmount', $this->_amount[$k]['amount']);
                 }
             }
         }
         $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
         $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
         $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
         if ($invoicing) {
             $this->assign('totalTaxAmount', $taxAmount);
             $this->assign('taxTerm', $taxTerm);
             $this->assign('individual', $individual);
             $this->set('individual', $individual);
         }
         $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);
     }
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $lineItemForTemplate = array();
         $getTaxDetails = FALSE;
         if (!empty($this->_lineItem) && is_array($this->_lineItem)) {
             foreach ($this->_lineItem as $key => $value) {
                 if (!empty($value)) {
                     $lineItemForTemplate[$key] = $value;
                 }
                 if ($invoicing) {
                     foreach ($value as $v) {
                         if (isset($v['tax_rate'])) {
                             $getTaxDetails = TRUE;
                         }
                     }
                 }
             }
         }
         if (!empty($lineItemForTemplate)) {
             $this->assign('lineItem', $lineItemForTemplate);
         }
         $this->assign('getTaxDetails', $getTaxDetails);
     }
     //display additional participants profile.
     self::assignProfiles($this);
     //consider total amount.
     $this->assign('isAmountzero', $this->_totalAmount <= 0 ? TRUE : FALSE);
     $contribButton = ts('Continue');
     $this->addButtons(array(array('type' => 'back', 'name' => ts('Go Back')), array('type' => 'next', 'name' => $contribButton, 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"))));
     $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'];
             }
         }
     }
     $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_PriceSet::getPricesetCount($this->_priceSetId));
     $this->addFormRule(array('CRM_Event_Form_Registration_Confirm', 'formRule'), $this);
 }
Example #4
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     if ($this->_values['event']['is_monetary'] && ($this->_params[0]['amount'] || $this->_params[0]['amount'] == 0)) {
         $this->_amount = array();
         $taxAmount = 0;
         foreach ($this->_params as $k => $v) {
             if ($v == 'skip') {
                 continue;
             }
             $individualTaxAmount = 0;
             //display tax amount on confirmation page
             $taxAmount += $v['tax_amount'];
             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 (!empty($v['first_name']) && !empty($v['last_name'])) {
                     $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 (!empty($v['discountAmount'])) {
                     $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 (empty($v['first_name'])) {
                     $this->_part[$k]['info'] = $append;
                 }
                 /*CRM-16320 */
                 $individual[$k]['totalAmtWithTax'] = $this->_amount[$k]['amount'];
                 $individual[$k]['totalTaxAmt'] = $individualTaxAmount + $v['tax_amount'];
                 $this->_totalAmount = $this->_totalAmount + $this->_amount[$k]['amount'];
                 if (!empty($v['is_primary'])) {
                     $this->set('primaryParticipantAmount', $this->_amount[$k]['amount']);
                 }
             }
         }
         $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
         $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
         $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
         if ($invoicing) {
             $this->assign('totalTaxAmount', $taxAmount);
             $this->assign('taxTerm', $taxTerm);
             $this->assign('individual', $individual);
             $this->set('individual', $individual);
         }
         $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);
     }
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $lineItemForTemplate = array();
         $getTaxDetails = FALSE;
         if (!empty($this->_lineItem) && is_array($this->_lineItem)) {
             foreach ($this->_lineItem as $key => $value) {
                 if (!empty($value)) {
                     $lineItemForTemplate[$key] = $value;
                 }
                 if ($invoicing) {
                     foreach ($value as $v) {
                         if (isset($v['tax_rate'])) {
                             $getTaxDetails = TRUE;
                         }
                     }
                 }
             }
         }
         if (!empty($lineItemForTemplate)) {
             $this->assign('lineItem', $lineItemForTemplate);
         }
         $this->assign('getTaxDetails', $getTaxDetails);
     }
     //display additional participants profile.
     self::assignProfiles($this);
     //consider total amount.
     $this->assign('isAmountzero', $this->_totalAmount <= 0 ? TRUE : FALSE);
     // @todo this needs to GO! We are getting rid of references to processor types in the code base in favour of
     // over-ride-able functions on them.
     // The processor effectively has a 'buildForm' hook it can use if it needs to.
     // The tricky thing is that we have no way of testing this code out - perhaps it hasn't worked for years!
     if ($this->_paymentProcessor['payment_processor_type'] == 'Google_Checkout' && empty($this->_params[0]['is_pay_later']) && !($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' => 'crm-form-submit'));
         $this->addButtons(array(array('type' => 'back', 'name' => ts('Go Back'))));
     } else {
         $contribButton = ts('Continue');
         $this->addButtons(array(array('type' => 'back', 'name' => ts('Go Back')), array('type' => 'next', 'name' => $contribButton, 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"))));
     }
     $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'];
             }
         }
     }
     $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_PriceSet::getPricesetCount($this->_priceSetId));
     $this->addFormRule(array('CRM_Event_Form_Registration_Confirm', 'formRule'), $this);
 }
Example #5
0
 /**
  * Function to build the form
  *
  * @return void
  * @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 (!empty($v['first_name']) && !empty($v['last_name'])) {
                     $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 (!empty($v['discountAmount'])) {
                     $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 (empty($v['first_name'])) {
                     $this->_part[$k]['info'] = $append;
                 }
                 $this->_totalAmount = $this->_totalAmount + $this->_amount[$k]['amount'];
                 if (!empty($v['is_primary'])) {
                     $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);
     }
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $lineItemForTemplate = array();
         foreach ($this->_lineItem as $key => $value) {
             if (!empty($value)) {
                 $lineItemForTemplate[$key] = $value;
             }
         }
         if (!empty($lineItemForTemplate)) {
             $this->assign('lineItem', $lineItemForTemplate);
         }
     }
     //display additional participants profile.
     $participantParams = $this->_params;
     $formattedValues = $profileFields = array();
     $count = 1;
     foreach ($participantParams as $participantNum => $participantValue) {
         if ($participantNum) {
             $prefix1 = 'additional';
             $prefix2 = 'additional_';
         } else {
             $prefix1 = '';
             $prefix2 = '';
         }
         if ($participantValue != 'skip') {
             //get the customPre profile info
             if (!empty($this->_values[$prefix2 . 'custom_pre_id'])) {
                 $values = $groupName = array();
                 CRM_Event_BAO_Event::displayProfile($participantValue, $this->_values[$prefix2 . 'custom_pre_id'], $groupName, $values, $profileFields);
                 if (count($values)) {
                     $formattedValues[$count][$prefix1 . 'CustomPre'] = $values;
                 }
                 $formattedValues[$count][$prefix1 . 'CustomPreGroupTitle'] = CRM_Utils_Array::value('groupTitle', $groupName);
             }
             //get the customPost profile info
             if (!empty($this->_values[$prefix2 . 'custom_post_id'])) {
                 $values = $groupName = array();
                 foreach ($this->_values[$prefix2 . 'custom_post_id'] as $gids) {
                     $val = array();
                     CRM_Event_BAO_Event::displayProfile($participantValue, $gids, $group, $val, $profileFields);
                     $values[$gids] = $val;
                     $groupName[$gids] = $group;
                 }
                 if (count($values)) {
                     $formattedValues[$count][$prefix1 . 'CustomPost'] = $values;
                 }
                 if (isset($formattedValues[$count][$prefix1 . 'CustomPre'])) {
                     $formattedValues[$count][$prefix1 . 'CustomPost'] = array_diff_assoc($formattedValues[$count][$prefix1 . 'CustomPost'], $formattedValues[$count][$prefix1 . 'CustomPre']);
                 }
                 $formattedValues[$count][$prefix1 . 'CustomPostGroupTitle'] = $groupName;
             }
             $count++;
         }
         $this->_fields = $profileFields;
     }
     if (!empty($formattedValues)) {
         $this->assign('primaryParticipantProfile', $formattedValues[1]);
         $this->set('primaryParticipantProfile', $formattedValues[1]);
         if ($count > 2) {
             unset($formattedValues[1]);
             $this->assign('addParticipantProfile', $formattedValues);
             $this->set('addParticipantProfile', $formattedValues);
         }
     }
     //consider total amount.
     $this->assign('isAmountzero', $this->_totalAmount <= 0 ? TRUE : FALSE);
     if ($this->_paymentProcessor['payment_processor_type'] == 'Google_Checkout' && empty($this->_params[0]['is_pay_later']) && !($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_PriceSet::getPricesetCount($this->_priceSetId));
 }
Example #6
0
 /**
  * Function to build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     if ($this->_values['event']['is_monetary'] && ($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 (!empty($v['first_name']) && !empty($v['last_name'])) {
                     $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 (!empty($v['discountAmount'])) {
                     $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 (empty($v['first_name'])) {
                     $this->_part[$k]['info'] = $append;
                 }
                 $this->_totalAmount = $this->_totalAmount + $this->_amount[$k]['amount'];
                 if (!empty($v['is_primary'])) {
                     $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);
     }
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $lineItemForTemplate = array();
         foreach ($this->_lineItem as $key => $value) {
             if (!empty($value)) {
                 $lineItemForTemplate[$key] = $value;
             }
         }
         if (!empty($lineItemForTemplate)) {
             $this->assign('lineItem', $lineItemForTemplate);
         }
     }
     //display additional participants profile.
     self::assignProfiles($this);
     //consider total amount.
     $this->assign('isAmountzero', $this->_totalAmount <= 0 ? TRUE : FALSE);
     if ($this->_paymentProcessor['payment_processor_type'] == 'Google_Checkout' && empty($this->_params[0]['is_pay_later']) && !($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' => 'crm-form-submit'));
         $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Go Back'))));
     } else {
         $contribButton = ts('Continue >>');
         $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Go Back')), array('type' => 'next', 'name' => $contribButton, 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"))));
     }
     $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'];
             }
         }
     }
     $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_PriceSet::getPricesetCount($this->_priceSetId));
 }