From ce1d7a5351ea6d0a263c005258664c33cf227adf Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Tue, 7 Sep 2021 18:07:48 +0100 Subject: [PATCH] Code added to have an active logbook and code to set it all up --- application/config/migration.php | 2 +- application/controllers/Logbooks.php | 8 ++++++ ...d_active_station_logbook_to_user_table.php | 25 +++++++++++++++++++ application/models/Logbooks_model.php | 9 +++++++ application/models/User_model.php | 1 + application/views/logbooks/edit.php | 2 +- application/views/logbooks/index.php | 8 +++--- 7 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 application/migrations/074_add_active_station_logbook_to_user_table.php diff --git a/application/config/migration.php b/application/config/migration.php index 7a7090ee..03abdf21 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE; | be upgraded / downgraded to. | */ -$config['migration_version'] = 73; +$config['migration_version'] = 74; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Logbooks.php b/application/controllers/Logbooks.php index b1b68fde..b723fc9c 100644 --- a/application/controllers/Logbooks.php +++ b/application/controllers/Logbooks.php @@ -96,6 +96,14 @@ class Logbooks extends CI_Controller { } } + public function set_active($id) { + $this->load->model('logbooks_model'); + $this->logbooks_model->set_logbook_active($id); + $this->user_model->update_session($this->session->userdata('user_id')); + + redirect('logbooks'); + } + public function delete($id) { $this->load->model('logbooks_model'); $this->logbooks_model->delete($id); diff --git a/application/migrations/074_add_active_station_logbook_to_user_table.php b/application/migrations/074_add_active_station_logbook_to_user_table.php new file mode 100644 index 00000000..61bc1718 --- /dev/null +++ b/application/migrations/074_add_active_station_logbook_to_user_table.php @@ -0,0 +1,25 @@ +dbforge->add_column('users', $fields); + } + + public function down() + { + $this->dbforge->drop_column('users', 'active_station_logbook'); + } +} diff --git a/application/models/Logbooks_model.php b/application/models/Logbooks_model.php index cb7aa401..a89f2610 100644 --- a/application/models/Logbooks_model.php +++ b/application/models/Logbooks_model.php @@ -45,6 +45,15 @@ class Logbooks_model extends CI_Model { $this->db->update('station_logbooks', $data); } + function set_logbook_active($id) { + $data = array( + 'active_station_logbook' => xss_clean($id), + ); + + $this->db->where('user_id', $this->session->userdata('user_id')); + $this->db->update('users', $data); + } + function logbook($id) { // Clean ID $clean_id = $this->security->xss_clean($id); diff --git a/application/models/User_model.php b/application/models/User_model.php index ab368d51..8aef15d1 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -283,6 +283,7 @@ class User_Model extends CI_Model { 'user_column3' => isset($u->row()->user_column3) ? $u->row()->user_column3: 'RSTR', 'user_column4' => isset($u->row()->user_column4) ? $u->row()->user_column4: 'Band', 'user_column5' => isset($u->row()->user_column5) ? $u->row()->user_column5: 'Country', + 'active_station_logbook' => $u->row()->active_station_logbook, ); $this->session->set_userdata($userdata); diff --git a/application/views/logbooks/edit.php b/application/views/logbooks/edit.php index e8826962..019b5b39 100644 --- a/application/views/logbooks/edit.php +++ b/application/views/logbooks/edit.php @@ -45,7 +45,7 @@ Hold down the Ctrl (windows) or Command (Mac) button to select multiple options. diff --git a/application/views/logbooks/index.php b/application/views/logbooks/index.php index cc1c8635..c5e3b309 100644 --- a/application/views/logbooks/index.php +++ b/application/views/logbooks/index.php @@ -37,10 +37,12 @@ - logbook_id; ?>" class="btn btn-outline-primary btn-sm"> Edit - + session->userdata('active_station_logbook') != $row->logbook_id) { ?> + logbook_id; ?>" class="btn btn-outline-primary btn-sm">Set as Active Logbook + + + 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 Station Logbook