From 6d68e6459daacfad84068225c9b548077dd1b599 Mon Sep 17 00:00:00 2001 From: phl0 Date: Sun, 15 Mar 2026 09:04:05 +0100 Subject: [PATCH 1/2] Use logbook ID instead of public slug for pulling worked grids --- application/controllers/Api.php | 41 +++++++++------------------ application/models/Logbooks_model.php | 19 ++++++++++++- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 16420d378..8e3af5570 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -748,13 +748,13 @@ class API extends CI_Controller { die(); } $api_user_id = $this->api_model->key_userid($obj['key']); - if(!isset($obj['logbook_public_slug'])) { + if(!isset($obj['logbook_id'])) { http_response_code(400); echo json_encode(['status' => 'failed', 'reason' => "missing fields"]); return; } - if($obj['logbook_public_slug'] != "") { - $logbook_slug = $obj['logbook_public_slug']; + if($obj['logbook_id'] != "") { + $logbook_id = $obj['logbook_id']; if(isset($obj['band'])) { $band = $obj['band']; } else { @@ -766,37 +766,24 @@ class API extends CI_Controller { $cnfm = null; } $this->load->model('logbooks_model'); - if(!$this->logbooks_model->public_slug_belongs_to_user($logbook_slug, $api_user_id)) { + if(!$this->logbooks_model->logbook_id_belongs_to_user($logbook_id, $api_user_id)) { http_response_code(403); - echo json_encode(['status' => 'failed', 'reason' => "logbook does not belong to this api key"]); + echo json_encode(['status' => 'failed', 'reason' => "logbook does not belong to this API key or logbook ID not found"]); die(); } - if($this->logbooks_model->public_slug_exists($logbook_slug)) { - $logbook_id = $this->logbooks_model->public_slug_exists_logbook_id($logbook_slug); - if($logbook_id != false) - { - $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($logbook_id); - if (!$logbooks_locations_array) { - http_response_code(404); - echo json_encode(['status' => 'failed', 'reason' => "Empty Logbook"]); - die(); - } - } else { + if ($this->logbooks_model->exists_logbook_id($logbook_id) != false) { + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($logbook_id); + if ($logbooks_locations_array[0] == -1) { http_response_code(404); - echo json_encode(['status' => 'failed', 'reason' => $logbook_slug." has no associated station locations"]); + echo json_encode(['status' => 'failed', 'reason' => "logbook with ID ".$logbook_id." has no associated station locations"]); die(); } - $this->load->model('logbook_model'); - - $arr = $this->api_model->get_grids_worked_in_logbook($logbooks_locations_array, $band, $cnfm); - http_response_code(201); - echo json_encode($arr); - - } else { - http_response_code(404); - echo json_encode(['status' => 'failed', 'reason' => "logbook not found"]); - die(); } + $this->load->model('logbook_model'); + + $arr = $this->api_model->get_grids_worked_in_logbook($logbooks_locations_array, $band, $cnfm); + http_response_code(201); + echo json_encode($arr); } diff --git a/application/models/Logbooks_model.php b/application/models/Logbooks_model.php index b114c2139..9ad07daa3 100644 --- a/application/models/Logbooks_model.php +++ b/application/models/Logbooks_model.php @@ -178,7 +178,6 @@ class Logbooks_model extends CI_Model { function public_slug_exists_logbook_id($slug) { $this->db->where('public_slug', $this->security->xss_clean($slug)); $query = $this->db->get('station_logbooks'); - if ($query->num_rows() > 0){ foreach ($query->result() as $row) { return $row->logbook_id; @@ -188,6 +187,17 @@ class Logbooks_model extends CI_Model { } } + function exists_logbook_id($logbook_id) { + $this->db->where('logbook_id', $this->security->xss_clean($logbook_id)); + $query = $this->db->get('station_logbooks'); + + if ($query->num_rows() > 0){ + return true; + } else { + return false; + } + } + function public_slug_belongs_to_user($slug, $user_id) { $this->db->where('public_slug', $this->security->xss_clean($slug)); $this->db->where('user_id', $user_id); @@ -195,6 +205,13 @@ class Logbooks_model extends CI_Model { return $query->num_rows() > 0; } + function logbook_id_belongs_to_user($logbook_id, $user_id) { + $this->db->where('logbook_id', $this->security->xss_clean($logbook_id)); + $this->db->where('user_id', $user_id); + $query = $this->db->get('station_logbooks'); + return $query->num_rows() > 0; + } + function is_public_slug_available($slug) { // Clean public_slug $clean_slug = $this->security->xss_clean($slug); From cc4dfe2d1e6731f152cc1d8710279357a9c0fcc5 Mon Sep 17 00:00:00 2001 From: phl0 Date: Sun, 15 Mar 2026 10:40:36 +0100 Subject: [PATCH 2/2] Fix logic --- application/controllers/Api.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 8e3af5570..4ae4f64d5 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -777,14 +777,12 @@ class API extends CI_Controller { http_response_code(404); echo json_encode(['status' => 'failed', 'reason' => "logbook with ID ".$logbook_id." has no associated station locations"]); die(); + } else { + $arr = $this->api_model->get_grids_worked_in_logbook($logbooks_locations_array, $band, $cnfm); + http_response_code(201); + echo json_encode($arr); } } - $this->load->model('logbook_model'); - - $arr = $this->api_model->get_grids_worked_in_logbook($logbooks_locations_array, $band, $cnfm); - http_response_code(201); - echo json_encode($arr); - } }