From a9c6acf25598127eb09e65a5e50af7d4306af9a0 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 5 Sep 2022 20:26:08 +0200 Subject: [PATCH] [Bands] User settings can now be saved. --- application/controllers/Awards.php | 10 +- application/controllers/Band.php | 113 ++++++++++++ application/models/Bands.php | 74 +++++++- application/views/bands/index.php | 73 ++++---- application/views/interface_assets/footer.php | 4 + assets/js/sections/bands.js | 163 ++++++++++++++++++ 6 files changed, 381 insertions(+), 56 deletions(-) create mode 100644 assets/js/sections/bands.js diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index e5c2fd38..f7c9e5ca 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -90,7 +90,7 @@ class Awards extends CI_Controller { $this->load->model('modes'); $this->load->model('bands'); - $data['worked_bands'] = $this->bands->get_worked_bands(); // Used in the view for band select + $data['worked_bands'] = $this->bands->get_worked_bands('dxcc'); // Used in the view for band select $data['modes'] = $this->modes->active(); // Used in the view for mode select if ($this->input->post('band') != NULL) { // Band is not set when page first loads. @@ -156,7 +156,7 @@ class Awards extends CI_Controller { public function vucc() { $this->load->model('vucc'); $this->load->model('bands'); - $data['worked_bands'] = $this->bands->get_worked_bands(); + $data['worked_bands'] = $this->bands->get_worked_bands('vucc'); $data['vucc_array'] = $this->vucc->get_vucc_array($data); @@ -249,7 +249,7 @@ class Awards extends CI_Controller { $this->load->model('modes'); $this->load->model('bands'); - $data['worked_bands'] = $this->bands->get_worked_bands(); + $data['worked_bands'] = $this->bands->get_worked_bands('cq'); $data['modes'] = $this->modes->active(); // Used in the view for mode select if ($this->input->post('band') != NULL) { // Band is not set when page first loads. @@ -307,7 +307,7 @@ class Awards extends CI_Controller { $this->load->model('modes'); $this->load->model('bands'); - $data['worked_bands'] = $this->bands->get_worked_bands(); + $data['worked_bands'] = $this->bands->get_worked_bands('was'); $data['modes'] = $this->modes->active(); // Used in the view for mode select if ($this->input->post('band') != NULL) { // Band is not set when page first loads. @@ -358,7 +358,7 @@ class Awards extends CI_Controller { $this->load->model('modes'); $this->load->model('bands'); - $data['worked_bands'] = $this->bands->get_worked_bands(); // Used in the view for band select + $data['worked_bands'] = $this->bands->get_worked_bands('iota'); // Used in the view for band select if ($this->input->post('band') != NULL) { // Band is not set when page first loads. if ($this->input->post('band') == 'All') { // Did the user specify a band? If not, use all bands diff --git a/application/controllers/Band.php b/application/controllers/Band.php index 0e3c0792..d590fd15 100644 --- a/application/controllers/Band.php +++ b/application/controllers/Band.php @@ -27,4 +27,117 @@ class Band extends CI_Controller { $this->load->view('bands/index'); $this->load->view('interface_assets/footer'); } + + public function create() + { + $this->load->model('bands'); + $this->load->library('form_validation'); + + $this->form_validation->set_rules('mode', 'Mode', 'required'); + $this->form_validation->set_rules('qrgmode', 'QRG-Mode', 'required'); + + if ($this->form_validation->run() == FALSE) + { + $data['page_title'] = "Create Mode"; + $this->load->view('mode/create', $data); + } + else + { + $this->bands->add(); + } + } + + public function edit($id) + { + $this->load->library('form_validation'); + + $this->load->model('bands'); + + $item_id_clean = $this->security->xss_clean($id); + + $mode_query = $this->bands->mode($item_id_clean); + + $data['my_mode'] = $mode_query->row(); + + $data['page_title'] = "Edit Mode"; + + $this->form_validation->set_rules('mode', 'Mode', 'required'); + $this->form_validation->set_rules('qrgmode', 'QRG-Mode', 'required'); + + if ($this->form_validation->run() == FALSE) + { + $this->load->view('interface_assets/header', $data); + $this->load->view('mode/edit'); + $this->load->view('interface_assets/footer'); + } + else + { + $this->bands->edit(); + + $data['notice'] = "Mode ".$this->security->xss_clean($this->input->post('mode', true))." Updated"; + + redirect('mode'); + } + } + + public function delete() { + $id = $this->input->post('id'); + $this->load->model('bands'); + $this->bands->delete($id); + } + + public function activate() { + $id = $this->input->post('id'); + $this->load->model('bands'); + $this->bands->activate($id); + header('Content-Type: application/json'); + echo json_encode(array('message' => 'OK')); + return; + } + + public function deactivate() { + $id = $this->input->post('id'); + $this->load->model('bands'); + $this->bands->deactivate($id); + header('Content-Type: application/json'); + echo json_encode(array('message' => 'OK')); + return; + } + + public function activateall() { + $this->load->model('bands'); + $this->bands->activateall(); + header('Content-Type: application/json'); + echo json_encode(array('message' => 'OK')); + return; + } + + public function deactivateall() { + $this->load->model('bands'); + $this->bands->deactivateall(); + header('Content-Type: application/json'); + echo json_encode(array('message' => 'OK')); + return; + } + + public function saveBand() { + $id = $this->security->xss_clean($this->input->post('id')); + $band['status'] = $this->security->xss_clean($this->input->post('status')); + $band['cq'] = $this->security->xss_clean($this->input->post('cq')); + $band['dok'] = $this->security->xss_clean($this->input->post('dok')); + $band['dxcc'] = $this->security->xss_clean($this->input->post('dxcc')); + $band['iota'] = $this->security->xss_clean($this->input->post('iota')); + $band['sig'] = $this->security->xss_clean($this->input->post('sig')); + $band['sota'] = $this->security->xss_clean($this->input->post('sota')); + $band['uscounties'] = $this->security->xss_clean($this->input->post('uscounties')); + $band['was'] = $this->security->xss_clean($this->input->post('was')); + $band['vucc'] = $this->security->xss_clean($this->input->post('vucc')); + + $this->load->model('bands'); + $this->bands->saveBand($id, $band); + + header('Content-Type: application/json'); + echo json_encode(array('message' => 'OK')); + return; + } } \ No newline at end of file diff --git a/application/models/Bands.php b/application/models/Bands.php index 517eae93..36e86731 100644 --- a/application/models/Bands.php +++ b/application/models/Bands.php @@ -35,7 +35,7 @@ class Bands extends CI_Model { $this->db->where('bandxuser.active', 1); if ($award != 'None') { - $this->db->where('bandxuser.".$award', 1); + $this->db->where('bandxuser.'.$award, 1); } $result = $this->db->get()->result(); @@ -90,6 +90,7 @@ class Bands extends CI_Model { array_push($worked_slots, strtoupper($row->COL_PROP_MODE)); } + // bring worked-slots in order of defined $bandslots $bandslots = $this->get_user_bands($award); $results = array(); @@ -122,12 +123,14 @@ class Bands extends CI_Model { } // bring worked-slots in order of defined $bandslots - $results = array(); - foreach(array_keys($this->bandslots) as $slot) { - if(in_array($slot, $worked_slots)) { - array_push($results, $slot); - } - } + $bandslots = $this->get_user_bands(); + + $results = array(); + foreach($bandslots as $slot) { + if(in_array($slot, $worked_slots)) { + array_push($results, $slot); + } + } return $results; } @@ -175,10 +178,11 @@ class Bands extends CI_Model { array_push($worked_slots, $row->COL_BAND); } - // bring worked-slots in order of defined $bandslots + $bandslots = $this->get_user_bands(); + $results = array(); - foreach(array_keys($this->bandslots) as $slot) { + foreach($bandslots as $slot) { if(in_array($slot, $worked_slots)) { array_push($results, $slot); } @@ -186,6 +190,58 @@ class Bands extends CI_Model { return $results; } + function activateall() { + $data = array( + 'active' => '1', + ); + $this->db->where('bandxuser.userid', $this->session->userdata('user_id')); + + $this->db->update('bandxuser', $data); + + return true; + } + + function deactivateall() { + $data = array( + 'active' => '0', + ); + $this->db->where('bandxuser.userid', $this->session->userdata('user_id')); + + $this->db->update('bandxuser', $data); + + return true; + } + + function delete($id) { + // Clean ID + $clean_id = $this->security->xss_clean($id); + + // Delete Mode + $this->db->delete('bandxuser', array('id' => $clean_id)); + } + + function saveBand($id, $band) { + $data = array( + 'active' => $band['status'] == "true" ? '1' : '0', + 'cq' => $band['cq'] == "true" ? '1' : '0', + 'dok' => $band['dok'] == "true" ? '1' : '0', + 'dxcc' => $band['dxcc'] == "true" ? '1' : '0', + 'iota' => $band['iota'] == "true" ? '1' : '0', + 'sig' => $band['sig'] == "true" ? '1' : '0', + 'sota' => $band['sota'] == "true" ? '1' : '0', + 'uscounties' => $band['uscounties'] == "true" ? '1' : '0', + 'was' => $band['was'] == "true" ? '1' : '0', + 'vucc' => $band['vucc'] == "true" ? '1' : '0' + ); + + $this->db->where('bandxuser.userid', $this->session->userdata('user_id')); + $this->db->where('bandxuser.id', $id); + + $this->db->update('bandxuser', $data); + + return true; + } + } ?> \ No newline at end of file diff --git a/application/views/bands/index.php b/application/views/bands/index.php index fafb3ef4..a7233c62 100644 --- a/application/views/bands/index.php +++ b/application/views/bands/index.php @@ -23,64 +23,53 @@

- +
- - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - -
BandStatusCQDOKDXCCIOTASIGSOTAUS CountiesWASVUCCBandActiveCQDOKDXCCIOTASIGSOTAUS CountiesWASVUCC
band?>active == 1) {echo 'Active';} else {echo 'Not Active';}; ?>
cq == 1) {echo 'checked';}?>>
dok == 1) {echo 'checked';}?>>
dxcc == 1) {echo 'checked';}?>>
iota == 1) {echo 'checked';}?>>
sig == 1) {echo 'checked';}?>>
sota == 1) {echo 'checked';}?>>
uscounties == 1) {echo 'checked';}?>>
was == 1) {echo 'checked';}?>>
vucc == 1) {echo 'checked';}?>>
- - band;?>active == 1) {echo 'checked';}?>>cq == 1) {echo 'checked';}?>>dok == 1) {echo 'checked';}?>>dxcc == 1) {echo 'checked';}?>>iota == 1) {echo 'checked';}?>>sig == 1) {echo 'checked';}?>>sota == 1) {echo 'checked';}?>>uscounties == 1) {echo 'checked';}?>>was == 1) {echo 'checked';}?>>vucc == 1) {echo 'checked';}?>> - Edit + Edit - Delete + Delete + + Save

diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 81d6da17..5d18a726 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2249,6 +2249,10 @@ $(document).ready(function(){ + uri->segment(1) == "band") { ?> + + + uri->segment(1) == "accumulated") { ?> diff --git a/assets/js/sections/bands.js b/assets/js/sections/bands.js new file mode 100644 index 00000000..86009e0b --- /dev/null +++ b/assets/js/sections/bands.js @@ -0,0 +1,163 @@ +$('.bandtable').DataTable({ + "pageLength": 25, + responsive: false, + ordering: false, + "scrollY": "500px", + "scrollCollapse": true, + "paging": false, + "scrollX": true +}); + +function createBandDialog() { + $.ajax({ + url: base_url + 'index.php/band/create', + type: 'post', + success: function (html) { + BootstrapDialog.show({ + title: 'Create band', + size: BootstrapDialog.SIZE_WIDE, + cssClass: 'create-band-dialog', + nl2br: false, + message: html, + buttons: [{ + label: 'Close', + action: function (dialogItself) { + dialogItself.close(); + } + }] + }); + } + }); +} + +function createBand(form) { + if (form.mode.value != '') { + $.ajax({ + url: base_url + 'index.php/band/create', + type: 'post', + data: { + 'band': form.band.value + }, + success: function (html) { + location.reload(); + } + }); + } +} + +function deactivateBand(bandid) { + $.ajax({ + url: base_url + 'index.php/band/deactivate', + type: 'post', + data: { 'id': bandid }, + success: function (html) { + $(".mode_" + modeid).text('not active'); + $('.btn_' + modeid).html('Activate'); + $('.btn_' + modeid).attr('onclick', 'activateMode(' + modeid + ')') + } + }); +} + +function activateBand(bandid) { + $.ajax({ + url: base_url + 'index.php/band/activate', + type: 'post', + data: { 'id': bandid }, + success: function (html) { + $('.mode_' + modeid).text('active'); + $('.btn_' + modeid).html('Deactivate'); + $('.btn_' + modeid).attr('onclick', 'deactivateMode(' + modeid + ')') + } + }); +} + +function deleteBand(id, band) { + BootstrapDialog.confirm({ + title: 'DANGER', + message: 'Warning! Are you sure you want to delete the following band: ' + band + '?', + type: BootstrapDialog.TYPE_DANGER, + closable: true, + draggable: true, + btnOKClass: 'btn-danger', + callback: function (result) { + if (result) { + $.ajax({ + url: base_url + 'index.php/band/delete', + type: 'post', + data: { + 'id': id + }, + success: function (data) { + $(".band_" + id).parent("tr:first").remove(); // removes mode from table + } + }); + } + } + }); +} + +function activateAllBands() { + BootstrapDialog.confirm({ + title: 'DANGER', + message: 'Warning! Are you sure you want to activate all bands?', + type: BootstrapDialog.TYPE_DANGER, + closable: true, + draggable: true, + btnOKClass: 'btn-danger', + callback: function (result) { + if (result) { + $.ajax({ + url: base_url + 'index.php/band/activateall', + type: 'post', + success: function (data) { + location.reload(); + } + }); + } + } + }); +} + +function deactivateAllBands() { + BootstrapDialog.confirm({ + title: 'DANGER', + message: 'Warning! Are you sure you want to deactivate all bands?', + type: BootstrapDialog.TYPE_DANGER, + closable: true, + draggable: true, + btnOKClass: 'btn-danger', + callback: function (result) { + if (result) { + $.ajax({ + url: base_url + 'index.php/band/deactivateall', + type: 'post', + success: function (data) { + location.reload(); + } + }); + } + } + }); +} + +function saveBand(id) { + $.ajax({ + url: base_url + 'index.php/band/saveBand', + type: 'post', + data: {'id': id, + 'status': $(".band_"+id+" input[type='checkbox']").is(":checked"), + 'cq': $(".cq_"+id+" input[type='checkbox']").is(":checked"), + 'dok': $(".dok_"+id+" input[type='checkbox']").is(":checked"), + 'dxcc': $(".dxcc_"+id+" input[type='checkbox']").is(":checked"), + 'iota': $(".iota_"+id+" input[type='checkbox']").is(":checked"), + 'sig': $(".sig_"+id+" input[type='checkbox']").is(":checked"), + 'sota': $(".sota_"+id+" input[type='checkbox']").is(":checked"), + 'uscounties': $(".uscounties_"+id+" input[type='checkbox']").is(":checked"), + 'was': $(".was_"+id+" input[type='checkbox']").is(":checked"), + 'vucc': $(".vucc_"+id+" input[type='checkbox']").is(":checked") + }, + success: function (html) { + // Add an alert to say that it is saved. Vanish after 5 seconds. + } + }); +} \ No newline at end of file