| @@ -1,0 +1,912 @@ | ||
| 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('_JEXEC') or defined('ABSPATH') or die('No script kiddies please!'); | |
| 12 | + | |
| 13 | +//This is a template file loaded (included) by the main lib in case of errors during the booking process to keep the current query string, without performing any redirect. | |
| 14 | +//The output of this template file is similar to the default view 'vikbooking' but it takes an error-message variable and an array parameter declared in the main library file. | |
| 15 | +//This is not a core-file and, even though it does not support overrides, it can be customized as it is never replaced by any update. | |
| 16 | + | |
| 17 | +$dbo = JFactory::getDbo(); | |
| 18 | +$session = JFactory::getSession(); | |
| 19 | + | |
| 20 | +$vbo_tn = VikBooking::getTranslator(); | |
| 21 | +$vbo_app = VikBooking::getVboApplication(); | |
| 22 | +$vbo_app->loadDatePicker(['type' => 'dates_range']); | |
| 23 | + | |
| 24 | +if (VikBooking::allowBooking()) { | |
| 25 | + $is_mobile = VikBooking::detectUserAgent(false, false); | |
| 26 | + | |
| 27 | + $calendartype = VikBooking::calendarType(); | |
| 28 | + $document = JFactory::getDocument(); | |
| 29 | + // load modalframe lib for search suggestions | |
| 30 | + $document->addStyleSheet(VBO_SITE_URI.'resources/jquery.fancybox.css'); | |
| 31 | + JHtml::fetch('script', VBO_SITE_URI.'resources/jquery.fancybox.js'); | |
| 32 | + | |
| 33 | + // restrictions and values | |
| 34 | + $restrictions = VikBooking::loadRestrictions(); | |
| 35 | + $oldroomsnum = $session->get('vbroomsnum', ''); | |
| 36 | + $oldarrpeople = $session->get('vbarrpeople', ''); | |
| 37 | + $pcheckin = VikRequest::getInt('checkin', '', 'request'); | |
| 38 | + $pcheckout = VikRequest::getInt('checkout', '', 'request'); | |
| 39 | + $sesscheckin = $session->get('vbcheckin', ''); | |
| 40 | + $sesscheckout = $session->get('vbcheckout', ''); | |
| 41 | + $pcategories = VikRequest::getString('categories', '', 'request'); | |
| 42 | + $pitemid = VikRequest::getInt('Itemid', '', 'request'); | |
| 43 | + | |
| 44 | + $pval = ""; | |
| 45 | + $rval = ""; | |
| 46 | + $vbdateformat = VikBooking::getDateFormat(); | |
| 47 | + if ($vbdateformat == "%d/%m/%Y") { | |
| 48 | + $df = 'd/m/Y'; | |
| 49 | + } elseif ($vbdateformat == "%m/%d/%Y") { | |
| 50 | + $df = 'm/d/Y'; | |
| 51 | + } else { | |
| 52 | + $df = 'Y/m/d'; | |
| 53 | + } | |
| 54 | + | |
| 55 | + if (!empty($pcheckin) || !empty($sesscheckin)) { | |
| 56 | + $pcheckin = !empty($pcheckin) ? $pcheckin : $sesscheckin; | |
| 57 | + $dp = date($df, $pcheckin); | |
| 58 | + if (VikBooking::dateIsValid($dp)) { | |
| 59 | + $pval = $dp; | |
| 60 | + } | |
| 61 | + } | |
| 62 | + if (!empty($pcheckout) || !empty($sesscheckout)) { | |
| 63 | + $pcheckout = !empty($pcheckout) ? $pcheckout : $sesscheckout; | |
| 64 | + $dr = date($df, $pcheckout); | |
| 65 | + if (VikBooking::dateIsValid($dr)) { | |
| 66 | + $rval = $dr; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + // form method is dependant to the platform | |
| 71 | + $form_method = VBOPlatformDetection::isWordPress() ? 'post' : 'get'; | |
| 72 | + | |
| 73 | + $selform = "<div class=\"vbdivsearch vbo-search-mainview vbo-search-noresults-cont\"><form action=\"".JRoute::rewrite('index.php?option=com_vikbooking&Itemid='.VikRequest::getString('Itemid', '', 'request'))."\" method=\"{$form_method}\"><div class=\"vb-search-inner\">\n"; | |
| 74 | + $selform .= "<input type=\"hidden\" name=\"option\" value=\"com_vikbooking\"/>\n"; | |
| 75 | + $selform .= "<input type=\"hidden\" name=\"task\" value=\"search\"/>\n"; | |
| 76 | + | |
| 77 | + $timeopst = VikBooking::getTimeOpenStore(); | |
| 78 | + if (is_array($timeopst)) { | |
| 79 | + $opent = VikBooking::getHoursMinutes($timeopst[0]); | |
| 80 | + $closet = VikBooking::getHoursMinutes($timeopst[1]); | |
| 81 | + $hcheckin = $opent[0]; | |
| 82 | + $mcheckin = $opent[1]; | |
| 83 | + $hcheckout = $closet[0]; | |
| 84 | + $mcheckout = $closet[1]; | |
| 85 | + } else { | |
| 86 | + $hcheckin = 0; | |
| 87 | + $mcheckin = 0; | |
| 88 | + $hcheckout = 0; | |
| 89 | + $mcheckout = 0; | |
| 90 | + } | |
| 91 | + | |
| 92 | + // datepicker calendar setup | |
| 93 | + if ($calendartype == "jqueryui") { | |
| 94 | + if ($vbdateformat == "%d/%m/%Y") { | |
| 95 | + $juidf = 'dd/mm/yy'; | |
| 96 | + } elseif ($vbdateformat == "%m/%d/%Y") { | |
| 97 | + $juidf = 'mm/dd/yy'; | |
| 98 | + } else { | |
| 99 | + $juidf = 'yy/mm/dd'; | |
| 100 | + } | |
| 101 | + // lang for jQuery UI Calendar is loaded through the application class | |
| 102 | + $ldecl = ' | |
| 103 | +jQuery.noConflict(); | |
| 104 | +function vbGetDateObject(dstring) { | |
| 105 | + var dparts = dstring.split("-"); | |
| 106 | + return new Date(dparts[0], (parseInt(dparts[1]) - 1), parseInt(dparts[2]), 0, 0, 0, 0); | |
| 107 | +} | |
| 108 | +function vbFullObject(obj) { | |
| 109 | + var jk; | |
| 110 | + for(jk in obj) { | |
| 111 | + return obj.hasOwnProperty(jk); | |
| 112 | + } | |
| 113 | +} | |
| 114 | +var vbrestrctarange, vbrestrctdrange, vbrestrcta, vbrestrctd;'; | |
| 115 | + $document->addScriptDeclaration($ldecl); | |
| 116 | + | |
| 117 | + // global restrictions | |
| 118 | + $totrestrictions = count($restrictions); | |
| 119 | + $wdaysrestrictions = []; | |
| 120 | + $wdaystworestrictions = []; | |
| 121 | + $wdaysrestrictionsrange = []; | |
| 122 | + $wdaysrestrictionsmonths = []; | |
| 123 | + $ctarestrictionsrange = []; | |
| 124 | + $ctarestrictionsmonths = []; | |
| 125 | + $ctdrestrictionsrange = []; | |
| 126 | + $ctdrestrictionsmonths = []; | |
| 127 | + $monthscomborestr = []; | |
| 128 | + $minlosrestrictions = []; | |
| 129 | + $minlosrestrictionsrange = []; | |
| 130 | + $maxlosrestrictions = []; | |
| 131 | + $maxlosrestrictionsrange = []; | |
| 132 | + $notmultiplyminlosrestrictions = []; | |
| 133 | + if ($totrestrictions > 0) { | |
| 134 | + foreach ($restrictions as $rmonth => $restr) { | |
| 135 | + if ($rmonth != 'range') { | |
| 136 | + if (strlen((string)$restr['wday'])) { | |
| 137 | + $wdaysrestrictions[($rmonth - 1)] = $restr['wday']; | |
| 138 | + $wdaysrestrictionsmonths[] = $rmonth; | |
| 139 | + if (strlen((string)$restr['wdaytwo'])) { | |
| 140 | + $wdaystworestrictions[($rmonth - 1)] = $restr['wdaytwo']; | |
| 141 | + $monthscomborestr[($rmonth - 1)] = VikBooking::parseJsDrangeWdayCombo($restr); | |
| 142 | + } | |
| 143 | + } elseif (!empty($restr['ctad']) || !empty($restr['ctdd'])) { | |
| 144 | + if (!empty($restr['ctad'])) { | |
| 145 | + $ctarestrictionsmonths[($rmonth - 1)] = explode(',', $restr['ctad']); | |
| 146 | + } | |
| 147 | + if (!empty($restr['ctdd'])) { | |
| 148 | + $ctdrestrictionsmonths[($rmonth - 1)] = explode(',', $restr['ctdd']); | |
| 149 | + } | |
| 150 | + } | |
| 151 | + if ($restr['multiplyminlos'] == 0) { | |
| 152 | + $notmultiplyminlosrestrictions[] = $rmonth; | |
| 153 | + } | |
| 154 | + $minlosrestrictions[($rmonth - 1)] = $restr['minlos']; | |
| 155 | + if (!empty($restr['maxlos']) && $restr['maxlos'] > 0 && $restr['maxlos'] >= $restr['minlos']) { | |
| 156 | + $maxlosrestrictions[($rmonth - 1)] = $restr['maxlos']; | |
| 157 | + } | |
| 158 | + } else { | |
| 159 | + foreach ($restr as $kr => $drestr) { | |
| 160 | + if (strlen((string)$drestr['wday'])) { | |
| 161 | + $wdaysrestrictionsrange[$kr][0] = date('Y-m-d', $drestr['dfrom']); | |
| 162 | + $wdaysrestrictionsrange[$kr][1] = date('Y-m-d', $drestr['dto']); | |
| 163 | + $wdaysrestrictionsrange[$kr][2] = $drestr['wday']; | |
| 164 | + $wdaysrestrictionsrange[$kr][3] = $drestr['multiplyminlos']; | |
| 165 | + $wdaysrestrictionsrange[$kr][4] = strlen((string)$drestr['wdaytwo']) ? $drestr['wdaytwo'] : -1; | |
| 166 | + $wdaysrestrictionsrange[$kr][5] = VikBooking::parseJsDrangeWdayCombo($drestr); | |
| 167 | + } elseif (!empty($drestr['ctad']) || !empty($drestr['ctdd'])) { | |
| 168 | + $ctfrom = date('Y-m-d', $drestr['dfrom']); | |
| 169 | + $ctto = date('Y-m-d', $drestr['dto']); | |
| 170 | + if (!empty($drestr['ctad'])) { | |
| 171 | + $ctarestrictionsrange[$kr][0] = $ctfrom; | |
| 172 | + $ctarestrictionsrange[$kr][1] = $ctto; | |
| 173 | + $ctarestrictionsrange[$kr][2] = explode(',', $drestr['ctad']); | |
| 174 | + } | |
| 175 | + if (!empty($drestr['ctdd'])) { | |
| 176 | + $ctdrestrictionsrange[$kr][0] = $ctfrom; | |
| 177 | + $ctdrestrictionsrange[$kr][1] = $ctto; | |
| 178 | + $ctdrestrictionsrange[$kr][2] = explode(',', $drestr['ctdd']); | |
| 179 | + } | |
| 180 | + } | |
| 181 | + $minlosrestrictionsrange[$kr][0] = date('Y-m-d', $drestr['dfrom']); | |
| 182 | + $minlosrestrictionsrange[$kr][1] = date('Y-m-d', $drestr['dto']); | |
| 183 | + $minlosrestrictionsrange[$kr][2] = $drestr['minlos']; | |
| 184 | + if (!empty($drestr['maxlos']) && $drestr['maxlos'] > 0 && $drestr['maxlos'] >= $drestr['minlos']) { | |
| 185 | + $maxlosrestrictionsrange[$kr] = $drestr['maxlos']; | |
| 186 | + } | |
| 187 | + } | |
| 188 | + unset($restrictions['range']); | |
| 189 | + } | |
| 190 | + } | |
| 191 | + | |
| 192 | + $resdecl = " | |
| 193 | +var vbrestrmonthswdays = " . json_encode($wdaysrestrictionsmonths) . "; | |
| 194 | +var vbrestrmonths = " . json_encode(array_keys($restrictions)) . "; | |
| 195 | +var vbrestrmonthscombojn = " . json_encode($monthscomborestr) . "; | |
| 196 | +var vbrestrminlos = " . json_encode((object) $minlosrestrictions) . "; | |
| 197 | +var vbrestrminlosrangejn = " . json_encode($minlosrestrictionsrange) . "; | |
| 198 | +var vbrestrmultiplyminlos = " . json_encode($notmultiplyminlosrestrictions) . "; | |
| 199 | +var vbrestrmaxlos = " . json_encode((object) $maxlosrestrictions) . "; | |
| 200 | +var vbrestrmaxlosrangejn = " . json_encode($maxlosrestrictionsrange) . "; | |
| 201 | +var vbrestrwdaysrangejn = " . json_encode($wdaysrestrictionsrange) . "; | |
| 202 | +var vbrestrcta = " . json_encode($ctarestrictionsmonths) . "; | |
| 203 | +var vbrestrctarange = " . json_encode($ctarestrictionsrange) . "; | |
| 204 | +var vbrestrctd = " . json_encode($ctdrestrictionsmonths) . "; | |
| 205 | +var vbrestrctdrange = " . json_encode($ctdrestrictionsrange) . "; | |
| 206 | +var vbcombowdays = {}; | |
| 207 | + | |
| 208 | +function vbRefreshCheckout(darrive) { | |
| 209 | + if (vbFullObject(vbcombowdays)) { | |
| 210 | + var vbtosort = new Array(); | |
| 211 | + for(var vbi in vbcombowdays) { | |
| 212 | + if (vbcombowdays.hasOwnProperty(vbi)) { | |
| 213 | + var vbusedate = darrive; | |
| 214 | + vbtosort[vbi] = vbusedate.setDate(vbusedate.getDate() + (vbcombowdays[vbi] - 1 - vbusedate.getDay() + 7) % 7 + 1); | |
| 215 | + } | |
| 216 | + } | |
| 217 | + vbtosort.sort(function(da, db) { | |
| 218 | + return da > db ? 1 : -1; | |
| 219 | + }); | |
| 220 | + for(var vbnext in vbtosort) { | |
| 221 | + if (vbtosort.hasOwnProperty(vbnext)) { | |
| 222 | + var vbfirstnextd = new Date(vbtosort[vbnext]); | |
| 223 | + jQuery('#checkindate').vboDatesRangePicker('checkout', 'minDate', vbfirstnextd); | |
| 224 | + jQuery('#checkindate').vboDatesRangePicker('checkout', 'setcheckoutdate', vbfirstnextd); | |
| 225 | + break; | |
| 226 | + } | |
| 227 | + } | |
| 228 | + } | |
| 229 | +} | |
| 230 | + | |
| 231 | +function vbSetMinCheckoutDate(selectedDate) { | |
| 232 | + var minlos = ".VikBooking::getDefaultNightsCalendar()."; | |
| 233 | + var maxlosrange = 0; | |
| 234 | + var nowcheckin = jQuery('#checkindate').vboDatesRangePicker('getCheckinDate'); | |
| 235 | + var nowd = nowcheckin.getDay(); | |
| 236 | + var nowcheckindate = new Date(nowcheckin.getTime()); | |
| 237 | + vbcombowdays = {}; | |
| 238 | + if (vbFullObject(vbrestrminlosrangejn)) { | |
| 239 | + for (var rk in vbrestrminlosrangejn) { | |
| 240 | + if (vbrestrminlosrangejn.hasOwnProperty(rk)) { | |
| 241 | + var minldrangeinit = vbGetDateObject(vbrestrminlosrangejn[rk][0]); | |
| 242 | + if (nowcheckindate >= minldrangeinit) { | |
| 243 | + var minldrangeend = vbGetDateObject(vbrestrminlosrangejn[rk][1]); | |
| 244 | + if (nowcheckindate <= minldrangeend) { | |
| 245 | + minlos = parseInt(vbrestrminlosrangejn[rk][2]); | |
| 246 | + if (vbFullObject(vbrestrmaxlosrangejn)) { | |
| 247 | + if (rk in vbrestrmaxlosrangejn) { | |
| 248 | + maxlosrange = parseInt(vbrestrmaxlosrangejn[rk]); | |
| 249 | + } | |
| 250 | + } | |
| 251 | + if (rk in vbrestrwdaysrangejn && nowd in vbrestrwdaysrangejn[rk][5]) { | |
| 252 | + vbcombowdays = vbrestrwdaysrangejn[rk][5][nowd]; | |
| 253 | + } | |
| 254 | + } | |
| 255 | + } | |
| 256 | + } | |
| 257 | + } | |
| 258 | + } | |
| 259 | + var nowm = nowcheckin.getMonth(); | |
| 260 | + if (vbFullObject(vbrestrmonthscombojn) && vbrestrmonthscombojn.hasOwnProperty(nowm)) { | |
| 261 | + if (nowd in vbrestrmonthscombojn[nowm]) { | |
| 262 | + vbcombowdays = vbrestrmonthscombojn[nowm][nowd]; | |
| 263 | + } | |
| 264 | + } | |
| 265 | + if (jQuery.inArray((nowm + 1), vbrestrmonths) != -1) { | |
| 266 | + minlos = parseInt(vbrestrminlos[nowm]); | |
| 267 | + } | |
| 268 | + nowcheckindate.setDate(nowcheckindate.getDate() + minlos); | |
| 269 | + jQuery('#checkindate').vboDatesRangePicker('checkout', 'minDate', nowcheckindate); | |
| 270 | + jQuery('#checkindate').vboDatesRangePicker('checkout', 'minStayNights', minlos); | |
| 271 | + if (maxlosrange > 0) { | |
| 272 | + var diffmaxminlos = maxlosrange - minlos; | |
| 273 | + var maxcheckoutdate = new Date(nowcheckindate.getTime()); | |
| 274 | + maxcheckoutdate.setDate(maxcheckoutdate.getDate() + diffmaxminlos); | |
| 275 | + jQuery('#checkindate').vboDatesRangePicker('checkout', 'maxDate', maxcheckoutdate); | |
| 276 | + } | |
| 277 | + if (nowm in vbrestrmaxlos) { | |
| 278 | + var diffmaxminlos = parseInt(vbrestrmaxlos[nowm]) - minlos; | |
| 279 | + var maxcheckoutdate = new Date(nowcheckindate.getTime()); | |
| 280 | + maxcheckoutdate.setDate(maxcheckoutdate.getDate() + diffmaxminlos); | |
| 281 | + jQuery('#checkindate').vboDatesRangePicker('checkout', 'maxDate', maxcheckoutdate); | |
| 282 | + } | |
| 283 | + if (!vbFullObject(vbcombowdays)) { | |
| 284 | + var is_checkout_disabled = false; | |
| 285 | + if (typeof selectedDate !== 'undefined' && typeof jQuery('#checkindate').vboDatesRangePicker('drpoption', 'beforeShowDay.checkout') === 'function') { | |
| 286 | + // let the datepicker validate if the min date to set for check-out is disabled due to CTD rules | |
| 287 | + is_checkout_disabled = !jQuery('#checkindate').vboDatesRangePicker('drpoption', 'beforeShowDay.checkout')(nowcheckindate)[0]; | |
| 288 | + } | |
| 289 | + if (!is_checkout_disabled) { | |
| 290 | + jQuery('#checkindate').vboDatesRangePicker('checkout', 'setCheckoutDate', nowcheckindate); | |
| 291 | + } else { | |
| 292 | + setTimeout(() => { | |
| 293 | + // make sure the minimum date just set for the checkout has not populated a CTD date that we do not want | |
| 294 | + var current_out_dt = jQuery('#checkindate').vboDatesRangePicker('getCheckoutDate'); | |
| 295 | + if (current_out_dt && current_out_dt.getTime() === nowcheckindate.getTime()) { | |
| 296 | + jQuery('#checkindate').vboDatesRangePicker('checkout', 'setCheckoutDate', null); | |
| 297 | + } | |
| 298 | + }, 100); | |
| 299 | + } | |
| 300 | + } else { | |
| 301 | + vbRefreshCheckout(nowcheckin); | |
| 302 | + } | |
| 303 | +}"; | |
| 304 | + | |
| 305 | + if ($wdaysrestrictions || $wdaysrestrictionsrange) { | |
| 306 | + $resdecl .= " | |
| 307 | +var vbrestrwdays = " . json_encode((object) $wdaysrestrictions) . "; | |
| 308 | +var vbrestrwdaystwo = " . json_encode((object) $wdaystworestrictions) . "; | |
| 309 | +function vbIsDayDisabled(date) { | |
| 310 | + if (!vbIsDayOpen(date) || !vboValidateCta(date)) { | |
| 311 | + return [false]; | |
| 312 | + } | |
| 313 | + var m = date.getMonth(), wd = date.getDay(); | |
| 314 | + if (vbFullObject(vbrestrwdaysrangejn)) { | |
| 315 | + for (var rk in vbrestrwdaysrangejn) { | |
| 316 | + if (vbrestrwdaysrangejn.hasOwnProperty(rk)) { | |
| 317 | + var wdrangeinit = vbGetDateObject(vbrestrwdaysrangejn[rk][0]); | |
| 318 | + if (date >= wdrangeinit) { | |
| 319 | + var wdrangeend = vbGetDateObject(vbrestrwdaysrangejn[rk][1]); | |
| 320 | + if (date <= wdrangeend) { | |
| 321 | + if (wd != vbrestrwdaysrangejn[rk][2]) { | |
| 322 | + if (vbrestrwdaysrangejn[rk][4] == -1 || wd != vbrestrwdaysrangejn[rk][4]) { | |
| 323 | + return [false]; | |
| 324 | + } | |
| 325 | + } | |
| 326 | + } | |
| 327 | + } | |
| 328 | + } | |
| 329 | + } | |
| 330 | + } | |
| 331 | + if (vbFullObject(vbrestrwdays)) { | |
| 332 | + if (jQuery.inArray((m+1), vbrestrmonthswdays) == -1) { | |
| 333 | + return [true]; | |
| 334 | + } | |
| 335 | + if (wd == vbrestrwdays[m]) { | |
| 336 | + return [true]; | |
| 337 | + } | |
| 338 | + if (vbFullObject(vbrestrwdaystwo)) { | |
| 339 | + if (wd == vbrestrwdaystwo[m]) { | |
| 340 | + return [true]; | |
| 341 | + } | |
| 342 | + } | |
| 343 | + return [false]; | |
| 344 | + } | |
| 345 | + return [true]; | |
| 346 | +} | |
| 347 | +function vbIsDayDisabledCheckout(date) { | |
| 348 | + if (!vbIsDayOpen(date) || !vboValidateCtd(date)) { | |
| 349 | + return [false]; | |
| 350 | + } | |
| 351 | + var m = date.getMonth(), wd = date.getDay(); | |
| 352 | + if (vbFullObject(vbcombowdays)) { | |
| 353 | + if (jQuery.inArray(wd, vbcombowdays) != -1) { | |
| 354 | + return [true]; | |
| 355 | + } else { | |
| 356 | + return [false]; | |
| 357 | + } | |
| 358 | + } | |
| 359 | + if (vbFullObject(vbrestrwdaysrangejn)) { | |
| 360 | + for (var rk in vbrestrwdaysrangejn) { | |
| 361 | + if (vbrestrwdaysrangejn.hasOwnProperty(rk)) { | |
| 362 | + var wdrangeinit = vbGetDateObject(vbrestrwdaysrangejn[rk][0]); | |
| 363 | + if (date >= wdrangeinit) { | |
| 364 | + var wdrangeend = vbGetDateObject(vbrestrwdaysrangejn[rk][1]); | |
| 365 | + if (date <= wdrangeend) { | |
| 366 | + if (wd != vbrestrwdaysrangejn[rk][2] && vbrestrwdaysrangejn[rk][3] == 1) { | |
| 367 | + return [false]; | |
| 368 | + } | |
| 369 | + } | |
| 370 | + } | |
| 371 | + } | |
| 372 | + } | |
| 373 | + } | |
| 374 | + if (vbFullObject(vbrestrwdays)) { | |
| 375 | + if (jQuery.inArray((m+1), vbrestrmonthswdays) == -1 || jQuery.inArray((m+1), vbrestrmultiplyminlos) != -1) { | |
| 376 | + return [true]; | |
| 377 | + } | |
| 378 | + if (wd == vbrestrwdays[m]) { | |
| 379 | + return [true]; | |
| 380 | + } | |
| 381 | + return [false]; | |
| 382 | + } | |
| 383 | + return [true]; | |
| 384 | +}"; | |
| 385 | + } | |
| 386 | + $document->addScriptDeclaration($resdecl); | |
| 387 | + } | |
| 388 | + | |
| 389 | + // global closing dates | |
| 390 | + $closing_dates = VikBooking::parseJsClosingDates(); | |
| 391 | + $sdecl = " | |
| 392 | +var vbclosingdates = " . json_encode($closing_dates) . "; | |
| 393 | +function vbCheckClosingDatesIn(date) { | |
| 394 | + if (!vbIsDayOpen(date) || !vboValidateCta(date)) { | |
| 395 | + return [false]; | |
| 396 | + } | |
| 397 | + return [true]; | |
| 398 | +} | |
| 399 | +function vbCheckClosingDatesOut(date) { | |
| 400 | + if (!vbIsDayOpen(date) || !vboValidateCtd(date)) { | |
| 401 | + return [false]; | |
| 402 | + } | |
| 403 | + return [true]; | |
| 404 | +} | |
| 405 | +function vbIsDayOpen(date) { | |
| 406 | + if (vbFullObject(vbclosingdates)) { | |
| 407 | + for (var cd in vbclosingdates) { | |
| 408 | + if (vbclosingdates.hasOwnProperty(cd)) { | |
| 409 | + var cdfrom = vbGetDateObject(vbclosingdates[cd][0]); | |
| 410 | + var cdto = vbGetDateObject(vbclosingdates[cd][1]); | |
| 411 | + if (date >= cdfrom && date <= cdto) { | |
| 412 | + return false; | |
| 413 | + } | |
| 414 | + } | |
| 415 | + } | |
| 416 | + } | |
| 417 | + return true; | |
| 418 | +} | |
| 419 | +function vboValidateCta(date) { | |
| 420 | + var m = date.getMonth(), wd = date.getDay(); | |
| 421 | + if (vbFullObject(vbrestrctarange)) { | |
| 422 | + for (var rk in vbrestrctarange) { | |
| 423 | + if (vbrestrctarange.hasOwnProperty(rk)) { | |
| 424 | + var wdrangeinit = vbGetDateObject(vbrestrctarange[rk][0]); | |
| 425 | + if (date >= wdrangeinit) { | |
| 426 | + var wdrangeend = vbGetDateObject(vbrestrctarange[rk][1]); | |
| 427 | + if (date <= wdrangeend) { | |
| 428 | + if (jQuery.inArray('-'+wd+'-', vbrestrctarange[rk][2]) >= 0) { | |
| 429 | + return false; | |
| 430 | + } | |
| 431 | + } | |
| 432 | + } | |
| 433 | + } | |
| 434 | + } | |
| 435 | + } | |
| 436 | + if (vbFullObject(vbrestrcta)) { | |
| 437 | + if (vbrestrcta.hasOwnProperty(m) && jQuery.inArray('-'+wd+'-', vbrestrcta[m]) >= 0) { | |
| 438 | + return false; | |
| 439 | + } | |
| 440 | + } | |
| 441 | + return true; | |
| 442 | +} | |
| 443 | +function vboValidateCtd(date) { | |
| 444 | + var m = date.getMonth(), wd = date.getDay(); | |
| 445 | + if (vbFullObject(vbrestrctdrange)) { | |
| 446 | + for (var rk in vbrestrctdrange) { | |
| 447 | + if (vbrestrctdrange.hasOwnProperty(rk)) { | |
| 448 | + var wdrangeinit = vbGetDateObject(vbrestrctdrange[rk][0]); | |
| 449 | + if (date >= wdrangeinit) { | |
| 450 | + var wdrangeend = vbGetDateObject(vbrestrctdrange[rk][1]); | |
| 451 | + if (date <= wdrangeend) { | |
| 452 | + if (jQuery.inArray('-'+wd+'-', vbrestrctdrange[rk][2]) >= 0) { | |
| 453 | + return false; | |
| 454 | + } | |
| 455 | + } | |
| 456 | + } | |
| 457 | + } | |
| 458 | + } | |
| 459 | + } | |
| 460 | + if (vbFullObject(vbrestrctd)) { | |
| 461 | + if (vbrestrctd.hasOwnProperty(m) && jQuery.inArray('-'+wd+'-', vbrestrctd[m]) >= 0) { | |
| 462 | + return false; | |
| 463 | + } | |
| 464 | + } | |
| 465 | + return true; | |
| 466 | +} | |
| 467 | +function vbSetGlobalMinCheckoutDate() { | |
| 468 | + var minlos = ".VikBooking::getDefaultNightsCalendar()."; | |
| 469 | + var nowcheckin = jQuery('#checkindate').vboDatesRangePicker('getCheckinDate'); | |
| 470 | + var nowcheckindate = new Date(nowcheckin.getTime()); | |
| 471 | + nowcheckindate.setDate(nowcheckindate.getDate() + minlos); | |
| 472 | + jQuery('#checkindate').vboDatesRangePicker('checkout', 'minDate', nowcheckindate); | |
| 473 | + jQuery('#checkindate').vboDatesRangePicker('checkout', 'minStayNights', minlos); | |
| 474 | + jQuery('#checkindate').vboDatesRangePicker('checkout', 'setCheckoutDate', nowcheckindate); | |
| 475 | +} | |
| 476 | + | |
| 477 | +jQuery(function() { | |
| 478 | + // reset regional | |
| 479 | + jQuery.datepicker.setDefaults(jQuery.datepicker.regional['']); | |
| 480 | + | |
| 481 | + // start DRP | |
| 482 | + jQuery('#checkindate').vboDatesRangePicker({ | |
| 483 | + checkout: '#checkoutdate', | |
| 484 | + dateFormat: '{$juidf}', | |
| 485 | + showOn: 'focus', | |
| 486 | + numberOfMonths: " . ($is_mobile ? '1' : '2') . ", | |
| 487 | + minDate: '" . VikBooking::getMinDaysAdvance() . "d', | |
| 488 | + maxDate: '" . VikBooking::getMaxDateFuture() . "', | |
| 489 | + beforeShowDay: { | |
| 490 | + checkin: " . ($wdaysrestrictions || $wdaysrestrictionsrange ? 'vbIsDayDisabled' : 'vbCheckClosingDatesIn') . ", | |
| 491 | + checkout: " . ($wdaysrestrictions || $wdaysrestrictionsrange ? 'vbIsDayDisabledCheckout' : 'vbCheckClosingDatesOut') . ", | |
| 492 | + }, | |
| 493 | + onSelect: { | |
| 494 | + checkin: (selectedDate) => { | |
| 495 | + " . ($totrestrictions ? 'vbSetMinCheckoutDate(selectedDate);' : 'vbSetGlobalMinCheckoutDate();') . " | |
| 496 | + vbCalcNights(); | |
| 497 | + }, | |
| 498 | + checkout: (selectedDate) => { | |
| 499 | + vbCalcNights(); | |
| 500 | + }, | |
| 501 | + }, | |
| 502 | + labels: { | |
| 503 | + checkin: Joomla.JText._('VBPICKUPROOM'), | |
| 504 | + checkout: Joomla.JText._('VBRETURNROOM'), | |
| 505 | + minStayNights: (nights) => { | |
| 506 | + return (Joomla.JText._('VBO_MIN_STAY_NIGHTS') + '').replace('%d', nights); | |
| 507 | + }, | |
| 508 | + }, | |
| 509 | + bottomCommands: { | |
| 510 | + clear: Joomla.JText._('VBO_CLEAR_DATES'), | |
| 511 | + close: Joomla.JText._('VBO_CLOSE'), | |
| 512 | + onClear: () => { | |
| 513 | + vbCalcNights(); | |
| 514 | + }, | |
| 515 | + }, | |
| 516 | + }); | |
| 517 | + | |
| 518 | + // set proper regional | |
| 519 | + jQuery('#checkindate').datepicker('option', jQuery.datepicker.regional['vikbooking']); | |
| 520 | + | |
| 521 | + // register additional triggers | |
| 522 | + jQuery('.vb-cal-img, .vbo-caltrigger').click(function() { | |
| 523 | + let dp = jQuery(this).prev('input'); | |
| 524 | + if (!dp.length) { | |
| 525 | + return; | |
| 526 | + } | |
| 527 | + if (dp.hasClass('hasDatepicker')) { | |
| 528 | + dp.focus(); | |
| 529 | + } else if (dp.attr('id') == 'checkoutdate') { | |
| 530 | + jQuery('#checkindate').focus(); | |
| 531 | + } | |
| 532 | + }); | |
| 533 | +});"; | |
| 534 | + | |
| 535 | + // add script declaration to document | |
| 536 | + $document->addScriptDeclaration($sdecl); | |
| 537 | + | |
| 538 | + // add HTML code to the form | |
| 539 | + $selform .= "<div class=\"vbo-search-inpblock vbo-search-inpblock-checkin\"><label for=\"checkindate\">" . JText::translate('VBPICKUPROOM') . "</label><div class=\"input-group\"><input type=\"text\" name=\"checkindate\" id=\"checkindate\" size=\"10\" autocomplete=\"off\" onfocus=\"this.blur();\" readonly/><i class=\"".VikBookingIcons::i('calendar', 'vbo-caltrigger')."\"></i></div><input type=\"hidden\" name=\"checkinh\" value=\"".$hcheckin."\"/><input type=\"hidden\" name=\"checkinm\" value=\"".$mcheckin."\"/></div>\n"; | |
| 540 | + $selform .= "<div class=\"vbo-search-inpblock vbo-search-inpblock-checkout\"><label for=\"checkoutdate\">" . JText::translate('VBRETURNROOM') . "</label><div class=\"input-group\"><input type=\"text\" name=\"checkoutdate\" id=\"checkoutdate\" size=\"10\" autocomplete=\"off\" onfocus=\"this.blur();\" readonly/><i class=\"".VikBookingIcons::i('calendar', 'vbo-caltrigger')."\"></i></div><input type=\"hidden\" name=\"checkouth\" value=\"".$hcheckout."\"/><input type=\"hidden\" name=\"checkoutm\" value=\"".$mcheckout."\"/></div>\n"; | |
| 541 | + } else { | |
| 542 | + // default platform Calendar | |
| 543 | + $selform .= "<div class=\"vbo-search-inpblock vbo-search-inpblock-checkin\"><label for=\"checkindate\">" . JText::translate('VBPICKUPROOM') . "</label><div class=\"input-group\">" . $vbo_app->getCalendar('', 'checkindate', 'checkindate', $vbdateformat, array ('class' => '','size' => '10','maxlength' => '19')); | |
| 544 | + $selform .= "<input type=\"hidden\" name=\"checkinh\" value=\"".$hcheckin."\"/><input type=\"hidden\" name=\"checkinm\" value=\"".$mcheckin."\"/></div></div>\n"; | |
| 545 | + $selform .= "<div class=\"vbo-search-inpblock vbo-search-inpblock-checkout\"><label for=\"checkoutdate\">" . JText::translate('VBRETURNROOM') . "</label><div class=\"input-group\">" . $vbo_app->getCalendar('', 'checkoutdate', 'checkoutdate', $vbdateformat, array ('class' => '','size' => '10','maxlength' => '19')); | |
| 546 | + $selform .= "<input type=\"hidden\" name=\"checkouth\" value=\"".$hcheckout."\"/><input type=\"hidden\" name=\"checkoutm\" value=\"".$mcheckout."\"/></div></div>\n"; | |
| 547 | + } | |
| 548 | + | |
| 549 | + // rooms, adults, children | |
| 550 | + $showchildren = VikBooking::showChildrenFront(); | |
| 551 | + $guests_label = VBOFactory::getConfig()->get('guests_label', 'adults'); | |
| 552 | + $use_guests_label = 'VBFORMADULTS'; | |
| 553 | + if (!$showchildren && !strcasecmp($guests_label, 'guests')) { | |
| 554 | + $use_guests_label = 'VBOINVTOTGUESTS'; | |
| 555 | + } | |
| 556 | + | |
| 557 | + // max number of rooms | |
| 558 | + $maxsearchnumrooms = VikBooking::getSearchNumRooms(); | |
| 559 | + if (intval($maxsearchnumrooms) > 1) { | |
| 560 | + $roomsel = "<label for=\"vbo-roomsnum\">".JText::translate('VBFORMROOMSN')."</label><select id=\"vbo-roomsnum\" name=\"roomsnum\" onchange=\"vbSetRoomsAdults(this.value);\">\n"; | |
| 561 | + for($r = 1; $r <= $maxsearchnumrooms; $r++) { | |
| 562 | + $roomsel .= "<option value=\"".$r."\"".(!empty($oldroomsnum) && $oldroomsnum == $r ? " selected=\"selected\"" : "").">".$r."</option>\n"; | |
| 563 | + } | |
| 564 | + $roomsel .= "</select>\n"; | |
| 565 | + } else { | |
| 566 | + $roomsel = "<input type=\"hidden\" name=\"roomsnum\" value=\"1\">\n"; | |
| 567 | + } | |
| 568 | + | |
| 569 | + // max number of adults per room | |
| 570 | + $globnumadults = VikBooking::getSearchNumAdults(); | |
| 571 | + $adultsparts = explode('-', $globnumadults); | |
| 572 | + $adultsel = "<select name=\"adults[]\">"; | |
| 573 | + for($a = $adultsparts[0]; $a <= $adultsparts[1]; $a++) { | |
| 574 | + $adultsel .= "<option value=\"".$a."\"".((is_array($oldarrpeople) && isset($oldarrpeople[1]) && $oldarrpeople[1]['adults'] == $a) || (intval($adultsparts[0]) < 1 && $a == 1) ? " selected=\"selected\"" : "").">".$a."</option>"; | |
| 575 | + } | |
| 576 | + $adultsel .= "</select>"; | |
| 577 | + | |
| 578 | + // max number of children per room | |
| 579 | + $globnumchildren = VikBooking::getSearchNumChildren(); | |
| 580 | + $childrenparts = explode('-', $globnumchildren); | |
| 581 | + $childrensel = "<select name=\"children[]\">"; | |
| 582 | + for($c = $childrenparts[0]; $c <= $childrenparts[1]; $c++) { | |
| 583 | + $childrensel .= "<option value=\"".$c."\"".(is_array($oldarrpeople) && isset($oldarrpeople[1]) && $oldarrpeople[1]['children'] == $c ? " selected=\"selected\"" : "").">".$c."</option>"; | |
| 584 | + } | |
| 585 | + $childrensel .= "</select>"; | |
| 586 | + // | |
| 587 | + $selform .= "<div class=\"vbo-search-num-racblock\">\n"; | |
| 588 | + $selform .= " <div class=\"vbo-search-num-rooms\">".$roomsel."</div>\n"; | |
| 589 | + $selform .= " <div class=\"vbo-search-num-aduchild-block\" id=\"vbo-search-num-aduchild-block\">\n"; | |
| 590 | + $selform .= " <div class=\"vbo-search-num-aduchild-entry\">".(intval($maxsearchnumrooms) > 1 || (!empty($oldroomsnum) && (int)$oldroomsnum > 1) ? "<span class=\"vbo-search-roomnum\">".JText::translate('VBFORMNUMROOM')." 1</span>" : "")."\n"; | |
| 591 | + $selform .= " <div class=\"vbo-search-num-adults-entry\"><label class=\"vbo-search-num-adults-entry-label\">".JText::translate($use_guests_label)."</label><span class=\"vbo-search-num-adults-entry-inp\">".$adultsel."</span></div>\n"; | |
| 592 | + if ($showchildren) { | |
| 593 | + $selform .= " <div class=\"vbo-search-num-children-entry\"><label class=\"vbo-search-num-children-entry-label\">".JText::translate('VBFORMCHILDREN')."</label><span class=\"vbo-search-num-children-entry-inp\">".$childrensel."</span></div>\n"; | |
| 594 | + } | |
| 595 | + $selform .= " </div>\n"; | |
| 596 | + $selform .= " </div>\n"; | |
| 597 | + //the tag <div id=\"vbjstotnights\"></div> will be used by javascript to calculate the nights | |
| 598 | + $selform .= " <div id=\"vbjstotnights\"></div>\n"; | |
| 599 | + $selform .= "</div>\n"; | |
| 600 | + if (VikBooking::showCategoriesFront()) { | |
| 601 | + $q = "SELECT * FROM `#__vikbooking_categories` ORDER BY `#__vikbooking_categories`.`name` ASC;"; | |
| 602 | + $dbo->setQuery($q); | |
| 603 | + $categories = $dbo->loadAssocList(); | |
| 604 | + if ($categories) { | |
| 605 | + $vbo_tn->translateContents($categories, '#__vikbooking_categories'); | |
| 606 | + $selform .= "<div class=\"vbo-search-categories\"><label for=\"vbo-formcategories\" class=\"vbformcategories\">" . JText::translate('VBROOMCAT') . "</label><select id=\"vbo-formcategories\" name=\"categories\">"; | |
| 607 | + $selform .= "<option value=\"all\">" . JText::translate('VBALLCAT') . "</option>\n"; | |
| 608 | + foreach ($categories as $cat) { | |
| 609 | + $selform .= "<option value=\"" . $cat['id'] . "\"" . ($pcategories == (string)$cat['id'] ? ' selected="selected"' : '') . ">" . $cat['name'] . "</option>\n"; | |
| 610 | + } | |
| 611 | + $selform .= "</select></div>\n"; | |
| 612 | + } | |
| 613 | + } | |
| 614 | + $selform .= "<div class=\"vbo-search-submit\"><button type=\"submit\" class=\"btn vbo-pref-color-btn\">" . JText::translate('VBSEARCHBUTTON') . "</button></div>\n"; | |
| 615 | + $selform .= "</div>\n"; | |
| 616 | + $selform .= (!empty ($pitemid) ? "<input type=\"hidden\" name=\"Itemid\" value=\"" . $pitemid . "\"/>" : "") . "</form></div>"; | |
| 617 | + | |
| 618 | + ?> | |
| 619 | + <script type="text/javascript"> | |
| 620 | + function vbAddElement() { | |
| 621 | + var ni = document.getElementById('vbo-search-num-aduchild-block'); | |
| 622 | + var numi = document.getElementById('vbroomhelper'); | |
| 623 | + var num = (document.getElementById('vbroomhelper').value -1)+ 2; | |
| 624 | + numi.value = num; | |
| 625 | + var newdiv = document.createElement('div'); | |
| 626 | + var divIdName = 'vb'+num+'racont'; | |
| 627 | + newdiv.setAttribute('id',divIdName); | |
| 628 | + newdiv.innerHTML = '<div class=\'vbo-search-num-aduchild-entry\'><span class=\'vbo-search-roomnum\'><?php echo addslashes(JText::translate('VBFORMNUMROOM')); ?> '+ num +'</span><div class=\'vbo-search-num-adults-entry\'><label class=\'vbo-search-num-adults-entry-label\'><?php echo addslashes(JText::translate($use_guests_label)); ?></label><span class=\'vbo-search-num-adults-entry-inp\'><?php echo addslashes(str_replace('"', "'", $adultsel)); ?></span></div><?php if ($showchildren): ?><div class=\'vbo-search-num-children-entry\'><label class=\'vbo-search-num-children-entry-label\'><?php echo addslashes(JText::translate('VBFORMCHILDREN')); ?></label><span class=\'vbo-search-num-adults-entry-inp\'><?php echo addslashes(str_replace('"', "'", $childrensel)); ?></span></div><?php endif; ?></div>'; | |
| 629 | + ni.appendChild(newdiv); | |
| 630 | + } | |
| 631 | + function vbSetRoomsAdults(totrooms) { | |
| 632 | + var actrooms = parseInt(document.getElementById('vbroomhelper').value); | |
| 633 | + var torooms = parseInt(totrooms); | |
| 634 | + var difrooms; | |
| 635 | + if (torooms > actrooms) { | |
| 636 | + difrooms = torooms - actrooms; | |
| 637 | + for(var ir=1; ir<=difrooms; ir++) { | |
| 638 | + vbAddElement(); | |
| 639 | + } | |
| 640 | + } | |
| 641 | + if (torooms < actrooms) { | |
| 642 | + for(var ir=actrooms; ir>torooms; ir--) { | |
| 643 | + if (ir > 1) { | |
| 644 | + var rmra = document.getElementById('vb' + ir + 'racont'); | |
| 645 | + rmra.parentNode.removeChild(rmra); | |
| 646 | + } | |
| 647 | + } | |
| 648 | + document.getElementById('vbroomhelper').value = torooms; | |
| 649 | + } | |
| 650 | + } | |
| 651 | + function vbCalcNights() { | |
| 652 | + var vbcheckin = document.getElementById('checkindate').value; | |
| 653 | + var vbcheckout = document.getElementById('checkoutdate').value; | |
| 654 | + if (vbcheckin.length > 0 && vbcheckout.length > 0) { | |
| 655 | + var vbcheckinp = vbcheckin.split("/"); | |
| 656 | + var vbcheckoutp = vbcheckout.split("/"); | |
| 657 | + <?php | |
| 658 | + if ($vbdateformat == "%d/%m/%Y") { | |
| 659 | + ?> | |
| 660 | + var vbinmonth = parseInt(vbcheckinp[1]); | |
| 661 | + vbinmonth = vbinmonth - 1; | |
| 662 | + var vbinday = parseInt(vbcheckinp[0], 10); | |
| 663 | + var vbcheckind = new Date(vbcheckinp[2], vbinmonth, vbinday); | |
| 664 | + var vboutmonth = parseInt(vbcheckoutp[1]); | |
| 665 | + vboutmonth = vboutmonth - 1; | |
| 666 | + var vboutday = parseInt(vbcheckoutp[0], 10); | |
| 667 | + var vbcheckoutd = new Date(vbcheckoutp[2], vboutmonth, vboutday); | |
| 668 | + <?php | |
| 669 | + } elseif ($vbdateformat == "%m/%d/%Y") { | |
| 670 | + ?> | |
| 671 | + var vbinmonth = parseInt(vbcheckinp[0]); | |
| 672 | + vbinmonth = vbinmonth - 1; | |
| 673 | + var vbinday = parseInt(vbcheckinp[1], 10); | |
| 674 | + var vbcheckind = new Date(vbcheckinp[2], vbinmonth, vbinday); | |
| 675 | + var vboutmonth = parseInt(vbcheckoutp[0]); | |
| 676 | + vboutmonth = vboutmonth - 1; | |
| 677 | + var vboutday = parseInt(vbcheckoutp[1], 10); | |
| 678 | + var vbcheckoutd = new Date(vbcheckoutp[2], vboutmonth, vboutday); | |
| 679 | + <?php | |
| 680 | + } else { | |
| 681 | + ?> | |
| 682 | + var vbinmonth = parseInt(vbcheckinp[1]); | |
| 683 | + vbinmonth = vbinmonth - 1; | |
| 684 | + var vbinday = parseInt(vbcheckinp[2], 10); | |
| 685 | + var vbcheckind = new Date(vbcheckinp[0], vbinmonth, vbinday); | |
| 686 | + var vboutmonth = parseInt(vbcheckoutp[1]); | |
| 687 | + vboutmonth = vboutmonth - 1; | |
| 688 | + var vboutday = parseInt(vbcheckoutp[2], 10); | |
| 689 | + var vbcheckoutd = new Date(vbcheckoutp[0], vboutmonth, vboutday); | |
| 690 | + <?php | |
| 691 | + } | |
| 692 | + ?> | |
| 693 | + var vbdivider = 1000 * 60 * 60 * 24; | |
| 694 | + var vbints = vbcheckind.getTime(); | |
| 695 | + var vboutts = vbcheckoutd.getTime(); | |
| 696 | + if (vboutts > vbints) { | |
| 697 | + //var vbnights = Math.ceil((vboutts - vbints) / (vbdivider)); | |
| 698 | + var utc1 = Date.UTC(vbcheckind.getFullYear(), vbcheckind.getMonth(), vbcheckind.getDate()); | |
| 699 | + var utc2 = Date.UTC(vbcheckoutd.getFullYear(), vbcheckoutd.getMonth(), vbcheckoutd.getDate()); | |
| 700 | + var vbnights = Math.ceil((utc2 - utc1) / vbdivider); | |
| 701 | + if (vbnights > 0) { | |
| 702 | + document.getElementById('vbjstotnights').innerHTML = '<?php echo addslashes(JText::translate('VBJSTOTNIGHTS')); ?>: '+vbnights; | |
| 703 | + } else { | |
| 704 | + document.getElementById('vbjstotnights').innerHTML = ''; | |
| 705 | + } | |
| 706 | + } else { | |
| 707 | + document.getElementById('vbjstotnights').innerHTML = ''; | |
| 708 | + } | |
| 709 | + } else { | |
| 710 | + document.getElementById('vbjstotnights').innerHTML = ''; | |
| 711 | + } | |
| 712 | + } | |
| 713 | + </script> | |
| 714 | + <input type="hidden" id="vbroomhelper" value="1"/> | |
| 715 | + <?php | |
| 716 | + if (isset($err) && strlen($err)) { | |
| 717 | + echo "<p class=\"err\">" . $err . "</p>"; | |
| 718 | + } | |
| 719 | + ?> | |
| 720 | + <div class="vbo-intro-main"><?php echo VikBooking::getIntroMain(); ?></div> | |
| 721 | + <?php | |
| 722 | + // write the form | |
| 723 | + echo $selform; | |
| 724 | + | |
| 725 | + // check for guests allowed policy | |
| 726 | + if (!$showchildren && $guests_allowed_policy = VikBooking::getGuestsAllowedPolicy($vbo_tn)) { | |
| 727 | + ?> | |
| 728 | + <div class="vbo-guests-allowed-policy"><?php echo $guests_allowed_policy; ?></div> | |
| 729 | + <?php | |
| 730 | + } | |
| 731 | + ?> | |
| 732 | + <div class="vbo-closing-main"><?php echo VikBooking::getClosingMain(); ?></div> | |
| 733 | + | |
| 734 | + <script type="text/javascript"> | |
| 735 | + jQuery(function() { | |
| 736 | + jQuery('.vbo-search-submit').find('button[type="submit"]').on('click', function(e) { | |
| 737 | + e.preventDefault(); | |
| 738 | + jQuery(this).prop('disabled', true); | |
| 739 | + jQuery(this).html('<?php VikBookingIcons::e('circle-notch', 'fa-spin fa-fw'); ?> ' + jQuery(this).text()); | |
| 740 | + jQuery(this).closest('form').submit(); | |
| 741 | + }); | |
| 742 | + }); | |
| 743 | + </script> | |
| 744 | + | |
| 745 | + <?php | |
| 746 | + //search suggestions | |
| 747 | + if (isset($err_code_info) && count($err_code_info) > 0 && (int)VikBooking::showSearchSuggestions() > 0) { | |
| 748 | + if (!empty($pitemid) && !isset($err_code_info['Itemid'])) { | |
| 749 | + $err_code_info['Itemid'] = $pitemid; | |
| 750 | + } | |
| 751 | + | |
| 752 | + /** | |
| 753 | + * We also inject the current category filter to suggest only rooms of the same category. | |
| 754 | + * | |
| 755 | + * @since 1.14 (J) - 1.4.0 (WP) | |
| 756 | + */ | |
| 757 | + if (!empty($pcategories) && $pcategories != 'all') { | |
| 758 | + $err_code_info['categories'] = $pcategories; | |
| 759 | + } | |
| 760 | + // | |
| 761 | + | |
| 762 | + /** | |
| 763 | + * Clients have reported that in case of error code #1 (no availability for the party requested, but some rooms would | |
| 764 | + * be able to allocate the party in the rooms that are simply not available on the requested dates), we should not | |
| 765 | + * suggest only other closed booking dates, but rather check for also other possible booking solutions. In short, | |
| 766 | + * if the error code is #1, we should perform another AJAX request like if the error code was #2 (query failed for | |
| 767 | + * fetching the rooms, no rates defined for this number of nights or no rooms for the party requested). | |
| 768 | + * | |
| 769 | + * @since 1.13.5 (J) - 1.3.6 (WP) | |
| 770 | + */ | |
| 771 | + $rq_err_code_infos = array(); | |
| 772 | + if ($err_code_info['code'] === 1) { | |
| 773 | + // clone the error code info array | |
| 774 | + $copy_errcode = $err_code_info; | |
| 775 | + // overwrite error code to #2 | |
| 776 | + $copy_errcode['code'] = 2; | |
| 777 | + // push first request to fetch other possible rooms (higher priority to get the booking) | |
| 778 | + array_push($rq_err_code_infos, $copy_errcode); | |
| 779 | + // then push the regular error code #1 to find the closest available booking dates | |
| 780 | + array_push($rq_err_code_infos, $err_code_info); | |
| 781 | + // if split stays are enabled, we invert the error code positions | |
| 782 | + if (VBOFactory::getConfig()->get('split_stay_ratio', 0) > 0) { | |
| 783 | + $rq_err_code_infos = array_reverse($rq_err_code_infos); | |
| 784 | + } | |
| 785 | + } else { | |
| 786 | + // push the regular error code info to make just one request | |
| 787 | + array_push($rq_err_code_infos, $err_code_info); | |
| 788 | + } | |
| 789 | + ?> | |
| 790 | + <div id="vbo-search-suggestions"></div> | |
| 791 | + <script type="text/javascript"> | |
| 792 | + jQuery(function() { | |
| 793 | + <?php | |
| 794 | + foreach ($rq_err_code_infos as $rq_index => $err_code_info) { | |
| 795 | + ?> | |
| 796 | + setTimeout(function() { | |
| 797 | + var jqxhr = jQuery.ajax({ | |
| 798 | + type: "POST", | |
| 799 | + url: "<?php echo VikBooking::ajaxUrl(JRoute::rewrite('index.php?option=com_vikbooking&view=searchsuggestions&getjson=1&tmpl=component', false)); ?>", | |
| 800 | + data: <?php echo json_encode($err_code_info); ?> | |
| 801 | + }).done(function(res) { | |
| 802 | + try { | |
| 803 | + // response is a JSON-encoded array | |
| 804 | + var out = JSON.parse(res); | |
| 805 | + jQuery("#vbo-search-suggestions").append(out[0]); | |
| 806 | + } catch (err) { | |
| 807 | + jQuery("#vbo-search-suggestions").html(res); | |
| 808 | + } | |
| 809 | + }).fail(function() { | |
| 810 | + console.log('Failure event when calling the search suggestions view'); | |
| 811 | + }); | |
| 812 | + }, <?php echo $rq_index * 500; ?>); | |
| 813 | + <?php | |
| 814 | + } | |
| 815 | + ?> | |
| 816 | + }); | |
| 817 | + </script> | |
| 818 | + <?php | |
| 819 | + } | |
| 820 | + // | |
| 821 | + //echo javascript to fill the date values | |
| 822 | + if (!empty ($pval) && !empty ($rval)) { | |
| 823 | + if ($calendartype == "jqueryui") { | |
| 824 | + ?> | |
| 825 | + <script type="text/javascript"> | |
| 826 | + jQuery(function() { | |
| 827 | + jQuery('#checkindate').val('<?php echo $pval; ?>'); | |
| 828 | + jQuery('#checkoutdate').val('<?php echo $rval; ?>'); | |
| 829 | + }); | |
| 830 | + </script> | |
| 831 | + <?php | |
| 832 | + } else { | |
| 833 | + ?> | |
| 834 | + <script type="text/javascript"> | |
| 835 | + document.getElementById('checkindate').value='<?php echo $pval; ?>'; | |
| 836 | + document.getElementById('checkoutdate').value='<?php echo $rval; ?>'; | |
| 837 | + </script> | |
| 838 | + <?php | |
| 839 | + } | |
| 840 | + } | |
| 841 | + // | |
| 842 | + if (!empty($oldroomsnum) && $oldroomsnum > 1 && count($oldarrpeople) > 0) { | |
| 843 | + $oldroomscountadults = array(); | |
| 844 | + $oldroomscountchildren = array(); | |
| 845 | + for($i = 2; $i <= $oldroomsnum; $i++) { | |
| 846 | + $globnumadults = VikBooking::getSearchNumAdults(); | |
| 847 | + $adultsparts = explode('-', $globnumadults); | |
| 848 | + $adultsel = "<select name=\"adults[]\">"; | |
| 849 | + for($a = $adultsparts[0]; $a <= $adultsparts[1]; $a++) { | |
| 850 | + $adultsel .= "<option value=\"".$a."\"".(($oldarrpeople[$i]['adults'] ?? null) == $a ? " selected=\"selected\"" : "").">".$a."</option>"; | |
| 851 | + } | |
| 852 | + $adultsel .= "</select>"; | |
| 853 | + $oldroomscountadults[$i] = $adultsel; | |
| 854 | + $globnumchildren = VikBooking::getSearchNumChildren(); | |
| 855 | + $childrenparts = explode('-', $globnumchildren); | |
| 856 | + $childrensel = "<select name=\"children[]\">"; | |
| 857 | + for($c = $childrenparts[0]; $c <= $childrenparts[1]; $c++) { | |
| 858 | + $childrensel .= "<option value=\"".$c."\"".(($oldarrpeople[$i]['children'] ?? null) == $c ? " selected=\"selected\"" : "").">".$c."</option>"; | |
| 859 | + } | |
| 860 | + $childrensel .= "</select>"; | |
| 861 | + $oldroomscountchildren[$i] = $childrensel; | |
| 862 | + } | |
| 863 | + ?> | |
| 864 | + <script type="text/javascript"> | |
| 865 | + function vbAddElementSession() { | |
| 866 | + var oldradultsvals = new Array(); | |
| 867 | + var oldrchildrenvals = new Array(); | |
| 868 | + <?php | |
| 869 | + for($i = 2; $i <= $oldroomsnum; $i++) { | |
| 870 | + ?> | |
| 871 | + oldradultsvals[<?php echo $i; ?>] = "<?php echo addslashes(str_replace('"', "'", $oldroomscountadults[$i])); ?>"; | |
| 872 | + oldrchildrenvals[<?php echo $i; ?>] = "<?php echo addslashes(str_replace('"', "'", $oldroomscountchildren[$i])); ?>"; | |
| 873 | + <?php | |
| 874 | + } | |
| 875 | + ?> | |
| 876 | + var ni = document.getElementById('vbo-search-num-aduchild-block'); | |
| 877 | + var numi = document.getElementById('vbroomhelper'); | |
| 878 | + var num = (document.getElementById('vbroomhelper').value -1)+ 2; | |
| 879 | + numi.value = num; | |
| 880 | + var newdiv = document.createElement('div'); | |
| 881 | + var divIdName = 'vb'+num+'racont'; | |
| 882 | + newdiv.setAttribute('id',divIdName); | |
| 883 | + newdiv.innerHTML = '<div class=\'vbo-search-num-aduchild-entry\'><span class=\'vbo-search-roomnum\'><?php echo addslashes(JText::translate('VBFORMNUMROOM')); ?> '+ num +'</span><div class=\'vbo-search-num-adults-entry\'><span class=\'vbo-search-num-adults-entry-label\'><?php echo addslashes(JText::translate($use_guests_label)); ?></span><span class=\'vbo-search-num-adults-entry-inp\'>'+ oldradultsvals[num] +'</span></div><?php if ($showchildren): ?><div class=\'vbo-search-num-children-entry\'><span class=\'vbo-search-num-children-entry-label\'><?php echo addslashes(JText::translate('VBFORMCHILDREN')); ?></span><span class=\'vbo-search-num-adults-entry-inp\'>'+ oldrchildrenvals[num] +'</span></div><?php endif; ?></div>'; | |
| 884 | + ni.appendChild(newdiv); | |
| 885 | + } | |
| 886 | + function vbSetRoomsAdultsSession(totrooms) { | |
| 887 | + var actrooms = parseInt(document.getElementById('vbroomhelper').value); | |
| 888 | + var torooms = parseInt(totrooms); | |
| 889 | + var difrooms; | |
| 890 | + if (torooms > actrooms) { | |
| 891 | + difrooms = torooms - actrooms; | |
| 892 | + for(var ir=1; ir<=difrooms; ir++) { | |
| 893 | + vbAddElementSession(); | |
| 894 | + } | |
| 895 | + } | |
| 896 | + if (torooms < actrooms) { | |
| 897 | + for(var ir=actrooms; ir>torooms; ir--) { | |
| 898 | + if (ir > 1) { | |
| 899 | + var rmra = document.getElementById('vb' + ir + 'racont'); | |
| 900 | + rmra.parentNode.removeChild(rmra); | |
| 901 | + } | |
| 902 | + } | |
| 903 | + document.getElementById('vbroomhelper').value = torooms; | |
| 904 | + } | |
| 905 | + } | |
| 906 | + vbSetRoomsAdultsSession('<?php echo $oldroomsnum; ?>'); | |
| 907 | + </script> | |
| 908 | + <?php | |
| 909 | + } | |
| 910 | +} else { | |
| 911 | + echo VikBooking::getDisabledBookingMsg(); | |
| 912 | +} | |