From b37f595edc2ac26d0f6cf44fa08668dd97e669b1 Mon Sep 17 00:00:00 2001 From: int2001 Date: Mon, 27 May 2024 10:06:36 +0000 Subject: [PATCH] Added CL to JCC and fixed bug where map differs from summary --- application/controllers/Awards.php | 216 ++++++++++++------------- application/models/Jcc_model.php | 70 +++----- application/views/awards/jcc/index.php | 4 + 3 files changed, 136 insertions(+), 154 deletions(-) diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index ebdf59095..522f0c779 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -266,67 +266,66 @@ class Awards extends CI_Controller { ]; $this->load->model('jcc_model'); - $this->load->model('modes'); - $this->load->model('bands'); + $this->load->model('modes'); + $this->load->model('bands'); - $data['worked_bands'] = $this->bands->get_worked_bands('jcc'); - $data['modes'] = $this->modes->active(); + $data['worked_bands'] = $this->bands->get_worked_bands('jcc'); + $data['modes'] = $this->modes->active(); - if ($this->input->post('band') != NULL) { // Band is not set when page first loads. - if ($this->input->post('band') == 'All') { // Did the user specify a band? If not, use all bands - $bands = $data['worked_bands']; - } - else { - $bands[] = $this->security->xss_clean($this->input->post('band')); - } - } - else { - $bands = $data['worked_bands']; - } + if ($this->input->post('band') != NULL) { // Band is not set when page first loads. + if ($this->input->post('band') == 'All') { // Did the user specify a band? If not, use all bands + $bands = $data['worked_bands']; + } else { + $bands[] = $this->security->xss_clean($this->input->post('band')); + } + } else { + $bands = $data['worked_bands']; + } - $data['bands'] = $bands; // Used for displaying selected band(s) in the table in the view + $data['bands'] = $bands; // Used for displaying selected band(s) in the table in the view - if($this->input->method() === 'post') { - $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['includedeleted'] = $this->security->xss_clean($this->input->post('includedeleted')); - $postdata['Africa'] = $this->security->xss_clean($this->input->post('Africa')); - $postdata['Asia'] = $this->security->xss_clean($this->input->post('Asia')); - $postdata['Europe'] = $this->security->xss_clean($this->input->post('Europe')); - $postdata['NorthAmerica'] = $this->security->xss_clean($this->input->post('NorthAmerica')); - $postdata['SouthAmerica'] = $this->security->xss_clean($this->input->post('SouthAmerica')); - $postdata['Oceania'] = $this->security->xss_clean($this->input->post('Oceania')); - $postdata['Antarctica'] = $this->security->xss_clean($this->input->post('Antarctica')); - $postdata['band'] = $this->security->xss_clean($this->input->post('band')); - $postdata['mode'] = $this->security->xss_clean($this->input->post('mode')); - } - else { // Setting default values at first load of page - $postdata['qsl'] = 1; - $postdata['lotw'] = 1; - $postdata['eqsl'] = 0; - $postdata['qrz'] = 0; - $postdata['worked'] = 1; - $postdata['confirmed'] = 1; - $postdata['notworked'] = 0; - $postdata['includedeleted'] = 0; - $postdata['Africa'] = 1; - $postdata['Asia'] = 1; - $postdata['Europe'] = 1; - $postdata['NorthAmerica'] = 1; - $postdata['SouthAmerica'] = 1; - $postdata['Oceania'] = 1; - $postdata['Antarctica'] = 1; - $postdata['band'] = 'All'; - $postdata['mode'] = 'All'; - } + if($this->input->method() === 'post') { + $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['clublog'] = $this->security->xss_clean($this->input->post('clublog')); + $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['includedeleted'] = $this->security->xss_clean($this->input->post('includedeleted')); + $postdata['Africa'] = $this->security->xss_clean($this->input->post('Africa')); + $postdata['Asia'] = $this->security->xss_clean($this->input->post('Asia')); + $postdata['Europe'] = $this->security->xss_clean($this->input->post('Europe')); + $postdata['NorthAmerica'] = $this->security->xss_clean($this->input->post('NorthAmerica')); + $postdata['SouthAmerica'] = $this->security->xss_clean($this->input->post('SouthAmerica')); + $postdata['Oceania'] = $this->security->xss_clean($this->input->post('Oceania')); + $postdata['Antarctica'] = $this->security->xss_clean($this->input->post('Antarctica')); + $postdata['band'] = $this->security->xss_clean($this->input->post('band')); + $postdata['mode'] = $this->security->xss_clean($this->input->post('mode')); + } else { // Setting default values at first load of page + $postdata['qsl'] = 1; + $postdata['lotw'] = 1; + $postdata['eqsl'] = 0; + $postdata['qrz'] = 0; + $postdata['clublog'] = 0; + $postdata['worked'] = 1; + $postdata['confirmed'] = 1; + $postdata['notworked'] = 0; + $postdata['includedeleted'] = 0; + $postdata['Africa'] = 1; + $postdata['Asia'] = 1; + $postdata['Europe'] = 1; + $postdata['NorthAmerica'] = 1; + $postdata['SouthAmerica'] = 1; + $postdata['Oceania'] = 1; + $postdata['Antarctica'] = 1; + $postdata['band'] = 'All'; + $postdata['mode'] = 'All'; + } - $data['jcc_array'] = $this->jcc_model->get_jcc_array($bands, $postdata); - $data['jcc_summary'] = $this->jcc_model->get_jcc_summary($bands, $postdata); + $data['jcc_array'] = $this->jcc_model->get_jcc_array($bands, $postdata); + $data['jcc_summary'] = $this->jcc_model->get_jcc_summary($bands, $postdata); // Render Page $data['page_title'] = "Awards - JCC"; @@ -335,37 +334,38 @@ 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')); + 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['clublog'] = $this->security->xss_clean($this->input->post('clublog')); + $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); + $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; - } + $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 jcc_cities() { - $this->load->model('Jcc_model'); - $data = $this->Jcc_model->jccCities(); - header('Content-Type: application/json'); - echo json_encode($data, JSON_PRETTY_PRINT); - } + public function jcc_cities() { + $this->load->model('Jcc_model'); + $data = $this->Jcc_model->jccCities(); + header('Content-Type: application/json'); + echo json_encode($data, JSON_PRETTY_PRINT); + } public function vucc() { @@ -1491,35 +1491,35 @@ class Awards extends CI_Controller { This displays the DXCC map */ public function jcc_map() { - $this->load->model('jcc_model'); - $this->load->model('bands'); + $this->load->model('jcc_model'); + $this->load->model('bands'); - $bands[] = $this->security->xss_clean($this->input->post('band')); + $bands[] = $this->security->xss_clean($this->input->post('band')); - $postdata['qsl'] = $this->input->post('qsl') == 0 ? NULL: 1; - $postdata['lotw'] = $this->input->post('lotw') == 0 ? NULL: 1; - $postdata['eqsl'] = $this->input->post('eqsl') == 0 ? NULL: 1; - $postdata['qrz'] = $this->input->post('qrz') == 0 ? NULL: 1; - $postdata['clublog'] = $this->input->post('clublog') == 0 ? NULL: 1; - $postdata['worked'] = $this->input->post('worked') == 0 ? NULL: 1; - $postdata['confirmed'] = $this->input->post('confirmed') == 0 ? NULL: 1; - $postdata['notworked'] = $this->input->post('notworked') == 0 ? NULL: 1; - $postdata['band'] = $this->security->xss_clean($this->input->post('band')); - $postdata['mode'] = $this->security->xss_clean($this->input->post('mode')); + $postdata['qsl'] = $this->input->post('qsl') == 0 ? NULL: 1; + $postdata['lotw'] = $this->input->post('lotw') == 0 ? NULL: 1; + $postdata['eqsl'] = $this->input->post('eqsl') == 0 ? NULL: 1; + $postdata['qrz'] = $this->input->post('qrz') == 0 ? NULL: 1; + $postdata['clublog'] = $this->input->post('clublog') == 0 ? NULL: 1; + $postdata['worked'] = $this->input->post('worked') == 0 ? NULL: 1; + $postdata['confirmed'] = $this->input->post('confirmed') == 0 ? NULL: 1; + $postdata['notworked'] = $this->input->post('notworked') == 0 ? NULL: 1; + $postdata['band'] = $this->security->xss_clean($this->input->post('band')); + $postdata['mode'] = $this->security->xss_clean($this->input->post('mode')); - $jcc_wkd = $this->jcc_model->fetch_jcc_wkd($postdata); - $jcc_cnfm = $this->jcc_model->fetch_jcc_cnfm($postdata); + $jcc_wkd = $this->jcc_model->fetch_jcc_wkd($postdata); + $jcc_cnfm = $this->jcc_model->fetch_jcc_cnfm($postdata); - $jccs = []; - foreach ($jcc_wkd as $jcc) { - $jccs[$jcc->COL_CNTY] = array(1, 0); - } - foreach ($jcc_cnfm as $jcc) { - $jccs[$jcc->COL_CNTY][1] = 1; - } + $jccs = []; + foreach ($jcc_wkd as $jcc) { + $jccs[$jcc->COL_CNTY] = array(1, 0); + } + foreach ($jcc_cnfm as $jcc) { + $jccs[$jcc->COL_CNTY][1] = 1; + } - header('Content-Type: application/json'); - echo json_encode($jccs); + header('Content-Type: application/json'); + echo json_encode($jccs); } /* diff --git a/application/models/Jcc_model.php b/application/models/Jcc_model.php index 7d99f4868..16b0be900 100644 --- a/application/models/Jcc_model.php +++ b/application/models/Jcc_model.php @@ -2,8 +2,13 @@ class Jcc_model extends CI_Model { + + private $location_list=null; function __construct() { $this->load->library('Genfunctions'); + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + $this->location_list = "'".implode("','",$logbooks_locations_array)."'"; } public $jaCities = array( @@ -924,14 +929,6 @@ class Jcc_model extends CI_Model { ); function get_jcc_array($bands, $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); @@ -951,14 +948,14 @@ class Jcc_model extends CI_Model { } if ($postdata['worked'] != NULL) { - $jccBand = $this->getJccWorked($location_list, $band, $postdata); + $jccBand = $this->getJccWorked($this->location_list, $band, $postdata); foreach ($jccBand as $line) { $bandJcc[$line->col_cnty][$band] = '
col_cnty . '","' . $band . '","All","All","'. $postdata['mode'] . '","JCC", "")\'>W
'; $cities[$line->col_cnty]['count']++; } } if ($postdata['confirmed'] != NULL) { - $jccBand = $this->getJccConfirmed($location_list, $band, $postdata); + $jccBand = $this->getJccConfirmed($this->location_list, $band, $postdata); foreach ($jccBand as $line) { $bandJcc[$line->col_cnty][$band] = '
col_cnty . '","' . $band . '","All","All","'. $postdata['mode'] . '","JCC", "'.$qsl.'")\'>C
'; $cities[$line->col_cnty]['count']++; @@ -968,7 +965,7 @@ class Jcc_model extends CI_Model { // We want to remove the worked cities in the list, since we do not want to display them if ($postdata['worked'] == NULL) { - $jccBand = $this->getJccWorked($location_list, $postdata['band'], $postdata); + $jccBand = $this->getJccWorked($this->location_list, $postdata['band'], $postdata); foreach ($jccBand as $line) { unset($bandJcc[$line->col_cnty]); } @@ -976,7 +973,7 @@ class Jcc_model extends CI_Model { // We want to remove the confirmed cities in the list, since we do not want to display them if ($postdata['confirmed'] == NULL) { - $wasBand = $this->getJccConfirmed($location_list, $postdata['band'], $postdata); + $wasBand = $this->getJccConfirmed($this->location_list, $postdata['band'], $postdata); foreach ($wasBand as $line) { unset($bandJcc[$line->col_cnty]); } @@ -1116,35 +1113,25 @@ class Jcc_model extends CI_Model { /* * Function gets worked and confirmed summary on each band on the active stationprofile */ - function get_jcc_summary($bands, $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)."'"; - + function get_jcc_summary($bands, $postdata) { foreach ($bands as $band) { if ($band != 'SAT') { - $worked = $this->getSummaryByBand($band, $postdata, $location_list); - $confirmed = $this->getSummaryByBandConfirmed($band, $postdata, $location_list); + $worked = $this->getSummaryByBand($band, $postdata, $this->location_list); + $confirmed = $this->getSummaryByBandConfirmed($band, $postdata, $this->location_list); $jccSummary['worked'][$band] = $worked[0]->count; $jccSummary['confirmed'][$band] = $confirmed[0]->count; } } - $workedTotal = $this->getSummaryByBand($postdata['band'], $postdata, $location_list); - $confirmedTotal = $this->getSummaryByBandConfirmed($postdata['band'], $postdata, $location_list); + $workedTotal = $this->getSummaryByBand($postdata['band'], $postdata, $this->location_list); + $confirmedTotal = $this->getSummaryByBandConfirmed($postdata['band'], $postdata, $this->location_list); $jccSummary['worked']['Total'] = $workedTotal[0]->count; $jccSummary['confirmed']['Total'] = $confirmedTotal[0]->count; if (in_array('SAT', $bands)) { - $worked = $this->getSummaryByBand('SAT', $postdata, $location_list); - $confirmed = $this->getSummaryByBandConfirmed('SAT', $postdata, $location_list); + $worked = $this->getSummaryByBand('SAT', $postdata, $this->location_list); + $confirmed = $this->getSummaryByBandConfirmed('SAT', $postdata, $this->location_list); $jccSummary['worked']['SAT'] = $worked[0]->count; $jccSummary['confirmed']['SAT'] = $confirmed[0]->count; } @@ -1152,8 +1139,7 @@ class Jcc_model extends CI_Model { return $jccSummary; } - function getSummaryByBand($band, $postdata, $location_list) - { + function getSummaryByBand($band, $postdata, $location_list) { $sql = "SELECT count(distinct thcv.col_cnty) as count FROM " . $this->config->item('table_name') . " thcv"; $sql .= " where station_id in (" . $location_list . ")"; @@ -1185,8 +1171,7 @@ class Jcc_model extends CI_Model { return $query->result(); } - function getSummaryByBandConfirmed($band, $postdata, $location_list) - { + function getSummaryByBandConfirmed($band, $postdata, $location_list) { $sql = "SELECT count(distinct thcv.col_cnty) as count FROM " . $this->config->item('table_name') . " thcv"; $sql .= " where station_id in (" . $location_list . ")"; @@ -1230,17 +1215,8 @@ class Jcc_model extends CI_Model { } 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)."'"; - $sql = "SELECT distinct col_cnty FROM " . $this->config->item('table_name') . " thcv - where station_id in (" . $location_list . ")"; + where station_id in (" . $this->location_list . ")"; if ($postdata['mode'] != 'All') { $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; @@ -1259,7 +1235,7 @@ class Jcc_model extends CI_Model { } $qsos = array(); foreach($jccs as $jcc) { - $qso = $this->getFirstQso($location_list, $jcc, $postdata); + $qso = $this->getFirstQso($this->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]['name']); } @@ -1282,7 +1258,8 @@ class Jcc_model extends CI_Model { } function fetch_jcc_wkd($postdata) { - $sql = 'SELECT DISTINCT `COL_CNTY` FROM '.$this->config->item('table_name').' WHERE 1'; + $sql = 'SELECT DISTINCT `COL_CNTY` FROM '.$this->config->item('table_name').' WHERE 1 + and station_id in ('.$this->location_list.')'; $sql .= $this->addStateToQuery(); $sql .= $this->genfunctions->addBandToQuery($postdata['band']); if ($postdata['mode'] != 'All') { @@ -1294,7 +1271,8 @@ class Jcc_model extends CI_Model { } function fetch_jcc_cnfm($postdata) { - $sql = 'SELECT DISTINCT `COL_CNTY` FROM '.$this->config->item('table_name').' WHERE 1'; + $sql = 'SELECT DISTINCT `COL_CNTY` FROM '.$this->config->item('table_name').' WHERE 1 + and station_id in ('.$this->location_list.')'; $sql .= $this->addStateToQuery(); $sql .= $this->genfunctions->addBandToQuery($postdata['band']); if ($postdata['mode'] != 'All') { diff --git a/application/views/awards/jcc/index.php b/application/views/awards/jcc/index.php index 17fdd5a6f..7b42374ed 100644 --- a/application/views/awards/jcc/index.php +++ b/application/views/awards/jcc/index.php @@ -63,6 +63,10 @@ input->post('qrz')) echo ' checked="checked"'; ?> > +
+ input->post('clublog')) echo ' checked="checked"'; ?> > + +