diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 9e88e859..12d1deb0 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -8,6 +8,12 @@ class API extends CI_Controller { } + function test() { + $this->load->model('api_model'); + + echo $this->api_model->key_userid('cl61533ebc1fbfa'); + } + /* TODOs - Search Callsign (Return Json) @@ -476,8 +482,10 @@ class API extends CI_Controller { die(); } + $user_id = $this->api_model->key_userid($obj['key']); + // Store Result to Database - $this->cat->update($obj); + $this->cat->update($obj, $user_id); // Return Message diff --git a/application/models/Api_model.php b/application/models/Api_model.php index 21db4b45..28d0030d 100644 --- a/application/models/Api_model.php +++ b/application/models/Api_model.php @@ -28,6 +28,12 @@ class API_Model extends CI_Model { return $query->result_array()[0]; } + function key_userid($key) { + $this->db->where('key', $key); + $query = $this->db->get('api'); + + return $query->result_array()[0]['user_id']; + } function update_key_description($key, $description) { diff --git a/application/models/Cat.php b/application/models/Cat.php index d6426f21..60d15986 100644 --- a/application/models/Cat.php +++ b/application/models/Cat.php @@ -8,10 +8,10 @@ parent::__construct(); } - function update($result) { + function update($result, $user_id) { $this->db->where('radio', $result['radio']); - $this->db->where('user_id', $this->session->userdata('user_id')); + $this->db->where('user_id', $user_id); $query = $this->db->get('cat'); if ($query->num_rows() > 0) @@ -31,7 +31,7 @@ ); $this->db->where('id', $radio_id); - $this->db->where('user_id', $this->session->userdata('user_id')); + $this->db->where('user_id', $user_id); $this->db->update('cat', $data); } } else { @@ -64,7 +64,7 @@ 'uplink_freq' => $result['uplink_freq'], 'downlink_mode' => $result['downlink_mode'], 'uplink_mode' => $result['uplink_mode'], - 'user_id' => $this->session->userdata('user_id'), + 'user_id' => $user_id, ); } else { $data = array( @@ -72,7 +72,7 @@ 'frequency' => $result['frequency'], 'mode' => $result['mode'], 'timestamp' => $result['timestamp'], - 'user_id' => $this->session->userdata('user_id'), + 'user_id' => $user_id, ); }