From cff683703e3c05a64cde138dbb0501be651d81bc Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 9 Apr 2024 20:21:25 +0200 Subject: [PATCH] Now displays worked/confirmed icons/lines --- application/controllers/Visitor.php | 66 ++++++++++++++++++++--- application/models/Stationsetup_model.php | 13 +++++ assets/js/sections/exportmap.js | 54 +++++++++++++++++-- 3 files changed, 122 insertions(+), 11 deletions(-) diff --git a/application/controllers/Visitor.php b/application/controllers/Visitor.php index e099fd25b..0461e5a37 100644 --- a/application/controllers/Visitor.php +++ b/application/controllers/Visitor.php @@ -28,6 +28,9 @@ class Visitor extends CI_Controller { } elseif($method == "mapqsos") { $this->mapqsos(); + } + elseif($method == "get_map_custom") { + $this->get_map_custom(); } else { $this->index($method); @@ -448,15 +451,17 @@ class Visitor extends CI_Controller { } $qsos = $this->logbook_model->get_qsos($qsocount, null, $logbooks_locations_array, $band); + $userid = $this->stationsetup_model->public_slug_exists_userid($slug); + $user_default_confirmation = $this->get_user_default_confirmation($userid); $mappedcoordinates = array(); foreach ($qsos->result('array') as $qso) { if (!empty($qso['COL_MY_GRIDSQUARE']) || !empty($qso['COL_MY_VUCC_GRIDS'])) { if (!empty($qso['COL_GRIDSQUARE']) || !empty($qso['COL_VUCC_GRIDS'])) { - $mappedcoordinates[] = $this->calculate($qso, ($qso['COL_MY_GRIDSQUARE'] ?? '') == '' ? $qso['COL_MY_VUCC_GRIDS'] : $qso['COL_MY_GRIDSQUARE'], ($qso['COL_GRIDSQUARE'] ?? '') == '' ? $qso['COL_VUCC_GRIDS'] : $qso['COL_GRIDSQUARE']); + $mappedcoordinates[] = $this->calculate($qso, ($qso['COL_MY_GRIDSQUARE'] ?? '') == '' ? $qso['COL_MY_VUCC_GRIDS'] : $qso['COL_MY_GRIDSQUARE'], ($qso['COL_GRIDSQUARE'] ?? '') == '' ? $qso['COL_VUCC_GRIDS'] : $qso['COL_GRIDSQUARE'], $user_default_confirmation); } else { if (!empty($qso['lat']) || !empty($qso['long'])) { - $mappedcoordinates[] = $this->calculateCoordinates($qso, $qso['lat'], $qso['long'], ($qso['COL_MY_GRIDSQUARE'] ?? '') == '' ? $qso['COL_MY_VUCC_GRIDS'] : $qso['COL_MY_GRIDSQUARE']); + $mappedcoordinates[] = $this->calculateCoordinates($qso, $qso['lat'], $qso['long'], ($qso['COL_MY_GRIDSQUARE'] ?? '') == '' ? $qso['COL_MY_VUCC_GRIDS'] : $qso['COL_MY_GRIDSQUARE'], $user_default_confirmation); } } } @@ -466,7 +471,7 @@ class Visitor extends CI_Controller { echo json_encode($mappedcoordinates); } - public function calculate($qso, $locator1, $locator2) { + public function calculate($qso, $locator1, $locator2, $user_default_confirmation) { $this->load->library('Qra'); $this->load->model('logbook_model'); @@ -479,12 +484,12 @@ class Visitor extends CI_Controller { $data['latlng1'] = $latlng1; $data['latlng2'] = $latlng2; - $data['confirmed'] = ($this->logbook_model->qso_is_confirmed($qso)==true) ? true : false; + $data['confirmed'] = ($this->qso_is_confirmed($qso, $user_default_confirmation)==true) ? true : false; return $data; } - public function calculateCoordinates($qso, $lat, $long, $mygrid) { + public function calculateCoordinates($qso, $lat, $long, $mygrid, $user_default_confirmation) { $this->load->library('Qra'); $this->load->model('logbook_model'); @@ -498,8 +503,57 @@ class Visitor extends CI_Controller { $data['latlng1'] = $latlng1; $data['latlng2'] = $latlng2; - $data['confirmed'] = ($this->logbook_model->qso_is_confirmed($qso)==true) ? true : false; + $data['confirmed'] = ($this->qso_is_confirmed($qso, $user_default_confirmation)==true) ? true : false; return $data; } + + // [MAP Custom] // + public function get_map_custom() { + $this->load->model('stationsetup_model'); + $slug = $this->security->xss_clean($this->input->post('slug')); + $userid = $this->stationsetup_model->public_slug_exists_userid($slug); + + $this->load->model('user_options_model'); + + $result=$this->user_options_model->get_options('map_custom', null, $userid); + $jsonout=[]; + foreach($result->result() as $options) { + if ($options->option_name=='icon') $jsonout[$options->option_key]=json_decode($options->option_value,true); + else $jsonout[$options->option_name.'_'.$options->option_key]=$options->option_value; + } + header('Content-Type: application/json'); + echo json_encode($jsonout); + } + + function qso_is_confirmed($qso, $user_default_confirmation) { + $confirmed = false; + $qso = (array) $qso; + if (strpos($user_default_confirmation, 'Q') !== false) { // QSL + if ($qso['COL_QSL_RCVD']=='Y') { $confirmed = true; } + } + if (strpos($user_default_confirmation, 'L') !== false) { // LoTW + if ($qso['COL_LOTW_QSL_RCVD']=='Y') { $confirmed = true; } + } + if (strpos($user_default_confirmation, 'E') !== false) { // eQsl + if ($qso['COL_EQSL_QSL_RCVD']=='Y') { $confirmed = true; } + } + if (strpos($user_default_confirmation, 'Z') !== false) { // QRZ + if ($qso['COL_QRZCOM_QSO_DOWNLOAD_STATUS']=='Y') { $confirmed = true; } + } + return $confirmed; + } + + function get_user_default_confirmation($userid) { + $this->db->where('user_id', $userid); + $query = $this->db->get('users'); + + if ($query->num_rows() > 0){ + foreach ($query->result() as $row) { + return $row->user_default_confirmation; + } + } else { + return ''; + } + } } diff --git a/application/models/Stationsetup_model.php b/application/models/Stationsetup_model.php index cead38a23..46c1f074b 100644 --- a/application/models/Stationsetup_model.php +++ b/application/models/Stationsetup_model.php @@ -174,6 +174,19 @@ class Stationsetup_model extends CI_Model { return array(-1); // Put some default-Value here, if no relation found } } + + function public_slug_exists_userid($slug) { + $this->db->where('public_slug', $this->security->xss_clean($slug)); + $query = $this->db->get('station_logbooks'); + + if ($query->num_rows() > 0){ + foreach ($query->result() as $row) { + return $row->user_id; + } + } else { + return -1; + } + } } ?> diff --git a/assets/js/sections/exportmap.js b/assets/js/sections/exportmap.js index 8adbd732e..3919520a1 100644 --- a/assets/js/sections/exportmap.js +++ b/assets/js/sections/exportmap.js @@ -1,6 +1,19 @@ var zonemarkers = []; var clicklines = []; +var iconsList = { 'qso': { 'color': defaultlinecolor, 'icon': 'fas fa-dot-circle', 'iconSize': [5, 5] }, 'qsoconfirm': { 'color': defaultlinecolor, 'icon': 'fas fa-dot-circle', 'iconSize': [5, 5] } }; + +var stationIcon = L.divIcon({ className: 'cspot_station', iconSize: [5, 5], iconAnchor: [5, 5]}); +var qsoIcon = L.divIcon({ className: 'cspot_qso', iconSize: [5, 5], iconAnchor: [5, 5] }); //default (fas fa-dot-circle red) +var qsoconfirmIcon = L.divIcon({ className: 'cspot_qsoconfirm', iconSize: [5, 5], iconAnchor: [5, 5] }); +var redIconImg = L.icon({ iconUrl: icon_dot_url, iconSize: [5, 5] }); // old // + +var defaultlinecolor = 'blue'; + +if (isDarkModeTheme()) { + defaultlinecolor = 'red'; +} + $(document).ready(function () { mapQsos(); }); @@ -24,14 +37,34 @@ function mapQsos(form) { band: band }, success: function(data) { - loadMap(data, showgrid, showcq, showlines); + + loadMapOptions(data, showgrid, showcq, showlines, slug); }, error: function() { }, }); }; -function loadMap(data, showgrid, showcq, showlines) { +function loadMapOptions(data, showgrid, showcq, showlines, slug) { + $.ajax({ + url: base_url + 'index.php/visitor/get_map_custom', + type: 'POST', + dataType: 'json', + data: { + slug: slug, + }, + error: function () { + }, + success: function (json_mapinfo) { + if (typeof json_mapinfo.qso !== "undefined") { + iconsList = json_mapinfo; + } + loadMap(data, showgrid, showcq, showlines, iconsList); + } + }); +} + +function loadMap(data, showgrid, showcq, showlines, iconsList) { var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; var osmAttrib='Map data © OpenStreetMap contributors'; // If map is already initialized @@ -73,7 +106,6 @@ function loadMap(data, showgrid, showcq, showlines) { clicklines = []; $.each(data, function(k, v) { - linecolor = 'red'; if (this.latlng2[1] < -170) { this.latlng2[1] = parseFloat(this.latlng2[1])+360; @@ -82,9 +114,17 @@ function loadMap(data, showgrid, showcq, showlines) { this.latlng1[1] = parseFloat(this.latlng1[1])+360; } - var marker = L.marker([this.latlng1[0], this.latlng1[1]], {icon: redIcon}, {closeOnClick: false, autoClose: false}).addTo(map); + var marker = L.marker([this.latlng1[0], this.latlng1[1]], {icon: stationIcon}, {closeOnClick: false, autoClose: false}).addTo(map); - var marker2 = L.marker([this.latlng2[0], this.latlng2[1]], {icon: redIcon},{closeOnClick: false, autoClose: false}).addTo(map); + // var marker2 = L.marker([this.latlng2[0], this.latlng2[1]], {icon: redIcon},{closeOnClick: false, autoClose: false}).addTo(map); + + if (this.confirmed && iconsList.qsoconfirm.icon !== "0") { + var marker2 = L.marker([this.latlng2[0], this.latlng2[1]], {icon: qsoconfirmIcon},{closeOnClick: false, autoClose: false}).addTo(map); + linecolor = iconsList.qsoconfirm.color; + } else { + var marker2 = L.marker([this.latlng2[0], this.latlng2[1]], {icon: qsoIcon},{closeOnClick: false, autoClose: false}).addTo(map); + linecolor = iconsList.qso.color; + } if (showlines === "true") { const multiplelines = []; @@ -127,6 +167,10 @@ function loadMap(data, showgrid, showcq, showlines) { } } + $.each(iconsList, function (icon, data) { + $('#exportmap' + ' .cspot_' + icon).addClass(data.icon).css("color", data.color); + }); + map.addLayer(osm); var printer = L.easyPrint({