diff --git a/src/application/controllers/Backend_api.php b/src/application/controllers/Backend_api.php index fb5abeff..2f5ae866 100644 --- a/src/application/controllers/Backend_api.php +++ b/src/application/controllers/Backend_api.php @@ -199,12 +199,16 @@ class Backend_api extends CI_Controller { } // Get appointments - $where_clause = [ - $where_id => $this->input->post('record_id'), - 'DATE(start_datetime) >=' => $this->input->post('start_date'), - 'DATE(start_datetime) <=' => date('Y-m-d', strtotime($this->input->post('end_date') . ' +1 day')), - 'is_unavailable' => FALSE - ]; + $record_id = $this->db->escape($_POST['record_id']); + $start_date = $this->db->escape($_POST['start_date']); + $end_date = $this->db->escape(date('Y-m-d', strtotime($_POST['end_date'] . ' +1 day'))); + + $where_clause = $where_id . ' = ' . $record_id . ' + AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ') + or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ') + or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . ')) + AND is_unavailable = 0 + '; $response['appointments'] = $this->appointments_model->get_batch($where_clause); @@ -218,12 +222,12 @@ class Backend_api extends CI_Controller { // Get unavailable periods (only for provider). if ($this->input->post('filter_type') == FILTER_TYPE_PROVIDER) { - $where_clause = [ - $where_id => $this->input->post('record_id'), - 'DATE(start_datetime) >=' => $this->input->post('start_date'), - 'DATE(start_datetime) <=' => date('Y-m-d', strtotime($this->input->post('end_date') . ' +1 day')), - 'is_unavailable' => TRUE - ]; + $where_clause = $where_id . ' = ' . $record_id . ' + AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ') + or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ') + or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . ')) + AND is_unavailable = 1 + '; $response['unavailables'] = $this->appointments_model->get_batch($where_clause); }