diff --git a/application/controllers/Dxatlas.php b/application/controllers/Dxatlas.php new file mode 100644 index 00000000..a749b257 --- /dev/null +++ b/application/controllers/Dxatlas.php @@ -0,0 +1,122 @@ +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('dxcc'); + $this->load->model('logbook_model'); + $this->load->model('stations'); + + $data['station_profile'] = $this->stations->all(); // Used in the view for station location select + $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'] = "DX Atlas Gridsquare Export"; + + $this->load->view('interface_assets/header', $data); + $this->load->view('dxatlas/index'); + $this->load->view('interface_assets/footer'); + + } + + public function export() { + $this->load->model('dxatlas_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 QRAs + $grids = $this->dxatlas_model->get_gridsquares($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate); + + $this->generateFiles($grids['worked'], $grids['confirmed'], $band); + } + + function generateFiles($wkdArray, $cfmArray, $band) { + + $gridCfmArray = []; + $gridWkdArray = []; + $fieldCfmArray = []; + $fieldWkdArray = []; + + foreach ($cfmArray as $grid) { + $field = substr($grid, 0, 2); + if (!in_array($field, $fieldCfmArray)) { + $fieldCfmArray[] = $field; + } + $gridCfmArray[] = $grid; + } + + + foreach ($wkdArray as $grid) { + $field = substr($grid, 0, 2); + if (!in_array($field, $fieldCfmArray)) { + if (!in_array($field, $fieldWkdArray)) { + $fieldWkdArray[] = $field; + } + } + if (!in_array($grid, $gridCfmArray)) { + $gridWkdArray[] = $grid; + } + } + + $gridWkdString = ''; + $gridCfmString = ''; + + asort($gridWkdArray); + asort($gridCfmArray); + asort($fieldWkdArray); + asort($fieldCfmArray); + + foreach ($fieldWkdArray as $fields) { + $gridWkdString .= $fields . "\r\n"; + } + + foreach ($gridWkdArray as $grids) { + $gridWkdString .= $grids . "\r\n"; + } + + foreach ($fieldCfmArray as $fields) { + $gridCfmString .= $fields . "\r\n"; + } + + foreach ($gridCfmArray as $grids) { + $gridCfmString .= $grids . "\r\n"; + } + + $this->makeZip($gridWkdString, $gridCfmString, $band); + } + + function makeZip($gridWkdString, $gridCfmString, $band) { + $zipFileName = 'dxatlas_gridsquares_'. $band . '.zip'; + // Prepare File + $file = tempnam("tmp", "zip"); + $zip = new ZipArchive(); + $zip->open($file, ZipArchive::OVERWRITE); + + // Stuff with content + $zip->addFromString($band . '_grids.wkd', $gridWkdString); + $zip->addFromString($band . '_grids.cfm', $gridCfmString); + + // Close and send to users + $zip->close(); + $length = filesize($file); + header('Content-Type: application/zip'); + header('Content-Length: ' . $length); + header('Content-Disposition: attachment; filename="' . $zipFileName . '"'); + readfile($file); + unlink($file); + } +} diff --git a/application/models/Dxatlas_model.php b/application/models/Dxatlas_model.php new file mode 100644 index 00000000..154537d4 --- /dev/null +++ b/application/models/Dxatlas_model.php @@ -0,0 +1,172 @@ +fetchGrids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate); + + if (isset($gridArray)) { + return $gridArray; + } else { + return 0; + } + } + + /* + * Builds the array for worked and confirmed gridsquares + */ + function fetchGrids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate) { + + // Getting all the worked grids + $col_gridsquare_worked = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'none', 'single'); + + $workedGridArray = array(); + foreach ($col_gridsquare_worked as $workedgrid) { + array_push($workedGridArray, $workedgrid['gridsquare']); + } + + $col_vucc_grids_worked = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'none', 'multi'); + + foreach ($col_vucc_grids_worked as $gridSplit) { + $grids = explode(",", $gridSplit['col_vucc_grids']); + foreach($grids as $key) { + $grid_four = strtoupper(substr(trim($key),0,4)); + + if(!in_array($grid_four, $workedGridArray)){ + array_push($workedGridArray, $grid_four); + } + } + } + + // Getting all the confirmed grids + $col_gridsquare_confirmed = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'both', 'single'); + + $confirmedGridArray = array(); + foreach ($col_gridsquare_confirmed as $confirmedgrid) { + array_push($confirmedGridArray, $confirmedgrid['gridsquare']); + if(in_array($confirmedgrid['gridsquare'], $workedGridArray)){ + $index = array_search($confirmedgrid['gridsquare'],$workedGridArray); + unset($workedGridArray[$index]); + } + } + + $col_vucc_grids_confirmed = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'both', 'multi'); + + foreach ($col_vucc_grids_confirmed as $gridSplit) { + $grids = explode(",", $gridSplit['col_vucc_grids']); + foreach($grids as $key) { + $grid_four = strtoupper(substr(trim($key),0,4)); + + if(!in_array($grid_four, $confirmedGridArray)){ + array_push($confirmedGridArray, $grid_four); + } + if(in_array($grid_four, $workedGridArray)){ + $index = array_search($grid_four,$workedGridArray); + unset($workedGridArray[$index]); + } + } + } + + $vuccArray['worked'] = $workedGridArray; + $vuccArray['confirmed'] = $confirmedGridArray; + + return $vuccArray; + } + + /* + * Gets the grids from the datbase + * + * Filters: + * + * $band = filter on band + * $mode = filter on mode + * $dxcc = filter on dxx + * $cqz = filter on cq zone + * $propagation = Filter on propagation + * $fromdate = Date range from + * $todate = Date range to + * $column = Chooses if we fetch from col_gridsquare (only single grids) or col_vucc_grids (multisquares) + * $confirmationMethod - qsl, lotw or both, use anything else to skip confirmed + * + */ + function get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, $confirmationMethod, $column) { + $sql = ""; + + if ($column == 'single') { + $sql .= "select distinct upper(substring(col_gridsquare, 1, 4)) gridsquare + from " . $this->config->item('table_name') . + " where col_gridsquare <> ''"; + } + else if ($column == 'multi') { + $sql .= "select col_vucc_grids + from " . $this->config->item('table_name') . + " where col_vucc_grids <> '' "; + } + + if ($station_id != "All") { + $sql .= ' and station_id = ' . $station_id; + } + + if ($confirmationMethod == 'both') { + $sql .= " and (col_qsl_rcvd='Y' or col_lotw_qsl_rcvd='Y')"; + } + else if ($confirmationMethod == 'qsl') { + $sql .= " and col_qsl_rcvd='Y'"; + } + else if ($confirmationMethod == 'lotw') { + $sql .= " and col_lotw_qsl_rcvd='Y'"; + } + + 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 . "'"; + } + + $query = $this->db->query($sql); + + return $query->result_array(); + } +} +?> diff --git a/application/views/dxatlas/index.php b/application/views/dxatlas/index.php new file mode 100644 index 00000000..7d7cad24 --- /dev/null +++ b/application/views/dxatlas/index.php @@ -0,0 +1,137 @@ +
+
+

+ +
+
+ Export your logbook for use in DX Atlas to display worked / confirmed gridsquares. +
+ + + +
+ +
+
+
+ + +
+
+ +
+
+ + +
+
+ + +
+ +
+ + +
+ +
+ + + +
+
+ + +
+ +
+ + +
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+ +
+
+
+
+
+
+
+ +
+
+
+
diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 1644bc1a..c76b0b80 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2024,6 +2024,24 @@ function deleteQsl(id) { +uri->segment(1) == "dxatlas") { ?> + + + + + uri->segment(1) == "qslprint") { ?>