Implemented enrichment of spot

This commit is contained in:
int2001 2023-07-21 05:45:56 +00:00
parent 99e46bf1fc
commit 45161142ef
3 changed files with 42 additions and 6 deletions

View File

@ -12,12 +12,12 @@ class Dxcluster extends CI_Controller {
function qrg_lookup($qrg) {
$call_found=$this->logbook_model->qrg_lookup($qrg);
$call_found=$this->logbook_model->dxc_qrg_lookup($this->security->xss_clean($qrg));
header('Content-Type: application/json');
if ($call_found) {
header('Content-Type: application/json');
echo json_encode($call_found, JSON_PRETTY_PRINT);
} else {
echo '{ error: "not found" }';
echo '{ "error": "not found" }';
}
}
@ -30,7 +30,7 @@ class Dxcluster extends CI_Controller {
header('Content-Type: application/json');
echo json_encode($dxcc, JSON_PRETTY_PRINT);
} else {
echo '{ error: "not found" }';
echo '{ "error": "not found" }';
}
}
}

View File

@ -3993,6 +3993,42 @@ class Logbook_model extends CI_Model {
return false;
}
public function dxc_qrg_lookup($qrg, $maxage = 120) {
if ( ($this->optionslib->get_option('dxcache_url') != '') && (is_numeric($qrg)) ) {
$dxcache_url = $this->optionslib->get_option('dxcache_url').'/spot/'.$qrg;
// CURL Functions
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $dxcache_url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Cloudlog DXLookup');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$jsonraw = curl_exec($ch);
curl_close($ch);
$json = json_decode($jsonraw);
// Create JSON object
if (strlen($jsonraw)>20) {
$datetimecurrent = new DateTime("now", new DateTimeZone('UTC')); // Today's Date/Time
$datetimespot = new DateTime($json->when, new DateTimeZone('UTC'));
$spotage = $datetimecurrent->diff($datetimespot);
$minutes = $spotage->days * 24 * 60;
$minutes += $spotage->h * 60;
$minutes += $spotage->i;
$json->age=$minutes;
if ($minutes<=$maxage) {
$dxcc=$this->dxcc_lookup($json->spotted,date('Ymd', time()));
$json->dxcc=$dxcc;
return ($json);
} else {
return '';
}
} else {
return '';
}
}
}
}
function validateADIFDate($date, $format = 'Ymd')

View File

@ -937,10 +937,10 @@ $(document).on('keypress',function(e) {
if ($this->optionslib->get_option('dxcache_url') != ''){ ?>
<script type="text/javascript">
var dxcluster_provider =' <?php echo $this->optionslib->get_option('dxcache_url'); ?>';
var dxcluster_provider ='/index.php/dxcluster';
$(document).ready(function() {
$("#check_cluster").on("click", function() {
$.ajax({ url: dxcluster_provider+"/spot/"+$("#frequency").val()/1000, cache: false, dataType: "json" }).done(
$.ajax({ url: dxcluster_provider+"/qrg_lookup/"+$("#frequency").val()/1000, cache: false, dataType: "json" }).done(
function(dxspot) {
$("#callsign").val(dxspot.spotted);
$("#callsign").trigger("blur");