PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.7
VikBooking Hotel Booking Engine & PMS v1.6.7
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / site / views / precheckin / tmpl / default.php

default.php in VikBooking Hotel Booking Engine & PMS 1.6.7, at site/views/precheckin/tmpl/default.php

710 lines 26.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage com_vikbooking
5 * @author Alessio Gaggii - e4j - Extensionsforjoomla.com
6 * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 $document = JFactory::getDocument();
14 // load jQuery lib e jQuery UI
15 if (VikBooking::loadJquery()) {
16 JHtml::fetch('jquery.framework', true, true);
17 }
18 $document->addStyleSheet(VBO_SITE_URI.'resources/jquery-ui.min.css');
19 JHtml::fetch('script', VBO_SITE_URI.'resources/jquery-ui.min.js');
20
21 $currencysymb = VikBooking::getCurrencySymb();
22 $datesep = VikBooking::getDateSeparator();
23 $nowdf = VikBooking::getDateFormat();
24 if ($nowdf == "%d/%m/%Y") {
25 $df = 'd/m/Y';
26 $juidf = 'dd/mm/yy';
27 } elseif ($nowdf == "%m/%d/%Y") {
28 $df = 'm/d/Y';
29 $juidf = 'mm/dd/yy';
30 } else {
31 $df = 'Y/m/d';
32 $juidf = 'yy/mm/dd';
33 }
34 $wdays_map = array(
35 JText::translate('VBWEEKDAYZERO'),
36 JText::translate('VBWEEKDAYONE'),
37 JText::translate('VBWEEKDAYTWO'),
38 JText::translate('VBWEEKDAYTHREE'),
39 JText::translate('VBWEEKDAYFOUR'),
40 JText::translate('VBWEEKDAYFIVE'),
41 JText::translate('VBWEEKDAYSIX')
42 );
43 $ts_info = getdate($this->order['ts']);
44 $checkin_info = getdate($this->order['checkin']);
45 $checkout_info = getdate($this->order['checkout']);
46 $pitemid = VikRequest::getInt('Itemid', 0, 'request');
47
48 // compose the calculation for pax_data
49 list($pax_fields, $pax_fields_attributes) = VikBooking::getPaxFields(true);
50 $pax_data = array();
51 $count_pax_data = 1;
52 if (!empty($this->customer['pax_data'])) {
53 $pax_data = json_decode($this->customer['pax_data'], true);
54 }
55
56 $arrpeople = array();
57 foreach ($this->orderrooms as $ind => $or) {
58 $num = $ind + 1;
59 $arrpeople[$num]['adults'] = $or['adults'];
60 $arrpeople[$num]['children'] = $or['children'];
61 $arrpeople[$num]['children_age'] = $or['childrenage'];
62 $arrpeople[$num]['t_first_name'] = $or['t_first_name'];
63 $arrpeople[$num]['t_last_name'] = $or['t_last_name'];
64 }
65
66 // countries list
67 $all_countries = VikBooking::getCountriesArray();
68
69 // access the active back-end driver instance also for pre-checkin
70 $pax_fields_obj = VBOCheckinPax::getInstance();
71
72 // load langs for JS
73 JText::script('VBO_UPLOAD_FAILED');
74 JText::script('VBO_REMOVEF_CONFIRM');
75 JText::script('VBO_PRECHECKIN_TOAST_HELP');
76 ?>
77
78 <h3 class="vbo-booking-details-intro"><?php echo JText::sprintf('VBOYOURBOOKCONFAT', VikBooking::getFrontTitle()); ?></h3>
79
80 <div class="vbo-booking-details-topcontainer vbo-booking-details-precheckin">
81
82 <div class="vbo-booking-details-head vbo-booking-details-head-confirmed">
83 <h4><?php echo JText::translate('VBOPRECHECKIN'); ?></h4>
84 </div>
85
86 <div class="vbo-booking-details-midcontainer">
87 <div class="vbo-booking-details-bookinfos">
88 <span class="vbvordudatatitle"><?php echo JText::translate('VBORDERDETAILS'); ?></span>
89 <div class="vbo-booking-details-bookinfo">
90 <span class="vbo-booking-details-bookinfo-lbl"><?php echo JText::translate('VBORDEREDON'); ?></span>
91 <span class="vbo-booking-details-bookinfo-val"><?php echo $wdays_map[$ts_info['wday']].', '.date(str_replace("/", $datesep, $df).' H:i', $this->order['ts']); ?></span>
92 </div>
93 <div class="vbo-booking-details-bookinfo">
94 <span class="vbo-booking-details-bookinfo-lbl"><?php echo JText::translate('VBCONFIRMNUMB'); ?></span>
95 <span class="vbo-booking-details-bookinfo-val"><?php echo $this->order['confirmnumber']; ?></span>
96 </div>
97 <div class="vbo-booking-details-bookinfo">
98 <span class="vbo-booking-details-bookinfo-lbl"><?php echo JText::translate('VBDAL'); ?></span>
99 <span class="vbo-booking-details-bookinfo-val"><?php echo $wdays_map[$checkin_info['wday']].', '.date(str_replace("/", $datesep, $df).' H:i', $this->order['checkin']); ?></span>
100 </div>
101 <div class="vbo-booking-details-bookinfo">
102 <span class="vbo-booking-details-bookinfo-lbl"><?php echo JText::translate('VBAL'); ?></span>
103 <span class="vbo-booking-details-bookinfo-val"><?php echo $wdays_map[$checkout_info['wday']].', '.date(str_replace("/", $datesep, $df).' H:i', $this->order['checkout']); ?></span>
104 </div>
105 <div class="vbo-booking-details-bookinfo">
106 <span class="vbo-booking-details-bookinfo-lbl"><?php echo JText::translate('VBDAYS'); ?></span>
107 <span class="vbo-booking-details-bookinfo-val"><?php echo $this->order['days']; ?></span>
108 </div>
109 </div>
110 </div>
111
112 <div class="vbo-precheckin-container">
113 <div class="info vbo-precheckin-disclaimer"><?php echo JText::translate('VBO_PRECHECKIN_DISCLAIMER'); ?></div>
114 <form action="<?php echo JRoute::rewrite('index.php?option=com_vikbooking'.(!empty($pitemid) ? '&Itemid='.$pitemid : '')); ?>" method="post">
115 <input type="hidden" name="option" value="com_vikbooking" />
116 <input type="hidden" name="task" value="storeprecheckin" />
117 <input type="hidden" name="sid" value="<?php echo empty($this->order['sid']) && !empty($this->order['idorderota']) ? $this->order['idorderota'] : $this->order['sid']; ?>" />
118 <input type="hidden" name="ts" value="<?php echo $this->order['ts']; ?>" />
119 <input type="hidden" name="Itemid" value="<?php echo $pitemid; ?>" />
120 <?php
121 foreach ($this->orderrooms as $ind => $or) {
122 $num = $ind + 1;
123 // total guests details available
124 $count_pax_data = $num < 2 ? $count_pax_data : 0;
125 if (isset($pax_data[$ind])) {
126 $count_pax_data = count($pax_data[$ind]);
127 }
128
129 // calculate the number of guests to register depending on current driver settings for pre-checkin (plugin only)
130 $guests_to_register = $pax_fields_obj->registerChildren($precheckin = true) ? ($arrpeople[$num]['adults'] + $arrpeople[$num]['children']) : $arrpeople[$num]['adults'];
131 ?>
132 <div class="vbo-precheckin-room-wrapper">
133 <div class="vbo-precheckin-room-wrap <?php echo $count_pax_data >= $guests_to_register ? 'vbo-precheckin-guestscount-complete' : 'vbo-precheckin-guestscount-incomplete'; ?>">
134 <div class="vbo-precheckin-room-head">
135 <span><?php echo $or['name']; ?></span>
136 </div>
137 <div class="vbo-precheckin-adults-cont">
138 <?php
139 for ($g = 1; $g <= $guests_to_register; $g++) {
140 $current_guest = array();
141 if (count($pax_data) && isset($pax_data[$ind]) && isset($pax_data[$ind][$g])) {
142 $current_guest = $pax_data[$ind][$g];
143 } elseif ($ind < 1 && $g == 1) {
144 $current_guest = $this->customer;
145 }
146 ?>
147 <div class="vbo-precheckin-adult-wrap">
148 <div class="vbo-precheckin-adult-num">
149 <span><?php echo JText::sprintf('VBOGUESTNUM', $g); ?></span>
150 </div>
151 <?php
152 /**
153 * Overrides tip: to add and collect custom details from each guest it is possible to push more
154 * pairs of key-values to $pax_fields. For example, a custom value could be pushed like this:
155 *
156 * $pax_fields['custom_field_key'] = 'Custom Field Name';
157 * $pax_fields_attributes['custom_field_key'] = 'text';
158 *
159 * @see the best way to customize the guest fields is to use the apposite plugin hooks/events.
160 */
161 $pax_field_ind = 1;
162 foreach ($pax_fields as $paxk => $paxv) {
163 ?>
164 <div class="vbo-precheckin-guest-detail<?php echo isset($pax_fields_attributes[$paxk]) && $pax_fields_attributes[$paxk] == 'file' ? ' vbo-precheckin-guest-detail-files' : ''; ?>">
165 <label for="pax-field-<?php echo $paxv . '-' . $ind . '-' . $g . '-' . $paxk; ?>"><?php echo $paxv; ?></label>
166 <?php
167 if (isset($pax_fields_attributes[$paxk]) && is_array($pax_fields_attributes[$paxk])) {
168 // select with multiple choices
169 ?>
170 <select name="guests[<?php echo $ind; ?>][<?php echo $g; ?>][<?php echo $paxk; ?>]">
171 <option></option>
172 <?php
173 $opt_ind = 1;
174 foreach ($pax_fields_attributes[$paxk] as $attrk => $attrv) {
175 $paxv_selected = isset($current_guest[$paxk]) && ($current_guest[$paxk] == $attrv || (!is_numeric($attrk) && $current_guest[$paxk] == $attrk));
176 if (!$paxv_selected && isset($current_guest[$paxk]) && is_numeric($current_guest[$paxk])) {
177 /**
178 * It is safe to compare such select tags, which usually refer to "gender",
179 * to even numeric values in order to attempt to pre-select the current value.
180 */
181 $paxv_selected = ($opt_ind == $current_guest[$paxk]);
182 }
183 ?>
184 <option value="<?php echo !is_numeric($attrk) ? $attrk : $attrv; ?>"<?php echo ($paxv_selected ? ' selected="selected"' : ''); ?>><?php echo $attrv; ?></option>
185 <?php
186 $opt_ind++;
187 }
188 ?>
189 </select>
190 <?php
191 } elseif (isset($pax_fields_attributes[$paxk]) && $pax_fields_attributes[$paxk] == 'country') {
192 // field of type country
193 echo VikBooking::getCountriesSelect('guests['.$ind.']['.$g.']['.$paxk.']', $all_countries, (isset($current_guest[$paxk]) ? $current_guest[$paxk] : ''), $paxv);
194 } elseif (isset($pax_fields_attributes[$paxk]) && $pax_fields_attributes[$paxk] == 'calendar') {
195 // datepicker
196 ?>
197 <input type="text" autocomplete="off" data-gind="<?php echo $g; ?>" class="vbo-paxfield vbo-paxfield-datepicker" name="guests[<?php echo $ind; ?>][<?php echo $g; ?>][<?php echo $paxk; ?>]" value="<?php echo (isset($current_guest[$paxk]) ? $this->escape($current_guest[$paxk]) : ''); ?>" />
198 <?php
199 } elseif (isset($pax_fields_attributes[$paxk]) && $pax_fields_attributes[$paxk] == 'file') {
200 // file upload (multiple files allowed)
201 ?>
202 <input type="hidden" id="vbo-paxfield-curfiles-<?php echo $ind . '-' . $g . '-' . $paxk; ?>" name="guests[<?php echo $ind; ?>][<?php echo $g; ?>][<?php echo $paxk; ?>]" value="<?php echo (isset($current_guest[$paxk]) ? $this->escape($current_guest[$paxk]) : ''); ?>" />
203
204 <div class="vbo-paxfield-upload-container">
205 <button type="button" class="btn vbo-pref-color-btn-secondary vbo-precheckin-uploadfile" data-roomi="<?php echo $ind; ?>" data-guesti="<?php echo $g; ?>" data-paxk="<?php echo $paxk; ?>"><?php VikBookingIcons::e('camera'); ?> <?php echo JText::translate('VBOUPSELLADD'); ?></button>
206 <div class="vbo-paxfield-upload-progress-wrap" id="vbo-paxfield-upload-progress-<?php echo $ind . '-' . $g . '-' . $paxk; ?>" style="display: none;">
207 <div class="vbo-paxfield-upload-progress">&nbsp;</div>
208 </div>
209 </div>
210
211 <div class="vbo-paxfield vbo-paxfield-files" id="vbo-paxfield-files-<?php echo $ind . '-' . $g . '-' . $paxk; ?>" data-gselector="<?php echo $ind . '-' . $g . '-' . $paxk; ?>">
212 <?php
213 if (isset($current_guest[$paxk]) && !empty($current_guest[$paxk])) {
214 $guest_files = explode('|', $current_guest[$paxk]);
215 foreach ($guest_files as $gfk => $guest_file) {
216 if (empty($guest_file) || strpos($guest_file, 'http') !== 0) {
217 continue;
218 }
219 $furl_segments = explode('/', $guest_file);
220 $guest_fname = $furl_segments[(count($furl_segments) - 1)];
221 $read_fname = substr($guest_fname, (strpos($guest_fname, '_') + 1));
222 ?>
223 <div class="vbo-paxfield-file-uploaded">
224 <span class="vbo-paxfield-file-uploaded-rm"><?php VikBookingIcons::e('times-circle'); ?></span>
225 <a href="<?php echo $guest_file; ?>" target="_blank">
226 <?php VikBookingIcons::e('image'); ?>
227 <span><?php echo $read_fname; ?></span>
228 </a>
229 </div>
230 <?php
231 }
232 }
233 ?>
234 </div>
235 <?php
236 } elseif (isset($pax_fields_attributes[$paxk]) && $pax_fields_attributes[$paxk] == 'text') {
237 // text
238 ?>
239 <input type="text" autocomplete="off" data-gind="<?php echo $g; ?>" class="vbo-paxfield" name="guests[<?php echo $ind; ?>][<?php echo $g; ?>][<?php echo $paxk; ?>]" value="<?php echo (isset($current_guest[$paxk]) ? $this->escape($current_guest[$paxk]) : ''); ?>" />
240 <?php
241 } else {
242 /**
243 * Attempt to render a custom field previously installed through a third party plugin.
244 * If no such field type is found, the object will default to the "text" type.
245 *
246 * @since 1.16.3 (J) - 1.6.3 (WP)
247 */
248
249 // get an instance of the VBOCheckinPaxfield object
250 $pax_field_obj = $pax_fields_obj->getField($paxk);
251
252 // detect the current type of guest
253 $guest_type = $g > $arrpeople[$num]['adults'] ? 'child' : 'adult';
254
255 // set object data
256 $pax_field_obj->setGuestType($guest_type)
257 ->setFieldNumber($pax_field_ind)
258 ->setGuestNumber($g)
259 ->setGuestData($current_guest)
260 ->setRoomIndex($ind)
261 ->setRoomGuests($arrpeople[$num]['adults'], $arrpeople[$num]['children'])
262 ->setTotalRooms(count($arrpeople));
263
264 // render input field
265 $pax_field_html = $pax_fields_obj->render($pax_field_obj);
266 if (empty($pax_field_html)) {
267 // nothing to display, increase the counter and continue
268 $pax_field_ind++;
269 continue;
270 }
271
272 // access the implementor object
273 $implementor = $pax_fields_obj->getFieldTypeImplementor($pax_field_obj);
274
275 // check if a particular CSS class has been defined
276 $field_container_class = $implementor->getContainerClassAttr();
277 $field_container_class = !empty($field_container_class) ? " $field_container_class" : '';
278
279 // display the custom field type
280 ?>
281 <div class="vbo-precheckin-custom-field<?php echo $field_container_class; ?>">
282 <?php echo $pax_field_html; ?>
283 </div>
284 <?php
285 }
286 ?>
287 </div>
288 <?php
289 $pax_field_ind++;
290 }
291 ?>
292 </div>
293 <?php
294 }
295 ?>
296 </div>
297 </div>
298 </div>
299 <?php
300 }
301 ?>
302 <div class="vbo-precheckin-submit">
303 <button type="submit" class="btn btn-large vbo-pref-color-btn"><?php echo JText::translate('VBOSUBMITPRECHECKIN'); ?></button>
304 </div>
305 </form>
306 </div>
307
308 </div>
309
310 <input type="file" id="vbo-precheckin-upload-field" accept="image/*,.pdf" multiple="multiple" style="display: none;" />
311
312 <script type="text/javascript">
313 /**
314 * Declare global score variables
315 */
316 var vbo_prechin_current_room = null,
317 vbo_prechin_current_guest = null,
318 vbo_prechin_current_paxk = null,
319 vbo_typingtoast_displayed = false,
320 vbo_typingtoast_changes = 0;
321
322 /**
323 * Displays a toast message
324 */
325 function vboPresentToast(content, duration, clickcallback) {
326 // remove any other previous toast from the document
327 jQuery('.vbo-toast-message').remove();
328 // build toast
329 var toast = jQuery('<div>').addClass('vbo-toast-message vbo-toast-message-presented');
330 // onclick function
331 var onclickfunc = function() {
332 // hide toast when clicked
333 jQuery(this).removeClass('vbo-toast-message-presented').addClass('vbo-toast-message-dimissed');
334 };
335 if (typeof clickcallback === 'function') {
336 onclickfunc = function() {
337 // launch callback
338 clickcallback.call(this);
339 // hide toast either way
340 jQuery(this).removeClass('vbo-toast-message-presented').addClass('vbo-toast-message-dimissed');
341 };
342 }
343 // register click event on toast
344 toast.on('click', onclickfunc);
345 // build toast content
346 var inner = jQuery('<div>').addClass('vbo-toast-message-content');
347 toast.append(inner.append(content));
348 // present toast
349 jQuery('body').append(toast);
350 // set timeout for auto-dismiss
351 if (typeof duration === 'undefined') {
352 duration = 4000;
353 }
354 if (!isNaN(duration) && duration > 0) {
355 // if duration NaN or <= 0, the toast won't be dismissed automatically
356 setTimeout(function() {
357 jQuery('.vbo-toast-message').removeClass('vbo-toast-message-presented').addClass('vbo-toast-message-dimissed');
358 }, duration);
359 }
360 }
361
362 /**
363 * Some older smartphones or tablets may not support files uploading
364 */
365 function vboIsUploadSupported() {
366 if (!navigator || !navigator.userAgent) {
367 return false;
368 }
369 if (navigator.userAgent.match(/(Android (1.0|1.1|1.5|1.6|2.0|2.1))|(Windows Phone (OS 7|8.0))|(XBLWP)|(ZuneWP)|(w(eb)?OSBrowser)|(webOS)|(Kindle\/(1.0|2.0|2.5|3.0))/)) {
370 return false;
371 } else {
372 return true;
373 }
374 }
375
376 /**
377 * Checks wether a jQuery XHR response object was due to a connection error.
378 * Property readyState 0 = Network Error (UNSENT), 4 = HTTP error (DONE).
379 * Property responseText may not be set in some browsers.
380 * This is what to check to determine if a connection error occurred.
381 */
382 function vboIsConnectionLostError(err) {
383 if (!err || !err.hasOwnProperty('status')) {
384 return false;
385 }
386
387 return (
388 err.statusText == 'error'
389 && err.status == 0
390 && (err.readyState == 0 || err.readyState == 4)
391 && (!err.hasOwnProperty('responseText') || err.responseText == '')
392 );
393 }
394
395 /**
396 * Ensures AJAX requests that fail due to connection errors are retried automatically.
397 * This function is made specifically to work with AJAX uploads.
398 */
399 function vboDoAjaxUpload(url, data, success, failure, progress, attempt) {
400 var VBO_AJAX_MAX_ATTEMPTS = 3;
401
402 if (attempt === undefined) {
403 attempt = 1;
404 }
405
406 var settings = {
407 type: 'post',
408 contentType: false,
409 processData: false,
410 cache: false,
411 };
412
413 // register event for upload progress
414 settings.xhr = function() {
415 var xhrobj = jQuery.ajaxSettings.xhr();
416 if (xhrobj.upload) {
417 // attach progress event
418 xhrobj.upload.addEventListener('progress', function(event) {
419 // calculate percentage
420 var percent = 0;
421 var position = event.loaded || event.position;
422 var total = event.total;
423 if (event.lengthComputable) {
424 percent = Math.ceil(position / total * 100);
425 }
426 // trigger callback
427 progress(percent);
428 }, false);
429 }
430 return xhrobj;
431 };
432
433 if (typeof url === 'object') {
434 // configuration object passed
435 Object.assign(settings, url);
436 } else {
437 // use the default settings
438 settings.url = url;
439 }
440
441 // set request data
442 settings.data = data;
443
444 return jQuery.ajax(
445 settings
446 ).done(function(resp) {
447 if (success !== undefined) {
448 // launch success callback function
449 success(resp);
450 }
451 }).fail(function(err) {
452 /**
453 * If the error is caused by a site connection lost, and if the number
454 * of retries is lower than max attempts, retry the same AJAX request.
455 */
456 if (attempt < VBO_AJAX_MAX_ATTEMPTS && vboIsConnectionLostError(err)) {
457 // delay the retry by half second
458 setTimeout(function() {
459 // relaunch same request and increase number of attempts
460 console.log('Retrying previous AJAX request');
461 vboDoAjaxUpload(url, data, success, failure, progress, (attempt + 1));
462 }, 500);
463 } else {
464 // launch the failure callback otherwise
465 if (failure !== undefined) {
466 failure(err);
467 }
468 }
469
470 // always log the error in console
471 console.log('AJAX request failed' + (err.status == 500 ? ' (' + err.responseText + ')' : ''), err);
472 });
473 }
474
475 /**
476 * Updates the progress bar for the current uploading process
477 */
478 function vboUploadSetProgress(selector_suffix, progress) {
479 progress = Math.max(0, progress);
480 progress = Math.min(100, progress);
481
482 var progress_wrap = jQuery('#vbo-paxfield-upload-progress-' + selector_suffix);
483 if (!progress_wrap.length) {
484 return;
485 }
486 progress_wrap.find('.vbo-paxfield-upload-progress').width(progress + '%').html(progress + '%');
487 }
488
489 /**
490 * Uploads the selected document(s)
491 */
492 function vboUploadDocuments(files) {
493 // create form data object
494 var formData = new FormData();
495
496 // set booking and pre-checkin information
497 formData.append('sid', '<?php echo empty($this->order['sid']) && !empty($this->order['idorderota']) ? $this->order['idorderota'] : $this->order['sid']; ?>');
498 formData.append('ts', '<?php echo $this->order['ts']; ?>');
499 formData.append('room_index', vbo_prechin_current_room);
500 formData.append('guest_index', vbo_prechin_current_guest);
501 formData.append('pax_index', vbo_prechin_current_paxk);
502
503 // selector suffix is composed of room, guest and pax field indexes
504 var selector_suffix = vbo_prechin_current_room + '-' + vbo_prechin_current_guest + '-' + vbo_prechin_current_paxk;
505
506 // iterate files selected and append them to the form data
507 for (var i = 0; i < files.length; i++) {
508 formData.append('docs[]', files[i]);
509 }
510
511 // display progress wrap
512 jQuery('#vbo-paxfield-upload-progress-' + selector_suffix).show();
513
514 // AJAX request to upload the files selected
515 vboDoAjaxUpload(
516 // url
517 '<?php echo VikBooking::ajaxUrl(JRoute::rewrite('index.php?option=com_vikbooking&task=precheckin_upload_docs&tmpl=component'.(!empty($pitemid) ? '&Itemid='.$pitemid : ''), false)); ?>',
518 // form data
519 formData,
520 // success callback
521 function(response) {
522 // hide progress wrap
523 jQuery('#vbo-paxfield-upload-progress-' + selector_suffix).hide();
524 // unset progress
525 vboUploadSetProgress(selector_suffix, 0);
526
527 // parse response
528 try {
529 var obj_res = JSON.parse(response),
530 uploaded_urls = [];
531
532 for (var i in obj_res) {
533 if (!obj_res.hasOwnProperty(i) || !obj_res[i].hasOwnProperty('url')) {
534 continue;
535 }
536 uploaded_urls.push(obj_res[i]['url']);
537 }
538 if (!uploaded_urls.length) {
539 console.log('no valid URLs returned', response);
540 return false;
541 }
542 // update hidden field
543 var hidden_inp = jQuery('#vbo-paxfield-curfiles-' + selector_suffix);
544 var current_guest_files = hidden_inp.val().split('|');
545 if (!current_guest_files.length || !current_guest_files[0].length) {
546 current_guest_files = [];
547 }
548 // merge current files with new ones uploaded
549 var new_guest_files = current_guest_files.concat(uploaded_urls);
550 // update hidden input field to contain all files
551 hidden_inp.val(new_guest_files.join('|'));
552 // display links for the newly uploaded files
553 var uploaded_content = '';
554 for (var i = 0; i < uploaded_urls.length; i++) {
555 var furl_segments = uploaded_urls[i].split('/');
556 var guest_fname = furl_segments[(furl_segments.length - 1)];
557 var read_fname = guest_fname.substr((guest_fname.indexOf('_') + 1));
558
559 uploaded_content += '<div class="vbo-paxfield-file-uploaded">';
560 uploaded_content += ' <span class="vbo-paxfield-file-uploaded-rm"><?php VikBookingIcons::e('times-circle'); ?></span>';
561 uploaded_content += ' <a href="' + uploaded_urls[i] + '" target="_blank">';
562 uploaded_content += ' <?php VikBookingIcons::e('image'); ?>';
563 uploaded_content += ' <span>' + read_fname + '</span>';
564 uploaded_content += ' </a>';
565 uploaded_content += '</div>';
566 }
567 // append the new content
568 jQuery('#vbo-paxfield-files-' + selector_suffix).append(uploaded_content);
569
570 // display toast message
571 vboPresentToast(Joomla.JText._('VBO_PRECHECKIN_TOAST_HELP'), 4000, function() {
572 jQuery('html,body').animate({scrollTop: jQuery('.vbo-precheckin-submit').offset().top - 100}, {duration: 400});
573 });
574 } catch(err) {
575 console.error('could not parse JSON response for uploading documents', err, response);
576 }
577 },
578 // failure callback
579 function(error) {
580 alert(Joomla.JText._('VBO_UPLOAD_FAILED'));
581 // hide progress wrap
582 jQuery('#vbo-paxfield-upload-progress-' + selector_suffix).hide();
583 // unset progress
584 vboUploadSetProgress(selector_suffix, 0);
585
586 console.error(error);
587 },
588 // progress callback
589 function(progress) {
590 // update progress bar
591 vboUploadSetProgress(selector_suffix, progress);
592 }
593 );
594 }
595
596 /**
597 * Declare functions for DOM ready
598 */
599 jQuery(function() {
600
601 /**
602 * Datepicker for birth date
603 */
604 jQuery('.vbo-paxfield-datepicker').datepicker({
605 dateFormat: "<?php echo $juidf; ?>",
606 changeMonth: true,
607 changeYear: true,
608 yearRange: "<?php echo (date('Y') - 100) . ':' . date('Y'); ?>"
609 });
610
611 /**
612 * Click event on file-upload button
613 */
614 jQuery('.vbo-precheckin-uploadfile').click(function() {
615 var elem = jQuery(this);
616
617 var room_index = elem.data('roomi'),
618 guest_index = elem.data('guesti'),
619 pax_index = elem.data('paxk');
620
621 // check if device supports file upload
622 if (!vboIsUploadSupported()) {
623 alert('Your device may not support files uploading');
624 return false;
625 }
626
627 // update global vars
628 vbo_prechin_current_room = room_index;
629 vbo_prechin_current_guest = guest_index;
630 vbo_prechin_current_paxk = pax_index;
631
632 // trigger the click event on the hidden input field for the files upload
633 jQuery('#vbo-precheckin-upload-field').trigger('click');
634 });
635
636 /**
637 * Change event on global file-upload hidden field
638 */
639 jQuery('#vbo-precheckin-upload-field').on('change', function(e) {
640 // get files selected
641 var files = jQuery(this)[0].files;
642
643 if (!files || !files.length) {
644 console.error('no files selected for upload');
645 return false;
646 }
647
648 // upload selected files
649 vboUploadDocuments(files);
650
651 // make the input value empty
652 jQuery(this).val(null);
653 });
654
655 /**
656 * Click event on the button to remove an uploaded file
657 */
658 jQuery(document.body).on('click', '.vbo-paxfield-file-uploaded-rm', function() {
659 var file_container = jQuery(this).closest('.vbo-paxfield-file-uploaded');
660 if (!file_container.length) {
661 return false;
662 }
663 var file_url = file_container.find('a').attr('href');
664 var files_selector = file_container.closest('.vbo-paxfield-files').attr('data-gselector');
665 if (confirm(Joomla.JText._('VBO_REMOVEF_CONFIRM'))) {
666 var pax_elem = jQuery('#vbo-paxfield-curfiles-' + files_selector);
667 var pax_urls = pax_elem.val();
668 if (pax_urls.indexOf(file_url + '|') >= 0) {
669 pax_urls = pax_urls.replace(file_url + '|', '');
670 } else if (pax_urls.indexOf('|' + file_url) >= 0) {
671 pax_urls = pax_urls.replace('|' + file_url, '');
672 } else {
673 pax_urls = pax_urls.replace(file_url, '');
674 }
675 // update hidden input value
676 pax_elem.val(pax_urls);
677 // remove the file container
678 file_container.remove();
679 // display toast message
680 vboPresentToast(Joomla.JText._('VBO_PRECHECKIN_TOAST_HELP'), 4000, function() {
681 jQuery('html,body').animate({scrollTop: jQuery('.vbo-precheckin-submit').offset().top - 100}, {duration: 400});
682 });
683 }
684 });
685
686 /**
687 * Change event on input fields to trigger the toast message
688 */
689 jQuery('.vbo-precheckin-room-wrapper').find('input[type="text"], select').on('change', function() {
690 // if toast displayed and clicked, unset listener
691 if (vbo_typingtoast_displayed === true) {
692 jQuery('.vbo-precheckin-room-wrapper').find('input[type="text"], select').off('change');
693 }
694 // increase counter
695 vbo_typingtoast_changes++;
696 if (vbo_typingtoast_changes > 2) {
697 // reset counter
698 vbo_typingtoast_changes = 0;
699 // display toast message
700 vboPresentToast(Joomla.JText._('VBO_PRECHECKIN_TOAST_HELP'), 4000, function() {
701 jQuery('html,body').animate({scrollTop: jQuery('.vbo-precheckin-submit').offset().top - 100}, {duration: 400});
702 // if toast is clicked, we never display it again
703 vbo_typingtoast_displayed = true;
704 });
705 }
706 });
707
708 });
709 </script>
710