From 1feac9389ee9c8c8ccd1015a4e548c11457adbfd Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sat, 25 May 2024 09:41:27 +0200 Subject: [PATCH 01/29] moved upload and download to clublog model --- application/controllers/Clublog.php | 208 ++++------------------ application/models/Clublog_model.php | 246 +++++++++++++++++++++++---- 2 files changed, 248 insertions(+), 206 deletions(-) diff --git a/application/controllers/Clublog.php b/application/controllers/Clublog.php index c68bd6f7d..94e9e8a1f 100644 --- a/application/controllers/Clublog.php +++ b/application/controllers/Clublog.php @@ -1,221 +1,87 @@ -session->userdata('user_id') == '') { - echo "Maintenance Mode is active. Try again later.\n"; - redirect('user/login'); + echo "Maintenance Mode is active. Try again later.\n"; + redirect('dashboard'); } } // Show frontend if there is one - public function index() { - $this->config->load('config'); + public function index() + { + // nothing to display + redirect('dashboard'); } // Upload ADIF to Clublog - public function upload() { + public function upload() + { + $this->load->model('clublog_model'); // set the last run in cron table for the correct cron id $this->load->model('cron_model'); - $this->cron_model->set_last_run($this->router->class.'_'.$this->router->method); + $this->cron_model->set_last_run($this->router->class . '_' . $this->router->method); $users = $this->clublog_model->get_clublog_users(); - foreach ($users as $user) { - $this->uploadUser($user->user_id, $user->user_clublog_name, $user->user_clublog_password); + if (!empty($users)) { + foreach ($users as $user) { + $r = $this->clublog_model->uploadUser($user->user_id, $user->user_clublog_name, $user->user_clublog_password); + } + } else { + $r = "No user has configured Clublog."; } + + echo $r; } // Download ADIF from Clublog - public function download() { + public function download() + { $this->load->model('clublog_model'); // set the last run in cron table for the correct cron id $this->load->model('cron_model'); - $this->cron_model->set_last_run($this->router->class.'_'.$this->router->method); + $this->cron_model->set_last_run($this->router->class . '_' . $this->router->method); $users = $this->clublog_model->get_clublog_users(); - foreach ($users as $user) { - $this->downloadUser($user->user_id, $user->user_clublog_name, $user->user_clublog_password); - } - } - - function downloadUser($userid, $username, $password) { - $clean_username = $this->security->xss_clean($username); - $clean_password = $this->security->xss_clean($password); - $clean_userid = $this->security->xss_clean($userid); - - $this->config->load('config'); - ini_set('memory_limit', '-1'); - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - error_reporting(E_ALL); - - $this->load->helper('file'); - - $this->load->model('clublog_model'); - $this->load->model('logbook_model'); - - $station_profiles = $this->clublog_model->all_enabled($clean_userid); // Fetch unique Calls per User with aggregated station_ids - if ($station_profiles->num_rows()) { - foreach ($station_profiles->result() as $station_row) { - $lastrec=$this->clublog_model->clublog_last_qsl_rcvd_date($station_row->station_callsign); - $url='https://clublog.org/getmatches.php?api=608df94896cb9c5421ae748235492b43815610c9&email='.$clean_username.'&password='.$clean_password.'&callsign='.$station_row->station_callsign.'&startyear='.substr($lastrec,0,4).'&startmonth='.substr($lastrec,4,2).'&startday='.substr($lastrec,6,2); - $request = curl_init($url); - - // recieve a file - curl_setopt($request, CURLOPT_RETURNTRANSFER, true); - $response = curl_exec($request); - $info = curl_getinfo($request); - curl_close ($request); - if(curl_errno($request)) { - echo curl_error($request); - } elseif (preg_match_all('/Invalid callsign/',$response)) { // We're trying to download calls for a station we're not granted. Disable Clublog-Transfer for that station(s) - $this->clublog_model->disable_sync4call($station_row->station_callsign,$station_row->station_ids); - } else { - try { - $cl_qsls=json_decode($response); - foreach ($cl_qsls as $oneqsl) { - $this->logbook_model->clublog_update($oneqsl[2], $oneqsl[0], $oneqsl[3], 'Y', $station_row->station_callsign, $station_row->station_ids); - } - } catch (Exception $e) { - log_message("Error","Something gone wrong while trying to Download for station(s) ".$station_row->station_ids." / Call: ".$station_row->station_callsign); - } - } - + if (!empty($users)) { + foreach ($users as $user) { + $r = $this->clublog_model->downloadUser($user->user_id, $user->user_clublog_name, $user->user_clublog_password); } + } else { + $r = "No user has configured Clublog."; } + + echo $r; } - function uploadUser($userid, $username, $password) { - $clean_username = $this->security->xss_clean($username); - $clean_passord = $this->security->xss_clean($password); - $clean_userid = $this->security->xss_clean($userid); - - $this->config->load('config'); - ini_set('memory_limit', '-1'); - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - error_reporting(E_ALL); - - $this->load->helper('file'); - - $this->load->model('clublog_model'); - - $station_profiles = $this->clublog_model->all_with_count($clean_userid); - - if($station_profiles->num_rows()){ - foreach ($station_profiles->result() as $station_row) - { - if($station_row->qso_total > 0) { - $data['qsos'] = $this->clublog_model->get_clublog_qsos($station_row->station_id); - - if($data['qsos']->num_rows()){ - $string = $this->load->view('adif/data/clublog', $data, TRUE); - - $ranid = uniqid(); - - if ( ! write_file('uploads/clublog'.$ranid.$station_row->station_id.'.adi', $string)) { - echo 'Unable to write the file - Make the folder Upload folder has write permissions.'; - } - else { - - $file_info = get_file_info('uploads/clublog'.$ranid.$station_row->station_id.'.adi'); - - // initialise the curl request - $request = curl_init('https://clublog.org/putlogs.php'); - - if($this->config->item('directory') != "") { - $filepath = $_SERVER['DOCUMENT_ROOT']."/".$this->config->item('directory')."/".$file_info['server_path']; - } else { - $filepath = $_SERVER['DOCUMENT_ROOT']."/".$file_info['server_path']; - } - - if (function_exists('curl_file_create')) { // php 5.5+ - $cFile = curl_file_create($filepath); - } else { // - $cFile = '@' . realpath($filepath); - } - - // send a file - curl_setopt($request, CURLOPT_POST, true); - curl_setopt( - $request, - CURLOPT_POSTFIELDS, - array( - 'email' => $clean_username, - 'password' => $clean_passord, - 'callsign' => $station_row->station_callsign, - 'api' => "608df94896cb9c5421ae748235492b43815610c9", - 'file' => $cFile - )); - - // output the response - curl_setopt($request, CURLOPT_RETURNTRANSFER, true); - $response = curl_exec($request); - $info = curl_getinfo($request); - - if(curl_errno($request)) { - echo curl_error($request); - } - curl_close ($request); - - - // If Clublog Accepts mark the QSOs - if (preg_match('/\baccepted\b/', $response)) { - echo "QSOs uploaded and Logbook QSOs marked as sent to Clublog"."
"; - $this->load->model('clublog_model'); - $this->clublog_model->mark_qsos_sent($station_row->station_id); - echo "Clublog upload for ".$station_row->station_callsign."
"; - log_message('info', 'Clublog upload for '.$station_row->station_callsign.' successfully sent.'); - } else if (preg_match('/checksum duplicate/',$response)) { - echo "QSOs uploaded (asduplicate!) and Logbook QSOs marked as sent to Clublog"."
"; - $this->load->model('clublog_model'); - $this->clublog_model->mark_qsos_sent($station_row->station_id); - echo "Clublog upload for ".$station_row->station_callsign."
"; - log_message('info', 'Clublog DUPLICATE upload for '.$station_row->station_callsign.' successfully sent.'); - } else { - echo "Error ".$response."
"; - log_message('error', 'Clublog upload for '.$station_row->station_callsign.' failed reason '.$response); - } - - // Delete the ADIF file used for clublog - unlink('uploads/clublog'.$ranid.$station_row->station_id.'.adi'); - - } - - } else { - echo "Nothing awaiting upload to clublog for ".$station_row->station_callsign."
"; - - log_message('info', 'Nothing awaiting upload to clublog for '.$station_row->station_callsign); - } - } - } - } - } - - function markqso($station_id) { + function markqso($station_id) + { $clean_station_id = $this->security->xss_clean($station_id); $this->load->model('clublog_model'); $this->clublog_model->mark_qsos_sent($clean_station_id); } // Find DXCC - function find_dxcc($callsign) { + function find_dxcc($callsign) + { $clean_callsign = $this->security->xss_clean($callsign); // Live lookup against Clublogs API - $url = "https://clublog.org/dxcc?call=".$clean_callsign."&api=608df94896cb9c5421ae748235492b43815610c9&full=1"; + $url = "https://clublog.org/dxcc?call=" . $clean_callsign . "&api=608df94896cb9c5421ae748235492b43815610c9&full=1"; $json = file_get_contents($url); $data = json_decode($json, TRUE); diff --git a/application/models/Clublog_model.php b/application/models/Clublog_model.php index dee198086..326121fc6 100644 --- a/application/models/Clublog_model.php +++ b/application/models/Clublog_model.php @@ -1,8 +1,10 @@ db->select('user_clublog_name, user_clublog_password, user_id'); $this->db->where('coalesce(user_clublog_name, "") != ""'); $this->db->where('coalesce(user_clublog_password, "") != ""'); @@ -10,50 +12,221 @@ class Clublog_model extends CI_Model { return $query->result(); } - function mark_qsos_sent($station_id) { + function uploadUser($userid, $username, $password) + { + $clean_username = $this->security->xss_clean($username); + $clean_passord = $this->security->xss_clean($password); + $clean_userid = $this->security->xss_clean($userid); + + $return = "No QSO's to upload"; + + $this->config->load('config'); + + ini_set('memory_limit', '-1'); + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + error_reporting(E_ALL); + + $this->load->helper('file'); + + $station_profiles = $this->all_with_count($clean_userid); + + if ($station_profiles->num_rows()) { + foreach ($station_profiles->result() as $station_row) { + if ($station_row->qso_total > 0) { + $data['qsos'] = $this->get_clublog_qsos($station_row->station_id); + + if ($data['qsos']->num_rows()) { + $string = $this->load->view('adif/data/clublog', $data, TRUE); + + $ranid = uniqid(); + + if (!write_file('uploads/clublog' . $ranid . $station_row->station_id . '.adi', $string)) { + $return = 'Unable to write the file - Make the folder Upload folder has write permissions.'; + } else { + + $file_info = get_file_info('uploads/clublog' . $ranid . $station_row->station_id . '.adi'); + + // initialise the curl request + $request = curl_init('https://clublog.org/putlogs.php'); + + if ($this->config->item('directory') != "") { + $filepath = $_SERVER['DOCUMENT_ROOT'] . "/" . $this->config->item('directory') . "/" . $file_info['server_path']; + } else { + $filepath = $_SERVER['DOCUMENT_ROOT'] . "/" . $file_info['server_path']; + } + + if (function_exists('curl_file_create')) { // php 5.5+ + $cFile = curl_file_create($filepath); + } else { // + $cFile = '@' . realpath($filepath); + } + + // send a file + curl_setopt($request, CURLOPT_POST, true); + curl_setopt( + $request, + CURLOPT_POSTFIELDS, + array( + 'email' => $clean_username, + 'password' => $clean_passord, + 'callsign' => $station_row->station_callsign, + 'api' => "608df94896cb9c5421ae748235492b43815610c9", + 'file' => $cFile + ) + ); + + // output the response + curl_setopt($request, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($request); + $info = curl_getinfo($request); + + if (curl_errno($request)) { + $return = curl_error($request); + } + curl_close($request); + + + // If Clublog Accepts mark the QSOs + if (preg_match('/\baccepted\b/', $response)) { + $return = "QSOs uploaded and Logbook QSOs marked as sent to Clublog"; + $this->mark_qsos_sent($station_row->station_id); + $return = "Clublog upload for " . $station_row->station_callsign; + log_message('info', 'Clublog upload for ' . $station_row->station_callsign . ' successfully sent.'); + } else if (preg_match('/checksum duplicate/', $response)) { + $return = "QSOs uploaded (asduplicate!) and Logbook QSOs marked as sent to Clublog"; + $this->mark_qsos_sent($station_row->station_id); + $return = "Clublog upload for " . $station_row->station_callsign; + log_message('info', 'Clublog DUPLICATE upload for ' . $station_row->station_callsign . ' successfully sent.'); + } else { + $return = "Error " . $response; + log_message('error', 'Clublog upload for ' . $station_row->station_callsign . ' failed reason ' . $response); + } + + // Delete the ADIF file used for clublog + unlink('uploads/clublog' . $ranid . $station_row->station_id . '.adi'); + } + } else { + + $return = "Nothing awaiting upload to clublog for " . $station_row->station_callsign; + log_message('info', 'Nothing awaiting upload to clublog for ' . $station_row->station_callsign); + } + } + } + } + log_message('info', $return); + return $return . "\n"; + } + + function downloadUser($userid, $username, $password) + { + $clean_username = $this->security->xss_clean($username); + $clean_password = $this->security->xss_clean($password); + $clean_userid = $this->security->xss_clean($userid); + + $return = "Nothing to download"; + + $this->config->load('config'); + + ini_set('memory_limit', '-1'); + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + error_reporting(E_ALL); + + $this->load->helper('file'); + $this->load->model('logbook_model'); + + $station_profiles = $this->all_enabled($clean_userid); // Fetch unique Calls per User with aggregated station_ids + + if ($station_profiles->num_rows()) { + foreach ($station_profiles->result() as $station_row) { + $lastrec = $this->clublog_last_qsl_rcvd_date($station_row->station_callsign); + $url = 'https://clublog.org/getmatches.php?api=608df94896cb9c5421ae748235492b43815610c9&email=' . $clean_username . '&password=' . $clean_password . '&callsign=' . $station_row->station_callsign . '&startyear=' . substr($lastrec, 0, 4) . '&startmonth=' . substr($lastrec, 4, 2) . '&startday=' . substr($lastrec, 6, 2); + $request = curl_init($url); + + // recieve a file + curl_setopt($request, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($request); + $info = curl_getinfo($request); + curl_close($request); + + if (curl_errno($request)) { + $return = curl_error($request); + } elseif (preg_match_all('/Login rejected/', $response)) { + $return = "Wrong Clublog username and password for Callsign: '" . $station_row->station_callsign . "'. 'LOGIN REJECTED'."; + log_message('error', $return); + } elseif (preg_match_all('/Invalid callsign/', $response)) { // We're trying to download calls for a station we're not granted. Disable Clublog-Transfer for that station(s) + $this->disable_sync4call($station_row->station_callsign, $station_row->station_ids); + $return = "The callsign '" . $station_row->station_callsign . "' does not match the user account at Clublog. 'INVALID CALLSIGN'."; + log_message('debug', $return); + } else { + try { + $cl_qsls = json_decode($response); + foreach ($cl_qsls as $oneqsl) { + $this->logbook_model->clublog_update($oneqsl[2], $oneqsl[0], $oneqsl[3], 'Y', $station_row->station_callsign, $station_row->station_ids); + } + } catch (Exception $e) { + $return = "Something gone wrong while trying to Download for station(s) " . $station_row->station_ids . " / Call: " . $station_row->station_callsign; + log_message("error", $return); + } + + $return = "QSO's for Callsign: '" . $station_row->station_callsign . "' were successfully downloaded"; + log_message('info', $return); + } + } + } + + return $return . "\n"; + } + + function mark_qsos_sent($station_id) + { $data = array( - 'COL_CLUBLOG_QSO_UPLOAD_DATE' => date('Y-m-d'), - 'COL_CLUBLOG_QSO_UPLOAD_STATUS' => "Y", + 'COL_CLUBLOG_QSO_UPLOAD_DATE' => date('Y-m-d'), + 'COL_CLUBLOG_QSO_UPLOAD_STATUS' => "Y", ); $this->db->where("station_id", $station_id); $this->db->group_start(); $this->db->where("COL_CLUBLOG_QSO_UPLOAD_STATUS", null); $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", ""); - $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "N"); - $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "M"); + $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "N"); + $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "M"); $this->db->group_end(); $this->db->update($this->config->item('table_name'), $data); } - function mark_qso_sent($qso_id) { + function mark_qso_sent($qso_id) + { $data = array( - 'COL_CLUBLOG_QSO_UPLOAD_DATE' => date('Y-m-d'), - 'COL_CLUBLOG_QSO_UPLOAD_STATUS' => "Y", + 'COL_CLUBLOG_QSO_UPLOAD_DATE' => date('Y-m-d'), + 'COL_CLUBLOG_QSO_UPLOAD_STATUS' => "Y", ); $this->db->where("COL_PRIMARY_KEY", $qso_id); $this->db->update($this->config->item('table_name'), $data); } - function get_last_five($station_id) { + function get_last_five($station_id) + { $this->db->where('station_id', $station_id); $this->db->group_start(); $this->db->where("COL_CLUBLOG_QSO_UPLOAD_STATUS", null); $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", ""); $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "N"); $this->db->group_end(); - $this->db->limit(5); + $this->db->limit(5); $query = $this->db->get($this->config->item('table_name')); return $query; } - function mark_all_qsos_notsent($station_id) { + function mark_all_qsos_notsent($station_id) + { $data = array( - 'COL_CLUBLOG_QSO_UPLOAD_DATE' => null, - 'COL_CLUBLOG_QSO_UPLOAD_STATUS' => "M", - 'COL_CLUBLOG_QSO_UPLOAD_STATUS' => "N", + 'COL_CLUBLOG_QSO_UPLOAD_DATE' => null, + 'COL_CLUBLOG_QSO_UPLOAD_STATUS' => "M", + 'COL_CLUBLOG_QSO_UPLOAD_STATUS' => "N", ); $this->db->where("station_id", $station_id); @@ -61,11 +234,12 @@ class Clublog_model extends CI_Model { $this->db->update($this->config->item('table_name'), $data); } - function get_clublog_qsos($station_id){ + function get_clublog_qsos($station_id) + { $this->db->select('*, dxcc_entities.name as station_country'); - $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); + $this->db->join('station_profile', 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id'); $this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer'); - $this->db->where($this->config->item('table_name').'.station_id', $station_id); + $this->db->where($this->config->item('table_name') . '.station_id', $station_id); $this->db->where('station_profile.clublogignore', 0); $this->db->group_start(); $this->db->where("COL_CLUBLOG_QSO_UPLOAD_STATUS", null); @@ -73,17 +247,18 @@ class Clublog_model extends CI_Model { $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "M"); $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "N"); $this->db->group_end(); - + $query = $this->db->get($this->config->item('table_name')); return $query; - } + } - function clublog_last_qsl_rcvd_date($callsign) { + function clublog_last_qsl_rcvd_date($callsign) + { $qso_table_name = $this->config->item('table_name'); $this->db->from($qso_table_name); - $this->db->join('station_profile', 'station_profile.station_id = '.$qso_table_name.'.station_id'); + $this->db->join('station_profile', 'station_profile.station_id = ' . $qso_table_name . '.station_id'); $this->db->where('station_profile.station_callsign', $callsign); $this->db->select("DATE_FORMAT(COL_CLUBLOG_QSO_DOWNLOAD_DATE,'%Y%m%d') AS COL_CLUBLOG_QSO_DOWNLOAD_DATE", FALSE); @@ -95,7 +270,7 @@ class Clublog_model extends CI_Model { $query = $this->db->get(); $row = $query->row(); - if (isset($row->COL_CLUBLOG_QSO_DOWNLOAD_DATE)){ + if (isset($row->COL_CLUBLOG_QSO_DOWNLOAD_DATE)) { return $row->COL_CLUBLOG_QSO_DOWNLOAD_DATE; } else { // No previous date (first time import has run?), so choose UNIX EPOCH! @@ -104,24 +279,27 @@ class Clublog_model extends CI_Model { } } - function disable_sync4call($call, $stations) { - $sql="update station_profile set clublogignore=1 where station_callsign=? and station_id in (".$stations.")"; - $query = $this->db->query($sql,$call); + function disable_sync4call($call, $stations) + { + $sql = "update station_profile set clublogignore=1 where station_callsign=? and station_id in (" . $stations . ")"; + $query = $this->db->query($sql, $call); } - function all_enabled($userid) { - $sql="select sp.station_callsign, group_concat(sp.station_id) as station_ids from station_profile sp + function all_enabled($userid) + { + $sql = "select sp.station_callsign, group_concat(sp.station_id) as station_ids from station_profile sp inner join users u on (u.user_id=sp.user_id) where u.user_clublog_name is not null and u.user_clublog_password is not null and sp.clublogignore=0 and u.user_id=? group by sp.station_callsign"; - $query = $this->db->query($sql,$userid); + $query = $this->db->query($sql, $userid); return $query; } - function all_with_count($userid) { - $this->db->select('station_profile.station_id, station_profile.station_callsign, count('.$this->config->item('table_name').'.station_id) as qso_total'); + function all_with_count($userid) + { + $this->db->select('station_profile.station_id, station_profile.station_callsign, count(' . $this->config->item('table_name') . '.station_id) as qso_total'); $this->db->from('station_profile'); - $this->db->join($this->config->item('table_name'),'station_profile.station_id = '.$this->config->item('table_name').'.station_id','left'); + $this->db->join($this->config->item('table_name'), 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id', 'left'); $this->db->group_by('station_profile.station_id'); $this->db->where('station_profile.user_id', $userid); $this->db->where('station_profile.clublogignore', 0); @@ -135,5 +313,3 @@ class Clublog_model extends CI_Model { return $this->db->get(); } } - -?> From ee63c90d62302e7d0638069674f10c1350d56ffb Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Sat, 25 May 2024 10:00:23 +0200 Subject: [PATCH 02/29] Tweaking db calls for speed --- application/models/Logbook_model.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index bffe90cb9..9a2de908a 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -3372,8 +3372,14 @@ function lotw_last_qsl_date($user_id) { function import_bulk($records, $station_id = "0", $skipDuplicate = false, $markClublog = false, $markLotw = false, $dxccAdif = false, $markQrz = false, $markHrd = false,$skipexport = false, $operatorName = false, $apicall = false, $skipStationCheck = false) { $custom_errors=''; $a_qsos=[]; + if (!$this->stations->check_station_is_accessible($station_id) && $apicall == false ) { + return 'Station not accessible
'; + } + $station_id_ok = true; + $station_profile=$this->stations->profile_clean($station_id); + foreach ($records as $record) { - $one_error = $this->logbook_model->import($record, $station_id, $skipDuplicate, $markClublog, $markLotw,$dxccAdif, $markQrz, $markHrd, $skipexport, $operatorName, $apicall, $skipStationCheck, true); + $one_error = $this->logbook_model->import($record, $station_id, $skipDuplicate, $markClublog, $markLotw,$dxccAdif, $markQrz, $markHrd, $skipexport, $operatorName, $apicall, $skipStationCheck, true, $station_id_ok, $station_profile); if ($one_error['error'] ?? '' != '') { $custom_errors.=$one_error['error']."
"; } else { @@ -3395,14 +3401,18 @@ function lotw_last_qsl_date($user_id) { * $markHrd - used in ADIF import to mark QSOs as exported to HRDLog.net Logbook when importing QSOs * $skipexport - used in ADIF import to skip the realtime upload to QRZ Logbook when importing QSOs from ADIF */ - function import($record, $station_id = "0", $skipDuplicate = false, $markClublog = false, $markLotw = false, $dxccAdif = false, $markQrz = false, $markHrd = false,$skipexport = false, $operatorName = false, $apicall = false, $skipStationCheck = false, $batchmode = false) { + function import($record, $station_id = "0", $skipDuplicate = false, $markClublog = false, $markLotw = false, $dxccAdif = false, $markQrz = false, $markHrd = false,$skipexport = false, $operatorName = false, $apicall = false, $skipStationCheck = false, $batchmode = false, $station_id_ok = false, $station_profile = null) { // be sure that station belongs to user $this->load->model('stations'); - if (!$this->stations->check_station_is_accessible($station_id) && $apicall == false ) { - return 'Station not accessible
'; + if ($station_id_ok == false) { + if (!$this->stations->check_station_is_accessible($station_id) && $apicall == false) { + return 'Station not accessible
'; + } } - $station_profile=$this->stations->profile_clean($station_id); + if ($station_profile == null) { + $station_profile=$this->stations->profile_clean($station_id); + } $station_profile_call=$station_profile->station_callsign; if (($station_id !=0 ) && (!(isset($record['station_callsign'])))) { From 6d1338f4297f8e9196f0a7dfa0f22bcd715897dc Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sat, 25 May 2024 19:57:00 +0200 Subject: [PATCH 03/29] hide time in public view and show in user dateformat in dashboard --- application/models/Logbook_model.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index bffe90cb9..4ec833ffe 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -4868,7 +4868,25 @@ function lotw_last_qsl_date($user_id) { if ($row->COL_NAME != null) { $plot['html'] .= "Name: ".$row->COL_NAME."
"; } - $plot['html'] .= "Date/Time: ".$row->COL_TIME_ON."
"; + + // Get Date format + if($this->session->userdata('user_date_format')) { + // If Logged in and session exists + $user_date_format = $this->session->userdata('user_date_format'); + } else { + // Get Default date format from /config/wavelog.php + $user_date_format = $this->config->item('qso_date_format'); + } + + $qso_time_on = new DateTime($row->COL_TIME_ON); + + if ($this->uri->segment(1) == 'visitor') { + $qso_time_on = $qso_time_on->format('Y-m-d'); + } else { + $qso_time_on = $qso_time_on->format($user_date_format.' H:m:i'); + } + + $plot['html'] .= "Date/Time: ".$qso_time_on."
"; $plot['html'] .= ($row->COL_SAT_NAME != null) ? ("SAT: ".$row->COL_SAT_NAME."
") : ("Band: ".$row->COL_BAND."
"); $plot['html'] .= "Mode: ".($row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE)."
"; From 2ff5775a846e98851ee509ab26e448d575d90252 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Sat, 25 May 2024 21:24:35 +0200 Subject: [PATCH 04/29] Remove one db call for each page load --- application/models/User_model.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/application/models/User_model.php b/application/models/User_model.php index 1c567cd06..66de40a64 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -151,8 +151,8 @@ class User_Model extends CI_Model { $user_show_profile_image, $user_previous_qsl_type, $user_amsat_status_upload, $user_mastodon_url, $user_default_band, $user_default_confirmation, $user_qso_end_times, $user_quicklog, $user_quicklog_enter, $language, $user_hamsat_key, $user_hamsat_workable_only, $user_iota_to_qso_tab, $user_sota_to_qso_tab, - $user_wwff_to_qso_tab, $user_pota_to_qso_tab, $user_sig_to_qso_tab, $user_dok_to_qso_tab, - $user_lotw_name, $user_lotw_password, $user_eqsl_name, $user_eqsl_password, $user_clublog_name, $user_clublog_password, + $user_wwff_to_qso_tab, $user_pota_to_qso_tab, $user_sig_to_qso_tab, $user_dok_to_qso_tab, + $user_lotw_name, $user_lotw_password, $user_eqsl_name, $user_eqsl_password, $user_clublog_name, $user_clublog_password, $user_winkey) { // Check that the user isn't already used if(!$this->exists($username)) { @@ -403,9 +403,11 @@ class User_Model extends CI_Model { // FUNCTION: void update_session() // Updates a user's login session after they've logged in // TODO: This should return bool TRUE/FALSE or 0/1 - function update_session($id) { + function update_session($id, $u = null) { - $u = $this->get_by_id($id); + if ($u == null) { + $u = $this->get_by_id($id); + } $userdata = array( 'user_id' => $u->row()->user_id, @@ -455,7 +457,7 @@ class User_Model extends CI_Model { // FUNCTION: bool validate_session() // Validate a user's login session // If the user's session is corrupted in any way, it will clear the session - function validate_session() { + function validate_session($u = null) { if($this->session->userdata('user_id')) { @@ -466,7 +468,7 @@ class User_Model extends CI_Model { if(ENVIRONMENT != 'maintenance') { if($this->_auth($user_id."-".$user_type, $user_hash)) { // Freshen the session - $this->update_session($user_id); + $this->update_session($user_id, $u); return 1; } else { $this->clear_session(); @@ -476,7 +478,7 @@ class User_Model extends CI_Model { if($user_type == '99') { if($this->_auth($user_id."-".$user_type, $user_hash)) { // Freshen the session - $this->update_session($user_id); + $this->update_session($user_id, $u); return 1; } else { $this->clear_session(); @@ -533,7 +535,7 @@ class User_Model extends CI_Model { if($this->config->item('auth_mode') > $level) { $level = $this->config->item('auth_mode'); } - if(($this->validate_session()) && ($u->row()->user_type >= $level) || $this->config->item('use_auth') == FALSE || $level == 0) { + if(($this->validate_session($u)) && ($u->row()->user_type >= $level) || $this->config->item('use_auth') == FALSE || $level == 0) { $this->set_last_seen($u->row()->user_id); return 1; } else { From 9110d0795e70e80eafc1d1c9aebb53aa4da91892 Mon Sep 17 00:00:00 2001 From: int2001 Date: Sun, 26 May 2024 04:19:16 +0000 Subject: [PATCH 05/29] Fixes PHP8-Bug within CI3 --- system/helpers/text_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 5d5a958e2..124ea8395 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -357,7 +357,7 @@ if ( ! function_exists('highlight_code')) return str_replace( array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), array('<?', '?>', '<%', '%>', '\\', '</script>'), - $str + $str ?? '' ); } } From 5be9caa2c5dd8e8e322331ad3e09baca51e0229c Mon Sep 17 00:00:00 2001 From: int2001 Date: Sun, 26 May 2024 05:13:11 +0000 Subject: [PATCH 06/29] Refactored MODES to use ONE SQL in Constructor (reduces SQLs) --- application/models/Logbook_model.php | 29 +++++++++++++++++----------- application/models/Stations.php | 4 ++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 9a2de908a..4fce14484 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2,6 +2,18 @@ class Logbook_model extends CI_Model { + public function __construct() { + $this->oop_populate_modes(); + } + + private $oop_modes=[]; + private function oop_populate_modes() { + $r = $this->db->get('adif_modes'); + foreach($r->result_array() as $row){ + $this->oop_modes[$row['submode']][]=($row['mode'] ?? ''); + } + } + /* Add QSO to Logbook */ function create_qso() { @@ -4177,17 +4189,12 @@ function lotw_last_qsl_date($user_id) { } function get_main_mode_if_submode($mode) { - $this->db->select('mode'); - $this->db->where('submode', $mode); - - $query = $this->db->get('adif_modes'); - if ($query->num_rows() > 0){ - $row = $query->row_array(); - return $row['mode']; - } else { - return null; - } - } + if (array_key_exists($mode,$this->oop_modes)) { + return($this->oop_modes[$mode]); + } else { + return null; + } + } /* * Check the dxxc_prefixes table and return (dxcc, country) diff --git a/application/models/Stations.php b/application/models/Stations.php index 08c154d93..6c1414c4e 100644 --- a/application/models/Stations.php +++ b/application/models/Stations.php @@ -2,6 +2,10 @@ class Stations extends CI_Model { + public function __construct() { + } + + function all_with_count() { $this->db->select('station_profile.*, dxcc_entities.name as station_country, dxcc_entities.end as dxcc_end, count('.$this->config->item('table_name').'.station_id) as qso_total'); From 3e9318b88a53cb1e1d7c355c92efbc16f4ce23aa Mon Sep 17 00:00:00 2001 From: int2001 Date: Sun, 26 May 2024 05:37:46 +0000 Subject: [PATCH 07/29] Cache more results (reduces 400 Calls on 400 QSOs) --- application/models/Logbook_model.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 4fce14484..22016b748 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2,6 +2,7 @@ class Logbook_model extends CI_Model { + private $station_result=[]; public function __construct() { $this->oop_populate_modes(); } @@ -4016,15 +4017,17 @@ function lotw_last_qsl_date($user_id) { // Collect field information from the station profile table thats required for the QSO. if($station_id != "0") { + if (!(array_key_exists($station_id,$this->station_result))) { $this->db->select('station_profile.*, dxcc_entities.name as station_country'); $this->db->where('station_id', $station_id); $this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer'); - $station_result = $this->db->get('station_profile'); + $this->station_result[$station_id] = $this->db->get('station_profile'); + } - if ($station_result->num_rows() > 0){ + if ($this->station_result[$station_id]->num_rows() > 0){ $data['station_id'] = $station_id; - $row = $station_result->row_array(); + $row = $this->station_result[$station_id]->row_array(); if (strpos(trim($row['station_gridsquare']), ',') !== false) { $data['COL_MY_VUCC_GRIDS'] = strtoupper(trim($row['station_gridsquare'])); From 57bdafe2c0e1eae7153567fc7d0968ed3773c012 Mon Sep 17 00:00:00 2001 From: int2001 Date: Sun, 26 May 2024 06:02:51 +0000 Subject: [PATCH 08/29] Reduce load produced by the "CIA"-Function --- application/models/User_model.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/application/models/User_model.php b/application/models/User_model.php index 1c567cd06..cae203921 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -534,7 +534,11 @@ class User_Model extends CI_Model { $level = $this->config->item('auth_mode'); } if(($this->validate_session()) && ($u->row()->user_type >= $level) || $this->config->item('use_auth') == FALSE || $level == 0) { - $this->set_last_seen($u->row()->user_id); + $ls=new DateTime($u->row()->last_seen ?? '1971-01-01'); + $n=new DateTime("now"); + if ($ls->diff($n)->format('%s') > 60) { // Reduce load of the Spy-Function. shouldn't be called at anytimne. 60seconds diff is enough + $this->set_last_seen($u->row()->user_id); + } return 1; } else { return 0; From c26beab69cfac618ff85fa515cccb405aaff35d0 Mon Sep 17 00:00:00 2001 From: int2001 Date: Sun, 26 May 2024 06:38:19 +0000 Subject: [PATCH 09/29] More reduction. Instead of querying DXCC in a loop, fetch them via like --- application/models/Logbook_model.php | 165 ++++++++++++++------------- 1 file changed, 84 insertions(+), 81 deletions(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 22016b748..6fc8c30fd 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -4294,95 +4294,98 @@ function lotw_last_qsl_date($user_id) { public function dxcc_lookup($call, $date){ - $csadditions = '/^T$|^P$|^R$|^A$|^M$/'; + $csadditions = '/^T$|^P$|^R$|^A$|^M$/'; - $dxcc_exceptions = $this->db->select('`entity`, `adif`, `cqz`,`cont`') - ->where('call', $call) - ->where('(start <= ', $date) - ->or_where('start is null)', NULL, false) - ->where('(end >= ', $date) - ->or_where('end is null)', NULL, false) - ->get('dxcc_exceptions'); + $dxcc_exceptions = $this->db->select('`entity`, `adif`, `cqz`,`cont`') + ->where('call', $call) + ->where('(start <= ', $date) + ->or_where('start is null)', NULL, false) + ->where('(end >= ', $date) + ->or_where('end is null)', NULL, false) + ->get('dxcc_exceptions'); - if ($dxcc_exceptions->num_rows() > 0){ - $row = $dxcc_exceptions->row_array(); - return $row; - } else { + if ($dxcc_exceptions->num_rows() > 0){ + $row = $dxcc_exceptions->row_array(); + return $row; + } else { - if (preg_match('/(^KG4)[A-Z09]{3}/', $call)) { // KG4/ and KG4 5 char calls are Guantanamo Bay. If 4 or 6 char, it is USA - $call = "K"; - } elseif (preg_match('/(^OH\/)|(\/OH[1-9]?$)/', $call)) { # non-Aland prefix! - $call = "OH"; # make callsign OH = finland - } elseif (preg_match('/(^CX\/)|(\/CX[1-9]?$)/', $call)) { # non-Antarctica prefix! - $call = "CX"; # make callsign CX = Uruguay - } elseif (preg_match('/(^3D2R)|(^3D2.+\/R)/', $call)) { # seems to be from Rotuma - $call = "3D2/R"; # will match with Rotuma - } elseif (preg_match('/^3D2C/', $call)) { # seems to be from Conway Reef - $call = "3D2/C"; # will match with Conway - } elseif (preg_match('/(^LZ\/)|(\/LZ[1-9]?$)/', $call)) { # LZ/ is LZ0 by DXCC but this is VP8h - $call = "LZ"; - } elseif (preg_match('/(^KG4)[A-Z09]{2}/', $call)) { - $call = "KG4"; - } elseif (preg_match('/(^KG4)[A-Z09]{1}/', $call)) { - $call = "K"; - } elseif (preg_match('/\w\/\w/', $call)) { - if (preg_match_all('/^((\d|[A-Z])+\/)?((\d|[A-Z]){3,})(\/(\d|[A-Z])+)?(\/(\d|[A-Z])+)?$/', $call, $matches)) { - $prefix = $matches[1][0]; - $callsign = $matches[3][0]; - $suffix = $matches[5][0]; - if ($prefix) { - $prefix = substr($prefix, 0, -1); # Remove the / at the end - } - if ($suffix) { - $suffix = substr($suffix, 1); # Remove the / at the beginning - }; - if (preg_match($csadditions, $suffix)) { - if ($prefix) { - $call = $prefix; - } else { - $call = $callsign; - } - } else { - $result = $this->wpx($call, 1); # use the wpx prefix instead - if ($result == '') { - $row['adif'] = 0; - $row['cont'] = ''; - $row['entity'] = '- NONE -'; - $row['cqz'] = 0; - $row['long'] = '0'; - $row['lat'] = '0'; - return $row; - } else { - $call = $result . "AA"; - } - } - } - } + if (preg_match('/(^KG4)[A-Z09]{3}/', $call)) { // KG4/ and KG4 5 char calls are Guantanamo Bay. If 4 or 6 char, it is USA + $call = "K"; + } elseif (preg_match('/(^OH\/)|(\/OH[1-9]?$)/', $call)) { # non-Aland prefix! + $call = "OH"; # make callsign OH = finland + } elseif (preg_match('/(^CX\/)|(\/CX[1-9]?$)/', $call)) { # non-Antarctica prefix! + $call = "CX"; # make callsign CX = Uruguay + } elseif (preg_match('/(^3D2R)|(^3D2.+\/R)/', $call)) { # seems to be from Rotuma + $call = "3D2/R"; # will match with Rotuma + } elseif (preg_match('/^3D2C/', $call)) { # seems to be from Conway Reef + $call = "3D2/C"; # will match with Conway + } elseif (preg_match('/(^LZ\/)|(\/LZ[1-9]?$)/', $call)) { # LZ/ is LZ0 by DXCC but this is VP8h + $call = "LZ"; + } elseif (preg_match('/(^KG4)[A-Z09]{2}/', $call)) { + $call = "KG4"; + } elseif (preg_match('/(^KG4)[A-Z09]{1}/', $call)) { + $call = "K"; + } elseif (preg_match('/\w\/\w/', $call)) { + if (preg_match_all('/^((\d|[A-Z])+\/)?((\d|[A-Z]){3,})(\/(\d|[A-Z])+)?(\/(\d|[A-Z])+)?$/', $call, $matches)) { + $prefix = $matches[1][0]; + $callsign = $matches[3][0]; + $suffix = $matches[5][0]; + if ($prefix) { + $prefix = substr($prefix, 0, -1); # Remove the / at the end + } + if ($suffix) { + $suffix = substr($suffix, 1); # Remove the / at the beginning + }; + if (preg_match($csadditions, $suffix)) { + if ($prefix) { + $call = $prefix; + } else { + $call = $callsign; + } + } else { + $result = $this->wpx($call, 1); # use the wpx prefix instead + if ($result == '') { + $row['adif'] = 0; + $row['cont'] = ''; + $row['entity'] = '- NONE -'; + $row['cqz'] = 0; + $row['long'] = '0'; + $row['lat'] = '0'; + return $row; + } else { + $call = $result . "AA"; + } + } + } + } - $len = strlen($call); + $len = strlen($call); - // query the table, removing a character from the right until a match - for ($i = $len; $i > 0; $i--){ - //printf("searching for %s\n", substr($call, 0, $i)); - $dxcc_result = $this->db->select('*') - ->where('call', substr($call, 0, $i)) - ->where('(start <= ', $date) - ->or_where("start is null)", NULL, false) - ->where('(end >= ', $date) - ->or_where("end is null)", NULL, false) - ->get('dxcc_prefixes'); + // Fetch all candidates in one shot instead of looping + $dxcc_result = $this->db->select('*') + ->like('call', substr($call, 0, 1),'after') + ->where('(start <= ', $date) + ->or_where("start is null)", NULL, false) + ->where('(end >= ', $date) + ->or_where("end is null)", NULL, false) + ->get('dxcc_prefixes'); - //$dxcc_result = $this->db->query("select `call`, `entity`, `adif` from dxcc_prefixes where `call` = '".substr($call, 0, $i) ."'"); - //print $this->db->last_query(); + foreach($dxcc_result->result_array() as $row){ + $dxcc_array[$row['call']]=$row; + } - if ($dxcc_result->num_rows() > 0){ - $row = $dxcc_result->row_array(); - return $row; - } - } - } + // query the table, removing a character from the right until a match + for ($i = $len; $i > 0; $i--){ + //printf("searching for %s\n", substr($call, 0, $i)); + if (array_key_exists(substr($call,0,$i),$dxcc_array)) { + $row = $dxcc_array[substr($call,0,$i)]; + // $row = $dxcc_result->row_array(); + return $row; + } + } + } - return array("Not Found", "Not Found"); + return array("Not Found", "Not Found"); } function wpx($testcall, $i) { From 310362e96ca278e3cda235dc1a20fd25c54d9e49 Mon Sep 17 00:00:00 2001 From: int2001 Date: Sun, 26 May 2024 10:52:05 +0000 Subject: [PATCH 10/29] Reduced more queries (DXCC Speedup) --- application/models/Logbook_model.php | 201 ++++++++++++++------------- 1 file changed, 101 insertions(+), 100 deletions(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 6fc8c30fd..ab190a348 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -4204,106 +4204,107 @@ function lotw_last_qsl_date($user_id) { */ public function check_dxcc_table($call, $date){ - $csadditions = '/^T$|^P$|^R$|^A$|^M$/'; - - $dxcc_exceptions = $this->db->select('`entity`, `adif`, `cqz`, `cont`') - ->where('call', $call) - ->where('(start <= ', $date) - ->or_where('start is null)', NULL, false) - ->where('(end >= ', $date) - ->or_where('end is null)', NULL, false) - ->get('dxcc_exceptions'); - - if ($dxcc_exceptions->num_rows() > 0){ - $row = $dxcc_exceptions->row_array(); - return array($row['adif'], $row['entity'], $row['cqz'], $row['cont']); - } - if (preg_match('/(^KG4)[A-Z09]{3}/', $call)) { // KG4/ and KG4 5 char calls are Guantanamo Bay. If 4 or 6 char, it is USA - $call = "K"; - } elseif (preg_match('/(^OH\/)|(\/OH[1-9]?$)/', $call)) { # non-Aland prefix! - $call = "OH"; # make callsign OH = finland - } elseif (preg_match('/(^CX\/)|(\/CX[1-9]?$)/', $call)) { # non-Antarctica prefix! - $call = "CX"; # make callsign CX = Uruguay - } elseif (preg_match('/(^3D2R)|(^3D2.+\/R)/', $call)) { # seems to be from Rotuma - $call = "3D2/R"; # will match with Rotuma - } elseif (preg_match('/^3D2C/', $call)) { # seems to be from Conway Reef - $call = "3D2/C"; # will match with Conway - } elseif (preg_match('/(^LZ\/)|(\/LZ[1-9]?$)/', $call)) { # LZ/ is LZ0 by DXCC but this is VP8h - $call = "LZ"; - } elseif (preg_match('/(^KG4)[A-Z09]{2}/', $call)) { - $call = "KG4"; - } elseif (preg_match('/(^KG4)[A-Z09]{1}/', $call)) { - $call = "K"; - } elseif (preg_match('/\w\/\w/', $call)) { - if (preg_match_all('/^((\d|[A-Z])+\/)?((\d|[A-Z]){3,})(\/(\d|[A-Z])+)?(\/(\d|[A-Z])+)?$/', $call, $matches)) { - $prefix = $matches[1][0]; - $callsign = $matches[3][0]; - $suffix = $matches[5][0]; - if ($prefix) { - $prefix = substr($prefix, 0, -1); # Remove the / at the end - } - if ($suffix) { - $suffix = substr($suffix, 1); # Remove the / at the beginning - }; - if (preg_match($csadditions, $suffix)) { - if ($prefix) { - $call = $prefix; - } else { - $call = $callsign; - } - } else { - $result = $this->wpx($call, 1); # use the wpx prefix instead - if ($result == '') { - $row['adif'] = 0; - $row['entity'] = '- NONE -'; - $row['cqz'] = 0; - $row['cont'] = ''; - return array($row['adif'], $row['entity'], $row['cqz'], $row['cont']); - } else { - $call = $result . "AA"; - } - } - } - } - - $len = strlen($call); - - // query the table, removing a character from the right until a match - for ($i = $len; $i > 0; $i--){ - //printf("searching for %s\n", substr($call, 0, $i)); - $dxcc_result = $this->db->select('`call`, `entity`, `adif`, `cqz`, `cont`') - ->where('call', substr($call, 0, $i)) - ->where('(start <= ', $date) - ->or_where("start is null)", NULL, false) - ->where('(end >= ', $date) - ->or_where("end is null)", NULL, false) - ->get('dxcc_prefixes'); - - //$dxcc_result = $this->db->query("select `call`, `entity`, `adif` from dxcc_prefixes where `call` = '".substr($call, 0, $i) ."'"); - //print $this->db->last_query(); - - if ($dxcc_result->num_rows() > 0){ - $row = $dxcc_result->row_array(); - return array($row['adif'], $row['entity'], $row['cqz'], $row['cont']); - } - } - - return array("Not Found", "Not Found"); - - } - - public function dxcc_lookup($call, $date){ - $csadditions = '/^T$|^P$|^R$|^A$|^M$/'; - $dxcc_exceptions = $this->db->select('`entity`, `adif`, `cqz`,`cont`') - ->where('call', $call) + $dxcc_exceptions = $this->db->select('`entity`, `adif`, `cqz`, `cont`') + ->where('`call`', $call) ->where('(start <= ', $date) ->or_where('start is null)', NULL, false) ->where('(end >= ', $date) ->or_where('end is null)', NULL, false) ->get('dxcc_exceptions'); + if ($dxcc_exceptions->num_rows() > 0){ + $row = $dxcc_exceptions->row_array(); + return array($row['adif'], $row['entity'], $row['cqz'], $row['cont']); + } + if (preg_match('/(^KG4)[A-Z09]{3}/', $call)) { // KG4/ and KG4 5 char calls are Guantanamo Bay. If 4 or 6 char, it is USA + $call = "K"; + } elseif (preg_match('/(^OH\/)|(\/OH[1-9]?$)/', $call)) { # non-Aland prefix! + $call = "OH"; # make callsign OH = finland + } elseif (preg_match('/(^CX\/)|(\/CX[1-9]?$)/', $call)) { # non-Antarctica prefix! + $call = "CX"; # make callsign CX = Uruguay + } elseif (preg_match('/(^3D2R)|(^3D2.+\/R)/', $call)) { # seems to be from Rotuma + $call = "3D2/R"; # will match with Rotuma + } elseif (preg_match('/^3D2C/', $call)) { # seems to be from Conway Reef + $call = "3D2/C"; # will match with Conway + } elseif (preg_match('/(^LZ\/)|(\/LZ[1-9]?$)/', $call)) { # LZ/ is LZ0 by DXCC but this is VP8h + $call = "LZ"; + } elseif (preg_match('/(^KG4)[A-Z09]{2}/', $call)) { + $call = "KG4"; + } elseif (preg_match('/(^KG4)[A-Z09]{1}/', $call)) { + $call = "K"; + } elseif (preg_match('/\w\/\w/', $call)) { + if (preg_match_all('/^((\d|[A-Z])+\/)?((\d|[A-Z]){3,})(\/(\d|[A-Z])+)?(\/(\d|[A-Z])+)?$/', $call, $matches)) { + $prefix = $matches[1][0]; + $callsign = $matches[3][0]; + $suffix = $matches[5][0]; + if ($prefix) { + $prefix = substr($prefix, 0, -1); # Remove the / at the end + } + if ($suffix) { + $suffix = substr($suffix, 1); # Remove the / at the beginning + }; + if (preg_match($csadditions, $suffix)) { + if ($prefix) { + $call = $prefix; + } else { + $call = $callsign; + } + } else { + $result = $this->wpx($call, 1); # use the wpx prefix instead + if ($result == '') { + $row['adif'] = 0; + $row['entity'] = '- NONE -'; + $row['cqz'] = 0; + $row['cont'] = ''; + return array($row['adif'], $row['entity'], $row['cqz'], $row['cont']); + } else { + $call = $result . "AA"; + } + } + } + } + + $len = strlen($call); + $dxcc_array=[]; + // Fetch all candidates in one shot instead of looping + $dxcc_result=$this->db->query("SELECT `call`, `entity`, `adif`, `cqz`, `cont` + FROM `dxcc_prefixes` + WHERE ? like concat(`call`,'%') + and `call` like ? + AND (`start` <= ? OR start is null) + AND (`end` >= ? OR end is null) order by length(`call`) desc limit 1",array($call,substr($call,0,1).'%',$date,$date)); + + foreach($dxcc_result->result_array() as $row){ + $dxcc_array[$row['call']]=$row; + } + + // query the table, removing a character from the right until a match + for ($i = $len; $i > 0; $i--){ + //printf("searching for %s\n", substr($call, 0, $i)); + if (array_key_exists(substr($call,0,$i),$dxcc_array)) { + $row = $dxcc_array[substr($call,0,$i)]; + // $row = $dxcc_result->row_array(); + return array($row['adif'], $row['entity'], $row['cqz'], $row['cont']); + } + } + + return array("Not Found", "Not Found"); + + } + + public function dxcc_lookup($call, $date) { + + $csadditions = '/^T$|^P$|^R$|^A$|^M$/'; + + $dxcc_exceptions = $this->db->select('`entity`, `adif`, `cqz`,`cont`') + ->where('`call`', $call) + ->where('(start <= ', $date) + ->or_where('start is null)', NULL, false) + ->where('(end >= ', $date) + ->or_where('end is null)', NULL, false) + ->get('dxcc_exceptions'); if ($dxcc_exceptions->num_rows() > 0){ $row = $dxcc_exceptions->row_array(); return $row; @@ -4360,15 +4361,15 @@ function lotw_last_qsl_date($user_id) { } $len = strlen($call); + $dxcc_array=[]; - // Fetch all candidates in one shot instead of looping - $dxcc_result = $this->db->select('*') - ->like('call', substr($call, 0, 1),'after') - ->where('(start <= ', $date) - ->or_where("start is null)", NULL, false) - ->where('(end >= ', $date) - ->or_where("end is null)", NULL, false) - ->get('dxcc_prefixes'); + // Fetch all candidates in one shot instead of looping + $dxcc_result=$this->db->query("SELECT `call`, `entity`, `adif`, `cqz`, `cont` + FROM `dxcc_prefixes` + WHERE ? like concat(`call`,'%') + and `call` like ? + AND (`start` <= ? OR start is null) + AND (`end` >= ? OR end is null) order by length(`call`) desc limit 1",array($call,substr($call,0,1).'%',$date,$date)); foreach($dxcc_result->result_array() as $row){ $dxcc_array[$row['call']]=$row; From 090c62fece12f958ace0be63837009fd715a71a9 Mon Sep 17 00:00:00 2001 From: int2001 Date: Sun, 26 May 2024 11:41:53 +0000 Subject: [PATCH 11/29] BugFix (Take 1st Element of Mode-Array) --- application/models/Logbook_model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index ab190a348..ac8ab93a0 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -4193,7 +4193,7 @@ function lotw_last_qsl_date($user_id) { function get_main_mode_if_submode($mode) { if (array_key_exists($mode,$this->oop_modes)) { - return($this->oop_modes[$mode]); + return($this->oop_modes[$mode][0]); } else { return null; } From a4330da95a5a245b2b0a43907d515b365908744d Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Sun, 26 May 2024 20:43:28 +0200 Subject: [PATCH 12/29] Active id is already fetched, no need for db call in foreach --- application/views/adif/import.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/views/adif/import.php b/application/views/adif/import.php index 3264e66df..ae0164f52 100644 --- a/application/views/adif/import.php +++ b/application/views/adif/import.php @@ -61,7 +61,7 @@ - '.$contest['name'].''; } ?> @@ -172,7 +172,7 @@ } ?>>station_callsign; ?> (station_profile_name; ?>) -
+

@@ -218,7 +218,7 @@

-
+

From ad759c2919ee3cc989b93d536ce3762e2a73d745 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Sun, 26 May 2024 20:47:36 +0200 Subject: [PATCH 13/29] And controller is needed --- application/controllers/Adif.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/controllers/Adif.php b/application/controllers/Adif.php index 30684c4a6..966251de5 100644 --- a/application/controllers/Adif.php +++ b/application/controllers/Adif.php @@ -152,6 +152,7 @@ class adif extends CI_Controller { $station_profile = $this->stations->profile($active_station_id); $data['active_station_info'] = $station_profile->row(); + $data['active_station_id'] = $active_station_id; $this->load->view('interface_assets/header', $data); $this->load->view('adif/import'); From 7a9af010dc1bb6872ec960b33455f327c57ee292 Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 27 May 2024 06:57:03 +0200 Subject: [PATCH 14/29] Fix code formatting --- application/models/Logbook_model.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 4ec833ffe..62e93624d 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -4868,7 +4868,7 @@ function lotw_last_qsl_date($user_id) { if ($row->COL_NAME != null) { $plot['html'] .= "Name: ".$row->COL_NAME."
"; } - + // Get Date format if($this->session->userdata('user_date_format')) { // If Logged in and session exists @@ -4877,15 +4877,15 @@ function lotw_last_qsl_date($user_id) { // Get Default date format from /config/wavelog.php $user_date_format = $this->config->item('qso_date_format'); } - + $qso_time_on = new DateTime($row->COL_TIME_ON); if ($this->uri->segment(1) == 'visitor') { - $qso_time_on = $qso_time_on->format('Y-m-d'); + $qso_time_on = $qso_time_on->format('Y-m-d'); } else { $qso_time_on = $qso_time_on->format($user_date_format.' H:m:i'); } - + $plot['html'] .= "Date/Time: ".$qso_time_on."
"; $plot['html'] .= ($row->COL_SAT_NAME != null) ? ("SAT: ".$row->COL_SAT_NAME."
") : ("Band: ".$row->COL_BAND."
"); $plot['html'] .= "Mode: ".($row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE)."
"; From 55093f52deee51cd805539ae5b834097a2e98d9d Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 27 May 2024 06:57:54 +0200 Subject: [PATCH 15/29] Show time as H:i as in all other places --- application/models/Logbook_model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 62e93624d..1303a84ed 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -4883,7 +4883,7 @@ function lotw_last_qsl_date($user_id) { if ($this->uri->segment(1) == 'visitor') { $qso_time_on = $qso_time_on->format('Y-m-d'); } else { - $qso_time_on = $qso_time_on->format($user_date_format.' H:m:i'); + $qso_time_on = $qso_time_on->format($user_date_format.' H:i'); } $plot['html'] .= "Date/Time: ".$qso_time_on."
"; From 8603c1f2b5c19cfd73abf7d82e562085909198c3 Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 27 May 2024 06:59:38 +0200 Subject: [PATCH 16/29] Hide time based on config --- application/models/Logbook_model.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 1303a84ed..1c22b6c06 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -4881,7 +4881,11 @@ function lotw_last_qsl_date($user_id) { $qso_time_on = new DateTime($row->COL_TIME_ON); if ($this->uri->segment(1) == 'visitor') { - $qso_time_on = $qso_time_on->format('Y-m-d'); + $visitor_date_format = 'Y-m-d'; + if ($this->config->item('show_time')) { + $visitor_date_format .= ' H:i'; + } + $qso_time_on = $qso_time_on->format($visitor_date_format); } else { $qso_time_on = $qso_time_on->format($user_date_format.' H:i'); } From 2ff173f6592a0246b7152cc63c5013d4914bec28 Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 27 May 2024 07:00:30 +0200 Subject: [PATCH 17/29] Show time category only if time is actually shown Also use default date format from config --- application/models/Logbook_model.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 1c22b6c06..cecbe3223 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -4868,6 +4868,7 @@ function lotw_last_qsl_date($user_id) { if ($row->COL_NAME != null) { $plot['html'] .= "Name: ".$row->COL_NAME."
"; } + $date_cat = "Date"; // Get Date format if($this->session->userdata('user_date_format')) { @@ -4881,16 +4882,18 @@ function lotw_last_qsl_date($user_id) { $qso_time_on = new DateTime($row->COL_TIME_ON); if ($this->uri->segment(1) == 'visitor') { - $visitor_date_format = 'Y-m-d'; + $visitor_date_format = $this->config->item('qso_date_format'); if ($this->config->item('show_time')) { $visitor_date_format .= ' H:i'; + $date_cat .= "/Time"; } $qso_time_on = $qso_time_on->format($visitor_date_format); } else { $qso_time_on = $qso_time_on->format($user_date_format.' H:i'); + $date_cat .= "/Time"; } - $plot['html'] .= "Date/Time: ".$qso_time_on."
"; + $plot['html'] .= $date_cat.": ".$qso_time_on."
"; $plot['html'] .= ($row->COL_SAT_NAME != null) ? ("SAT: ".$row->COL_SAT_NAME."
") : ("Band: ".$row->COL_BAND."
"); $plot['html'] .= "Mode: ".($row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE)."
"; From 3ebb862ec5be61e989ad87cbc71b6e32a6f83e8a Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Mon, 27 May 2024 10:12:20 +0200 Subject: [PATCH 18/29] public map should be enabled by default --- application/views/visitor/index.php | 2 +- application/views/visitor/layout/header.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/views/visitor/index.php b/application/views/visitor/index.php index d01b2a8ca..2bdc0f09c 100644 --- a/application/views/visitor/index.php +++ b/application/views/visitor/index.php @@ -45,7 +45,7 @@ function echo_table_col($row, $name) { -optionslib->get_option('public_maps') == 'true') { ?> +optionslib->get_option('public_maps') ?? 'true' == 'true') { ?>
diff --git a/application/views/visitor/layout/header.php b/application/views/visitor/layout/header.php index 801277900..c913f8c54 100644 --- a/application/views/visitor/layout/header.php +++ b/application/views/visitor/layout/header.php @@ -62,7 +62,7 @@