diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index dabdced0..a6c24309 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -619,4 +619,70 @@ class Awards extends CI_Controller { header('Content-Type: application/json'); echo json_encode($zones); } + + /* + function iota + This displays the IOTA map + */ + public function iota_map() { + $this->load->model('iota'); + $this->load->model('bands'); + + $bands[] = $this->input->post('band'); + + $postdata['lotw'] = $this->input->post('lotw') == 0 ? NULL: 1; + $postdata['qsl'] = $this->input->post('qsl') == 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->input->post('band'); + $postdata['mode'] = $this->input->post('mode'); + $postdata['includedeleted'] = $this->input->post('includedeleted') == 0 ? NULL: 1; + $postdata['Africa'] = $this->input->post('Africa') == 0 ? NULL: 1; + $postdata['Asia'] = $this->input->post('Asia') == 0 ? NULL: 1; + $postdata['Europe'] = $this->input->post('Europe') == 0 ? NULL: 1; + $postdata['NorthAmerica'] = $this->input->post('NorthAmerica') == 0 ? NULL: 1; + $postdata['SouthAmerica'] = $this->input->post('SouthAmerica') == 0 ? NULL: 1; + $postdata['Oceania'] = $this->input->post('Oceania') == 0 ? NULL: 1; + $postdata['Antarctica'] = $this->input->post('Antarctica') == 0 ? NULL: 1; + + $iotalist = $this->iota->fetchIota($postdata); + + $iota_array = $this->iota->get_iota_array($iotalist, $bands, $postdata); + + $i = 0; + + foreach ($iotalist as $iota) { + $newiota[$i]['tag'] = $iota->tag; + $newiota[$i]['prefix'] = $iota->prefix; + $newiota[$i]['name'] = ucwords(strtolower($iota->name), "- (/"); + if ($iota->status == 'D') { + $newiota[$i]['name'] .= ' (deleted)'; + } + $newiota[$i]['lat1'] = $iota->lat1; + $newiota[$i]['lon1'] = $iota->lon1; + $newiota[$i]['lat2'] = $iota->lat2; + $newiota[$i]['lon2'] = $iota->lon2; + $newiota[$i++]['status'] = isset($iota_array[$iota->tag]) ? $this->returnStatus($iota_array[$iota->tag]) : 'x'; + } + + header('Content-Type: application/json'); + echo json_encode($newiota); + } + + function returnStatus($string) { + foreach ($string as $key) { + if($key != "") { + if (strpos($key, '>W<') !== false) { + return 'W'; + } + if (strpos($key, '>C<') !== false) { + return 'C'; + } + if ($key == '-') { + return '-'; + } + } + } + } } \ No newline at end of file diff --git a/application/models/Iota.php b/application/models/Iota.php index b578961f..2135c6b6 100644 --- a/application/models/Iota.php +++ b/application/models/Iota.php @@ -78,13 +78,7 @@ class IOTA extends CI_Model { $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; } - if ($band == 'SAT') { - $sql .= " and col_prop_mode ='" . $band . "'"; - } - else { - $sql .= " and col_prop_mode !='SAT'"; - $sql .= " and col_band ='" . $band . "'"; - } + $sql .= $this->addBandToQuery($band); if ($postdata['includedeleted'] == NULL) { $sql .= " and coalesce(iota.status, '') <> 'D'"; @@ -107,13 +101,7 @@ class IOTA extends CI_Model { $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; } - if ($band == 'SAT') { - $sql .= " and col_prop_mode ='" . $band . "'"; - } - else { - $sql .= " and col_prop_mode !='SAT'"; - $sql .= " and col_band ='" . $band . "'"; - } + $sql .= $this->addBandToQuery($band); if ($postdata['includedeleted'] == NULL) { $sql .= " and coalesce(iota.status, '') <> 'D'"; @@ -137,7 +125,7 @@ class IOTA extends CI_Model { $location_list = "'".implode("','",$logbooks_locations_array)."'"; - $sql = "select tag, name, prefix, dxccid, status from iota where 1=1"; + $sql = "select tag, name, prefix, dxccid, status, lat1, lat2, lon1, lon2 from iota where 1=1"; if ($postdata['includedeleted'] == NULL) { $sql .= " and coalesce(iota.status, '') <> 'D'"; @@ -182,27 +170,11 @@ class IOTA extends CI_Model { $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; } - if ($postdata['band'] != 'All') { - if ($postdata['band'] == 'SAT') { - $sql .= " and col_prop_mode ='" . $postdata['band'] . "'"; - } - else { - $sql .= " and col_prop_mode !='SAT'"; - $sql .= " and col_band ='" . $postdata['band'] . "'"; - } - } + $sql .= $this->addBandToQuery($postdata['band']); $sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y'))"; - if ($postdata['band'] != 'All') { - if ($postdata['band'] == 'SAT') { - $sql .= " and col_prop_mode ='" . $postdata['band'] . "'"; - } - else { - $sql .= " and col_prop_mode !='SAT'"; - $sql .= " and col_band ='" . $postdata['band'] . "'"; - } - } + $sql .= $this->addBandToQuery($postdata['band']); if ($postdata['includedeleted'] == NULL) { $sql .= " and coalesce(iota.status, '') <> 'D'"; @@ -236,15 +208,7 @@ class IOTA extends CI_Model { $sql .= $this->addContinentsToQuery($postdata); - if ($postdata['band'] != 'All') { - if ($postdata['band'] == 'SAT') { - $sql .= " and col_prop_mode ='" . $postdata['band'] . "'"; - } - else { - $sql .= " and col_prop_mode !='SAT'"; - $sql .= " and col_band ='" . $postdata['band'] . "'"; - } - } + $sql .= $this->addBandToQuery($postdata['band']); $query = $this->db->query($sql); @@ -392,5 +356,18 @@ class IOTA extends CI_Model { return $query->result(); } + + 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/views/awards/iota/index.php b/application/views/awards/iota/index.php index c6d55a7d..52bb40a1 100644 --- a/application/views/awards/iota/index.php +++ b/application/views/awards/iota/index.php @@ -1,4 +1,38 @@ + + +

@@ -108,11 +142,35 @@
+ +
+ + +
+ +
+
+
+ +
+ +
+ +
+ ×Nothing found!
'; } ?> +
+ diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index c55e7758..573a2dd2 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -44,6 +44,10 @@ function load_was_map() { +uri->segment(1) == "awards" && ($this->uri->segment(2) == "iota") ) { ?> + + + uri->segment(1) == "statistics") { ?> diff --git a/assets/js/sections/iotamap.js b/assets/js/sections/iotamap.js new file mode 100644 index 00000000..2d085af6 --- /dev/null +++ b/assets/js/sections/iotamap.js @@ -0,0 +1,165 @@ +var osmUrl = $('#iotamapjs').attr("tileUrl"); + +function load_iota_map() { + $('.nav-tabs a[href="#iotamaptab"]').tab('show'); + $.ajax({ + url: base_url + 'index.php/awards/iota_map', + type: 'post', + data: { + band: $('#band2').val(), + mode: $('#mode').val(), + worked: +$('#worked').prop('checked'), + confirmed: +$('#confirmed').prop('checked'), + notworked: +$('#notworked').prop('checked'), + qsl: +$('#qsl').prop('checked'), + lotw: +$('#lotw').prop('checked'), + includedeleted: +$('#includedeleted').prop('checked'), + Africa: +$('#Africa').prop('checked'), + Asia: +$('#Asia').prop('checked'), + Europe: +$('#Europe').prop('checked'), + NorthAmerica: +$('#NorthAmerica').prop('checked'), + SouthAmerica: +$('#SouthAmerica').prop('checked'), + Oceania: +$('#Oceania').prop('checked'), + Antarctica: +$('#Antarctica').prop('checked'), + }, + success: function(data) { + load_iota_map2(data, worked, confirmed, notworked); + }, + error: function() { + + }, + }); +} + +function load_iota_map2(data, worked, confirmed, notworked) { + + // If map is already initialized + var container = L.DomUtil.get('iotamap'); + + if(container != null){ + container._leaflet_id = null; + container.remove(); + $("#iotamaptab").append('
'); + } + + var map = L.map('iotamap'); + L.tileLayer( + osmUrl, + { + attribution: '© OpenStreetMap contributors, CC-BY-SA', + maxZoom: 18 + } + ).addTo(map); + + var notworkedcount = data.length; + var confirmedcount = 0; + var workednotconfirmedcount = 0; + + for (var i = 0; i < data.length; i++) { + var D = data[i]; + if (D['status'] != 'x') { + var mapColor = 'red'; + + if (D['status'] == 'C') { + mapColor = 'green'; + if (confirmed != '0') { + addPolygon(L, D, mapColor, map); + addMarker(L, D, mapColor, map); + confirmedcount++; + notworkedcount--; + } + } + if (D['status'] == 'W') { + mapColor = 'orange'; + if (worked != '0') { + addPolygon(L, D, mapColor, map); + addMarker(L, D, mapColor, map); + workednotconfirmedcount++; + notworkedcount--; + } + } + + + // Make a check here and hide what I don't want to show + if (notworked != '0') { + if (mapColor == 'red') { + addPolygon(L, D, mapColor, map); + addMarker(L, D, mapColor, map); + } + } + } + } + + /*Legend specific*/ + var legend = L.control({ position: "topright" }); + + if (notworked.checked == false) { + notworkedcount = 0; + } + + legend.onAdd = function(map) { + var div = L.DomUtil.create("div", "legend"); + div.innerHTML += "

Colors

"; + div.innerHTML += 'Confirmed ('+confirmedcount+')
'; + div.innerHTML += 'Worked not confirmed ('+workednotconfirmedcount+')
'; + div.innerHTML += 'Not worked ('+notworkedcount+')
'; + return div; + }; + + legend.addTo(map); + + map.setView([20, 0], 2); +} + +/* + * We need to fix some islands that would wrap around the whole map. + * That's why we add 360 degrees to some of them. + * The following island have this problem: + * AN-016, AS-027, AS-092, AS-174, OC-016 + * AN-020 is and exception + */ +function addPolygon(L, D, mapColor, map) { + if (D['tag'] != 'AN-016') { + if (D['lon1'] > 0 && D['lon2'] < 0 && D['lon1'] - D['lon2'] > 180) { + D['lon2'] = parseFloat(D['lon2'])+360; + + } + + if (D['lon1'] < 0 && D['lon2'] > 0 && D['lon2'] - D['lon1'] > 180) { + D['lon1'] = parseFloat(D['lon1'])+360; + } + } + + // It seems to me that latitudes have the wrong sign to be drawn correctly in leaflet. That's why they are mulitipled with -1 to be drawn in the correct hemisphere. + var latlngs = [ + [D['lat1']*-1, D['lon1']], + [D['lat2']*-1, D['lon1']], + [D['lat2']*-1, D['lon2']], + [D['lat1']*-1, D['lon2']] + ]; + + var polygon = L.polygon(latlngs, {color: mapColor}).addTo(map); +} + +function addMarker(L, D, mapColor, map) { + var title = '' + D['tag'] + ''; + var myIcon = L.divIcon({ + className: 'my-div-icon', + html: title, + iconSize: [60, 10] + }); + + // It seems to me that latitudes have the wrong sign to be drawn correctly in leaflet. That's why they are mulitipled with -1 to be drawn in the correct hemisphere. + L.marker( + [D['lat1']*-1, D['lon1']], { + icon: myIcon, + iota: D['tag'], + title: D['tag'], + } + ).addTo(map).on('click', onClick); +} + +function onClick(e) { + var marker = e.target; + displayContacts(marker.options.iota, $('#band2').val(), $('#mode').val(), 'IOTA'); +}