diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index c02e8514..9c22960b 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -276,9 +276,41 @@ class Awards extends CI_Controller { public function was() { $this->load->model('was'); - $data['was'] = $this->was->show_stats(); $data['worked_bands'] = $this->was->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['was_array'] = $this->was->get_was_array($bands, $postdata); + // Render Page $data['page_title'] = "Awards - WAS (Worked all states)"; $this->load->view('interface_assets/header', $data); diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index a7be96ad..80f4f5ec 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -259,6 +259,7 @@ class Logbook_model extends CI_Model { $this->db->where('COL_STATE', $state); $this->db->where_in('COL_DXCC', ['291', '6', '110']); if($band != "SAT") { + $this->db->where('COL_BAND !=', 'SAT'); $this->db->where('COL_BAND', $band); } else { $this->db->where('COL_PROP_MODE', "SAT"); diff --git a/application/models/Was.php b/application/models/Was.php index 9a8300ad..932c3abf 100644 --- a/application/models/Was.php +++ b/application/models/Was.php @@ -2,6 +2,8 @@ class was extends CI_Model { + public $stateString = 'AK,AL,AR,AZ,CA,CO,CT,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY'; + public $bandslots = array("160m"=>0, "80m"=>0, "60m"=>0, @@ -36,22 +38,17 @@ class was extends CI_Model { $CI->load->model('Stations'); $station_id = $CI->Stations->find_active(); - // get all bands where we have worked states, need to filter on correct dxcc and state (as Cloudlog aren't always setting correct dxcc on import) + // 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 COL_DXCC in ('291', '6', '110') - and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY') - and station_id = ".$station_id." AND COL_PROP_MODE != \"SAT\"" + "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 COL_DXCC in ('291', '6', '110') - and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY') - and station_id = ".$station_id." AND COL_PROP_MODE = \"SAT\"" + "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){ @@ -65,71 +62,154 @@ class was extends CI_Model { array_push($results, $slot); } } - return $results; } - function show_stats(){ + function get_was_array($bands, $postdata) { $CI =& get_instance(); $CI->load->model('Stations'); $station_id = $CI->Stations->find_active(); - $data = $this->db->query( - "select COL_STATE, COL_MODE, lcase(COL_BAND) as COL_BAND, count(COL_STATE) as cnt - from ".$this->config->item('table_name')." - where station_id = ".$station_id." AND COL_PROP_MODE != \"SAT\" - and COL_DXCC in ('291', '6', '110') - and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY') - group by COL_STATE, COL_MODE, COL_BAND" - ); + $stateArray = explode(',', $this->stateString); - $results = array(); - $last_state = ""; - foreach($data->result() as $row){ - if ($last_state != $row->COL_STATE){ - // new row - $results[$row->COL_STATE] = $this->bandslots; - $last_state = $row->COL_STATE; + $states = array(); // Used for keeping track of which states that are not worked + + foreach ($bands as $band) { + foreach ($stateArray as $state) { // Generating array for use in the table + $bandWas[$state][$band] = '-'; // Sets all to dash to indicate no result + $states[$state]['count'] = 0; // Inits each state's count } - // update stats - if (!isset($results[$row->COL_STATE])) - $results[$row->COL_STATE] = []; - - if (!isset($results[$row->COL_STATE][$row->COL_BAND])) - $results[$row->COL_STATE][$row->COL_BAND] = 0; - - $results[$row->COL_STATE][$row->COL_BAND] += $row->cnt; - } - - // Satellite WAS - $satellite_data = $this->db->query( - "select COL_STATE, COL_PROP_MODE as COL_PROP_MODE, count(COL_STATE) as cnt - from ".$this->config->item('table_name')." - where station_id = ".$station_id." AND COL_PROP_MODE = \"SAT\" - and COL_DXCC in ('291', '6', '110') - and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY') - group by COL_STATE" - ); - - foreach($satellite_data->result() as $row){ - if ($last_state != $row->COL_STATE){ - // new row - $results[$row->COL_STATE] = $this->bandslots; - $last_state = $row->COL_STATE; + if ($postdata['worked'] != NULL) { + $wasBand = $this->getWasWorked($station_id, $band, $postdata); + foreach ($wasBand as $line) { + $bandWas[$line->col_state][$band] = '
col_state) . '"&Band="' . $band . '"\'>W
'; + $states[$line->col_state]['count']++; + } + } + if ($postdata['confirmed'] != NULL) { + $wasBand = $this->getWasConfirmed($station_id, $band, $postdata); + foreach ($wasBand as $line) { + $bandWas[$line->col_state][$band] = '
col_state) . '"&Band="' . $band . '"\'>C
'; + $states[$line->col_state]['count']++; + } } - - // update stats - if (!isset($results[$row->COL_STATE])) - $results[$row->COL_STATE] = []; - - if (!isset($results[$row->COL_STATE][$row->COL_PROP_MODE])) - $results[$row->COL_STATE][$row->COL_PROP_MODE] = 0; - - $results[$row->COL_STATE][$row->COL_PROP_MODE] += $row->cnt; } - return $results; + // We want to remove the worked states in the list, since we do not want to display them + if ($postdata['worked'] == NULL) { + $wasBand = $this->getWasWorked($station_id, $postdata['band'], $postdata); + foreach ($wasBand as $line) { + unset($bandWas[$line->col_state]); + } + } + + // We want to remove the confirmed states in the list, since we do not want to display them + if ($postdata['confirmed'] == NULL) { + $wasBand = $this->getWasConfirmed($station_id, $postdata['band'], $postdata); + foreach ($wasBand as $line) { + unset($bandWas[$line->col_state]); + } + } + + if ($postdata['notworked'] == NULL) { + foreach ($stateArray as $state) { + if ($states[$state]['count'] == 0) { + unset($bandWas[$state]); + }; + } + } + + if (isset($bandWas)) { + return $bandWas; + } + 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 getWasWorked($station_id, $band, $postdata) { + $sql = "SELECT distinct col_state FROM " . $this->config->item('table_name') . " thcv + where station_id = " . $station_id; + + $sql .= $this->addStateToQuery(); + + $sql .= $this->addBandToQuery($band); + + $sql .= " and not exists (select 1 from ". $this->config->item('table_name') . + " where station_id = ". $station_id . + " and col_state = thcv.col_state"; + + $sql .= $this->addBandToQuery($band); + + $sql .= $this->addQslToQuery($postdata); + + $sql .= $this->addStateToQuery(); + + $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 getWasConfirmed($station_id, $band, $postdata) { + $sql = "SELECT distinct col_state FROM " . $this->config->item('table_name') . " thcv + where station_id = " . $station_id; + + $sql .= $this->addStateToQuery(); + + $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; + } + + function addStateToQuery() { + $sql = ''; + $sql .= " and COL_DXCC in ('291', '6', '110')"; + $sql .= " and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')"; + return $sql; } } ?> \ No newline at end of file diff --git a/application/views/awards/was/index.php b/application/views/awards/was/index.php index 0d3d489b..bcd79896 100644 --- a/application/views/awards/was/index.php +++ b/application/views/awards/was/index.php @@ -5,36 +5,92 @@ load->view("awards/nav_bar")?> +
+
- + +
+
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"'; ?> > + +
+
+
+ + +
+ +
+ +
+
+ + +
+ +
+ + +
+
+ + + + - - $slot\n"; + '; + foreach($bands as $band) { + echo ''; } - ?> - + echo ' - - $val){ - print(""); - foreach($val as $band=>$count){ - if (in_array($band, $worked_bands)) { - if ($count == 0){ - print(""); - }else{ - printf("", str_replace("&", "%26", $state), $band, $count); - } - } + '; + foreach ($was_array as $was => $value) { // Fills the table with the data + echo ' + '; + foreach ($value as $key) { + echo ''; } - print(""); + echo ''; } + echo '
WAS ()State' . $band . '
$state %d
'. $was .'' . $key . '
'; - ?> - - - - + } + else { + echo ''; + } \ No newline at end of file