3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
37 * This class generates form components to allow an Event to be cancelled or transferred from an email link
40 class CRM_Event_Form_SelfSvcUpdate
extends CRM_Core_Form
{
47 protected $_participant_id;
54 protected $_contact_id;
56 * name of the particpant
61 protected $_contact_name;
63 * email of participant
67 protected $_contact_email;
69 * event to be cancelled/transferred
79 protected $_event_title;
85 protected $_event_start_date;
97 protected $_participant = array();
103 protected $_part_values;
105 * details of event registration values
109 protected $_details = array();
111 * Is backoffice form?
115 protected $isBackoffice = FALSE;
117 * Set variables up before form is built based on participant ID from URL
121 public function preProcess() {
122 $config = CRM_Core_Config
::singleton();
123 $session = CRM_Core_Session
::singleton();
124 $this->_userContext
= $session->readUserContext();
125 $participant = $values = array();
126 $this->_participant_id
= CRM_Utils_Request
::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST');
127 $this->_userChecksum
= CRM_Utils_Request
::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST');
128 $this->isBackoffice
= CRM_Utils_Request
::retrieve('is_backoffice', 'String', $this, FALSE, NULL, 'REQUEST');
129 $params = array('id' => $this->_participant_id
);
130 $this->_participant
= CRM_Event_BAO_Participant
::getValues($params, $values, $participant);
131 $this->_part_values
= $values[$this->_participant_id
];
132 $this->set('values', $this->_part_values
);
133 //fetch Event by event_id, verify that this event can still be xferred/cancelled
134 $this->_event_id
= $this->_part_values
['event_id'];
135 $url = CRM_Utils_System
::url('civicrm/event/info', "reset=1&id={$this->_event_id}");
136 $this->_contact_id
= $this->_part_values
['participant_contact_id'];
137 $validUser = CRM_Contact_BAO_Contact_Utils
::validChecksum($this->_contact_id
, $this->_userChecksum
);
138 if (!$validUser && !CRM_Core_Permission
::check('edit all events')) {
139 CRM_Core_Error
::statusBounce(ts('You do not have sufficient permission to transfer/cancel this participant.'), $url);
141 $this->assign('action', $this->_action
);
142 if ($this->_participant_id
) {
143 $this->assign('participantId', $this->_participant_id
);
147 $this->_event_title
= CRM_Event_BAO_Event
::getFieldValue('CRM_Event_DAO_Event', $this->_event_id
, $daoName);
148 $daoName = 'start_date';
149 $this->_event_start_date
= CRM_Event_BAO_Event
::getFieldValue('CRM_Event_DAO_Event', $this->_event_id
, $daoName);
150 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contact_id
);
151 $this->_contact_name
= $displayName;
152 $this->_contact_email
= $email;
154 $details = CRM_Event_BAO_Participant
::participantDetails($this->_participant_id
);
155 $optionGroupId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name');
156 $contributionId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participant_id
, 'contribution_id', 'participant_id');
157 $this->assign('contributionId', $contributionId);
159 SELECT cpst.name as status, cov.name as role, cp.fee_level, cp.fee_amount, cp.register_date, cp.status_id, civicrm_event.start_date
160 FROM civicrm_participant cp
161 LEFT JOIN civicrm_participant_status_type cpst ON cpst.id = cp.status_id
162 LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = {$optionGroupId}
163 LEFT JOIN civicrm_event ON civicrm_event.id = cp.event_id
164 WHERE cp.id = {$this->_participant_id}";
165 $dao = CRM_Core_DAO
::executeQuery($query);
166 while ($dao->fetch()) {
167 $details['status'] = $dao->status
;
168 $details['role'] = $dao->role
;
169 $details['fee_level'] = trim($dao->fee_level
, CRM_Core_DAO
::VALUE_SEPARATOR
);
170 $details['fee_amount'] = $dao->fee_amount
;
171 $details['register_date'] = $dao->register_date
;
172 $details['event_start_date'] = $dao->start_date
;
174 //verify participant status is still Registered
175 if ($details['status'] != "Registered") {
176 $status = "You cannot transfer or cancel your registration for " . $this->_event_title
. ' as you are not currently registered for this event.';
177 CRM_Core_Session
::setStatus($status, ts('Sorry'), 'alert');
178 CRM_Utils_System
::redirect($url);
180 $query = "select start_date as start, selfcancelxfer_time as time from civicrm_event where id = " . $this->_event_id
;
181 $dao = CRM_Core_DAO
::executeQuery($query);
182 while ($dao->fetch()) {
183 $time_limit = $dao->time
;
184 $start_date = $dao->start
;
186 $start_time = new Datetime($start_date);
187 $timenow = new Datetime();
188 if (!$this->isBackoffice
&& !empty($start_time) && $start_time < $timenow) {
189 $status = ts("Registration for this event cannot be cancelled or transferred once the event has begun. Contact the event organizer if you have questions.");
190 CRM_Core_Error
::statusBounce($status, $url, ts('Sorry'));
192 if (!$this->isBackoffice
&& !empty($time_limit) && $time_limit > 0) {
193 $interval = $timenow->diff($start_time);
194 $days = $interval->format('%d');
195 $hours = $interval->format('%h');
196 if ($hours <= $time_limit && $days < 1) {
197 $status = ts("Registration for this event cannot be cancelled or transferred less than %1 hours prior to the event's start time. Contact the event organizer if you have questions.", array(1 => $time_limit));
198 CRM_Core_Error
::statusBounce($status, $url, ts('Sorry'));
201 $this->assign('details', $details);
202 $this->selfsvcupdateUrl
= CRM_Utils_System
::url('civicrm/event/selfsvcupdate', "reset=1&id={$this->_participant_id}&id=0");
203 $this->selfsvcupdateText
= ts('Update');
204 $this->selfsvcupdateButtonText
= ts('Update');
205 // Based on those ids retrieve event and verify it is eligible
206 // for self update (event.start_date > today, event can be 'self_updated'
207 // retrieve contact name and email, and let user verify his/her identity
210 * buildQuickForm -populate input variables for source Event
211 * to cancel or transfer to another person
215 public function buildQuickForm() {
216 $this->add('select', 'action', ts('Transfer or Cancel Registration'), array(ts('-select-'), ts('Transfer'), ts('Cancel')), TRUE);
217 $this->addButtons(array(
220 'name' => ts('Submit'),
223 $this->addFormRule(array('CRM_Event_Form_SelfSvcUpdate', 'formRule'), $this);
224 parent
::buildQuickForm();
228 * Set default values for contact
232 public function setDefaultValues() {
233 $this->_defaults
= array();
234 $this->_defaults
['details'] = $this->_details
;
235 return $this->_defaults
;
239 * Validate action input
240 * @param array $fields
241 * Posted fields of the form.
246 * list of errors to be posted back to the form
248 public static function formRule($fields, $files, $self) {
250 if (empty($fields['action'])) {
251 $errors['action'] = ts("Please select Transfer OR Cancel action.");
253 return empty($errors) ?
TRUE : $errors;
257 * Process submit form - based on user selection of action
258 * transfer or cancel the event
262 public function postProcess() {
263 //if selection is cancel, cancel this participant' registration, process refund
264 //if transfer, process form to allow selection of transferree
265 $params = $this->controller
->exportValues($this->_name
);
266 $action = $params['action'];
267 if ($action == "1") {
268 $action = "Transfer Event";
269 $this->transferParticipant($params);
271 elseif ($action == "2") {
272 $action = "Cancel Event";
273 $this->cancelParticipant($params);
278 * Transfer to a new form, allowing selection of a new contact
279 * based on email and name. The Event will be transferred to this new participant
283 public function transferParticipant($params) {
284 $isBackOfficeArg = $this->isBackoffice ?
'&is_backoffice=1' : '';
285 CRM_Utils_System
::redirect(CRM_Utils_System
::url(
286 'civicrm/event/selfsvctransfer',
290 'pid' => $this->_participant_id
,
291 'cs' => $this->_userChecksum
,
297 * Cancel this participant and finish, send cancellation email. At this point no
298 * auto-cancellation of payment is handled, so payment needs to be manually cancelled
302 public function cancelParticipant($params) {
303 //set participant record status to Cancelled, refund payment if possible
304 // send email to participant and admin, and log Activity
306 $value['id'] = $this->_participant_id
;
307 $cancelledId = array_search('Cancelled',
308 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'"));
309 $value['status_id'] = $cancelledId;
310 CRM_Event_BAO_Participant
::create($value);
311 $domainValues = array();
312 $domain = CRM_Core_BAO_Domain
::getDomain();
321 'contact' => CRM_Core_SelectValues
::contactTokens(),
323 foreach ($tokens['domain'] as $token) {
324 $domainValues[$token] = CRM_Utils_Token
::getDomainTokenReplacement($token, $domain);
326 $participantRoles = array();
327 $participantRoles = CRM_Event_PseudoConstant
::participantRole();
328 $participantDetails = array();
329 $query = "SELECT * FROM civicrm_participant WHERE id = {$this->_participant_id}";
330 $dao = CRM_Core_DAO
::executeQuery($query);
331 while ($dao->fetch()) {
332 $participantDetails[$dao->id
] = array(
334 'role' => $participantRoles[$dao->role_id
],
335 'is_test' => $dao->is_test
,
336 'event_id' => $dao->event_id
,
337 'status_id' => $dao->status_id
,
338 'fee_amount' => $dao->fee_amount
,
339 'contact_id' => $dao->contact_id
,
340 'register_date' => $dao->register_date
,
341 'registered_by_id' => $dao->registered_by_id
,
344 $eventDetails = array();
345 $eventParams = array('id' => $this->_event_id
);
346 CRM_Event_BAO_Event
::retrieve($eventParams, $eventDetails[$this->_event_id
]);
347 //get default participant role.
348 $eventDetails[$this->_event_id
]['participant_role'] = CRM_Utils_Array
::value($eventDetails[$this->_event_id
]['default_role_id'], $participantRoles);
349 //get the location info
350 $locParams = array('entity_id' => $this->_event_id
, 'entity_table' => 'civicrm_event');
351 $eventDetails[$this->_event_id
]['location'] = CRM_Core_BAO_Location
::getValues($locParams, TRUE);
352 //get contact details
353 $contactIds[$this->_contact_id
] = $this->_contact_id
;
354 list($currentContactDetails) = CRM_Utils_Token
::getTokenDetails($contactIds, NULL,
355 FALSE, FALSE, NULL, array(),
356 'CRM_Event_BAO_Participant'
358 foreach ($currentContactDetails as $contactId => $contactValues) {
359 $contactDetails[$this->_contact_id
] = $contactValues;
361 //send a 'cancelled' email to user, and cc the event's cc_confirm email
362 $mail = CRM_Event_BAO_Participant
::sendTransitionParticipantMail($this->_participant_id
,
363 $participantDetails[$this->_participant_id
],
364 $eventDetails[$this->_event_id
],
365 $contactDetails[$this->_contact_id
],
370 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contact_name
));
371 $statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', array(1 => $this->_contact_email
));
372 CRM_Core_Session
::setStatus($statusMsg, ts('Thanks'), 'success');
373 if (!empty($this->isBackoffice
)) {
376 $url = CRM_Utils_System
::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true");
377 CRM_Utils_System
::redirect($url);