diff --git a/application/controllers/Oqrs.php b/application/controllers/Oqrs.php index 46fde176..f7830889 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'); @@ -159,11 +160,13 @@ class Oqrs extends CI_Controller { } $data['callsign'] = $this->security->xss_clean($postdata['callsign']); + $data['usermessage'] = $this->security->xss_clean($postdata['message']); $message = $this->load->view('email/oqrs_request', $data, TRUE); $this->email->from('noreply@cloudlog.co.uk', 'Cloudlog'); $this->email->to($email); + $this->email->reply_to($this->security->xss_clean($postdata['email']), strtoupper($data['callsign'])); $this->email->subject('Cloudlog OQRS from ' . strtoupper($data['callsign'])); $this->email->message($message); @@ -182,4 +185,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..0cc87564 100644 --- a/application/models/Oqrs_model.php +++ b/application/models/Oqrs_model.php @@ -50,7 +50,7 @@ class Oqrs_model extends CI_Model { $callsign = $this->security->xss_clean($callsign); $sql = 'select lower(col_mode) col_mode, coalesce(col_submode, "") col_submode, col_band from ' . $this->config->item('table_name') . ' where station_id = ' . $station_id . ' and col_call ="' . $callsign . '" and col_prop_mode != "SAT"'; - $sql .= ' union select lower(col_mode) col_mode, coalesce(col_submode, "") col_submode, "SAT" col_band from ' . $this->config->item('table_name') . ' where station_id = ' . $station_id . ' and col_call ="' . $callsign . '" and col_prop_mode = "SAT"'; + $sql .= ' union all select lower(col_mode) col_mode, coalesce(col_submode, "") col_submode, "SAT" col_band from ' . $this->config->item('table_name') . ' where station_id = ' . $station_id . ' and col_call ="' . $callsign . '" and col_prop_mode = "SAT"'; $query = $this->db->query($sql); @@ -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,57 @@ 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 ($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']; + } - if ($query->num_rows() > 0) { - return true; + $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'); + } + + public function oqrs_requests($location_list) { + if ($location_list != "") { + $sql = 'SELECT COUNT(*) AS number FROM oqrs JOIN station_profile ON oqrs.station_id = station_profile.station_id WHERE oqrs.station_id IN ('.$location_list.') AND status < 2'; + $query = $this->db->query($sql); + $row = $query->row(); + return $row->number; } else { - return false; + return 0; } } } diff --git a/application/views/email/oqrs_request.php b/application/views/email/oqrs_request.php index 1518fc85..c35ec6cc 100644 --- a/application/views/email/oqrs_request.php +++ b/application/views/email/oqrs_request.php @@ -1,8 +1,14 @@ Hi, -You got an OQRS request from . +You got an OQRS request from . + +The user entered the following message: + + + + Please log into your Cloudlog and process it. Regards, -Cloudlog. \ No newline at end of file +Cloudlog. diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index 6263f796..22b125ad 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -229,7 +229,18 @@
- OQRS Requests +load->model('oqrs_model'); +$CI->load->model('logbooks_model'); +$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); +if ($logbooks_locations_array) { + $location_list = "'".implode("','",$logbooks_locations_array)."'"; +} else { + $location_list = null; +} +?> + OQRS Requests oqrs_model->oqrs_requests($location_list) > 0) { echo "".$CI->oqrs_model->oqrs_requests($location_list).""; } ?> Print Requested QSLs 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 @@ -