From 278cf3b016952fa52fb50df7fcd60353ef71f964 Mon Sep 17 00:00:00 2001 From: Thomas Werzmirzowsky Date: Sat, 4 Dec 2021 17:14:57 +0100 Subject: [PATCH] set logbook active on creation of first logbook set station profile active on creation of first station profile disabled deletion of active logbook disabled deletion of active station profile --- application/models/Logbooks_model.php | 23 ++++++++++++++++++--- application/models/Stations.php | 12 +++++++++++ application/views/logbooks/index.php | 6 ++++-- application/views/station_profile/index.php | 7 +++++-- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/application/models/Logbooks_model.php b/application/models/Logbooks_model.php index 82e46858..ffa92a1b 100644 --- a/application/models/Logbooks_model.php +++ b/application/models/Logbooks_model.php @@ -8,7 +8,7 @@ class Logbooks_model extends CI_Model { return $this->db->get('station_logbooks'); } - function add() { + function add() { // Create data array with field values $data = array( 'user_id' => $this->session->userdata('user_id'), @@ -16,14 +16,31 @@ class Logbooks_model extends CI_Model { ); // Insert Records - $this->db->insert('station_logbooks', $data); + $this->db->insert('station_logbooks', $data); + $logbook_id = $this->db->insert_id(); + + // check if user has no active logbook yet + if ($this->session->userdata('active_station_logbook') === null) { + // set logbook active + $this->set_logbook_active($logbook_id); + + // update user session data + $CI =& get_instance(); + $CI->load->model('user_model'); + $CI->user_model->update_session($this->session->userdata('user_id')); + } } function delete($id) { // Clean ID $clean_id = $this->security->xss_clean($id); - // Delete QSOs + // do not delete active logbook + if ($this->session->userdata('active_station_logbook') === $clean_id) { + return; + } + + // Delete logbook $this->db->where('user_id', $this->session->userdata('user_id')); $this->db->where('logbook_id', $id); $this->db->delete('station_logbooks'); diff --git a/application/models/Stations.php b/application/models/Stations.php index c4db7311..12cdb296 100644 --- a/application/models/Stations.php +++ b/application/models/Stations.php @@ -50,9 +50,16 @@ class Stations extends CI_Model { * Adds post material into the station profile table. */ function add() { + // check if user has no active station profile yet + $station_active = null; + if ($this->find_active() === '0') { + $station_active = 1; + } + // Create data array with field values $data = array( 'user_id' => $this->session->userdata('user_id'), + 'station_active' => $station_active, 'station_profile_name' => xss_clean($this->input->post('station_profile_name', true)), 'station_gridsquare' => xss_clean(strtoupper($this->input->post('gridsquare', true))), 'station_city' => xss_clean($this->input->post('city', true)), @@ -106,6 +113,11 @@ class Stations extends CI_Model { // Clean ID $clean_id = $this->security->xss_clean($id); + // do not delete active station + if ($clean_id === $this->find_active()) { + return; + } + // Delete QSOs $this->db->where('station_id', $id); $this->db->delete($this->config->item('table_name')); diff --git a/application/views/logbooks/index.php b/application/views/logbooks/index.php index 2c936417..cba7457a 100644 --- a/application/views/logbooks/index.php +++ b/application/views/logbooks/index.php @@ -43,8 +43,10 @@ logbook_id; ?>" class="btn btn-outline-primary btn-sm"> Edit - logbook_id; ?>" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want delete station profile logbook_name; ?> this will delete all QSOs within this station logbook?');"> Delete - + session->userdata('active_station_logbook') != $row->logbook_id) { ?> + logbook_id; ?>" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want delete station profile logbook_name; ?> this will delete all QSOs within this station logbook?');"> Delete + + diff --git a/application/views/station_profile/index.php b/application/views/station_profile/index.php index 81223879..3dacda2e 100644 --- a/application/views/station_profile/index.php +++ b/application/views/station_profile/index.php @@ -61,7 +61,7 @@ station_country;?> station_gridsquare;?> - station_active != 1) { ?> + station_active != 1) { ?> station_id; ?>" class="btn btn-outline-secondary btn-sm" onclick="return confirm('Are you sure you want to make station station_profile_name; ?> the active station?');">Set Active Active Station @@ -84,7 +84,10 @@ 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 - station_id; ?>" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want delete station profile station_profile_name; ?> this will delete all QSOs within this station profile?');"> Delete Profile + station_active != 1) { ?> + station_id; ?>" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want delete station profile station_profile_name; ?> this will delete all QSOs within this station profile?');"> Delete Profile + +