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