diff --git a/application/controllers/Oqrs.php b/application/controllers/Oqrs.php index 46fde176..3500ad1d 100644 --- a/application/controllers/Oqrs.php +++ b/application/controllers/Oqrs.php @@ -91,6 +91,7 @@ class Oqrs extends CI_Controller { $this->load->model('oqrs_model'); $data['result'] = $this->oqrs_model->getOqrsRequests($location_list); + $data['stations'] = $this->oqrs_model->get_oqrs_stations(); $this->load->view('interface_assets/header', $data); $this->load->view('oqrs/showrequests'); @@ -182,4 +183,21 @@ class Oqrs extends CI_Controller { $this->oqrs_model->mark_oqrs_line_as_done($id); } + + public function search() { + $this->load->model('oqrs_model'); + + $searchCriteria = array( + 'user_id' => (int)$this->session->userdata('user_id'), + 'de' => xss_clean($this->input->post('de')), + 'dx' => xss_clean($this->input->post('dx')), + 'status' => xss_clean($this->input->post('status')), + 'oqrsResults' => xss_clean($this->input->post('oqrsResults')), + ); + + $qsos = $this->oqrs_model->searchOqrs($searchCriteria); + + header("Content-Type: application/json"); + print json_encode($qsos); + } } diff --git a/application/models/Oqrs_model.php b/application/models/Oqrs_model.php index 7736b1e5..553f026d 100644 --- a/application/models/Oqrs_model.php +++ b/application/models/Oqrs_model.php @@ -84,7 +84,7 @@ class Oqrs_model extends CI_Model { } function getOqrsRequests($location_list) { - $sql = 'select * from oqrs join station_profile on oqrs.station_id = station_profile.station_id where oqrs.station_id in (' . $location_list . ') and oqrs.status < 2'; + $sql = 'select * from oqrs join station_profile on oqrs.station_id = station_profile.station_id where oqrs.station_id in (' . $location_list . ')'; $query = $this->db->query($sql); @@ -251,15 +251,46 @@ class Oqrs_model extends CI_Model { return ''; } - function getOqrsStationsFromSlug($logbook_id) { - $sql = 'SELECT station_callsign FROM `station_logbooks_relationship` JOIN `station_profile` ON station_logbooks_relationship.station_location_id = station_profile.station_id WHERE station_profile.oqrs = 1 AND station_logbook_id = '.$logbook_id.';'; + /* + * @param array $searchCriteria + * @return array + */ + public function searchOqrs($searchCriteria) : array { + $conditions = []; + $binding = [$searchCriteria['user_id']]; - $query = $this->db->query($sql); - - if ($query->num_rows() > 0) { - return true; - } else { - return false; + if ($searchCriteria['de'] !== '') { + $conditions[] = "station_profile.STATION_CALLSIGN = ?"; + $binding[] = trim($searchCriteria['de']); } + if ($searchCriteria['dx'] !== '') { + $conditions[] = "oqrs.requestcallsign LIKE ?"; + $binding[] = '%' . trim($searchCriteria['dx']) . '%'; + } + if ($searchCriteria['status'] !== '') { + $conditions[] = "oqrs.status = ?"; + $binding[] = $searchCriteria['status']; + } + + $where = trim(implode(" AND ", $conditions)); + if ($where != "") { + $where = "AND $where"; + } + + $limit = $searchCriteria['oqrsResults']; + + $sql = " + SELECT * + FROM oqrs + INNER JOIN station_profile ON oqrs.station_id=station_profile.station_id + WHERE station_profile.user_id = ? + $where + ORDER BY oqrs.id + LIMIT $limit + "; + + $data = $this->db->query($sql, $binding); + + return $data->result('array'); } -} +} \ No newline at end of file diff --git a/application/views/oqrs/showrequests.php b/application/views/oqrs/showrequests.php index cdd18674..583ae530 100644 --- a/application/views/oqrs/showrequests.php +++ b/application/views/oqrs/showrequests.php @@ -1,126 +1,123 @@ -