2020-03-07 10:39:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class IOTA extends CI_Model {
|
|
|
|
|
|
|
|
function get_iota_array($iotaArray, $bands, $postdata) {
|
2021-09-09 20:18:55 +00:00
|
|
|
$CI =& get_instance();
|
|
|
|
$CI->load->model('logbooks_model');
|
|
|
|
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
|
|
|
|
2021-11-14 16:11:59 +00:00
|
|
|
if (!$logbooks_locations_array) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-09-09 20:18:55 +00:00
|
|
|
$location_list = "'".implode("','",$logbooks_locations_array)."'";
|
2020-03-07 10:39:22 +00:00
|
|
|
|
2020-03-18 18:26:26 +00:00
|
|
|
foreach ($bands as $band) { // Looping through bands and iota to generate the array needed for display
|
2020-03-07 10:39:22 +00:00
|
|
|
foreach ($iotaArray as $iota) {
|
|
|
|
$iotaMatrix[$iota->tag]['prefix'] = $iota->prefix;
|
|
|
|
$iotaMatrix[$iota->tag]['name'] = $iota->name;
|
|
|
|
if ($postdata['includedeleted'])
|
|
|
|
$iotaMatrix[$iota->tag]['Deleted'] = isset($iota->status) && $iota->status == 'D' ? "<div class='alert-danger'>Y</div>" : '';
|
|
|
|
$iotaMatrix[$iota->tag][$band] = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
// If worked is checked, we add worked iotas to the array
|
|
|
|
if ($postdata['worked'] != NULL) {
|
2021-09-09 20:18:55 +00:00
|
|
|
$workedIota = $this->getIotaBandWorked($location_list, $band, $postdata);
|
2020-03-07 10:39:22 +00:00
|
|
|
foreach ($workedIota as $wiota) {
|
2021-07-26 11:13:16 +00:00
|
|
|
$iotaMatrix[$wiota->tag][$band] = '<div class="alert-danger"><a href=\'javascript:displayContacts("'.$wiota->tag.'","'. $band . '","'. $postdata['mode'] . '","IOTA")\'>W</a></div>';
|
2020-03-07 10:39:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If confirmed is checked, we add confirmed iotas to the array
|
|
|
|
if ($postdata['confirmed'] != NULL) {
|
2021-09-09 20:18:55 +00:00
|
|
|
$confirmedIota = $this->getIotaBandConfirmed($location_list, $band, $postdata);
|
2020-03-07 10:39:22 +00:00
|
|
|
foreach ($confirmedIota as $ciota) {
|
2021-07-26 11:13:16 +00:00
|
|
|
$iotaMatrix[$ciota->tag][$band] = '<div class="alert-success"><a href=\'javascript:displayContacts("'.$ciota->tag.'","'. $band . '","'. $postdata['mode'] . '","IOTA")\'>C</a></div>';
|
2020-03-07 10:39:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We want to remove the worked iotas in the list, since we do not want to display them
|
|
|
|
if ($postdata['worked'] == NULL) {
|
2021-09-09 20:18:55 +00:00
|
|
|
$workedIota = $this->getIotaWorked($location_list, $postdata);
|
2020-03-07 10:39:22 +00:00
|
|
|
foreach ($workedIota as $wiota) {
|
|
|
|
if (array_key_exists($wiota->tag, $iotaMatrix)) {
|
|
|
|
unset($iotaMatrix[$wiota->tag]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We want to remove the confirmed iotas in the list, since we do not want to display them
|
|
|
|
if ($postdata['confirmed'] == NULL) {
|
2021-09-09 20:18:55 +00:00
|
|
|
$confirmedIOTA = $this->getIotaConfirmed($location_list, $postdata);
|
2020-03-07 10:39:22 +00:00
|
|
|
foreach ($confirmedIOTA as $ciota) {
|
|
|
|
if (array_key_exists($ciota->tag, $iotaMatrix)) {
|
|
|
|
unset($iotaMatrix[$ciota->tag]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($iotaMatrix)) {
|
|
|
|
return $iotaMatrix;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-09 20:18:55 +00:00
|
|
|
function getIotaBandConfirmed($location_list, $band, $postdata) {
|
2021-07-24 12:31:16 +00:00
|
|
|
$sql = "SELECT distinct col_iota as tag FROM " . $this->config->item('table_name') . " thcv
|
2020-03-07 10:39:22 +00:00
|
|
|
join iota on thcv.col_iota = iota.tag
|
2021-09-09 20:18:55 +00:00
|
|
|
where station_id in (" . $location_list .
|
|
|
|
") and thcv.col_iota is not null
|
2021-07-26 11:13:16 +00:00
|
|
|
and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')";
|
|
|
|
|
|
|
|
if ($postdata['mode'] != 'All') {
|
|
|
|
$sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')";
|
|
|
|
}
|
2020-03-07 10:39:22 +00:00
|
|
|
|
2022-12-11 16:47:36 +00:00
|
|
|
$sql .= $this->addBandToQuery($band);
|
2020-03-07 10:39:22 +00:00
|
|
|
|
|
|
|
if ($postdata['includedeleted'] == NULL) {
|
|
|
|
$sql .= " and coalesce(iota.status, '') <> 'D'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql .= $this->addContinentsToQuery($postdata);
|
|
|
|
|
|
|
|
$query = $this->db->query($sql);
|
|
|
|
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
2021-09-09 20:18:55 +00:00
|
|
|
function getIotaBandWorked($location_list, $band, $postdata) {
|
2021-07-24 12:31:16 +00:00
|
|
|
$sql = 'SELECT distinct col_iota as tag FROM ' . $this->config->item('table_name'). ' thcv
|
2020-03-07 10:39:22 +00:00
|
|
|
join iota on thcv.col_iota = iota.tag
|
2021-09-09 20:18:55 +00:00
|
|
|
where station_id in (' . $location_list .
|
|
|
|
') and thcv.col_iota is not null';
|
2020-03-07 10:39:22 +00:00
|
|
|
|
2021-07-26 11:13:16 +00:00
|
|
|
if ($postdata['mode'] != 'All') {
|
|
|
|
$sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')";
|
|
|
|
}
|
|
|
|
|
2022-12-11 16:47:36 +00:00
|
|
|
$sql .= $this->addBandToQuery($band);
|
2020-03-07 10:39:22 +00:00
|
|
|
|
|
|
|
if ($postdata['includedeleted'] == NULL) {
|
|
|
|
$sql .= " and coalesce(iota.status, '') <> 'D'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql .= $this->addContinentsToQuery($postdata);
|
|
|
|
|
|
|
|
$query = $this->db->query($sql);
|
|
|
|
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetchIota($postdata) {
|
2022-01-06 19:02:53 +00:00
|
|
|
$CI =& get_instance();
|
|
|
|
$CI->load->model('logbooks_model');
|
|
|
|
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
|
|
|
|
|
|
|
if (!$logbooks_locations_array) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$location_list = "'".implode("','",$logbooks_locations_array)."'";
|
|
|
|
|
2022-12-11 16:47:36 +00:00
|
|
|
$sql = "select tag, name, prefix, dxccid, status, lat1, lat2, lon1, lon2 from iota where 1=1";
|
2020-03-07 10:39:22 +00:00
|
|
|
|
|
|
|
if ($postdata['includedeleted'] == NULL) {
|
|
|
|
$sql .= " and coalesce(iota.status, '') <> 'D'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql .= $this->addContinentsToQuery($postdata);
|
|
|
|
|
|
|
|
if ($postdata['notworked'] == NULL) {
|
2021-09-09 20:18:55 +00:00
|
|
|
$sql .= " and exists (select 1 from " . $this->config->item('table_name') . " where station_id in (". $location_list . ") and col_iota = iota.tag";
|
2021-07-26 11:13:16 +00:00
|
|
|
|
|
|
|
if ($postdata['mode'] != 'All') {
|
|
|
|
$sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')";
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:39:22 +00:00
|
|
|
if ($postdata['band'] != 'All') {
|
|
|
|
if ($postdata['band'] == 'SAT') {
|
|
|
|
$sql .= " and col_prop_mode ='" . $postdata['band'] . "'";
|
|
|
|
}
|
|
|
|
else {
|
2020-03-18 18:26:26 +00:00
|
|
|
$sql .= " and col_prop_mode !='SAT'";
|
2020-03-07 10:39:22 +00:00
|
|
|
$sql .= " and col_band ='" . $postdata['band'] . "'";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$sql .= ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql .= ' order by tag';
|
|
|
|
$query = $this->db->query($sql);
|
|
|
|
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
2021-09-09 20:18:55 +00:00
|
|
|
function getIotaWorked($location_list, $postdata) {
|
2021-07-24 12:31:16 +00:00
|
|
|
$sql = "SELECT distinct col_iota as tag FROM " . $this->config->item('table_name') . " thcv
|
2020-03-07 10:39:22 +00:00
|
|
|
join iota on thcv.col_iota = iota.tag
|
2021-09-09 20:18:55 +00:00
|
|
|
where station_id in (" . $location_list .
|
|
|
|
") and thcv.col_iota is not null
|
|
|
|
and not exists (select 1 from ". $this->config->item('table_name') . " where station_id = ". $location_list .
|
2020-03-07 10:39:22 +00:00
|
|
|
" and col_iota = thcv.col_iota";
|
|
|
|
|
2021-07-26 11:13:16 +00:00
|
|
|
if ($postdata['mode'] != 'All') {
|
|
|
|
$sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')";
|
|
|
|
}
|
|
|
|
|
2022-12-11 16:47:36 +00:00
|
|
|
$sql .= $this->addBandToQuery($postdata['band']);
|
2020-03-07 10:39:22 +00:00
|
|
|
|
2021-07-26 11:13:16 +00:00
|
|
|
$sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y'))";
|
2020-03-07 10:39:22 +00:00
|
|
|
|
2022-12-11 16:47:36 +00:00
|
|
|
$sql .= $this->addBandToQuery($postdata['band']);
|
2020-03-07 10:39:22 +00:00
|
|
|
|
|
|
|
if ($postdata['includedeleted'] == NULL) {
|
|
|
|
$sql .= " and coalesce(iota.status, '') <> 'D'";
|
|
|
|
}
|
|
|
|
|
2021-07-26 11:13:16 +00:00
|
|
|
if ($postdata['mode'] != 'All') {
|
|
|
|
$sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')";
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:39:22 +00:00
|
|
|
$sql .= $this->addContinentsToQuery($postdata);
|
|
|
|
|
|
|
|
$query = $this->db->query($sql);
|
|
|
|
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
2021-09-09 20:18:55 +00:00
|
|
|
function getIotaConfirmed($location_list, $postdata) {
|
2021-07-24 12:31:16 +00:00
|
|
|
$sql = "SELECT distinct col_iota as tag FROM " . $this->config->item('table_name') . " thcv
|
2020-03-07 10:39:22 +00:00
|
|
|
join iota on thcv.col_iota = iota.tag
|
2021-09-09 20:18:55 +00:00
|
|
|
where station_id in (" . $location_list .
|
|
|
|
") and thcv.col_iota is not null
|
2021-07-26 11:13:16 +00:00
|
|
|
and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')";
|
|
|
|
|
|
|
|
if ($postdata['mode'] != 'All') {
|
|
|
|
$sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')";
|
|
|
|
}
|
2020-03-07 10:39:22 +00:00
|
|
|
|
|
|
|
if ($postdata['includedeleted'] == NULL) {
|
|
|
|
$sql .= " and coalesce(iota.status, '') <> 'D'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql .= $this->addContinentsToQuery($postdata);
|
|
|
|
|
2022-12-11 16:47:36 +00:00
|
|
|
$sql .= $this->addBandToQuery($postdata['band']);
|
2020-03-07 10:39:22 +00:00
|
|
|
|
|
|
|
$query = $this->db->query($sql);
|
|
|
|
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Made function instead of repeating this several times
|
|
|
|
function addContinentsToQuery($postdata) {
|
|
|
|
$sql = '';
|
|
|
|
if ($postdata['Africa'] == NULL) {
|
|
|
|
$sql .= " and left(tag, 2) <> 'AF'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($postdata['Europe'] == NULL) {
|
|
|
|
$sql .= " and left(tag, 2) <> 'EU'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($postdata['Asia'] == NULL) {
|
|
|
|
$sql .= " and left(tag, 2) <> 'AS'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($postdata['SouthAmerica'] == NULL) {
|
|
|
|
$sql .= " and left(tag, 2) <> 'SA'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($postdata['NorthAmerica'] == NULL) {
|
|
|
|
$sql .= " and left(tag, 2) <> 'NA'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($postdata['Oceania'] == NULL) {
|
|
|
|
$sql .= " and left(tag, 2) <> 'OC'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($postdata['Antarctica'] == NULL) {
|
|
|
|
$sql .= " and left(tag, 2) <> 'AN'";
|
|
|
|
}
|
|
|
|
return $sql;
|
|
|
|
}
|
2020-10-11 12:54:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function gets worked and confirmed summary on each band on the active stationprofile
|
|
|
|
*/
|
2022-01-06 19:02:53 +00:00
|
|
|
function get_iota_summary($bands, $postdata)
|
2020-10-11 12:54:23 +00:00
|
|
|
{
|
2021-09-09 20:18:55 +00:00
|
|
|
$CI =& get_instance();
|
|
|
|
$CI->load->model('logbooks_model');
|
|
|
|
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
|
|
|
|
2021-11-14 16:11:59 +00:00
|
|
|
if (!$logbooks_locations_array) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-09-09 20:18:55 +00:00
|
|
|
$location_list = "'".implode("','",$logbooks_locations_array)."'";
|
2020-10-11 12:54:23 +00:00
|
|
|
|
|
|
|
foreach ($bands as $band) {
|
2022-01-06 19:02:53 +00:00
|
|
|
$worked = $this->getSummaryByBand($band, $postdata, $location_list);
|
|
|
|
$confirmed = $this->getSummaryByBandConfirmed($band, $postdata, $location_list);
|
2020-10-11 12:54:23 +00:00
|
|
|
$iotaSummary['worked'][$band] = $worked[0]->count;
|
|
|
|
$iotaSummary['confirmed'][$band] = $confirmed[0]->count;
|
|
|
|
}
|
|
|
|
|
2022-01-06 19:02:53 +00:00
|
|
|
$workedTotal = $this->getSummaryByBand($postdata['band'], $postdata, $location_list);
|
|
|
|
$confirmedTotal = $this->getSummaryByBandConfirmed($postdata['band'], $postdata, $location_list);
|
2020-10-15 07:49:55 +00:00
|
|
|
|
|
|
|
$iotaSummary['worked']['Total'] = $workedTotal[0]->count;
|
|
|
|
$iotaSummary['confirmed']['Total'] = $confirmedTotal[0]->count;
|
|
|
|
|
2020-10-11 12:54:23 +00:00
|
|
|
return $iotaSummary;
|
|
|
|
}
|
|
|
|
|
2022-01-06 19:02:53 +00:00
|
|
|
function getSummaryByBand($band, $postdata, $location_list)
|
2020-10-11 12:54:23 +00:00
|
|
|
{
|
|
|
|
$sql = "SELECT count(distinct thcv.col_iota) as count FROM " . $this->config->item('table_name') . " thcv";
|
2022-01-06 19:02:53 +00:00
|
|
|
$sql .= ' join iota on thcv.col_iota = iota.tag';
|
2020-10-11 12:54:23 +00:00
|
|
|
|
2021-09-09 20:18:55 +00:00
|
|
|
$sql .= " where station_id in (" . $location_list . ")";
|
2020-10-11 12:54:23 +00:00
|
|
|
|
|
|
|
if ($band == 'SAT') {
|
|
|
|
$sql .= " and thcv.col_prop_mode ='" . $band . "'";
|
2020-10-15 07:49:55 +00:00
|
|
|
} else if ($band == 'All') {
|
2022-09-07 18:40:31 +00:00
|
|
|
$this->load->model('bands');
|
|
|
|
|
|
|
|
$bandslots = $this->bands->get_worked_bands('iota');
|
|
|
|
|
|
|
|
$bandslots_list = "'".implode("','",$bandslots)."'";
|
|
|
|
|
|
|
|
$sql .= " and thcv.col_band in (" . $bandslots_list . ")" .
|
|
|
|
" and thcv.col_prop_mode !='SAT'";
|
2020-10-11 12:54:23 +00:00
|
|
|
} else {
|
|
|
|
$sql .= " and thcv.col_prop_mode !='SAT'";
|
|
|
|
$sql .= " and thcv.col_band ='" . $band . "'";
|
2022-01-06 19:02:53 +00:00
|
|
|
}
|
2020-10-11 12:54:23 +00:00
|
|
|
|
2022-01-06 19:02:53 +00:00
|
|
|
if ($postdata['includedeleted'] == NULL) {
|
|
|
|
$sql .= " and coalesce(iota.status, '') <> 'D'";
|
2020-10-11 12:54:23 +00:00
|
|
|
}
|
2022-01-06 19:02:53 +00:00
|
|
|
|
|
|
|
if ($postdata['mode'] != 'All') {
|
|
|
|
$sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql .= $this->addContinentsToQuery($postdata);
|
|
|
|
|
2020-10-11 12:54:23 +00:00
|
|
|
$query = $this->db->query($sql);
|
|
|
|
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
2022-01-06 19:02:53 +00:00
|
|
|
function getSummaryByBandConfirmed($band, $postdata, $location_list)
|
2020-10-11 12:54:23 +00:00
|
|
|
{
|
|
|
|
$sql = "SELECT count(distinct thcv.col_iota) as count FROM " . $this->config->item('table_name') . " thcv";
|
2022-01-06 19:02:53 +00:00
|
|
|
$sql .= ' join iota on thcv.col_iota = iota.tag';
|
2020-10-11 12:54:23 +00:00
|
|
|
|
2021-09-09 20:18:55 +00:00
|
|
|
$sql .= " where station_id in (" . $location_list . ")";
|
2020-10-11 12:54:23 +00:00
|
|
|
|
|
|
|
if ($band == 'SAT') {
|
|
|
|
$sql .= " and thcv.col_prop_mode ='" . $band . "'";
|
2020-10-15 07:49:55 +00:00
|
|
|
} else if ($band == 'All') {
|
2022-09-07 18:40:31 +00:00
|
|
|
$this->load->model('bands');
|
|
|
|
|
|
|
|
$bandslots = $this->bands->get_worked_bands('iota');
|
|
|
|
|
|
|
|
$bandslots_list = "'".implode("','",$bandslots)."'";
|
|
|
|
|
|
|
|
$sql .= " and thcv.col_band in (" . $bandslots_list . ")" .
|
|
|
|
" and thcv.col_prop_mode !='SAT'";
|
2020-10-11 12:54:23 +00:00
|
|
|
} else {
|
|
|
|
$sql .= " and thcv.col_prop_mode !='SAT'";
|
|
|
|
$sql .= " and thcv.col_band ='" . $band . "'";
|
|
|
|
}
|
|
|
|
|
2022-01-06 19:02:53 +00:00
|
|
|
if ($postdata['includedeleted'] == NULL) {
|
|
|
|
$sql .= " and coalesce(iota.status, '') <> 'D'";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($postdata['mode'] != 'All') {
|
|
|
|
$sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql .= $this->addContinentsToQuery($postdata);
|
|
|
|
|
2020-10-11 12:54:23 +00:00
|
|
|
$sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')";
|
|
|
|
|
|
|
|
$query = $this->db->query($sql);
|
|
|
|
|
|
|
|
return $query->result();
|
|
|
|
}
|
2022-12-11 16:47:36 +00:00
|
|
|
|
|
|
|
function addBandToQuery($band) {
|
|
|
|
$sql = '';
|
|
|
|
if ($band != 'All') {
|
|
|
|
if ($band == 'SAT') {
|
|
|
|
$sql .= " and col_prop_mode ='" . $band . "'";
|
|
|
|
} else {
|
|
|
|
$sql .= " and col_prop_mode !='SAT'";
|
|
|
|
$sql .= " and col_band ='" . $band . "'";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $sql;
|
|
|
|
}
|
2020-03-07 10:39:22 +00:00
|
|
|
}
|
2021-07-24 12:31:16 +00:00
|
|
|
?>
|