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'); 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/controllers/Dashboard.php b/application/controllers/Dashboard.php index 2d5f82557..8fd6499bb 100644 --- a/application/controllers/Dashboard.php +++ b/application/controllers/Dashboard.php @@ -51,6 +51,7 @@ class Dashboard extends CI_Controller $data['current_active'] = $this->stations->find_active(); $data['themesWithoutMode'] = $this->setup_model->checkThemesWithoutMode(); + $data['dashboard_map'] = $this->optionslib->get_option('dashboard_map'); $this->load->model('cat'); $this->load->model('vucc'); diff --git a/application/controllers/Logbookadvanced.php b/application/controllers/Logbookadvanced.php index 5651509c6..d376b2536 100644 --- a/application/controllers/Logbookadvanced.php +++ b/application/controllers/Logbookadvanced.php @@ -190,6 +190,8 @@ class Logbookadvanced extends CI_Controller { } function export_to_adif() { + ini_set('memory_limit', '-1'); + set_time_limit(0); $this->load->model('logbookadvanced_model'); $ids = xss_clean($this->input->post('id')); @@ -202,6 +204,8 @@ class Logbookadvanced extends CI_Controller { } function export_to_adif_params() { + ini_set('memory_limit', '-1'); + set_time_limit(0); $this->load->model('logbookadvanced_model'); $postdata = $this->input->post(); diff --git a/application/controllers/Visitor.php b/application/controllers/Visitor.php index abcf4d6d3..4fe27ce9b 100644 --- a/application/controllers/Visitor.php +++ b/application/controllers/Visitor.php @@ -2,9 +2,14 @@ class Visitor extends CI_Controller { + // Define number of QSO per page + private $qso_per_page; + function __construct() { parent::__construct(); + + $this->qso_per_page = 25; } function _remap($method) { @@ -40,43 +45,58 @@ class Visitor extends CI_Controller { public function index($public_slug = NULL) { - $this->load->model('user_model'); - // Check slug passed and is valid - if ($this->security->xss_clean($public_slug, TRUE) === FALSE) - { + if ($this->security->xss_clean($public_slug, TRUE) === FALSE) { + // Public Slug failed the XSS test log_message('error', '[Visitor] XSS Attack detected on public_slug '. $public_slug); show_404('Unknown Public Page.'); + } else { + // Checked slug passed and clean log_message('info', '[Visitor] public_slug '. $public_slug .' loaded'); - // Check if the slug is contained in the station_logbooks table - $this->load->model('logbooks_model'); + // Load necessary models + $this->load->model('dxcc'); + $this->load->model('cat'); + $this->load->model('logbook_model'); + $this->load->model('logbooks_model'); + if($this->logbooks_model->public_slug_exists($public_slug)) { - // Load the public view + // Load the public view $logbook_id = $this->logbooks_model->public_slug_exists_logbook_id($public_slug); - if($logbook_id != false) - { + + if($logbook_id != false) { + // Get associated station locations for mysql queries $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($logbook_id); if (!$logbooks_locations_array) { show_404('Empty Logbook'); } + } else { log_message('error', $public_slug.' has no associated station locations'); show_404('Unknown Public Page.'); } - $this->load->model('logbook_model'); - // Public visitor so no QRA to setup $data['qra'] = "none"; - $this->load->model('cat'); + // Pagination Configuration + $this->load->library('pagination'); + $config['base_url'] = base_url().'index.php/visitor/'.$public_slug; + $config['total_rows'] = $this->logbook_model->total_qsos($logbooks_locations_array); + $config['per_page'] = $this->qso_per_page; + $config['num_links'] = 6; + $config['full_tag_open'] = ''; + $config['full_tag_close'] = ''; + $config['cur_tag_open'] = ''; + $config['cur_tag_close'] = ''; + + $this->pagination->initialize($config); // Store info $data['todays_qsos'] = $this->logbook_model->todays_qsos($logbooks_locations_array); @@ -92,6 +112,10 @@ class Visitor extends CI_Controller { $data['total_countries_confirmed_eqsl'] = $CountriesBreakdown['Countries_Worked_EQSL']; $data['total_countries_confirmed_lotw'] = $CountriesBreakdown['Countries_Worked_LOTW']; + $dxcc = $this->dxcc->list_current(); + $current = $this->logbook_model->total_countries_current($logbooks_locations_array); + $data['total_countries_needed'] = count($dxcc->result()) - $current; + $QSLStatsBreakdownArray =$this->logbook_model->get_QSLStats($logbooks_locations_array); $data['total_qsl_sent'] = $QSLStatsBreakdownArray['QSL_Sent']; @@ -104,21 +128,15 @@ class Visitor extends CI_Controller { $data['total_lotw_sent'] = $QSLStatsBreakdownArray['LoTW_Sent']; $data['total_lotw_rcvd'] = $QSLStatsBreakdownArray['LoTW_Received']; - $data['last_five_qsos'] = $this->logbook_model->get_last_qsos('18', $logbooks_locations_array); + $data['results'] = $this->logbook_model->get_qsos($this->qso_per_page,$this->uri->segment(3),$logbooks_locations_array); $data['page_title'] = "Dashboard"; $data['slug'] = $public_slug; - $this->load->model('dxcc'); - $dxcc = $this->dxcc->list_current(); - - $current = $this->logbook_model->total_countries_current($logbooks_locations_array); - - $data['total_countries_needed'] = count($dxcc->result()) - $current; - $this->load->view('visitor/layout/header', $data); $this->load->view('visitor/index'); $this->load->view('visitor/layout/footer'); + } else { // Show 404 log_message('error', '[Visitor] XSS Attack detected on public_slug '. $public_slug); @@ -150,7 +168,7 @@ class Visitor extends CI_Controller { show_404('Unknown Public Page.'); } - $qsos = $this->logbook_model->get_qsos('18', null, $logbooks_locations_array); + $qsos = $this->logbook_model->get_qsos($this->qso_per_page, $this->uri->segment(4), $logbooks_locations_array); // [PLOT] ADD plot // $plot_array = $this->logbook_model->get_plot_array_for_map($qsos->result()); @@ -580,4 +598,4 @@ class Visitor extends CI_Controller { return ''; } } -} +} \ No newline at end of file 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(); } } - -?> diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 55a74f3ad..bf081c32b 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2,6 +2,19 @@ class Logbook_model extends CI_Model { + private $station_result=[]; + 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() { @@ -3375,8 +3388,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 { @@ -3398,14 +3417,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'])))) { @@ -3997,15 +4020,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'])); @@ -4170,202 +4195,201 @@ 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][0]); + } else { + return null; + } + } /* * Check the dxxc_prefixes table and return (dxcc, country) */ public function check_dxcc_table($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 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"); - 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); + public function dxcc_lookup($call, $date) { - // 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'); + $csadditions = '/^T$|^P$|^R$|^A$|^M$/'; - //$dxcc_result = $this->db->query("select `call`, `entity`, `adif` from dxcc_prefixes where `call` = '".substr($call, 0, $i) ."'"); - //print $this->db->last_query(); + $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_result->num_rows() > 0){ - $row = $dxcc_result->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['cont'] = ''; + $row['entity'] = '- NONE -'; + $row['cqz'] = 0; + $row['long'] = '0'; + $row['lat'] = '0'; + return $row; + } else { + $call = $result . "AA"; + } + } + } + } - return array("Not Found", "Not Found"); + $len = strlen($call); + $dxcc_array=[]; - } + // Fetch all candidates in one shot instead of looping + $dxcc_result=$this->db->query("SELECT * + 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)); - public function dxcc_lookup($call, $date){ + foreach($dxcc_result->result_array() as $row){ + $dxcc_array[$row['call']]=$row; + } - $csadditions = '/^T$|^P$|^R$|^A$|^M$/'; + // 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; + } + } + } - $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 (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); - - // 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'); - - //$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 $row; - } - } - } - - return array("Not Found", "Not Found"); + return array("Not Found", "Not Found"); } function wpx($testcall, $i) { @@ -4871,7 +4895,32 @@ 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."
"; + $date_cat = "Date"; + + // 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') { + $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_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)."
"; 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'); diff --git a/application/models/User_model.php b/application/models/User_model.php index 1c567cd06..d10c76c7e 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,8 +535,12 @@ 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) { - $this->set_last_seen($u->row()->user_id); + if(($this->validate_session($u)) && ($u->row()->user_type >= $level) || $this->config->item('use_auth') == FALSE || $level == 0) { + $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; 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 @@

-
+

diff --git a/application/views/dashboard/index.php b/application/views/dashboard/index.php index a00b5d49a..5dca5035a 100644 --- a/application/views/dashboard/index.php +++ b/application/views/dashboard/index.php @@ -30,12 +30,12 @@ function echo_table_col($row, $name) { case 'SOTA': echo '' . ($row->COL_SOTA_REF) . ''; break; case 'WWFF': echo '' . ($row->COL_WWFF_REF) . ''; break; case 'POTA': echo '' . ($row->COL_POTA_REF) . ''; break; - case 'Grid': + case 'Grid': $ci->load->library('qra'); echo '' . ($ci->qra->echoQrbCalcLink($row->station_gridsquare, $row->COL_VUCC_GRIDS, $row->COL_GRIDSQUARE)) . ''; break; case 'Distance': echo '' . ($row->COL_DISTANCE ? $row->COL_DISTANCE . ' km' : '') . ''; break; case 'Band': echo ''; if($row->COL_SAT_NAME != null) { echo ''.$row->COL_SAT_NAME.''; } else { echo strtolower($row->COL_BAND); } echo ''; break; - case 'Frequency': + case 'Frequency': $ci->load->library('frequency'); echo ''; if($row->COL_SAT_NAME != null) { echo ''.$row->COL_SAT_NAME.''; } else { if($row->COL_FREQ != null) { echo $ci->frequency->hz_to_mhz($row->COL_FREQ); } else { echo strtolower($row->COL_BAND); } } echo ''; break; case 'State': echo '' . ($row->COL_STATE) . ''; break; @@ -114,7 +114,7 @@ function echo_table_col($row, $name) { -optionslib->get_option('dashboard_map') != "false" && $this->optionslib->get_option('dashboard_map') != "map_at_right") { ?> +
@@ -184,7 +184,7 @@ function echo_table_col($row, $name) {
- optionslib->get_option('dashboard_map') == "map_at_right") { ?> +
@@ -192,7 +192,7 @@ function echo_table_col($row, $name) {
- + diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index c81034465..01a6b7152 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -15,12 +15,14 @@ - optionslib->get_theme()) { ?> - + optionslib->get_theme(); + if ($theme) { ?> + - + diff --git a/application/views/visitor/index.php b/application/views/visitor/index.php index d01b2a8ca..c4f92166b 100644 --- a/application/views/visitor/index.php +++ b/application/views/visitor/index.php @@ -1,42 +1,125 @@ '.$ctx->lang->line('gen_hamradio_mode').''; break; - case 'RSTS': echo ''; break; - case 'RSTR': echo ''; break; - case 'Country': echo ''; break; - case 'IOTA': echo ''; break; - case 'SOTA': echo ''; break; - case 'State': echo ''; break; - case 'Grid': echo ''; break; - case 'Distance': echo ''; break; - case 'Band': echo ''; break; - case 'Frequency': echo ''; break; - case 'Operator': echo ''; break; +function echo_table_header_col($ctx, $name) +{ + switch ($name) { + case 'Mode': + echo ''; + break; + case 'RSTS': + echo ''; + break; + case 'RSTR': + echo ''; + break; + case 'Country': + echo ''; + break; + case 'IOTA': + echo ''; + break; + case 'SOTA': + echo ''; + break; + case 'State': + echo ''; + break; + case 'Grid': + echo ''; + break; + case 'Distance': + echo ''; + break; + case 'Band': + echo ''; + break; + case 'Frequency': + echo ''; + break; + case 'Operator': + echo ''; + break; } } -function echo_table_col($row, $name) { - $ci =& get_instance(); - switch($name) { - case 'Mode': echo ''; break; - case 'RSTS': echo ''; break; - case 'RSTR': echo ''; break; - case 'Country': echo ''; break; - case 'IOTA': echo ''; break; - case 'SOTA': echo ''; break; - case 'WWFF': echo ''; break; - case 'POTA': echo ''; break; - case 'Grid': - $ci->load->library('qra'); - echo ''; break; - case 'Distance':echo ''; break; - case 'Band': echo ''; } else { echo strtolower($row->COL_BAND); } echo ''; break; - case 'Frequency': - $ci->load->library('frequency'); - echo ''; break; - case 'State': echo ''; break; - case 'Operator': echo ''; break; +function echo_table_col($row, $name) +{ + $CI = &get_instance(); + switch ($name) { + case 'Mode': + echo ''; + break; + case 'RSTS': + echo ''; + break; + case 'RSTR': + echo ''; + break; + case 'Country': + echo ''; + break; + case 'IOTA': + echo ''; + break; + case 'SOTA': + echo ''; + break; + case 'WWFF': + echo ''; + break; + case 'POTA': + echo ''; + break; + case 'Grid': + $CI->load->library('qra'); + echo ''; + break; + case 'Distance': + echo ''; + break; + case 'Band': + echo ''; + } else { + echo strtolower($row->COL_BAND); + } + echo ''; + break; + case 'Frequency': + $CI->load->library('frequency'); + echo ''; + break; + case 'State': + echo ''; + break; + case 'Operator': + echo ''; + break; } } @@ -45,188 +128,214 @@ function echo_table_col($row, $name) { -optionslib->get_option('public_maps') == 'true') { ?> +optionslib->get_option('public_maps') ?? 'true'; +if ($public_maps_option == 'true') { ?>
- -
-
+ +
+
+
+
'.$ctx->lang->line('gen_hamradio_rsts').''.$ctx->lang->line('gen_hamradio_rstr').''.$ctx->lang->line('general_word_country').''.$ctx->lang->line('gen_hamradio_iota').''.$ctx->lang->line('gen_hamradio_sota').''.$ctx->lang->line('gen_hamradio_state').''.$ctx->lang->line('gen_hamradio_gridsquare').''.$ctx->lang->line('gen_hamradio_distance').''.$ctx->lang->line('gen_hamradio_band').''.$ctx->lang->line('gen_hamradio_frequency').''.$ctx->lang->line('gen_hamradio_operator').'' . $ctx->lang->line('gen_hamradio_mode') . '' . $ctx->lang->line('gen_hamradio_rsts') . '' . $ctx->lang->line('gen_hamradio_rstr') . '' . $ctx->lang->line('general_word_country') . '' . $ctx->lang->line('gen_hamradio_iota') . '' . $ctx->lang->line('gen_hamradio_sota') . '' . $ctx->lang->line('gen_hamradio_state') . '' . $ctx->lang->line('gen_hamradio_gridsquare') . '' . $ctx->lang->line('gen_hamradio_distance') . '' . $ctx->lang->line('gen_hamradio_band') . '' . $ctx->lang->line('gen_hamradio_frequency') . '' . $ctx->lang->line('gen_hamradio_operator') . ''; echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE . '' . $row->COL_RST_SENT; if ($row->COL_STX) { echo ' COL_CONTEST_ID:"n/a").'" class="badge text-bg-light">'; printf("%03d", $row->COL_STX); echo '';} if ($row->COL_STX_STRING) { echo ' COL_CONTEST_ID:"n/a").'" class="badge text-bg-light">' . $row->COL_STX_STRING . '';} echo '' . $row->COL_RST_RCVD; if ($row->COL_SRX) { echo ' COL_CONTEST_ID:"n/a").'" class="badge text-bg-light">'; printf("%03d", $row->COL_SRX); echo '';} if ($row->COL_SRX_STRING) { echo ' COL_CONTEST_ID:"n/a").'" class="badge text-bg-light">' . $row->COL_SRX_STRING . '';} echo '' . ucwords(strtolower(($row->COL_COUNTRY))) . '' . ($row->COL_IOTA) . '' . ($row->COL_SOTA_REF) . '' . ($row->COL_WWFF_REF) . '' . ($row->COL_POTA_REF) . '' . ($ci->qra->echoQrbCalcLink($row->station_gridsquare, $row->COL_VUCC_GRIDS, $row->COL_GRIDSQUARE, true)) . '' . ($row->COL_DISTANCE ? $row->COL_DISTANCE . ' km' : '') . ''; if($row->COL_SAT_NAME != null) { echo ''.$row->COL_SAT_NAME.''; if($row->COL_FREQ != null) { echo $ci->frequency->hz_to_mhz($row->COL_FREQ); } else { echo strtolower($row->COL_BAND); } echo '' . ($row->COL_STATE) . '' . ($row->COL_OPERATOR) . ''; + echo $row->COL_SUBMODE == null ? $row->COL_MODE : $row->COL_SUBMODE . '' . $row->COL_RST_SENT; + if ($row->COL_STX) { + echo ' COL_CONTEST_ID : "n/a") . '" class="badge text-bg-light">'; + printf("%03d", $row->COL_STX); + echo ''; + } + if ($row->COL_STX_STRING) { + echo ' COL_CONTEST_ID : "n/a") . '" class="badge text-bg-light">' . $row->COL_STX_STRING . ''; + } + echo '' . $row->COL_RST_RCVD; + if ($row->COL_SRX) { + echo ' COL_CONTEST_ID : "n/a") . '" class="badge text-bg-light">'; + printf("%03d", $row->COL_SRX); + echo ''; + } + if ($row->COL_SRX_STRING) { + echo ' COL_CONTEST_ID : "n/a") . '" class="badge text-bg-light">' . $row->COL_SRX_STRING . ''; + } + echo '' . ucwords(strtolower(($row->COL_COUNTRY))) . '' . ($row->COL_IOTA) . '' . ($row->COL_SOTA_REF) . '' . ($row->COL_WWFF_REF) . '' . ($row->COL_POTA_REF) . '' . ($CI->qra->echoQrbCalcLink($row->station_gridsquare, $row->COL_VUCC_GRIDS, $row->COL_GRIDSQUARE, true)) . '' . ($row->COL_DISTANCE ? $row->COL_DISTANCE . ' km' : '') . ''; + if ($row->COL_SAT_NAME != null) { + echo '' . $row->COL_SAT_NAME . ''; + if ($row->COL_FREQ != null) { + echo $CI->frequency->hz_to_mhz($row->COL_FREQ); + } else { + echo strtolower($row->COL_BAND); + } + echo '' . ($row->COL_STATE) . '' . ($row->COL_OPERATOR) . '
+ + + -
-
+ config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE || ($this->config->item('show_time'))) { ?> + + + + session->userdata('user_column1') == "" ? 'Mode' : $this->session->userdata('user_column1')); + echo_table_header_col($this, $this->session->userdata('user_column2') == "" ? 'RSTS' : $this->session->userdata('user_column2')); + echo_table_header_col($this, $this->session->userdata('user_column3') == "" ? 'RSTR' : $this->session->userdata('user_column3')); + echo_table_header_col($this, $this->session->userdata('user_column4') == "" ? 'Band' : $this->session->userdata('user_column4')); + ?> + + + + 0) { + foreach ($results->result() as $row) { ?> + '; ?> - - - + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE || ($this->config->item('show_time'))) { ?> - - - - session->userdata('user_column1')==""?'Mode':$this->session->userdata('user_column1')); - echo_table_header_col($this, $this->session->userdata('user_column2')==""?'RSTS':$this->session->userdata('user_column2')); - echo_table_header_col($this, $this->session->userdata('user_column3')==""?'RSTR':$this->session->userdata('user_column3')); - echo_table_header_col($this, $this->session->userdata('user_column4')==""?'Band':$this->session->userdata('user_column4')); + // Get Date format + if ($this->session->userdata('user_date_format')) { + // If Logged in and session exists + $custom_date_format = $this->session->userdata('user_date_format'); + } else { + // Get Default date format from /config/wavelog.php + $custom_date_format = $this->config->item('qso_date_format'); + } + + ?> + + + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE || ($this->config->item('show_time'))) { ?> + + + + + session->userdata('user_column1') == "" ? 'Mode' : $this->session->userdata('user_column1')); + echo_table_col($row, $this->session->userdata('user_column2') == "" ? 'RSTS' : $this->session->userdata('user_column2')); + echo_table_col($row, $this->session->userdata('user_column3') == "" ? 'RSTR' : $this->session->userdata('user_column3')); + echo_table_col($row, $this->session->userdata('user_column4') == "" ? 'Band' : $this->session->userdata('user_column4')); + ?> + + + +
COL_TIME_ON); + echo date($custom_date_format, $timestamp); ?>COL_TIME_ON); + echo date('H:i', $timestamp); ?> + COL_CALL)); ?> +
+
+ pagination)) { ?> + '; + $config['full_tag_close'] = ''; + $config['attributes'] = ['class' => 'page-link']; + $config['first_link'] = false; + $config['last_link'] = false; + $config['first_tag_open'] = '
  • '; + $config['first_tag_close'] = '
  • '; + $config['prev_link'] = '«'; + $config['prev_tag_open'] = '
  • '; + $config['prev_tag_close'] = '
  • '; + $config['next_link'] = '»'; + $config['next_tag_open'] = '
  • '; + $config['next_tag_close'] = '
  • '; + $config['last_tag_open'] = '
  • '; + $config['last_tag_close'] = '
  • '; + $config['cur_tag_open'] = '
  • '; + $config['cur_tag_close'] = '(current)
  • '; + $config['num_tag_open'] = '
  • '; + $config['num_tag_close'] = '
  • '; + $this->pagination->initialize($config); ?> - - - 0) { - foreach ($last_five_qsos->result() as $row) { ?> - '; ?> + pagination->create_links(); ?> - + - // Get Date format - if($this->session->userdata('user_date_format')) { - // If Logged in and session exists - $custom_date_format = $this->session->userdata('user_date_format'); - } else { - // Get Default date format from /config/wavelog.php - $custom_date_format = $this->config->item('qso_date_format'); - } +
    +
    + + + + - ?> + + + + - - config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE || ($this->config->item('show_time'))) { ?> - + + + + - - - session->userdata('user_column1')==""?'Mode':$this->session->userdata('user_column1')); - echo_table_col($row, $this->session->userdata('user_column2')==""?'RSTS':$this->session->userdata('user_column2')); - echo_table_col($row, $this->session->userdata('user_column3')==""?'RSTR':$this->session->userdata('user_column3')); - echo_table_col($row, $this->session->userdata('user_column4')==""?'Band':$this->session->userdata('user_column4')); - ?> - - -
    COL_TIME_ON); echo date($custom_date_format, $timestamp); ?>COL_TIME_ON); echo date('H:i', $timestamp); ?>
    - COL_CALL)); ?> -
    + + + + + + + + + + + + + + + + + + + + + + + + +
    + / + / + +
    + + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE) && ($total_qsl_sent != 0 || $total_qsl_rcvd != 0 || $total_qsl_requested != 0)) { ?> + + + + + + + + + + + + + + + + + + + +
    + + + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE) && ($total_eqsl_sent != 0 || $total_eqsl_rcvd != 0)) { ?> + + + + + + + + + + + + + + +
    + + + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE) && ($total_lotw_sent != 0 || $total_lotw_rcvd != 0)) { ?> + + + + + + + + + + + + + + +
    + +
    +
    - - -
    -
    - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - -
    - / - / - -
    - - config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE) && ($total_qsl_sent != 0 || $total_qsl_rcvd != 0 || $total_qsl_requested != 0)) { ?> - - - - - - - - - - - - - - - - - - - -
    - - - config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE) && ($total_eqsl_sent != 0 || $total_eqsl_rcvd != 0)) { ?> - - - - - - - - - - - - - - -
    - - - config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE) && ($total_lotw_sent != 0 || $total_lotw_rcvd != 0)) { ?> - - - - - - - - - - - - - - -
    - -
    -
    - - -
    +
    \ No newline at end of file diff --git a/application/views/visitor/layout/footer.php b/application/views/visitor/layout/footer.php index d4a767cf0..1954e96c8 100644 --- a/application/views/visitor/layout/footer.php +++ b/application/views/visitor/layout/footer.php @@ -36,7 +36,7 @@ - var qso_loc = ''; + var qso_loc = 'uri->segment(3));?>'; var q_zoom = 3; diff --git a/application/views/visitor/layout/header.php b/application/views/visitor/layout/header.php index 67d81086f..0d0cc866b 100644 --- a/application/views/visitor/layout/header.php +++ b/application/views/visitor/layout/header.php @@ -62,7 +62,8 @@