From e61baa195dbdddde5a75ef76d0988c075aa1abd3 Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Wed, 17 Aug 2022 08:16:44 +0200 Subject: [PATCH] Add station copy When doing portable activations, often times you need a new station location that is identical to another one with just a few changes like the grid square, SIG, and/or SOTA. This commit implements a copy function for station locations. --- application/controllers/Station.php | 83 ++++++++++++++------- application/views/station_profile/edit.php | 20 +++-- application/views/station_profile/index.php | 1 + 3 files changed, 70 insertions(+), 34 deletions(-) diff --git a/application/controllers/Station.php b/application/controllers/Station.php index 311f1281..a7dd8495 100644 --- a/application/controllers/Station.php +++ b/application/controllers/Station.php @@ -31,7 +31,7 @@ class Station extends CI_Controller { $this->load->view('interface_assets/footer'); } - public function create() + public function create() { $this->load->model('stations'); $this->load->model('dxcc'); @@ -52,49 +52,76 @@ class Station extends CI_Controller { $this->load->view('interface_assets/footer'); } else - { + { $this->stations->add(); - + redirect('station'); } } public function edit($id) + { + $data = $this->load_station_for_editing($id); + $data['page_title'] = "Edit Station Location: {$data['my_station_profile']->station_profile_name}"; + + if ($this->form_validation->run() == FALSE) { + $this->load->view('interface_assets/header', $data); + $this->load->view('station_profile/edit'); + $this->load->view('interface_assets/footer'); + } else { + $this->stations->edit(); + + $data['notice'] = "Station Profile " . $this->security->xss_clean($this->input->post('station_profile_name', true)) . " Updated"; + + redirect('station'); + } + } + + public function copy($id) + { + $data = $this->load_station_for_editing($id); + $data['page_title'] = "Duplicate Station Location: {$data['my_station_profile']->station_profile_name}"; + + // we NULLify station_id and station_profile_name to make sure we are creating a new station + $data['copy_from'] = $data['my_station_profile']->station_id; + $data['my_station_profile']->station_id = NULL; + $data['my_station_profile']->station_profile_name = ''; + + if ($this->form_validation->run() == FALSE) + { + $this->load->view('interface_assets/header', $data); + $this->load->view('station_profile/edit'); + $this->load->view('interface_assets/footer'); + } + else + { + $this->stations->add(); + + redirect('station'); + } + } + + function load_station_for_editing($id): array { $this->load->library('form_validation'); $this->load->model('stations'); $this->load->model('dxcc'); - $this->load->model('logbook_model'); + $this->load->model('logbook_model'); - $data['iota_list'] = $this->logbook_model->fetchIota(); + $data['iota_list'] = $this->logbook_model->fetchIota(); $item_id_clean = $this->security->xss_clean($id); $station_profile_query = $this->stations->profile($item_id_clean); $data['my_station_profile'] = $station_profile_query->row(); - - $data['dxcc_list'] = $this->dxcc->list(); - $data['page_title'] = "Edit Station Location"; + $data['dxcc_list'] = $this->dxcc->list(); $this->form_validation->set_rules('station_profile_name', 'Station Profile Name', 'required'); - if ($this->form_validation->run() == FALSE) - { - $this->load->view('interface_assets/header', $data); - $this->load->view('station_profile/edit'); - $this->load->view('interface_assets/footer'); - } - else - { - $this->stations->edit(); - - $data['notice'] = "Station Profile ".$this->security->xss_clean($this->input->post('station_profile_name', true))." Updated"; - - redirect('station'); - } + return $data; } // This function allows a user to claim ownership of a station location @@ -104,7 +131,7 @@ class Station extends CI_Controller { $this->stations->claim_user($id); echo $this->session->userdata('user_id'); - + redirect('station'); } @@ -112,7 +139,7 @@ class Station extends CI_Controller { // $id is the profile that needs reassigned to QSOs $this->load->model('stations'); $this->stations->reassign($id); - + //$this->stations->logbook_session_data(); redirect('station'); } @@ -120,7 +147,7 @@ class Station extends CI_Controller { function set_active($current, $new) { $this->load->model('stations'); $this->stations->set_active($current, $new); - + //$this->stations->logbook_session_data(); redirect('station'); } @@ -128,14 +155,14 @@ class Station extends CI_Controller { function assign_all() { $this->load->model('Logbook_model'); $this->Logbook_model->update_all_station_ids(); - + redirect('station'); } public function delete($id) { $this->load->model('stations'); $this->stations->delete($id); - + redirect('station'); } @@ -179,4 +206,4 @@ class Station extends CI_Controller { echo json_encode($json); } -} \ No newline at end of file +} diff --git a/application/views/station_profile/edit.php b/application/views/station_profile/edit.php index ac17e08d..97f46ee9 100644 --- a/application/views/station_profile/edit.php +++ b/application/views/station_profile/edit.php @@ -18,16 +18,24 @@ -
+ station_id != NULL) { + $form_action = "Update"; + ?> + + - + + +
-
: station_profile_name; ?> (Callsign: station_callsign; ?>)
+
(Callsign: station_callsign; ?>)
- +
station_profile_name; } ?>" required> @@ -241,7 +249,7 @@ } ?> - + Station IOTA reference. For example: EU-005 You can look up IOTA references at the IOTA World website.
@@ -320,7 +328,7 @@
- + diff --git a/application/views/station_profile/index.php b/application/views/station_profile/index.php index b6401e8c..088596b7 100644 --- a/application/views/station_profile/index.php +++ b/application/views/station_profile/index.php @@ -79,6 +79,7 @@ station_id; ?>" class="btn btn-outline-primary btn-sm"> Claim Ownership station_id; ?>" class="btn btn-outline-primary btn-sm"> Edit + station_id; ?>" class="btn btn-outline-primary btn-sm"> Copy station_id; ?>" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want to delete all QSOs within this station profile?');"> Empty Log