From 6cc96d21282de8920292bb0bc028be68fb3bad15 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 23 Aug 2021 15:50:19 +0100 Subject: [PATCH] [Station Location] Allow user to claim a location and also only show those of the user or non claimed. --- application/controllers/Station.php | 10 ++++++++++ application/models/Stations.php | 12 ++++++++++++ application/views/station_profile/index.php | 3 +++ 3 files changed, 25 insertions(+) diff --git a/application/controllers/Station.php b/application/controllers/Station.php index e59b44dd1..3b332cc25 100644 --- a/application/controllers/Station.php +++ b/application/controllers/Station.php @@ -97,6 +97,16 @@ class Station extends CI_Controller { } } + // This function allows a user to claim ownership of a station location + function claim_user($id) { + // $id is the profile id + $this->load->model('stations'); + $this->stations->claim_user($id); + + //$this->stations->logbook_session_data(); + redirect('station'); + } + function reassign_profile($id) { // $id is the profile that needs reassigned to QSOs $this->load->model('stations'); diff --git a/application/models/Stations.php b/application/models/Stations.php index d179bb00b..57ffe5fcd 100644 --- a/application/models/Stations.php +++ b/application/models/Stations.php @@ -14,6 +14,8 @@ class Stations extends CI_Model { $this->db->from('station_profile'); $this->db->join($this->config->item('table_name'),'station_profile.station_id = '.$this->config->item('table_name').'.station_id','left'); $this->db->group_by('station_profile.station_id'); + $this->db->where('station_profile.user_id', $this->session->userdata('user_id')); + $this->db->or_where('station_profile.user_id =', NULL); return $this->db->get(); } @@ -114,6 +116,16 @@ class Stations extends CI_Model { $this->db->delete($this->config->item('table_name')); } + function claim_user($id) { + + $data = array( + 'user_id' => $this->session->userdata('user_id') + ); + + $this->db->where('station_id', xss_clean($id, true)); + $this->db->update('station_profile', $data); + } + function set_active($current, $new) { // Clean inputs diff --git a/application/views/station_profile/index.php b/application/views/station_profile/index.php index b6b480ddf..bececfeee 100644 --- a/application/views/station_profile/index.php +++ b/application/views/station_profile/index.php @@ -75,6 +75,9 @@ qso_total;?> QSOs + user_id == "") { ?> + station_id; ?>" class="btn btn-outline-primary btn-sm"> Claim Ownership + station_id; ?>" class="btn btn-outline-primary btn-sm"> Edit