From b9c39ed6ed73798fa532f567a98b3a67d86f6593 Mon Sep 17 00:00:00 2001 From: int2001 Date: Thu, 13 Jul 2023 15:19:08 +0000 Subject: [PATCH] Added LotW-Gradient to add_qso and changed getting lotw-info from File to DB --- application/controllers/Logbook.php | 30 ++++++++-------------------- application/models/Logbook_model.php | 10 ++++++++++ application/views/qso/index.php | 2 +- assets/js/sections/qso.js | 14 +++++++++++++ 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index 6c5d7675..87933907 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -98,30 +98,15 @@ class Logbook extends CI_Controller { $callsign = str_replace("-","/",$callsign); // Check if callsign is an LOTW User - $lotw_member = ""; - $lotw_file_name = "./updates/lotw_users.csv"; - - if (file_exists($lotw_file_name)) { - $f = fopen($lotw_file_name, "r"); - $result = false; - while ($row = fgetcsv($f)) { - if ($row[0] == strtoupper($callsign)) { - $result = $row[0]; - $lotw_member = "active"; - break; - } - } - - if($lotw_member != "active") { - $lotw_member = "not found"; - } - fclose($f); - } else { - $lotw_member = "not found"; - } - // Check Database for all other data $this->load->model('logbook_model'); + + $lotw_days=$this->logbook_model->check_last_lotw($callsign); + if ($lotw_days != null) { + $lotw_member="active"; + } else { + $lotw_member="not found"; + } $return = [ "callsign" => strtoupper($callsign), @@ -137,6 +122,7 @@ class Logbook extends CI_Controller { "bearing" => "", "workedBefore" => false, "lotw_member" => $lotw_member, + "lotw_days" => $lotw_days, "image" => "", ]; diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index cd1f915f..2e9319a8 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -296,6 +296,16 @@ class Logbook_model extends CI_Model { $this->add_qso($data, $skipexport = false); } + public function check_last_lotw($call){ // Fetch difference in days when $call has last updated LotW + + $sql="select datediff(now(),lastupload) as DAYS from lotw_users where callsign = ?"; // Use binding to prevent SQL-injection + $query = $this->db->query($sql, $call); + $row = $query->row(); + if (isset($row)) { + return($row->DAYS); + } + } + public function check_station($id){ $this->db->select('station_profile.*, dxcc_entities.name as station_country'); diff --git a/application/views/qso/index.php b/application/views/qso/index.php index b649aa2f..4533b6b5 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -65,7 +65,7 @@
- +
diff --git a/assets/js/sections/qso.js b/assets/js/sections/qso.js index 86114217..e6d4e998 100644 --- a/assets/js/sections/qso.js +++ b/assets/js/sections/qso.js @@ -329,6 +329,9 @@ function reset_fields() { $('#country').val(""); $('#continent').val(""); $('#lotw_info').text(""); + $('#lotw_info').removeClass("lotw_info_red"); + $('#lotw_info').removeClass("lotw_info_yellow"); + $('#lotw_info').removeClass("lotw_info_orange"); $('#qrz_info').text(""); $('#hamqth_info').text(""); $('#sota_info').text(""); @@ -457,6 +460,17 @@ $("#callsign").focusout(function() { if(result.lotw_member == "active") { $('#lotw_info').text("LoTW"); + if (result.lotw_days > 365) { + $('#lotw_info').addClass('lotw_info_red'); + } else if (result.lotw_days > 30) { + $('#lotw_info').addClass('lotw_info_orange'); + $lotw_hint = ' lotw_info_orange'; + } else if (result.lotw_days > 7) { + $('#lotw_info').addClass('lotw_info_yellow'); + } + $('#lotw_info').attr('data-toggle',"tooltip"); + $('#lotw_info').attr('data-original-title',"LoTW User. Last upload was "+result.lotw_days+" days ago"); + $('[data-toggle="tooltip"]').tooltip(); } $('#qrz_info').html(''); $('#qrz_info').attr('title', 'Lookup '+find_callsign+' info on qrz.com');