Add lookup function for grid and name for WWFF refs

这个提交包含在:
phl0 2022-10-19 14:52:43 +02:00
父节点 ab7f336947
当前提交 e67435d497
找不到此签名对应的密钥
GPG 密钥 ID: 48EA1E640798CA9A
共有 9 个文件被更改,包括 176 次插入26 次删除

查看文件

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

查看文件

@ -436,14 +436,23 @@ class QSO extends CI_Controller {
echo json_encode($json); echo json_encode($json);
} }
public function get_sota_info() { public function get_sota_info() {
$this->load->library('sota'); $this->load->library('sota');
$sota = xss_clean($this->input->post('sota')); $sota = xss_clean($this->input->post('sota'));
header('Content-Type: application/json'); header('Content-Type: application/json');
echo $this->sota->info($sota); echo $this->sota->info($sota);
} }
public function get_wwff_info() {
$this->load->library('wwff');
$wwff = xss_clean($this->input->post('wwff'));
header('Content-Type: application/json');
echo $this->wwff->info($wwff);
}
function check_locator($grid) { function check_locator($grid) {
$grid = $this->input->post('locator'); $grid = $this->input->post('locator');

查看文件

@ -68,6 +68,7 @@ class User extends CI_Controller {
$data['user_measurement_base'] = $this->input->post('user_measurement_base'); $data['user_measurement_base'] = $this->input->post('user_measurement_base');
$data['user_stylesheet'] = $this->input->post('user_stylesheet'); $data['user_stylesheet'] = $this->input->post('user_stylesheet');
$data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $data['user_sota_lookup'] = $this->input->post('user_sota_lookup');
$data['user_wwff_lookup'] = $this->input->post('user_wwff_lookup');
$data['user_show_notes'] = $this->input->post('user_show_notes'); $data['user_show_notes'] = $this->input->post('user_show_notes');
$data['user_column1'] = $this->input->post('user_column1'); $data['user_column1'] = $this->input->post('user_column1');
$data['user_column2'] = $this->input->post('user_column2'); $data['user_column2'] = $this->input->post('user_column2');
@ -96,6 +97,7 @@ class User extends CI_Controller {
$this->input->post('user_date_format'), $this->input->post('user_date_format'),
$this->input->post('user_stylesheet'), $this->input->post('user_stylesheet'),
$this->input->post('user_sota_lookup'), $this->input->post('user_sota_lookup'),
$this->input->post('user_wwff_lookup'),
$this->input->post('user_show_notes'), $this->input->post('user_show_notes'),
$this->input->post('user_column1'), $this->input->post('user_column1'),
$this->input->post('user_column2'), $this->input->post('user_column2'),
@ -133,6 +135,7 @@ class User extends CI_Controller {
$data['user_measurement_base'] = $this->input->post('user_measurement_base'); $data['user_measurement_base'] = $this->input->post('user_measurement_base');
$data['user_stylesheet'] = $this->input->post('user_stylesheet'); $data['user_stylesheet'] = $this->input->post('user_stylesheet');
$data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $data['user_sota_lookup'] = $this->input->post('user_sota_lookup');
$data['user_wwff_lookup'] = $this->input->post('user_wwff_lookup');
$data['user_show_notes'] = $this->input->post('user_show_notes'); $data['user_show_notes'] = $this->input->post('user_show_notes');
$data['user_column1'] = $this->input->post('user_column1'); $data['user_column1'] = $this->input->post('user_column1');
$data['user_column2'] = $this->input->post('user_column2'); $data['user_column2'] = $this->input->post('user_column2');
@ -305,6 +308,12 @@ class User extends CI_Controller {
$data['user_sota_lookup'] = $q->user_sota_lookup; $data['user_sota_lookup'] = $q->user_sota_lookup;
} }
if($this->input->post('user_wwff_lookup')) {
$data['user_wwff_lookup'] = $this->input->post('user_wwff_lookup', true);
} else {
$data['user_wwff_lookup'] = $q->user_wwff_lookup;
}
if($this->input->post('user_show_notes')) { if($this->input->post('user_show_notes')) {
$data['user_show_notes'] = $this->input->post('user_show_notes', true); $data['user_show_notes'] = $this->input->post('user_show_notes', true);
} else { } else {
@ -389,6 +398,7 @@ class User extends CI_Controller {
$data['user_timezone'] = $this->input->post('user_timezone', true); $data['user_timezone'] = $this->input->post('user_timezone', true);
$data['user_stylesheet'] = $this->input->post('user_stylesheet'); $data['user_stylesheet'] = $this->input->post('user_stylesheet');
$data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $data['user_sota_lookup'] = $this->input->post('user_sota_lookup');
$data['user_wwff_lookup'] = $this->input->post('user_wwff_lookup');
$data['user_show_notes'] = $this->input->post('user_show_notes'); $data['user_show_notes'] = $this->input->post('user_show_notes');
$data['user_column1'] = $this->input->post('user_column1'); $data['user_column1'] = $this->input->post('user_column1');
$data['user_column2'] = $this->input->post('user_column2'); $data['user_column2'] = $this->input->post('user_column2');

查看文件

@ -0,0 +1,59 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/***
* Wwff library is a World Wide Flora Fauna client
*/
class Wwff
{
// return summit references matching the provided query
public function get($query): array
{
if (empty($query)) {
return [];
}
$json = [];
$ref = strtoupper($query);
$file = 'assets/json/wwff.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 WWFF
public function info($ref) {
$url = 'https://www.cqgma.org/wwff_ref.php?ref='.$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;
}
}

查看文件

@ -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_wwff_lookup extends CI_Migration {
public function up()
{
if (!$this->db->field_exists('user_wwff_lookup', 'users')) {
$fields = array(
'user_wwff_lookup integer DEFAULT 0 AFTER user_sota_lookup',
);
$this->dbforge->add_column('users', $fields);
}
}
public function down()
{
if ($this->db->field_exists('user_wwff_lookup', 'users')) {
$this->dbforge->drop_column('users', 'user_wwff_lookup');
}
}
}

查看文件

@ -112,7 +112,7 @@ class User_Model extends CI_Model {
// FUNCTION: bool add($username, $password, $email, $type) // FUNCTION: bool add($username, $password, $email, $type)
// Add a user // Add a user
function add($username, $password, $email, $type, $firstname, $lastname, $callsign, $locator, $timezone, function add($username, $password, $email, $type, $firstname, $lastname, $callsign, $locator, $timezone,
$measurement, $user_date_format, $user_stylesheet, $user_sota_lookup, $user_show_notes, $measurement, $user_date_format, $user_stylesheet, $user_sota_lookup, $user_wwff_lookup, $user_show_notes,
$user_column1, $user_column2, $user_column3, $user_column4, $user_column5, $user_show_profile_image) { $user_column1, $user_column2, $user_column3, $user_column4, $user_column5, $user_show_profile_image) {
// Check that the user isn't already used // Check that the user isn't already used
if(!$this->exists($username)) { if(!$this->exists($username)) {
@ -130,6 +130,7 @@ class User_Model extends CI_Model {
'user_date_format' => xss_clean($user_date_format), 'user_date_format' => xss_clean($user_date_format),
'user_stylesheet' => xss_clean($user_stylesheet), 'user_stylesheet' => xss_clean($user_stylesheet),
'user_sota_lookup' => xss_clean($user_sota_lookup), 'user_sota_lookup' => xss_clean($user_sota_lookup),
'user_wwff_lookup' => xss_clean($user_wwff_lookup),
'user_show_notes' => xss_clean($user_show_notes), 'user_show_notes' => xss_clean($user_show_notes),
'user_column1' => xss_clean($user_column1), 'user_column1' => xss_clean($user_column1),
'user_column2' => xss_clean($user_column2), 'user_column2' => xss_clean($user_column2),
@ -181,6 +182,7 @@ class User_Model extends CI_Model {
'user_date_format' => xss_clean($fields['user_date_format']), 'user_date_format' => xss_clean($fields['user_date_format']),
'user_stylesheet' => xss_clean($fields['user_stylesheet']), 'user_stylesheet' => xss_clean($fields['user_stylesheet']),
'user_sota_lookup' => xss_clean($fields['user_sota_lookup']), 'user_sota_lookup' => xss_clean($fields['user_sota_lookup']),
'user_wwff_lookup' => xss_clean($fields['user_wwff_lookup']),
'user_show_notes' => xss_clean($fields['user_show_notes']), 'user_show_notes' => xss_clean($fields['user_show_notes']),
'user_column1' => xss_clean($fields['user_column1']), 'user_column1' => xss_clean($fields['user_column1']),
'user_column2' => xss_clean($fields['user_column2']), 'user_column2' => xss_clean($fields['user_column2']),
@ -296,6 +298,7 @@ class User_Model extends CI_Model {
'user_date_format' => $u->row()->user_date_format, 'user_date_format' => $u->row()->user_date_format,
'user_stylesheet' => $u->row()->user_stylesheet, 'user_stylesheet' => $u->row()->user_stylesheet,
'user_sota_lookup' => isset($u->row()->user_sota_lookup) ? $u->row()->user_sota_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_show_notes' => isset($u->row()->user_show_notes) ? $u->row()->user_show_notes : 1, '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_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', 'user_column1' => isset($u->row()->user_column1) ? $u->row()->user_column1: 'Mode',

查看文件

@ -1088,6 +1088,27 @@ $(document).on('keypress',function(e) {
}); });
<?php } ?> <?php } ?>
<?php if ($this->session->userdata('user_wwff_lookup') == 1) { ?>
$('#wwff_ref').change(function() {
var wwff = $('#wwff_ref').val();
if (wwff.length > 0) {
$.ajax({
url: base_url+'index.php/qso/get_wwff_info',
type: 'post',
data: {'wwff': wwff},
success: function(res) {
$('#qth').val(res.name);
$('#locator').val(res.locator);
},
error: function() {
$('#qth').val('');
$('#locator').val('');
},
});
}
});
<?php } ?>
<?php if ($this->config->item('qso_auto_qth')) { ?> <?php if ($this->config->item('qso_auto_qth')) { ?>
$('#qth').focusout(function() { $('#qth').focusout(function() {
if ($('#locator').val() === '') { if ($('#locator').val() === '') {

查看文件

@ -129,13 +129,24 @@
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-row">
<label for="sotalookup">SOTA auto lookup gridsquare and name for summit.</label> <div class="form-group col-md-6">
<select class="custom-select" id="sotalookup" name="user_sota_lookup"> <label for="sotalookup">SOTA auto lookup gridsquare and name for summit.</label>
<option value="0"><?php echo $this->lang->line('general_word_no'); ?></option> <select class="custom-select" id="sotalookup" name="user_sota_lookup">
<option value="1"><?php echo $this->lang->line('general_word_yes'); ?></option> <option value="0"><?php echo $this->lang->line('general_word_no'); ?></option>
</select> <option value="1"><?php echo $this->lang->line('general_word_yes'); ?></option>
<div class="small form-text text-muted">If this is set, name and gridsquare is fetched from the API and filled in location and locator.</div></td> </select>
<div class="small form-text text-muted">If this is set, name and gridsquare is fetched from the API and filled in location and locator.</div></td>
</div>
<div class="form-group col-md-6">
<label for="wwfflookup">WWFF auto lookup gridsquare and name for reference.</label>
<select class="custom-select" id="wwfflookup" name="user_wwff_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 this is set, name and gridsquare is fetched from the API and filled in location and locator.</div></td>
</div>
</div> </div>
<div class="form-group"> <div class="form-group">

查看文件

@ -278,27 +278,35 @@
</div> </div>
<br> <br>
<div class="row"> <div class="row">
<!-- Club Log -->
<div class="col-md"> <div class="col-md">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
Summits On The Air Gridsquare and Location Autocomplete
</div> </div>
<div class="card-body"> <div class="card-body">
<div class="form-group"> <div class="form-row">
<label for="sotalookup">SOTA auto lookup gridsquare and name for summit.</label> <div class="form-group col-md-6">
<select class="custom-select" id="sotalookup" name="user_sota_lookup"> <label for="sotalookup">SOTA auto lookup gridsquare and name for summit.</label>
<option value="1" <?php if ($user_sota_lookup == 1) { echo " selected =\"selected\""; } ?>><?php echo $this->lang->line('general_word_yes'); ?></option> <select class="custom-select" id="sotalookup" name="user_sota_lookup">
<option value="0" <?php if ($user_sota_lookup == 0) { echo " selected =\"selected\""; } ?>><?php echo $this->lang->line('general_word_no'); ?></option> <option value="1" <?php if ($user_sota_lookup == 1) { echo " selected =\"selected\""; } ?>><?php echo $this->lang->line('general_word_yes'); ?></option>
</select> <option value="0" <?php if ($user_sota_lookup == 0) { echo " selected =\"selected\""; } ?>><?php echo $this->lang->line('general_word_no'); ?></option>
<div class="small form-text text-muted">If this is set, name and gridsquare is fetched from the API and filled in location and locator.</div></td> </select>
<div class="small form-text text-muted">If this is set, name and gridsquare is fetched from the API and filled in location and locator.</div></td>
</div>
<div class="form-group col-md-6">
<label for="wwfflookup">WWFF auto lookup gridsquare and name for summit.</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 this is set, name and gridsquare is fetched from the API and filled in location and locator.</div></td>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<br> <br>
<div class="row"> <div class="row">
<!-- Club Log --> <!-- Club Log -->