From 2cfd8efdf2c4b9c86ba70480d34239771c96d01e Mon Sep 17 00:00:00 2001 From: AndreasK79 Date: Mon, 30 Mar 2020 21:03:38 +0200 Subject: [PATCH] Enhanced the CQ award with a table and form. --- application/controllers/Awards.php | 38 ++++- application/models/Cq.php | 192 +++++++++++++++++++++- application/models/Logbook_model.php | 9 +- application/views/awards/cq/index.php | 222 +++++++++++++++++++------- 4 files changed, 403 insertions(+), 58 deletions(-) diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index 9c22960b..d1e4d9cf 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -253,6 +253,41 @@ class Awards extends CI_Controller { } $data['cqz'] = $zones; + $data['worked_bands'] = $this->cq->get_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->input->post('band'); + } + } + else { + $bands = $data['worked_bands']; + } + + $data['bands'] = $bands; // Used for displaying selected band(s) in the table in the view + + if($this->input->method() === 'post') { + $postdata['lotw'] = $this->input->post('lotw'); + $postdata['qsl'] = $this->input->post('qsl'); + $postdata['worked'] = $this->input->post('worked'); + $postdata['confirmed'] = $this->input->post('confirmed'); + $postdata['notworked'] = $this->input->post('notworked'); + $postdata['band'] = $this->input->post('band'); + } + else { // Setting default values at first load of page + $postdata['lotw'] = 1; + $postdata['qsl'] = 1; + $postdata['worked'] = 1; + $postdata['confirmed'] = 1; + $postdata['notworked'] = 1; + $postdata['band'] = 'All'; + } + + $data['cq_array'] = $this->cq->get_cq_array($bands, $postdata); + // Render page $data['page_title'] = "Awards - CQ Magazine"; $this->load->view('interface_assets/header', $data); @@ -264,7 +299,8 @@ class Awards extends CI_Controller { $this->load->model('logbook_model'); $cqzone = str_replace('"', "", $this->input->get("CQZone")); - $data['results'] = $this->logbook_model->cq_qso_details($cqzone); + $band = str_replace('"', "", $this->input->get("Band")); + $data['results'] = $this->logbook_model->cq_qso_details($cqzone, $band); // Render Page $data['page_title'] = "Log View - DXCC"; diff --git a/application/models/Cq.php b/application/models/Cq.php index a47a9907..1485d8cb 100644 --- a/application/models/Cq.php +++ b/application/models/Cq.php @@ -7,7 +7,6 @@ class CQ extends CI_Model{ parent::__construct(); } - function get_zones(){ $CI =& get_instance(); $CI->load->model('Stations'); @@ -22,4 +21,195 @@ class CQ extends CI_Model{ return $data->result(); } + + public $bandslots = array("160m" => 0, + "80m" => 0, + "60m" => 0, + "40m" => 0, + "30m" => 0, + "20m" => 0, + "17m" => 0, + "15m" => 0, + "12m" => 0, + "10m" => 0, + "6m" => 0, + "4m" => 0, + "2m" => 0, + "70cm" => 0, + "23cm" => 0, + "13cm" => 0, + "9cm" => 0, + "6cm" => 0, + "3cm" => 0, + "1.25cm" => 0, + "SAT" => 0, + ); + + function get_worked_bands() + { + $CI =& get_instance(); + $CI->load->model('Stations'); + $station_id = $CI->Stations->find_active(); + + // get all worked slots from database + $data = $this->db->query( + "SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `" . $this->config->item('table_name') . "` WHERE station_id = " . $station_id . " AND COL_PROP_MODE != \"SAT\"" + ); + $worked_slots = array(); + foreach ($data->result() as $row) { + array_push($worked_slots, $row->COL_BAND); + } + + $SAT_data = $this->db->query( + "SELECT distinct LOWER(`COL_PROP_MODE`) as `COL_PROP_MODE` FROM `" . $this->config->item('table_name') . "` WHERE station_id = " . $station_id . " AND COL_PROP_MODE = \"SAT\"" + ); + + foreach ($SAT_data->result() as $row) { + array_push($worked_slots, strtoupper($row->COL_PROP_MODE)); + } + + // bring worked-slots in order of defined $bandslots + $results = array(); + foreach (array_keys($this->bandslots) as $slot) { + if (in_array($slot, $worked_slots)) { + array_push($results, $slot); + } + } + return $results; + } + + function get_cq_array($bands, $postdata) { + $CI =& get_instance(); + $CI->load->model('Stations'); + $station_id = $CI->Stations->find_active(); + + $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 + } + + foreach ($bands as $band) { + for ($i = 1; $i <= 40; $i++) { + $bandCq[$i][$band] = '-'; // Sets all to dash to indicate no result + } + + if ($postdata['worked'] != NULL) { + $cqBand = $this->getCQWorked($station_id, $band, $postdata); + foreach ($cqBand as $line) { + $bandCq[$line->col_cqz][$band] = '
col_cqz) . '"&Band="' . $band . '"\'>W
'; + $cqZ[$line->col_cqz]['count']++; + } + } + if ($postdata['confirmed'] != NULL) { + $cqBand = $this->getCQConfirmed($station_id, $band, $postdata); + foreach ($cqBand as $line) { + $bandCq[$line->col_cqz][$band] = '
col_cqz) . '"&Band="' . $band . '"\'>C
'; + $cqZ[$line->col_cqz]['count']++; + } + } + } + + // We want to remove the worked zones in the list, since we do not want to display them + if ($postdata['worked'] == NULL) { + $cqBand = $this->getCQWorked($station_id, $postdata['band'], $postdata); + foreach ($cqBand as $line) { + unset($bandCq[$line->col_cqz]); + } + } + + // We want to remove the confirmed zones in the list, since we do not want to display them + if ($postdata['confirmed'] == NULL) { + $cqBand = $this->getCQConfirmed($station_id, $postdata['band'], $postdata); + foreach ($cqBand as $line) { + unset($bandCq[$line->col_cqz]); + } + } + + if ($postdata['notworked'] == NULL) { + for ($i = 1; $i <= 40; $i++) { + if ($cqZ[$i]['count'] == 0) { + unset($bandCq[$i]); + }; + } + } + + if (isset($bandCq)) { + return $bandCq; + } else { + return 0; + } + } + + /* + * Function returns all worked, but not confirmed states + * $postdata contains data from the form, in this case Lotw or QSL are used + */ + function getCQWorked($station_id, $band, $postdata) { + $sql = "SELECT distinct col_cqz FROM " . $this->config->item('table_name') . " thcv + where station_id = " . $station_id . " and col_cqz <> ''"; + + $sql .= $this->addBandToQuery($band); + + $sql .= " and not exists (select 1 from " . $this->config->item('table_name') . + " where station_id = " . $station_id . + " and col_cqz = thcv.col_cqz and col_cqz <> '' "; + + $sql .= $this->addBandToQuery($band); + + $sql .= $this->addQslToQuery($postdata); + + $sql .= ")"; + + $query = $this->db->query($sql); + + return $query->result(); + } + + /* + * Function returns all confirmed states on given band and on LoTW or QSL + * $postdata contains data from the form, in this case Lotw or QSL are used + */ + function getCQConfirmed($station_id, $band, $postdata) { + $sql = "SELECT distinct col_cqz FROM " . $this->config->item('table_name') . " thcv + where station_id = " . $station_id . " and col_cqz <> ''"; + + $sql .= $this->addBandToQuery($band); + + $sql .= $this->addQslToQuery($postdata); + + $query = $this->db->query($sql); + + return $query->result(); + } + + function addQslToQuery($postdata) { + $sql = ''; + if ($postdata['lotw'] != NULL and $postdata['qsl'] == NULL) { + $sql .= " and col_lotw_qsl_rcvd = 'Y'"; + } + + if ($postdata['qsl'] != NULL and $postdata['lotw'] == NULL) { + $sql .= " and col_qsl_rcvd = 'Y'"; + } + + if ($postdata['qsl'] != NULL && $postdata['lotw'] != NULL) { + $sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')"; + } + 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; + } + } diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 9161fa43..ebbf3a1f 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -238,11 +238,18 @@ class Logbook_model extends CI_Model { return $this->db->query($sql); } - public function cq_qso_details($cqzone){ + public function cq_qso_details($cqzone, $band){ $CI =& get_instance(); $CI->load->model('Stations'); $station_id = $CI->Stations->find_active(); + if ($band == 'SAT') { + $this->db->where('col_prop_mode', $band); + } else if ($band != '') { + $this->db->where('col_prop_mode !=', 'SAT'); + $this->db->where('col_band', $band); + } + $this->db->where('station_id', $station_id); $this->db->where('COL_CQZ', $cqzone); diff --git a/application/views/awards/cq/index.php b/application/views/awards/cq/index.php index 30794999..0597191d 100644 --- a/application/views/awards/cq/index.php +++ b/application/views/awards/cq/index.php @@ -5,60 +5,172 @@ load->view("awards/nav_bar")?>

CQ Zones worked:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" usemap="#CQ" border="0"> - Maps from JF9EXF site. -

Notes:

- + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + " usemap="#CQ" border="0"> + + Maps from JF9EXF site. +

Notes:

+
    +
  • All US callsigns are allocated zone 5 by the FCC. This may not be correct
  • +
+ +
+ +
+
+
+
+ + +
+
Worked / confirmed
+
+
+ input->post('worked') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> > + +
+
+ input->post('confirmed') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> > + +
+
+ input->post('notworked') || $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"'; ?> > + +
+
+
+ + +
+ +
+ +
+
+ + +
+ +
+ + +
+
+ +
+
+ + + + CQ Zone'; + foreach($bands as $band) { + echo '' . $band . ''; + } + echo ' + + '; + foreach ($cq_array as $cq => $value) { // Fills the table with the data + echo ' + '. $cq .''; + foreach ($value as $key) { + echo '' . $key . ''; + } + echo ''; + } + echo '
'; + + } + else { + echo ''; + } + ?> + +
+