| 1 |
<?php |
| 2 |
use SureCart\Models\Order; |
| 3 |
use SureCart\Models\Checkout; |
| 4 |
use SureCart\Models\Customer; |
| 5 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly. |
| 6 |
|
| 7 |
class ESHB_Booking_Calendar { |
| 8 |
public $plugin_settings = array(); |
| 9 |
public $calendar = array(); |
| 10 |
public $accomodations = array(); |
| 11 |
public $bookings = array(); |
| 12 |
public $calendar_settings = array( |
| 13 |
'start_date' => '', |
| 14 |
'end_date' => '', |
| 15 |
'booking_period' => 'custom', |
| 16 |
'current_accomodation' => 'all', |
| 17 |
'current_status' => ['processing', 'on-hold', 'completed', 'pending', 'blocked'], |
| 18 |
'allowed_status' => ['processing', 'on-hold', 'completed', 'pending', 'blocked'], |
| 19 |
); |
| 20 |
|
| 21 |
public function __construct() { |
| 22 |
|
| 23 |
$this->plugin_settings = get_option( 'eshb_settings', [] ); |
| 24 |
|
| 25 |
// Setup calendar settings |
| 26 |
$today_date = gmdate("Y-m-d"); |
| 27 |
$default_end_date = gmdate('Y-m-d', strtotime('+14 days')); |
| 28 |
|
| 29 |
// use defaults |
| 30 |
$start_date = $today_date; |
| 31 |
$end_date = $default_end_date; |
| 32 |
$current_status = $this->calendar_settings['current_status']; |
| 33 |
$current_accomodation = $this->calendar_settings['current_accomodation']; |
| 34 |
$booking_period = $this->calendar_settings['booking_period']; |
| 35 |
|
| 36 |
// Verify nonce for form processing |
| 37 |
if (isset($_POST['nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), ESHB_Helper::generate_secure_nonce_action('booking_calendar_nonce'))) { |
| 38 |
// Sanitize and validate GET parameters |
| 39 |
$start_date = !empty($_POST['start-date']) ? sanitize_text_field(wp_unslash($_POST['start-date'])) : $today_date; |
| 40 |
$end_date = !empty($_POST['end-date']) ? sanitize_text_field(wp_unslash($_POST['end-date'])) : $default_end_date; |
| 41 |
$current_status = !empty($_POST['booking-status']) ? [sanitize_text_field(wp_unslash($_POST['booking-status']))] : $this->calendar_settings['current_status']; |
| 42 |
$current_accomodation = !empty($_POST['accomodation-id']) ? sanitize_text_field(wp_unslash($_POST['accomodation-id'])) : $this->calendar_settings['current_accomodation']; |
| 43 |
$booking_period = !empty($_POST['booking-period']) ? sanitize_text_field(wp_unslash($_POST['booking-period'])) : $this->calendar_settings['booking_period']; |
| 44 |
} |
| 45 |
|
| 46 |
if ($booking_period != 'custom') { |
| 47 |
|
| 48 |
// Current date |
| 49 |
$start_date = gmdate('Y-m-01'); |
| 50 |
$end_date = gmdate('Y-m-t'); |
| 51 |
|
| 52 |
|
| 53 |
if (!empty($_POST['action-prev-period']) || !empty($_POST['action-next-period'])){ |
| 54 |
$start_date = !empty($_POST['start-date']) ? sanitize_text_field(wp_unslash($_POST['start-date'])) : $start_date; |
| 55 |
$end_date = !empty($_POST['end-date']) ? sanitize_text_field(wp_unslash($_POST['end-date'])) : $end_date; |
| 56 |
} |
| 57 |
|
| 58 |
if ($booking_period == 'month') { |
| 59 |
|
| 60 |
if (!empty($_POST['action-prev-period'])) { |
| 61 |
$date = $start_date; |
| 62 |
$start_date = gmdate('Y-m-01', strtotime('-1 month', strtotime($date))); |
| 63 |
$end_date = gmdate('Y-m-t', strtotime('-1 month', strtotime($date))); |
| 64 |
} |
| 65 |
|
| 66 |
if (!empty($_POST['action-next-period'])) { |
| 67 |
$date = $start_date; |
| 68 |
$start_date = gmdate('Y-m-01', strtotime('+1 month', strtotime($date))); |
| 69 |
$end_date = gmdate('Y-m-t', strtotime('+1 month', strtotime($date))); |
| 70 |
} |
| 71 |
|
| 72 |
} elseif ($booking_period == 'quarter') { |
| 73 |
// Default: current quarter |
| 74 |
$current_month = gmdate('n'); |
| 75 |
$quarter_start_month = floor(($current_month - 1) / 3) * 3 + 1; |
| 76 |
$start_date = gmdate('Y-' . str_pad($quarter_start_month, 2, '0', STR_PAD_LEFT) . '-01'); |
| 77 |
$end_date = gmdate('Y-m-t', strtotime("+2 months", strtotime($start_date))); // end of third month |
| 78 |
|
| 79 |
|
| 80 |
if (!empty($_POST['action-prev-period'])) { |
| 81 |
$start_date = !empty($_POST['start-date']) ? sanitize_text_field(wp_unslash($_POST['start-date'])) : $start_date; |
| 82 |
$end_date = !empty($_POST['end-date']) ? sanitize_text_field(wp_unslash($_POST['end-date'])) : $end_date; |
| 83 |
$start_date = gmdate('Y-m-01', strtotime('-3 months', strtotime($start_date))); |
| 84 |
$end_date = gmdate('Y-m-t', strtotime('+2 months', strtotime($start_date))); |
| 85 |
} |
| 86 |
|
| 87 |
if (!empty($_POST['action-next-period'])) { |
| 88 |
$start_date = !empty($_POST['start-date']) ? sanitize_text_field(wp_unslash($_POST['start-date'])) : $start_date; |
| 89 |
$end_date = !empty($_POST['end-date']) ? sanitize_text_field(wp_unslash($_POST['end-date'])) : $end_date; |
| 90 |
$start_date = gmdate('Y-m-01', strtotime('+3 months', strtotime($start_date))); |
| 91 |
$end_date = gmdate('Y-m-t', strtotime('+2 months', strtotime($start_date))); |
| 92 |
} |
| 93 |
|
| 94 |
} elseif ($booking_period == 'year') { |
| 95 |
// Default to full current year |
| 96 |
$start_date = gmdate('Y-01-01'); |
| 97 |
$end_date = gmdate('Y-12-31'); |
| 98 |
|
| 99 |
if (!empty($_POST['action-prev-period'])) { |
| 100 |
$start_date = !empty($_POST['start-date']) ? sanitize_text_field(wp_unslash($_POST['start-date'])) : $start_date; |
| 101 |
$end_date = !empty($_POST['end-date']) ? sanitize_text_field(wp_unslash($_POST['end-date'])) : $end_date; |
| 102 |
$start_date = gmdate('Y-01-01', strtotime('-1 year', strtotime($start_date))); |
| 103 |
$end_date = gmdate('Y-12-31', strtotime('-1 year', strtotime($end_date))); |
| 104 |
} |
| 105 |
|
| 106 |
if (!empty($_POST['action-next-period'])) { |
| 107 |
$start_date = !empty($_POST['start-date']) ? sanitize_text_field(wp_unslash($_POST['start-date'])) : $start_date; |
| 108 |
$end_date = !empty($_POST['end-date']) ? sanitize_text_field(wp_unslash($_POST['end-date'])) : $end_date; |
| 109 |
$start_date = gmdate('Y-01-01', strtotime('+1 year', strtotime($start_date))); |
| 110 |
$end_date = gmdate('Y-12-31', strtotime('+1 year', strtotime($end_date))); |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
$this->calendar_settings = array_merge( |
| 117 |
$this->calendar_settings, |
| 118 |
[ |
| 119 |
'start' => $start_date, |
| 120 |
'end' => $end_date, |
| 121 |
'current_status' => $current_status, |
| 122 |
'current_accomodation' => $current_accomodation, |
| 123 |
] |
| 124 |
); |
| 125 |
|
| 126 |
$this->calendar = [ |
| 127 |
'name' => 'Booking Calendar', |
| 128 |
'settings' => $this->calendar_settings, |
| 129 |
'dates' => $this->get_dates_from_range($this->calendar_settings['start'], $this->calendar_settings['end']), |
| 130 |
'accomodations' => $this->accomodations, |
| 131 |
]; |
| 132 |
|
| 133 |
// Set all accomodations & bookings |
| 134 |
$this->set_all_accomodations(); |
| 135 |
$this->set_all_bookings(); |
| 136 |
} |
| 137 |
|
| 138 |
public function get_dates_from_range($start_date, $end_date) { |
| 139 |
$dates = array(); |
| 140 |
$start = new DateTime($start_date); |
| 141 |
$end = new DateTime($end_date); |
| 142 |
$end = $end->modify('+1 day'); // Include end date |
| 143 |
|
| 144 |
while ($start < $end) { |
| 145 |
$dates[] = $start->format('Y-m-d'); |
| 146 |
$start->modify('+1 day'); |
| 147 |
} |
| 148 |
|
| 149 |
return $dates; |
| 150 |
} |
| 151 |
|
| 152 |
public function set_all_accomodations () { |
| 153 |
// Fetch all accomodations |
| 154 |
$accomodation_posts = get_posts([ |
| 155 |
'post_type' => 'eshb_accomodation', |
| 156 |
'posts_per_page' => -1, |
| 157 |
'post_status' => 'publish', |
| 158 |
'orderby' => 'ID', |
| 159 |
'order' => 'DESC', |
| 160 |
]); |
| 161 |
|
| 162 |
foreach ($accomodation_posts as $post) { |
| 163 |
$accomodation_id = $post->ID; |
| 164 |
$metaboxes = get_post_meta($accomodation_id, 'eshb_accomodation_metaboxes', true); |
| 165 |
$total_rooms = isset($metaboxes['total_rooms']) ? floatval($metaboxes['total_rooms']) : 0; |
| 166 |
|
| 167 |
$this->accomodations[] = [ |
| 168 |
'id' => $accomodation_id, |
| 169 |
'name' => $post->post_title, |
| 170 |
'type' => $post->post_type, |
| 171 |
'status' => $post->post_status, |
| 172 |
'total_rooms' => $total_rooms, |
| 173 |
]; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
public function set_all_bookings (){ |
| 178 |
|
| 179 |
$plugin_settings = $this->plugin_settings; |
| 180 |
$booked_type = $plugin_settings['booking-type']; |
| 181 |
$bookings = []; |
| 182 |
|
| 183 |
$booking_posts = get_posts([ |
| 184 |
'post_type' => 'eshb_booking', |
| 185 |
'posts_per_page' => -1, |
| 186 |
'post_status' => ['publish', 'deposit-payment', 'pending', 'processing', 'on-hold', 'completed'], |
| 187 |
'orderby' => 'title', |
| 188 |
'order' => 'ASC', |
| 189 |
]); |
| 190 |
|
| 191 |
foreach ($booking_posts as $post) { |
| 192 |
$booking_id = $post->ID; |
| 193 |
$metaboxes = get_post_meta($booking_id, 'eshb_booking_metaboxes', true); |
| 194 |
|
| 195 |
$accomodation_id = floatval($metaboxes['booking_accomodation_id'] ?? 0); |
| 196 |
$order_id = $metaboxes['order_id'] ?? ''; |
| 197 |
$check_in = $metaboxes['booking_start_date'] ?? ''; |
| 198 |
$check_out = $metaboxes['booking_end_date'] ?? ''; |
| 199 |
$booked_dates = $this->get_dates_from_range($check_in, $check_out); |
| 200 |
|
| 201 |
if (count($booked_dates) > 1) { |
| 202 |
array_pop($booked_dates); |
| 203 |
} |
| 204 |
|
| 205 |
$booking_status = $metaboxes['booking_status'] ?? ''; |
| 206 |
$customer = ''; |
| 207 |
|
| 208 |
|
| 209 |
if (class_exists('WooCommerce') && wc_get_order($order_id)) { |
| 210 |
$order = wc_get_order($order_id); |
| 211 |
$customer = trim($order->get_billing_first_name() . ' ' . $order->get_billing_last_name()); |
| 212 |
} |
| 213 |
|
| 214 |
$customer = apply_filters( 'eshb_customer_data_in_calendar', $customer, $order_id, $booked_type); |
| 215 |
|
| 216 |
|
| 217 |
if (in_array($booking_status, ['processing', 'on-hold'])) { |
| 218 |
$booking_status = 'blocked'; |
| 219 |
} |
| 220 |
|
| 221 |
if(in_array($booking_status, $this->calendar_settings['current_status'])){ |
| 222 |
$bookings[] = [ |
| 223 |
'id' => $booking_id, |
| 224 |
'check_in' => $check_in, |
| 225 |
'check_out' => $check_out, |
| 226 |
'status' => $booking_status, |
| 227 |
'accomodation_id' => $accomodation_id, |
| 228 |
'customer' => $customer, |
| 229 |
'source_type' => 'internal', |
| 230 |
]; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
} |
| 236 |
|
| 237 |
$bookings = apply_filters('eshb_modify_calendar_booking_data', $bookings, $this->calendar_settings); |
| 238 |
|
| 239 |
$this->bookings = array_merge($this->bookings, $bookings); |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
private function get_bookings_for_accomodation($accomodation_id) { |
| 245 |
return array_filter($this->bookings, function($booking) use ($accomodation_id) { |
| 246 |
return intval($booking['accomodation_id']) === intval($accomodation_id); |
| 247 |
}); |
| 248 |
} |
| 249 |
|
| 250 |
public function render_booking_cells($dates, $accomodations, $accomodation_limit = 0) { |
| 251 |
|
| 252 |
if ( ! isset( $_POST['nonce'] ) || |
| 253 |
! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), ESHB_Helper::generate_secure_nonce_action('booking_calendar_nonce') ) ) { |
| 254 |
$filtered_accomodation_id = ''; |
| 255 |
} |
| 256 |
|
| 257 |
if ($accomodation_limit > 0) { |
| 258 |
$accomodations = array_slice($accomodations, 0, $accomodation_limit); |
| 259 |
} |
| 260 |
|
| 261 |
$filtered_accomodation_id = !empty($_REQUEST['accomodation-id']) ? sanitize_text_field(wp_unslash($_REQUEST['accomodation-id'])): ''; |
| 262 |
if(!empty($filtered_accomodation_id)){ |
| 263 |
$accomodations = array_filter($accomodations, function($accomodation) use ($filtered_accomodation_id) { |
| 264 |
return $accomodation['id'] == $filtered_accomodation_id; |
| 265 |
}); |
| 266 |
} |
| 267 |
|
| 268 |
$html = ''; |
| 269 |
$dates_map = array_flip($dates); |
| 270 |
$total_dates = count($dates); |
| 271 |
|
| 272 |
// Group bookings by accomodation id for faster access |
| 273 |
$bookings_by_accomodation = []; |
| 274 |
foreach ($this->bookings as $booking) { |
| 275 |
if (!isset($booking['accomodation_id'])) continue; |
| 276 |
$acc_id = $booking['accomodation_id']; |
| 277 |
$bookings_by_accomodation[$acc_id][] = $booking; |
| 278 |
} |
| 279 |
|
| 280 |
foreach ($accomodations as $accomodation) { |
| 281 |
$accomodation_id = $accomodation['id']; |
| 282 |
|
| 283 |
if ( function_exists( 'pll_get_post' )) { |
| 284 |
$default_lang = pll_default_language(); |
| 285 |
$main_post_id = pll_get_post( $accomodation_id, $default_lang ) ? pll_get_post( $accomodation_id, $default_lang ) : $accomodation_id ; |
| 286 |
$accomodation_id = $main_post_id; |
| 287 |
}elseif ( function_exists( 'apply_filters' ) && function_exists( 'icl_object_id' ) ) { |
| 288 |
$accomodation_id = apply_filters( 'wpml_original_element_id', NULL, $accomodation_id, 'post_post' ); |
| 289 |
} |
| 290 |
|
| 291 |
$accomodation_name = $accomodation['name']; |
| 292 |
|
| 293 |
$bookings = isset($bookings_by_accomodation[$accomodation_id]) ? $bookings_by_accomodation[$accomodation_id] : []; |
| 294 |
|
| 295 |
// Group bookings by date range |
| 296 |
$grouped_bookings = []; |
| 297 |
foreach ($bookings as $booking) { |
| 298 |
$key = $booking['check_in'] . '|' . $booking['check_out']; |
| 299 |
$grouped_bookings[$key][] = $booking; |
| 300 |
} |
| 301 |
|
| 302 |
$html .= '<tr>'; |
| 303 |
$html .= '<th class="left-heading"><div class="room-info">' . esc_html($accomodation_name) . '</div></th>'; |
| 304 |
$date_pointer = 0; |
| 305 |
|
| 306 |
while ($date_pointer < $total_dates) { |
| 307 |
$current_date = $dates[$date_pointer]; |
| 308 |
$matched = false; |
| 309 |
|
| 310 |
foreach ($grouped_bookings as $range_key => $group) { |
| 311 |
[$check_in, $check_out] = explode('|', $range_key); |
| 312 |
|
| 313 |
if ($check_in <= $current_date && $check_out > $current_date) { |
| 314 |
$colspan = 0; |
| 315 |
$tmp_date = $current_date; |
| 316 |
$max_days = $total_dates; // do not exceed 60 days range |
| 317 |
$loop_count = 0; |
| 318 |
|
| 319 |
while ( |
| 320 |
$tmp_date < $check_out && |
| 321 |
isset($dates_map[$tmp_date]) && |
| 322 |
$loop_count < $max_days |
| 323 |
) { |
| 324 |
$colspan++; |
| 325 |
$tmp_date = gmdate('Y-m-d', strtotime($tmp_date . ' +1 day')); |
| 326 |
$loop_count++; |
| 327 |
} |
| 328 |
|
| 329 |
if ($colspan <= 0) { |
| 330 |
$colspan = 1; |
| 331 |
} |
| 332 |
|
| 333 |
$html .= '<td class="booking-info-col" colspan="' . $colspan . '">'; |
| 334 |
|
| 335 |
foreach ($group as $booking) { |
| 336 |
|
| 337 |
$source_type = $booking['source_type']; |
| 338 |
|
| 339 |
if($source_type == 'internal'){ |
| 340 |
$status_class = 'status-' . esc_attr($booking['status']); |
| 341 |
$html .= '<a href="#" class="booking-info ' . esc_attr($status_class) . '" data-source-type="internal" data-booking-id="' . esc_attr($booking['id']) . '" data-accomodation-id="' . esc_attr($accomodation_id) . '">'; |
| 342 |
$html .= '<span class="booking-id">#' . esc_html($booking['id']) . '</span>'; |
| 343 |
$html .= '<span class="booking-customer">' . esc_html($booking['customer']) . '</span>'; |
| 344 |
$html .= '</a>'; |
| 345 |
} |
| 346 |
|
| 347 |
$html = apply_filters( 'eshb_calendar_booking_info_btn', $html, $booking, $accomodation_id ); |
| 348 |
|
| 349 |
} |
| 350 |
|
| 351 |
$html .= '</td>'; |
| 352 |
|
| 353 |
$date_pointer += $colspan; |
| 354 |
$matched = true; |
| 355 |
break; |
| 356 |
} |
| 357 |
|
| 358 |
} |
| 359 |
|
| 360 |
if (!$matched) { |
| 361 |
$html .= '<td class="status-available"><div class="eshb-booking-info"></div></td>'; |
| 362 |
$date_pointer++; |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
$html .= '</tr>'; |
| 367 |
} |
| 368 |
|
| 369 |
return $html; |
| 370 |
} |
| 371 |
|
| 372 |
public function render_accomodation_cells($accomodations, $accomodation_limit = 0) { |
| 373 |
|
| 374 |
|
| 375 |
if ( ! isset( $_POST['nonce'] ) || |
| 376 |
! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), ESHB_Helper::generate_secure_nonce_action('booking_calendar_nonce') ) ) { |
| 377 |
$filtered_accomodation_id = ''; |
| 378 |
}else{ |
| 379 |
$filtered_accomodation_id = !empty(sanitize_text_field(wp_unslash($_REQUEST['accomodation-id']))) ? sanitize_text_field(wp_unslash($_REQUEST['accomodation-id'])): ''; |
| 380 |
} |
| 381 |
|
| 382 |
if ($accomodation_limit > 0) { |
| 383 |
$accomodations = array_slice($accomodations, 0, $accomodation_limit); |
| 384 |
} |
| 385 |
|
| 386 |
if(!empty($filtered_accomodation_id)){ |
| 387 |
$accomodations = array_filter($accomodations, function($accomodation) use ($filtered_accomodation_id) { |
| 388 |
return $accomodation['id'] == $filtered_accomodation_id; |
| 389 |
}); |
| 390 |
} |
| 391 |
|
| 392 |
$html = ''; |
| 393 |
foreach ($accomodations as $accomodation) { |
| 394 |
$accomodation_name = $accomodation['name']; |
| 395 |
$html .= '<tr>'; |
| 396 |
$html .= '<td><div class="room-info">' . esc_html($accomodation_name) . '</div></td>'; |
| 397 |
$html .= '</tr>'; |
| 398 |
} |
| 399 |
|
| 400 |
return $html; |
| 401 |
} |
| 402 |
|
| 403 |
public function render_dates_table ($dates, $accomodations, $accomodation_limit = 0) { |
| 404 |
if ($accomodation_limit > 0) { |
| 405 |
$accomodations = array_slice($accomodations, 0, $accomodation_limit); |
| 406 |
} |
| 407 |
|
| 408 |
$html = '<div class="eshb-accomodations-dates-table-wrapper table-wrapper">'; |
| 409 |
$html .= '<table class="eshb-accomodations-dates-table sticky-table">'; |
| 410 |
|
| 411 |
$html .= '<thead>'; |
| 412 |
$html .= '<tr>'; |
| 413 |
$html .= '<th class="left-heading"><div class="table-heading">'. esc_html__('Accomodations', 'easy-hotel') .'</div></th>'; |
| 414 |
foreach ($dates as $date) { |
| 415 |
$wp_date_format = get_option('date_format'); |
| 416 |
$formatted_date = DateTime::createFromFormat('Y-m-d', $date)->format($wp_date_format); |
| 417 |
$html .= '<th>'; |
| 418 |
$html .= '<div class="date">'; |
| 419 |
$html .= esc_html( DateTime::createFromFormat('Y-m-d', $date)->format('j') ) . '<br />'; |
| 420 |
$html .= esc_html( DateTime::createFromFormat('Y-m-d', $date)->format('M'), DateTime::createFromFormat('Y-m-d', $date)->format('F'). ' abbreviation') . '<br />'; |
| 421 |
$html .= '<small class="eshb-subscript">' . DateTime::createFromFormat('Y-m-d', $date)->format('Y').'</small><br />'; |
| 422 |
$html .= '<small class="eshb-subscript">' . DateTime::createFromFormat('Y-m-d', $date)->format('D') . '</small>'; |
| 423 |
$html .= '</div>'; |
| 424 |
$html .= '</th>'; |
| 425 |
} |
| 426 |
$html .= '</tr>'; |
| 427 |
$html .= '</thead>'; |
| 428 |
$html .= '<tbody>'; |
| 429 |
|
| 430 |
$html .= $this->render_booking_cells($dates, $accomodations, ' '); |
| 431 |
|
| 432 |
$html .= '</tbody>'; |
| 433 |
$html .= '<tfoot>'; |
| 434 |
$html .= '<tr>'; |
| 435 |
$html .= '<th class="left-heading"><div class="table-heading">'. esc_html__('Accomodations', 'easy-hotel') .'</div></th>'; |
| 436 |
foreach ($dates as $date) { |
| 437 |
$wp_date_format = get_option('date_format'); |
| 438 |
$formatted_date = DateTime::createFromFormat('Y-m-d', $date)->format($wp_date_format); |
| 439 |
$html .= '<th>'; |
| 440 |
$html .= '<div class="date">'; |
| 441 |
$html .= esc_html( DateTime::createFromFormat('Y-m-d', $date)->format('j') ) . '<br />'; |
| 442 |
$html .= esc_html( DateTime::createFromFormat('Y-m-d', $date)->format('M'), DateTime::createFromFormat('Y-m-d', $date)->format('F'). ' abbreviation' ) . '<br />'; |
| 443 |
$html .= '<small class="eshb-subscript">' . DateTime::createFromFormat('Y-m-d', $date)->format('Y').'</small><br />'; |
| 444 |
$html .= '<small class="eshb-subscript">' . DateTime::createFromFormat('Y-m-d', $date)->format('D') . '</small>'; |
| 445 |
$html .= '</div>'; |
| 446 |
$html .= '</th>'; |
| 447 |
} |
| 448 |
$html .= '</tr>'; |
| 449 |
$html .= '</tfoot>'; |
| 450 |
$html .= '</table>'; |
| 451 |
$html .= '</div>'; |
| 452 |
|
| 453 |
return $html; |
| 454 |
} |
| 455 |
|
| 456 |
public function render_booking_info_calendar () { |
| 457 |
$calendar = $this->calendar; |
| 458 |
$html = '<div class="eshb-booking-info-calendar">'; |
| 459 |
$html .= '<h1>' . esc_html($calendar['name']) . '</h1>'; |
| 460 |
$html .= $this->render_calendar_filter(); |
| 461 |
$html .= '<div class="eshb-booking-info-calendar-tables">'; |
| 462 |
$html .= $this->render_dates_table($calendar['dates'], $this->accomodations); |
| 463 |
$html .= '</div>'; |
| 464 |
$html .= $this->render_booking_info_modal(); |
| 465 |
$html .= '</div>'; |
| 466 |
return $html; |
| 467 |
} |
| 468 |
|
| 469 |
public function render_calendar_filter () { |
| 470 |
|
| 471 |
if ( ! isset( $_POST['nonce'] ) || |
| 472 |
! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), ESHB_Helper::generate_secure_nonce_action('booking_calendar_nonce') ) ) { |
| 473 |
$current_booking_period = 'custom'; |
| 474 |
}else{ |
| 475 |
$current_booking_period = !empty($_POST['booking-period']) ? sanitize_text_field(wp_unslash($_POST['booking-period'])) : 'custom'; |
| 476 |
} |
| 477 |
|
| 478 |
// filter by accomodation, booking status, period, date range, etc. |
| 479 |
$calendar_settings = $this->calendar_settings; |
| 480 |
$current_status = count($calendar_settings['current_status']) > 1 ? '' : $calendar_settings['current_status'][0]; |
| 481 |
$current_accomodation = $calendar_settings['current_accomodation']; |
| 482 |
$nonce_field = ESHB_Helper::eshb_nonce_field('booking_calendar_nonce', 'nonce', false); |
| 483 |
$action_url = add_query_arg( array( |
| 484 |
'post_type' => 'eshb_accomodation', |
| 485 |
'page' => 'eshb_bookings_calendar', |
| 486 |
), admin_url( 'edit.php' )); |
| 487 |
|
| 488 |
|
| 489 |
$period_select_field_dispaly = $current_booking_period != 'custom' ? 'none' : 'block'; |
| 490 |
|
| 491 |
$html = '<div class="eshb-calendar-filter">'; |
| 492 |
$html .= '<form action="'.$action_url.'" method="post" class="eshb-calendar-filter-form">'; |
| 493 |
$html .= $nonce_field; |
| 494 |
$html .= '<div class="eshb-calendar-filter-options">'; |
| 495 |
$html .= '<select id="eshb-calendar-filter-accomodation" name="accomodation-id">'; |
| 496 |
$html .= '<option value="">' . esc_html__('All Accomodations', 'easy-hotel') . '</option>'; |
| 497 |
foreach ($this->accomodations as $accomodation) { |
| 498 |
$html .= '<option value="' . esc_attr($accomodation['id']) . '" '. selected( $accomodation['id'], $current_accomodation, false ).'>' . esc_html($accomodation['name']) . '</option>'; |
| 499 |
} |
| 500 |
$html .= '</select>'; |
| 501 |
$html .= '<select id="eshb-calendar-filter-status" name="booking-status">'; |
| 502 |
$html .= '<option '. selected( '', $current_status, false ).' value="">' . esc_html__('All Statuses', 'easy-hotel') . '</option>'; |
| 503 |
$html .= '<option '. selected( 'pending', $current_status, false ).' value="pending">' . esc_html__('Pending', 'easy-hotel') . '</option>'; |
| 504 |
$html .= '<option '. selected( 'completed', $current_status, false ).' value="completed">' . esc_html__('Confirmed', 'easy-hotel') . '</option>'; |
| 505 |
$html .= '<option '. selected( 'blocked', $current_status, false ).' value="blocked">' . esc_html__('Blocked', 'easy-hotel') . '</option>'; |
| 506 |
$html .= '</select>'; |
| 507 |
$html .= '<div id="eshb-calendar-filter-period-wrapper">'; |
| 508 |
$html .= '<span>' . esc_html__('Period ', 'easy-hotel') . '</span> '; |
| 509 |
if($current_booking_period != 'custom') { |
| 510 |
$html .= '<input type="submit" name="action-prev-period" class="button period-navigator" value="Prev" />'; |
| 511 |
} |
| 512 |
$html .= '<select id="eshb-calendar-filter-period" name="booking-period">'; |
| 513 |
$html .= '<option '. selected( 'custom', $current_booking_period, false ) .' value="custom">' . esc_html__('Custom', 'easy-hotel') . '</option>'; |
| 514 |
$html .= '<option '. selected( 'month', $current_booking_period, false ) .' value="month">' . esc_html__('Month', 'easy-hotel') . '</option>'; |
| 515 |
$html .= '<option '. selected( 'quarter', $current_booking_period, false ) .' value="quarter">' . esc_html__('Quarter', 'easy-hotel') . '</option>'; |
| 516 |
$html .= '<option '. selected( 'year', $current_booking_period, false ) .' value="year">' . esc_html__('Year', 'easy-hotel') . '</option>'; |
| 517 |
$html .= '</select>'; |
| 518 |
if($current_booking_period != 'custom') { |
| 519 |
$html .= '<input type="submit" name="action-next-period" class="button period-navigator" value="Next" />'; |
| 520 |
} |
| 521 |
$html .= '<div id="eshb-calendar-filter-date-range" style="display:'. $period_select_field_dispaly .'">'; |
| 522 |
$html .= '<input type="date" name="start-date" class="eshb-datepicker" value="'. $calendar_settings['start'] .'"/> to '; |
| 523 |
$html .= '<input type="date" name="end-date" class="eshb-datepicker" value="'. $calendar_settings['end'] .'"/>'; |
| 524 |
$html .= '</div>'; |
| 525 |
$html .= '</div>'; |
| 526 |
$html .= '</div>'; |
| 527 |
|
| 528 |
$html .= '<div class="eshb-calendar-filter-actions">'; |
| 529 |
$html .= '<button type="submit" id="eshb-calendar-filter-apply" class="button button-primary">' . esc_html__('Apply Filter', 'easy-hotel') . '</button>'; |
| 530 |
$html .= '</div>'; |
| 531 |
|
| 532 |
$html .= '</form>'; |
| 533 |
$html .= '<div class="eshb-calendar-legends">'; |
| 534 |
$html .= '<legend class="legend-item complete" title="' . esc_html__('Confirmed', 'easy-hotel') . '"><span>' . esc_html__('Confirmed', 'easy-hotel') . '</span></legend>'; |
| 535 |
|
| 536 |
$html = apply_filters( 'eshb_calendar_legend', $html); |
| 537 |
|
| 538 |
$html .= '<legend class="legend-item pending" title="' . esc_html__('Pending', 'easy-hotel') . '"><span>' . esc_html__('Pending', 'easy-hotel') . '</span></legend>'; |
| 539 |
$html .= '<legend class="legend-item blocked" title="' . esc_html__('Blocked', 'easy-hotel') . '"><span>' . esc_html__('Blocked', 'easy-hotel') . '</span></legend>'; |
| 540 |
$html .= '</div>'; |
| 541 |
$html .= '</div>'; |
| 542 |
return $html; |
| 543 |
} |
| 544 |
|
| 545 |
public function render_booking_info_modal(){ |
| 546 |
?> |
| 547 |
<div id="eshb-booking-info-modal" class="modal"> |
| 548 |
<div class="booking-info-modal-bg-overlay"></div> |
| 549 |
<div class="booking-info-modal-main"> |
| 550 |
<div class="booking-info-modal-header"> |
| 551 |
<h2 class="booking-info-modal-bookig-details-title"><?php echo esc_html__( 'Booking Details', 'easy-hotel' ) ?></h2> |
| 552 |
<button class="booking-info-modal-close"> |
| 553 |
<span class="screen-reader-text"><?php echo esc_html__( 'Close popup panel', 'easy-hotel' ) ?></span> |
| 554 |
</button> |
| 555 |
</div> |
| 556 |
<div class="booking-info-modal-content"> |
| 557 |
<!-- contents will come by ajax --> |
| 558 |
</div> |
| 559 |
</div> |
| 560 |
|
| 561 |
</div> |
| 562 |
<?php |
| 563 |
} |
| 564 |
} |