diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 2eaf99a7..c5a650d4 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -158,6 +158,30 @@ class API extends CI_Controller { } } + function station_info($key) { + $this->load->model('api_model'); + $this->load->model('stations'); + header("Content-type: application/json"); + if(substr($this->api_model->access($key),0,1) == 'r') { /* Checkpermission for _r_eading */ + $this->api_model->update_last_used($key); + $userid = $this->api_model->key_userid($key); + $station_ids = array(); + $stations=$this->stations->all_of_user($userid); + foreach ($stations->result() as $row) { + $result['station_id']=$row->station_id; + $result['station_profile_name']=$row->station_profile_name; + $result['station_gridsquare']=$row->station_gridsquare; + $result['station_callsign']=$row->station_callsign;; + $result['station_active']=$row->station_active; + array_push($station_ids, $result); + } + echo json_encode($station_ids); + } else { + http_response_code(401); + echo json_encode(['status' => 'failed', 'reason' => "missing or invalid api key"]); + } + } + // FUNCTION: search() // Handle search requests /* diff --git a/application/models/Stations.php b/application/models/Stations.php index dca8cd88..17ae2008 100644 --- a/application/models/Stations.php +++ b/application/models/Stations.php @@ -23,9 +23,12 @@ class Stations extends CI_Model { return $this->db->get(); } - function all_of_user() { + function all_of_user($userid = null) { + if ($userid == null) { + $userid=$this->session->userdata('user_id'); // Fallback to session-uid, if userid is omitted + } $this->db->select('station_profile.*, dxcc_entities.name as station_country, dxcc_entities.end as dxcc_end'); - $this->db->where('user_id', $this->session->userdata('user_id')); + $this->db->where('user_id', $userid); $this->db->join('dxcc_entities','station_profile.station_dxcc = dxcc_entities.adif','left outer'); return $this->db->get('station_profile'); }