kopia lustrzana https://github.com/magicbug/Cloudlog
Merge pull request #1188 from AndreasK79/userid_hardware
[Hardware] Added userid to everything that has to do with hardware.pull/1189/head^2
commit
d65f608439
|
@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE;
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$config['migration_version'] = 76;
|
$config['migration_version'] = 77;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
@ -7,21 +7,21 @@
|
||||||
// Check Auth
|
// Check Auth
|
||||||
$this->load->model('user_model');
|
$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'); }
|
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||||
|
|
||||||
// load the view
|
// load the view
|
||||||
$data['page_title'] = "Radio Interface";
|
$data['page_title'] = "Hardware Interfaces";
|
||||||
|
|
||||||
$this->load->view('interface_assets/header', $data);
|
$this->load->view('interface_assets/header', $data);
|
||||||
$this->load->view('radio/index');
|
$this->load->view('radio/index');
|
||||||
$this->load->view('interface_assets/footer');
|
$this->load->view('interface_assets/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
function status() {
|
function status() {
|
||||||
|
|
||||||
// Check Auth
|
// Check Auth
|
||||||
$this->load->model('user_model');
|
$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'); }
|
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->load->model('cat');
|
||||||
$query = $this->cat->status();
|
$query = $this->cat->status();
|
||||||
if ($query->num_rows() > 0)
|
if ($query->num_rows() > 0)
|
||||||
|
@ -58,14 +58,14 @@
|
||||||
echo "<td colspan=\"4\">No CAT Interfaced radios found.</td>";
|
echo "<td colspan=\"4\">No CAT Interfaced radios found.</td>";
|
||||||
echo "</tr>";
|
echo "</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function json($id)
|
function json($id)
|
||||||
{
|
{
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
$this->load->model('cat');
|
$this->load->model('cat');
|
||||||
|
|
||||||
$query = $this->cat->radio_status($id);
|
$query = $this->cat->radio_status($id);
|
||||||
|
@ -97,8 +97,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Satellite Mode
|
// Get Satellite Mode
|
||||||
$uplink_mode = $this->get_mode_designator($row->uplink_freq);
|
$uplink_mode = $this->get_mode_designator($row->uplink_freq);
|
||||||
$downlink_mode = $this->get_mode_designator($row->downlink_freq);
|
$downlink_mode = $this->get_mode_designator($row->downlink_freq);
|
||||||
|
|
||||||
if ($uplink_mode != "" && $downlink_mode != "") {
|
if ($uplink_mode != "" && $downlink_mode != "") {
|
||||||
$sat_mode = $uplink_mode."/".$downlink_mode;
|
$sat_mode = $uplink_mode."/".$downlink_mode;
|
||||||
|
@ -119,7 +119,7 @@
|
||||||
$sat_mode = "";
|
$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
|
$datetime1 = new DateTime(); // Today's Date/Time
|
||||||
$datetime2 = new DateTime($row->newtime);
|
$datetime2 = new DateTime($row->newtime);
|
||||||
$interval = $datetime1->diff($datetime2);
|
$interval = $datetime1->diff($datetime2);
|
||||||
|
@ -127,7 +127,7 @@
|
||||||
$minutes = $interval->days * 24 * 60;
|
$minutes = $interval->days * 24 * 60;
|
||||||
$minutes += $interval->h * 60;
|
$minutes += $interval->h * 60;
|
||||||
$minutes += $interval->i;
|
$minutes += $interval->i;
|
||||||
|
|
||||||
$updated_at = $minutes;
|
$updated_at = $minutes;
|
||||||
|
|
||||||
// Return Json data
|
// Return Json data
|
||||||
|
@ -143,7 +143,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_mode_designator($frequency)
|
function get_mode_designator($frequency)
|
||||||
{
|
{
|
||||||
if ($frequency > 21000000 && $frequency < 22000000)
|
if ($frequency > 21000000 && $frequency < 22000000)
|
||||||
|
@ -176,13 +176,13 @@
|
||||||
// Check Auth
|
// Check Auth
|
||||||
$this->load->model('user_model');
|
$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'); }
|
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->load->model('cat');
|
||||||
|
|
||||||
$this->cat->delete($id);
|
$this->cat->delete($id);
|
||||||
|
|
||||||
$this->session->set_flashdata('message', 'Radio Profile Deleted');
|
$this->session->set_flashdata('message', 'Radio Profile Deleted');
|
||||||
|
|
||||||
redirect('radio');
|
redirect('radio');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Migration_add_userid_to_hardware extends CI_Migration {
|
||||||
|
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$fields = array(
|
||||||
|
'user_id BIGINT(20) DEFAULT NULL',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->dbforge->add_column('cat', $fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
$this->dbforge->drop_column('cat', 'user_id');
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,10 +9,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function update($result) {
|
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');
|
$query = $this->db->get('cat');
|
||||||
|
|
||||||
if ($query->num_rows() > 0)
|
if ($query->num_rows() > 0)
|
||||||
{
|
{
|
||||||
if($result['radio'] == "SatPC32") {
|
if($result['radio'] == "SatPC32") {
|
||||||
|
@ -20,7 +21,7 @@
|
||||||
foreach ($query->result() as $row)
|
foreach ($query->result() as $row)
|
||||||
{
|
{
|
||||||
$radio_id = $row->id;
|
$radio_id = $row->id;
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'sat_name' => $result['sat_name'],
|
'sat_name' => $result['sat_name'],
|
||||||
'downlink_freq' => $result['downlink_freq'],
|
'downlink_freq' => $result['downlink_freq'],
|
||||||
|
@ -30,14 +31,15 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->db->where('id', $radio_id);
|
$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 {
|
} else {
|
||||||
// Update the record
|
// Update the record
|
||||||
foreach ($query->result() as $row)
|
foreach ($query->result() as $row)
|
||||||
{
|
{
|
||||||
$radio_id = $row->id;
|
$radio_id = $row->id;
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'frequency' => $result['frequency'],
|
'frequency' => $result['frequency'],
|
||||||
'mode' => $result['mode'],
|
'mode' => $result['mode'],
|
||||||
|
@ -45,12 +47,13 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->db->where('id', $radio_id);
|
$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 {
|
} else {
|
||||||
// Add a new record
|
// Add a new record
|
||||||
|
|
||||||
if($result['radio'] == "SatPC32") {
|
if($result['radio'] == "SatPC32") {
|
||||||
$data = array(
|
$data = array(
|
||||||
'radio' => $result['radio'],
|
'radio' => $result['radio'],
|
||||||
|
@ -61,6 +64,7 @@
|
||||||
'uplink_freq' => $result['uplink_freq'],
|
'uplink_freq' => $result['uplink_freq'],
|
||||||
'downlink_mode' => $result['downlink_mode'],
|
'downlink_mode' => $result['downlink_mode'],
|
||||||
'uplink_mode' => $result['uplink_mode'],
|
'uplink_mode' => $result['uplink_mode'],
|
||||||
|
'user_id' => $this->session->userdata('user_id'),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$data = array(
|
$data = array(
|
||||||
|
@ -68,23 +72,25 @@
|
||||||
'frequency' => $result['frequency'],
|
'frequency' => $result['frequency'],
|
||||||
'mode' => $result['mode'],
|
'mode' => $result['mode'],
|
||||||
'timestamp' => $result['timestamp'],
|
'timestamp' => $result['timestamp'],
|
||||||
|
'user_id' => $this->session->userdata('user_id'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->insert('cat', $data);
|
$this->db->insert('cat', $data);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function status() {
|
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');
|
$query = $this->db->get('cat');
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
function recent_status() {
|
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);
|
$this->db->where("timestamp > date_sub(now(), interval 15 minute)", NULL, FALSE);
|
||||||
|
|
||||||
$query = $this->db->get('cat');
|
$query = $this->db->get('cat');
|
||||||
|
@ -94,27 +100,23 @@
|
||||||
/* Return list of radios */
|
/* Return list of radios */
|
||||||
function radios() {
|
function radios() {
|
||||||
$this->db->select('id, radio');
|
$this->db->select('id, radio');
|
||||||
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||||
$query = $this->db->get('cat');
|
$query = $this->db->get('cat');
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function radio_status($id) {
|
function radio_status($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('SELECT *, CONVERT_TZ(`timestamp`, @@session.time_zone, \'+00:00\' ) as newtime FROM `cat` WHERE id = '.$id.' ');
|
return $this->db->query($sql);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function delete($id) {
|
function delete($id) {
|
||||||
$this->db->where('id', $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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Ładowanie…
Reference in New Issue