Changeset 3335386
- Timestamp:
- 07/28/2025 01:05:22 PM (7 months ago)
- Location:
- syncbooking
- Files:
-
- 8 edited
-
tags/1.16.0/php/bar-sync/form.php (modified) (1 diff)
-
tags/1.16.0/php/theme-sync/page/website/include/js/js_calendar.js (modified) (2 diffs)
-
tags/1.16.0/php/theme-sync/page/website/search.php (modified) (1 diff)
-
tags/1.16.0/sync-booking.php (modified) (2 diffs)
-
trunk/php/bar-sync/form.php (modified) (1 diff)
-
trunk/php/theme-sync/page/website/include/js/js_calendar.js (modified) (2 diffs)
-
trunk/php/theme-sync/page/website/search.php (modified) (1 diff)
-
trunk/sync-booking.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
syncbooking/tags/1.16.0/php/bar-sync/form.php
r3315509 r3335386 68 68 </div> 69 69 <div class="syncbooking_fields_standard_1"> 70 <div class="syncbooking_fieldtitle"> Houses</div><select id="syncbooking_houses" name="syncbooking_houses" data-name="syncbooking_houses" required="" class="syncbooking_select w-node-fb710099-db7c-2639-34c4-66414496ad51-32c5e373 w-select">70 <div class="syncbooking_fieldtitle">Rooms</div><select id="syncbooking_houses" name="syncbooking_houses" data-name="syncbooking_houses" required="" class="syncbooking_select w-node-fb710099-db7c-2639-34c4-66414496ad51-32c5e373 w-select"> 71 71 <option value="1">1</option> 72 72 <option value="2">2</option> -
syncbooking/tags/1.16.0/php/theme-sync/page/website/include/js/js_calendar.js
r3315509 r3335386 163 163 let lastCheckIn = null; // ms del click precedente (per doppio-clic) 164 164 165 /* -------------------------------------165 /* ------------------------------------- 166 166 Inizializza flatpickr 167 167 ------------------------------------- */ 168 const fp = flatpickr(calendarInput, { 169 mode: "range", 170 dateFormat: "d/m/y", 171 minDate: new Date().fp_incr(1), 172 clickOpens: false, // lo apriamo manualmente noi 173 174 /* 1. carica tutte le notti già piene (una sola volta) ---------- */ 175 async onReady(_, __, inst) { 176 const year = new Date().getFullYear(); 177 const body = `accommodation=${structureId}&unavailable_year=${year}`; 168 const fp = flatpickr(calendarInput, { 169 mode: "range", 170 dateFormat: "d/m/y", 171 minDate: new Date().fp_incr(1), 172 clickOpens: false, 173 174 async onReady(_, __, inst) { 175 const year = new Date().getFullYear(); 176 const body = `accommodation=${structureId}&unavailable_year=${year}`; 177 178 try { 179 const res = await fetch(API_URL, { 180 method: "POST", 181 headers: formHdr, 182 body, 183 }); 184 const json = await res.json(); 185 186 console.log("📦 Risposta PHP (unavailable_days):", json); 187 188 if ( 189 json.status !== "unavailable_days" || 190 !Array.isArray(json.unavailable_days) 191 ) { 192 console.warn("⚠️ unavailable_days malformato."); 193 return; 194 } 195 196 globalDisabled = json.unavailable_days.map(toLocalMidnight); 197 inst.set("disable", globalDisabled); 198 console.log(`🚫 Disabilitate ${globalDisabled.length} notti`); 199 } catch (err) { 200 console.error("⛔ fetch unavailable_year FAILED:", err); 201 } 202 }, 203 204 onOpen(_, __, inst) { 205 inst.clear(); 206 inst.set("maxDate", null); 207 inst.set("disable", globalDisabled); 208 lastCheckIn = null; 209 }, 210 211 async onChange(selected, dateStr, inst) { 212 if (selected.length === 0) { 213 calendarInput.value = ""; 214 calendarInput.placeholder = DEFAULT_PH; 215 if (rangeDatesInput) { 216 rangeDatesInput.value = ""; 217 rangeDatesInput.placeholder = DEFAULT_PH; 218 } 219 inst.set("maxDate", null); 220 inst.set("disable", globalDisabled); 221 lastCheckIn = null; 222 return; 223 } 224 225 if (selected.length === 2) { 226 if (selected[0].getTime() === selected[1].getTime()) { 227 inst.clear(); 228 inst.set("maxDate", null); 229 inst.set("disable", globalDisabled); 230 calendarInput.value = ""; 231 calendarInput.placeholder = DEFAULT_PH; 232 if (rangeDatesInput) { 233 rangeDatesInput.value = ""; 234 rangeDatesInput.placeholder = DEFAULT_PH; 235 } 236 lastCheckIn = null; 237 return; 238 } 239 calendarInput.value = dateStr; 240 calendarInput.placeholder = dateStr; 241 if (rangeDatesInput) { 242 rangeDatesInput.value = dateStr; 243 rangeDatesInput.placeholder = dateStr; 244 } 245 lastCheckIn = null; 246 return; 247 } 248 249 if (selected.length === 1) { 250 const checkIn = selected[0]; 251 252 if (lastCheckIn && checkIn.getTime() === lastCheckIn) { 253 inst.clear(); 254 inst.set("maxDate", null); 255 inst.set("disable", globalDisabled); 256 calendarInput.value = ""; 257 calendarInput.placeholder = DEFAULT_PH; 258 if (rangeDatesInput) { 259 rangeDatesInput.value = ""; 260 rangeDatesInput.placeholder = DEFAULT_PH; 261 } 262 lastCheckIn = null; 263 console.log("🔄 Reset per doppio clic"); 264 return; 265 } 266 267 lastCheckIn = checkIn.getTime(); 268 inst.set("maxDate", null); 269 270 const unixCheck = Date.UTC( 271 checkIn.getFullYear(), 272 checkIn.getMonth(), 273 checkIn.getDate() 274 ) / 1000; 275 276 const toYMD = (d) => 277 d.getFullYear() + 278 "-" + 279 String(d.getMonth() + 1).padStart(2, "0") + 280 "-" + 281 String(d.getDate()).padStart(2, "0"); 282 283 const body = `accommodation=${structureId}&arrival_day=${unixCheck}&mode=single`; 178 284 179 285 try { … … 185 291 const json = await res.json(); 186 292 187 if ( 188 json.status !== "unavailable_days" || 189 !Array.isArray(json.unavailable_days) 190 ) { 191 console.warn("⚠️ unavailable_days malformato."); 293 console.log("📦 Risposta PHP (available_intervals):", json); 294 295 if (json.status !== "available_intervals") { 296 console.warn("⚠️ available_intervals mancante."); 192 297 return; 193 298 } 194 globalDisabled = json.unavailable_days.map(toLocalMidnight); 195 inst.set("disable", globalDisabled); 196 console.log(`🚫 Disabilitate ${globalDisabled.length} notti`); 299 300 const ymd = toYMD(checkIn); 301 let maxDt = null; 302 303 for (const roomId in json.available_intervals) { 304 for (const iv of json.available_intervals[roomId]) { 305 if (iv.start === ymd) { 306 const end = new Date(iv.end + "T00:00:00"); // checkout incluso 307 console.log(`📆 Intervallo stanza ${roomId}: ${iv.start} → ${iv.end} (max notte: ${toYMD(new Date(end.getTime() - 86400000))})`); 308 if (!maxDt || end > maxDt) { 309 maxDt = end; 310 } 311 } 312 } 313 } 314 315 if (!maxDt) { 316 console.warn("⚠️ nessun intervallo contiguo. Solo prima notte."); 317 const afterCheckIn = (d) => d > checkIn; 318 inst.set("disable", globalDisabled.concat(afterCheckIn)); 319 inst.set("maxDate", checkIn); 320 return; 321 } 322 323 const outOfRange = (d) => d < checkIn || d >= maxDt; 324 const cleanedDisabled = globalDisabled.filter( 325 (d) => d.getTime() !== maxDt.getTime() 326 ); 327 328 inst.set("disable", cleanedDisabled.concat(outOfRange)); 329 inst.set("maxDate", maxDt); 330 console.log("🟢 Range consentito:", ymd, "→", toYMD(maxDt)); 331 332 // ✅ Forza selezionabilità del giorno maxDt (checkout) 333 setTimeout(() => { 334 const cells = document.querySelectorAll(".flatpickr-day"); 335 const maxDtStr = toYMD(maxDt); 336 cells.forEach((cell) => { 337 if (cell.dateObj) { 338 const dStr = toYMD(cell.dateObj); 339 if (dStr === maxDtStr) { 340 cell.classList.remove("flatpickr-disabled"); 341 cell.removeAttribute("aria-disabled"); 342 } 343 } 344 }); 345 }, 0); 346 197 347 } catch (err) { 198 console.error("⛔ fetch unavailable_year FAILED:", err); 199 } 200 }, 201 202 /* 2. onOpen: ogni volta riparti “pulito” ----------------------- */ 203 onOpen(_, __, inst) { 204 inst.clear(); // rimuove highlight visivo 205 inst.set("maxDate", null); 206 inst.set("disable", globalDisabled); 207 lastCheckIn = null; // reset doppio-clic 208 }, 209 210 /* 3. Gestione selezione --------------------------------------- */ 211 async onChange(selected, dateStr, inst) { 212 /* --- A. Nessuna data -------------------------------------- */ 213 if (selected.length === 0) { 214 calendarInput.value = ""; 215 calendarInput.placeholder = DEFAULT_PH; 216 if (rangeDatesInput) { 217 rangeDatesInput.value = ""; 218 rangeDatesInput.placeholder = DEFAULT_PH; 219 } 220 inst.set("maxDate", null); 221 inst.set("disable", globalDisabled); 222 lastCheckIn = null; 223 return; 224 } 225 226 /* --- B. Range completo (2 date) --------------------------- */ 227 if (selected.length === 2) { 228 if (selected[0].getTime() === selected[1].getTime()) { 229 // due clic sulla stessa data → reset 230 inst.clear(); 231 inst.set("maxDate", null); 232 inst.set("disable", globalDisabled); 233 calendarInput.value = ""; 234 calendarInput.placeholder = DEFAULT_PH; 235 if (rangeDatesInput) { 236 rangeDatesInput.value = ""; 237 rangeDatesInput.placeholder = DEFAULT_PH; 238 } 239 lastCheckIn = null; 240 return; 241 } 242 // range valido → popola input 243 calendarInput.value = dateStr; 244 calendarInput.placeholder = dateStr; 245 if (rangeDatesInput) { 246 rangeDatesInput.value = dateStr; 247 rangeDatesInput.placeholder = dateStr; 248 } 249 lastCheckIn = null; 250 return; 251 } 252 253 /* --- C. Solo check-in ------------------------------------- */ 254 if (selected.length === 1) { 255 const checkIn = selected[0]; 256 257 /* doppio-clic sulla stessa data → reset ------------------ */ 258 if (lastCheckIn && checkIn.getTime() === lastCheckIn) { 259 inst.clear(); 260 inst.set("maxDate", null); 261 inst.set("disable", globalDisabled); 262 calendarInput.value = ""; 263 calendarInput.placeholder = DEFAULT_PH; 264 if (rangeDatesInput) { 265 rangeDatesInput.value = ""; 266 rangeDatesInput.placeholder = DEFAULT_PH; 267 } 268 lastCheckIn = null; 269 console.log("🔄 Reset per doppio clic"); 270 return; 271 } 272 lastCheckIn = checkIn.getTime(); // salva 273 274 /* non scrivere nulla nell’input */ 275 inst.set("maxDate", null); 276 277 /* timestamp a mezzanotte UTC */ 278 const unixCheck = 279 Date.UTC( 280 checkIn.getFullYear(), 281 checkIn.getMonth(), 282 checkIn.getDate() 283 ) / 1000; 284 285 /* helper per yyyy-mm-dd (locale) */ 286 const toYMD = (d) => 287 d.getFullYear() + 288 "-" + 289 String(d.getMonth() + 1).padStart(2, "0") + 290 "-" + 291 String(d.getDate()).padStart(2, "0"); 292 293 /* fetch intervallo consentito ----------------------------- */ 294 const body = `accommodation=${structureId}&arrival_day=${unixCheck}&mode=single`; 295 try { 296 const res = await fetch(API_URL, { 297 method: "POST", 298 headers: formHdr, 299 body, 300 }); 301 const json = await res.json(); 302 if (json.status !== "available_intervals") { 303 console.warn("⚠️ available_intervals mancante."); 304 return; 305 } 306 307 const ymd = toYMD(checkIn); 308 let maxDt = null; 309 310 Object.values(json.available_intervals).forEach((arr) => { 311 arr.forEach((iv) => { 312 if (iv.start === ymd) { 313 const end = new Date(iv.end + "T00:00:00"); 314 if (!maxDt || end > maxDt) maxDt = end; 315 } 316 }); 317 }); 318 319 /* se il PHP NON ha intervallo → consenti solo check-in ---- */ 320 if (!maxDt) { 321 console.warn("⚠️ nessun intervallo contiguo. Solo prima notte."); 322 const afterCheckIn = (d) => d > checkIn; 323 inst.set("disable", globalDisabled.concat(afterCheckIn)); 324 inst.set("maxDate", checkIn); 325 return; 326 } 327 328 /* imposta limiti normali ------------------------------- */ 329 const outOfRange = (d) => d < checkIn || d > maxDt; 330 inst.set("disable", globalDisabled.concat(outOfRange)); 331 inst.set("maxDate", maxDt); 332 console.log("🟢 Range consentito:", ymd, "→", toYMD(maxDt)); 333 } catch (err) { 334 console.error("⛔ fetch arrival_day FAILED:", err); 335 } 336 } 337 }, 338 }); 339 340 /* ------------------ apertura/chiusura manuale ------------------ */ 341 calendarInput.addEventListener("click", () => { 342 if (fp.isOpen) { 343 fp.close(); // richiude se già aperto 344 } else { 345 fp.open(); // altrimenti apre 346 } 347 }); 348 console.error("⛔ fetch arrival_day FAILED:", err); 349 } 350 } 351 }, 352 }); 353 354 355 356 /* ------------------ apertura/chiusura manuale ------------------ */ 357 calendarInput.addEventListener("click", () => { 358 if (fp.isOpen) { 359 fp.close(); 360 } else { 361 fp.open(); 362 } 363 }); 364 348 365 349 366 // ✅ Click su search -
syncbooking/tags/1.16.0/php/theme-sync/page/website/search.php
r3315509 r3335386 36 36 </div> 37 37 <div class="structure_selectdate"> 38 <div id="house_data" class="structure_date"><label class="search_field"> Houses</label>38 <div id="house_data" class="structure_date"><label class="search_field">Rooms</label> 39 39 <div><select id="house_number" name="house_number" data-name="house_number" required="" class="text_field_1 w-select"> 40 40 <option value="1">1</option> -
syncbooking/tags/1.16.0/sync-booking.php
r3315509 r3335386 4 4 Plugin URI: http://syncbooking.com/plugin 5 5 Description: Sync All Booking of your Hotel or BnB, and get new bookings!. 6 Version: 1.1 5.06 Version: 1.17.0 7 7 Author: SyncBooking.com 8 8 Author URI: http://syncbooking.com/ … … 17 17 define( 'syncbooking_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 18 18 define( 'syncbooking_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 19 define( 'syncbooking_PLUGIN_VERSION', "1.1 5.0" );19 define( 'syncbooking_PLUGIN_VERSION', "1.17.0" ); 20 20 21 21 global $syncbooking_structure_data; -
syncbooking/trunk/php/bar-sync/form.php
r3315503 r3335386 68 68 </div> 69 69 <div class="syncbooking_fields_standard_1"> 70 <div class="syncbooking_fieldtitle"> Houses</div><select id="syncbooking_houses" name="syncbooking_houses" data-name="syncbooking_houses" required="" class="syncbooking_select w-node-fb710099-db7c-2639-34c4-66414496ad51-32c5e373 w-select">70 <div class="syncbooking_fieldtitle">Rooms</div><select id="syncbooking_houses" name="syncbooking_houses" data-name="syncbooking_houses" required="" class="syncbooking_select w-node-fb710099-db7c-2639-34c4-66414496ad51-32c5e373 w-select"> 71 71 <option value="1">1</option> 72 72 <option value="2">2</option> -
syncbooking/trunk/php/theme-sync/page/website/include/js/js_calendar.js
r3315503 r3335386 163 163 let lastCheckIn = null; // ms del click precedente (per doppio-clic) 164 164 165 /* -------------------------------------165 /* ------------------------------------- 166 166 Inizializza flatpickr 167 167 ------------------------------------- */ 168 const fp = flatpickr(calendarInput, { 169 mode: "range", 170 dateFormat: "d/m/y", 171 minDate: new Date().fp_incr(1), 172 clickOpens: false, // lo apriamo manualmente noi 173 174 /* 1. carica tutte le notti già piene (una sola volta) ---------- */ 175 async onReady(_, __, inst) { 176 const year = new Date().getFullYear(); 177 const body = `accommodation=${structureId}&unavailable_year=${year}`; 168 const fp = flatpickr(calendarInput, { 169 mode: "range", 170 dateFormat: "d/m/y", 171 minDate: new Date().fp_incr(1), 172 clickOpens: false, 173 174 async onReady(_, __, inst) { 175 const year = new Date().getFullYear(); 176 const body = `accommodation=${structureId}&unavailable_year=${year}`; 177 178 try { 179 const res = await fetch(API_URL, { 180 method: "POST", 181 headers: formHdr, 182 body, 183 }); 184 const json = await res.json(); 185 186 console.log("📦 Risposta PHP (unavailable_days):", json); 187 188 if ( 189 json.status !== "unavailable_days" || 190 !Array.isArray(json.unavailable_days) 191 ) { 192 console.warn("⚠️ unavailable_days malformato."); 193 return; 194 } 195 196 globalDisabled = json.unavailable_days.map(toLocalMidnight); 197 inst.set("disable", globalDisabled); 198 console.log(`🚫 Disabilitate ${globalDisabled.length} notti`); 199 } catch (err) { 200 console.error("⛔ fetch unavailable_year FAILED:", err); 201 } 202 }, 203 204 onOpen(_, __, inst) { 205 inst.clear(); 206 inst.set("maxDate", null); 207 inst.set("disable", globalDisabled); 208 lastCheckIn = null; 209 }, 210 211 async onChange(selected, dateStr, inst) { 212 if (selected.length === 0) { 213 calendarInput.value = ""; 214 calendarInput.placeholder = DEFAULT_PH; 215 if (rangeDatesInput) { 216 rangeDatesInput.value = ""; 217 rangeDatesInput.placeholder = DEFAULT_PH; 218 } 219 inst.set("maxDate", null); 220 inst.set("disable", globalDisabled); 221 lastCheckIn = null; 222 return; 223 } 224 225 if (selected.length === 2) { 226 if (selected[0].getTime() === selected[1].getTime()) { 227 inst.clear(); 228 inst.set("maxDate", null); 229 inst.set("disable", globalDisabled); 230 calendarInput.value = ""; 231 calendarInput.placeholder = DEFAULT_PH; 232 if (rangeDatesInput) { 233 rangeDatesInput.value = ""; 234 rangeDatesInput.placeholder = DEFAULT_PH; 235 } 236 lastCheckIn = null; 237 return; 238 } 239 calendarInput.value = dateStr; 240 calendarInput.placeholder = dateStr; 241 if (rangeDatesInput) { 242 rangeDatesInput.value = dateStr; 243 rangeDatesInput.placeholder = dateStr; 244 } 245 lastCheckIn = null; 246 return; 247 } 248 249 if (selected.length === 1) { 250 const checkIn = selected[0]; 251 252 if (lastCheckIn && checkIn.getTime() === lastCheckIn) { 253 inst.clear(); 254 inst.set("maxDate", null); 255 inst.set("disable", globalDisabled); 256 calendarInput.value = ""; 257 calendarInput.placeholder = DEFAULT_PH; 258 if (rangeDatesInput) { 259 rangeDatesInput.value = ""; 260 rangeDatesInput.placeholder = DEFAULT_PH; 261 } 262 lastCheckIn = null; 263 console.log("🔄 Reset per doppio clic"); 264 return; 265 } 266 267 lastCheckIn = checkIn.getTime(); 268 inst.set("maxDate", null); 269 270 const unixCheck = Date.UTC( 271 checkIn.getFullYear(), 272 checkIn.getMonth(), 273 checkIn.getDate() 274 ) / 1000; 275 276 const toYMD = (d) => 277 d.getFullYear() + 278 "-" + 279 String(d.getMonth() + 1).padStart(2, "0") + 280 "-" + 281 String(d.getDate()).padStart(2, "0"); 282 283 const body = `accommodation=${structureId}&arrival_day=${unixCheck}&mode=single`; 178 284 179 285 try { … … 185 291 const json = await res.json(); 186 292 187 if ( 188 json.status !== "unavailable_days" || 189 !Array.isArray(json.unavailable_days) 190 ) { 191 console.warn("⚠️ unavailable_days malformato."); 293 console.log("📦 Risposta PHP (available_intervals):", json); 294 295 if (json.status !== "available_intervals") { 296 console.warn("⚠️ available_intervals mancante."); 192 297 return; 193 298 } 194 globalDisabled = json.unavailable_days.map(toLocalMidnight); 195 inst.set("disable", globalDisabled); 196 console.log(`🚫 Disabilitate ${globalDisabled.length} notti`); 299 300 const ymd = toYMD(checkIn); 301 let maxDt = null; 302 303 for (const roomId in json.available_intervals) { 304 for (const iv of json.available_intervals[roomId]) { 305 if (iv.start === ymd) { 306 const end = new Date(iv.end + "T00:00:00"); // checkout incluso 307 console.log(`📆 Intervallo stanza ${roomId}: ${iv.start} → ${iv.end} (max notte: ${toYMD(new Date(end.getTime() - 86400000))})`); 308 if (!maxDt || end > maxDt) { 309 maxDt = end; 310 } 311 } 312 } 313 } 314 315 if (!maxDt) { 316 console.warn("⚠️ nessun intervallo contiguo. Solo prima notte."); 317 const afterCheckIn = (d) => d > checkIn; 318 inst.set("disable", globalDisabled.concat(afterCheckIn)); 319 inst.set("maxDate", checkIn); 320 return; 321 } 322 323 const outOfRange = (d) => d < checkIn || d >= maxDt; 324 const cleanedDisabled = globalDisabled.filter( 325 (d) => d.getTime() !== maxDt.getTime() 326 ); 327 328 inst.set("disable", cleanedDisabled.concat(outOfRange)); 329 inst.set("maxDate", maxDt); 330 console.log("🟢 Range consentito:", ymd, "→", toYMD(maxDt)); 331 332 // ✅ Forza selezionabilità del giorno maxDt (checkout) 333 setTimeout(() => { 334 const cells = document.querySelectorAll(".flatpickr-day"); 335 const maxDtStr = toYMD(maxDt); 336 cells.forEach((cell) => { 337 if (cell.dateObj) { 338 const dStr = toYMD(cell.dateObj); 339 if (dStr === maxDtStr) { 340 cell.classList.remove("flatpickr-disabled"); 341 cell.removeAttribute("aria-disabled"); 342 } 343 } 344 }); 345 }, 0); 346 197 347 } catch (err) { 198 console.error("⛔ fetch unavailable_year FAILED:", err); 199 } 200 }, 201 202 /* 2. onOpen: ogni volta riparti “pulito” ----------------------- */ 203 onOpen(_, __, inst) { 204 inst.clear(); // rimuove highlight visivo 205 inst.set("maxDate", null); 206 inst.set("disable", globalDisabled); 207 lastCheckIn = null; // reset doppio-clic 208 }, 209 210 /* 3. Gestione selezione --------------------------------------- */ 211 async onChange(selected, dateStr, inst) { 212 /* --- A. Nessuna data -------------------------------------- */ 213 if (selected.length === 0) { 214 calendarInput.value = ""; 215 calendarInput.placeholder = DEFAULT_PH; 216 if (rangeDatesInput) { 217 rangeDatesInput.value = ""; 218 rangeDatesInput.placeholder = DEFAULT_PH; 219 } 220 inst.set("maxDate", null); 221 inst.set("disable", globalDisabled); 222 lastCheckIn = null; 223 return; 224 } 225 226 /* --- B. Range completo (2 date) --------------------------- */ 227 if (selected.length === 2) { 228 if (selected[0].getTime() === selected[1].getTime()) { 229 // due clic sulla stessa data → reset 230 inst.clear(); 231 inst.set("maxDate", null); 232 inst.set("disable", globalDisabled); 233 calendarInput.value = ""; 234 calendarInput.placeholder = DEFAULT_PH; 235 if (rangeDatesInput) { 236 rangeDatesInput.value = ""; 237 rangeDatesInput.placeholder = DEFAULT_PH; 238 } 239 lastCheckIn = null; 240 return; 241 } 242 // range valido → popola input 243 calendarInput.value = dateStr; 244 calendarInput.placeholder = dateStr; 245 if (rangeDatesInput) { 246 rangeDatesInput.value = dateStr; 247 rangeDatesInput.placeholder = dateStr; 248 } 249 lastCheckIn = null; 250 return; 251 } 252 253 /* --- C. Solo check-in ------------------------------------- */ 254 if (selected.length === 1) { 255 const checkIn = selected[0]; 256 257 /* doppio-clic sulla stessa data → reset ------------------ */ 258 if (lastCheckIn && checkIn.getTime() === lastCheckIn) { 259 inst.clear(); 260 inst.set("maxDate", null); 261 inst.set("disable", globalDisabled); 262 calendarInput.value = ""; 263 calendarInput.placeholder = DEFAULT_PH; 264 if (rangeDatesInput) { 265 rangeDatesInput.value = ""; 266 rangeDatesInput.placeholder = DEFAULT_PH; 267 } 268 lastCheckIn = null; 269 console.log("🔄 Reset per doppio clic"); 270 return; 271 } 272 lastCheckIn = checkIn.getTime(); // salva 273 274 /* non scrivere nulla nell’input */ 275 inst.set("maxDate", null); 276 277 /* timestamp a mezzanotte UTC */ 278 const unixCheck = 279 Date.UTC( 280 checkIn.getFullYear(), 281 checkIn.getMonth(), 282 checkIn.getDate() 283 ) / 1000; 284 285 /* helper per yyyy-mm-dd (locale) */ 286 const toYMD = (d) => 287 d.getFullYear() + 288 "-" + 289 String(d.getMonth() + 1).padStart(2, "0") + 290 "-" + 291 String(d.getDate()).padStart(2, "0"); 292 293 /* fetch intervallo consentito ----------------------------- */ 294 const body = `accommodation=${structureId}&arrival_day=${unixCheck}&mode=single`; 295 try { 296 const res = await fetch(API_URL, { 297 method: "POST", 298 headers: formHdr, 299 body, 300 }); 301 const json = await res.json(); 302 if (json.status !== "available_intervals") { 303 console.warn("⚠️ available_intervals mancante."); 304 return; 305 } 306 307 const ymd = toYMD(checkIn); 308 let maxDt = null; 309 310 Object.values(json.available_intervals).forEach((arr) => { 311 arr.forEach((iv) => { 312 if (iv.start === ymd) { 313 const end = new Date(iv.end + "T00:00:00"); 314 if (!maxDt || end > maxDt) maxDt = end; 315 } 316 }); 317 }); 318 319 /* se il PHP NON ha intervallo → consenti solo check-in ---- */ 320 if (!maxDt) { 321 console.warn("⚠️ nessun intervallo contiguo. Solo prima notte."); 322 const afterCheckIn = (d) => d > checkIn; 323 inst.set("disable", globalDisabled.concat(afterCheckIn)); 324 inst.set("maxDate", checkIn); 325 return; 326 } 327 328 /* imposta limiti normali ------------------------------- */ 329 const outOfRange = (d) => d < checkIn || d > maxDt; 330 inst.set("disable", globalDisabled.concat(outOfRange)); 331 inst.set("maxDate", maxDt); 332 console.log("🟢 Range consentito:", ymd, "→", toYMD(maxDt)); 333 } catch (err) { 334 console.error("⛔ fetch arrival_day FAILED:", err); 335 } 336 } 337 }, 338 }); 339 340 /* ------------------ apertura/chiusura manuale ------------------ */ 341 calendarInput.addEventListener("click", () => { 342 if (fp.isOpen) { 343 fp.close(); // richiude se già aperto 344 } else { 345 fp.open(); // altrimenti apre 346 } 347 }); 348 console.error("⛔ fetch arrival_day FAILED:", err); 349 } 350 } 351 }, 352 }); 353 354 355 356 /* ------------------ apertura/chiusura manuale ------------------ */ 357 calendarInput.addEventListener("click", () => { 358 if (fp.isOpen) { 359 fp.close(); 360 } else { 361 fp.open(); 362 } 363 }); 364 348 365 349 366 // ✅ Click su search -
syncbooking/trunk/php/theme-sync/page/website/search.php
r3315503 r3335386 36 36 </div> 37 37 <div class="structure_selectdate"> 38 <div id="house_data" class="structure_date"><label class="search_field"> Houses</label>38 <div id="house_data" class="structure_date"><label class="search_field">Rooms</label> 39 39 <div><select id="house_number" name="house_number" data-name="house_number" required="" class="text_field_1 w-select"> 40 40 <option value="1">1</option> -
syncbooking/trunk/sync-booking.php
r3315503 r3335386 4 4 Plugin URI: http://syncbooking.com/plugin 5 5 Description: Sync All Booking of your Hotel or BnB, and get new bookings!. 6 Version: 1.1 5.06 Version: 1.17.0 7 7 Author: SyncBooking.com 8 8 Author URI: http://syncbooking.com/ … … 17 17 define( 'syncbooking_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 18 18 define( 'syncbooking_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 19 define( 'syncbooking_PLUGIN_VERSION', "1.1 5.0" );19 define( 'syncbooking_PLUGIN_VERSION', "1.17.0" ); 20 20 21 21 global $syncbooking_structure_data;
Note: See TracChangeset
for help on using the changeset viewer.