diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 8ce180acd..1c1216aed 100644 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -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'); diff --git a/application/controllers/Usermode.php b/application/controllers/Usermode.php new file mode 100644 index 000000000..148dd68aa --- /dev/null +++ b/application/controllers/Usermode.php @@ -0,0 +1,63 @@ +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; + } + +} diff --git a/application/models/Usermodes.php b/application/models/Usermodes.php new file mode 100644 index 000000000..287a00237 --- /dev/null +++ b/application/models/Usermodes.php @@ -0,0 +1,97 @@ +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; + } +} + +?> diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index c24b27b30..70179fc3e 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2348,6 +2348,10 @@ $('#sats').change(function(){ + uri->segment(1) == "usermode") { ?> + + + uri->segment(1) == "mode") { ?> diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index 15368caee..ca1727a2e 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -413,6 +413,7 @@
  • +
  • config->item('special_callsign') && $this->session->userdata('clubstation') == 0) { ?> session->userdata('available_clubstations'))) { ?> diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 4d364ffb8..cf246e6ef 100644 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -144,7 +144,7 @@ ') + .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(''); + }); + }); + }, +}); + + +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(); + } + }); + } + } + }); +}