Add POTA lookup function

This commit is contained in:
phl0 2023-05-01 21:14:30 +02:00
parent cb71e0961f
commit 846dec0f61
No known key found for this signature in database
GPG Key ID: 48EA1E640798CA9A
9 changed files with 156 additions and 3 deletions

View File

@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 120;
$config['migration_version'] = 121;
/*
|--------------------------------------------------------------------------

View File

@ -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'));

View File

@ -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');

View File

@ -0,0 +1,59 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/***
* Pota library is a Parks On The Air client
*/
class Pota
{
// return summit references matching the provided query
public function get($query): array
{
if (empty($query)) {
return [];
}
$json = [];
$ref = strtoupper($query);
$file = 'assets/json/pota.txt';
if (is_readable($file)) {
$lines = file($file, FILE_IGNORE_NEW_LINES);
$input = preg_quote($ref, '~');
$reg = '~^' . $input . '(.*)$~';
$result = preg_grep($reg, $lines);
foreach ($result as &$value) {
// Limit to 100 as to not slowdown browser too much
if (count($json) <= 100) {
$json[] = ["name" => $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;
}
}

View File

@ -0,0 +1,29 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
* This adds an option to enable grid and name lookup
* for WWFF references
*/
class Migration_add_user_pota_lookup extends CI_Migration {
public function up()
{
if (!$this->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');
}
}
}

View File

@ -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',

View File

@ -1084,6 +1084,27 @@ $(document).on('keypress',function(e) {
});
<?php } ?>
<?php if ($this->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('');
},
});
}
});
<?php } ?>
$('#stationProfile').change(function() {
var stationProfile = $('#stationProfile').val();
$.ajax({

View File

@ -267,6 +267,20 @@
from the API and filled in location and locator.</div>
</td>
</div>
<div class="form-group col-md-12">
<label for="potalookup">POTA auto lookup gridsquare and name for
park.</label>
<select class="custom-select" id="potalookup" name="user_pota_lookup">
<option value="0"><?php echo $this->lang->line('general_word_no'); ?>
</option>
<option value="1"><?php echo $this->lang->line('general_word_yes'); ?>
</option>
</select>
<div class="small form-text text-muted">If set, name and gridsquare is fetched
from the API and filled in location and locator.</div>
</td>
</div>
</div>
</div>

View File

@ -318,13 +318,21 @@
<div class="small form-text text-muted">If set, name and gridsquare is fetched from the API and filled in location and locator.</div></td>
</div>
<div class="form-group col-md-12">
<label for="wwfflookup">WWFF auto lookup gridsquare and name for summit.</label>
<label for="wwfflookup">WWFF auto lookup gridsquare and name for reference.</label>
<select class="custom-select" id="wwfflookup" name="user_wwff_lookup">
<option value="1" <?php if ($user_wwff_lookup == 1) { echo " selected =\"selected\""; } ?>><?php echo $this->lang->line('general_word_yes'); ?></option>
<option value="0" <?php if ($user_wwff_lookup == 0) { echo " selected =\"selected\""; } ?>><?php echo $this->lang->line('general_word_no'); ?></option>
</select>
<div class="small form-text text-muted">If set, name and gridsquare is fetched from the API and filled in location and locator.</div></td>
</div>
<div class="form-group col-md-12">
<label for="potalookup">POTA auto lookup gridsquare and name for park.</label>
<select class="custom-select" id="potalookup" name="user_pota_lookup">
<option value="1" <?php if ($user_pota_lookup == 1) { echo " selected =\"selected\""; } ?>><?php echo $this->lang->line('general_word_yes'); ?></option>
<option value="0" <?php if ($user_pota_lookup == 0) { echo " selected =\"selected\""; } ?>><?php echo $this->lang->line('general_word_no'); ?></option>
</select>
<div class="small form-text text-muted">If set, name and gridsquare is fetched from the API and filled in location and locator.</div></td>
</div>
</div>
</div>
</div>