Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
fee14197 | 3 | | CiviCRM version 5 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
f299f7db | 5 | | Copyright CiviCRM LLC (c) 2004-2020 | |
6a488035 TO |
6 | +--------------------------------------------------------------------+ |
7 | | This file is a part of CiviCRM. | | |
8 | | | | |
9 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
10 | | under the terms of the GNU Affero General Public License | | |
11 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
12 | | | | |
13 | | CiviCRM is distributed in the hope that it will be useful, but | | |
14 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
16 | | See the GNU Affero General Public License for more details. | | |
17 | | | | |
18 | | You should have received a copy of the GNU Affero General Public | | |
19 | | License and the CiviCRM Licensing Exception along | | |
20 | | with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | *} | |
26 | {* This template is used for adding/editing/deleting offline Event Registrations *} | |
1beb268a CW |
27 | |
28 | {* Ajax callback for showing event fee snippet *} | |
bc2eeabb | 29 | {if $showFeeBlock} |
6a488035 TO |
30 | {if $priceSet} |
31 | <div id='validate_pricefield' class='messages crm-error hiddenElement'></div> | |
32 | {literal} | |
33 | <script type="text/javascript"> | |
34 | ||
ae8f569f | 35 | var fieldOptionsFull = []; |
6a488035 TO |
36 | {/literal} |
37 | {foreach from=$priceSet.fields item=fldElement key=fldId} | |
38 | {if $fldElement.options} | |
39 | {foreach from=$fldElement.options item=fldOptions key=opId} | |
40 | {if $fldOptions.is_full} | |
41 | {literal} | |
ae8f569f | 42 | fieldOptionsFull[{/literal}{$fldId}{literal}] = []; |
6a488035 TO |
43 | fieldOptionsFull[{/literal}{$fldId}{literal}][{/literal}{$opId}{literal}] = 1; |
44 | {/literal} | |
45 | {/if} | |
46 | {/foreach} | |
47 | {/if} | |
48 | {/foreach} | |
49 | {literal} | |
50 | ||
51 | if ( fieldOptionsFull.length > 0 ) { | |
3cc60a06 | 52 | CRM.$(function($) { |
ae8f569f CW |
53 | $("input,#priceset select,#priceset").each(function () { |
54 | if ( $(this).attr('price') ) { | |
55 | switch( $(this).attr('type') ) { | |
6a488035 TO |
56 | case 'checkbox': |
57 | case 'radio': | |
ae8f569f | 58 | $(this).click( function() { |
6a488035 TO |
59 | validatePriceField(this); |
60 | }); | |
61 | break; | |
62 | ||
63 | case 'select-one': | |
ae8f569f | 64 | $(this).change( function() { |
6a488035 TO |
65 | validatePriceField(this); |
66 | }); | |
67 | break; | |
68 | case 'text': | |
ae8f569f | 69 | $(this).bind( 'keyup', function() { validatePriceField(this) }); |
6a488035 TO |
70 | break; |
71 | } | |
72 | } | |
73 | }); | |
74 | }); | |
75 | ||
76 | function validatePriceField( obj ) { | |
77 | var namePart = cj(obj).attr('name').split('_'); | |
78 | var fldVal = cj(obj).val(); | |
79 | if ( cj(obj).attr('type') == 'checkbox') { | |
80 | var eleIdpart = namePart[1].split('['); | |
81 | var eleId = eleIdpart[0]; | |
82 | } | |
83 | else { | |
84 | var eleId = namePart[1]; | |
85 | } | |
86 | var showError = false; | |
87 | ||
88 | switch( cj(obj).attr('type') ) { | |
89 | case 'text': | |
90 | if ( fieldOptionsFull[eleId] && fldVal ) { | |
91 | showError = true; | |
92 | cj(obj).parent( ).parent( ).children('.label').addClass('crm-error'); | |
93 | } | |
94 | else { | |
95 | cj(obj).parent( ).parent( ).children('.label').removeClass('crm-error'); | |
96 | cj('#validate_pricefield').hide( ).html(''); | |
97 | } | |
98 | break; | |
99 | ||
100 | case 'checkbox': | |
101 | var checkBoxValue = eleIdpart[1].split(']'); | |
8539f25d | 102 | if ( cj(obj).prop("checked") == true && |
6a488035 TO |
103 | fieldOptionsFull[eleId] && |
104 | fieldOptionsFull[eleId][checkBoxValue[0]]) { | |
105 | showError = true; | |
106 | cj(obj).parent( ).addClass('crm-error'); | |
107 | } | |
108 | else { | |
109 | cj(obj).parent( ).removeClass('crm-error'); | |
110 | } | |
111 | break; | |
112 | ||
113 | default: | |
114 | if ( fieldOptionsFull[eleId] && | |
115 | fieldOptionsFull[eleId][fldVal] ) { | |
116 | showError = true; | |
117 | cj(obj).parent( ).addClass('crm-error'); | |
118 | } | |
119 | else { | |
120 | cj(obj).parent( ).removeClass('crm-error'); | |
121 | } | |
122 | } | |
123 | ||
124 | if ( showError ) { | |
ee8c1ef3 | 125 | cj('#validate_pricefield').show().html('<i class="crm-i fa-exclamation-triangle crm-i-red"></i>{/literal} {ts escape='js'}This Option is already full for this event.{/ts}{literal}'); |
6a488035 TO |
126 | } |
127 | else { | |
128 | cj('#validate_pricefield').hide( ).html(''); | |
129 | } | |
130 | } | |
131 | } | |
59e44db1 PJ |
132 | |
133 | // change the status to default 'partially paid' for partial payments | |
b6c15d8a | 134 | var feeAmount, userModifiedAmount; |
81f3d017 | 135 | var partiallyPaidStatusId = {/literal}{$partiallyPaidStatusId}{literal}; |
59e44db1 PJ |
136 | |
137 | cj('#total_amount') | |
138 | .focus( | |
139 | function() { | |
140 | feeAmount = cj(this).val(); | |
31a1201f | 141 | feeAmount = Number(feeAmount.replace(/[^0-9\.]+/g,"")); |
59e44db1 PJ |
142 | } |
143 | ) | |
144 | .change( | |
145 | function() { | |
146 | userModifiedAmount = cj(this).val(); | |
31a1201f | 147 | userModifiedAmount = Number(userModifiedAmount.replace(/[^0-9\.]+/g,"")); |
59e44db1 | 148 | if (userModifiedAmount < feeAmount) { |
f5bb53b8 | 149 | cj('#status_id').val(partiallyPaidStatusId).change(); |
59e44db1 PJ |
150 | } |
151 | } | |
152 | ); | |
153 | ||
b50fdacc | 154 | cj('form[name=Participant]').on("click", '.validate', |
59e44db1 | 155 | function(e) { |
ad44e24b DRJ |
156 | if (CRM.$('#total_amount').length == 0) { |
157 | var $balance = CRM.$('#payment-info-balance'); | |
158 | if ($balance.length > 0 && parseFloat($balance.attr('data-balance')) == 0) { | |
159 | return true; | |
160 | } | |
161 | } | |
59e44db1 PJ |
162 | var userSubmittedStatus = cj('#status_id').val(); |
163 | var statusLabel = cj('#status_id option:selected').text(); | |
81f3d017 PJ |
164 | if (userModifiedAmount < feeAmount && userSubmittedStatus != partiallyPaidStatusId) { |
165 | var msg = "{/literal}{ts escape="js" 1="%1"}Payment amount is less than the amount owed. Expected participant status is 'Partially paid'. Are you sure you want to set the participant status to %1? Click OK to continue, Cancel to change your entries.{/ts}{literal}"; | |
166 | var result = confirm(ts(msg, {1: statusLabel})); | |
59e44db1 | 167 | if (result == false) { |
81f3d017 | 168 | return false; |
59e44db1 PJ |
169 | } |
170 | } | |
171 | } | |
172 | ); | |
6a488035 TO |
173 | </script> |
174 | {/literal} | |
175 | {/if} | |
d5397f2f | 176 | |
6a488035 | 177 | {include file="CRM/Event/Form/EventFees.tpl"} |
1beb268a | 178 | |
1beb268a | 179 | {* Main event form template *} |
6a488035 TO |
180 | {else} |
181 | {if $participantMode == 'test' } | |
182 | {assign var=registerMode value="TEST"} | |
183 | {elseif $participantMode == 'live'} | |
184 | {assign var=registerMode value="LIVE"} | |
185 | {/if} | |
6a488035 | 186 | <div class="crm-block crm-form-block crm-participant-form-block"> |
c4145ded MWMC |
187 | {if $newCredit AND $action EQ 1 AND $participantMode EQ null} |
188 | <div class="action-link css_right crm-link-credit-card-mode"> | |
189 | {if $contactId} | |
190 | {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/participant' q="reset=1&action=add&cid=`$contactId`&context=`$context`&mode=live"}{/capture} | |
191 | {else} | |
192 | {capture assign=ccModeLink}{crmURL p='civicrm/contact/view/participant' q="reset=1&action=add&context=standalone&mode=live"}{/capture} | |
193 | {/if} | |
194 | <a class="open-inline-noreturn action-item crm-hover-button" href="{$ccModeLink}">» {ts}submit credit card event registration{/ts}</a> | |
195 | </div> | |
196 | {/if} | |
6a488035 TO |
197 | <div class="view-content"> |
198 | {if $participantMode} | |
f6eedce7 | 199 | <div class="help"> |
6a488035 TO |
200 | {ts 1=$displayName 2=$registerMode}Use this form to submit an event registration on behalf of %1. <strong>A %2 transaction will be submitted</strong> using the selected payment processor.{/ts} |
201 | </div> | |
202 | {/if} | |
203 | <div id="eventFullMsg" class="messages status no-popup" style="display:none;"></div> | |
204 | ||
205 | ||
206 | {if $action eq 1 AND $paid} | |
f6eedce7 | 207 | <div class="help"> |
6a488035 TO |
208 | {ts}If you are accepting offline payment from this participant, check <strong>Record Payment</strong>. You will be able to fill in the payment information, and optionally send a receipt.{/ts} |
209 | </div> | |
210 | {/if} | |
211 | ||
212 | {if $action eq 8} {* If action is Delete *} | |
6a488035 TO |
213 | <div class="crm-participant-form-block-delete messages status no-popup"> |
214 | <div class="crm-content"> | |
215 | <div class="icon inform-icon"></div> | |
216 | {ts}WARNING: Deleting this registration will result in the loss of related payment records (if any).{/ts} {ts}Do you want to continue?{/ts} | |
217 | </div> | |
218 | {if $additionalParticipant} | |
219 | <div class="crm-content"> | |
220 | {ts 1=$additionalParticipant} There are %1 more Participant(s) registered by this participant.{/ts} | |
221 | </div> | |
222 | {/if} | |
223 | </div> | |
224 | {if $additionalParticipant} | |
225 | {$form.delete_participant.html} | |
226 | {/if} | |
227 | {else} {* If action is other than Delete *} | |
228 | <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div> | |
229 | <table class="form-layout-compressed"> | |
2944baac | 230 | <tr class="crm-participant-form-contact-id"> |
231 | <td class="label">{$form.contact_id.label}</td> | |
232 | <td>{$form.contact_id.html}</td> | |
233 | </tr> | |
6a488035 TO |
234 | {if $action EQ 2} |
235 | {if $additionalParticipants} {* Display others registered by this participant *} | |
236 | <tr class="crm-participant-form-block-additionalParticipants"> | |
237 | <td class="label"><label>{ts}Also Registered by this Participant{/ts}</label></td> | |
238 | <td> | |
239 | {foreach from=$additionalParticipants key=apName item=apURL} | |
240 | <a href="{$apURL}" title="{ts}view additional participant{/ts}">{$apName}</a><br /> | |
241 | {/foreach} | |
242 | </td> | |
243 | </tr> | |
244 | {/if} | |
245 | {if $registered_by_contact_id} | |
246 | <tr class="crm-participant-form-block-registered-by"> | |
247 | <td class="label"><label>{ts}Registered By{/ts}</label></td> | |
248 | <td class="view-value"> | |
249 | <a href="{crmURL p='civicrm/contact/view/participant' q="reset=1&id=$participant_registered_by_id&cid=$registered_by_contact_id&action=view"}" | |
250 | title="{ts}view primary participant{/ts}">{$registered_by_display_name}</a> | |
251 | </td> | |
252 | </tr> | |
253 | {/if} | |
254 | {/if} | |
6a488035 | 255 | <tr class="crm-participant-form-block-event_id"> |
1beb268a CW |
256 | <td class="label">{$form.event_id.label}</td> |
257 | <td class="view-value"> | |
258 | {$form.event_id.html} | |
259 | {if $is_test} | |
260 | {ts}(test){/ts} | |
261 | {/if} | |
262 | </td> | |
6a488035 TO |
263 | </tr> |
264 | ||
265 | {* CRM-7362 --add campaign *} | |
1beb268a | 266 | {include file="CRM/Campaign/Form/addCampaignToComponent.tpl" campaignTrClass="crm-participant-form-block-campaign_id"} |
6a488035 TO |
267 | |
268 | <tr class="crm-participant-form-block-role_id"> | |
269 | <td class="label">{$form.role_id.label}</td> | |
270 | <td>{$form.role_id.html}</td> | |
271 | </tr> | |
272 | <tr class="crm-participant-form-block-register_date"> | |
273 | <td class="label">{$form.register_date.label}</td> | |
6ba1830e | 274 | <td>{$form.register_date.html}</td> |
6a488035 TO |
275 | </tr> |
276 | <tr class="crm-participant-form-block-status_id"> | |
277 | <td class="label">{$form.status_id.label}</td> | |
278 | <td>{$form.status_id.html}{if $event_is_test} {ts}(test){/ts}{/if} | |
279 | <div id="notify">{$form.is_notify.html}{$form.is_notify.label}</div> | |
280 | </td> | |
281 | </tr> | |
282 | <tr class="crm-participant-form-block-source"> | |
283 | <td class="label">{$form.source.label}</td><td>{$form.source.html|crmAddClass:huge}<br /> | |
284 | <span class="description">{ts}Source for this registration (if applicable).{/ts}</span></td> | |
285 | </tr> | |
9580e4a2 | 286 | {if $participantMode} |
287 | <tr class="crm-participant-form-block-payment_processor_id"> | |
288 | <td class="label nowrap">{$form.payment_processor_id.label}</td> | |
289 | <td>{$form.payment_processor_id.html}</td> | |
290 | </tr> | |
291 | {/if} | |
6a488035 | 292 | </table> |
0b2b58ea | 293 | {if $participantId and $hasPayment} |
29c61b58 PJ |
294 | <table class='form-layout'> |
295 | <tr> | |
296 | <td class='label'>{ts}Fees{/ts}</td> | |
297 | {* this is where the payment info is shown using CRM/Contribute/Page/PaymentInfo.tpl tpl*} | |
298 | <td id='payment-info'></td> | |
299 | </tr> | |
300 | </table> | |
301 | {/if} | |
6a488035 | 302 | {* Fee block (EventFees.tpl) is injected here when an event is selected. *} |
ab421ec6 | 303 | <div class="crm-event-form-fee-block"></div> |
6a488035 TO |
304 | <fieldset> |
305 | <table class="form-layout"> | |
306 | <tr class="crm-participant-form-block-note"> | |
307 | <td class="label">{$form.note.label}</td><td>{$form.note.html}</td> | |
308 | </tr> | |
309 | </table> | |
310 | </fieldset> | |
311 | ||
312 | <div class="crm-participant-form-block-customData"> | |
313 | <div id="customData" class="crm-customData-block"></div> {* Participant Custom data *} | |
314 | <div id="customData{$eventNameCustomDataTypeID}" class="crm-customData-block"></div> {* Event Custom Data *} | |
315 | <div id="customData{$roleCustomDataTypeID}" class="crm-customData-block"></div> {* Role Custom Data *} | |
316 | <div id="customData{$eventTypeCustomDataTypeID}" class="crm-customData-block"></div> {* Role Custom Data *} | |
317 | </div> | |
318 | {/if} | |
319 | ||
320 | {if $accessContribution and $action eq 2 and $rows.0.contribution_id} | |
321 | {include file="CRM/Contribute/Form/Selector.tpl" context="Search"} | |
322 | {/if} | |
323 | ||
324 | <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div> | |
325 | </div> | |
326 | </div> | |
1beb268a | 327 | {* JS block for ADD or UPDATE actions only *} |
6a488035 | 328 | {if $action eq 1 or $action eq 2} |
0b2b58ea | 329 | {if $participantId and $hasPayment} |
685dc433 | 330 | {include file="CRM/Contribute/Page/PaymentInfo.tpl" show='payments'} |
dfbeebc5 | 331 | {/if} |
b1ea2569 PJ |
332 | |
333 | {*include custom data js file*} | |
334 | {include file="CRM/common/customData.tpl"} | |
335 | ||
6a488035 | 336 | <script type="text/javascript"> |
1beb268a | 337 | {literal} |
3cc60a06 | 338 | CRM.$(function($) { |
82a54c66 | 339 | |
b50fdacc | 340 | var $form = $('form.{/literal}{$form.formClass}{literal}'); |
6a488035 | 341 | |
1beb268a CW |
342 | // Handle event selection |
343 | $('#event_id', $form).change(function() { | |
344 | var eventId = $(this).val(); | |
345 | if (!eventId) { | |
346 | return; | |
347 | } | |
348 | var info = $(this).select2('data').extra; | |
6a488035 | 349 | |
1beb268a | 350 | // Set role from default |
cd120ea0 | 351 | $('select[name^=role_id]', $form).select2('val', [info.default_role_id], true); |
6a488035 | 352 | |
1beb268a CW |
353 | // Set campaign default |
354 | $('#campaign_id', $form).select2('val', info.campaign_id); | |
6a488035 | 355 | |
1beb268a | 356 | // Event and event-type custom data |
4bd532e8 JP |
357 | CRM.buildCustomData('Participant', eventId, {/literal}{$eventNameCustomDataTypeID}{literal}, null, null, null, true); |
358 | CRM.buildCustomData('Participant', info.event_type_id, {/literal}{$eventTypeCustomDataTypeID}{literal}, null, null, null, true); | |
6a488035 | 359 | |
1beb268a CW |
360 | buildFeeBlock(); |
361 | }); | |
6a488035 | 362 | |
1beb268a | 363 | // Handle participant role selection |
cd120ea0 CW |
364 | $('select[name^=role_id]', $form).change(buildRoleCustomData); |
365 | if ($('select[name^=role_id]', $form).val()) { | |
366 | buildRoleCustomData(); | |
367 | } | |
6a488035 | 368 | |
1beb268a | 369 | buildFeeBlock(); |
6a488035 | 370 | |
1beb268a CW |
371 | //build discount block |
372 | if ($('#discount_id', $form).val()) { | |
373 | buildFeeBlock($('#discount_id', $form).val()); | |
374 | } | |
95e7a695 CW |
375 | $($form).on('change', '#discount_id', function() { |
376 | buildFeeBlock($(this).val()); | |
377 | }); | |
6a488035 | 378 | |
cd120ea0 | 379 | function buildRoleCustomData() { |
91dcfec6 CW |
380 | var roleId = $('select[name^=role_id]', $form).val() || []; |
381 | CRM.buildCustomData('Participant', roleId.join(), {/literal}{$roleCustomDataTypeID}{literal}); | |
cd120ea0 CW |
382 | } |
383 | ||
1beb268a CW |
384 | //build fee block |
385 | function buildFeeBlock(discountId) { | |
386 | var dataUrl = {/literal}"{crmURL p=$urlPath h=0 q="snippet=4&qfKey=$qfKey"}"; | |
6a488035 | 387 | |
1beb268a CW |
388 | {if $urlPathVar} |
389 | dataUrl += '&' + '{$urlPathVar}'; | |
390 | {/if} | |
ce44b391 | 391 | {if $isBackOffice} |
392 | dataUrl += '&' + 'is_backoffice=1'; | |
393 | {/if} | |
6a488035 | 394 | |
1beb268a | 395 | {literal} |
ab421ec6 | 396 | var eventId = $('[name=event_id], #event_id', $form).val(); |
6a488035 | 397 | |
1beb268a CW |
398 | if (eventId) { |
399 | dataUrl += '&eventId=' + eventId; | |
400 | } | |
401 | else { | |
ab421ec6 CW |
402 | $('#eventFullMsg', $form).hide( ); |
403 | $('.crm-event-form-fee-block', $form).html(''); | |
1beb268a CW |
404 | return; |
405 | } | |
6a488035 | 406 | |
8838f818 | 407 | var participantId = {/literal}{$participantId|@json_encode}{literal}; |
6a488035 | 408 | |
1beb268a CW |
409 | if (participantId) { |
410 | dataUrl += '&participantId=' + participantId; | |
411 | } | |
6a488035 | 412 | |
1beb268a CW |
413 | if (discountId) { |
414 | dataUrl += '&discountId=' + discountId; | |
415 | } | |
6a488035 | 416 | |
b6c15d8a | 417 | $.ajax({ |
1beb268a | 418 | url: dataUrl, |
1beb268a | 419 | success: function ( html ) { |
ab421ec6 | 420 | $(".crm-event-form-fee-block", $form).html( html ).trigger('crmLoad'); |
5be1890a | 421 | //show event real full as well as waiting list message. |
ab421ec6 CW |
422 | if ( $("#hidden_eventFullMsg", $form).val( ) ) { |
423 | $( "#eventFullMsg", $form).show( ).html( $("#hidden_eventFullMsg", $form).val( ) ); | |
5be1890a CW |
424 | } |
425 | else { | |
ab421ec6 | 426 | $( "#eventFullMsg", $form ).hide( ); |
5be1890a | 427 | } |
1beb268a CW |
428 | } |
429 | }); | |
6a488035 | 430 | } |
1beb268a | 431 | |
b6c15d8a | 432 | {/literal} |
b67c3f78 | 433 | CRM.buildCustomData( '{$customDataType}', null, null ); |
b6c15d8a CW |
434 | {if $eventID} |
435 | CRM.buildCustomData( '{$customDataType}', {$eventID}, {$eventNameCustomDataTypeID} ); | |
436 | {/if} | |
437 | {if $eventTypeID} | |
438 | CRM.buildCustomData( '{$customDataType}', {$eventTypeID}, {$eventTypeCustomDataTypeID} ); | |
439 | {/if} | |
440 | {literal} | |
6a488035 | 441 | |
1beb268a | 442 | }); |
6a488035 TO |
443 | </script> |
444 | {/literal} | |
445 | ||
446 | {/if} | |
447 | ||
6a488035 | 448 | |
6a488035 TO |
449 | <script type="text/javascript"> |
450 | {literal} | |
453ed6d1 | 451 | |
6a488035 | 452 | sendNotification(); |
453ed6d1 KJ |
453 | function sendNotification() { |
454 | var notificationStatusIds = {/literal}"{$notificationStatusIds}"{literal}; | |
455 | notificationStatusIds = notificationStatusIds.split(','); | |
456 | if (cj.inArray(cj('select#status_id option:selected').val(), notificationStatusIds) > -1) { | |
6a488035 | 457 | cj("#notify").show(); |
8539f25d | 458 | cj("#is_notify").prop('checked', true); |
453ed6d1 KJ |
459 | } |
460 | else { | |
461 | cj("#notify").hide(); | |
8539f25d | 462 | cj("#is_notify").prop('checked', false); |
6a488035 TO |
463 | } |
464 | } | |
465 | ||
6a488035 | 466 | {/literal} |
6a488035 | 467 | </script> |
6a488035 | 468 | |
453ed6d1 | 469 | {/if} {* end of main event block*} |