user_model->validate_session() == 0) {
// user is not logged in
redirect('user/login');
}
session_write_close();
// load the view
$data['page_title'] = __("Hardware Interfaces");
$this->load->is_loaded('worker') ?: $this->load->library('worker');
$data['worker_enabled'] = $this->worker->is_enabled(); // without this line worker.js is not loaded!
$data['radios_user_worker'] = null;
if ($this->worker->is_enabled()) {
$topic = 'radios_user.' . $this->session->userdata('user_id');
$this->worker->register_topic($topic);
$data['radios_user_worker'] = ['topic' => $topic, 'token' => $this->worker->create_token($topic)];
}
$footerData = [];
$footerData['scripts'] = [
'assets/js/sections/radio.js',
];
$this->load->view('interface_assets/header', $data);
$this->load->view('radio/index');
$this->load->view('interface_assets/footer', $footerData);
}
function status() {
if(!$this->user_model->authorize(3)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }
session_write_close();
$this->load->model('cat');
$query = $this->cat->status();
// Get the default radio
$default_user_radio = $this->user_options_model->get_options('cat', array('option_name' => $this->_get_optionname()), $this->_get_correct_uid())->row()->option_value ?? NULL;
if ($query->num_rows() > 0) {
echo "";
echo "" . __("Radio") . " ";
if ($this->session->userdata('clubstation') == 1 && clubaccess_check(9)) {
echo "" . __("Operator") . " ";
}
echo "" . __("Frequency") . " ";
echo "" . __("Mode") . " ";
echo "" . __("Timestamp") . " ";
echo " ";
echo "" . __("Options") . " ";
echo "" . __("Settings") . " ";
echo " ";
echo "
";
// WebSocket as first row
echo "";
echo "" . __("WebSocket") . " ";
echo "- "; // Frequency
echo "- "; // Mode
echo "- "; // Timestamp
echo ' '; // Last updated
if ($default_user_radio === 'ws') {
echo '' . __("Default (click to release)") . '
';
} else {
echo '' . __("Set as default radio") . '
';
}
echo ' '; // Settings (no edit for WebSocket)
echo ' '; // Delete (no delete for WebSocket)
echo " ";
foreach ($query->result() as $row) {
echo '';
echo "" . $row->radio . " ";
if ($this->session->userdata('clubstation') == 1 && clubaccess_check(9)) {
$operator = $this->user_model->get_by_id($row->operator)->row();
if ($operator) {
echo "" . $operator->user_callsign . " ";
} else {
echo "" . __("UNKNOWN") . " ";
}
}
if (empty($row->frequency) || $row->frequency == "0") {
$freq_html = "- / -";
} elseif (empty($row->frequency_rx) || $row->frequency_rx == "0") {
$freq_html = $this->frequency->qrg_conversion($row->frequency);
} elseif ($this->frequency->frequencies_are_equal($row->frequency, $row->frequency_rx)) {
$freq_html = $this->frequency->qrg_conversion($row->frequency);
} else {
$freq_html = $this->frequency->qrg_conversion($row->frequency_rx) . " / " . $this->frequency->qrg_conversion($row->frequency);
}
echo '' . $freq_html . ' ';
if (empty($row->mode) || $row->mode == "non") {
$mode_html = "N/A";
} elseif (empty($row->mode_rx) || $row->mode_rx == "non") {
$mode_html = $row->mode;
} else {
$mode_html = $row->mode_rx . " / " . $row->mode;
}
echo '' . $mode_html . ' ';
// Get Date format
if ($this->session->userdata('user_date_format')) {
// If Logged in and session exists
$custom_date_format = $this->session->userdata('user_date_format');
} else {
// Get Default date format from /config/wavelog.php
$custom_date_format = $this->config->item('qso_date_format');
}
$phpdate = strtotime($row->timestamp);
echo "" . date($custom_date_format . ' H:i:s', $phpdate) . " ";
$last_updated = $this->cat->last_updated()->row()->id;
if ($last_updated == $row->id) {
echo '' . __("last updated") . ' ';
} else {
echo ' ';
}
if ($default_user_radio == $row->id) {
echo '' . __("Default (click to release)") . '
';
} else {
echo '' . __("Set as default radio") . '
';
}
echo " " . __("Edit") . " ";
echo "id . "\" class=\"btn btn-sm btn-danger\"> " . __("Delete") . " ";
echo " ";
}
echo " ";
} else {
// No radios found - show WebSocket button
if ($default_user_radio === 'ws') {
$websocket_button = '' . __("WebSocket is currently default (click to release)") . '
';
} else {
$websocket_button = '' . __("Set WebSocket as default radio") . '
';
}
echo "";
echo "";
echo __("No CAT interfaced radios found.");
echo "
" . __("You can still set the WebSocket option as your default radio.") . "
";
echo $websocket_button;
echo "
";
echo " ";
}
}
public function saveCatUrl() {
$url = $this->input->post('caturl', true);
$id = $this->input->post('id', true);
$this->load->model('cat');
$this->cat->updateCatUrl($id,$url);
}
public function editCatUrl() {
$this->load->model('cat');
$data['container'] = $this->cat->radio_status($this->input->post('id', true))->row();
$data['page_title'] = __("Edit CAT Settings");
$this->load->view('radio/edit', $data);
}
function json($id) {
$clean_id = $this->security->xss_clean($id);
// Check if users logged in
if ($this->user_model->validate_session() == 0) {
// user is not logged in
// Return Json data
header('Content-Type: application/json');
echo json_encode(array(
"error" => "not_logged_in"
), JSON_PRETTY_PRINT);
} else {
session_write_close();
header('Content-Type: application/json');
$this->load->model('cat');
$query = $this->cat->radio_status($clean_id);
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
echo json_encode($this->cat->format_status($row), JSON_PRETTY_PRINT);
}
}
}
}
function delete($id) {
$clean_id = $this->security->xss_clean($id);
// Check Auth
if (!$this->user_model->authorize(3)) {
$this->session->set_flashdata('error', __("You're not allowed to do that!"));
redirect('dashboard');
}
$this->load->model('cat');
$this->cat->delete($clean_id);
if ($clean_id == $this->user_options_model->get_options('cat', array('option_name' => $this->_get_optionname()), $this->_get_correct_uid())->row()->option_value ?? '') {
$this->release_default_radio();
}
$this->session->set_flashdata('message', __("Radio removed successfully"));
session_write_close();
redirect('radio');
}
function set_default_radio() {
// get the radio_id from POST
$clean_radio_id = $this->input->post('radio_id', TRUE);
// Check Auth
if (!$this->user_model->authorize(3)) {
$this->session->set_flashdata('error', __("You're not allowed to do that!"));
redirect('dashboard');
}
// we unset the current default radio
$this->release_default_radio();
// Set the user_option and session data
$this->user_options_model->set_option('cat', $this->_get_optionname(), array('radio_id' => $clean_radio_id), $this->_get_correct_uid());
$this->session->set_userdata('radio', $clean_radio_id);
}
function release_default_radio() {
// Check Auth
if (!$this->user_model->authorize(3)) {
$this->session->set_flashdata('error', __("You're not allowed to do that!"));
redirect('dashboard');
}
// Unset the user_option and session data
$this->user_options_model->del_option('cat', $this->_get_optionname(), NULL, $this->_get_correct_uid());
$this->session->unset_userdata('radio');
}
private function _get_correct_uid() {
if ($this->_is_clubstation()) {
return $this->session->userdata('source_uid');
} else {
return $this->session->userdata('user_id');
}
}
private function _is_clubstation() {
return $this->session->userdata('clubstation') == 1;
}
private function _get_optionname() {
if ($this->_is_clubstation() && ($this->session->userdata('source_uid') ?? '') != '') {
return 'default_clubradio_' . $this->session->userdata('user_id');
} else {
return 'default_radio';
}
}
}