diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index 709e0b01..183212f9 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -31,17 +31,63 @@ class Awards extends CI_Controller { public function dok () { + + $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('dok'); $this->load->model('bands'); + $this->load->model('modes'); if($this->input->method() === 'post') { $postdata['doks'] = $this->input->post('doks'); } else { $postdata['doks'] = 'both'; } - $data['doks'] = $this->dok->show_stats($postdata); - $data['worked_bands'] = $this->bands->get_worked_bands_dok(); // Used in the view for band select + $data['worked_bands'] = $this->bands->get_worked_bands('dok'); + $data['modes'] = $this->modes->active(); + + if ($this->input->post('band') != NULL) { + if ($this->input->post('band') == 'All') { + $bands = $data['worked_bands']; + } else { + $bands[] = $this->input->post('band'); + } + } else { + $bands = $data['worked_bands']; + } + + $data['bands'] = $bands; + + if($this->input->method() === 'post') { + $postdata['qsl'] = $this->input->post('qsl'); + $postdata['lotw'] = $this->input->post('lotw'); + $postdata['eqsl'] = $this->input->post('eqsl'); + $postdata['worked'] = $this->input->post('worked'); + $postdata['confirmed'] = $this->input->post('confirmed'); + $postdata['band'] = $this->input->post('band'); + $postdata['mode'] = $this->input->post('mode'); + } else { + $postdata['qsl'] = 1; + $postdata['lotw'] = 1; + $postdata['eqsl'] = 0; + $postdata['worked'] = 1; + $postdata['confirmed'] = 1; + $postdata['band'] = 'All'; + $postdata['mode'] = 'All'; + } + + if ($logbooks_locations_array) { + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + $data['dok_array'] = $this->dok->get_dok_array($bands, $postdata, $location_list); + $data['dok_summary'] = $this->dok->get_dok_summary($bands, $postdata, $location_list); + } else { + $location_list = null; + $data['dok_array'] = null; + $data['dok_summary'] = null; + } // Render Page $data['page_title'] = "Awards - DOK"; @@ -66,9 +112,6 @@ class Awards extends CI_Controller { $arguments["order"] = ''; $arguments["join_station_profile"] = true; - // print_r($arguments); - // return; - // Load the API and Logbook models $this->load->model('api_model'); $this->load->model('logbook_model'); @@ -81,7 +124,7 @@ class Awards extends CI_Controller { // Render Page $data['page_title'] = "Log View - DOK"; - $data['filter'] = str_replace("(and)", ", ", $q);//implode(", ", array_keys($a)); + $data['filter'] = str_replace("(and)", ", ", $q); $this->load->view('awards/details', $data); } @@ -206,8 +249,9 @@ class Awards extends CI_Controller { $band = str_replace('"', "", $this->input->post("Band")); $mode = str_replace('"', "", $this->input->post("Mode")); $type = $this->input->post('Type'); + $qsl = $this->input->post('QSL'); - $data['results'] = $this->logbook_model->qso_details($searchphrase, $band, $mode, $type); + $data['results'] = $this->logbook_model->qso_details($searchphrase, $band, $mode, $type, $qsl); // This is done because we have two different ways to get dxcc info in Cloudlog. Once is using the name (in awards), and the other one is using the ADIF DXCC. // We replace the values to make it look a bit nicer @@ -217,9 +261,23 @@ class Awards extends CI_Controller { $searchphrase = $dxccname['name']; } + $qsltype = []; + if (strpos($qsl, "Q") !== false) { + $qsltype[] = "QSL"; + } + if (strpos($qsl, "L") !== false) { + $qsltype[] = "LotW"; + } + if (strpos($qsl, "E") !== false) { + $qsltype[] = "eQSL"; + } + // Render Page $data['page_title'] = "Log View - " . $type; $data['filter'] = $type . " " . $searchphrase . " and band ".$band . " and mode ".$mode; + if (!empty($qsltype)) { + $data['filter'] .= " and ".implode('/', $qsltype); + } $this->load->view('awards/details', $data); } @@ -733,4 +791,4 @@ class Awards extends CI_Controller { } } } -} \ No newline at end of file +} diff --git a/application/models/Dok.php b/application/models/Dok.php index 0700791e..bc04302f 100644 --- a/application/models/Dok.php +++ b/application/models/Dok.php @@ -2,93 +2,248 @@ class DOK extends CI_Model { - function show_stats($postdata) { - $CI =& get_instance(); - $CI->load->model('logbooks_model'); - $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); +function get_dok_array($bands, $postdata, $location_list) { + $doks = array(); - if (!$logbooks_locations_array) { - return null; + $list = $this->getDoksFromDB($location_list); + foreach ($this->getSdoksFromDB($location_list) as $sdok) { + $list[] = $sdok; + } + foreach ($list as $dok) { + $doks[$dok->COL_DARC_DOK]['count'] = 0; } - $this->load->model('bands'); + $qsl = ""; + if ($postdata['confirmed'] != NULL) { + if ($postdata['qsl'] != NULL ) { + $qsl .= "Q"; + } + if ($postdata['lotw'] != NULL ) { + $qsl .= "L"; + } + if ($postdata['eqsl'] != NULL ) { + $qsl .= "E"; + } + } - $location_list = "'".implode("','",$logbooks_locations_array)."'"; - $sql = "select upper(COL_DARC_DOK) as COL_DARC_DOK, COL_MODE, lcase(COL_BAND) as COL_BAND, count(COL_DARC_DOK) as cnt from ".$this->config->item('table_name')." WHERE station_id in (" . $location_list . ") AND COL_DARC_DOK IS NOT NULL AND COL_DARC_DOK != '' AND COL_DXCC = 230"; + foreach ($bands as $band) { + foreach ($list as $dok) { + $bandDok[$dok->COL_DARC_DOK][$band] = '-'; + } + + if ($postdata['worked'] != NULL) { + $dokBand = $this->getDokWorked($location_list, $band, $postdata); + foreach ($dokBand as $line) { + if (array_key_exists($line->COL_DARC_DOK, $bandDok)) { /* For now ignore DOKs which are logged but not existing in the official lists any more */ + $bandDok[$line->COL_DARC_DOK][$band] = '
COL_DARC_DOK . '","' . $band . '","' . $postdata['mode'] . '","DOK", "")\'>W
'; + $doks[$line->COL_DARC_DOK]['count']++; + } + } + } + + if ($postdata['confirmed'] != NULL) { + $dokBand = $this->getDokConfirmed($location_list, $band, $postdata); + foreach ($dokBand as $line) { + if (array_key_exists($line->COL_DARC_DOK, $bandDok)) { /* For now ignore DOKs which are logged but not existing in the official lists any more */ + $bandDok[$line->COL_DARC_DOK][$band] = '
COL_DARC_DOK . '","' . $band . '","' . $postdata['mode'] . '","DOK", "'.$qsl.'")\'>C
'; + $doks[$line->COL_DARC_DOK]['count']++; + } + } + } + + // We want to remove the worked DOKs in the list, since we do not want to display them + if ($postdata['worked'] == NULL) { + $dokBand = $this->getDokWorked($location_list, $postdata['band'], $postdata); + foreach ($dokBand as $line) { + unset($bandDok[$line->COL_DARC_DOK]); + } + } + + // We want to remove the worked DOKs in the list, since we do not want to display them + if ($postdata['confirmed'] == NULL) { + $dokBand = $this->getDokConfirmed($location_list, $postdata['band'], $postdata); + foreach ($dokBand as $line) { + unset($bandDok[$line->COL_DARC_DOK]); + } + } + } + + foreach ($list as $dok) { + if($doks[$dok->COL_DARC_DOK]['count'] == 0) { + unset($bandDok[$dok->COL_DARC_DOK]); + } + } + + // We want to hide NM as marking not having a DOK at all + unset($bandDok['NM']); + + if (isset($bandDok)) { + return $bandDok; + } else { + return 0; + } + + } + + function getDokWorked($location_list, $band, $postdata) { + $sql = "SELECT DISTINCT COL_DARC_DOK FROM " . $this->config->item('table_name') . " thcv + WHERE station_id IN (" . $location_list . ") AND COL_DARC_DOK <> '' AND COL_DARC_DOK <> 'NM'"; + + if ($postdata['mode'] != 'All') { + $sql .= " AND (COL_MODE = '" . $postdata['mode'] . "' OR COL_SUBMODE = '" . $postdata['mode'] . "')"; + } + $sql .= $this->addDokTypeToQuery($postdata['doks']); + $sql .= $this->addBandToQuery($band); + $sql .= " AND NOT EXISTS (SELECT 1 from " . $this->config->item('table_name') . + " WHERE station_id in (" . $location_list . + ") AND COL_DARC_DOK = thcv.COL_DARC_DOK AND COL_DARC_DOK <> '' AND COL_DARC_DOK <> 'NM' "; + $sql .= $this->addDokTypeToQuery($postdata['doks']); + $sql .= $this->addBandToQuery($band); + $sql .= $this->addQslToQuery($postdata); + $sql .= ")"; + $query = $this->db->query($sql); + + return $query->result(); + + } + + function getDokConfirmed($location_list, $band, $postdata) { + $sql = "SELECT DISTINCT COL_DARC_DOK FROM " . $this->config->item('table_name') . " thcv + WHERE station_id IN (" . $location_list . ") AND COL_DARC_DOK <> '' AND COL_DARC_DOK <> '' AND COL_DARC_DOK <> 'NM'"; + if ($postdata['mode'] != 'All') { + $sql .= " AND (COL_MODE = '" . $postdata['mode'] . "' or COL_SUBMODE = '" . $postdata['mode'] . "')"; + } + $sql .= $this->addDokTypeToQuery($postdata['doks']); + $sql .= $this->addBandToQuery($band); + $sql .= $this->addQslToQuery($postdata); + $query = $this->db->query($sql); + return $query->result(); + } + + function addQslToQuery($postdata) { + $sql = ''; + $qsl = array(); + if ($postdata['lotw'] != NULL || $postdata['qsl'] != NULL || $postdata['eqsl'] != NULL) { + $sql .= 'and ('; + if ($postdata['qsl'] != NULL) { + array_push($qsl, "col_qsl_rcvd = 'Y'"); + } + if ($postdata['lotw'] != NULL) { + array_push($qsl, "col_lotw_qsl_rcvd = 'Y'"); + } + if ($postdata['eqsl'] != NULL) { + array_push($qsl, "col_eqsl_qsl_rcvd = 'Y'"); + } + $sql .= implode(' or ', $qsl); + $sql .= ')'; + } + return $sql; + } + + 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; + } + + function addDokTypeToQuery($doks) { + $sql = ''; + if ($doks == 'dok') { + $sql .= " AND COL_DARC_DOK REGEXP '^[A-Z][0-9]{2}$'"; + } else if ($doks == 'sdok') { + $sql .= " AND COL_DARC_DOK NOT REGEXP '^[A-Z][0-9]{2}$'"; + } + return $sql; + } + + function get_dok_summary($bands, $postdata, $location_list) { + foreach ($bands as $band) { + $worked = $this->getSummaryByBand($band, $postdata, $location_list); + $confirmed = $this->getSummaryByBandConfirmed($band, $postdata, $location_list); + $dokSummary['worked'][$band] = $worked[0]->count; + $dokSummary['confirmed'][$band] = $confirmed[0]->count; + } + + + $workedTotal = $this->getSummaryByBand($postdata['band'], $postdata, $location_list); + $confirmedTotal = $this->getSummaryByBandConfirmed($postdata['band'], $postdata, $location_list); + + $dokSummary['worked']['Total'] = $workedTotal[0]->count; + $dokSummary['confirmed']['Total'] = $confirmedTotal[0]->count; + + return $dokSummary; + } + + function getSummaryByBand($band, $postdata, $location_list) { + $sql = "SELECT count(distinct thcv.COL_DARC_DOK) AS count FROM " . $this->config->item('table_name') . " thcv"; + $sql .= " WHERE station_id IN (" . $location_list . ') AND COL_DARC_DOK != "" AND COL_DARC_DOK <> "NM"'; + if ($band == 'SAT') { + $sql .= " AND thcv.COL_PROP_MODE ='" . $band . "'"; + } else if ($band == 'All') { + $this->load->model('bands'); + $bandslots = $this->bands->get_worked_bands('dok'); + $bandslots_list = "'".implode("','",$bandslots)."'"; + $sql .= " AND thcv.COL_BAND in (" . $bandslots_list . ")"; + } else { + $sql .= " AND thcv.COL_PROP_MODE !='SAT'"; + $sql .= " AND thcv.COL_BAND ='" . $band . "'"; + } if ($postdata['doks'] == 'dok') { $sql .= " AND COL_DARC_DOK REGEXP '^[A-Z][0-9]{2}$'"; } else if ($postdata['doks'] == 'sdok') { $sql .= " AND COL_DARC_DOK NOT REGEXP '^[A-Z][0-9]{2}$'"; } - $sql .= " group by COL_DARC_DOK, COL_MODE, COL_BAND"; - $sql .= " order by COL_DARC_DOK asc"; - - $data = $this->db->query($sql); - - $results = array(); - $last_dok = ""; - foreach($data->result() as $row){ - if ($last_dok != $row->COL_DARC_DOK){ - // new row - $results[$row->COL_DARC_DOK] = $this->bands->bandslots; - $last_dok = $row->COL_DARC_DOK; - } - - // update stats - if (!isset($results[$row->COL_DARC_DOK])) - $results[$row->COL_DARC_DOK] = []; - - if (!isset($results[$row->COL_DARC_DOK][$row->COL_BAND])) - $results[$row->COL_DARC_DOK][$row->COL_BAND] = 0; - - $results[$row->COL_DARC_DOK][$row->COL_BAND] += $row->cnt; - } - - return $results; + $query = $this->db->query($sql); + return $query->result(); } - /** - * Function: mostactive - * Information: Returns the most active band - **/ - function info($callsign) - { - $exceptions = $this->db->query(' - SELECT * - FROM `dxcc_exceptions` - WHERE `prefix` = \''.$callsign.'\' - LIMIT 1 - '); - - if ($exceptions->num_rows() > 0) - { - return $exceptions; + function getSummaryByBandConfirmed($band, $postdata, $location_list){ + $sql = "SELECT count(distinct thcv.COL_DARC_DOK) AS count FROM " . $this->config->item('table_name') . " thcv"; + $sql .= " WHERE station_id IN (" . $location_list . ') AND COL_DARC_DOK != "" AND COL_DARC_DOK <> "NM"'; + if ($band == 'SAT') { + $sql .= " AND thcv.COL_PROP_MODE ='" . $band . "'"; + } else if ($band == 'All') { + $this->load->model('bands'); + $bandslots = $this->bands->get_worked_bands('dok'); + $bandslots_list = "'".implode("','",$bandslots)."'"; + $sql .= " AND thcv.COL_BAND in (" . $bandslots_list . ")"; } else { - - $query = $this->db->query(' - SELECT * - FROM dxcc_entities - WHERE prefix = SUBSTRING( \''.$callsign.'\', 1, LENGTH( prefix ) ) - ORDER BY LENGTH( prefix ) DESC - LIMIT 1 - '); - - return $query; + $sql .= " AND thcv.COL_PROP_MODE !='SAT'"; + $sql .= " AND thcv.COL_BAND ='" . $band . "'"; } + if ($postdata['doks'] == 'dok') { + $sql .= " AND COL_DARC_DOK REGEXP '^[A-Z][0-9]{2}$'"; + } else if ($postdata['doks'] == 'sdok') { + $sql .= " AND COL_DARC_DOK NOT REGEXP '^[A-Z][0-9]{2}$'"; + } + $sql .= $this->addQslToQuery($postdata); + $query = $this->db->query($sql); + return $query->result(); } - function search(){ - print_r($this->input->get()); - return; - } - - function empty_table($table) { - $this->db->empty_table($table); + function getDoksFromDB($location_list) { + $sql = 'SELECT DISTINCT `COL_DARC_DOK` FROM '.$this->config->item('table_name'); + $sql .= " WHERE station_id IN (" . $location_list . ') AND COL_DARC_DOK != "" AND COL_DARC_DOK <> "NM"'; + $sql .= " AND COL_DARC_DOK REGEXP '^[A-Z][0-9]{2}$'"; + $sql .= " ORDER BY COL_DARC_DOK ASC"; + $query = $this->db->query($sql); + return $query->result(); } - function list() { - $this->db->order_by('name', 'ASC'); - return $this->db->get('dxcc_entities'); + function getSdoksFromDB($location_list) { + $sql = 'SELECT DISTINCT `COL_DARC_DOK` FROM '.$this->config->item('table_name'); + $sql .= " WHERE station_id IN (" . $location_list . ') AND COL_DARC_DOK != "" AND COL_DARC_DOK <> "NM"'; + $sql .= " AND COL_DARC_DOK NOT REGEXP '^[A-Z][0-9]{2}$'"; + $sql .= " ORDER BY COL_DARC_DOK ASC"; + $query = $this->db->query($sql); + return $query->result(); } } ?> diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 64fc6562..fca8dda8 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -257,7 +257,7 @@ class Logbook_model extends CI_Model { /* * Used to fetch QSOs from the logbook in the awards */ - public function qso_details($searchphrase, $band, $mode, $type){ + public function qso_details($searchphrase, $band, $mode, $type, $qsl){ $CI =& get_instance(); $CI->load->model('logbooks_model'); $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); @@ -292,6 +292,9 @@ class Logbook_model extends CI_Model { case 'POTA': $this->db->where('COL_POTA_REF', $searchphrase); break; + case 'DOK': + $this->db->where('COL_DARC_DOK', $searchphrase); + break; } $this->db->where_in($this->config->item('table_name').'.station_id', $logbooks_locations_array); @@ -305,6 +308,21 @@ class Logbook_model extends CI_Model { } } + if (!empty($qsl)) { + $qslfilter = array(); + if (strpos($qsl, "Q") !== false) { + $qslfilter[] = 'COL_QSL_RCVD = "Y"'; + } + if (strpos($qsl, "L") !== false) { + $qslfilter[] = 'COL_LOTW_QSL_RCVD = "Y"'; + } + if (strpos($qsl, "E") !== false) { + $qslfilter[] = 'COL_EQSL_QSL_RCVD = "Y"'; + } + $sql = "(".implode(' OR ', $qslfilter).")"; + $this->db->where($sql); + } + if ($mode != 'All') { $this->db->where("(COL_MODE='" . $mode . "' OR COL_SUBMODE='" . $mode ."')"); } diff --git a/application/views/awards/dok/index.php b/application/views/awards/dok/index.php index aed9a0aa..a4fe94d3 100644 --- a/application/views/awards/dok/index.php +++ b/application/views/awards/dok/index.php @@ -1,11 +1,40 @@ +
-

-
-
+

+ +
+
- +
+ +
+
Worked / Confirmed
+
+
+ input->post('worked') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> > + +
+
+ input->post('confirmed') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> > + +
+
+
+ +
+
QSL / LoTW
+
+
+ input->post('qsl') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> > + +
+
+ input->post('lotw') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> > + +
+
+ input->post('eqsl')) echo ' checked="checked"'; ?> > + +
+
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + $value) { + if (preg_match('/^[A-Z][0-9]{2}$/', $dok)) { + $doks[] = $dok; + } + } +?> +
- - + + +
- - - - +
+ +
+
+
+ +
+ +
+ + +
- - $slot\n"; - } - ?> - - - - $val){ - print(""); - foreach($val as $band=>$count){ - if (in_array($band, $worked_bands)) { - if ($count == 0){ - print(""); - }else{ - printf("", str_replace("&", "%26", $dok), $band, $count); - } - } + '; + foreach($bands as $band) { + echo ''; } - print(""); + echo ' + + '; + foreach ($dok_array as $dok => $value) { // Fills the table with the data + echo ' + '; + foreach ($value as $key) { + echo ''; + } + echo ''; + } + echo '
DOKs ()
$dok %dDOK' . $band . '
'. $dok .'' . $key . '
+

Summary

+ + + + '; + + foreach($bands as $band) { + echo ''; + } + echo ' + + + + '; + + foreach ($dok_summary['worked'] as $dxcc) { // Fills the table with the data + echo ''; } - ?> - + echo ' + '; + foreach ($dok_summary['confirmed'] as $dxcc) { // Fills the table with the data + echo ''; + } -
' . $band . 'Total
Total worked' . $dxcc . '
Total confirmed' . $dxcc . '
- + +
'; + + } + else { echo ''; - } ?> + } + ?> + + + diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index df4031da..cd96e0e6 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2568,7 +2568,7 @@ function deleteQsl(id) { /* * Used to fetch QSOs from the logbook in the awards */ - function displayContacts(searchphrase, band, mode, type) { + function displayContacts(searchphrase, band, mode, type, qsl) { var baseURL = ""; $.ajax({ url: baseURL + 'index.php/awards/qso_details_ajax', @@ -2577,7 +2577,8 @@ function deleteQsl(id) { 'Searchphrase': searchphrase, 'Band': band, 'Mode': mode, - 'Type': type + 'Type': type, + 'QSL' : qsl }, success: function (html) { BootstrapDialog.show({ @@ -3214,6 +3215,38 @@ function deleteQsl(id) { $('[class*="buttons"]').css("color", "white"); } + uri->segment(2) == "dok") { ?> +