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