PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.9
VikBooking Hotel Booking Engine & PMS v1.6.9
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 / admin / views / calendar / tmpl / default.php

default.php in VikBooking Hotel Booking Engine & PMS 1.6.9, at admin/views/calendar/tmpl/default.php

1,360 lines 51.9 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 $room = $this->room;
14 $allc = $this->allc;
15 $payments = $this->payments;
16 $busy = $this->busy;
17 $vmode = $this->vmode;
18
19 $dbo = JFactory::getDbo();
20 $vbo_app = VikBooking::getVboApplication();
21 $vbo_app->loadSelect2();
22 $vbo_app->loadDatePicker();
23
24 $document = JFactory::getDocument();
25 $document->addStyleSheet(VBO_ADMIN_URI.'resources/jquery.highlighttextarea.min.css');
26 JHtml::fetch('script', VBO_ADMIN_URI.'resources/jquery.highlighttextarea.min.js');
27
28 // JS lang def
29 JText::script('VBFILLCUSTFIELDS');
30 JText::script('VBMSGTHREE');
31 JText::script('VBMSGFOUR');
32 JText::script('VBDBTEXTROOMCLOSED');
33 JText::script('ORDER_NOTES');
34 JText::script('VBSUBMCLOSEROOM');
35 JText::script('VBCUSTINFO');
36 JText::script('VBMAKERESERV');
37 JText::script('VBDAY');
38 JText::script('VBOCALCLOSEOTHERROOMS');
39 JText::script('VBERRCUSTOMEREMAILEXISTS');
40 JText::script('VBAPPLY');
41 JText::script('VBANNULLA');
42 JText::script('VBO_MARK_UNITS_CLOSED');
43
44 $vbo_df = VikBooking::getDateFormat(true);
45 if ($vbo_df == "%d/%m/%Y") {
46 $df = 'd/m/Y';
47 $juidf = 'dd/mm/yy';
48 } elseif ($vbo_df == "%m/%d/%Y") {
49 $df = 'm/d/Y';
50 $juidf = 'mm/dd/yy';
51 } else {
52 $df = 'Y/m/d';
53 $juidf = 'yy/mm/dd';
54 }
55 $datesep = VikBooking::getDateSeparator(true);
56 $prices_vat_included = (int)VikBooking::ivaInclusa();
57
58 $pcheckin = VikRequest::getString('checkin', '', 'request');
59 $pcheckin_ymd = $pcheckin;
60 if (!empty($pcheckin)) {
61 $pcheckin = date(str_replace('%', '', $vbo_df), strtotime($pcheckin));
62 }
63 $pcheckout = VikRequest::getString('checkout', '', 'request');
64 $pcheckout_ymd = $pcheckout;
65 if (!empty($pcheckout)) {
66 $pcheckout = date(str_replace('%', '', $vbo_df), strtotime($pcheckout));
67 }
68
69 $ptmpl = VikRequest::getString('tmpl', '', 'request');
70 $poverview = VikRequest::getInt('overv', '', 'request');
71 $poverview_change = VikRequest::getInt('overview_change', 0, 'request');
72 $padults = VikRequest::getInt('adults', 0, 'request');
73 $pchildren = VikRequest::getInt('children', 0, 'request');
74 $pidprice = VikRequest::getInt('idprice', 0, 'request');
75 $pbooknow = VikRequest::getInt('booknow', 0, 'request');
76
77 /**
78 * Split stay data for booking.
79 *
80 * @since 1.16.0 (J) - 1.6.0 (WP)
81 */
82 $split_stay = VikRequest::getVar('split_stay', array());
83 $rooms_data = [];
84 foreach ($allc as $room_info) {
85 $rooms_data[$room_info['id']] = $room_info['name'];
86 }
87
88 if ($this->new_res_id) {
89 ?>
90 <p class="successmade"><?php echo JText::translate('VBBOOKMADE'); ?> &nbsp;&nbsp;&nbsp; <a href="index.php?option=com_vikbooking&task=editorder&cid[]=<?php echo $this->new_res_id; ?>" target="_blank" class="btn"><i class="vboicn-eye"></i> <?php echo JText::translate('VBOVIEWBOOKINGDET'); ?></a></p>
91 <?php
92 if ($poverview > 0 && $ptmpl == 'component') {
93 $poverview_change = 1;
94 }
95 }
96
97 $timeopst = VikBooking::getTimeOpenStore();
98 if (is_array($timeopst)) {
99 $opent = VikBooking::getHoursMinutes($timeopst[0]);
100 $closet = VikBooking::getHoursMinutes($timeopst[1]);
101 $hcheckin = $opent[0];
102 $mcheckin = $opent[1];
103 $hcheckout = $closet[0];
104 $mcheckout = $closet[1];
105 } else {
106 $hcheckin = 0;
107 $mcheckin = 0;
108 $hcheckout = 0;
109 $mcheckout = 0;
110 }
111 $formatparts = explode(':', VikBooking::getNumberFormatData());
112 $currencysymb = VikBooking::getCurrencySymb(true);
113 $globnumadults = VikBooking::getSearchNumAdults(true);
114 $adultsparts = explode('-', $globnumadults);
115 $seladults = "<select name=\"adults\" id=\"vbo-sel-adults\">\n";
116 for ($i = $adultsparts[0]; $i <= ((int)$adultsparts[1] * $room['units']); $i++) {
117 $seladults .= "<option value=\"".$i."\"".((intval($adultsparts[0]) < 1 && $i == 1 && $padults < 1) || ($padults > 0 && $i == $padults) ? " selected=\"selected\"" : "").">".$i."</option>\n";
118 }
119 $seladults .= "</select>\n";
120 $globnumchildren = VikBooking::getSearchNumChildren(true);
121 $childrenparts = explode('-', $globnumchildren);
122 $selchildren = "<select name=\"children\" id=\"vbo-sel-children\">\n";
123 for ($i = $childrenparts[0]; $i <= ((int)$childrenparts[1] * $room['units']); $i++) {
124 $selchildren .= "<option value=\"".$i."\"" . ($pchildren > 0 && $i == $pchildren ? ' selected="selected"' : '') . ">".$i."</option>\n";
125 }
126 $selchildren .= "</select>\n";
127 $selpayments = '<select name="payment"><option value="">'.JText::translate('VBPAYMUNDEFINED').'</option>';
128 if (is_array($payments) && $payments) {
129 foreach ($payments as $pay) {
130 $selpayments .= '<option value="'.$pay['id'].'">'.$pay['name'].'</option>';
131 }
132 }
133 $selpayments .= '</select>';
134 // custom fields
135 $all_countries = array();
136 $q = "SELECT * FROM `#__vikbooking_custfields` ORDER BY `#__vikbooking_custfields`.`ordering` ASC;";
137 $dbo->setQuery($q);
138 $all_cfields = $dbo->loadAssocList();
139 if ($all_cfields) {
140 $q = "SELECT * FROM `#__vikbooking_countries` ORDER BY `#__vikbooking_countries`.`country_name` ASC;";
141 $dbo->setQuery($q);
142 $all_countries = $dbo->loadAssocList();
143 }
144
145 $wiva = "";
146 $q = "SELECT * FROM `#__vikbooking_iva`;";
147 $dbo->setQuery($q);
148 $ivas = $dbo->loadAssocList();
149 if ($ivas) {
150 foreach ($ivas as $kiv => $iv) {
151 $wiva .= "<option value=\"".$iv['id']."\" data-aliqid=\"".$iv['id']."\"".($kiv < 1 ? ' selected="selected"' : '').">".(empty($iv['name']) ? $iv['aliq']."%" : $iv['name']." - ".$iv['aliq']."%")."</option>\n";
152 }
153 }
154
155 // close other rooms select
156 $closeotherrooms = '';
157 if (count($allc) > 1) {
158 $closeotherrooms = "<select id=\"vbo-calendar-closeall\" multiple=\"multiple\" name=\"closeothers[]\" onchange=\"vboCheckCloseOthers();\">\n";
159 $closeotherrooms .= "<option></option>\n";
160 $closeotherrooms .= "<option value=\"".$room['id']."\" data-currentr=\"true\" disabled=\"disabled\">".$room['name']."</option>\n";
161 $closeotherrooms .= "<option value=\"-1\">- ".JText::translate('VBOCALCLOSEALLROOMSDT')."</option>\n";
162 foreach ($allc as $cc) {
163 if ($cc['id'] == $room['id']) {
164 continue;
165 }
166 $closeotherrooms .= "<option value=\"".$cc['id']."\">".$cc['name']."</option>\n";
167 }
168 $closeotherrooms .= "</select>\n";
169 }
170
171 ?>
172
173 <div class="vbo-admin-container">
174
175 <div class="vbo-config-maintab-left">
176
177 <fieldset class="adminform">
178 <div class="vbo-params-wrap">
179 <legend class="adminlegend">
180 <div class="vbo-quickres-head">
181 <span><?php echo $room['name'] . " - " . JText::translate('VBQUICKBOOK') . (!empty($split_stay) ? ' (' . JText::translate('VBO_SPLIT_STAY') . ')' : ''); ?></span>
182 <div class="vbo-quickres-head-right">
183 <form name="vbchroom" id="vbchroom" method="post" action="index.php?option=com_vikbooking">
184 <input type="hidden" name="task" value="calendar"/>
185 <input type="hidden" name="option" value="com_vikbooking"/>
186 <select id="vbo-calendar-changeroom" name="cid[]" onchange="jQuery('#vbchroom').submit();">
187 <?php
188 foreach ($allc as $cc) {
189 echo "<option value=\"".$cc['id']."\"".($cc['id'] == $room['id'] ? " selected=\"selected\"" : "").">".$cc['name']."</option>\n";
190 }
191 ?>
192 </select>
193 <?php
194 if ($ptmpl == 'component') {
195 echo "<input type=\"hidden\" name=\"tmpl\" value=\"component\" />\n";
196 }
197 ?>
198 </form>
199 </div>
200 </div>
201 </legend>
202 <form name="newb" method="post" action="index.php?option=com_vikbooking" id="vbo-calendar-newb-form">
203 <div class="vbo-params-container">
204 <div class="vbo-param-container">
205 <div class="vbo-param-label"><?php echo JText::translate('VBDATEPICKUP'); ?></div>
206 <div class="vbo-param-setting">
207 <div class="input-append">
208 <input type="text" autocomplete="off" name="checkindate" id="checkindate" size="10" />
209 <button type="button" class="btn vbodatepicker-trig-icon"><span class="icon-calendar"></span></button>
210 </div>
211 <span class="vbo-calendar-time-inline"><?php echo JText::translate('VBAT')." ".($hcheckin < 10 ? '0'.$hcheckin : $hcheckin).":".($mcheckin < 10 ? '0'.$mcheckin : $mcheckin); ?></span>
212 <input type="hidden" name="checkinh" value="<?php echo $hcheckin; ?>"/>
213 <input type="hidden" name="checkinm" value="<?php echo $mcheckin; ?>"/>
214 </div>
215 </div>
216 <div class="vbo-param-container">
217 <div class="vbo-param-label"><?php echo JText::translate('VBDATERELEASE'); ?></div>
218 <div class="vbo-param-setting">
219 <div class="input-append">
220 <input type="text" autocomplete="off" name="checkoutdate" id="checkoutdate" size="10" />
221 <button type="button" class="btn vbodatepicker-trig-icon"><span class="icon-calendar"></span></button>
222 </div>
223 <span class="vbo-calendar-time-inline"><?php echo JText::translate('VBAT')." ".($hcheckout < 10 ? '0'.$hcheckout : $hcheckout).":".($mcheckout < 10 ? '0'.$mcheckout : $mcheckout); ?></span>
224 <span style="display: none; margin-left: 25px; vertical-align: top;" id="vbjstotnights">
225 <span style="font-weight: bold;"><?php echo JText::translate('VBDAYS'); ?></span>
226 <input type="number" min="1" step="1" value="1" id="vbo-numnights" style="margin: 0;" />
227 </span>
228 <input type="hidden" name="checkouth" value="<?php echo $hcheckout; ?>"/>
229 <input type="hidden" name="checkoutm" value="<?php echo $mcheckout; ?>"/>
230 </div>
231 </div>
232 <div class="vbo-param-container" style="<?php echo !empty($split_stay) ? 'display: none;' : ''; ?>">
233 <div class="vbo-param-label">
234 <span class="vbcloseroomsp">
235 <label for="setclosed-on"><?php echo JText::translate('VBCLOSEROOM'); ?> <i class="<?php echo VikBookingIcons::i('ban'); ?>" style="float: none;"></i></label>
236 </span>
237 </div>
238 <div class="vbo-param-setting">
239 <?php echo $vbo_app->printYesNoButtons('setclosed', JText::translate('VBYES'), JText::translate('VBNO'), 0, 1, 0, 'vbCloseRoom();'); ?>
240 <div class="vbo-close-all-rooms-sel" id="vbo-close-all-rooms-sel" style="display: none;"><?php echo $closeotherrooms; ?></div>
241 </div>
242 </div>
243 <?php
244 if ($room['units'] > 1 && empty($split_stay)) {
245 $num_rooms_vals = range(1, $room['units']);
246 $num_rooms_opts = '';
247 foreach ($num_rooms_vals as $nrv) {
248 $num_rooms_opts .= '<option value="'.$nrv.'">'.$nrv.'</option>'."\n";
249 }
250 ?>
251 <div class="vbo-param-container" id="vbo-row-numrooms">
252 <div class="vbo-param-label"><?php echo JText::translate('VBPVIEWROOMSEVEN'); ?></div>
253 <div class="vbo-param-setting">
254 <select name="num_rooms" id="vbo-sel-numrooms">
255 <?php echo $num_rooms_opts; ?>
256 </select>
257 </div>
258 </div>
259 <?php
260 } else {
261 ?>
262 <input type="hidden" name="num_rooms" value="1"/>
263 <?php
264 }
265 ?>
266 <div class="vbo-param-container" id="vbo-row-people">
267 <div class="vbo-param-label"><?php echo JText::translate('VBQUICKRESGUESTS'); ?></div>
268 <div class="vbo-param-setting">
269 <span class="vbo-quickres-aduchi-wrap">
270 <span class="vbo-quickres-aduchi-inlbl"><?php echo JText::translate('VBQUICKADULTS'); ?></span>
271 <?php echo $seladults; ?>
272 </span>
273 <span class="vbo-quickres-aduchi-wrap">
274 <span class="vbo-quickres-aduchi-inlbl"><?php echo JText::translate('VBQUICKCHILDREN'); ?></span>
275 <?php echo $selchildren; ?>
276 </span>
277 </div>
278 </div>
279 <?php
280 if (!empty($split_stay)) {
281 foreach ($split_stay as $sps_k => $sps_v) {
282 ?>
283 <div class="vbo-param-container">
284 <div class="vbo-param-label"><?php echo $sps_k < 1 ? '<i class="' . VikBookingIcons::i('random') . '"></i> ' . JText::translate('VBO_SPLIT_STAY') : ' '; ?></div>
285 <div class="vbo-param-setting">
286 <div class="vbo-cal-splitstay-details">
287 <div class="vbo-cal-splitstay-room">
288 <span class="vbo-cal-splitstay-room-name"><?php VikBookingIcons::e('bed'); ?> <?php echo $rooms_data[$sps_v['idroom']]; ?></span>
289 <span class="vbo-cal-splitstay-room-nights"><?php VikBookingIcons::e('moon'); ?> <?php echo $sps_v['nights']; ?> <?php echo $sps_v['nights'] > 1 ? JText::translate('VBDAYS') : JText::translate('VBDAY'); ?></span>
290 </div>
291 <div class="vbo-cal-splitstay-dates">
292 <span class="vbo-cal-splitstay-dates-in"><?php VikBookingIcons::e('plane-arrival'); ?> <?php echo date(str_replace("/", $datesep, $df), strtotime($sps_v['checkin'])); ?></span>
293 <span class="vbo-cal-splitstay-dates-out"><?php VikBookingIcons::e('plane-departure'); ?> <?php echo date(str_replace("/", $datesep, $df), strtotime($sps_v['checkout'])); ?></span>
294 </div>
295 </div>
296 </div>
297 </div>
298 <?php
299 }
300 }
301 ?>
302 <div class="vbo-param-container"<?php echo ($poverview > 0 ? ' style="display: none;"' : ''); ?> id="vbo-row-bstat">
303 <div class="vbo-param-label"><?php echo JText::translate('VBCALBOOKINGSTATUS'); ?></div>
304 <div class="vbo-param-setting">
305 <select name="newstatus">
306 <option value="confirmed"><?php echo JText::translate('VBCONFIRMED'); ?></option>
307 <option value="standby"><?php echo JText::translate('VBSTANDBY'); ?></option>
308 </select>
309 </div>
310 </div>
311 <div class="vbo-param-container" id="vbo-row-bpay">
312 <div class="vbo-param-label"><?php echo JText::translate('VBCALBOOKINGPAYMENT'); ?></div>
313 <div class="vbo-param-setting">
314 <?php echo $selpayments; ?>
315 </div>
316 </div>
317 <div class="vbo-param-container" id="vbo-row-fillcustfields">
318 <div class="vbo-param-label">&nbsp;</div>
319 <div class="vbo-param-setting">
320 <span class="vbo-assign-customer" id="vbfillcustfields">
321 <i class="<?php echo VikBookingIcons::i('user-circle'); ?>"></i>
322 <span><?php echo JText::translate('VBFILLCUSTFIELDS'); ?></span>
323 </span>
324 </div>
325 </div>
326 <div class="vbo-param-container" id="vbo-row-cmail">
327 <div class="vbo-param-label"><?php echo JText::translate('VBCUSTEMAIL'); ?></div>
328 <div class="vbo-param-setting">
329 <input type="text" name="custmail" id="custmailfield" value="" size="25"/>
330 </div>
331 </div>
332 <div class="vbo-param-container">
333 <div class="vbo-param-label" id="vbcustdatalbl"><?php echo JText::translate('VBCUSTINFO'); ?></div>
334 <div class="vbo-param-setting">
335 <textarea name="custdata" id="vbcustdatatxtarea" rows="5" cols="70" style="min-width: 300px;"></textarea>
336 </div>
337 </div>
338 <div class="vbo-param-container" id="vbo-website-rates-row" style="display: none;">
339 <div class="vbo-param-label"><?php echo JText::translate('VBOWEBSITERATES'); ?></div>
340 <div class="vbo-param-setting" id="vbo-website-rates-cont"></div>
341 </div>
342 <div class="vbo-param-container" id="vbo-row-custcost">
343 <div class="vbo-param-label"><?php echo JText::translate('VBOROOMCUSTRATEPLANADD'); ?></div>
344 <div class="vbo-param-setting">
345 <div class="vbo-calendar-costs-wrapper">
346 <?php echo $currencysymb; ?> <input name="cust_cost" id="cust_cost" value="" onfocus="document.getElementById('taxid').style.display = 'inline-block';" onkeyup="vbCalcDailyCost(this.value);" onchange="vbCalcDailyCost(this.value);" type="number" step="any" min="0">
347 <select class="vbo-calendar-taxid" name="taxid" id="taxid" style="display: none;">
348 <option value=""><?php echo JText::translate('VBNEWOPTFOUR'); ?></option>
349 <?php echo $wiva; ?>
350 </select>
351 <div id="avg-daycost" class="vbo-calendar-avg-daycost" style="display: none;">
352 <select name="totalpnight">
353 <option value="total"></option>
354 <option value="pnight"></option>
355 </select>
356 </div>
357 </div>
358 </div>
359 </div>
360 <div id="vbo-force-bookingdates" class="vbo-param-container" style="display: none;">
361 <div class="vbo-param-label"><?php echo $vbo_app->createPopover(array('title' => JText::translate('VBO_FORCE_BOOKDATES'), 'content' => JText::translate('VBO_FORCE_BOOKDATES_HELP'))); ?> <?php echo JText::translate('VBO_FORCE_BOOKDATES'); ?></div>
362 <div class="vbo-param-setting">
363 <?php echo $vbo_app->printYesNoButtons('forcebooking', JText::translate('VBYES'), JText::translate('VBNO'), 0, 1, 0); ?>
364 <div class="vbo-param-setting-comment"></div>
365 </div>
366 </div>
367 <div class="vbo-param-container">
368 <div class="vbo-param-label">&nbsp;</div>
369 <div class="vbo-param-setting">
370 <button type="submit" id="quickbsubmit" class="btn btn-success btn-large"><i class="icon-save"></i> <span><?php echo JText::translate('VBMAKERESERV'); ?></span></button>
371 </div>
372 </div>
373 </div>
374 <?php
375 if ($poverview > 0) {
376 ?>
377 <input type="hidden" name="overv" value="<?php echo $poverview; ?>" />
378 <?php
379 }
380 if ($ptmpl == 'component') {
381 ?>
382 <input type="hidden" name="tmpl" value="component" />
383 <?php
384 }
385 if (!empty($split_stay)) {
386 // add hidden fields for the split stay booking
387 foreach ($split_stay as $spsk => $sps_room) {
388 foreach ($sps_room as $sps_room_k => $sps_room_v) {
389 ?>
390 <input type="hidden" name="split_stay_data[<?php echo $spsk; ?>][<?php echo $sps_room_k; ?>]" value="<?php echo JHtml::fetch('esc_attr', $sps_room_v); ?>" />
391 <?php
392 }
393 }
394 }
395 ?>
396 <input type="hidden" name="customer_id" value="" id="customer_id_inpfield"/>
397 <input type="hidden" name="countrycode" value="" id="ccode_inpfield"/>
398 <input type="hidden" name="state" value="" id="state_inpfield"/>
399 <input type="hidden" name="t_first_name" value="" id="t_first_name_inpfield"/>
400 <input type="hidden" name="t_last_name" value="" id="t_last_name_inpfield"/>
401 <input type="hidden" name="phone" value="" id="phonefield"/>
402 <input type="hidden" name="idprice" value="" id="booking-idprice"/>
403 <input type="hidden" name="roomcost" value="" id="booking-roomcost"/>
404 <input type="hidden" name="task" value="calendar"/>
405 <input type="hidden" name="cid[]" value="<?php echo $room['id']; ?>"/>
406 <input type="hidden" name="option" value="com_vikbooking" />
407 </form>
408 </div>
409 </fieldset>
410
411 </div>
412
413 <div class="vbo-config-maintab-right">
414 <div class="vbo-avcalendars-wrapper">
415 <div class="vbo-avcalendars-roomphoto">
416 <?php
417 if (is_file(VBO_SITE_PATH . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $room['img'])) {
418 ?>
419 <img alt="Room Image" src="<?php echo VBO_SITE_URI; ?>resources/uploads/<?php echo $room['img']; ?>" />
420 <?php
421 } else {
422 VikBookingIcons::e('image', 'vbo-enormous-icn');
423 }
424 ?>
425 </div>
426 <?php
427 $check = false;
428 if (empty($busy)) {
429 ?>
430 <p class="warn"><?php echo JText::translate('VBNOFUTURERES'); ?></p>
431 <?php
432 } else {
433 $check = true;
434 // build URL for each number of calendar months
435 $base_uri_data = [
436 'option' => 'com_vikbooking',
437 'task' => 'calendar',
438 'cid' => [
439 $room['id']
440 ],
441 'split_stay' => $split_stay,
442 ];
443 if (!empty($pcheckin_ymd) && !empty($pcheckout_ymd)) {
444 $base_uri_data['checkin'] = $pcheckin_ymd;
445 $base_uri_data['checkout'] = $pcheckout_ymd;
446 }
447 if ($padults > 0) {
448 $base_uri_data['adults'] = $padults;
449 $base_uri_data['children'] = $pchildren;
450 }
451 if (!empty($pidprice)) {
452 $base_uri_data['idprice'] = $pidprice;
453 }
454 if (!empty($pbooknow)) {
455 $base_uri_data['booknow'] = $pbooknow;
456 }
457 if ($ptmpl == 'component') {
458 $base_uri_data['tmpl'] = 'component';
459 }
460 ?>
461 <div>
462 <a class="vbmodelink<?php echo $vmode == 3 ? ' vbmodelink-active' : ''; ?>" href="index.php?<?php echo http_build_query(array_merge($base_uri_data, ['vmode' => 3])); ?>"><?php VikBookingIcons::e('calendar'); ?> <span><?php echo JText::translate('VBTHREEMONTHS'); ?></span></a>
463 <a class="vbmodelink<?php echo $vmode == 6 ? ' vbmodelink-active' : ''; ?>" href="index.php?<?php echo http_build_query(array_merge($base_uri_data, ['vmode' => 6])); ?>"><?php VikBookingIcons::e('calendar'); ?> <span><?php echo JText::translate('VBSIXMONTHS'); ?></span></a>
464 <a class="vbmodelink<?php echo $vmode == 12 ? ' vbmodelink-active' : ''; ?>" href="index.php?<?php echo http_build_query(array_merge($base_uri_data, ['vmode' => 12])); ?>"><?php VikBookingIcons::e('calendar'); ?> <span><?php echo JText::translate('VBTWELVEMONTHS'); ?></span></a>
465 <a class="vbmodelink<?php echo $vmode == 24 ? ' vbmodelink-active' : ''; ?>" href="index.php?<?php echo http_build_query(array_merge($base_uri_data, ['vmode' => 24])); ?>"><?php VikBookingIcons::e('calendar'); ?> <span><?php echo JText::translate('VBTWOYEARS'); ?></span></a>
466 </div>
467 <?php
468 }
469 ?>
470 <div class="vbo-calendar-cals-container">
471 <?php
472 $arr = getdate();
473 $mon = $arr['mon'];
474 $year = $arr['year'];
475 $dayts = mktime(0, 0, 0, $mon, 1, $year);
476 $newarr = getdate($dayts);
477
478 $firstwday = (int)VikBooking::getFirstWeekDay();
479 $days_labels = array(
480 JText::translate('VBSUN'),
481 JText::translate('VBMON'),
482 JText::translate('VBTUE'),
483 JText::translate('VBWED'),
484 JText::translate('VBTHU'),
485 JText::translate('VBFRI'),
486 JText::translate('VBSAT')
487 );
488 $days_indexes = array();
489 for ($i = 0; $i < 7; $i++) {
490 $days_indexes[$i] = (6-($firstwday-$i)+1)%7;
491 }
492
493 for ($jj = 1; $jj <= $vmode; $jj++) {
494 $d_count = 0;
495 echo '<div class="vbo-calendar-cal-container">';
496 $cal = "";
497 ?>
498 <table class="vbadmincaltable">
499 <tr class="vbadmincaltrmon">
500 <td colspan="7" align="center"><?php echo VikBooking::sayMonth($newarr['mon'])." ".$newarr['year']; ?></td>
501 </tr>
502 <tr class="vbadmincaltrmdays">
503 <?php
504 for ($i = 0; $i < 7; $i++) {
505 $d_ind = ($i + $firstwday) < 7 ? ($i + $firstwday) : ($i + $firstwday - 7);
506 echo '<td>'.$days_labels[$d_ind].'</td>';
507 }
508 ?>
509 </tr>
510 <tr>
511 <?php
512 for ($i=0, $n = $days_indexes[$newarr['wday']]; $i < $n; $i++, $d_count++) {
513 $cal .= "<td align=\"center\">&nbsp;</td>";
514 }
515 while ($newarr['mon'] == $mon) {
516 if ($d_count > 6) {
517 $d_count = 0;
518 $cal .= "</tr>\n<tr>";
519 }
520 $dclass = "free";
521 $dalt = "";
522 $bid = "";
523 $totfound = 0;
524 if ($check) {
525 foreach ($busy as $b) {
526 $tmpone = getdate($b['checkin']);
527 $ritts = mktime(0, 0, 0, $tmpone['mon'], $tmpone['mday'], $tmpone['year']);
528 $tmptwo = getdate($b['checkout']);
529 $conts = mktime(0, 0, 0, $tmptwo['mon'], $tmptwo['mday'], $tmptwo['year']);
530 if ($newarr[0] >= $ritts && $newarr[0] < $conts) {
531 $dclass = "busy";
532 $bid = $b['idorder'];
533 if ((int)$b['closure']) {
534 $dclass .= " busy-closure";
535 $dalt = JText::translate('VBDBTEXTROOMCLOSED');
536 } elseif ($newarr[0] == $ritts) {
537 $dalt = JText::translate('VBPICKUPAT')." ".date('H:i', $b['checkin']);
538 } elseif ($newarr[0] == $conts) {
539 $dalt = JText::translate('VBRELEASEAT')." ".date('H:i', $b['checkout']);
540 }
541 $totfound++;
542 }
543 }
544 }
545 $useday = ($newarr['mday'] < 10 ? "0".$newarr['mday'] : $newarr['mday']);
546 if ($totfound > 0 && $totfound < $room['units']) {
547 $dclass .= " vbo-partially";
548 }
549 if ($totfound == 1) {
550 $dlnk = "<a href=\"index.php?option=com_vikbooking&task=editbusy&cid[]=".$bid."\"".($ptmpl == 'component' ? ' target="_blank"' : '').">".$useday."</a>";
551 $cal .= "<td align=\"center\" data-daydate=\"".date($df, $newarr[0])."\" class=\"".$dclass."\"".(!empty($dalt) ? " title=\"".$dalt."\"" : "").">".$dlnk."</td>\n";
552 } elseif ($totfound > 1) {
553 $dlnk = "<a href=\"index.php?option=com_vikbooking&task=choosebusy&idroom=".$room['id']."&ts=".$newarr[0]."\"".($ptmpl == 'component' ? ' target="_blank"' : '').">".$useday."</a>";
554 $cal .= "<td align=\"center\" data-daydate=\"".date($df, $newarr[0])."\" class=\"".$dclass."\">".$dlnk."</td>\n";
555 } else {
556 $dlnk = $useday;
557 $cal .= "<td align=\"center\" data-daydate=\"".date($df, $newarr[0])."\" class=\"".$dclass."\">".$dlnk."</td>\n";
558 }
559 $next = $newarr['mday'] + 1;
560 $dayts = mktime(0, 0, 0, $newarr['mon'], $next, $newarr['year']);
561 $newarr = getdate($dayts);
562 $d_count++;
563 }
564
565 for ($i = $d_count; $i <= 6; $i++) {
566 $cal .= "<td align=\"center\">&nbsp;</td>";
567 }
568
569 echo $cal;
570 ?>
571 </tr>
572 </table>
573 <?php
574 echo "</div>";
575 if ($mon == 12) {
576 $mon = 1;
577 $year += 1;
578 $dayts = mktime(0, 0, 0, $mon, 01, $year);
579 } else {
580 $mon += 1;
581 $dayts = mktime(0, 0, 0, $mon, 01, $year);
582 }
583 $newarr = getdate($dayts);
584 }
585 ?>
586 </div>
587 </div>
588 </div>
589
590 </div>
591
592 <div class="vbo-calendar-modal-helper" style="display: none;">
593 <div class="vbo-calendar-cfields-filler">
594 <div class="vbo-calendar-cfields-topcont">
595 <div class="vbo-calendar-cfields-search">
596 <label for="vbo-searchcust"><?php echo JText::translate('VBOSEARCHEXISTCUST'); ?></label>
597 <span id="vbo-searchcust-loading">
598 <i class="vboicn-hour-glass"></i>
599 </span>
600 <input type="text" id="vbo-searchcust" autocomplete="off" value="" placeholder="<?php echo htmlspecialchars(JText::translate('VBOSEARCHCUSTBY')); ?>" size="35" />
601 <div id="vbo-searchcust-res"></div>
602 </div>
603 </div>
604 <div class="vbo-calendar-cfields-inner">
605 <?php
606 foreach ($all_cfields as $cfield) {
607 if ($cfield['type'] == 'text' && $cfield['isphone'] == 1) {
608 ?>
609 <div class="vbo-calendar-cfield-entry">
610 <label for="cfield<?php echo $cfield['id']; ?>" data-fieldid="<?php echo $cfield['id']; ?>"><?php echo JText::translate($cfield['name']); ?></label>
611 <span>
612 <?php
613 echo $vbo_app->printPhoneInputField([
614 'id' => 'cfield' . $cfield['id'],
615 'class' => 'vbo-calendar-cfield-phone',
616 'data-isemail' => '0',
617 'data-isnominative' => '0',
618 'data-isphone' => '1'
619 ], [
620 'fullNumberOnBlur' => true
621 ]);
622 ?>
623 </span>
624 </div>
625 <?php
626 } elseif ($cfield['type'] == 'text') {
627 ?>
628 <div class="vbo-calendar-cfield-entry">
629 <label for="cfield<?php echo $cfield['id']; ?>" data-fieldid="<?php echo $cfield['id']; ?>"><?php echo JText::translate($cfield['name']); ?></label>
630 <span>
631 <input type="text" id="cfield<?php echo $cfield['id']; ?>" data-isemail="<?php echo ($cfield['isemail'] == 1 ? '1' : '0'); ?>" data-isnominative="<?php echo ($cfield['isnominative'] == 1 ? '1' : '0'); ?>" data-isphone="0" value="" size="35"/>
632 </span>
633 </div>
634 <?php
635 } elseif ($cfield['type'] == 'textarea') {
636 ?>
637 <div class="vbo-calendar-cfield-entry">
638 <label for="cfield<?php echo $cfield['id']; ?>" data-fieldid="<?php echo $cfield['id']; ?>"><?php echo JText::translate($cfield['name']); ?></label>
639 <span>
640 <textarea id="cfield<?php echo $cfield['id']; ?>" rows="4" cols="35"></textarea>
641 </span>
642 </div>
643 <?php
644 } elseif ($cfield['type'] == 'country') {
645 ?>
646 <div class="vbo-calendar-cfield-entry">
647 <label for="cfield<?php echo $cfield['id']; ?>" data-fieldid="<?php echo $cfield['id']; ?>"><?php echo JText::translate($cfield['name']); ?></label>
648 <span>
649 <select id="cfield<?php echo $cfield['id']; ?>" class="vbo-calendar-cfield-country">
650 <option value=""> </option>
651 <?php
652 foreach ($all_countries as $country) {
653 ?>
654 <option value="<?php echo $country['country_name']; ?>" data-ccode="<?php echo $country['country_3_code']; ?>" data-c2code="<?php echo $country['country_2_code']; ?>"><?php echo $country['country_name']; ?></option>
655 <?php
656 }
657 ?>
658 </select>
659 </span>
660 </div>
661 <?php
662 } elseif ($cfield['type'] == 'state') {
663 ?>
664 <div class="vbo-calendar-cfield-entry">
665 <label for="cfield<?php echo $cfield['id']; ?>" data-fieldid="<?php echo $cfield['id']; ?>"><?php echo JText::translate($cfield['name']); ?></label>
666 <span>
667 <select id="cfield<?php echo $cfield['id']; ?>" class="vbo-calendar-cfield-state">
668 <option value="">-----</option>
669 </select>
670 </span>
671 </div>
672 <?php
673 }
674 }
675 ?>
676 </div>
677 </div>
678 </div>
679
680 <form action="index.php?option=com_vikbooking" method="post" name="adminForm" id="adminForm">
681 <input type="hidden" name="task" value="" />
682 <input type="hidden" name="option" value="com_vikbooking" />
683 </form>
684
685 <script type="text/javascript">
686 <?php echo ($poverview_change > 0 ? 'window.parent.hasNewBooking = true;' . "\n" : ''); ?>
687 var vbo_glob_sel_nights = 0;
688 var customers_search_vals = "";
689 var prev_tareat = null;
690 var booknowmade = false;
691 var vbo_quickres_has_custdetails = false;
692
693 function vbCloseRoom() {
694 var ckbox = jQuery('input[name="setclosed"]');
695 if (ckbox.length && ckbox.prop('checked')) {
696 jQuery('#vbo-close-all-rooms-sel').show();
697 jQuery('#vbo-row-people').hide();
698 if (jQuery('#vbo-row-numrooms').length) {
699 jQuery('#vbo-row-numrooms').hide();
700 }
701 jQuery('#vbo-row-bstat').hide();
702 jQuery('#vbo-row-custcost').hide();
703 jQuery('#vbo-row-cmail').hide();
704 jQuery('#vbo-row-fillcustfields').hide();
705 jQuery('#vbo-row-bpay').hide();
706 jQuery("#vbo-website-rates-row").hide();
707 if (prev_tareat === null) {
708 // save the previous customer information
709 prev_tareat = jQuery('#vbcustdatatxtarea').val();
710 }
711 jQuery('#vbcustdatatxtarea').val(Joomla.JText._('VBDBTEXTROOMCLOSED'));
712 jQuery('#vbcustdatalbl').text(Joomla.JText._('ORDER_NOTES'));
713 jQuery("#quickbsubmit").removeClass("btn-success").addClass("btn-danger").find("span").text(Joomla.JText._('VBSUBMCLOSEROOM'));
714 // hide force booking and untick checkbox
715 jQuery('#vbo-force-bookingdates').hide();
716 jQuery('input[name="forcebooking"]').prop('checked', false);
717 } else {
718 jQuery('#vbo-close-all-rooms-sel').hide();
719 jQuery('#vbo-row-people').show();
720 if (jQuery('#vbo-row-numrooms').length) {
721 jQuery('#vbo-row-numrooms').show();
722 }
723 jQuery('#vbo-row-bstat').show();
724 jQuery('#vbo-row-custcost').show();
725 jQuery('#vbo-row-cmail').show();
726 jQuery('#vbo-row-fillcustfields').show();
727 jQuery('#vbo-row-bpay').show();
728 jQuery('#vbcustdatatxtarea').val(prev_tareat + "");
729 jQuery('#vbcustdatalbl').text(Joomla.JText._('VBCUSTINFO'));
730 jQuery("#quickbsubmit").removeClass("btn-danger").addClass("btn-success").find("span").text(Joomla.JText._('VBMAKERESERV'));
731 }
732 }
733
734 function showCustomFields() {
735 let modal_body = VBOCore.displayModal({
736 suffix: 'calendar-cfields',
737 extra_class: 'vbo-modal-tall',
738 title: Joomla.JText._('VBFILLCUSTFIELDS'),
739 body_prepend: true,
740 footer_left: '<button type="button" class="btn" onclick="hideCustomFields();">' + Joomla.JText._('VBANNULLA') + '</button>',
741 footer_right: '<button type="button" class="btn btn-success" onclick="applyCustomFieldsContent();"><i class="icon-edit"></i> ' + Joomla.JText._('VBAPPLY') + '</button>',
742 dismiss_event: 'vbo-calendar-cfields-dismiss',
743 onDismiss: () => {
744 jQuery('.vbo-calendar-cfields-filler').appendTo('.vbo-calendar-modal-helper');
745 },
746 });
747
748 jQuery('.vbo-calendar-cfields-filler').appendTo(modal_body);
749
750 setTimeout(function() {
751 jQuery('#vbo-searchcust').focus();
752 }, 500);
753 }
754
755 function hideCustomFields() {
756 VBOCore.emitEvent('vbo-calendar-cfields-dismiss');
757 }
758
759 function applyCustomFieldsContent() {
760 var cfields_cont = "";
761 var cfields_labels = new Array;
762 var nominatives = new Array;
763 var tot_rows = 1;
764 jQuery(".vbo-calendar-cfields-inner .vbo-calendar-cfield-entry").each(function() {
765 var cfield_name = jQuery(this).find("label").text();
766 var cfield_input = jQuery(this).find("span").find("input");
767 var cfield_textarea = jQuery(this).find("span").find("textarea");
768 var cfield_select = jQuery(this).find("span").find("select.vbo-calendar-cfield-country");
769 var cfield_state = jQuery(this).find("span").find("select.vbo-calendar-cfield-state");
770 var cfield_cont = "";
771 if (cfield_input.length) {
772 cfield_cont = cfield_input.val();
773 if (cfield_input.attr("data-isemail") == "1" && cfield_cont && cfield_cont.length) {
774 jQuery("#custmailfield").val(cfield_cont);
775 }
776 if (cfield_input.attr("data-isphone") == "1") {
777 jQuery("#phonefield").val(cfield_cont);
778 }
779 if (cfield_input.attr("data-isnominative") == "1") {
780 nominatives.push(cfield_cont);
781 }
782 } else if (cfield_textarea.length) {
783 cfield_cont = cfield_textarea.val();
784 } else if (cfield_select.length) {
785 cfield_cont = cfield_select.val();
786 if (cfield_cont && cfield_cont.length) {
787 var country_code = jQuery("option:selected", cfield_select).attr("data-ccode");
788 if (country_code.length) {
789 jQuery("#ccode_inpfield").val(country_code);
790 }
791 }
792 } else if (cfield_state.length) {
793 cfield_cont = cfield_state.val();
794 jQuery("#state_inpfield").val(cfield_cont);
795 }
796 if (cfield_cont && cfield_cont.length) {
797 cfields_cont += cfield_name + ": " + cfield_cont + "\r\n";
798 tot_rows++;
799 cfields_labels.push(cfield_name + ":");
800 }
801 });
802 if (cfields_cont.length) {
803 cfields_cont = cfields_cont.replace(/\r\n+$/, "");
804 }
805 if (nominatives.length > 1) {
806 jQuery("#t_first_name_inpfield").val(nominatives[0]);
807 jQuery("#t_last_name_inpfield").val(nominatives[1]);
808 }
809 jQuery("#vbcustdatatxtarea").val(cfields_cont);
810 jQuery("#vbcustdatatxtarea").attr("rows", tot_rows);
811 // highlight custom fields labels
812 if (jQuery('#vbo-highlight-cfields').length) {
813 jQuery("#vbcustdatatxtarea").highlightTextarea('destroy');
814 }
815 jQuery("#vbcustdatatxtarea").highlightTextarea({
816 words: cfields_labels,
817 color: "#ddd",
818 id: "vbo-highlight-cfields"
819 });
820 // end highlight
821 hideCustomFields();
822 // toggle var to detect some values were entered
823 vbo_quickres_has_custdetails = true;
824 }
825
826 function vbCalcNights() {
827 vbo_glob_sel_nights = 0;
828 var vbcheckin = document.getElementById("checkindate").value;
829 var vbcheckout = document.getElementById("checkoutdate").value;
830 if (vbcheckin.length > 0 && vbcheckout.length > 0) {
831 var vbcheckinp = vbcheckin.split("/");
832 var vbcheckoutp = vbcheckout.split("/");
833 var vbo_df = "<?php echo $vbo_df; ?>";
834 if (vbo_df == "%d/%m/%Y") {
835 var vbinmonth = parseInt(vbcheckinp[1]);
836 vbinmonth = vbinmonth - 1;
837 var vbinday = parseInt(vbcheckinp[0], 10);
838 var vbcheckind = new Date(vbcheckinp[2], vbinmonth, vbinday);
839 var vboutmonth = parseInt(vbcheckoutp[1]);
840 vboutmonth = vboutmonth - 1;
841 var vboutday = parseInt(vbcheckoutp[0], 10);
842 var vbcheckoutd = new Date(vbcheckoutp[2], vboutmonth, vboutday);
843 }else if (vbo_df == "%m/%d/%Y") {
844 var vbinmonth = parseInt(vbcheckinp[0]);
845 vbinmonth = vbinmonth - 1;
846 var vbinday = parseInt(vbcheckinp[1], 10);
847 var vbcheckind = new Date(vbcheckinp[2], vbinmonth, vbinday);
848 var vboutmonth = parseInt(vbcheckoutp[0]);
849 vboutmonth = vboutmonth - 1;
850 var vboutday = parseInt(vbcheckoutp[1], 10);
851 var vbcheckoutd = new Date(vbcheckoutp[2], vboutmonth, vboutday);
852 } else {
853 var vbinmonth = parseInt(vbcheckinp[1]);
854 vbinmonth = vbinmonth - 1;
855 var vbinday = parseInt(vbcheckinp[2], 10);
856 var vbcheckind = new Date(vbcheckinp[0], vbinmonth, vbinday);
857 var vboutmonth = parseInt(vbcheckoutp[1]);
858 vboutmonth = vboutmonth - 1;
859 var vboutday = parseInt(vbcheckoutp[2], 10);
860 var vbcheckoutd = new Date(vbcheckoutp[0], vboutmonth, vboutday);
861 }
862 var vbdivider = 1000 * 60 * 60 * 24;
863 var vbints = vbcheckind.getTime();
864 var vboutts = vbcheckoutd.getTime();
865 if (vboutts > vbints) {
866 //var vbnights = Math.ceil((vboutts - vbints) / (vbdivider));
867 var utc1 = Date.UTC(vbcheckind.getFullYear(), vbcheckind.getMonth(), vbcheckind.getDate());
868 var utc2 = Date.UTC(vbcheckoutd.getFullYear(), vbcheckoutd.getMonth(), vbcheckoutd.getDate());
869 var vbnights = Math.ceil((utc2 - utc1) / vbdivider);
870 if (vbnights > 0) {
871 vbo_glob_sel_nights = vbnights;
872 jQuery('#vbjstotnights').show();
873 jQuery("#vbo-numnights").val(vbnights);
874 // update average cost per night
875 vbCalcDailyCost(document.getElementById("cust_cost").value);
876 } else {
877 jQuery('#vbjstotnights').hide();
878 }
879 } else {
880 jQuery('#vbjstotnights').hide();
881 }
882 } else {
883 jQuery('#vbjstotnights').hide();
884 }
885 }
886
887 function vbCalcDailyCost(cur_val) {
888 // trigger calculation of website rates
889 vboCalcWebsiteRates();
890 //
891 if (cur_val.length && !isNaN(cur_val) && vbo_glob_sel_nights > 0) {
892 var cur_float = parseFloat(cur_val);
893 var selopts = jQuery("#avg-daycost").find("select").find("option");
894 // total cost with average cost per night
895 var avg_cost = (cur_float / vbo_glob_sel_nights).toFixed(<?php echo (int)$formatparts[0]; ?>);
896 var avg_cost_str = "<?php echo $currencysymb; ?> " + avg_cost + "/" + Joomla.JText._('VBDAY') + " = <?php echo $currencysymb; ?> " + cur_float.toFixed(<?php echo (int)$formatparts[0]; ?>);
897 selopts.first().text(avg_cost_str);
898 // cost multiplied by number of nights
899 var final_cost = (cur_float * vbo_glob_sel_nights).toFixed(<?php echo (int)$formatparts[0]; ?>);
900 var final_cost_str = "<?php echo $currencysymb; ?> " + cur_float.toFixed(<?php echo (int)$formatparts[0]; ?>) + "/" + Joomla.JText._('VBDAY') + " = <?php echo $currencysymb; ?> " + final_cost;
901 selopts.last().text(final_cost_str);
902 // show drop down
903 jQuery("#avg-daycost").show();
904 } else {
905 jQuery("#avg-daycost").hide();
906 }
907 }
908
909 function vboCalcWebsiteRates() {
910 // unset previously selected rates, if any
911 vboUnsetWebsiteRate();
912 // hide force booking and untick checkbox
913 jQuery('#vbo-force-bookingdates').hide();
914 jQuery('input[name="forcebooking"]').prop('checked', false);
915 //
916 var checkinfdate = jQuery("#checkindate").val();
917 var adults = jQuery("#vbo-sel-adults").val();
918 var children = jQuery("#vbo-sel-children").val();
919 var units = jQuery("#vbo-sel-numrooms").val();
920 if (!checkinfdate.length || vbo_glob_sel_nights < 1 || jQuery("input[name=\"setclosed\"]").is(":checked") || <?php echo !empty($split_stay) ? 'true' : 'false'; ?>) {
921 jQuery("#vbo-website-rates-row").hide();
922 return false;
923 }
924 var jqxhr = jQuery.ajax({
925 type: "POST",
926 url: "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=calc_rates'); ?>",
927 data: {
928 id_room: <?php echo $room['id']; ?>,
929 checkinfdate: checkinfdate,
930 num_nights: vbo_glob_sel_nights,
931 num_adults: adults,
932 num_children: children,
933 units: units,
934 only_rates: 1,
935 tmpl: "component"
936 }
937 }).done(function(resp) {
938 var obj_res = null;
939 try {
940 obj_res = typeof resp === 'string' ? JSON.parse(resp) : resp;
941 } catch(err) {
942 console.error("could not parse JSON response", resp);
943 }
944 if (obj_res === null || !Array.isArray(obj_res)) {
945 jQuery("#vbo-website-rates-row").hide();
946 console.info("invalid JSON response", resp);
947 return false;
948 }
949 if (jQuery("input[name=\"setclosed\"]").is(":checked")) {
950 jQuery("#vbo-website-rates-row").hide();
951 return false;
952 }
953 if (obj_res.hasOwnProperty(1) && obj_res[1] == -1 && !jQuery('input[name="setclosed"]').prop('checked')) {
954 // the room is not available or has no rates, display force booking toggle
955 jQuery('#vbo-force-bookingdates').show();
956 if (typeof obj_res[0] == 'string' && obj_res[0].indexOf('e4j.error') >= 0) {
957 jQuery('#vbo-force-bookingdates').find('.vbo-param-setting-comment').text(obj_res[0].replace('e4j.error.', ''));
958 } else {
959 jQuery('#vbo-force-bookingdates').find('.vbo-param-setting-comment').text('');
960 }
961 }
962 if (!obj_res[0].hasOwnProperty("idprice")) {
963 jQuery("#vbo-website-rates-row").hide();
964 console.log("error in response", resp);
965 return false;
966 }
967 // check whether rates are inclusive of taxes
968 var vbo_tax_included = <?php echo $prices_vat_included; ?>;
969 // display the rates obtained
970 var wrhtml = "";
971 for (var i in obj_res) {
972 if (!obj_res.hasOwnProperty(i)) {
973 continue;
974 }
975 if (!vbo_tax_included && obj_res[i].hasOwnProperty('net') && obj_res[i].hasOwnProperty('fnet')) {
976 obj_res[i]['tot'] = obj_res[i]['net'];
977 obj_res[i]['ftot'] = obj_res[i]['fnet'];
978 }
979 wrhtml += "<div class=\"vbo-cal-wbrate-wrap\" onclick=\"vboSelWebsiteRate(this);\">";
980 wrhtml += "<div class=\"vbo-cal-wbrate-inner\">";
981 wrhtml += "<span class=\"vbo-cal-wbrate-name\" data-idprice=\"" + obj_res[i]['idprice'] + "\">" + obj_res[i]['name'] + "</span>";
982 wrhtml += "<span class=\"vbo-cal-wbrate-cost\" data-cost=\"" + obj_res[i]['tot'] + "\">" + obj_res[i]['ftot'] + "</span>";
983 wrhtml += "</div>";
984 wrhtml += "</div>";
985 }
986 jQuery("#vbo-website-rates-cont").html(wrhtml);
987 jQuery("#vbo-website-rates-row").fadeIn();
988 if (<?php echo $pidprice > 0 && $pbooknow > 0 ? 'true' : 'false'; ?> && !booknowmade) {
989 // we get here by clicking the book-now button from the rates calculator only once
990 booknowmade = true;
991 // trigger the click for the requested rate plan ID
992 jQuery('.vbo-cal-wbrate-name[data-idprice="<?php echo $pidprice; ?>"]').closest('.vbo-cal-wbrate-wrap').trigger('click');
993 }
994 }).fail(function() {
995 jQuery("#vbo-website-rates-row").hide();
996 console.error("Error calculating the rates");
997 });
998 }
999
1000 function vboSelWebsiteRate(elem) {
1001 var rate = jQuery(elem);
1002 var idprice = rate.find('.vbo-cal-wbrate-name').attr('data-idprice');
1003 var cost = rate.find('.vbo-cal-wbrate-cost').attr('data-cost');
1004 var prev_idprice = jQuery('#booking-idprice').val();
1005 // reset all selected classes
1006 jQuery('.vbo-cal-wbrate-wrap').removeClass('vbo-cal-wbrate-wrap-selected');
1007 if (prev_idprice.length && prev_idprice == idprice) {
1008 // rate plan has been de-selected
1009 jQuery('#booking-idprice').val("");
1010 jQuery('#booking-roomcost').val("");
1011 jQuery('#cust_cost').attr('readonly', false);
1012 } else {
1013 // rate plan has been selected
1014 rate.addClass('vbo-cal-wbrate-wrap-selected');
1015 jQuery('#booking-idprice').val(idprice);
1016 jQuery('#booking-roomcost').val(cost);
1017 jQuery('#cust_cost').attr('readonly', true);
1018 }
1019 }
1020
1021 function vboUnsetWebsiteRate() {
1022 jQuery('#booking-idprice').val("");
1023 jQuery('#booking-roomcost').val("");
1024 jQuery('.vbo-cal-wbrate-wrap').removeClass('vbo-cal-wbrate-wrap-selected');
1025 jQuery('#cust_cost').attr('readonly', false);
1026 }
1027
1028 function vboReloadStates(country_3_code) {
1029 var states_elem = jQuery('select.vbo-calendar-cfield-state');
1030
1031 // unset the current states/provinces
1032 states_elem.html('');
1033
1034 if (!country_3_code || !country_3_code.length) {
1035 return;
1036 }
1037
1038 // make a request to load the states/provinces of the selected country
1039 VBOCore.doAjax(
1040 "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=states.load_from_country'); ?>",
1041 {
1042 country_3_code: country_3_code,
1043 tmpl: "component"
1044 },
1045 (response) => {
1046 try {
1047 var obj_res = typeof response === 'string' ? JSON.parse(response) : response;
1048 if (!obj_res) {
1049 console.error('Unexpected JSON response', obj_res);
1050 return false;
1051 }
1052
1053 // append empty value
1054 states_elem.append('<option value="">-----</option>');
1055
1056 for (var i = 0; i < obj_res.length; i++) {
1057 // append state
1058 states_elem.append('<option value="' + obj_res[i]['state_2_code'] + '">' + obj_res[i]['state_name'] + '</option>');
1059 }
1060 } catch(err) {
1061 console.error('could not parse JSON response', err, response);
1062 }
1063 },
1064 (error) => {
1065 console.error(error);
1066 }
1067 );
1068 }
1069
1070 jQuery(function() {
1071
1072 jQuery('.vbo-calendar-cfield-country').on('change', function() {
1073 // trigger event for phone number
1074 jQuery('.vbo-calendar-cfield-phone').trigger('vboupdatephonenumber', jQuery(this).find('option:selected').attr('data-c2code'));
1075 // reload state/province
1076 vboReloadStates(jQuery(this).find('option:selected').attr('data-ccode'));
1077 });
1078
1079 jQuery('td.free').click(function() {
1080 var indate = jQuery('#checkindate').val();
1081 var outdate = jQuery('#checkoutdate').val();
1082 var clickdate = jQuery(this).attr('data-daydate');
1083 if (!(indate.length > 0)) {
1084 jQuery('#checkindate').datepicker("setDate", clickdate);
1085 } else if (!(outdate.length > 0) && clickdate != indate) {
1086 jQuery('#checkoutdate').datepicker("setDate", clickdate);
1087 } else {
1088 jQuery('#checkoutdate').datepicker("setDate", '');
1089 jQuery('#checkindate').datepicker("setDate", clickdate);
1090 }
1091 jQuery(".ui-datepicker-current-day").click();
1092 });
1093
1094 jQuery("#quickbsubmit").click(function() {
1095 setTimeout(function() {
1096 jQuery(this).prop('disabled', true);
1097 }, 200);
1098 });
1099
1100 jQuery('#vbo-calendar-newb-form').on('submit', function() {
1101 if (!document.newb.checkindate.value.match(/\S/)) {
1102 alert(Joomla.JText._('VBMSGTHREE'));
1103 jQuery('#quickbsubmit').prop('disabled', false);
1104 return false;
1105 }
1106
1107 if (!document.newb.checkoutdate.value.match(/\S/)) {
1108 alert(Joomla.JText._('VBMSGFOUR'));
1109 jQuery('#quickbsubmit').prop('disabled', false);
1110 return false;
1111 }
1112
1113 jQuery('#quickbsubmit').prop('disabled', true);
1114
1115 if (!jQuery(this).find('[name="setclosed"]').prop('checked') && !jQuery(this).find('[name="custmail"]').val() && !vbo_quickres_has_custdetails && <?php echo $room['units'] > 1 ? 'true' : 'false'; ?>) {
1116 // no closure, no customer email, multiple units, ask if the units should be marked as closed
1117 if (confirm(Joomla.JText._('VBO_MARK_UNITS_CLOSED'))) {
1118 // append hidden field to form
1119 jQuery(this).append('<input type="hidden" name="setunitsclosed" value="1" />');
1120 // check if "room closed" should be added
1121 if (!jQuery('#vbcustdatatxtarea').val()) {
1122 jQuery('#vbcustdatatxtarea').val(Joomla.JText._('VBDBTEXTROOMCLOSED'));
1123 }
1124 }
1125 }
1126
1127 return true;
1128 });
1129
1130 jQuery("#vbo-calendar-changeroom").select2();
1131 if (jQuery("#vbo-calendar-closeall").length) {
1132 jQuery("#vbo-calendar-closeall").select2({placeholder: "- " + Joomla.JText._('VBOCALCLOSEOTHERROOMS') + " -", width: "300px"});
1133 }
1134
1135 jQuery("#vbo-sel-numrooms, #vbo-sel-adults").change(function() {
1136 vboCalcWebsiteRates();
1137 });
1138
1139 jQuery('.vbo-calendar-cfield-entry input[data-isemail="1"]').first().blur(function() {
1140 var curemail = jQuery(this).val();
1141 if (curemail.length) {
1142 var jqxhr = jQuery.ajax({
1143 type: "POST",
1144 url: "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=searchcustomer'); ?>",
1145 data: {
1146 kw: curemail,
1147 email: 1,
1148 tmpl: "component"
1149 }
1150 }).done(function(cont) {
1151 try {
1152 var obj_res = typeof cont === 'string' ? JSON.parse(cont) : cont;
1153 alert(Joomla.JText._('VBERRCUSTOMEREMAILEXISTS') + " (" + obj_res['first_name'] + " " + obj_res['last_name'] + ")");
1154 } catch(e) {
1155 console.error(e);
1156 }
1157 }).fail(function() {
1158 console.log("Error searching for existing email");
1159 });
1160 }
1161 });
1162
1163 jQuery("#vbfillcustfields").click(function() {
1164 showCustomFields();
1165 });
1166
1167 // search customer - start
1168 var vbocustsdelay = (function() {
1169 var timer = 0;
1170 return function(callback, ms) {
1171 clearTimeout (timer);
1172 timer = setTimeout(callback, ms);
1173 };
1174 })();
1175
1176 function vboCustomerSearch(words) {
1177 jQuery("#vbo-searchcust-res").hide().html("");
1178 jQuery("#vbo-searchcust-loading").show();
1179 var jqxhr = jQuery.ajax({
1180 type: "POST",
1181 url: "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=searchcustomer'); ?>",
1182 data: {
1183 kw: words,
1184 tmpl: "component"
1185 }
1186 }).done(function(cont) {
1187 if (cont) {
1188 var obj_res = typeof cont === 'string' ? JSON.parse(cont) : cont;
1189 customers_search_vals = obj_res[0];
1190 jQuery("#vbo-searchcust-res").html(obj_res[1]);
1191 } else {
1192 customers_search_vals = "";
1193 jQuery("#vbo-searchcust-res").html("----");
1194 }
1195 jQuery("#vbo-searchcust-res").show();
1196 jQuery("#vbo-searchcust-loading").hide();
1197 }).fail(function() {
1198 jQuery("#vbo-searchcust-loading").hide();
1199 alert("Error searching");
1200 });
1201 }
1202
1203 jQuery("#vbo-searchcust").keyup(function(event) {
1204 vbocustsdelay(function() {
1205 var keywords = jQuery("#vbo-searchcust").val();
1206 var chars = keywords.length;
1207 if (chars > 1) {
1208 if ((event.which > 96 && event.which < 123) || (event.which > 64 && event.which < 91) || event.which == 13) {
1209 vboCustomerSearch(keywords);
1210 }
1211 } else {
1212 if (jQuery("#vbo-searchcust-res").is(":visible")) {
1213 jQuery("#vbo-searchcust-res").hide();
1214 }
1215 }
1216 }, 600);
1217 });
1218 // search customer - end
1219
1220 // datepickers - start
1221 jQuery("#checkindate").datepicker({
1222 showOn: "focus",
1223 dateFormat: "<?php echo $juidf; ?>",
1224 numberOfMonths: 1,
1225 onSelect: function(selectedDate) {
1226 var nownights = parseInt(jQuery("#vbo-numnights").val());
1227 var nowcheckin = jQuery("#checkindate").datepicker("getDate");
1228 var nowcheckindate = new Date(nowcheckin.getTime());
1229 nowcheckindate.setDate(nowcheckindate.getDate() + nownights);
1230 jQuery("#checkoutdate").datepicker("option", "minDate", nowcheckindate);
1231 jQuery("#checkoutdate").datepicker("setDate", nowcheckindate);
1232 vbCalcNights();
1233 }
1234 });
1235 jQuery("#checkoutdate").datepicker({
1236 showOn: "focus",
1237 dateFormat: "<?php echo $juidf; ?>",
1238 numberOfMonths: 1,
1239 onSelect: function(selectedDate) {
1240 vbCalcNights();
1241 }
1242 });
1243 jQuery(".vbodatepicker-trig-icon").click(function(){
1244 var jdp = jQuery(this).prev("input.hasDatepicker");
1245 if (jdp.length) {
1246 jdp.focus();
1247 }
1248 });
1249 jQuery("#vbo-numnights").on("change keyup", function() {
1250 if (!jQuery("#checkindate").length) {
1251 return;
1252 }
1253 var nownights = parseInt(jQuery(this).val());
1254 var nowcheckin = jQuery("#checkindate").datepicker("getDate");
1255 var nowcheckindate = new Date(nowcheckin.getTime());
1256 nowcheckindate.setDate(nowcheckindate.getDate() + nownights);
1257 jQuery("#checkoutdate").datepicker("option", "minDate", nowcheckindate);
1258 jQuery("#checkoutdate").datepicker("setDate", nowcheckindate);
1259 vbo_glob_sel_nights = nownights;
1260 // update average cost per night
1261 vbCalcDailyCost(document.getElementById("cust_cost").value);
1262 });
1263 // datepickers - end
1264 <?php echo (!empty($pcheckin) ? 'jQuery("#checkindate").datepicker("setDate", "'.$pcheckin.'");'."\n" : ''); ?>
1265 <?php echo (!empty($pcheckout) ? 'jQuery("#checkoutdate").datepicker("setDate", "'.$pcheckout.'");'."\n" : ''); ?>
1266 <?php echo (!empty($pcheckin) || !empty($pcheckout) ? 'jQuery(".ui-datepicker-current-day").click();'."\n" : ''); ?>
1267 });
1268
1269 jQuery(document).on("click", ".vbo-custsearchres-entry", function() {
1270 var custid = jQuery(this).attr("data-custid");
1271 var custemail = jQuery(this).attr("data-email");
1272 var custphone = jQuery(this).attr("data-phone");
1273 var custcountry = jQuery(this).attr("data-country");
1274 var custfirstname = jQuery(this).attr("data-firstname");
1275 var custlastname = jQuery(this).attr("data-lastname");
1276 jQuery("#customer_id_inpfield").val(custid);
1277 if (customers_search_vals.hasOwnProperty(custid)) {
1278 jQuery.each(customers_search_vals[custid], function(cfid, cfval) {
1279 var fill_field = jQuery("#cfield"+cfid);
1280 if (fill_field.length) {
1281 fill_field.val(cfval);
1282 }
1283 });
1284 } else {
1285 jQuery("input[data-isnominative=\"1\"]").each(function(k, v) {
1286 if (k == 0) {
1287 jQuery(this).val(custfirstname);
1288 return true;
1289 }
1290 if (k == 1) {
1291 jQuery(this).val(custlastname);
1292 return true;
1293 }
1294 return false;
1295 });
1296 jQuery("input[data-isemail=\"1\"]").val(custemail);
1297 jQuery("input[data-isphone=\"1\"]").val(custphone).trigger('vboupdatephonenumber');
1298 // populate main calendar form
1299 jQuery("#custmailfield").val(custemail);
1300 jQuery("#t_first_name_inpfield").val(custfirstname);
1301 jQuery("#t_last_name_inpfield").val(custlastname);
1302 //
1303 }
1304 applyCustomFieldsContent();
1305 if (custcountry.length) {
1306 jQuery("#ccode_inpfield").val(custcountry);
1307 }
1308 if (custphone.length) {
1309 jQuery("#phonefield").val(custphone);
1310 }
1311 });
1312
1313 var vborefreshingsel = false;
1314 function vboCheckCloseOthers() {
1315 if (!jQuery("#vbo-calendar-closeall").length || vborefreshingsel) {
1316 // avoid recursion loop by triggering the change event for select2
1317 return;
1318 }
1319 var selall = jQuery('#vbo-calendar-closeall option[value="-1"]').is(':selected');
1320 // always select the current room unless all get de-selected
1321 var optselected = jQuery('#vbo-calendar-closeall option:selected');
1322 var none_sel = !optselected.length ? true : false;
1323 if (optselected.length === 1 && optselected.first().attr('data-currentr')) {
1324 none_sel = true;
1325 }
1326 var curropt = jQuery('#vbo-calendar-closeall option[data-currentr="true"]');
1327 if (!none_sel) {
1328 curropt.prop('selected', true);
1329 curropt.prop('disabled', true);
1330 } else {
1331 curropt.prop('selected', false);
1332 curropt.prop('disabled', true);
1333 }
1334 //
1335 jQuery('#vbo-calendar-closeall').find('option').each(function() {
1336 var curval = jQuery(this).val();
1337 var curroom = jQuery(this).attr('data-currentr');
1338 if (!curval.length || curval == '-1' || curroom) {
1339 return true;
1340 }
1341 if (selall) {
1342 jQuery(this).prop('disabled', true);
1343 jQuery(this).prop('selected', false);
1344 } else {
1345 jQuery(this).prop('disabled', false);
1346 }
1347 });
1348 vboRefreshCloseOthers();
1349 }
1350
1351 function vboRefreshCloseOthers() {
1352 // prevent recursion loop
1353 vborefreshingsel = true;
1354 jQuery("#vbo-calendar-closeall").trigger('change');
1355 setTimeout(function() {
1356 vborefreshingsel = false;
1357 }, 200);
1358 }
1359 </script>
1360