diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index f795eda5e..b03a30d31 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -110,6 +110,9 @@ class Awards extends CI_Controller { $this->load->model('dxcc'); $this->load->model('modes'); $this->load->model('bands'); + $this->load->model('logbooks_model'); + + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); $data['orbits'] = $this->bands->get_worked_orbits(); $data['sats_available'] = $this->bands->get_worked_sats(); @@ -183,14 +186,22 @@ class Awards extends CI_Controller { $postdata['dateTo'] = null; } - $dxcclist = $this->dxcc->fetchdxcc($postdata); - if ($dxcclist && $dxcclist[0]->adif == "0") { - unset($dxcclist[0]); - } - $dxcc_result = $this->dxcc->get_dxcc_array($dxcclist, $bands, $postdata); - $data['dxcc_array'] = ($dxcc_result && isset($dxcc_result['matrix'])) ? $dxcc_result['matrix'] : null; - $data['dxcc_summary'] = ($dxcc_result && isset($dxcc_result['summary'])) ? $dxcc_result['summary'] : null; + if ($logbooks_locations_array) { + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + $dxcclist = $this->dxcc->fetchdxcc($postdata, $location_list); + if ($dxcclist && $dxcclist[0]->adif == "0") { + unset($dxcclist[0]); + } + $dxcc_result = $this->dxcc->get_dxcc_array($dxcclist, $bands, $postdata, $location_list); + // Extract bands data and summary from the result + $data['dxcc_array'] = ($dxcc_result && isset($dxcc_result['matrix'])) ? $dxcc_result['matrix'] : null; + $data['dxcc_summary'] = ($dxcc_result && isset($dxcc_result['summary'])) ? $dxcc_result['summary'] : null; + } else { + $location_list = null; + $data['dxcc_array'] = null; + $data['dxcc_summary'] = null; + } // Render Page $data['page_title'] = sprintf(__("Awards - %s"), __("DXCC")); @@ -1705,59 +1716,70 @@ class Awards extends CI_Controller { This displays the DXCC map */ public function dxcc_map() { - $this->load->model('dxcc'); - $this->load->model('bands'); + $this->load->model('dxcc'); + $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',true) ?? 0) == 0 ? NULL: 1; - $postdata['lotw'] = ($this->input->post('lotw',true) ?? 0) == 0 ? NULL: 1; - $postdata['eqsl'] = ($this->input->post('eqsl',true) ?? 0) == 0 ? NULL: 1; - $postdata['qrz'] = ($this->input->post('qrz',true) ?? 0) == 0 ? NULL: 1; - $postdata['clublog'] = ($this->input->post('clublog',true) ?? 0) == 0 ? NULL: 1; - $postdata['worked'] = ($this->input->post('worked',true) ?? 0) == 0 ? NULL: 1; - $postdata['confirmed'] = ($this->input->post('confirmed',true) ?? 0) == 0 ? NULL: 1; - $postdata['notworked'] = ($this->input->post('notworked',true) ?? 0) == 0 ? NULL: 1; + $postdata['qsl'] = ($this->input->post('qsl',true) ?? 0) == 0 ? NULL: 1; + $postdata['lotw'] = ($this->input->post('lotw',true) ?? 0) == 0 ? NULL: 1; + $postdata['eqsl'] = ($this->input->post('eqsl',true) ?? 0) == 0 ? NULL: 1; + $postdata['qrz'] = ($this->input->post('qrz',true) ?? 0) == 0 ? NULL: 1; + $postdata['clublog'] = ($this->input->post('clublog',true) ?? 0) == 0 ? NULL: 1; + $postdata['worked'] = ($this->input->post('worked',true) ?? 0) == 0 ? NULL: 1; + $postdata['confirmed'] = ($this->input->post('confirmed',true) ?? 0) == 0 ? NULL: 1; + $postdata['notworked'] = ($this->input->post('notworked',true) ?? 0) == 0 ? NULL: 1; - $postdata['includedeleted'] = ($this->input->post('includedeleted',true) ?? 0) == 0 ? NULL: 1; - $postdata['Africa'] = ($this->input->post('Africa',true) ?? 0) == 0 ? NULL: 1; - $postdata['Asia'] = ($this->input->post('Asia',true) ?? 0) == 0 ? NULL: 1; - $postdata['Europe'] = ($this->input->post('Europe',true) ?? 0) == 0 ? NULL: 1; - $postdata['NorthAmerica'] = ($this->input->post('NorthAmerica',true) ?? 0) == 0 ? NULL: 1; - $postdata['SouthAmerica'] = ($this->input->post('SouthAmerica',true) ?? 0) == 0 ? NULL: 1; - $postdata['Oceania'] = ($this->input->post('Oceania',true) ?? 0) == 0 ? NULL: 1; - $postdata['Antarctica'] = ($this->input->post('Antarctica',true) ?? 0) == 0 ? NULL: 1; - $postdata['band'] = $this->security->xss_clean($this->input->post('band')); - $postdata['mode'] = $this->security->xss_clean($this->input->post('mode')); - $postdata['sat'] = $this->security->xss_clean($this->input->post('sat')); - $postdata['orbit'] = $this->security->xss_clean($this->input->post('orbit')); + $postdata['includedeleted'] = ($this->input->post('includedeleted',true) ?? 0) == 0 ? NULL: 1; + $postdata['Africa'] = ($this->input->post('Africa',true) ?? 0) == 0 ? NULL: 1; + $postdata['Asia'] = ($this->input->post('Asia',true) ?? 0) == 0 ? NULL: 1; + $postdata['Europe'] = ($this->input->post('Europe',true) ?? 0) == 0 ? NULL: 1; + $postdata['NorthAmerica'] = ($this->input->post('NorthAmerica',true) ?? 0) == 0 ? NULL: 1; + $postdata['SouthAmerica'] = ($this->input->post('SouthAmerica',true) ?? 0) == 0 ? NULL: 1; + $postdata['Oceania'] = ($this->input->post('Oceania',true) ?? 0) == 0 ? NULL: 1; + $postdata['Antarctica'] = ($this->input->post('Antarctica',true) ?? 0) == 0 ? NULL: 1; + $postdata['band'] = $this->security->xss_clean($this->input->post('band')); + $postdata['mode'] = $this->security->xss_clean($this->input->post('mode')); + $postdata['sat'] = $this->security->xss_clean($this->input->post('sat')); + $postdata['orbit'] = $this->security->xss_clean($this->input->post('orbit')); $postdata['dateFrom'] = $this->security->xss_clean($this->input->post('dateFrom')); $postdata['dateTo'] = $this->security->xss_clean($this->input->post('dateTo')); - $dxcclist = $this->dxcc->fetchdxcc($postdata); - if ($dxcclist[0]->adif == "0") { - unset($dxcclist[0]); - } + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - $dxcc_array = $this->dxcc->get_dxcc_array($dxcclist, $bands, $postdata, true); + $dxcclist = $this->dxcc->fetchdxcc($postdata, $logbooks_locations_array); - $i = 0; + if ($dxcclist[0]->adif == "0") { + unset($dxcclist[0]); + } - foreach ($dxcclist as $dxcc) { - $newdxcc[$i]['adif'] = $dxcc->adif; - $newdxcc[$i]['prefix'] = $dxcc->prefix; - $newdxcc[$i]['name'] = ucwords(strtolower($dxcc->name), "- (/"); - if ($dxcc->Enddate!=null) { - $newdxcc[$i]['name'] .= ' (deleted)'; - } - $newdxcc[$i]['lat'] = $dxcc->lat; - $newdxcc[$i]['long'] = $dxcc->long; - $newdxcc[$i++]['status'] = isset($dxcc_array[$dxcc->adif]) ? $this->returnStatus($dxcc_array[$dxcc->adif]) : 'x'; - } + if ($logbooks_locations_array) { + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + $dxcc_array = $this->dxcc->get_dxcc_array($dxcclist, $bands, $postdata, $location_list, true); + } else { + $location_list = null; + $dxcc_array = array(); + } - header('Content-Type: application/json'); - echo json_encode($newdxcc); + $i = 0; + + foreach ($dxcclist as $dxcc) { + $newdxcc[$i]['adif'] = $dxcc->adif; + $newdxcc[$i]['prefix'] = $dxcc->prefix; + $newdxcc[$i]['name'] = ucwords(strtolower($dxcc->name), "- (/"); + if ($dxcc->Enddate!=null) { + $newdxcc[$i]['name'] .= ' (deleted)'; + } + $newdxcc[$i]['lat'] = $dxcc->lat; + $newdxcc[$i]['long'] = $dxcc->long; + $newdxcc[$i++]['status'] = isset($dxcc_array[$dxcc->adif]) ? $dxcc_array[$dxcc->adif] : 'x'; + } + + + header('Content-Type: application/json'); + echo json_encode($newdxcc); } /* diff --git a/application/models/Dxcc.php b/application/models/Dxcc.php index 8f04298f6..4469f8b05 100644 --- a/application/models/Dxcc.php +++ b/application/models/Dxcc.php @@ -31,32 +31,15 @@ class DXCC extends CI_Model { return $this->db->get('dxcc_entities'); } - function get_dxcc_array($dxccArray, $bands, $postdata, $map = false) { - $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_dxcc_array($dxccArray, $bands, $postdata, $location_list, $map = false) { $qsl = $this->genfunctions->gen_qsl_from_postdata($postdata); // Initialize matrix with all DXCC entities foreach ($dxccArray as $dxcc) { - // Handle both object and array formats - if (is_array($dxcc)) { - $adif = $dxcc['adif'] ?? '0'; - $name = $dxcc['name'] ?? ''; - $prefix = $dxcc['prefix'] ?? ''; - $enddate = $dxcc['end'] ?? null; - } else { - $adif = $dxcc->adif ?? '0'; - $name = $dxcc->name ?? ''; - $prefix = $dxcc->prefix ?? ''; - $enddate = $dxcc->end ?? null; - } + $adif = $dxcc->adif ?? '0'; + $name = $dxcc->name ?? ''; + $prefix = $dxcc->prefix ?? ''; + $enddate = $dxcc->end ?? null; if ($adif == '0') { $dxccMatrix[$adif]['name'] = $name; @@ -103,11 +86,14 @@ class DXCC extends CI_Model { continue; } + // Ensure string key for consistency + $dxccKey = (string)$dxcc->dxcc; + // Track worked status for this DXCC - if (!isset($dxccWorkedStatus[$dxcc->dxcc])) { - $dxccWorkedStatus[$dxcc->dxcc] = 0; + if (!isset($dxccWorkedStatus[$dxccKey])) { + $dxccWorkedStatus[$dxccKey] = 0; } - $dxccWorkedStatus[$dxcc->dxcc]++; + $dxccWorkedStatus[$dxccKey]++; // Check if confirmed based on the confirmation types selected in postdata $isConfirmed = false; @@ -134,19 +120,19 @@ class DXCC extends CI_Model { } if ($isConfirmed) { - $dxccMatrix[$dxcc->dxcc][$dxcc->col_band] = '
'; + $dxccMatrix[$dxccKey][$dxcc->col_band] = ''; // Track confirmed DXCCs for summary - if (!isset($confirmedDxccs[$dxcc->col_band][$dxcc->dxcc])) { - $confirmedDxccs[$dxcc->col_band][$dxcc->dxcc] = true; + if (!isset($confirmedDxccs[$dxcc->col_band][$dxccKey])) { + $confirmedDxccs[$dxcc->col_band][$dxccKey] = true; $summary['confirmed'][$dxcc->col_band]++; } } else { - $dxccMatrix[$dxcc->dxcc][$dxcc->col_band] = ''; + $dxccMatrix[$dxccKey][$dxcc->col_band] = ''; } // Track worked DXCCs for summary - if (!isset($workedDxccs[$dxcc->col_band][$dxcc->dxcc])) { - $workedDxccs[$dxcc->col_band][$dxcc->dxcc] = true; + if (!isset($workedDxccs[$dxcc->col_band][$dxccKey])) { + $workedDxccs[$dxcc->col_band][$dxccKey] = true; $summary['worked'][$dxcc->col_band]++; } } @@ -157,11 +143,14 @@ class DXCC extends CI_Model { continue; } + // Ensure string key for consistency + $dxccKey = (string)$dxcc->dxcc; + // Track worked status for this DXCC - if (!isset($dxccWorkedStatus[$dxcc->dxcc])) { - $dxccWorkedStatus[$dxcc->dxcc] = 0; + if (!isset($dxccWorkedStatus[$dxccKey])) { + $dxccWorkedStatus[$dxccKey] = 0; } - $dxccWorkedStatus[$dxcc->dxcc]++; + $dxccWorkedStatus[$dxccKey]++; // Check if confirmed based on the confirmation types selected in postdata $isConfirmed = false; @@ -188,19 +177,19 @@ class DXCC extends CI_Model { } if ($isConfirmed) { - $dxccMatrix[$dxcc->dxcc][$dxcc->col_band] = ''; + $dxccMatrix[$dxccKey][$dxcc->col_band] = ''; // Track confirmed DXCCs for summary - if (!isset($confirmedDxccs[$dxcc->col_band][$dxcc->dxcc])) { - $confirmedDxccs[$dxcc->col_band][$dxcc->dxcc] = true; + if (!isset($confirmedDxccs[$dxcc->col_band][$dxccKey])) { + $confirmedDxccs[$dxcc->col_band][$dxccKey] = true; $summary['confirmed'][$dxcc->col_band]++; - } - } else { - $dxccMatrix[$dxcc->dxcc][$dxcc->col_band] = ''; + } + } else { + $dxccMatrix[$dxccKey][$dxcc->col_band] = ''; } // Track worked DXCCs for summary - if (!isset($workedDxccs[$dxcc->col_band][$dxcc->dxcc])) { - $workedDxccs[$dxcc->col_band][$dxcc->dxcc] = true; + if (!isset($workedDxccs[$dxcc->col_band][$dxccKey])) { + $workedDxccs[$dxcc->col_band][$dxccKey] = true; $summary['worked'][$dxcc->col_band]++; } } @@ -258,7 +247,7 @@ class DXCC extends CI_Model { if ($map) { $mapDxccs = []; foreach ($dxccMatrix as $dxcc => $data) { - if (!isset($dxccWorkedStatus[$dxcc])) { + if (!isset($totalWorkedDxccs[$dxcc])) { $mapDxccs[$dxcc] = '-'; // Not worked } elseif (isset($totalConfirmedDxccs[$dxcc])) { $mapDxccs[$dxcc] = 'C'; // Confirmed @@ -277,20 +266,8 @@ class DXCC extends CI_Model { } } - private function cf_type($postdata,$qsl,$lotw,$eqsl,$qrz,$clublog) { - $string=''; - if ((($qsl ?? 0)>0) && (($postdata['qsl'] ?? '') != '')) { $string.='Q'; } - if ((($lotw ?? 0)>0) && (($postdata['lotw'] ?? '') != '')) { $string.='L'; } - if ((($eqsl ?? 0)>0) && (($postdata['eqsl'] ?? '') != '')) { $string.='E'; } - if ((($qrz ?? 0)>0) && (($postdata['qrz'] ?? '') != '')) { $string.='Z'; } - if ((($clublog ?? 0)>0) && (($postdata['clublog'] ?? '') != '')) { $string.='C'; } - if ($string == '') { $string='C'; } - return $string; - } - /* * Gets all DXCC data with confirmation status in efficient query using MAX aggregation - * Returns both regular bands and satellite data */ function getDxccData($location_list, $postdata) { $bindings = []; @@ -392,118 +369,8 @@ class DXCC extends CI_Model { return $query->result(); } - function getDxccBandConfirmed($location_list, $postdata) { + function fetchDxcc($postdata, $location_list) { $bindings=[]; - $sql = "select adif as dxcc, name, lotw, qsl, eqsl, qrz, clublog from dxcc_entities - join ( - select col_dxcc, - sum(case when thcv.col_lotw_qsl_rcvd ='Y' then 1 else 0 end) as lotw, - sum(case when thcv.col_qsl_rcvd = 'Y' then 1 else 0 end) as qsl, - sum(case when thcv.col_eqsl_qsl_rcvd = 'Y' then 1 else 0 end) as eqsl, - sum(case when thcv.COL_QRZCOM_QSO_DOWNLOAD_STATUS= 'Y' then 1 else 0 end) as qrz, - sum(case when thcv.COL_CLUBLOG_QSO_DOWNLOAD_STATUS = 'Y' then 1 else 0 end) as clublog - from ".$this->config->item('table_name')." thcv - LEFT JOIN satellite on thcv.COL_SAT_NAME = satellite.name - where station_id in (" . $location_list . - ") and col_dxcc > 0"; - - if ($postdata['sat'] != 'All') { - $sql .= " and col_sat_name = ?"; - $bindings[]=$postdata['sat']; - } - - if ($postdata['mode'] != 'All') { - $sql .= " and (col_mode = ? or col_submode = ?)"; - $bindings[]=$postdata['mode']; - $bindings[]=$postdata['mode']; - } - - $sql .= $this->addOrbitToQuery($postdata,$bindings); - - $sql .= $this->genfunctions->addQslToQuery($postdata); - - if ($postdata['dateFrom'] != NULL) { - $sql .= " and col_time_on >= ?"; - $bindings[]=$postdata['dateFrom'] . ' 00:00:00'; - } - - if ($postdata['dateTo'] != NULL) { - $sql .= " and col_time_on <= ?"; - $bindings[]=$postdata['dateTo'] . ' 23:59:59'; - } - - $sql .= " group by col_dxcc - ) x on dxcc_entities.adif = x.col_dxcc"; - - if ($postdata['includedeleted'] == NULL) { - $sql .= " and dxcc_entities.end is null"; - } - - $sql .= $this->addContinentsToQuery($postdata); - - $query = $this->db->query($sql,$bindings); - - return $query->result(); - } - - function getDxccBandWorked($location_list, $band, $postdata) { - $bindings=[]; - $sql = "select adif as dxcc, name from dxcc_entities - join ( - select col_dxcc from ".$this->config->item('table_name')." thcv - LEFT JOIN satellite on thcv.COL_SAT_NAME = satellite.name - where station_id in (" . $location_list . - ") and col_dxcc > 0"; - $sql .= $this->genfunctions->addBandToQuery($band,$bindings); - if ($band == 'SAT') { - $sql .= " and col_prop_mode ='SAT'"; - if ($postdata['sat'] != 'All') { - $sql .= " and col_sat_name = ?"; - $bindings[]=$postdata['sat']; - } - } else { - $sql.=" and (col_prop_mode != 'SAT' or col_prop_mode is null)"; - } - - if ($postdata['mode'] != 'All') { - $sql .= " and (col_mode = ? or col_submode = ?)"; - $bindings[]=$postdata['mode']; - $bindings[]=$postdata['mode']; - } - - if ($postdata['dateFrom'] != NULL) { - $sql .= " and col_time_on >= ?"; - $bindings[]=$postdata['dateFrom'] . ' 00:00:00'; - } - - if ($postdata['dateTo'] != NULL) { - $sql .= " and col_time_on <= ?"; - $bindings[]=$postdata['dateTo'] . ' 23:59:59'; - } - - $sql .= $this->addOrbitToQuery($postdata,$bindings); - - $sql .= " group by col_dxcc - ) x on dxcc_entities.adif = x.col_dxcc";; - if ($postdata['includedeleted'] == NULL) { - $sql .= " and dxcc_entities.end is null"; - } - $sql .= $this->addContinentsToQuery($postdata); - - $query = $this->db->query($sql,$bindings); - return $query->result(); - } - - function fetchDxcc($postdata) { - $bindings=[]; - $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 adif, prefix, name, date(end) Enddate, date(start) Startdate, lat, `long` from dxcc_entities"; @@ -565,146 +432,6 @@ class DXCC extends CI_Model { return $query->result(); } - function getDxccWorked($location_list, $postdata) { - $bindings=[]; - $sql = "SELECT adif as dxcc FROM dxcc_entities - join ( - select col_dxcc - from ".$this->config->item('table_name')." thcv - LEFT JOIN satellite on thcv.COL_SAT_NAME = satellite.name - where station_id in (" . $location_list . - ") and col_dxcc > 0"; - $sql .= $this->genfunctions->addBandToQuery($postdata['band'],$bindings); - if ($postdata['band'] == 'SAT') { - $sql .= " and col_prop_mode = 'SAT'"; - if ($postdata['sat'] != 'All') { - $sql .= " and col_sat_name = ?"; - $bindings[]=$postdata['sat']; - } - $sql .= $this->addOrbitToQuery($postdata,$bindings); - } else { - $sql.=" and (col_prop_mode != 'SAT' or col_prop_mode is null)"; - } - - - if ($postdata['mode'] != 'All') { - $sql .= " and (col_mode = ? or col_submode = ?)"; - $bindings[]=$postdata['mode']; - $bindings[]=$postdata['mode']; - } - - if ($postdata['dateFrom'] != NULL) { - $sql .= " and col_time_on >= ?"; - $bindings[]=$postdata['dateFrom'] . ' 00:00:00'; - } - - if ($postdata['dateTo'] != NULL) { - $sql .= " and col_time_on <= ?"; - $bindings[]=$postdata['dateTo'] . ' 23:59:59'; - } - - $sql .= " and not exists (select 1 from ".$this->config->item('table_name')." where station_id in (". $location_list .") and col_dxcc = thcv.col_dxcc and col_dxcc > 0"; - $sql .= $this->genfunctions->addBandToQuery($postdata['band'],$bindings); - if ($postdata['band'] == 'SAT') { - $sql .= " and col_prop_mode = 'SAT'"; - if ($postdata['sat'] != 'All') { - $sql .= " and col_sat_name = ?"; - $bindings[]=$postdata['sat']; - } - $sql .= $this->addOrbitToQuery($postdata,$bindings); - } else { - $sql.=" and (col_prop_mode != 'SAT' or col_prop_mode is null)"; - } - - if ($postdata['dateFrom'] != NULL) { - $sql .= " and col_time_on >= ?"; - $bindings[]=$postdata['dateFrom'] . ' 00:00:00'; - } - - if ($postdata['dateTo'] != NULL) { - $sql .= " and col_time_on <= ?"; - $bindings[]=$postdata['dateTo'] . ' 23:59:59'; - } - - - if ($postdata['mode'] != 'All') { - $sql .= " and (col_mode = ? or col_submode = ?)"; - $bindings[]=$postdata['mode']; - $bindings[]=$postdata['mode']; - } - - $sql .= $this->genfunctions->addQslToQuery($postdata); - $sql .= ')'; - $sql .= " group by col_dxcc - ) ll on dxcc_entities.adif = ll.col_dxcc - where 1=1"; - - if ($postdata['includedeleted'] == NULL) { - $sql .= " and dxcc_entities.end is null"; - } - - $sql .= $this->addContinentsToQuery($postdata); - $query = $this->db->query($sql,$bindings); - return $query->result(); - } - - function getDxccConfirmed($location_list, $postdata) { - $bindings=[]; - $sql = "SELECT adif as dxcc, lotw, qsl, eqsl, qrz, clublog FROM dxcc_entities - join ( - select col_dxcc, sum(case when thcv.col_lotw_qsl_rcvd ='Y' then 1 else 0 end) as lotw,sum(case when thcv.col_qsl_rcvd = 'Y' then 1 else 0 end) as qsl,sum(case when thcv.col_eqsl_qsl_rcvd = 'Y' then 1 else 0 end) as eqsl,sum(case when thcv.COL_QRZCOM_QSO_DOWNLOAD_STATUS= 'Y' then 1 else 0 end) as qrz,sum(case when thcv.COL_CLUBLOG_QSO_DOWNLOAD_STATUS = 'Y' then 1 else 0 end) as clublog - from ".$this->config->item('table_name')." thcv - LEFT JOIN satellite on thcv.COL_SAT_NAME = satellite.name - where station_id in (". $location_list . - ") and col_dxcc > 0"; - - if ($postdata['dateFrom'] != NULL) { - $sql .= " and col_time_on >= ?"; - $bindings[]=$postdata['dateFrom'] . ' 00:00:00'; - } - - if ($postdata['dateTo'] != NULL) { - $sql .= " and col_time_on <= ?"; - $bindings[]=$postdata['dateTo'] . ' 23:59:59'; - } - - $sql .= $this->genfunctions->addBandToQuery($postdata['band'],$bindings); - if ($postdata['band'] == 'SAT') { - $sql .= " and col_prop_mode = 'SAT'"; - if ($postdata['sat'] != 'All') { - $sql .= " and col_sat_name = ?"; - $bindings[]=$postdata['sat']; - } - } else { - $sql.=" and (col_prop_mode != 'SAT' or col_prop_mode is null)"; - } - - if ($postdata['mode'] != 'All') { - $sql .= " and (col_mode = ? or col_submode = ?)"; - $bindings[]=$postdata['mode']; - $bindings[]=$postdata['mode']; - } - - $sql .= $this->addOrbitToQuery($postdata,$bindings); - - $sql .= $this->genfunctions->addQslToQuery($postdata); - - $sql .= " group by col_dxcc - ) ll on dxcc_entities.adif = ll.col_dxcc - where 1=1"; - - if ($postdata['includedeleted'] == NULL) { - $sql .= " and dxcc_entities.end is null"; - } - - $sql .= $this->addContinentsToQuery($postdata); - - - $query = $this->db->query($sql,$bindings); - - return $query->result(); - } - // Made function instead of repeating this several times function addContinentsToQuery($postdata) { $sql = ''; @@ -738,100 +465,6 @@ class DXCC extends CI_Model { return $sql; } - /* - * Function gets worked and confirmed summary on each band on the active stationprofile - * Now uses data from get_dxcc_array instead of separate queries - much more efficient! - */ - function get_dxcc_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)."'"; - - // Get all DXCC entities - $this->load->model('dxcc'); - $dxccEntities = $this->dxcc->list_current(); - - $result = $this->get_dxcc_array($dxccEntities, $bands, $postdata); - - if ($result && isset($result['summary'])) { - return $result['summary']; - } - - // Fallback to empty structure if something went wrong - $dxccSummary = []; - foreach ($bands as $band) { - $dxccSummary['worked'][$band] = '-'; - $dxccSummary['confirmed'][$band] = '-'; - } - $dxccSummary['worked']['Total'] = '-'; - $dxccSummary['confirmed']['Total'] = '-'; - - return $dxccSummary; - } - - function getSummaryByBand($band, $postdata, $location_list) { - $bindings=[]; - $sql = "SELECT count(distinct thcv.col_dxcc) as count FROM " . $this->config->item('table_name') . " thcv"; - $sql .= " LEFT JOIN satellite on thcv.COL_SAT_NAME = satellite.name"; - $sql .= " join dxcc_entities d on thcv.col_dxcc = d.adif"; - - $sql .= " where station_id in (" . $location_list . ") and col_dxcc > 0"; - - if ($band == 'SAT') { - $sql .= " and thcv.col_prop_mode ='" . $band . "'"; - if ($band != 'All' && $postdata['sat'] != 'All') { - $sql .= " and col_sat_name = ?"; - $bindings[]=$postdata['sat']; - } - } else if ($band == 'All') { - $this->load->model('bands'); - - $bandslots = $this->bands->get_worked_bands('dxcc'); - - $bandslots_list = "'".implode("','",$bandslots)."'"; - - $sql .= " and thcv.col_band in (" . $bandslots_list . ")" . - " and thcv.col_prop_mode !='SAT'"; - } else { - $sql .= " and thcv.col_prop_mode !='SAT'"; - $sql .= " and thcv.col_band = ?"; - $bindings[]=$band; - } - - if ($postdata['dateFrom'] != NULL) { - $sql .= " and col_time_on >= ?"; - $bindings[]=$postdata['dateFrom'] . ' 00:00:00'; - } - - if ($postdata['dateTo'] != NULL) { - $sql .= " and col_time_on <= ?"; - $bindings[]=$postdata['dateTo'] . ' 23:59:59'; - } - - if ($postdata['mode'] != 'All') { - $sql .= " and (col_mode = ? or col_submode = ?)"; - $bindings[]=$postdata['mode']; - $bindings[]=$postdata['mode']; - } - - if ($postdata['includedeleted'] == NULL) { - $sql .= " and d.end is null"; - } - - $sql .= $this->addContinentsToQuery($postdata); - - $sql .= $this->addOrbitToQuery($postdata,$bindings); - - $query = $this->db->query($sql,$bindings); - - return $query->result(); - } - // Adds orbit type to query function addOrbitToQuery($postdata,&$binding) { $sql = ''; @@ -843,68 +476,6 @@ class DXCC extends CI_Model { return $sql; } - function getSummaryByBandConfirmed($band, $postdata, $location_list) { - $bindings=[]; - $sql = "SELECT count(distinct thcv.col_dxcc) as count, sum(case when thcv.col_lotw_qsl_rcvd ='Y' then 1 else 0 end) as lotw,sum(case when thcv.col_qsl_rcvd = 'Y' then 1 else 0 end) as qsl,sum(case when thcv.col_eqsl_qsl_rcvd = 'Y' then 1 else 0 end) as eqsl,sum(case when thcv.COL_QRZCOM_QSO_DOWNLOAD_STATUS= 'Y' then 1 else 0 end) as qrz,sum(case when thcv.COL_CLUBLOG_QSO_DOWNLOAD_STATUS = 'Y' then 1 else 0 end) as clublog FROM " . $this->config->item('table_name') . " thcv"; - $sql .= " LEFT JOIN satellite on thcv.COL_SAT_NAME = satellite.name"; - $sql .= " join dxcc_entities d on thcv.col_dxcc = d.adif"; - - $sql .= " where station_id in (" . $location_list . ") and col_dxcc > 0"; - - if ($band == 'SAT') { - $sql .= " and thcv.col_prop_mode = ?"; - $bindings[]=$band; - if ($postdata['sat'] != 'All') { - $sql .= " and col_sat_name = ?"; - $bindings[]=$postdata['sat']; - } - } else if ($band == 'All') { - $this->load->model('bands'); - - $bandslots = $this->bands->get_worked_bands('dxcc'); - - $bandslots_list = "'".implode("','",$bandslots)."'"; - - $sql .= " and thcv.col_band in (" . $bandslots_list . ")" . - " and thcv.col_prop_mode !='SAT'"; - } else { - $sql .= " and thcv.col_prop_mode !='SAT'"; - $sql .= " and thcv.col_band = ?"; - $bindings[]=$band; - } - - if ($postdata['dateFrom'] != NULL) { - $sql .= " and col_time_on >= ?"; - $bindings[]=$postdata['dateFrom'] . ' 00:00:00'; - } - - if ($postdata['dateTo'] != NULL) { - $sql .= " and col_time_on <= ?"; - $bindings[]=$postdata['dateTo'] . ' 23:59:59'; - } - - if ($postdata['mode'] != 'All') { - $sql .= " and (col_mode = ? or col_submode = ?)"; - $bindings[]=$postdata['mode']; - $bindings[]=$postdata['mode']; - } - - $sql .= $this->genfunctions->addQslToQuery($postdata); - - $sql .= $this->addOrbitToQuery($postdata,$bindings); - - - if ($postdata['includedeleted'] == NULL) { - $sql .= " and d.end is null"; - } - - $sql .= $this->addContinentsToQuery($postdata); - - $query = $this->db->query($sql,$bindings); - - return $query->result(); - } - /* * Functions below are all used in the calltester controller */ @@ -1226,10 +797,8 @@ class DXCC extends CI_Model { // query the table, removing a character from the right until a match for ($i = $len; $i > 0; $i--) { - //printf("searching for %s\n", substr($call, 0, $i)); if (array_key_exists(substr($call, 0, $i), $dxcc_array)) { $row = $dxcc_array[substr($call, 0, $i)]; - // $row = $dxcc_result->row_array(); return $row; } } diff --git a/application/views/awards/dxcc/index.php b/application/views/awards/dxcc/index.php index 713b66160..f080aadba 100644 --- a/application/views/awards/dxcc/index.php +++ b/application/views/awards/dxcc/index.php @@ -172,7 +172,7 @@