CRM-15474 - Move js-based form alterations to php
[civicrm-core.git] / CRM / Event / Form / Participant.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 *
31 * @package CRM
06b69b18 32 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
33 * $Id$
34 *
35 */
36
37/**
38 * This class generates form components for processing a participation
39 * in an event
40 */
41class CRM_Event_Form_Participant extends CRM_Contact_Form_Task {
42
96f50de2
CW
43 public $useLivePageJS = TRUE;
44
6a488035
TO
45 /**
46 * the values for the contribution db object
47 *
48 * @var array
49 * @protected
50 */
51 public $_values;
52
53 /**
54 * the values for the quickconfig for priceset
55 *
56 * @var boolean
57 * @protected
58 */
59 public $_quickConfig = NULL;
60
61 /**
62 * Price Set ID, if the new price set method is used
63 *
64 * @var int
65 * @protected
66 */
67 public $_priceSetId;
68
69 /**
70 * Array of fields for the price set
71 *
72 * @var array
73 * @protected
74 */
75 public $_priceSet;
76
77 /**
78 * the id of the participation that we are proceessing
79 *
80 * @var int
81 * @protected
82 */
83 public $_id;
84
85 /**
86 * the id of the note
87 *
88 * @var int
89 * @protected
90 */
91 protected $_noteId = NULL;
92
93 /**
94 * the id of the contact associated with this participation
95 *
96 * @var int
97 * @protected
98 */
99 public $_contactId;
100
101 /**
102 * array of event values
103 *
104 * @var array
105 * @protected
106 */
107 protected $_event;
108
109 /**
110 * Are we operating in "single mode", i.e. adding / editing only
111 * one participant record, or is this a batch add operation
112 *
113 * @var boolean
114 */
115 public $_single = FALSE;
116
117 /**
118 * If event is paid or unpaid
119 */
120 public $_isPaidEvent;
121
122 /**
123 * Page action
124 */
125 public $_action;
126
127 /**
128 * Role Id
129 */
130 protected $_roleId = NULL;
131
132 /**
133 * Event Type Id
134 */
135 protected $_eventTypeId = NULL;
136
137 /**
138 * participant status Id
139 */
140 protected $_statusId = NULL;
141
142 /**
143 * cache all the participant statuses
144 */
145 protected $_participantStatuses;
146
147 /**
148 * participant mode
149 */
150 public $_mode = NULL;
151
152 /**
153 * event ID preselect
154 */
155 public $_eID = NULL;
156
157 /*
158 *Line Item for Price Set
159 */
160
161 public $_lineItem = NULL;
162 /*
163 *Contribution mode for event registration for offline mode
164 */
165
166 public $_contributeMode = 'direct';
167
168 public $_online;
169
170 /**
171 * store id of role custom data type ( option value )
172 */
173 protected $_roleCustomDataTypeID;
174
175 /**
176 * store id of event Name custom data type ( option value)
177 */
178 protected $_eventNameCustomDataTypeID;
179
180 /**
181 * selected discount id
182 */
183 public $_originalDiscountId = NULL;
184
185 /**
186 * event id
187 */
188 public $_eventId = NULL;
189
190 /**
191 * id of payment, if any
192 */
193 public $_paymentId = NULL;
194
9a4df24c
EM
195 /**
196 * @todo add explanatory note about this
197 * @var null
198 */
199 public $_onlinePendingContributionId = NULL;
200
6a488035
TO
201 /**
202 * Function to set variables up before form is built
203 *
204 * @return void
205 * @access public
206 */
207 public function preProcess() {
208 $this->_showFeeBlock = CRM_Utils_Array::value('eventId', $_GET);
209 $this->assign('showFeeBlock', FALSE);
210 $this->assign('feeBlockPaid', FALSE);
211
212 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
213 $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
214 $this->_eID = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
215 $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
216 $this->assign('context', $this->_context);
217
218 if ($this->_contactId) {
219 $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
220 $this->assign('displayName', $displayName);
e2046b33
CW
221 $this->setPageTitle(ts('Event Registration for %1', array(1 => $displayName)));
222 }
223 else {
224 $this->setPageTitle(ts('Event Registration'));
6a488035
TO
225 }
226
227 // check the current path, if search based, then dont get participantID
228 // CRM-5792
229 $path = CRM_Utils_System::currentPath();
0edbaec6
JM
230 if (
231 strpos($path, 'civicrm/contact/search') === 0 ||
232 strpos($path, 'civicrm/group/search') === 0
233 ) {
6a488035
TO
234 $this->_id = NULL;
235 }
236 else {
237 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
238 }
239
240 if ($this->_id) {
29c61b58 241 $this->assign('participantId', $this->_id);
29c61b58 242
6a488035
TO
243 $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
244 $this->_id, 'id', 'participant_id'
245 );
0b2b58ea
PJ
246
247 $this->assign('hasPayment', $this->_paymentId);
248
a4e0d7b5
DG
249 // CRM-12615 - Get payment information from the primary registration
250 if ((!$this->_paymentId) && ($this->_action == CRM_Core_Action::UPDATE)) {
251 $registered_by_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant',
252 $this->_id, 'registered_by_id', 'id'
253 );
254 if ($registered_by_id) {
255 $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
256 $registered_by_id, 'id', 'participant_id'
257 );
258 $this->assign('registeredByParticipantId', $registered_by_id);
259 }
260 }
6a488035
TO
261 }
262
263 // get the option value for custom data type
264 $this->_roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name');
265 $this->_eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name');
266 $this->_eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name');
267 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID);
268 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID);
269 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID);
270
271 if ($this->_mode) {
272 $this->assign('participantMode', $this->_mode);
273
274 $this->_paymentProcessor = array('billing_mode' => 1);
275
276 $validProcessors = array();
277 $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
278
279 foreach ($processors as $ppID => $label) {
280 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
281 if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
282 continue;
283 }
284 elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') {
285 continue;
286 }
287 else {
288 $paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this);
289 $error = $paymentObject->checkConfig();
290 if (empty($error)) {
291 $validProcessors[$ppID] = $label;
292 }
293 $paymentObject = NULL;
294 }
295 }
296 if (empty($validProcessors)) {
297 CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page'));
298 }
299 else {
300 $this->_processors = $validProcessors;
301 }
302 // also check for billing information
303 // get the billing location type
180409a4 304 $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
6a488035
TO
305 // CRM-8108 remove ts around Billing location type
306 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
307 $this->_bltID = array_search('Billing', $locationTypes);
308 if (!$this->_bltID) {
309 CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
310 }
311 $this->set('bltID', $this->_bltID);
312 $this->assign('bltID', $this->_bltID);
313
314 $this->_fields = array();
315
316 CRM_Core_Payment_Form::setCreditCardFields($this);
317
318 // this required to show billing block
319 $this->assign_by_ref('paymentProcessor', $paymentProcessor);
320 $this->assign('hidePayPalExpress', TRUE);
321 }
322
323 if ($this->_showFeeBlock) {
324 $this->assign('showFeeBlock', TRUE);
325 $isMonetary = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock, 'is_monetary');
326 if ($isMonetary) {
327 $this->assign('feeBlockPaid', TRUE);
328 }
329 return CRM_Event_Form_EventFees::preProcess($this);
330 }
331
332 //custom data related code
333 $this->_cdType = CRM_Utils_Array::value('type', $_GET);
334 $this->assign('cdType', FALSE);
335 if ($this->_cdType) {
336 $this->assign('cdType', TRUE);
63dbed83 337 return CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, NULL, NULL, NULL, TRUE);
6a488035
TO
338 }
339
340 //check the mode when this form is called either single or as
341 //search task action
342 if ($this->_id || $this->_contactId || $this->_context == 'standalone') {
343 $this->_single = TRUE;
344 $this->assign('urlPath', 'civicrm/contact/view/participant');
345 if (!$this->_id && !$this->_contactId) {
346 $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'),
347 'url' => CRM_Utils_System::url('civicrm/event', 'reset=1'),
348 ));
349
350 CRM_Utils_System::appendBreadCrumb($breadCrumbs);
351 }
352 }
353 else {
354 //set the appropriate action
355 $context = $this->get('context');
356 $urlString = 'civicrm/contact/search';
357 $this->_action = CRM_Core_Action::BASIC;
358 switch ($context) {
359 case 'advanced':
360 $urlString = 'civicrm/contact/search/advanced';
361 $this->_action = CRM_Core_Action::ADVANCED;
362 break;
363
364 case 'builder':
365 $urlString = 'civicrm/contact/search/builder';
366 $this->_action = CRM_Core_Action::PROFILE;
367 break;
368
369 case 'basic':
370 $urlString = 'civicrm/contact/search/basic';
371 $this->_action = CRM_Core_Action::BASIC;
372 break;
373
374 case 'custom':
375 $urlString = 'civicrm/contact/search/custom';
376 $this->_action = CRM_Core_Action::COPY;
377 break;
378 }
379 parent::preProcess();
380
381 $this->_single = FALSE;
382 $this->_contactId = NULL;
383
384 //set ajax path, this used for custom data building
385 $this->assign('urlPath', $urlString);
386 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
387 }
388
389 $this->assign('single', $this->_single);
390
391 if (!$this->_id) {
392 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
393 }
394 $this->assign('action', $this->_action);
395
396 // check for edit permission
397 if (!CRM_Core_Permission::checkActionPermission('CiviEvent', $this->_action)) {
398 CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
399 }
400
401 if ($this->_action & CRM_Core_Action::DELETE) {
402 // check delete permission for contribution
403 if ($this->_id && $this->_paymentId && !CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
404 CRM_Core_Error::fatal(ts("This Participant is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
405 }
406 return;
407 }
408
409 if ($this->_id) {
410 // assign participant id to the template
411 $this->assign('participantId', $this->_id);
412 $this->_roleId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'role_id');
413 }
414
415 // when fee amount is included in form
8cc574cf 416 if (!empty($_POST['hidden_feeblock']) || !empty($_POST['send_receipt'])) {
6a488035
TO
417 CRM_Event_Form_EventFees::preProcess($this);
418 CRM_Event_Form_EventFees::buildQuickForm($this);
419 CRM_Event_Form_EventFees::setDefaultValues($this);
420 }
421
422 // when custom data is included in this page
a7488080 423 if (!empty($_POST['hidden_custom'])) {
7df021e5 424 // Custom data of type participant role
425 // Note: Some earlier commits imply $_POST['role_id'] could be a comma separated string,
426 // not sure if that ever really happens
a7488080 427 if (!empty($_POST['role_id'])) {
7df021e5 428 foreach ($_POST['role_id'] as $roleID) {
429 CRM_Custom_Form_CustomData::preProcess($this, $this->_roleCustomDataTypeID, $roleID, 1, 'Participant', $this->_id);
6a488035
TO
430 CRM_Custom_Form_CustomData::buildQuickForm($this);
431 CRM_Custom_Form_CustomData::setDefaultValues($this);
432 }
433 }
434
435 //custom data of type participant event
436 CRM_Custom_Form_CustomData::preProcess($this, $this->_eventNameCustomDataTypeID, $_POST['event_id'], 1, 'Participant', $this->_id);
437 CRM_Custom_Form_CustomData::buildQuickForm($this);
438 CRM_Custom_Form_CustomData::setDefaultValues($this);
439
440 // custom data of type participant event type
441 $eventTypeId = NULL;
442 if ($eventId = CRM_Utils_Array::value('event_id', $_POST)) {
443 $eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
444 }
445 CRM_Custom_Form_CustomData::preProcess($this, $this->_eventTypeCustomDataTypeID, $eventTypeId,
446 1, 'Participant', $this->_id
447 );
448 CRM_Custom_Form_CustomData::buildQuickForm($this);
449 CRM_Custom_Form_CustomData::setDefaultValues($this);
450
451 //custom data of type participant, ( we 'null' to reset subType and subName)
452 CRM_Custom_Form_CustomData::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id);
453 CRM_Custom_Form_CustomData::buildQuickForm($this);
454 CRM_Custom_Form_CustomData::setDefaultValues($this);
455 }
456
457 // CRM-4395, get the online pending contribution id.
458 $this->_onlinePendingContributionId = NULL;
459 if (!$this->_mode && $this->_id && ($this->_action & CRM_Core_Action::UPDATE)) {
460 $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id,
461 'Event'
462 );
463 }
464 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId);
6a488035
TO
465 }
466
467 /**
468 * This function sets the default values for the form in edit/view mode
469 * the default values are retrieved from the database
470 *
471 * @access public
472 *
355ba699 473 * @return void
6a488035
TO
474 */
475 public function setDefaultValues() {
476 if ($this->_showFeeBlock) {
477 return CRM_Event_Form_EventFees::setDefaultValues($this);
478 }
479
480 if ($this->_cdType) {
481 return CRM_Custom_Form_CustomData::setDefaultValues($this);
482 }
483
484 $defaults = array();
485
486 if ($this->_action & CRM_Core_Action::DELETE) {
487 return $defaults;
488 }
489
490 if ($this->_id) {
491 $ids = array();
492 $params = array('id' => $this->_id);
493
494 CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
495 $sep = CRM_Core_DAO::VALUE_SEPARATOR;
496 if ($defaults[$this->_id]['role_id']) {
bdc20176 497 $roleIDs = explode($sep, $defaults[$this->_id]['role_id']);
6a488035
TO
498 }
499 $this->_contactId = $defaults[$this->_id]['contact_id'];
500 $this->_statusId = $defaults[$this->_id]['participant_status_id'];
501
502 //set defaults for note
503 $noteDetails = CRM_Core_BAO_Note::getNote($this->_id, 'civicrm_participant');
504 $defaults[$this->_id]['note'] = array_pop($noteDetails);
505
506 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
507 if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
508 $this->assign('additionalParticipants', CRM_Event_BAO_Participant::getAdditionalParticipants($this->_id));
509 }
510
511 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
a7488080 512 if (!empty($defaults[$this->_id]['participant_registered_by_id'])) {
6a488035
TO
513 $registered_by_contact_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant',
514 $defaults[$this->_id]['participant_registered_by_id'],
515 'contact_id', 'id'
516 );
517 $this->assign('participant_registered_by_id', $defaults[$this->_id]['participant_registered_by_id']);
518 $this->assign('registered_by_contact_id', $registered_by_contact_id);
519 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact::displayName($registered_by_contact_id));
520 }
521 }
522
523 if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) {
524 $inactiveNeeded = TRUE;
525 $viewMode = TRUE;
526 }
527 else {
528 $viewMode = FALSE;
529 $inactiveNeeded = FALSE;
530 }
531
532 //setting default register date
533 if ($this->_action == CRM_Core_Action::ADD) {
534 $statuses = array_flip($this->_participantStatuses);
535 $defaults[$this->_id]['status_id'] = CRM_Utils_Array::value(ts('Registered'), $statuses);
a7488080 536 if (!empty($defaults[$this->_id]['event_id'])) {
6a488035
TO
537 $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
538 $defaults[$this->_id]['event_id'],
bdc20176 539 'financial_type_id'
d96cf288 540 );
6a488035 541 if ($contributionTypeId) {
d96cf288 542 $defaults[$this->_id]['financial_type_id'] = $contributionTypeId;
6a488035
TO
543 }
544 }
545
546 if ($this->_mode) {
547 $fields["email-{$this->_bltID}"] = 1;
548 $fields['email-Primary'] = 1;
549
550 if ($this->_contactId) {
551 CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $fields, $defaults);
552 }
553
554 if (empty($defaults["email-{$this->_bltID}"]) &&
555 !empty($defaults['email-Primary'])
556 ) {
557 $defaults[$this->_id]["email-{$this->_bltID}"] = $defaults['email-Primary'];
558 }
559 }
560
561 $submittedRole = $this->getElementValue('role_id');
a7488080 562 if (!empty($submittedRole[0])) {
6a488035
TO
563 $roleID = $submittedRole[0];
564 }
565 $submittedEvent = $this->getElementValue('event_id');
a4e49a48 566 if (!empty($submittedEvent[0])) {
6a488035
TO
567 $eventID = $submittedEvent[0];
568 }
569 }
570 else {
571 $defaults[$this->_id]['record_contribution'] = 0;
572
573 if ($defaults[$this->_id]['participant_is_pay_later']) {
574 $this->assign('participant_is_pay_later', TRUE);
575 }
576
577 $this->assign('participant_status_id', $defaults[$this->_id]['participant_status_id']);
6a488035
TO
578 $eventID = $defaults[$this->_id]['event_id'];
579
580 $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
581
582 $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'discount_id');
583 if ($this->_discountId) {
584 $this->set('discountId', $this->_discountId);
585 }
586 }
587
588 list($defaults[$this->_id]['register_date'],
589 $defaults[$this->_id]['register_date_time']
590 ) = CRM_Utils_Date::setDateDefaults(
591 CRM_Utils_Array::value('register_date', $defaults[$this->_id]), 'activityDateTime'
592 );
593
594 //assign event and role id, this is needed for Custom data building
595 $sep = CRM_Core_DAO::VALUE_SEPARATOR;
a7488080 596 if (!empty($defaults[$this->_id]['participant_role_id'])) {
6a488035
TO
597 $roleIDs = explode($sep, $defaults[$this->_id]['participant_role_id']);
598 }
6a488035
TO
599 if (isset($_POST['event_id'])) {
600 $eventID = $_POST['event_id'];
bdc20176
PJ
601 }
602
603 if($this->_eID) {
604 $eventID = $this->_eID;
605 //@todo - rationalise the $this->_eID with $POST['event_id'], $this->_eid is set when eid=x is in the url
606 $roleID = CRM_Core_DAO::getFieldValue(
607 'CRM_Event_DAO_Event',
608 $this->_eID,
609 'default_role_id'
610 );
611 if(empty($roleIDs)) {
612 $roleIDs = (array) $defaults[$this->_id]['participant_role_id'] = $roleID;
6a488035 613 }
bdc20176
PJ
614 $defaults[$this->_id]['event_id'] = $eventID;
615 }
616 if (!empty($eventID)) {
617 $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
618 }
619 //these should take precedence so we state them last
620 $urlRoleIDS = CRM_Utils_Request::retrieve('roles', 'String');
621 if($urlRoleIDS) {
622 $roleIDs = explode(',', $urlRoleIDS);
623 }
624 if (isset($roleIDs)) {
cd120ea0 625 $defaults[$this->_id]['role_id'] = implode(',', $roleIDs);
6a488035
TO
626 }
627
628 if (isset($eventID)) {
629 $this->assign('eventID', $eventID);
630 $this->set('eventId', $eventID);
631 }
632
633 if (isset($this->_eventTypeId)) {
634 $this->assign('eventTypeID', $this->_eventTypeId);
635 }
636
637 $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_id]));
638 return $defaults[$this->_id];
639 }
640
641 /**
642 * Function to build the form
643 *
355ba699 644 * @return void
6a488035
TO
645 * @access public
646 */
647 public function buildQuickForm() {
e8cf3013
PJ
648 $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
649 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
81f3d017 650 $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
e8cf3013 651
6a488035
TO
652 if ($this->_showFeeBlock) {
653 return CRM_Event_Form_EventFees::buildQuickForm($this);
654 }
655
656 if ($this->_cdType) {
657 return CRM_Custom_Form_CustomData::buildQuickForm($this);
658 }
659
660 //need to assign custom data type to the template
661 $this->assign('customDataType', 'Participant');
662
663 $this->applyFilter('__ALL__', 'trim');
664
665 if ($this->_action & CRM_Core_Action::DELETE) {
666 if ($this->_single) {
667 $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id,
668 NULL,
669 $this->_contactId,
670 FALSE,
671 TRUE
672 )) - 1;
673 if ($additionalParticipant) {
674 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'),
675 2 => ts('Delete only this participant record.'),
676 );
677 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
678 $this->setDefaults(array('delete_participant' => 1));
679 $this->assign('additionalParticipant', $additionalParticipant);
680 }
681 }
682 $this->addButtons(array(
683 array(
684 'type' => 'next',
685 'name' => ts('Delete'),
686 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
687 'isDefault' => TRUE,
688 ),
689 array(
690 'type' => 'cancel',
691 'name' => ts('Cancel'),
692 ),
693 )
694 );
695 return;
696 }
697
698
01bfdd10
CW
699 if ($this->_single && $this->_context == 'standalone') {
700 $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
6a488035 701 }
6a488035 702
1beb268a
CW
703 $eventFieldParams = array(
704 'entity' => 'event',
705 'select' => array('minimumInputLength' => 0),
706 'api' => array(
707 'extra' => array('campaign_id', 'default_role_id', 'event_type_id'),
708 )
709 );
6a488035
TO
710
711 if ($this->_mode) {
1beb268a
CW
712 // exclude events which are not monetary when credit card registration is used
713 $eventFieldParams['api']['params']['is_monetary'] = 1;
6a488035
TO
714 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE);
715 }
716
1beb268a 717 $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
6a488035
TO
718
719 //frozen the field fix for CRM-4171
720 if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) {
721 if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
722 $this->_id, 'contribution_id', 'participant_id'
723 )) {
724 $element->freeze();
725 }
726 }
727
728 //CRM-7362 --add campaigns.
729 $campaignId = NULL;
730 if ($this->_id) {
731 $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id');
732 }
733 if (!$campaignId) {
734 $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
735 if ($eventId) {
736 $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
737 }
738 }
739 CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
740
741 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
742
743 if ($this->_id) {
744 $this->assign('entityID', $this->_id);
745 }
746
cd120ea0 747 $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
6a488035
TO
748
749 // CRM-4395
750 $checkCancelledJs = array('onchange' => "return sendNotification( );");
751 $confirmJS = NULL;
752 if ($this->_onlinePendingContributionId) {
753 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus());
754 $cancelledContributionStatusId = array_search('Cancelled',
755 CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
756 );
757 $checkCancelledJs = array(
758 'onchange' =>
759 "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
760 );
761
762 $participantStatusId = array_search('Pending from pay later',
763 CRM_Event_PseudoConstant::participantStatus()
764 );
765 $contributionStatusId = array_search('Completed',
766 CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
767 );
768 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
769 }
770
453ed6d1
KJ
771 // get the participant status names to build special status array which is used to show notification
772 // checkbox below participant status select
773 $participantStatusName = CRM_Event_PseudoConstant::participantStatus();
774 $notificationStatuses = array(
775 'Cancelled',
776 'Pending from waitlist',
777 'Pending from approval',
778 'Expired',
779 );
780
781 // get the required status and then implode only ids
782 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
783 $this->assign('notificationStatusIds', $notificationStatusIds);
784
f76b27fe 785 $this->_participantStatuses = $statusOptions = CRM_Event_BAO_Participant::buildOptions('status_id', 'create');
f6bae84f 786
f76b27fe
CW
787 // Only show refund status when editing
788 if ($this->_action & CRM_Core_Action::ADD) {
789 $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
790 if ($pendingRefundStatusId) {
791 unset($statusOptions[$pendingRefundStatusId]);
792 }
793 }
794
795 $this->addSelect('status_id', $checkCancelledJs + array('options' => $statusOptions, 'option_url' => 'civicrm/admin/participant_status'), TRUE);
6a488035
TO
796
797 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
798
799 $this->add('text', 'source', ts('Event Source'));
800 $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
801 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
802
803 $buttons[] = array(
804 'type' => 'upload',
805 'name' => ts('Save'),
806 'isDefault' => TRUE,
807 'js' => $confirmJS,
808 );
809
810 $path = CRM_Utils_System::currentPath();
239a5027
PJ
811 $excludeForPaths = array(
812 'civicrm/contact/search',
813 'civicrm/group/search'
814 );
815 if (!in_array($path, $excludeForPaths)) {
6a488035
TO
816 $buttons[] = array(
817 'type' => 'upload',
818 'name' => ts('Save and New'),
819 'subName' => 'new',
820 'js' => $confirmJS,
821 );
822 }
239a5027 823
6a488035
TO
824 $buttons[] = array(
825 'type' => 'cancel',
826 'name' => ts('Cancel'),
827 );
828
829 $this->addButtons($buttons);
830 if ($this->_action == CRM_Core_Action::VIEW) {
831 $this->freeze();
832 }
833 }
834
835 /**
836 * Add local and global form rules
837 *
838 * @access protected
839 *
840 * @return void
841 */
842 function addRules() {
843 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
844 }
845
846 /**
847 * global validation rules for the form
848 *
2a6da8d7
EM
849 * @param $values
850 * @param $files
851 * @param $self
852 *
853 * @internal param array $fields posted values of the form
6a488035
TO
854 *
855 * @return array list of errors to be posted back to the form
856 * @static
857 * @access public
858 */
859 static function formRule($values, $files, $self) {
860 // If $values['_qf_Participant_next'] is Delete or
861 // $values['event_id'] is empty, then return
862 // instead of proceeding further.
863
864 if ((CRM_Utils_Array::value('_qf_Participant_next', $values) == 'Delete') ||
865 (!$values['event_id'])
866 ) {
867 return TRUE;
868 }
869
870 $errorMsg = array();
6a488035 871
a7488080 872 if (!empty($values['payment_processor_id'])) {
6a488035 873 // make sure that credit card number and cvv are valid
7cb3d4f0 874 CRM_Core_Payment_Form::validateCreditCard($values, $errorMsg);
6a488035
TO
875 }
876
a7488080
CW
877 if (!empty($values['record_contribution'])) {
878 if (empty($values['financial_type_id'])) {
d96cf288
DG
879 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
880 }
a7488080 881 if (empty($values['payment_instrument_id'])) {
d96cf288
DG
882 $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.');
883 }
6a488035
TO
884 }
885
886 // validate contribution status for 'Failed'.
8cc574cf 887 if ($self->_onlinePendingContributionId && !empty($values['record_contribution']) &&
6a488035
TO
888 (CRM_Utils_Array::value('contribution_status_id', $values) ==
889 array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))
890 )
891 ) {
892 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
893 }
894
895 // do the amount validations.
896 //skip for update mode since amount is freeze, CRM-6052
8cc574cf 897 if ((!$self->_id && empty($values['total_amount']) &&
6a488035
TO
898 empty($self->_values['line_items'])
899 ) ||
900 ($self->_id && !$self->_paymentId && isset($self->_values['line_items']) && is_array($self->_values['line_items']))
901 ) {
902 if ($priceSetId = CRM_Utils_Array::value('priceSetId', $values)) {
9da8dc8c 903 CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
6a488035
TO
904 }
905 }
4d3f1e42
JM
906 // For single additions - show validation error if the contact has already been registered
907 // for this event with the same role.
908 if($self->_single && ($self->_action & CRM_Core_Action::ADD)) {
909 $contactId = $self->_contactId;
910 $eventId = CRM_Utils_Array::value('event_id', $values);
911 if(!empty($contactId) && !empty($eventId)) {
912 $dupeCheck = new CRM_Event_BAO_Participant;
913 $dupeCheck->contact_id = $contactId;
914 $dupeCheck->event_id = $eventId;
915 $dupeCheck->find(TRUE);
916 if(!empty($dupeCheck->id)) {
917 $errorMsg['event_id'] = ts("This contact has already been assigned to this event.");
918 }
919 }
920 }
6a488035
TO
921 return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg;
922 }
923
924 /**
925 * Function to process the form
926 *
927 * @access public
928 */
929 public function postProcess() {
930 // get the submitted form values.
931 $params = $this->controller->exportValues($this->_name);
932
933 if ($this->_action & CRM_Core_Action::DELETE) {
934 if (CRM_Utils_Array::value('delete_participant', $params) == 2) {
935 $additionalId = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id));
936 $participantLinks = (CRM_Event_BAO_Participant::getAdditionalParticipantUrl($additionalId));
937 }
938 if (CRM_Utils_Array::value('delete_participant', $params) == 1) {
939 $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id);
940 foreach ($additionalIds as $value) {
941 CRM_Event_BAO_Participant::deleteParticipant($value);
942 }
943 }
944 CRM_Event_BAO_Participant::deleteParticipant($this->_id);
945 CRM_Core_Session::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
946 if (!empty($participantLinks)) {
947 $status = ts('The following participants no longer have an event fee recorded. You can edit their registration and record a replacement contribution by clicking the links below:') . '<br>' . $participantLinks;
948 CRM_Core_Session::setStatus($status, ts('Group Payment Deleted'));
949 }
950 return;
951 }
4d3f1e42
JM
952 // When adding a single contact, the formRule prevents you from adding duplicates
953 // (See above in formRule()). When adding more than one contact, the duplicates are
954 // removed automatically and the user receives one notification.
955 if ($this->_action & CRM_Core_Action::ADD) {
aae2f9e6
JM
956 $event_id = $this->_eventId;
957 if(empty($event_id) && !empty($params['event_id'])) {
958 $event_id = $params['event_id'];
959 }
960 if(!$this->_single && !empty($event_id)) {
4d3f1e42
JM
961 $duplicateContacts = 0;
962 while(list($k,$dupeCheckContactId) = each($this->_contactIds)) {
963 // Eliminate contacts that have already been assigned to this event.
964 $dupeCheck = new CRM_Event_BAO_Participant;
965 $dupeCheck->contact_id = $dupeCheckContactId;
aae2f9e6 966 $dupeCheck->event_id = $event_id;
4d3f1e42
JM
967 $dupeCheck->find(TRUE);
968 if(!empty($dupeCheck->id)) {
969 $duplicateContacts++;
970 unset($this->_contactIds[$k]);
971 }
972 }
973 if($duplicateContacts > 0) {
974 $msg = ts(
975 "%1 contacts have already been assigned to this event. They were not added a second time.",
976 array(1 => $duplicateContacts)
977 );
978 CRM_Core_Session::setStatus($msg);
979 }
980 if(count($this->_contactIds) == 0) {
981 CRM_Core_Session::setStatus(ts("No participants were added."));
982 return;
983 }
aef8149f
JM
984 // We have to re-key $this->_contactIds so each contact has the same
985 // key as their corresponding record in the $participants array that
986 // will be created below.
987 $this->_contactIds = array_values($this->_contactIds);
4d3f1e42
JM
988 }
989 }
990
6a488035 991
aac57c29 992 $participantStatus = CRM_Event_PseudoConstant::participantStatus();
6a488035 993 // set the contact, when contact is selected
479696ed
CW
994 if (!empty($params['contact_id'])) {
995 $this->_contactId = $params['contact_id'];
6a488035 996 }
9da8dc8c 997 if ($this->_priceSetId && $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
6a488035
TO
998 $this->_quickConfig = $isQuickConfig;
999 }
1000
1001 if ($this->_id) {
1002 $params['id'] = $this->_id;
1003 }
1004
1005 $config = CRM_Core_Config::singleton();
1006 if ($this->_isPaidEvent) {
1007
1008 $contributionParams = array();
1009 $lineItem = array();
1010 $additionalParticipantDetails = array();
1011 if (($this->_id && $this->_action & CRM_Core_Action::UPDATE) && $this->_paymentId) {
1012 $participantBAO = new CRM_Event_BAO_Participant();
1013 $participantBAO->id = $this->_id;
1014 $participantBAO->find(TRUE);
1015 $contributionParams['total_amount'] = $participantBAO->fee_amount;
1016
1017 $params['discount_id'] = NULL;
1018 //re-enter the values for UPDATE mode
1019 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level;
1020 $params['fee_amount'] = $participantBAO->fee_amount;
1021 if (isset($params['priceSetId'])) {
1022 $lineItem[0] = CRM_Price_BAO_LineItem::getLineItems($this->_id);
1023 }
1024 //also add additional participant's fee level/priceset
1025 if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
1026 $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id);
1027 $hasLineItems = CRM_Utils_Array::value('priceSetId', $params, FALSE);
1028 $additionalParticipantDetails = CRM_Event_BAO_Participant::getFeeDetails($additionalIds,
1029 $hasLineItems
1030 );
1031 }
1032 }
1033 else {
1034
1035 //check if discount is selected
a7488080 1036 if (!empty($params['discount_id'])) {
6a488035
TO
1037 $discountId = $params['discount_id'];
1038 }
1039 else {
1040 $discountId = $params['discount_id'] = 'null';
1041 }
1042
1043 //lets carry currency, CRM-4453
1044 $params['fee_currency'] = $config->defaultCurrency;
9da8dc8c 1045 CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'],
8567d0f8
PN
1046 $params, $lineItem[0]
1047 );
6a488035
TO
1048 //CRM-11529 for quick config backoffice transactions
1049 //when financial_type_id is passed in form, update the
1050 //lineitems with the financial type selected in form
1051 $submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $params);
1052 $isPaymentRecorded = CRM_Utils_Array::value('record_contribution', $params);
1053 if ($isPaymentRecorded && $this->_quickConfig && $submittedFinancialType) {
1054 foreach ($lineItem[0] as &$values) {
1055 $values['financial_type_id'] = $submittedFinancialType;
1056 }
1057 }
1058
1059 $params['fee_level'] = $params['amount_level'];
1060 $contributionParams['total_amount'] = $params['amount'];
f6bae84f 1061 if ($this->_quickConfig && !empty($params['total_amount']) &&
372ad74d 1062 $params['status_id'] != array_search('Partially paid', $participantStatus)) {
6a488035
TO
1063 $params['fee_amount'] = $params['total_amount'];
1064 } else {
1065 //fix for CRM-3086
1066 $params['fee_amount'] = $params['amount'];
1067 }
1068 }
1069
1070 if (isset($params['priceSetId'])) {
1071 if (!empty($lineItem[0])) {
1072 $this->set('lineItem', $lineItem);
1073
1074 $this->_lineItem = $lineItem;
1075 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1076
1077 $participantCount = array();
1078 foreach ($lineItem as $k) {
1079 foreach ($k as $v) {
1080 if (CRM_Utils_Array::value('participant_count', $v) > 0) {
1081 $participantCount[] = $v['participant_count'];
1082 }
1083 }
1084 }
1085 }
1086 if (isset($participantCount)) {
1087 $this->assign('pricesetFieldsCount', $participantCount);
1088 }
1089 $this->assign('lineItem', empty($lineItem[0]) || $this->_quickConfig? FALSE : $lineItem);
1090 }
1091 else {
1092 $this->assign('amount_level', $params['amount_level']);
1093 }
1094 }
1095
1096 $this->_params = $params;
fbc54416
PJ
1097 $amountOwed = NULL;
1098 if (isset($params['amount'])) {
1099 $amountOwed = $params['amount'];
1100 unset($params['amount']);
1101 }
6a488035
TO
1102 $params['register_date'] = CRM_Utils_Date::processDate($params['register_date'], $params['register_date_time']);
1103 $params['receive_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $params));
1104 $params['contact_id'] = $this->_contactId;
1105
1106 // overwrite actual payment amount if entered
a7488080 1107 if (!empty($params['total_amount'])) {
6a488035
TO
1108 $contributionParams['total_amount'] = CRM_Utils_Array::value('total_amount', $params);
1109 }
1110
1111
1112 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1113 $session = CRM_Core_Session::singleton();
1114 $userID = $session->get('userID');
1115 list($userName,
1116 $userEmail
1117 ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
1118
1119 if ($this->_contactId) {
1120 list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_contactId);
1121 }
1122
7df021e5 1123 //modify params according to parameter used in create
1124 //participant method (addParticipant)
1125 $this->_params['participant_status_id'] = $params['status_id'];
1126 $this->_params['participant_role_id'] = is_array($params['role_id']) ? $params['role_id'] : explode(',', $params['role_id']);
1127 $this->_params['participant_register_date'] = $params['register_date'];
1128 $roleIdWithSeparator = implode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_params['participant_role_id']);
1129
6a488035
TO
1130 if ($this->_mode) {
1131 if (!$this->_isPaidEvent) {
1132 CRM_Core_Error::fatal(ts('Selected Event is not Paid Event '));
1133 }
6a488035
TO
1134
1135 $eventTitle =
1136 CRM_Core_DAO::getFieldValue(
1137 'CRM_Event_DAO_Event',
1138 $params['event_id'],
1139 'title'
1140 );
1141
1142 // set source if not set
1143 if (empty($params['source'])) {
03e04002 1144 $this->_params['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
6a488035
TO
1145 }
1146 else {
03e04002 1147 $this->_params['participant_source'] = $params['source'];
6a488035
TO
1148 }
1149 $this->_params['description'] = $this->_params['participant_source'];
1150
1151 $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'],
1152 $this->_mode
1153 );
1154 $now = date('YmdHis');
1155 $fields = array();
1156
1157 // set email for primary location.
1158 $fields['email-Primary'] = 1;
1159 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail;
1160
1161 $params['register_date'] = $now;
1162
1163 // now set the values for the billing location.
1164 foreach ($this->_fields as $name => $dontCare) {
1165 $fields[$name] = 1;
1166 }
1167
1168 // also add location name to the array
1169 $params["address_name-{$this->_bltID}"] =
1170 CRM_Utils_Array::value('billing_first_name', $params) . ' ' .
1171 CRM_Utils_Array::value('billing_middle_name', $params) . ' ' .
1172 CRM_Utils_Array::value('billing_last_name', $params);
1173
1174 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1175 $fields["address_name-{$this->_bltID}"] = 1;
1176 $fields["email-{$this->_bltID}"] = 1;
1177 $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type');
1178
1179 $nameFields = array('first_name', 'middle_name', 'last_name');
1180
1181 foreach ($nameFields as $name) {
1182 $fields[$name] = 1;
1183 if (array_key_exists("billing_$name", $params)) {
1184 $params[$name] = $params["billing_{$name}"];
1185 $params['preserveDBName'] = TRUE;
1186 }
1187 }
1188 $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactId, NULL, NULL, $ctype);
1189 }
1190
e03317f1 1191 if (!empty($this->_params['participant_role_id'])) {
7df021e5 1192 $customFieldsRole = array();
1193 foreach ($this->_params['participant_role_id'] as $roleKey) {
1194 $customFieldsRole = CRM_Utils_Array::crmArrayMerge(CRM_Core_BAO_CustomField::getFields('Participant',
1195 FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID), $customFieldsRole);
6a488035 1196 }
7df021e5 1197 $customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant',
1198 FALSE,
1199 FALSE,
1200 CRM_Utils_Array::value('event_id', $params),
1201 $this->_eventNameCustomDataTypeID
1202 );
1203 $customFieldsEventType = CRM_Core_BAO_CustomField::getFields('Participant',
1204 FALSE,
1205 FALSE,
1206 $this->_eventTypeId,
1207 $this->_eventTypeCustomDataTypeID
1208 );
1209 $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole,
1210 CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1211 );
1212 $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
1213 $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEventType, $customFields);
1214 $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
1215 $customFields,
1216 $this->_id,
1217 'Participant'
1218 );
6a488035
TO
1219 }
1220
1221 //do cleanup line items if participant edit the Event Fee.
1222 if (($this->_lineItem || !isset($params['proceSetId'])) && !$this->_paymentId && $this->_id) {
1223 CRM_Price_BAO_LineItem::deleteLineItems($this->_id, 'civicrm_participant');
1224 }
03e04002 1225
6a488035 1226 if ($this->_mode) {
dc8cdf3a 1227 // add all the additional payment params we need
6a488035
TO
1228 $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
1229 $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
1230
1231 $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
1232 $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
1233 $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
1234 $this->_params['amount'] = $params['fee_amount'];
1235 $this->_params['amount_level'] = $params['amount_level'];
1236 $this->_params['currencyID'] = $config->defaultCurrency;
1237 $this->_params['payment_action'] = 'Sale';
1238 $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
1239
1240 // at this point we've created a contact and stored its address etc
1241 // all the payment processors expect the name and address to be in the
1242 // so we copy stuff over to first_name etc.
1243 $paymentParams = $this->_params;
a7488080 1244 if (!empty($this->_params['send_receipt'])) {
6a488035
TO
1245 $paymentParams['email'] = $this->_contributorEmail;
1246 }
1247 CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
1248
1249 $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
1250
bf2c70af 1251 $result = $payment->doDirectPayment($paymentParams);
6a488035
TO
1252
1253 if (is_a($result, 'CRM_Core_Error')) {
1254 CRM_Core_Error::displaySessionError($result);
1255 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/participant',
1256 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1257 ));
1258 }
1259
1260 if ($result) {
1261 $this->_params = array_merge($this->_params, $result);
1262 }
1263
1264 $this->_params['receive_date'] = $now;
1265
a7488080 1266 if (!empty($this->_params['send_receipt'])) {
6a488035
TO
1267 $this->_params['receipt_date'] = $now;
1268 }
1269 else {
1270 $this->_params['receipt_date'] = NULL;
1271 }
1272
1273 $this->set('params', $this->_params);
1274 $this->assign('trxn_id', $result['trxn_id']);
1275 $this->assign('receive_date',
1276 CRM_Utils_Date::processDate($this->_params['receive_date'])
1277 );
1278
1279 //add contribution record
1280 $this->_params['financial_type_id'] =
1281 CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1282 $this->_params['mode'] = $this->_mode;
1283
1284 //add contribution reocord
1285 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm::processContribution($this, $this->_params, $result, $contactID, FALSE);
1286
1287 // add participant record
1288 $participants = array();
dc8cdf3a
K
1289 if (!empty($this->_params['role_id']) && is_array($this->_params['role_id'])) {
1290 $this->_params['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR,
1291 $this->_params['role_id']
6a488035
TO
1292 );
1293 }
5c320924
C
1294
1295 //CRM-15372 patch to fix fee amount replacing amount
1296 $this->_params['fee_amount'] = $this->_params['amount'];
1297
bf2c70af 1298 $participants[] = CRM_Event_Form_Registration::addParticipant($this, $contactID);
6a488035
TO
1299
1300 //add custom data for participant
1301 CRM_Core_BAO_CustomValueTable::postProcess($this->_params,
1302 CRM_Core_DAO::$_nullArray,
1303 'civicrm_participant',
1304 $participants[0]->id,
1305 'Participant'
1306 );
1307 //add participant payment
1308 $paymentParticipant = array(
1309 'participant_id' => $participants[0]->id,
1310 'contribution_id' => $contribution->id,
1311 );
1312 $ids = array();
1313
1314 CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids);
1315 $this->_contactIds[] = $this->_contactId;
1316 }
1317 else {
1318 $participants = array();
1319 if ($this->_single) {
1320 if ($params['role_id']) {
7df021e5 1321 $params['role_id'] = $roleIdWithSeparator;
6a488035
TO
1322 }
1323 else {
1324 $params['role_id'] = 'NULL';
1325 }
1326 $participants[] = CRM_Event_BAO_Participant::create($params);
1327 }
1328 else {
1329 foreach ($this->_contactIds as $contactID) {
1330 $commonParams = $params;
1331 $commonParams['contact_id'] = $contactID;
1332 if ($commonParams['role_id']) {
dc8cdf3a 1333 $commonParams['role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['role_id']);
6a488035
TO
1334 }
1335 else {
1336 $commonParams['role_id'] = 'NULL';
1337 }
1338 $participants[] = CRM_Event_BAO_Participant::create($commonParams);
1339 }
1340 }
1341
1342 if (isset($params['event_id'])) {
1343 $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
1344 $params['event_id'],
1345 'title'
1346 );
1347 }
1348
1349 if ($this->_single) {
1350 $this->_contactIds[] = $this->_contactId;
1351 }
1352
1353 $contributions = array();
a7488080
CW
1354 if (!empty($params['record_contribution'])) {
1355 if (!empty($params['id'])) {
6a488035
TO
1356 if ($this->_onlinePendingContributionId) {
1357 $ids['contribution'] = $this->_onlinePendingContributionId;
1358 }
1359 else {
1360 $ids['contribution'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1361 $params['id'],
1362 'contribution_id',
1363 'participant_id'
1364 );
1365 }
1366 }
1367 unset($params['note']);
1368
1369 //build contribution params
1370 if (!$this->_onlinePendingContributionId) {
1371 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
1372 }
1373
1374 $contributionParams['currency'] = $config->defaultCurrency;
1375 $contributionParams['non_deductible_amount'] = 'null';
0d8afee2 1376 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array::value('receive_date', $params) : 'null';
6a488035
TO
1377
1378 $recordContribution = array( 'contact_id', 'financial_type_id',
1379 'payment_instrument_id', 'trxn_id',
1380 'contribution_status_id', 'receive_date',
1381 'check_number', 'campaign_id',
1382 );
1383
1384 foreach ($recordContribution as $f) {
1385 $contributionParams[$f] = CRM_Utils_Array::value($f, $params);
1386 if ($f == 'trxn_id') {
1387 $this->assign('trxn_id', $contributionParams[$f]);
1388 }
1389 }
1390
1391 //insert financial type name in receipt.
1392 $this->assign('contributionTypeName', CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1393 $contributionParams['skipLineItem'] = 1;
7030a002
PN
1394 if ($this->_id) {
1395 $contributionParams['contribution_mode'] = 'participant';
1396 $contributionParams['participant_id'] = $this->_id;
1397 }
6a488035
TO
1398 // Set is_pay_later flag for back-office offline Pending status contributions
1399 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Pending', 'name')) {
1400 $contributionParams['is_pay_later'] = 1;
1401 }
d6dce594 1402 elseif ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name')) {
1403 $contributionParams['is_pay_later'] = 0;
1404 }
f8325309 1405
aac57c29 1406 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
5e494d5c
PJ
1407 if (!$amountOwed && $this->_action & CRM_Core_Action::UPDATE) {
1408 $amountOwed = $params['fee_amount'];
1409 }
1410
356579e9 1411 // if multiple participants are link, consider contribution total amount as the amount Owed
ea707c1b 1412 if ($this->_id && CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
356579e9
PJ
1413 $amountOwed = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution',
1414 $ids['contribution'],
1415 'total_amount'
1416 );
1417 }
1418
aac57c29
PJ
1419 // CRM-13964 partial_payment_total
1420 if ($amountOwed > $params['total_amount']) {
1421 // the owed amount
1422 $contributionParams['partial_payment_total'] = $amountOwed;
1423 // the actual amount paid
1424 $contributionParams['partial_amount_pay'] = $params['total_amount'];
1425 }
f8325309 1426 }
372ad74d 1427
6a488035 1428 if ($this->_single) {
dbd48d4e 1429 if (empty($ids)) {
1430 $ids = array();
1431 }
6a488035
TO
1432 $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
1433 }
1434 else {
1435 $ids = array();
1436 foreach ($this->_contactIds as $contactID) {
1437 $contributionParams['contact_id'] = $contactID;
1438 $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
1439 }
1440 }
1441
1442 //insert payment record for this participation
dbd48d4e 1443 if (empty($ids['contribution'])) {
6a488035
TO
1444 foreach ($this->_contactIds as $num => $contactID) {
1445 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1446 $ppDAO->participant_id = $participants[$num]->id;
1447 $ppDAO->contribution_id = $contributions[$num]->id;
1448 $ppDAO->save();
1449 }
1450 }
1451 // next create the transaction record
1452 $transaction = new CRM_Core_Transaction();
1453
1454 // CRM-11124
1455 if ($this->_quickConfig) {
a7488080 1456 if (!empty($this->_params['amount_priceset_level_radio'])) {
7030a002
PN
1457 $feeLevel = $this->_params['amount_priceset_level_radio'];
1458 }
1459 else {
1460 $feeLevel[] = $this->_params['fee_level'] ;
1461 }
1462 CRM_Event_BAO_Participant::createDiscountTrxn($this->_eventId, $contributionParams, $feeLevel);
6a488035
TO
1463 }
1464 $transaction->commit();
1465 }
1466 }
1467
1468 // also store lineitem stuff here
1469 if ((($this->_lineItem & $this->_action & CRM_Core_Action::ADD) ||
1470 ($this->_lineItem && CRM_Core_Action::UPDATE && !$this->_paymentId))
1471 ) {
1472 foreach ($this->_contactIds as $num => $contactID) {
1473 foreach ($this->_lineItem as $key => $value) {
1474 if (is_array($value) && $value != 'skip') {
1475 foreach ($value as $lineKey => $line) {
aac57c29 1476 //10117 update the line items for participants if contribution amount is recorded
f6bae84f 1477 if ($this->_quickConfig && !empty($params['total_amount']) &&
372ad74d 1478 ($params['status_id'] != array_search('Partially paid', $participantStatus))
aac57c29
PJ
1479 ) {
1480 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1481 }
6a488035
TO
1482 $lineItem[$this->_priceSetId][$lineKey] = $line;
1483 }
1484 CRM_Price_BAO_LineItem::processPriceSet($participants[$num]->id, $lineItem, CRM_Utils_Array::value($num, $contributions, NULL), 'civicrm_participant');
1485 }
1486 }
1487 }
1488 }
1489
1490 $updateStatusMsg = NULL;
1491 //send mail when participant status changed, CRM-4326
1492 if ($this->_id && $this->_statusId &&
8cc574cf 1493 $this->_statusId != CRM_Utils_Array::value('status_id', $params) && !empty($params['is_notify'])) {
6a488035
TO
1494
1495 $updateStatusMsg = CRM_Event_BAO_Participant::updateStatusMessage($this->_id,
1496 $params['status_id'],
1497 $this->_statusId
1498 );
1499 }
1500
1501 $sent = array();
1502 $notSent = array();
a7488080 1503 if (!empty($params['send_receipt'])) {
6a488035
TO
1504 if (array_key_exists($params['from_email_address'], $this->_fromEmails['from_email_id'])) {
1505 $receiptFrom = $params['from_email_address'];
1506 }
1507
1508 $this->assign('module', 'Event Registration');
1509 //use of the message template below requires variables in different format
1510 $event = $events = array();
1511 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1512
1513 //get all event details.
1514 CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1515 $event = $events[$params['event_id']];
1516 unset($event['start_date']);
1517 unset($event['end_date']);
1518
1519 $role = CRM_Event_PseudoConstant::participantRole();
1520 $participantRoles = CRM_Utils_Array::value('role_id', $params);
1521 if (is_array($participantRoles)) {
1522 $selectedRoles = array();
c7101803 1523 foreach ($participantRoles as $roleId) {
6a488035
TO
1524 $selectedRoles[] = $role[$roleId];
1525 }
1526 $event['participant_role'] = implode(', ', $selectedRoles);
1527 }
1528 else {
1529 $event['participant_role'] = CRM_Utils_Array::value($participantRoles, $role);
1530 }
1531 $event['is_monetary'] = $this->_isPaidEvent;
1532
1533 if ($params['receipt_text']) {
1534 $event['confirm_email_text'] = $params['receipt_text'];
1535 }
1536
1537 $this->assign('isAmountzero', 1);
1538 $this->assign('event', $event);
1539
1540 $this->assign('isShowLocation', $event['is_show_location']);
1541 if (CRM_Utils_Array::value('is_show_location', $event) == 1) {
1542 $locationParams = array(
1543 'entity_id' => $params['event_id'],
1544 'entity_table' => 'civicrm_event',
1545 );
1546 $location = CRM_Core_BAO_Location::getValues($locationParams, TRUE);
1547 $this->assign('location', $location);
1548 }
1549
1550 $status = CRM_Event_PseudoConstant::participantStatus();
1551 if ($this->_isPaidEvent) {
1552 $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
1553 if (!$this->_mode) {
1554 if (isset($params['payment_instrument_id'])) {
1555 $this->assign('paidBy',
1556 CRM_Utils_Array::value($params['payment_instrument_id'],
1557 $paymentInstrument
1558 )
1559 );
1560 }
1561 }
1562
1563 $this->assign('totalAmount', $contributionParams['total_amount']);
81f3d017
PJ
1564 if (isset($contributionParams['partial_payment_total'])) {
1565 // balance amount
1566 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_pay'];
1567 $this->assign('balanceAmount', $balanceAmount );
1568 }
6a488035
TO
1569 $this->assign('isPrimary', 1);
1570 $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
1571 }
1572 if ($this->_mode) {
a7488080 1573 if (!empty($params['billing_first_name'])) {
6a488035
TO
1574 $name = $params['billing_first_name'];
1575 }
1576
a7488080 1577 if (!empty($params['billing_middle_name'])) {
6a488035
TO
1578 $name .= " {$params['billing_middle_name']}";
1579 }
1580
a7488080 1581 if (!empty($params['billing_last_name'])) {
6a488035
TO
1582 $name .= " {$params['billing_last_name']}";
1583 }
1584 $this->assign('billingName', $name);
1585
1586 // assign the address formatted up for display
1587 $addressParts = array(
1588 "street_address-{$this->_bltID}",
1589 "city-{$this->_bltID}",
1590 "postal_code-{$this->_bltID}",
1591 "state_province-{$this->_bltID}",
1592 "country-{$this->_bltID}",
1593 );
1594 $addressFields = array();
1595 foreach ($addressParts as $part) {
1596 list($n, $id) = explode('-', $part);
1597 if (isset($this->_params['billing_' . $part])) {
1598 $addressFields[$n] = $this->_params['billing_' . $part];
1599 }
1600 }
1601 $this->assign('address', CRM_Utils_Address::format($addressFields));
1602
1603 $date = CRM_Utils_Date::format($params['credit_card_exp_date']);
1604 $date = CRM_Utils_Date::mysqlToIso($date);
1605 $this->assign('credit_card_exp_date', $date);
1606 $this->assign('credit_card_number',
1607 CRM_Utils_System::mungeCreditCard($params['credit_card_number'])
1608 );
1609 $this->assign('credit_card_type', $params['credit_card_type']);
1610 $this->assign('contributeMode', 'direct');
1611 $this->assign('isAmountzero', 0);
1612 $this->assign('is_pay_later', 0);
1613 $this->assign('isPrimary', 1);
1614 }
1615
1616 $this->assign('register_date', $params['register_date']);
1617 if ($params['receive_date']) {
1618 $this->assign('receive_date', $params['receive_date']);
1619 }
1620
1621 $participant = array(array('participant_id', '=', $participants[0]->id, 0, 0));
1622 // check whether its a test drive ref CRM-3075
a7488080 1623 if (!empty($this->_defaultValues['is_test'])) {
6a488035
TO
1624 $participant[] = array('participant_test', '=', 1, 0, 0);
1625 }
1626
1627 $template = CRM_Core_Smarty::singleton();
1628 $customGroup = array();
1629 //format submitted data
1630 foreach ($params['custom'] as $fieldID => $values) {
1631 foreach ($values as $fieldValue) {
1632 $customValue = array('data' => $fieldValue['value']);
1633 $customFields[$fieldID]['id'] = $fieldID;
1634 $formattedValue = CRM_Core_BAO_CustomGroup::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
1635 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace('&nbsp;', '', $formattedValue);
1636 }
1637 }
1638
1639 foreach ($this->_contactIds as $num => $contactID) {
1640 // Retrieve the name and email of the contact - this will be the TO for receipt email
1641 list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($contactID);
1642
1643 $this->_contributorDisplayName = ($this->_contributorDisplayName == ' ') ? $this->_contributorEmail : $this->_contributorDisplayName;
1644
1645 $waitStatus = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
1646 if ($waitingStatus = CRM_Utils_Array::value($params['status_id'], $waitStatus)) {
1647 $this->assign('isOnWaitlist', TRUE);
1648 }
1649
1650 $this->assign('customGroup', $customGroup);
1651 $this->assign('contactID', $contactID);
1652 $this->assign('participantID', $participants[$num]->id);
1653
1654 $this->_id = $participants[$num]->id;
1655
1656 if ($this->_isPaidEvent) {
1657 // fix amount for each of participants ( for bulk mode )
1658 $eventAmount = array();
1659 if (!empty($additionalParticipantDetails)) {
1660 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName;
1661 }
1662
1663 $eventAmount[$num] = array(
1664 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1665 'amount' => $params['fee_amount'],
1666 );
1667 //as we are using same template for online & offline registration.
1668 //So we have to build amount as array.
1669 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1670 $this->assign('amount', $eventAmount);
1671 }
1672
1673 $sendTemplateParams = array(
1674 'groupName' => 'msg_tpl_workflow_event',
1675 'valueName' => 'event_offline_receipt',
1676 'contactId' => $contactID,
1677 'isTest' => (bool) CRM_Utils_Array::value('is_test', $this->_defaultValues),
99deba35 1678 'PDFFilename' => ts('confirmation').'.pdf',
6a488035
TO
1679 );
1680
1681 // try to send emails only if email id is present
1682 // and the do-not-email option is not checked for that contact
1683 if ($this->_contributorEmail and !$this->_toDoNotEmail) {
1684 $sendTemplateParams['from'] = $receiptFrom;
1685 $sendTemplateParams['toName'] = $this->_contributorDisplayName;
1686 $sendTemplateParams['toEmail'] = $this->_contributorEmail;
1687 $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc', $this->_fromEmails);
1688 $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc', $this->_fromEmails);
1689 }
1690
c6327d7d 1691 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
6a488035
TO
1692 if ($mailSent) {
1693 $sent[] = $contactID;
1694 foreach ($participants as $ids => $values) {
1695 if ($values->contact_id == $contactID) {
641f812f 1696 $values->details = CRM_Utils_Array::value('receipt_text', $params);
6a488035
TO
1697 CRM_Activity_BAO_Activity::addActivity($values, 'Email');
1698 break;
1699 }
1700 }
1701 }
1702 else {
1703 $notSent[] = $contactID;
1704 }
1705 }
1706 }
1707
1708 // set the participant id if it is not set
1709 if (!$this->_id) {
1710 $this->_id = $participants[0]->id;
1711 }
1712
1713 if (($this->_action & CRM_Core_Action::UPDATE)) {
1714 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName));
a7488080 1715 if (!empty($params['send_receipt']) && count($sent)) {
6a488035
TO
1716 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail));
1717 }
1718
1719 if ($updateStatusMsg) {
1720 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1721 }
1722 }
1723 elseif ($this->_action & CRM_Core_Action::ADD) {
1724 if ($this->_single) {
1725 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName));
a7488080 1726 if (!empty($params['send_receipt']) && count($sent)) {
6a488035
TO
1727 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail));
1728 }
1729 }
1730 else {
1731 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds)));
1732 if (count($notSent) > 0) {
1733 $statusMsg .= ' ' . ts('Email has NOT been sent to %1 contact(s) - communication preferences specify DO NOT EMAIL OR valid Email is NOT present. ', array(1 => count($notSent)));
1734 }
1735 elseif (isset($params['send_receipt'])) {
1736 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1737 }
1738 }
1739 }
1740 CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
1741
1742 $buttonName = $this->controller->getButtonName();
1743 if ($this->_context == 'standalone') {
1744 if ($buttonName == $this->getButtonName('upload', 'new')) {
1745 $urlParams = 'reset=1&action=add&context=standalone';
1746 if ($this->_mode) {
1747 $urlParams .= '&mode=' . $this->_mode;
1748 }
1749 if ($this->_eID) {
1750 $urlParams .= '&eid=' . $this->_eID;
1751 }
1752 $session->replaceUserContext(CRM_Utils_System::url('civicrm/participant/add', $urlParams));
1753 }
1754 else {
1755 $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view',
1756 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1757 ));
1758 }
1759 }
1760 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1761 $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/participant',
1762 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"
1763 ));
1764 }
1765 }
1766}