Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-10-14-11-24-52
[civicrm-core.git] / CRM / Event / Form / Participant.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
32 * @copyright CiviCRM LLC (c) 2004-2014
33 * $Id$
34 *
35 */
36
37 /**
38 * This class generates form components for processing a participation
39 * in an event
40 */
41 class CRM_Event_Form_Participant extends CRM_Contact_Form_Task {
42
43 public $useLivePageJS = TRUE;
44
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
195 /**
196 * @todo add explanatory note about this
197 * @var null
198 */
199 public $_onlinePendingContributionId = NULL;
200
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);
221 $this->setPageTitle(ts('Event Registration for %1', array(1 => $displayName)));
222 }
223 else {
224 $this->setPageTitle(ts('Event Registration'));
225 }
226
227 // check the current path, if search based, then dont get participantID
228 // CRM-5792
229 $path = CRM_Utils_System::currentPath();
230 if (
231 strpos($path, 'civicrm/contact/search') === 0 ||
232 strpos($path, 'civicrm/group/search') === 0
233 ) {
234 $this->_id = NULL;
235 }
236 else {
237 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
238 }
239
240 if ($this->_id) {
241 $this->assign('participantId', $this->_id);
242
243 $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
244 $this->_id, 'id', 'participant_id'
245 );
246
247 $this->assign('hasPayment', $this->_paymentId);
248
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 }
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
304 $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
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);
337 return CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, NULL, NULL, NULL, TRUE);
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
416 if (!empty($_POST['hidden_feeblock']) || !empty($_POST['send_receipt'])) {
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
423 if (!empty($_POST['hidden_custom'])) {
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
427 if (!empty($_POST['role_id'])) {
428 foreach ($_POST['role_id'] as $roleID) {
429 CRM_Custom_Form_CustomData::preProcess($this, $this->_roleCustomDataTypeID, $roleID, 1, 'Participant', $this->_id);
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);
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 *
473 * @return void
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']) {
497 $roleIDs = explode($sep, $defaults[$this->_id]['role_id']);
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)
512 if (!empty($defaults[$this->_id]['participant_registered_by_id'])) {
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);
536 if (!empty($defaults[$this->_id]['event_id'])) {
537 $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
538 $defaults[$this->_id]['event_id'],
539 'financial_type_id'
540 );
541 if ($contributionTypeId) {
542 $defaults[$this->_id]['financial_type_id'] = $contributionTypeId;
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');
562 if (!empty($submittedRole[0])) {
563 $roleID = $submittedRole[0];
564 }
565 $submittedEvent = $this->getElementValue('event_id');
566 if (!empty($submittedEvent[0])) {
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']);
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;
596 if (!empty($defaults[$this->_id]['participant_role_id'])) {
597 $roleIDs = explode($sep, $defaults[$this->_id]['participant_role_id']);
598 }
599 if (isset($_POST['event_id'])) {
600 $eventID = $_POST['event_id'];
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;
613 }
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)) {
625 $defaults[$this->_id]['role_id'] = implode(',', $roleIDs);
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 *
644 * @return void
645 * @access public
646 */
647 public function buildQuickForm() {
648 $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
649 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
650 $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
651
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
699 if ($this->_single && $this->_context == 'standalone') {
700 $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
701 }
702
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 );
710
711 if ($this->_mode) {
712 // exclude events which are not monetary when credit card registration is used
713 $eventFieldParams['api']['params']['is_monetary'] = 1;
714 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE);
715 }
716
717 $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
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
747 $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
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
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
785 $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
786 $this->addSelect('status_id', $checkCancelledJs + array('option_url' => 'civicrm/admin/participant_status'), TRUE);
787
788 $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
789 'enable_cart'
790 );
791 $pendingInCartStatusId = array_search('Pending in cart', $participantStatusName);
792 $this->assign('pendingInCartStatusId', $pendingInCartStatusId);
793 $this->assign('enableCart', $enableCart);
794 $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
795 $this->assign('pendingRefundStatusId', $pendingRefundStatusId);
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();
811 $excludeForPaths = array(
812 'civicrm/contact/search',
813 'civicrm/group/search'
814 );
815 if (!in_array($path, $excludeForPaths)) {
816 $buttons[] = array(
817 'type' => 'upload',
818 'name' => ts('Save and New'),
819 'subName' => 'new',
820 'js' => $confirmJS,
821 );
822 }
823
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 *
849 * @param $values
850 * @param $files
851 * @param $self
852 *
853 * @internal param array $fields posted values of the form
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();
871
872 if (!empty($values['payment_processor_id'])) {
873 // make sure that credit card number and cvv are valid
874 CRM_Core_Payment_Form::validateCreditCard($values, $errorMsg);
875 }
876
877 if (!empty($values['record_contribution'])) {
878 if (empty($values['financial_type_id'])) {
879 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
880 }
881 if (empty($values['payment_instrument_id'])) {
882 $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.');
883 }
884 }
885
886 // validate contribution status for 'Failed'.
887 if ($self->_onlinePendingContributionId && !empty($values['record_contribution']) &&
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
897 if ((!$self->_id && empty($values['total_amount']) &&
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)) {
903 CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
904 }
905 }
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 }
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 }
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) {
956 if(!$this->_single && !empty($this->_eventId)) {
957 $duplicateContacts = 0;
958 while(list($k,$dupeCheckContactId) = each($this->_contactIds)) {
959 // Eliminate contacts that have already been assigned to this event.
960 $dupeCheck = new CRM_Event_BAO_Participant;
961 $dupeCheck->contact_id = $dupeCheckContactId;
962 $dupeCheck->event_id = $this->_eventId;
963 $dupeCheck->find(TRUE);
964 if(!empty($dupeCheck->id)) {
965 $duplicateContacts++;
966 unset($this->_contactIds[$k]);
967 }
968 }
969 if($duplicateContacts > 0) {
970 $msg = ts(
971 "%1 contacts have already been assigned to this event. They were not added a second time.",
972 array(1 => $duplicateContacts)
973 );
974 CRM_Core_Session::setStatus($msg);
975 }
976 if(count($this->_contactIds) == 0) {
977 CRM_Core_Session::setStatus(ts("No participants were added."));
978 return;
979 }
980 // We have to re-key $this->_contactIds so each contact has the same
981 // key as their corresponding record in the $participants array that
982 // will be created below.
983 $this->_contactIds = array_values($this->_contactIds);
984 }
985 }
986
987
988 $participantStatus = CRM_Event_PseudoConstant::participantStatus();
989 // set the contact, when contact is selected
990 if (!empty($params['contact_id'])) {
991 $this->_contactId = $params['contact_id'];
992 }
993 if ($this->_priceSetId && $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
994 $this->_quickConfig = $isQuickConfig;
995 }
996
997 if ($this->_id) {
998 $params['id'] = $this->_id;
999 }
1000
1001 $config = CRM_Core_Config::singleton();
1002 if ($this->_isPaidEvent) {
1003
1004 $contributionParams = array();
1005 $lineItem = array();
1006 $additionalParticipantDetails = array();
1007 if (($this->_id && $this->_action & CRM_Core_Action::UPDATE) && $this->_paymentId) {
1008 $participantBAO = new CRM_Event_BAO_Participant();
1009 $participantBAO->id = $this->_id;
1010 $participantBAO->find(TRUE);
1011 $contributionParams['total_amount'] = $participantBAO->fee_amount;
1012
1013 $params['discount_id'] = NULL;
1014 //re-enter the values for UPDATE mode
1015 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level;
1016 $params['fee_amount'] = $participantBAO->fee_amount;
1017 if (isset($params['priceSetId'])) {
1018 $lineItem[0] = CRM_Price_BAO_LineItem::getLineItems($this->_id);
1019 }
1020 //also add additional participant's fee level/priceset
1021 if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
1022 $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id);
1023 $hasLineItems = CRM_Utils_Array::value('priceSetId', $params, FALSE);
1024 $additionalParticipantDetails = CRM_Event_BAO_Participant::getFeeDetails($additionalIds,
1025 $hasLineItems
1026 );
1027 }
1028 }
1029 else {
1030
1031 //check if discount is selected
1032 if (!empty($params['discount_id'])) {
1033 $discountId = $params['discount_id'];
1034 }
1035 else {
1036 $discountId = $params['discount_id'] = 'null';
1037 }
1038
1039 //lets carry currency, CRM-4453
1040 $params['fee_currency'] = $config->defaultCurrency;
1041 CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'],
1042 $params, $lineItem[0]
1043 );
1044 //CRM-11529 for quick config backoffice transactions
1045 //when financial_type_id is passed in form, update the
1046 //lineitems with the financial type selected in form
1047 $submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $params);
1048 $isPaymentRecorded = CRM_Utils_Array::value('record_contribution', $params);
1049 if ($isPaymentRecorded && $this->_quickConfig && $submittedFinancialType) {
1050 foreach ($lineItem[0] as &$values) {
1051 $values['financial_type_id'] = $submittedFinancialType;
1052 }
1053 }
1054
1055 $params['fee_level'] = $params['amount_level'];
1056 $contributionParams['total_amount'] = $params['amount'];
1057 if ($this->_quickConfig && !empty($params['total_amount']) &&
1058 $params['status_id'] != array_search('Partially paid', $participantStatus)) {
1059 $params['fee_amount'] = $params['total_amount'];
1060 } else {
1061 //fix for CRM-3086
1062 $params['fee_amount'] = $params['amount'];
1063 }
1064 }
1065
1066 if (isset($params['priceSetId'])) {
1067 if (!empty($lineItem[0])) {
1068 $this->set('lineItem', $lineItem);
1069
1070 $this->_lineItem = $lineItem;
1071 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1072
1073 $participantCount = array();
1074 foreach ($lineItem as $k) {
1075 foreach ($k as $v) {
1076 if (CRM_Utils_Array::value('participant_count', $v) > 0) {
1077 $participantCount[] = $v['participant_count'];
1078 }
1079 }
1080 }
1081 }
1082 if (isset($participantCount)) {
1083 $this->assign('pricesetFieldsCount', $participantCount);
1084 }
1085 $this->assign('lineItem', empty($lineItem[0]) || $this->_quickConfig? FALSE : $lineItem);
1086 }
1087 else {
1088 $this->assign('amount_level', $params['amount_level']);
1089 }
1090 }
1091
1092 $this->_params = $params;
1093 $amountOwed = NULL;
1094 if (isset($params['amount'])) {
1095 $amountOwed = $params['amount'];
1096 unset($params['amount']);
1097 }
1098 $params['register_date'] = CRM_Utils_Date::processDate($params['register_date'], $params['register_date_time']);
1099 $params['receive_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $params));
1100 $params['contact_id'] = $this->_contactId;
1101
1102 // overwrite actual payment amount if entered
1103 if (!empty($params['total_amount'])) {
1104 $contributionParams['total_amount'] = CRM_Utils_Array::value('total_amount', $params);
1105 }
1106
1107
1108 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1109 $session = CRM_Core_Session::singleton();
1110 $userID = $session->get('userID');
1111 list($userName,
1112 $userEmail
1113 ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
1114
1115 if ($this->_contactId) {
1116 list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_contactId);
1117 }
1118
1119 //modify params according to parameter used in create
1120 //participant method (addParticipant)
1121 $this->_params['participant_status_id'] = $params['status_id'];
1122 $this->_params['participant_role_id'] = is_array($params['role_id']) ? $params['role_id'] : explode(',', $params['role_id']);
1123 $this->_params['participant_register_date'] = $params['register_date'];
1124 $roleIdWithSeparator = implode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_params['participant_role_id']);
1125
1126 if ($this->_mode) {
1127 if (!$this->_isPaidEvent) {
1128 CRM_Core_Error::fatal(ts('Selected Event is not Paid Event '));
1129 }
1130
1131 $eventTitle =
1132 CRM_Core_DAO::getFieldValue(
1133 'CRM_Event_DAO_Event',
1134 $params['event_id'],
1135 'title'
1136 );
1137
1138 // set source if not set
1139 if (empty($params['source'])) {
1140 $this->_params['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
1141 }
1142 else {
1143 $this->_params['participant_source'] = $params['source'];
1144 }
1145 $this->_params['description'] = $this->_params['participant_source'];
1146
1147 $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'],
1148 $this->_mode
1149 );
1150 $now = date('YmdHis');
1151 $fields = array();
1152
1153 // set email for primary location.
1154 $fields['email-Primary'] = 1;
1155 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail;
1156
1157 $params['register_date'] = $now;
1158
1159 // now set the values for the billing location.
1160 foreach ($this->_fields as $name => $dontCare) {
1161 $fields[$name] = 1;
1162 }
1163
1164 // also add location name to the array
1165 $params["address_name-{$this->_bltID}"] =
1166 CRM_Utils_Array::value('billing_first_name', $params) . ' ' .
1167 CRM_Utils_Array::value('billing_middle_name', $params) . ' ' .
1168 CRM_Utils_Array::value('billing_last_name', $params);
1169
1170 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1171 $fields["address_name-{$this->_bltID}"] = 1;
1172 $fields["email-{$this->_bltID}"] = 1;
1173 $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type');
1174
1175 $nameFields = array('first_name', 'middle_name', 'last_name');
1176
1177 foreach ($nameFields as $name) {
1178 $fields[$name] = 1;
1179 if (array_key_exists("billing_$name", $params)) {
1180 $params[$name] = $params["billing_{$name}"];
1181 $params['preserveDBName'] = TRUE;
1182 }
1183 }
1184 $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactId, NULL, NULL, $ctype);
1185 }
1186
1187 if (!empty($this->_params['participant_role_id'])) {
1188 $customFieldsRole = array();
1189 foreach ($this->_params['participant_role_id'] as $roleKey) {
1190 $customFieldsRole = CRM_Utils_Array::crmArrayMerge(CRM_Core_BAO_CustomField::getFields('Participant',
1191 FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID), $customFieldsRole);
1192 }
1193 $customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant',
1194 FALSE,
1195 FALSE,
1196 CRM_Utils_Array::value('event_id', $params),
1197 $this->_eventNameCustomDataTypeID
1198 );
1199 $customFieldsEventType = CRM_Core_BAO_CustomField::getFields('Participant',
1200 FALSE,
1201 FALSE,
1202 $this->_eventTypeId,
1203 $this->_eventTypeCustomDataTypeID
1204 );
1205 $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole,
1206 CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1207 );
1208 $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
1209 $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEventType, $customFields);
1210 $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
1211 $customFields,
1212 $this->_id,
1213 'Participant'
1214 );
1215 }
1216
1217 //do cleanup line items if participant edit the Event Fee.
1218 if (($this->_lineItem || !isset($params['proceSetId'])) && !$this->_paymentId && $this->_id) {
1219 CRM_Price_BAO_LineItem::deleteLineItems($this->_id, 'civicrm_participant');
1220 }
1221
1222 if ($this->_mode) {
1223 // add all the additional payment params we need
1224 $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}"]);
1225 $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
1226
1227 $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
1228 $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
1229 $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
1230 $this->_params['amount'] = $params['fee_amount'];
1231 $this->_params['amount_level'] = $params['amount_level'];
1232 $this->_params['currencyID'] = $config->defaultCurrency;
1233 $this->_params['payment_action'] = 'Sale';
1234 $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
1235
1236 // at this point we've created a contact and stored its address etc
1237 // all the payment processors expect the name and address to be in the
1238 // so we copy stuff over to first_name etc.
1239 $paymentParams = $this->_params;
1240 if (!empty($this->_params['send_receipt'])) {
1241 $paymentParams['email'] = $this->_contributorEmail;
1242 }
1243 CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
1244
1245 $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
1246
1247 $result = $payment->doDirectPayment($paymentParams);
1248
1249 if (is_a($result, 'CRM_Core_Error')) {
1250 CRM_Core_Error::displaySessionError($result);
1251 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/participant',
1252 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1253 ));
1254 }
1255
1256 if ($result) {
1257 $this->_params = array_merge($this->_params, $result);
1258 }
1259
1260 $this->_params['receive_date'] = $now;
1261
1262 if (!empty($this->_params['send_receipt'])) {
1263 $this->_params['receipt_date'] = $now;
1264 }
1265 else {
1266 $this->_params['receipt_date'] = NULL;
1267 }
1268
1269 $this->set('params', $this->_params);
1270 $this->assign('trxn_id', $result['trxn_id']);
1271 $this->assign('receive_date',
1272 CRM_Utils_Date::processDate($this->_params['receive_date'])
1273 );
1274
1275 //add contribution record
1276 $this->_params['financial_type_id'] =
1277 CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1278 $this->_params['mode'] = $this->_mode;
1279
1280 //add contribution reocord
1281 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm::processContribution($this, $this->_params, $result, $contactID, FALSE);
1282
1283 // add participant record
1284 $participants = array();
1285 if (!empty($this->_params['role_id']) && is_array($this->_params['role_id'])) {
1286 $this->_params['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR,
1287 $this->_params['role_id']
1288 );
1289 }
1290
1291 //CRM-15372 patch to fix fee amount replacing amount
1292 $this->_params['fee_amount'] = $this->_params['amount'];
1293
1294 $participants[] = CRM_Event_Form_Registration::addParticipant($this, $contactID);
1295
1296 //add custom data for participant
1297 CRM_Core_BAO_CustomValueTable::postProcess($this->_params,
1298 CRM_Core_DAO::$_nullArray,
1299 'civicrm_participant',
1300 $participants[0]->id,
1301 'Participant'
1302 );
1303 //add participant payment
1304 $paymentParticipant = array(
1305 'participant_id' => $participants[0]->id,
1306 'contribution_id' => $contribution->id,
1307 );
1308 $ids = array();
1309
1310 CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids);
1311 $this->_contactIds[] = $this->_contactId;
1312 }
1313 else {
1314 $participants = array();
1315 if ($this->_single) {
1316 if ($params['role_id']) {
1317 $params['role_id'] = $roleIdWithSeparator;
1318 }
1319 else {
1320 $params['role_id'] = 'NULL';
1321 }
1322 $participants[] = CRM_Event_BAO_Participant::create($params);
1323 }
1324 else {
1325 foreach ($this->_contactIds as $contactID) {
1326 $commonParams = $params;
1327 $commonParams['contact_id'] = $contactID;
1328 if ($commonParams['role_id']) {
1329 $commonParams['role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['role_id']);
1330 }
1331 else {
1332 $commonParams['role_id'] = 'NULL';
1333 }
1334 $participants[] = CRM_Event_BAO_Participant::create($commonParams);
1335 }
1336 }
1337
1338 if (isset($params['event_id'])) {
1339 $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
1340 $params['event_id'],
1341 'title'
1342 );
1343 }
1344
1345 if ($this->_single) {
1346 $this->_contactIds[] = $this->_contactId;
1347 }
1348
1349 $contributions = array();
1350 if (!empty($params['record_contribution'])) {
1351 if (!empty($params['id'])) {
1352 if ($this->_onlinePendingContributionId) {
1353 $ids['contribution'] = $this->_onlinePendingContributionId;
1354 }
1355 else {
1356 $ids['contribution'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1357 $params['id'],
1358 'contribution_id',
1359 'participant_id'
1360 );
1361 }
1362 }
1363 unset($params['note']);
1364
1365 //build contribution params
1366 if (!$this->_onlinePendingContributionId) {
1367 if (empty($params['source'])) {
1368 $contributionParams['source'] = ts('%1 : Offline registration (by %2)', array(1 => $eventTitle, 2 => $userName));
1369 }
1370 else {
1371 $contributionParams['source'] = $params['source'];
1372 }
1373 }
1374
1375 $contributionParams['currency'] = $config->defaultCurrency;
1376 $contributionParams['non_deductible_amount'] = 'null';
1377 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array::value('receive_date', $params) : 'null';
1378
1379 $recordContribution = array( 'contact_id', 'financial_type_id',
1380 'payment_instrument_id', 'trxn_id',
1381 'contribution_status_id', 'receive_date',
1382 'check_number', 'campaign_id',
1383 );
1384
1385 foreach ($recordContribution as $f) {
1386 $contributionParams[$f] = CRM_Utils_Array::value($f, $params);
1387 if ($f == 'trxn_id') {
1388 $this->assign('trxn_id', $contributionParams[$f]);
1389 }
1390 }
1391
1392 //insert financial type name in receipt.
1393 $this->assign('contributionTypeName', CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1394 $contributionParams['skipLineItem'] = 1;
1395 if ($this->_id) {
1396 $contributionParams['contribution_mode'] = 'participant';
1397 $contributionParams['participant_id'] = $this->_id;
1398 }
1399 // Set is_pay_later flag for back-office offline Pending status contributions
1400 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Pending', 'name')) {
1401 $contributionParams['is_pay_later'] = 1;
1402 }
1403 elseif ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name')) {
1404 $contributionParams['is_pay_later'] = 0;
1405 }
1406
1407 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1408 if (!$amountOwed && $this->_action & CRM_Core_Action::UPDATE) {
1409 $amountOwed = $params['fee_amount'];
1410 }
1411
1412 // if multiple participants are link, consider contribution total amount as the amount Owed
1413 if ($this->_id && CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
1414 $amountOwed = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution',
1415 $ids['contribution'],
1416 'total_amount'
1417 );
1418 }
1419
1420 // CRM-13964 partial_payment_total
1421 if ($amountOwed > $params['total_amount']) {
1422 // the owed amount
1423 $contributionParams['partial_payment_total'] = $amountOwed;
1424 // the actual amount paid
1425 $contributionParams['partial_amount_pay'] = $params['total_amount'];
1426 }
1427 }
1428
1429 if (CRM_Utils_Array::value('tax_amount', $this->_params)) {
1430 $contributionParams['tax_amount'] = $this->_params['tax_amount'];
1431 }
1432
1433 if ($this->_single) {
1434 if (empty($ids)) {
1435 $ids = array();
1436 }
1437 $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
1438 }
1439 else {
1440 $ids = array();
1441 foreach ($this->_contactIds as $contactID) {
1442 $contributionParams['contact_id'] = $contactID;
1443 $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
1444 }
1445 }
1446
1447 //insert payment record for this participation
1448 if (empty($ids['contribution'])) {
1449 foreach ($this->_contactIds as $num => $contactID) {
1450 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1451 $ppDAO->participant_id = $participants[$num]->id;
1452 $ppDAO->contribution_id = $contributions[$num]->id;
1453 $ppDAO->save();
1454 }
1455 }
1456 // next create the transaction record
1457 $transaction = new CRM_Core_Transaction();
1458
1459 // CRM-11124
1460 if ($this->_quickConfig) {
1461 if (!empty($this->_params['amount_priceset_level_radio'])) {
1462 $feeLevel = $this->_params['amount_priceset_level_radio'];
1463 }
1464 else {
1465 $feeLevel[] = $this->_params['fee_level'] ;
1466 }
1467 CRM_Event_BAO_Participant::createDiscountTrxn($this->_eventId, $contributionParams, $feeLevel);
1468 }
1469 $transaction->commit();
1470 }
1471 }
1472
1473 // also store lineitem stuff here
1474 if ((($this->_lineItem & $this->_action & CRM_Core_Action::ADD) ||
1475 ($this->_lineItem && CRM_Core_Action::UPDATE && !$this->_paymentId))
1476 ) {
1477 foreach ($this->_contactIds as $num => $contactID) {
1478 foreach ($this->_lineItem as $key => $value) {
1479 if (is_array($value) && $value != 'skip') {
1480 foreach ($value as $lineKey => $line) {
1481 //10117 update the line items for participants if contribution amount is recorded
1482 if ($this->_quickConfig && !empty($params['total_amount']) &&
1483 ($params['status_id'] != array_search('Partially paid', $participantStatus))
1484 ) {
1485 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1486 if (!empty($params['tax_amount'])) {
1487 $line['unit_price'] = $line['unit_price'] - $params['tax_amount'];
1488 $line['line_total'] = $line['line_total'] - $params['tax_amount'];
1489 }
1490 }
1491 $lineItem[$this->_priceSetId][$lineKey] = $line;
1492 }
1493 CRM_Price_BAO_LineItem::processPriceSet($participants[$num]->id, $lineItem, CRM_Utils_Array::value($num, $contributions, NULL), 'civicrm_participant');
1494 }
1495 }
1496 }
1497 }
1498
1499 $updateStatusMsg = NULL;
1500 //send mail when participant status changed, CRM-4326
1501 if ($this->_id && $this->_statusId &&
1502 $this->_statusId != CRM_Utils_Array::value('status_id', $params) && !empty($params['is_notify'])) {
1503
1504 $updateStatusMsg = CRM_Event_BAO_Participant::updateStatusMessage($this->_id,
1505 $params['status_id'],
1506 $this->_statusId
1507 );
1508 }
1509
1510 $sent = array();
1511 $notSent = array();
1512 if (!empty($params['send_receipt'])) {
1513 if (array_key_exists($params['from_email_address'], $this->_fromEmails['from_email_id'])) {
1514 $receiptFrom = $params['from_email_address'];
1515 }
1516
1517 $this->assign('module', 'Event Registration');
1518 //use of the message template below requires variables in different format
1519 $event = $events = array();
1520 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1521
1522 //get all event details.
1523 CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1524 $event = $events[$params['event_id']];
1525 unset($event['start_date']);
1526 unset($event['end_date']);
1527
1528 $role = CRM_Event_PseudoConstant::participantRole();
1529 $participantRoles = CRM_Utils_Array::value('role_id', $params);
1530 if (is_array($participantRoles)) {
1531 $selectedRoles = array();
1532 foreach ($participantRoles as $roleId) {
1533 $selectedRoles[] = $role[$roleId];
1534 }
1535 $event['participant_role'] = implode(', ', $selectedRoles);
1536 }
1537 else {
1538 $event['participant_role'] = CRM_Utils_Array::value($participantRoles, $role);
1539 }
1540 $event['is_monetary'] = $this->_isPaidEvent;
1541
1542 if ($params['receipt_text']) {
1543 $event['confirm_email_text'] = $params['receipt_text'];
1544 }
1545
1546 $this->assign('isAmountzero', 1);
1547 $this->assign('event', $event);
1548
1549 $this->assign('isShowLocation', $event['is_show_location']);
1550 if (CRM_Utils_Array::value('is_show_location', $event) == 1) {
1551 $locationParams = array(
1552 'entity_id' => $params['event_id'],
1553 'entity_table' => 'civicrm_event',
1554 );
1555 $location = CRM_Core_BAO_Location::getValues($locationParams, TRUE);
1556 $this->assign('location', $location);
1557 }
1558
1559 $status = CRM_Event_PseudoConstant::participantStatus();
1560 if ($this->_isPaidEvent) {
1561 $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
1562 if (!$this->_mode) {
1563 if (isset($params['payment_instrument_id'])) {
1564 $this->assign('paidBy',
1565 CRM_Utils_Array::value($params['payment_instrument_id'],
1566 $paymentInstrument
1567 )
1568 );
1569 }
1570 }
1571
1572 $this->assign('totalAmount', $contributionParams['total_amount']);
1573 if (isset($contributionParams['partial_payment_total'])) {
1574 // balance amount
1575 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_pay'];
1576 $this->assign('balanceAmount', $balanceAmount );
1577 }
1578 $this->assign('isPrimary', 1);
1579 $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
1580 }
1581 if ($this->_mode) {
1582 if (!empty($params['billing_first_name'])) {
1583 $name = $params['billing_first_name'];
1584 }
1585
1586 if (!empty($params['billing_middle_name'])) {
1587 $name .= " {$params['billing_middle_name']}";
1588 }
1589
1590 if (!empty($params['billing_last_name'])) {
1591 $name .= " {$params['billing_last_name']}";
1592 }
1593 $this->assign('billingName', $name);
1594
1595 // assign the address formatted up for display
1596 $addressParts = array(
1597 "street_address-{$this->_bltID}",
1598 "city-{$this->_bltID}",
1599 "postal_code-{$this->_bltID}",
1600 "state_province-{$this->_bltID}",
1601 "country-{$this->_bltID}",
1602 );
1603 $addressFields = array();
1604 foreach ($addressParts as $part) {
1605 list($n, $id) = explode('-', $part);
1606 if (isset($this->_params['billing_' . $part])) {
1607 $addressFields[$n] = $this->_params['billing_' . $part];
1608 }
1609 }
1610 $this->assign('address', CRM_Utils_Address::format($addressFields));
1611
1612 $date = CRM_Utils_Date::format($params['credit_card_exp_date']);
1613 $date = CRM_Utils_Date::mysqlToIso($date);
1614 $this->assign('credit_card_exp_date', $date);
1615 $this->assign('credit_card_number',
1616 CRM_Utils_System::mungeCreditCard($params['credit_card_number'])
1617 );
1618 $this->assign('credit_card_type', $params['credit_card_type']);
1619 $this->assign('contributeMode', 'direct');
1620 $this->assign('isAmountzero', 0);
1621 $this->assign('is_pay_later', 0);
1622 $this->assign('isPrimary', 1);
1623 }
1624
1625 $this->assign('register_date', $params['register_date']);
1626 if ($params['receive_date']) {
1627 $this->assign('receive_date', $params['receive_date']);
1628 }
1629
1630 $participant = array(array('participant_id', '=', $participants[0]->id, 0, 0));
1631 // check whether its a test drive ref CRM-3075
1632 if (!empty($this->_defaultValues['is_test'])) {
1633 $participant[] = array('participant_test', '=', 1, 0, 0);
1634 }
1635
1636 $template = CRM_Core_Smarty::singleton();
1637 $customGroup = array();
1638 //format submitted data
1639 foreach ($params['custom'] as $fieldID => $values) {
1640 foreach ($values as $fieldValue) {
1641 $customValue = array('data' => $fieldValue['value']);
1642 $customFields[$fieldID]['id'] = $fieldID;
1643 $formattedValue = CRM_Core_BAO_CustomGroup::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
1644 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace('&nbsp;', '', $formattedValue);
1645 }
1646 }
1647
1648 foreach ($this->_contactIds as $num => $contactID) {
1649 // Retrieve the name and email of the contact - this will be the TO for receipt email
1650 list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($contactID);
1651
1652 $this->_contributorDisplayName = ($this->_contributorDisplayName == ' ') ? $this->_contributorEmail : $this->_contributorDisplayName;
1653
1654 $waitStatus = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
1655 if ($waitingStatus = CRM_Utils_Array::value($params['status_id'], $waitStatus)) {
1656 $this->assign('isOnWaitlist', TRUE);
1657 }
1658
1659 $this->assign('customGroup', $customGroup);
1660 $this->assign('contactID', $contactID);
1661 $this->assign('participantID', $participants[$num]->id);
1662
1663 $this->_id = $participants[$num]->id;
1664
1665 if ($this->_isPaidEvent) {
1666 // fix amount for each of participants ( for bulk mode )
1667 $eventAmount = array();
1668 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,'contribution_invoice_settings');
1669 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
1670 $totalTaxAmount = 0;
1671
1672 //add dataArray in the receipts in ADD and UPDATE condition
1673 $dataArray = array();
1674 if ($this->_action & CRM_Core_Action::ADD) {
1675 $line = $lineItem[0];
1676 }
1677 elseif ($this->_action & CRM_Core_Action::UPDATE) {
1678 $line = $this->_values['line_items'];
1679 }
1680 if ($invoicing) {
1681 foreach ($line as $key => $value) {
1682 if (isset($value['tax_amount'])) {
1683 $totalTaxAmount += $value['tax_amount'];
1684 if (isset($dataArray[(string) $value['tax_rate']])) {
1685 $dataArray[(string) $value['tax_rate']] = $dataArray[(string) $value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
1686 }
1687 else {
1688 $dataArray[(string) $value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
1689 }
1690 }
1691 }
1692 $this->assign('totalTaxAmount', $totalTaxAmount);
1693 $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings));
1694 $this->assign('dataArray', $dataArray);
1695 }
1696 if (!empty($additionalParticipantDetails)) {
1697 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName;
1698 }
1699
1700 $eventAmount[$num] = array(
1701 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1702 'amount' => $params['fee_amount'],
1703 );
1704 //as we are using same template for online & offline registration.
1705 //So we have to build amount as array.
1706 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1707 $this->assign('amount', $eventAmount);
1708 }
1709
1710 $sendTemplateParams = array(
1711 'groupName' => 'msg_tpl_workflow_event',
1712 'valueName' => 'event_offline_receipt',
1713 'contactId' => $contactID,
1714 'isTest' => (bool) CRM_Utils_Array::value('is_test', $this->_defaultValues),
1715 'PDFFilename' => ts('confirmation').'.pdf',
1716 );
1717
1718 // try to send emails only if email id is present
1719 // and the do-not-email option is not checked for that contact
1720 if ($this->_contributorEmail and !$this->_toDoNotEmail) {
1721 $sendTemplateParams['from'] = $receiptFrom;
1722 $sendTemplateParams['toName'] = $this->_contributorDisplayName;
1723 $sendTemplateParams['toEmail'] = $this->_contributorEmail;
1724 $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc', $this->_fromEmails);
1725 $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc', $this->_fromEmails);
1726 }
1727
1728 //send email with pdf invoice
1729 $template = CRM_Core_Smarty::singleton( );
1730 $taxAmt = $template->get_template_vars('dataArray');
1731 $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1732 $this->_id, 'contribution_id', 'participant_id'
1733 );
1734 $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
1735 $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
1736 if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
1737 $sendTemplateParams['isEmailPdf'] = True;
1738 $sendTemplateParams['contributionId'] = $contributionId;
1739 }
1740 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
1741 if ($mailSent) {
1742 $sent[] = $contactID;
1743 foreach ($participants as $ids => $values) {
1744 if ($values->contact_id == $contactID) {
1745 $values->details = CRM_Utils_Array::value('receipt_text', $params);
1746 CRM_Activity_BAO_Activity::addActivity($values, 'Email');
1747 break;
1748 }
1749 }
1750 }
1751 else {
1752 $notSent[] = $contactID;
1753 }
1754 }
1755 }
1756
1757 // set the participant id if it is not set
1758 if (!$this->_id) {
1759 $this->_id = $participants[0]->id;
1760 }
1761
1762 if (($this->_action & CRM_Core_Action::UPDATE)) {
1763 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName));
1764 if (!empty($params['send_receipt']) && count($sent)) {
1765 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail));
1766 }
1767
1768 if ($updateStatusMsg) {
1769 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1770 }
1771 }
1772 elseif ($this->_action & CRM_Core_Action::ADD) {
1773 if ($this->_single) {
1774 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName));
1775 if (!empty($params['send_receipt']) && count($sent)) {
1776 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail));
1777 }
1778 }
1779 else {
1780 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds)));
1781 if (count($notSent) > 0) {
1782 $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)));
1783 }
1784 elseif (isset($params['send_receipt'])) {
1785 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1786 }
1787 }
1788 }
1789 CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
1790
1791 $buttonName = $this->controller->getButtonName();
1792 if ($this->_context == 'standalone') {
1793 if ($buttonName == $this->getButtonName('upload', 'new')) {
1794 $urlParams = 'reset=1&action=add&context=standalone';
1795 if ($this->_mode) {
1796 $urlParams .= '&mode=' . $this->_mode;
1797 }
1798 if ($this->_eID) {
1799 $urlParams .= '&eid=' . $this->_eID;
1800 }
1801 $session->replaceUserContext(CRM_Utils_System::url('civicrm/participant/add', $urlParams));
1802 }
1803 else {
1804 $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view',
1805 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1806 ));
1807 }
1808 }
1809 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1810 $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/participant',
1811 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"
1812 ));
1813 }
1814 }
1815 }