From b2750b827f1736d789539865812f33e2bd169ea5 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 6 Dec 2020 13:21:35 +0100 Subject: [PATCH] [KML Export] Bugfix, as it was not working. Also made a GUI with options for what you want to export. --- application/controllers/Kml.php | 51 ++++++-- application/models/Logbook_model.php | 43 ++++++- application/views/interface_assets/footer.php | 17 +++ application/views/interface_assets/header.php | 4 + application/views/kml/index.php | 119 ++++++++++++++++++ 5 files changed, 221 insertions(+), 13 deletions(-) create mode 100644 application/views/kml/index.php diff --git a/application/controllers/Kml.php b/application/controllers/Kml.php index 89a51a87..50776661 100644 --- a/application/controllers/Kml.php +++ b/application/controllers/Kml.php @@ -9,7 +9,28 @@ class Kml extends CI_Controller { - public function index() + public function index() + { + $this->load->model('user_model'); + $this->load->model('modes'); + $this->load->model('dxcc'); + $this->load->model('logbook_model'); + + if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } + + $data['worked_bands'] = $this->dxcc->get_worked_bands(); // Used in the view for band select + $data['modes'] = $this->modes->active(); // Used in the view for mode select + $data['dxcc'] = $this->logbook_model->fetchDxcc(); // Used in the view for dxcc select + + $data['page_title'] = "KML Export"; + + $this->load->view('interface_assets/header', $data); + $this->load->view('kml/index'); + $this->load->view('interface_assets/footer'); + + } + + public function export() { // Load Librarys $this->load->library('qra'); @@ -18,12 +39,18 @@ class Kml extends CI_Controller { // Load Database connections $this->load->model('logbook_model'); - // Get QSOs with Valid QRAs - $qsos = $this->logbook_model->kml_get_all_qsos(); + // Parameters + $band = $this->input->post('band'); + $mode = $this->input->post('mode'); + $dxcc = $this->input->post('dxcc_id'); + $cqz = $this->input->post('cqz'); + $propagation = $this->input->post('prop_mode'); + $fromdate = $this->input->post('fromdate'); + $todate = $this->input->post('todate'); + + // Get QSOs with Valid QRAs + $qsos = $this->logbook_model->kml_get_all_qsos($band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate); - //header('Content-type: text/xml'); - //header("Cache-Control: no-cache"); - $output = ""; $output .= ""; @@ -32,7 +59,7 @@ class Kml extends CI_Controller { foreach ($qsos->result() as $row) { $output .= ""; - //print_r($row); + if($row->COL_GRIDSQUARE != null) { $stn_loc = $this->qra->qra2latlong($row->COL_GRIDSQUARE); @@ -41,7 +68,7 @@ class Kml extends CI_Controller { } else { $query = $this->db->query(' SELECT * - FROM dxcc + FROM dxcc_entities WHERE prefix = SUBSTRING( \''.$row->COL_CALL.'\', 1, LENGTH( prefix ) ) ORDER BY LENGTH( prefix ) DESC LIMIT 1 @@ -55,7 +82,6 @@ class Kml extends CI_Controller { $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 .= ""; @@ -64,13 +90,16 @@ class Kml extends CI_Controller { $output .= "
"; } - $output .= ""; $output .= "
"; + if (!file_exists('kml')) { + mkdir('kml', 0755, true); + } + if ( ! write_file('kml/qsos.kml', $output)) { - echo 'Unable to write the file - Make the folder KML has write permissions.'; + echo 'Unable to write the file - Make sure the folder KML has write permissions.'; } else { diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index ced1876b..0bf477cb 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -810,10 +810,49 @@ class Logbook_model extends CI_Model { return $query; } - /* Get All QSOs with a Valid Grid */ - function kml_get_all_qsos() { + /* 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\''); + + if ($band != 'All') { + if ($band == 'SAT') { + $this->db->where('COL_PROP_MODE = \'' . $band . '\''); + } + else { + $this->db->where('COL_PROP_MODE != \'SAT\''); + $this->db->where('COL_BAND = \'' . $band .'\''); + } + } + + if ($mode != 'All') { + $this->db->where('COL_MODE = \'' . $mode . '\''); + } + + if ($dxcc != 'All') { + $this->db->where('COL_DXCC = ' . $dxcc); + } + + if ($cqz != 'All') { + $this->db->where('COL_CQZ = ' . $cqz); + } + + if ($propagation != 'All') { + $this->db->where('COL_PROP_MODE = ' . $propagation); + } + + // If date is set, we format the date and add it to the where-statement + if ($fromdate != "") { + $from = DateTime::createFromFormat('d/m/Y', $fromdate); + $from = $from->format('Y-m-d'); + $this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) >= '".$from."'"); + } + if ($todate != "") { + $to = DateTime::createFromFormat('d/m/Y', $todate); + $to = $to->format('Y-m-d'); + $this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) <= '".$to."'"); + } + $query = $this->db->get($this->config->item('table_name')); return $query; diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 8c06589a..d470de5b 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2284,6 +2284,23 @@ $(document).ready(function(){ +uri->segment(1) == "kml") { ?> + + + + +