Example #1
0
 /**
  * Set variables up before form is built.
  *
  * @param CRM_Core_Form $form
  */
 public static function preProcess(&$form)
 {
     $session = CRM_Core_Session::singleton();
     $contactID = $form->_contactID;
     $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $form->_id);
     $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     $form->_profileId = $profileId[0];
     if (!$form->_profileId || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_profileId, 'is_active')) {
         CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
     }
     $requiredProfileFields = array('organization_name', 'email');
     $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_profileId, $requiredProfileFields);
     if (!$validProfile) {
         CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the required fields of the selected onbehalf profile are disabled.'));
     }
     $form->assign('profileId', $form->_profileId);
     $form->assign('mode', $form->_mode);
     if ($contactID) {
         $form->_employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID);
         if (!empty($form->_membershipContactID) && $contactID != $form->_membershipContactID) {
             // renewal case - membership being renewed may or may not be for organization
             if (!empty($form->_employers) && array_key_exists($form->_membershipContactID, $form->_employers)) {
                 // if _membershipContactID belongs to employers list, we can say:
                 $form->_relatedOrganizationFound = TRUE;
             }
         } elseif (!empty($form->_employers)) {
             // not a renewal case and _employers list is not empty
             $form->_relatedOrganizationFound = TRUE;
         }
         if ($form->_relatedOrganizationFound) {
             // Related org url - pass checksum if needed
             $args = array('cid' => '');
             if (!empty($_GET['cs'])) {
                 $args = array('uid' => $form->_contactID, 'cs' => $_GET['cs'], 'cid' => '');
             }
             $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
             $form->assign('locDataURL', $locDataURL);
             if (!empty($form->_submitValues['onbehalf'])) {
                 if (!empty($form->_submitValues['onbehalfof_id'])) {
                     $form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
                 }
                 $form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf']));
             }
         }
         if ($form->_values['is_for_organization'] != 2) {
             $form->assign('relatedOrganizationFound', $form->_relatedOrganizationFound);
         } else {
             $form->assign('onBehalfRequired', $form->_onBehalfRequired);
         }
         if (count($form->_employers) == 1) {
             foreach ($form->_employers as $id => $value) {
                 $form->_organizationName = $value['name'];
                 $orgId = $id;
             }
             $form->assign('orgId', $orgId);
             $form->assign('organizationName', $form->_organizationName);
         }
     }
 }
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @param null
  *
  * @return array    array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     $ufJoinParams = array('entity_table' => 'civicrm_survey', 'module' => 'CiviCampaign', 'entity_id' => $this->_surveyId);
     list($defaults['contact_profile_id'], $second) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     $defaults['activity_profile_id'] = $second ? array_shift($second) : '';
     return $defaults;
 }
Example #3
0
 /**
  * Set default values for the form.
  *
  * Note that in edit/view mode the default values are retrieved from the database.
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     $ufJoinParams = array('module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
     list($defaults['custom_pre_id'], $second) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     $defaults['custom_post_id'] = $second ? array_shift($second) : '';
     return $defaults;
 }
Example #4
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     if ($this->_id) {
         $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
         CRM_Utils_System::setTitle(ts('Include Profiles (%1)', array(1 => $title)));
     }
     $ufJoinParams = array('module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
     list($defaults['custom_pre_id'], $defaults['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     return $defaults;
 }
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     if ($this->_id) {
         $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
         CRM_Utils_System::setTitle(ts('Title and Settings (%1)', array(1 => $title)));
         $ufJoinParams = array('module' => 'OnBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $defaults['onbehalf_profile_id'] = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     } else {
         CRM_Utils_System::setTitle(ts('Title and Settings'));
     }
     return $defaults;
 }
Example #6
0
 /**
  * Set variables up before form is built.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function preProcess(&$form)
 {
     $contriDAO = new CRM_Contribute_DAO_Contribution();
     $contriDAO->id = $form->_id;
     $contriDAO->find(TRUE);
     if ($contriDAO->contribution_page_id) {
         $ufJoinParams = array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $contriDAO->contribution_page_id);
         $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         //check if any honree profile is enabled if yes then assign its profile type to $_honoreeProfileType
         // which will be used to constraint soft-credit contact type in formRule, CRM-13981
         if ($profileId[0]) {
             $form->_honoreeProfileType = CRM_Core_BAO_UFGroup::getContactType($profileId[0]);
         }
     }
 }
Example #7
0
 /**
  * Set variables up before form is built.
  *
  * @param CRM_Core_Form $form
  */
 public static function preProcess(&$form)
 {
     $session = CRM_Core_Session::singleton();
     $contactID = $session->get('userID');
     $ufJoinParams = array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $form->_id);
     $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     $form->_honoreeProfileId = $profileId[0];
     if (!$form->_honoreeProfileId || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_honoreeProfileId, 'is_active')) {
         CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.'));
     }
     $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_honoreeProfileId);
     $requiredProfileFields = array('Individual' => array('first_name', 'last_name'), 'Organization' => array('organization_name', 'email'), 'Household' => array('household_name', 'email'));
     $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_honoreeProfileId, $requiredProfileFields[$profileContactType]);
     if (!$validProfile) {
         CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
     }
 }
Example #8
0
 static function setValues($id, &$values)
 {
     $params = array('id' => $id);
     CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $values);
     // get the amounts and the label
     require_once 'CRM/Core/OptionGroup.php';
     $values['amount'] = array();
     CRM_Core_OptionGroup::getAssoc("civicrm_contribution_page.amount.{$id}", $values['amount'], true);
     // get the profile ids
     require_once 'CRM/Core/BAO/UFJoin.php';
     $ufJoinParams = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $id);
     list($values['custom_pre_id'], $values['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     // add an accounting code also
     if ($values['contribution_type_id']) {
         $values['accountingCode'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $values['contribution_type_id'], 'accounting_code');
     }
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 static function preProcess(&$form)
 {
     $session = CRM_Core_Session::singleton();
     $contactID = $session->get('userID');
     $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $form->_id);
     $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     $form->_profileId = $profileId[0];
     if (!$form->_profileId || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_profileId, 'is_active')) {
         CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
     }
     $requiredProfileFields = array('organization_name', 'email');
     $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_profileId, $requiredProfileFields);
     if (!$validProfile) {
         CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the required fields of the selected onbehalf profile are disabled.'));
     }
     $form->assign('profileId', $form->_profileId);
     $form->assign('mode', $form->_mode);
     if ($contactID) {
         $form->_employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID);
         if (!empty($form->_employers)) {
             $form->_relatedOrganizationFound = TRUE;
             $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', 'cid=', FALSE, NULL, FALSE);
             $form->assign('locDataURL', $locDataURL);
             $dataURL = CRM_Utils_System::url('civicrm/ajax/employer', 'cid=' . $contactID, FALSE, NULL, FALSE);
             $form->assign('employerDataURL', $dataURL);
         }
         if ($form->_values['is_for_organization'] != 2) {
             $form->assign('relatedOrganizationFound', $form->_relatedOrganizationFound);
         } else {
             $form->assign('onBehalfRequired', $form->_onBehalfRequired);
         }
         if (count($form->_employers) == 1) {
             foreach ($form->_employers as $id => $value) {
                 $form->_organizationName = $value['name'];
                 $orgId = $id;
             }
             $form->assign('orgId', $orgId);
             $form->assign('organizationName', $form->_organizationName);
         }
     }
 }
 /**
  * This function sets the default values for the form. 
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     $eventId = $this->_id;
     $defaults = parent::setDefaultValues();
     $this->setShowHide($defaults);
     if (isset($eventId)) {
         $params = array('id' => $eventId);
         CRM_Event_BAO_Event::retrieve($params, $defaults);
         require_once 'CRM/Core/BAO/UFJoin.php';
         $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent', 'entity_id' => $eventId);
         list($defaults['custom_pre_id'], $defaults['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         if ($defaults['is_multiple_registrations']) {
             // CRM-4377: set additional participants’ profiles – set to ‘none’ if explicitly unset (non-active)
             $ufJoin = new CRM_Core_DAO_UFJoin();
             $ufJoin->module = 'CiviEvent_Additional';
             $ufJoin->entity_table = 'civicrm_event';
             $ufJoin->entity_id = $eventId;
             $ufJoin->orderBy('weight');
             $ufJoin->find();
             $custom = array(1 => 'additional_custom_pre_id', 2 => 'additional_custom_post_id');
             while ($ufJoin->fetch()) {
                 $defaults[$custom[$ufJoin->weight]] = $ufJoin->is_active ? $ufJoin->uf_group_id : 'none';
             }
         }
     } else {
         $defaults['is_email_confirm'] = 0;
     }
     // provide defaults for required fields if empty (and as a 'hint' for approval message field)
     $defaults['registration_link_text'] = CRM_Utils_Array::value('registration_link_text', $defaults, ts('Register Now'));
     $defaults['confirm_title'] = CRM_Utils_Array::value('confirm_title', $defaults, ts('Confirm Your Registration Information'));
     $defaults['thankyou_title'] = CRM_Utils_Array::value('thankyou_title', $defaults, ts('Thank You for Registering'));
     $defaults['approval_req_text'] = CRM_Utils_Array::value('approval_req_text', $defaults, ts('Participation in this event requires approval. Submit your registration request here. Once approved, you will receive an email with a link to a web page where you can complete the registration process.'));
     if (CRM_Utils_Array::value('registration_start_date', $defaults)) {
         list($defaults['registration_start_date'], $defaults['registration_start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['registration_start_date'], 'activityDateTime');
     }
     if (CRM_Utils_Array::value('registration_end_date', $defaults)) {
         list($defaults['registration_end_date'], $defaults['registration_end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['registration_end_date'], 'activityDateTime');
     }
     return $defaults;
 }
Example #11
0
 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     $this->_eventId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
     //CRM-4320
     $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this);
     // current mode
     $this->_mode = $this->_action == 1024 ? 'test' : 'live';
     $this->_values = $this->get('values');
     $this->_fields = $this->get('fields');
     $this->_bltID = $this->get('bltID');
     $this->_paymentProcessor = $this->get('paymentProcessor');
     $this->_priceSetId = $this->get('priceSetId');
     $this->_priceSet = $this->get('priceSet');
     $this->_lineItem = $this->get('lineItem');
     $this->_isEventFull = $this->get('isEventFull');
     $this->_lineItemParticipantsCount = $this->get('lineItemParticipants');
     if (!is_array($this->_lineItem)) {
         $this->_lineItem = array();
     }
     if (!is_array($this->_lineItemParticipantsCount)) {
         $this->_lineItemParticipantsCount = array();
     }
     $this->_availableRegistrations = $this->get('availableRegistrations');
     $this->_participantIDS = $this->get('participantIDs');
     //check if participant allow to walk registration wizard.
     $this->_allowConfirmation = $this->get('allowConfirmation');
     // check for Approval
     $this->_requireApproval = $this->get('requireApproval');
     // check for waitlisting.
     $this->_allowWaitlist = $this->get('allowWaitlist');
     $this->_forcePayement = $this->get('forcePayement');
     //get the additional participant ids.
     $this->_additionalParticipantIds = $this->get('additionalParticipantIds');
     $config = CRM_Core_Config::singleton();
     if (!$this->_values) {
         // create redirect URL to send folks back to event info page is registration not available
         $infoUrl = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_eventId}", FALSE, NULL, FALSE, TRUE);
         // this is the first time we are hitting this, so check for permissions here
         if (!CRM_Core_Permission::event(CRM_Core_Permission::EDIT, $this->_eventId, 'register for events')) {
             CRM_Core_Error::statusBounce(ts('You do not have permission to register for this event'), $infoUrl);
         }
         // get all the values from the dao object
         $this->_values = $this->_fields = array();
         $this->_forcePayement = FALSE;
         //retrieve event information
         $params = array('id' => $this->_eventId);
         CRM_Event_BAO_Event::retrieve($params, $this->_values['event']);
         // check for is_monetary status
         $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values['event']);
         // check for ability to add contributions of type
         if ($isMonetary && CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($this->_values['event']['financial_type_id']))) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
         $this->checkValidEvent($infoUrl);
         // get the participant values, CRM-4320
         $this->_allowConfirmation = FALSE;
         if ($this->_participantId) {
             $this->processFirstParticipant($this->_participantId);
         }
         //check for additional participants.
         if ($this->_allowConfirmation && $this->_values['event']['is_multiple_registrations']) {
             $additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId);
             $cnt = 1;
             foreach ($additionalParticipantIds as $additionalParticipantId) {
                 $this->_additionalParticipantIds[$cnt] = $additionalParticipantId;
                 $cnt++;
             }
             $this->set('additionalParticipantIds', $this->_additionalParticipantIds);
         }
         $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId, FALSE, CRM_Utils_Array::value('has_waitlist', $this->_values['event']));
         $this->_allowWaitlist = $this->_isEventFull = FALSE;
         if ($eventFull && !$this->_allowConfirmation) {
             $this->_isEventFull = TRUE;
             //lets redirecting to info only when to waiting list.
             $this->_allowWaitlist = CRM_Utils_Array::value('has_waitlist', $this->_values['event']);
             if (!$this->_allowWaitlist) {
                 CRM_Utils_System::redirect($infoUrl);
             }
         }
         $this->set('isEventFull', $this->_isEventFull);
         $this->set('allowWaitlist', $this->_allowWaitlist);
         //check for require requires approval.
         $this->_requireApproval = FALSE;
         if (!empty($this->_values['event']['requires_approval']) && !$this->_allowConfirmation) {
             $this->_requireApproval = TRUE;
         }
         $this->set('requireApproval', $this->_requireApproval);
         if (isset($this->_values['event']['default_role_id'])) {
             $participant_role = CRM_Core_OptionGroup::values('participant_role');
             $this->_values['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"];
         }
         $isPayLater = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eventId, 'is_pay_later');
         //check for various combinations for paylater, payment
         //process with paid event.
         if ($isMonetary && (!$isPayLater || !empty($this->_values['event']['payment_processor']))) {
             $this->_paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('payment_processor', $this->_values['event']));
             $this->assignPaymentProcessor($isPayLater);
         }
         //init event fee.
         self::initEventFee($this, $this->_eventId);
         // get the profile ids
         $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent', 'entity_id' => $this->_eventId);
         list($this->_values['custom_pre_id'], $this->_values['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         // set profiles for additional participants
         if ($this->_values['event']['is_multiple_registrations']) {
             // CRM-4377: CiviEvent for the main participant, CiviEvent_Additional for additional participants
             $ufJoinParams['module'] = 'CiviEvent_Additional';
             list($this->_values['additional_custom_pre_id'], $this->_values['additional_custom_post_id'], $preActive, $postActive) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
             // CRM-4377: we need to maintain backward compatibility, hence if there is profile for main contact
             // set same profile for additional contacts.
             if ($this->_values['custom_pre_id'] && !$this->_values['additional_custom_pre_id']) {
                 $this->_values['additional_custom_pre_id'] = $this->_values['custom_pre_id'];
             }
             if ($this->_values['custom_post_id'] && !$this->_values['additional_custom_post_id']) {
                 $this->_values['additional_custom_post_id'] = $this->_values['custom_post_id'];
             }
             // now check for no profile condition, in that case is_active = 0
             if (isset($preActive) && !$preActive) {
                 unset($this->_values['additional_custom_pre_id']);
             }
             if (isset($postActive) && !$postActive) {
                 unset($this->_values['additional_custom_post_id']);
             }
         }
         $this->assignBillingType();
         if ($this->_values['event']['is_monetary']) {
             CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor);
         }
         $params = array('entity_id' => $this->_eventId, 'entity_table' => 'civicrm_event');
         $this->_values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
         $this->set('values', $this->_values);
         $this->set('fields', $this->_fields);
         $this->_availableRegistrations = CRM_Event_BAO_Participant::eventFull($this->_values['event']['id'], TRUE, CRM_Utils_Array::value('has_waitlist', $this->_values['event']));
         $this->set('availableRegistrations', $this->_availableRegistrations);
     }
     $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor);
     // check if this is a paypal auto return and redirect accordingly
     if (CRM_Core_Payment::paypalRedirect($this->_paymentProcessor)) {
         $url = CRM_Utils_System::url('civicrm/event/register', "_qf_ThankYou_display=1&qfKey={$this->controller->_key}");
         CRM_Utils_System::redirect($url);
     }
     // The concept of contributeMode is deprecated.
     $this->_contributeMode = $this->get('contributeMode');
     $this->assign('contributeMode', $this->_contributeMode);
     // setting CMS page title
     CRM_Utils_System::setTitle($this->_values['event']['title']);
     $this->assign('title', $this->_values['event']['title']);
     $this->assign('paidEvent', $this->_values['event']['is_monetary']);
     // we do not want to display recently viewed items on Registration pages
     $this->assign('displayRecent', FALSE);
     // Registration page values are cleared from session, so can't use normal Printer Friendly view.
     // Use Browser Print instead.
     $this->assign('browserPrint', TRUE);
     $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']);
     $this->assign('isShowLocation', $isShowLocation);
     // Handle PCP
     $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this);
     if ($pcpId) {
         $pcp = CRM_PCP_BAO_PCP::handlePcp($pcpId, 'event', $this->_values['event']);
         $this->_pcpId = $pcp['pcpId'];
         $this->_values['event']['intro_text'] = CRM_Utils_Array::value('intro_text', $pcp['pcpInfo']);
     }
     // assign all event properties so wizard templates can display event info.
     $this->assign('event', $this->_values['event']);
     $this->assign('location', $this->_values['location']);
     $this->assign('bltID', $this->_bltID);
     $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']);
     $this->assign('isShowLocation', $isShowLocation);
     //CRM-6907
     $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values['event'], $config->defaultCurrency);
     //lets allow user to override campaign.
     $campID = CRM_Utils_Request::retrieve('campID', 'Positive', $this);
     if ($campID && CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
         $this->_values['event']['campaign_id'] = $campID;
     }
     // Set the same value for is_billing_required as contribution page so code can be shared.
     $this->_values['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $this->_values['event']);
     // check if billing block is required for pay later
     // note that I have started removing the use of isBillingAddressRequiredForPayLater in favour of letting
     // the CRM_Core_Payment_Manual class handle it - but there are ~300 references to it in the code base so only
     // removing in very limited cases.
     if (CRM_Utils_Array::value('is_pay_later', $this->_values['event'])) {
         $this->_isBillingAddressRequiredForPayLater = CRM_Utils_Array::value('is_billing_required', $this->_values['event']);
         $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater);
     }
 }
 function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE)
 {
     $contribution =& $objects['contribution'];
     $memberships =& $objects['membership'];
     if (is_numeric($memberships)) {
         $memberships = array($objects['membership']);
     }
     $participant =& $objects['participant'];
     $event =& $objects['event'];
     $changeToday = CRM_Utils_Array::value('trxn_date', $input, self::$_now);
     $recurContrib =& $objects['contributionRecur'];
     $values = array();
     if ($input['component'] == 'contribute') {
         if ($contribution->contribution_page_id) {
             CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
             $source = ts('Online Contribution') . ': ' . $values['title'];
         } elseif ($recurContrib->id) {
             $contribution->contribution_page_id = NULL;
             $values['amount'] = $recurContrib->amount;
             $values['contribution_type_id'] = $objects['contributionType']->id;
             $values['title'] = $source = ts('Offline Recurring Contribution');
             $values['is_email_receipt'] = $recurContrib->is_email_receipt;
             $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
             $values['receipt_from_name'] = $domainValues[0];
             $values['receipt_from_email'] = $domainValues[1];
         }
         $contribution->source = $source;
         if (CRM_Utils_Array::value('is_email_receipt', $values)) {
             $contribution->receipt_date = self::$_now;
         }
         if (!empty($memberships)) {
             foreach ($memberships as $membershipTypeIdKey => $membership) {
                 if ($membership) {
                     $format = '%Y%m%d';
                     $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id);
                     // CRM-8141 update the membership type with the value recorded in log when membership created/renewed
                     // this picks up membership type changes during renewals
                     $sql = "\nSELECT    membership_type_id\nFROM      civicrm_membership_log\nWHERE     membership_id={$membership->id}\nORDER BY  id DESC\nLIMIT 1;";
                     $dao = new CRM_Core_DAO();
                     $dao->query($sql);
                     if ($dao->fetch()) {
                         if (!empty($dao->membership_type_id)) {
                             $membership->membership_type_id = $dao->membership_type_id;
                             $membership->save();
                         }
                         // else fall back to using current membership type
                     }
                     // else fall back to using current membership type
                     $dao->free();
                     if ($currentMembership) {
                         /*
                          * Fixed FOR CRM-4433
                          * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
                          * when Contribution mode is notify and membership is for renewal )
                          */
                         CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);
                         $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday);
                         $dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
                     } else {
                         $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id);
                     }
                     //get the status for membership.
                     $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE);
                     $formatedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, 2), 'join_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $dates), $format), 'start_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $dates), $format), 'end_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $dates), $format), 'reminder_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('reminder_date', $dates), $format));
                     //we might be renewing membership,
                     //so make status override false.
                     $formatedParams['is_override'] = FALSE;
                     $membership->copyValues($formatedParams);
                     $membership->save();
                     //updating the membership log
                     $membershipLog = array();
                     $membershipLog = $formatedParams;
                     $logStartDate = $formatedParams['start_date'];
                     if (CRM_Utils_Array::value('log_start_date', $dates)) {
                         $logStartDate = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
                         $logStartDate = CRM_Utils_Date::isoToMysql($logStartDate);
                     }
                     $membershipLog['start_date'] = $logStartDate;
                     $membershipLog['membership_id'] = $membership->id;
                     $membershipLog['modified_id'] = $membership->contact_id;
                     $membershipLog['modified_date'] = date('Ymd');
                     $membershipLog['membership_type_id'] = $membership->membership_type_id;
                     CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
                     //update related Memberships.
                     CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams);
                     //update the membership type key of membership relatedObjects array
                     //if it has changed after membership update
                     if ($membershipTypeIdKey != $membership->membership_type_id) {
                         $memberships[$membership->membership_type_id] = $membership;
                         $contribution->_relatedObjects['membership'][$membership->membership_type_id] = $membership;
                         unset($contribution->_relatedObjects['membership'][$membershipTypeIdKey]);
                         unset($memberships[$membershipTypeIdKey]);
                     }
                 }
             }
         }
     } else {
         // event
         $eventParams = array('id' => $objects['event']->id);
         $values['event'] = array();
         CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
         $eventParams = array('id' => $objects['event']->id);
         $values['event'] = array();
         CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
         //get location details
         $locationParams = array('entity_id' => $objects['event']->id, 'entity_table' => 'civicrm_event');
         $values['location'] = CRM_Core_BAO_Location::getValues($locationParams);
         $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'module' => 'CiviEvent');
         list($custom_pre_id, $custom_post_ids) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $values['custom_pre_id'] = $custom_pre_id;
         $values['custom_post_id'] = $custom_post_ids;
         $contribution->source = ts('Online Event Registration') . ': ' . $values['event']['title'];
         if ($values['event']['is_email_confirm']) {
             $contribution->receipt_date = self::$_now;
             $values['is_email_receipt'] = 1;
         }
         $participant->status_id = 1;
         $participant->save();
     }
     if (CRM_Utils_Array::value('net_amount', $input, 0) == 0 && CRM_Utils_Array::value('fee_amount', $input, 0) != 0) {
         $input['net_amount'] = $input['amount'] - $input['fee_amount'];
     }
     $addLineItems = FALSE;
     if (empty($contribution->id)) {
         $addLineItems = TRUE;
     }
     $contribution->contribution_status_id = 1;
     $contribution->is_test = $input['is_test'];
     $contribution->fee_amount = CRM_Utils_Array::value('fee_amount', $input, 0);
     $contribution->net_amount = CRM_Utils_Array::value('net_amount', $input, 0);
     $contribution->trxn_id = $input['trxn_id'];
     $contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date);
     $contribution->thankyou_date = CRM_Utils_Date::isoToMysql($contribution->thankyou_date);
     $contribution->cancel_date = 'null';
     if (CRM_Utils_Array::value('check_number', $input)) {
         $contribution->check_number = $input['check_number'];
     }
     if (CRM_Utils_Array::value('payment_instrument_id', $input)) {
         $contribution->payment_instrument_id = $input['payment_instrument_id'];
     }
     $contribution->save();
     //add lineitems for recurring payments
     if (CRM_Utils_Array::value('contributionRecur', $objects) && $objects['contributionRecur']->id && $addLineItems) {
         $this->addrecurLineItems($objects['contributionRecur']->id, $contribution->id);
     }
     // next create the transaction record
     $paymentProcessor = '';
     if (isset($objects['paymentProcessor'])) {
         if (is_array($objects['paymentProcessor'])) {
             $paymentProcessor = $objects['paymentProcessor']['payment_processor_type'];
         } else {
             $paymentProcessor = $objects['paymentProcessor']->payment_processor_type;
         }
     }
     if ($contribution->trxn_id) {
         $trxnParams = array('contribution_id' => $contribution->id, 'trxn_date' => isset($input['trxn_date']) ? $input['trxn_date'] : self::$_now, 'trxn_type' => 'Debit', 'total_amount' => $input['amount'], 'fee_amount' => $contribution->fee_amount, 'net_amount' => $contribution->net_amount, 'currency' => $contribution->currency, 'payment_processor' => $paymentProcessor, 'trxn_id' => $contribution->trxn_id);
         $trxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams);
     }
     self::updateRecurLinkedPledge($contribution);
     // create an activity record
     if ($input['component'] == 'contribute') {
         //CRM-4027
         $targetContactID = NULL;
         if (CRM_Utils_Array::value('related_contact', $ids)) {
             $targetContactID = $contribution->contact_id;
             $contribution->contact_id = $ids['related_contact'];
         }
         CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID);
         // event
     } else {
         CRM_Activity_BAO_Activity::addActivity($participant);
     }
     CRM_Core_Error::debug_log_message("Contribution record updated successfully");
     $transaction->commit();
     // CRM-9132 legacy behaviour was that receipts were sent out in all instances. Still sending
     // when array_key 'is_email_receipt doesn't exist in case some instances where is needs setting haven't been set
     if (!array_key_exists('is_email_receipt', $values) || $values['is_email_receipt'] == 1) {
         self::sendMail($input, $ids, $objects, $values, $recur, FALSE);
     }
     CRM_Core_Error::debug_log_message("Success: Database updated and mail sent");
 }
 function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE)
 {
     $contribution =& $objects['contribution'];
     $primaryContributionID = isset($contribution->id) ? $contribution->id : $objects['first_contribution']->id;
     $memberships =& $objects['membership'];
     if (is_numeric($memberships)) {
         $memberships = array($objects['membership']);
     }
     $participant =& $objects['participant'];
     $event =& $objects['event'];
     $changeToday = CRM_Utils_Array::value('trxn_date', $input, self::$_now);
     $recurContrib =& $objects['contributionRecur'];
     $values = array();
     if (isset($input['is_email_receipt'])) {
         $values['is_email_receipt'] = $input['is_email_receipt'];
     }
     $source = NULL;
     if ($input['component'] == 'contribute') {
         if ($contribution->contribution_page_id) {
             CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
             $source = ts('Online Contribution') . ': ' . $values['title'];
         } elseif ($recurContrib && $recurContrib->id) {
             $contribution->contribution_page_id = NULL;
             $values['amount'] = $recurContrib->amount;
             $values['financial_type_id'] = $objects['contributionType']->id;
             $values['title'] = $source = ts('Offline Recurring Contribution');
             $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
             $values['receipt_from_name'] = $domainValues[0];
             $values['receipt_from_email'] = $domainValues[1];
         }
         if ($recurContrib && $recurContrib->id && !isset($input['is_email_receipt'])) {
             //CRM-13273 - is_email_receipt setting on recurring contribution should take precedence over contribution page setting
             // but CRM-16124 if $input['is_email_receipt'] is set then that should not be overridden.
             $values['is_email_receipt'] = $recurContrib->is_email_receipt;
         }
         $contribution->source = $source;
         if (CRM_Utils_Array::value('is_email_receipt', $values)) {
             $contribution->receipt_date = self::$_now;
         }
         if (!empty($memberships)) {
             $membershipsUpdate = array();
             foreach ($memberships as $membershipTypeIdKey => $membership) {
                 if ($membership) {
                     $format = '%Y%m%d';
                     $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id);
                     // CRM-8141 update the membership type with the value recorded in log when membership created/renewed
                     // this picks up membership type changes during renewals
                     $sql = "\nSELECT    membership_type_id\nFROM      civicrm_membership_log\nWHERE     membership_id={$membership->id}\nORDER BY  id DESC\nLIMIT 1;";
                     $dao = new CRM_Core_DAO();
                     $dao->query($sql);
                     if ($dao->fetch()) {
                         if (!empty($dao->membership_type_id)) {
                             $membership->membership_type_id = $dao->membership_type_id;
                             $membership->save();
                         }
                         // else fall back to using current membership type
                     }
                     // else fall back to using current membership type
                     $dao->free();
                     $num_terms = $contribution->getNumTermsByContributionAndMembershipType($membership->membership_type_id, $primaryContributionID);
                     if ($currentMembership) {
                         /*
                          * Fixed FOR CRM-4433
                          * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
                          * when Contribution mode is notify and membership is for renewal )
                          */
                         CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);
                         // @todo - we should pass membership_type_id instead of null here but not
                         // adding as not sure of testing
                         $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday, NULL, $num_terms);
                         $dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
                     } else {
                         $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id, NULL, NULL, NULL, $num_terms);
                     }
                     //get the status for membership.
                     $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE, $membership->membership_type_id, (array) $membership);
                     $formatedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, 2), 'join_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $dates), $format), 'start_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $dates), $format), 'end_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $dates), $format));
                     //we might be renewing membership,
                     //so make status override false.
                     $formatedParams['is_override'] = FALSE;
                     $membership->copyValues($formatedParams);
                     $membership->save();
                     //updating the membership log
                     $membershipLog = array();
                     $membershipLog = $formatedParams;
                     $logStartDate = $formatedParams['start_date'];
                     if (CRM_Utils_Array::value('log_start_date', $dates)) {
                         $logStartDate = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
                         $logStartDate = CRM_Utils_Date::isoToMysql($logStartDate);
                     }
                     $membershipLog['start_date'] = $logStartDate;
                     $membershipLog['membership_id'] = $membership->id;
                     $membershipLog['modified_id'] = $membership->contact_id;
                     $membershipLog['modified_date'] = date('Ymd');
                     $membershipLog['membership_type_id'] = $membership->membership_type_id;
                     CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
                     //update related Memberships.
                     CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams);
                     //update the membership type key of membership relatedObjects array
                     //if it has changed after membership update
                     if ($membershipTypeIdKey != $membership->membership_type_id) {
                         $membershipsUpdate[$membership->membership_type_id] = $membership;
                         $contribution->_relatedObjects['membership'][$membership->membership_type_id] = $membership;
                         unset($contribution->_relatedObjects['membership'][$membershipTypeIdKey]);
                         unset($memberships[$membershipTypeIdKey]);
                     }
                 }
             }
             //update the memberships object with updated membershipTypeId data
             //if membershipTypeId has changed after membership update
             if (!empty($membershipsUpdate)) {
                 $memberships = $memberships + $membershipsUpdate;
             }
         }
     } else {
         // event
         $eventParams = array('id' => $objects['event']->id);
         $values['event'] = array();
         CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
         //get location details
         $locationParams = array('entity_id' => $objects['event']->id, 'entity_table' => 'civicrm_event');
         $values['location'] = CRM_Core_BAO_Location::getValues($locationParams);
         $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'module' => 'CiviEvent');
         list($custom_pre_id, $custom_post_ids) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $values['custom_pre_id'] = $custom_pre_id;
         $values['custom_post_id'] = $custom_post_ids;
         //for tasks 'Change Participant Status' and 'Batch Update Participants Via Profile' case
         //and cases involving status updation through ipn
         $values['totalAmount'] = $input['amount'];
         $contribution->source = ts('Online Event Registration') . ': ' . $values['event']['title'];
         if ($values['event']['is_email_confirm']) {
             $contribution->receipt_date = self::$_now;
             $values['is_email_receipt'] = 1;
         }
         if (!CRM_Utils_Array::value('skipComponentSync', $input)) {
             $participant->status_id = 1;
         }
         $participant->save();
     }
     if (CRM_Utils_Array::value('net_amount', $input, 0) == 0 && CRM_Utils_Array::value('fee_amount', $input, 0) != 0) {
         $input['net_amount'] = $input['amount'] - $input['fee_amount'];
     }
     // This complete transaction function is being overloaded to create new contributions too.
     // here we record if it is a new contribution.
     // @todo separate the 2 more appropriately.
     $isNewContribution = FALSE;
     if (empty($contribution->id)) {
         $isNewContribution = TRUE;
         if (!empty($input['amount']) && $input['amount'] != $contribution->total_amount) {
             $contribution->total_amount = $input['amount'];
             // The BAO does this stuff but we are actually kinda bypassing it here (bad code! go sit in the corner)
             // so we have to handle net_amount in this (naughty) code.
             if (isset($input['fee_amount']) && is_numeric($input['fee_amount'])) {
                 $contribution->fee_amount = $input['fee_amount'];
             }
             $contribution->net_amount = $contribution->total_amount - $contribution->fee_amount;
         }
         if (!empty($input['campaign_id'])) {
             $contribution->campaign_id = $input['campaign_id'];
         }
     }
     $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array('labelColumn' => 'name', 'flip' => 1));
     // @todo this section should call the api  in order to have hooks called &
     // because all this 'messiness' setting variables could be avoided
     // by letting the api resolve pseudoconstants & copy set values and format dates.
     $contribution->contribution_status_id = $contributionStatuses['Completed'];
     $contribution->is_test = $input['is_test'];
     // CRM-15960 If we don't have a value we 'want' for the amounts, leave it to the BAO to sort out.
     if (isset($input['net_amount'])) {
         $contribution->fee_amount = CRM_Utils_Array::value('fee_amount', $input, 0);
     }
     if (isset($input['net_amount'])) {
         $contribution->net_amount = $input['net_amount'];
     }
     $contribution->trxn_id = $input['trxn_id'];
     $contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date);
     $contribution->thankyou_date = CRM_Utils_Date::isoToMysql($contribution->thankyou_date);
     $contribution->receipt_date = CRM_Utils_Date::isoToMysql($contribution->receipt_date);
     $contribution->cancel_date = 'null';
     if (CRM_Utils_Array::value('check_number', $input)) {
         $contribution->check_number = $input['check_number'];
     }
     if (CRM_Utils_Array::value('payment_instrument_id', $input)) {
         $contribution->payment_instrument_id = $input['payment_instrument_id'];
     }
     if (!empty($contribution->id)) {
         $contributionId['id'] = $contribution->id;
         $input['prevContribution'] = CRM_Contribute_BAO_Contribution::getValues($contributionId, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
     }
     $contribution->save();
     //add line items for recurring payments
     if (!empty($contribution->contribution_recur_id)) {
         if ($isNewContribution) {
             $input['line_item'] = $this->addRecurLineItems($contribution->contribution_recur_id, $contribution);
         } else {
             // this is just to prevent e-notices when we call recordFinancialAccounts - per comments on that line - intention is somewhat unclear
             $input['line_item'] = array();
         }
         if (!empty($memberships) && $primaryContributionID != $contribution->id) {
             foreach ($memberships as $membership) {
                 try {
                     $membershipPayment = array('membership_id' => $membership->id, 'contribution_id' => $contribution->id);
                     if (!civicrm_api3('membership_payment', 'getcount', $membershipPayment)) {
                         civicrm_api3('membership_payment', 'create', $membershipPayment);
                     }
                 } catch (CiviCRM_API3_Exception $e) {
                     echo $e->getMessage();
                     // we are catching & ignoring errors as an extra precaution since lost IPNs may be more serious that lost membership_payment data
                     // this fn is unit-tested so risk of changes elsewhere breaking it are otherwise mitigated
                 }
             }
         }
     }
     //copy initial contribution custom fields for recurring contributions
     if ($recurContrib && $recurContrib->id) {
         $this->copyCustomValues($recurContrib->id, $contribution->id);
     }
     // next create the transaction record
     $paymentProcessor = $paymentProcessorId = '';
     if (isset($objects['paymentProcessor'])) {
         if (is_array($objects['paymentProcessor'])) {
             $paymentProcessor = $objects['paymentProcessor']['payment_processor_type'];
             $paymentProcessorId = $objects['paymentProcessor']['id'];
         } else {
             $paymentProcessor = $objects['paymentProcessor']->payment_processor_type;
             $paymentProcessorId = $objects['paymentProcessor']->id;
         }
     }
     //it's hard to see how it could reach this point without a contributon id as it is saved in line 511 above
     // which raised the question as to whether this check preceded line 511 & if so whether something could be broken
     // From a lot of code reading /debugging I'm still not sure the intent WRT first & subsequent payments in this code
     // it would be good if someone added some comments or refactored this
     if ($contribution->id) {
         $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         if (empty($input['prevContribution']) && $paymentProcessorId || !$input['prevContribution']->is_pay_later && $input['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatuses)) {
             $input['payment_processor'] = $paymentProcessorId;
         }
         $input['contribution_status_id'] = array_search('Completed', $contributionStatuses);
         $input['total_amount'] = $input['amount'];
         $input['contribution'] = $contribution;
         $input['financial_type_id'] = $contribution->financial_type_id;
         if (CRM_Utils_Array::value('participant', $contribution->_relatedObjects)) {
             $input['contribution_mode'] = 'participant';
             $input['participant_id'] = $contribution->_relatedObjects['participant']->id;
             $input['skipLineItem'] = 1;
         }
         //@todo writing a unit test I was unable to create a scenario where this line did not fatal on second
         // and subsequent payments. In this case the line items are created at $this->addRecurLineItems
         // and since the contribution is saved prior to this line there is always a contribution-id,
         // however there is never a prevContribution (which appears to mean original contribution not previous
         // contribution - or preUpdateContributionObject most accurately)
         // so, this is always called & only appears to succeed when prevContribution exists - which appears
         // to mean "are we updating an exisitng pending contribution"
         //I was able to make the unit test complete as fataling here doesn't prevent
         // the contribution being created - but activities would not be created or emails sent
         CRM_Contribute_BAO_Contribution::recordFinancialAccounts($input, NULL);
     }
     self::updateRecurLinkedPledge($contribution);
     // create an activity record
     if ($input['component'] == 'contribute') {
         //CRM-4027
         $targetContactID = NULL;
         if (CRM_Utils_Array::value('related_contact', $ids)) {
             $targetContactID = $contribution->contact_id;
             $contribution->contact_id = $ids['related_contact'];
         }
         CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID);
         // event
     } else {
         CRM_Activity_BAO_Activity::addActivity($participant);
     }
     CRM_Core_Error::debug_log_message("Contribution record updated successfully");
     $transaction->commit();
     // CRM-9132 legacy behaviour was that receipts were sent out in all instances. Still sending
     // when array_key 'is_email_receipt doesn't exist in case some instances where is needs setting haven't been set
     if (!array_key_exists('is_email_receipt', $values) || $values['is_email_receipt'] == 1) {
         self::sendMail($input, $ids, $objects, $values, $recur, FALSE);
         CRM_Core_Error::debug_log_message("Receipt sent");
     }
     CRM_Core_Error::debug_log_message("Success: Database updated");
 }
Example #14
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $params = $this->_params;
     $honor_block_is_active = $this->get('honor_block_is_active');
     // make sure we have values for it
     if ($honor_block_is_active && !empty($params['soft_credit_type_id'])) {
         $honorName = null;
         $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
         $this->assign('honor_block_is_active', $honor_block_is_active);
         $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
         CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
         $fieldTypes = array('Contact');
         $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']);
         $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
     }
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     $amount_block_is_active = $this->get('amount_block_is_active');
     $this->assign('amount_block_is_active', $amount_block_is_active);
     if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
         $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
         $productID = $params['selectProduct'];
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
         $this->set('productID', $productID);
         $this->set('option', $option);
     }
     $config = CRM_Core_Config::singleton();
     if (in_array('CiviMember', $config->enableComponents)) {
         if (isset($params['selectMembership']) && $params['selectMembership'] != 'no_thanks') {
             CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, $this->_membershipContactID, FALSE, $params['selectMembership'], FALSE);
         } else {
             $this->assign('membershipBlock', FALSE);
         }
     }
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if (!empty($params['hidden_onbehalf_profile'])) {
         $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $profileId = $OnBehalfProfile[0];
         $fieldTypes = array('Contact', 'Organization');
         $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
         $fieldTypes = array_merge($fieldTypes, $contactSubType);
         if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
             $fieldTypes = array_merge($fieldTypes, array('Membership'));
         } else {
             $fieldTypes = array_merge($fieldTypes, array('Contribution'));
         }
         $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign('is_separate_payment', $this->_separateMembershipPayment);
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     } else {
         $this->assign('is_quick_config', 1);
         $this->_params['is_quick_config'] = 1;
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
     if ($this->_paymentProcessor && $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType) && !$this->_params['is_pay_later'] && !($this->_amount == 0)) {
         $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 {
         if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] || $this->_amount <= 0.0 || $this->_params['is_pay_later'] || $this->_separateMembershipPayment && $this->_amount <= 0.0) {
             $contribButton = ts('Continue >>');
             $this->assign('button', ts('Continue'));
         } else {
             $contribButton = ts('Make Contribution');
             $this->assign('button', ts('Make Contribution'));
         }
         $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'name' => ts('Go Back'))));
     }
     $defaults = array();
     $fields = array();
     foreach ($this->_fields as $name => $dontCare) {
         if ($name != 'onbehalf' || $name != 'honor') {
             $fields[$name] = 1;
         }
     }
     $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
     $contact = $this->_params;
     foreach ($fields as $name => $dontCare) {
         if (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
                 if (isset($contact["{$name}_id"])) {
                     $defaults["{$name}_id"] = $contact["{$name}_id"];
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
                 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
             }
         }
     }
     $this->assign('useForMember', $this->get('useForMember'));
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $this->setDefaults($defaults);
     $this->freeze();
 }
Example #15
0
 /**
  * Gather values for contribution mail - this function has been created
  * as part of CRM-9996 refactoring as a step towards simplifying the composeMessage function
  * Values related to the contribution in question are gathered
  *
  * @param array $input
  *   Input into function (probably from payment processor).
  * @param array $values
  * @param array $ids
  *   The set of ids related to the input.
  *
  * @return array
  */
 public function _gatherMessageValues($input, &$values, $ids = array())
 {
     // set display address of contributor
     if ($this->address_id) {
         $addressParams = array('id' => $this->address_id);
         $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
         $addressDetails = array_values($addressDetails);
         $values['address'] = $addressDetails[0]['display'];
     }
     if ($this->_component == 'contribute') {
         if (isset($this->contribution_page_id)) {
             CRM_Contribute_BAO_ContributionPage::setValues($this->contribution_page_id, $values);
             if ($this->contribution_page_id) {
                 // CRM-8254 - override default currency if applicable
                 $config = CRM_Core_Config::singleton();
                 $config->defaultCurrency = CRM_Utils_Array::value('currency', $values, $config->defaultCurrency);
             }
         } else {
             // Handle re-print receipt for offline contributions (call from PDF.php - no contribution_page_id)
             $values['is_email_receipt'] = 1;
             $values['title'] = 'Contribution';
         }
         // set lineItem for contribution
         if ($this->id) {
             $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->id, 'contribution', 1);
             if (!empty($lineItem)) {
                 $itemId = key($lineItem);
                 foreach ($lineItem as &$eachItem) {
                     if (is_array($this->_relatedObjects['membership']) && array_key_exists($eachItem['membership_type_id'], $this->_relatedObjects['membership'])) {
                         $eachItem['join_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->join_date);
                         $eachItem['start_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->start_date);
                         $eachItem['end_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->end_date);
                     }
                 }
                 $values['lineItem'][0] = $lineItem;
                 $values['priceSetID'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItem[$itemId]['price_field_id'], 'price_set_id');
             }
         }
         $relatedContact = CRM_Contribute_BAO_Contribution::getOnbehalfIds($this->id, $this->contact_id);
         // if this is onbehalf of contribution then set related contact
         if (!empty($relatedContact['individual_id'])) {
             $values['related_contact'] = $ids['related_contact'] = $relatedContact['individual_id'];
         }
     } else {
         // event
         $eventParams = array('id' => $this->_relatedObjects['event']->id);
         $values['event'] = array();
         CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
         // add custom fields for event
         $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this->_relatedObjects['event'], $this->_relatedObjects['event']->id);
         $eventCustomGroup = array();
         foreach ($eventGroupTree as $key => $group) {
             if ($key === 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $customField) {
                 $groupLabel = $group['title'];
                 if (!empty($customField['customValue'])) {
                     foreach ($customField['customValue'] as $customFieldValues) {
                         $eventCustomGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues);
                     }
                 }
             }
         }
         $values['event']['customGroup'] = $eventCustomGroup;
         //get participant details
         $participantParams = array('id' => $this->_relatedObjects['participant']->id);
         $values['participant'] = array();
         CRM_Event_BAO_Participant::getValues($participantParams, $values['participant'], $participantIds);
         // add custom fields for event
         $participantGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this->_relatedObjects['participant'], $this->_relatedObjects['participant']->id);
         $participantCustomGroup = array();
         foreach ($participantGroupTree as $key => $group) {
             if ($key === 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $customField) {
                 $groupLabel = $group['title'];
                 if (!empty($customField['customValue'])) {
                     foreach ($customField['customValue'] as $customFieldValues) {
                         $participantCustomGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues);
                     }
                 }
             }
         }
         $values['participant']['customGroup'] = $participantCustomGroup;
         //get location details
         $locationParams = array('entity_id' => $this->_relatedObjects['event']->id, 'entity_table' => 'civicrm_event');
         $values['location'] = CRM_Core_BAO_Location::getValues($locationParams);
         $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'module' => 'CiviEvent');
         list($custom_pre_id, $custom_post_ids) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $values['custom_pre_id'] = $custom_pre_id;
         $values['custom_post_id'] = $custom_post_ids;
         // set lineItem for event contribution
         if ($this->id) {
             $participantIds = CRM_Event_BAO_Participant::getParticipantIds($this->id);
             if (!empty($participantIds)) {
                 foreach ($participantIds as $pIDs) {
                     $lineItem = CRM_Price_BAO_LineItem::getLineItems($pIDs);
                     if (!CRM_Utils_System::isNull($lineItem)) {
                         $values['lineItem'][] = $lineItem;
                     }
                 }
             }
         }
     }
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $this->id);
     $customGroup = array();
     foreach ($groupTree as $key => $group) {
         if ($key === 'info') {
             continue;
         }
         foreach ($group['fields'] as $k => $customField) {
             $groupLabel = $group['title'];
             if (!empty($customField['customValue'])) {
                 foreach ($customField['customValue'] as $customFieldValues) {
                     $customGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues);
                 }
             }
         }
     }
     $values['customGroup'] = $customGroup;
     return $values;
 }
Example #16
0
 /**
  * Set default values for the form.
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if ($this->_addProfileBottom || $this->_addProfileBottomAdd) {
         return;
     }
     $eventId = $this->_id;
     $defaults = parent::setDefaultValues();
     $this->setShowHide($defaults);
     if (isset($eventId)) {
         $params = array('id' => $eventId);
         CRM_Event_BAO_Event::retrieve($params, $defaults);
         $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent', 'entity_id' => $eventId);
         list($defaults['custom_pre_id'], $defaults['custom_post']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         // Get the id for the event registration profile
         $eventRegistrationIdParams = $eventRegistrationIdDefaults = array('name' => 'event_registration');
         CRM_Core_BAO_UFGroup::retrieve($eventRegistrationIdParams, $eventRegistrationIdDefaults);
         // Set event registration as the default profile if none selected
         if (!$defaults['custom_pre_id'] && count($defaults['custom_post']) == 0) {
             $defaults['custom_pre_id'] = CRM_Utils_Array::value('id', $eventRegistrationIdDefaults);
         }
         if (isset($defaults['custom_post']) && is_numeric($defaults['custom_post'])) {
             $defaults['custom_post_id'] = $defaults['custom_post'];
         } elseif (!empty($defaults['custom_post'])) {
             $defaults['custom_post_id'] = $defaults['custom_post'][0];
             unset($defaults['custom_post'][0]);
             $this->_profilePostMultiple = $defaults['custom_post'];
             foreach ($defaults['custom_post'] as $key => $value) {
                 self::buildMultipleProfileBottom($this, $key);
                 $defaults["custom_post_id_multiple[{$key}]"] = $value;
             }
         }
         $this->assign('profilePostMultiple', CRM_Utils_Array::value('custom_post', $defaults));
         if (!empty($defaults['is_multiple_registrations'])) {
             // CRM-4377: set additional participants’ profiles – set to ‘none’ if explicitly unset (non-active)
             $ufJoinAddParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent_Additional', 'entity_id' => $eventId);
             list($defaults['additional_custom_pre_id'], $defaults['additional_custom_post']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinAddParams);
             if (isset($defaults['additional_custom_post']) && is_numeric($defaults['additional_custom_post'])) {
                 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'];
             } elseif (!empty($defaults['additional_custom_post'])) {
                 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'][0];
                 unset($defaults['additional_custom_post'][0]);
                 $this->_profilePostMultipleAdd = $defaults['additional_custom_post'];
                 foreach ($defaults['additional_custom_post'] as $key => $value) {
                     self::buildMultipleProfileBottom($this, $key, 'additional_', ts('Profile for Additional Participants'));
                     $defaults["additional_custom_post_id_multiple[{$key}]"] = $value;
                 }
             }
             $this->assign('profilePostMultipleAdd', CRM_Utils_Array::value('additional_custom_post', $defaults));
         }
     } else {
         $defaults['is_email_confirm'] = 0;
     }
     // provide defaults for required fields if empty (and as a 'hint' for approval message field)
     $defaults['registration_link_text'] = CRM_Utils_Array::value('registration_link_text', $defaults, ts('Register Now'));
     $defaults['confirm_title'] = CRM_Utils_Array::value('confirm_title', $defaults, ts('Confirm Your Registration Information'));
     $defaults['thankyou_title'] = CRM_Utils_Array::value('thankyou_title', $defaults, ts('Thank You for Registering'));
     $defaults['approval_req_text'] = CRM_Utils_Array::value('approval_req_text', $defaults, ts('Participation in this event requires approval. Submit your registration request here. Once approved, you will receive an email with a link to a web page where you can complete the registration process.'));
     if (!empty($defaults['registration_start_date'])) {
         list($defaults['registration_start_date'], $defaults['registration_start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['registration_start_date'], 'activityDateTime');
     }
     if (!empty($defaults['registration_end_date'])) {
         list($defaults['registration_end_date'], $defaults['registration_end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['registration_end_date'], 'activityDateTime');
     }
     return $defaults;
 }
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $productID = $this->get('productID');
     $option = $this->get('option');
     $membershipTypeID = $this->get('membershipTypeID');
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     if ($productID) {
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
     }
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     } else {
         if (is_array($membershipTypeID)) {
             $membershipTypeID = current($membershipTypeID);
         }
         $this->assign('is_quick_config', 1);
         $this->_params['is_quick_config'] = 1;
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $this->assign('useForMember', $this->get('useForMember'));
     $params = $this->_params;
     $honor_block_is_active = $this->get('honor_block_is_active');
     if ($honor_block_is_active && (!empty($params["honor_first_name"]) && !empty($params["honor_last_name"]) || !empty($params["honor_email"]))) {
         $this->assign('honor_block_is_active', $honor_block_is_active);
         $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values));
         $prefix = CRM_Core_PseudoConstant::individualPrefix();
         $honor = CRM_Core_PseudoConstant::honor();
         $this->assign('honor_type', $honor[$params["honor_type_id"]]);
         $this->assign('honor_prefix', $params["honor_prefix_id"] ? $prefix[$params["honor_prefix_id"]] : ' ');
         $this->assign('honor_first_name', $params["honor_first_name"]);
         $this->assign('honor_last_name', $params["honor_last_name"]);
         $this->assign('honor_email', $params["honor_email"]);
     }
     $qParams = "reset=1&amp;id={$this->_id}";
     //pcp elements
     if ($this->_pcpId) {
         $qParams .= "&amp;pcpId={$this->_pcpId}";
         $this->assign('pcpBlock', TRUE);
         foreach (array('pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) {
             if (CRM_Utils_Array::value($val, $this->_params)) {
                 $this->assign($val, $this->_params[$val]);
             }
         }
     }
     $this->assign('qParams', $qParams);
     if ($membershipTypeID) {
         $transactionID = $this->get('membership_trx_id');
         $membershipAmount = $this->get('membership_amount');
         $renewalMode = $this->get('renewal_mode');
         $this->assign('membership_trx_id', $transactionID);
         $this->assign('membership_amount', $membershipAmount);
         $this->assign('renewal_mode', $renewalMode);
         CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, FALSE, $membershipTypeID, TRUE, NULL, $this->_membershipContactID);
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign("is_separate_payment", $this->_separateMembershipPayment);
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if (CRM_Utils_Array::value('hidden_onbehalf_profile', $params)) {
         $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $profileId = $OnBehalfProfile[0];
         $fieldTypes = array('Contact', 'Organization');
         $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
         $fieldTypes = array_merge($fieldTypes, $contactSubType);
         if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
             $fieldTypes = array_merge($fieldTypes, array('Membership'));
         } else {
             $fieldTypes = array_merge($fieldTypes, array('Contribution'));
         }
         $this->buildCustom($profileId, 'onbehalfProfile', TRUE, TRUE, $fieldTypes);
     }
     $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $this->_params));
     $this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)));
     $defaults = array();
     $options = array();
     $fields = array();
     $removeCustomFieldTypes = array('Contribution');
     foreach ($this->_fields as $name => $dontCare) {
         if ($name == 'onbehalf') {
             foreach ($dontCare as $key => $value) {
                 $fields['onbehalf'][$key] = 1;
             }
         } else {
             $fields[$name] = 1;
         }
     }
     $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
     $contact = $this->_params = $this->controller->exportValues('Main');
     foreach ($fields as $name => $dontCare) {
         if ($name == 'onbehalf') {
             foreach ($dontCare as $key => $value) {
                 //$defaults[$key] = $contact['onbehalf'][$key];
                 if (isset($contact['onbehalf'][$key])) {
                     $defaults[$key] = $contact['onbehalf'][$key];
                 }
                 if (isset($contact['onbehalf']["{$key}_id"])) {
                     $defaults["{$key}_id"] = $contact['onbehalf']["{$key}_id"];
                 }
             }
         } elseif (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && CRM_Utils_Array::value($name . '_custom', $contact)) {
                 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
             }
         }
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $this->_submitValues = array_merge($this->_submitValues, $defaults);
     $this->setDefaults($defaults);
     $values['entity_id'] = $this->_id;
     $values['entity_table'] = 'civicrm_contribution_page';
     CRM_Friend_BAO_Friend::retrieve($values, $data);
     $tellAFriend = FALSE;
     if ($this->_pcpId) {
         if ($this->_pcpBlock['is_tellfriend_enabled']) {
             $this->assign('friendText', ts('Tell a Friend'));
             $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
             $tellAFriend = TRUE;
         }
     } elseif (CRM_Utils_Array::value('is_active', $data)) {
         $friendText = $data['title'];
         $this->assign('friendText', $friendText);
         $subUrl = "eid={$this->_id}&pcomponent=contribute";
         $tellAFriend = TRUE;
     }
     if ($tellAFriend) {
         if ($this->_action & CRM_Core_Action::PREVIEW) {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&action=preview&{$subUrl}");
         } else {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&{$subUrl}");
         }
         $this->assign('friendURL', $url);
     }
     $this->freeze();
     // can we blow away the session now to prevent hackery
     // CRM-9491
     $this->controller->reset();
 }
Example #18
0
 /** 
  * Function to set variables up before form is built 
  *                                                           
  * @return void 
  * @access public 
  */
 function preProcess()
 {
     $this->_eventId = CRM_Utils_Request::retrieve('id', 'Positive', $this, true);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false);
     //CRM-4320
     $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this);
     // current mode
     $this->_mode = $this->_action == 1024 ? 'test' : 'live';
     $this->_values = $this->get('values');
     $this->_fields = $this->get('fields');
     $this->_bltID = $this->get('bltID');
     $this->_paymentProcessor = $this->get('paymentProcessor');
     $this->_priceSetId = $this->get('priceSetId');
     $this->_priceSet = $this->get('priceSet');
     //check if participant allow to walk registration wizard.
     $this->_allowConfirmation = $this->get('allowConfirmation');
     // check for Approval
     $this->_requireApproval = $this->get('requireApproval');
     // check for waitlisting.
     $this->_allowWaitlist = $this->get('allowWaitlist');
     //get the additional participant ids.
     $this->_additionalParticipantIds = $this->get('additionalParticipantIds');
     $config =& CRM_Core_Config::singleton();
     if (!$this->_values) {
         // create redirect URL to send folks back to event info page is registration not available
         $infoUrl = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_eventId}", false, null, false, true);
         // this is the first time we are hitting this, so check for permissions here
         if (!CRM_Core_Permission::event(CRM_Core_Permission::EDIT, $this->_eventId)) {
             CRM_Core_Error::statusBounce(ts('You do not have permission to register for this event'), $infoUrl);
         }
         // get all the values from the dao object
         $this->_values = array();
         $this->_fields = array();
         // get the participant values, CRM-4320
         $this->_allowConfirmation = false;
         if ($this->_participantId) {
             require_once 'CRM/Event/BAO/Event.php';
             $ids = $participantValues = array();
             $participantParams = array('id' => $this->_participantId);
             require_once 'CRM/Event/BAO/Participant.php';
             CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids);
             $this->_values['participant'] = $participantValues[$this->_participantId];
             //allow pending status class walk registration wizard.
             require_once 'CRM/Core/PseudoConstant.php';
             if (array_key_exists($participantValues[$this->_participantId]['status_id'], CRM_Event_PseudoConstant::participantStatus(null, "class = 'Pending'"))) {
                 $this->_allowConfirmation = true;
                 $this->set('allowConfirmation', true);
             }
         }
         //retrieve event information
         require_once 'CRM/Event/BAO/Event.php';
         $params = array('id' => $this->_eventId);
         CRM_Event_BAO_Event::retrieve($params, $this->_values['event']);
         require_once 'CRM/Event/BAO/Participant.php';
         //check for additional participants.
         if ($this->_allowConfirmation && $this->_values['event']['is_multiple_registrations']) {
             $this->_additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId);
             $this->set('additionalParticipantIds', $this->_additionalParticipantIds);
         }
         $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId);
         $this->_allowWaitlist = false;
         if ($eventFull && !$this->_allowConfirmation) {
             //lets redirecting to info only when to waiting list.
             $this->_allowWaitlist = CRM_Utils_Array::value('has_waitlist', $this->_values['event']);
             if (!$this->_allowWaitlist) {
                 CRM_Utils_System::redirect($infoUrl);
             }
         }
         $this->set('allowWaitlist', $this->_allowWaitlist);
         //check for require requires approval.
         $this->_requireApproval = false;
         if (CRM_Utils_Array::value('requires_approval', $this->_values['event']) && !$this->_allowConfirmation) {
             $this->_requireApproval = true;
         }
         $this->set('requireApproval', $this->_requireApproval);
         // also get the accounting code
         if (CRM_Utils_Array::value('contribution_type_id', $this->_values['event'])) {
             $this->_values['event']['accountingCode'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $this->_values['event']['contribution_type_id'], 'accounting_code');
         }
         if (isset($this->_values['event']['default_role_id'])) {
             require_once 'CRM/Core/OptionGroup.php';
             $participant_role = CRM_Core_OptionGroup::values('participant_role');
             $this->_values['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"];
         }
         // is the event active (enabled)?
         if (!$this->_values['event']['is_active']) {
             // form is inactive, die a fatal death
             CRM_Core_Error::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
         }
         // is online registration is enabled?
         if (!$this->_values['event']['is_online_registration']) {
             CRM_Core_Error::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $infoUrl);
         }
         // is this an event template ?
         if (CRM_Utils_Array::value('is_template', $this->_values['event'])) {
             CRM_Core_Error::statusBounce(ts('Event templates are not meant to be registered.'), $infoUrl);
         }
         $now = date('YmdHis');
         $startDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_start_date', $this->_values['event']));
         if ($startDate && $startDate >= $now) {
             CRM_Core_Error::statusBounce(ts('Registration for this event begins on %1', array(1 => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('registration_start_date', $this->_values['event'])))), $infoUrl);
         }
         $endDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_end_date', $this->_values['event']));
         if ($endDate && $endDate < $now) {
             CRM_Core_Error::statusBounce(ts('Registration for this event ended on %1', array(1 => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('registration_end_date', $this->_values['event'])))), $infoUrl);
         }
         // check for is_monetary status
         $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values['event']);
         //retrieve custom information
         $eventID = $this->_eventId;
         $isPayLater = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'is_pay_later');
         //check for variour combination for paylater, payment
         //process with paid event.
         if ($isMonetary && (!$isPayLater || CRM_Utils_Array::value('payment_processor_id', $this->_values['event']))) {
             $ppID = CRM_Utils_Array::value('payment_processor_id', $this->_values['event']);
             if (!$ppID) {
                 CRM_Core_Error::statusBounce(ts('A payment processor must be selected for this event registration page, or the event must be configured to give users the option to pay later (contact the site administrator for assistance).'), $infoUrl);
             }
             require_once 'CRM/Core/BAO/PaymentProcessor.php';
             $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
             // make sure we have a valid payment class, else abort
             if ($this->_values['event']['is_monetary']) {
                 if (!$this->_paymentProcessor) {
                     CRM_Core_Error::fatal(ts('The site administrator must set a Payment Processor for this event in order to use online registration.'));
                 }
                 // ensure that processor has a valid config
                 $payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this);
                 $error = $payment->checkConfig();
                 if (!empty($error)) {
                     CRM_Core_Error::fatal($error);
                 }
             }
             $this->_paymentProcessor['processorName'] = $payment->_processorName;
             $this->set('paymentProcessor', $this->_paymentProcessor);
         }
         // get price info
         $price = self::initPriceSet($this, $eventID);
         if ($price == false) {
             if (!isset($this->_values['fee'])) {
                 $this->_values['fee'] = array();
             }
             require_once 'CRM/Core/OptionGroup.php';
             CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$eventID}", $this->_values['fee'], true);
             //fix for non-upgraded price sets.CRM-4256.
             if ($isMonetary && empty($this->_values['fee'])) {
                 CRM_Core_Error::fatal(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System::url('civicrm/event/manage', 'reset=1&action=update&subPage=Fee&id=' . $this->_eventId))));
             }
         }
         // get the profile ids
         require_once 'CRM/Core/BAO/UFJoin.php';
         $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent', 'entity_id' => $this->_eventId);
         list($this->_values['custom_pre_id'], $this->_values['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         // set profiles for additional participants
         if ($this->_values['event']['is_multiple_registrations']) {
             require_once 'CRM/Core/BAO/UFJoin.php';
             $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent_Additional', 'entity_id' => $this->_eventId);
             list($this->_values['additional_custom_pre_id'], $this->_values['additional_custom_post_id'], $preActive, $postActive) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
             // CRM-4377: we need to maintain backward compatibility, hence if there is profile for main contact
             // set same profile for additional contacts.
             if ($this->_values['custom_pre_id'] && !$this->_values['additional_custom_pre_id']) {
                 $this->_values['additional_custom_pre_id'] = $this->_values['custom_pre_id'];
             }
             if ($this->_values['custom_post_id'] && !$this->_values['additional_custom_post_id']) {
                 $this->_values['additional_custom_post_id'] = $this->_values['custom_post_id'];
             }
             // now check for no profile condition, in that case is_active = 0
             if (isset($preActive) && !$preActive) {
                 unset($this->_values['additional_custom_pre_id']);
             }
             if (isset($postActive) && !$postActive) {
                 unset($this->_values['additional_custom_post_id']);
             }
         }
         $params = array('id' => $this->_eventId);
         // get the billing location type
         $locationTypes =& CRM_Core_PseudoConstant::locationType();
         $this->_bltID = array_search('Billing', $locationTypes);
         if (!$this->_bltID) {
             CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
         }
         $this->set('bltID', $this->_bltID);
         if ($this->_values['event']['is_monetary'] && $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) {
             require_once 'CRM/Core/Payment/Form.php';
             CRM_Core_Payment_Form::setCreditCardFields($this);
         }
         $params = array('entity_id' => $this->_eventId, 'entity_table' => 'civicrm_event');
         require_once 'CRM/Core/BAO/Location.php';
         $this->_values['location'] = CRM_Core_BAO_Location::getValues($params, true);
         $this->set('values', $this->_values);
         $this->set('fields', $this->_fields);
     }
     $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor);
     // check if this is a paypal auto return and redirect accordingly
     if (CRM_Core_Payment::paypalRedirect($this->_paymentProcessor)) {
         $url = CRM_Utils_System::url('civicrm/event/register', "_qf_ThankYou_display=1&qfKey={$this->controller->_key}");
         CRM_Utils_System::redirect($url);
     }
     $this->_contributeMode = $this->get('contributeMode');
     $this->assign('contributeMode', $this->_contributeMode);
     // setting CMS page title
     CRM_Utils_System::setTitle($this->_values['event']['title']);
     $this->assign('title', $this->_values['event']['title']);
     $this->assign('paidEvent', $this->_values['event']['is_monetary']);
     // we do not want to display recently viewed items on Registration pages
     $this->assign('displayRecent', false);
     // Registration page values are cleared from session, so can't use normal Printer Friendly view.
     // Use Browser Print instead.
     $this->assign('browserPrint', true);
     // assign all event properties so wizard templates can display event info.
     $this->assign('event', $this->_values['event']);
     $this->assign('location', $this->_values['location']);
     $this->assign('bltID', $this->_bltID);
     $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']);
     $this->assign('isShowLocation', $isShowLocation);
 }
Example #19
0
 /**
  * Retrieve survey associated profile id.
  */
 public static function getSurveyProfileId($surveyId)
 {
     if (!$surveyId) {
         return NULL;
     }
     static $ufIds = array();
     if (!array_key_exists($surveyId, $ufIds)) {
         //get the profile id.
         $ufJoinParams = array('entity_id' => $surveyId, 'entity_table' => 'civicrm_survey', 'module' => 'CiviCampaign');
         list($first, $second) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         if ($first) {
             $ufIds[$surveyId] = array($first);
         }
         if ($second) {
             $ufIds[$surveyId][] = array_shift($second);
         }
     }
     return CRM_Utils_Array::value($surveyId, $ufIds);
 }
Example #20
0
 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     parent::preProcess();
     self::preProcessPaymentOptions($this);
     // Make the contributionPageID available to the template
     $this->assign('contributionPageID', $this->_id);
     $this->assign('isShare', CRM_Utils_Array::value('is_share', $this->_values));
     $this->assign('isConfirmEnabled', CRM_Utils_Array::value('is_confirm_enabled', $this->_values));
     $this->assign('reset', CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject));
     $this->assign('mainDisplay', CRM_Utils_Request::retrieve('_qf_Main_display', 'Boolean', CRM_Core_DAO::$_nullObject));
     // Possible values for 'is_for_organization':
     // * 0 - org profile disabled
     // * 1 - org profile optional
     // * 2 - org profile required
     $this->_onbehalf = FALSE;
     if (!empty($this->_values['is_for_organization'])) {
         if ($this->_values['is_for_organization'] == 2) {
             $this->_onBehalfRequired = TRUE;
         }
         // Add organization profile if 1 of the following are true:
         // If the org profile is required
         if ($this->_onBehalfRequired || empty($_POST) || !empty($_POST['is_for_organization'])) {
             $this->_onbehalf = TRUE;
             CRM_Contribute_Form_Contribution_OnBehalfOf::preProcess($this);
         }
     }
     $this->assign('onBehalfRequired', $this->_onBehalfRequired);
     if ($this->_honor_block_is_active) {
         CRM_Contact_Form_ProfileContact::preprocess($this);
     }
     if ($this->_snippet) {
         $this->assign('isOnBehalfCallback', CRM_Utils_Array::value('onbehalf', $_GET, FALSE));
         return;
     }
     if (!empty($this->_pcpInfo['id']) && !empty($this->_pcpInfo['intro_text'])) {
         $this->assign('intro_text', $this->_pcpInfo['intro_text']);
     } elseif (!empty($this->_values['intro_text'])) {
         $this->assign('intro_text', $this->_values['intro_text']);
     }
     $qParams = "reset=1&amp;id={$this->_id}";
     if ($pcpId = CRM_Utils_Array::value('pcp_id', $this->_pcpInfo)) {
         $qParams .= "&amp;pcpId={$pcpId}";
     }
     $this->assign('qParams', $qParams);
     if (!empty($this->_values['footer_text'])) {
         $this->assign('footer_text', $this->_values['footer_text']);
     }
     //CRM-5001
     //CRM-15787
     $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
     if (!empty($this->_values['is_for_organization']) && empty($member['is_active'])) {
         $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
         $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $onBehalfProfileIDs = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         // getUFGroupIDs returns an array with the first item being the ID we need
         $onBehalfProfileID = $onBehalfProfileIDs[0];
         if ($onBehalfProfileID) {
             $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($onBehalfProfileID);
             foreach (array('Individual', 'Organization', 'Household') as $contactType) {
                 if (in_array($contactType, $onBehalfProfile) && (in_array('Membership', $onBehalfProfile) || in_array('Contribution', $onBehalfProfile))) {
                     CRM_Core_Error::fatal($msg);
                 }
             }
         }
         if ($postID = CRM_Utils_Array::value('custom_post_id', $this->_values)) {
             $postProfile = CRM_Core_BAO_UFGroup::profileGroups($postID);
             foreach (array('Individual', 'Organization', 'Household') as $contactType) {
                 if (in_array($contactType, $postProfile) && (in_array('Membership', $postProfile) || in_array('Contribution', $postProfile))) {
                     CRM_Core_Error::fatal($msg);
                 }
             }
         }
     }
 }
Example #21
0
 /**
  * Global validation rules for the form.
  *
  * @param array $values
  *   Posted values of the form.
  *
  * @param $files
  * @param $self
  *
  * @return array
  *   list of errors to be posted back to the form
  */
 public static function formRule($values, $files, $self)
 {
     $errors = array();
     $contributionPageId = $self->_id;
     //CRM-4286
     if (strstr($values['title'], '/')) {
         $errors['title'] = ts("Please do not use '/' in Title");
     }
     // ensure on-behalf-of profile meets minimum requirements
     if (!empty($values['is_organization'])) {
         if (empty($values['onbehalf_profile_id'])) {
             $errors['onbehalf_profile_id'] = ts('Please select a profile to collect organization information on this contribution page.');
         } else {
             $requiredProfileFields = array('organization_name', 'email');
             if (!CRM_Core_BAO_UFGroup::checkValidProfile($values['onbehalf_profile_id'], $requiredProfileFields)) {
                 $errors['onbehalf_profile_id'] = ts('Profile does not contain the minimum required fields for an On Behalf Of Organization');
             }
         }
     }
     //CRM-11494
     $start = CRM_Utils_Date::processDate($values['start_date']);
     $end = CRM_Utils_Date::processDate($values['end_date']);
     if ($end < $start && $end != 0) {
         $errors['end_date'] = ts('End date should be after Start date.');
     }
     if (!empty($self->_values['payment_processor']) && ($financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($values['financial_type_id']))) {
         $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
     }
     //dont allow on behalf of save when
     //pre or post profile consists of membership fields
     if ($contributionPageId && !empty($values['is_organization'])) {
         $ufJoinParams = array('module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $contributionPageId);
         list($contributionProfiles['custom_pre_id'], $contributionProfiles['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $conProfileType = NULL;
         if ($contributionProfiles['custom_pre_id']) {
             $preProfileType = CRM_Core_BAO_UFField::getProfileType($contributionProfiles['custom_pre_id']);
             if ($preProfileType == 'Membership') {
                 $conProfileType = "'Includes Profile (top of page)'";
             }
         }
         if ($contributionProfiles['custom_post_id']) {
             $postProfileType = CRM_Core_BAO_UFField::getProfileType($contributionProfiles['custom_post_id']);
             if ($postProfileType == 'Membership') {
                 $conProfileType = empty($conProfileType) ? "'Includes Profile (bottom of page)'" : "{$conProfileType} and 'Includes Profile (bottom of page)'";
             }
         }
         if (!empty($conProfileType)) {
             $errors['is_organization'] = ts("You should move the membership related fields configured in %1 to the 'On Behalf' profile for this Contribution Page", array(1 => $conProfileType));
         }
     }
     return $errors;
 }
 /**
  * Send the emails.
  *
  * @param int $contactID
  *   Contact id.
  * @param array $values
  *   Associated array of fields.
  * @param bool $isTest
  *   If in test mode.
  * @param bool $returnMessageText
  *   Return the message text instead of sending the mail.
  *
  * @param null $fieldTypes
  *
  * @return void
  */
 public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL)
 {
     $gIds = $params = array();
     $email = NULL;
     if (isset($values['custom_pre_id'])) {
         $preProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_pre_id']);
         if ($preProfileType == 'Membership' && !empty($values['membership_id'])) {
             $params['custom_pre_id'] = array(array('member_id', '=', $values['membership_id'], 0, 0));
         } elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) {
             $params['custom_pre_id'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0));
         }
         $gIds['custom_pre_id'] = $values['custom_pre_id'];
     }
     if (isset($values['custom_post_id'])) {
         $postProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_post_id']);
         if ($postProfileType == 'Membership' && !empty($values['membership_id'])) {
             $params['custom_post_id'] = array(array('member_id', '=', $values['membership_id'], 0, 0));
         } elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) {
             $params['custom_post_id'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0));
         }
         $gIds['custom_post_id'] = $values['custom_post_id'];
     }
     if (!empty($values['is_for_organization'])) {
         if (!empty($values['membership_id'])) {
             $params['onbehalf_profile'] = array(array('member_id', '=', $values['membership_id'], 0, 0));
         } elseif (!empty($values['contribution_id'])) {
             $params['onbehalf_profile'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0));
         }
     }
     //check whether it is a test drive
     if ($isTest && !empty($params['custom_pre_id'])) {
         $params['custom_pre_id'][] = array('contribution_test', '=', 1, 0, 0);
     }
     if ($isTest && !empty($params['custom_post_id'])) {
         $params['custom_post_id'][] = array('contribution_test', '=', 1, 0, 0);
     }
     if (!$returnMessageText && !empty($gIds)) {
         //send notification email if field values are set (CRM-1941)
         foreach ($gIds as $key => $gId) {
             if ($gId) {
                 $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
                 if ($email) {
                     $val = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array::value($key, $params), TRUE);
                     CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val);
                 }
             }
         }
     }
     if (!empty($values['is_email_receipt']) || !empty($values['onbehalf_dupe_alert']) || $returnMessageText) {
         $template = CRM_Core_Smarty::singleton();
         // get the billing location type
         if (!array_key_exists('related_contact', $values)) {
             $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
             $billingLocationTypeId = array_search('Billing', $locationTypes);
         } else {
             // presence of related contact implies onbehalf of org case,
             // where location type is set to default.
             $locType = CRM_Core_BAO_LocationType::getDefault();
             $billingLocationTypeId = $locType->id;
         }
         if (!array_key_exists('related_contact', $values)) {
             list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, $billingLocationTypeId);
         }
         // get primary location email if no email exist( for billing location).
         if (!$email) {
             list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         }
         if (empty($displayName)) {
             list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         }
         //for display profile need to get individual contact id,
         //hence get it from related_contact if on behalf of org true CRM-3767
         //CRM-5001 Contribution/Membership:: On Behalf of Organization,
         //If profile GROUP contain the Individual type then consider the
         //profile is of Individual ( including the custom data of membership/contribution )
         //IF Individual type not present in profile then it is consider as Organization data.
         $userID = $contactID;
         if ($preID = CRM_Utils_Array::value('custom_pre_id', $values)) {
             if (!empty($values['related_contact'])) {
                 $preProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($preID);
                 //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test
                 if (in_array('Individual', $preProfileTypes) || in_array('Contact', $postProfileTypes)) {
                     //Take Individual contact ID
                     $userID = CRM_Utils_Array::value('related_contact', $values);
                 }
             }
             self::buildCustomDisplay($preID, 'customPre', $userID, $template, $params['custom_pre_id']);
         }
         $userID = $contactID;
         if ($postID = CRM_Utils_Array::value('custom_post_id', $values)) {
             if (!empty($values['related_contact'])) {
                 $postProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($postID);
                 if (in_array('Individual', $postProfileTypes) || in_array('Contact', $postProfileTypes)) {
                     //Take Individual contact ID
                     $userID = CRM_Utils_Array::value('related_contact', $values);
                 }
             }
             self::buildCustomDisplay($postID, 'customPost', $userID, $template, $params['custom_post_id']);
         }
         if (isset($values['honor'])) {
             $honorValues = $values['honor'];
             CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($template, $honorValues['honor_profile_values'], $honorValues['honor_profile_id'], $honorValues['honor_id']);
         }
         $title = isset($values['title']) ? $values['title'] : CRM_Contribute_PseudoConstant::contributionPage($values['contribution_page_id']);
         // set email in the template here
         $tplParams = array('email' => $email, 'receiptFromEmail' => CRM_Utils_Array::value('receipt_from_email', $values), 'contactID' => $contactID, 'displayName' => $displayName, 'contributionID' => CRM_Utils_Array::value('contribution_id', $values), 'contributionOtherID' => CRM_Utils_Array::value('contribution_other_id', $values), 'lineItem' => CRM_Utils_Array::value('lineItem', $values), 'priceSetID' => CRM_Utils_Array::value('priceSetID', $values), 'title' => $title, 'isShare' => CRM_Utils_Array::value('is_share', $values), 'thankyou_title' => CRM_Utils_Array::value('thankyou_title', $values));
         if ($contributionTypeId = CRM_Utils_Array::value('financial_type_id', $values)) {
             $tplParams['contributionTypeId'] = $contributionTypeId;
             $tplParams['contributionTypeName'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionTypeId);
         }
         if ($contributionPageId = CRM_Utils_Array::value('id', $values)) {
             $tplParams['contributionPageId'] = $contributionPageId;
         }
         // address required during receipt processing (pdf and email receipt)
         if ($displayAddress = CRM_Utils_Array::value('address', $values)) {
             $tplParams['address'] = $displayAddress;
         }
         // CRM-6976
         $originalCCReceipt = CRM_Utils_Array::value('cc_receipt', $values);
         // cc to related contacts of contributor OR the one who
         // signs up. Is used for cases like - on behalf of
         // contribution / signup ..etc
         if (array_key_exists('related_contact', $values)) {
             list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($values['related_contact']);
             $ccMailId = "{$ccDisplayName} <{$ccEmail}>";
             //@todo - this is the only place in this function where  $values is altered - but I can't find any evidence it is used
             $values['cc_receipt'] = !empty($values['cc_receipt']) ? $values['cc_receipt'] . ',' . $ccMailId : $ccMailId;
             // reset primary-email in the template
             $tplParams['email'] = $ccEmail;
             $tplParams['onBehalfName'] = $displayName;
             $tplParams['onBehalfEmail'] = $email;
             $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $values['id']);
             $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
             $profileId = $OnBehalfProfile[0];
             $userID = $contactID;
             self::buildCustomDisplay($profileId, 'onBehalfProfile', $userID, $template, $params['onbehalf_profile'], $fieldTypes);
         }
         // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
         $sendTemplateParams = array('groupName' => !empty($values['isMembership']) ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', 'valueName' => !empty($values['isMembership']) ? 'membership_online_receipt' : 'contribution_online_receipt', 'contactId' => $contactID, 'tplParams' => $tplParams, 'isTest' => $isTest, 'PDFFilename' => 'receipt.pdf');
         if ($returnMessageText) {
             list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
             return array('subject' => $subject, 'body' => $message, 'to' => $displayName, 'html' => $html);
         }
         if ($values['is_email_receipt']) {
             $sendTemplateParams['from'] = CRM_Utils_Array::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>';
             $sendTemplateParams['toName'] = $displayName;
             $sendTemplateParams['toEmail'] = $email;
             $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values);
             $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values);
             //send email with pdf invoice
             $template = CRM_Core_Smarty::singleton();
             $taxAmt = $template->get_template_vars('dataArray');
             $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
             $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
             if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
                 $sendTemplateParams['isEmailPdf'] = TRUE;
                 $sendTemplateParams['contributionId'] = $values['contribution_id'];
             }
             list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
         }
         // send duplicate alert, if dupe match found during on-behalf-of processing.
         if (!empty($values['onbehalf_dupe_alert'])) {
             $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution';
             $sendTemplateParams['valueName'] = 'contribution_dupalert';
             $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>";
             $sendTemplateParams['toName'] = CRM_Utils_Array::value('receipt_from_name', $values);
             $sendTemplateParams['toEmail'] = CRM_Utils_Array::value('receipt_from_email', $values);
             $sendTemplateParams['tplParams']['onBehalfID'] = $contactID;
             $sendTemplateParams['tplParams']['receiptMessage'] = $message;
             // fix cc and reset back to original, CRM-6976
             $sendTemplateParams['cc'] = $originalCCReceipt;
             CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
         }
     }
 }
Example #23
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     if ($this->_id) {
         $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
         CRM_Utils_System::setTitle(ts('Include Profiles') . " ({$title})");
     }
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $this->assign('perm', 1);
     }
     $ufJoinParams = array('module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
     list($defaults['custom_pre_id'], $second) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     $defaults['custom_post_id'] = $second ? array_shift($second) : '';
     return $defaults;
 }
 function get_profile_groups($event_id)
 {
     $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent', 'entity_id' => $event_id);
     $group_ids = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
     return $group_ids;
 }
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $productID = $this->get('productID');
     $option = $this->get('option');
     $membershipTypeID = $this->get('membershipTypeID');
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     if ($productID) {
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
     }
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     } else {
         if (is_array($membershipTypeID)) {
             $membershipTypeID = current($membershipTypeID);
         }
         $this->assign('is_quick_config', 1);
         $this->_params['is_quick_config'] = 1;
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $this->assign('useForMember', $this->get('useForMember'));
     $params = $this->_params;
     $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     if ($invoicing) {
         $getTaxDetails = FALSE;
         $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
         foreach ($this->_lineItem as $key => $value) {
             foreach ($value as $v) {
                 if (isset($v['tax_rate'])) {
                     if ($v['tax_rate'] != '') {
                         $getTaxDetails = TRUE;
                     }
                 }
             }
         }
         $this->assign('getTaxDetails', $getTaxDetails);
         $this->assign('taxTerm', $taxTerm);
         $this->assign('totalTaxAmount', $params['tax_amount']);
     }
     if ($this->_honor_block_is_active && !empty($params['soft_credit_type_id'])) {
         $honorName = NULL;
         $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
         $this->assign('honor_block_is_active', $this->_honor_block_is_active);
         $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
         CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
         $fieldTypes = array('Contact');
         $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']);
         $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
     }
     $qParams = "reset=1&amp;id={$this->_id}";
     //pcp elements
     if ($this->_pcpId) {
         $qParams .= "&amp;pcpId={$this->_pcpId}";
         $this->assign('pcpBlock', TRUE);
         foreach (array('pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) {
             if (!empty($this->_params[$val])) {
                 $this->assign($val, $this->_params[$val]);
             }
         }
     }
     $this->assign('qParams', $qParams);
     if ($membershipTypeID) {
         $transactionID = $this->get('membership_trx_id');
         $membershipAmount = $this->get('membership_amount');
         $renewalMode = $this->get('renewal_mode');
         $this->assign('membership_trx_id', $transactionID);
         $this->assign('membership_amount', $membershipAmount);
         $this->assign('renewal_mode', $renewalMode);
         $this->buildMembershipBlock($this->_membershipContactID, FALSE, $membershipTypeID, TRUE, NULL);
         if (!empty($params['auto_renew'])) {
             $this->assign('auto_renew', TRUE);
         }
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign("is_separate_payment", $this->_separateMembershipPayment);
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if (!empty($params['hidden_onbehalf_profile'])) {
         $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $profileId = $OnBehalfProfile[0];
         $fieldTypes = array('Contact', 'Organization');
         $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
         $fieldTypes = array_merge($fieldTypes, $contactSubType);
         if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
             $fieldTypes = array_merge($fieldTypes, array('Membership'));
         } else {
             $fieldTypes = array_merge($fieldTypes, array('Contribution'));
         }
         $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
     }
     $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $this->_params));
     $this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)));
     $defaults = array();
     $fields = array();
     foreach ($this->_fields as $name => $dontCare) {
         if ($name != 'onbehalf' || $name != 'honor') {
             $fields[$name] = 1;
         }
     }
     $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
     $contact = $this->_params = $this->controller->exportValues('Main');
     foreach ($fields as $name => $dontCare) {
         if (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
                 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
             }
         }
     }
     $this->_submitValues = array_merge($this->_submitValues, $defaults);
     $this->setDefaults($defaults);
     $values['entity_id'] = $this->_id;
     $values['entity_table'] = 'civicrm_contribution_page';
     CRM_Friend_BAO_Friend::retrieve($values, $data);
     $tellAFriend = FALSE;
     if ($this->_pcpId) {
         if ($this->_pcpBlock['is_tellfriend_enabled']) {
             $this->assign('friendText', ts('Tell a Friend'));
             $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
             $tellAFriend = TRUE;
         }
     } elseif (!empty($data['is_active'])) {
         $friendText = $data['title'];
         $this->assign('friendText', $friendText);
         $subUrl = "eid={$this->_id}&pcomponent=contribute";
         $tellAFriend = TRUE;
     }
     if ($tellAFriend) {
         if ($this->_action & CRM_Core_Action::PREVIEW) {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&action=preview&{$subUrl}");
         } else {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&{$subUrl}");
         }
         $this->assign('friendURL', $url);
     }
     $this->freeze();
     // can we blow away the session now to prevent hackery
     // CRM-9491
     $this->controller->reset();
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $this->_eventId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
     //CRM-4320
     $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this);
     // current mode
     $this->_mode = $this->_action == 1024 ? 'test' : 'live';
     $this->_values = $this->get('values');
     $this->_fields = $this->get('fields');
     $this->_bltID = $this->get('bltID');
     $this->_paymentProcessor = $this->get('paymentProcessor');
     $this->_priceSetId = $this->get('priceSetId');
     $this->_priceSet = $this->get('priceSet');
     $this->_lineItem = $this->get('lineItem');
     $this->_isEventFull = $this->get('isEventFull');
     $this->_lineItemParticipantsCount = $this->get('lineItemParticipants');
     if (!is_array($this->_lineItem)) {
         $this->_lineItem = array();
     }
     if (!is_array($this->_lineItemParticipantsCount)) {
         $this->_lineItemParticipantsCount = array();
     }
     $this->_availableRegistrations = $this->get('availableRegistrations');
     $this->_participantIDS = $this->get('participantIDs');
     //check if participant allow to walk registration wizard.
     $this->_allowConfirmation = $this->get('allowConfirmation');
     // check for Approval
     $this->_requireApproval = $this->get('requireApproval');
     // check for waitlisting.
     $this->_allowWaitlist = $this->get('allowWaitlist');
     $this->_forcePayement = $this->get('forcePayement');
     //get the additional participant ids.
     $this->_additionalParticipantIds = $this->get('additionalParticipantIds');
     $config = CRM_Core_Config::singleton();
     if (!$this->_values) {
         // create redirect URL to send folks back to event info page is registration not available
         $infoUrl = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_eventId}", FALSE, NULL, FALSE, TRUE);
         // this is the first time we are hitting this, so check for permissions here
         if (!CRM_Core_Permission::event(CRM_Core_Permission::EDIT, $this->_eventId, 'register for events')) {
             CRM_Core_Error::statusBounce(ts('You do not have permission to register for this event'), $infoUrl);
         }
         // get all the values from the dao object
         $this->_values = $this->_fields = array();
         $this->_forcePayement = FALSE;
         //retrieve event information
         $params = array('id' => $this->_eventId);
         CRM_Event_BAO_Event::retrieve($params, $this->_values['event']);
         $this->checkValidEvent($infoUrl);
         // get the participant values, CRM-4320
         $this->_allowConfirmation = FALSE;
         if ($this->_participantId) {
             $this->processFirstParticipant($this->_participantId);
         }
         //check for additional participants.
         if ($this->_allowConfirmation && $this->_values['event']['is_multiple_registrations']) {
             $additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId);
             $cnt = 1;
             foreach ($additionalParticipantIds as $additionalParticipantId) {
                 $this->_additionalParticipantIds[$cnt] = $additionalParticipantId;
                 $cnt++;
             }
             $this->set('additionalParticipantIds', $this->_additionalParticipantIds);
         }
         $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId, FALSE, CRM_Utils_Array::value('has_waitlist', $this->_values['event']));
         $this->_allowWaitlist = $this->_isEventFull = FALSE;
         if ($eventFull && !$this->_allowConfirmation) {
             $this->_isEventFull = TRUE;
             //lets redirecting to info only when to waiting list.
             $this->_allowWaitlist = CRM_Utils_Array::value('has_waitlist', $this->_values['event']);
             if (!$this->_allowWaitlist) {
                 CRM_Utils_System::redirect($infoUrl);
             }
         }
         $this->set('isEventFull', $this->_isEventFull);
         $this->set('allowWaitlist', $this->_allowWaitlist);
         //check for require requires approval.
         $this->_requireApproval = FALSE;
         if (!empty($this->_values['event']['requires_approval']) && !$this->_allowConfirmation) {
             $this->_requireApproval = TRUE;
         }
         $this->set('requireApproval', $this->_requireApproval);
         if (isset($this->_values['event']['default_role_id'])) {
             $participant_role = CRM_Core_OptionGroup::values('participant_role');
             $this->_values['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"];
         }
         // check for is_monetary status
         $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values['event']);
         $isPayLater = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eventId, 'is_pay_later');
         //check for variour combination for paylater, payment
         //process with paid event.
         if ($isMonetary && (!$isPayLater || !empty($this->_values['event']['payment_processor']))) {
             $ppID = CRM_Utils_Array::value('payment_processor', $this->_values['event']);
             if (!$ppID) {
                 CRM_Core_Error::statusBounce(ts('A payment processor must be selected for this event registration page, or the event must be configured to give users the option to pay later (contact the site administrator for assistance).'), $infoUrl);
             }
             $ppIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ppID);
             $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($ppIds, $this->_mode);
             $this->set('paymentProcessors', $this->_paymentProcessors);
             //set default payment processor
             if (!empty($this->_paymentProcessors) && empty($this->_paymentProcessor)) {
                 foreach ($this->_paymentProcessors as $ppId => $values) {
                     if ($values['is_default'] == 1 || count($this->_paymentProcessors) == 1) {
                         $defaultProcessorId = $ppId;
                         break;
                     }
                 }
             }
             if (isset($defaultProcessorId)) {
                 $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($defaultProcessorId, $this->_mode);
             }
             // make sure we have a valid payment class, else abort
             if ($this->_values['event']['is_monetary']) {
                 if (!CRM_Utils_System::isNull($this->_paymentProcessors)) {
                     foreach ($this->_paymentProcessors as $eachPaymentProcessor) {
                         // check selected payment processor is active
                         if (!$eachPaymentProcessor) {
                             CRM_Core_Error::fatal(ts('The site administrator must set a Payment Processor for this event in order to use online registration.'));
                         }
                         // ensure that processor has a valid config
                         $payment = CRM_Core_Payment::singleton($this->_mode, $eachPaymentProcessor, $this);
                         $error = $payment->checkConfig();
                         if (!empty($error)) {
                             CRM_Core_Error::fatal($error);
                         }
                     }
                 }
             }
         }
         //init event fee.
         self::initEventFee($this, $this->_eventId);
         // get the profile ids
         $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent', 'entity_id' => $this->_eventId);
         list($this->_values['custom_pre_id'], $this->_values['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         // set profiles for additional participants
         if ($this->_values['event']['is_multiple_registrations']) {
             // CRM-4377: CiviEvent for the main participant, CiviEvent_Additional for additional participants
             $ufJoinParams['module'] = 'CiviEvent_Additional';
             list($this->_values['additional_custom_pre_id'], $this->_values['additional_custom_post_id'], $preActive, $postActive) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
             // CRM-4377: we need to maintain backward compatibility, hence if there is profile for main contact
             // set same profile for additional contacts.
             if ($this->_values['custom_pre_id'] && !$this->_values['additional_custom_pre_id']) {
                 $this->_values['additional_custom_pre_id'] = $this->_values['custom_pre_id'];
             }
             if ($this->_values['custom_post_id'] && !$this->_values['additional_custom_post_id']) {
                 $this->_values['additional_custom_post_id'] = $this->_values['custom_post_id'];
             }
             // now check for no profile condition, in that case is_active = 0
             if (isset($preActive) && !$preActive) {
                 unset($this->_values['additional_custom_pre_id']);
             }
             if (isset($postActive) && !$postActive) {
                 unset($this->_values['additional_custom_post_id']);
             }
         }
         // get the billing location type
         $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
         // CRM-8108 remove ts from Billing as the location type can not be translated in CiviCRM!
         //$this->_bltID = array_search( ts('Billing'),  $locationTypes );
         $this->_bltID = array_search('Billing', $locationTypes);
         if (!$this->_bltID) {
             CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
         }
         $this->set('bltID', $this->_bltID);
         if ($this->_values['event']['is_monetary'] && $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) {
             CRM_Core_Payment_Form::setCreditCardFields($this);
         }
         $params = array('entity_id' => $this->_eventId, 'entity_table' => 'civicrm_event');
         $this->_values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
         $this->set('values', $this->_values);
         $this->set('fields', $this->_fields);
         $this->_availableRegistrations = CRM_Event_BAO_Participant::eventFull($this->_values['event']['id'], TRUE, CRM_Utils_Array::value('has_waitlist', $this->_values['event']));
         $this->set('availableRegistrations', $this->_availableRegistrations);
     }
     $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor);
     // check if this is a paypal auto return and redirect accordingly
     if (CRM_Core_Payment::paypalRedirect($this->_paymentProcessor)) {
         $url = CRM_Utils_System::url('civicrm/event/register', "_qf_ThankYou_display=1&qfKey={$this->controller->_key}");
         CRM_Utils_System::redirect($url);
     }
     $this->_contributeMode = $this->get('contributeMode');
     $this->assign('contributeMode', $this->_contributeMode);
     // setting CMS page title
     CRM_Utils_System::setTitle($this->_values['event']['title']);
     $this->assign('title', $this->_values['event']['title']);
     $this->assign('paidEvent', $this->_values['event']['is_monetary']);
     // we do not want to display recently viewed items on Registration pages
     $this->assign('displayRecent', FALSE);
     // Registration page values are cleared from session, so can't use normal Printer Friendly view.
     // Use Browser Print instead.
     $this->assign('browserPrint', TRUE);
     $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']);
     $this->assign('isShowLocation', $isShowLocation);
     // Handle PCP
     $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this);
     if ($pcpId) {
         $pcp = CRM_PCP_BAO_PCP::handlePcp($pcpId, 'event', $this->_values['event']);
         $this->_pcpId = $pcp['pcpId'];
         $this->_values['event']['intro_text'] = CRM_Utils_Array::value('intro_text', $pcp['pcpInfo']);
     }
     // assign all event properties so wizard templates can display event info.
     $this->assign('event', $this->_values['event']);
     $this->assign('location', $this->_values['location']);
     $this->assign('bltID', $this->_bltID);
     $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']);
     $this->assign('isShowLocation', $isShowLocation);
     //CRM-6907
     $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values['event'], $config->defaultCurrency);
     //lets allow user to override campaign.
     $campID = CRM_Utils_Request::retrieve('campID', 'Positive', $this);
     if ($campID && CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
         $this->_values['event']['campaign_id'] = $campID;
     }
 }