public function res_admin_insert_out_of_work_callback() { // Check if user is logged in or die Resource_Booking_Ajax_Common::check_if_user_logged_in_or_die(); // Check if user is a labmanager or die Resource_Booking_Ajax_Common::check_if_labmanager_or_die(); // If here, user is labmanager (hopefully) $resource_id = isset($_POST['resource_id']) ? $_POST['resource_id'] : 'none'; $type = isset($_POST['type']) ? $_POST['type'] : 'none'; $reason = isset($_POST['reason']) ? intval($_POST['reason']) : 0; $start = isset($_POST['start']) ? $_POST['start'] : null; $end = isset($_POST['end']) ? $_POST['end'] : null; Resource_Booking_Ajax_Common::check_if_valid_date_with_time_or_die($start); Resource_Booking_Ajax_Common::check_if_valid_date_with_time_or_die($end); if ('none' == $resource_id && 'none' == $type) { // And die wp_send_json_error(array("message" => "Select at least a resource or a type")); } if ('none' != $resource_id && 'none' != $type) { // And die wp_send_json_error(array("message" => "Select only a resource or a type")); } $reason_string = ""; switch ($reason) { case 0: break; case 1: $reason_string = "Clean room closed"; break; case 2: $reason_string = "Resource out of work"; break; case 3: $reason_string = "Holiday"; break; default: wp_send_json_error(array("message" => "Wrong reason")); } $resources = array(); if ('none' != $resource_id) { // Resource selected if ('all' == $resource_id) { //Check if resource exists $resourcesA = $this->rb_db->get_resources_list(); foreach ($resourcesA as $resource) { $resource_id = $resource->resource_id; $resource_info = Resource_Booking_Ajax_Common::get_resource_info_or_die($this->rb_db, $resource_id, "array"); $resources[] = $resource_info; } } else { $resource_id = intval($resource_id, 10); $resource_info = Resource_Booking_Ajax_Common::get_resource_info_or_die($this->rb_db, $resource_id, "array"); $resources[] = $resource_info; } } else { // Type selected $resourcesA = $this->rb_db->get_resources_list($type); foreach ($resourcesA as $resource) { $resource_id = $resource->resource_id; $resource_info = Resource_Booking_Ajax_Common::get_resource_info_or_die($this->rb_db, $resource_id, "array"); $resources[] = $resource_info; } } foreach ($resources as $resource) { $resource_id = $resource->resourceInfo["resource_id"]; $bookingsA = $this->rb_db->list_bookings_by_resource_id_start_end($resource_id, $start, $end); foreach ($bookingsA as $booking) { $booking_id = $booking->id; $this->rb_db->delete_booking($booking_id, $resource_id, null); } if ($reason != 0) { $booking = $this->rb_db->insert_booking($resource_id, 1, $reason_string, $start, $end, $reason_string, $reason); } } $response = new StdClass(); $response->success = true; echo json_encode($response); wp_die(); }
public function res_resource_info_callback() { // Check if user is logged in or die Resource_Booking_Ajax_Common::check_if_user_logged_in_or_die(); $resource_id = isset($_POST['resource_id']) ? intval($_POST['resource_id'], 10) : 0; // Validation will be done in the next function Resource_Booking_Ajax_Common::get_resource_info_or_die($this->rb_db, $resource_id, 'json'); }