public function save_rooms_and_guest_info() { if (defined('DOING_AJAX') && DOING_AJAX && $_POST) { $data = $_POST; if (is_rooms_exists_on_booking($data['room_ID'], $data['booking_ID'], $data['booking_room_ID'])) { wp_send_json_error(array('message' => 'Room already exists')); } else { require_class('gump.class.php'); $gump = new GUMP(); $data['room_type_ID'] = get_room_type($data['room_ID'])->ID; $data = $gump->sanitize($data); $gump->validation_rules(array('guest' => 'required|min_len,1|max_len,100', 'room_ID' => 'required|numeric', 'room_type_ID' => 'required|numeric', 'no_of_adult' => 'required|numeric', 'no_of_child' => 'numeric', 'date_in' => 'required|date', 'date_out' => 'required|date')); if ($gump->run($data) !== false) { if (in_array(get_booking_status($data['booking_ID']), array('NEW'))) { wp_send_json_error(array('message' => 'You can\'t add room while booking is not confirmed.')); } else { if (is_room_available($data['room_ID'], $data['date_in'], $data['booking_room_ID']) == 0) { $error['date_in'] = 'Selected room is not available on that date. Please check calendar to see availability.'; javacript_notices($error, '#roomsAndGuestInfoForm'); wp_send_json_error(array('js' => print_javascript_notices(false))); } else { if (do_save_rooms_and_guest_info($data) !== false) { wp_send_json_success(array('message' => 'Successfully saved.')); } else { wp_send_json_error(array('message' => 'Error while saving.')); } } } } else { javacript_notices($gump->get_key_and_value_errors(true), '#roomsAndGuestInfoForm'); wp_send_json_error(array('js' => print_javascript_notices(false))); } } exit; } }