Merge pull request #264 from Manawyrm/jsoncallsign

Fetch all callsign information in a single JSON request
这个提交包含在:
Peter Goodhall 2019-02-26 17:19:56 +00:00 提交者 GitHub
当前提交 dfcac9627d
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23
共有 7 个文件被更改,包括 196 次插入223 次删除

267
application/controllers/Logbook.php 普通文件 -> 可执行文件
查看文件

@ -1,5 +1,6 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Logbook extends CI_Controller { class Logbook extends CI_Controller {
function index() 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/ */ /* Used to generate maps for displaying on /logbook/ */
function qso_map() { function qso_map() {
$this->load->model('logbook_model'); $this->load->model('logbook_model');
@ -113,142 +184,11 @@ class Logbook extends CI_Controller {
$this->load->view('view_log/qso', $data); $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) { function partial($id) {
$this->load->model('user_model'); $this->load->model('user_model');
if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; } if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; }
$html = "";
$this->db->like('COL_CALL', $id); $this->db->like('COL_CALL', $id);
$this->db->order_by("COL_TIME_ON", "desc"); $this->db->order_by("COL_TIME_ON", "desc");
$this->db->limit(16); $this->db->limit(16);
@ -256,32 +196,33 @@ class Logbook extends CI_Controller {
if ($query->num_rows() > 0) if ($query->num_rows() > 0)
{ {
echo "<h2>QSOs Matches with ".strtoupper($id)."</h2>"; $html .= "<h2>QSOs Matches with ".strtoupper($id)."</h2>";
echo "<table class=\"partial\" width=\"100%\">"; $html .= "<table class=\"partial\" width=\"100%\">";
echo "<tr>"; $html .= "<tr>";
echo "<td>Date</td>"; $html .= "<td>Date</td>";
echo "<td>Callsign</td>"; $html .= "<td>Callsign</td>";
echo "<td>RST Sent</td>"; $html .= "<td>RST Sent</td>";
echo "<td>RST Recv</td>"; $html .= "<td>RST Recv</td>";
echo "<td>Band</td>"; $html .= "<td>Band</td>";
echo "<td>Mode</td>"; $html .= "<td>Mode</td>";
echo "</tr>"; $html .= "</tr>";
foreach ($query->result() as $row) foreach ($query->result() as $row)
{ {
echo "<tr>"; $html .= "<tr>";
echo "<td>".$row->COL_TIME_ON."</td>"; $html .= "<td>".$row->COL_TIME_ON."</td>";
echo "<td>".$row->COL_CALL."</td>"; $html .= "<td>".$row->COL_CALL."</td>";
echo "<td>".$row->COL_RST_SENT."</td>"; $html .= "<td>".$row->COL_RST_SENT."</td>";
echo "<td>".$row->COL_RST_RCVD."</td>"; $html .= "<td>".$row->COL_RST_RCVD."</td>";
if($row->COL_SAT_NAME != null) { if($row->COL_SAT_NAME != null) {
echo "<td>".$row->COL_SAT_NAME."</td>"; $html .= "<td>".$row->COL_SAT_NAME."</td>";
} else { } else {
echo "<td>".$row->COL_BAND."</td>"; $html .= "<td>".$row->COL_BAND."</td>";
} }
echo "<td>".$row->COL_MODE."</td>"; $html .= "<td>".$row->COL_MODE."</td>";
echo "</tr>"; $html .= "</tr>";
} }
echo "</table>"; $html .= "</table>";
return $html;
} else { } else {
if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) { if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) {
// Lookup using QRZ // Lookup using QRZ
@ -293,16 +234,19 @@ class Logbook extends CI_Controller {
} }
$data['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key')); $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 // Lookup using hamli
$this->load->library('hamli'); $this->load->library('hamli');
$data['callsign'] = $this->hamli->callsign($id); $data['callsign'] = $this->hamli->callsign($id);
} }*/
$data['id'] = strtoupper($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); $data = json_decode($json, TRUE);
// echo ucfirst(strtolower($data['Name'])); // echo ucfirst(strtolower($data['Name']));
echo $json; return $data;
} }
/* /*
@ -380,19 +324,20 @@ class Logbook extends CI_Controller {
/* return station bearing */ /* return station bearing */
function bearing() { function bearing($locator) {
$this->load->library('Qra'); $this->load->library('Qra');
if($this->uri->segment(3) != null) { if($locator != null) {
if($this->session->userdata('user_locator') != null){ if($this->session->userdata('user_locator') != null){
$mylocator = $this->session->userdata('user_locator'); $mylocator = $this->session->userdata('user_locator');
} else { } else {
$mylocator = $this->config->item('locator'); $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 普通文件 -> 可执行文件
查看文件

0
application/controllers/Radio.php 普通文件 -> 可执行文件
查看文件

0
application/libraries/Qrz.php 普通文件 -> 可执行文件
查看文件

103
application/models/Logbook_model.php 普通文件 -> 可执行文件
查看文件

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

49
application/views/qso/index.php 普通文件 -> 可执行文件
查看文件

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

0
sql/tables/cat.sql 普通文件 -> 可执行文件
查看文件