From e3b510feb256cea1d8cc185deb7f6c24bec7e020 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Thu, 3 Dec 2015 18:19:21 +0530 Subject: [PATCH] CRM-16761 - Self Service additional changes --- CRM/Event/Form/SelfSvcTransfer.php | 54 ++++++++++++++----- CRM/Event/Form/SelfSvcUpdate.php | 30 +++++++++-- .../event_online_receipt_html.tpl | 18 +++---- .../event_online_receipt_text.tpl | 1 + .../event_online_receipt_html.tpl | 18 +++---- .../event_online_receipt_text.tpl | 1 + 6 files changed, 87 insertions(+), 35 deletions(-) diff --git a/CRM/Event/Form/SelfSvcTransfer.php b/CRM/Event/Form/SelfSvcTransfer.php index 10ce6ef144..a8b7fd1a73 100644 --- a/CRM/Event/Form/SelfSvcTransfer.php +++ b/CRM/Event/Form/SelfSvcTransfer.php @@ -231,7 +231,9 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { //check that either an email or firstname+lastname is included in the form(CRM-9587) $to_contact_id = self::checkProfileComplete($fields, $errors, $self); //To check if the user is already registered for the event(CRM-2426) - self::checkRegistration($fields, $self, $to_contact_id, $errors); + if ($to_contact_id) { + self::checkRegistration($fields, $self, $to_contact_id, $errors); + } //return parent::formrule($fields, $files, $self); return empty($errors) ? TRUE : $errors; } @@ -257,7 +259,10 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { } $contact = CRM_Contact_BAO_Contact::matchContactOnEmail($email, ""); $contact_id = empty($contact->contact_id) ? NULL : $contact->contact_id; - if (empty($contact_id)) { + if (!CRM_Utils_Rule::email($fields['email'])) { + $errors['email'] = ts('Enter valid email address.'); + } + if (empty($errors) && empty($contact_id)) { $params = array( 'email-Primary' => CRM_Utils_Array::value('email', $fields, NULL), 'first_name' => CRM_Utils_Array::value('first_name', $fields, NULL), @@ -325,11 +330,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { //first create the new participant row -don't set registered_by yet or email won't be sent $participant = CRM_Event_BAO_Participant::create($value_to); //send a confirmation email to the new participant - $err = $this->participantTransfer($participant); - if (!$err) { - $statusMsg = "Failed to send confirmation email"; - CRM_Core_Session::setStatus($statusMsg, ts('Error'), 'error'); - } + $this->participantTransfer($participant); //now update registered_by_id $query = "UPDATE civicrm_participant cp SET cp.registered_by_id = %1 WHERE cp.id = ({$participant->id})"; $params = array(1 => array($this->_from_participant_id, 'Integer')); @@ -357,6 +358,8 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $displayName)); $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $email)); CRM_Core_Session::setStatus($statusMsg, ts('Registration Transferred'), 'success'); + $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}"); + CRM_Utils_System::redirect($url); } /** @@ -408,18 +411,43 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { } $eventDetails = array(); $eventParams = array('id' => $participant->event_id); - CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails[$participant->event_id]); + CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails); //get default participant role. - $eventDetails[$participant->event_id]['participant_role'] = CRM_Utils_Array::value($eventDetails[$participant->event_id]['default_role_id'], $participantRoles); + $eventDetails['participant_role'] = CRM_Utils_Array::value($eventDetails['default_role_id'], $participantRoles); //get the location info $locParams = array( 'entity_id' => $participant->event_id, 'entity_table' => 'civicrm_event', ); - $eventDetails[$participant->event_id]['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE); - $res = CRM_Event_BAO_Participant::sendTransitionParticipantMail($participant->id, $participantDetails[$participant->id], $eventDetails[$participant->event_id], $contactDetails[$participant->contact_id], $domainValues, "Confirm", TRUE); - //now registered_id can be updated (mail won't be send if it is set - return $res; + $eventDetails['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE); + $toEmail = CRM_Utils_Array::value('email', $contactDetails[$participant->contact_id]); + if ($toEmail) { + //take a receipt from as event else domain. + $receiptFrom = $domainValues['name'] . ' <' . $domainValues['email'] . '>'; + if (!empty($eventDetails['confirm_from_name']) && !empty($eventDetails['confirm_from_email'])) { + $receiptFrom = $eventDetails['confirm_from_name'] . ' <' . $eventDetails['confirm_from_email'] . '>'; + } + $participantName = $contactDetails[$participant->contact_id]['display_name']; + $tplParams = array( + 'event' => $eventDetails, + 'participant' => $participantDetails[$participant->id], + 'participantID' => $participant->id, + 'participant_status' => 'Registered', + ); + + $sendTemplateParams = array( + 'groupName' => 'msg_tpl_workflow_event', + 'valueName' => 'event_online_receipt', + 'contactId' => $participantDetails[$participant->id]['contact_id'], + 'tplParams' => $tplParams, + 'from' => $receiptFrom, + 'toName' => $participantName, + 'toEmail' => $toEmail, + 'cc' => CRM_Utils_Array::value('cc_confirm', $eventDetails), + 'bcc' => CRM_Utils_Array::value('bcc_confirm', $eventDetails), + ); + CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); + } } /** diff --git a/CRM/Event/Form/SelfSvcUpdate.php b/CRM/Event/Form/SelfSvcUpdate.php index e16edfa17a..8caa74edd6 100644 --- a/CRM/Event/Form/SelfSvcUpdate.php +++ b/CRM/Event/Form/SelfSvcUpdate.php @@ -118,6 +118,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $this->_userContext = $session->readUserContext(); $participant = $values = array(); $this->_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST'); + $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST'); $params = array('id' => $this->_participant_id); $this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant); $this->_part_values = $values[$this->_participant_id]; @@ -126,6 +127,10 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $this->_event_id = $this->_part_values['event_id']; $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true"); $this->_contact_id = $this->_part_values['participant_contact_id']; + $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($this->_contact_id, $userChecksum); + if (!$validUser && !CRM_Core_Permission::check('edit all events')) { + CRM_Core_Error::statusBounce(ts('You do not have sufficient permission to transfer/cancel this participant.'), $url); + } $this->assign('action', $this->_action); if ($this->_participant_id) { $this->assign('participantId', $this->_participant_id); @@ -175,8 +180,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $timenow = new Datetime(); if (!empty($start_time) && $start_time < $timenow) { $status = ts("The event has been started, cannot transfer or cancel this event"); - $session->setStatus($status, ts('Oops.'), 'alert'); - CRM_Utils_System::redirect($url); + CRM_Core_Error::statusBounce($status, $url, ts('Oops')); } if (!empty($time_limit) && $time_limit > 0) { $interval = $timenow->diff($start_time); @@ -184,8 +188,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $hours = $interval->format('%h'); if ($hours <= $time_limit && $days < 1) { $status = ts("Less than %1 hours to start time, cannot transfer or cancel this event", array(1 => $time_limit)); - $session->setStatus($status, ts('Oops.'), 'alert'); - CRM_Utils_System::redirect($url); + CRM_Core_Error::statusBounce($status, $url, ts('Oops')); } } $this->assign('details', $details); @@ -210,6 +213,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { 'name' => ts('Submit'), ), )); + $this->addFormRule(array('CRM_Event_Form_SelfSvcUpdate', 'formRule'), $this); parent::buildQuickForm(); } @@ -224,6 +228,24 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { return $this->_defaults; } + /** + * Validate action input + * @param array $fields + * Posted fields of the form. + * @param $files + * @param $self + * + * @return array + * list of errors to be posted back to the form + */ + public static function formRule($fields, $files, $self) { + $errors = array(); + if (empty($fields['action'])) { + $errors['action'] = ts("Please select Transfer OR Cancel action."); + } + return empty($errors) ? TRUE : $errors; + } + /** * Process submit form - based on user selection of action * transfer or cancel the event diff --git a/CRM/Upgrade/4.7.beta1.msg_template/message_templates/event_online_receipt_html.tpl b/CRM/Upgrade/4.7.beta1.msg_template/message_templates/event_online_receipt_html.tpl index 5f13bcc55e..fa1beb268b 100644 --- a/CRM/Upgrade/4.7.beta1.msg_template/message_templates/event_online_receipt_html.tpl +++ b/CRM/Upgrade/4.7.beta1.msg_template/message_templates/event_online_receipt_html.tpl @@ -507,16 +507,16 @@ {/foreach} {/foreach} {/if} - {if $event.allow_selfcancelxfer } - - - {ts 1=$event.selfcancelxfer_time}You may transfer your registration to another participant or cancel your registration up to %1 hours before the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}
- {capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`$participant.id`&{contact.checksum}" h=0 a=1 fe=1}{/capture} - {ts}Click here to transfer or cancel your registration.{/ts} - - - {/if} + {if $event.allow_selfcancelxfer } + + + {ts 1=$event.selfcancelxfer_time}You may transfer your registration to another participant or cancel your registration up to %1 hours before the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}
+ {capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`$participant.id`&{contact.checksum}" h=0 a=1 fe=1}{/capture} + {ts}Click here to transfer or cancel your registration.{/ts} + + + {/if} diff --git a/CRM/Upgrade/4.7.beta1.msg_template/message_templates/event_online_receipt_text.tpl b/CRM/Upgrade/4.7.beta1.msg_template/message_templates/event_online_receipt_text.tpl index 85a6177114..ba5703c2a4 100644 --- a/CRM/Upgrade/4.7.beta1.msg_template/message_templates/event_online_receipt_text.tpl +++ b/CRM/Upgrade/4.7.beta1.msg_template/message_templates/event_online_receipt_text.tpl @@ -303,6 +303,7 @@ You were registered by: {$payer.name} {/foreach} {/foreach} {/if} + {if $event.allow_selfcancelxfer } {ts 1=$event.selfcancelxfer_time}You may transfer your registration to another participant or cancel your registration up to %1 hours before the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if} {capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`$participant.id`&{contact.checksum}" h=0 a=1 fe=1}{/capture} diff --git a/xml/templates/message_templates/event_online_receipt_html.tpl b/xml/templates/message_templates/event_online_receipt_html.tpl index 5f13bcc55e..6c72cad20d 100644 --- a/xml/templates/message_templates/event_online_receipt_html.tpl +++ b/xml/templates/message_templates/event_online_receipt_html.tpl @@ -507,16 +507,16 @@ {/foreach} {/foreach} {/if} - {if $event.allow_selfcancelxfer } - - - {ts 1=$event.selfcancelxfer_time}You may transfer your registration to another participant or cancel your registration up to %1 hours before the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}
- {capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`$participant.id`&{contact.checksum}" h=0 a=1 fe=1}{/capture} - {ts}Click here to transfer or cancel your registration.{/ts} - - - {/if} + {if $event.allow_selfcancelxfer } + + + {ts 1=$event.selfcancelxfer_time}You may transfer your registration to another participant or cancel your registration up to %1 hours before the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if}
+ {capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`$participant.id`&{contact.checksum}" h=0 a=1 fe=1}{/capture} + {ts}Click here to transfer or cancel your registration.{/ts} + + + {/if} diff --git a/xml/templates/message_templates/event_online_receipt_text.tpl b/xml/templates/message_templates/event_online_receipt_text.tpl index 85a6177114..ba5703c2a4 100644 --- a/xml/templates/message_templates/event_online_receipt_text.tpl +++ b/xml/templates/message_templates/event_online_receipt_text.tpl @@ -303,6 +303,7 @@ You were registered by: {$payer.name} {/foreach} {/foreach} {/if} + {if $event.allow_selfcancelxfer } {ts 1=$event.selfcancelxfer_time}You may transfer your registration to another participant or cancel your registration up to %1 hours before the event.{/ts} {if $totalAmount}{ts}Cancellations are not refundable.{/ts}{/if} {capture assign=selfService}{crmURL p='civicrm/event/selfsvcupdate' q="reset=1&pid=`$participant.id`&{contact.checksum}" h=0 a=1 fe=1}{/capture} -- 2.25.1