From 40412354e497aab45808bd02170922829194097b Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Fri, 5 May 2023 09:34:32 +0200 Subject: [PATCH 1/9] [eQSL] Added cron job --- application/controllers/Eqsl.php | 671 ++++++++++++----------- application/models/Eqslmethods_model.php | 55 ++ application/models/Logbook_model.php | 41 +- 3 files changed, 398 insertions(+), 369 deletions(-) diff --git a/application/controllers/Eqsl.php b/application/controllers/Eqsl.php index 18f6f7aa..5f1d6beb 100644 --- a/application/controllers/Eqsl.php +++ b/application/controllers/Eqsl.php @@ -3,8 +3,7 @@ class eqsl extends CI_Controller { /* Controls who can access the controller and its functions */ - function __construct() - { + function __construct() { parent::__construct(); $this->load->helper(array('form', 'url')); @@ -29,7 +28,7 @@ class eqsl extends CI_Controller { $this->load->library('upload', $config); - $this->load->model('logbook_model'); + $this->load->model('eqslmethods_model'); $eqsl_results = array(); if ($this->input->post('eqslimport') == 'fetch') @@ -100,17 +99,16 @@ class eqsl extends CI_Controller { ini_set('memory_limit', '-1'); set_time_limit(0); - $this->load->model('logbook_model'); + $this->load->model('eqslmethods_model'); $data['page_title'] = "eQSL QSO Upload"; $custom_date_format = $this->session->userdata('user_date_format'); - if ($this->input->post('eqslexport') == "export") - { + if ($this->input->post('eqslexport') == "export") { // Get credentials for eQSL $query = $this->user_model->get_by_id($this->session->userdata('user_id')); - $q = $query->row(); - $data['user_eqsl_name'] = $q->user_eqsl_name; + $q = $query->row(); + $data['user_eqsl_name'] = $q->user_eqsl_name; $data['user_eqsl_password'] = $q->user_eqsl_password; // Validate that eQSL credentials are not empty @@ -121,8 +119,8 @@ class eqsl extends CI_Controller { // Grab the list of QSOs to send information about // perform an HTTP get on each one, and grab the status back - $qslsnotsent = $this->logbook_model->eqsl_not_yet_sent(); - + $qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent(); + $table = ""; $table .= ""; $table .= ""; @@ -133,335 +131,40 @@ class eqsl extends CI_Controller { $table .= ""; $table .= ""; $table .= ""; - // Build out the ADIF info string according to specs http://eqsl.cc/qslcard/ADIFContentSpecs.cfm - foreach ($qslsnotsent->result_array() as $qsl) - { + + foreach ($qslsnotsent->result_array() as $qsl) { + // eQSL username changes for linked account. // i.e. when operating /P it must be callsign/p // the password, however, is always the same as the main account $data['user_eqsl_name'] = $qsl['station_callsign']; + $adif = $this->generateAdif($qsl, $data); + + $status = $this->uploadQso($adif); - $COL_QSO_DATE = date('Ymd',strtotime($qsl['COL_TIME_ON'])); - $COL_TIME_ON = date('Hi',strtotime($qsl['COL_TIME_ON'])); - - # Set up the single record file - $adif = "http://www.eqsl.cc/qslcard/importADIF.cfm?"; - $adif .= "ADIFData=CloudlogUpload%20"; - - /* Handy reference of escaping chars - "<" = 3C - ">" = 3E - ":" = 3A - " " = 20 - "_" = 5F - "-" = 2D - "." = 2E - */ - - $adif .= "%3C"; - $adif .= "ADIF%5FVER"; - $adif .= "%3A"; - $adif .= "4"; - $adif .= "%3E"; - $adif .= "1%2E00 "; - $adif .= "%20"; - - $adif .= "%3C"; - $adif .= "EQSL%5FUSER"; - $adif .= "%3A"; - $adif .= strlen($data['user_eqsl_name']); - $adif .= "%3E"; - $adif .= $data['user_eqsl_name']; - $adif .= "%20"; - - $adif .= "%3C"; - $adif .= "EQSL%5FPSWD"; - $adif .= "%3A"; - $adif .= strlen($data['user_eqsl_password']); - $adif .= "%3E"; - $adif .= urlencode($data['user_eqsl_password']); - $adif .= "%20"; - - $adif .= "%3C"; - $adif .= "EOH"; - $adif .= "%3E"; - - # Lay out the required fields - $adif .= "%3C"; - $adif .= "QSO%5FDATE"; - $adif .= "%3A"; - $adif .= "8"; - $adif .= "%3E"; - $adif .= $COL_QSO_DATE; - $adif .= "%20"; - - $adif .= "%3C"; - $adif .= "TIME%5FON"; - $adif .= "%3A"; - $adif .= "4"; - $adif .= "%3E"; - $adif .= $COL_TIME_ON; - $adif .= "%20"; - - $adif .= "%3C"; - $adif .= "CALL"; - $adif .= "%3A"; - $adif .= strlen($qsl['COL_CALL']); - $adif .= "%3E"; - $adif .= $qsl['COL_CALL']; - $adif .= "%20"; - - $adif .= "%3C"; - $adif .= "MODE"; - $adif .= "%3A"; - $adif .= strlen($qsl['COL_MODE']); - $adif .= "%3E"; - $adif .= $qsl['COL_MODE']; - $adif .= "%20"; - - if(isset($qsl['COL_SUBMODE'])) { - $adif .= "%3C"; - $adif .= "SUBMODE"; - $adif .= "%3A"; - $adif .= strlen($qsl['COL_SUBMODE']); - $adif .= "%3E"; - $adif .= $qsl['COL_SUBMODE']; - $adif .= "%20"; - } - - $adif .= "%3C"; - $adif .= "BAND"; - $adif .= "%3A"; - $adif .= strlen($qsl['COL_BAND']); - $adif .= "%3E"; - $adif .= $qsl['COL_BAND']; - $adif .= "%20"; - - # End all the required fields - - - // adding RST_Sent - $adif .= "%3C"; - $adif .= "RST%5FSENT"; - $adif .= "%3A"; - $adif .= strlen($qsl['COL_RST_SENT']); - $adif .= "%3E"; - $adif .= $qsl['COL_RST_SENT']; - $adif .= "%20"; - - // adding prop mode if it isn't blank - if ($qsl['COL_PROP_MODE']){ - $adif .= "%3C"; - $adif .= "PROP%5FMODE"; - $adif .= "%3A"; - $adif .= strlen($qsl['COL_PROP_MODE']); - $adif .= "%3E"; - $adif .= $qsl['COL_PROP_MODE']; - $adif .= "%20"; - } - - // adding sat name if it isn't blank - if ($qsl['COL_SAT_NAME'] != ''){ - $adif .= "%3C"; - $adif .= "SAT%5FNAME"; - $adif .= "%3A"; - $adif .= strlen($qsl['COL_SAT_NAME']); - $adif .= "%3E"; - $adif .= str_replace('-', '%2D', $qsl['COL_SAT_NAME']); - $adif .= "%20"; - } - - // adding sat mode if it isn't blank - if ($qsl['COL_SAT_MODE'] != ''){ - $adif .= "%3C"; - $adif .= "SAT%5FMODE"; - $adif .= "%3A"; - $adif .= strlen($qsl['COL_SAT_MODE']); - $adif .= "%3E"; - $adif .= $qsl['COL_SAT_MODE']; - $adif .= "%20"; - } - - // adding qslmsg if it isn't blank - if ($qsl['COL_QSLMSG'] != ''){ - $adif .= "%3C"; - $adif .= "QSLMSG"; - $adif .= "%3A"; - $adif .= strlen($qsl['COL_QSLMSG']); - $adif .= "%3E"; - $adif .= $qsl['COL_QSLMSG']; - $adif .= "%20"; - } - - if ($qsl['eqslqthnickname'] != ''){ - $adif .= "%3C"; - $adif .= "APP%5FEQSL%5FQTH%5FNICKNAME"; - $adif .= "%3A"; - $adif .= strlen($qsl['eqslqthnickname']); - $adif .= "%3E"; - $adif .= $qsl['eqslqthnickname']; - $adif .= "%20"; - } - - // adding sat mode if it isn't blank - if ($qsl['station_gridsquare'] != ''){ - $adif .= "%3C"; - $adif .= "MY%5FGRIDSQUARE"; - $adif .= "%3A"; - $adif .= strlen($qsl['station_gridsquare']); - $adif .= "%3E"; - $adif .= $qsl['station_gridsquare']; - $adif .= "%20"; - } - - - # Tie a bow on it! - $adif .= "%3C"; - $adif .= "EOR"; - $adif .= "%3E"; - - # Make sure we don't have any spaces - $adif = str_replace(" ", '%20', $adif); - - $status = ""; - - // begin script - $ch = curl_init(); - - // basic curl options for all requests - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_HEADER, 1); - - // use the URL we built - curl_setopt($ch, CURLOPT_URL, $adif); - - $result = curl_exec($ch); - $chi = curl_getinfo($ch); - curl_close($ch); - - - /* Time for some error handling - Things we might get back - Result: 0 out of 0 records added -> eQSL didn't understand the format - Result: 1 out of 1 records added -> Fantastic - Error: No match on eQSL_User/eQSL_Pswd -> eQSL credentials probably wrong - Warning: Y=2013 M=08 D=11 F6ARS 15M JT65 Bad record: Duplicate - Result: 0 out of 1 records added -> Dupe, OM! - */ - - if ($chi['http_code'] == "200") - { - if (stristr($result, "Result: 1 out of 1 records added")) - { - $status = "Sent"; - $this->logbook_model->eqsl_mark_sent($qsl['COL_PRIMARY_KEY']); - } - else - { - if (stristr($result, "Error: No match on eQSL_User/eQSL_Pswd")) - { - $this->session->set_flashdata('warning', 'Your eQSL username and/or password is incorrect.'); redirect('eqsl/export'); - } - else - { - if (stristr($result, "Result: 0 out of 0 records added")) - { - $this->session->set_flashdata('warning', 'Something went wrong with eQSL.cc!'); redirect('eqsl/export'); - } - else - { - if (stristr($result, "Bad record: Duplicate")) - { - $status = "Duplicate"; - - # Mark the QSL as sent if this is a dupe. - $this->logbook_model->eqsl_mark_sent($qsl['COL_PRIMARY_KEY']); - } - } - } - } - } - else - { - if ($chi['http_code'] == "500") - { - $this->session->set_flashdata('warning', 'eQSL.cc is experiencing issues. Please try exporting QSOs later.'); redirect('eqsl/export'); - } - else - { - if ($chi['http_code'] == "400") - { - $this->session->set_flashdata('warning', 'There was an error in one of the QSOs. You might want to manually upload them.'); redirect('eqsl/export'); - $status = "Error"; - } - else - { - if ($chi['http_code'] == "404") - { - $this->session->set_flashdata('warning', 'It seems that the eQSL site has changed. Please open up an issue on GitHub.'); redirect('eqsl/export'); - } - } - } - } $table .= ""; - $timestamp = strtotime($qsl['COL_TIME_ON']); - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - if(isset($qsl['COL_SUBMODE'])) { - $table .= ""; - } else { - $table .= ""; - } - $table .= ""; - $table .= ""; + $timestamp = strtotime($qsl['COL_TIME_ON']); + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + if(isset($qsl['COL_SUBMODE'])) { + $table .= ""; + } else { + $table .= ""; + } + $table .= ""; + $table .= ""; $table .= ""; } $table .= "
DateBandResult
".date($custom_date_format, $timestamp)."".date('H:i', $timestamp)."".str_replace("0","Ø",$qsl['COL_CALL'])."".$qsl['COL_MODE']."".$qsl['COL_SUBMODE']."".$qsl['COL_BAND']."".$status."".date($custom_date_format, $timestamp)."".date('H:i', $timestamp)."".str_replace("0","Ø",$qsl['COL_CALL'])."".$qsl['COL_MODE']."".$qsl['COL_SUBMODE']."".$qsl['COL_BAND']."".$status."
"; // Dump out a table with the results $data['eqsl_results_table'] = $table; - log_message('debug', $result); - } - else - { - $qslsnotsent = $this->logbook_model->eqsl_not_yet_sent(); - - if ($qslsnotsent->num_rows() > 0) - { - $table = ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - - foreach ($qslsnotsent->result_array() as $qsl) - { - $table .= ""; - $timestamp = strtotime($qsl['COL_TIME_ON']); - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - - if(isset($qsl['COL_SUBMODE'])) { - $table .= ""; - } else { - $table .= ""; - } - $table .= ""; - $table .= ""; - $table .= ""; - } - $table .= "
DateTimeCallModeSubmodeBandeQSL QTH Nickname
".date($custom_date_format, $timestamp)."".date('H:i', $timestamp)."" . str_replace("0","Ø",strtoupper($qsl['COL_CALL'])) . "".$qsl['COL_MODE']."".$qsl['COL_SUBMODE']."".$qsl['COL_BAND']."".$qsl['eqslqthnickname']."
"; - - $data['eqsl_table'] = $table; + } else { + $qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent(); + if ($qslsnotsent->num_rows() > 0) { + $data['eqsl_table'] = $this->writeEqslNotSent($qslsnotsent->result_array(), $custom_date_format); } } @@ -470,6 +173,290 @@ class eqsl extends CI_Controller { $this->load->view('interface_assets/footer'); } + function uploadQso($adif) { + $status = ""; + + // begin script + $ch = curl_init(); + + // basic curl options for all requests + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HEADER, 1); + + // use the URL we built + curl_setopt($ch, CURLOPT_URL, $adif); + + $result = curl_exec($ch); + $chi = curl_getinfo($ch); + curl_close($ch); + + /* Time for some error handling + Things we might get back + Result: 0 out of 0 records added -> eQSL didn't understand the format + Result: 1 out of 1 records added -> Fantastic + Error: No match on eQSL_User/eQSL_Pswd -> eQSL credentials probably wrong + Warning: Y=2013 M=08 D=11 F6ARS 15M JT65 Bad record: Duplicate + Result: 0 out of 1 records added -> Dupe, OM! + */ + + if ($chi['http_code'] == "200") { + if (stristr($result, "Result: 1 out of 1 records added")) { + $status = "Sent"; + $this->eqsl_mark_sent->eqsl_mark_sent($qsl['COL_PRIMARY_KEY']); + } else { + if (stristr($result, "Error: No match on eQSL_User/eQSL_Pswd")) { + $this->session->set_flashdata('warning', 'Your eQSL username and/or password is incorrect.'); redirect('eqsl/export'); + } else { + if (stristr($result, "Result: 0 out of 0 records added")) { + $this->session->set_flashdata('warning', 'Something went wrong with eQSL.cc!'); redirect('eqsl/export'); + } else { + if (stristr($result, "Bad record: Duplicate")) { + $status = "Duplicate"; + + # Mark the QSL as sent if this is a dupe. + $this->eqsl_mark_sent->eqsl_mark_sent($qsl['COL_PRIMARY_KEY']); + } + } + } + } + } else { + if ($chi['http_code'] == "500") { + $this->session->set_flashdata('warning', 'eQSL.cc is experiencing issues. Please try exporting QSOs later.'); redirect('eqsl/export'); + } else { + if ($chi['http_code'] == "400") { + $this->session->set_flashdata('warning', 'There was an error in one of the QSOs. You might want to manually upload them.'); redirect('eqsl/export'); + $status = "Error"; + } else { + if ($chi['http_code'] == "404") { + $this->session->set_flashdata('warning', 'It seems that the eQSL site has changed. Please open up an issue on GitHub.'); redirect('eqsl/export'); + } + } + } + } + log_message('debug', $result); + return $status; + } + + // Build out the ADIF info string according to specs http://eqsl.cc/qslcard/ADIFContentSpecs.cfm + function generateAdif($qsl, $data) { + $COL_QSO_DATE = date('Ymd',strtotime($qsl['COL_TIME_ON'])); + $COL_TIME_ON = date('Hi',strtotime($qsl['COL_TIME_ON'])); + + # Set up the single record file + $adif = "http://www.eqsl.cc/qslcard/importADIF.cfm?"; + $adif .= "ADIFData=CloudlogUpload%20"; + + /* Handy reference of escaping chars + "<" = 3C + ">" = 3E + ":" = 3A + " " = 20 + "_" = 5F + "-" = 2D + "." = 2E + */ + + $adif .= "%3C"; + $adif .= "ADIF%5FVER"; + $adif .= "%3A"; + $adif .= "4"; + $adif .= "%3E"; + $adif .= "1%2E00 "; + $adif .= "%20"; + + $adif .= "%3C"; + $adif .= "EQSL%5FUSER"; + $adif .= "%3A"; + $adif .= strlen($data['user_eqsl_name']); + $adif .= "%3E"; + $adif .= $data['user_eqsl_name']; + $adif .= "%20"; + + $adif .= "%3C"; + $adif .= "EQSL%5FPSWD"; + $adif .= "%3A"; + $adif .= strlen($data['user_eqsl_password']); + $adif .= "%3E"; + $adif .= urlencode($data['user_eqsl_password']); + $adif .= "%20"; + + $adif .= "%3C"; + $adif .= "EOH"; + $adif .= "%3E"; + + # Lay out the required fields + $adif .= "%3C"; + $adif .= "QSO%5FDATE"; + $adif .= "%3A"; + $adif .= "8"; + $adif .= "%3E"; + $adif .= $COL_QSO_DATE; + $adif .= "%20"; + + $adif .= "%3C"; + $adif .= "TIME%5FON"; + $adif .= "%3A"; + $adif .= "4"; + $adif .= "%3E"; + $adif .= $COL_TIME_ON; + $adif .= "%20"; + + $adif .= "%3C"; + $adif .= "CALL"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_CALL']); + $adif .= "%3E"; + $adif .= $qsl['COL_CALL']; + $adif .= "%20"; + + $adif .= "%3C"; + $adif .= "MODE"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_MODE']); + $adif .= "%3E"; + $adif .= $qsl['COL_MODE']; + $adif .= "%20"; + + if(isset($qsl['COL_SUBMODE'])) { + $adif .= "%3C"; + $adif .= "SUBMODE"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_SUBMODE']); + $adif .= "%3E"; + $adif .= $qsl['COL_SUBMODE']; + $adif .= "%20"; + } + + $adif .= "%3C"; + $adif .= "BAND"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_BAND']); + $adif .= "%3E"; + $adif .= $qsl['COL_BAND']; + $adif .= "%20"; + + # End all the required fields + + // adding RST_Sent + $adif .= "%3C"; + $adif .= "RST%5FSENT"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_RST_SENT']); + $adif .= "%3E"; + $adif .= $qsl['COL_RST_SENT']; + $adif .= "%20"; + + // adding prop mode if it isn't blank + if ($qsl['COL_PROP_MODE']){ + $adif .= "%3C"; + $adif .= "PROP%5FMODE"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_PROP_MODE']); + $adif .= "%3E"; + $adif .= $qsl['COL_PROP_MODE']; + $adif .= "%20"; + } + + // adding sat name if it isn't blank + if ($qsl['COL_SAT_NAME'] != ''){ + $adif .= "%3C"; + $adif .= "SAT%5FNAME"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_SAT_NAME']); + $adif .= "%3E"; + $adif .= str_replace('-', '%2D', $qsl['COL_SAT_NAME']); + $adif .= "%20"; + } + + // adding sat mode if it isn't blank + if ($qsl['COL_SAT_MODE'] != ''){ + $adif .= "%3C"; + $adif .= "SAT%5FMODE"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_SAT_MODE']); + $adif .= "%3E"; + $adif .= $qsl['COL_SAT_MODE']; + $adif .= "%20"; + } + + // adding qslmsg if it isn't blank + if ($qsl['COL_QSLMSG'] != ''){ + $adif .= "%3C"; + $adif .= "QSLMSG"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_QSLMSG']); + $adif .= "%3E"; + $adif .= $qsl['COL_QSLMSG']; + $adif .= "%20"; + } + + if ($qsl['eqslqthnickname'] != ''){ + $adif .= "%3C"; + $adif .= "APP%5FEQSL%5FQTH%5FNICKNAME"; + $adif .= "%3A"; + $adif .= strlen($qsl['eqslqthnickname']); + $adif .= "%3E"; + $adif .= $qsl['eqslqthnickname']; + $adif .= "%20"; + } + + // adding sat mode if it isn't blank + if ($qsl['station_gridsquare'] != ''){ + $adif .= "%3C"; + $adif .= "MY%5FGRIDSQUARE"; + $adif .= "%3A"; + $adif .= strlen($qsl['station_gridsquare']); + $adif .= "%3E"; + $adif .= $qsl['station_gridsquare']; + $adif .= "%20"; + } + + # Tie a bow on it! + $adif .= "%3C"; + $adif .= "EOR"; + $adif .= "%3E"; + + # Make sure we don't have any spaces + $adif = str_replace(" ", '%20', $adif); + + return $adif; + } + + function writeEqslNotSent($qslsnotsent, $custom_date_format) { + $table = ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + + foreach ($qslsnotsent as $qsl) + { + $table .= ""; + $timestamp = strtotime($qsl['COL_TIME_ON']); + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + + if(isset($qsl['COL_SUBMODE'])) { + $table .= ""; + } else { + $table .= ""; + } + $table .= ""; + $table .= ""; + $table .= ""; + } + $table .= "
DateTimeCallModeSubmodeBandeQSL QTH Nickname
".date($custom_date_format, $timestamp)."".date('H:i', $timestamp)."" . str_replace("0","Ø",strtoupper($qsl['COL_CALL'])) . "".$qsl['COL_MODE']."".$qsl['COL_SUBMODE']."".$qsl['COL_BAND']."".$qsl['eqslqthnickname']."
"; + + return $table; + } + function image($id) { $this->load->library('electronicqsl'); $this->load->model('Eqsl_images'); @@ -529,7 +516,6 @@ class eqsl extends CI_Controller { } public function tools() { - // Check logged in $this->load->model('user_model'); if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } @@ -543,7 +529,6 @@ class eqsl extends CI_Controller { } public function mark_all_sent() { - // Check logged in $this->load->model('user_model'); if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } @@ -556,5 +541,33 @@ class eqsl extends CI_Controller { redirect('eqsl/tools'); } + + /* + * Used for CRON job + */ + public function upload() { + $this->load->model('eqslmethods_model'); + + $users = $this->eqslmethods_model->get_eqsl_users(); + + foreach ($users as $user) { + $this->uploadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password); + } + } + + function uploadUser($userid, $username, $password) { + $data['user_eqsl_name'] = $this->security->xss_clean($username); + $data['user_eqsl_password'] = $this->security->xss_clean($password); + $clean_userid = $this->security->xss_clean($userid); + + $qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent($clean_userid); + + foreach ($qslsnotsent as $qsl) { + $data['user_eqsl_name'] = $qsl['station_callsign']; + $adif = $this->generateAdif($qsl, $data); + + $status = $this->uploadQso($adif); + } + } } // end class diff --git a/application/models/Eqslmethods_model.php b/application/models/Eqslmethods_model.php index c60c97c4..e112d2e8 100644 --- a/application/models/Eqslmethods_model.php +++ b/application/models/Eqslmethods_model.php @@ -18,6 +18,61 @@ class Eqslmethods_model extends CI_Model { $this->db->update($this->config->item('table_name'), $data); } + function get_eqsl_users() { + $this->db->select('user_eqsl_name, user_eqsl_password, user_id'); + $this->db->where('coalesce(user_eqsl_name, "") != ""'); + $this->db->where('coalesce(user_eqsl_password, "") != ""'); + $query = $this->db->get($this->config->item('auth_table')); + return $query->result(); + } + + + // Show all QSOs we need to send to eQSL + function eqsl_not_yet_sent($userid = null) { + $CI =& get_instance(); + if ($userid == null) { + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + } else { + $CI->load->model('Stations'); + $stations = $CI->Stations->all_of_user(); + $logbooks_locations_array = array(); + foreach ($stations->result() as $row) { + array_push($logbooks_locations_array, $row->station_id); + } + } + + $this->db->select('station_profile.*, '.$this->config->item('table_name').'.COL_PRIMARY_KEY, '.$this->config->item('table_name').'.COL_TIME_ON, '.$this->config->item('table_name').'.COL_CALL, '.$this->config->item('table_name').'.COL_MODE, '.$this->config->item('table_name').'.COL_SUBMODE, '.$this->config->item('table_name').'.COL_BAND, '.$this->config->item('table_name').'.COL_COMMENT, '.$this->config->item('table_name').'.COL_RST_SENT, '.$this->config->item('table_name').'.COL_PROP_MODE, '.$this->config->item('table_name').'.COL_SAT_NAME, '.$this->config->item('table_name').'.COL_SAT_MODE, '.$this->config->item('table_name').'.COL_QSLMSG'); + $this->db->from('station_profile'); + $this->db->join($this->config->item('table_name'),'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); + $this->db->where("coalesce(station_profile.eqslqthnickname, '') <> ''"); + $this->db->where($this->config->item('table_name').'.COL_CALL !=', ''); + $this->db->group_start(); + $this->db->where($this->config->item('table_name').'.COL_EQSL_QSL_SENT is null'); + $this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', ''); + $this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'R'); + $this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'Q'); + $this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'N'); + $this->db->group_end(); + $this->db->where_in('station_profile.station_id', $logbooks_locations_array); + + return $this->db->get(); + } + + // Mark the QSO as sent to eQSL + function eqsl_mark_sent($primarykey) { + $data = array( + 'COL_EQSL_QSLSDATE' => date('Y-m-d H:i:s'), // eQSL doesn't give us a date, so let's use current + 'COL_EQSL_QSL_SENT' => 'Y', + ); + + $this->db->where('COL_PRIMARY_KEY', $primarykey); + + $this->db->update($this->config->item('table_name'), $data); + + return "eQSL Sent"; + } + } ?> \ No newline at end of file diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 80cb64b6..b301148f 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2573,20 +2573,6 @@ class Logbook_model extends CI_Model { return "Updated"; } - // Mark the QSO as sent to eQSL - function eqsl_mark_sent($primarykey) { - $data = array( - 'COL_EQSL_QSLSDATE' => date('Y-m-d H:i:s'), // eQSL doesn't give us a date, so let's use current - 'COL_EQSL_QSL_SENT' => 'Y', - ); - - $this->db->where('COL_PRIMARY_KEY', $primarykey); - - $this->db->update($this->config->item('table_name'), $data); - - return "eQSL Sent"; - } - // Get the last date we received an eQSL function eqsl_last_qsl_rcvd_date($callsign, $nickname) { $qso_table_name = $this->config->item('table_name'); @@ -2637,29 +2623,6 @@ class Logbook_model extends CI_Model { } } - // Show all QSOs we need to send to eQSL - function eqsl_not_yet_sent() { - $CI =& get_instance(); - $CI->load->model('logbooks_model'); - $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - - $this->db->select('station_profile.*, '.$this->config->item('table_name').'.COL_PRIMARY_KEY, '.$this->config->item('table_name').'.COL_TIME_ON, '.$this->config->item('table_name').'.COL_CALL, '.$this->config->item('table_name').'.COL_MODE, '.$this->config->item('table_name').'.COL_SUBMODE, '.$this->config->item('table_name').'.COL_BAND, '.$this->config->item('table_name').'.COL_COMMENT, '.$this->config->item('table_name').'.COL_RST_SENT, '.$this->config->item('table_name').'.COL_PROP_MODE, '.$this->config->item('table_name').'.COL_SAT_NAME, '.$this->config->item('table_name').'.COL_SAT_MODE, '.$this->config->item('table_name').'.COL_QSLMSG'); - $this->db->from('station_profile'); - $this->db->join($this->config->item('table_name'),'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); - $this->db->where("coalesce(station_profile.eqslqthnickname, '') <> ''"); - $this->db->where($this->config->item('table_name').'.COL_CALL !=', ''); - $this->db->group_start(); - $this->db->where($this->config->item('table_name').'.COL_EQSL_QSL_SENT is null'); - $this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', ''); - $this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'R'); - $this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'Q'); - $this->db->or_where($this->config->item('table_name').'.COL_EQSL_QSL_SENT', 'N'); - $this->db->group_end(); - $this->db->where_in('station_profile.station_id', $logbooks_locations_array); - - return $this->db->get(); - } - /* * $skipDuplicate - used in ADIF import to skip duplicate checking when importing QSOs * $markLoTW - used in ADIF import to mark QSOs as exported to LoTW when importing QSOs @@ -3901,6 +3864,4 @@ function validateADIFDate($date, $format = 'Ymd') $d = DateTime::createFromFormat($format, $date); return $d && $d->format($format) == $date; } - - -?> +?> \ No newline at end of file From 7d96662558dda4b7e4bc8bffde819f5cf8ae6596 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Fri, 5 May 2023 10:58:36 +0200 Subject: [PATCH 2/9] [eQSL] Added styles to table --- application/controllers/Eqsl.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/application/controllers/Eqsl.php b/application/controllers/Eqsl.php index 5f1d6beb..21f43ac1 100644 --- a/application/controllers/Eqsl.php +++ b/application/controllers/Eqsl.php @@ -423,16 +423,16 @@ class eqsl extends CI_Controller { } function writeEqslNotSent($qslsnotsent, $custom_date_format) { - $table = ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; + $table = '
DateTimeCallModeSubmodeBandeQSL QTH Nickname
'; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; foreach ($qslsnotsent as $qsl) { @@ -450,9 +450,9 @@ class eqsl extends CI_Controller { } $table .= ""; $table .= ""; - $table .= ""; + $table .= ""; } - $table .= "
DateTimeCallModeSubmodeBandeQSL QTH Nickname
".$qsl['COL_BAND']."".$qsl['eqslqthnickname']."
"; + $table .= ""; return $table; } From 3e0d9201879998604ca969ba4734b38edbc49fd8 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Fri, 5 May 2023 11:10:37 +0200 Subject: [PATCH 3/9] [eQSL] Removed duplication of code for table --- application/controllers/Eqsl.php | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/application/controllers/Eqsl.php b/application/controllers/Eqsl.php index 21f43ac1..25c09cda 100644 --- a/application/controllers/Eqsl.php +++ b/application/controllers/Eqsl.php @@ -121,17 +121,8 @@ class eqsl extends CI_Controller { // perform an HTTP get on each one, and grab the status back $qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent(); - $table = ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - + $data['eqsl_table'] = $this->writeEqslNotSent($qslsnotsent->result_array(), $custom_date_format); + foreach ($qslsnotsent->result_array() as $qsl) { // eQSL username changes for linked account. @@ -141,26 +132,7 @@ class eqsl extends CI_Controller { $adif = $this->generateAdif($qsl, $data); $status = $this->uploadQso($adif); - - $table .= ""; - $timestamp = strtotime($qsl['COL_TIME_ON']); - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - if(isset($qsl['COL_SUBMODE'])) { - $table .= ""; - } else { - $table .= ""; - } - $table .= ""; - $table .= ""; - $table .= ""; } - $table .= "
DateTimeCallModeSubmodeBandResult
".date($custom_date_format, $timestamp)."".date('H:i', $timestamp)."".str_replace("0","Ø",$qsl['COL_CALL'])."".$qsl['COL_MODE']."".$qsl['COL_SUBMODE']."".$qsl['COL_BAND']."".$status."
"; - - // Dump out a table with the results - $data['eqsl_results_table'] = $table; } else { $qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent(); if ($qslsnotsent->num_rows() > 0) { From 9c13e2408ac223ea7a148cd8c7060d9b75a43865 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Fri, 5 May 2023 11:16:48 +0200 Subject: [PATCH 4/9] [eQSL] Added init to cron job --- application/controllers/Eqsl.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/Eqsl.php b/application/controllers/Eqsl.php index 25c09cda..6a6f5b20 100644 --- a/application/controllers/Eqsl.php +++ b/application/controllers/Eqsl.php @@ -528,6 +528,8 @@ class eqsl extends CI_Controller { } function uploadUser($userid, $username, $password) { + ini_set('memory_limit', '-1'); + set_time_limit(0); $data['user_eqsl_name'] = $this->security->xss_clean($username); $data['user_eqsl_password'] = $this->security->xss_clean($password); $clean_userid = $this->security->xss_clean($userid); From f7968ac35c14594556e6ec018978d389bf53126e Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Fri, 5 May 2023 11:38:14 +0200 Subject: [PATCH 5/9] [eQSL] Fixed result table --- application/controllers/Eqsl.php | 37 ++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/application/controllers/Eqsl.php b/application/controllers/Eqsl.php index 6a6f5b20..f64745b0 100644 --- a/application/controllers/Eqsl.php +++ b/application/controllers/Eqsl.php @@ -121,8 +121,7 @@ class eqsl extends CI_Controller { // perform an HTTP get on each one, and grab the status back $qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent(); - $data['eqsl_table'] = $this->writeEqslNotSent($qslsnotsent->result_array(), $custom_date_format); - + $rows = ""; foreach ($qslsnotsent->result_array() as $qsl) { // eQSL username changes for linked account. @@ -132,7 +131,23 @@ class eqsl extends CI_Controller { $adif = $this->generateAdif($qsl, $data); $status = $this->uploadQso($adif); + + + $timestamp = strtotime($qsl['COL_TIME_ON']); + $rows .= "".date($custom_date_format, $timestamp).""; + $rows .= "".date('H:i', $timestamp).""; + $rows .= "".str_replace("0","Ø",$qsl['COL_CALL']).""; + $rows .= "".$qsl['COL_MODE'].""; + if(isset($qsl['COL_SUBMODE'])) { + $rows .= "".$qsl['COL_SUBMODE'].""; + } else { + $rows .= ""; + } + $rows .= "".$qsl['COL_BAND'].""; + $rows .= "".$status.""; } + $rows .= ""; + $data['eqsl_table'] = $this->generateResultTable($custom_date_format, $rows); } else { $qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent(); if ($qslsnotsent->num_rows() > 0) { @@ -209,6 +224,24 @@ class eqsl extends CI_Controller { return $status; } + function generateResultTable($custom_date_format, $rows) { + $table = ''; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + + $table .= $rows; + $table .= "
DateTimeCallModeSubmodeBandStatus
"; + + return $table; + } + // Build out the ADIF info string according to specs http://eqsl.cc/qslcard/ADIFContentSpecs.cfm function generateAdif($qsl, $data) { $COL_QSO_DATE = date('Ymd',strtotime($qsl['COL_TIME_ON'])); From daad9916893d2a901de7216a52625b31d753d196 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Fri, 5 May 2023 12:00:23 +0200 Subject: [PATCH 6/9] [eQSL] Added datatable --- application/views/interface_assets/footer.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 89384901..9e00854a 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -2672,6 +2672,21 @@ function deleteQsl(id) { + +uri->segment(1) == "eqsl") { ?> + + + uri->segment(1) == "qslprint") { ?>