first commit

This commit is contained in:
Roman Pyrih
2026-04-21 15:48:41 +02:00
commit 7483681901
10216 changed files with 3236626 additions and 0 deletions

View File

@@ -0,0 +1,648 @@
/**
* Yacht Booking Calendar Styles
*
* @package YachtBooking
*/
/* Calendar Wrapper */
.yacht-calendar-wrapper {
max-width: 1200px;
margin: 0 auto 40px;
padding: 20px;
}
.yacht-calendar-switcher {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px 14px;
margin: 0 0 22px 0;
padding: 14px 16px;
background: #f7f9fc;
border: 1px solid #dbe5f0;
border-radius: 10px;
}
.yacht-calendar-switcher-label {
font-size: 14px;
font-weight: 700;
color: #021526;
}
.yacht-calendar-switcher-buttons {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.yacht-calendar-switcher-button {
display: inline-flex;
align-items: center;
padding: 9px 14px;
border: 1px solid #c8d4e3;
border-radius: 999px;
background: #fff;
color: #14324a;
font-size: 14px;
font-weight: 600;
line-height: 1.2;
cursor: pointer;
transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.yacht-calendar-switcher-button:hover,
.yacht-calendar-switcher-button:focus {
border-color: #bc1834;
color: #bc1834;
outline: none;
transform: translateY(-1px);
}
.yacht-calendar-switcher-button.is-active {
background: #bc1834;
border-color: #bc1834;
color: #fff;
box-shadow: 0 8px 18px rgba(188, 24, 52, 0.18);
}
/* Calendar Header */
.yacht-calendar-header {
margin-bottom: 30px;
}
.yacht-calendar-title {
font-size: 28px;
font-weight: 700;
color: #021526;
margin: 0 0 15px 0;
}
.yacht-calendar-description {
color: #666;
font-size: 16px;
line-height: 1.6;
}
.yacht-calendar-instructions {
margin: 0 0 12px 0;
padding: 12px 14px;
background: #eef6ff;
border: 1px solid #d1e4ff;
border-left: 4px solid #1565c0;
border-radius: 6px;
color: #0f2742;
font-size: 14px;
line-height: 1.55;
}
.yacht-calendar-instructions p {
margin: 0;
}
.yacht-calendar-legend {
display: flex;
flex-wrap: wrap;
gap: 10px 16px;
align-items: center;
margin: 0 0 18px 0;
}
.yacht-legend-item {
display: inline-flex;
align-items: center;
gap: 8px;
font-size: 14px;
font-weight: 600;
color: #1f2937;
}
.yacht-legend-swatch {
width: 16px;
height: 16px;
border-radius: 4px;
border: 1px solid rgba(0, 0, 0, 0.2);
}
.yacht-legend-swatch-past {
background: #d0d5dd;
}
/* Calendar Container */
.yacht-calendar {
margin-bottom: 30px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
padding: 20px;
}
/* FullCalendar overrides */
.yacht-calendar .fc {
font-family: inherit;
}
.yacht-calendar .fc-button-primary {
background: #bc1834;
border-color: #bc1834;
text-transform: uppercase;
font-weight: 600;
font-size: 13px;
padding: 8px 16px;
}
.yacht-calendar .fc-button-primary:hover {
background: #021526;
border-color: #021526;
}
.yacht-calendar .fc-button-primary:not(:disabled):active,
.yacht-calendar .fc-button-primary:not(:disabled).fc-button-active {
background: #021526;
border-color: #021526;
}
.yacht-calendar .fc-daygrid-day.fc-day-past {
background: #f5f5f5;
opacity: 0.6;
}
.yacht-calendar .fc-daygrid-day.fc-day-past .fc-daygrid-day-number {
color: #999;
}
.yacht-calendar .fc-daygrid-day:hover {
background: #f8f9fa;
}
.yacht-calendar .fc-highlight {
background: rgba(188, 24, 52, 0.1) !important;
}
/* Day numbers - prevent truncation */
.yacht-calendar .fc-daygrid-day-top {
display: flex;
justify-content: center;
align-items: center;
padding: 5px;
}
.yacht-calendar .fc-daygrid-day-number {
padding: 4px 6px;
min-width: 28px;
text-align: center;
display: inline-block;
font-size: 14px;
line-height: 1.2;
}
.yacht-calendar .fc-daygrid-day-frame {
min-height: 80px;
display: flex;
flex-direction: column;
position: relative;
}
/* Custom day status classes */
.yacht-day-available {
cursor: pointer;
}
.yacht-day-booked,
.yacht-day-blocked {
cursor: not-allowed;
}
.yacht-calendar .fc-bg-event {
opacity: 0.78 !important;
}
.yacht-calendar .fc-bg-event.yacht-day-available {
opacity: 0.66 !important;
}
.yacht-calendar .fc-bg-event.yacht-day-booked,
.yacht-calendar .fc-bg-event.yacht-day-blocked {
opacity: 0.92 !important;
}
/* Booking Form Styles */
.yacht-booking-form-container {
background: #f9f9f9;
padding: 30px;
border-radius: 8px;
margin-top: 30px;
border: 1px solid #e0e0e0;
}
.yacht-booking-form-container h4 {
margin: 0 0 25px 0;
font-size: 22px;
font-weight: 700;
color: #021526;
}
.yacht-booking-form .form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 20px;
}
.yacht-booking-form .form-field {
margin-bottom: 20px;
}
.yacht-booking-form label {
display: block;
font-weight: 600;
margin-bottom: 8px;
color: #333;
font-size: 14px;
}
.yacht-booking-form label .required {
color: #bc1834;
margin-left: 2px;
}
.yacht-booking-form input[type="text"],
.yacht-booking-form input[type="email"],
.yacht-booking-form input[type="tel"],
.yacht-booking-form input[type="date"] {
width: 100%;
padding: 12px 15px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
transition: border-color 0.3s ease, box-shadow 0.3s ease;
background: #fff;
box-sizing: border-box;
}
.yacht-booking-form input:focus {
outline: none;
border-color: #bc1834;
box-shadow: 0 0 0 3px rgba(188, 24, 52, 0.1);
}
.yacht-booking-form input:read-only {
background: #f5f5f5;
cursor: not-allowed;
}
.booking-terms {
margin-top: 18px;
font-size: 14px;
line-height: 1.5;
color: #333;
}
.booking-terms a {
color: #bc1834;
text-decoration: underline;
}
.yacht-booking-form .form-actions {
margin-top: 25px;
}
.yacht-booking-submit {
background: #bc1834;
color: #fff;
padding: 14px 30px;
border: none;
border-radius: 4px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
width: 100%;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.yacht-booking-submit:hover {
background: #021526;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.yacht-booking-submit:disabled {
background: #ccc;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
/* Response Messages */
.yacht-booking-response {
margin-top: 20px;
}
.booking-success,
.booking-error {
padding: 15px;
border-radius: 4px;
font-size: 15px;
line-height: 1.5;
}
.booking-success strong,
.booking-error strong {
display: block;
margin-bottom: 5px;
}
/* Error/Notice Messages */
.yacht-calendar-error,
.yacht-calendar-notice {
padding: 20px;
border-radius: 4px;
margin-bottom: 20px;
}
.yacht-calendar-error p,
.yacht-calendar-notice p {
margin: 0;
line-height: 1.5;
}
/* View-only mode (booking disabled) */
.yacht-calendar-view-only {
max-width: 1200px;
padding: 15px;
margin-bottom: 20px;
}
.yacht-calendar-view-only .yacht-calendar-header {
margin-bottom: 15px;
}
.yacht-calendar-view-only .yacht-calendar-title {
font-size: 22px;
margin-bottom: 10px;
}
.yacht-calendar-view-only .yacht-calendar-instructions {
margin-bottom: 8px;
padding: 8px 12px;
font-size: 13px;
}
.yacht-calendar-view-only .yacht-calendar-legend {
margin-bottom: 10px;
font-size: 13px;
}
.yacht-calendar-view-only .yacht-calendar {
padding: 10px;
margin-bottom: 0;
height: auto !important;
overflow: visible;
}
.yacht-calendar-view-only .fc-daygrid-day-frame {
min-height: 36px;
}
.yacht-calendar-view-only .fc-daygrid-day-top {
padding: 2px;
}
.yacht-calendar-view-only .fc-daygrid-day-number {
padding: 2px 4px;
min-width: 22px;
font-size: 12px;
}
.yacht-calendar-view-only .fc-col-header-cell {
font-size: 12px;
padding: 4px 0;
}
.yacht-calendar-view-only .fc-button {
font-size: 11px !important;
padding: 5px 10px !important;
}
.yacht-calendar-view-only .fc-toolbar-title {
font-size: 16px !important;
}
/* Inquiry layout (calendar + form side by side) */
.yacht-inquiry-layout {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 24px;
align-items: start;
}
.yacht-inquiry-form-container {
background: #021526;
padding: 24px;
border-radius: 8px;
border: none;
}
.yacht-inquiry-form-container h4 {
margin: 0 0 8px 0;
font-size: 20px;
font-weight: 700;
color: #fff;
}
.yacht-inquiry-desc {
margin: 0 0 18px 0;
color: rgba(255, 255, 255, 0.7);
font-size: 14px;
line-height: 1.5;
}
.yacht-inquiry-form .form-field {
margin-bottom: 14px;
}
.yacht-inquiry-form label {
display: block;
font-weight: 600;
margin-bottom: 5px;
color: rgba(255, 255, 255, 0.9);
font-size: 13px;
}
.yacht-inquiry-form label .required {
color: #ff6b6b;
margin-left: 2px;
}
.yacht-inquiry-form input[type="text"],
.yacht-inquiry-form input[type="email"],
.yacht-inquiry-form input[type="tel"],
.yacht-inquiry-form textarea {
width: 100%;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 4px;
font-size: 14px;
transition: border-color 0.3s ease, box-shadow 0.3s ease;
background: rgba(255, 255, 255, 0.1);
color: #fff;
box-sizing: border-box;
font-family: inherit;
}
.yacht-inquiry-form input::placeholder,
.yacht-inquiry-form textarea::placeholder {
color: rgba(255, 255, 255, 0.4);
}
.yacht-inquiry-form input:focus,
.yacht-inquiry-form textarea:focus {
outline: none;
border-color: #bc1834;
box-shadow: 0 0 0 3px rgba(188, 24, 52, 0.3);
background: rgba(255, 255, 255, 0.15);
}
.yacht-inquiry-form textarea {
resize: vertical;
min-height: 60px;
}
.yacht-inquiry-form .form-actions {
margin-top: 18px;
}
.yacht-inquiry-form .booking-terms {
color: rgba(255, 255, 255, 0.6);
font-size: 13px;
}
.yacht-inquiry-form .booking-terms a {
color: rgba(255, 255, 255, 0.85);
}
.yacht-inquiry-form .yacht-booking-submit {
background: #bc1834;
border-color: #bc1834;
color: #fff;
}
.yacht-inquiry-form .yacht-booking-submit:hover {
background: #fff;
color: #021526;
}
.yacht-inquiry-response {
margin-top: 15px;
}
/* Tablet Responsive */
@media (max-width: 992px) {
.yacht-calendar-title {
font-size: 24px;
}
.yacht-calendar {
padding: 15px;
}
}
/* Inquiry layout tablet */
@media (max-width: 992px) {
.yacht-inquiry-layout {
grid-template-columns: 1fr;
}
}
/* Mobile Responsive */
@media (max-width: 768px) {
.yacht-calendar-wrapper {
padding: 15px;
}
.yacht-calendar-switcher {
padding: 12px;
}
.yacht-calendar-switcher-buttons {
width: 100%;
}
.yacht-inquiry-form-container {
padding: 18px;
}
.yacht-calendar-title {
font-size: 22px;
}
.yacht-calendar {
padding: 10px;
}
.yacht-calendar-legend {
gap: 8px 12px;
}
.yacht-booking-form-container {
padding: 20px;
}
.yacht-booking-form .form-row {
grid-template-columns: 1fr;
gap: 0;
}
.yacht-calendar .fc-toolbar {
flex-direction: column;
gap: 10px;
}
.yacht-calendar .fc-toolbar-chunk {
display: flex;
justify-content: center;
width: 100%;
}
.yacht-calendar .fc-button {
font-size: 12px;
padding: 6px 12px;
}
}
/* Extra Small Mobile */
@media (max-width: 480px) {
.yacht-calendar-wrapper {
padding: 10px;
}
.yacht-calendar-switcher {
padding: 10px;
}
.yacht-calendar-switcher-button {
width: 100%;
justify-content: center;
}
.yacht-calendar-title {
font-size: 20px;
}
.yacht-booking-form-container {
padding: 15px;
}
.yacht-booking-form input[type="text"],
.yacht-booking-form input[type="email"],
.yacht-booking-form input[type="tel"] {
font-size: 14px;
padding: 10px 12px;
}
.yacht-booking-submit {
padding: 12px 20px;
font-size: 14px;
}
}

View File

@@ -0,0 +1,443 @@
/**
* Yacht Booking Calendar - Frontend JavaScript
*
* @package YachtBooking
*/
(function($) {
'use strict';
/**
* Initialize Yacht Calendar
*/
function initYachtCalendar($wrapper) {
const calendarId = $wrapper.data('calendar-id');
const bookingEnabled = $wrapper.data('booking-enabled') !== 0;
const yachtsData = $wrapper.attr('data-yachts');
const primaryColor = $wrapper.data('primary-color') || '#2271b1';
const normalizeColor = function(color, fallbackColor, legacyColor) {
const raw = (color || '').toString().trim().toLowerCase();
if (!raw || raw === legacyColor) {
return fallbackColor;
}
return color;
};
const availableBg = normalizeColor($wrapper.data('available-bg'), '#35b56a', '#d4edda');
const bookedBg = normalizeColor($wrapper.data('booked-bg'), '#e53935', '#f8d7da');
const yachtItems = yachtsData ? JSON.parse(yachtsData) : [];
const yachtMap = {};
const state = {
currentYachtId: parseInt($wrapper.attr('data-yacht-id'), 10) || 0
};
const $calendarEl = $wrapper.find('.yacht-calendar');
const $title = $wrapper.find('.yacht-calendar-title');
const $description = $wrapper.find('.yacht-calendar-description');
const $switcher = $wrapper.find('.yacht-calendar-switcher');
const $switcherButtonsContainer = $wrapper.find('.yacht-calendar-switcher-buttons');
const $form = $wrapper.find('.yacht-booking-form');
const $formContainer = $wrapper.find('.yacht-booking-form-container');
const $inquiryForm = $wrapper.find('.yacht-inquiry-form');
const $inquiryResponse = $wrapper.find('.yacht-inquiry-response');
if (!$calendarEl.length) {
console.error('Calendar element not found');
return;
}
yachtItems.forEach(function(item) {
yachtMap[item.id] = item;
});
function getAvailabilityUrl() {
return yachtBookingData.apiUrl + '/availability/' + state.currentYachtId;
}
function getTitleText(yachtTitle) {
if (bookingEnabled) {
return (yachtBookingData.i18n.bookingTitlePrefix || 'Rezerwacja: %s').replace('%s', yachtTitle);
}
return (yachtBookingData.i18n.availabilityTitlePrefix || 'Dostepnosc: %s').replace('%s', yachtTitle);
}
function renderSwitcherButtons() {
if (!$switcher.length || !$switcherButtonsContainer.length) {
return;
}
const otherYachts = yachtItems.filter(function(item) {
return item.id !== state.currentYachtId;
});
if (!otherYachts.length) {
$switcher.hide();
$switcherButtonsContainer.empty();
return;
}
const buttonsHtml = otherYachts.map(function(item) {
return '<button type="button" class="yacht-calendar-switcher-button" data-yacht-id="' + item.id + '" aria-pressed="false">' +
escapeHtml(item.title) +
'</button>';
}).join('');
$switcherButtonsContainer.html(buttonsHtml);
$switcher.show();
}
function resetFormsForYachtSwitch() {
if ($form.length) {
$form.each(function() {
this.reset();
});
$form.attr('data-yacht-id', state.currentYachtId);
$form.find('.yacht-booking-response').empty();
}
if ($formContainer.length) {
$formContainer.stop(true, true).hide();
}
if ($inquiryForm.length) {
$inquiryForm.each(function() {
this.reset();
});
$inquiryForm.attr('data-yacht-id', state.currentYachtId);
}
if ($inquiryResponse.length) {
$inquiryResponse.empty();
}
}
function updateYachtDetails() {
const yacht = yachtMap[state.currentYachtId];
if (!yacht) {
return;
}
$title.text(getTitleText(yacht.title));
if ($description.length) {
if (yacht.description) {
$description.html(yacht.description).show();
} else {
$description.empty().hide();
}
}
renderSwitcherButtons();
resetFormsForYachtSwitch();
}
// FullCalendar initialization
const calendar = new FullCalendar.Calendar($calendarEl[0], {
initialView: 'dayGridMonth',
contentHeight: bookingEnabled ? undefined : 'auto',
locale: 'pl',
firstDay: 1, // Poniedziałek
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth'
},
buttonText: {
today: 'Dzisiaj',
month: 'Miesiąc'
},
selectable: bookingEnabled,
selectMirror: bookingEnabled,
unselectAuto: false,
selectLongPressDelay: 1,
// Fetch events (availability) from REST API
events: function(info, successCallback, failureCallback) {
const startDate = formatDate(info.start);
const endDate = formatDate(info.end);
$.ajax({
url: getAvailabilityUrl(),
method: 'GET',
data: {
start: startDate,
end: endDate
},
success: function(data) {
const events = data.map(function(day) {
return {
id: day.date,
start: day.date,
allDay: true,
display: 'background',
backgroundColor: day.status === 'available' ? availableBg : bookedBg,
classNames: ['yacht-day-' + day.status],
extendedProps: {
status: day.status,
booking_id: day.booking_id || null
}
};
});
successCallback(events);
},
error: function(xhr, status, error) {
console.error('Error fetching availability:', error);
failureCallback(error);
}
});
},
// Handle date selection
select: function(info) {
const startDate = formatDate(info.start);
let endDate = formatDate(info.end);
// FullCalendar end date is exclusive, so subtract 1 day
endDate = subtractDay(endDate);
// Check if any selected dates are unavailable
const unavailableDates = calendar.getEvents().filter(function(event) {
const eventDate = formatDate(event.start);
return eventDate >= startDate && eventDate <= endDate &&
event.extendedProps.status !== 'available';
});
if (unavailableDates.length > 0) {
alert(yachtBookingData.i18n.unavailableDatesSelected || 'Wybrane daty zawierają niedostępne terminy. Proszę wybrać inne daty.');
calendar.unselect();
return;
}
// Fill form dates
$form.find('.booking-start-date').val(startDate);
$form.find('.booking-end-date').val(endDate);
// Show booking form
$formContainer.slideDown(300);
// Scroll to form
$('html, body').animate({
scrollTop: $formContainer.offset().top - 100
}, 500);
},
// Highlight selectable dates
selectAllow: function(selectInfo) {
// Must select at least 1 day
const daysDiff = Math.ceil((selectInfo.end - selectInfo.start) / (1000 * 60 * 60 * 24));
return daysDiff >= 1;
},
// Disable past dates
selectConstraint: {
start: new Date().toISOString().split('T')[0]
},
// Day cell class names
dayCellClassNames: function(arg) {
const today = new Date();
today.setHours(0, 0, 0, 0);
if (arg.date < today) {
return ['fc-day-past'];
}
return [];
}
});
calendar.render();
updateYachtDetails();
$switcher.on('click', '.yacht-calendar-switcher-button', function() {
const newYachtId = parseInt($(this).attr('data-yacht-id'), 10) || 0;
if (!newYachtId || newYachtId === state.currentYachtId) {
return;
}
state.currentYachtId = newYachtId;
$wrapper.attr('data-yacht-id', newYachtId);
calendar.unselect();
updateYachtDetails();
calendar.refetchEvents();
});
// Handle inquiry form submission
if ($inquiryForm.length) {
$inquiryForm.on('submit', function(e) {
e.preventDefault();
var $submitBtn = $inquiryForm.find('.yacht-booking-submit');
var $response = $inquiryForm.find('.yacht-inquiry-response');
var originalBtnText = $submitBtn.text();
$submitBtn.prop('disabled', true).text(yachtBookingData.i18n.submitting || 'Wysyłanie...');
$response.html('');
var formData = {
yacht_id: state.currentYachtId,
customer_name: $inquiryForm.find('[name="customer_name"]').val(),
customer_email: $inquiryForm.find('[name="customer_email"]').val(),
customer_phone: $inquiryForm.find('[name="customer_phone"]').val(),
preferred_dates: $inquiryForm.find('[name="preferred_dates"]').val(),
message: $inquiryForm.find('[name="message"]').val()
};
$.ajax({
url: yachtBookingData.apiUrl + '/inquiries',
method: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader('X-WP-Nonce', yachtBookingData.nonce);
},
contentType: 'application/json',
data: JSON.stringify(formData),
success: function(response) {
$response.html('<div class="booking-success" style="padding: 12px; background: #d4edda; color: #155724; border: 1px solid #c3e6cb; border-radius: 4px; margin-top: 12px;">' +
'<strong>' + (yachtBookingData.i18n.successTitle || 'Sukces!') + '</strong> ' +
(response.message || yachtBookingData.i18n.inquirySuccess || 'Twoje zapytanie zostało wysłane.') +
'</div>');
$inquiryForm[0].reset();
},
error: function(xhr) {
var errorMessage = yachtBookingData.i18n.errorMessage || 'Wystąpił błąd. Spróbuj ponownie.';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMessage = xhr.responseJSON.message;
}
$response.html('<div class="booking-error" style="padding: 12px; background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; margin-top: 12px;">' +
'<strong>' + (yachtBookingData.i18n.errorTitle || 'Błąd!') + '</strong> ' +
errorMessage +
'</div>');
},
complete: function() {
$submitBtn.prop('disabled', false).text(originalBtnText);
}
});
});
}
// Handle form submission
if ($form.length) {
$form.on('submit', function(e) {
e.preventDefault();
const $submitBtn = $form.find('.yacht-booking-submit');
const $response = $form.find('.yacht-booking-response');
const originalBtnText = $submitBtn.text();
// Disable submit button
$submitBtn.prop('disabled', true).text(yachtBookingData.i18n.submitting || 'Wysyłanie...');
$response.html('');
// Serialize form data
const formData = {
yacht_id: state.currentYachtId,
start_date: $form.find('[name="start_date"]').val(),
end_date: $form.find('[name="end_date"]').val(),
customer_name: $form.find('[name="customer_name"]').val(),
customer_email: $form.find('[name="customer_email"]').val(),
customer_phone: $form.find('[name="customer_phone"]').val()
};
// Submit booking via REST API
$.ajax({
url: yachtBookingData.apiUrl + '/bookings',
method: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader('X-WP-Nonce', yachtBookingData.nonce);
},
contentType: 'application/json',
data: JSON.stringify(formData),
success: function(response) {
// Show success message
$response.html('<div class="booking-success" style="padding: 15px; background: #d4edda; color: #155724; border: 1px solid #c3e6cb; border-radius: 4px; margin-top: 15px;">' +
'<strong>' + (yachtBookingData.i18n.successTitle || 'Sukces!') + '</strong> ' +
(yachtBookingData.i18n.successMessage || 'Twoja rezerwacja została wysłana. Skontaktujemy się z Tobą wkrótce.') +
'</div>');
// Reset form
$form[0].reset();
// Hide form after 2 seconds
setTimeout(function() {
$formContainer.slideUp(300);
}, 2000);
// Unselect dates
calendar.unselect();
// Refresh calendar to show new booking
calendar.refetchEvents();
},
error: function(xhr, status, error) {
let errorMessage = yachtBookingData.i18n.errorMessage || 'Wystąpił błąd podczas wysyłania rezerwacji. Spróbuj ponownie.';
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMessage = xhr.responseJSON.message;
}
$response.html('<div class="booking-error" style="padding: 15px; background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; margin-top: 15px;">' +
'<strong>' + (yachtBookingData.i18n.errorTitle || 'Błąd!') + '</strong> ' +
errorMessage +
'</div>');
console.error('Booking error:', error);
},
complete: function() {
// Re-enable submit button
$submitBtn.prop('disabled', false).text(originalBtnText);
}
});
});
}
}
/**
* Format date to YYYY-MM-DD
*/
function formatDate(date) {
const d = new Date(date);
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, '0');
const day = String(d.getDate()).padStart(2, '0');
return year + '-' + month + '-' + day;
}
/**
* Subtract one day from date string
*/
function subtractDay(dateString) {
const d = new Date(dateString);
d.setDate(d.getDate() - 1);
return formatDate(d);
}
function escapeHtml(value) {
return $('<div>').text(value || '').html();
}
/**
* Initialize on document ready
*/
$(document).ready(function() {
$('.yacht-calendar-wrapper').each(function() {
initYachtCalendar($(this));
});
});
/**
* Initialize on Elementor frontend init
*/
$(window).on('elementor/frontend/init', function() {
elementorFrontend.hooks.addAction('frontend/element_ready/yacht-calendar.default', function($scope) {
const $wrapper = $scope.find('.yacht-calendar-wrapper');
if ($wrapper.length) {
initYachtCalendar($wrapper);
}
});
});
})(jQuery);

View File

@@ -0,0 +1,594 @@
<?php
/**
* Yacht Calendar Widget for Elementor
*
* @package YachtBooking
*/
namespace YachtBooking;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use Elementor\Controls_Manager;
use Elementor\Widget_Base;
/**
* Yacht Calendar Widget Class
*/
class Calendar_Widget extends Widget_Base {
/**
* Get yachts for quick switcher.
*
* @return array<int, array<string, mixed>>
*/
private function get_yacht_switcher_items() {
$yachts = get_posts(
array(
'post_type' => 'yacht',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
)
);
$items = array();
foreach ( $yachts as $yacht ) {
$items[] = array(
'id' => (int) $yacht->ID,
'title' => get_the_title( $yacht ),
'description' => wp_kses_post( wpautop( $yacht->post_content ) ),
);
}
return $items;
}
/**
* Render quick yacht switcher.
*
* @param array<int, array<string, mixed>> $yachts Yacht items.
* @param int $active_id Active yacht ID.
* @return void
*/
private function render_yacht_switcher( $yachts, $active_id ) {
$other_yachts = array_filter(
$yachts,
static function( $yacht_item ) use ( $active_id ) {
return (int) $yacht_item['id'] !== (int) $active_id;
}
);
if ( empty( $other_yachts ) ) {
return;
}
?>
<div class="yacht-calendar-switcher" aria-label="<?php esc_attr_e( 'Szybki wybór jachtu', 'yacht-booking' ); ?>">
<span class="yacht-calendar-switcher-label"><?php esc_html_e( 'Zobacz też:', 'yacht-booking' ); ?></span>
<div class="yacht-calendar-switcher-buttons">
<?php foreach ( $other_yachts as $yacht_item ) : ?>
<button type="button"
class="yacht-calendar-switcher-button"
data-yacht-id="<?php echo esc_attr( $yacht_item['id'] ); ?>"
aria-pressed="false">
<?php echo esc_html( $yacht_item['title'] ); ?>
</button>
<?php endforeach; ?>
</div>
</div>
<?php
}
/**
* Get widget name
*
* @return string Widget name.
*/
public function get_name() {
return 'yacht-calendar';
}
/**
* Get widget title
*
* @return string Widget title.
*/
public function get_title() {
return esc_html__( 'Kalendarz Jachtu', 'yacht-booking' );
}
/**
* Get widget icon
*
* @return string Widget icon.
*/
public function get_icon() {
return 'eicon-calendar';
}
/**
* Get widget categories
*
* @return array Widget categories.
*/
public function get_categories() {
return array( 'basic' );
}
/**
* Get widget keywords
*
* @return array Widget keywords.
*/
public function get_keywords() {
return array( 'yacht', 'calendar', 'booking', 'kalendarz', 'rezerwacja' );
}
/**
* Register widget controls
*/
protected function register_controls() {
// Content Section - Yacht Selection
$this->start_controls_section(
'content_section',
array(
'label' => esc_html__( 'Ustawienia Kalendarza', 'yacht-booking' ),
'tab' => Controls_Manager::TAB_CONTENT,
)
);
// Yacht selector
$yachts = get_posts(
array(
'post_type' => 'yacht',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'fields' => 'ids',
)
);
$yacht_options = array();
foreach ( $yachts as $yacht_id ) {
$yacht_options[ $yacht_id ] = get_the_title( $yacht_id );
}
if ( empty( $yacht_options ) ) {
$yacht_options[0] = esc_html__( 'Brak jachtów - dodaj pierwszy jacht w panelu admin', 'yacht-booking' );
}
$this->add_control(
'yacht_id',
array(
'label' => esc_html__( 'Wybierz Jacht', 'yacht-booking' ),
'type' => Controls_Manager::SELECT,
'options' => $yacht_options,
'default' => array_key_first( $yacht_options ),
'label_block' => true,
)
);
$this->add_control(
'show_form',
array(
'label' => esc_html__( 'Pokaż formularz rezerwacji', 'yacht-booking' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Tak', 'yacht-booking' ),
'label_off' => esc_html__( 'Nie', 'yacht-booking' ),
'return_value' => 'yes',
'default' => 'yes',
)
);
$this->add_control(
'calendar_height',
array(
'label' => esc_html__( 'Wysokość kalendarza', 'yacht-booking' ),
'type' => Controls_Manager::SLIDER,
'range' => array(
'px' => array(
'min' => 400,
'max' => 1000,
),
),
'default' => array(
'size' => 600,
'unit' => 'px',
),
)
);
$this->end_controls_section();
// Style Section
$this->start_controls_section(
'style_section',
array(
'label' => esc_html__( 'Styl', 'yacht-booking' ),
'tab' => Controls_Manager::TAB_STYLE,
)
);
$this->add_control(
'primary_color',
array(
'label' => esc_html__( 'Kolor główny', 'yacht-booking' ),
'type' => Controls_Manager::COLOR,
'default' => '#2271b1',
)
);
$this->add_control(
'available_color',
array(
'label' => esc_html__( 'Kolor dni dostępnych', 'yacht-booking' ),
'type' => Controls_Manager::COLOR,
'default' => '#35b56a',
)
);
$this->add_control(
'booked_color',
array(
'label' => esc_html__( 'Kolor dni zajętych', 'yacht-booking' ),
'type' => Controls_Manager::COLOR,
'default' => '#e53935',
)
);
$this->end_controls_section();
}
/**
* Render widget output on the frontend
*/
protected function render() {
$settings = $this->get_settings_for_display();
$yacht_id = ! empty( $settings['yacht_id'] ) ? (int) $settings['yacht_id'] : 0;
if ( ! $yacht_id ) {
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
echo '<div class="yacht-calendar-notice" style="padding: 20px; background: #fff3cd; border: 1px solid #ffc107; border-radius: 4px;">';
echo '<p style="margin: 0;"><strong>' . esc_html__( 'Uwaga:', 'yacht-booking' ) . '</strong> ';
echo esc_html__( 'Najpierw dodaj jacht w panelu administratora.', 'yacht-booking' ) . '</p>';
echo '</div>';
}
return;
}
$yacht = get_post( $yacht_id );
$yacht_switcher = $this->get_yacht_switcher_items();
$booking_enabled = Settings::is_booking_enabled();
$show_form = $booking_enabled && 'yes' === $settings['show_form'];
$calendar_id = 'yacht-calendar-' . $this->get_id();
$raw_height = ! empty( $settings['calendar_height']['size'] ) ? (int) $settings['calendar_height']['size'] : 600;
$height = $raw_height;
$primary_color = ! empty( $settings['primary_color'] ) ? $settings['primary_color'] : '#2271b1';
$available_bg = ! empty( $settings['available_color'] ) ? $settings['available_color'] : '#35b56a';
$booked_bg = ! empty( $settings['booked_color'] ) ? $settings['booked_color'] : '#e53935';
$terms_url = Settings::get_terms_page_url();
?>
<div class="yacht-calendar-wrapper<?php echo $booking_enabled ? '' : ' yacht-calendar-view-only'; ?>"
data-yacht-id="<?php echo esc_attr( $yacht_id ); ?>"
data-calendar-id="<?php echo esc_attr( $calendar_id ); ?>"
data-primary-color="<?php echo esc_attr( $primary_color ); ?>"
data-available-bg="<?php echo esc_attr( $available_bg ); ?>"
data-booked-bg="<?php echo esc_attr( $booked_bg ); ?>"
data-yachts="<?php echo esc_attr( wp_json_encode( $yacht_switcher ) ); ?>"
data-booking-enabled="<?php echo $booking_enabled ? '1' : '0'; ?>">
<?php $this->render_yacht_switcher( $yacht_switcher, $yacht_id ); ?>
<div class="yacht-calendar-header">
<h3 class="yacht-calendar-title">
<?php if ( $booking_enabled ) : ?>
<?php
/* translators: %s: yacht name */
printf( esc_html__( 'Rezerwacja: %s', 'yacht-booking' ), esc_html( $yacht->post_title ) );
?>
<?php else : ?>
<?php
/* translators: %s: yacht name */
printf( esc_html__( 'Dostępność: %s', 'yacht-booking' ), esc_html( $yacht->post_title ) );
?>
<?php endif; ?>
</h3>
<div class="yacht-calendar-description"<?php echo $yacht->post_content ? '' : ' style="display: none;"'; ?>>
<?php echo wp_kses_post( wpautop( $yacht->post_content ) ); ?>
</div>
</div>
<div class="yacht-calendar-instructions">
<p>
<?php if ( $booking_enabled ) : ?>
<strong><?php esc_html_e( 'Instrukcja:', 'yacht-booking' ); ?></strong>
<?php esc_html_e( 'Zielone dni są dostępne, czerwone są zajęte lub zablokowane. Wybierz termin, przeciągając myszą po dostępnych dniach.', 'yacht-booking' ); ?>
<?php else : ?>
<?php esc_html_e( 'Zielone dni są dostępne, czerwone są zajęte lub zablokowane. Aby zarezerwować jacht, skontaktuj się z nami telefonicznie lub mailowo.', 'yacht-booking' ); ?>
<?php endif; ?>
</p>
</div>
<div class="yacht-calendar-legend" aria-label="<?php esc_attr_e( 'Legenda kalendarza rezerwacji', 'yacht-booking' ); ?>">
<span class="yacht-legend-item">
<span class="yacht-legend-swatch" style="background-color: <?php echo esc_attr( $available_bg ); ?>;"></span>
<?php esc_html_e( 'Dostępny', 'yacht-booking' ); ?>
</span>
<span class="yacht-legend-item">
<span class="yacht-legend-swatch" style="background-color: <?php echo esc_attr( $booked_bg ); ?>;"></span>
<?php esc_html_e( 'Zajęty / zablokowany', 'yacht-booking' ); ?>
</span>
<span class="yacht-legend-item">
<span class="yacht-legend-swatch yacht-legend-swatch-past"></span>
<?php esc_html_e( 'Data przeszła', 'yacht-booking' ); ?>
</span>
</div>
<?php if ( ! $booking_enabled ) : ?>
<div class="yacht-inquiry-layout">
<div class="yacht-inquiry-calendar-col">
<div id="<?php echo esc_attr( $calendar_id ); ?>"
class="yacht-calendar"
style="height: <?php echo esc_attr( $height ); ?>px;">
</div>
</div>
<div class="yacht-inquiry-form-col">
<div class="yacht-inquiry-form-container">
<h4><?php esc_html_e( 'Zapytaj o rezerwację', 'yacht-booking' ); ?></h4>
<p class="yacht-inquiry-desc">
<?php esc_html_e( 'Wypełnij formularz, a skontaktujemy się z Tobą w sprawie rezerwacji.', 'yacht-booking' ); ?>
</p>
<form class="yacht-inquiry-form" data-yacht-id="<?php echo esc_attr( $yacht_id ); ?>">
<?php wp_nonce_field( 'yacht_inquiry_submit', 'yacht_inquiry_nonce' ); ?>
<div class="form-field">
<label for="inquiry_name_<?php echo esc_attr( $this->get_id() ); ?>">
<?php esc_html_e( 'Imię i nazwisko', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="text"
id="inquiry_name_<?php echo esc_attr( $this->get_id() ); ?>"
name="customer_name"
required>
</div>
<div class="form-field">
<label for="inquiry_email_<?php echo esc_attr( $this->get_id() ); ?>">
<?php esc_html_e( 'Email', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="email"
id="inquiry_email_<?php echo esc_attr( $this->get_id() ); ?>"
name="customer_email"
required>
</div>
<div class="form-field">
<label for="inquiry_phone_<?php echo esc_attr( $this->get_id() ); ?>">
<?php esc_html_e( 'Telefon', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="tel"
id="inquiry_phone_<?php echo esc_attr( $this->get_id() ); ?>"
name="customer_phone"
required>
</div>
<div class="form-field">
<label for="inquiry_dates_<?php echo esc_attr( $this->get_id() ); ?>">
<?php esc_html_e( 'Preferowane terminy', 'yacht-booking' ); ?>
</label>
<input type="text"
id="inquiry_dates_<?php echo esc_attr( $this->get_id() ); ?>"
name="preferred_dates"
placeholder="<?php esc_attr_e( 'np. 15-22 lipca', 'yacht-booking' ); ?>">
</div>
<div class="form-field">
<label for="inquiry_message_<?php echo esc_attr( $this->get_id() ); ?>">
<?php esc_html_e( 'Wiadomość', 'yacht-booking' ); ?>
</label>
<textarea id="inquiry_message_<?php echo esc_attr( $this->get_id() ); ?>"
name="message"
rows="3"
placeholder="<?php esc_attr_e( 'Dodatkowe pytania lub uwagi...', 'yacht-booking' ); ?>"></textarea>
</div>
<?php if ( $terms_url ) : ?>
<p class="booking-terms">
<?php
printf(
wp_kses_post( __( 'Wysyłając formularz akceptujesz %s.', 'yacht-booking' ) ),
'<a href="' . esc_url( $terms_url ) . '" target="_blank" rel="noopener">' . esc_html__( 'regulamin', 'yacht-booking' ) . '</a>'
);
?>
</p>
<?php endif; ?>
<div class="form-actions">
<button type="submit" class="yacht-booking-submit">
<?php esc_html_e( 'Wyślij zapytanie', 'yacht-booking' ); ?>
</button>
</div>
<div class="yacht-inquiry-response"></div>
</form>
</div>
</div>
</div>
<?php else : ?>
<div id="<?php echo esc_attr( $calendar_id ); ?>"
class="yacht-calendar"
style="height: <?php echo esc_attr( $height ); ?>px;">
</div>
<?php if ( $show_form ) : ?>
<div class="yacht-booking-form-container" style="display: none;">
<h4><?php esc_html_e( 'Formularz Rezerwacji', 'yacht-booking' ); ?></h4>
<form class="yacht-booking-form" data-yacht-id="<?php echo esc_attr( $yacht_id ); ?>">
<?php wp_nonce_field( 'yacht_booking_submit', 'yacht_booking_nonce' ); ?>
<div class="form-row">
<div class="form-field">
<label for="booking_start_date_<?php echo esc_attr( $this->get_id() ); ?>">
<?php esc_html_e( 'Data rozpoczęcia', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="text"
id="booking_start_date_<?php echo esc_attr( $this->get_id() ); ?>"
name="start_date"
class="booking-start-date"
readonly
required>
</div>
<div class="form-field">
<label for="booking_end_date_<?php echo esc_attr( $this->get_id() ); ?>">
<?php esc_html_e( 'Data zakończenia', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="text"
id="booking_end_date_<?php echo esc_attr( $this->get_id() ); ?>"
name="end_date"
class="booking-end-date"
readonly
required>
</div>
</div>
<div class="form-field">
<label for="booking_name_<?php echo esc_attr( $this->get_id() ); ?>">
<?php esc_html_e( 'Imię i nazwisko', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="text"
id="booking_name_<?php echo esc_attr( $this->get_id() ); ?>"
name="customer_name"
required>
</div>
<div class="form-field">
<label for="booking_email_<?php echo esc_attr( $this->get_id() ); ?>">
<?php esc_html_e( 'Email', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="email"
id="booking_email_<?php echo esc_attr( $this->get_id() ); ?>"
name="customer_email"
required>
</div>
<div class="form-field">
<label for="booking_phone_<?php echo esc_attr( $this->get_id() ); ?>">
<?php esc_html_e( 'Telefon', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="tel"
id="booking_phone_<?php echo esc_attr( $this->get_id() ); ?>"
name="customer_phone"
required>
</div>
<?php if ( $terms_url ) : ?>
<p class="booking-terms">
<?php
printf(
wp_kses_post( __( 'Wysyłając formularz akceptujesz %s.', 'yacht-booking' ) ),
'<a href="' . esc_url( $terms_url ) . '" target="_blank" rel="noopener">' . esc_html__( 'regulamin', 'yacht-booking' ) . '</a>'
);
?>
</p>
<?php endif; ?>
<div class="form-actions">
<button type="submit" class="yacht-booking-submit">
<?php esc_html_e( 'Wyślij rezerwację', 'yacht-booking' ); ?>
</button>
</div>
<div class="yacht-booking-response"></div>
</form>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php
}
/**
* Render widget output in the editor (Elementor preview)
*/
protected function content_template() {
?>
<#
var yachtId = settings.yacht_id;
var calendarId = 'yacht-calendar-preview-' + view.getID();
var height = settings.calendar_height.size || 600;
var showForm = 'yes' === settings.show_form;
#>
<div class="yacht-calendar-wrapper"
data-yacht-id="{{ yachtId }}"
data-calendar-id="{{ calendarId }}"
data-primary-color="{{ settings.primary_color }}"
data-available-bg="{{ settings.available_color }}"
data-booked-bg="{{ settings.booked_color }}">
<div class="yacht-calendar-switcher">
<span class="yacht-calendar-switcher-label">
<?php esc_html_e( 'Szybki wybór jachtu:', 'yacht-booking' ); ?>
</span>
<div class="yacht-calendar-switcher-buttons">
<button type="button" class="yacht-calendar-switcher-button is-active">
<?php esc_html_e( 'Aktualnie wybrany jacht', 'yacht-booking' ); ?>
</button>
<button type="button" class="yacht-calendar-switcher-button">
<?php esc_html_e( 'Inny jacht', 'yacht-booking' ); ?>
</button>
</div>
</div>
<div class="yacht-calendar-header">
<h3 class="yacht-calendar-title">
<?php esc_html_e( 'Kalendarz Rezerwacji Jachtu', 'yacht-booking' ); ?>
</h3>
<p class="yacht-calendar-notice" style="background: #e3f2fd; padding: 10px; border-radius: 4px;">
<strong><?php esc_html_e( 'Podgląd Elementor:', 'yacht-booking' ); ?></strong>
<?php esc_html_e( 'Kalendarz będzie widoczny na stronie frontu.', 'yacht-booking' ); ?>
</p>
</div>
<div class="yacht-calendar-instructions">
<p>
<strong><?php esc_html_e( 'Instrukcja:', 'yacht-booking' ); ?></strong>
<?php esc_html_e( 'Wybierz termin przeciągając po zielonych dniach. Czerwone dni są niedostępne.', 'yacht-booking' ); ?>
</p>
</div>
<div class="yacht-calendar-legend">
<span class="yacht-legend-item">
<span class="yacht-legend-swatch" style="background-color: #35b56a;"></span>
<?php esc_html_e( 'Dostępny', 'yacht-booking' ); ?>
</span>
<span class="yacht-legend-item">
<span class="yacht-legend-swatch" style="background-color: #e53935;"></span>
<?php esc_html_e( 'Zajęty / zablokowany', 'yacht-booking' ); ?>
</span>
</div>
<div id="{{ calendarId }}"
class="yacht-calendar"
style="height: {{ height }}px; background: #f5f5f5; display: flex; align-items: center; justify-content: center;">
<p style="color: #666;">
<?php esc_html_e( 'Kalendarz FullCalendar zostanie załadowany na stronie frontu', 'yacht-booking' ); ?>
</p>
</div>
<# if ( showForm ) { #>
<div class="yacht-booking-form-container">
<h4><?php esc_html_e( 'Formularz Rezerwacji', 'yacht-booking' ); ?></h4>
<p style="background: #fff3cd; padding: 10px; border-radius: 4px;">
<?php esc_html_e( 'Formularz rezerwacji będzie aktywny na stronie frontu po wybraniu dat w kalendarzu.', 'yacht-booking' ); ?>
</p>
</div>
<# } #>
</div>
<?php
}
}

View File

@@ -0,0 +1,413 @@
<?php
/**
* Shortcode Handler
*
* @package YachtBooking
*/
namespace YachtBooking;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Shortcode class - handles [yacht_calendar] shortcode
*/
class Shortcode {
/**
* Single instance
*
* @var Shortcode
*/
private static $instance = null;
/**
* Get instance
*
* @return Shortcode
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct() {
add_shortcode( 'yacht_calendar', array( $this, 'render_calendar' ) );
}
/**
* Get yachts for quick switcher.
*
* @return array<int, array<string, mixed>>
*/
private function get_yacht_switcher_items() {
$yachts = get_posts(
array(
'post_type' => 'yacht',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
)
);
$items = array();
foreach ( $yachts as $yacht ) {
$items[] = array(
'id' => (int) $yacht->ID,
'title' => get_the_title( $yacht ),
'description' => wp_kses_post( wpautop( $yacht->post_content ) ),
);
}
return $items;
}
/**
* Render quick yacht switcher.
*
* @param array<int, array<string, mixed>> $yachts Yacht items.
* @param int $active_id Active yacht ID.
* @return void
*/
private function render_yacht_switcher( $yachts, $active_id ) {
$other_yachts = array_filter(
$yachts,
static function( $yacht_item ) use ( $active_id ) {
return (int) $yacht_item['id'] !== (int) $active_id;
}
);
if ( empty( $other_yachts ) ) {
return;
}
?>
<div class="yacht-calendar-switcher" aria-label="<?php esc_attr_e( 'Szybki wybór jachtu', 'yacht-booking' ); ?>">
<span class="yacht-calendar-switcher-label"><?php esc_html_e( 'Zobacz też:', 'yacht-booking' ); ?></span>
<div class="yacht-calendar-switcher-buttons">
<?php foreach ( $other_yachts as $yacht_item ) : ?>
<button type="button"
class="yacht-calendar-switcher-button"
data-yacht-id="<?php echo esc_attr( $yacht_item['id'] ); ?>"
aria-pressed="false">
<?php echo esc_html( $yacht_item['title'] ); ?>
</button>
<?php endforeach; ?>
</div>
</div>
<?php
}
/**
* Render calendar shortcode
*
* Usage: [yacht_calendar yacht_id="1" show_form="yes" height="600"]
*
* @param array $atts Shortcode attributes.
* @return string HTML output.
*/
public function render_calendar( $atts ) {
$atts = shortcode_atts(
array(
'yacht_id' => 0,
'show_form' => 'yes',
'height' => 600,
'primary_color' => '#2271b1',
'available_color' => '#35b56a',
'booked_color' => '#e53935',
),
$atts,
'yacht_calendar'
);
$yacht_id = (int) $atts['yacht_id'];
// If no yacht_id provided, get first yacht
if ( ! $yacht_id ) {
$yachts = get_posts(
array(
'post_type' => 'yacht',
'posts_per_page' => 1,
'orderby' => 'ID',
'order' => 'ASC',
'fields' => 'ids',
)
);
if ( empty( $yachts ) ) {
return '<div class="yacht-calendar-error" style="padding: 20px; background: #f8d7da; border: 1px solid #f5c6cb; border-radius: 4px;">' .
'<p><strong>' . esc_html__( 'Błąd:', 'yacht-booking' ) . '</strong> ' .
esc_html__( 'Brak jachtów w systemie. Dodaj przynajmniej jeden jacht w panelu administratora.', 'yacht-booking' ) .
'</p></div>';
}
$yacht_id = $yachts[0];
}
$yacht = get_post( $yacht_id );
if ( ! $yacht || 'yacht' !== $yacht->post_type ) {
return '<div class="yacht-calendar-error" style="padding: 20px; background: #f8d7da; border: 1px solid #f5c6cb; border-radius: 4px;">' .
'<p><strong>' . esc_html__( 'Błąd:', 'yacht-booking' ) . '</strong> ' .
esc_html__( 'Nie znaleziono jachtu o podanym ID.', 'yacht-booking' ) .
'</p></div>';
}
$booking_enabled = Settings::is_booking_enabled();
$yacht_switcher = $this->get_yacht_switcher_items();
$show_form = $booking_enabled && 'yes' === strtolower( $atts['show_form'] );
$height = (int) $atts['height'];
$primary_color = sanitize_hex_color( $atts['primary_color'] );
$available_bg = sanitize_hex_color( $atts['available_color'] );
$booked_bg = sanitize_hex_color( $atts['booked_color'] );
$calendar_id = 'yacht-calendar-' . wp_rand( 1000, 9999 );
$terms_url = Settings::get_terms_page_url();
ob_start();
?>
<div class="yacht-calendar-wrapper<?php echo $booking_enabled ? '' : ' yacht-calendar-view-only'; ?>"
data-yacht-id="<?php echo esc_attr( $yacht_id ); ?>"
data-calendar-id="<?php echo esc_attr( $calendar_id ); ?>"
data-primary-color="<?php echo esc_attr( $primary_color ); ?>"
data-available-bg="<?php echo esc_attr( $available_bg ); ?>"
data-booked-bg="<?php echo esc_attr( $booked_bg ); ?>"
data-yachts="<?php echo esc_attr( wp_json_encode( $yacht_switcher ) ); ?>"
data-booking-enabled="<?php echo $booking_enabled ? '1' : '0'; ?>">
<?php $this->render_yacht_switcher( $yacht_switcher, $yacht_id ); ?>
<div class="yacht-calendar-header">
<h3 class="yacht-calendar-title">
<?php if ( $booking_enabled ) : ?>
<?php
/* translators: %s: yacht name */
printf( esc_html__( 'Rezerwacja: %s', 'yacht-booking' ), esc_html( $yacht->post_title ) );
?>
<?php else : ?>
<?php
/* translators: %s: yacht name */
printf( esc_html__( 'Dostępność: %s', 'yacht-booking' ), esc_html( $yacht->post_title ) );
?>
<?php endif; ?>
</h3>
<div class="yacht-calendar-description"<?php echo $yacht->post_content ? '' : ' style="display: none;"'; ?>>
<?php echo wp_kses_post( wpautop( $yacht->post_content ) ); ?>
</div>
</div>
<div class="yacht-calendar-instructions">
<p>
<?php if ( $booking_enabled ) : ?>
<strong><?php esc_html_e( 'Instrukcja:', 'yacht-booking' ); ?></strong>
<?php esc_html_e( 'Zielone dni są dostępne, czerwone są zajęte lub zablokowane. Wybierz termin, przeciągając myszą po dostępnych dniach.', 'yacht-booking' ); ?>
<?php else : ?>
<?php esc_html_e( 'Zielone dni są dostępne, czerwone są zajęte lub zablokowane. Aby zarezerwować jacht, skontaktuj się z nami telefonicznie lub mailowo.', 'yacht-booking' ); ?>
<?php endif; ?>
</p>
</div>
<div class="yacht-calendar-legend" aria-label="<?php esc_attr_e( 'Legenda kalendarza rezerwacji', 'yacht-booking' ); ?>">
<span class="yacht-legend-item">
<span class="yacht-legend-swatch" style="background-color: <?php echo esc_attr( $available_bg ); ?>;"></span>
<?php esc_html_e( 'Dostępny', 'yacht-booking' ); ?>
</span>
<span class="yacht-legend-item">
<span class="yacht-legend-swatch" style="background-color: <?php echo esc_attr( $booked_bg ); ?>;"></span>
<?php esc_html_e( 'Zajęty / zablokowany', 'yacht-booking' ); ?>
</span>
<span class="yacht-legend-item">
<span class="yacht-legend-swatch yacht-legend-swatch-past"></span>
<?php esc_html_e( 'Data przeszła', 'yacht-booking' ); ?>
</span>
</div>
<?php if ( ! $booking_enabled ) : ?>
<div class="yacht-inquiry-layout">
<div class="yacht-inquiry-calendar-col">
<div id="<?php echo esc_attr( $calendar_id ); ?>"
class="yacht-calendar"
style="height: <?php echo esc_attr( $height ); ?>px;">
</div>
</div>
<div class="yacht-inquiry-form-col">
<div class="yacht-inquiry-form-container">
<h4><?php esc_html_e( 'Zapytaj o rezerwację', 'yacht-booking' ); ?></h4>
<p class="yacht-inquiry-desc">
<?php esc_html_e( 'Wypełnij formularz, a skontaktujemy się z Tobą w sprawie rezerwacji.', 'yacht-booking' ); ?>
</p>
<form class="yacht-inquiry-form" data-yacht-id="<?php echo esc_attr( $yacht_id ); ?>">
<?php wp_nonce_field( 'yacht_inquiry_submit', 'yacht_inquiry_nonce' ); ?>
<div class="form-field">
<label for="inquiry_name_<?php echo esc_attr( $calendar_id ); ?>">
<?php esc_html_e( 'Imię i nazwisko', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="text"
id="inquiry_name_<?php echo esc_attr( $calendar_id ); ?>"
name="customer_name"
required>
</div>
<div class="form-field">
<label for="inquiry_email_<?php echo esc_attr( $calendar_id ); ?>">
<?php esc_html_e( 'Email', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="email"
id="inquiry_email_<?php echo esc_attr( $calendar_id ); ?>"
name="customer_email"
required>
</div>
<div class="form-field">
<label for="inquiry_phone_<?php echo esc_attr( $calendar_id ); ?>">
<?php esc_html_e( 'Telefon', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="tel"
id="inquiry_phone_<?php echo esc_attr( $calendar_id ); ?>"
name="customer_phone"
required>
</div>
<div class="form-field">
<label for="inquiry_dates_<?php echo esc_attr( $calendar_id ); ?>">
<?php esc_html_e( 'Preferowane terminy', 'yacht-booking' ); ?>
</label>
<input type="text"
id="inquiry_dates_<?php echo esc_attr( $calendar_id ); ?>"
name="preferred_dates"
placeholder="<?php esc_attr_e( 'np. 15-22 lipca', 'yacht-booking' ); ?>">
</div>
<div class="form-field">
<label for="inquiry_message_<?php echo esc_attr( $calendar_id ); ?>">
<?php esc_html_e( 'Wiadomość', 'yacht-booking' ); ?>
</label>
<textarea id="inquiry_message_<?php echo esc_attr( $calendar_id ); ?>"
name="message"
rows="3"
placeholder="<?php esc_attr_e( 'Dodatkowe pytania lub uwagi...', 'yacht-booking' ); ?>"></textarea>
</div>
<?php if ( $terms_url ) : ?>
<p class="booking-terms">
<?php
printf(
wp_kses_post( __( 'Wysyłając formularz akceptujesz %s.', 'yacht-booking' ) ),
'<a href="' . esc_url( $terms_url ) . '" target="_blank" rel="noopener">' . esc_html__( 'regulamin', 'yacht-booking' ) . '</a>'
);
?>
</p>
<?php endif; ?>
<div class="form-actions">
<button type="submit" class="yacht-booking-submit">
<?php esc_html_e( 'Wyślij zapytanie', 'yacht-booking' ); ?>
</button>
</div>
<div class="yacht-inquiry-response"></div>
</form>
</div>
</div>
</div>
<?php else : ?>
<div id="<?php echo esc_attr( $calendar_id ); ?>"
class="yacht-calendar"
style="height: <?php echo esc_attr( $height ); ?>px;">
</div>
<?php if ( $show_form ) : ?>
<div class="yacht-booking-form-container" style="display: none;">
<h4><?php esc_html_e( 'Formularz Rezerwacji', 'yacht-booking' ); ?></h4>
<form class="yacht-booking-form" data-yacht-id="<?php echo esc_attr( $yacht_id ); ?>">
<?php wp_nonce_field( 'yacht_booking_submit', 'yacht_booking_nonce' ); ?>
<div class="form-row">
<div class="form-field">
<label for="booking_start_date_<?php echo esc_attr( $calendar_id ); ?>">
<?php esc_html_e( 'Data rozpoczęcia', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="text"
id="booking_start_date_<?php echo esc_attr( $calendar_id ); ?>"
name="start_date"
class="booking-start-date"
readonly
required>
</div>
<div class="form-field">
<label for="booking_end_date_<?php echo esc_attr( $calendar_id ); ?>">
<?php esc_html_e( 'Data zakończenia', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="text"
id="booking_end_date_<?php echo esc_attr( $calendar_id ); ?>"
name="end_date"
class="booking-end-date"
readonly
required>
</div>
</div>
<div class="form-field">
<label for="booking_name_<?php echo esc_attr( $calendar_id ); ?>">
<?php esc_html_e( 'Imię i nazwisko', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="text"
id="booking_name_<?php echo esc_attr( $calendar_id ); ?>"
name="customer_name"
required>
</div>
<div class="form-field">
<label for="booking_email_<?php echo esc_attr( $calendar_id ); ?>">
<?php esc_html_e( 'Email', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="email"
id="booking_email_<?php echo esc_attr( $calendar_id ); ?>"
name="customer_email"
required>
</div>
<div class="form-field">
<label for="booking_phone_<?php echo esc_attr( $calendar_id ); ?>">
<?php esc_html_e( 'Telefon', 'yacht-booking' ); ?> <span class="required">*</span>
</label>
<input type="tel"
id="booking_phone_<?php echo esc_attr( $calendar_id ); ?>"
name="customer_phone"
required>
</div>
<?php if ( $terms_url ) : ?>
<p class="booking-terms">
<?php
printf(
wp_kses_post( __( 'Wysyłając formularz akceptujesz %s.', 'yacht-booking' ) ),
'<a href="' . esc_url( $terms_url ) . '" target="_blank" rel="noopener">' . esc_html__( 'regulamin', 'yacht-booking' ) . '</a>'
);
?>
</p>
<?php endif; ?>
<div class="form-actions">
<button type="submit" class="yacht-booking-submit">
<?php esc_html_e( 'Wyślij rezerwację', 'yacht-booking' ); ?>
</button>
</div>
<div class="yacht-booking-response"></div>
</form>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php
return ob_get_clean();
}
}