/** * Process Registration of free event. * * @param array $params * Form values. * @param int $contactID */ public function processRegistration($params, $contactID = NULL) { $session = CRM_Core_Session::singleton(); $this->_participantInfo = array(); // CRM-4320, lets build array of cancelled additional participant ids // those are drop or skip by primary at the time of confirmation. // get all in and then unset those are confirmed. $cancelledIds = $this->_additionalParticipantIds; $participantCount = array(); foreach ($params as $participantNum => $record) { if ($record == 'skip') { $participantCount[$participantNum] = 'skip'; } elseif ($participantNum) { $participantCount[$participantNum] = 'participant'; } } $registerByID = NULL; foreach ($params as $key => $value) { if ($value != 'skip') { $fields = NULL; // setting register by Id and unset contactId. if (empty($value['is_primary'])) { $contactID = NULL; $registerByID = $this->get('registerByID'); if ($registerByID) { $value['registered_by_id'] = $registerByID; } // get an email if one exists for the participant $participantEmail = ''; foreach (array_keys($value) as $valueName) { if (substr($valueName, 0, 6) == 'email-') { $participantEmail = $value[$valueName]; } } if ($participantEmail) { $this->_participantInfo[] = $participantEmail; } else { $this->_participantInfo[] = $value['first_name'] . ' ' . $value['last_name']; } } elseif (!empty($value['contact_id'])) { $contactID = $value['contact_id']; } else { $contactID = $this->getContactID(); } CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields, $this); //for free event or additional participant, dont create billing email address. if (empty($value['is_primary']) || !$this->_values['event']['is_monetary']) { unset($value["email-{$this->_bltID}"]); } $contactID = CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields, $this); // lets store the contactID in the session // we dont store in userID in case the user is doing multiple // transactions etc // for things like tell a friend if (!$this->getContactID() && !empty($value['is_primary'])) { $session->set('transaction.userID', $contactID); } //lets get the status if require approval or waiting. $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'"); if ($this->_allowWaitlist && !$this->_allowConfirmation) { $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses); } elseif ($this->_requireApproval && !$this->_allowConfirmation) { $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses); } $this->set('value', $value); $this->confirmPostProcess($contactID, NULL, NULL); //lets get additional participant id to cancel. if ($this->_allowConfirmation && is_array($cancelledIds)) { $additonalId = CRM_Utils_Array::value('participant_id', $value); if ($additonalId && ($key = array_search($additonalId, $cancelledIds))) { unset($cancelledIds[$key]); } } } } // update status and send mail to cancelled additional participants, CRM-4320 if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) { $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'")); CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId); } //set information about additional participants if exists if (count($this->_participantInfo)) { $this->set('participantInfo', $this->_participantInfo); } //send mail Confirmation/Receipt if ($this->_contributeMode != 'checkout' || $this->_contributeMode != 'notify') { $isTest = FALSE; if ($this->_action & CRM_Core_Action::PREVIEW) { $isTest = TRUE; } //handle if no additional participant. if (!$registerByID) { $registerByID = $this->get('registerByID'); } $primaryContactId = $this->get('primaryContactId'); //build an array of custom profile and assigning it to template. $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE); //lets carry all participant params w/ values. foreach ($additionalIDs as $participantID => $contactId) { $participantNum = NULL; if ($participantID == $registerByID) { $participantNum = 0; } else { if ($participantNum = array_search('participant', $participantCount)) { unset($participantCount[$participantNum]); } } if ($participantNum === NULL) { break; } //carry the participant submitted values. $this->_values['params'][$participantID] = $params[$participantNum]; } //lets send mails to all with meanigful text, CRM-4320. $this->assign('isOnWaitlist', $this->_allowWaitlist); $this->assign('isRequireApproval', $this->_requireApproval); foreach ($additionalIDs as $participantID => $contactId) { if ($participantID == $registerByID) { //set as Primary Participant $this->assign('isPrimary', 1); $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, NULL, $isTest); if (count($customProfile)) { $this->assign('customProfile', $customProfile); $this->set('customProfile', $customProfile); } } else { $this->assign('isPrimary', 0); $this->assign('customProfile', NULL); } //send Confirmation mail to Primary & additional Participants if exists CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest); } } }
/** * Apply variables for message to smarty template - this function is part of analysing what is in the huge * function & breaking it down into manageable chunks. Eventually it will be refactored into something else * Note we send directly from this function in some cases because it is only partly refactored * Don't call this function directly as the signature will change * * @param $values * @param $input * @param CRM_Core_SMARTY $template * @param bool $recur * @param bool $returnMessageText * * @return mixed */ public function _assignMessageVariablesToTemplate(&$values, $input, &$template, $recur = FALSE, $returnMessageText = TRUE) { $template->assign('first_name', $this->_relatedObjects['contact']->first_name); $template->assign('last_name', $this->_relatedObjects['contact']->last_name); $template->assign('displayName', $this->_relatedObjects['contact']->display_name); if (!empty($values['lineItem']) && !empty($this->_relatedObjects['membership'])) { $template->assign('useForMember', TRUE); } //assign honor information to receipt message $softRecord = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($this->id); if (isset($softRecord['soft_credit'])) { //if id of contribution page is present if (!empty($values['id'])) { $values['honor'] = array('honor_profile_values' => array(), 'honor_profile_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFJoin', $values['id'], 'uf_group_id', 'entity_id'), 'honor_id' => $softRecord['soft_credit'][1]['contact_id']); $softCreditTypes = CRM_Core_OptionGroup::values('soft_credit_type'); $template->assign('soft_credit_type', $softRecord['soft_credit'][1]['soft_credit_type_label']); $template->assign('honor_block_is_active', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFJoin', $values['id'], 'is_active', 'entity_id')); } else { //offline contribution $softCreditTypes = $softCredits = array(); foreach ($softRecord['soft_credit'] as $key => $softCredit) { $softCreditTypes[$key] = $softCredit['soft_credit_type_label']; $softCredits[$key] = array('Name' => $softCredit['contact_name'], 'Amount' => CRM_Utils_Money::format($softCredit['amount'], $softCredit['currency'])); } $template->assign('softCreditTypes', $softCreditTypes); $template->assign('softCredits', $softCredits); } } $dao = new CRM_Contribute_DAO_ContributionProduct(); $dao->contribution_id = $this->id; if ($dao->find(TRUE)) { $premiumId = $dao->product_id; $template->assign('option', $dao->product_option); $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $premiumId; $productDAO->find(TRUE); $template->assign('selectPremium', TRUE); $template->assign('product_name', $productDAO->name); $template->assign('price', $productDAO->price); $template->assign('sku', $productDAO->sku); } $template->assign('title', CRM_Utils_Array::value('title', $values)); $amount = CRM_Utils_Array::value('total_amount', $input, CRM_Utils_Array::value('amount', $input), NULL); if (empty($amount) && isset($this->total_amount)) { $amount = $this->total_amount; } $template->assign('amount', $amount); // add the new contribution values if (strtolower($this->_component) == 'contribute') { //PCP Info $softDAO = new CRM_Contribute_DAO_ContributionSoft(); $softDAO->contribution_id = $this->id; if ($softDAO->find(TRUE)) { $template->assign('pcpBlock', TRUE); $template->assign('pcp_display_in_roll', $softDAO->pcp_display_in_roll); $template->assign('pcp_roll_nickname', $softDAO->pcp_roll_nickname); $template->assign('pcp_personal_note', $softDAO->pcp_personal_note); //assign the pcp page title for email subject $pcpDAO = new CRM_PCP_DAO_PCP(); $pcpDAO->id = $softDAO->pcp_id; if ($pcpDAO->find(TRUE)) { $template->assign('title', $pcpDAO->title); } } } if ($this->financial_type_id) { $values['financial_type_id'] = $this->financial_type_id; } $template->assign('trxn_id', $this->trxn_id); $template->assign('receive_date', CRM_Utils_Date::mysqlToIso($this->receive_date)); $template->assign('contributeMode', 'notify'); $template->assign('action', $this->is_test ? 1024 : 1); $template->assign('receipt_text', CRM_Utils_Array::value('receipt_text', $values)); $template->assign('is_monetary', 1); $template->assign('is_recur', (bool) $recur); $template->assign('currency', $this->currency); $template->assign('address', CRM_Utils_Address::format($input)); if (!empty($values['customGroup'])) { $template->assign('customGroup', $values['customGroup']); } if ($this->_component == 'event') { $template->assign('title', $values['event']['title']); $participantRoles = CRM_Event_PseudoConstant::participantRole(); $viewRoles = array(); foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_relatedObjects['participant']->role_id) as $k => $v) { $viewRoles[] = $participantRoles[$v]; } $values['event']['participant_role'] = implode(', ', $viewRoles); $template->assign('event', $values['event']); $template->assign('participant', $values['participant']); $template->assign('location', $values['location']); $template->assign('customPre', $values['custom_pre_id']); $template->assign('customPost', $values['custom_post_id']); $isTest = FALSE; if ($this->_relatedObjects['participant']->is_test) { $isTest = TRUE; } $values['params'] = array(); //to get email of primary participant. $primaryEmail = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $this->_relatedObjects['participant']->contact_id, 'email', 'contact_id'); $primaryAmount[] = array('label' => $this->_relatedObjects['participant']->fee_level . ' - ' . $primaryEmail, 'amount' => $this->_relatedObjects['participant']->fee_amount); //build an array of cId/pId of participants $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($this->_relatedObjects['participant']->id, NULL, $this->_relatedObjects['contact']->id, $isTest, TRUE); unset($additionalIDs[$this->_relatedObjects['participant']->id]); //send receipt to additional participant if exists if (count($additionalIDs)) { $template->assign('isPrimary', 0); $template->assign('customProfile', NULL); //set additionalParticipant true $values['params']['additionalParticipant'] = TRUE; foreach ($additionalIDs as $pId => $cId) { $amount = array(); //to change the status pending to completed $additional = new CRM_Event_DAO_Participant(); $additional->id = $pId; $additional->contact_id = $cId; $additional->find(TRUE); $additional->register_date = $this->_relatedObjects['participant']->register_date; $additional->status_id = 1; $additionalParticipantInfo = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $additional->contact_id, 'email', 'contact_id'); //if additional participant dont have email //use display name. if (!$additionalParticipantInfo) { $additionalParticipantInfo = CRM_Contact_BAO_Contact::displayName($additional->contact_id); } $amount[0] = array('label' => $additional->fee_level, 'amount' => $additional->fee_amount); $primaryAmount[] = array('label' => $additional->fee_level . ' - ' . $additionalParticipantInfo, 'amount' => $additional->fee_amount); $additional->save(); $additional->free(); $template->assign('amount', $amount); CRM_Event_BAO_Event::sendMail($cId, $values, $pId, $isTest, $returnMessageText); } } //build an array of custom profile and assigning it to template $customProfile = CRM_Event_BAO_Event::buildCustomProfile($this->_relatedObjects['participant']->id, $values, NULL, $isTest); if (count($customProfile)) { $template->assign('customProfile', $customProfile); } // for primary contact $values['params']['additionalParticipant'] = FALSE; $template->assign('isPrimary', 1); $template->assign('amount', $primaryAmount); $template->assign('register_date', CRM_Utils_Date::isoToMysql($this->_relatedObjects['participant']->register_date)); if ($this->payment_instrument_id) { $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); $template->assign('paidBy', $paymentInstrument[$this->payment_instrument_id]); } // carry paylater, since we did not created billing, // so need to pull email from primary location, CRM-4395 $values['params']['is_pay_later'] = $this->_relatedObjects['participant']->is_pay_later; } return $template; }
/** * Build the form object. * * @return void */ public function buildQuickForm() { $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses); $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId); if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::buildQuickForm($this); } //need to assign custom data type to the template $this->assign('customDataType', 'Participant'); $this->applyFilter('__ALL__', 'trim'); if ($this->_action & CRM_Core_Action::DELETE) { if ($this->_single) { $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, NULL, $this->_contactId, FALSE, TRUE)) - 1; if ($additionalParticipant) { $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.')); $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />'); $this->setDefaults(array('delete_participant' => 1)); $this->assign('additionalParticipant', $additionalParticipant); } } $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_single && $this->_context == 'standalone') { $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE); } $eventFieldParams = array('entity' => 'event', 'select' => array('minimumInputLength' => 0), 'api' => array('extra' => array('campaign_id', 'default_role_id', 'event_type_id'))); if ($this->_mode) { // exclude events which are not monetary when credit card registration is used $eventFieldParams['api']['params']['is_monetary'] = 1; $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE); } $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE); //frozen the field fix for CRM-4171 if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) { if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) { $element->freeze(); } } //CRM-7362 --add campaigns. $campaignId = NULL; if ($this->_id) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id'); } if (!$campaignId) { $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this); if ($eventId) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id'); } } CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime')); if ($this->_id) { $this->assign('entityID', $this->_id); } $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE); // CRM-4395 $checkCancelledJs = array('onchange' => "return sendNotification( );"); $confirmJS = NULL; if ($this->_onlinePendingContributionId) { $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus()); $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')); $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});"); $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus()); $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')); $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );"); } // get the participant status names to build special status array which is used to show notification // checkbox below participant status select $participantStatusName = CRM_Event_PseudoConstant::participantStatus(); $notificationStatuses = array('Cancelled', 'Pending from waitlist', 'Pending from approval', 'Expired'); // get the required status and then implode only ids $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses))); $this->assign('notificationStatusIds', $notificationStatusIds); $this->_participantStatuses = $statusOptions = CRM_Event_BAO_Participant::buildOptions('status_id', 'create'); // Only show refund status when editing if ($this->_action & CRM_Core_Action::ADD) { $pendingRefundStatusId = array_search('Pending refund', $participantStatusName); if ($pendingRefundStatusId) { unset($statusOptions[$pendingRefundStatusId]); } } $this->addSelect('status_id', $checkCancelledJs + array('options' => $statusOptions, 'option_url' => 'civicrm/admin/participant_status'), TRUE); $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL); $this->add('text', 'source', ts('Event Source')); $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note'); $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']); $buttons[] = array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $confirmJS); $path = CRM_Utils_System::currentPath(); $excludeForPaths = array('civicrm/contact/search', 'civicrm/group/search'); if (!in_array($path, $excludeForPaths)) { $buttons[] = array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS); } $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel')); $this->addButtons($buttons); if ($this->_action == CRM_Core_Action::VIEW) { $this->freeze(); } }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::buildQuickForm($this); } if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //need to assign custom data type to the template $this->assign('customDataType', 'Participant'); $this->applyFilter('__ALL__', 'trim'); if ($this->_action & CRM_Core_Action::DELETE) { if ($this->_single) { $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, NULL, $this->_contactId, FALSE, TRUE)) - 1; if ($additionalParticipant) { $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.')); $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />'); $this->setDefaults(array('delete_participant' => 1)); $this->assign('additionalParticipant', $additionalParticipant); } } $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_single) { $urlPath = 'civicrm/contact/view/participant'; $urlParams = "reset=1&cid={$this->_contactId}&context=participant"; if ($this->_context == 'standalone') { CRM_Contact_Form_NewContact::buildQuickForm($this); $urlParams = 'reset=1&context=standalone'; $urlPath = 'civicrm/participant/add'; } if ($this->_id) { $urlParams .= "&action=update&id={$this->_id}"; } else { $urlParams .= "&action=add"; } if ($this->_mode) { $urlParams .= "&mode={$this->_mode}"; } $url = CRM_Utils_System::url($urlPath, $urlParams, FALSE, NULL, FALSE); } else { $currentPath = CRM_Utils_System::currentPath(); $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', FALSE, NULL, FALSE); } $this->assign('refreshURL', $url); $this->add('hidden', 'past_event'); $events = array(); if ($this->_eID) { $eventEndDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eID, 'end_date'); } $this->assign('past', 0); if ($this->_action & CRM_Core_Action::UPDATE) { $events = CRM_Event_BAO_Event::getEvents(1, FALSE, FALSE); } elseif ($this->getElementValue('past_event') || isset($eventEndDate) && CRM_Utils_Date::currentDBDate() > CRM_Utils_Date::processDate($eventEndDate)) { $pastval = $this->getElementValue('past_event'); $events = CRM_Event_BAO_Event::getEvents($pastval); $this->assign('past', $pastval); } else { $events = CRM_Event_BAO_Event::getEvents(); } if ($this->_mode) { //unset the event which are not monetary when credit card //event registration is used foreach ($events as $key => $val) { $isPaid = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $key, 'is_monetary'); if (!$isPaid) { unset($events[$key]); } } $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE); } // build array(event -> eventType) mapper $query = "\nSELECT civicrm_event.id as id, civicrm_event.event_type_id as event_type_id\nFROM civicrm_event\nWHERE civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0"; $dao = CRM_Core_DAO::executeQuery($query); $eventAndTypeMapping = array(); while ($dao->fetch()) { $eventAndTypeMapping[$dao->id] = $dao->event_type_id; } $eventAndTypeMapping = json_encode($eventAndTypeMapping); // building of mapping ends -- //inherit the campaign from event. $eventCampaigns = array(); $allEventIds = array_keys($events); if (!empty($allEventIds)) { CRM_Core_PseudoConstant::populate($eventCampaigns, 'CRM_Event_DAO_Event', TRUE, 'campaign_id'); } $eventCampaigns = json_encode($eventCampaigns); $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, TRUE, array('onchange' => "buildFeeBlock( this.value ); CRM.buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} ); buildParticipantRole( this.value ); buildEventTypeCustomData( this.value, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' ); loadCampaign( this.value, {$eventCampaigns} );", 'class' => 'huge')); // CRM-6111 // note that embedding JS within PHP files is quite awful, IMO // but we do the same for the onChange element and this form is complex // and i did not want to break it late in the 3.2 cycle $preloadJSSnippet = NULL; if (CRM_Utils_Array::value('reset', $_GET) && $this->_eID) { $preloadJSSnippet = "\ncj(function() {\ncj('#event_id').val( '{$this->_eID}' );\nbuildFeeBlock( {$this->_eID} );\nCRM.buildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );\nbuildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );\nloadCampaign( {$this->_eID}, {$eventCampaigns} );\n});\n"; } $this->assign('preloadJSSnippet', $preloadJSSnippet); //frozen the field fix for CRM-4171 if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) { if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) { $element->freeze(); } } //CRM-7362 --add campaigns. $campaignId = NULL; if ($this->_id) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id'); } if (!$campaignId) { $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this); if ($eventId) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id'); } } CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime')); if ($this->_id) { $this->assign('entityID', $this->_id); } $roleids = CRM_Event_PseudoConstant::participantRole(); foreach ($roleids as $rolekey => $rolevalue) { $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue, array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );")); } $this->addGroup($roleTypes, 'role_id', ts('Participant Role')); $this->addRule('role_id', ts('Role is required'), 'required'); // CRM-4395 $checkCancelledJs = array('onchange' => "return sendNotification( );"); $confirmJS = NULL; if ($this->_onlinePendingContributionId) { $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus()); $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')); $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});"); $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus()); $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')); $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );"); } // get the participant status names to build special status array which is used to show notification // checkbox below participant status select $participantStatusName = CRM_Event_PseudoConstant::participantStatus(); $notificationStatuses = array('Cancelled', 'Pending from waitlist', 'Pending from approval', 'Expired'); // get the required status and then implode only ids $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses))); $this->assign('notificationStatusIds', $notificationStatusIds); $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + $this->_participantStatuses, TRUE, $checkCancelledJs); $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL); $this->add('text', 'source', ts('Event Source')); $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note'); $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']); $buttons[] = array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $confirmJS); $path = CRM_Utils_System::currentPath(); $excludeForPaths = array('civicrm/contact/search', 'civicrm/group/search'); if (!in_array($path, $excludeForPaths)) { $buttons[] = array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS); } $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel')); $this->addButtons($buttons); if ($this->_action == CRM_Core_Action::VIEW) { $this->freeze(); } }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::buildQuickForm($this); } if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //need to assign custom data type to the template $this->assign('customDataType', 'Participant'); $this->applyFilter('__ALL__', 'trim'); if ($this->_action & CRM_Core_Action::DELETE) { if ($this->_single) { require_once 'CRM/Event/BAO/Event.php'; $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_participantId, null, $this->_contactID, false, true)) - 1; if ($additionalParticipant) { $this->assign("additionalParticipant", $additionalParticipant); } } $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_single) { $urlPath = 'civicrm/contact/view/participant'; $urlParams = "reset=1&cid={$this->_contactID}&context=participant"; if ($this->_context == 'standalone') { require_once 'CRM/Contact/Form/NewContact.php'; CRM_Contact_Form_NewContact::buildQuickForm($this); $urlParams = "reset=1&context=standalone"; $urlPath = 'civicrm/participant/add'; } if ($this->_participantId) { $urlParams .= "&action=update&id={$this->_participantId}"; } else { $urlParams .= "&action=add"; } if (CRM_Utils_Request::retrieve('past', 'Boolean', $this)) { $urlParams .= "&past=true"; } if ($this->_mode) { $urlParams .= "&mode={$this->_mode}"; } $url = CRM_Utils_System::url($urlPath, $urlParams, false, null, false); } else { $currentPath = CRM_Utils_System::currentPath(); $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', false, null, false); } $this->assign("refreshURL", $url); $url .= "&past=true"; $this->assign("pastURL", $url); $events = array(); $this->assign("past", false); require_once "CRM/Event/BAO/Event.php"; if (CRM_Utils_Request::retrieve('past', 'Boolean', $this) || $this->_action & CRM_Core_Action::UPDATE) { $events = CRM_Event_BAO_Event::getEvents(true); $this->assign("past", true); } else { $events = CRM_Event_BAO_Event::getEvents(); } if ($this->_mode) { //unset the event which are not monetary when credit card //event registration is used foreach ($events as $key => $val) { $isPaid = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $key, 'is_monetary'); if (!$isPaid) { unset($events[$key]); } } $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, true); } $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, true, array('onchange' => "buildFeeBlock( this.value ); buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} );", 'class' => 'huge')); //frozen the field fix for CRM-4171 if ($this->_action & CRM_Core_Action::UPDATE && $this->_participantId) { if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id')) { $element->freeze(); } } $this->addDateTime('register_date', ts('Registration Date'), true); if ($this->_participantId) { $this->assign('entityID', $this->_participantId); } $this->add('select', 'role_id', ts('Participant Role'), array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), true, array('onchange' => "buildCustomData( 'Participant', this.value, {$this->_roleCustomDataTypeID} );")); // CRM-4395 $checkCancelledJs = array('onchange' => "return sendNotification( );"); if ($this->_onlinePendingContributionId) { $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus()); $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name')); $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});"); } $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(null, null, 'label'), true, $checkCancelledJs); $this->addElement('checkbox', 'is_notify', ts('Send Notification'), null); $this->add('text', 'source', ts('Event Source')); $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note'); $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']); $confirmJS = null; if ($this->_onlinePendingContributionId) { $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus()); $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name')); $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );"); } $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => true, 'js' => $confirmJS), array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS), array('type' => 'cancel', 'name' => ts('Cancel')))); if ($this->_action == CRM_Core_Action::VIEW) { $this->freeze(); } }
/** * Process the form submission. */ public function postProcess() { $now = date('YmdHis'); $this->_params = $this->get('params'); if (!empty($this->_params[0]['contact_id'])) { // unclear when this would be set & whether it could be checked in getContactID. // perhaps it relates to when cid is in the url //@todo someone who knows add comments on the various contactIDs in this form $contactID = $this->_params[0]['contact_id']; } else { $contactID = $this->getContactID(); } // if a discount has been applied, lets now deduct it from the amount // and fix the fee level if (!empty($this->_params[0]['discount']) && !empty($this->_params[0]['discount']['applied'])) { foreach ($this->_params as $k => $v) { if (CRM_Utils_Array::value('amount', $this->_params[$k]) > 0 && !empty($this->_params[$k]['discountAmount'])) { $this->_params[$k]['amount'] -= $this->_params[$k]['discountAmount']; $this->_params[$k]['amount_level'] .= CRM_Utils_Array::value('discountMessage', $this->_params[$k]); } } $this->set('params', $this->_params); } // CRM-4320, lets build array of cancelled additional participant ids // those are drop or skip by primary at the time of confirmation. // get all in and then unset those we want to process. $cancelledIds = $this->_additionalParticipantIds; $params = $this->_params; if ($this->_values['event']['is_monetary']) { $this->set('finalAmount', $this->_amount); } $participantCount = array(); //unset the skip participant from params. //build the $participantCount array. //maintain record for all participants. foreach ($params as $participantNum => $record) { if ($record == 'skip') { unset($params[$participantNum]); $participantCount[$participantNum] = 'skip'; } elseif ($participantNum) { $participantCount[$participantNum] = 'participant'; } //lets get additional participant id to cancel. if ($this->_allowConfirmation && is_array($cancelledIds)) { $additonalId = CRM_Utils_Array::value('participant_id', $record); if ($additonalId && ($key = array_search($additonalId, $cancelledIds))) { unset($cancelledIds[$key]); } } } $payment = $registerByID = $primaryCurrencyID = $contribution = NULL; $paymentObjError = ts('The system did not record payment details for this payment and so could not process the transaction. Please report this error to the site administrator.'); $this->participantIDS = array(); $fields = array(); foreach ($params as $key => $value) { CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields, $this); //unset the billing parameters if it is pay later mode //to avoid creation of billing location // @todo - the reasoning for this is unclear - elsewhere we check what fields are provided by // the form & if billing fields exist we create the address, relying on the form to collect // only information we intend to store. if ($this->_allowWaitlist || $this->_requireApproval || !empty($value['is_pay_later']) && !$this->_isBillingAddressRequiredForPayLater || empty($value['is_primary'])) { $billingFields = array("email-{$this->_bltID}", 'billing_first_name', 'billing_middle_name', 'billing_last_name', "billing_street_address-{$this->_bltID}", "billing_city-{$this->_bltID}", "billing_state_province-{$this->_bltID}", "billing_state_province_id-{$this->_bltID}", "billing_postal_code-{$this->_bltID}", "billing_country-{$this->_bltID}", "billing_country_id-{$this->_bltID}", "address_name-{$this->_bltID}"); foreach ($billingFields as $field) { unset($value[$field]); } if (!empty($value['is_pay_later'])) { $this->_values['params']['is_pay_later'] = TRUE; } } //Unset ContactID for additional participants and set RegisterBy Id. if (empty($value['is_primary'])) { $contactID = CRM_Utils_Array::value('contact_id', $value); $registerByID = $this->get('registerByID'); if ($registerByID) { $value['registered_by_id'] = $registerByID; } } else { $value['amount'] = $this->_totalAmount; } $contactID = CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields, $this); // lets store the contactID in the session // we dont store in userID in case the user is doing multiple // transactions etc // for things like tell a friend if (!$this->getContactID() && !empty($value['is_primary'])) { $session = CRM_Core_Session::singleton(); $session->set('transaction.userID', $contactID); } $value['description'] = ts('Online Event Registration') . ': ' . $this->_values['event']['title']; $value['accountingCode'] = CRM_Utils_Array::value('accountingCode', $this->_values['event']); $pending = FALSE; if ($this->_allowWaitlist || $this->_requireApproval) { //get the participant statuses. $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'"); if ($this->_allowWaitlist) { $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses); } else { $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses); } //there might be case user seleted pay later and //now becomes part of run time waiting list. $value['is_pay_later'] = FALSE; } // required only if paid event if ($this->_values['event']['is_monetary'] && !($this->_allowWaitlist || $this->_requireApproval)) { if (is_array($this->_paymentProcessor)) { $payment = $this->_paymentProcessor['object']; } if (!empty($this->_paymentProcessor) && $this->_paymentProcessor['object']->supports('preApproval')) { $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters')); $value = array_merge($value, $preApprovalParams); } $result = NULL; if (!empty($value['is_pay_later']) || $value['amount'] == 0 || $this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') { if ($value['amount'] != 0) { $pending = TRUE; //get the participant statuses. $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'"); $status = !empty($value['is_pay_later']) ? 'Pending from pay later' : 'Pending from incomplete transaction'; $value['participant_status_id'] = $value['participant_status'] = array_search($status, $pendingStatuses); } } elseif (!empty($value['is_primary'])) { CRM_Core_Payment_Form::mapParams($this->_bltID, $value, $value, TRUE); // payment email param can be empty for _bltID mapping // thus provide mapping for it with a different email value if (empty($value['email'])) { $value['email'] = CRM_Utils_Array::valueByRegexKey('/^email-/', $value); } if (is_object($payment)) { try { $result = $payment->doPayment($value); $value = array_merge($value, $result); } catch (\Civi\Payment\Exception\PaymentProcessorException $e) { CRM_Core_Session::singleton()->setStatus($e->getMessage()); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}")); } } else { CRM_Core_Error::fatal($paymentObjError); } } $value['receive_date'] = $now; if ($this->_allowConfirmation) { $value['participant_register_date'] = $this->_values['participant']['register_date']; } $createContrib = $value['amount'] != 0 ? TRUE : FALSE; // force to create zero amount contribution, CRM-5095 if (!$createContrib && $value['amount'] == 0 && $this->_priceSetId && $this->_lineItem) { $createContrib = TRUE; } if ($createContrib && !empty($value['is_primary']) && !$this->_allowWaitlist && !$this->_requireApproval) { // if paid event add a contribution record //if primary participant contributing additional amount //append (multiple participants) to its fee level. CRM-4196. $isAdditionalAmount = FALSE; if (count($params) > 1) { $isAdditionalAmount = TRUE; } //passing contribution id is already registered. $contribution = self::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount); $value['contributionID'] = $contribution->id; $value['contributionTypeID'] = $contribution->financial_type_id; $value['receive_date'] = $contribution->receive_date; $value['trxn_id'] = $contribution->trxn_id; $value['contributionID'] = $contribution->id; $value['contributionTypeID'] = $contribution->financial_type_id; } $value['contactID'] = $contactID; $value['eventID'] = $this->_eventId; $value['item_name'] = $value['description']; } if (!empty($value['contributionID'])) { $this->_values['contributionId'] = $value['contributionID']; } //CRM-4453. if (!empty($value['is_primary'])) { $primaryCurrencyID = CRM_Utils_Array::value('currencyID', $value); } if (empty($value['currencyID'])) { $value['currencyID'] = $primaryCurrencyID; } // CRM-11182 - Confirmation page might not be monetary if ($this->_values['event']['is_monetary']) { if (!$pending && !empty($value['is_primary']) && !$this->_allowWaitlist && !$this->_requireApproval) { // transactionID & receive date required while building email template $this->assign('trxn_id', $value['trxn_id']); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($value['receive_date'])); $this->set('receiveDate', CRM_Utils_Date::mysqlToIso($value['receive_date'])); $this->set('trxnId', CRM_Utils_Array::value('trxn_id', $value)); } } $value['fee_amount'] = CRM_Utils_Array::value('amount', $value); $this->set('value', $value); // handle register date CRM-4320 if ($this->_allowConfirmation) { $registerDate = CRM_Utils_Array::value('participant_register_date', $params); } elseif (!empty($params['participant_register_date']) && is_array($params['participant_register_date']) && !empty($params['participant_register_date'])) { $registerDate = CRM_Utils_Date::format($params['participant_register_date']); } else { $registerDate = date('YmdHis'); } $this->assign('register_date', $registerDate); $this->confirmPostProcess($contactID, $contribution, $payment); } //handle if no additional participant. if (!$registerByID) { $registerByID = $this->get('registerByID'); } $this->set('participantIDs', $this->_participantIDS); // create line items, CRM-5313 if ($this->_priceSetId && !empty($this->_lineItem)) { // take all processed participant ids. $allParticipantIds = $this->_participantIDS; // when participant re-walk wizard. if ($this->_allowConfirmation && !empty($this->_additionalParticipantIds)) { $allParticipantIds = array_merge(array($registerByID), $this->_additionalParticipantIds); } $entityTable = 'civicrm_participant'; $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); $totalTaxAmount = 0; $dataArray = array(); foreach ($this->_lineItem as $key => $value) { if ($value == 'skip') { continue; } if ($entityId = CRM_Utils_Array::value($key, $allParticipantIds)) { // do cleanup line items if participant re-walking wizard. if ($this->_allowConfirmation) { CRM_Price_BAO_LineItem::deleteLineItems($entityId, $entityTable); } $lineItem[$this->_priceSetId] = $value; CRM_Price_BAO_LineItem::processPriceSet($entityId, $lineItem, $contribution, $entityTable); } if ($invoicing) { foreach ($value as $line) { if (isset($line['tax_amount']) && isset($line['tax_rate'])) { $totalTaxAmount = $line['tax_amount'] + $totalTaxAmount; if (isset($dataArray[$line['tax_rate']])) { $dataArray[$line['tax_rate']] = $dataArray[$line['tax_rate']] + CRM_Utils_Array::value('tax_amount', $line); } else { $dataArray[$line['tax_rate']] = CRM_Utils_Array::value('tax_amount', $line); } } } } } if ($invoicing) { $this->assign('dataArray', $dataArray); $this->assign('totalTaxAmount', $totalTaxAmount); } } //update status and send mail to cancelled additional participants, CRM-4320 if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) { $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'")); CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId); } $isTest = FALSE; if ($this->_action & CRM_Core_Action::PREVIEW) { $isTest = TRUE; } // for Transfer checkout. // The concept of contributeMode is deprecated. if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') && empty($params[0]['is_pay_later']) && !$this->_allowWaitlist && !$this->_requireApproval && $this->_totalAmount > 0) { $primaryParticipant = $this->get('primaryParticipant'); if (empty($primaryParticipant['participantID'])) { $primaryParticipant['participantID'] = $registerByID; } //build an array of custom profile and assigning it to template $customProfile = CRM_Event_BAO_Event::buildCustomProfile($registerByID, $this->_values, NULL, $isTest); if (count($customProfile)) { $this->assign('customProfile', $customProfile); $this->set('customProfile', $customProfile); } // do a transfer only if a monetary payment greater than 0 if ($this->_values['event']['is_monetary'] && $primaryParticipant) { if ($payment && is_object($payment)) { //CRM 14512 provide line items of all participants to payment gateway $primaryContactId = $this->get('primaryContactId'); //build an array of cId/pId of participants $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE); //need to copy, since we are unsetting on the way. $copyParticipantCountLines = $participantCount; //lets carry all participant params w/ values. foreach ($additionalIDs as $participantID => $contactId) { $participantNum = NULL; $participantNum = $participantID; if ($participantID == $registerByID) { // This is the is primary participant. $participantNum = 0; } else { if ($participantNum = array_search('participant', $copyParticipantCountLines)) { //if no participant found break. if ($participantNum === NULL) { break; } //unset current particpant so we don't check them again unset($copyParticipantCountLines[$participantNum]); } } // get values of line items if ($this->_amount) { $amount = array(); $amount[$participantNum]['label'] = preg_replace('//', '', $params[$participantNum]['amount_level']); $amount[$participantNum]['amount'] = $params[$participantNum]['amount']; $params[$participantNum]['amounts'] = $amount; } if (!empty($this->_lineItem)) { $lineItems = $this->_lineItem; $lineItem = array(); if ($lineItemValue = CRM_Utils_Array::value($participantNum, $lineItems)) { $lineItem[] = $lineItemValue; } $params[$participantNum]['lineItem'] = $lineItem; } //only add additional particpants and not the primary particpant as we already have that //added to $primaryParticipant so that this change doesn't break or require changes to //existing gateway implementations $primaryParticipant['participants_info'][$participantID] = $params[$participantNum]; } //get event custom field information $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_eventId, 0, $this->_values['event']['event_type_id']); $primaryParticipant['eventCustomFields'] = $groupTree; // call postprocess hook before leaving $this->postProcessHook(); // this does not return $payment->doPayment($primaryParticipant, 'event'); } else { CRM_Core_Error::fatal($paymentObjError); } } } else { //otherwise send mail Confirmation/Receipt $primaryContactId = $this->get('primaryContactId'); //build an array of cId/pId of participants $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE); //lets send mails to all with meaningful text, CRM-4320. $this->assign('isOnWaitlist', $this->_allowWaitlist); $this->assign('isRequireApproval', $this->_requireApproval); //need to copy, since we are unsetting on the way. $copyParticipantCount = $participantCount; //lets carry all paticipant params w/ values. foreach ($additionalIDs as $participantID => $contactId) { $participantNum = NULL; if ($participantID == $registerByID) { $participantNum = 0; } else { if ($participantNum = array_search('participant', $copyParticipantCount)) { unset($copyParticipantCount[$participantNum]); } } if ($participantNum === NULL) { break; } //carry the participant submitted values. $this->_values['params'][$participantID] = $params[$participantNum]; } foreach ($additionalIDs as $participantID => $contactId) { $participantNum = 0; if ($participantID == $registerByID) { //set as Primary Participant $this->assign('isPrimary', 1); //build an array of custom profile and assigning it to template. $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, NULL, $isTest); if (count($customProfile)) { $this->assign('customProfile', $customProfile); $this->set('customProfile', $customProfile); } $this->_values['params']['additionalParticipant'] = FALSE; } else { //take the Additional participant number. if ($participantNum = array_search('participant', $participantCount)) { unset($participantCount[$participantNum]); } // Change $this->_values['participant'] to include additional participant values $ids = $participantValues = array(); $participantParams = array('id' => $participantID); CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids); $this->_values['participant'] = $participantValues[$participantID]; $this->assign('isPrimary', 0); $this->assign('customProfile', NULL); //Additional Participant should get only it's payment information if (!empty($this->_amount)) { $amount = array(); $params = $this->get('params'); $amount[$participantNum]['label'] = preg_replace('//', '', $params[$participantNum]['amount_level']); $amount[$participantNum]['amount'] = $params[$participantNum]['amount']; $this->assign('amounts', $amount); } if ($this->_lineItem) { $lineItems = $this->_lineItem; $lineItem = array(); if ($lineItemValue = CRM_Utils_Array::value($participantNum, $lineItems)) { $lineItem[] = $lineItemValue; } if ($invoicing) { $individual = $this->get('individual'); $dataArray[key($dataArray)] = $individual[$participantNum]['totalTaxAmt']; $this->assign('dataArray', $dataArray); $this->assign('totalAmount', $individual[$participantNum]['totalAmtWithTax']); $this->assign('totalTaxAmount', $individual[$participantNum]['totalTaxAmt']); $this->assign('individual', array($individual[$participantNum])); } $this->assign('lineItem', $lineItem); } $this->_values['params']['additionalParticipant'] = TRUE; $this->assign('isAdditionalParticipant', $this->_values['params']['additionalParticipant']); } //pass these variables since these are run time calculated. $this->_values['params']['isOnWaitlist'] = $this->_allowWaitlist; $this->_values['params']['isRequireApproval'] = $this->_requireApproval; //send mail to primary as well as additional participants. $this->assign('contactID', $contactId); $this->assign('participantID', $participantID); CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest); } } }
function sendMail(&$input, &$ids, &$objects, &$values, $recur = false, $returnMessageText = false) { $contribution =& $objects['contribution']; $membership =& $objects['membership']; $participant =& $objects['participant']; $event =& $objects['event']; if (empty($values)) { $values = array(); if ($input['component'] == 'contribute') { require_once 'CRM/Contribute/BAO/ContributionPage.php'; if (isset($contribution->contribution_page_id)) { CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values); } else { // Handle re-print receipt for offline contributions (call from PDF.php - no contribution_page_id) $values['is_email_receipt'] = 1; $values['title'] = 'Contribution'; } } else { // event $eventParams = array('id' => $objects['event']->id); $values['event'] = array(); require_once 'CRM/Event/BAO/Event.php'; CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); $eventParams = array('id' => $objects['event']->id); $values['event'] = array(); require_once 'CRM/Event/BAO/Event.php'; CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); //get location details $locationParams = array('entity_id' => $objects['event']->id, 'entity_table' => 'civicrm_event'); require_once 'CRM/Core/BAO/Location.php'; require_once 'CRM/Event/Form/ManageEvent/Location.php'; $values['location'] = CRM_Core_BAO_Location::getValues($locationParams); require_once 'CRM/Core/BAO/UFJoin.php'; $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'weight' => 1); $values['custom_pre_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); $ufJoinParams['weight'] = 2; $values['custom_post_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); } } $template =& CRM_Core_Smarty::singleton(); // CRM_Core_Error::debug('tpl',$template); //assign honor infomation to receiptmessage if ($honarID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'honor_contact_id')) { $honorDefault = array(); $honorIds = array(); $honorIds['contribution'] = $contribution->id; $idParams = array('id' => $honarID, 'contact_id' => $honarID); require_once "CRM/Contact/BAO/Contact.php"; CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $honorIds); require_once "CRM/Core/PseudoConstant.php"; $honorType = CRM_Core_PseudoConstant::honor(); $prefix = CRM_Core_PseudoConstant::individualPrefix(); $template->assign('honor_block_is_active', 1); $template->assign('honor_prefix', $prefix[$honorDefault["prefix_id"]]); $template->assign('honor_first_name', CRM_Utils_Array::value("first_name", $honorDefault)); $template->assign('honor_last_name', CRM_Utils_Array::value("last_name", $honorDefault)); $template->assign('honor_email', CRM_Utils_Array::value("email", $honorDefault["email"][1])); $template->assign('honor_type', $honorType[$contribution->honor_type_id]); } require_once 'CRM/Contribute/DAO/ContributionProduct.php'; $dao =& new CRM_Contribute_DAO_ContributionProduct(); $dao->contribution_id = $contribution->id; if ($dao->find(true)) { $premiumId = $dao->product_id; $template->assign('option', $dao->product_option); require_once 'CRM/Contribute/DAO/Product.php'; $productDAO =& new CRM_Contribute_DAO_Product(); $productDAO->id = $premiumId; $productDAO->find(true); $template->assign('selectPremium', true); $template->assign('product_name', $productDAO->name); $template->assign('price', $productDAO->price); $template->assign('sku', $productDAO->sku); } // add the new contribution values if ($input['component'] == 'contribute') { $template->assign('title', $values['title']); $template->assign('amount', $input['amount']); //PCP Info require_once 'CRM/Contribute/DAO/ContributionSoft.php'; $softDAO =& new CRM_Contribute_DAO_ContributionSoft(); $softDAO->contribution_id = $contribution->id; if ($softDAO->find(true)) { $template->assign('pcpBlock', true); $template->assign('pcp_display_in_roll', $softDAO->pcp_display_in_roll); $template->assign('pcp_roll_nickname', $softDAO->pcp_roll_nickname); $template->assign('pcp_personal_note', $softDAO->pcp_personal_note); //assign the pcp page title for email subject require_once 'CRM/Contribute/DAO/PCP.php'; $pcpDAO =& new CRM_Contribute_DAO_PCP(); $pcpDAO->id = $softDAO->pcp_id; if ($pcpDAO->find(true)) { $template->assign('title', $pcpDAO->title); } } } else { $template->assign('title', $values['event']['title']); $template->assign('totalAmount', $input['amount']); } $template->assign('trxn_id', $contribution->trxn_id); $template->assign('receive_date', CRM_Utils_Date::mysqlToIso($contribution->receive_date)); $template->assign('contributeMode', 'notify'); $template->assign('action', $contribution->is_test ? 1024 : 1); $template->assign('receipt_text', CRM_Utils_Array::value('receipt_text', $values)); $template->assign('is_monetary', 1); $template->assign('is_recur', $recur); if ($recur) { require_once 'CRM/Core/Payment.php'; $paymentObject =& CRM_Core_Payment::singleton($contribution->is_test ? 'test' : 'live', 'Contribute', $objects['paymentProcessor']); $url = $paymentObject->cancelSubscriptionURL(); $template->assign('cancelSubscriptionUrl', $url); if ($objects['paymentProcessor']['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) { //direct mode showing billing block, so use directIPN for temporary $template->assign('contributeMode', 'directIPN'); } } require_once 'CRM/Utils/Address.php'; $template->assign('address', CRM_Utils_Address::format($input)); if ($input['component'] == 'event') { require_once 'CRM/Core/OptionGroup.php'; $participant_role = CRM_Core_OptionGroup::values('participant_role'); $values['event']['participant_role'] = $participant_role[$participant->role_id]; $template->assign('event', $values['event']); $template->assign('location', $values['location']); $template->assign('customPre', $values['custom_pre_id']); $template->assign('customPost', $values['custom_post_id']); $isTest = false; if ($participant->is_test) { $isTest = true; } $values['params'] = array(); require_once "CRM/Event/BAO/Event.php"; //to get email of primary participant. $primaryEmail = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $participant->contact_id, 'email', 'contact_id'); $primaryAmount[] = array('label' => $participant->fee_level . ' - ' . $primaryEmail, 'amount' => $participant->fee_amount); //build an array of cId/pId of participants $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($participant->id, null, $ids['contact'], $isTest, true); unset($additionalIDs[$participant->id]); //send receipt to additional participant if exists if (count($additionalIDs)) { $template->assign('isPrimary', 0); $template->assign('customProfile', null); //set additionalParticipant true $values['params']['additionalParticipant'] = true; foreach ($additionalIDs as $pId => $cId) { $amount = array(); //to change the status pending to completed $additional =& new CRM_Event_DAO_Participant(); $additional->id = $pId; $additional->contact_id = $cId; $additional->find(true); $additional->register_date = $participant->register_date; $additional->status_id = 1; $additionalParticipantInfo = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $additional->contact_id, 'email', 'contact_id'); //if additional participant dont have email //use display name. if (!$additionalParticipantInfo) { require_once "CRM/Contact/BAO/Contact.php"; $additionalParticipantInfo = CRM_Contact_BAO_Contact::displayName($additional->contact_id); } $amount[0] = array('label' => $additional->fee_level, 'amount' => $additional->fee_amount); $primaryAmount[] = array('label' => $additional->fee_level . ' - ' . $additionalParticipantInfo, 'amount' => $additional->fee_amount); $additional->save(); $additional->free(); $template->assign('amount', $amount); CRM_Event_BAO_Event::sendMail($cId, $values, $pId, $isTest, $returnMessageText); } } //build an array of custom profile and assigning it to template $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participant->id, $values, null, $isTest); if (count($customProfile)) { $template->assign('customProfile', $customProfile); } // for primary contact $values['params']['additionalParticipant'] = false; $template->assign('isPrimary', 1); $template->assign('amount', $primaryAmount); // carry paylater, since we did not created billing, // so need to pull email from primary location, CRM-4395 $values['params']['is_pay_later'] = $participant->is_pay_later; return CRM_Event_BAO_Event::sendMail($ids['contact'], $values, $participant->id, $isTest, $returnMessageText); } else { if ($membership) { $values['membership_id'] = $membership->id; // need to set the membership values here $template->assign('membership_assign', 1); require_once 'CRM/Member/PseudoConstant.php'; $template->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id)); $template->assign('mem_start_date', $membership->start_date); $template->assign('mem_end_date', $membership->end_date); // if separate payment there are two contributions recorded and the // admin will need to send a receipt for each of them separately. // we dont link the two in the db (but can potentially infer it if needed) $template->assign('is_separate_payment', 0); } $values['contribution_id'] = $contribution->id; if (CRM_Utils_Array::value('related_contact', $ids)) { $values['related_contact'] = $ids['related_contact']; if (isset($ids['onbehalf_dupe_alert'])) { $values['onbehalf_dupe_alert'] = $ids['onbehalf_dupe_alert']; } require_once 'CRM/Core/BAO/Address.php'; $entityBlock = array('contact_id' => $ids['contact'], 'location_type_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', 'Main', 'id', 'name')); $address = CRM_Core_BAO_Address::getValues($entityBlock); $template->assign('onBehalfAddress', $address[$entityBlock['location_type_id']]['display']); } $isTest = false; if ($contribution->is_test) { $isTest = true; } // CRM_Core_Error::debug('val',$values); return CRM_Contribute_BAO_ContributionPage::sendMail($ids['contact'], $values, $isTest, $returnMessageText); } }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::buildQuickForm($this); } if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //need to assign custom data type to the template $this->assign('customDataType', 'Participant'); $this->applyFilter('__ALL__', 'trim'); if ($this->_action & CRM_Core_Action::DELETE) { if ($this->_single) { require_once 'CRM/Event/BAO/Event.php'; $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, null, $this->_contactId, false, true)) - 1; if ($additionalParticipant) { $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.')); $this->addRadio('delete_participant', null, $deleteParticipants, null, '<br />'); $this->setDefaults(array('delete_participant' => 1)); $this->assign("additionalParticipant", $additionalParticipant); } } $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_single) { $urlPath = 'civicrm/contact/view/participant'; $urlParams = "reset=1&cid={$this->_contactId}&context=participant"; if ($this->_context == 'standalone') { require_once 'CRM/Contact/Form/NewContact.php'; CRM_Contact_Form_NewContact::buildQuickForm($this); $urlParams = "reset=1&context=standalone"; $urlPath = 'civicrm/participant/add'; } if ($this->_id) { $urlParams .= "&action=update&id={$this->_id}"; } else { $urlParams .= "&action=add"; } if ($this->_mode) { $urlParams .= "&mode={$this->_mode}"; } $url = CRM_Utils_System::url($urlPath, $urlParams, false, null, false); } else { $currentPath = CRM_Utils_System::currentPath(); $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', false, null, false); } $this->assign("refreshURL", $url); $this->add('hidden', 'past_event'); $events = array(); $this->assign("past", false); require_once "CRM/Event/BAO/Event.php"; if ($this->_action & CRM_Core_Action::UPDATE) { $events = CRM_Event_BAO_Event::getEvents(true, false, false); } elseif ($this->getElementValue('past_event')) { $events = CRM_Event_BAO_Event::getEvents(true); $this->assign("past", true); } else { $events = CRM_Event_BAO_Event::getEvents(); } if ($this->_mode) { //unset the event which are not monetary when credit card //event registration is used foreach ($events as $key => $val) { $isPaid = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $key, 'is_monetary'); if (!$isPaid) { unset($events[$key]); } } $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, true); } // build array(event -> eventType) mapper $query = "\nSELECT civicrm_event.id as id, civicrm_event.event_type_id as event_type_id\nFROM civicrm_event\nWHERE civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0"; $dao =& CRM_Core_DAO::executeQuery($query); $eventAndTypeMapping = array(); while ($dao->fetch()) { $eventAndTypeMapping[$dao->id] = $dao->event_type_id; } $eventAndTypeMapping = json_encode($eventAndTypeMapping); // building of mapping ends -- $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, true, array('onchange' => "buildFeeBlock( this.value ); buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} ); buildParticipantRole( this.value ); buildEventTypeCustomData( this.value, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );", 'class' => 'huge')); // CRM-6111 // note that embedding JS within PHP files is quite awful, IMO // but we do the same for the onChange element and this form is complex // and i did not want to break it late in the 3.2 cycle $preloadJSSnippet = null; if (CRM_Utils_Array::value('reset', $_GET)) { $this->_eID = CRM_Utils_Request::retrieve('eid', 'Positive', $this); if ($this->_eID) { $preloadJSSnippet = "\ncj(function() {\ncj('#event_id').val( '{$this->_eID}' );\nbuildFeeBlock( {$this->_eID} ); \nbuildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );\nbuildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );\n});\n"; } } $this->assign('preloadJSSnippet', $preloadJSSnippet); //frozen the field fix for CRM-4171 if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) { if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) { $element->freeze(); } } $this->addDateTime('register_date', ts('Registration Date'), true, array('formatType' => 'activityDateTime')); if ($this->_id) { $this->assign('entityID', $this->_id); } $roleids = CRM_Event_PseudoConstant::participantRole(); foreach ($roleids as $rolekey => $rolevalue) { $roleTypes[] = HTML_QuickForm::createElement('checkbox', $rolekey, null, $rolevalue, array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );")); } $this->addGroup($roleTypes, 'role_id', ts('Participant Role')); $this->addRule('role_id', ts('Role is required'), 'required'); // CRM-4395 $checkCancelledJs = array('onchange' => "return sendNotification( );"); $confirmJS = null; if ($this->_onlinePendingContributionId) { $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus()); $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name')); $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});"); $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus()); $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name')); $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );"); } $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(null, null, 'label'); $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + $this->_participantStatuses, true, $checkCancelledJs); $this->addElement('checkbox', 'is_notify', ts('Send Notification'), null); $this->add('text', 'source', ts('Event Source')); $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note'); $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']); $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => true, 'js' => $confirmJS), array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS), array('type' => 'cancel', 'name' => ts('Cancel')))); if ($this->_action == CRM_Core_Action::VIEW) { $this->freeze(); } }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { require_once 'CRM/Event/BAO/Participant.php'; $config =& CRM_Core_Config::singleton(); $session =& CRM_Core_Session::singleton(); $contactID = $session->get('userID'); $now = date('YmdHis'); $this->_params = $this->get('params'); // if a discount has been applied, lets now deduct it from the amount // and fix the fee level if (CRM_Utils_Array::value('discount', $this->_params[0]) && CRM_Utils_Array::value('applied', $this->_params[0]['discount'])) { foreach ($this->_params as $k => $v) { if (CRM_Utils_Array::value('amount', $this->_params[$k]) > 0 && CRM_Utils_Array::value('discountAmount', $this->_params[$k])) { $this->_params[$k]['amount'] -= $this->_params[$k]['discountAmount']; $this->_params[$k]['amount_level'] .= CRM_Utils_Array::value('discountMessage', $this->_params[$k]); } } $this->set('params', $this->_params); } // CRM-4320, lets build array of cancelled additional participant ids // those are drop or skip by primary at the time of confirmation. // get all in and then unset those we want to process. $cancelledIds = $this->_additionalParticipantIds; $params = $this->_params; $this->set('finalAmount', $this->_amount); $participantCount = array(); //unset the skip participant from params. //build the $participantCount array. //maintain record for all participants. foreach ($params as $participantNum => $record) { if ($record == 'skip') { unset($params[$participantNum]); $participantCount[$participantNum] = 'skip'; } else { if ($participantNum) { $participantCount[$participantNum] = 'participant'; } } //lets get additional participant id to cancel. if ($this->_allowConfirmation && is_array($cancelledIds)) { $additonalId = CRM_Utils_Array::value('participant_id', $record); if ($additonalId && ($key = array_search($additonalId, $cancelledIds))) { unset($cancelledIds[$key]); } } } $payment = $registerByID = $primaryCurrencyID = $contribution = null; foreach ($params as $key => $value) { $this->_values['params'] = array(); $this->fixLocationFields($value, $fields); //unset the billing parameters if it is pay later mode //to avoid creation of billing location if ($this->_allowWaitlist || $this->_requireApproval || CRM_Utils_Array::value('is_pay_later', $value) || !CRM_Utils_Array::value('is_primary', $value)) { $billingFields = array("email-{$this->_bltID}", "billing_first_name", "billing_middle_name", "billing_last_name", "billing_street_address-{$this->_bltID}", "billing_city-{$this->_bltID}", "billing_state_province-{$this->_bltID}", "billing_state_province_id-{$this->_bltID}", "billing_postal_code-{$this->_bltID}", "billing_country-{$this->_bltID}", "billing_country_id-{$this->_bltID}", "address_name-{$this->_bltID}"); foreach ($billingFields as $field) { unset($value[$field]); } if (CRM_Utils_Array::value('is_pay_later', $value)) { $this->_values['params']['is_pay_later'] = true; } } //Unset ContactID for additional participants and set RegisterBy Id. if (!CRM_Utils_Array::value('is_primary', $value)) { $contactID = CRM_Utils_Array::value('contact_id', $value); $registerByID = $this->get('registerByID'); if ($registerByID) { $value['registered_by_id'] = $registerByID; } } else { $value['amount'] = $this->_totalAmount; } $contactID =& $this->updateContactFields($contactID, $value, $fields); // lets store the contactID in the session // we dont store in userID in case the user is doing multiple // transactions etc // for things like tell a friend if (!$session->get('userID') && CRM_Utils_Array::value('is_primary', $value)) { $session->set('transaction.userID', $contactID); } $value['description'] = ts('Online Event Registration') . ': ' . $this->_values['event']['title']; $value['accountingCode'] = CRM_Utils_Array::value('accountingCode', $this->_values['event']); // required only if paid event if ($this->_values['event']['is_monetary']) { require_once 'CRM/Core/Payment.php'; if (is_array($this->_paymentProcessor)) { $payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this); } $pending = false; $result = null; require_once 'CRM/Event/PseudoConstant.php'; if ($this->_allowWaitlist || $this->_requireApproval) { //get the participant statuses. $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(null, "class = 'Waiting'"); if ($this->_allowWaitlist) { $value['participant_status_id'] = array_search('On waitlist', $waitingStatuses); } else { $value['participant_status_id'] = array_search('Awaiting approval', $waitingStatuses); } //there might be case user seleted pay later and //now becomes part of run time waiting list. $value['is_pay_later'] = false; } else { if (CRM_Utils_Array::value('is_pay_later', $value) || $value['amount'] == 0 || $this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') { if ($value['amount'] != 0) { $pending = true; //get the participant statuses. require_once 'CRM/Event/PseudoConstant.php'; $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(null, "class = 'Pending'"); $status = CRM_Utils_Array::value('is_pay_later', $value) ? 'Pending from pay later' : 'Pending from incomplete transaction'; $value['participant_status_id'] = array_search($status, $pendingStatuses); } } else { if ($this->_contributeMode == 'express' && CRM_Utils_Array::value('is_primary', $value)) { $result =& $payment->doExpressCheckout($value); } else { if (CRM_Utils_Array::value('is_primary', $value)) { require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::mapParams($this->_bltID, $value, $value, true); $result =& $payment->doDirectPayment($value); } } } } if (is_a($result, 'CRM_Core_Error')) { CRM_Core_Error::displaySessionError($result); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}")); } if ($result) { $value = array_merge($value, $result); } $value['receive_date'] = $now; if ($this->_allowConfirmation) { $value['participant_register_date'] = $this->_values['participant']['register_date']; } $createContrib = $value['amount'] != 0 ? true : false; // force to create zero amount contribution, CRM-5095 if (!$createContrib && $value['amount'] == 0 && $this->_priceSetId && $this->_lineItem) { $createContrib = true; } if ($createContrib && CRM_Utils_Array::value('is_primary', $value) && !$this->_allowWaitlist && !$this->_requireApproval) { // if paid event add a contribution record //if primary participant contributing additional amount //append (multiple participants) to its fee level. CRM-4196. $isAdditionalAmount = false; if (count($params) > 1) { $isAdditionalAmount = true; } //passing contribution id is already registered. $contribution =& self::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount); $value['contributionID'] = $contribution->id; $value['contributionTypeID'] = $contribution->contribution_type_id; $value['receive_date'] = $contribution->receive_date; $value['trxn_id'] = $contribution->trxn_id; $value['contributionID'] = $contribution->id; $value['contributionTypeID'] = $contribution->contribution_type_id; } $value['contactID'] = $contactID; $value['eventID'] = $this->_eventId; $value['item_name'] = $value['description']; } //CRM-4453. if (CRM_Utils_Array::value('is_primary', $value)) { $primaryCurrencyID = CRM_Utils_Array::value('currencyID', $value); } if (!CRM_Utils_Array::value('currencyID', $value)) { $value['currencyID'] = $primaryCurrencyID; } if (!$pending && CRM_Utils_Array::value('is_primary', $value) && !$this->_allowWaitlist && !$this->_requireApproval) { // transactionID & receive date required while building email template $this->assign('trxn_id', $value['trxn_id']); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($value['receive_date'])); $this->set('receiveDate', CRM_Utils_Date::mysqlToIso($value['receive_date'])); $this->set('trxnId', CRM_Utils_Array::value('trxn_id', $value)); } $value['fee_amount'] = $value['amount']; $this->set('value', $value); // handle register date CRM-4320 if ($this->_allowConfirmation) { $registerDate = $params['participant_register_date']; } else { if (is_array($params['participant_register_date']) && !empty($params['participant_register_date'])) { $registerDate = CRM_Utils_Date::format($params['participant_register_date']); } else { $registerDate = date('YmdHis'); } } $this->assign('register_date', $registerDate); $this->confirmPostProcess($contactID, $contribution, $payment); } //handle if no additional participant. if (!$registerByID) { $registerByID = $this->get('registerByID'); } // create line items, CRM-5313 if ($this->_priceSetId && !empty($this->_lineItem)) { require_once 'CRM/Price/BAO/LineItem.php'; // take all processed participant ids. $allParticipantIds = $this->_participantIDS; // when participant re-walk wizard. if ($this->_allowConfirmation && !empty($this->_additionalParticipantIds)) { $allParticipantIds = array_merge(array($registerByID), $this->_additionalParticipantIds); } $entityTable = 'civicrm_participant'; foreach ($this->_lineItem as $key => $value) { if ($value != 'skip' && ($entityId = CRM_Utils_Array::value($key, $allParticipantIds))) { // do cleanup line items if participant re-walking wizard. if ($this->_allowConfirmation) { CRM_Price_BAO_LineItem::deleteLineItems($entityId, $entityTable); } // create line. foreach ($value as $line) { $line['entity_id'] = $entityId; $line['entity_table'] = $entityTable; CRM_Price_BAO_LineItem::create($line); } } } } //update status and send mail to cancelled additonal participants, CRM-4320 if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) { require_once 'CRM/Event/BAO/Participant.php'; require_once 'CRM/Event/PseudoConstant.php'; $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(null, "class = 'Negative'")); CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId); } $isTest = false; if ($this->_action & CRM_Core_Action::PREVIEW) { $isTest = true; } // for Transfer checkout. require_once "CRM/Event/BAO/Event.php"; if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') && !CRM_Utils_Array::value('is_pay_later', $params[0]) && !$this->_allowWaitlist && !$this->_requireApproval && $this->_totalAmount > 0) { $primaryParticipant = $this->get('primaryParticipant'); if (!CRM_Utils_Array::value('participantID', $primaryParticipant)) { $primaryParticipant['participantID'] = $registerByID; } //build an array of custom profile and assigning it to template $customProfile = CRM_Event_BAO_Event::buildCustomProfile($registerByID, $this->_values, null, $isTest); if (count($customProfile)) { $this->assign('customProfile', $customProfile); $this->set('customProfile', $customProfile); } // do a transfer only if a monetary payment greater than 0 if ($this->_values['event']['is_monetary'] && $primaryParticipant && $payment) { $payment->doTransferCheckout($primaryParticipant); } } else { //otherwise send mail Confirmation/Receipt $primaryContactId = $this->get('primaryContactId'); //build an array of cId/pId of participants require_once "CRM/Event/BAO/Event.php"; $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, null, $primaryContactId, $isTest, true); //lets send mails to all with meaningful text, CRM-4320. $this->assign('isOnWaitlist', $this->_allowWaitlist); $this->assign('isRequireApproval', $this->_requireApproval); foreach ($additionalIDs as $participantID => $contactId) { if ($participantID == $registerByID) { //set as Primary Participant $this->assign('isPrimary', 1); //build an array of custom profile and assigning it to template. $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, null, $isTest); if (count($customProfile)) { $this->assign('customProfile', $customProfile); $this->set('customProfile', $customProfile); } $this->_values['params']['additionalParticipant'] = false; } else { //take the Additional participant number. if ($paticipantNum = array_search('participant', $participantCount)) { unset($participantCount[$paticipantNum]); } $this->assign('isPrimary', 0); $this->assign('customProfile', null); //Additional Participant should get only it's payment information if ($this->_amount) { $amount = array(); $params = $this->get('params'); $amount[$paticipantNum]['label'] = $params[$paticipantNum]['amount_level']; $amount[$paticipantNum]['amount'] = $params[$paticipantNum]['amount']; $this->assign('amount', $amount); } if ($this->_lineItem) { $lineItems = $this->_lineItem; $lineItem = array(); $lineItem[] = CRM_Utils_Array::value($paticipantNum, $lineItems); $this->assign('lineItem', $lineItem); } $this->_values['params']['additionalParticipant'] = true; } //pass these variables since these are run time calculated. $this->_values['params']['isOnWaitlist'] = $this->_allowWaitlist; $this->_values['params']['isRequireApproval'] = $this->_requireApproval; //send mail to primary as well as additional participants. $this->assign('contactID', $contactId); $this->assign('participantID', $participantID); CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest); } } }
public function processRegistration($params, $contactID = null) { $session =& CRM_Core_Session::singleton(); $contactID = $session->get('userID'); $this->_participantInfo = array(); // CRM-4320, lets build array of cancelled additional participant ids // those are drop or skip by primary at the time of confirmation. // get all in and then unset those are confirmed. $cancelledIds = $this->_additionalParticipantIds; foreach ($params as $key => $value) { if ($value != 'skip') { $fields = null; // setting register by Id and unset contactId. if (!CRM_Utils_Array::value('is_primary', $value)) { $contactID = null; $registerByID = $this->get('registerByID'); if ($registerByID) { $value['registered_by_id'] = $registerByID; } if (CRM_Utils_Array::value("email-{$this->_bltID}", $value)) { $this->_participantInfo[] = $value["email-{$this->_bltID}"]; } else { $this->_participantInfo[] = $value['first_name'] . ' ' . $value['last_name']; } } require_once 'CRM/Event/Form/Registration/Confirm.php'; CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields); //for free event or additional participant, dont create billing email address. if (!CRM_Utils_Array::value('is_primary', $value) || !$this->_values['event']['is_monetary']) { unset($value["email-{$this->_bltID}"]); } $contactID =& CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields); // lets store the contactID in the session // we dont store in userID in case the user is doing multiple // transactions etc // for things like tell a friend if (!$session->get('userID') && CRM_Utils_Array::value('is_primary', $value)) { $session->set('transaction.userID', $contactID); } //lets get the status if require approval or waiting. require_once 'CRM/Event/PseudoConstant.php'; $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(null, "class = 'Waiting'"); if ($this->_allowWaitlist && !$this->_allowConfirmation) { $value['participant_status_id'] = array_search('On waitlist', $waitingStatuses); } else { if ($this->_requireApproval && !$this->_allowConfirmation) { $value['participant_status_id'] = array_search('Awaiting approval', $waitingStatuses); } } $this->set('value', $value); $this->confirmPostProcess($contactID, null, null); //lets get additional participant id to cancel. if ($this->_allowConfirmation && is_array($cancelledIds)) { $additonalId = CRM_Utils_Array::value('participant_id', $value); if ($additonalId && ($key = array_search($additonalId, $cancelledIds))) { unset($cancelledIds[$key]); } } } } // update status and send mail to cancelled additonal participants, CRM-4320 if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) { require_once 'CRM/Event/BAO/Participant.php'; require_once 'CRM/Event/PseudoConstant.php'; $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(null, "class = 'Negative'")); CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId); } //set information about additional participants if exists if (count($this->_participantInfo)) { $this->set('participantInfo', $this->_participantInfo); } //send mail Confirmation/Receipt require_once "CRM/Event/BAO/Event.php"; if ($this->_contributeMode != 'checkout' || $this->_contributeMode != 'notify') { $isTest = false; if ($this->_action & CRM_Core_Action::PREVIEW) { $isTest = true; } //handle if no additional participant. if (!$registerByID) { $registerByID = $this->get('registerByID'); } $primaryContactId = $this->get('primaryContactId'); //build an array of custom profile and assigning it to template. $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, null, $primaryContactId, $isTest, true); //lets send mails to all with meanigful text, CRM-4320. $this->assign('isOnWaitlist', $this->_allowWaitlist); $this->assign('isRequireApproval', $this->_requireApproval); foreach ($additionalIDs as $participantID => $contactId) { if ($participantID == $registerByID) { //set as Primary Participant $this->assign('isPrimary', 1); $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, null, $isTest); if (count($customProfile)) { $this->assign('customProfile', $customProfile); $this->set('customProfile', $customProfile); } } else { $this->assign('isPrimary', 0); $this->assign('customProfile', null); } //send Confirmation mail to Primary & additional Participants if exists CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest); } } }