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 @@