mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Merge pull request #2955 from HB9HIL/default_ws
Clubstation default radio per operator and Websocket as default radio
This commit is contained in:
@@ -36,6 +36,9 @@ class Radio extends CI_Controller {
|
||||
$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 "<thead><tr>";
|
||||
echo "<th>" . __("Radio") . "</th>";
|
||||
@@ -50,6 +53,23 @@ class Radio extends CI_Controller {
|
||||
echo "<th>" . __("Settings") . "</th>";
|
||||
echo "<th></th>";
|
||||
echo "</tr></thead><tbody>";
|
||||
|
||||
// WebSocket as first row
|
||||
echo "<tr>";
|
||||
echo "<td>" . __("WebSocket") . "</td>";
|
||||
echo "<td>-</td>"; // Frequency
|
||||
echo "<td>-</td>"; // Mode
|
||||
echo "<td>-</td>"; // Timestamp
|
||||
echo '<td></td>'; // Last updated
|
||||
if ($default_user_radio === 'ws') {
|
||||
echo '<td><button id="default_radio_btn_ws" class="btn btn-sm btn-primary ld-ext-right" onclick="release_default_radio(\'ws\')">' . __("Default (click to release)") . '<div class="ld ld-ring ld-spin"></div></button></td>';
|
||||
} else {
|
||||
echo '<td><button id="default_radio_btn_ws" class="btn btn-sm btn-outline-primary ld-ext-right" onclick="set_default_radio(\'ws\')">' . __("Set as default radio") . '<div class="ld ld-ring ld-spin"></div></button></td>';
|
||||
}
|
||||
echo '<td></td>'; // Settings (no edit for WebSocket)
|
||||
echo '<td></td>'; // Delete (no delete for WebSocket)
|
||||
echo "</tr>";
|
||||
|
||||
foreach ($query->result() as $row) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . $row->radio . "</td>";
|
||||
@@ -100,17 +120,10 @@ class Radio extends CI_Controller {
|
||||
echo '<td></td>';
|
||||
}
|
||||
|
||||
if ($this->session->userdata('clubstation') != 1) {
|
||||
$defaul_user_radio = $this->user_options_model->get_options('cat', array('option_name' => 'default_radio'))->row()->option_value ?? NULL;
|
||||
if (!$defaul_user_radio) {
|
||||
echo '<td><button id="default_radio_btn_' . $row->id . '" class="btn btn-sm btn-outline-primary ld-ext-right" onclick="set_default_radio(' . $row->id . ')">' . __("Set as default radio") . '<div class="ld ld-ring ld-spin"></div></button</td>';
|
||||
} else {
|
||||
if ($defaul_user_radio !== $row->id) {
|
||||
echo '<td><button id="default_radio_btn_' . $row->id . '" class="btn btn-sm btn-outline-primary ld-ext-right" onclick="set_default_radio(' . $row->id . ')">' . __("Set as default radio") . '<div class="ld ld-ring ld-spin"></div></button</td>';
|
||||
} else {
|
||||
echo '<td><button id="default_radio_btn_' . $row->id . '" class="btn btn-sm btn-primary ld-ext-right" onclick="release_default_radio(' . $row->id . ')">' . __("Default (click to release)") . '<div class="ld ld-ring ld-spin"></div></button</td>';
|
||||
}
|
||||
}
|
||||
if ($default_user_radio == $row->id) {
|
||||
echo '<td><button id="default_radio_btn_' . $row->id . '" class="btn btn-sm btn-primary ld-ext-right" onclick="release_default_radio(' . $row->id . ')">' . __("Default (click to release)") . '<div class="ld ld-ring ld-spin"></div></button</td>';
|
||||
} else {
|
||||
echo '<td><button id="default_radio_btn_' . $row->id . '" class="btn btn-sm btn-outline-primary ld-ext-right" onclick="set_default_radio(' . $row->id . ')">' . __("Set as default radio") . '<div class="ld ld-ring ld-spin"></div></button</td>';
|
||||
}
|
||||
echo "<td><button id='edit_cat_settings_".$row->id."' \" class=\"editCatSettings btn btn-sm btn-primary\"> " . __("Edit") . "</button></td>";
|
||||
echo "<td><a href=\"" . site_url('radio/delete') . "/" . $row->id . "\" class=\"btn btn-sm btn-danger\"> <i class=\"fas fa-trash-alt\"></i> " . __("Delete") . "</a></td>";
|
||||
@@ -118,8 +131,18 @@ class Radio extends CI_Controller {
|
||||
}
|
||||
echo "</tbody>";
|
||||
} else {
|
||||
// No radios found - show WebSocket button
|
||||
if ($default_user_radio === 'ws') {
|
||||
$websocket_button = '<button id="default_radio_btn_ws" type="button" class="btn btn-sm btn-primary mt-2 ld-ext-right d-block mx-auto" onclick="release_default_radio(\'ws\')">' . __("WebSocket is currently default (click to release)") . '<div class="ld ld-ring ld-spin"></div></button>';
|
||||
} else {
|
||||
$websocket_button = '<button id="default_radio_btn_ws" type="button" class="btn btn-sm btn-primary mt-2 ld-ext-right d-block mx-auto" onclick="set_default_radio(\'ws\')">' . __("Set WebSocket as default radio") . '<div class="ld ld-ring ld-spin"></div></button>';
|
||||
}
|
||||
echo "<thead><tr>";
|
||||
echo "<td colspan=\"6\"><div class=\"alert alert-info text-center\">" . __("No CAT interfaced radios found.") . "</div></td>";
|
||||
echo "<td colspan=\"6\"><div class=\"alert alert-info text-center\">";
|
||||
echo __("No CAT interfaced radios found.");
|
||||
echo "<p>" . __("You can still set the WebSocket option as your default radio.") . "</p>";
|
||||
echo $websocket_button;
|
||||
echo "</div></td>";
|
||||
echo "</tr></thead>";
|
||||
}
|
||||
}
|
||||
@@ -302,11 +325,11 @@ class Radio extends CI_Controller {
|
||||
|
||||
$this->cat->delete($clean_id);
|
||||
|
||||
if ($clean_id == $this->user_options_model->get_options('cat', array('option_name' => 'default_radio'))->row()->option_value ?? '') {
|
||||
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 Profile Deleted');
|
||||
$this->session->set_flashdata('message', __("Radio removed successfully"));
|
||||
|
||||
session_write_close();
|
||||
redirect('radio');
|
||||
@@ -315,8 +338,8 @@ class Radio extends CI_Controller {
|
||||
function set_default_radio() {
|
||||
|
||||
// get the radio_id from POST
|
||||
$clean_radio_id = $this->security->xss_clean($this->input->post('radio_id'));
|
||||
|
||||
$clean_radio_id = $this->input->post('radio_id', TRUE);
|
||||
|
||||
// Check Auth
|
||||
$this->load->model('user_model');
|
||||
if (!$this->user_model->authorize(3)) {
|
||||
@@ -328,7 +351,7 @@ class Radio extends CI_Controller {
|
||||
$this->release_default_radio();
|
||||
|
||||
// Set the user_option and session data
|
||||
$this->user_options_model->set_option('cat', 'default_radio', array('radio_id' => $clean_radio_id));
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -341,7 +364,27 @@ class Radio extends CI_Controller {
|
||||
}
|
||||
|
||||
// Unset the user_option and session data
|
||||
$this->user_options_model->del_option('cat', 'default_radio');
|
||||
$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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,19 @@
|
||||
<?= __("Active Radios"); ?>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text"><?= __("Below is a list of active radios that are connected to Wavelog."); ?></p>
|
||||
<p class="card-text"><?= __("If you haven't connected any radios yet, see the API page to generate API keys."); ?></p>
|
||||
<p class="card-text"><?= __("Below is a list of active radios that are connected to Wavelog."); ?> <?= __("If you haven't connected any radios yet, see the API page to generate API keys."); ?></p>
|
||||
<?php if ($this->session->userdata('clubstation') == 1) { ?>
|
||||
<p class="card-text"><?= __("As a clubstation operator, you can set a default radio which applies only to you. This allows you to have a default radio that is automatically selected when you log in, while still being able to use other radios if you want."); ?></p>
|
||||
<?php } else { ?>
|
||||
<p class="card-text"><?= __("As a normal user, you can set a default radio for yourself. This allows you to have a default radio that is automatically selected when you log in, while still being able to use other radios if you want."); ?></p>
|
||||
<?php } ?>
|
||||
<p class="card-text">
|
||||
<span class="badge text-bg-info"><?= __("Info"); ?></span> <?= sprintf(__("You can find out how to use the %s in the wiki."), '<a href="https://github.com/wavelog/wavelog/wiki/Radio-Interface" target="_blank">' . __("radio functions") . '</a>'); ?>
|
||||
<span class="badge text-bg-info"><?= __("Info"); ?></span> <?= sprintf(__("You can find out how to use the %sradio functions%s in the wiki."), '<a href="https://github.com/wavelog/wavelog/wiki/Radio-Interface" target="_blank">', '</a>'); ?>
|
||||
</p>
|
||||
<div class="table-responsive">
|
||||
<!-- Display Radio Statuses -->
|
||||
<table class="table table-sm table-condensated table-striped status"></table>
|
||||
<h3 id="radioResultsLoading" class="text-center"><div class="me-3 ld ld-ring ld-spin"></div><?= __("Please wait..."); ?></h3>
|
||||
<h6 id="radioResultsLoading" class="text-center"><div class="me-3 ld ld-ring ld-spin"></div><?= __("Please wait..."); ?></h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user