| 1 |
var start_time_checking_index; |
| 2 |
|
| 3 |
/** |
| 4 |
* Get dots for partially booked dates. |
| 5 |
* For parent booking resources with specific capacity, |
| 6 |
* System do not show partially booked dates, if at least one child booking resource fully available |
| 7 |
* Otherwise it show maximum number of time-slot in one specific child booking resource |
| 8 |
* |
| 9 |
* @param param_calendar_id ID of booking resource |
| 10 |
* @param my_thisDateTime timestamp of date |
| 11 |
* @returns {string} |
| 12 |
*/ |
| 13 |
function wpbc_show_date_info_top( param_calendar_id, my_thisDateTime ) { |
| 14 |
|
| 15 |
var resource_id = parseInt(param_calendar_id.replace("calendar_booking", '')); |
| 16 |
|
| 17 |
if (isNaN(resource_id)) { |
| 18 |
return ''; // FixIn: 10.9.5.2. |
| 19 |
} |
| 20 |
|
| 21 |
// console.log( _wpbc.bookings_in_calendar__get( resource_id ) ); // for debug |
| 22 |
|
| 23 |
// 1. Get child booking resources or single booking resource that exist in dates : [1] | [1,14,15,17] |
| 24 |
var child_resources_arr = wpbc_clone_obj(_wpbc.booking__get_param_value(resource_id, 'resources_id_arr__in_dates')); |
| 25 |
|
| 26 |
// '2023-08-21' |
| 27 |
var sql_date = wpbc__get__sql_class_date(new Date(my_thisDateTime)); |
| 28 |
|
| 29 |
var child_resource_id; |
| 30 |
var merged_seconds; |
| 31 |
var dots_count = 0; |
| 32 |
|
| 33 |
var dots_in__resources = []; |
| 34 |
|
| 35 |
// Loop all resources ID. |
| 36 |
if (child_resources_arr !== null) { |
| 37 |
for (child_resource_id of child_resources_arr) { // FixIn: 10.9.5.1. |
| 38 |
|
| 39 |
// _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[12].booked_time_slots.merged_seconds = [ "07:00:11 - 07:30:02", "10:00:11 - 00:00:00" ] |
| 40 |
// _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[2].booked_time_slots.merged_seconds = [ [ 25211, 27002 ], [ 36011, 86400 ] ] |
| 41 |
|
| 42 |
if (false !== _wpbc.bookings_in_calendar__get_for_date(resource_id, sql_date)) { |
| 43 |
merged_seconds = _wpbc.bookings_in_calendar__get_for_date(resource_id, sql_date)[child_resource_id].booked_time_slots.merged_seconds; // [ [ 25211, 27002 ], [ 36011, 86400 ] ] |
| 44 |
} else { |
| 45 |
merged_seconds = []; |
| 46 |
} |
| 47 |
|
| 48 |
if (0 === merged_seconds.length) { |
| 49 |
return ''; // Day available |
| 50 |
} |
| 51 |
|
| 52 |
for (var i = 0; i < merged_seconds.length; i++) { |
| 53 |
if (!wpbc_is_this_timeslot__full_day_booked(merged_seconds[i])) { // Check if this fully booked date. If yes, then do not count it |
| 54 |
dots_count++; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
dots_in__resources.push(dots_count); |
| 59 |
dots_count = 0; |
| 60 |
} |
| 61 |
} |
| 62 |
var dots_count_max = Math.max.apply( Math, dots_in__resources ); // Get maximum value in array [ 1, 5, 3] -> 5 |
| 63 |
|
| 64 |
var dot_content = ''; |
| 65 |
for ( var d = 0; d < dots_count_max; d++ ){ |
| 66 |
dot_content += '·'; |
| 67 |
} |
| 68 |
|
| 69 |
dot_content = ( '' !== dot_content ) ? '<div class="wpbc_time_dots">' + dot_content + '</div>' : ''; |
| 70 |
|
| 71 |
return dot_content; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Show Date Info at bottom of the Day Cell |
| 76 |
* |
| 77 |
* @param param_calendar_id 'calendar_booking1' |
| 78 |
* @param my_thisDateTime 56567557757 |
| 79 |
* @returns {string} |
| 80 |
*/ |
| 81 |
function wpbc_show_date_info_bottom( param_calendar_id, my_thisDateTime ) { |
| 82 |
|
| 83 |
var bottom_hint_arr = []; |
| 84 |
|
| 85 |
// Cost Hint |
| 86 |
if ( typeof (wpbc_show_day_cost_in_date_bottom) == 'function' ) { |
| 87 |
var cost_hint = wpbc_show_day_cost_in_date_bottom( param_calendar_id, my_thisDateTime ); |
| 88 |
if ( '' !== cost_hint ) { |
| 89 |
bottom_hint_arr.push( wpbc_show_day_cost_in_date_bottom( param_calendar_id, my_thisDateTime ) ); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
// Availability Hint // FixIn: 10.6.4.1. |
| 94 |
var availability = wpbc_get_in_date_availability_hint( param_calendar_id, my_thisDateTime ) |
| 95 |
if ( '' !== availability ) { |
| 96 |
bottom_hint_arr.push( availability ); |
| 97 |
} |
| 98 |
|
| 99 |
var bottom_hint = bottom_hint_arr.join( '' ); |
| 100 |
return bottom_hint; |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Get Availability Hint for in Day Cell |
| 105 |
* |
| 106 |
* @param param_calendar_id |
| 107 |
* @param my_thisDateTime |
| 108 |
* @returns {string} |
| 109 |
*/ |
| 110 |
function wpbc_get_in_date_availability_hint( param_calendar_id, my_thisDateTime ) { // FixIn: 10.6.4.1. |
| 111 |
|
| 112 |
/* |
| 113 |
var sql_date = wpbc__get__sql_class_date( new Date( my_thisDateTime ) ); // '2023-08-21' |
| 114 |
var resource_id = parseInt( param_calendar_id.replace( "calendar_booking", '' ) ); // 1 |
| 115 |
var day_availability_obj = _wpbc.bookings_in_calendar__get_for_date( resource_id, sql_date ); // obj |
| 116 |
|
| 117 |
if ( 'undefined' !== typeof (day_availability_obj.day_availability) ) { |
| 118 |
return '<strong>' + day_availability_obj.day_availability + '</strong> ' + 'available'; |
| 119 |
} else { |
| 120 |
return ''; |
| 121 |
} |
| 122 |
*/ |
| 123 |
|
| 124 |
var resource_id = parseInt( param_calendar_id.replace( "calendar_booking", '' ) ); |
| 125 |
|
| 126 |
// console.log( _wpbc.bookings_in_calendar__get( resource_id ) ); // for debug |
| 127 |
|
| 128 |
// 1. Get child booking resources or single booking resource that exist in dates : [1] | [1,14,15,17] |
| 129 |
// var child_resources_arr = wpbc_clone_obj( _wpbc.booking__get_param_value( resource_id, 'resources_id_arr__in_dates' ) ); |
| 130 |
|
| 131 |
// '2023-08-21' |
| 132 |
var sql_date = wpbc__get__sql_class_date( new Date( my_thisDateTime ) ); |
| 133 |
|
| 134 |
var hint__in_day__availability = ''; |
| 135 |
|
| 136 |
var get_for_date_obj = _wpbc.bookings_in_calendar__get_for_date( resource_id, sql_date ); |
| 137 |
|
| 138 |
if ( false !== get_for_date_obj ){ |
| 139 |
|
| 140 |
if ( |
| 141 |
(undefined != get_for_date_obj[ 'summary' ]) |
| 142 |
&& (undefined != get_for_date_obj[ 'summary' ].hint__in_day__availability) |
| 143 |
){ |
| 144 |
hint__in_day__availability = get_for_date_obj[ 'summary' ].hint__in_day__availability; // "5 available" |
| 145 |
} |
| 146 |
|
| 147 |
} |
| 148 |
|
| 149 |
return hint__in_day__availability; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
/** |
| 154 |
* Hide Tippy tooltip on scroll, to prevent issue on mobile touch devices of showing tooltip at top left corner! |
| 155 |
* @param evt |
| 156 |
*/ |
| 157 |
jQuery( window ).on( 'scroll', function ( event ){ //FixIn: 9.2.1.5 // FixIn: 9.4.3.3. |
| 158 |
if ( 'function' === typeof( wpbc_tippy ) ){ |
| 159 |
wpbc_tippy.hideAll(); |
| 160 |
} |
| 161 |
} ); |
| 162 |
|
| 163 |
|
| 164 |
/** |
| 165 |
* Check if in booking form exist times fields for booking for specific time-slot |
| 166 |
* @param resource_id |
| 167 |
* @param form_elements |
| 168 |
* @returns {boolean} |
| 169 |
*/ |
| 170 |
function wpbc_is_time_field_in_booking_form( resource_id, form_elements ){ // FixIn: 8.2.1.28. |
| 171 |
|
| 172 |
var count = form_elements.length; |
| 173 |
var start_time = false; |
| 174 |
var end_time = false; |
| 175 |
var duration = false; |
| 176 |
var element; |
| 177 |
|
| 178 |
/** |
| 179 |
* Get from booking form 'rangetime', 'durationtime', 'starttime', 'endtime', if exists. |
| 180 |
*/ |
| 181 |
for ( var i = 0; i < count; i++ ){ |
| 182 |
|
| 183 |
element = form_elements[ i ]; |
| 184 |
|
| 185 |
// Skip elements from garbage |
| 186 |
if ( jQuery( element ).closest( '.booking_form_garbage' ).length ){ // FixIn: 7.1.2.14. |
| 187 |
continue; |
| 188 |
} |
| 189 |
|
| 190 |
if ( |
| 191 |
( element.name != undefined ) |
| 192 |
&& ( element.name.indexOf( 'hint' ) !== -1 ) // FixIn: 9.5.5.2. |
| 193 |
){ |
| 194 |
var my_element = element.name; //.toString(); |
| 195 |
if ( my_element.indexOf( 'rangetime' ) !== -1 ){ // Range Time |
| 196 |
|
| 197 |
return true; |
| 198 |
} |
| 199 |
if ( (my_element.indexOf( 'durationtime' ) !== -1) ){ // Duration |
| 200 |
duration = element.value; |
| 201 |
} |
| 202 |
if ( my_element.indexOf( 'starttime' ) !== -1 ){ // Start Time |
| 203 |
start_time = element.value; |
| 204 |
} |
| 205 |
if ( my_element.indexOf( 'endtime' ) !== -1 ){ // End Time |
| 206 |
end_time = element.value; |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
// Duration get Values |
| 212 |
if ( ( duration !== false ) && ( start_time !== false ) ){ // we have Duration and Start time |
| 213 |
return true; |
| 214 |
} |
| 215 |
|
| 216 |
if ( ( start_time !== false ) && ( end_time !== false ) ){ // we have End time and Start time |
| 217 |
return true; |
| 218 |
} |
| 219 |
|
| 220 |
return false; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 225 |
//TODO: Continue Refactoring here 2018-04-21 |
| 226 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 227 |
|
| 228 |
|
| 229 |
//PS: This function from ../booking/inc/js/personal.js |
| 230 |
function wpbc_is_this_time_selection_not_available( resource_id, form_elements ){ |
| 231 |
|
| 232 |
// Skip this checking if we are in the Admin panel at Add booking page |
| 233 |
if ( location.href.indexOf( 'page=wpbc-new' ) > 0 ) { |
| 234 |
return false; |
| 235 |
} |
| 236 |
|
| 237 |
var count = form_elements.length; |
| 238 |
var start_time = false; |
| 239 |
var end_time = false; |
| 240 |
var duration = false; |
| 241 |
var element; |
| 242 |
var element_start = false; |
| 243 |
var element_end = false; |
| 244 |
var element_duration = false; |
| 245 |
var element_rangetime = false; |
| 246 |
|
| 247 |
/** |
| 248 |
* Get from booking form 'rangetime', 'durationtime', 'starttime', 'endtime', if exists. |
| 249 |
*/ |
| 250 |
for ( var i = 0; i < count; i++ ){ |
| 251 |
|
| 252 |
element = form_elements[ i ]; |
| 253 |
|
| 254 |
// Skip elements from garbage |
| 255 |
if ( jQuery( element ).closest( '.booking_form_garbage' ).length ){ // FixIn: 7.1.2.14. |
| 256 |
continue; |
| 257 |
} |
| 258 |
|
| 259 |
if ( |
| 260 |
( element.name != undefined ) |
| 261 |
&& ( element.name.indexOf( 'hint' ) === -1 ) //FixIn: 9.5.5.2 // FixIn: 9.6.3.9. |
| 262 |
){ |
| 263 |
var my_element = element.name; //.toString(); |
| 264 |
if ( my_element.indexOf( 'rangetime' ) !== -1 ){ // Range Time |
| 265 |
if ( element.value == '' ){ //FixIn: 7.0.Beta.19 |
| 266 |
var notice_message_id = wpbc_front_end__show_message__warning( element, _wpbc.get_message( 'message_check_required' ) ); |
| 267 |
return true; |
| 268 |
} |
| 269 |
var my_rangetime = element.value.split( '-' ); |
| 270 |
if ( my_rangetime.length > 1 ){ |
| 271 |
start_time = my_rangetime[ 0 ].replace( /(^\s+)|(\s+$)/g, "" ); // Trim |
| 272 |
end_time = my_rangetime[ 1 ].replace( /(^\s+)|(\s+$)/g, "" ); |
| 273 |
element_rangetime = element; |
| 274 |
} |
| 275 |
} |
| 276 |
if ( (my_element.indexOf( 'durationtime' ) !== -1) ){ // Duration |
| 277 |
duration = element.value; |
| 278 |
element_duration = element; |
| 279 |
} |
| 280 |
if ( my_element.indexOf( 'starttime' ) !== -1 ){ // Start Time |
| 281 |
start_time = element.value; |
| 282 |
element_start = element; |
| 283 |
} |
| 284 |
if ( my_element.indexOf( 'endtime' ) !== -1 ){ // End Time |
| 285 |
end_time = element.value; |
| 286 |
element_end = element; |
| 287 |
} |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
// Duration get Values |
| 293 |
if ( (duration !== false) && (start_time !== false) ){ // we have Duration and Start time so try to get End time |
| 294 |
|
| 295 |
var mylocalstarttime = start_time.split( ':' ); |
| 296 |
var d = new Date( 1980, 1, 1, mylocalstarttime[ 0 ], mylocalstarttime[ 1 ], 0 ); |
| 297 |
|
| 298 |
var my_duration = duration.split( ':' ); |
| 299 |
my_duration = my_duration[ 0 ] * 60 * 60 * 1000 + my_duration[ 1 ] * 60 * 1000; |
| 300 |
d.setTime( d.getTime() + my_duration ); |
| 301 |
|
| 302 |
var my_hours = d.getHours(); |
| 303 |
if ( my_hours < 10 ) my_hours = '0' + (my_hours + ''); |
| 304 |
var my_minutes = d.getMinutes(); |
| 305 |
if ( my_minutes < 10 ) my_minutes = '0' + (my_minutes + ''); |
| 306 |
|
| 307 |
// We are get end time |
| 308 |
end_time = (my_hours + '') + ':' + (my_minutes + ''); |
| 309 |
if ( end_time == '00:00' ) end_time = '23:59'; |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
if ( (start_time === false) || (end_time === false) ){ // We do not have Start or End time or Both of them, so do not check it |
| 314 |
|
| 315 |
return false; |
| 316 |
|
| 317 |
} else { |
| 318 |
|
| 319 |
var valid_time = true; |
| 320 |
if ( (start_time == '') || (end_time == '') ) valid_time = false; |
| 321 |
|
| 322 |
if ( !isValidTimeTextField( start_time ) ) valid_time = false; |
| 323 |
if ( !isValidTimeTextField( end_time ) ) valid_time = false; |
| 324 |
|
| 325 |
if ( valid_time === true ) |
| 326 |
if ( |
| 327 |
(typeof(checkRecurentTimeInside) == 'function') && |
| 328 |
|
| 329 |
( _wpbc.get_other_param( 'is_enabled_booking_recurrent_time' ) == true ) |
| 330 |
){ // Recheck Time here !!! |
| 331 |
valid_time = checkRecurentTimeInside( [ start_time, end_time ], resource_id ); |
| 332 |
} else { |
| 333 |
|
| 334 |
if ( typeof(checkTimeInside) == 'function' ){ |
| 335 |
valid_time = checkTimeInside( start_time, true, resource_id ); |
| 336 |
} |
| 337 |
|
| 338 |
if ( valid_time === true ){ |
| 339 |
if ( typeof(checkTimeInside) == 'function' ){ |
| 340 |
valid_time = checkTimeInside( end_time, false, resource_id ); |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
if ( valid_time !== true ){ |
| 346 |
//return false; // do not show warning for setting pending days selectable, if making booking for time-slot // FixIn: 7.0.1.23. |
| 347 |
if ( (_wpbc.get_other_param( 'is_enabled_change_over' )) && (element_start !== false) && (element_end !== false) ){ // FixIn: 6.1.1.1. |
| 348 |
wpbc_front_end__show_message__warning_under_element( '#date_booking' + resource_id, _wpbc.get_message( 'message_check_no_selected_dates' ) ); |
| 349 |
} |
| 350 |
if ( element_rangetime !== false ){ wpbc_front_end__show_message__warning_under_element( element_rangetime, _wpbc.get_message( 'message_error_range_time' ) ); } |
| 351 |
if ( element_duration !== false ){ wpbc_front_end__show_message__warning_under_element( element_duration, _wpbc.get_message( 'message_error_duration_time' ) ); } |
| 352 |
if ( element_start !== false ){ wpbc_front_end__show_message__warning_under_element( element_start, _wpbc.get_message( 'message_error_start_time' ) ); } |
| 353 |
if ( element_end !== false ){ wpbc_front_end__show_message__warning_under_element( element_end, _wpbc.get_message( 'message_error_end_time' ) ); } |
| 354 |
|
| 355 |
return true; |
| 356 |
|
| 357 |
} else { |
| 358 |
return false; |
| 359 |
} |
| 360 |
|
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
function isTimeTodayGone( myTime, sort_date_array ){ |
| 368 |
var date_to_check = sort_date_array[ 0 ]; |
| 369 |
if ( parseInt( date_to_check[0] ) < parseInt( _wpbc.get_other_param( 'today_arr' )[0] ) ) { |
| 370 |
return true; |
| 371 |
} |
| 372 |
if ( |
| 373 |
(parseInt( date_to_check[0] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[0] )) && |
| 374 |
(parseInt( date_to_check[1] ) < parseInt( _wpbc.get_other_param( 'today_arr' )[1] )) |
| 375 |
){ |
| 376 |
return true; |
| 377 |
} |
| 378 |
if ( |
| 379 |
(parseInt( date_to_check[0] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[0] )) && |
| 380 |
(parseInt( date_to_check[1] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[1] )) && |
| 381 |
(parseInt( date_to_check[2] ) < parseInt( _wpbc.get_other_param( 'today_arr' )[2] )) |
| 382 |
) { |
| 383 |
return true; |
| 384 |
} |
| 385 |
if ( |
| 386 |
(parseInt( date_to_check[0] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[0] )) && |
| 387 |
(parseInt( date_to_check[1] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[1] )) && |
| 388 |
(parseInt( date_to_check[2] ) == parseInt( _wpbc.get_other_param( 'today_arr' )[2] )) |
| 389 |
) { |
| 390 |
var mytime_value = myTime.split( ":" ); |
| 391 |
mytime_value = parseInt( mytime_value[0] ) * 60 + parseInt( mytime_value[1] ); |
| 392 |
|
| 393 |
var current_time_value = parseInt( _wpbc.get_other_param( 'today_arr' )[3] ) * 60 + parseInt( _wpbc.get_other_param( 'today_arr' )[4] ); |
| 394 |
|
| 395 |
if ( current_time_value > mytime_value ) { |
| 396 |
return true; |
| 397 |
} |
| 398 |
} |
| 399 |
return false; |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
function checkTimeInside( mytime, is_start_time, bk_type ){ |
| 404 |
|
| 405 |
var my_dates_str = document.getElementById( 'date_booking' + bk_type ).value; // GET DATES From TEXTAREA |
| 406 |
|
| 407 |
if ( my_dates_str.indexOf( ' - ' ) != 0 ){ |
| 408 |
|
| 409 |
my_dates_str = my_dates_str.replace( ' - ', ', ' ); // FixIn: 10.2.3.2. |
| 410 |
} |
| 411 |
|
| 412 |
return checkTimeInsideProcess( mytime, is_start_time, bk_type, my_dates_str ); |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
function checkRecurentTimeInside( my_rangetime, bk_type ){ |
| 417 |
|
| 418 |
var valid_time = true; |
| 419 |
var my_dates_str = document.getElementById( 'date_booking' + bk_type ).value; // GET DATES From TEXTAREA |
| 420 |
// recurrent time check for all days in loop |
| 421 |
|
| 422 |
var date_array = my_dates_str.split( ", " ); |
| 423 |
if ( date_array.length == 2 ){ // This recheck is need for editing booking, with single day |
| 424 |
if ( date_array[ 0 ] == date_array[ 1 ] ){ |
| 425 |
date_array = [ date_array[ 0 ] ]; |
| 426 |
} |
| 427 |
} |
| 428 |
var temp_date_str = ''; |
| 429 |
for ( var i = 0; i < date_array.length; i++ ){ // Get SORTED selected days array |
| 430 |
temp_date_str = date_array[ i ]; |
| 431 |
if ( checkTimeInsideProcess( my_rangetime[ 0 ], true, bk_type, temp_date_str ) == false ) valid_time = false; |
| 432 |
if ( checkTimeInsideProcess( my_rangetime[ 1 ], false, bk_type, temp_date_str ) == false ) valid_time = false; |
| 433 |
|
| 434 |
} |
| 435 |
|
| 436 |
return valid_time; |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
// Function check start and end time at selected days |
| 441 |
function checkTimeInsideProcess( mytime, is_start_time, bk_type, my_dates_str ){ |
| 442 |
var i, h, s, m; // FixIn: 9.1.5.1. |
| 443 |
|
| 444 |
var date_array = my_dates_str.split( ", " ); |
| 445 |
if ( date_array.length == 2 ){ // This recheck is need for editing booking, with single day |
| 446 |
if ( date_array[ 0 ] == date_array[ 1 ] ){ |
| 447 |
date_array = [ date_array[ 0 ] ]; |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
var temp_elemnt; |
| 452 |
var td_class; |
| 453 |
var sort_date_array = []; |
| 454 |
var work_date_array = []; |
| 455 |
var times_array = []; |
| 456 |
var is_check_for_time; |
| 457 |
|
| 458 |
for ( var i = 0; i < date_array.length; i++ ){ // Get SORTED selected days array |
| 459 |
temp_elemnt = date_array[ i ].split( "." ); |
| 460 |
sort_date_array[ i ] = [ temp_elemnt[ 2 ], temp_elemnt[ 1 ] + '', temp_elemnt[ 0 ] + '' ]; // [2009,7,1],... |
| 461 |
} |
| 462 |
sort_date_array.sort(); // SORT D a t e s |
| 463 |
for ( i = 0; i < sort_date_array.length; i++ ){ // trnasform to integers |
| 464 |
sort_date_array[ i ] = [ parseInt( sort_date_array[ i ][ 0 ] * 1 ), parseInt( sort_date_array[ i ][ 1 ] * 1 ), parseInt( sort_date_array[ i ][ 2 ] * 1 ) ]; // [2009,7,1],... |
| 465 |
} |
| 466 |
|
| 467 |
if ( is_start_time ) { |
| 468 |
if ( isTimeTodayGone( mytime, sort_date_array ) ) { |
| 469 |
return false; |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
// CHECK FOR BOOKING INSIDE OF S E L E C T E D DAY RANGE AND FOR TOTALLY BOOKED DAYS AT THE START AND END OF RANGE |
| 474 |
work_date_array = sort_date_array; |
| 475 |
for ( var j = 0; j < work_date_array.length; j++ ){ |
| 476 |
td_class = work_date_array[ j ][ 1 ] + '-' + work_date_array[ j ][ 2 ] + '-' + work_date_array[ j ][ 0 ]; |
| 477 |
|
| 478 |
if ( (j == 0) || (j == (work_date_array.length - 1)) ) is_check_for_time = true; // Check for time only start and end time |
| 479 |
else is_check_for_time = false; |
| 480 |
|
| 481 |
|
| 482 |
} /////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 483 |
|
| 484 |
|
| 485 |
// Check START OR END time for time no in correct fee range |
| 486 |
if ( is_start_time ) work_date_array = sort_date_array[ 0 ]; |
| 487 |
else work_date_array = sort_date_array[ sort_date_array.length - 1 ]; |
| 488 |
|
| 489 |
td_class = work_date_array[ 1 ] + '-' + work_date_array[ 2 ] + '-' + work_date_array[ 0 ]; |
| 490 |
|
| 491 |
// Get dates and time from pending dates |
| 492 |
//deleted |
| 493 |
// Get dates and time from pending dates |
| 494 |
//deleted |
| 495 |
|
| 496 |
|
| 497 |
times_array.sort(); // SORT TIMES |
| 498 |
|
| 499 |
var times_in_day = []; // array with all times |
| 500 |
var times_in_day_interval_marks = []; // array with time interval marks 1- stsrt time 2 - end time |
| 501 |
|
| 502 |
|
| 503 |
for ( i = 0; i < times_array.length; i++ ){ |
| 504 |
s = times_array[ i ][ 2 ]; // s = 2 - end time, s = 1 - start time |
| 505 |
// Start close interval |
| 506 |
if ( (s == 2) && (i == 0) ){ |
| 507 |
times_in_day[ times_in_day.length ] = 0; |
| 508 |
times_in_day_interval_marks[ times_in_day_interval_marks.length ] = 1; |
| 509 |
} |
| 510 |
// Normal |
| 511 |
times_in_day[ times_in_day.length ] = times_array[ i ][ 0 ] * 60 + parseInt( times_array[ i ][ 1 ] ); |
| 512 |
times_in_day_interval_marks[ times_in_day_interval_marks.length ] = s; |
| 513 |
// End close interval |
| 514 |
if ( (s == 1) && (i == (times_array.length - 1)) ){ |
| 515 |
times_in_day[ times_in_day.length ] = (24 * 60); |
| 516 |
times_in_day_interval_marks[ times_in_day_interval_marks.length ] = 2; |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
// Get time from entered time |
| 521 |
var mytime_value = mytime.split( ":" ); |
| 522 |
mytime_value = mytime_value[ 0 ] * 60 + parseInt( mytime_value[ 1 ] ); |
| 523 |
|
| 524 |
//alert('My time:'+ mytime_value + ' List of times: '+ times_in_day + ' Saved indexes: ' + start_time_checking_index + ' Days: ' + sort_date_array ) ; |
| 525 |
|
| 526 |
var start_i = 0; |
| 527 |
if ( start_time_checking_index != undefined ) |
| 528 |
if ( start_time_checking_index[ 0 ] != undefined ) |
| 529 |
if ( (!is_start_time) && (sort_date_array.length == 1) ){ |
| 530 |
start_i = start_time_checking_index[ 0 ]; |
| 531 |
/*start_i++;*/ |
| 532 |
} |
| 533 |
i = start_i; |
| 534 |
|
| 535 |
// Main checking inside a day |
| 536 |
for ( i = start_i; i < times_in_day.length; i++ ){ |
| 537 |
times_in_day[ i ] = parseInt( times_in_day[ i ] ); |
| 538 |
mytime_value = parseInt( mytime_value ); |
| 539 |
if ( is_start_time ){ |
| 540 |
if ( mytime_value > times_in_day[ i ] ){ |
| 541 |
// Its Ok, lets Loop to next item |
| 542 |
} else if ( mytime_value == times_in_day[ i ] ){ |
| 543 |
if ( times_in_day_interval_marks[ i ] == 1 ){ |
| 544 |
return false; //start time is begin with some other interval |
| 545 |
} else { |
| 546 |
if ( (i + 1) <= (times_in_day.length - 1) ){ |
| 547 |
if ( times_in_day[ i + 1 ] <= mytime_value ) return false; //start time is begin with next elemnt interval |
| 548 |
else { // start time from end of some other |
| 549 |
if ( sort_date_array.length > 1 ) |
| 550 |
if ( (i + 1) <= (times_in_day.length - 1) ) return false; // Its mean that we make end booking at some other day then this and we have some booking time at this day after start booking - its wrong |
| 551 |
start_time_checking_index = [ i, td_class, mytime_value ]; |
| 552 |
return true; |
| 553 |
} |
| 554 |
} |
| 555 |
if ( sort_date_array.length > 1 ) |
| 556 |
if ( (i + 1) <= (times_in_day.length - 1) ) return false; // Its mean that we make end booking at some other day then this and we have some booking time at this day after start booking - its wrong |
| 557 |
start_time_checking_index = [ i, td_class, mytime_value ]; |
| 558 |
return true; // start time from end of some other |
| 559 |
} |
| 560 |
} else if ( mytime_value < times_in_day[ i ] ){ |
| 561 |
if ( times_in_day_interval_marks[ i ] == 2 ){ |
| 562 |
return false; // start time inside of some interval |
| 563 |
} else { |
| 564 |
if ( sort_date_array.length > 1 ) |
| 565 |
if ( (i + 1) <= (times_in_day.length - 1) ) return false; // Its mean that we make end booking at some other day then this and we have some booking time at this day after start booking - its wrong |
| 566 |
start_time_checking_index = [ i, td_class, mytime_value ]; |
| 567 |
return true; |
| 568 |
} |
| 569 |
} |
| 570 |
} else { |
| 571 |
if ( sort_date_array.length == 1 ){ |
| 572 |
|
| 573 |
if ( start_time_checking_index != undefined ) |
| 574 |
if ( start_time_checking_index[ 2 ] != undefined ) |
| 575 |
|
| 576 |
if ( (start_time_checking_index[ 2 ] == times_in_day[ i ]) && (times_in_day_interval_marks[ i ] == 2) ){ // Good, because start time = end of some other interval and we need to get next interval for current end time. |
| 577 |
} else if ( times_in_day[ i ] < mytime_value ) return false; // some interval begins before end of curent "end time" |
| 578 |
else { |
| 579 |
if ( start_time_checking_index[ 2 ] >= mytime_value ) return false; // we are select only one day and end time is earlythe starttime its wrong |
| 580 |
return true; // if we selected only one day so evrything is fine and end time no inside some other intervals |
| 581 |
} |
| 582 |
} else { |
| 583 |
if ( times_in_day[ i ] < mytime_value ) return false; // Some other interval start before we make end time in the booking at the end day selection |
| 584 |
else return true; |
| 585 |
} |
| 586 |
|
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
if ( is_start_time ) start_time_checking_index = [ i, td_class, mytime_value ]; |
| 591 |
else { |
| 592 |
if ( start_time_checking_index != undefined ) |
| 593 |
if ( start_time_checking_index[ 2 ] != undefined ) |
| 594 |
if ( (sort_date_array.length == 1) && (start_time_checking_index[ 2 ] >= mytime_value) ) return false; // we are select only one day and end time is earlythe starttime its wrong |
| 595 |
} |
| 596 |
return true; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
//PS: This function from ../booking/inc/js/personal.js |
| 601 |
function isValidTimeTextField( timeStr ){ |
| 602 |
// Checks if time is in HH:MM AM/PM format. |
| 603 |
// The seconds and AM/PM are optional. |
| 604 |
|
| 605 |
var timePat = /^(\d{1,2}):(\d{2})(\s?(AM|am|PM|pm))?$/; |
| 606 |
|
| 607 |
var matchArray = timeStr.match( timePat ); |
| 608 |
if ( matchArray == null ){ |
| 609 |
return false; //("<?php esc_html_e('Time is not in a valid format. Use this format HH:MM or HH:MM AM/PM'); ?>"); |
| 610 |
} |
| 611 |
var hour = matchArray[ 1 ]; |
| 612 |
var minute = matchArray[ 2 ]; |
| 613 |
var ampm = matchArray[ 4 ]; |
| 614 |
|
| 615 |
if ( ampm == "" ){ |
| 616 |
ampm = null |
| 617 |
} |
| 618 |
|
| 619 |
if ( hour < 0 || hour > 24 ){ // FixIn: 8.3.1.1. |
| 620 |
return false; //("<?php esc_html_e('Hour must be between 1 and 12. (or 0 and 23 for military time)'); ?>"); |
| 621 |
} |
| 622 |
if ( hour > 12 && ampm != null ){ |
| 623 |
return false; //("<?php esc_html_e('You can not specify AM or PM for military time.'); ?>"); |
| 624 |
} |
| 625 |
if ( minute < 0 || minute > 59 ){ |
| 626 |
return false; //("<?php esc_html_e('Minute must be between 0 and 59.'); ?>"); |
| 627 |
} |
| 628 |
return true; |
| 629 |
} |
| 630 |
|