mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
@@ -17,7 +17,7 @@ class QSO extends CI_Controller {
|
||||
$this->load->model('stations');
|
||||
$this->load->model('logbook_model');
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('modes');
|
||||
$this->load->model('usermodes');
|
||||
$this->load->model('bands');
|
||||
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }
|
||||
|
||||
@@ -40,7 +40,7 @@ class QSO extends CI_Controller {
|
||||
$data['query'] = $this->logbook_model->last_custom($this->session->userdata('qso_page_last_qso_count'));
|
||||
$data['dxcc'] = $this->logbook_model->fetchDxcc();
|
||||
$data['iota'] = $this->logbook_model->fetchIota();
|
||||
$data['modes'] = $this->modes->active();
|
||||
$data['modes'] = $this->usermodes->active();
|
||||
$data['bands'] = $this->bands->get_user_bands_for_qso_entry();
|
||||
[$data['lat'], $data['lng']] = $this->qra->qra2latlong($this->stations->gridsquare_from_station($this->stations->find_active()));
|
||||
$data['user_default_band'] = $this->session->userdata('user_default_band');
|
||||
|
||||
63
application/controllers/Usermode.php
Normal file
63
application/controllers/Usermode.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
Handles Displaying of information for mode tools.
|
||||
*/
|
||||
|
||||
class Usermode extends CI_Controller {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->helper(array('form', 'url'));
|
||||
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->model('usermodes');
|
||||
$data['modes'] = $this->usermodes->all();
|
||||
// Render Page
|
||||
$data['page_title'] = __("Modes");
|
||||
$this->load->view('interface_assets/header', $data);
|
||||
$this->load->view('usermode/index');
|
||||
$this->load->view('interface_assets/footer');
|
||||
}
|
||||
|
||||
public function activate() {
|
||||
$id = $this->input->post('id',true);
|
||||
$this->load->model('usermodes');
|
||||
$this->usermodes->activate($id);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(array('message' => 'OK'));
|
||||
return;
|
||||
}
|
||||
|
||||
public function deactivate() {
|
||||
$id = $this->input->post('id',true);
|
||||
$this->load->model('usermodes');
|
||||
$this->usermodes->deactivate($id);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(array('message' => 'OK'));
|
||||
return;
|
||||
}
|
||||
|
||||
public function activateAll() {
|
||||
$this->load->model('usermodes');
|
||||
$this->usermodes->activateAll();
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(array('message' => 'OK'));
|
||||
return;
|
||||
}
|
||||
|
||||
public function deactivateAll() {
|
||||
$this->load->model('usermodes');
|
||||
$this->usermodes->deactivateAll();
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(array('message' => 'OK'));
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
97
application/models/Usermodes.php
Normal file
97
application/models/Usermodes.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
class Usermodes extends CI_Model {
|
||||
|
||||
function all() {
|
||||
$options_object = $this->user_options_model->get_options('usermodes', array('option_name' => 'enabled_usermodes', 'option_key' => 'json_modes'))->result();
|
||||
$usermodes = json_decode($options_object[0]->option_value ?? '[]');
|
||||
$this->db->where('active', 1); // Show only those which are not globally deactivated
|
||||
$this->db->order_by('mode', 'ASC');
|
||||
$this->db->order_by('submode', 'ASC');
|
||||
$modes=$this->db->get('adif_modes');
|
||||
$retmodes=[];
|
||||
foreach ($modes->result() as $row) {
|
||||
if (count($usermodes)>0) {
|
||||
if (in_array($row->mode.'~'.($row->submode ?? ''), $usermodes)) {
|
||||
$row->active=1;
|
||||
} else {
|
||||
$row->active=0;
|
||||
}
|
||||
}
|
||||
$retmodes[]=$row;
|
||||
}
|
||||
return $retmodes;
|
||||
}
|
||||
|
||||
function active() {
|
||||
$options_object = $this->user_options_model->get_options('usermodes', array('option_name' => 'enabled_usermodes', 'option_key' => 'json_modes'))->result();
|
||||
$usermodes = json_decode($options_object[0]->option_value ?? '[]');
|
||||
$this->db->where('active', 1); // Show only those which are not globally deactivated
|
||||
$this->db->order_by('mode', 'ASC');
|
||||
$this->db->order_by('submode', 'ASC');
|
||||
$modes=$this->db->get('adif_modes');
|
||||
$retmodes=[];
|
||||
foreach ($modes->result() as $row) {
|
||||
if (count($usermodes)>0) { // Something explicitly allowed, push it to array
|
||||
if (in_array($row->mode.'~'.($row->submode ?? ''), $usermodes)) {
|
||||
$row->active=1;
|
||||
$retmodes[]=$row;
|
||||
} else {
|
||||
$row->active=0;
|
||||
}
|
||||
} else { // Default-Status? Nothing in array: So everything is allowed
|
||||
$retmodes[]=$row;
|
||||
}
|
||||
}
|
||||
return $retmodes;
|
||||
}
|
||||
|
||||
function mode($id) {
|
||||
// Clean ID
|
||||
$clean_id = $this->security->xss_clean($id);
|
||||
|
||||
$this->db->where('id', $clean_id);
|
||||
return $this->db->get('adif_modes');
|
||||
}
|
||||
|
||||
function activate($id) {
|
||||
$clean_id = $this->security->xss_clean($id);
|
||||
|
||||
$modes=[];
|
||||
$raw_modes=$this->all();
|
||||
foreach ($raw_modes as $row) {
|
||||
if (($row->id == $clean_id) || ($row->active == 1)) {
|
||||
$modes[]=$row->mode.'~'.($row->submode ?? '');
|
||||
}
|
||||
}
|
||||
$this->user_options_model->set_option('usermodes', 'enabled_usermodes', array('json_modes' => json_encode($modes)));
|
||||
return true;
|
||||
}
|
||||
|
||||
function deactivate($id) {
|
||||
$clean_id = $this->security->xss_clean($id);
|
||||
|
||||
$modes=[];
|
||||
$raw_modes=$this->all();
|
||||
foreach ($raw_modes as $row) {
|
||||
if (($row->id != $clean_id) && ($row->active == 1)) {
|
||||
$modes[]=$row->mode.'~'.($row->submode ?? '');
|
||||
}
|
||||
}
|
||||
$this->user_options_model->set_option('usermodes', 'enabled_usermodes', array('json_modes' => json_encode($modes)));
|
||||
return true;
|
||||
}
|
||||
|
||||
function activateAll() {
|
||||
// Clean ID
|
||||
$this->user_options_model->set_option('usermodes', 'enabled_usermodes', array('json_modes' => '[]')); // Empty/Nothing is default (prevents migration)
|
||||
return true;
|
||||
}
|
||||
|
||||
function deactivateAll() {
|
||||
$this->user_options_model->set_option('usermodes', 'enabled_usermodes', array('json_modes' => '[""]')); // Put at least one senseless element to array, to deactivate all on userlevel
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -2348,6 +2348,10 @@ $('#sats').change(function(){
|
||||
<?php } ?>
|
||||
|
||||
|
||||
<?php if ($this->uri->segment(1) == "usermode") { ?>
|
||||
<script src="<?php echo base_url(); ?>assets/js/sections/usermode.js"></script>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($this->uri->segment(1) == "mode") { ?>
|
||||
<script src="<?php echo base_url(); ?>assets/js/sections/mode.js"></script>
|
||||
<?php } ?>
|
||||
|
||||
@@ -413,6 +413,7 @@
|
||||
<li><a class="dropdown-item" href="<?php echo site_url('stationsetup'); ?>" title="Manage station setup"><i class="fas fa-home"></i> <?= __("Station Setup"); ?></a></li>
|
||||
<?php } ?>
|
||||
<li><a class="dropdown-item" href="<?php echo site_url('band'); ?>" title="Manage Bands"><i class="fas fa-cog"></i> <?= __("Bands"); ?></a></li>
|
||||
<li><a class="dropdown-item" href="<?php echo site_url('usermode'); ?>" title="Manage Modes"><i class="fas fa-cog"></i> <?= __("Modes"); ?></a></li>
|
||||
|
||||
<?php if ($this->config->item('special_callsign') && $this->session->userdata('clubstation') == 0) { ?>
|
||||
<?php if (!empty($this->session->userdata('available_clubstations'))) { ?>
|
||||
|
||||
@@ -144,7 +144,7 @@
|
||||
<label for="mode"><?= __("Mode"); ?></label>
|
||||
<select id="mode" tabindex="1" class="form-select mode form-select-sm" name="mode">
|
||||
<?php
|
||||
foreach($modes->result() as $mode){
|
||||
foreach($modes as $mode){
|
||||
if ($mode->submode == null) {
|
||||
printf("<option value=\"%s\" %s>%s</option>", $mode->mode, $this->session->userdata('mode')==$mode->mode?"selected=\"selected\"":"",$mode->mode);
|
||||
} else {
|
||||
|
||||
80
application/views/usermode/index.php
Normal file
80
application/views/usermode/index.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<script>
|
||||
var lang_active_all_confirm = "<?= __("Warning! Are you sure you want to activate all modes?"); ?>";
|
||||
var lang_deactive_all_confirm = "<?= __("Warning! Are you sure you want to deactivate all modes?"); ?>";
|
||||
var lang_deactivate_mode = "<?= __("Deactivate"); ?>";
|
||||
var lang_activate_mode = "<?= __("Activate"); ?>";
|
||||
var lang_mode_active = "<?= __("Active"); ?>";
|
||||
var lang_mode_not_active = "<?= __("Not active"); ?>";
|
||||
</script>
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
<br>
|
||||
<?php if($this->session->flashdata('message')) { ?>
|
||||
<!-- Display Message -->
|
||||
<div class="alert-message error">
|
||||
<p><?php echo $this->session->flashdata('message'); ?></p>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<h2><?php echo $page_title; ?></h2>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<?= __("Modes"); ?>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">
|
||||
<?= __("Using the modes list you can control which modes are shown when creating a new QSO."); ?>
|
||||
</p>
|
||||
<p class="card-text">
|
||||
<?= __("Active modes will be shown in the QSO 'Mode' drop-down, while inactive modes will be hidden and cannot be selected."); ?>
|
||||
</p>
|
||||
<div class="table-responsive">
|
||||
<table style="width:100%" class="modetable table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="select-filter" scope="col"><?= __("Mode"); ?></th>
|
||||
<th class="select-filter" scope="col"><?= __("Sub-Mode"); ?></th>
|
||||
<th class="select-filter" scope="col">SSB / DATA / CW</th>
|
||||
<th class="select-filter" scope="col"><?= __("Status"); ?></th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($modes as $row) { ?>
|
||||
<tr>
|
||||
<td style="text-align: center; vertical-align: middle;" ><?php echo $row->mode;?></td>
|
||||
<td style="text-align: center; vertical-align: middle;" ><?php echo $row->submode;?></td>
|
||||
<td style="text-align: center; vertical-align: middle;" ><?php echo $row->qrgmode;?></td>
|
||||
<td style="text-align: center; vertical-align: middle;" class='mode_<?php echo $row->id ?>'><?php if ($row->active == 1) { echo __("Active");} else { echo __("Not active");};?></td>
|
||||
<td style="text-align: center; vertical-align: middle;" style="text-align: center">
|
||||
<?php if ($row->active == 1) {
|
||||
echo "<button onclick='javascript:deactivateMode(". $row->id . ")' class='btn_" . $row->id . " btn btn-secondary btn-sm'>" . __("Deactivate") . "</button>";
|
||||
} else {
|
||||
echo "<button onclick='javascript:activateMode(". $row->id . ")' class='btn_" . $row->id . " btn btn-primary btn-sm'>" . __("Activate") . "</button>";
|
||||
};?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th><---</th>
|
||||
<th><?= __("Filters"); ?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<table>
|
||||
</div>
|
||||
<br/>
|
||||
<p>
|
||||
<button onclick="activateAllModes();" class="btn btn-primary btn-sm"><?= __("Activate All"); ?></button>
|
||||
<button onclick="deactivateAllModes();" class="btn btn-primary btn-sm"><?= __("Deactivate All"); ?> </button>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
113
assets/js/sections/usermode.js
Normal file
113
assets/js/sections/usermode.js
Normal file
@@ -0,0 +1,113 @@
|
||||
$('.modetable').DataTable({
|
||||
"pageLength": 25,
|
||||
responsive: false,
|
||||
ordering: false,
|
||||
"scrollY": "500px",
|
||||
"scrollCollapse": true,
|
||||
"paging": false,
|
||||
"scrollX": true,
|
||||
"language": {
|
||||
url: getDataTablesLanguageUrl(),
|
||||
},
|
||||
initComplete: function () {
|
||||
this.api()
|
||||
.columns('.select-filter')
|
||||
.every(function () {
|
||||
var column = this;
|
||||
var select = $('<select class="form-select"><option value=""></option></select>')
|
||||
.appendTo($(column.footer()).empty())
|
||||
.on('change', function () {
|
||||
var val = $.fn.dataTable.util.escapeRegex($(this).val());
|
||||
|
||||
column.search(val ? '^' + val + '$' : '', true, false).draw();
|
||||
});
|
||||
|
||||
column
|
||||
.data()
|
||||
.unique()
|
||||
.sort()
|
||||
.each(function (d, j) {
|
||||
select.append('<option value="' + d + '">' + d + '</option>');
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
function deactivateMode(modeid) {
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/usermode/deactivate',
|
||||
type: 'post',
|
||||
data: { 'id': modeid },
|
||||
success: function (html) {
|
||||
$(".mode_" + modeid).text(lang_mode_not_active);
|
||||
$('.btn_' + modeid).html(lang_activate_mode);
|
||||
$('.btn_' + modeid).removeClass('btn-secondary');
|
||||
$('.btn_' + modeid).addClass('btn-primary');
|
||||
$('.btn_' + modeid).attr('onclick', 'activateMode(' + modeid + ')')
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function activateMode(modeid) {
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/usermode/activate',
|
||||
type: 'post',
|
||||
data: { 'id': modeid },
|
||||
success: function (html) {
|
||||
$('.mode_' + modeid).text(lang_mode_active);
|
||||
$('.btn_' + modeid).html(lang_deactivate_mode);
|
||||
$('.btn_' + modeid).removeClass('btn-primary');
|
||||
$('.btn_' + modeid).addClass('btn-secondary');
|
||||
$('.btn_' + modeid).attr('onclick', 'deactivateMode(' + modeid + ')')
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function activateAllModes() {
|
||||
BootstrapDialog.confirm({
|
||||
title: lang_general_word_danger,
|
||||
message: lang_active_all_confirm,
|
||||
type: BootstrapDialog.TYPE_DANGER,
|
||||
closable: true,
|
||||
draggable: true,
|
||||
btnOKClass: 'btn-danger',
|
||||
btnCancelLabel: lang_general_word_cancel,
|
||||
btnOKLabel: lang_general_word_ok,
|
||||
callback: function (result) {
|
||||
if (result) {
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/usermode/activateall',
|
||||
type: 'post',
|
||||
success: function (data) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function deactivateAllModes() {
|
||||
BootstrapDialog.confirm({
|
||||
title: lang_general_word_danger,
|
||||
message: lang_deactive_all_confirm,
|
||||
type: BootstrapDialog.TYPE_DANGER,
|
||||
closable: true,
|
||||
draggable: true,
|
||||
btnOKClass: 'btn-danger',
|
||||
btnCancelLabel: lang_general_word_cancel,
|
||||
btnOKLabel: lang_general_word_ok,
|
||||
callback: function (result) {
|
||||
if (result) {
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/usermode/deactivateall',
|
||||
type: 'post',
|
||||
success: function (data) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user