From 3ce3c12e39c5de571950c84ee40a2556adcc3a49 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 16 Mar 2022 11:27:54 +0100 Subject: [PATCH] Add SOTA csv export function --- application/controllers/Csv.php | 47 ++++++ application/models/Csv_model.php | 78 ++++++++++ application/views/csv/data/export.php | 40 +++++ application/views/csv/index.php | 137 ++++++++++++++++++ application/views/interface_assets/footer.php | 18 +++ application/views/interface_assets/header.php | 2 + 6 files changed, 322 insertions(+) create mode 100644 application/controllers/Csv.php create mode 100644 application/models/Csv_model.php create mode 100644 application/views/csv/data/export.php create mode 100644 application/views/csv/index.php diff --git a/application/controllers/Csv.php b/application/controllers/Csv.php new file mode 100644 index 00000000..af1b1402 --- /dev/null +++ b/application/controllers/Csv.php @@ -0,0 +1,47 @@ +load->model('user_model'); + + if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } + + $this->load->model('modes'); + $this->load->model('logbook_model'); + $this->load->model('stations'); + $this->load->model('bands'); + + $data['station_profile'] = $this->stations->all_of_user(); // Used in the view for station location select + $data['worked_bands'] = $this->bands->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'] = "SOTA CSV Export"; + + $this->load->view('interface_assets/header', $data); + $this->load->view('csv/index'); + $this->load->view('interface_assets/footer'); + + } + + public function export() { + $this->load->model('csv_model'); + + // Parameters + $station_id = $this->security->xss_clean($this->input->post('station_profile')); + $band = $this->security->xss_clean($this->input->post('band')); + $mode = $this->security->xss_clean($this->input->post('mode')); + $dxcc = $this->security->xss_clean($this->input->post('dxcc_id')); + $cqz = $this->security->xss_clean($this->input->post('cqz')); + $propagation = $this->security->xss_clean($this->input->post('prop_mode')); + $fromdate = $this->security->xss_clean($this->input->post('fromdate')); + $todate = $this->security->xss_clean($this->input->post('todate')); + + // Get QSOs with valid SOTA info + $data['qsos'] = $this->csv_model->get_qsos($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate); + + $this->load->view('csv/data/export', $data); + } + +} diff --git a/application/models/Csv_model.php b/application/models/Csv_model.php new file mode 100644 index 00000000..473a043f --- /dev/null +++ b/application/models/Csv_model.php @@ -0,0 +1,78 @@ +config->item('table_name'). + " JOIN station_profile on station_profile.station_id = ".$this->config->item('table_name').".station_id". + " WHERE COL_SOTA_REF <> ''"; + + if ($station_id != "All") { + $sql .= ' and ' . $this->config->item('table_name'). '.station_id = ' . $station_id; + } + + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + } else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + + if ($mode != 'All') { + $sql .= " and (COL_MODE = '" . $mode . "' or COL_SUBMODE = '" . $mode . "')"; + } + + if ($dxcc != 'All') { + $sql .= " and COL_DXCC ='" . $dxcc . "'"; + } + + if ($cqz != 'All') { + $sql .= " and COL_CQZ ='" . $cqz . "'"; + } + + if ($propagation != 'All') { + $sql .= " and 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'); + $sql .= " and date(COL_TIME_ON) >='" . $from . "'"; + } + if ($todate != "") { + $to = DateTime::createFromFormat('d/m/Y', $todate); + $to = $to->format('Y-m-d'); + $sql .= " and date(COL_TIME_ON) <='" . $to . "'"; + } + + $sql .= ' and station_profile.user_id = ' . $this->session->userdata('user_id'); + + $sql .= ' ORDER BY `COL_TIME_ON` ASC'; + + $query = $this->db->query($sql); + + return $query->result_array(); + } +} +?> diff --git a/application/views/csv/data/export.php b/application/views/csv/data/export.php new file mode 100644 index 00000000..4775586f --- /dev/null +++ b/application/views/csv/data/export.php @@ -0,0 +1,40 @@ +session->userdata('user_callsign').'-SOTA-'.date('dmY-Hi').'.csv"'); +$CI =& get_instance(); +$bands = array( + "2190m" => "VLF", + "560m" => "VLF", + "160m" => "1.8MHz", + "80m" => "3.5MHz", + "60m" => "5MHz", + "40m" => "7MHz", + "30m" => "10MHz", + "20m" => "14MHz", + "17m" => "18MHz", + "15m" => "21MHz", + "12m" => "24MHz", + "10m" => "28MHz", + "6m" => "50MHz", + "4m" => "70MHz", + "2m" => "144MHz", + "1.25m" => "220MHz", + "70cm" => "433MHz", + "33cm" => "900MHz", + "23cm" => "1240MHz", + "13cm" => "2.3GHz", + "9cm" => "3.4GHz", + "6cm" => "5.6GHz", + "3cm" => "10GHz", + "1.25cm" => "24GHz", + "6mm" => "MIcROWAVE", + "4mm" => "MIcROWAVE", + "2.5mm" => "MIcROWAVE", + "2mm" => "MIcROWAVE", + "1mm" => "MIcROWAVE" +); +foreach ($qsos as $qso) { + $timestamp = strtotime($qso['COL_TIME_ON']); + print "V2;".$qso['station_callsign'].";".$qso['COL_MY_SOTA_REF'].";".date('d/m/y', $timestamp).";".date('Hi', $timestamp).";".$bands[$qso['COL_BAND']].";".$qso['COL_MODE'].";".$qso['COL_CALL'].";".$qso['COL_SOTA_REF'].";".$qso['COL_COMMENT']."\n"; +} +?> diff --git a/application/views/csv/index.php b/application/views/csv/index.php new file mode 100644 index 00000000..3f060cbf --- /dev/null +++ b/application/views/csv/index.php @@ -0,0 +1,137 @@ +
+
+

+ +
+
+ Export your logbook for SOTA uploads. +
+ + + +
+ +
+
+
+ + +
+
+ +
+
+ + +
+
+ + +
+ +
+ + +
+ +
+ + + +
+
+ + +
+ +
+ + +
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+ +
+
+
+
+
+
+
+ +
+
+
+
diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 7978ec74..a2ac10a6 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2552,6 +2552,24 @@ function deleteQsl(id) { +uri->segment(1) == "csv") { ?> + + + + + uri->segment(1) == "qslprint") { ?>