From b4f1f63098104be57ba278276f58f39953895faa Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sun, 9 Oct 2022 16:46:37 +0100 Subject: [PATCH] [Welcome] Hide Creating Logbooks or claiming locations Hide Creating Logbooks or claiming locations if they are already in the database --- application/controllers/Welcome.php | 20 +++++++++++++++++ application/models/Logbooks_model.php | 31 +++++++++++++++++++++++++-- application/models/Stations.php | 9 +++++++- application/views/welcome/index.php | 22 ++++++++++++------- 4 files changed, 71 insertions(+), 11 deletions(-) diff --git a/application/controllers/Welcome.php b/application/controllers/Welcome.php index ec4f4ee0..f163f3f8 100644 --- a/application/controllers/Welcome.php +++ b/application/controllers/Welcome.php @@ -13,6 +13,13 @@ class Welcome extends CI_Controller { { $data['page_title'] = "Welcome to Cloudlog Version 2.0"; + // load stations model + $this->load->model('stations'); + $data['CountAllStationLocations'] = $this->stations->CountAllStationLocations(); + echo $data['CountAllStationLocations']; + $this->load->model('logbooks_model'); + $data['NumberOfStationLogbooks'] = $this->logbooks_model->CountAllStationLogbooks(); + $this->load->view('interface_assets/header', $data); $this->load->view('welcome/index'); $this->load->view('interface_assets/footer'); @@ -30,4 +37,17 @@ class Welcome extends CI_Controller { echo "Error Claiming Station Locations during Migration. See Logs for further information"; } } + + public function defaultlogbook() { + try { + // load model Stations and call function ClaimAllStationLocations + $this->load->model('logbooks_model'); + $this->logbooks_model->CreateDefaultLogbook(); + + echo "Default Logbook Created"; + } catch (Exception $e) { + log_message('error', 'Error Creating Default Logbook during Migration. '.$e->getMessage()); + echo "Error Creating Default Logbook during Migration. See Logs for further information"; + } + } } \ No newline at end of file diff --git a/application/models/Logbooks_model.php b/application/models/Logbooks_model.php index aede928f..c97bb467 100644 --- a/application/models/Logbooks_model.php +++ b/application/models/Logbooks_model.php @@ -7,6 +7,11 @@ class Logbooks_model extends CI_Model { return $this->db->get('station_logbooks'); } + function CountAllStationLogbooks() { + // count all logbooks + return $this->db->count_all('station_logbooks'); + } + function add() { // Create data array with field values $data = array( @@ -30,6 +35,21 @@ class Logbooks_model extends CI_Model { } } + function CreateDefaultLogbook() { + // Get the first USER ID from user table in the database + $id = $this->db->get("users")->row()->user_id; + + $data = array( + 'user_id' => $id, + 'logbook_name' => "Default Logbook", + ); + + $this->db->insert('station_logbooks', $data); + $logbook_id = $this->db->insert_id(); + + $this->set_logbook_active($logbook_id, $id); + } + function delete($id) { // Clean ID $clean_id = $this->security->xss_clean($id); @@ -55,10 +75,17 @@ class Logbooks_model extends CI_Model { $this->db->update('station_logbooks', $data); } - function set_logbook_active($id) { + function set_logbook_active($id, $user_id = null) { // Clean input $cleanId = xss_clean($id); + // check if user_id is set + if ($user_id === null) { + $user_id = $this->session->userdata('user_id'); + } else { + $user_id = xss_clean($user_id); + } + // be sure that logbook belongs to user if (!$this->check_logbook_is_accessible($cleanId)) { return; @@ -68,7 +95,7 @@ class Logbooks_model extends CI_Model { 'active_station_logbook' => $cleanId, ); - $this->db->where('user_id', $this->session->userdata('user_id')); + $this->db->where('user_id', $user_id); $this->db->update('users', $data); } diff --git a/application/models/Stations.php b/application/models/Stations.php index 69e4a44f..b02b5304 100644 --- a/application/models/Stations.php +++ b/application/models/Stations.php @@ -148,7 +148,7 @@ class Stations extends CI_Model { // Get the first USER ID from user table in the database $id = $this->db->get("users")->row()->user_id; } - + $data = array( 'user_id' => $id, ); @@ -156,6 +156,13 @@ class Stations extends CI_Model { $this->db->update('station_profile', $data); } + function CountAllStationLocations() { + // count all logbooks + // where user_id is not NULL + $this->db->where('user_id !=', NULL); + return $this->db->count_all('station_logbooks'); + } + function set_active($current, $new) { // Clean inputs $clean_current = $this->security->xss_clean($current); diff --git a/application/views/welcome/index.php b/application/views/welcome/index.php index 608dcc02..39607e8d 100644 --- a/application/views/welcome/index.php +++ b/application/views/welcome/index.php @@ -90,6 +90,7 @@
+
Assign ALL Station Locations to this username
@@ -99,15 +100,20 @@

- -
-
Create Station Logbooks
-
-

Needs Text

-
-
+ -
+ +
+
Create Station Logbooks
+
+

All the views now in Cloudlog are based around Station Logbooks, you can create as many as you want and group Station Locations it makes tracking awards a lot easier.

+

You don't have one at the moment and it can cause issues so press the button below and create a default logbook, you can change this later!

+ +
+
+ +
+
Update Country Files