2012-04-07 16:36:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Cat extends CI_Model {
|
|
|
|
|
2021-09-28 16:18:04 +00:00
|
|
|
function update($result, $user_id) {
|
2021-09-20 13:03:35 +00:00
|
|
|
|
2022-09-29 21:06:06 +00:00
|
|
|
$timestamp = gmdate("Y-m-d H:i:s");
|
2022-01-14 19:22:18 +00:00
|
|
|
|
2022-08-27 13:21:56 +00:00
|
|
|
if (isset($result['prop_mode'])) {
|
|
|
|
$prop_mode = $result['prop_mode'];
|
2022-09-29 21:32:08 +00:00
|
|
|
// For backward compatibility, SatPC32 does not set propergation mode
|
|
|
|
} else if (isset($result['sat_name'])) {
|
|
|
|
$prop_mode = "SAT";
|
2022-08-27 13:21:56 +00:00
|
|
|
} else {
|
2022-09-29 21:32:08 +00:00
|
|
|
$prop_mode = NULL;
|
2022-08-27 13:21:56 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 13:03:35 +00:00
|
|
|
$this->db->where('radio', $result['radio']);
|
2021-09-28 16:18:04 +00:00
|
|
|
$this->db->where('user_id', $user_id);
|
2012-04-07 16:36:38 +00:00
|
|
|
$query = $this->db->get('cat');
|
2021-09-20 13:03:35 +00:00
|
|
|
|
2022-08-29 00:12:28 +00:00
|
|
|
// Let's keep uplink_freq, downlink_freq, uplink_mode and downlink_mode for backward compatibility
|
|
|
|
$data = array(
|
|
|
|
'prop_mode' => $prop_mode,
|
2022-09-29 21:32:08 +00:00
|
|
|
'power' => $result['power'] ?? NULL,
|
2022-09-29 21:06:06 +00:00
|
|
|
'sat_name' => $result['sat_name'] ?? NULL,
|
2022-08-29 00:12:28 +00:00
|
|
|
'timestamp' => $timestamp,
|
|
|
|
);
|
2022-09-29 21:06:06 +00:00
|
|
|
if (isset($result['frequency']) && $result['frequency'] != "NULL") {
|
|
|
|
$data['frequency'] = $result['frequency'];
|
|
|
|
} else {
|
|
|
|
$data['frequency'] = $result['uplink_freq'];
|
|
|
|
}
|
|
|
|
if (isset($result['mode']) && $result['mode'] != "NULL") {
|
|
|
|
$data['mode'] = $result['mode'];
|
|
|
|
} else {
|
|
|
|
$data['mode'] = $result['uplink_mode'];
|
|
|
|
}
|
|
|
|
if (isset($result['frequency_rx'])) {
|
2022-09-29 23:24:10 +00:00
|
|
|
$data['frequency_rx'] = $result['frequency_rx'];
|
2022-09-30 16:12:48 +00:00
|
|
|
} else if (isset($result['downlink_freq']) && $result['downlink_freq'] != "NULL") {
|
2022-09-29 23:24:10 +00:00
|
|
|
$data['frequency_rx'] = $result['downlink_freq'];
|
2022-09-29 21:06:06 +00:00
|
|
|
} else {
|
2022-09-29 23:24:10 +00:00
|
|
|
$data['frequency_rx'] = NULL;
|
2022-09-29 21:06:06 +00:00
|
|
|
}
|
|
|
|
if (isset($result['mode_rx'])) {
|
2022-09-29 23:24:10 +00:00
|
|
|
$data['mode_rx'] = $result['mode_rx'];
|
2022-09-30 16:12:48 +00:00
|
|
|
} else if (isset($result['downlink_mode']) && $result['downlink_mode'] != "NULL") {
|
2022-09-29 23:24:10 +00:00
|
|
|
$data['mode_rx'] = $result['downlink_mode'];
|
2022-09-29 21:06:06 +00:00
|
|
|
} else {
|
2022-09-29 23:24:10 +00:00
|
|
|
$data['mode_rx'] = NULL;
|
2022-09-29 21:06:06 +00:00
|
|
|
}
|
2022-08-27 17:00:23 +00:00
|
|
|
|
2012-04-07 16:36:38 +00:00
|
|
|
if ($query->num_rows() > 0)
|
|
|
|
{
|
2022-08-27 13:21:56 +00:00
|
|
|
// Update the record
|
|
|
|
foreach ($query->result() as $row)
|
|
|
|
{
|
|
|
|
$radio_id = $row->id;
|
2021-09-20 13:03:35 +00:00
|
|
|
|
2022-08-27 13:21:56 +00:00
|
|
|
$this->db->where('id', $radio_id);
|
|
|
|
$this->db->where('user_id', $user_id);
|
|
|
|
$this->db->update('cat', $data);
|
2012-04-07 16:36:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Add a new record
|
2022-08-27 17:00:23 +00:00
|
|
|
$data['radio'] = $result['radio'];
|
|
|
|
$data['user_id'] = $user_id;
|
2012-04-07 16:36:38 +00:00
|
|
|
|
2021-09-20 13:03:35 +00:00
|
|
|
$this->db->insert('cat', $data);
|
2012-04-07 16:36:38 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-20 13:03:35 +00:00
|
|
|
|
2012-04-07 16:36:38 +00:00
|
|
|
function status() {
|
2021-09-20 13:03:35 +00:00
|
|
|
//$this->db->where('radio', $result['radio']);
|
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
2012-04-08 12:17:14 +00:00
|
|
|
$query = $this->db->get('cat');
|
2021-09-20 13:03:35 +00:00
|
|
|
|
2012-04-08 15:47:18 +00:00
|
|
|
return $query;
|
2012-04-07 16:36:38 +00:00
|
|
|
}
|
|
|
|
|
2021-05-03 13:06:56 +00:00
|
|
|
function recent_status() {
|
2021-09-20 13:03:35 +00:00
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
2021-12-27 17:18:27 +00:00
|
|
|
$this->db->where("timestamp > date_sub(UTC_TIMESTAMP(), interval 15 minute)", NULL, FALSE);
|
2021-05-03 13:06:56 +00:00
|
|
|
|
|
|
|
$query = $this->db->get('cat');
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
2012-04-08 12:17:14 +00:00
|
|
|
/* Return list of radios */
|
|
|
|
function radios() {
|
|
|
|
$this->db->select('id, radio');
|
2021-09-20 13:03:35 +00:00
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
2012-04-08 12:17:14 +00:00
|
|
|
$query = $this->db->get('cat');
|
2021-09-20 13:03:35 +00:00
|
|
|
|
2012-04-08 12:17:14 +00:00
|
|
|
return $query;
|
|
|
|
}
|
2019-09-06 15:55:13 +00:00
|
|
|
|
|
|
|
function radio_status($id) {
|
2022-07-23 16:27:45 +00:00
|
|
|
$sql = 'SELECT * FROM `cat` WHERE id = ' . $id . ' and user_id =' . $this->session->userdata('user_id');
|
2021-09-20 13:03:35 +00:00
|
|
|
return $this->db->query($sql);
|
2019-09-06 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 20:14:39 +00:00
|
|
|
function delete($id) {
|
|
|
|
$this->db->where('id', $id);
|
2021-09-20 13:03:35 +00:00
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
|
|
$this->db->delete('cat');
|
|
|
|
|
2012-11-13 20:14:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-04-07 16:36:38 +00:00
|
|
|
}
|
2021-07-05 19:23:35 +00:00
|
|
|
?>
|