1var is_booking_without_payment = false; 2var date_approved = []; 3var date2approve = []; 4var date_admin_blank = []; 5var dates_additional_info = []; 6var is_all_days_available = []; 7var avalaibility_filters = []; 8var wpbc_resource_availability = []; 9var is_show_cost_in_tooltips = false; 10var is_show_cost_in_date_cell = false; 11var is_show_availability_in_tooltips = false; 12var timeoutID_of_thank_you_page = null; 13 14/** 15 * Booking Calendar - JavaScript Settings 16 * 17 * Example or redefine some settings: 18 * <script type="text/javascript"> wpbc_settings.set_option( 'pending_days_selectable', true ); </script> 19 * [booking type=1] 20 * 21 //FixIn: 8.6.1.18 22 */ 23var wpbc_settings = (function ( obj, $) { 24 25 // Define private property 26 var p_options = obj.options = obj.options || []; 27 28 p_options['pending_days_selectable'] = false; 29 30 // Get Option 31 obj.get_option = function ( item_id ) { 32 33 return p_options[ item_id ]; 34 }; 35 36 // Set Option 37 obj.set_option = function ( item_id, item_value ) { 38 39 p_options[ item_id ] = item_value; 40 }; 41 42 return obj; 43 44}(wpbc_settings || {}, jQuery )); 45 46 47/** 48 * Get 'Cost Rate' for CSS class 49 * 50 * @param {string} class_day - day CSS class: '2-28-2023' 51 * @param {int} resource_id - ID of booking resource: 1 52 * @returns {string} - ' rate_100' 53 */ 54function wpbc__inline_booking_calendar__days_css__get_rate( class_day, resource_id ){ 55 if ( 56 ( 'undefined' !== typeof( prices_per_day ) ) 57 && ( 'undefined' !== typeof( prices_per_day[ resource_id ] ) ) 58 && ( 'undefined' !== typeof( prices_per_day[ resource_id ][ class_day ] ) ) 59 ){ 60 return ' rate_' + prices_per_day[ resource_id ][ class_day ]; 61 } 62 return ''; 63} 64 65/** 66 * Get 'Season Filters Names' for CSS class 67 * 68 * @param {string} class_day - day CSS class: '2-28-2023' 69 * @param {int} resource_id - ID of booking resource: 1 70 * @returns {string} - ' weekend_season high_season' 71 */ 72function wpbc__inline_booking_calendar__days_css__get_season_names( class_day, resource_id ){ 73 if ( 74 ( 'undefined' !== typeof( wpdev_bk_season_filter ) ) 75 && ( 'undefined' !== typeof( wpdev_bk_season_filter[ class_day ] ) ) 76 ){ 77 return ' ' + wpdev_bk_season_filter[ class_day ].join( ' ' ); 78 } 79 return ''; 80} 81 82 83/** 84 * Calendar Init 85 * 86 * @param bk_type - resource ID 87 * @param date_approved_par 88 * @param my_num_month 89 * @param start_day_of_week 90 * @param start_bk_month 91 * @returns {boolean} 92 */ 93function init_datepick_cal(bk_type, date_approved_par, my_num_month, start_day_of_week, start_bk_month ){ 94 95 if ( jQuery('#calendar_booking'+ bk_type).hasClass('hasDatepick') == true ) { // If the calendar with the same Booking resource is activated already, then exist. 96 return false; 97 } 98 99 var cl = document.getElementById('calendar_booking'+ bk_type);if (cl === null) return; // Get calendar instance and exit if its not exist 100 101 date_approved[ bk_type ] = date_approved_par; 102 103 var isRangeSelect = false; 104 var bkMultiDaysSelect = 365; 105 if ( bk_days_selection_mode==='dynamic' ) { isRangeSelect = true; bkMultiDaysSelect = 0; } 106 if ( bk_days_selection_mode==='single' ) bkMultiDaysSelect = 0; 107 108 var bkMinDate = 0; 109 var bkMaxDate = booking_max_monthes_in_calendar; 110 111 var is_this_admin = false; 112 if ( ( location.href.indexOf('page=wpbc-new') != -1 ) 113 && ( location.href.indexOf('booking_hash') != -1 ) // Comment this line for ability to add booking in past days at Booking > Add booking page. 114 ){ 115 is_this_admin = true; 116 bkMinDate = null; 117 bkMaxDate = null; 118 } 119 120 121 function selectDay(date) { 122 123 // Set unselectable, if only Availability Calendar here (and we do not insert Booking form by mistake). 124 var is_calendar_booking_unselectable = jQuery( '#calendar_booking_unselectable' + bk_type ); //FixIn: 8.0.1.2 125 var is_booking_form_also = jQuery( '#booking_form_div' + bk_type ); 126 if ( ( is_calendar_booking_unselectable.length > 0 ) && ( is_booking_form_also.length <= 0 ) ){ 127 128 wpbc_unselect_all_days( bk_type );
129 jQuery('.wpbc_only_calendar .popover_calendar_hover').remove(); //Hide all opened popovers 130 return false; 131 } //FixIn: 8.0.1.2 end 132 133 jQuery( '#date_booking' + bk_type ).val( date ); 134 135 if ( typeof( bkDisableBookedTimeSlots ) == 'function' ){ 136 // HERE WE WILL DISABLE ALL OPTIONS IN RANGE TIME INTERVALS FOR SINGLE DAYS SELECTIONS FOR THAT DAYS WHEN HOURS ALREADY BOOKED 137 bkDisableBookedTimeSlots( jQuery( '#date_booking' + bk_type ).val(), bk_type ); 138 } 139 if ( typeof( selectDayPro ) == 'function' ){ 140 selectDayPro( date, bk_type ); 141 } 142 jQuery( ".booking_form_div" ).trigger( "date_selected", [ bk_type, date ] ); 143 } 144 145 function hoverDay(value, date){ 146 147 if ( typeof( wpbc_prepare_tooltip_content ) == 'function' ){ 148 wpbc_prepare_tooltip_content( value, date, bk_type ); 149 } 150 151 if ( 152 ( location.href.indexOf( 'page=wpbc' ) == -1 ) 153 || ( location.href.indexOf( 'page=wpbc-new' ) > 0 ) 154 || ( location.href.indexOf( 'page=wpbc-availability' ) > 0 ) 155 ){ // Do not show it (range) at the main admin page 156 if ( typeof( hoverDayPro ) == 'function' ){ 157 hoverDayPro( value, date, bk_type ); 158 } 159 } 160 161 var is_calendar_booking_unselectable = jQuery( '#calendar_booking_unselectable' + bk_type ); //FixIn: 8.0.1.2 162 var is_booking_form_also = jQuery( '#booking_form_div' + bk_type ); 163 // Set unselectable, if only Availability Calendar here (and we do not insert Booking form by mistake). 164 if ( ( is_calendar_booking_unselectable.length == 1 ) && ( is_booking_form_also.length != 1 ) ){ 165 jQuery( '#calendar_booking' + bk_type + ' .datepick-days-cell-over' ).removeClass( 'datepick-days-cell-over' ); // clear all highlight days selections 166 jQuery( '.wpbc_only_calendar #calendar_booking' + bk_type + ' .datepick-days-cell, ' + 167 '.wpbc_only_calendar #calendar_booking' + bk_type + ' .datepick-days-cell a' ).css( 'cursor', 'default' ); 168 return false; 169 } //FixIn: 8.0.1.2 end 170 } 171 172 function applyCSStoDays(date ){ 173 174 var class_day = (date.getMonth()+1) + '-' + date.getDate() + '-' + date.getFullYear(); 175 var sql_class_day = date.getFullYear() 176 + '-' 177 + ( ((date.getMonth() + 1) < 10) ? ('0' + (date.getMonth() + 1)) : (date.getMonth() + 1) ) 178 + '-' 179 + ( (date.getDate() < 10) ? ('0' + date.getDate()) : date.getDate() ); 180 181 var additional_class = ' wpbc_weekday_' + date.getDay() + ' '; 182 183 additional_class += wpbc__inline_booking_calendar__days_css__get_rate( class_day, bk_type ); // ' rate_100' 184 additional_class += wpbc__inline_booking_calendar__days_css__get_season_names( class_day, bk_type ); // ' weekend_season high_season' 185 186 if (is_this_admin == false) { 187 var my_test_date = new Date( wpbc_today[0],(wpbc_today[1]-1), wpbc_today[2] ,0,0,0 ); //Get today 188 if ( (days_between( date, my_test_date)) < block_some_dates_from_today ) 189 return [false, 'cal4date-' + class_day +' date_user_unavailable']; 190 191 if( typeof( wpbc_available_days_num_from_today ) !== 'undefined') 192 if ( parseInt( '0' + wpbc_available_days_num_from_today ) > 0 ) 193 if ( (days_between( date, my_test_date)) > parseInt( '0' + wpbc_available_days_num_from_today ) ) 194 return [false, 'cal4date-' + class_day +' date_user_unavailable']; 195 } 196 197 if (typeof( is_this_day_available ) == 'function') { 198 var is_day_available = is_this_day_available( date, bk_type); 199 var season_filter = ''; //FixIn: 6.0.1.8 200 if ( is_day_available instanceof Array ) { 201 season_filter = ' season_filter_id_' + is_day_available[1]; 202 is_day_available = is_day_available[0]; 203 } 204 if (! is_day_available) {return [false, 'cal4date-' + class_day +' date_user_unavailable season_unavailable ' + season_filter ];} 205 } 206 207 208 if ( 209 ( 'undefined' !== typeof (wpbc_resource_availability) ) 210 && ( 'undefined' !== typeof (wpbc_resource_availability[ bk_type ]) ) 211 && ( wpdev_in_array( wpbc_resource_availability[ bk_type ], sql_class_day ) ) 212 ){ 213 return [false, 'cal4date-' + class_day +' date_user_unavailable resource_unavailable ' ]; 214 } 215 216 217 var blank_admin_class_day = ''; 218 if(typeof(date_admin_blank[ bk_type ]) !== 'undefined') 219 if(typeof(date_admin_blank[ bk_type ][ class_day ]) !== 'undefined') { 220 blank_admin_class_day = ' date_admin_blank '; 221 } 222 223 // Check availability per day for BL 224 var reserved_days_count = 1; 225 if(typeof(availability_per_day) !== 'undefined') 226 if(typeof(availability_per_day[ bk_type ]) !== 'undefined') 227 if(typeof(availability_per_day[ bk_type ][ class_day ]) !== 'undefined') { 228 reserved_days_count = parseInt( availability_per_day[ bk_type ][ class_day ] );} 229 230 // Number of Check In Dates for BL 231 var checkin_days_count = [0 ,0]; 232 if(typeof(wpbc_check_in_dates) !== 'undefined') 233 if(typeof(wpbc_check_in_dates[ bk_type ]) !== 'undefined') 234 if(typeof(wpbc_check_in_dates[ bk_type ][ class_day ]) !== 'undefined') { 235 // [ Number of check in bookings, Pending or Approved status ] 236 checkin_days_count = [ wpbc_check_in_dates[ bk_type ][ class_day ][ 0 ] , wpbc_check_in_dates[ bk_type ][ class_day ][ 1 ] ]; 237 } 238 239 // Number of Check Out Dates for BL 240 var checkout_days_count = [0 ,0]; 241 if(typeof(wpbc_check_out_dates) !== 'undefined') 242 if(typeof(wpbc_check_out_dates[ bk_type ]) !== 'undefined') 243 if(typeof(wpbc_check_out_dates[ bk_type ][ class_day ]) !== 'undefined') { 244 // [ Number of check Out bookings, Pending or Approved status ] 245 checkout_days_count = [ wpbc_check_out_dates[ bk_type ][ class_day ][ 0 ] , wpbc_check_out_dates[ bk_type ][ class_day ][ 1 ] ]; 246 } 247 248 // Booked both check in/out dates in the same child resources 249 var both_check_in_out_num = 0; 250 if ( typeof( getNumberClosedCheckInOutDays ) == 'function' ) { 251 both_check_in_out_num = getNumberClosedCheckInOutDays( bk_type, class_day ); 252 } 253 254 255 // we have 0 available at this day - Only for resources, which have childs 256 if ( wpdev_in_array( parent_booking_resources, bk_type ) ) 257 if (reserved_days_count <= 0) { 258 if(typeof(date2approve[ bk_type ]) !== 'undefined') 259 if(typeof(date2approve[ bk_type ][ class_day ]) !== 'undefined') 260 return [false, 'cal4date-' + class_day +' full_day_booking date2approve date_unavailable_for_all_childs ' + blank_admin_class_day]; 261 return [false, 'cal4date-' + class_day +' full_day_booking date_approved date_unavailable_for_all_childs ' + blank_admin_class_day]; 262 } 263 264 var th=0; 265 var tm=0; 266 var ts=0; 267 var time_return_value = false;
268 269 var is_set_pending_days_selectable = wpbc_settings.get_option( 'pending_days_selectable' ); // set pending days selectable //FixIn: 8.6.1.18 270 271 // Select dates which need to approve, its exist only in Admin 272 if(typeof(date2approve[ bk_type ]) !== 'undefined') 273 if(typeof(date2approve[ bk_type ][ class_day ]) !== 'undefined') { 274 275 for (var ia=0;ia<date2approve[ bk_type ][ class_day ].length;ia++) { 276 277 th = date2approve[ bk_type ][ class_day ][ia][3]; 278 tm = date2approve[ bk_type ][ class_day ][ia][4]; 279 ts = date2approve[ bk_type ][ class_day ][ia][5]; 280 if ( ( th == 0 ) && ( tm == 0 ) && ( ts == 0 ) ) { 281 return [ is_set_pending_days_selectable, 'cal4date-' + class_day +' full_day_booking date2approve' + blank_admin_class_day]; // Orange //FixIn: 8.6.1.18 282 } else { 283 if ( is_booking_used_check_in_out_time === true ) { 284 if (ts == '1') additional_class += ' check_in_time' + ' check_in_time_date2approve'; //FixIn: 6.0.1.2 285 if (ts == '2') additional_class += ' check_out_time'+ ' check_out_time_date2approve'; //FixIn: 6.0.1.2 286 } else { 287 additional_class += ' times_clock'; //FixIn: 8.2.1.27 288 } 289 time_return_value = [true, 'date_available cal4date-' + class_day +' date2approve timespartly' + additional_class]; // Times 290 if(typeof( isDayFullByTime ) == 'function') { 291 if ( isDayFullByTime(bk_type, class_day ) ) { 292 return [ is_set_pending_days_selectable, 'cal4date-' + class_day +' full_day_booking date2approve' + blank_admin_class_day]; // Orange //FixIn: 8.6.1.18 293 } 294 } 295 } 296 297 } 298 299 } 300 301 //select Approved dates 302 if(typeof(date_approved[ bk_type ]) !== 'undefined') 303 if(typeof(date_approved[ bk_type ][ class_day ]) !== 'undefined') { 304 305 for (var ia=0;ia<date_approved[ bk_type ][ class_day ].length;ia++) { 306 307 th = date_approved[ bk_type ][ class_day ][ia][3]; 308 tm = date_approved[ bk_type ][ class_day ][ia][4]; 309 ts = date_approved[ bk_type ][ class_day ][ia][5]; 310 if ( ( th == 0 ) && ( tm == 0 ) && ( ts == 0 ) ) 311 return [false, 'cal4date-' + class_day +' full_day_booking date_approved' + blank_admin_class_day]; //Blue or Grey in client 312 else { 313 if ( is_booking_used_check_in_out_time === true ) { 314 if (ts == '1') additional_class += ' check_in_time' + ' check_in_time_date_approved'; //FixIn: 6.0.1.2 315 if (ts == '2') additional_class += ' check_out_time'+ ' check_out_time_date_approved'; //FixIn: 6.0.1.2 316 } else { 317 additional_class += ' times_clock'; //FixIn: 8.2.1.27 318 } 319 time_return_value = [true, 'date_available cal4date-' + class_day +' date_approved timespartly' + additional_class]; // Times 320 if(typeof( isDayFullByTime ) == 'function') { 321 if ( isDayFullByTime(bk_type, class_day ) ) return [false, 'cal4date-' + class_day +' full_day_booking date_approved' + blank_admin_class_day]; // Blue or Grey in client 322 } 323 } 324 325 } 326 } 327 328 329 for (var i=0; i<user_unavilable_days.length;i++) { 330 if (date.getDay()==user_unavilable_days[i]) return [false, 'cal4date-' + class_day +' date_user_unavailable' ]; 331 } 332 333 var is_datepick_unselectable = ''; 334 335 336 var is_exist_check_in_out_for_parent_resource = Math.max( checkin_days_count[0], checkout_days_count[0] ); 337 //FixIn: 8.4.7.29 338 if ( ! wpdev_in_array( parent_booking_resources, bk_type ) ) { 339 is_exist_check_in_out_for_parent_resource = 0; 340 } 341 342 if ( ( time_return_value !== false ) && ( is_exist_check_in_out_for_parent_resource == 0 ) ) { // Check this only for single booking resources - is_exist_check_in_out_for_parent_resource == 0 343 if ( is_booking_used_check_in_out_time === true ) { 344 // If the date is check in/out and the check in/out time is activated so then this date is unavailable 345 if ( ( additional_class.indexOf('check_in_time') != -1 ) && ( additional_class.indexOf('check_out_time') != -1 ) ){ 346 // Make this date unavailable 347 time_return_value[0] = false;
348 time_return_value[1]=time_return_value[1].replace("date_available",""); 349 } 350 } 351 if ( ( wpdev_in_array( parent_booking_resources, bk_type ) ) && ( (reserved_days_count - both_check_in_out_num ) <= 0 ) ) { //FixIn: 6.0.1.2 352 time_return_value[0] = false; 353 time_return_value[1]=time_return_value[1].replace("check_in_time",""); 354 time_return_value[1]=time_return_value[1].replace("check_out_time",""); 355 time_return_value[1]=time_return_value[1].replace("timespartly",""); 356 time_return_value[1]=time_return_value[1].replace("date_available",""); 357 } 358 return time_return_value; 359 360 } else { 361 362 if ( 363 ( is_booking_used_check_in_out_time === true ) 364 && ( ( is_exist_check_in_out_for_parent_resource > 0 ) || ( (reserved_days_count - both_check_in_out_num ) <= 0 ) ) 365 ) { // Check Check In / Out dates for the parent resources. // reserved_days_count - number of available items, including check in/out dates || both_check_in_out_num number of items with both check in/out //FixIn: 6.0.1.12 366 367 // Unavailable 368 if ( (reserved_days_count - both_check_in_out_num ) <= 0 ) { 369 // Check Pending or Approved by the Check In date 370 if ( checkin_days_count[1] == 1 ) additional_class = ' full_day_booking date_approved'; 371 else additional_class = ' full_day_booking date2approve'; 372 return [false, 'cal4date-' + class_day + additional_class + blank_admin_class_day]; 373 } 374 375 // Recheck if this date check in/out 376 if ( (reserved_days_count - both_check_in_out_num - checkin_days_count[0]) <= 0 ) { 377 if ( checkin_days_count[1] == 1 ) additional_class += ' date_approved check_in_time_date_approved'; //FixIn: 9.6.3.2 378 else additional_class += ' date2approve check_in_time_date2approve'; //FixIn: 9.6.3.2 379 additional_class += ' timespartly check_in_time'; 380 } 381 if ( (reserved_days_count - both_check_in_out_num - checkout_days_count[0]) <= 0 ) { 382 if ( checkout_days_count[1] == 1 ) additional_class += ' date_approved check_out_time_date_approved'; //FixIn: 9.6.3.2 383 else additional_class += ' date2approve check_out_time_date2approve'; //FixIn: 9.6.3.2 384 additional_class += ' timespartly check_out_time'; 385 } 386 } 387 388 return [true, 'date_available cal4date-' + class_day +' reserved_days_count' + reserved_days_count + ' ' + is_datepick_unselectable + additional_class+ ' ']; 389 } 390 } 391 392 function changeMonthYear( year, month ){ 393 if ( typeof (prepare_highlight) == 'function' ){ 394 setTimeout( "prepare_highlight();", 1000 ); 395 } 396 } 397 398 // Configure and show calendar 399 jQuery('#calendar_booking'+ bk_type).text(''); 400 jQuery('#calendar_booking'+ bk_type).datepick( 401 {beforeShowDay: applyCSStoDays, 402 onSelect: selectDay, 403 onHover:hoverDay, 404 onChangeMonthYear:changeMonthYear, 405 showOn: 'both', 406 multiSelect: bkMultiDaysSelect, 407 numberOfMonths: my_num_month, 408 stepMonths: 1, 409 prevText: '«', 410 nextText: '»', 411 dateFormat: 'dd.mm.yy', 412 changeMonth: false, 413 changeYear: false, 414 minDate: bkMinDate, maxDate: bkMaxDate, //'1Y', 415 // minDate: new Date(2020, 2, 1), maxDate: new Date(2020, 9, 31), // Ability to set any start and end date in calendar 416 showStatus: false, 417 multiSeparator: ', ', 418 closeAtTop: false, 419 firstDay:start_day_of_week, 420 gotoCurrent: false, 421 hideIfNoPrevNext:true, 422 rangeSelect:isRangeSelect, 423 // showWeeks: true, 424 useThemeRoller :false // ui-cupertino.datepick.css 425 } 426 ); 427 428 //FixIn: 7.1.2.8 429 setTimeout( function ( ) { 430 jQuery( '.datepick-days-cell.datepick-today.datepick-days-cell-over' ).removeClass( 'datepick-days-cell-over' ); 431 }, 500 ); 432 433 if ( start_bk_month != false ) { 434 var inst = jQuery.datepick._getInst(document.getElementById('calendar_booking'+bk_type)); 435 inst.cursorDate = new Date(); 436 inst.cursorDate.setFullYear( start_bk_month[0], (start_bk_month[1]-1) , 1 ); 437 // In some cases, the setFullYear can set only Year, and not the Month and day //FixIn:6.2.3.5 438 inst.cursorDate.setMonth( parseInt( start_bk_month[1] - 1 ) ); 439 inst.cursorDate.setDate( 1 ); 440 441 inst.drawMonth = inst.cursorDate.getMonth(); 442 inst.drawYear = inst.cursorDate.getFullYear(); 443 444 jQuery.datepick._notifyChange(inst);
445 jQuery.datepick._adjustInstDate(inst); 446 jQuery.datepick._showDate(inst); 447 jQuery.datepick._updateDatepick(inst); 448 } 449} 450 451 452//////////////////////////////////////////////////////////////////////////// 453// Days Selections - support functions 454//////////////////////////////////////////////////////////////////////////// 455 456/** 457 * Get first day of selection 458 * 459 * @param dates 460 * @returns {string|*} 461 */ 462function get_first_day_of_selection(dates) { 463 464 // Multiple days selections 465 if ( dates.indexOf( ',' ) != -1 ){ 466 var dates_array = dates.split( /,\s*/ ); 467 var length = dates_array.length; 468 var element = null; 469 var new_dates_array = []; 470 471 for ( var i = 0; i < length; i++ ){ 472 473 element = dates_array[ i ].split( /\./ ); 474 475 new_dates_array[ new_dates_array.length ] = element[ 2 ] + '.' + element[ 1 ] + '.' + element[ 0 ]; //2013.12.20 476 } 477 new_dates_array.sort(); 478 479 element = new_dates_array[ 0 ].split( /\./ ); 480 481 return element[ 2 ] + '.' + element[ 1 ] + '.' + element[ 0 ]; //20.12.2013 482 } 483 484 // Range days selection 485 if ( dates.indexOf( ' - ' ) != -1 ){ 486 var start_end_date = dates.split( " - " ); 487 return start_end_date[ 0 ]; 488 } 489 490 // Single day selection 491 return dates; //20.12.2013 492} 493 494 495// Get last day of selection 496function get_last_day_of_selection(dates) { 497 498 // Multiple days selections 499 if ( dates.indexOf(',') != -1 ){ 500 var dates_array =dates.split(/,\s*/); 501 var length = dates_array.length; 502 var element = null; 503 var new_dates_array = []; 504 505 for (var i = 0; i < length; i++) { 506 507 element = dates_array[i].split(/\./); 508 509 new_dates_array[new_dates_array.length] = element[2]+'.' + element[1]+'.' + element[0]; //2013.12.20 510 } 511 new_dates_array.sort(); 512 513 element = new_dates_array[(new_dates_array.length-1)].split(/\./); 514 515 return element[2]+'.' + element[1]+'.' + element[0]; //20.12.2013 516 } 517 518 // Range days selection 519 if ( dates.indexOf(' - ') != -1 ){ 520 var start_end_date = dates.split(" - "); 521 return start_end_date[(start_end_date.length-1)]; 522 } 523 524 // Single day selection 525 return dates; //20.12.2013 526} 527 528 529// Set selected days at calendar as UnAvailable 530function setUnavailableSelectedDays( bk_type ){ 531 var sel_dates = jQuery( '#calendar_booking' + bk_type ).datepick( 'getDate' ); 532 var class_day2; 533 for ( var i = 0; i < sel_dates.length; i++ ){ 534 class_day2 = (sel_dates[ i ].getMonth() + 1) + '-' + sel_dates[ i ].getDate() + '-' + sel_dates[ i ].getFullYear(); 535 date_approved[ bk_type ][ class_day2 ] = [(sel_dates[ i ].getMonth() + 1), sel_dates[ i ].getDate(), sel_dates[ i ].getFullYear(), 0, 0, 0]; 536 jQuery( '#calendar_booking' + bk_type + ' td.cal4date-' + class_day2 ).html( sel_dates[ i ].getDate() ); 537 // jQuery('#calendar_booking'+bk_type).datepick('refresh'); 538 } 539} 540 541 542// After reservation action is done 543function setReservedSelectedDates( bk_type ){ 544 545 var is_pay_now = false; 546 547 if (document.getElementById('calendar_booking'+bk_type) === null ) { 548 // No calendar at the page, only booking form (BL) 549 jQuery( '#submiting' + bk_type ).html( '' ); 550 jQuery( '#booking_form_div' + bk_type ).hide(); 551 552 if ( jQuery( '#ajax_respond_insert' + bk_type ).offset().top > 0 ){ //FixIn: 9.2.3.9 553 // makeScroll( '#ajax_respond_insert' + bk_type ); 554 } else { 555 makeScroll( '#submiting' + bk_type ); 556 } 557 558 559 if ( ( document.getElementById('gateway_payment_forms'+bk_type) != null ) && 560 ( document.getElementById('gateway_payment_forms'+bk_type).innerHTML != '' ) ) 561 is_pay_now = true; 562 563 if ( (! is_pay_now) || ( is_booking_without_payment == true ) ) 564 if (type_of_thank_you_message == 'page') { // Page 565 timeoutID_of_thank_you_page = setTimeout(function ( ) {location.href= thank_you_page_URL;} ,1000); 566 } else { // Message 567 568 document.getElementById('submiting'+bk_type).innerHTML = '<div class=\"submiting_content wpdev-help-message alert alert-warning alert-success\" >'+new_booking_title+'</div>'; 569 570 if ( parseInt( new_booking_title_time ) > 0 ){ //FixIn: 9.6.2.2 571 572 jQuery('.submiting_content').fadeOut( new_booking_title_time ); 573 574 setTimeout( function (){ 575 location.reload( true ); 576 }, parseInt( 1000 + new_booking_title_time ) ); //FixIn: 8.1.2.14 577 } 578 } 579 580 } else { 581 582 setUnavailableSelectedDays( bk_type ); 583 document.getElementById('date_booking' + bk_type).value = ''; 584 jQuery('#calendar_booking' + bk_type + ', .block_hints').hide(); 585 586 if ( location.href.indexOf('admin.php') == -1 ) { // Front End 587 588 // Get calendar from the html and insert it before form div, which will hide after btn click 589 jQuery('#calendar_booking' + bk_type).insertBefore("#booking_form_div" + bk_type); 590 document.getElementById("booking_form_div" + bk_type).style.display = "none"; 591 592 jQuery( '#hided_booking_form' + bk_type ).prevAll( 'select[name="active_booking_form"]' ).hide(); //FixIn: 7.1.2.13 593 jQuery( '#hided_booking_form' + bk_type ).prevAll( 'label[for="calendar_type"]' ).hide(); 594 595 //makeScroll('#ajax_respond_insert' + bk_type); //FixIn: 9.1.2.1 596 597 if ((document.getElementById('gateway_payment_forms' + bk_type) != null) && 598 (document.getElementById('gateway_payment_forms' + bk_type).innerHTML != '')) 599 is_pay_now = true; 600 601 if ((!is_pay_now) || (is_booking_without_payment == true)) { 602 if (type_of_thank_you_message == 'page') { // Page 603 timeoutID_of_thank_you_page = setTimeout(function ( ) { 604 location.href = thank_you_page_URL; 605 }, 1000); 606 } else { // Message 607 document.getElementById('submiting' + bk_type).innerHTML = '<div class=\"submiting_content wpdev-help-message alert alert-warning alert-success\" >' + new_booking_title + '</div>'; 608 609 //FixIn: 8.5.2.26 610 if ( ! jQuery('#submiting' + bk_type ).is(':visible') ) { 611 jQuery('#submiting' + bk_type ).closest( 'form.booking_form').before( jQuery('#submiting' + bk_type ) ); 612 jQuery('#submiting' + bk_type ).show(); 613 jQuery(".wpbc_submit_spinner").hide(); 614 } 615 616 makeScroll( '#submiting' + bk_type ); 617 618 if ( parseInt( new_booking_title_time ) > 0 ){ //FixIn: 9.6.2.2 619 620 jQuery('.submiting_content').fadeOut( new_booking_title_time ); 621 622 setTimeout( function (){ 623 location.reload( true ); 624 }, parseInt( 1000 + new_booking_title_time ) ); //FixIn: 8.1.2.14 625 } 626 } 627 } 628 629 } else { // Back End 630 setTimeout( function () { 631 location.reload( true ); 632 }, 1000); 633 } 634 } 635} 636 637 638/** 639 * Check ID of selected additional calendars 640 * 641 * @param int bk_type 642 * @returns array 643 */
644function wpbc_get_arr_of_selected_additional_calendars( bk_type ){ //FixIn: 8.5.2.26 645 646 var selected_additionl_calendars = []; 647 648 // Checking according additional calendars 649 if ( document.getElementById( 'additional_calendars' + bk_type ) != null ){ 650 651 var id_additional_str = document.getElementById( 'additional_calendars' + bk_type ).value; 652 var id_additional_arr = id_additional_str.split( ',' ); 653 654 var is_all_additional_days_unselected = true; 655 656 for ( var ia = 0; ia < id_additional_arr.length; ia++ ){ 657 if ( document.getElementById( 'date_booking' + id_additional_arr[ ia ] ).value != '' ){ 658 selected_additionl_calendars.push( id_additional_arr[ ia ] ); 659 } 660 } 661 } 662 return selected_additionl_calendars; 663} 664 665//////////////////////////////////////////////////////////////////////////// 666// Submit Booking Data 667//////////////////////////////////////////////////////////////////////////// 668 669// Check fields at form and then send request 670function mybooking_submit( submit_form , bk_type, wpdev_active_locale){ 671//console.log( wpbc_get_arr_of_selected_additional_calendars( bk_type ) ); 672 673 674 var target_elm = jQuery( ".booking_form_div" ).trigger( "booking_form_submit_click", [bk_type, submit_form, wpdev_active_locale] ); //FixIn: 8.8.3.13 675 if ( 676 ( jQuery( target_elm ).find( 'input[name="booking_form_show_summary"]' ).length > 0 ) 677 && ( 'pause_submit' === jQuery( target_elm ).find( 'input[name="booking_form_show_summary"]' ).val() ) 678 ) 679 { 680 return false; 681 } 682 683 //FixIn: 8.4.0.2 684 var is_error = wpbc_check_errors_in_booking_form( bk_type ); 685 if ( is_error ) { return false; } 686 687 // Show message if no selected days in Calendar(s) 688 if (document.getElementById('date_booking' + bk_type).value == '') { 689 690 var arr_of_selected_additional_calendars = wpbc_get_arr_of_selected_additional_calendars( bk_type ); //FixIn: 8.5.2.26 691 692 if ( arr_of_selected_additional_calendars.length == 0 ) { 693 showMessageUnderElement( '#date_booking' + bk_type, message_verif_selectdts, ''); 694 makeScroll('#calendar_booking' + bk_type); // Scroll to the calendar 695 return; 696 } 697 } 698 699 var count = submit_form.elements.length; 700 var formdata = ''; 701 var inp_value; 702 var element; 703 var el_type; 704 705 706 // Serialize form here 707 for ( var i = 0; i < count; i++ ){ //FixIn: 9.1.5.1 708 element = submit_form.elements[i]; 709 710 if ( jQuery( element ).closest( '.booking_form_garbage' ).length ) { 711 continue; // Skip elements from garbage //FixIn: 7.1.2.14 712 } 713 714 if ( 715 ( element.type !== 'button' ) 716 && ( element.type !== 'hidden' ) 717 && ( element.name !== ( 'date_booking' + bk_type ) ) 718 // && ( jQuery( element ).is( ':visible' ) ) //FixIn: 7.2.1.12.2 // Its prevent of saving hints, and some other hidden element 719 ) { // Skip buttons and hidden element - type //FixIn: 7.2.1.12 720 721 722 // Get Element Value 723 if ( element.type == 'checkbox' ){ 724 725 if (element.value == '') { 726 inp_value = element.checked; 727 } else { 728 if (element.checked) inp_value = element.value; 729 else inp_value = ''; 730 } 731 732 } else if ( element.type == 'radio' ) { 733 734 if (element.checked) { 735 inp_value = element.value; 736 } else { 737 // Check if this radio required, and if it does not check, then show warning, otherwise if it is not required or some other option checked skip this loop 738 // We need to check it here, because radio have the several options with same name and type, and otherwise we will save several options with selected and empty values. 739 if ( //FixIn: 7.0.1.62 740 ( element.className.indexOf('wpdev-validates-as-required') !== -1 ) 741 && ( jQuery( element ).is( ':visible' ) ) //FixIn: 7.2.1.12.2 // Its prevent of saving hints, and some other hidden element 742 && ( ! jQuery(':radio[name="'+element.name+'"]', submit_form).is(":checked") ) ) { 743 showErrorMessage( element , message_verif_requred_for_radio_box, false ); //FixIn: 8.5.1.3 744 return; 745 } 746 continue; 747 } 748 } else { 749 inp_value = element.value; 750 } 751 752 // Get value in selectbox of multiple selection 753 if (element.type =='select-multiple') { 754 inp_value = jQuery('[name="'+element.name+'"]').val() ; 755 if (( inp_value == null ) || (inp_value.toString() == '' )) 756 inp_value=''; 757 } 758 759 // Make validation only for visible elements 760 if ( jQuery( element ).is( ':visible' ) ) { //FixIn: 7.2.1.12.2 761 // Recheck for max num. available visitors selection 762 if ( element.name == ('visitors'+bk_type) ){ 763 if ( typeof(is_max_visitors_selection_more_than_available) == 'function' ){ 764 765 //FixIn: 8.2.1.28 766 if ( ( wpbc_is_time_field_in_booking_form( bk_type, submit_form.elements ) ) 767 && ( ! wpdev_in_array( parent_booking_resources, bk_type ) ) 768 ) { 769 770 // We are having timeslots and this is single booking resource, so skip checking for max number of visitors 771 772 } else { 773 774 if ( is_max_visitors_selection_more_than_available( bk_type, inp_value, element ) ){ 775 return; 776 } 777 } 778 } 779 } 780 // Phone validation 781 /*if ( element.name == ('phone'+bk_type) ) { 782 // we validate a phone number of 10 digits with no comma, no spaces, no punctuation and there will be no + sign in front the number - See more at: http://www.w3resource.com/javascript/form/phone-no-vali
782dation.php#sthash.U9FHwcdW.dpuf 783 var reg = /^\d{10}$/; 784 var message_verif_phone = "Please enter correctly phone number"; 785 if ( inp_value != '' ) 786 if(reg.test(inp_value) == false) {showErrorMessage( element , message_verif_phone, false );return;} 787 }*/ 788 789 // Validation Check --- Requred fields 790 if ( element.className.indexOf('wpdev-validates-as-required') !== -1 ){ 791 if ((element.type =='checkbox') && ( element.checked === false)) { 792 if ( ! jQuery(':checkbox[name="'+element.name+'"]', submit_form).is(":checked") ) { 793 showErrorMessage( element , message_verif_requred_for_check_box, false ); //FixIn: 8.5.1.3 794 return; 795 } 796 } 797 if (element.type =='radio') { 798 if ( ! jQuery(':radio[name="'+element.name+'"]', submit_form).is(":checked") ) { 799 showErrorMessage( element , message_verif_requred_for_radio_box, false ); //FixIn: 8.5.1.3 800 return; 801 } 802 } 803 804 if ( (element.type != 'checkbox') && (element.type != 'radio') && ( '' === wpbc_trim( inp_value ) ) ){ //FixIn: 8.8.1.3 //FixIn:7.0.1.39 //FixIn: 8.7.11.12 805 showErrorMessage( element , message_verif_requred, false ); //FixIn: 8.5.1.3 806 return; 807 } 808 } 809 810 // Validation Check --- Email correct filling field 811 if ( element.className.indexOf('wpdev-validates-as-email') !== -1 ){ 812 inp_value = inp_value.replace(/^\s+|\s+$/gm,''); // Trim white space //FixIn: 5.4.5 813 var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/; 814 if ( inp_value != '' ) 815 if(reg.test(inp_value) == false) { 816 showErrorMessage( element , message_verif_emeil, false ); //FixIn: 8.5.1.3 817 return; 818 } 819 } 820 821 // Validation Check --- Same Email Field 822 if ( ( element.className.indexOf('wpdev-validates-as-email') !== -1 ) && ( element.className.indexOf('same_as_') !== -1 ) ) { 823 824 // Get the name of Primary Email field from the "same_as_NAME" class 825 var primary_email_name = element.className.match(/same_as_([^\s])+/gi); 826 if (primary_email_name != null) { // We found 827 primary_email_name = primary_email_name[0].substr(8); 828 829 // Recehck if such primary email field exist in the booking form 830 if (jQuery('[name="' + primary_email_name + bk_type + '"]').length > 0) { 831 832 // Recheck the values of the both emails, if they do not equla show warning 833 if ( jQuery('[name="' + primary_email_name + bk_type + '"]').val() !== inp_value ) { 834 showErrorMessage( element , message_verif_same_emeil , false ); //FixIn: 8.5.1.3 835 return; 836 } 837 } 838 } 839 // Skip one loop for the email veryfication field 840 continue; //FixIn: 8.1.2.15 841 } 842 843 } 844 845 // Get Form Data 846 if ( element.name !== ('captcha_input' + bk_type) ) { 847 if (formdata !=='') formdata += '~'; // next field element 848 849 el_type = element.type; 850 if ( element.className.indexOf('wpdev-validates-as-email') !== -1 ) el_type='email'; 851 if ( element.className.indexOf('wpdev-validates-as-coupon') !== -1 ) el_type='coupon'; 852 853 inp_value = inp_value + ''; 854 inp_value = inp_value.replace(new RegExp("\\^",'g'), '^'); // replace registered characters 855 inp_value = inp_value.replace(new RegExp("~",'g'), '~'); // replace registered characters 856 857 inp_value = inp_value.replace(/"/g, '"'); // replace double quot 858 inp_value = inp_value.replace(/'/g, '''); // replace single quot 859 860 formdata += el_type + '^' + element.name + '^' + inp_value ; // element attr 861 } 862 } 863 864 } // End Fields Loop 865 866 //FixIn:6.1.1.3 867 if( typeof( wpbc_is_this_time_selection_not_available ) == 'function' ) { 868 869 if ( document.getElementById('date_booking' + bk_type).value == '' ) { // Primary calendar not selected. 870 871 if ( document.getElementById('additional_calendars' + bk_type ) != null ) { // Checking additional calendars. 872 873 var id_additional_str = document.getElementById('additional_calendars' + bk_type).value; //Loop have to be here based on , sign 874 var id_additional_arr = id_additional_str.split(','); 875 var is_times_dates_ok = false;
876 for ( var ia=0;ia<id_additional_arr.length;ia++ ) { 877 if ( 878 ( document.getElementById('date_booking' + id_additional_arr[ia] ).value != '' ) 879 && ( ! wpbc_is_this_time_selection_not_available( id_additional_arr[ia], submit_form.elements ) ) 880 ){ 881 is_times_dates_ok = true; 882 } 883 } 884 if ( ! is_times_dates_ok ) return; 885 } 886 } else { //Primary calendar selected. 887 if ( wpbc_is_this_time_selection_not_available( bk_type, submit_form.elements ) ) 888 return; 889 } 890 } 891 892 if ( bk_days_selection_mode == 'dynamic' ) { // Check if visitor finish dates selection. 893 //FixIn:6.1.1.5 894 var selected_dates_cal_id = []; // Get ID of calendars, where selected dates. 895 if ( document.getElementById('date_booking' + bk_type).value != '' ) { 896 selected_dates_cal_id[selected_dates_cal_id.length] = bk_type; 897 } 898 if ( document.getElementById('additional_calendars' + bk_type) != null ) { // Checking according additional calendars. 899 var id_additional_str = document.getElementById('additional_calendars' + bk_type).value; //Loop have to be here based on , sign 900 var id_additional_arr = id_additional_str.split(','); 901 var is_all_additional_days_unselected = true; 902 for (var ia=0;ia<id_additional_arr.length;ia++) { 903 if (document.getElementById('date_booking' + id_additional_arr[ia] ).value != '' ) { 904 selected_dates_cal_id[selected_dates_cal_id.length] = id_additional_arr[ia]; 905 } 906 } 907 } 908 for( var ci = 0; ci < selected_dates_cal_id.length; ci++) { 909 var abk_type = selected_dates_cal_id[selected_dates_cal_id.length] 910 if (document.getElementById('calendar_booking'+abk_type) != null ) { 911 var inst = jQuery.datepick._getInst(document.getElementById('calendar_booking'+abk_type)); 912 if (bk_2clicks_mode_days_min != undefined) { 913 if(typeof( check_conditions_for_range_days_selection_for_check_in ) == 'function') { 914 var first_date = get_first_day_of_selection(document.getElementById('date_booking' + abk_type).value); 915 var date_sections = first_date.split("."); 916 var selceted_first_day = new Date; 917 selceted_first_day.setFullYear( parseInt(date_sections[2]-0) ,parseInt(date_sections[1]-1), parseInt(date_sections[0]-0) ); 918 check_conditions_for_range_days_selection_for_check_in(selceted_first_day, abk_type); 919 } 920 if (inst.dates.length < bk_2clicks_mode_days_min ) { 921 showMessageUnderElement( '#date_booking' + abk_type, message_verif_selectdts, ''); 922 makeScroll('#calendar_booking' + abk_type); // Scroll to the calendar 923 return; 924 } 925 } 926 } 927 } 928 } 929 930 // Cpatch verify 931 var captcha = document.getElementById('wpdev_captcha_challenge_' + bk_type); 932 933 //Disable Submit button 934 jQuery('#booking_form_div' + bk_type + ' input[type="button"]').prop("disabled", true); 935 jQuery('#booking_form_div' + bk_type + ' button').prop("disabled", true); //FixIn: 8.5.2.7 936 if (captcha != null) form_submit_send( bk_type, formdata, captcha.value, document.getElementById('captcha_input' + bk_type).value ,wpdev_active_locale); 937 else form_submit_send( bk_type, formdata, '', '' , wpdev_active_locale); 938 return; 939} 940 941 942// Gathering params for sending Ajax request and then send it 943function form_submit_send( bk_type, formdata, captcha_chalange, user_captcha ,wpdev_active_locale){ 944 945 document.getElementById('submiting' + bk_type).innerHTML = '<div style="height:20px;width:100%;text-align:center;margin:15px auto;"><img style="vertical-align:middle;box-shadow:none;width:14px;" src="'+wpdev_bk_plugin_url+'/assets/img/ajax-loader.gif"><//div>'; 946 947 var my_booking_form = ''; 948 var my_booking_hash = ''; 949 if (document.getElementById('booking_form_type' + bk_type) != undefined) 950 my_booking_form =document.getElementById('booking_form_type' + bk_type).value; 951 952 if ( wpdev_bk_edit_id_hash != '' ) my_booking_hash = wpdev_bk_edit_id_hash; 953 954 var is_send_emeils = 1; 955 if ( jQuery('#is_send_email_for_pending').length ) { 956 is_send_emeils = jQuery( '#is_send_email_for_pending' ).is( ':checked' ); //FixIn: 8.7.9.5 957 if ( false === is_send_emeils ) { is_send_emeils = 0; } 958 else { is_send_emeils = 1; } 959 } 960 961 if ( document.getElementById('date_booking' + bk_type).value != '' ) //FixIn:6.1.1.3 962 send_ajax_submit(bk_type,formdata,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form,wpdev_active_locale ); // Ajax sending request 963 else { 964 jQuery('#booking_form_div' + bk_type ).hide(); 965 jQuery('#submiting' + bk_type ).hide(); 966 } 967 968 var formdata_additional_arr; 969 var formdata_additional; 970 var my_form_field; 971 var id_additional; 972 var id_additional_str; 973 var id_additional_arr; 974 if (document.getElementById('additional_calendars' + bk_type) != null ) { 975 976 id_additional_str = document.getElementById('additional_calendars' + bk_type).value; //Loop have to be here based on , sign 977 id_additional_arr = id_additional_str.split(','); 978 979 //FixIn: 8.5.2.26 980 if ( ! jQuery( '#booking_form_div' + bk_type ).is( ':visible' ) ) { 981 jQuery( '#booking_form_div' + bk_type ).after( 982 '<div class="wpbc_submit_spinner" style="height:20px;width:100%;text-align:center;margin:15px auto;"><img style="vertical-align:middle;box-shadow:none;width:14px;" src="'+wpdev_bk_plugin_url+'/assets/img/ajax-loader.gif"></div>' 983 ); 984 } 985 986 987 988 for (var ia=0;ia<id_additional_arr.length;ia++) { 989 formdata_additional_arr = formdata; 990 formdata_additional = ''; 991 id_additional = id_additional_arr[ia]; 992 993 994 formdata_additional_arr = formdata_additional_arr.split('~'); 995 for (var j=0;j<formdata_additional_arr.length;j++) { 996 my_form_field = formdata_additional_arr[j].split('^'); 997 if (formdata_additional !=='') formdata_additional += '~'; 998 999 if (my_form_field[1].substr( (my_form_field[1].length -2),2)=='[]') 1000 my_form_field[1] = my_form_field[1].substr(0, (my_form_field[1].length - (''+bk_type).length ) - 2 ) + id_additional + '[]'; 1001 else 1002 my_form_field[1] = my_form_field[1].substr(0, (my_form_field[1].length - (''+bk_type).length ) ) + id_additional ; 1003 1004 1005 formdata_additional += my_form_field[0] + '^' + my_form_field[1] + '^' + my_form_field[2]; 1006 } 1007 1008 if ( jQuery('#gateway_payment_forms' + bk_type).length > 0 ) { // If Payment form for main booking resources is showing then append payment form for additional calendars. 1009 jQuery('#gateway_payment_forms' + bk_type).after('<div id="gateway_payment_forms'+id_additional+'"></div>'); 1010 jQuery('#gateway_payment_forms' + bk_type).after('<div id="ajax_respond_insert'+id_additional+'" style="display:none;"></div>'); 1011 } 1012 //FixIn: 8.5.2.17 1013 send_ajax_submit( id_additional ,formdata_additional,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form ,wpdev_active_locale ); // Submit 1014 1015// if (document.getElementById('date_booking' + id_additional).value != '' ) { 1016// setUnavailableSelectedDays(id_additional); // Set selected days unavailable in this calendar 1017// jQuery('#calendar_booking'+id_additional).insertBefore("#booking_form_div"+bk_type); // Insert calendar before form to do not hide it 1018// if (document.getElementById('gateway_payment_forms'+id_additional) != null) 1019// jQuery('#gateway_payment_forms'+id_additional).insertBefore("#booking_form_div"+bk_type); // Insert payment form to do not hide it 1020// else { 1021// jQuery("#booking_form_div"+bk_type).append('<div id="gateway_payment_forms'+id_additional+'" ></div>'); 1022// jQuery("#booking_form_div"+bk_type).append('<div id="ajax_respond_insert'+id_additional+'" ></div>'); 1023// } 1024// send_ajax_submit( id_additional ,formdata_additional,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form ,wpdev_active_locale ); 1025// } 1026 } 1027 } 1028} 1029 1030 1031//<![CDATA[ 1032function send_ajax_submit(bk_type,formdata,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form ,wpdev_active_locale ) { 1033 // Ajax POST here
1034 1035 var my_bk_res = bk_type; 1036 if ( document.getElementById('bk_type' + bk_type) != null ) my_bk_res = document.getElementById('bk_type' + bk_type).value; 1037 1038 jQuery.ajax({ // Start Ajax Sending 1039 // url: wpdev_bk_plugin_url+ '/' + wpdev_bk_plugin_filename, 1040 url: wpbc_ajaxurl, 1041 type:'POST', 1042 success: function (data, textStatus){if( textStatus == 'success') jQuery('#ajax_respond_insert' + bk_type).html( data ) ;}, 1043 error:function (XMLHttpRequest, textStatus, errorThrown){window.status = 'Ajax sending Error status:'+ textStatus;alert(XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText);if (XMLHttpRequest.status == 500) {alert('Please check at this page according this error:' + ' https://wpbookingcalendar.com/faq/#ajax-sending-error');}}, 1044 // beforeSend: someFunction, 1045 data:{ 1046 // ajax_action : 'INSERT_INTO_TABLE', 1047 action : 'INSERT_INTO_TABLE', 1048 bktype: my_bk_res , 1049 dates: document.getElementById('date_booking' + bk_type).value , 1050 form: formdata, 1051 captcha_chalange:captcha_chalange, 1052 captcha_user_input: user_captcha, 1053 is_send_emeils : is_send_emeils, 1054 my_booking_hash:my_booking_hash, 1055 booking_form_type:my_booking_form, 1056 wpdev_active_locale:wpdev_active_locale, 1057 wpbc_nonce: document.getElementById('wpbc_nonce' + bk_type).value 1058 } 1059 }); 1060} 1061//]]> 1062 1063//////////////////////////////////////////////////////////////////////////// 1064//////////////////////////////////////////////////////////////////////////// 1065 1066// Show Error Message in Booking Form at Front End 1067function showErrorMessage( element , errorMessage , isScrollStop ) { //FixIn: 8.5.1.3 1068 //FixIn: 8.4.0.2 1069 // if(typeof( bk_form_step_click ) == 'function') { 1070 // bk_form_step_click(); // rollback to 1st step, if system will show warning and booking form is using this customization: in the Exmaple #2 here: https://wpbookingcalendar.com/faq/customize-booking-form-for-having-several-steps-of-reservation/ 1071 // } 1072 1073 //FixIn: 8.5.1.3 1074 if ( ! isScrollStop ){ 1075 makeScroll( element ); 1076 } 1077 //FixIn: 8.7.11.10 1078 if ( jQuery( "[name='" + element.name + "']" ).is( ':visible' ) ){ 1079 jQuery("[name='"+ element.name +"']") 1080 .fadeOut( 350 ).fadeIn( 300 ) 1081 .fadeOut( 350 ).fadeIn( 400 ) 1082 .fadeOut( 350 ).fadeIn( 300 ) 1083 .fadeOut( 350 ).fadeIn( 400 ) 1084 .animate( {opacity: 1}, 4000 ) 1085 ; // mark red border 1086 } 1087 if (jQuery("[name='"+ element.name +"']").attr('type') == "radio") { 1088 1089 if ( ( ! jQuery( "[name='" + element.name + "']" ).parent().parent().parent().next().hasClass( 'alert-warning' )) 1090 || ( 1091 ( jQuery( "[name='" + element.name + "']" ).parent().parent().parent().next().hasClass( 'alert-warning' )) 1092 && ( ! jQuery( "[name='" + element.name + "']" ).parent().parent().parent().next().is( ':visible' ) ) 1093 ) 1094 ){ //FixIn: 8.4.5.7 1095 jQuery( "[name='" + element.name + "']" ).parent().parent().parent() 1096 .after( '<span class="wpdev-help-message alert alert-warning">' + errorMessage + '</span>' ); // Show message 1097 } 1098 1099 } else if (jQuery("[name='"+ element.name +"']").attr('type') == "checkbox") { 1100 1101 if ( ( ! jQuery( "[name='" + element.name + "']" ).parent().next().hasClass( 'alert-warning' )) 1102 || ( 1103 ( jQuery( "[name='" + element.name + "']" ).parent().next().hasClass( 'alert-warning' )) 1104 && ( ! jQuery( "[name='" + element.name + "']" ).parent().next().is( ':visible' ) ) 1105 ) 1106 ){ //FixIn: 8.4.5.7 1107 jQuery( "[name='" + element.name + "']" ).parent() 1108 .after( '<span class="wpdev-help-message alert alert-warning">' + errorMessage + '</span>' ); // Show message 1109 } 1110 1111 } else { 1112 1113 if ( ( ! jQuery( "[name='" + element.name + "']" ).next().hasClass( 'alert-warning' )) 1114 || ( 1115 ( jQuery( "[name='" + element.name + "']" ).next().hasClass( 'alert-warning' )) 1116 && ( ! jQuery( "[name='" + element.name + "']" ).next().is( ':visible' ) ) 1117 ) 1118 ){ //FixIn: 8.4.5.7 1119 jQuery( "[name='" + element.name + "']" ) 1120 .after( '<span class="wpdev-help-message alert alert-warning">' + errorMessage + '</span>' ); // Show message 1121 } 1122 } 1123 1124 jQuery( '.wpdev-help-message' ).css( { 1125 // 'padding' : '5px 5px 4px', 1126 'margin' : '2px 2px 2px 10px', 1127 'vertical-align': 'top' 1128 // 'line-height' : '32px' 1129 } ); 1130 // Calendar error message: //FixIn: 9.3.1.9 1131 jQuery( '.wpdev-element-message' ).css( { 1132 'margin' : '10px 5px 10px 0px', 1133 'line-height' : '32px' 1134 } ); 1135 1136 1137 if ( element.type == 'checkbox' ) 1138 jQuery(".wpdev-help-message").css( { 'vertical-align': 'middle'} ); 1139 1140 jQuery(".widget_wpdev_booking .booking_form .wpdev-help-message") 1141 .css( {'vertical-align': 'sub' } ) ; 1142 jQuery(".wpdev-help-message") 1143 .animate( {opacity: 1}, 10000 ) 1144 .fadeOut( 2000 ); 1145 1146 if ( ! jQuery( "[name='" + element.name + "']" ).is( ':visible' ) ){ 1147 makeScroll( jQuery(".wpdev-help-message") ); 1148 } 1149 jQuery( element ).trigger( 'focus' ); //FixIn: 8.7.11.12 1150 return element; //FixIn: 9.3.1.9 1151} 1152 1153/** 1154 * Show message under specific element 1155 * 1156 * @param {type} element - jQuery definition of the element 1157 * @param {type} errorMessage - String message 1158 * @param {type} message_type "" | "alert-danger" | "alert-success" | "alert-info" 1159 */ 1160function showMessageUnderElement( element , errorMessage , message_type) { 1161 //FixIn: 8.4.0.2 1162 // if(typeof( bk_form_step_click ) == 'function') { 1163 // bk_form_step_click(); // rollback to 1st step, if system will show warning and booking form is using this customization: in the Exmaple #2 here: https://wpbookingcalendar.com/faq/customize-booking-form-for-having-several-steps-of-reservation/ 1164 // } 1165 1166 makeScroll( element ); 1167 1168 if ( jQuery( element ).attr('type') == "radio" ) { 1169 1170 if ( ( ! jQuery( element ).parent().parent().parent().next().hasClass( 'alert-warning' )) 1171 || ( 1172 ( jQuery( element ).parent().parent().parent().next().hasClass( 'alert-warning' )) 1173 && ( ! jQuery( element ).parent().parent().parent().next().is( ':visible' ) ) 1174 ) 1175 ){ //FixIn: 8.4.5.7 1176 jQuery( element ).parent().parent().parent() 1177 .after( '<span class="wpdev-help-message wpdev-element-message alert alert-warning ' + message_type + '">' + errorMessage + '</span>' ); // Show message 1178 } 1179 } else if (jQuery( element ).attr('type') == "checkbox") { 1180 1181 if ( ( ! jQuery( element ).parent().next().hasClass( 'alert-warning' )) 1182 || ( 1183 ( jQuery( element ).parent().next().hasClass( 'alert-warning' )) 1184 && ( ! jQuery( element ).parent().next().is( ':visible' ) ) 1185 ) 1186 ){ //FixIn: 8.4.5.7 1187 jQuery( element ).parent() 1188 .after( '<span class="wpdev-help-message wpdev-element-message alert alert-warning ' + message_type + '">' + errorMessage + '</span>' ); // Show message 1189 } 1190 } else { 1191 if ( ( ! jQuery( element ).next().hasClass( 'alert-warning' )) 1192 || ( 1193 ( jQuery( element ).next().hasClass( 'alert-warning' )) 1194 && ( ! jQuery( element ).next().is( ':visible' ) ) 1195 ) 1196 ){ //FixIn: 8.4.5.7 1197 jQuery( element ) 1198 .after( '<span class="wpdev-help-message wpdev-element-message alert alert-warning ' + message_type + '">' + errorMessage + '</span>' ); // Show message 1199 } 1200 } 1201 // jQuery(".wpdev-help-message") 1202 // .css( {'padding' : '5px 5px 4px', 'margin' : '10px 2px', 'vertical-align': 'middle' } ); 1203 jQuery(".widget_wpdev_booking .booking_form .wpdev-help-message") 1204 .css( {'vertical-align': 'sub' } ) ; 1205 jQuery(".wpdev-help-message") 1206 .animate( {opacity: 1}, 10000 ) 1207 .fadeOut( 2000 ); 1208} 1209 1210// Hint labels inside of input boxes 1211jQuery(document).ready( function(){ 1212 1213 jQuery('div.inside_hint').on( 'click', function(){ //FixIn: 8.7.11.12 1214 jQuery(this).css('visibility', 'hidden').siblings('.has-inside-hint').trigger( 'focus' ); //FixIn: 8.7.11.12 1215 }); 1216 1217 jQuery('input.has-inside-hint').on( 'blur', function(){ //FixIn: 8.7.11.12 1218 if ( this.value == '' ) 1219 jQuery(this).siblings('.inside_hint').css('visibility', ''); 1220 }).on( 'focus', function(){ //FixIn: 8.7.11.12 1221 jQuery(this).siblings('.inside_hint').css('visibility', 'hidden'); 1222 }); 1223 1224 jQuery('.booking_form_div input[type=button]').prop("disabled", false); 1225}); 1226 1227
1228//////////////////////////////////////////////////////////////////////////// 1229// Support Functions 1230//////////////////////////////////////////////////////////////////////////// 1231 1232// Scroll to script 1233function makeScroll( object_name ){ 1234 1235 var targetOffset = jQuery( object_name ).offset().top; 1236 if ( targetOffset <= 0 ){ 1237 1238 if ( 0 != jQuery( object_name ).nextAll( ':visible' ).length ){ 1239 targetOffset = jQuery( object_name ).nextAll( ':visible' ).first().offset().top; //FixIn: 9.2.3.9 1240 } else if ( 0 != jQuery( object_name ).parent().nextAll( ':visible' ).length ){ 1241 targetOffset = jQuery( object_name ).parent().nextAll( ':visible' ).first().offset().top; 1242 } 1243 1244 } 1245 1246 if ( jQuery( '#wpadminbar' ).length > 0 ){ 1247 targetOffset = targetOffset - 50; 1248 } else { 1249 targetOffset = targetOffset - 20; 1250 } 1251 1252 jQuery( 'html,body' ).animate( {scrollTop: targetOffset}, 500 ); 1253} 1254 1255 1256//FixIn: 8.8.1.3 1257/** 1258 * Trim strings and array joined with (,) 1259 * 1260 * @param string_to_trim string / array 1261 * @returns string 1262 */ 1263function wpbc_trim( string_to_trim ){ 1264 1265 if ( Array.isArray( string_to_trim ) ){ 1266 string_to_trim = string_to_trim.join( ',' ); 1267 } 1268 1269 if ( 'string' == typeof (string_to_trim) ){ 1270 string_to_trim = string_to_trim.trim(); 1271 } 1272 1273 return string_to_trim; 1274} 1275 1276 1277function wpdev_in_array (array_here, p_val) { 1278 for(var i = 0, l = array_here.length; i < l; i++) { 1279 if(array_here[i] == p_val) { 1280 return true; 1281 } 1282 } 1283 return false; 1284} 1285 1286 1287function days_between(date1, date2) { 1288 1289 // The number of milliseconds in one day 1290 var ONE_DAY = 1000 * 60 * 60 * 24; 1291 1292 // Convert both dates to milliseconds 1293 var date1_ms = date1.getTime(); 1294 var date2_ms = date2.getTime(); 1295 1296 // Calculate the difference in milliseconds 1297 var difference_ms = date1_ms - date2_ms; 1298 1299 // Convert back to days and return 1300 return Math.round(difference_ms/ONE_DAY); 1301 1302} 1303 1304 1305function daysInMonth(month,year) { 1306 var m = [31,28,31,30,31,30,31,31,30,31,30,31]; 1307 if (month != 2) return m[month - 1]; 1308 if (year%4 != 0) return m[1]; 1309 if (year%100 == 0 && year%400 != 0) return m[1]; 1310 return m[1] + 1; 1311} 1312 1313 1314function wpbc_timeline_nav( timeline_obj, nav_step ){ 1315 1316 jQuery( ".wpbc_timeline_front_end" ).trigger( "timeline_nav" , [ timeline_obj, nav_step ] ); //FixIn:7.0.1.48 1317 1318 jQuery( '#'+timeline_obj.html_client_id + ' .wpbc_tl_prev,#'+timeline_obj.html_client_id + ' .wpbc_tl_next').remove(); 1319 1320 jQuery('#'+timeline_obj.html_client_id + ' .wpbc_tl_title').html( '<span class="glyphicon glyphicon-refresh wpbc_spin"></span>   Loading...' ); // '<div style="height:20px;width:100%;text-align:center;margin:15px auto;">Loading ... <img style="vertical-align:middle;box-shadow:none;width:14px;" src="'+wpdev_bk_plugin_url+'/assets/img/ajax-loader.gif"><//div>' 1321 1322 jQuery.ajax({ 1323 url: wpbc_ajaxurl, 1324 type:'POST', 1325 success: function ( data, textStatus ){ // Note, here we direct show HTML to TimeLine frame 1326 if( textStatus == 'success') { 1327 jQuery('#' + timeline_obj.html_client_id + ' .wpbc_timeline_ajax_replace' ).html( data ); 1328 return true; 1329 } 1330 }, 1331 error: function ( XMLHttpRequest, textStatus, errorThrown){ 1332 window.status = 'Ajax Error! Status: ' + textStatus; 1333 alert( 'Ajax Error! Status: ' + XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText ); 1334 }, 1335 // beforeSend: someFunction, 1336 data:{ 1337 action: 'WPBC_TIMELINE_NAV', 1338 timeline_obj: timeline_obj, 1339 nav_step: nav_step, 1340 wpdev_active_locale:wpbc_active_locale, 1341 wpbc_nonce: document.getElementById('wpbc_nonce_'+ timeline_obj.html_client_id).value 1342 } 1343 }); 1344} 1345 1346 1347 1348/** 1349 * Unselect all days in calendar 1350 * 1351 * @param bk_type - ID of booking resource 1352 */
1353function wpbc_unselect_all_days( bk_type ){ //FixIn: 8.0.1.2 1354 1355 var is_calendar_exist = jQuery( '#calendar_booking' + bk_type ); 1356 1357 if ( is_calendar_exist.length > 0 ){ 1358 1359 var inst = jQuery.datepick._getInst( document.getElementById( 'calendar_booking' + bk_type ) ); // Unselect all dates and set properties of Datepick 1360 1361 jQuery( '#date_booking' + bk_type ).val( '' ); 1362 inst.stayOpen = false; 1363 inst.dates = []; 1364 jQuery.datepick._updateDatepick( inst ); 1365 } 1366} 1367 1368 1369 1370//FixIn: 8.4.0.2 1371/** 1372 * Check errors in booking form fields, and show warnings if some errors exist. 1373 * Check errors, like not selected dates or not filled requred form fields, or not correct entering email or phone fields, etc... 1374 * 1375 * @param bk_type int (ID of booking resource) 1376 */ 1377function wpbc_check_errors_in_booking_form( bk_type ) { 1378 1379 var is_error_in_field = false; // By default all is good - no error 1380 1381 var my_form = jQuery( '#booking_form' + bk_type ); 1382 1383 if ( my_form.length ) { 1384 1385 var fields_with_errors_arr = []; 1386 1387 // Pseudo-selector that get form elements <input , <textarea , <select, <button... 1388 my_form.find( ':input' ).each( function( index, el ) { 1389 1390 // Skip some elements 1391 var skip_elements = [ 'hidden', 'button' ]; 1392 1393 if ( -1 == skip_elements.indexOf( jQuery( el ).attr( 'type' ) ) ){ 1394 1395 // Check Calendar Dates Selection 1396 if ( ( 'date_booking' + bk_type ) == jQuery( el ).attr( 'name' ) ) { 1397 1398 // Show Warning only if the calendar visible ( we are at step with calendar) 1399 if ( 1400 ( ( jQuery( '#calendar_booking' + bk_type ).is( ':visible' ) ) && ( '' == jQuery( el ).val() ) ) 1401 && ( wpbc_get_arr_of_selected_additional_calendars( bk_type ).length == 0 ) //FixIn: 8.5.2.26 1402 ){ //FixIn: 8.4.4.5 1403 showMessageUnderElement( '#date_booking' + bk_type, message_verif_selectdts, '' ); 1404 makeScroll('#calendar_booking' + bk_type); // Scroll to the calendar //FixIn: 8.5.1.3 1405 is_error_in_field = true; // Error 1406 } 1407 } 1408 1409 // Check only visible elements at this step 1410 if ( jQuery( el ).is( ':visible' ) ){ 1411// console.log( '|id, type, val, visible|::', jQuery( el ).attr( 'name' ), '|' + jQuery( el ).attr( 'type' ) + '|', jQuery( el ).val(), jQuery( el ).is( ':visible' ) ); 1412 1413 // Is Required 1414 if ( jQuery( el ).hasClass( 'wpdev-validates-as-required' ) ){ 1415 1416 // Checkboxes 1417 if ( 'checkbox' == jQuery( el ).attr( 'type' ) ){ 1418 1419 if ( 1420 ( ! jQuery( el ).is( ':checked' )) 1421 && ( ! jQuery( ':checkbox[name="' + el.name + '"]', my_form ).is( ":checked" ) ) //FixIn: 8.5.2.12 1422 ){ 1423 showErrorMessage( el, message_verif_requred_for_check_box, is_error_in_field ); 1424 fields_with_errors_arr.push( el ); 1425 is_error_in_field = true; // Error 1426 } 1427 1428 // Radio boxes 1429 } else if ( 'radio' == jQuery( el ).attr( 'type' ) ){ 1430 1431 if ( !jQuery( ':radio[name="' + jQuery( el ).attr( 'name' ) + '"]', my_form ).is( ':checked' ) ){ 1432 showErrorMessage( el, message_verif_requred_for_radio_box, is_error_in_field ); 1433 fields_with_errors_arr.push( el ); 1434 is_error_in_field = true; // Error 1435 } 1436 1437 // Other elements 1438 } else { 1439 1440 var inp_value = jQuery( el ).val(); 1441 1442 if ( '' === wpbc_trim( inp_value ) ){ //FixIn: 8.8.1.3 //FixIn: 8.7.11.12 1443 showErrorMessage( el, message_verif_requred, is_error_in_field ); 1444 fields_with_errors_arr.push( el ); 1445 is_error_in_field = true; // Error 1446 } 1447 } 1448 } 1449 1450 // Validate Email 1451 if ( jQuery( el ).hasClass( 'wpdev-validates-as-email' ) ){ 1452 var inp_value = jQuery( el ).val(); 1453 inp_value = inp_value.replace( /^\s+|\s+$/gm, '' ); // Trim white space //FixIn: 5.4.5 1454 var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/; 1455 if ( (inp_value != '') && (reg.test( inp_value ) == false) ){ 1456 showErrorMessage( el, message_verif_emeil, is_error_in_field ); 1457 fields_with_errors_arr.push( el ); 1458 is_error_in_field = true; // Error 1459 } 1460 } 1461 1462 // Validate For digit entering - for example for - Phone 1463 // <p>Digit Field:<br />[text* dig_field class:validate_as_digit] </p> 1464 // <p>Phone:<br />[text* phone class:validate_digit_8] </p> 1465 1466 var classList = jQuery( el ).attr( 'class' ); 1467 1468 if ( classList ){ 1469 1470 classList = classList.split( /\s+/ ); 1471 1472 jQuery.each( classList, function ( cl_index, cl_item ){ 1473
1474 //////////////////////////////////////////////////////////////////////////////////////////// 1475 1476 // Validate field value as "Date" [CSS class - 'validate_as_digit'] 1477 if ( 'validate_as_date' === cl_item ) { 1478 1479 // Valid values: 09-25-2018, 09/25/2018, 09-25-2018, 31-9-1918 --- m/d/Y, m.d.Y, m-d-Y, d/m/Y, d.m.Y, d-m-Y 1480 var regex = new RegExp( '^[0-3]?\\d{1}[\\/\\.\\-]+[0-3]?\\d{1}[\\/\\.\\-]+[0-2]+\\d{3}$' ); // Check for Date 09/25/2018 1481 var message_verif_phone = 'This field must be valid date like this ' + '09/25/2018'; 1482 var inp_value = jQuery( el ).val(); 1483 1484 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 1485 showErrorMessage( el, message_verif_phone, is_error_in_field ); 1486 fields_with_errors_arr.push( el ); 1487 is_error_in_field = true; // Error 1488 } 1489 } 1490
1491 //////////////////////////////////////////////////////////////////////////////////////////// 1492 1493 // Validate field value as "DIGIT" [CSS class - 'validate_as_digit'] 1494 if ( 'validate_as_digit' === cl_item ) { 1495 1496 var regex = new RegExp( '^[0-9]+\\.?[0-9]*$' ); // Check for digits 1497 var message_verif_phone = 'This field must contain only digits'; 1498 var inp_value = jQuery( el ).val(); 1499 1500 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 1501 showErrorMessage( el, message_verif_phone, is_error_in_field ); 1502 fields_with_errors_arr.push( el ); 1503 is_error_in_field = true; // Error 1504 } 1505 } 1506 1507 //////////////////////////////////////////////////////////////////////////////////////////// 1508 1509 // Validate field value as "Phone" number or any other valid number wth specific number of digits [CSS class - 'validate_digit_8' || 'validate_digit_10' ] 1510 var is_validate_digit = cl_item.substring( 0, 15 ); 1511 1512 // Check if class start with 'validate_digit_' 1513 if ( 'validate_digit_' === is_validate_digit ){ 1514 1515 // Get number of digit in class: validate_digit_8 => 8 or validate_digit_10 => 10 1516 var digits_to_check = parseInt( cl_item.substring( 15 ) ); 1517 1518 // Check about any errors in 1519 if ( !isNaN( digits_to_check ) ){ 1520 1521 var regex = new RegExp( '^\\d{' + digits_to_check + '}$' ); // We was valid it as parseInt - only integer variable - digits_to_check 1522 var message_verif_phone = 'This field must contain ' + digits_to_check + ' digits'; 1523 var inp_value = jQuery( el ).val(); 1524 1525 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 1526 showErrorMessage( el, message_verif_phone, is_error_in_field ); 1527 fields_with_errors_arr.push( el ); 1528 is_error_in_field = true; // Error 1529 } 1530 } 1531 } 1532
1533 //////////////////////////////////////////////////////////////////////////////////////////// 1534 1535 }); 1536 } 1537 } 1538 } 1539 } ); 1540 1541 if ( fields_with_errors_arr.length > 0 ){ 1542 jQuery( fields_with_errors_arr[ 0 ] ).trigger( 'focus' ); //FixIn: 9.3.1.9 1543 } 1544 } 1545 1546 return is_error_in_field; 1547} 1548 1549 1550//FixIn: 8.4.4.4 1551function bk_calendar_step_click( el ){ 1552 var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val(); 1553 var is_error = wpbc_check_errors_in_booking_form( br_id ); 1554 if ( is_error ){ 1555 return false; 1556 } 1557 if ( br_id != undefined ){ 1558 jQuery( "#booking_form" + br_id + " .bk_calendar_step" ).css( {"display": "none"} ); 1559 jQuery( "#booking_form" + br_id + " .bk_form_step" ).css( {"display": "block"} ); 1560 } else { 1561 jQuery( ".bk_calendar_step" ).css( {"display": "none"} ); 1562 jQuery( ".bk_form_step" ).css( {"display": "block"} ); 1563 } 1564} 1565 1566function bk_form_step_click( el ){ 1567 var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val(); 1568 var is_error = false; // wpbc_check_errors_in_booking_form( br_id ); //FixIn: 8.4.5.6 1569 if ( is_error ){ 1570 return false; 1571 } 1572 if ( br_id != undefined ){ 1573 jQuery( "#booking_form" + br_id + " .bk_calendar_step" ).css( {"display": "block"} ); 1574 jQuery( "#booking_form" + br_id + " .bk_form_step" ).css( {"display": "none"} ); 1575 makeScroll( "#bklnk" + br_id ); 1576 } else { 1577 jQuery( ".bk_calendar_step" ).css( {"display": "block"} ); 1578 jQuery( ".bk_form_step" ).css( {"display": "none"} ); 1579 } 1580} 1581 1582//FixIn: 8.6.1.15 1583/** 1584 * Go to next specific step in Wizard style booking form, with 1585 * check all required elements specific step, otherwise show warning message! 1586 * 1587 * @param el 1588 * @param step_num 1589 * @returns {boolean} 1590 */ 1591function wpbc_wizard_step( el, step_num, step_from ){ 1592 var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val(); 1593 1594 //FixIn: 8.8.1.5 1595 if ( ( undefined == step_from ) || ( step_num > step_from ) ){ 1596 if ( 1 != step_num ){ //FixIn: 8.7.7.8 1597 var is_error = wpbc_check_errors_in_booking_form( br_id ); 1598 if ( is_error ){ 1599 return false; 1600 } 1601 } 1602 } 1603 1604 if ( wpbc_is_some_elements_visible( br_id, ['rangetime', 'durationtime', 'starttime', 'endtime'] ) ){ 1605 if ( wpbc_is_this_time_selection_not_available( br_id, document.getElementById( 'booking_form' + br_id ) ) ){ 1606 return false; 1607 } 1608 } 1609 1610 if ( br_id != undefined ){ 1611 jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" ).css( {"display": "none"} ); 1612 jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" + step_num ).css( {"display": "block"} ); 1613 } 1614} 1615 1616 1617//FixIn: 8.6.1.15 1618/** 1619 * Check if at least one element from array of elements names in booking form visible or not. 1620 * Usage Example: if ( wpbc_is_some_elements_visible( br_id, ['rangetime', 'durationtime', 'starttime', 'endtime'] ) ){ ... } 1621 * 1622 * @param bk_type 1623 * @param elements_names 1624 * @returns {boolean} 1625 */ 1626function wpbc_is_some_elements_visible( bk_type, elements_names ){ 1627 1628 var is_some_elements_visible = false; 1629 1630 var my_form = jQuery( '#booking_form' + bk_type ); 1631 1632 if ( my_form.length ){ 1633 1634 // Pseudo-selector that get form elements <input , <textarea , <select, <button... 1635 my_form.find( ':input' ).each( function ( index, el ){ 1636 1637 // Skip some elements 1638 var skip_elements = ['hidden', 'button']; 1639 1640 if ( -1 == skip_elements.indexOf( jQuery( el ).attr( 'type' ) ) ){ 1641 1642 for ( var ei = 0; ei < ( elements_names.length - 1) ; ei++ ){ 1643 1644 // Check Calendar Dates Selection 1645 if ( (elements_names[ ei ] + bk_type) == jQuery( el ).attr( 'name' ) ){ 1646 1647 if ( jQuery( el ).is( ':visible' ) ){ 1648 is_some_elements_visible = true; 1649 } 1650 } 1651 } 1652 } 1653 } ); 1654 } 1655 return is_some_elements_visible; 1656} 1657 1658//FixIn: 9.2.3.4 1659/** 1660 * Select dates in calendar 1661 * 1662 * @param int resource_id 1 1663 * @param array selected_dates [ [ 2022, "09", 20 ], [ 2022, "09", 21 ], ... ] 1664 */
1665function wpbc_select_days_in_calendar( resource_id, selected_dates ){ 1666 1667 clearTimeout( timeout_DSwindow ); 1668 1669 var inst = jQuery.datepick._getInst( document.getElementById( 'calendar_booking' + resource_id ) ); 1670 inst.dates = []; 1671 var original_array = []; 1672 var date; 1673 1674 var bk_inputing = document.getElementById( 'date_booking' + resource_id ); 1675 var bk_distinct_dates = []; 1676 1677 if ( 0 ){ // Select one additional day in calendar, during editing of booking //FixIn: 6.2.3.6 1678 var last_selected_date = new Date(); 1679 last_selected_date.setFullYear( parseInt( selected_dates[ selected_dates.length - 1 ][ 0 ] ) ); 1680 last_selected_date.setMonth( parseInt( selected_dates[ selected_dates.length - 1 ][ 1 ] - 1 ) ); 1681 last_selected_date.setDate( parseInt( selected_dates[ selected_dates.length - 1 ][ 2 ] ) ); 1682 last_selected_date.setHours( 0 ); 1683 last_selected_date.setMinutes( 0 ); 1684 last_selected_date.setSeconds( 0 ); 1685 var last_selected_next_date = new Date( last_selected_date.getTime() + 1000 * 60 * 60 * 24 ); 1686 selected_dates.push( new Array( last_selected_next_date.getFullYear(), (last_selected_next_date.getMonth() + 1), last_selected_next_date.getDate() ) ); 1687 } 1688 1689 for ( var i = 0; i < selected_dates.length; i++ ){ 1690 1691 var dta = selected_dates[ i ]; 1692 1693 date = new Date(); 1694 date.setFullYear( dta[ 0 ], (dta[ 1 ] - 1), dta[ 2 ] ); // get date 1695 original_array.push( jQuery.datepick._restrictMinMax( inst, jQuery.datepick._determineDate( inst, date, null ) ) ); //add date 1696 1697 // Add leading 0 for number from 1 to 9 //FixIn: 8.0.2.2 1698 dta[ 2 ] = parseInt( dta[ 2 ] ); 1699 if ( dta[ 2 ] < 10 ){ 1700 dta[ 2 ] = '0' + dta[ 2 ]; 1701 } 1702 dta[ 1 ] = parseInt( dta[ 1 ] ); 1703 if ( dta[ 1 ] < 10 ){ 1704 dta[ 1 ] = '0' + dta[ 1 ]; 1705 } 1706 if ( !wpdev_in_array( bk_distinct_dates, dta[ 2 ] + '.' + dta[ 1 ] + '.' + dta[ 0 ] ) ) 1707 bk_distinct_dates.push( dta[ 2 ] + '.' + dta[ 1 ] + '.' + dta[ 0 ] ); 1708 } 1709 1710 for ( var j = 0; j < original_array.length; j++ ){ //loop array of dates 1711 if ( original_array[ j ] != -1 ) inst.dates.push( original_array[ j ] ); 1712 } 1713 var dateStr = (inst.dates.length == 0 ? '' : jQuery.datepick._formatDate( inst, inst.dates[ 0 ] )); // Get first date 1714 for ( i = 1; i < inst.dates.length; i++ ) 1715 dateStr += jQuery.datepick._get( inst, 'multiSeparator' ) + jQuery.datepick._formatDate( inst, inst.dates[ i ] ); // Gathering all dates 1716 jQuery( '#date_booking' + resource_id ).val( dateStr ); // Fill the input box 1717 1718 if ( original_array.length > 0 ){ // Set showing of start month 1719 inst.cursorDate = original_array[ 0 ]; 1720 inst.drawMonth = inst.cursorDate.getMonth(); 1721 inst.drawYear = inst.cursorDate.getFullYear(); 1722 } 1723 1724 // Update calendar 1725 jQuery.datepick._notifyChange( inst ); 1726 jQuery.datepick._adjustInstDate( inst ); 1727 jQuery.datepick._showDate( inst ); 1728 jQuery.datepick._updateDatepick( inst ); 1729 1730 if ( bk_inputing != null ) 1731 bk_inputing.value = bk_distinct_dates.join( ', ' ); 1732 1733 1734 if ( typeof (check_condition_sections_in_bkform) == 'function' ){ 1735 check_condition_sections_in_bkform( jQuery( '#date_booking' + resource_id ).val(), resource_id ); 1736 } 1737 1738 if ( typeof (bkDisableBookedTimeSlots) == 'function' ){ 1739 /* HERE WE WILL DISABLE ALL OPTIONS IN RANGE TIME INTERVALS FOR SINGLE DAYS SELECTIONS FOR THAT DAYS WHERE HOURS ALREADY BOOKED */ 1740 bkDisableBookedTimeSlots( jQuery( '#date_booking' + resource_id ).val(), resource_id ); 1741 } 1742 1743 if ( typeof (showCostHintInsideBkForm) == 'function' ){ 1744 showCostHintInsideBkForm( resource_id ); 1745 } 1746} 1747
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.