From 846dec0f61305d372ef55f46446fdf7c71a012a6 Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 1 May 2023 21:14:30 +0200 Subject: [PATCH] Add POTA lookup function --- application/config/migration.php | 2 +- application/controllers/Qso.php | 9 +++ application/controllers/User.php | 10 ++++ application/libraries/Pota.php | 59 +++++++++++++++++++ .../migrations/121_add_user_pota_lookup.php | 29 +++++++++ application/models/User_model.php | 5 +- application/views/interface_assets/footer.php | 21 +++++++ application/views/user/add.php | 14 +++++ application/views/user/edit.php | 10 +++- 9 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 application/libraries/Pota.php create mode 100644 application/migrations/121_add_user_pota_lookup.php diff --git a/application/config/migration.php b/application/config/migration.php index 982aa71d..36e3840a 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'] = 120; +$config['migration_version'] = 121; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 1c26e734..3189df04 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -483,6 +483,15 @@ class QSO extends CI_Controller { echo $this->wwff->info($wwff); } + public function get_pota_info() { + $this->load->library('pota'); + + $pota = xss_clean($this->input->post('pota')); + + header('Content-Type: application/json'); + echo $this->pota->info($pota); + } + public function get_station_power() { $this->load->model('stations'); $stationProfile = xss_clean($this->input->post('stationProfile')); diff --git a/application/controllers/User.php b/application/controllers/User.php index fecca221..e34e91f1 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -73,6 +73,7 @@ class User extends CI_Controller { $data['user_qth_lookup'] = $this->input->post('user_qth_lookup'); $data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $data['user_wwff_lookup'] = $this->input->post('user_wwff_lookup'); + $data['user_pota_lookup'] = $this->input->post('user_pota_lookup'); $data['user_show_notes'] = $this->input->post('user_show_notes'); $data['user_column1'] = $this->input->post('user_column1'); $data['user_column2'] = $this->input->post('user_column2'); @@ -105,6 +106,7 @@ class User extends CI_Controller { $this->input->post('user_qth_lookup'), $this->input->post('user_sota_lookup'), $this->input->post('user_wwff_lookup'), + $this->input->post('user_pota_lookup'), $this->input->post('user_show_notes'), $this->input->post('user_column1'), $this->input->post('user_column2'), @@ -146,6 +148,7 @@ class User extends CI_Controller { $data['user_qth_lookup'] = $this->input->post('user_qth_lookup'); $data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $data['user_wwff_lookup'] = $this->input->post('user_wwff_lookup'); + $data['user_pota_lookup'] = $this->input->post('user_pota_lookup'); $data['user_show_notes'] = $this->input->post('user_show_notes'); $data['user_column1'] = $this->input->post('user_column1'); $data['user_column2'] = $this->input->post('user_column2'); @@ -332,6 +335,12 @@ class User extends CI_Controller { $data['user_wwff_lookup'] = $q->user_wwff_lookup; } + if($this->input->post('user_pota_lookup')) { + $data['user_pota_lookup'] = $this->input->post('user_pota_lookup', true); + } else { + $data['user_pota_lookup'] = $q->user_pota_lookup; + } + if($this->input->post('user_show_notes')) { $data['user_show_notes'] = $this->input->post('user_show_notes', true); } else { @@ -430,6 +439,7 @@ class User extends CI_Controller { $data['user_qth_lookup'] = $this->input->post('user_qth_lookup'); $data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $data['user_wwff_lookup'] = $this->input->post('user_wwff_lookup'); + $data['user_pota_lookup'] = $this->input->post('user_pota_lookup'); $data['user_show_notes'] = $this->input->post('user_show_notes'); $data['user_column1'] = $this->input->post('user_column1'); $data['user_column2'] = $this->input->post('user_column2'); diff --git a/application/libraries/Pota.php b/application/libraries/Pota.php new file mode 100644 index 00000000..7e404885 --- /dev/null +++ b/application/libraries/Pota.php @@ -0,0 +1,59 @@ + $value]; + } + } + } + + return $json; + } + + // fetches the summit information from POTA + public function info($ref) { + $url = 'https://api.pota.app/park/'.$ref; + + // Let's use cURL instead of file_get_contents + // begin script + $ch = curl_init(); + + // basic curl options for all requests + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HEADER, 0); + + // use the URL we built + curl_setopt($ch, CURLOPT_URL, $url); + + $summit_info = curl_exec($ch); + + // Close cURL handle + curl_close($ch); + + return $summit_info; + } +} diff --git a/application/migrations/121_add_user_pota_lookup.php b/application/migrations/121_add_user_pota_lookup.php new file mode 100644 index 00000000..5575da43 --- /dev/null +++ b/application/migrations/121_add_user_pota_lookup.php @@ -0,0 +1,29 @@ +db->field_exists('user_pota_lookup', 'users')) { + $fields = array( + 'user_pota_lookup integer DEFAULT 0 AFTER user_wwff_lookup', + ); + + $this->dbforge->add_column('users', $fields); + } + } + + public function down() + { + if ($this->db->field_exists('user_pota_lookup', 'users')) { + $this->dbforge->drop_column('users', 'user_pota_lookup'); + } + } +} diff --git a/application/models/User_model.php b/application/models/User_model.php index 5e6de8c8..d58cf883 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -122,7 +122,7 @@ class User_Model extends CI_Model { // Add a user function add($username, $password, $email, $type, $firstname, $lastname, $callsign, $locator, $timezone, $measurement, $user_date_format, $user_stylesheet, $user_qth_lookup, $user_sota_lookup, $user_wwff_lookup, - $user_show_notes, $user_column1, $user_column2, $user_column3, $user_column4, $user_column5, + $user_pota_lookup, $user_show_notes, $user_column1, $user_column2, $user_column3, $user_column4, $user_column5, $user_show_profile_image, $user_previous_qsl_type, $user_amsat_status_upload) { // Check that the user isn't already used if(!$this->exists($username)) { @@ -142,6 +142,7 @@ class User_Model extends CI_Model { 'user_qth_lookup' => xss_clean($user_qth_lookup), 'user_sota_lookup' => xss_clean($user_sota_lookup), 'user_wwff_lookup' => xss_clean($user_wwff_lookup), + 'user_pota_lookup' => xss_clean($user_pota_lookup), 'user_show_notes' => xss_clean($user_show_notes), 'user_column1' => xss_clean($user_column1), 'user_column2' => xss_clean($user_column2), @@ -197,6 +198,7 @@ class User_Model extends CI_Model { 'user_qth_lookup' => xss_clean($fields['user_qth_lookup']), 'user_sota_lookup' => xss_clean($fields['user_sota_lookup']), 'user_wwff_lookup' => xss_clean($fields['user_wwff_lookup']), + 'user_pota_lookup' => xss_clean($fields['user_pota_lookup']), 'user_show_notes' => xss_clean($fields['user_show_notes']), 'user_column1' => xss_clean($fields['user_column1']), 'user_column2' => xss_clean($fields['user_column2']), @@ -316,6 +318,7 @@ class User_Model extends CI_Model { 'user_qth_lookup' => isset($u->row()->user_qth_lookup) ? $u->row()->user_qth_lookup : 0, 'user_sota_lookup' => isset($u->row()->user_sota_lookup) ? $u->row()->user_sota_lookup : 0, 'user_wwff_lookup' => isset($u->row()->user_wwff_lookup) ? $u->row()->user_wwff_lookup : 0, + 'user_pota_lookup' => isset($u->row()->user_pota_lookup) ? $u->row()->user_pota_lookup : 0, 'user_show_notes' => isset($u->row()->user_show_notes) ? $u->row()->user_show_notes : 1, 'user_show_profile_image' => isset($u->row()->user_show_profile_image) ? $u->row()->user_show_profile_image : 0, 'user_column1' => isset($u->row()->user_column1) ? $u->row()->user_column1: 'Mode', diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 4d507f9e..89384901 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -1084,6 +1084,27 @@ $(document).on('keypress',function(e) { }); +session->userdata('user_pota_lookup') == 1) { ?> + $('#pota_ref').change(function() { + var pota = $('#pota_ref').val(); + if (pota.length > 0) { + $.ajax({ + url: base_url+'index.php/qso/get_pota_info', + type: 'post', + data: {'pota': pota}, + success: function(res) { + $('#qth').val(res.name); + $('#locator').val(res.grid6); + }, + error: function() { + $('#qth').val(''); + $('#locator').val(''); + }, + }); + } + }); + + $('#stationProfile').change(function() { var stationProfile = $('#stationProfile').val(); $.ajax({ diff --git a/application/views/user/add.php b/application/views/user/add.php index 0ae5ce78..a10ce41c 100644 --- a/application/views/user/add.php +++ b/application/views/user/add.php @@ -267,6 +267,20 @@ from the API and filled in location and locator. + +
+ + +
If set, name and gridsquare is fetched + from the API and filled in location and locator.
+ +
diff --git a/application/views/user/edit.php b/application/views/user/edit.php index df6a25e2..8e3bd2fc 100644 --- a/application/views/user/edit.php +++ b/application/views/user/edit.php @@ -318,13 +318,21 @@
If set, name and gridsquare is fetched from the API and filled in location and locator.
- +
If set, name and gridsquare is fetched from the API and filled in location and locator.
+
+ + +
If set, name and gridsquare is fetched from the API and filled in location and locator.
+