diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index 8c4b086d0..5456ec127 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -1235,6 +1235,123 @@ class Awards extends CI_Controller { } } + header('Content-Type: application/json'); + echo json_encode($states); + } + + public function wap() { + $footerData = []; + $footerData['scripts'] = [ + 'assets/js/sections/wapmap_geojson.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/wapmap_geojson.js")), + 'assets/js/sections/wapmap.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/wapmap.js")), + 'assets/js/leaflet/L.Maidenhead.js', + ]; + + $this->load->model('wap'); + $this->load->model('modes'); + $this->load->model('bands'); + + $data['worked_bands'] = $this->bands->get_worked_bands('wap'); + $data['modes'] = $this->modes->active(); // Used in the view for mode select + + 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->security->xss_clean($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['qsl'] = $this->security->xss_clean($this->input->post('qsl')); + $postdata['lotw'] = $this->security->xss_clean($this->input->post('lotw')); + $postdata['eqsl'] = $this->security->xss_clean($this->input->post('eqsl')); + $postdata['qrz'] = $this->security->xss_clean($this->input->post('qrz')); + $postdata['worked'] = $this->security->xss_clean($this->input->post('worked')); + $postdata['confirmed'] = $this->security->xss_clean($this->input->post('confirmed')); + $postdata['notworked'] = $this->security->xss_clean($this->input->post('notworked')); + $postdata['band'] = $this->security->xss_clean($this->input->post('band')); + $postdata['mode'] = $this->security->xss_clean($this->input->post('mode')); + } + else { // Setting default values at first load of page + $postdata['qsl'] = 1; + $postdata['lotw'] = 1; + $postdata['eqsl'] = 0; + $postdata['qrz'] = 0; + $postdata['worked'] = 1; + $postdata['confirmed'] = 1; + $postdata['notworked'] = 1; + $postdata['band'] = 'All'; + $postdata['mode'] = 'All'; + } + + $data['wap_array'] = $this->wap->get_wap_array($bands, $postdata); + $data['wap_summary'] = $this->wap->get_wap_summary($bands, $postdata); + + // Render Page + $data['page_title'] = sprintf(__("Awards - %s"), __("WAP")); + $this->load->view('interface_assets/header', $data); + $this->load->view('awards/wap/index'); + $this->load->view('interface_assets/footer', $footerData); + } + + /* + function WAP_map + + This displays the WAP Worked All The Netherlands Provinces map and requires the $band_type and $mode_type + */ + public function wap_map() { + $stateString = 'DR,FL,FR,GD,GR,LB,NB,NH,OV,UT,ZH,ZL'; + $wapArray = explode(',', $stateString); + + $this->load->model('wap'); + + $bands[] = $this->security->xss_clean($this->input->post('band')); + + $postdata['qsl'] = $this->input->post('qsl') == 0 ? NULL: 1; + $postdata['lotw'] = $this->input->post('lotw') == 0 ? NULL: 1; + $postdata['eqsl'] = $this->input->post('eqsl') == 0 ? NULL: 1; + $postdata['qrz'] = $this->input->post('qrz') == 0 ? NULL: 1; + $postdata['worked'] = $this->input->post('worked') == 0 ? NULL: 1; + $postdata['confirmed'] = $this->input->post('confirmed') == 0 ? NULL: 1; + $postdata['notworked'] = $this->input->post('notworked') == 0 ? NULL: 1; + $postdata['band'] = $this->security->xss_clean($this->input->post('band')); + $postdata['mode'] = $this->security->xss_clean($this->input->post('mode')); + + $wap_array = $this->wap->get_wap_array($bands, $postdata); + + $states = array(); + + foreach ($wapArray as $state) { // Generating array for use in the table + $states[$state] = '-'; // Inits each state's count + } + + + foreach ($wap_array as $was => $value) { + foreach ($value as $key) { + if($key != "") { + if (strpos($key, '>W<') !== false) { + $states[$was] = 'W'; + break; + } + if (strpos($key, '>C<') !== false) { + $states[$was] = 'C'; + break; + } + if (strpos($key, '-') !== false) { + $states[$was] = '-'; + break; + } + } + } + } + header('Content-Type: application/json'); echo json_encode($states); } diff --git a/application/controllers/Band.php b/application/controllers/Band.php index e37055e4f..af7419877 100644 --- a/application/controllers/Band.php +++ b/application/controllers/Band.php @@ -135,6 +135,7 @@ class Band extends CI_Controller { $band['sig'] = $this->security->xss_clean($this->input->post('sig')); $band['sota'] = $this->security->xss_clean($this->input->post('sota')); $band['uscounties'] = $this->security->xss_clean($this->input->post('uscounties')); + $band['wap'] = $this->security->xss_clean($this->input->post('wap')); $band['was'] = $this->security->xss_clean($this->input->post('was')); $band['wwff'] = $this->security->xss_clean($this->input->post('wwff')); $band['vucc'] = $this->security->xss_clean($this->input->post('vucc')); diff --git a/application/migrations/245_add_wap_bandxuser.php b/application/migrations/245_add_wap_bandxuser.php new file mode 100644 index 000000000..08ba62e2b --- /dev/null +++ b/application/migrations/245_add_wap_bandxuser.php @@ -0,0 +1,23 @@ +db->field_exists('wap', 'bandxuser')) { + $this->dbforge->add_column('bandxuser', $fields); + } + } + + public function down() + { + if ($this->db->field_exists('wap', 'bandxuser')) { + $this->dbforge->drop_column('bandxuser', 'wap'); + } + } +} diff --git a/application/models/Bands.php b/application/models/Bands.php index b437ee1e5..cead11235 100644 --- a/application/models/Bands.php +++ b/application/models/Bands.php @@ -279,6 +279,7 @@ class Bands extends CI_Model { 'sig' => $band['sig'] == "true" ? '1' : '0', 'sota' => $band['sota'] == "true" ? '1' : '0', 'uscounties' => $band['uscounties'] == "true" ? '1' : '0', + 'wap' => $band['wap'] == "true" ? '1' : '0', 'waja' => $band['waja'] == "true" ? '1' : '0', 'was' => $band['was'] == "true" ? '1' : '0', 'wwff' => $band['wwff'] == "true" ? '1' : '0', @@ -306,7 +307,7 @@ class Bands extends CI_Model { } function add($band_data) { - + $this->db->where('band', $band_data['band']); $result = $this->db->get('bands'); @@ -315,10 +316,10 @@ class Bands extends CI_Model { } $binding = []; - $sql = "insert into bandxuser (bandid, userid) select bands.id, " - . $this->session->userdata('user_id') - . " from bands where band = ? - and not exists (select 1 from bandxuser where userid = " . $this->session->userdata('user_id') . " + $sql = "insert into bandxuser (bandid, userid) select bands.id, " + . $this->session->userdata('user_id') + . " from bands where band = ? + and not exists (select 1 from bandxuser where userid = " . $this->session->userdata('user_id') . " and bandid = bands.id);"; $binding[] = $band_data['band']; diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 08be3f853..821aa0bba 100644 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -582,6 +582,10 @@ class Logbook_model extends CI_Model { $this->db->where('COL_STATE', $searchphrase); $this->db->where_in('COL_DXCC', ['291', '6', '110']); break; + case 'WAP': + $this->db->where('COL_STATE', $searchphrase); + $this->db->where_in('COL_DXCC', ['263']); + break; case 'RAC': $this->db->where('COL_STATE', $searchphrase); $this->db->where_in('COL_DXCC', ['1']); @@ -1463,8 +1467,8 @@ class Logbook_model extends CI_Model { } else { $retvals['detail']=__("DXCC has to be Numeric"); return $retvals; - } - + } + $data = array( 'COL_TIME_ON' => $time_on, 'COL_TIME_OFF' => $time_off, diff --git a/application/models/Wap.php b/application/models/Wap.php new file mode 100644 index 000000000..4ffe29c23 --- /dev/null +++ b/application/models/Wap.php @@ -0,0 +1,268 @@ +load->library('Genfunctions'); + } + + public $stateString = 'DR,FL,FR,GD,GR,LB,NB,NH,OV,UT,ZH,ZL'; + + + function get_wap_array($bands, $postdata) { + $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)."'"; + + $stateArray = explode(',', $this->stateString); + + $states = array(); // Used for keeping track of which states that are not worked + + $qsl = $this->genfunctions->gen_qsl_from_postdata($postdata); + + foreach ($stateArray as $state) { // Generating array for use in the table + $states[$state]['count'] = 0; // Inits each state's count + } + + + foreach ($bands as $band) { + foreach ($stateArray as $state) { // Generating array for use in the table + $bandwap[$state][$band] = '-'; // Sets all to dash to indicate no result + } + + if ($postdata['worked'] != NULL) { + $wapBand = $this->getwapWorked($location_list, $band, $postdata); + foreach ($wapBand as $line) { + $bandwap[$line->col_state][$band] = '
'; + $states[$line->col_state]['count']++; + } + } + if ($postdata['confirmed'] != NULL) { + $wapBand = $this->getwapConfirmed($location_list, $band, $postdata); + foreach ($wapBand as $line) { + $bandwap[$line->col_state][$band] = ''; + $states[$line->col_state]['count']++; + } + } + } + + // We want to remove the worked states in the list, since we do not want to display them + if ($postdata['worked'] == NULL) { + $wapBand = $this->getwapWorked($location_list, $postdata['band'], $postdata); + foreach ($wapBand as $line) { + unset($bandwap[$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) { + $wapBand = $this->getwapConfirmed($location_list, $postdata['band'], $postdata); + foreach ($wapBand as $line) { + unset($bandwap[$line->col_state]); + } + } + + if ($postdata['notworked'] == NULL) { + foreach ($stateArray as $state) { + if ($states[$state]['count'] == 0) { + unset($bandwap[$state]); + }; + } + } + + if (isset($bandwap)) { + return $bandwap; + } + else { + return 0; + } + } + + /* + * Function gets worked and confirmed summary on each band on the active stationprofile + */ + function get_wap_summary($bands, $postdata) { + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + if (!$logbooks_locations_array) { + return null; + } + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + foreach ($bands as $band) { + $worked = $this->getSummaryByBand($band, $postdata, $location_list); + $confirmed = $this->getSummaryByBandConfirmed($band, $postdata, $location_list); + $wapSummary['worked'][$band] = $worked[0]->count; + $wapSummary['confirmed'][$band] = $confirmed[0]->count; + } + + $workedTotal = $this->getSummaryByBand($postdata['band'], $postdata, $location_list); + $confirmedTotal = $this->getSummaryByBandConfirmed($postdata['band'], $postdata, $location_list); + + $wapSummary['worked']['Total'] = $workedTotal[0]->count; + $wapSummary['confirmed']['Total'] = $confirmedTotal[0]->count; + + return $wapSummary; + } + + function getSummaryByBand($band, $postdata, $location_list) { + $bindings=[]; + $sql = "SELECT count(distinct thcv.col_state) as count FROM " . $this->config->item('table_name') . " thcv"; + + $sql .= " where station_id in (" . $location_list . ")"; + + if ($band == 'SAT') { + $sql .= " and thcv.col_prop_mode = ?"; + $bindings[]=$band; + } else if ($band == 'All') { + $this->load->model('bands'); + + $bandslots = $this->bands->get_worked_bands('wap'); + + $bandslots_list = "'".implode("','",$bandslots)."'"; + + $sql .= " and thcv.col_band in (" . $bandslots_list . ")" . + " and thcv.col_prop_mode !='SAT'"; + } else { + $sql .= " and thcv.col_prop_mode !='SAT'"; + $sql .= " and thcv.col_band = ?"; + $bindings[]=$band; + } + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = ? or col_submode = ?)"; + $bindings[]=$postdata['mode']; + $bindings[]=$postdata['mode']; + } + + $sql .= $this->addStateToQuery(); + + $query = $this->db->query($sql,$bindings); + + return $query->result(); + } + + function getSummaryByBandConfirmed($band, $postdata, $location_list) { + $bindings=[]; + $sql = "SELECT count(distinct thcv.col_state) as count FROM " . $this->config->item('table_name') . " thcv"; + + $sql .= " where station_id in (" . $location_list . ")"; + + if ($band == 'SAT') { + $sql .= " and thcv.col_prop_mode = ?"; + $bindings[]=$band; + } else if ($band == 'All') { + $this->load->model('bands'); + + $bandslots = $this->bands->get_worked_bands('wap'); + + $bandslots_list = "'".implode("','",$bandslots)."'"; + + $sql .= " and thcv.col_band in (" . $bandslots_list . ")" . + " and thcv.col_prop_mode !='SAT'"; + } else { + $sql .= " and thcv.col_prop_mode !='SAT'"; + $sql .= " and thcv.col_band = ?"; + $bindings[]=$band; + } + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = ? or col_submode = ?)"; + $bindings[]=$postdata['mode']; + $bindings[]=$postdata['mode']; + } + + $sql .= $this->genfunctions->addQslToQuery($postdata); + + $sql .= $this->addStateToQuery(); + + $query = $this->db->query($sql,$bindings); + + return $query->result(); + } + + /* + * Function returns all worked, but not confirmed states + * $postdata contains data from the form, in this case Lotw or QSL are used + */ + function getwapWorked($location_list, $band, $postdata) { + $bindings=[]; + $sql = "SELECT distinct col_state FROM " . $this->config->item('table_name') . " thcv + where station_id in (" . $location_list . ")"; + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = ? or col_submode = ?)"; + $bindings[]=$postdata['mode']; + $bindings[]=$postdata['mode']; + } + + $sql .= $this->addStateToQuery(); + + $sql .= $this->genfunctions->addBandToQuery($band,$bindings); + + $sql .= " and not exists (select 1 from ". $this->config->item('table_name') . + " where station_id in (". $location_list . ")" . + " and col_state = thcv.col_state"; + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = ? or col_submode = ?)"; + $bindings[]=$postdata['mode']; + $bindings[]=$postdata['mode']; + } + + $sql .= $this->genfunctions->addBandToQuery($band,$bindings); + + $sql .= $this->genfunctions->addQslToQuery($postdata); + + $sql .= $this->addStateToQuery(); + + $sql .= ")"; + + $query = $this->db->query($sql,$bindings); + + 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 getwapConfirmed($location_list, $band, $postdata) { + $bindings=[]; + $sql = "SELECT distinct col_state FROM " . $this->config->item('table_name') . " thcv + where station_id in (" . $location_list . ")"; + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = ? or col_submode = ?)"; + $bindings[]=$postdata['mode']; + $bindings[]=$postdata['mode']; + } + + $sql .= $this->addStateToQuery(); + + $sql .= $this->genfunctions->addBandToQuery($band,$bindings); + + $sql .= $this->genfunctions->addQslToQuery($postdata); + + $query = $this->db->query($sql,$bindings); + + return $query->result(); + } + + function addStateToQuery() { + $sql = ''; + $sql .= " and COL_DXCC = 263"; + $sql .= " and COL_STATE in ('DR','FL','FR','GD','GR','LB','NB','NH','OV','UT','ZH','ZL')"; + + return $sql; + } +} +?> diff --git a/application/views/awards/wap/index.php b/application/views/awards/wap/index.php new file mode 100644 index 000000000..ece805a2b --- /dev/null +++ b/application/views/awards/wap/index.php @@ -0,0 +1,205 @@ + + + + +| '; + + foreach($bands as $band) { + echo ' | ' . $band . ' | '; + } + echo '' . __("Total") . ' |
| ' . __("Total worked") . ' | '; + + foreach ($wap_summary['worked'] as $wap) { // Fills the table with the data + echo '' . $wap . ' | '; + } + + echo '|
| ' . __("Total confirmed") . ' | '; + foreach ($wap_summary['confirmed'] as $wap) { // Fills the table with the data + echo '' . $wap . ' | '; + } + + echo '