From 670d5b9213cd32f3d59a719aebbf436c89ef8f11 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 27 Oct 2022 15:17:52 +0200 Subject: [PATCH 1/2] Deal with misset user locator without failing --- application/controllers/Logbook.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 677afec2..78233465 100755 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -58,9 +58,13 @@ class Logbook extends CI_Controller { if($this->session->userdata('user_locator')) { $this->load->library('qra'); $qra_position = $this->qra->qra2latlong($this->session->userdata('user_locator')); - $data['qra'] = "set"; - $data['qra_lat'] = $qra_position[0]; - $data['qra_lng'] = $qra_position[1]; + if (isset($qra_position[0]) and isset($qra_position[1])) { + $data['qra'] = "set"; + $data['qra_lat'] = $qra_position[0]; + $data['qra_lng'] = $qra_position[1]; + } else { + $data['qra'] = "none"; + } } else { $data['qra'] = "none"; } From 11ff04208a6f7e538fc7f5d19f464def2792a4c6 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 27 Oct 2022 15:18:50 +0200 Subject: [PATCH 2/2] Check locator for valid value --- application/controllers/User.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/application/controllers/User.php b/application/controllers/User.php index f68d5434..7128e97f 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -40,6 +40,7 @@ class User extends CI_Controller { $this->form_validation->set_rules('user_lastname', 'Last name', 'required'); $this->form_validation->set_rules('user_callsign', 'Callsign', 'required'); $this->form_validation->set_rules('user_locator', 'Locator', 'required'); + $this->form_validation->set_rules('user_locator', 'Locator', 'callback_check_locator'); $this->form_validation->set_rules('user_timezone', 'Timezone', 'required'); // Get themes list @@ -167,7 +168,7 @@ class User extends CI_Controller { $this->form_validation->set_rules('user_firstname', 'First name', 'required|xss_clean'); $this->form_validation->set_rules('user_lastname', 'Last name', 'required|xss_clean'); $this->form_validation->set_rules('user_callsign', 'Callsign', 'trim|required|xss_clean'); - $this->form_validation->set_rules('user_locator', 'Locator', 'required|xss_clean'); + $this->form_validation->set_rules('user_locator', 'Locator', 'callback_check_locator'); $this->form_validation->set_rules('user_timezone', 'Timezone', 'required'); // Get themes list @@ -629,4 +630,26 @@ class User extends CI_Controller { redirect('user/login'); } } + + function check_locator($grid) { + $grid = $this->input->post('user_locator'); + // Allow empty locator + if (preg_match('/^$/', $grid)) return true; + // Allow 6-digit locator + if (preg_match('/^[A-Ra-r]{2}[0-9]{2}[A-Za-z]{2}$/', $grid)) return true; + // Allow 4-digit locator + else if (preg_match('/^[A-Ra-r]{2}[0-9]{2}$/', $grid)) return true; + // Allow 4-digit grid line + else if (preg_match('/^[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2}$/', $grid)) return true; + // Allow 4-digit grid corner + else if (preg_match('/^[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2}$/', $grid)) return true; + // Allow 2-digit locator + else if (preg_match('/^[A-Ra-r]{2}$/', $grid)) return true; + // Allow 8-digit locator + else if (preg_match('/^[A-Ra-r]{2}[0-9]{2}[A-Za-z]{2}[0-9]{2}$/', $grid)) return true; + else { + $this->form_validation->set_message('check_locator', 'Please check value for grid locator ('.strtoupper($grid).').'); + return false; + } + } }