diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index ac3a0d618..251c85763 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -329,6 +329,31 @@ class Awards extends CI_Controller { $this->load->view('interface_assets/footer', $footerData); } + public function jcc_export() { + $this->load->model('Jcc_model'); + $postdata['qsl'] = $this->security->xss_clean($this->input->post('qsl')); + $postdata['lotw'] = $this->security->xss_clean($this->input->post('lotw')); + $postdata['eqsl'] = $this->security->xss_clean($this->input->post('eqsl')); + $postdata['qrz'] = $this->security->xss_clean($this->input->post('qrz')); + $postdata['worked'] = $this->security->xss_clean($this->input->post('worked')); + $postdata['confirmed'] = $this->security->xss_clean($this->input->post('confirmed')); + $postdata['notworked'] = $this->security->xss_clean($this->input->post('notworked')); + $postdata['band'] = $this->security->xss_clean($this->input->post('band')); + $postdata['mode'] = $this->security->xss_clean($this->input->post('mode')); + + $qsos = $this->Jcc_model->exportJcc($postdata); + + $fp = fopen( 'php://output', 'w' ); + $i=1; + fputcsv($fp, array('No', 'Callsign', 'Date', 'Band', 'Mode', 'Remarks'), ';'); + foreach ($qsos as $qso) { + fputcsv($fp, array($i, $qso['call'], $qso['date'], ($qso['prop_mode'] != null ? $qso['band'].' / '.$qso['prop_mode'] : $qso['band']), $qso['mode'], $qso['cnty'].' - '.$qso['jcc']), ';'); + $i++; + } + fclose($fp); + return; + } + public function vucc() { $this->load->model('vucc'); $this->load->model('bands'); diff --git a/application/models/Jcc_model.php b/application/models/Jcc_model.php index f972eee40..93e887647 100644 --- a/application/models/Jcc_model.php +++ b/application/models/Jcc_model.php @@ -825,9 +825,8 @@ class Jcc_model extends CI_Model { ); function get_jcc_array($bands, $postdata) { - $CI =& get_instance(); - $CI->load->model('logbooks_model'); - $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); if (!$logbooks_locations_array) { return null; @@ -1020,9 +1019,8 @@ class Jcc_model extends CI_Model { */ function get_jcc_summary($bands, $postdata) { - $CI =& get_instance(); - $CI->load->model('logbooks_model'); - $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); if (!$logbooks_locations_array) { return null; @@ -1131,5 +1129,59 @@ class Jcc_model extends CI_Model { $sql .= " and COL_CNTY in (".implode(',', array_keys($this->jaCities)).")"; return $sql; } + + function exportJcc($postdata) { + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + if (!$logbooks_locations_array) { + return null; + } + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + $jccArray = array_keys($this->jaCities); + + $sql = "SELECT distinct col_cnty FROM " . $this->config->item('table_name') . " thcv + where station_id in (" . $location_list . ")"; + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; + } + + $sql .= $this->addStateToQuery(); + $sql .= $this->genfunctions->addBandToQuery($postdata['band']); + $sql .= $this->genfunctions->addQslToQuery($postdata); + $sql .= ' ORDER BY COL_CNTY ASC'; + + $query = $this->db->query($sql); + + $jccs = array(); + foreach($query->result() as $line) { + $jccs[] = $line->col_cnty; + } + $qsos = array(); + foreach($jccs as $jcc) { + $qso = $this->getFirstQso($location_list, $jcc, $postdata); + $qsos[] = array('call' => $qso[0]->COL_CALL, 'date' => $qso[0]->COL_TIME_ON, 'band' => $qso[0]->COL_BAND, 'mode' => $qso[0]->COL_MODE, 'prop_mode' => $qso[0]->COL_PROP_MODE, 'cnty' => $qso[0]->COL_CNTY, 'jcc' => $this->jaCities[$qso[0]->COL_CNTY]); + } + + return $qsos; + } + + function getFirstQso($location_list, $jcc, $postdata) { + $sql = 'SELECT COL_CNTY, COL_CALL, COL_TIME_ON, COL_BAND, COL_MODE, COL_PROP_MODE FROM '.$this->config->item('table_name').' t1 + WHERE station_id in ('.$location_list.')'; + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; + } + $sql .= $this->addStateToQuery(); + $sql .= $this->genfunctions->addBandToQuery($postdata['band']); + $sql .= $this->genfunctions->addQslToQuery($postdata); + $sql .= ' AND COL_CNTY = \''.$jcc.'\''; + $sql .= ' ORDER BY COL_TIME_ON ASC LIMIT 1'; + $query = $this->db->query($sql); + return $query->result(); + } } ?> diff --git a/application/views/awards/jcc/index.php b/application/views/awards/jcc/index.php index 776b5199f..0e4c464f4 100644 --- a/application/views/awards/jcc/index.php +++ b/application/views/awards/jcc/index.php @@ -98,6 +98,7 @@