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 / admin / views / calendar / tmpl / default.php

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

1,353 lines 51.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 $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
692 function vbCloseRoom() {
693 var ckbox = jQuery('input[name="setclosed"]');
694 if (ckbox.length && ckbox.prop('checked')) {
695 jQuery('#vbo-close-all-rooms-sel').show();
696 jQuery('#vbo-row-people').hide();
697 if (jQuery('#vbo-row-numrooms').length) {
698 jQuery('#vbo-row-numrooms').hide();
699 }
700 jQuery('#vbo-row-bstat').hide();
701 jQuery('#vbo-row-custcost').hide();
702 jQuery('#vbo-row-cmail').hide();
703 jQuery('#vbo-row-fillcustfields').hide();
704 jQuery('#vbo-row-bpay').hide();
705 jQuery("#vbo-website-rates-row").hide();
706 if (prev_tareat === null) {
707 // save the previous customer information
708 prev_tareat = jQuery('#vbcustdatatxtarea').val();
709 }
710 jQuery('#vbcustdatatxtarea').val(Joomla.JText._('VBDBTEXTROOMCLOSED'));
711 jQuery('#vbcustdatalbl').text(Joomla.JText._('ORDER_NOTES'));
712 jQuery("#quickbsubmit").removeClass("btn-success").addClass("btn-danger").find("span").text(Joomla.JText._('VBSUBMCLOSEROOM'));
713 // hide force booking and untick checkbox
714 jQuery('#vbo-force-bookingdates').hide();
715 jQuery('input[name="forcebooking"]').prop('checked', false);
716 } else {
717 jQuery('#vbo-close-all-rooms-sel').hide();
718 jQuery('#vbo-row-people').show();
719 if (jQuery('#vbo-row-numrooms').length) {
720 jQuery('#vbo-row-numrooms').show();
721 }
722 jQuery('#vbo-row-bstat').show();
723 jQuery('#vbo-row-custcost').show();
724 jQuery('#vbo-row-cmail').show();
725 jQuery('#vbo-row-fillcustfields').show();
726 jQuery('#vbo-row-bpay').show();
727 jQuery('#vbcustdatatxtarea').val(prev_tareat + "");
728 jQuery('#vbcustdatalbl').text(Joomla.JText._('VBCUSTINFO'));
729 jQuery("#quickbsubmit").removeClass("btn-danger").addClass("btn-success").find("span").text(Joomla.JText._('VBMAKERESERV'));
730 }
731 }
732
733 function showCustomFields() {
734 let modal_body = VBOCore.displayModal({
735 suffix: 'calendar-cfields',
736 extra_class: 'vbo-modal-tall',
737 title: Joomla.JText._('VBFILLCUSTFIELDS'),
738 body_prepend: true,
739 footer_left: '<button type="button" class="btn" onclick="hideCustomFields();">' + Joomla.JText._('VBANNULLA') + '</button>',
740 footer_right: '<button type="button" class="btn btn-success" onclick="applyCustomFieldsContent();"><i class="icon-edit"></i> ' + Joomla.JText._('VBAPPLY') + '</button>',
741 dismiss_event: 'vbo-calendar-cfields-dismiss',
742 onDismiss: () => {
743 jQuery('.vbo-calendar-cfields-filler').appendTo('.vbo-calendar-modal-helper');
744 },
745 });
746
747 jQuery('.vbo-calendar-cfields-filler').appendTo(modal_body);
748
749 setTimeout(function() {
750 jQuery('#vbo-searchcust').focus();
751 }, 500);
752 }
753
754 function hideCustomFields() {
755 VBOCore.emitEvent('vbo-calendar-cfields-dismiss');
756 }
757
758 function applyCustomFieldsContent() {
759 var cfields_cont = "";
760 var cfields_labels = new Array;
761 var nominatives = new Array;
762 var tot_rows = 1;
763 jQuery(".vbo-calendar-cfields-inner .vbo-calendar-cfield-entry").each(function() {
764 var cfield_name = jQuery(this).find("label").text();
765 var cfield_input = jQuery(this).find("span").find("input");
766 var cfield_textarea = jQuery(this).find("span").find("textarea");
767 var cfield_select = jQuery(this).find("span").find("select.vbo-calendar-cfield-country");
768 var cfield_state = jQuery(this).find("span").find("select.vbo-calendar-cfield-state");
769 var cfield_cont = "";
770 if (cfield_input.length) {
771 cfield_cont = cfield_input.val();
772 if (cfield_input.attr("data-isemail") == "1" && cfield_cont && cfield_cont.length) {
773 jQuery("#custmailfield").val(cfield_cont);
774 }
775 if (cfield_input.attr("data-isphone") == "1") {
776 jQuery("#phonefield").val(cfield_cont);
777 }
778 if (cfield_input.attr("data-isnominative") == "1") {
779 nominatives.push(cfield_cont);
780 }
781 } else if (cfield_textarea.length) {
782 cfield_cont = cfield_textarea.val();
783 } else if (cfield_select.length) {
784 cfield_cont = cfield_select.val();
785 if (cfield_cont && cfield_cont.length) {
786 var country_code = jQuery("option:selected", cfield_select).attr("data-ccode");
787 if (country_code.length) {
788 jQuery("#ccode_inpfield").val(country_code);
789 }
790 }
791 } else if (cfield_state.length) {
792 cfield_cont = cfield_state.val();
793 jQuery("#state_inpfield").val(cfield_cont);
794 }
795 if (cfield_cont && cfield_cont.length) {
796 cfields_cont += cfield_name + ": " + cfield_cont + "\r\n";
797 tot_rows++;
798 cfields_labels.push(cfield_name + ":");
799 }
800 });
801 if (cfields_cont.length) {
802 cfields_cont = cfields_cont.replace(/\r\n+$/, "");
803 }
804 if (nominatives.length > 1) {
805 jQuery("#t_first_name_inpfield").val(nominatives[0]);
806 jQuery("#t_last_name_inpfield").val(nominatives[1]);
807 }
808 jQuery("#vbcustdatatxtarea").val(cfields_cont);
809 jQuery("#vbcustdatatxtarea").attr("rows", tot_rows);
810 // highlight custom fields labels
811 if (jQuery('#vbo-highlight-cfields').length) {
812 jQuery("#vbcustdatatxtarea").highlightTextarea('destroy');
813 }
814 jQuery("#vbcustdatatxtarea").highlightTextarea({
815 words: cfields_labels,
816 color: "#ddd",
817 id: "vbo-highlight-cfields"
818 });
819 // end highlight
820 hideCustomFields();
821 }
822
823 function vbCalcNights() {
824 vbo_glob_sel_nights = 0;
825 var vbcheckin = document.getElementById("checkindate").value;
826 var vbcheckout = document.getElementById("checkoutdate").value;
827 if (vbcheckin.length > 0 && vbcheckout.length > 0) {
828 var vbcheckinp = vbcheckin.split("/");
829 var vbcheckoutp = vbcheckout.split("/");
830 var vbo_df = "<?php echo $vbo_df; ?>";
831 if (vbo_df == "%d/%m/%Y") {
832 var vbinmonth = parseInt(vbcheckinp[1]);
833 vbinmonth = vbinmonth - 1;
834 var vbinday = parseInt(vbcheckinp[0], 10);
835 var vbcheckind = new Date(vbcheckinp[2], vbinmonth, vbinday);
836 var vboutmonth = parseInt(vbcheckoutp[1]);
837 vboutmonth = vboutmonth - 1;
838 var vboutday = parseInt(vbcheckoutp[0], 10);
839 var vbcheckoutd = new Date(vbcheckoutp[2], vboutmonth, vboutday);
840 }else if (vbo_df == "%m/%d/%Y") {
841 var vbinmonth = parseInt(vbcheckinp[0]);
842 vbinmonth = vbinmonth - 1;
843 var vbinday = parseInt(vbcheckinp[1], 10);
844 var vbcheckind = new Date(vbcheckinp[2], vbinmonth, vbinday);
845 var vboutmonth = parseInt(vbcheckoutp[0]);
846 vboutmonth = vboutmonth - 1;
847 var vboutday = parseInt(vbcheckoutp[1], 10);
848 var vbcheckoutd = new Date(vbcheckoutp[2], vboutmonth, vboutday);
849 } else {
850 var vbinmonth = parseInt(vbcheckinp[1]);
851 vbinmonth = vbinmonth - 1;
852 var vbinday = parseInt(vbcheckinp[2], 10);
853 var vbcheckind = new Date(vbcheckinp[0], vbinmonth, vbinday);
854 var vboutmonth = parseInt(vbcheckoutp[1]);
855 vboutmonth = vboutmonth - 1;
856 var vboutday = parseInt(vbcheckoutp[2], 10);
857 var vbcheckoutd = new Date(vbcheckoutp[0], vboutmonth, vboutday);
858 }
859 var vbdivider = 1000 * 60 * 60 * 24;
860 var vbints = vbcheckind.getTime();
861 var vboutts = vbcheckoutd.getTime();
862 if (vboutts > vbints) {
863 //var vbnights = Math.ceil((vboutts - vbints) / (vbdivider));
864 var utc1 = Date.UTC(vbcheckind.getFullYear(), vbcheckind.getMonth(), vbcheckind.getDate());
865 var utc2 = Date.UTC(vbcheckoutd.getFullYear(), vbcheckoutd.getMonth(), vbcheckoutd.getDate());
866 var vbnights = Math.ceil((utc2 - utc1) / vbdivider);
867 if (vbnights > 0) {
868 vbo_glob_sel_nights = vbnights;
869 jQuery('#vbjstotnights').show();
870 jQuery("#vbo-numnights").val(vbnights);
871 // update average cost per night
872 vbCalcDailyCost(document.getElementById("cust_cost").value);
873 } else {
874 jQuery('#vbjstotnights').hide();
875 }
876 } else {
877 jQuery('#vbjstotnights').hide();
878 }
879 } else {
880 jQuery('#vbjstotnights').hide();
881 }
882 }
883
884 function vbCalcDailyCost(cur_val) {
885 // trigger calculation of website rates
886 vboCalcWebsiteRates();
887 //
888 if (cur_val.length && !isNaN(cur_val) && vbo_glob_sel_nights > 0) {
889 var cur_float = parseFloat(cur_val);
890 var selopts = jQuery("#avg-daycost").find("select").find("option");
891 // total cost with average cost per night
892 var avg_cost = (cur_float / vbo_glob_sel_nights).toFixed(<?php echo (int)$formatparts[0]; ?>);
893 var avg_cost_str = "<?php echo $currencysymb; ?> " + avg_cost + "/" + Joomla.JText._('VBDAY') + " = <?php echo $currencysymb; ?> " + cur_float.toFixed(<?php echo (int)$formatparts[0]; ?>);
894 selopts.first().text(avg_cost_str);
895 // cost multiplied by number of nights
896 var final_cost = (cur_float * vbo_glob_sel_nights).toFixed(<?php echo (int)$formatparts[0]; ?>);
897 var final_cost_str = "<?php echo $currencysymb; ?> " + cur_float.toFixed(<?php echo (int)$formatparts[0]; ?>) + "/" + Joomla.JText._('VBDAY') + " = <?php echo $currencysymb; ?> " + final_cost;
898 selopts.last().text(final_cost_str);
899 // show drop down
900 jQuery("#avg-daycost").show();
901 } else {
902 jQuery("#avg-daycost").hide();
903 }
904 }
905
906 function vboCalcWebsiteRates() {
907 // unset previously selected rates, if any
908 vboUnsetWebsiteRate();
909 // hide force booking and untick checkbox
910 jQuery('#vbo-force-bookingdates').hide();
911 jQuery('input[name="forcebooking"]').prop('checked', false);
912 //
913 var checkinfdate = jQuery("#checkindate").val();
914 var adults = jQuery("#vbo-sel-adults").val();
915 var children = jQuery("#vbo-sel-children").val();
916 var units = jQuery("#vbo-sel-numrooms").val();
917 if (!checkinfdate.length || vbo_glob_sel_nights < 1 || jQuery("input[name=\"setclosed\"]").is(":checked") || <?php echo !empty($split_stay) ? 'true' : 'false'; ?>) {
918 jQuery("#vbo-website-rates-row").hide();
919 return false;
920 }
921 var jqxhr = jQuery.ajax({
922 type: "POST",
923 url: "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=calc_rates'); ?>",
924 data: {
925 id_room: <?php echo $room['id']; ?>,
926 checkinfdate: checkinfdate,
927 num_nights: vbo_glob_sel_nights,
928 num_adults: adults,
929 num_children: children,
930 units: units,
931 only_rates: 1,
932 tmpl: "component"
933 }
934 }).done(function(resp) {
935 var obj_res = null;
936 try {
937 obj_res = typeof resp === 'string' ? JSON.parse(resp) : resp;
938 } catch(err) {
939 console.error("could not parse JSON response", resp);
940 }
941 if (obj_res === null || !Array.isArray(obj_res)) {
942 jQuery("#vbo-website-rates-row").hide();
943 console.info("invalid JSON response", resp);
944 return false;
945 }
946 if (jQuery("input[name=\"setclosed\"]").is(":checked")) {
947 jQuery("#vbo-website-rates-row").hide();
948 return false;
949 }
950 if (obj_res.hasOwnProperty(1) && obj_res[1] == -1 && !jQuery('input[name="setclosed"]').prop('checked')) {
951 // the room is not available or has no rates, display force booking toggle
952 jQuery('#vbo-force-bookingdates').show();
953 if (typeof obj_res[0] == 'string' && obj_res[0].indexOf('e4j.error') >= 0) {
954 jQuery('#vbo-force-bookingdates').find('.vbo-param-setting-comment').text(obj_res[0].replace('e4j.error.', ''));
955 } else {
956 jQuery('#vbo-force-bookingdates').find('.vbo-param-setting-comment').text('');
957 }
958 }
959 if (!obj_res[0].hasOwnProperty("idprice")) {
960 jQuery("#vbo-website-rates-row").hide();
961 console.log("error in response", resp);
962 return false;
963 }
964 // check whether rates are inclusive of taxes
965 var vbo_tax_included = <?php echo $prices_vat_included; ?>;
966 // display the rates obtained
967 var wrhtml = "";
968 for (var i in obj_res) {
969 if (!obj_res.hasOwnProperty(i)) {
970 continue;
971 }
972 if (!vbo_tax_included && obj_res[i].hasOwnProperty('net') && obj_res[i].hasOwnProperty('fnet')) {
973 obj_res[i]['tot'] = obj_res[i]['net'];
974 obj_res[i]['ftot'] = obj_res[i]['fnet'];
975 }
976 wrhtml += "<div class=\"vbo-cal-wbrate-wrap\" onclick=\"vboSelWebsiteRate(this);\">";
977 wrhtml += "<div class=\"vbo-cal-wbrate-inner\">";
978 wrhtml += "<span class=\"vbo-cal-wbrate-name\" data-idprice=\"" + obj_res[i]['idprice'] + "\">" + obj_res[i]['name'] + "</span>";
979 wrhtml += "<span class=\"vbo-cal-wbrate-cost\" data-cost=\"" + obj_res[i]['tot'] + "\">" + obj_res[i]['ftot'] + "</span>";
980 wrhtml += "</div>";
981 wrhtml += "</div>";
982 }
983 jQuery("#vbo-website-rates-cont").html(wrhtml);
984 jQuery("#vbo-website-rates-row").fadeIn();
985 if (<?php echo $pidprice > 0 && $pbooknow > 0 ? 'true' : 'false'; ?> && !booknowmade) {
986 // we get here by clicking the book-now button from the rates calculator only once
987 booknowmade = true;
988 // trigger the click for the requested rate plan ID
989 jQuery('.vbo-cal-wbrate-name[data-idprice="<?php echo $pidprice; ?>"]').closest('.vbo-cal-wbrate-wrap').trigger('click');
990 }
991 }).fail(function() {
992 jQuery("#vbo-website-rates-row").hide();
993 console.error("Error calculating the rates");
994 });
995 }
996
997 function vboSelWebsiteRate(elem) {
998 var rate = jQuery(elem);
999 var idprice = rate.find('.vbo-cal-wbrate-name').attr('data-idprice');
1000 var cost = rate.find('.vbo-cal-wbrate-cost').attr('data-cost');
1001 var prev_idprice = jQuery('#booking-idprice').val();
1002 // reset all selected classes
1003 jQuery('.vbo-cal-wbrate-wrap').removeClass('vbo-cal-wbrate-wrap-selected');
1004 if (prev_idprice.length && prev_idprice == idprice) {
1005 // rate plan has been de-selected
1006 jQuery('#booking-idprice').val("");
1007 jQuery('#booking-roomcost').val("");
1008 jQuery('#cust_cost').attr('readonly', false);
1009 } else {
1010 // rate plan has been selected
1011 rate.addClass('vbo-cal-wbrate-wrap-selected');
1012 jQuery('#booking-idprice').val(idprice);
1013 jQuery('#booking-roomcost').val(cost);
1014 jQuery('#cust_cost').attr('readonly', true);
1015 }
1016 }
1017
1018 function vboUnsetWebsiteRate() {
1019 jQuery('#booking-idprice').val("");
1020 jQuery('#booking-roomcost').val("");
1021 jQuery('.vbo-cal-wbrate-wrap').removeClass('vbo-cal-wbrate-wrap-selected');
1022 jQuery('#cust_cost').attr('readonly', false);
1023 }
1024
1025 function vboReloadStates(country_3_code) {
1026 var states_elem = jQuery('select.vbo-calendar-cfield-state');
1027
1028 // unset the current states/provinces
1029 states_elem.html('');
1030
1031 if (!country_3_code || !country_3_code.length) {
1032 return;
1033 }
1034
1035 // make a request to load the states/provinces of the selected country
1036 VBOCore.doAjax(
1037 "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=states.load_from_country'); ?>",
1038 {
1039 country_3_code: country_3_code,
1040 tmpl: "component"
1041 },
1042 (response) => {
1043 try {
1044 var obj_res = typeof response === 'string' ? JSON.parse(response) : response;
1045 if (!obj_res) {
1046 console.error('Unexpected JSON response', obj_res);
1047 return false;
1048 }
1049
1050 // append empty value
1051 states_elem.append('<option value="">-----</option>');
1052
1053 for (var i = 0; i < obj_res.length; i++) {
1054 // append state
1055 states_elem.append('<option value="' + obj_res[i]['state_2_code'] + '">' + obj_res[i]['state_name'] + '</option>');
1056 }
1057 } catch(err) {
1058 console.error('could not parse JSON response', err, response);
1059 }
1060 },
1061 (error) => {
1062 console.error(error);
1063 }
1064 );
1065 }
1066
1067 jQuery(function() {
1068
1069 jQuery('.vbo-calendar-cfield-country').on('change', function() {
1070 // trigger event for phone number
1071 jQuery('.vbo-calendar-cfield-phone').trigger('vboupdatephonenumber', jQuery(this).find('option:selected').attr('data-c2code'));
1072 // reload state/province
1073 vboReloadStates(jQuery(this).find('option:selected').attr('data-ccode'));
1074 });
1075
1076 jQuery('td.free').click(function() {
1077 var indate = jQuery('#checkindate').val();
1078 var outdate = jQuery('#checkoutdate').val();
1079 var clickdate = jQuery(this).attr('data-daydate');
1080 if (!(indate.length > 0)) {
1081 jQuery('#checkindate').datepicker("setDate", clickdate);
1082 } else if (!(outdate.length > 0) && clickdate != indate) {
1083 jQuery('#checkoutdate').datepicker("setDate", clickdate);
1084 } else {
1085 jQuery('#checkoutdate').datepicker("setDate", '');
1086 jQuery('#checkindate').datepicker("setDate", clickdate);
1087 }
1088 jQuery(".ui-datepicker-current-day").click();
1089 });
1090
1091 jQuery("#quickbsubmit").click(function() {
1092 setTimeout(function() {
1093 jQuery(this).prop('disabled', true);
1094 }, 200);
1095 });
1096
1097 jQuery('#vbo-calendar-newb-form').on('submit', function() {
1098 if (!document.newb.checkindate.value.match(/\S/)) {
1099 alert(Joomla.JText._('VBMSGTHREE'));
1100 return false;
1101 }
1102
1103 if (!document.newb.checkoutdate.value.match(/\S/)) {
1104 alert(Joomla.JText._('VBMSGFOUR'));
1105 return false;
1106 }
1107
1108 if (!jQuery(this).find('[name="setclosed"]').prop('checked') && !jQuery(this).find('[name="custmail"]').val() && <?php echo $room['units'] > 1 ? 'true' : 'false'; ?>) {
1109 // no closure, no customer email, multiple units, ask if the units should be marked as closed
1110 if (confirm(Joomla.JText._('VBO_MARK_UNITS_CLOSED'))) {
1111 // append hidden field to form
1112 jQuery(this).append('<input type="hidden" name="setunitsclosed" value="1" />');
1113 // check if "room closed" should be added
1114 if (!jQuery('#vbcustdatatxtarea').val()) {
1115 jQuery('#vbcustdatatxtarea').val(Joomla.JText._('VBDBTEXTROOMCLOSED'));
1116 }
1117 }
1118 }
1119
1120 return true;
1121 });
1122
1123 jQuery("#vbo-calendar-changeroom").select2();
1124 if (jQuery("#vbo-calendar-closeall").length) {
1125 jQuery("#vbo-calendar-closeall").select2({placeholder: "- " + Joomla.JText._('VBOCALCLOSEOTHERROOMS') + " -", width: "300px"});
1126 }
1127
1128 jQuery("#vbo-sel-numrooms, #vbo-sel-adults").change(function() {
1129 vboCalcWebsiteRates();
1130 });
1131
1132 jQuery('.vbo-calendar-cfield-entry input[data-isemail="1"]').first().blur(function() {
1133 var curemail = jQuery(this).val();
1134 if (curemail.length) {
1135 var jqxhr = jQuery.ajax({
1136 type: "POST",
1137 url: "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=searchcustomer'); ?>",
1138 data: {
1139 kw: curemail,
1140 email: 1,
1141 tmpl: "component"
1142 }
1143 }).done(function(cont) {
1144 try {
1145 var obj_res = typeof cont === 'string' ? JSON.parse(cont) : cont;
1146 alert(Joomla.JText._('VBERRCUSTOMEREMAILEXISTS') + " (" + obj_res['first_name'] + " " + obj_res['last_name'] + ")");
1147 } catch(e) {
1148 console.error(e);
1149 }
1150 }).fail(function() {
1151 console.log("Error searching for existing email");
1152 });
1153 }
1154 });
1155
1156 jQuery("#vbfillcustfields").click(function() {
1157 showCustomFields();
1158 });
1159
1160 // search customer - start
1161 var vbocustsdelay = (function() {
1162 var timer = 0;
1163 return function(callback, ms) {
1164 clearTimeout (timer);
1165 timer = setTimeout(callback, ms);
1166 };
1167 })();
1168
1169 function vboCustomerSearch(words) {
1170 jQuery("#vbo-searchcust-res").hide().html("");
1171 jQuery("#vbo-searchcust-loading").show();
1172 var jqxhr = jQuery.ajax({
1173 type: "POST",
1174 url: "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=searchcustomer'); ?>",
1175 data: {
1176 kw: words,
1177 tmpl: "component"
1178 }
1179 }).done(function(cont) {
1180 if (cont) {
1181 var obj_res = typeof cont === 'string' ? JSON.parse(cont) : cont;
1182 customers_search_vals = obj_res[0];
1183 jQuery("#vbo-searchcust-res").html(obj_res[1]);
1184 } else {
1185 customers_search_vals = "";
1186 jQuery("#vbo-searchcust-res").html("----");
1187 }
1188 jQuery("#vbo-searchcust-res").show();
1189 jQuery("#vbo-searchcust-loading").hide();
1190 }).fail(function() {
1191 jQuery("#vbo-searchcust-loading").hide();
1192 alert("Error searching");
1193 });
1194 }
1195
1196 jQuery("#vbo-searchcust").keyup(function(event) {
1197 vbocustsdelay(function() {
1198 var keywords = jQuery("#vbo-searchcust").val();
1199 var chars = keywords.length;
1200 if (chars > 1) {
1201 if ((event.which > 96 && event.which < 123) || (event.which > 64 && event.which < 91) || event.which == 13) {
1202 vboCustomerSearch(keywords);
1203 }
1204 } else {
1205 if (jQuery("#vbo-searchcust-res").is(":visible")) {
1206 jQuery("#vbo-searchcust-res").hide();
1207 }
1208 }
1209 }, 600);
1210 });
1211 // search customer - end
1212
1213 // datepickers - start
1214 jQuery("#checkindate").datepicker({
1215 showOn: "focus",
1216 dateFormat: "<?php echo $juidf; ?>",
1217 numberOfMonths: 1,
1218 onSelect: function(selectedDate) {
1219 var nownights = parseInt(jQuery("#vbo-numnights").val());
1220 var nowcheckin = jQuery("#checkindate").datepicker("getDate");
1221 var nowcheckindate = new Date(nowcheckin.getTime());
1222 nowcheckindate.setDate(nowcheckindate.getDate() + nownights);
1223 jQuery("#checkoutdate").datepicker("option", "minDate", nowcheckindate);
1224 jQuery("#checkoutdate").datepicker("setDate", nowcheckindate);
1225 vbCalcNights();
1226 }
1227 });
1228 jQuery("#checkoutdate").datepicker({
1229 showOn: "focus",
1230 dateFormat: "<?php echo $juidf; ?>",
1231 numberOfMonths: 1,
1232 onSelect: function(selectedDate) {
1233 vbCalcNights();
1234 }
1235 });
1236 jQuery(".vbodatepicker-trig-icon").click(function(){
1237 var jdp = jQuery(this).prev("input.hasDatepicker");
1238 if (jdp.length) {
1239 jdp.focus();
1240 }
1241 });
1242 jQuery("#vbo-numnights").on("change keyup", function() {
1243 if (!jQuery("#checkindate").length) {
1244 return;
1245 }
1246 var nownights = parseInt(jQuery(this).val());
1247 var nowcheckin = jQuery("#checkindate").datepicker("getDate");
1248 var nowcheckindate = new Date(nowcheckin.getTime());
1249 nowcheckindate.setDate(nowcheckindate.getDate() + nownights);
1250 jQuery("#checkoutdate").datepicker("option", "minDate", nowcheckindate);
1251 jQuery("#checkoutdate").datepicker("setDate", nowcheckindate);
1252 vbo_glob_sel_nights = nownights;
1253 // update average cost per night
1254 vbCalcDailyCost(document.getElementById("cust_cost").value);
1255 });
1256 // datepickers - end
1257 <?php echo (!empty($pcheckin) ? 'jQuery("#checkindate").datepicker("setDate", "'.$pcheckin.'");'."\n" : ''); ?>
1258 <?php echo (!empty($pcheckout) ? 'jQuery("#checkoutdate").datepicker("setDate", "'.$pcheckout.'");'."\n" : ''); ?>
1259 <?php echo (!empty($pcheckin) || !empty($pcheckout) ? 'jQuery(".ui-datepicker-current-day").click();'."\n" : ''); ?>
1260 });
1261
1262 jQuery(document).on("click", ".vbo-custsearchres-entry", function() {
1263 var custid = jQuery(this).attr("data-custid");
1264 var custemail = jQuery(this).attr("data-email");
1265 var custphone = jQuery(this).attr("data-phone");
1266 var custcountry = jQuery(this).attr("data-country");
1267 var custfirstname = jQuery(this).attr("data-firstname");
1268 var custlastname = jQuery(this).attr("data-lastname");
1269 jQuery("#customer_id_inpfield").val(custid);
1270 if (customers_search_vals.hasOwnProperty(custid)) {
1271 jQuery.each(customers_search_vals[custid], function(cfid, cfval) {
1272 var fill_field = jQuery("#cfield"+cfid);
1273 if (fill_field.length) {
1274 fill_field.val(cfval);
1275 }
1276 });
1277 } else {
1278 jQuery("input[data-isnominative=\"1\"]").each(function(k, v) {
1279 if (k == 0) {
1280 jQuery(this).val(custfirstname);
1281 return true;
1282 }
1283 if (k == 1) {
1284 jQuery(this).val(custlastname);
1285 return true;
1286 }
1287 return false;
1288 });
1289 jQuery("input[data-isemail=\"1\"]").val(custemail);
1290 jQuery("input[data-isphone=\"1\"]").val(custphone).trigger('vboupdatephonenumber');
1291 // populate main calendar form
1292 jQuery("#custmailfield").val(custemail);
1293 jQuery("#t_first_name_inpfield").val(custfirstname);
1294 jQuery("#t_last_name_inpfield").val(custlastname);
1295 //
1296 }
1297 applyCustomFieldsContent();
1298 if (custcountry.length) {
1299 jQuery("#ccode_inpfield").val(custcountry);
1300 }
1301 if (custphone.length) {
1302 jQuery("#phonefield").val(custphone);
1303 }
1304 });
1305
1306 var vborefreshingsel = false;
1307 function vboCheckCloseOthers() {
1308 if (!jQuery("#vbo-calendar-closeall").length || vborefreshingsel) {
1309 // avoid recursion loop by triggering the change event for select2
1310 return;
1311 }
1312 var selall = jQuery('#vbo-calendar-closeall option[value="-1"]').is(':selected');
1313 // always select the current room unless all get de-selected
1314 var optselected = jQuery('#vbo-calendar-closeall option:selected');
1315 var none_sel = !optselected.length ? true : false;
1316 if (optselected.length === 1 && optselected.first().attr('data-currentr')) {
1317 none_sel = true;
1318 }
1319 var curropt = jQuery('#vbo-calendar-closeall option[data-currentr="true"]');
1320 if (!none_sel) {
1321 curropt.prop('selected', true);
1322 curropt.prop('disabled', true);
1323 } else {
1324 curropt.prop('selected', false);
1325 curropt.prop('disabled', true);
1326 }
1327 //
1328 jQuery('#vbo-calendar-closeall').find('option').each(function() {
1329 var curval = jQuery(this).val();
1330 var curroom = jQuery(this).attr('data-currentr');
1331 if (!curval.length || curval == '-1' || curroom) {
1332 return true;
1333 }
1334 if (selall) {
1335 jQuery(this).prop('disabled', true);
1336 jQuery(this).prop('selected', false);
1337 } else {
1338 jQuery(this).prop('disabled', false);
1339 }
1340 });
1341 vboRefreshCloseOthers();
1342 }
1343
1344 function vboRefreshCloseOthers() {
1345 // prevent recursion loop
1346 vborefreshingsel = true;
1347 jQuery("#vbo-calendar-closeall").trigger('change');
1348 setTimeout(function() {
1349 vborefreshingsel = false;
1350 }, 200);
1351 }
1352 </script>
1353