diff --git a/application/config/migration.php b/application/config/migration.php index 927c09f6..f0bf3d0f 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 76; +$config['migration_version'] = 77; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Radio.php b/application/controllers/Radio.php index d8c95838..2a2a5709 100755 --- a/application/controllers/Radio.php +++ b/application/controllers/Radio.php @@ -7,21 +7,21 @@ // Check Auth $this->load->model('user_model'); if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } - + // load the view - $data['page_title'] = "Radio Interface"; + $data['page_title'] = "Hardware Interfaces"; $this->load->view('interface_assets/header', $data); $this->load->view('radio/index'); $this->load->view('interface_assets/footer'); } - + function status() { - + // Check Auth $this->load->model('user_model'); if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } - + $this->load->model('cat'); $query = $this->cat->status(); if ($query->num_rows() > 0) @@ -58,14 +58,14 @@ echo "No CAT Interfaced radios found."; echo ""; } - + } function json($id) { header('Content-Type: application/json'); - + $this->load->model('cat'); $query = $this->cat->radio_status($id); @@ -97,8 +97,8 @@ } // Get Satellite Mode - $uplink_mode = $this->get_mode_designator($row->uplink_freq); - $downlink_mode = $this->get_mode_designator($row->downlink_freq); + $uplink_mode = $this->get_mode_designator($row->uplink_freq); + $downlink_mode = $this->get_mode_designator($row->downlink_freq); if ($uplink_mode != "" && $downlink_mode != "") { $sat_mode = $uplink_mode."/".$downlink_mode; @@ -119,7 +119,7 @@ $sat_mode = ""; } - // Calculate how old the data is in minutes + // Calculate how old the data is in minutes $datetime1 = new DateTime(); // Today's Date/Time $datetime2 = new DateTime($row->newtime); $interval = $datetime1->diff($datetime2); @@ -127,7 +127,7 @@ $minutes = $interval->days * 24 * 60; $minutes += $interval->h * 60; $minutes += $interval->i; - + $updated_at = $minutes; // Return Json data @@ -143,7 +143,7 @@ } } - + function get_mode_designator($frequency) { if ($frequency > 21000000 && $frequency < 22000000) @@ -176,13 +176,13 @@ // Check Auth $this->load->model('user_model'); if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } - + $this->load->model('cat'); - + $this->cat->delete($id); - + $this->session->set_flashdata('message', 'Radio Profile Deleted'); - + redirect('radio'); } diff --git a/application/migrations/077_add_userid_to_hardware.php b/application/migrations/077_add_userid_to_hardware.php new file mode 100644 index 00000000..8abba611 --- /dev/null +++ b/application/migrations/077_add_userid_to_hardware.php @@ -0,0 +1,20 @@ +dbforge->add_column('cat', $fields); + } + + public function down() + { + $this->dbforge->drop_column('cat', 'user_id'); + } +} diff --git a/application/models/Cat.php b/application/models/Cat.php index 2f92b788..d6426f21 100644 --- a/application/models/Cat.php +++ b/application/models/Cat.php @@ -9,10 +9,11 @@ } function update($result) { - - $this->db->where('radio', $result['radio']); + + $this->db->where('radio', $result['radio']); + $this->db->where('user_id', $this->session->userdata('user_id')); $query = $this->db->get('cat'); - + if ($query->num_rows() > 0) { if($result['radio'] == "SatPC32") { @@ -20,7 +21,7 @@ foreach ($query->result() as $row) { $radio_id = $row->id; - + $data = array( 'sat_name' => $result['sat_name'], 'downlink_freq' => $result['downlink_freq'], @@ -30,14 +31,15 @@ ); $this->db->where('id', $radio_id); - $this->db->update('cat', $data); + $this->db->where('user_id', $this->session->userdata('user_id')); + $this->db->update('cat', $data); } } else { // Update the record foreach ($query->result() as $row) { $radio_id = $row->id; - + $data = array( 'frequency' => $result['frequency'], 'mode' => $result['mode'], @@ -45,12 +47,13 @@ ); $this->db->where('id', $radio_id); - $this->db->update('cat', $data); + $this->db->where('user_id', $this->session->userdata('user_id')); + $this->db->update('cat', $data); } } } else { // Add a new record - + if($result['radio'] == "SatPC32") { $data = array( 'radio' => $result['radio'], @@ -61,6 +64,7 @@ 'uplink_freq' => $result['uplink_freq'], 'downlink_mode' => $result['downlink_mode'], 'uplink_mode' => $result['uplink_mode'], + 'user_id' => $this->session->userdata('user_id'), ); } else { $data = array( @@ -68,23 +72,25 @@ 'frequency' => $result['frequency'], 'mode' => $result['mode'], 'timestamp' => $result['timestamp'], + 'user_id' => $this->session->userdata('user_id'), ); } - $this->db->insert('cat', $data); + $this->db->insert('cat', $data); } } - - + function status() { - //$this->db->where('radio', $result['radio']); + //$this->db->where('radio', $result['radio']); + $this->db->where('user_id', $this->session->userdata('user_id')); $query = $this->db->get('cat'); - + return $query; } function recent_status() { + $this->db->where('user_id', $this->session->userdata('user_id')); $this->db->where("timestamp > date_sub(now(), interval 15 minute)", NULL, FALSE); $query = $this->db->get('cat'); @@ -94,27 +100,23 @@ /* Return list of radios */ function radios() { $this->db->select('id, radio'); + $this->db->where('user_id', $this->session->userdata('user_id')); $query = $this->db->get('cat'); - + return $query; } - function radio_status($id) { - - return $this->db->query('SELECT *, CONVERT_TZ(`timestamp`, @@session.time_zone, \'+00:00\' ) as newtime FROM `cat` WHERE id = '.$id.' '); - + $sql = 'SELECT *, CONVERT_TZ(`timestamp`, @@session.time_zone, \'+00:00\' ) as newtime FROM `cat` WHERE id = ' . $id . ' and user_id =' . $this->session->userdata('user_id'); + return $this->db->query($sql); } - function delete($id) { $this->db->where('id', $id); - $this->db->delete('cat'); - + $this->db->where('user_id', $this->session->userdata('user_id')); + $this->db->delete('cat'); + return true; } - - - } ?>