mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
288 lines
9.5 KiB
PHP
288 lines
9.5 KiB
PHP
<?php
|
|
|
|
class CQ extends CI_Model{
|
|
|
|
function __construct() {
|
|
$this->load->library('Genfunctions');
|
|
}
|
|
|
|
function get_cq_array($bands, $postdata, $location_list, $map = false) {
|
|
$cqZ = array(); // Used for keeping track of which states that are not worked
|
|
|
|
for ($i = 1; $i <= 40; $i++) {
|
|
$cqZ[$i]['count'] = 0; // Inits each cq zone's count
|
|
}
|
|
|
|
$qsl = $this->genfunctions->gen_qsl_from_postdata($postdata);
|
|
|
|
// Initialize all bands to dash
|
|
foreach ($bands as $band) {
|
|
for ($i = 1; $i <= 40; $i++) {
|
|
$bandCq[$i][$band] = '-'; // Sets all to dash to indicate no result
|
|
}
|
|
}
|
|
|
|
// Initialize summary counters only for the bands passed in
|
|
foreach ($bands as $band) {
|
|
$summary['worked'][$band] = 0;
|
|
$summary['confirmed'][$band] = 0;
|
|
}
|
|
$summary['worked']['Total'] = 0;
|
|
$summary['confirmed']['Total'] = 0;
|
|
|
|
// Track unique zone/band combinations for totals
|
|
$workedZones = []; // [band][zone] = true
|
|
$confirmedZones = []; // [band][zone] = true
|
|
|
|
// Create a lookup array for valid bands
|
|
$validBands = array_flip($bands); // ['160m' => true, '80m' => true, etc]
|
|
|
|
$cqdata = $this->getCqZoneData($location_list, $postdata);
|
|
$cqdata_sat = $this->getCqZoneDataSat($location_list, $postdata);
|
|
|
|
foreach ($cqdata as $cq) {
|
|
// Skip if this band is not in our requested bands list
|
|
if (!isset($validBands[$cq->col_band])) {
|
|
continue;
|
|
}
|
|
|
|
$cqZ[$cq->col_cqz]['count']++; // Count each cq zone
|
|
|
|
// Check if confirmed based on the confirmation types selected in postdata
|
|
$isConfirmed = false;
|
|
$confirmationLetters = '';
|
|
if (isset($postdata['qsl']) && $postdata['qsl'] == 1 && $cq->qsl == 1) {
|
|
$isConfirmed = true;
|
|
$confirmationLetters .= 'Q';
|
|
}
|
|
if (isset($postdata['lotw']) && $postdata['lotw'] == 1 && $cq->lotw == 1) {
|
|
$isConfirmed = true;
|
|
$confirmationLetters .= 'L';
|
|
}
|
|
if (isset($postdata['eqsl']) && $postdata['eqsl'] == 1 && $cq->eqsl == 1) {
|
|
$isConfirmed = true;
|
|
$confirmationLetters .= 'E';
|
|
}
|
|
if (isset($postdata['qrz']) && $postdata['qrz'] == 1 && $cq->qrz == 1) {
|
|
$isConfirmed = true;
|
|
$confirmationLetters .= 'Z';
|
|
}
|
|
if (isset($postdata['clublog']) && $postdata['clublog'] == 1 && $cq->clublog == 1) {
|
|
$isConfirmed = true;
|
|
$confirmationLetters .= 'C';
|
|
}
|
|
|
|
if ($isConfirmed) {
|
|
$bandCq[$cq->col_cqz][$cq->col_band] = '<div class="bg-success awardsBgSuccess"><a href=\'javascript:displayContacts("' . str_replace("&", "%26", $cq->col_cqz) . '","' . $cq->col_band . '","All", "All","'. $postdata['mode'] . '","CQZone","'.$qsl.'")\'>' . $confirmationLetters . '</a></div>';
|
|
// Track confirmed zones for summary
|
|
if (!isset($confirmedZones[$cq->col_band][$cq->col_cqz])) {
|
|
$confirmedZones[$cq->col_band][$cq->col_cqz] = true;
|
|
$summary['confirmed'][$cq->col_band]++;
|
|
}
|
|
} else {
|
|
$bandCq[$cq->col_cqz][$cq->col_band] = '<div class="bg-danger awardsBgWarning"><a href=\'javascript:displayContacts("' . str_replace("&", "%26", $cq->col_cqz) . '","' . $cq->col_band . '","All", "All","'. $postdata['mode'] . '","CQZone","")\'>W</a></div>';
|
|
}
|
|
|
|
// Track worked zones for summary
|
|
if (!isset($workedZones[$cq->col_band][$cq->col_cqz])) {
|
|
$workedZones[$cq->col_band][$cq->col_cqz] = true;
|
|
$summary['worked'][$cq->col_band]++;
|
|
}
|
|
}
|
|
|
|
foreach ($cqdata_sat as $cq) {
|
|
// Skip if this band is not in our requested bands list
|
|
if (!isset($validBands[$cq->col_band])) {
|
|
continue;
|
|
}
|
|
|
|
$cqZ[$cq->col_cqz]['count']++; // Count each cq zone
|
|
|
|
// Check if confirmed based on the confirmation types selected in postdata
|
|
$isConfirmed = false;
|
|
$confirmationLetters = '';
|
|
if (isset($postdata['qsl']) && $postdata['qsl'] == 1 && $cq->qsl == 1) {
|
|
$isConfirmed = true;
|
|
$confirmationLetters .= 'Q';
|
|
}
|
|
if (isset($postdata['lotw']) && $postdata['lotw'] == 1 && $cq->lotw == 1) {
|
|
$isConfirmed = true;
|
|
$confirmationLetters .= 'L';
|
|
}
|
|
if (isset($postdata['eqsl']) && $postdata['eqsl'] == 1 && $cq->eqsl == 1) {
|
|
$isConfirmed = true;
|
|
$confirmationLetters .= 'E';
|
|
}
|
|
if (isset($postdata['qrz']) && $postdata['qrz'] == 1 && $cq->qrz == 1) {
|
|
$isConfirmed = true;
|
|
$confirmationLetters .= 'Z';
|
|
}
|
|
if (isset($postdata['clublog']) && $postdata['clublog'] == 1 && $cq->clublog == 1) {
|
|
$isConfirmed = true;
|
|
$confirmationLetters .= 'C';
|
|
}
|
|
|
|
if ($isConfirmed) {
|
|
$bandCq[$cq->col_cqz][$cq->col_band] = '<div class="bg-success awardsBgSuccess"><a href=\'javascript:displayContacts("' . str_replace("&", "%26", $cq->col_cqz) . '","' . $cq->col_band . '","All", "All","'. $postdata['mode'] . '","CQZone","'.$qsl.'")\'>' . $confirmationLetters . '</a></div>';
|
|
// Track confirmed zones for summary
|
|
if (!isset($confirmedZones[$cq->col_band][$cq->col_cqz])) {
|
|
$confirmedZones[$cq->col_band][$cq->col_cqz] = true;
|
|
$summary['confirmed'][$cq->col_band]++;
|
|
}
|
|
} else {
|
|
$bandCq[$cq->col_cqz][$cq->col_band] = '<div class="bg-danger awardsBgWarning"><a href=\'javascript:displayContacts("' . str_replace("&", "%26", $cq->col_cqz) . '","' . $cq->col_band . '","All", "All","'. $postdata['mode'] . '","CQZone","")\'>W</a></div>';
|
|
}
|
|
|
|
// Track worked zones for summary
|
|
if (!isset($workedZones[$cq->col_band][$cq->col_cqz])) {
|
|
$workedZones[$cq->col_band][$cq->col_cqz] = true;
|
|
$summary['worked'][$cq->col_band]++;
|
|
}
|
|
}
|
|
|
|
// Calculate totals across all bands (excluding SAT)
|
|
$totalWorkedZones = [];
|
|
$totalConfirmedZones = [];
|
|
foreach ($workedZones as $band => $zones) {
|
|
// Skip SAT for totals
|
|
if ($band === 'SAT') {
|
|
continue;
|
|
}
|
|
foreach ($zones as $zone => $true) {
|
|
if (!isset($totalWorkedZones[$zone])) {
|
|
$totalWorkedZones[$zone] = true;
|
|
$summary['worked']['Total']++;
|
|
}
|
|
}
|
|
}
|
|
foreach ($confirmedZones as $band => $zones) {
|
|
// Skip SAT for totals
|
|
if ($band === 'SAT') {
|
|
continue;
|
|
}
|
|
foreach ($zones as $zone => $true) {
|
|
if (!isset($totalConfirmedZones[$zone])) {
|
|
$totalConfirmedZones[$zone] = true;
|
|
$summary['confirmed']['Total']++;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Remove zones based on postdata filters
|
|
for ($i = 1; $i <= 40; $i++) {
|
|
// Remove not-worked zones if filter is disabled
|
|
if ($postdata['notworked'] == NULL && $cqZ[$i]['count'] == 0) {
|
|
unset($bandCq[$i]);
|
|
continue;
|
|
}
|
|
|
|
// Remove worked-only zones if filter is disabled
|
|
if ($postdata['worked'] == NULL && $cqZ[$i]['count'] > 0 && !isset($totalConfirmedZones[$i])) {
|
|
unset($bandCq[$i]);
|
|
continue;
|
|
}
|
|
|
|
// Remove confirmed zones if filter is disabled
|
|
if ($postdata['confirmed'] == NULL && isset($totalConfirmedZones[$i])) {
|
|
unset($bandCq[$i]);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
// If this is for the map, return simplified format
|
|
if ($map) {
|
|
$mapZones = [];
|
|
for ($i = 1; $i <= 40; $i++) {
|
|
if ($cqZ[$i]['count'] == 0) {
|
|
$mapZones[$i-1] = '-'; // Not worked
|
|
} elseif (isset($totalConfirmedZones[$i])) {
|
|
$mapZones[$i-1] = 'C'; // Confirmed
|
|
} else {
|
|
$mapZones[$i-1] = 'W'; // Worked but not confirmed
|
|
}
|
|
}
|
|
return $mapZones;
|
|
}
|
|
|
|
if (isset($bandCq)) {
|
|
// Return both the band data and summary
|
|
return ['bands' => $bandCq, 'summary' => $summary];
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
function getCqZoneData($location_list, $postdata) {
|
|
$bindings=[];
|
|
$sql = "SELECT thcv.col_cqz, thcv.col_band,
|
|
MAX(case when thcv.col_lotw_qsl_rcvd ='Y' then 1 else 0 end) as lotw,
|
|
MAX(case when thcv.col_qsl_rcvd = 'Y' then 1 else 0 end) as qsl,
|
|
MAX(case when thcv.col_eqsl_qsl_rcvd = 'Y' then 1 else 0 end) as eqsl,
|
|
MAX(case when thcv.COL_QRZCOM_QSO_DOWNLOAD_STATUS= 'Y' then 1 else 0 end) as qrz,
|
|
MAX(case when thcv.COL_CLUBLOG_QSO_DOWNLOAD_STATUS = 'Y' then 1 else 0 end) as clublog
|
|
FROM " . $this->config->item('table_name') . " thcv
|
|
where station_id in (" . $location_list . ") and col_cqz <= 40 and col_cqz <> ''";
|
|
|
|
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 col_prop_mode != 'SAT'";
|
|
|
|
$sql .= " GROUP BY thcv.col_cqz, thcv.col_band";
|
|
|
|
$query = $this->db->query($sql,$bindings);
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
function getCqZoneDataSat($location_list, $postdata) {
|
|
$bindings=[];
|
|
$sql = "SELECT thcv.col_cqz, 'SAT' as col_band,
|
|
MAX(case when thcv.col_lotw_qsl_rcvd ='Y' then 1 else 0 end) as lotw,
|
|
MAX(case when thcv.col_qsl_rcvd = 'Y' then 1 else 0 end) as qsl,
|
|
MAX(case when thcv.col_eqsl_qsl_rcvd = 'Y' then 1 else 0 end) as eqsl,
|
|
MAX(case when thcv.COL_QRZCOM_QSO_DOWNLOAD_STATUS= 'Y' then 1 else 0 end) as qrz,
|
|
MAX(case when thcv.COL_CLUBLOG_QSO_DOWNLOAD_STATUS = 'Y' then 1 else 0 end) as clublog
|
|
FROM " . $this->config->item('table_name') . " thcv
|
|
where station_id in (" . $location_list . ") and col_cqz <= 40 and col_cqz <> ''";
|
|
|
|
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 col_prop_mode = 'SAT'";
|
|
|
|
$sql .= " GROUP BY thcv.col_cqz";
|
|
|
|
$query = $this->db->query($sql,$bindings);
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
}
|