PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.7.2
VikBooking Hotel Booking Engine & PMS v1.7.2
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 / booking / tmpl / default_upgrade.php

default_upgrade.php in VikBooking Hotel Booking Engine & PMS 1.7.2, at site/views/booking/tmpl/default_upgrade.php

324 lines 11.2 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
15 $currencysymb = VikBooking::getCurrencySymb();
16 $pitemid = VikRequest::getInt('Itemid', 0, 'request');
17 $room_upgrade_trigger = VikRequest::getInt('room_upgrade', 0, 'request');
18
19 $upgrade_options = VBORoomHelper::getInstance([
20 'booking' => $this->ord,
21 'rooms' => $this->orderrooms,
22 ], true)->getUpgradeOptions($this->vbo_tn);
23
24 if ($upgrade_options) {
25 /**
26 * Include the VBOCore JS class.
27 */
28 $document->addScript(VBO_ADMIN_URI . 'resources/vbocore.js');
29
30 // load JS lang strings
31 JText::script('VBO_UPGRADE_ROOMS');
32 JText::script('VBO_DOUPGRADE_CONFIRM');
33 JText::script('VBOREVIEWGENERROR');
34
35 // find the first and last booking-room index suited for upgrade
36 $first_oroom_index = 0;
37 foreach ($upgrade_options['upgrade'] as $upgk => $upgv) {
38 $first_oroom_index = $upgk;
39 break;
40 }
41 $last_oroom_index = max(array_keys($upgrade_options['upgrade']));
42
43 ?>
44 <div class="vbo-booking-mod-container">
45 <div class="vbo-booking-mod-inner">
46 <div class="vbo-booking-mod-cmd vbo-booking-roomupgrade-cmd">
47 <a href="JavaScript: void(0);" onclick="vboDisplayUpgradeOptions();"><?php VikBookingIcons::e('gem'); ?> <?php echo JText::translate('VBO_UPGRADE_ROOMS'); ?></a>
48 </div>
49 </div>
50 </div>
51
52 <div id="vbo-hidden-roomupgrade-target" style="display: none;">
53 <div class="vbo-roomupgrade-wrapper">
54 <?php
55 foreach ($upgrade_options['upgrade'] as $upgk => $upg_data) {
56 ?>
57 <div class="vbo-roomupgrade-booked-room" data-upgindex="<?php echo $upgk; ?>" style="<?php echo $upgk != $first_oroom_index ? 'display: none;' : ''; ?>">
58 <div class="vbo-roomupgrade-booked-room-inner">
59 <div class="vbo-roomupgrade-current-wrap">
60 <div class="vbo-roomupgrade-current-cont">
61 <div class="vbo-roomupgrade-current-info">
62 <?php
63 if (!empty($this->orderrooms[$upgk]['img'])) {
64 ?>
65 <img src="<?php echo VBO_SITE_URI; ?>resources/uploads/<?php echo $this->orderrooms[$upgk]['img']; ?>"/>
66 <?php
67 }
68 ?>
69 <div class="vbo-roomupgrade-current-name"><?php echo $this->orderrooms[$upgk]['name']; ?></div>
70 </div>
71 <div class="vbo-roomupgrade-current-pricing">
72 <div class="vbo-roomupgrade-current-pricing-stay">
73 <div class="vbo-roomupgrade-current-pricing-det vbo-roomupgrade-current-pricing-nights"><?php VikBookingIcons::e('moon', 'vbo-pref-color-text'); ?> <?php echo $this->ord['days']; ?></div>
74 <div class="vbo-roomupgrade-current-pricing-det vbo-roomupgrade-current-pricing-adults"><?php VikBookingIcons::e('male', 'vbo-pref-color-text'); ?> <?php echo $this->orderrooms[$upgk]['adults']; ?></div>
75 <?php
76 if ($this->orderrooms[$upgk]['children'] > 0) {
77 ?>
78 <div class="vbo-roomupgrade-current-pricing-det vbo-roomupgrade-current-pricing-children"><?php VikBookingIcons::e('child', 'vbo-pref-color-text'); ?> <?php echo $this->orderrooms[$upgk]['children']; ?></div>
79 <?php
80 }
81 ?>
82 </div>
83 <?php
84 // current room cost
85 $room_cost = $this->orderrooms[$upgk]['cust_cost'] > 0 ? (float)$this->orderrooms[$upgk]['cust_cost'] : (float)$this->orderrooms[$upgk]['room_cost'];
86 ?>
87 <div class="vbo-roomupgrade-current-pricing-det vbo-roomupgrade-current-pricing-cost">
88 <span class="vbo_currency vbo_keepcost"><?php echo $currencysymb; ?></span>
89 <span class="vbo_price vbo_keepcost"><?php echo VikBooking::numberFormat($room_cost); ?></span>
90 </div>
91 </div>
92 </div>
93 <div class="vbo-roomupgrade-current-keep">
94 <button type="button" class="btn vbo-pref-color-btn-secondary" onclick="vboUpgradeNavigate();"><?php echo JText::translate('VBO_KEEP_ROOM'); ?></button>
95 </div>
96 </div>
97 <div class="vbo-roomupgrade-solutions-wrap">
98 <?php
99 foreach ($upg_data['r_costs'] as $rid => $upgrade_sol) {
100 ?>
101 <div class="vbo-roomupgrade-solution-cont">
102 <div class="vbo-roomupgrade-solution-data">
103 <div class="vbo-roomupgrade-solution-info">
104 <div class="vbo-roomupgrade-solution-info-main">
105 <?php
106 if (!empty($upgrade_options['rooms'][$rid]['img'])) {
107 ?>
108 <img src="<?php echo VBO_SITE_URI; ?>resources/uploads/<?php echo $upgrade_options['rooms'][$rid]['img']; ?>"/>
109 <?php
110 }
111 ?>
112 <div class="vbo-roomupgrade-solution-name">
113 <a href="<?php echo JRoute::rewrite('index.php?option=com_vikbooking&view=roomdetails&roomid=' . $rid . (!empty($pitemid) ? '&Itemid='.$pitemid : '')); ?>" target="_blank"><?php echo $upgrade_options['rooms'][$rid]['name']; ?></a>
114 </div>
115 </div>
116 <?php
117 if (!empty($upgrade_options['rooms'][$rid]['smalldesc'])) {
118 ?>
119 <div class="vbo-roomupgrade-solution-descr"><?php echo $upgrade_options['rooms'][$rid]['smalldesc']; ?></div>
120 <?php
121 }
122 ?>
123 </div>
124 <?php
125 if ($room_cost < $upgrade_sol['upgrade_cost']) {
126 ?>
127 <div class="vbo-roomupgrade-solution-pricing">
128 <div class="vbo-roomupgrade-solution-upgrade-cost">
129 <span class="vbo_currency vbo_keepcost"><?php echo $currencysymb; ?></span>
130 <span class="vbo_price vbo_keepcost"><?php echo VikBooking::numberFormat($upgrade_sol['upgrade_cost']); ?></span>
131 </div>
132 <?php
133 if (isset($upg_data['discount']) && $upg_data['discount'] > 0) {
134 ?>
135 <div class="vbo-roomupgrade-solution-upgrade-saveamount">
136 <span class="vbo_currency vbo_keepcost"><?php echo $currencysymb; ?></span>
137 <del class="vbo_price vbo_keepcost"><?php echo VikBooking::numberFormat($upgrade_sol['cost']); ?></del>
138 </div>
139 <div class="vbo-roomupgrade-solution-upgrade-savepcent">
140 <span><?php echo JText::sprintf('VBO_YOU_SAVE_PCENT', $upg_data['discount'] . '%'); ?></span>
141 </div>
142 <?php
143 }
144 ?>
145 </div>
146 <?php
147 }
148 ?>
149 </div>
150 <div class="vbo-roomupgrade-solution-confirm">
151 <button type="button" class="btn vbo-pref-color-btn" onclick="vboDoUpgrade('<?php echo $rid; ?>');"><?php echo JText::translate('VBO_UPGRADE_CONFIRM'); ?></button>
152 </div>
153 </div>
154 <?php
155 }
156 ?>
157 </div>
158 </div>
159 </div>
160 <?php
161 }
162 ?>
163 <?php
164 // echo 'Debug<pre>' . print_r($upgrade_options, true) . '</pre>';
165 ?>
166 </div>
167 </div>
168
169 <?php
170 // modal loading body
171 $loading_body = '<i class="' . VikBookingIcons::i('circle-notch', 'fa-spin fa-fw') . '"></i>';
172
173 // total rooms supporting an upgrade
174 $tot_upgrades = count($upgrade_options['upgrade']);
175
176 // AJAX upgrade URL
177 $ajax_upgrade_url = VikBooking::ajaxUrl(JRoute::rewrite('index.php?option=com_vikbooking&task=upgrade_room' . (!empty($pitemid) ? '&Itemid='.$pitemid : ''), false));
178
179 $document->addScriptDeclaration(
180 <<<JS
181 var vbo_oroom_index = $first_oroom_index;
182 var vbo_upgrade_reload = false;
183
184 function vboDisplayUpgradeOptions() {
185 // number of upgrade steps
186 var vbo_tot_upgrade_steps = $tot_upgrades;
187 var vbo_upgrade_steps_count = '';
188 if (vbo_tot_upgrade_steps > 1) {
189 vbo_upgrade_steps_count = jQuery('<span></span>').addClass('vbo-modal-upgrade-step-counter').html(' (<span class="vbo-modal-upgrade-step-current">1</span>/$tot_upgrades)');
190 }
191
192 // display modal
193 var upgrade_modal_body = VBOCore.displayModal({
194 suffix: 'roomupgrade',
195 title: jQuery('<span></span>').text(Joomla.JText._('VBO_UPGRADE_ROOMS')).append(vbo_upgrade_steps_count),
196 body: '',
197 dismiss_event: 'vbo-dismiss-modal-roomupgrade',
198 onDismiss: () => {
199 vboDismissUpgradeOptions();
200 },
201 loading_event: 'vbo-loading-modal-roomupgrade',
202 loading_body: '$loading_body',
203 });
204
205 // move content to modal body
206 jQuery('.vbo-roomupgrade-wrapper').appendTo(upgrade_modal_body);
207 }
208
209 function vboHideUpgradeOptions() {
210 // hide and dismiss modal
211 VBOCore.emitEvent('vbo-dismiss-modal-roomupgrade');
212 }
213
214 function vboDismissUpgradeOptions() {
215 // move modal content (modal wrapper already dismissed)
216 jQuery('.vbo-roomupgrade-wrapper').appendTo(jQuery('#vbo-hidden-roomupgrade-target'));
217
218 // reset index and display status
219 vbo_oroom_index = $first_oroom_index;
220 jQuery('.vbo-roomupgrade-booked-room').hide();
221 jQuery('.vbo-roomupgrade-booked-room[data-upgindex="' + vbo_oroom_index + '"]').show();
222
223 // check for page refresh flag
224 if (vbo_upgrade_reload) {
225 document.location.href = jQuery('.vbo-current-booking-uri').first().attr('href');
226 }
227
228 return;
229 }
230
231 function vboUpgradeNavigate() {
232 if ($tot_upgrades < 2) {
233 // just one room supporting the upgrade
234 return vboHideUpgradeOptions();
235 }
236
237 // find the next upgrade index, if any
238 for (let find_index = ++vbo_oroom_index; find_index <= $last_oroom_index; find_index++) {
239 if (jQuery('.vbo-roomupgrade-booked-room[data-upgindex="' + find_index + '"]').length) {
240 vbo_oroom_index = find_index;
241 break;
242 }
243 }
244 if (!jQuery('.vbo-roomupgrade-booked-room[data-upgindex="' + vbo_oroom_index + '"]').length) {
245 // next upgrade not found
246 return vboHideUpgradeOptions();
247 }
248
249 // display next slide
250 jQuery('.vbo-roomupgrade-booked-room').hide();
251 jQuery('.vbo-roomupgrade-booked-room[data-upgindex="' + vbo_oroom_index + '"]').fadeIn();
252
253 // increase slide counter
254 var current_step_index = jQuery('.vbo-roomupgrade-booked-room').index(jQuery('.vbo-roomupgrade-booked-room[data-upgindex="' + vbo_oroom_index + '"]'));
255 jQuery('.vbo-modal-upgrade-step-current').text(++current_step_index);
256 }
257
258 function vboDoUpgrade(rid) {
259 if (!confirm(Joomla.JText._('VBO_DOUPGRADE_CONFIRM')) || !rid) {
260 return false;
261 }
262
263 // show loading
264 VBOCore.emitEvent('vbo-loading-modal-roomupgrade');
265
266 // perform the request
267 VBOCore.doAjax(
268 "$ajax_upgrade_url",
269 {
270 bid: '{$this->ord['id']}',
271 sid: '{$this->ord['sid']}',
272 ts: '{$this->ord['ts']}',
273 room_index: vbo_oroom_index,
274 room_id: rid,
275 tmpl: "component"
276 },
277 (response) => {
278 // hide loading
279 VBOCore.emitEvent('vbo-loading-modal-roomupgrade');
280 try {
281 // make sure the response was successful
282 var obj_res = typeof response === 'string' ? JSON.parse(response) : response;
283 if (!obj_res || !obj_res.hasOwnProperty('success') || !obj_res['success']) {
284 alert(obj_res.hasOwnProperty('error') ? obj_res['error'] : Joomla.JText._('VBOREVIEWGENERROR'));
285 return false;
286 }
287
288 // turn flag on for reloading the booking when the modal gets dismissed
289 vbo_upgrade_reload = true;
290
291 // navigate to next room, or close the modal if none
292 return vboUpgradeNavigate();
293 } catch(err) {
294 // display an error
295 alert(Joomla.JText._('VBOREVIEWGENERROR'));
296 // log the error
297 console.error('could not parse JSON response', err, response);
298 }
299 },
300 (error) => {
301 // hide loading
302 VBOCore.emitEvent('vbo-loading-modal-roomupgrade');
303 // display the error
304 alert(error.responseText || Joomla.JText._('VBOREVIEWGENERROR'));
305 }
306 );
307 }
308 JS
309 );
310
311 if ($room_upgrade_trigger) {
312 // trigger the opening of the room upgrade modal when page loads
313 ?>
314 <script type="text/javascript">
315 jQuery(function() {
316 setTimeout(() => {
317 vboDisplayUpgradeOptions();
318 }, 500);
319 });
320 </script>
321 <?php
322 }
323 }
324