/** * custom_init() * * Process booking post data * * @param none * @return none */ public function custom_init() { $action = browser_request('action'); if ($action != '') { switch ($action) { case 'check_availability': $data = $_POST; push_to_booking_session(array('date_in' => array_data($data, 'date_in', date('Y-m-d')), 'date_out' => array_data($data, 'date_out', add_days_to_date(date('Y-m-d'), 1)), 'no_of_adult' => array_data($data, 'no_of_adult', 1), 'no_of_room' => array_data($data, 'no_of_room', 0), 'type' => 'BOOKING', 'no_of_child' => array_data($data, 'no_of_child', 0))); redirect_by_page_path('rooms'); break; case 'book_room': $data = $_POST; if (array_data($data, 'room_type_ID', '') == '' || !is_bookable($data['room_type_ID'])) { add_this_notices('error', 'Selected room is Out of Order.'); return; } if (is_date_and_room_not_available($data['room_type_ID'], format_db_date($data['date_in']), format_db_date($data['date_out']))) { return; } if (!has_sufficient_room($data)) { return; } $nights = count_nights($data['date_in'], $data['date_out']); $room_price = get_room_price_with_nights($data['room_type_ID'], $data['date_in'], $data['date_out']); $total_amount = calculate_total_amount($data['room_type_ID'], $data['date_in'], $data['date_out'], $data['no_of_room']); push_to_booking_session(array('date_in' => $data['date_in'], 'date_out' => $data['date_out'], 'no_of_adult' => $data['no_of_adult'], 'no_of_child' => array_data($data, 'no_of_child', 0), 'room_type_ID' => $data['room_type_ID'], 'no_of_night' => $nights, 'no_of_room' => $data['no_of_room'], 'room_price' => $room_price, 'amount' => $total_amount, 'booking_ID' => 0, 'amount_paid' => 0, 'payment_status' => PAYMENT_DEFAULT_STATUS, 'booking_status' => BOOKING_DEFAULT_STATUS)); redirect_by_page_path('review'); break; case 'make_reservation': if (is_empty_booking()) { add_this_notices('error', 'Please select date.'); redirect_by_page_path('/'); return; } $data = get_booking_session(); if (!is_bookable($data['room_type_ID'])) { add_this_notices('error', 'Selected room is Out of Order.'); return; } $data = push_to_booking_session(array_merge($data, $_POST, array('date_booked' => date('Y-m-d H:i:s')))); if ($this->process($data)) { redirect_by_page_path('success'); } break; case 'save_booking': if (isset($_POST['save_booking_field']) && wp_verify_nonce($_POST['save_booking_field'], 'save_booking_action')) { $info = get_booking_by_id(browser_request('bid', 0)); $post = array_merge((array) $info, $_POST); $post['no_of_night'] = count_nights($post['date_in'], $post['date_out']); $post['room_price'] = get_room_price_with_nights($post['room_type_ID'], $post['date_in'], $post['date_out']); $post['amount'] = calculate_total_amount($post['room_type_ID'], $post['date_in'], $post['date_out'], $post['no_of_room']); $post['date_booked'] = array_data($info, 'date_booked', date('Y-m-d H:i:s')); $post['type'] = 'RESERVATION'; $post['room_code'] = room_code($post['room_type_ID']); if (($bid = $this->process($post)) != false) { exit(wp_redirect('admin.php?page=edit-booking&bid=' . $bid)); } } break; case 'export-bookings': $results = get_bookings_for_export(); // When executed in a browser, this script will prompt for download // of 'test.xls' which can then be opened by Excel or OpenOffice. require_class('php-export-data.class.php'); // 'browser' tells the library to stream the data directly to the browser. // other options are 'file' or 'string' // 'test.xls' is the filename that the browser will use when attempting to // save the download $exporter = new ExportDataExcel('browser', 'reports.xls'); $exporter->initialize(); // starts streaming data to web browser $exporter->addRow(array('BOOKING NO', 'ROOM TYPE', 'ROOM PRICE', 'CHECK IN', 'CHECK OUT', 'NO OF NIGHTS', 'NO OF ROOMS', 'TOTAL AMOUNT', 'AMOUNT PAID', 'NO OF ADULT', 'NO OF CHILD', 'BOOKED BY', 'BIRTHDATE', 'EMAIL ADDRESS', 'PHONE', 'COUNTRY', 'ADDRESS 1', 'ADDRESS 2', 'PROVINCE', 'CITY', 'ZIPCODE', 'NATIONALITY', 'BOOKING STATUS', 'PAYMENT STATUS', 'DATE BOOKED')); foreach ($results as $i => $r) { // pass addRow() an array and it converts it to Excel XML format and sends // it to the browser $exporter->addRow($r); } $exporter->finalize(); // writes the footer, flushes remaining data to browser. exit; // all done break; } } }
function is_date_and_room_not_available($room_ID, $from, $to, $booking_ID = 0) { $range = get_dates_from_date_range($from, $to); foreach ($range as $i => $k) { if (is_selected_date_and_room_not_available($room_ID, format_db_date($k), $booking_ID) > 0) { add_this_notices('error', 'Selected room is not available on that date. Please check calendar to see availability.'); return true; } } return false; }