Merge pull request #264 from Manawyrm/jsoncallsign

Fetch all callsign information in a single JSON request
pull/265/head
Peter Goodhall 2019-02-26 17:19:56 +00:00 zatwierdzone przez GitHub
commit dfcac9627d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 196 dodań i 223 usunięć

267
application/controllers/Logbook.php 100644 → 100755
Wyświetl plik

@ -1,5 +1,6 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Logbook extends CI_Controller {
function index()
@ -52,6 +53,76 @@ class Logbook extends CI_Controller {
}
function json($callsign)
{
$this->load->model('user_model');
if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
$this->load->model('logbook_model');
$return = [
"dxcc" => false,
"callsign_name" => "",
"callsign_qra" => "",
"callsign_qth" => "",
"callsign_iota" => "",
"bearing" => ""
];
$return['dxcc'] = $this->find_dxcc($callsign);
$return['partial'] = $this->partial($callsign);
// Do we have local data for the Callsign?
if($this->logbook_model->call_name($callsign) != null)
{
$return['callsign_name'] = $this->logbook_model->call_name($callsign);
$return['callsign_qra'] = $this->logbook_model->call_qra($callsign);
$return['callsign_qth'] = $this->logbook_model->call_qth($callsign);
$return['callsign_iota'] = $this->logbook_model->call_iota($callsign);
$return['bearing'] = $this->bearing($return['callsign_qra']);
echo json_encode($return, JSON_PRETTY_PRINT);
return;
}
if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null)
{
// Lookup using QRZ
$this->load->library('qrz');
if(!$this->session->userdata('qrz_session_key')) {
$qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password'));
$this->session->set_userdata('qrz_session_key', $qrz_session_key);
}
$callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'));
}
if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null)
{
// Load the HamQTH library
$this->load->library('hamqth');
if(!$this->session->userdata('hamqth_session_key')) {
$hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password'));
$this->session->set_userdata('hamqth_session_key', $hamqth_session_key);
}
$callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'));
}
if (isset($callbook))
{
$return['callsign_name'] = $callbook['name'];
$return['callsign_qra'] = $callbook['gridsquare'];
$return['callsign_qth'] = $callbook['city'];
$return['callsign_iota'] = $callbook['iota'];
}
$return['bearing'] = $this->bearing($return['callsign_qra']);
echo json_encode($return, JSON_PRETTY_PRINT);
return;
}
/* Used to generate maps for displaying on /logbook/ */
function qso_map() {
$this->load->model('logbook_model');
@ -113,142 +184,11 @@ class Logbook extends CI_Controller {
$this->load->view('view_log/qso', $data);
}
function callsign_qra($qra) {
$this->load->model('user_model');
if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
$this->load->model('logbook_model');
if($this->logbook_model->call_qra($qra)) {
echo $this->logbook_model->call_qra($qra);
} else {
if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) {
// Lookup using QRZ
$this->load->library('qrz');
if(!$this->session->userdata('qrz_session_key')) {
$qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password'));
$this->session->set_userdata('qrz_session_key', $qrz_session_key);
}
$callbook = $this->qrz->search($qra, $this->session->userdata('qrz_session_key'));
echo $callbook['gridsquare'];
} elseif ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) {
// Load the HamQTH library
$this->load->library('hamqth');
if(!$this->session->userdata('hamqth_session_key')) {
$hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password'));
$this->session->set_userdata('hamqth_session_key', $hamqth_session_key);
}
$callbook = $this->hamqth->search($qra, $this->session->userdata('hamqth_session_key'));
echo $callbook['gridsquare'];
}
}
}
function callsign_qth($callsign) {
if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) {
// Lookup using QRZ
$this->load->library('qrz');
if(!$this->session->userdata('qrz_session_key')) {
$qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password'));
$this->session->set_userdata('qrz_session_key', $qrz_session_key);
}
$callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'));
echo $callbook['city'];
} elseif ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) {
// Load the HamQTH library
$this->load->library('hamqth');
if(!$this->session->userdata('hamqth_session_key')) {
$hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password'));
$this->session->set_userdata('hamqth_session_key', $hamqth_session_key);
}
$callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'));
echo $callbook['city'];
}
}
function callsign_iota($callsign) {
if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) {
// Lookup using QRZ
$this->load->library('qrz');
if(!$this->session->userdata('qrz_session_key')) {
$qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password'));
$this->session->set_userdata('qrz_session_key', $qrz_session_key);
}
$callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'));
echo $callbook['iota'];
} elseif ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) {
// Load the HamQTH library
$this->load->library('hamqth');
if(!$this->session->userdata('hamqth_session_key')) {
$hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password'));
$this->session->set_userdata('hamqth_session_key', $hamqth_session_key);
}
$callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'));
echo $callbook['iota'];
}
}
function callsign_name($callsign) {
$this->load->model('user_model');
if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
$this->load->model('logbook_model');
if($this->logbook_model->call_name($callsign) != null) {
echo $this->logbook_model->call_name($callsign);
} else {
if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) {
// Lookup using QRZ
$this->load->library('qrz');
if(!$this->session->userdata('qrz_session_key')) {
$qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password'));
$this->session->set_userdata('qrz_session_key', $qrz_session_key);
}
$callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'));
echo $callbook['name'];
} elseif ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) {
// Load the HamQTH library
$this->load->library('hamqth');
if(!$this->session->userdata('hamqth_session_key')) {
$hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password'));
$this->session->set_userdata('hamqth_session_key', $hamqth_session_key);
}
$callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key'));
echo $callbook['name'];
}
}
}
function partial($id) {
$this->load->model('user_model');
if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
$html = "";
$this->db->like('COL_CALL', $id);
$this->db->order_by("COL_TIME_ON", "desc");
$this->db->limit(16);
@ -256,32 +196,33 @@ class Logbook extends CI_Controller {
if ($query->num_rows() > 0)
{
echo "<h2>QSOs Matches with ".strtoupper($id)."</h2>";
echo "<table class=\"partial\" width=\"100%\">";
echo "<tr>";
echo "<td>Date</td>";
echo "<td>Callsign</td>";
echo "<td>RST Sent</td>";
echo "<td>RST Recv</td>";
echo "<td>Band</td>";
echo "<td>Mode</td>";
echo "</tr>";
$html .= "<h2>QSOs Matches with ".strtoupper($id)."</h2>";
$html .= "<table class=\"partial\" width=\"100%\">";
$html .= "<tr>";
$html .= "<td>Date</td>";
$html .= "<td>Callsign</td>";
$html .= "<td>RST Sent</td>";
$html .= "<td>RST Recv</td>";
$html .= "<td>Band</td>";
$html .= "<td>Mode</td>";
$html .= "</tr>";
foreach ($query->result() as $row)
{
echo "<tr>";
echo "<td>".$row->COL_TIME_ON."</td>";
echo "<td>".$row->COL_CALL."</td>";
echo "<td>".$row->COL_RST_SENT."</td>";
echo "<td>".$row->COL_RST_RCVD."</td>";
$html .= "<tr>";
$html .= "<td>".$row->COL_TIME_ON."</td>";
$html .= "<td>".$row->COL_CALL."</td>";
$html .= "<td>".$row->COL_RST_SENT."</td>";
$html .= "<td>".$row->COL_RST_RCVD."</td>";
if($row->COL_SAT_NAME != null) {
echo "<td>".$row->COL_SAT_NAME."</td>";
$html .= "<td>".$row->COL_SAT_NAME."</td>";
} else {
echo "<td>".$row->COL_BAND."</td>";
$html .= "<td>".$row->COL_BAND."</td>";
}
echo "<td>".$row->COL_MODE."</td>";
echo "</tr>";
$html .= "<td>".$row->COL_MODE."</td>";
$html .= "</tr>";
}
echo "</table>";
$html .= "</table>";
return $html;
} else {
if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) {
// Lookup using QRZ
@ -293,16 +234,19 @@ class Logbook extends CI_Controller {
}
$data['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'));
} else {
}
// There's no hamli integration? Disabled for now.
/*else {
// Lookup using hamli
$this->load->library('hamli');
$data['callsign'] = $this->hamli->callsign($id);
}
}*/
$data['id'] = strtoupper($id);
$this->load->view('search/result', $data);
return $this->load->view('search/result', $data, true);
}
}
@ -363,7 +307,7 @@ class Logbook extends CI_Controller {
$data = json_decode($json, TRUE);
// echo ucfirst(strtolower($data['Name']));
echo $json;
return $data;
}
/*
@ -380,19 +324,20 @@ class Logbook extends CI_Controller {
/* return station bearing */
function bearing() {
function bearing($locator) {
$this->load->library('Qra');
if($this->uri->segment(3) != null) {
if($locator != null) {
if($this->session->userdata('user_locator') != null){
$mylocator = $this->session->userdata('user_locator');
} else {
$mylocator = $this->config->item('locator');
}
$bearing = $this->qra->bearing($mylocator, $this->uri->segment(3));
$bearing = $this->qra->bearing($mylocator, $locator);
echo $bearing;
return $bearing;
}
return "";
}
}

0
application/controllers/Qso.php 100644 → 100755
Wyświetl plik

0
application/controllers/Radio.php 100644 → 100755
Wyświetl plik

0
application/libraries/Qrz.php 100644 → 100755
Wyświetl plik

103
application/models/Logbook_model.php 100644 → 100755
Wyświetl plik

@ -285,46 +285,85 @@ class Logbook_model extends CI_Model {
/* Callsign QRA */
function call_qra($callsign) {
$this->db->select('COL_CALL, COL_GRIDSQUARE, COL_TIME_ON');
$this->db->where('COL_CALL', $callsign);
$where = "COL_GRIDSQUARE != \"\"";
function call_qra($callsign) {
$this->db->select('COL_CALL, COL_GRIDSQUARE, COL_TIME_ON');
$this->db->where('COL_CALL', $callsign);
$where = "COL_GRIDSQUARE != \"\"";
$this->db->where($where);
$this->db->where($where);
$this->db->order_by("COL_TIME_ON", "desc");
$this->db->limit(1);
$query = $this->db->get($this->config->item('table_name'));
$callsign = "";
if ($query->num_rows() > 0)
{
$data = $query->row();
$callsign = strtoupper($data->COL_GRIDSQUARE);
}
$this->db->order_by("COL_TIME_ON", "desc");
$this->db->limit(1);
$query = $this->db->get($this->config->item('table_name'));
$callsign = "";
if ($query->num_rows() > 0)
{
$data = $query->row();
$callsign = strtoupper($data->COL_GRIDSQUARE);
}
return $callsign;
}
return $callsign;
}
function call_name($callsign) {
$this->db->select('COL_CALL, COL_NAME, COL_TIME_ON');
$this->db->where('COL_CALL', $callsign);
$where = "COL_NAME != \"\"";
function call_name($callsign) {
$this->db->select('COL_CALL, COL_NAME, COL_TIME_ON');
$this->db->where('COL_CALL', $callsign);
$where = "COL_NAME != \"\"";
$this->db->where($where);
$this->db->where($where);
$this->db->order_by("COL_TIME_ON", "desc");
$this->db->limit(1);
$query = $this->db->get($this->config->item('table_name'));
$name = "";
if ($query->num_rows() > 0)
{
$data = $query->row();
$name = $data->COL_NAME;
}
$this->db->order_by("COL_TIME_ON", "desc");
$this->db->limit(1);
$query = $this->db->get($this->config->item('table_name'));
$name = "";
if ($query->num_rows() > 0)
{
$data = $query->row();
$name = $data->COL_NAME;
}
return $name;
}
return $name;
}
function call_qth($callsign) {
$this->db->select('COL_CALL, COL_QTH, COL_TIME_ON');
$this->db->where('COL_CALL', $callsign);
$where = "COL_QTH != \"\"";
$this->db->where($where);
$this->db->order_by("COL_TIME_ON", "desc");
$this->db->limit(1);
$query = $this->db->get($this->config->item('table_name'));
$name = "";
if ($query->num_rows() > 0)
{
$data = $query->row();
$name = $data->COL_QTH;
}
return $name;
}
function call_iota($callsign) {
$this->db->select('COL_CALL, COL_IOTA, COL_TIME_ON');
$this->db->where('COL_CALL', $callsign);
$where = "COL_IOTA != \"\"";
$this->db->where($where);
$this->db->order_by("COL_TIME_ON", "desc");
$this->db->limit(1);
$query = $this->db->get($this->config->item('table_name'));
$name = "";
if ($query->num_rows() > 0)
{
$data = $query->row();
$name = $data->COL_IOTA;
}
return $name;
}
/* Return QSO Info */
function qso_info($id) {
$this->db->where('COL_PRIMARY_KEY', $id);

49
application/views/qso/index.php 100644 → 100755
Wyświetl plik

@ -321,7 +321,7 @@
}
i=0;
typeDelay=1000;
typeDelay=500;
$(document).ready(function(){
@ -453,46 +453,35 @@
$("#callsign").keyup(delay(function(){
if ($(this).val()) {
/* Find and populate DXCC */
$.get('logbook/find_dxcc/' + $(this).val(), function(result) {
$.getJSON('logbook/json/' + $(this).val(), function(result)
{
//$('#country').val(result);
obj = JSON.parse(result);
$('#country').val(convert_case(obj.Name));
$('#dxcc_id').val(obj.DXCC);
$('#cqz').val(obj.CQZ);
$('#country').val(convert_case(result.dxcc.Name));
$('#dxcc_id').val(result.dxcc.DXCC);
$('#cqz').val(result.dxcc.CQZ);
});
/* Find Locator if the field is empty */
if($('#locator').val() == "") {
$.get('logbook/callsign_qra/' + $(this).val(), function(result) {
$('#locator').val(result);
$('#locator_info').load("logbook/bearing/" + result).fadeIn("slow");
});
$('#locator').val(result.callsign_qra);
$('#locator_info').html(result.bearing);
}
/* Find Operators Name */
if($('#name').val() == "") {
$.get('logbook/callsign_name/' + $(this).val(), function(result) {
$('#name').val(result);
});
$('#name').val(result.callsign_name);
}
if($('#qth').val() == "") {
$.get('logbook/callsign_qth/' + $(this).val(), function(result) {
$('#qth').val(result);
});
}
if($('#qth').val() == "") {
$.get('logbook/callsign_iota/' + $(this).val(), function(result) {
$('#iota_ref').val(result);
});
$('#qth').val(result.callsign_qth);
}
/* Find Callsign Matches */
$('#partial_view').load("logbook/partial/" + $(this).val()).fadeIn("slow");
if($('#qth').val() == "") {
$('#iota_ref').val(result.callsign_iota);
}
/* display past QSOs */
$('#partial_view').html(result.partial);
});
} else {
/* Reset fields ... */
$('#country').val("");
@ -502,7 +491,7 @@
$('#qth').val("");
$('#locator').val("");
$('#iota_ref').val("");
$('#partial_view').load("logbook/partial/");
}
}, typeDelay));

0
sql/tables/cat.sql 100644 → 100755
Wyświetl plik