/**
  * Retrieve query results
  *
  * @since 1.4.1
  */
 public function get_bookings()
 {
     $bookings = array();
     $args = apply_filters('rtb_query_args', $this->args, $this->context);
     $query = new WP_Query($args);
     if ($query->have_posts()) {
         require_once RTB_PLUGIN_DIR . '/includes/Booking.class.php';
         while ($query->have_posts()) {
             $query->the_post();
             $booking = new rtbBooking();
             if ($booking->load_post($query->post)) {
                 $bookings[] = $booking;
             }
         }
     }
     $this->bookings = $bookings;
     return $this->bookings;
 }
 /**
  * Handle ajax requests to send an email
  *
  * @since 1.3.1
  */
 public function email_modal_ajax()
 {
     global $rtb_controller;
     // Authenticate request
     if (!check_ajax_referer('rtb-admin', 'nonce') || !current_user_can('manage_bookings')) {
         $this->nopriv_ajax();
     }
     // Set up $_POST object for validation
     foreach ($_POST['email'] as $field) {
         $_POST[$field['name']] = $field['value'];
     }
     $id = (int) $_POST['ID'];
     $name = sanitize_text_field($_POST['name']);
     $email = sanitize_text_field($_POST['email']);
     $subject = stripcslashes(sanitize_text_field($_POST['rtb-email-subject']));
     $message = stripcslashes(wp_kses_post($_POST['rtb-email-message']));
     if (empty($message)) {
         wp_send_json_error(array('error' => 'email_missing_message', 'msg' => __('Please enter a message before sending the email.', 'restaurant-reservations')));
     }
     if (empty($id) || empty($name) || empty($email)) {
         wp_send_json_error(array('error' => 'email_missing_data', 'msg' => __('The email could not be sent because some critical information was missing.', 'restaurant-reservations')));
     }
     require_once RTB_PLUGIN_DIR . '/includes/Booking.class.php';
     $booking = new rtbBooking();
     if (!$booking->load_post($id)) {
         wp_send_json_error(array('error' => 'email_missing_booking', 'msg' => __('There was an error loading the booking and the email was not sent.', 'restaurant-reservations')));
     }
     $email = new rtbNotificationEmail('admin_email_notice', 'user');
     $email->subject = empty($subject) ? $rtb_controller->settings->get_setting('subject-admin-notice') : $subject;
     $email->message = $message;
     $email->set_booking($booking);
     if ($email->prepare_notification()) {
         $email->send_notification();
     }
     // Store email in postmeta for log
     $booking->add_log('email', $email->subject, $email->message);
     $booking->insert_post_data();
     wp_send_json_success();
 }
 /**
  * Retrieve all the data for all the bookings
  * @since 0.0.1
  */
 public function bookings_data()
 {
     $args = array('post_type' => RTB_BOOKING_POST_TYPE, 'posts_per_page' => $this->per_page, 'paged' => isset($_GET['paged']) ? $_GET['paged'] : 1, 'post_status' => isset($_GET['status']) ? $_GET['status'] : array('confirmed', 'pending', 'closed'));
     if (isset($_GET['orderby'])) {
         $args['orderby'] = $_GET['orderby'];
     }
     $args['order'] = isset($_GET['order']) ? $_GET['order'] : 'ASC';
     if ($this->filter_start_date !== null || $this->filter_end_date !== null) {
         $date_query = array();
         if ($this->filter_start_date !== null) {
             $date_query['after'] = $this->filter_start_date;
         }
         if ($this->filter_end_date !== null) {
             $date_query['before'] = $this->filter_end_date;
         }
         if (count($date_query)) {
             $args['date_query'] = $date_query;
         }
     } elseif (isset($_GET['schedule'])) {
         if ($_GET['schedule'] == 'today') {
             $today = getdate();
             $args['year'] = $today['year'];
             $args['monthnum'] = $today['mon'];
             $args['day'] = $today['mday'];
         }
         if ($_GET['schedule'] == 'upcoming') {
             $args['date_query'] = array(array('after' => '-1 hour'));
             if (empty($_GET['order'])) {
                 $args['order'] = 'ASC';
             }
         }
     }
     $args = apply_filters('rtb_bookings_table_query_args', $args);
     // Make query
     $query = new WP_Query($args);
     if ($query->have_posts()) {
         while ($query->have_posts()) {
             $query->the_post();
             require_once RTB_PLUGIN_DIR . '/includes/Booking.class.php';
             $booking = new rtbBooking();
             if ($booking->load_post($query->post)) {
                 $this->bookings[] = $booking;
             }
         }
     }
 }