function gdlrs_get_reservation_bar($single_form = false)
 {
     global $hostel_option;
     $ret = '<form class="gdlr-reservation-bar" id="gdlr-reservation-bar" data-action="gdlr_hostel_booking" ';
     $ret .= $single_form ? 'method="post" action="' . esc_url(add_query_arg(array($hostel_option['booking-slug'] => ''), home_url('/'))) . '" ' : '';
     $ret .= ' >';
     $ret .= '<div class="gdlr-reservation-bar-title">' . __('Your Reservation', 'gdlr-hotel') . '</div>';
     if (!empty($_GET['state']) && $_GET['state'] == 4 && !empty($_GET['invoice'])) {
         global $wpdb;
         $temp_sql = "SELECT contact_info, booking_data FROM " . $wpdb->prefix . "gdlr_hostel_payment ";
         $temp_sql .= "WHERE id = " . $_GET['invoice'];
         $result = $wpdb->get_row($temp_sql);
         $data = unserialize($result->booking_data);
         $contact = unserialize($result->contact_info);
         $ret .= '<div class="gdlr-reservation-bar-summary-form" id="gdlr-reservation-bar-summary-form" style="display: block;">';
         $ret .= gdlrs_get_summary_form($data, false, $contact['coupon']);
         $ret .= '</div>';
     } else {
         $ret .= '<div class="gdlr-reservation-bar-summary-form" id="gdlr-reservation-bar-summary-form"></div>';
         if (!empty($_POST['hotel_data'])) {
             $ret .= '<div class="gdlr-reservation-bar-room-form gdlr-active" id="gdlr-reservation-bar-room-form" style="display: block;">';
             $ret .= gdlrs_get_reservation_room_form($_POST, 0);
             $ret .= '</div>';
         } else {
             $ret .= '<div class="gdlr-reservation-bar-room-form" id="gdlr-reservation-bar-room-form"></div>';
         }
         $ret .= '<div class="gdlr-reservation-bar-date-form" id="gdlr-reservation-bar-date-form">';
         $ret .= gdlrs_get_reservation_date_form($single_form);
         $ret .= '</div>';
         $ret .= '<div class="gdlr-reservation-bar-service-form" id="gdlr-reservation-bar-service-form"></div>';
     }
     if ($single_form) {
         $ret .= '<input type="hidden" name="single-room" value="' . get_the_ID() . '" />';
     } else {
         if (!empty($_POST['single-room'])) {
             $ret .= '<input type="hidden" name="single-room" value="' . $_POST['single-room'] . '" />';
         }
     }
     $ret .= '</form>';
     return $ret;
 }
 function gdlr_ajax_hostel_booking()
 {
     if (!empty($_POST['data'])) {
         parse_str($_POST['data'], $data);
     }
     if (!empty($_POST['contact'])) {
         parse_str($_POST['contact'], $contact);
     }
     if (!empty($_POST['service'])) {
         parse_str($_POST['service'], $service);
         $data['service'] = empty($service['service-select']) ? array() : $service['service-select'];
         $data['service-amount'] = empty($service['service-amount']) ? array() : $service['service-amount'];
     } else {
         if (empty($data['service'])) {
             $data['service'] = array();
             $data['service-amount'] = array();
         }
     }
     $ret = array();
     // query section
     if ($_POST['state'] == 2) {
         $data['gdlr-room-id'] = empty($data['gdlr-room-id']) ? array() : $data['gdlr-room-id'];
         // check and fill people for private room
         if (!empty($_POST['room_id'])) {
             $post_option = json_decode(gdlr_decode_preventslashes(get_post_meta($_POST['room_id'], 'post-option', true)), true);
             if (!empty($post_option['room-type']) && $post_option['room-type'] == 'private') {
                 $guest_pos = intval($post_option['room-amount']) - 1;
                 for ($i = 0; $i < intval($data['gdlr-room-number']); $i++) {
                     if ($guest_pos <= 0) {
                         break;
                     }
                     if (empty($data['gdlr-room-id'][$i])) {
                         $data['gdlr-room-id'][$i] = $_POST['room_id'];
                         $guest_pos--;
                     }
                 }
             }
         }
         $room_number = gdlrs_get_edited_room($data['gdlr-room-number'], $data['gdlr-room-id']);
         // room form
         $ret['room_form'] = gdlrs_get_reservation_room_form($data, $room_number);
         // content area
         if (empty($data['gdlr-check-in']) || empty($data['gdlr-check-out']) || $data['gdlr-check-out'] < $data['gdlr-check-in']) {
             $ret['content'] = '<div class="gdlr-room-selection-complete">';
             $ret['content'] .= '<div class="gdlr-room-selection-title" >' . __('Date field invalid', 'gdlr-hotel') . '</div>';
             $ret['content'] .= '<div class="gdlr-room-selection-content" >' . __('Please select \'check in\' and \'check out\' date from reservation bar again.', 'gdlr-hotel') . '</div>';
             $ret['content'] .= '</div>';
         } else {
             if ($data['gdlr-room-number'] > $room_number) {
                 $ret['content'] = gdlrs_get_booking_room_query($data, $room_number);
             } else {
                 $data['gdlr-hotel-branches'] = empty($data['gdlr-hotel-branches']) ? '' : $data['gdlr-hotel-branches'];
                 $ret['content'] = '<div class="gdlr-room-selection-complete">';
                 $ret['content'] .= '<div class="gdlr-room-selection-title" >' . __('Room Selection is Complete', 'gdlr-hotel') . '</div>';
                 $ret['content'] .= '<div class="gdlr-room-selection-caption" >' . __('You can edit your booking by using the panel on the left', 'gdlr-hotel') . '</div>';
                 $ret['content'] .= gdlrs_get_booking_services($data['gdlr-hotel-branches'], $data['service']);
                 $ret['content'] .= '<div class="gdlr-room-selection-divider" ></div>';
                 $ret['content'] .= '<a class="gdlr-button with-border gdlr-room-selection-next">' . __('Go to next step', 'gdlr-hotel') . '</a>';
                 $ret['content'] .= '</div>';
             }
         }
         $ret['state'] = 2;
     } else {
         if ($_POST['state'] == 3) {
             if (!empty($data['service'])) {
                 $ret['service'] = '';
                 foreach ($data['service'] as $key => $service_id) {
                     $ret['service'] .= '<input type="hidden" name="service[]" value="' . $service_id . '" />';
                     $ret['service'] .= '<input type="hidden" name="service-amount[]" value="' . $data['service-amount'][$key] . '" />';
                 }
             } else {
                 $ret['service'] = '<input type="hidden" />';
             }
             if (empty($_POST['contact'])) {
                 $ret['summary_form'] = gdlrs_get_summary_form($data);
                 $ret['content'] = gdlrs_get_booking_contact_form();
                 $ret['state'] = 3;
             } else {
                 $validate = gdlr_validate_contact_form($contact);
                 if (!empty($validate)) {
                     $ret['state'] = 3;
                     $ret['error_message'] = $validate;
                 } else {
                     $ret['summary_form'] = gdlrs_get_summary_form($data, false);
                     if ($_POST['contact_type'] == 'contact') {
                         $booking = gdlrs_insert_booking_db(array('data' => $data, 'contact' => $contact, 'payment_status' => 'booking'));
                         global $hostel_option;
                         $mail_content = gdlr_hostel_mail_content($contact, $data, array(), array('total_price' => $booking['total-price'], 'pay_amount' => 0, 'booking_code' => $booking['code']));
                         gdlr_hostel_mail($contact['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content);
                         gdlr_hostel_mail($hostel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content);
                         $ret['content'] = gdlrs_booking_complete_message();
                         $ret['state'] = 4;
                     } else {
                         global $hostel_option;
                         $booking = gdlrs_insert_booking_db(array('data' => $data, 'contact' => $contact, 'payment_status' => 'pending'));
                         if ($contact['payment-method'] == 'paypal') {
                             $ret['payment'] = 'paypal';
                             $ret['payment_url'] = $hostel_option['paypal-action-url'];
                             $ret['addition_part'] = gdlrs_additional_paypal_part(array('title' => __('Room Booking', 'gdlr-hotel'), 'invoice' => $booking['invoice'], 'price' => $booking['pay-amount']));
                         } else {
                             if ($contact['payment-method'] == 'stripe') {
                                 $ret['content'] = gdlrs_get_stripe_form(array('invoice' => $booking['invoice']));
                             } else {
                                 if ($contact['payment-method'] == 'paymill') {
                                     $ret['content'] = gdlrs_get_paymill_form(array('invoice' => $booking['invoice']));
                                 } else {
                                     if ($contact['payment-method'] == 'authorize') {
                                         $ret['content'] = gdlrs_get_authorize_form(array('invoice' => $booking['invoice'], 'price' => $booking['pay-amount']));
                                     }
                                 }
                             }
                         }
                         // made payment
                         $ret['state'] = 3;
                     }
                 }
             }
         }
     }
     if (!empty($data)) {
         $ret['data'] = $data;
     }
     die(json_encode($ret));
 }