From 1ce153a2ca10a271028476eb7b5fba52a0d30ebc Mon Sep 17 00:00:00 2001
From: Andreas <6977712+AndreasK79@users.noreply.github.com>
Date: Fri, 12 Nov 2021 12:45:33 +0100
Subject: [PATCH] [KML Export] Fixed query to get the correct QSOs. Also added
an extra check if lat and lng were undefined
---
application/controllers/Kml.php | 47 +++++++++++++---------------
application/models/Logbook_model.php | 2 +-
2 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/application/controllers/Kml.php b/application/controllers/Kml.php
index e404f6fb..9d0f27ed 100644
--- a/application/controllers/Kml.php
+++ b/application/controllers/Kml.php
@@ -9,8 +9,7 @@
class Kml extends CI_Controller {
- public function index()
- {
+ public function index() {
$this->load->model('user_model');
$this->load->model('modes');
$this->load->model('dxcc');
@@ -27,12 +26,10 @@ class Kml extends CI_Controller {
$this->load->view('interface_assets/header', $data);
$this->load->view('kml/index');
$this->load->view('interface_assets/footer');
-
}
- public function export()
- {
- // Load Librarys
+ public function export() {
+ // Load Libraries
$this->load->library('qra');
$this->load->helper('file');
@@ -56,10 +53,7 @@ class Kml extends CI_Controller {
$output .= "";
- foreach ($qsos->result() as $row)
- {
- $output .= "";
-
+ foreach ($qsos->result() as $row) {
if($row->COL_GRIDSQUARE != null) {
$stn_loc = $this->qra->qra2latlong($row->COL_GRIDSQUARE);
@@ -73,21 +67,24 @@ class Kml extends CI_Controller {
ORDER BY LENGTH( prefix ) DESC
LIMIT 1
');
-
- foreach ($query->result() as $dxcc) {
- $lat = $dxcc->lat;
- $lng = $dxcc->long;
- }
+ foreach ($query->result() as $dxcc) {
+ $lat = $dxcc->lat;
+ $lng = $dxcc->long;
+ }
}
- $timestamp = strtotime($row->COL_TIME_ON);
+ if (isset($lat) && isset($lng)) {
+ $output .= "";
- $output .= "".$row->COL_CALL."";
- $output .= "Date/Time: ".date('Y-m-d H:i:s', ($timestamp))."
Band: ".$row->COL_BAND."
]]>";
- $output .= "";
- $output .= "".$lng.",".$lat.",0";
- $output .= "";
- $output .= "";
+ $timestamp = strtotime($row->COL_TIME_ON);
+
+ $output .= "".$row->COL_CALL."";
+ $output .= "Date/Time: ".date('Y-m-d H:i:s', ($timestamp))."
Band: ".$row->COL_BAND."
]]>";
+ $output .= "";
+ $output .= "".$lng.",".$lat.",0";
+ $output .= "";
+ $output .= "";
+ }
}
$output .= "";
@@ -97,12 +94,10 @@ class Kml extends CI_Controller {
mkdir('kml', 0755, true);
}
- if ( ! write_file('kml/qsos.kml', $output))
- {
+ if ( ! write_file('kml/qsos.kml', $output)) {
echo 'Unable to write the file. Make sure the folder KML has write permissions.';
}
- else
- {
+ else {
header("Content-Disposition: attachment; filename=\"qsos.kml\"");
echo $output;
}
diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php
index 41c660cd..b52a7a79 100755
--- a/application/models/Logbook_model.php
+++ b/application/models/Logbook_model.php
@@ -912,7 +912,7 @@ class Logbook_model extends CI_Model {
/* Get all QSOs with a valid grid for use in the KML export */
function kml_get_all_qsos($band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate) {
$this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_SUBMODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY, COL_SAT_NAME, COL_GRIDSQUARE');
- $this->db->where('COL_GRIDSQUARE != \'null\'');
+ $this->db->where("coalesce(COL_GRIDSQUARE, '') <> ''");
if ($band != 'All') {
if ($band == 'SAT') {