diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index cd405b62..5a829f50 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -557,6 +557,108 @@ class Awards extends CI_Controller { $this->load->view('interface_assets/footer',$footerData); } + public function ffma() { + $data['page_title']= lang('menu_ffma'); + + $this->load->model('bands'); + $this->load->model('ffma_model'); + $this->load->model('stations'); + + $data['homegrid']= explode(',', $this->stations->find_gridsquare()); + + $data['layer']= $this->optionslib->get_option('option_map_tile_server'); + + $data['attribution']= $this->optionslib->get_option('option_map_tile_server_copyright'); + + $data['gridsquares_gridsquares']= lang('gridsquares_gridsquares'); + $data['gridsquares_gridsquares_worked']= lang('gridsquares_gridsquares_worked'); + $data['gridsquares_gridsquares_lotw']= lang('gridsquares_gridsquares_lotw'); + $data['gridsquares_gridsquares_paper']= lang('gridsquares_gridsquares_paper'); + + $footerData = []; + $footerData['scripts']= [ + 'assets/js/leaflet/geocoding.js', + 'assets/js/leaflet/L.MaidenheadColouredGridmasterMap.js', + 'assets/js/sections/ffma.js?' + ]; + + $this->load->view('interface_assets/header',$data); + $this->load->view('awards/ffma/index'); + $this->load->view('interface_assets/footer',$footerData); + } + + public function getFfmaGridsjs() { + $this->load->model('ffma_model'); + + $array_grid_4char = array(); + $array_grid_4char_lotw = array(); + $array_grid_4char_paper = array(); + + $grid_4char = ""; + $grid_4char_lotw = ""; + + $query = $this->ffma_model->get_lotw(); + if ($query && $query->num_rows() > 0) { + foreach ($query->result() as $row) { + $grid_4char_lotw = strtoupper(substr($row->GRID_SQUARES,0,4)); + if(!in_array($grid_4char_lotw, $array_grid_4char_lotw)){ + array_push($array_grid_4char_lotw, $grid_4char_lotw); + } + } + } + + $query = $this->ffma_model->get_paper(); + if ($query && $query->num_rows() > 0) { + foreach ($query->result() as $row) { + $grid_4char_paper = strtoupper(substr($row->GRID_SQUARES,0,4)); + if(!in_array($grid_4char_paper, $array_grid_4char_paper)){ + array_push($array_grid_4char_paper, $grid_4char_paper); + } + } + } + + $query = $this->ffma_model->get_worked(); + if ($query && $query->num_rows() > 0) { + foreach ($query->result() as $row) { + $grid_four = strtoupper(substr($row->GRID_SQUARES,0,4)); + if(!in_array($grid_four, $array_grid_4char)){ + array_push($array_grid_4char, $grid_four); + } + } + } + + $vucc_grids = $this->ffma_model->get_vucc_lotw(); + foreach($vucc_grids as $key) { + $grid_four_lotw = strtoupper(substr($key,0,4)); + if(!in_array($grid_four_lotw, $array_grid_4char_lotw)){ + array_push($array_grid_4char_lotw, $grid_four_lotw); + } + } + + $vucc_grids = $this->ffma_model->get_vucc_paper(); + foreach($vucc_grids as $key) { + $grid_four_paper = strtoupper(substr($key,0,4)); + if(!in_array($grid_four_paper, $array_grid_4char_paper)){ + array_push($array_grid_4char_paper, $grid_four_paper); + } + } + + $vucc_grids = $this->ffma_model->get_vucc_worked(); + foreach($vucc_grids as $key) { + $grid_four = strtoupper(substr($key,0,4)); + if(!in_array($grid_four, $array_grid_4char)){ + array_push($array_grid_4char, $grid_four); + } + } + + $data['grid_4char_lotw'] = ($array_grid_4char_lotw); + $data['grid_4char_paper'] = ($array_grid_4char_paper); + $data['grid_4char'] = ($array_grid_4char); + + header('Content-Type: application/json'); + echo json_encode($data); + } + public function getGridmasterGridsjs() { $this->load->model('gridmaster_model'); @@ -592,7 +694,7 @@ class Awards extends CI_Controller { foreach ($query->result() as $row) { $grid_four = strtoupper(substr($row->GRID_SQUARES,0,4)); if(!in_array($grid_four, $array_grid_4char)){ - array_push($array_grid_4char, $grid_four); + array_push($array_grid_4char, $grid_four); } } } diff --git a/application/language/english/menu_lang.php b/application/language/english/menu_lang.php index 52a06af3..224bcbb3 100644 --- a/application/language/english/menu_lang.php +++ b/application/language/english/menu_lang.php @@ -37,6 +37,7 @@ $lang['menu_awards'] = 'Awards'; $lang['menu_cq'] = 'CQ'; $lang['menu_dok'] = 'DOK'; $lang['menu_dxcc'] = 'DXCC'; +$lang['menu_ffma'] = 'Fred Fish Memorial Award'; $lang['menu_iota'] = 'IOTA'; $lang['menu_pota'] = 'POTA'; $lang['menu_sig'] = 'SIG'; diff --git a/application/models/Ffma_model.php b/application/models/Ffma_model.php new file mode 100644 index 00000000..d9ae6cbd --- /dev/null +++ b/application/models/Ffma_model.php @@ -0,0 +1,189 @@ +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)."'"; + + $sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,4) as GRID_SQUARES FROM ' + .$this->config->item('table_name') + .' WHERE station_id in ('.$location_list.')' + ." and COL_LOTW_QSL_RCVD = 'Y'" + ." and COL_BAND = '6M'" + .' AND substring(COL_GRIDSQUARE,1,4) in (\''.implode('\',\'', $this->us_grids).'\')'; + return $this->db->query($sql); + } + + function get_paper() { + $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)."'"; + + $sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,4) as GRID_SQUARES FROM ' + .$this->config->item('table_name') + .' WHERE station_id in ('.$location_list.')' + ." and COL_QSL_RCVD = 'Y'" + ." and COL_BAND = '6M'" + .' AND substring(COL_GRIDSQUARE,1,4) in (\''.implode('\',\'', $this->us_grids).'\')'; + return $this->db->query($sql); + } + + function get_worked() { + $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)."'"; + + $sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,4) as GRID_SQUARES FROM ' + .$this->config->item('table_name') + .' WHERE station_id in ('.$location_list.')' + ." and COL_BAND = '6M'" + .' AND substring(COL_GRIDSQUARE,1,4) in (\''.implode('\',\'', $this->us_grids).'\')'; + return $this->db->query($sql); + } + + function get_vucc_lotw() { + $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)."'"; + + $sql = 'SELECT distinct COL_VUCC_GRIDS as VUCC_GRIDS FROM ' + .$this->config->item('table_name') + .' WHERE station_id in ('.$location_list.')' + ." and COL_LOTW_QSL_RCVD = 'Y'" + ." and COL_VUCC_GRIDS != ''" + ." and COL_VUCC_GRIDS IS NOT NULL" + ." and COL_BAND = '6M'"; + $query = $this->db->query($sql); + $vucc_grids = []; + foreach ($query->result() as $row) { + $grids = explode(',', $row->VUCC_GRIDS); + foreach ($grids as $grid) { + if (in_array(substr($grid, 0, 4), $this->us_grids)) { + if (!in_array(substr($grid, 0, 4), $vucc_grids)) { + $vucc_grids[] = substr($grid, 0, 4); + } + } + } + } + return $vucc_grids; + } + + function get_vucc_paper() { + $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)."'"; + + $sql = 'SELECT distinct COL_VUCC_GRIDS as VUCC_GRIDS FROM ' + .$this->config->item('table_name') + .' WHERE station_id in ('.$location_list.')' + ." and COL_QSL_RCVD = 'Y'" + ." and COL_VUCC_GRIDS != ''" + ." and COL_VUCC_GRIDS IS NOT NULL" + ." and COL_BAND = '6M'"; + $query = $this->db->query($sql); + $vucc_grids = []; + foreach ($query->result() as $row) { + $grids = explode(',', $row->VUCC_GRIDS); + foreach ($grids as $grid) { + if (in_array(substr($grid, 0, 4), $this->us_grids)) { + if (!in_array(substr($grid, 0, 4), $vucc_grids)) { + $vucc_grids[] = substr($grid, 0, 4); + } + } + } + } + return $vucc_grids; + } + + function get_vucc_worked() { + $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)."'"; + + $sql = 'SELECT distinct COL_VUCC_GRIDS as VUCC_GRIDS FROM ' + .$this->config->item('table_name') + .' WHERE station_id in ('.$location_list.')' + ." and COL_VUCC_GRIDS != ''" + ." and COL_VUCC_GRIDS IS NOT NULL" + ." and COL_BAND = '6M'"; + $query = $this->db->query($sql); + $vucc_grids = []; + foreach ($query->result() as $row) { + $grids = explode(',', $row->VUCC_GRIDS); + foreach ($grids as $grid) { + if (in_array(substr($grid, 0, 4), $this->us_grids)) { + if (!in_array(substr($grid, 0, 4), $vucc_grids)) { + $vucc_grids[] = substr($grid, 0, 4); + } + } + } + } + return $vucc_grids; + } + +} diff --git a/application/views/awards/ffma/index.php b/application/views/awards/ffma/index.php new file mode 100644 index 00000000..6caed124 --- /dev/null +++ b/application/views/awards/ffma/index.php @@ -0,0 +1,84 @@ + + + +
+ +
+ +

+ + session->flashdata('message')) { ?> + +
+

session->flashdata('message'); ?>

+
+ +
+ +
+
+
+
+
Latitude:
+
+
Longitude:
+
+
Gridsquare:
+
+
Distance:
+
+
Bearing:
+
+
+ diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index 4bf71553..77550728 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -137,6 +137,8 @@ + + diff --git a/assets/js/sections/ffma.js b/assets/js/sections/ffma.js new file mode 100644 index 00000000..6ab5f9c6 --- /dev/null +++ b/assets/js/sections/ffma.js @@ -0,0 +1,138 @@ +var map; +var grid_four = ''; +var grid_four_lotw = ''; +var grid_four_paper = ''; + +function gridPlot(form) { + $(".ld-ext-right-plot").addClass('running'); + $(".ld-ext-right-plot").prop('disabled', true); + $('#plot').prop("disabled", true); + // If map is already initialized + var container = L.DomUtil.get('gridsquare_map'); + + if(container != null){ + container._leaflet_id = null; + container.remove(); + $("#gridmapcontainer").append('
'); + } + + ajax_url = site_url + '/awards/getFfmaGridsjs'; + + $.ajax({ + url: ajax_url, + type: 'get', + success: function (data) { + $('.cohidden').show(); + $(".ld-ext-right-plot").removeClass('running'); + $(".ld-ext-right-plot").prop('disabled', false); + $('#plot').prop("disabled", false); + grid_four = data.grid_4char; + grid_four_lotw = data.grid_4char_lotw; + grid_four_paper = data.grid_4char_paper; + paper_count = 0; + grid_four_paper.forEach((element) => { + if (!grid_four_lotw.includes(element)) { + paper_count++; + } + }); + var layer = L.tileLayer(jslayer, { + maxZoom: 12, + attribution: jsattribution, + id: 'mapbox.streets' + }); + + map = L.map('gridsquare_map', { + layers: [layer], + center: [38, -91], + zoom: 5, + minZoom: 4, + maxZoom: 12, + fullscreenControl: true, + fullscreenControlOptions: { + position: 'topleft' + }, + }); + + var printer = L.easyPrint({ + tileLayer: layer, + sizeModes: ['Current'], + filename: 'myMap', + exportOnly: true, + hideControlContainer: true + }).addTo(map); + + /*Legend specific*/ + var legend = L.control({ position: "topright" }); + + legend.onAdd = function(map) { + var div = L.DomUtil.create("div", "legend"); + div.innerHTML += "

" + gridsquares_gridsquares + "

"; + div.innerHTML += '' + gridsquares_gridsquares_lotw + ' ('+grid_four_lotw.length+')
'; + div.innerHTML += '' + gridsquares_gridsquares_paper + ' ('+paper_count+')
'; + div.innerHTML += '' + gridsquares_gridsquares_worked + ' ('+(grid_four.length)+')
'; + return div; + }; + + legend.addTo(map); + + var maidenhead = L.maidenhead().addTo(map); + map.on('mousemove', onMapMove); + + }, + error: function (data) { + }, + }); +} + +function spawnGridsquareModal(loc_4char) { + var ajax_data = ({ + 'Searchphrase': loc_4char, + 'Band': '6m', + 'Type': 'VUCC' + }) + $.ajax({ + url: base_url + 'index.php/awards/qso_details_ajax', + type: 'post', + data: ajax_data, + success: function (html) { + BootstrapDialog.show({ + title: lang_general_word_qso_data, + cssClass: 'qso-dialog', + size: BootstrapDialog.SIZE_WIDE, + nl2br: false, + message: html, + onshown: function(dialog) { + + $('[data-toggle="tooltip"]').tooltip(); + $('.contacttable').DataTable({ + "pageLength": 25, + responsive: false, + ordering: false, + "scrollY": "550px", + "scrollCollapse": true, + "paging": false, + "scrollX": true, + dom: 'Bfrtip', + buttons: [ + 'csv' + ] + }); + // change color of csv-button if dark mode is chosen + if (isDarkModeTheme()) { + $(".buttons-csv").css("color", "white"); + } + }, + buttons: [{ + label: 'Close', + action: function(dialogItself) { + dialogItself.close(); + } + }] + }); + } + }); +} + +$(document).ready(function(){ + gridPlot(this.form); +})