| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage mod_vikbooking_horizontalsearch |
| 5 |
* @author Alessio Gaggii - E4J s.r.l |
| 6 |
* @copyright Copyright (C) 2018 E4J s.r.l. All rights reserved. |
| 7 |
* @license GNU General Public License version 2 or later; see LICENSE |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
$dbo = JFactory::getDbo(); |
| 15 |
$vbo_tn = VikBooking::getTranslator(); |
| 16 |
$is_mobile = VikBooking::detectUserAgent(false, false); |
| 17 |
|
| 18 |
$document = JFactory::getDocument(); |
| 19 |
$document->addStyleSheet($baseurl.'modules/mod_vikbooking_horizontalsearch/mod_vikbooking_horizontalsearch.css'); |
| 20 |
//load jQuery UI |
| 21 |
$document->addStyleSheet(VBO_SITE_URI.'resources/jquery-ui.min.css'); |
| 22 |
JHtml::fetch('script', VBO_SITE_URI.'resources/jquery-ui.min.js'); |
| 23 |
|
| 24 |
$timeopst = VikBooking::getTimeOpenStore(); |
| 25 |
$restrictions = VikBooking::loadRestrictions(); |
| 26 |
$vbdateformat = VikBooking::getDateFormat(); |
| 27 |
if ($vbdateformat == "%d/%m/%Y") { |
| 28 |
$df = 'd/m/Y'; |
| 29 |
} elseif ($vbdateformat == "%m/%d/%Y") { |
| 30 |
$df = 'm/d/Y'; |
| 31 |
} else { |
| 32 |
$df = 'Y/m/d'; |
| 33 |
} |
| 34 |
|
| 35 |
// define the dates layout type |
| 36 |
$dates_layout_type = $params->get('datestype'); |
| 37 |
// whether the inquiry form should be displayed |
| 38 |
$needs_inquiry = ($dates_layout_type == 'inquiry'); |
| 39 |
// inquiry layout has got the same output as the human |
| 40 |
$dates_layout_type = $dates_layout_type == 'inquiry' ? 'human' : $dates_layout_type; |
| 41 |
|
| 42 |
// define the apposite wrapper class |
| 43 |
$wrapper_class = 'vbo-horizsearch-standardformat-wrap'; |
| 44 |
if ($params->get('datestype') == 'human') { |
| 45 |
$wrapper_class = 'vbo-horizsearch-humanformat-wrap'; |
| 46 |
} elseif ($params->get('datestype') == 'inquiry') { |
| 47 |
$wrapper_class = 'vbo-horizsearch-inquiryformat-wrap'; |
| 48 |
} |
| 49 |
|
| 50 |
// language definitions for JS |
| 51 |
JText::script('VBO_PLEASE_FILL_FIELDS'); |
| 52 |
JText::script('VBO_PLEASE_SEL_DATES'); |
| 53 |
JText::script('VBO_THANKS_INQ_SUBMITTED'); |
| 54 |
|
| 55 |
?> |
| 56 |
|
| 57 |
<div class="vbmodhorsearchmaindiv <?php echo $wrapper_class; ?>"> |
| 58 |
<form action="<?php echo JRoute::rewrite('index.php?option=com_vikbooking&task=search&Itemid=' . $params->get('itemid', 0)); ?>" method="post" id="vbo-mod-horsearch-form-<?php echo $randid; ?>"> |
| 59 |
<input type="hidden" name="task" value="search" /> |
| 60 |
<?php |
| 61 |
if (intval($params->get('room_id')) > 0) { |
| 62 |
?> |
| 63 |
<input type="hidden" name="roomdetail" value="<?php echo $params->get('room_id'); ?>" /> |
| 64 |
<?php |
| 65 |
} |
| 66 |
if (is_array($timeopst)) { |
| 67 |
$opent = VikBooking::getHoursMinutes($timeopst[0]); |
| 68 |
$closet = VikBooking::getHoursMinutes($timeopst[1]); |
| 69 |
$hcheckin = $opent[0]; |
| 70 |
$mcheckin = $opent[1]; |
| 71 |
$hcheckout = $closet[0]; |
| 72 |
$mcheckout = $closet[1]; |
| 73 |
} else { |
| 74 |
$hcheckin = 0; |
| 75 |
$mcheckin = 0; |
| 76 |
$hcheckout = 0; |
| 77 |
$mcheckout = 0; |
| 78 |
} |
| 79 |
|
| 80 |
if ($vbdateformat == "%d/%m/%Y") { |
| 81 |
$juidf = 'dd/mm/yy'; |
| 82 |
} elseif ($vbdateformat == "%m/%d/%Y") { |
| 83 |
$juidf = 'mm/dd/yy'; |
| 84 |
} else { |
| 85 |
$juidf = 'yy/mm/dd'; |
| 86 |
} |
| 87 |
|
| 88 |
// lang for jQuery UI Calendar |
| 89 |
$is_rtl_str = 'false'; |
| 90 |
$now_lang = JFactory::getLanguage(); |
| 91 |
if (method_exists($now_lang, 'isRtl')) { |
| 92 |
$is_rtl_str = $now_lang->isRtl() ? 'true' : $is_rtl_str; |
| 93 |
} |
| 94 |
|
| 95 |
$ldecl = ' |
| 96 |
jQuery.noConflict(); |
| 97 |
jQuery(function($){'."\n".' |
| 98 |
$.datepicker.regional["vikbookingmod"] = {'."\n".' |
| 99 |
closeText: "'.JText::translate('VBJQCALDONE').'",'."\n".' |
| 100 |
prevText: "'.JText::translate('VBJQCALPREV').'",'."\n".' |
| 101 |
nextText: "'.JText::translate('VBJQCALNEXT').'",'."\n".' |
| 102 |
currentText: "'.JText::translate('VBJQCALTODAY').'",'."\n".' |
| 103 |
monthNames: ["'.JText::translate('VBMONTHONE').'","'.JText::translate('VBMONTHTWO').'","'.JText::translate('VBMONTHTHREE').'","'.JText::translate('VBMONTHFOUR').'","'.JText::translate('VBMONTHFIVE').'","'.JText::translate('VBMONTHSIX').'","'.JText::translate('VBMONTHSEVEN').'","'.JText::translate('VBMONTHEIGHT').'","'.JText::translate('VBMONTHNINE').'","'.JText::translate('VBMONTHTEN').'","'.JText::translate('VBMONTHELEVEN').'","'.JText::translate('VBMONTHTWELVE').'"],'."\n".' |
| 104 |
monthNamesShort: ["'.mb_substr(JText::translate('VBMONTHONE'), 0, 3, 'UTF-8').'","'.mb_substr(JText::translate('VBMONTHTWO'), 0, 3, 'UTF-8').'","'.mb_substr(JText::translate('VBMONTHTHREE'), 0, 3, 'UTF-8').'","'.mb_substr(JText::translate('VBMONTHFOUR'), 0, 3, 'UTF-8').'","'.mb_substr(JText::translate('VBMONTHFIVE'), 0, 3, 'UTF-8').'","'.mb_substr(JText::translate('VBMONTHSIX'), 0, 3, 'UTF-8').'","'.mb_substr(JText::translate('VBMONTHSEVEN'), 0, 3, 'UTF-8').'","'.mb_substr(JText::translate('VBMONTHEIGHT'), 0, 3, 'UTF-8').'","'.mb_substr(JText::translate('VBMONTHNINE'), 0, 3, 'UTF-8').'","'.mb_substr(JText::translate('VBMONTHTEN'), 0, 3, 'UTF-8').'","'.mb_substr(JText::translate('VBMONTHELEVEN'), 0, 3, 'UTF-8').'","'.mb_substr(JText::translate('VBMONTHTWELVE'), 0, 3, 'UTF-8').'"],'."\n".' |
| 105 |
dayNames: ["'.JText::translate('VBJQCALSUN').'", "'.JText::translate('VBJQCALMON').'", "'.JText::translate('VBJQCALTUE').'", "'.JText::translate('VBJQCALWED').'", "'.JText::translate('VBJQCALTHU').'", "'.JText::translate('VBJQCALFRI').'", "'.JText::translate('VBJQCALSAT').'"],'."\n".' |
| 106 |
dayNamesShort: ["'.mb_substr(JText::translate('VBJQCALSUN'), 0, 3, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALMON'), 0, 3, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALTUE'), 0, 3, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALWED'), 0, 3, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALTHU'), 0, 3, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALFRI'), 0, 3, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALSAT'), 0, 3, 'UTF-8').'"],'."\n".' |
| 107 |
dayNamesMin: ["'.mb_substr(JText::translate('VBJQCALSUN'), 0, 2, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALMON'), 0, 2, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALTUE'), 0, 2, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALWED'), 0, 2, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALTHU'), 0, 2, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALFRI'), 0, 2, 'UTF-8').'", "'.mb_substr(JText::translate('VBJQCALSAT'), 0, 2, 'UTF-8').'"],'."\n".' |
| 108 |
weekHeader: "'.JText::translate('VBJQCALWKHEADER').'",'."\n".' |
| 109 |
dateFormat: "'.$juidf.'",'."\n".' |
| 110 |
firstDay: '.VikBooking::getFirstWeekDay().','."\n".' |
| 111 |
isRTL: ' . $is_rtl_str . ','."\n".' |
| 112 |
showMonthAfterYear: false,'."\n".' |
| 113 |
yearSuffix: ""'."\n".' |
| 114 |
};'."\n".' |
| 115 |
$.datepicker.setDefaults($.datepicker.regional["vikbookingmod"]);'."\n".' |
| 116 |
}); |
| 117 |
'.($dates_layout_type == 'human' ? VikBookingWidgetHorizontalSearch::getMonWdayScript($params->get('mondayslen'), $randid) : '').' |
| 118 |
function vbGetDateObject'.$randid.'(dstring) { |
| 119 |
var dparts = dstring.split("-"); |
| 120 |
return new Date(dparts[0], (parseInt(dparts[1]) - 1), parseInt(dparts[2]), 0, 0, 0, 0); |
| 121 |
} |
| 122 |
function vbFullObject'.$randid.'(obj) { |
| 123 |
var jk; |
| 124 |
for(jk in obj) { |
| 125 |
return obj.hasOwnProperty(jk); |
| 126 |
} |
| 127 |
} |
| 128 |
var vbrestrctarange, vbrestrctdrange, vbrestrcta, vbrestrctd;'; |
| 129 |
$document->addScriptDeclaration($ldecl); |
| 130 |
|
| 131 |
// global restrictions |
| 132 |
$totrestrictions = count($restrictions); |
| 133 |
$wdaysrestrictions = array(); |
| 134 |
$wdaystworestrictions = array(); |
| 135 |
$wdaysrestrictionsrange = array(); |
| 136 |
$wdaysrestrictionsmonths = array(); |
| 137 |
$ctarestrictionsrange = array(); |
| 138 |
$ctarestrictionsmonths = array(); |
| 139 |
$ctdrestrictionsrange = array(); |
| 140 |
$ctdrestrictionsmonths = array(); |
| 141 |
$monthscomborestr = array(); |
| 142 |
$minlosrestrictions = array(); |
| 143 |
$minlosrestrictionsrange = array(); |
| 144 |
$maxlosrestrictions = array(); |
| 145 |
$maxlosrestrictionsrange = array(); |
| 146 |
$notmultiplyminlosrestrictions = array(); |
| 147 |
if ($totrestrictions > 0) { |
| 148 |
foreach ($restrictions as $rmonth => $restr) { |
| 149 |
if ($rmonth != 'range') { |
| 150 |
if (strlen((string)$restr['wday'])) { |
| 151 |
$wdaysrestrictions[] = "'".($rmonth - 1)."': '".$restr['wday']."'"; |
| 152 |
$wdaysrestrictionsmonths[] = $rmonth; |
| 153 |
if (strlen((string)$restr['wdaytwo'])) { |
| 154 |
$wdaystworestrictions[] = "'".($rmonth - 1)."': '".$restr['wdaytwo']."'"; |
| 155 |
$monthscomborestr[($rmonth - 1)] = VikBooking::parseJsDrangeWdayCombo($restr); |
| 156 |
} |
| 157 |
} elseif (!empty($restr['ctad']) || !empty($restr['ctdd'])) { |
| 158 |
if (!empty($restr['ctad'])) { |
| 159 |
$ctarestrictionsmonths[($rmonth - 1)] = explode(',', $restr['ctad']); |
| 160 |
} |
| 161 |
if (!empty($restr['ctdd'])) { |
| 162 |
$ctdrestrictionsmonths[($rmonth - 1)] = explode(',', $restr['ctdd']); |
| 163 |
} |
| 164 |
} |
| 165 |
if ($restr['multiplyminlos'] == 0) { |
| 166 |
$notmultiplyminlosrestrictions[] = $rmonth; |
| 167 |
} |
| 168 |
$minlosrestrictions[] = "'".($rmonth - 1)."': '".$restr['minlos']."'"; |
| 169 |
if (!empty($restr['maxlos']) && $restr['maxlos'] > 0 && $restr['maxlos'] > $restr['minlos']) { |
| 170 |
$maxlosrestrictions[] = "'".($rmonth - 1)."': '".$restr['maxlos']."'"; |
| 171 |
} |
| 172 |
} else { |
| 173 |
foreach ($restr as $kr => $drestr) { |
| 174 |
if (strlen((string)$drestr['wday'])) { |
| 175 |
$wdaysrestrictionsrange[$kr][0] = date('Y-m-d', $drestr['dfrom']); |
| 176 |
$wdaysrestrictionsrange[$kr][1] = date('Y-m-d', $drestr['dto']); |
| 177 |
$wdaysrestrictionsrange[$kr][2] = $drestr['wday']; |
| 178 |
$wdaysrestrictionsrange[$kr][3] = $drestr['multiplyminlos']; |
| 179 |
$wdaysrestrictionsrange[$kr][4] = strlen((string)$drestr['wdaytwo']) ? $drestr['wdaytwo'] : -1; |
| 180 |
$wdaysrestrictionsrange[$kr][5] = VikBooking::parseJsDrangeWdayCombo($drestr); |
| 181 |
} elseif (!empty($drestr['ctad']) || !empty($drestr['ctdd'])) { |
| 182 |
$ctfrom = date('Y-m-d', $drestr['dfrom']); |
| 183 |
$ctto = date('Y-m-d', $drestr['dto']); |
| 184 |
if (!empty($drestr['ctad'])) { |
| 185 |
$ctarestrictionsrange[$kr][0] = $ctfrom; |
| 186 |
$ctarestrictionsrange[$kr][1] = $ctto; |
| 187 |
$ctarestrictionsrange[$kr][2] = explode(',', $drestr['ctad']); |
| 188 |
} |
| 189 |
if (!empty($drestr['ctdd'])) { |
| 190 |
$ctdrestrictionsrange[$kr][0] = $ctfrom; |
| 191 |
$ctdrestrictionsrange[$kr][1] = $ctto; |
| 192 |
$ctdrestrictionsrange[$kr][2] = explode(',', $drestr['ctdd']); |
| 193 |
} |
| 194 |
} |
| 195 |
$minlosrestrictionsrange[$kr][0] = date('Y-m-d', $drestr['dfrom']); |
| 196 |
$minlosrestrictionsrange[$kr][1] = date('Y-m-d', $drestr['dto']); |
| 197 |
$minlosrestrictionsrange[$kr][2] = $drestr['minlos']; |
| 198 |
if (!empty($drestr['maxlos']) && $drestr['maxlos'] > 0 && $drestr['maxlos'] >= $drestr['minlos']) { |
| 199 |
$maxlosrestrictionsrange[$kr] = $drestr['maxlos']; |
| 200 |
} |
| 201 |
} |
| 202 |
unset($restrictions['range']); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
$resdecl = " |
| 207 |
var vbrestrmonthswdays = [".implode(", ", $wdaysrestrictionsmonths)."]; |
| 208 |
var vbrestrmonths = [".implode(", ", array_keys($restrictions))."]; |
| 209 |
var vbrestrmonthscombojn = JSON.parse('".json_encode($monthscomborestr)."'); |
| 210 |
var vbrestrminlos = {".implode(", ", $minlosrestrictions)."}; |
| 211 |
var vbrestrminlosrangejn = JSON.parse('".json_encode($minlosrestrictionsrange)."'); |
| 212 |
var vbrestrmultiplyminlos = [".implode(", ", $notmultiplyminlosrestrictions)."]; |
| 213 |
var vbrestrmaxlos = {".implode(", ", $maxlosrestrictions)."}; |
| 214 |
var vbrestrmaxlosrangejn = JSON.parse('".json_encode($maxlosrestrictionsrange)."'); |
| 215 |
var vbrestrwdaysrangejn = JSON.parse('".json_encode($wdaysrestrictionsrange)."'); |
| 216 |
var vbrestrcta = JSON.parse('".json_encode($ctarestrictionsmonths)."'); |
| 217 |
var vbrestrctarange = JSON.parse('".json_encode($ctarestrictionsrange)."'); |
| 218 |
var vbrestrctd = JSON.parse('".json_encode($ctdrestrictionsmonths)."'); |
| 219 |
var vbrestrctdrange = JSON.parse('".json_encode($ctdrestrictionsrange)."'); |
| 220 |
var vbcombowdays = {}; |
| 221 |
function vbRefreshCheckout".$randid."(darrive) { |
| 222 |
if (vbFullObject".$randid."(vbcombowdays)) { |
| 223 |
var vbtosort = new Array(); |
| 224 |
for(var vbi in vbcombowdays) { |
| 225 |
if (vbcombowdays.hasOwnProperty(vbi)) { |
| 226 |
var vbusedate = darrive; |
| 227 |
vbtosort[vbi] = vbusedate.setDate(vbusedate.getDate() + (vbcombowdays[vbi] - 1 - vbusedate.getDay() + 7) % 7 + 1); |
| 228 |
} |
| 229 |
} |
| 230 |
vbtosort.sort(function(da, db) { |
| 231 |
return da > db ? 1 : -1; |
| 232 |
}); |
| 233 |
for(var vbnext in vbtosort) { |
| 234 |
if (vbtosort.hasOwnProperty(vbnext)) { |
| 235 |
var vbfirstnextd = new Date(vbtosort[vbnext]); |
| 236 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'option', 'minDate', vbfirstnextd ); |
| 237 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'setDate', vbfirstnextd ); |
| 238 |
break; |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
function vbSetMinCheckoutDatemod".$randid."(selectedDate) { |
| 244 |
var minlos = ".VikBooking::getDefaultNightsCalendar()."; |
| 245 |
var maxlosrange = 0; |
| 246 |
var nowcheckin = jQuery('#checkindatemod".$randid."').datepicker('getDate'); |
| 247 |
var nowd = nowcheckin.getDay(); |
| 248 |
var nowcheckindate = new Date(nowcheckin.getTime()); |
| 249 |
vbcombowdays = {}; |
| 250 |
if (vbFullObject".$randid."(vbrestrminlosrangejn)) { |
| 251 |
for (var rk in vbrestrminlosrangejn) { |
| 252 |
if (vbrestrminlosrangejn.hasOwnProperty(rk)) { |
| 253 |
var minldrangeinit = vbGetDateObject".$randid."(vbrestrminlosrangejn[rk][0]); |
| 254 |
if (nowcheckindate >= minldrangeinit) { |
| 255 |
var minldrangeend = vbGetDateObject".$randid."(vbrestrminlosrangejn[rk][1]); |
| 256 |
if (nowcheckindate <= minldrangeend) { |
| 257 |
minlos = parseInt(vbrestrminlosrangejn[rk][2]); |
| 258 |
if (vbFullObject".$randid."(vbrestrmaxlosrangejn)) { |
| 259 |
if (rk in vbrestrmaxlosrangejn) { |
| 260 |
maxlosrange = parseInt(vbrestrmaxlosrangejn[rk]); |
| 261 |
} |
| 262 |
} |
| 263 |
if (rk in vbrestrwdaysrangejn && nowd in vbrestrwdaysrangejn[rk][5]) { |
| 264 |
vbcombowdays = vbrestrwdaysrangejn[rk][5][nowd]; |
| 265 |
} |
| 266 |
} |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
} |
| 271 |
var nowm = nowcheckin.getMonth(); |
| 272 |
if (vbFullObject".$randid."(vbrestrmonthscombojn) && vbrestrmonthscombojn.hasOwnProperty(nowm)) { |
| 273 |
if (nowd in vbrestrmonthscombojn[nowm]) { |
| 274 |
vbcombowdays = vbrestrmonthscombojn[nowm][nowd]; |
| 275 |
} |
| 276 |
} |
| 277 |
if (jQuery.inArray((nowm + 1), vbrestrmonths) != -1) { |
| 278 |
minlos = parseInt(vbrestrminlos[nowm]); |
| 279 |
} |
| 280 |
nowcheckindate.setDate(nowcheckindate.getDate() + minlos); |
| 281 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'option', 'minDate', nowcheckindate ); |
| 282 |
if (maxlosrange > 0) { |
| 283 |
var diffmaxminlos = maxlosrange - minlos; |
| 284 |
var maxcheckoutdate = new Date(nowcheckindate.getTime()); |
| 285 |
maxcheckoutdate.setDate(maxcheckoutdate.getDate() + diffmaxminlos); |
| 286 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'option', 'maxDate', maxcheckoutdate ); |
| 287 |
} |
| 288 |
if (nowm in vbrestrmaxlos) { |
| 289 |
var diffmaxminlos = parseInt(vbrestrmaxlos[nowm]) - minlos; |
| 290 |
var maxcheckoutdate = new Date(nowcheckindate.getTime()); |
| 291 |
maxcheckoutdate.setDate(maxcheckoutdate.getDate() + diffmaxminlos); |
| 292 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'option', 'maxDate', maxcheckoutdate ); |
| 293 |
} |
| 294 |
if (!vbFullObject".$randid."(vbcombowdays)) { |
| 295 |
var is_checkout_disabled = false; |
| 296 |
if (typeof selectedDate !== 'undefined' && typeof jQuery('#checkoutdatemod".$randid."').datepicker('option', 'beforeShowDay') === 'function') { |
| 297 |
// let the datepicker validate if the min date to set for check-out is disabled due to CTD rules |
| 298 |
is_checkout_disabled = !jQuery('#checkoutdatemod".$randid."').datepicker('option', 'beforeShowDay')(nowcheckindate)[0]; |
| 299 |
} |
| 300 |
if (!is_checkout_disabled) { |
| 301 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'setDate', nowcheckindate ); |
| 302 |
} else { |
| 303 |
setTimeout(() => { |
| 304 |
// make sure the minimum date just set for the checkout has not populated a CTD date that we do not want |
| 305 |
var current_out_dt = jQuery('#checkoutdatemod".$randid."').datepicker('getDate'); |
| 306 |
if (current_out_dt && current_out_dt.getTime() === nowcheckindate.getTime()) { |
| 307 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'setDate', null ); |
| 308 |
} |
| 309 |
jQuery('#checkoutdatemod".$randid."').focus(); |
| 310 |
}, 100); |
| 311 |
} |
| 312 |
} else { |
| 313 |
vbRefreshCheckout".$randid."(nowcheckin); |
| 314 |
} |
| 315 |
jQuery('#checkoutdatemod".$randid."').find('.ui-datepicker-current-day').click(); |
| 316 |
}"; |
| 317 |
|
| 318 |
if (count($wdaysrestrictions) > 0 || count($wdaysrestrictionsrange) > 0) { |
| 319 |
$resdecl .= " |
| 320 |
var vbrestrwdays = {".implode(", ", $wdaysrestrictions)."}; |
| 321 |
var vbrestrwdaystwo = {".implode(", ", $wdaystworestrictions)."}; |
| 322 |
function vbIsDayDisabledmod".$randid."(date) { |
| 323 |
if (!vbIsDayOpenmod".$randid."(date) || !vboValidateCtamod".$randid."(date)) { |
| 324 |
return [false]; |
| 325 |
} |
| 326 |
var m = date.getMonth(), wd = date.getDay(); |
| 327 |
if (vbFullObject".$randid."(vbrestrwdaysrangejn)) { |
| 328 |
for (var rk in vbrestrwdaysrangejn) { |
| 329 |
if (vbrestrwdaysrangejn.hasOwnProperty(rk)) { |
| 330 |
var wdrangeinit = vbGetDateObject".$randid."(vbrestrwdaysrangejn[rk][0]); |
| 331 |
if (date >= wdrangeinit) { |
| 332 |
var wdrangeend = vbGetDateObject".$randid."(vbrestrwdaysrangejn[rk][1]); |
| 333 |
if (date <= wdrangeend) { |
| 334 |
if (wd != vbrestrwdaysrangejn[rk][2]) { |
| 335 |
if (vbrestrwdaysrangejn[rk][4] == -1 || wd != vbrestrwdaysrangejn[rk][4]) { |
| 336 |
return [false]; |
| 337 |
} |
| 338 |
} |
| 339 |
} |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
if (vbFullObject".$randid."(vbrestrwdays)) { |
| 345 |
if (jQuery.inArray((m+1), vbrestrmonthswdays) == -1) { |
| 346 |
return [true]; |
| 347 |
} |
| 348 |
if (wd == vbrestrwdays[m]) { |
| 349 |
return [true]; |
| 350 |
} |
| 351 |
if (vbFullObject".$randid."(vbrestrwdaystwo)) { |
| 352 |
if (wd == vbrestrwdaystwo[m]) { |
| 353 |
return [true]; |
| 354 |
} |
| 355 |
} |
| 356 |
return [false]; |
| 357 |
} |
| 358 |
return [true]; |
| 359 |
} |
| 360 |
function vbIsDayDisabledCheckoutmod".$randid."(date) { |
| 361 |
if (!vbIsDayOpenmod".$randid."(date) || !vboValidateCtdmod".$randid."(date)) { |
| 362 |
return [false]; |
| 363 |
} |
| 364 |
var m = date.getMonth(), wd = date.getDay(); |
| 365 |
if (vbFullObject".$randid."(vbcombowdays)) { |
| 366 |
if (jQuery.inArray(wd, vbcombowdays) != -1) { |
| 367 |
return [true]; |
| 368 |
} else { |
| 369 |
return [false]; |
| 370 |
} |
| 371 |
} |
| 372 |
if (vbFullObject".$randid."(vbrestrwdaysrangejn)) { |
| 373 |
for (var rk in vbrestrwdaysrangejn) { |
| 374 |
if (vbrestrwdaysrangejn.hasOwnProperty(rk)) { |
| 375 |
var wdrangeinit = vbGetDateObject".$randid."(vbrestrwdaysrangejn[rk][0]); |
| 376 |
if (date >= wdrangeinit) { |
| 377 |
var wdrangeend = vbGetDateObject".$randid."(vbrestrwdaysrangejn[rk][1]); |
| 378 |
if (date <= wdrangeend) { |
| 379 |
if (wd != vbrestrwdaysrangejn[rk][2] && vbrestrwdaysrangejn[rk][3] == 1) { |
| 380 |
return [false]; |
| 381 |
} |
| 382 |
} |
| 383 |
} |
| 384 |
} |
| 385 |
} |
| 386 |
} |
| 387 |
if (vbFullObject".$randid."(vbrestrwdays)) { |
| 388 |
if (jQuery.inArray((m+1), vbrestrmonthswdays) == -1 || jQuery.inArray((m+1), vbrestrmultiplyminlos) != -1) { |
| 389 |
return [true]; |
| 390 |
} |
| 391 |
if (wd == vbrestrwdays[m]) { |
| 392 |
return [true]; |
| 393 |
} |
| 394 |
return [false]; |
| 395 |
} |
| 396 |
return [true]; |
| 397 |
}"; |
| 398 |
} |
| 399 |
$document->addScriptDeclaration($resdecl); |
| 400 |
} |
| 401 |
|
| 402 |
// global closing dates |
| 403 |
$closing_dates = VikBooking::parseJsClosingDates(); |
| 404 |
$sdecl = " |
| 405 |
var vbclosingdates = JSON.parse('".json_encode($closing_dates)."'); |
| 406 |
function vbCheckClosingDatesInmod".$randid."(date) { |
| 407 |
if (!vbIsDayOpenmod".$randid."(date) || !vboValidateCtamod".$randid."(date)) { |
| 408 |
return [false]; |
| 409 |
} |
| 410 |
return [true]; |
| 411 |
} |
| 412 |
function vbCheckClosingDatesOutmod".$randid."(date) { |
| 413 |
if (!vbIsDayOpenmod".$randid."(date) || !vboValidateCtdmod".$randid."(date)) { |
| 414 |
return [false]; |
| 415 |
} |
| 416 |
return [true]; |
| 417 |
} |
| 418 |
function vbIsDayOpenmod".$randid."(date) { |
| 419 |
if (vbFullObject".$randid."(vbclosingdates)) { |
| 420 |
for (var cd in vbclosingdates) { |
| 421 |
if (vbclosingdates.hasOwnProperty(cd)) { |
| 422 |
var cdfrom = vbGetDateObject".$randid."(vbclosingdates[cd][0]); |
| 423 |
var cdto = vbGetDateObject".$randid."(vbclosingdates[cd][1]); |
| 424 |
if (date >= cdfrom && date <= cdto) { |
| 425 |
return false; |
| 426 |
} |
| 427 |
} |
| 428 |
} |
| 429 |
} |
| 430 |
return true; |
| 431 |
} |
| 432 |
function vboValidateCtamod".$randid."(date) { |
| 433 |
var m = date.getMonth(), wd = date.getDay(); |
| 434 |
if (vbFullObject".$randid."(vbrestrctarange)) { |
| 435 |
for (var rk in vbrestrctarange) { |
| 436 |
if (vbrestrctarange.hasOwnProperty(rk)) { |
| 437 |
var wdrangeinit = vbGetDateObject".$randid."(vbrestrctarange[rk][0]); |
| 438 |
if (date >= wdrangeinit) { |
| 439 |
var wdrangeend = vbGetDateObject".$randid."(vbrestrctarange[rk][1]); |
| 440 |
if (date <= wdrangeend) { |
| 441 |
if (jQuery.inArray('-'+wd+'-', vbrestrctarange[rk][2]) >= 0) { |
| 442 |
return false; |
| 443 |
} |
| 444 |
} |
| 445 |
} |
| 446 |
} |
| 447 |
} |
| 448 |
} |
| 449 |
if (vbFullObject".$randid."(vbrestrcta)) { |
| 450 |
if (vbrestrcta.hasOwnProperty(m) && jQuery.inArray('-'+wd+'-', vbrestrcta[m]) >= 0) { |
| 451 |
return false; |
| 452 |
} |
| 453 |
} |
| 454 |
return true; |
| 455 |
} |
| 456 |
function vboValidateCtdmod".$randid."(date) { |
| 457 |
var m = date.getMonth(), wd = date.getDay(); |
| 458 |
if (vbFullObject".$randid."(vbrestrctdrange)) { |
| 459 |
for (var rk in vbrestrctdrange) { |
| 460 |
if (vbrestrctdrange.hasOwnProperty(rk)) { |
| 461 |
var wdrangeinit = vbGetDateObject".$randid."(vbrestrctdrange[rk][0]); |
| 462 |
if (date >= wdrangeinit) { |
| 463 |
var wdrangeend = vbGetDateObject".$randid."(vbrestrctdrange[rk][1]); |
| 464 |
if (date <= wdrangeend) { |
| 465 |
if (jQuery.inArray('-'+wd+'-', vbrestrctdrange[rk][2]) >= 0) { |
| 466 |
return false; |
| 467 |
} |
| 468 |
} |
| 469 |
} |
| 470 |
} |
| 471 |
} |
| 472 |
} |
| 473 |
if (vbFullObject".$randid."(vbrestrctd)) { |
| 474 |
if (vbrestrctd.hasOwnProperty(m) && jQuery.inArray('-'+wd+'-', vbrestrctd[m]) >= 0) { |
| 475 |
return false; |
| 476 |
} |
| 477 |
} |
| 478 |
return true; |
| 479 |
} |
| 480 |
function vbSetGlobalMinCheckoutDatemod".$randid."() { |
| 481 |
var nowcheckin = jQuery('#checkindatemod".$randid."').datepicker('getDate'); |
| 482 |
var nowcheckindate = new Date(nowcheckin.getTime()); |
| 483 |
nowcheckindate.setDate(nowcheckindate.getDate() + ".VikBooking::getDefaultNightsCalendar()."); |
| 484 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'option', 'minDate', nowcheckindate ); |
| 485 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'setDate', nowcheckindate ); |
| 486 |
jQuery('#checkoutdatemod".$randid."').find('.ui-datepicker-current-day').click(); |
| 487 |
} |
| 488 |
function vbFormatCalDateMod{$randid}(idc) { |
| 489 |
var vb_period = document.getElementById((idc == 'from' ? 'inp-checkindatemod{$randid}' : 'inp-checkoutdatemod{$randid}')).value; |
| 490 |
if (!vb_period || !vb_period.length) { |
| 491 |
return; |
| 492 |
} |
| 493 |
var vb_period_parts = vb_period.split('/'); |
| 494 |
if ('%d/%m/%Y' == '{$vbdateformat}') { |
| 495 |
var period_date = new Date(vb_period_parts[2], (parseInt(vb_period_parts[1]) - 1), parseInt(vb_period_parts[0], 10), 0, 0, 0, 0); |
| 496 |
var data = [parseInt(vb_period_parts[0], 10), parseInt(vb_period_parts[1]), vb_period_parts[2]]; |
| 497 |
} else if ('%m/%d/%Y' == '{$vbdateformat}') { |
| 498 |
var period_date = new Date(vb_period_parts[2], (parseInt(vb_period_parts[0]) - 1), parseInt(vb_period_parts[1], 10), 0, 0, 0, 0); |
| 499 |
var data = [parseInt(vb_period_parts[1], 10), parseInt(vb_period_parts[0]), vb_period_parts[2]]; |
| 500 |
} else { |
| 501 |
var period_date = new Date(vb_period_parts[0], (parseInt(vb_period_parts[1]) - 1), parseInt(vb_period_parts[2], 10), 0, 0, 0, 0); |
| 502 |
var data = [parseInt(vb_period_parts[2], 10), parseInt(vb_period_parts[1]), vb_period_parts[0]]; |
| 503 |
} |
| 504 |
jQuery('.vbo-horizsearch-showcalendar-'+idc).find('.vbo-horizsearch-placeholder').remove(); |
| 505 |
var elcont = jQuery('#vbo-horizsearch-period{$randid}-'+idc); |
| 506 |
elcont.find('.vbo-horizsearch-period-wday').text(vboMapWdays{$randid}[period_date.getDay()]); |
| 507 |
elcont.find('.vbo-horizsearch-period-mday').text(period_date.getDate()); |
| 508 |
elcont.find('.vbo-horizsearch-period-month').text(vboMapMons{$randid}[period_date.getMonth()]); |
| 509 |
elcont.find('.vbo-horizsearch-period-year').text(period_date.getFullYear()); |
| 510 |
jQuery('.vbo-horizsearch-dpicker-cont').hide(); |
| 511 |
} |
| 512 |
var vboCalVisible{$randid} = false; |
| 513 |
var vboGuestsVisible{$randid} = false; |
| 514 |
jQuery(function() { |
| 515 |
jQuery.datepicker.setDefaults( jQuery.datepicker.regional[ '' ] ); |
| 516 |
jQuery('#checkindatemod".$randid."').datepicker({ |
| 517 |
".($dates_layout_type != 'human' ? "showOn: 'focus'," : '')." |
| 518 |
".($dates_layout_type == 'human' ? "altField: '#inp-checkindatemod{$randid}',\n" : '')." |
| 519 |
numberOfMonths: ".($is_mobile ? '1' : '2').",".(count($wdaysrestrictions) > 0 || count($wdaysrestrictionsrange) > 0 ? "\nbeforeShowDay: vbIsDayDisabledmod".$randid.",\n" : "\nbeforeShowDay: vbCheckClosingDatesInmod".$randid.",\n")." |
| 520 |
onSelect: function( selectedDate ) { |
| 521 |
".($totrestrictions > 0 ? "vbSetMinCheckoutDatemod".$randid."(selectedDate);" : "vbSetGlobalMinCheckoutDatemod".$randid."();")." |
| 522 |
vbCalcNightsMod".$randid."(); |
| 523 |
".($dates_layout_type == 'human' ? "vbFormatCalDateMod".$randid."('from');" : '')." |
| 524 |
} |
| 525 |
}); |
| 526 |
jQuery('#checkindatemod".$randid."').datepicker( 'option', 'dateFormat', '".$juidf."'); |
| 527 |
jQuery('#checkindatemod".$randid."').datepicker( 'option', 'minDate', '".VikBooking::getMinDaysAdvance()."d'); |
| 528 |
jQuery('#checkindatemod".$randid."').datepicker( 'option', 'maxDate', '".VikBooking::getMaxDateFuture()."'); |
| 529 |
jQuery('#checkoutdatemod".$randid."').datepicker({ |
| 530 |
".($dates_layout_type != 'human' ? "showOn: 'focus'," : '')." |
| 531 |
".($dates_layout_type == 'human' ? "altField: '#inp-checkoutdatemod{$randid}',\n" : '')." |
| 532 |
numberOfMonths: ".($is_mobile ? '1' : '2').",".(count($wdaysrestrictions) > 0 || count($wdaysrestrictionsrange) > 0 ? "\nbeforeShowDay: vbIsDayDisabledCheckoutmod".$randid.",\n" : "\nbeforeShowDay: vbCheckClosingDatesOutmod".$randid.",\n")." |
| 533 |
onSelect: function( selectedDate ) { |
| 534 |
vbCalcNightsMod".$randid."(); |
| 535 |
".($dates_layout_type == 'human' ? "vbFormatCalDateMod".$randid."('to');" : '')." |
| 536 |
} |
| 537 |
}); |
| 538 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'option', 'dateFormat', '".$juidf."'); |
| 539 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'option', 'minDate', '".VikBooking::getMinDaysAdvance()."d'); |
| 540 |
jQuery('#checkindatemod".$randid."').datepicker( 'option', jQuery.datepicker.regional[ 'vikbookingmod' ] ); |
| 541 |
jQuery('#checkoutdatemod".$randid."').datepicker( 'option', jQuery.datepicker.regional[ 'vikbookingmod' ] ); |
| 542 |
jQuery('.vb-cal-img, .vbo-caltrigger').click(function(){ |
| 543 |
var jdp = jQuery(this).prev('input.hasDatepicker'); |
| 544 |
if (jdp.length) { |
| 545 |
jdp.focus(); |
| 546 |
} |
| 547 |
}); |
| 548 |
jQuery('#vbo-horizsearch-checkin{$randid}, #vbo-horizsearch-checkout{$randid}').click(function() { |
| 549 |
var childcal = jQuery(this).parent().find('.vbo-horizsearch-dpicker-cont'); |
| 550 |
if (!childcal.is(':visible')) { |
| 551 |
jQuery('.vbo-horizsearch-dpicker-cont').hide(); |
| 552 |
} |
| 553 |
childcal.fadeToggle(400, function() { |
| 554 |
if (jQuery(this).is(':visible')) { |
| 555 |
vboCalVisible{$randid} = true; |
| 556 |
jQuery(this).parent().find('.vbo-horizsearch-showcalendar').addClass('vbo-horizsearch-dpicker-cont-active'); |
| 557 |
} else { |
| 558 |
vboCalVisible{$randid} = false; |
| 559 |
jQuery(this).parent().find('.vbo-horizsearch-showcalendar').removeClass('vbo-horizsearch-dpicker-cont-active'); |
| 560 |
} |
| 561 |
}); |
| 562 |
}); |
| 563 |
jQuery('label.vbo-horizsearch-lbl-dt-{$randid}').click(function() { |
| 564 |
jQuery(this).next('.vbo-horizsearch-showcalendar').trigger('click'); |
| 565 |
}); |
| 566 |
jQuery(document).keydown(function(e) { |
| 567 |
if (e.keyCode == 27) { |
| 568 |
if (vboCalVisible{$randid}) { |
| 569 |
jQuery('.vbo-horizsearch-dpicker-cont').hide(); |
| 570 |
jQuery('.vbo-horizsearch-dpicker-cont-active').removeClass('vbo-horizsearch-dpicker-cont-active'); |
| 571 |
vboCalVisible{$randid} = false; |
| 572 |
} |
| 573 |
if (vboGuestsVisible{$randid}) { |
| 574 |
jQuery('.vbmodhorsearch-hum-guests-modifier').hide(); |
| 575 |
jQuery('.vbmodhorsearch-hum-guests-count-active').removeClass('vbmodhorsearch-hum-guests-count-active'); |
| 576 |
vboGuestsVisible{$randid} = false; |
| 577 |
} |
| 578 |
} |
| 579 |
}); |
| 580 |
jQuery(document).mouseup(function(e) { |
| 581 |
if (!vboCalVisible{$randid} && !vboGuestsVisible{$randid}) { |
| 582 |
return false; |
| 583 |
} |
| 584 |
if (vboCalVisible{$randid}) { |
| 585 |
var vbo_overlay_cont = jQuery('.vbo-horizsearch-dpicker-cont'); |
| 586 |
if (!vbo_overlay_cont.is(e.target) && vbo_overlay_cont.has(e.target).length === 0) { |
| 587 |
jQuery('.vbo-horizsearch-dpicker-cont').hide(); |
| 588 |
jQuery('.vbo-horizsearch-dpicker-cont-active').removeClass('vbo-horizsearch-dpicker-cont-active'); |
| 589 |
vboCalVisible{$randid} = false; |
| 590 |
} |
| 591 |
} |
| 592 |
if (vboGuestsVisible{$randid}) { |
| 593 |
var vbo_overlay_cont = jQuery('#vbmodhorsearch-hum-guests-count{$randid}').parent().find('.vbmodhorsearch-hum-guests-modifier'); |
| 594 |
if (!vbo_overlay_cont.is(e.target) && vbo_overlay_cont.has(e.target).length === 0) { |
| 595 |
vbo_overlay_cont.hide(); |
| 596 |
jQuery('.vbmodhorsearch-hum-guests-count-active').removeClass('vbmodhorsearch-hum-guests-count-active'); |
| 597 |
vboGuestsVisible{$randid} = false; |
| 598 |
} |
| 599 |
} |
| 600 |
}); |
| 601 |
jQuery('#vbmodhorsearch-hum-guests-count{$randid}').click(function() { |
| 602 |
var mainblock = jQuery(this); |
| 603 |
mainblock.parent().find('.vbmodhorsearch-hum-guests-modifier').fadeToggle(400, function() { |
| 604 |
if (jQuery(this).is(':visible')) { |
| 605 |
vboGuestsVisible{$randid} = true; |
| 606 |
mainblock.addClass('vbmodhorsearch-hum-guests-count-active'); |
| 607 |
} else { |
| 608 |
vboGuestsVisible{$randid} = false; |
| 609 |
mainblock.removeClass('vbmodhorsearch-hum-guests-count-active'); |
| 610 |
} |
| 611 |
}); |
| 612 |
}); |
| 613 |
});"; |
| 614 |
$document->addScriptDeclaration($sdecl); |
| 615 |
|
| 616 |
if ($dates_layout_type == 'human') { |
| 617 |
// layout with readable dates |
| 618 |
?> |
| 619 |
<div class="vbmodhorsearch-hum-dates-wrap"> |
| 620 |
<div class="vbmodhorsearch-humcalcont vbmodhorsearchcheckindiv"> |
| 621 |
<label class="vbo-horizsearch-lbl-dt-<?php echo $randid; ?>"><?php echo JText::translate('VBMCHECKIN'); ?></label> |
| 622 |
<div class="vbo-horizsearch-showcalendar vbo-horizsearch-showcalendar-from" id="vbo-horizsearch-checkin<?php echo $randid; ?>"> |
| 623 |
<?php VikBookingIcons::e('calendar'); ?> |
| 624 |
<span class="vbo-horizsearch-placeholder"><?php echo JText::translate('HORIZSEARCHPICKDATE'); ?></span> |
| 625 |
<div id="vbo-horizsearch-period<?php echo $randid; ?>-from" class="vbo-horizsearch-period-from"> |
| 626 |
<span class="vbo-horizsearch-period-mday"></span> |
| 627 |
<div class="vbo-horizsearch-period-dt"> |
| 628 |
<span class="vbo-horizsearch-period-month"></span> |
| 629 |
<span class="vbo-horizsearch-period-year"></span> |
| 630 |
<span class="vbo-horizsearch-period-wday"></span> |
| 631 |
</div> |
| 632 |
</div> |
| 633 |
</div> |
| 634 |
<div class="vbo-horizsearch-dpicker-cont vbo-horizsearch-dpicker-from" id="checkindatemod<?php echo $randid; ?>" style="display: none;"></div> |
| 635 |
<input type="hidden" name="checkindate" id="inp-checkindatemod<?php echo $randid; ?>"/> |
| 636 |
<input type="hidden" name="checkinh" value="<?php echo $hcheckin; ?>"/> |
| 637 |
<input type="hidden" name="checkinm" value="<?php echo $mcheckin; ?>"/> |
| 638 |
</div> |
| 639 |
<div class="vbmodhorsearch-humcalcont vbmodhorsearchcheckoutdiv"> |
| 640 |
<label class="vbo-horizsearch-lbl-dt-<?php echo $randid; ?>"><?php echo JText::translate('VBMCHECKOUT'); ?></label> |
| 641 |
<div class="vbo-horizsearch-showcalendar vbo-horizsearch-showcalendar-to" id="vbo-horizsearch-checkout<?php echo $randid; ?>"> |
| 642 |
<?php VikBookingIcons::e('calendar'); ?> |
| 643 |
<span class="vbo-horizsearch-placeholder"><?php echo JText::translate('HORIZSEARCHPICKDATE'); ?></span> |
| 644 |
<div id="vbo-horizsearch-period<?php echo $randid; ?>-to" class="vbo-horizsearch-period-to"> |
| 645 |
<span class="vbo-horizsearch-period-mday"></span> |
| 646 |
<div class="vbo-horizsearch-period-dt"> |
| 647 |
<span class="vbo-horizsearch-period-month"></span> |
| 648 |
<span class="vbo-horizsearch-period-year"></span> |
| 649 |
<span class="vbo-horizsearch-period-wday"></span> |
| 650 |
</div> |
| 651 |
</div> |
| 652 |
</div> |
| 653 |
<div class="vbo-horizsearch-dpicker-cont vbo-horizsearch-dpicker-to" id="checkoutdatemod<?php echo $randid; ?>" style="display: none;"></div> |
| 654 |
<input type="hidden" name="checkoutdate" id="inp-checkoutdatemod<?php echo $randid; ?>"/> |
| 655 |
<input type="hidden" name="checkouth" value="<?php echo $hcheckout; ?>"/> |
| 656 |
<input type="hidden" name="checkoutm" value="<?php echo $mcheckout; ?>"/> |
| 657 |
</div> |
| 658 |
<div class="vbmodhorsearchtotnights" id="vbjstotnightsmod<?php echo $randid; ?>"></div> |
| 659 |
</div> |
| 660 |
<?php |
| 661 |
} else { |
| 662 |
// classic layout with input fields |
| 663 |
?> |
| 664 |
<div class="vbmodhorsearchcheckindiv"> |
| 665 |
<label for="checkindatemod<?php echo $randid; ?>"><?php echo JText::translate('VBMCHECKIN'); ?></label> |
| 666 |
<div class="input-group"> |
| 667 |
<input type="text" name="checkindate" id="checkindatemod<?php echo $randid; ?>" size="10" autocomplete="off" onfocus="this.blur();" readonly/> |
| 668 |
<?php VikBookingIcons::e('calendar', 'vbo-caltrigger'); ?> |
| 669 |
<input type="hidden" name="checkinh" value="<?php echo $hcheckin; ?>"/> |
| 670 |
<input type="hidden" name="checkinm" value="<?php echo $mcheckin; ?>"/> |
| 671 |
</div> |
| 672 |
</div> |
| 673 |
<div class="vbmodhorsearchcheckoutdiv"> |
| 674 |
<label for="checkoutdatemod<?php echo $randid; ?>"><?php echo JText::translate('VBMCHECKOUT'); ?></label> |
| 675 |
<div class="input-group"> |
| 676 |
<input type="text" name="checkoutdate" id="checkoutdatemod<?php echo $randid; ?>" size="10" autocomplete="off" onfocus="this.blur();" readonly/> |
| 677 |
<?php VikBookingIcons::e('calendar', 'vbo-caltrigger'); ?> |
| 678 |
<input type="hidden" name="checkouth" value="<?php echo $hcheckout; ?>"/> |
| 679 |
<input type="hidden" name="checkoutm" value="<?php echo $mcheckout; ?>"/> |
| 680 |
</div> |
| 681 |
</div> |
| 682 |
<?php |
| 683 |
} |
| 684 |
|
| 685 |
// number of nights calculated (they are displayed above for the human readable layout) |
| 686 |
if ($dates_layout_type == 'standard') { |
| 687 |
?> |
| 688 |
<div class="vbmodhorsearchtotnights" id="vbjstotnightsmod<?php echo $randid; ?>"></div> |
| 689 |
<?php |
| 690 |
} |
| 691 |
|
| 692 |
// rooms, adults, children |
| 693 |
$showchildren = VikBooking::showChildrenFront(); |
| 694 |
$guests_label = VBOFactory::getConfig()->get('guests_label', 'adults'); |
| 695 |
$use_guests_label = 'VBMFORMADULTS'; |
| 696 |
if (!$showchildren && !strcasecmp($guests_label, 'guests')) { |
| 697 |
$use_guests_label = 'VBMHORSGUESTS'; |
| 698 |
} |
| 699 |
// max number of rooms |
| 700 |
$maxsearchnumrooms = VikBooking::getSearchNumRooms(); |
| 701 |
// overwrite to always one room if inquiry |
| 702 |
if ($needs_inquiry) { |
| 703 |
$maxsearchnumrooms = 1; |
| 704 |
} |
| 705 |
|
| 706 |
if (intval($maxsearchnumrooms) > 1) { |
| 707 |
$roomsel = "<span class=\"vbhsrnselsp\"><select name=\"roomsnum\" id=\"vbmodformroomsn".$randid."\" onchange=\"vbSetRoomsAdultsMod".$randid."(this.value);\">\n"; |
| 708 |
for ($r = 1; $r <= intval($maxsearchnumrooms); $r++) { |
| 709 |
$roomsel .= "<option value=\"".$r."\">".$r."</option>\n"; |
| 710 |
} |
| 711 |
$roomsel .= "</select></span>\n"; |
| 712 |
} else { |
| 713 |
$roomsel = "<input type=\"hidden\" name=\"roomsnum\" value=\"1\">\n"; |
| 714 |
} |
| 715 |
|
| 716 |
// max number of adults per room |
| 717 |
$globnumadults = VikBooking::getSearchNumAdults(); |
| 718 |
$adultsparts = explode('-', $globnumadults); |
| 719 |
// overwrite maximum adults per room to max total adults if inquiry |
| 720 |
if ($needs_inquiry) { |
| 721 |
$adultsparts[1] = VikBookingWidgetHorizontalSearch::getMaxestGuests('adults'); |
| 722 |
$adultsparts[1] = $adultsparts[1] < $adultsparts[0] ? $adultsparts[0] : $adultsparts[1]; |
| 723 |
} |
| 724 |
$adultsel = "<select name=\"adults[]\" onchange=\"vbCountTotGuests".$randid."();\">"; |
| 725 |
$def_adults = intval($params->get('defadults')) > 1 ? intval($params->get('defadults')) : 0; |
| 726 |
for ($a = $adultsparts[0]; $a <= $adultsparts[1]; $a++) { |
| 727 |
$adultsel .= "<option value=\"".$a."\"".(($def_adults > 1 && $a == $def_adults) || (intval($adultsparts[0]) < 1 && $a == 1) ? " selected=\"selected\"" : "").">".$a."</option>"; |
| 728 |
} |
| 729 |
$adultsel .= "</select>"; |
| 730 |
|
| 731 |
// max number of children per room |
| 732 |
$globnumchildren = VikBooking::getSearchNumChildren(); |
| 733 |
$childrenparts = explode('-', $globnumchildren); |
| 734 |
// overwrite maximum children per room to max total children if inquiry |
| 735 |
if ($needs_inquiry) { |
| 736 |
$childrenparts[1] = VikBookingWidgetHorizontalSearch::getMaxestGuests('children'); |
| 737 |
$childrenparts[1] = $childrenparts[1] < $childrenparts[0] ? $childrenparts[0] : $childrenparts[1]; |
| 738 |
} |
| 739 |
$childrensel = "<select name=\"children[]\" onchange=\"vbCountTotGuests".$randid."();\">"; |
| 740 |
for ($c = $childrenparts[0]; $c <= $childrenparts[1]; $c++) { |
| 741 |
$childrensel .= "<option value=\"".$c."\">".$c."</option>"; |
| 742 |
} |
| 743 |
$childrensel .= "</select>"; |
| 744 |
|
| 745 |
if ($dates_layout_type == 'human') { |
| 746 |
// layout with readable dates and guests selection in modal |
| 747 |
$def_adults = $def_adults > 0 ? $def_adults : (int)$adultsparts[0]; |
| 748 |
$def_children = (int)$childrenparts[0]; |
| 749 |
?> |
| 750 |
<div class="vbmodhorsearch-hum-guests-wrap"> |
| 751 |
|
| 752 |
<label onclick="jQuery('#vbmodhorsearch-hum-guests-count<?php echo $randid; ?>').trigger('click');"><?php echo JText::translate('VBMHORSGUESTS'); ?></label> |
| 753 |
|
| 754 |
<div class="vbmodhorsearch-hum-guests-count" id="vbmodhorsearch-hum-guests-count<?php echo $randid; ?>"> |
| 755 |
<div class="vbmodhorsearch-hum-guests-elem vbmodhorsearch-hum-guests-rooms"<?php echo intval($maxsearchnumrooms) < 2 ? ' style="display: none;"' : ''; ?>> |
| 756 |
<label><?php echo JText::translate('VBMFORMROOMSN'); ?></label> |
| 757 |
<span id="vbmodhorsearch-hum-guests-rooms<?php echo $randid; ?>">1</span> |
| 758 |
</div> |
| 759 |
<div class="vbmodhorsearch-hum-guests-elem vbmodhorsearch-hum-guests-adults"> |
| 760 |
<label><?php echo JText::translate($use_guests_label); ?></label> |
| 761 |
<span id="vbmodhorsearch-hum-guests-adults<?php echo $randid; ?>"><?php echo $def_adults; ?></span> |
| 762 |
</div> |
| 763 |
<?php |
| 764 |
if ($showchildren) { |
| 765 |
?> |
| 766 |
<div class="vbmodhorsearch-hum-guests-elem vbmodhorsearch-hum-guests-children"> |
| 767 |
<label><?php echo JText::translate('VBFORMCHILDREN'); ?></label> |
| 768 |
<span id="vbmodhorsearch-hum-guests-children<?php echo $randid; ?>"><?php echo $def_children; ?></span> |
| 769 |
</div> |
| 770 |
<?php |
| 771 |
} |
| 772 |
?> |
| 773 |
</div> |
| 774 |
|
| 775 |
<div class="vbmodhorsearch-hum-guests-modifier" style="display: none;"> |
| 776 |
<div class="vbmodhorsearch-hum-guests-modifier-inner"> |
| 777 |
|
| 778 |
<?php |
| 779 |
if (intval($maxsearchnumrooms) > 1) { |
| 780 |
?> |
| 781 |
<div class="vbmodhorsearchroomsel"> |
| 782 |
<label for="vbmodformroomsn<?php echo $randid; ?>"><?php echo JText::translate('VBMFORMROOMSN'); ?></label> |
| 783 |
<?php echo $roomsel; ?> |
| 784 |
</div> |
| 785 |
<?php |
| 786 |
} else { |
| 787 |
echo $roomsel; |
| 788 |
} |
| 789 |
?> |
| 790 |
<div class="vbmodhorsearchroomdentr"> |
| 791 |
<div class="vbmodhorsearchroomdentrfirst"> |
| 792 |
<?php |
| 793 |
if (intval($maxsearchnumrooms) > 1) { |
| 794 |
?> |
| 795 |
<span class="horsrnum"><?php echo JText::translate('VBMFORMNUMROOM'); ?> 1</span> |
| 796 |
<?php |
| 797 |
} |
| 798 |
?> |
| 799 |
<div class="horsanumdiv"> |
| 800 |
<label class="horsanumlb"><?php echo JText::translate($use_guests_label); ?></label> |
| 801 |
<span class="horsanumsel"><?php echo $adultsel; ?></span> |
| 802 |
</div> |
| 803 |
<?php if ($showchildren): ?> |
| 804 |
<div class="horscnumdiv"> |
| 805 |
<label class="horscnumlb"><?php echo JText::translate('VBFORMCHILDREN'); ?></label> |
| 806 |
<span class="horscnumsel"><?php echo $childrensel; ?></span> |
| 807 |
</div> |
| 808 |
<?php endif; ?> |
| 809 |
</div> |
| 810 |
<div class="vbmoreroomscontmod" id="vbmoreroomscontmod<?php echo $randid; ?>"></div> |
| 811 |
</div> |
| 812 |
|
| 813 |
</div> |
| 814 |
</div> |
| 815 |
|
| 816 |
</div> |
| 817 |
<?php |
| 818 |
} else { |
| 819 |
// classic layout with select fields |
| 820 |
?> |
| 821 |
<div class="vbmodhorsearchrac"> |
| 822 |
|
| 823 |
<div class="vbmodhorsearchroomsel"> |
| 824 |
<?php if (intval($maxsearchnumrooms) > 1): ?><label for="vbmodformroomsn<?php echo $randid; ?>"><?php echo JText::translate('VBMFORMROOMSN'); ?></label><?php endif; ?> |
| 825 |
<?php echo $roomsel; ?> |
| 826 |
</div> |
| 827 |
|
| 828 |
<div class="vbmodhorsearchroomdentr"> |
| 829 |
|
| 830 |
<div class="vbmodhorsearchroomdentrfirst"> |
| 831 |
<?php if (intval($maxsearchnumrooms) > 1): ?><span class="horsrnum"><?php echo JText::translate('VBMFORMNUMROOM'); ?> 1</span><?php endif; ?> |
| 832 |
<div class="horsanumdiv"> |
| 833 |
<label class="horsanumlb"><?php echo JText::translate($use_guests_label); ?></label> |
| 834 |
<span class="horsanumsel"><?php echo $adultsel; ?></span> |
| 835 |
</div> |
| 836 |
<?php if ($showchildren): ?> |
| 837 |
<div class="horscnumdiv"> |
| 838 |
<label class="horscnumlb"><?php echo JText::translate('VBFORMCHILDREN'); ?></label> |
| 839 |
<span class="horscnumsel"><?php echo $childrensel; ?></span> |
| 840 |
</div> |
| 841 |
<?php endif; ?> |
| 842 |
</div> |
| 843 |
|
| 844 |
<div class="vbmoreroomscontmod" id="vbmoreroomscontmod<?php echo $randid; ?>"></div> |
| 845 |
|
| 846 |
</div> |
| 847 |
|
| 848 |
</div> |
| 849 |
<?php |
| 850 |
} |
| 851 |
|
| 852 |
if (intval($params->get('showcat')) === 1) { |
| 853 |
$q = "SELECT * FROM `#__vikbooking_categories` ORDER BY `#__vikbooking_categories`.`name` ASC;"; |
| 854 |
$dbo->setQuery($q); |
| 855 |
$dbo->execute(); |
| 856 |
if ($dbo->getNumRows() > 0) { |
| 857 |
$categories = $dbo->loadAssocList(); |
| 858 |
$vbo_tn->translateContents($categories, '#__vikbooking_categories'); |
| 859 |
?> |
| 860 |
<div class="vbmodhorsearchcategoriesblock"> |
| 861 |
<label class="vbmodhscategories" for="vbmodhscategories<?php echo $randid; ?>"><?php echo JText::translate('VBMROOMCAT'); ?></label> |
| 862 |
<span class="vbhsrcselsp"> |
| 863 |
<select name="categories" id="vbmodhscategories<?php echo $randid; ?>"> |
| 864 |
<option value="all"><?php echo JText::translate('VBMALLCAT'); ?></option> |
| 865 |
<?php |
| 866 |
foreach ($categories as $cat) { |
| 867 |
?> |
| 868 |
<option value="<?php echo $cat['id']; ?>"><?php echo $cat['name']; ?></option> |
| 869 |
<?php |
| 870 |
} |
| 871 |
?> |
| 872 |
</select> |
| 873 |
</span> |
| 874 |
</div> |
| 875 |
<?php |
| 876 |
} |
| 877 |
} elseif (intval($params->get('category_id')) > 0) { |
| 878 |
/** |
| 879 |
* We need to pass also the hidden value "category_id" in order |
| 880 |
* to allow the back-nav ("change dates" or "step-bar") to keep |
| 881 |
* the requested category filter. |
| 882 |
* |
| 883 |
* @since 1.2.11 |
| 884 |
*/ |
| 885 |
?> |
| 886 |
<input type="hidden" name="categories" value="<?php echo (int)$params->get('category_id'); ?>" /> |
| 887 |
<input type="hidden" name="category_id" value="<?php echo (int)$params->get('category_id'); ?>" /> |
| 888 |
<?php |
| 889 |
} |
| 890 |
|
| 891 |
if ($needs_inquiry) { |
| 892 |
// build the inquiry/request quotation fields |
| 893 |
$inquiry_fields = VikBookingWidgetHorizontalSearch::grabInquiryFields(); |
| 894 |
// start a field counter |
| 895 |
$field_counter = 0; |
| 896 |
?> |
| 897 |
<div class="vbo-mod-horsearch-inquiry-fields"> |
| 898 |
<?php |
| 899 |
foreach ($inquiry_fields as $fieldset) { |
| 900 |
// need to ignore some default fields? evaluate their ->type property and skip it. |
| 901 |
if (!is_object($fieldset) || empty($fieldset->type) || empty($fieldset->fields) || !is_array($fieldset->fields)) { |
| 902 |
// invalid fieldset object |
| 903 |
continue; |
| 904 |
} |
| 905 |
foreach ($fieldset->fields as $inq_field) { |
| 906 |
// get the field input type |
| 907 |
$input_type = VikBookingWidgetHorizontalSearch::parseFieldType($fieldset->type, $inq_field); |
| 908 |
$input_title = VikBookingWidgetHorizontalSearch::parseFieldLabel($fieldset->type, $inq_field); |
| 909 |
// increase field counter |
| 910 |
$field_counter++; |
| 911 |
// build field unique ID |
| 912 |
$field_id = $randid . '-' . $field_counter; |
| 913 |
// check if the fields of this fieldset should be required |
| 914 |
$required_attr = (isset($fieldset->required) && $fieldset->required) ? ' required' : ''; |
| 915 |
?> |
| 916 |
<div class="vbo-mod-horsearch-inquiry-field" data-type="<?php echo $fieldset->type; ?>" data-input-type="<?php echo $input_type; ?>"> |
| 917 |
<label for="<?php echo $field_id; ?>"><?php echo $input_title; ?></label> |
| 918 |
<?php |
| 919 |
switch ($input_type) { |
| 920 |
case 'text': |
| 921 |
?> |
| 922 |
<input type="text" id="<?php echo $field_id; ?>" name="inquiry[<?php echo $fieldset->type; ?>][]" value=""<?php echo $required_attr; ?> /> |
| 923 |
<?php |
| 924 |
break; |
| 925 |
case 'email': |
| 926 |
?> |
| 927 |
<input type="email" id="<?php echo $field_id; ?>" name="inquiry[<?php echo $fieldset->type; ?>][]" value=""<?php echo $required_attr; ?> /> |
| 928 |
<?php |
| 929 |
break; |
| 930 |
case 'phone': |
| 931 |
?> |
| 932 |
<input type="tel" id="<?php echo $field_id; ?>" name="inquiry[<?php echo $fieldset->type; ?>][]" value=""<?php echo $required_attr; ?> /> |
| 933 |
<?php |
| 934 |
break; |
| 935 |
case 'number': |
| 936 |
?> |
| 937 |
<input type="number" id="<?php echo $field_id; ?>" name="inquiry[<?php echo $fieldset->type; ?>][]" value=""<?php echo $required_attr; ?> /> |
| 938 |
<?php |
| 939 |
break; |
| 940 |
case 'textarea': |
| 941 |
?> |
| 942 |
<textarea id="<?php echo $field_id; ?>" name="inquiry[<?php echo $fieldset->type; ?>][]"></textarea> |
| 943 |
<?php |
| 944 |
break; |
| 945 |
case 'checkbox': |
| 946 |
?> |
| 947 |
<input type="checkbox" id="<?php echo $field_id; ?>" name="inquiry[<?php echo $fieldset->type; ?>][]" value="1"<?php echo $required_attr; ?> /> |
| 948 |
<?php |
| 949 |
break; |
| 950 |
case 'country': |
| 951 |
$countries_sel = VikBooking::getCountriesSelect("inquiry[{$fieldset->type}][]", [], $inq_field->defvalue); |
| 952 |
// make sure to define the ID of the select tag |
| 953 |
if (strpos($countries_sel, 'id=') === false) { |
| 954 |
$countries_sel = str_replace('<select ', '<select id="' . $field_id . '" ', $countries_sel); |
| 955 |
} |
| 956 |
// check if the select should be required |
| 957 |
if (!empty($required_attr) && strpos($countries_sel, 'required') === false) { |
| 958 |
$countries_sel = str_replace('<select ', '<select required ', $countries_sel); |
| 959 |
} |
| 960 |
// print the select field |
| 961 |
echo $countries_sel; |
| 962 |
|
| 963 |
break; |
| 964 |
default: |
| 965 |
break; |
| 966 |
} |
| 967 |
?> |
| 968 |
</div> |
| 969 |
<?php |
| 970 |
} |
| 971 |
} |
| 972 |
|
| 973 |
// security measure: register a new CSRF token to avoid spammers |
| 974 |
JHtml::fetch('vbohtml.scripts.ajaxcsrf'); |
| 975 |
|
| 976 |
?> |
| 977 |
</div> |
| 978 |
|
| 979 |
<div class="vbo-mod-horsearch-inquiry-submit"> |
| 980 |
<button type="button" onclick="vboModHorSearchSendRequest(this, '<?php echo $randid; ?>');" class="btn vbsearchinputmodhors vbo-pref-color-btn"><?php echo JText::translate('INQ_SEND_REQUESTS') ?></button> |
| 981 |
</div> |
| 982 |
|
| 983 |
<div class="vbo-mod-horsearch-inquiry-checkav"> |
| 984 |
<div class="vbo-mod-horsearch-inquiry-checkav-inner"> |
| 985 |
<h4><?php echo JText::translate('INQ_OR_BOOK_ONLINE'); ?></h4> |
| 986 |
<div> |
| 987 |
<button type="button" onclick="vboModHorSearchBookOnline('<?php echo $randid; ?>');" class="btn vbsearchinputmodhors vbo-mod-horsearch-checkav-btn"><?php echo JText::translate('INQ_CHECK_AVAILABILITY') ?></button> |
| 988 |
</div> |
| 989 |
</div> |
| 990 |
</div> |
| 991 |
<?php |
| 992 |
// append a hidden input field for the current user language |
| 993 |
?> |
| 994 |
<input type="hidden" name="ulang" value="<?php echo JFactory::getLanguage()->getTag(); ?>" /> |
| 995 |
<?php |
| 996 |
} else { |
| 997 |
// regular search form widget |
| 998 |
?> |
| 999 |
<div class="vbmodhorsearchbookdiv"> |
| 1000 |
<button type="submit" id="vbo-mod-horsearch-sbt-<?php echo $randid; ?>" class="btn vbsearchinputmodhors vbo-pref-color-btn"><?php echo JText::translate('SEARCHD'); ?></button> |
| 1001 |
</div> |
| 1002 |
|
| 1003 |
<script type="text/javascript"> |
| 1004 |
jQuery(function() { |
| 1005 |
jQuery('button#vbo-mod-horsearch-sbt-<?php echo $randid; ?>').on('click', function(e) { |
| 1006 |
e.preventDefault(); |
| 1007 |
jQuery(this).prop('disabled', true); |
| 1008 |
jQuery(this).html('<?php VikBookingIcons::e('circle-notch', 'fa-spin fa-fw'); ?> ' + jQuery(this).text()); |
| 1009 |
jQuery(this).closest('form').submit(); |
| 1010 |
}); |
| 1011 |
}); |
| 1012 |
</script> |
| 1013 |
<?php |
| 1014 |
} |
| 1015 |
?> |
| 1016 |
</form> |
| 1017 |
</div> |
| 1018 |
|
| 1019 |
<div class="vbo-modhs-js-helpers" style="display: none;"> |
| 1020 |
<div class="vbo-modhs-add-element-html"> |
| 1021 |
<div class="vbmodhorsearchroomdentr"> |
| 1022 |
<span class="horsrnum"><?php echo JText::translate('VBMFORMNUMROOM'); ?> %d</span> |
| 1023 |
<div class="horsanumdiv"> |
| 1024 |
<span class="horsanumsel"><?php echo $adultsel; ?></span> |
| 1025 |
<?php |
| 1026 |
if ($showchildren) { |
| 1027 |
?> |
| 1028 |
<div class="horscnumdiv"> |
| 1029 |
<span class="horscnumsel"><?php echo $childrensel; ?></span> |
| 1030 |
</div> |
| 1031 |
<?php |
| 1032 |
} |
| 1033 |
?> |
| 1034 |
</div> |
| 1035 |
</div> |
| 1036 |
</div> |
| 1037 |
</div> |
| 1038 |
|
| 1039 |
<script type="text/javascript"> |
| 1040 |
function vboModHorSearchSendRequest(elem, formId) { |
| 1041 |
var form_el = document.getElementById('vbo-mod-horsearch-form-' + formId); |
| 1042 |
if (!form_el) { |
| 1043 |
console.error('form not found', formId); |
| 1044 |
return false; |
| 1045 |
} |
| 1046 |
|
| 1047 |
// valid all form required fields |
| 1048 |
if (typeof form_el.checkValidity === 'function' && !form_el.checkValidity()) { |
| 1049 |
// modern browsers will support this HTML5 method to check the form required fields |
| 1050 |
alert(Joomla.JText._('VBO_PLEASE_FILL_FIELDS')); |
| 1051 |
return false; |
| 1052 |
} |
| 1053 |
|
| 1054 |
// make sure the dates have been selected |
| 1055 |
var checkin_date_el = jQuery(form_el).find('input[name="checkindate"]'); |
| 1056 |
var checkout_date_el = jQuery(form_el).find('input[name="checkoutdate"]'); |
| 1057 |
if (!checkin_date_el.length || !checkin_date_el.val().length || !checkout_date_el.length || !checkout_date_el.val().length) { |
| 1058 |
alert(Joomla.JText._('VBO_PLEASE_SEL_DATES')); |
| 1059 |
return false; |
| 1060 |
} |
| 1061 |
// make sure the dates are not identical to have a min stay of 1 night |
| 1062 |
// as by default the datepicker could set equal dates to the hidden fields. |
| 1063 |
if (checkin_date_el.val() == checkout_date_el.val()) { |
| 1064 |
alert(Joomla.JText._('VBO_PLEASE_SEL_DATES')); |
| 1065 |
return false; |
| 1066 |
} |
| 1067 |
|
| 1068 |
// disable the send request button to avoid double submissions |
| 1069 |
elem.disabled = true; |
| 1070 |
|
| 1071 |
// get form values |
| 1072 |
var qstring = jQuery(form_el).serialize(); |
| 1073 |
|
| 1074 |
// make sure the task is not set |
| 1075 |
qstring = qstring.replace('task=search', ''); |
| 1076 |
qstring = qstring.replace('view=search', ''); |
| 1077 |
|
| 1078 |
// make the ajax request to the controller |
| 1079 |
jQuery.ajax({ |
| 1080 |
type: "POST", |
| 1081 |
url: "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=submit_inquiry&Itemid=' . $params->get('itemid', 0), false); ?>", |
| 1082 |
data: qstring |
| 1083 |
}).done(function(res) { |
| 1084 |
if (!res.hasOwnProperty('status')) { |
| 1085 |
alert('Invalid response'); |
| 1086 |
// re-enable the button |
| 1087 |
elem.disabled = false; |
| 1088 |
return false; |
| 1089 |
} |
| 1090 |
if (!res.status) { |
| 1091 |
alert(res.error); |
| 1092 |
// re-enable the button |
| 1093 |
elem.disabled = false; |
| 1094 |
return false; |
| 1095 |
} |
| 1096 |
// show success message by replacing all fields |
| 1097 |
jQuery('.vbo-mod-horsearch-inquiry-fields').html('<p class="vbo-mod-horsearch-inquiry-mess-success">' + Joomla.JText._('VBO_THANKS_INQ_SUBMITTED') + '</p>'); |
| 1098 |
// remove submit button container |
| 1099 |
jQuery('.vbo-mod-horsearch-inquiry-submit').remove(); |
| 1100 |
}).fail(function(err) { |
| 1101 |
alert(err.responseText); |
| 1102 |
// re-enable the button |
| 1103 |
elem.disabled = false; |
| 1104 |
}); |
| 1105 |
} |
| 1106 |
|
| 1107 |
function vboModHorSearchBookOnline(formId) { |
| 1108 |
var form_el = document.getElementById('vbo-mod-horsearch-form-' + formId); |
| 1109 |
if (!form_el) { |
| 1110 |
console.error('form not found', formId); |
| 1111 |
return false; |
| 1112 |
} |
| 1113 |
|
| 1114 |
// we need to let a button of type button trigger the submit of the "check availability" |
| 1115 |
// or in case of inquiry, the browser will check the validity of the required fields. |
| 1116 |
|
| 1117 |
// we only check if the dates have been selected |
| 1118 |
var checkin_date_el = jQuery(form_el).find('input[name="checkindate"]'); |
| 1119 |
var checkout_date_el = jQuery(form_el).find('input[name="checkoutdate"]'); |
| 1120 |
if (!checkin_date_el.length || !checkin_date_el.val().length || !checkout_date_el.length || !checkout_date_el.val().length) { |
| 1121 |
alert(Joomla.JText._('VBO_PLEASE_SEL_DATES')); |
| 1122 |
return false; |
| 1123 |
} |
| 1124 |
|
| 1125 |
// make sure the dates are not identical to have a min stay of 1 night |
| 1126 |
// as by default the datepicker could set equal dates to the hidden fields. |
| 1127 |
if (checkin_date_el.val() == checkout_date_el.val()) { |
| 1128 |
alert(Joomla.JText._('VBO_PLEASE_SEL_DATES')); |
| 1129 |
return false; |
| 1130 |
} |
| 1131 |
|
| 1132 |
// simply submit the form to start the booking process |
| 1133 |
form_el.submit(); |
| 1134 |
|
| 1135 |
return true; |
| 1136 |
} |
| 1137 |
|
| 1138 |
function vbAddElementMod<?php echo $randid; ?>() { |
| 1139 |
var ni = document.getElementById('vbmoreroomscontmod<?php echo $randid; ?>'); |
| 1140 |
var numi = document.getElementById('vbroomhelpermod<?php echo $randid; ?>'); |
| 1141 |
var num = (document.getElementById('vbroomhelpermod<?php echo $randid; ?>').value -1)+ 2; |
| 1142 |
numi.value = num; |
| 1143 |
var newdiv = document.createElement('div'); |
| 1144 |
var divIdName = 'vb'+num+'racont'; |
| 1145 |
newdiv.setAttribute('id', divIdName); |
| 1146 |
var new_element_html = document.getElementsByClassName('vbo-modhs-add-element-html')[0].innerHTML; |
| 1147 |
var rp_rgx = new RegExp('%d', 'g'); |
| 1148 |
newdiv.innerHTML = new_element_html.replace(rp_rgx, num); |
| 1149 |
ni.appendChild(newdiv); |
| 1150 |
} |
| 1151 |
|
| 1152 |
function vbSetRoomsAdultsMod<?php echo $randid; ?>(totrooms) { |
| 1153 |
var actrooms = parseInt(document.getElementById('vbroomhelpermod<?php echo $randid; ?>').value); |
| 1154 |
var torooms = parseInt(totrooms); |
| 1155 |
var difrooms; |
| 1156 |
if (torooms > actrooms) { |
| 1157 |
difrooms = torooms - actrooms; |
| 1158 |
for (var ir = 1; ir <= difrooms; ir++) { |
| 1159 |
vbAddElementMod<?php echo $randid; ?>(); |
| 1160 |
} |
| 1161 |
} |
| 1162 |
if (torooms < actrooms) { |
| 1163 |
for (var ir = actrooms; ir > torooms; ir--) { |
| 1164 |
if (ir > 1) { |
| 1165 |
var rmra = document.getElementById('vb' + ir + 'racont'); |
| 1166 |
rmra.parentNode.removeChild(rmra); |
| 1167 |
} |
| 1168 |
} |
| 1169 |
document.getElementById('vbroomhelpermod<?php echo $randid; ?>').value = torooms; |
| 1170 |
} |
| 1171 |
if (document.getElementById('vbmodhorsearch-hum-guests-rooms<?php echo $randid; ?>')) { |
| 1172 |
document.getElementById('vbmodhorsearch-hum-guests-rooms<?php echo $randid; ?>').innerText = torooms; |
| 1173 |
vbCountTotGuests<?php echo $randid; ?>(); |
| 1174 |
} |
| 1175 |
} |
| 1176 |
|
| 1177 |
function vbCountTotGuests<?php echo $randid; ?>() { |
| 1178 |
if (!document.getElementById('vbmodhorsearch-hum-guests-rooms<?php echo $randid; ?>')) { |
| 1179 |
return; |
| 1180 |
} |
| 1181 |
var totadults = 0; |
| 1182 |
var totchildren = 0; |
| 1183 |
jQuery('#vbmodhorsearch-hum-guests-count<?php echo $randid; ?>').parent().find('select[name="adults[]"]').each(function() { |
| 1184 |
var curel = jQuery(this).find('option:selected'); |
| 1185 |
if (curel.length) { |
| 1186 |
totadults += parseInt(curel.val()); |
| 1187 |
} |
| 1188 |
}); |
| 1189 |
jQuery('#vbmodhorsearch-hum-guests-adults<?php echo $randid; ?>').text(totadults); |
| 1190 |
if (jQuery('#vbmodhorsearch-hum-guests-children<?php echo $randid; ?>').length) { |
| 1191 |
jQuery('#vbmodhorsearch-hum-guests-count<?php echo $randid; ?>').parent().find('select[name="children[]"]').each(function() { |
| 1192 |
var curel = jQuery(this).find('option:selected'); |
| 1193 |
if (curel.length) { |
| 1194 |
totchildren += parseInt(curel.val()); |
| 1195 |
} |
| 1196 |
}); |
| 1197 |
jQuery('#vbmodhorsearch-hum-guests-children<?php echo $randid; ?>').text(totchildren); |
| 1198 |
} |
| 1199 |
} |
| 1200 |
|
| 1201 |
function vbCalcNightsMod<?php echo $randid; ?>() { |
| 1202 |
var vbcheckin = document.getElementById('checkindatemod<?php echo $randid; ?>').value; |
| 1203 |
var vbcheckout = document.getElementById('checkoutdatemod<?php echo $randid; ?>').value; |
| 1204 |
if (vbcheckin.length > 0 && vbcheckout.length > 0) { |
| 1205 |
var vbcheckinp = vbcheckin.split("/"); |
| 1206 |
var vbcheckoutp = vbcheckout.split("/"); |
| 1207 |
<?php |
| 1208 |
if ($vbdateformat == "%d/%m/%Y") { |
| 1209 |
?> |
| 1210 |
var vbinmonth = parseInt(vbcheckinp[1]); |
| 1211 |
vbinmonth = vbinmonth - 1; |
| 1212 |
var vbinday = parseInt(vbcheckinp[0], 10); |
| 1213 |
var vbcheckind = new Date(vbcheckinp[2], vbinmonth, vbinday); |
| 1214 |
var vboutmonth = parseInt(vbcheckoutp[1]); |
| 1215 |
vboutmonth = vboutmonth - 1; |
| 1216 |
var vboutday = parseInt(vbcheckoutp[0], 10); |
| 1217 |
var vbcheckoutd = new Date(vbcheckoutp[2], vboutmonth, vboutday); |
| 1218 |
<?php |
| 1219 |
} elseif ($vbdateformat == "%m/%d/%Y") { |
| 1220 |
?> |
| 1221 |
var vbinmonth = parseInt(vbcheckinp[0]); |
| 1222 |
vbinmonth = vbinmonth - 1; |
| 1223 |
var vbinday = parseInt(vbcheckinp[1], 10); |
| 1224 |
var vbcheckind = new Date(vbcheckinp[2], vbinmonth, vbinday); |
| 1225 |
var vboutmonth = parseInt(vbcheckoutp[0]); |
| 1226 |
vboutmonth = vboutmonth - 1; |
| 1227 |
var vboutday = parseInt(vbcheckoutp[1], 10); |
| 1228 |
var vbcheckoutd = new Date(vbcheckoutp[2], vboutmonth, vboutday); |
| 1229 |
<?php |
| 1230 |
} else { |
| 1231 |
?> |
| 1232 |
var vbinmonth = parseInt(vbcheckinp[1]); |
| 1233 |
vbinmonth = vbinmonth - 1; |
| 1234 |
var vbinday = parseInt(vbcheckinp[2], 10); |
| 1235 |
var vbcheckind = new Date(vbcheckinp[0], vbinmonth, vbinday); |
| 1236 |
var vboutmonth = parseInt(vbcheckoutp[1]); |
| 1237 |
vboutmonth = vboutmonth - 1; |
| 1238 |
var vboutday = parseInt(vbcheckoutp[2], 10); |
| 1239 |
var vbcheckoutd = new Date(vbcheckoutp[0], vboutmonth, vboutday); |
| 1240 |
<?php |
| 1241 |
} |
| 1242 |
?> |
| 1243 |
var vbdivider = 1000 * 60 * 60 * 24; |
| 1244 |
var vbints = vbcheckind.getTime(); |
| 1245 |
var vboutts = vbcheckoutd.getTime(); |
| 1246 |
if (vboutts > vbints) { |
| 1247 |
//var vbnights = Math.ceil((vboutts - vbints) / (vbdivider)); |
| 1248 |
var utc1 = Date.UTC(vbcheckind.getFullYear(), vbcheckind.getMonth(), vbcheckind.getDate()); |
| 1249 |
var utc2 = Date.UTC(vbcheckoutd.getFullYear(), vbcheckoutd.getMonth(), vbcheckoutd.getDate()); |
| 1250 |
var vbnights = Math.ceil((utc2 - utc1) / vbdivider); |
| 1251 |
if (vbnights > 0) { |
| 1252 |
document.getElementById('vbjstotnightsmod<?php echo $randid; ?>').innerHTML = '<div class="vbo-horizsearch-numnights-inner"><span><?php echo addslashes(JText::translate('VBMJSTOTNIGHTS')); ?>:</span> <span>'+vbnights+'</span></div>'; |
| 1253 |
} else { |
| 1254 |
document.getElementById('vbjstotnightsmod<?php echo $randid; ?>').innerHTML = ''; |
| 1255 |
} |
| 1256 |
} else { |
| 1257 |
document.getElementById('vbjstotnightsmod<?php echo $randid; ?>').innerHTML = ''; |
| 1258 |
} |
| 1259 |
} else { |
| 1260 |
document.getElementById('vbjstotnightsmod<?php echo $randid; ?>').innerHTML = ''; |
| 1261 |
} |
| 1262 |
} |
| 1263 |
</script> |
| 1264 |
|
| 1265 |
<input type="hidden" id="vbroomhelpermod<?php echo $randid; ?>" value="1"/> |
| 1266 |
|