From 1114973f8d35cce54fb289116b4c32742ad6cc56 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 6 Sep 2022 20:18:17 +0200 Subject: [PATCH] [Bands] Added edit band --- application/controllers/Band.php | 37 +++++++++------------ application/models/Bands.php | 17 ++++++++++ application/views/bands/edit.php | 14 ++++++++ application/views/bands/index.php | 2 +- assets/js/sections/bands.js | 54 +++++++++++++++++++++++++++++-- 5 files changed, 98 insertions(+), 26 deletions(-) create mode 100644 application/views/bands/edit.php diff --git a/application/controllers/Band.php b/application/controllers/Band.php index 5d3bf386..61403418 100644 --- a/application/controllers/Band.php +++ b/application/controllers/Band.php @@ -46,37 +46,30 @@ class Band extends CI_Controller { } } - public function edit($id) + public function edit() { - $this->load->library('form_validation'); - $this->load->model('bands'); - $item_id_clean = $this->security->xss_clean($id); + $item_id_clean = $this->security->xss_clean($this->input->post('id')); - $mode_query = $this->bands->mode($item_id_clean); + $band_query = $this->bands->getband($item_id_clean); - $data['my_mode'] = $mode_query->row(); + $data['my_band'] = $band_query->row(); - $data['page_title'] = "Edit Mode"; + $data['page_title'] = "Edit Band"; - $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(); + $this->load->view('bands/edit', $data); + } - $data['notice'] = "Mode ".$this->security->xss_clean($this->input->post('mode', true))." Updated"; + public function saveupdatedband() { + $this->load->model('bands'); - redirect('mode'); - } + $id = $this->security->xss_clean($this->input->post('id', true)); + $band = $this->security->xss_clean($this->input->post('band', true)); + + $this->bands->saveupdatedband($id, $band); + echo json_encode(array('message' => 'OK')); + return; } public function delete() { diff --git a/application/models/Bands.php b/application/models/Bands.php index cf7e51f9..3c7c2b81 100644 --- a/application/models/Bands.php +++ b/application/models/Bands.php @@ -257,6 +257,23 @@ class Bands extends CI_Model { $this->db->query("insert into bandxuser (bandid, userid, active, cq, dok, dxcc, iota, sig, sota, uscounties, was, vucc) select bands.id, " . $this->session->userdata('user_id') . ", 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 from bands where band ='".$data['band']."' and not exists (select 1 from bandxuser where userid = " . $this->session->userdata('user_id') . " and bandid = bands.id);"); } + + function getband($id) { + $this->db->where('id', $id); + return $this->db->get('bands'); + } + + function saveupdatedband($id, $band) { + $data = array( + 'band' => $band, + ); + + $this->db->where('bands.id', $id); + + $this->db->update('bands', $data); + + return true; + } } ?> \ No newline at end of file diff --git a/application/views/bands/edit.php b/application/views/bands/edit.php new file mode 100644 index 00000000..79d14742 --- /dev/null +++ b/application/views/bands/edit.php @@ -0,0 +1,14 @@ +