From 87d5c8e1b0706798c341a8c6b54aef2195d1f4d6 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Tue, 12 Oct 2021 15:19:39 +0100 Subject: [PATCH] [Station Logbook] Improved edit interface --- application/controllers/Logbooks.php | 26 +++++++---- application/models/Logbooks_model.php | 35 +++++++++++++++ application/views/logbooks/edit.php | 65 ++++++++++++++++++++------- 3 files changed, 101 insertions(+), 25 deletions(-) diff --git a/application/controllers/Logbooks.php b/application/controllers/Logbooks.php index b723fc9c..9e136115 100644 --- a/application/controllers/Logbooks.php +++ b/application/controllers/Logbooks.php @@ -63,10 +63,12 @@ class Logbooks extends CI_Controller { $data['station_logbook_details'] = $station_logbook_details_query->row(); $data['station_locations_list'] = $this->stations->all(); + + $data['station_locations_linked'] = $this->logbooks_model->list_logbooks_linked($station_logbook_id); $data['page_title'] = "Edit Station Logbook"; - $this->form_validation->set_rules('station_logbook_name', 'Station Logbook Name', 'required'); + $this->form_validation->set_rules('station_logbook_id', 'Station Logbook Name', 'required'); if ($this->form_validation->run() == FALSE) { @@ -76,23 +78,22 @@ class Logbooks extends CI_Controller { } else { - $this->logbooks_model->edit(); $data['notice'] = "Station Logbooks ".$this->security->xss_clean($this->input->post('station_logbook_name', true))." Updated"; - foreach ($this->input->post('SelectedStationLocations') as $selectedOption){ - // Check if theres already a link between logbook and location - if($this->logbooks_model->relationship_exists($this->input->post('station_logbook_id'), $selectedOption) != TRUE) { + if($this->input->post('SelectedStationLocation') != "") { + if($this->logbooks_model->relationship_exists($this->input->post('station_logbook_id'), $this->input->post('SelectedStationLocation')) != TRUE) { // If no link exisits create - $this->logbooks_model->create_logbook_location_link($this->input->post('station_logbook_id'), $selectedOption); + $this->logbooks_model->create_logbook_location_link($this->input->post('station_logbook_id'), $this->input->post('SelectedStationLocation')); + echo "linked"; } else { echo "Already Linked"; } - - // Delete link if removed + } else { + $this->logbooks_model->edit(); } - redirect('logbooks'); + redirect('logbooks/edit/'.$this->input->post('station_logbook_id')); } } @@ -111,4 +112,11 @@ class Logbooks extends CI_Controller { redirect('logbooks'); } + public function delete_relationship($logbook_id, $station_id) { + $this->load->model('logbooks_model'); + $this->logbooks_model->delete_relationship($logbook_id, $station_id); + + redirect('logbooks/edit/'.$logbook_id); + } + } \ No newline at end of file diff --git a/application/models/Logbooks_model.php b/application/models/Logbooks_model.php index a89f2610..a5d44266 100644 --- a/application/models/Logbooks_model.php +++ b/application/models/Logbooks_model.php @@ -108,5 +108,40 @@ class Logbooks_model extends CI_Model { return false; } } + + function list_logbooks_linked($logbook_id) { + + $relationships_array = array(); + + $this->db->where('station_logbook_id', $logbook_id); + $query = $this->db->get('station_logbooks_relationship'); + + + if ($query->num_rows() > 0){ + foreach ($query->result() as $row) + { + array_push($relationships_array, $row->station_location_id); + } + + $this->db->where_in('station_id', $relationships_array); + $query = $this->db->get('station_profile'); + + return $query; + } + else{ + return false; + } + } + + function delete_relationship($logbook_id, $station_id) { + // Clean ID + $clean_logbook_id = $this->security->xss_clean($logbook_id); + $clean_station_id = $this->security->xss_clean($station_id); + + // Delete QSOs + $this->db->where('station_logbook_id', $clean_logbook_id); + $this->db->where('station_location_id', $clean_station_id); + $this->db->delete('station_logbooks_relationship'); + } } ?> \ No newline at end of file diff --git a/application/views/logbooks/edit.php b/application/views/logbooks/edit.php index 019b5b39..04b9485e 100644 --- a/application/views/logbooks/edit.php +++ b/application/views/logbooks/edit.php @@ -18,47 +18,80 @@ -
- - -
: logbook_name; ?>
- -
- - logbook_name; } ?>" required> - Shortname for the station location. For example: Home (IO87IP) -
+ + + +
+ + logbook_name; } ?>" required> + Shortname for the station location. For example: Home (IO87IP) +
+ + + + +
+
Station Locations
+
+ +
- result() as $row) { ?> - + - Hold down the Ctrl (windows) or Command (Mac) button to select multiple options.
+ + + + +
- +
+
+ Linked Locations +
- +
+ + + + + + + + - + + result() as $row) { ?> + + + + + + +
Location Name
station_profile_name;?> (Callsign: station_callsign;?> DXCC: station_country;?>)
+
+ +
\ No newline at end of file