From 6cf405e0bdcdc569a4118fcb2117e9a281e3728a Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Mon, 3 Jun 2024 07:45:22 +0200 Subject: [PATCH 1/5] move the first functions --- application/controllers/Eqsl.php | 303 +---------------------- application/models/Eqslmethods_model.php | 300 ++++++++++++++++++++++ 2 files changed, 306 insertions(+), 297 deletions(-) diff --git a/application/controllers/Eqsl.php b/application/controllers/Eqsl.php index 0c5b32dda..d072bd9be 100644 --- a/application/controllers/Eqsl.php +++ b/application/controllers/Eqsl.php @@ -172,9 +172,9 @@ class eqsl extends CI_Controller { // 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); + $adif = $this->eqslmethods_model->generateAdif($qsl, $data); - $status = $this->uploadQso($adif, $qsl); + $status = $this->eqslmethods_model->uploadQso($adif, $qsl); $timestamp = strtotime($qsl['COL_TIME_ON']); $rows .= "".date($custom_date_format, $timestamp).""; @@ -203,70 +203,7 @@ class eqsl extends CI_Controller { $this->load->view('interface_assets/footer'); } - function uploadQso($adif, $qsl) { - $this->load->model('eqslmethods_model'); - $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->eqslmethods_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->eqslmethods_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'); - } - } - } - } - log_message('debug', $result); - return $status; - } + function generateResultTable($custom_date_format, $rows) { $table = ''; @@ -286,192 +223,7 @@ class eqsl extends CI_Controller { return $table; } - // Build out the ADIF info string according to specs https://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 = "https://www.eqsl.cc/qslcard/importADIF.cfm?"; - $adif .= "ADIFData=WavelogUpload%20"; - - /* Handy reference of escaping chars - "<" = 3C - ">" = 3E - ":" = 3A - " " = 20 - "_" = 5F - "-" = 2D - "." = 2E - "&" = 26 - */ - - $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'] != ''){ - $qsl['COL_QSLMSG'] = str_replace(array(chr(10),chr(13)),array(' ',' '),$qsl['COL_QSLMSG']); - $adif .= "%3C"; - $adif .= "QSLMSG"; - $adif .= "%3A"; - $adif .= strlen($qsl['COL_QSLMSG']); - $adif .= "%3E"; - $adif .= str_replace('&','%26',$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 = '
'; @@ -713,57 +465,14 @@ class eqsl extends CI_Controller { * Used for CRON job */ public function sync() { - // 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); - ini_set('memory_limit', '-1'); - set_time_limit(0); $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); - $this->downloadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password); - } + $this->eqslmethods_model->sync(); } - public function downloadUser($userid, $username, $password) { - $this->load->library('EqslImporter'); - $this->load->model('eqslmethods_model'); - - $config['upload_path'] = './uploads/'; - $eqsl_locations = $this->eqslmethods_model->all_of_user_with_eqsl_nick_defined($userid); - - $eqsl_results = array(); - - foreach ($eqsl_locations->result_array() as $eqsl_location) { - $this->eqslimporter->from_callsign_and_QTH( - $eqsl_location['station_callsign'], - $eqsl_location['eqslqthnickname'], - $config['upload_path'], - $eqsl_location['station_id'] - ); - - $eqsl_results[] = $this->eqslimporter->fetch($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->result_array() as $qsl) { - $data['user_eqsl_name'] = $qsl['station_callsign']; - $adif = $this->generateAdif($qsl, $data); - - $status = $this->uploadQso($adif, $qsl); - } - } + } // end class diff --git a/application/models/Eqslmethods_model.php b/application/models/Eqslmethods_model.php index 506710f2e..f8d2a5f4f 100644 --- a/application/models/Eqslmethods_model.php +++ b/application/models/Eqslmethods_model.php @@ -2,6 +2,306 @@ class Eqslmethods_model extends CI_Model { + function sync() { + + ini_set('memory_limit', '-1'); + set_time_limit(0); + + $users = $this->get_eqsl_users(); + + foreach ($users as $user) { + $this->uploadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password); + $this->downloadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password); + } + } + + function downloadUser($userid, $username, $password) { + $this->load->library('EqslImporter'); + + $config['upload_path'] = './uploads/'; + $eqsl_locations = $this->all_of_user_with_eqsl_nick_defined($userid); + + $eqsl_results = array(); + + foreach ($eqsl_locations->result_array() as $eqsl_location) { + $this->eqslimporter->from_callsign_and_QTH( + $eqsl_location['station_callsign'], + $eqsl_location['eqslqthnickname'], + $config['upload_path'], + $eqsl_location['station_id'] + ); + + $eqsl_results[] = $this->eqslimporter->fetch($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->result_array() as $qsl) { + $data['user_eqsl_name'] = $qsl['station_callsign']; + $adif = $this->generateAdif($qsl, $data); + + $status = $this->uploadQso($adif, $qsl); + } + } + + // Build out the ADIF info string according to specs https://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 = "https://www.eqsl.cc/qslcard/importADIF.cfm?"; + $adif .= "ADIFData=WavelogUpload%20"; + + /* Handy reference of escaping chars + "<" = 3C + ">" = 3E + ":" = 3A + " " = 20 + "_" = 5F + "-" = 2D + "." = 2E + "&" = 26 + */ + + $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'] != ''){ + $qsl['COL_QSLMSG'] = str_replace(array(chr(10),chr(13)),array(' ',' '),$qsl['COL_QSLMSG']); + $adif .= "%3C"; + $adif .= "QSLMSG"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_QSLMSG']); + $adif .= "%3E"; + $adif .= str_replace('&','%26',$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 uploadQso($adif, $qsl) { + $this->load->model('eqslmethods_model'); + $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->eqslmethods_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->eqslmethods_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'); + } + } + } + } + log_message('debug', $result); + return $status; + } + function mark_all_as_sent() { $data = array( 'COL_EQSL_QSL_SENT' => 'Y', From fabb8d825c4c68884aed3dbf7d0ae78ea4c2aba8 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Mon, 3 Jun 2024 07:46:00 +0200 Subject: [PATCH 2/5] format code --- application/controllers/Eqsl.php | 411 +++++++------- application/models/Eqslmethods_model.php | 652 ++++++++++++----------- 2 files changed, 536 insertions(+), 527 deletions(-) diff --git a/application/controllers/Eqsl.php b/application/controllers/Eqsl.php index d072bd9be..c625a3475 100644 --- a/application/controllers/Eqsl.php +++ b/application/controllers/Eqsl.php @@ -1,4 +1,4 @@ -load->helper(array('form', 'url')); if (ENVIRONMENT == 'maintenance' && $this->session->userdata('user_id') == '') { - echo "Maintenance Mode is active. Try again later.\n"; + echo "Maintenance Mode is active. Try again later.\n"; redirect('user/login'); } } - // Default view when loading controller. + // Default view when loading controller. public function index() { $this->lang->load('qslcard'); @@ -38,221 +38,224 @@ class eqsl extends CI_Controller { public function import() { $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'); } + if (!$this->user_model->authorize(2)) { + $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); + redirect('dashboard'); + } - $this->load->model('stations'); - $data['station_profile'] = $this->stations->all_of_user(); - $active_station_id = $this->stations->find_active(); - $station_profile = $this->stations->profile($active_station_id); - $data['active_station_info'] = $station_profile->row(); + $this->load->model('stations'); + $data['station_profile'] = $this->stations->all_of_user(); + $active_station_id = $this->stations->find_active(); + $station_profile = $this->stations->profile($active_station_id); + $data['active_station_info'] = $station_profile->row(); - // Check if eQSL Nicknames have been defined - $this->load->model('eqslmethods_model'); - $eqsl_locations = $this->eqslmethods_model->all_of_user_with_eqsl_nick_defined(); - if($eqsl_locations->num_rows() == 0) { - $this->session->set_flashdata('error', 'eQSL Nicknames in Station Profiles aren\'t defined!'); + // Check if eQSL Nicknames have been defined + $this->load->model('eqslmethods_model'); + $eqsl_locations = $this->eqslmethods_model->all_of_user_with_eqsl_nick_defined(); + if ($eqsl_locations->num_rows() == 0) { + $this->session->set_flashdata('error', 'eQSL Nicknames in Station Profiles aren\'t defined!'); + } + + ini_set('memory_limit', '-1'); + set_time_limit(0); + + $config['upload_path'] = './uploads/'; + $config['allowed_types'] = 'adi|ADI'; + + $this->load->library('upload', $config); + + $eqsl_results = array(); + if (($this->input->post('eqslimport') == 'fetch') && (!($this->config->item('disable_manual_eqsl')))) { + $this->load->library('EqslImporter'); + + // Get credentials for eQSL + $query = $this->user_model->get_by_id($this->session->userdata('user_id')); + $q = $query->row(); + $eqsl_password = $q->user_eqsl_password; + + // Validate that eQSL credentials are not empty + if ($eqsl_password == '') { + $this->session->set_flashdata('warning', 'You have not defined your eQSL.cc credentials!'); + redirect('eqsl/import'); } - ini_set('memory_limit', '-1'); - set_time_limit(0); + $eqsl_force_from_date = (!$this->input->post('eqsl_force_from_date') == "") ? $this->input->post('eqsl_force_from_date') : ""; + foreach ($eqsl_locations->result_array() as $eqsl_location) { + $this->eqslimporter->from_callsign_and_QTH( + $eqsl_location['station_callsign'], + $eqsl_location['eqslqthnickname'], + $config['upload_path'], + $eqsl_location['station_id'] + ); - $config['upload_path'] = './uploads/'; - $config['allowed_types'] = 'adi|ADI'; + $eqsl_results[] = $this->eqslimporter->fetch($eqsl_password, $eqsl_force_from_date); + } + } elseif (($this->input->post('eqslimport') == 'upload')) { + $station_id4upload = $this->input->post('station_profile'); + if ($this->stations->check_station_is_accessible($station_id4upload)) { + $station_callsign = $this->stations->profile($station_id4upload)->row()->station_callsign; + if (!$this->upload->do_upload()) { + $data['page_title'] = "eQSL Import"; + $data['error'] = $this->upload->display_errors(); - $this->load->library('upload', $config); + $this->load->view('interface_assets/header', $data); + $this->load->view('eqsl/import'); + $this->load->view('interface_assets/footer'); - $eqsl_results = array(); - if (($this->input->post('eqslimport') == 'fetch') && (!($this->config->item('disable_manual_eqsl')))) { - $this->load->library('EqslImporter'); - - // Get credentials for eQSL - $query = $this->user_model->get_by_id($this->session->userdata('user_id')); - $q = $query->row(); - $eqsl_password = $q->user_eqsl_password; - - // Validate that eQSL credentials are not empty - if ($eqsl_password == '') - { - $this->session->set_flashdata('warning', 'You have not defined your eQSL.cc credentials!'); - redirect('eqsl/import'); - } - - $eqsl_force_from_date = (!$this->input->post('eqsl_force_from_date')=="")?$this->input->post('eqsl_force_from_date'):""; - foreach ($eqsl_locations->result_array() as $eqsl_location) { - $this->eqslimporter->from_callsign_and_QTH( - $eqsl_location['station_callsign'], - $eqsl_location['eqslqthnickname'], - $config['upload_path'], - $eqsl_location['station_id'] - ); - - $eqsl_results[] = $this->eqslimporter->fetch($eqsl_password, $eqsl_force_from_date); - } - } elseif (($this->input->post('eqslimport') == 'upload')) { - $station_id4upload=$this->input->post('station_profile'); - if ($this->stations->check_station_is_accessible($station_id4upload)) { - $station_callsign=$this->stations->profile($station_id4upload)->row()->station_callsign; - if ( ! $this->upload->do_upload()) - { - $data['page_title'] = "eQSL Import"; - $data['error'] = $this->upload->display_errors(); - - $this->load->view('interface_assets/header', $data); - $this->load->view('eqsl/import'); - $this->load->view('interface_assets/footer'); - - return; - } else { - $data = array('upload_data' => $this->upload->data()); - - $this->load->library('EqslImporter'); - $this->eqslimporter->from_file('./uploads/'.$data['upload_data']['file_name'], $station_callsign, $station_id4upload); - - $eqsl_results[] = $this->eqslimporter->import(); - } + return; } else { - log_message('error',$station_id4upload." is not valid for user!"); + $data = array('upload_data' => $this->upload->data()); + + $this->load->library('EqslImporter'); + $this->eqslimporter->from_file('./uploads/' . $data['upload_data']['file_name'], $station_callsign, $station_id4upload); + + $eqsl_results[] = $this->eqslimporter->import(); } } else { - $data['page_title'] = "eQSL Import"; - - $this->load->view('interface_assets/header', $data); - $this->load->view('eqsl/import'); - $this->load->view('interface_assets/footer'); - - return; + log_message('error', $station_id4upload . " is not valid for user!"); } - - $data['eqsl_results'] = $eqsl_results; - $data['page_title'] = "eQSL Import Information"; + } else { + $data['page_title'] = "eQSL Import"; $this->load->view('interface_assets/header', $data); - $this->load->view('eqsl/analysis'); + $this->load->view('eqsl/import'); $this->load->view('interface_assets/footer'); + + return; + } + + $data['eqsl_results'] = $eqsl_results; + $data['page_title'] = "eQSL Import Information"; + + $this->load->view('interface_assets/header', $data); + $this->load->view('eqsl/analysis'); + $this->load->view('interface_assets/footer'); } // end function public function export() { $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'); } + if (!$this->user_model->authorize(2)) { + $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); + redirect('dashboard'); + } - // Check if eQSL Nicknames have been defined - $this->load->model('stations'); - if($this->stations->are_eqsl_nicks_defined() == 0) { - $this->session->set_flashdata('error', 'eQSL Nicknames in Station Profiles aren\'t defined!'); + // Check if eQSL Nicknames have been defined + $this->load->model('stations'); + if ($this->stations->are_eqsl_nicks_defined() == 0) { + $this->session->set_flashdata('error', 'eQSL Nicknames in Station Profiles aren\'t defined!'); + } + + ini_set('memory_limit', '-1'); + set_time_limit(0); + $this->load->model('eqslmethods_model'); + + $data['page_title'] = "eQSL QSO Upload"; + $custom_date_format = $this->session->userdata('user_date_format'); + + if ((!($this->config->item('disable_manual_eqsl'))) && ($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; + $data['user_eqsl_password'] = $q->user_eqsl_password; + + // Validate that eQSL credentials are not empty + if ($data['user_eqsl_name'] == '' || $data['user_eqsl_password'] == '') { + $this->session->set_flashdata('warning', 'You have not defined your eQSL.cc credentials!'); + redirect('eqsl/import'); } - ini_set('memory_limit', '-1'); - set_time_limit(0); - $this->load->model('eqslmethods_model'); + $rows = ''; + // Grab the list of QSOs to send information about + // perform an HTTP get on each one, and grab the status back + $qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent(); - $data['page_title'] = "eQSL QSO Upload"; - $custom_date_format = $this->session->userdata('user_date_format'); + foreach ($qslsnotsent->result_array() as $qsl) { + $rows .= ""; + // 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->eqslmethods_model->generateAdif($qsl, $data); - if ((!($this->config->item('disable_manual_eqsl'))) && ($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; - $data['user_eqsl_password'] = $q->user_eqsl_password; + $status = $this->eqslmethods_model->uploadQso($adif, $qsl); - // Validate that eQSL credentials are not empty - if ($data['user_eqsl_name'] == '' || $data['user_eqsl_password'] == '') - { - $this->session->set_flashdata('warning', 'You have not defined your eQSL.cc credentials!'); redirect('eqsl/import'); - } - - $rows = ''; - // Grab the list of QSOs to send information about - // perform an HTTP get on each one, and grab the status back - $qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent(); - - foreach ($qslsnotsent->result_array() as $qsl) { - $rows .= ""; - // 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->eqslmethods_model->generateAdif($qsl, $data); - - $status = $this->eqslmethods_model->uploadQso($adif, $qsl); - - $timestamp = strtotime($qsl['COL_TIME_ON']); - $rows .= ""; - $rows .= ""; - $rows .= ""; - $rows .= ""; - if(isset($qsl['COL_SUBMODE'])) { - $rows .= ""; - } else { - $rows .= ""; - } - $rows .= ""; - $rows .= ""; - } - $rows .= ""; - $data['eqsl_table'] = $this->generateResultTable($custom_date_format, $rows); - } 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); + $timestamp = strtotime($qsl['COL_TIME_ON']); + $rows .= ""; + $rows .= ""; + $rows .= ""; + $rows .= ""; + if (isset($qsl['COL_SUBMODE'])) { + $rows .= ""; + } else { + $rows .= ""; } + $rows .= ""; + $rows .= ""; } + $rows .= ""; + $data['eqsl_table'] = $this->generateResultTable($custom_date_format, $rows); + } 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); + } + } - $this->load->view('interface_assets/header', $data); - $this->load->view('eqsl/export'); - $this->load->view('interface_assets/footer'); + $this->load->view('interface_assets/header', $data); + $this->load->view('eqsl/export'); + $this->load->view('interface_assets/footer'); } - + function generateResultTable($custom_date_format, $rows) { $table = '
".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 . "
'; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= $rows; $table .= "
DateTimeCallModeSubmodeBandStatus
DateTimeCallModeSubmodeBandStatus
"; return $table; } - + function writeEqslNotSent($qslsnotsent, $custom_date_format) { $table = ''; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - $table .= ""; - - foreach ($qslsnotsent as $qsl) - { + $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 .= ""; + $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
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']."" . 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'] . "
"; @@ -264,7 +267,7 @@ class eqsl extends CI_Controller { $this->load->library('electronicqsl'); $this->load->model('Eqsl_images'); - if($this->Eqsl_images->get_image($id) == "No Image") { + if ($this->Eqsl_images->get_image($id) == "No Image") { $this->load->model('logbook_model'); $this->load->model('user_model'); $qso_query = $this->logbook_model->get_qso($id); @@ -292,31 +295,29 @@ class eqsl extends CI_Controller { $dom->preserveWhiteSpace = false; $images = $dom->getElementsByTagName('img'); - if(!isset($images) || count($images) == 0) { + if (!isset($images) || count($images) == 0) { echo "Rate Limited"; exit; } - foreach ($images as $image) - { + foreach ($images as $image) { header('Content-Type: image/jpg'); - $content = file_get_contents("https://www.eqsl.cc".$image->getAttribute('src')); + $content = file_get_contents("https://www.eqsl.cc" . $image->getAttribute('src')); if ($content === false) { echo "No response"; exit; } echo $content; - $filename = uniqid().'.jpg'; - if (file_put_contents($this->Eqsl_images->get_imagePath('p') .'/'. $filename, $content) !== false) { + $filename = uniqid() . '.jpg'; + if (file_put_contents($this->Eqsl_images->get_imagePath('p') . '/' . $filename, $content) !== false) { $this->Eqsl_images->save_image($id, $filename); } } } else { header('Content-Type: image/jpg'); - $image_url = base_url($this->Eqsl_images->get_imagePath() .'/'. $this->Eqsl_images->get_image($id)); + $image_url = base_url($this->Eqsl_images->get_imagePath() . '/' . $this->Eqsl_images->get_image($id)); header('Location: ' . $image_url); } - } function bulk_download_image($id) { @@ -355,33 +356,34 @@ class eqsl extends CI_Controller { $dom->preserveWhiteSpace = false; $images = $dom->getElementsByTagName('img'); - if(!isset($images) || count($images) == 0) { + if (!isset($images) || count($images) == 0) { $error = "Rate Limited"; return $error; } - foreach ($images as $image) - { - $content = file_get_contents("https://www.eqsl.cc".$image->getAttribute('src')); + foreach ($images as $image) { + $content = file_get_contents("https://www.eqsl.cc" . $image->getAttribute('src')); if ($content === false) { $error = "No response"; return $error; } - $filename = uniqid().'.jpg'; - if($this->Eqsl_images->get_image($id) == "No Image") { - if (file_put_contents($this->Eqsl_images->get_imagePath('p') .'/'. $filename, $content) !== false) { + $filename = uniqid() . '.jpg'; + if ($this->Eqsl_images->get_image($id) == "No Image") { + if (file_put_contents($this->Eqsl_images->get_imagePath('p') . '/' . $filename, $content) !== false) { $this->Eqsl_images->save_image($id, $filename); } } } return $error; - } 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'); } + if (!$this->user_model->authorize(2)) { + $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); + redirect('dashboard'); + } $data['page_title'] = "eQSL Tools"; @@ -394,8 +396,11 @@ class eqsl extends CI_Controller { public function download() { // 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'); } - $errors=0; + if (!$this->user_model->authorize(2)) { + $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); + redirect('dashboard'); + } + $errors = 0; if ($this->input->post('eqsldownload') == 'download') { $i = 0; @@ -427,7 +432,7 @@ class eqsl extends CI_Controller { } } $data['eqsl_results'] = $eqsl_results; - $data['eqsl_stats'] = "Successfully downloaded: ".$i." / Errors: ".count($eqsl_results); + $data['eqsl_stats'] = "Successfully downloaded: " . $i . " / Errors: " . count($eqsl_results); $data['page_title'] = "eQSL Download Information"; $this->load->view('interface_assets/header', $data); @@ -450,8 +455,11 @@ 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'); } - + if (!$this->user_model->authorize(2)) { + $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); + redirect('dashboard'); + } + // mark all eqsls as sent $this->load->model('eqslmethods_model'); $this->eqslmethods_model->mark_all_as_sent(); @@ -467,12 +475,9 @@ class eqsl extends CI_Controller { public function sync() { // 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); $this->load->model('eqslmethods_model'); $this->eqslmethods_model->sync(); } - - - } // end class diff --git a/application/models/Eqslmethods_model.php b/application/models/Eqslmethods_model.php index f8d2a5f4f..65a2a5dfa 100644 --- a/application/models/Eqslmethods_model.php +++ b/application/models/Eqslmethods_model.php @@ -3,63 +3,63 @@ class Eqslmethods_model extends CI_Model { function sync() { - + ini_set('memory_limit', '-1'); - set_time_limit(0); + set_time_limit(0); - $users = $this->get_eqsl_users(); + $users = $this->get_eqsl_users(); - foreach ($users as $user) { - $this->uploadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password); - $this->downloadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password); - } + foreach ($users as $user) { + $this->uploadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password); + $this->downloadUser($user->user_id, $user->user_eqsl_name, $user->user_eqsl_password); + } } function downloadUser($userid, $username, $password) { - $this->load->library('EqslImporter'); + $this->load->library('EqslImporter'); - $config['upload_path'] = './uploads/'; - $eqsl_locations = $this->all_of_user_with_eqsl_nick_defined($userid); + $config['upload_path'] = './uploads/'; + $eqsl_locations = $this->all_of_user_with_eqsl_nick_defined($userid); - $eqsl_results = array(); + $eqsl_results = array(); - foreach ($eqsl_locations->result_array() as $eqsl_location) { - $this->eqslimporter->from_callsign_and_QTH( - $eqsl_location['station_callsign'], - $eqsl_location['eqslqthnickname'], - $config['upload_path'], - $eqsl_location['station_id'] - ); + foreach ($eqsl_locations->result_array() as $eqsl_location) { + $this->eqslimporter->from_callsign_and_QTH( + $eqsl_location['station_callsign'], + $eqsl_location['eqslqthnickname'], + $config['upload_path'], + $eqsl_location['station_id'] + ); - $eqsl_results[] = $this->eqslimporter->fetch($password); - } - } + $eqsl_results[] = $this->eqslimporter->fetch($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); + 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); - foreach ($qslsnotsent->result_array() as $qsl) { - $data['user_eqsl_name'] = $qsl['station_callsign']; - $adif = $this->generateAdif($qsl, $data); - - $status = $this->uploadQso($adif, $qsl); - } - } + $qslsnotsent = $this->eqslmethods_model->eqsl_not_yet_sent($clean_userid); + + foreach ($qslsnotsent->result_array() as $qsl) { + $data['user_eqsl_name'] = $qsl['station_callsign']; + $adif = $this->generateAdif($qsl, $data); + + $status = $this->uploadQso($adif, $qsl); + } + } // Build out the ADIF info string according to specs https://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 = "https://www.eqsl.cc/qslcard/importADIF.cfm?"; - $adif .= "ADIFData=WavelogUpload%20"; - - /* Handy reference of escaping chars + 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 = "https://www.eqsl.cc/qslcard/importADIF.cfm?"; + $adif .= "ADIFData=WavelogUpload%20"; + + /* Handy reference of escaping chars "<" = 3C ">" = 3E ":" = 3A @@ -69,193 +69,193 @@ class Eqslmethods_model extends CI_Model { "." = 2E "&" = 26 */ - - $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"; + $adif .= "%3C"; + $adif .= "ADIF%5FVER"; + $adif .= "%3A"; + $adif .= "4"; + $adif .= "%3E"; + $adif .= "1%2E00 "; + $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"; - } + $adif .= "%3C"; + $adif .= "EQSL%5FUSER"; + $adif .= "%3A"; + $adif .= strlen($data['user_eqsl_name']); + $adif .= "%3E"; + $adif .= $data['user_eqsl_name']; + $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"; - } + $adif .= "%3C"; + $adif .= "EQSL%5FPSWD"; + $adif .= "%3A"; + $adif .= strlen($data['user_eqsl_password']); + $adif .= "%3E"; + $adif .= urlencode($data['user_eqsl_password']); + $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"; - } + $adif .= "%3C"; + $adif .= "EOH"; + $adif .= "%3E"; - // adding qslmsg if it isn't blank - if ($qsl['COL_QSLMSG'] != ''){ - $qsl['COL_QSLMSG'] = str_replace(array(chr(10),chr(13)),array(' ',' '),$qsl['COL_QSLMSG']); - $adif .= "%3C"; - $adif .= "QSLMSG"; - $adif .= "%3A"; - $adif .= strlen($qsl['COL_QSLMSG']); - $adif .= "%3E"; - $adif .= str_replace('&','%26',$qsl['COL_QSLMSG']); - $adif .= "%20"; - } + # Lay out the required fields + $adif .= "%3C"; + $adif .= "QSO%5FDATE"; + $adif .= "%3A"; + $adif .= "8"; + $adif .= "%3E"; + $adif .= $COL_QSO_DATE; + $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"; - } + $adif .= "%3C"; + $adif .= "TIME%5FON"; + $adif .= "%3A"; + $adif .= "4"; + $adif .= "%3E"; + $adif .= $COL_TIME_ON; + $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"; - } + $adif .= "%3C"; + $adif .= "CALL"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_CALL']); + $adif .= "%3E"; + $adif .= $qsl['COL_CALL']; + $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); + $adif .= "%3C"; + $adif .= "MODE"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_MODE']); + $adif .= "%3E"; + $adif .= $qsl['COL_MODE']; + $adif .= "%20"; - return $adif; - } + 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'] != '') { + $qsl['COL_QSLMSG'] = str_replace(array(chr(10), chr(13)), array(' ', ' '), $qsl['COL_QSLMSG']); + $adif .= "%3C"; + $adif .= "QSLMSG"; + $adif .= "%3A"; + $adif .= strlen($qsl['COL_QSLMSG']); + $adif .= "%3E"; + $adif .= str_replace('&', '%26', $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 uploadQso($adif, $qsl) { - $this->load->model('eqslmethods_model'); - $status = ""; - - // begin script - $ch = curl_init(); + $this->load->model('eqslmethods_model'); + $status = ""; - // 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); + // begin script + $ch = curl_init(); - /* Time for some error handling + // 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 @@ -263,71 +263,76 @@ class Eqslmethods_model extends CI_Model { 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->eqslmethods_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->eqslmethods_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'); - } - } - } - } - log_message('debug', $result); - return $status; - } - function mark_all_as_sent() { - $data = array( - 'COL_EQSL_QSL_SENT' => 'Y', - 'COL_EQSL_QSLSDATE' => date('Y-m-d')." 00:00:00", - ); + if ($chi['http_code'] == "200") { + if (stristr($result, "Result: 1 out of 1 records added")) { + $status = "Sent"; + $this->eqslmethods_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"; - $userid=$this->session->userdata('user_id'); - if ($userid ?? '' != '') { - $stations = $this->get_all_user_locations($userid); - $logbooks_locations_array = array(); - foreach ($stations->result() as $row) { - array_push($logbooks_locations_array, $row->station_id); - } - if (count($logbooks_locations_array)>0) { - $this->db->where_in('station_id', $logbooks_locations_array); - $this->db->group_start(); - $this->db->where('COL_EQSL_QSL_SENT', 'N'); - $this->db->or_where('COL_EQSL_QSL_SENT', 'R'); - $this->db->or_where('COL_EQSL_QSL_SENT', 'Q'); - $this->db->or_where('COL_EQSL_QSL_SENT', null); - $this->db->group_end(); + # Mark the QSL as sent if this is a dupe. + $this->eqslmethods_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'); + } + } + } + } + log_message('debug', $result); + return $status; + } - $this->db->update($this->config->item('table_name'), $data); - } - } - } + function mark_all_as_sent() { + $data = array( + 'COL_EQSL_QSL_SENT' => 'Y', + 'COL_EQSL_QSLSDATE' => date('Y-m-d') . " 00:00:00", + ); + + $userid = $this->session->userdata('user_id'); + if ($userid ?? '' != '') { + $stations = $this->get_all_user_locations($userid); + $logbooks_locations_array = array(); + foreach ($stations->result() as $row) { + array_push($logbooks_locations_array, $row->station_id); + } + if (count($logbooks_locations_array) > 0) { + $this->db->where_in('station_id', $logbooks_locations_array); + $this->db->group_start(); + $this->db->where('COL_EQSL_QSL_SENT', 'N'); + $this->db->or_where('COL_EQSL_QSL_SENT', 'R'); + $this->db->or_where('COL_EQSL_QSL_SENT', 'Q'); + $this->db->or_where('COL_EQSL_QSL_SENT', null); + $this->db->group_end(); + + $this->db->update($this->config->item('table_name'), $data); + } + } + } function get_eqsl_users() { $this->db->select('user_eqsl_name, user_eqsl_password, user_id'); @@ -341,15 +346,15 @@ class Eqslmethods_model extends CI_Model { * Gets all station location for user, for use in cron where we don't have any login */ function get_all_user_locations($userid) { - $this->db->select('station_profile.*, dxcc_entities.name as station_country, dxcc_entities.end as dxcc_end'); - $this->db->where('user_id', $userid); - $this->db->join('dxcc_entities','station_profile.station_dxcc = dxcc_entities.adif','left outer'); - return $this->db->get('station_profile'); - } + $this->db->select('station_profile.*, dxcc_entities.name as station_country, dxcc_entities.end as dxcc_end'); + $this->db->where('user_id', $userid); + $this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer'); + return $this->db->get('station_profile'); + } // Show all QSOs we need to send to eQSL function eqsl_not_yet_sent($userid = null) { - $CI =& get_instance(); + $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')); @@ -359,20 +364,20 @@ class Eqslmethods_model extends CI_Model { foreach ($stations->result() as $row) { array_push($logbooks_locations_array, $row->station_id); } - array_push($logbooks_locations_array, -9999); + array_push($logbooks_locations_array, -9999); } - $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->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->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->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->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); @@ -381,7 +386,7 @@ class Eqslmethods_model extends CI_Model { // Show all QSOs whose eQSL card images we did not download yet function eqsl_not_yet_downloaded($userid = null) { - $CI =& get_instance(); + $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')); @@ -391,16 +396,16 @@ class Eqslmethods_model extends CI_Model { foreach ($stations->result() as $row) { array_push($logbooks_locations_array, $row->station_id); } - array_push($logbooks_locations_array, -9999); + array_push($logbooks_locations_array, -9999); } - $this->db->select('station_profile.station_id, '.$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_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, eQSL_images.qso_id'); + $this->db->select('station_profile.station_id, ' . $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_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, eQSL_images.qso_id'); $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->join('eQSL_images','eQSL_images.qso_id = '.$this->config->item('table_name').'.COL_PRIMARY_KEY','left outer'); + $this->db->join($this->config->item('table_name'), 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id'); + $this->db->join('eQSL_images', 'eQSL_images.qso_id = ' . $this->config->item('table_name') . '.COL_PRIMARY_KEY', 'left outer'); //$this->db->where("coalesce(station_profile.eqslqthnickname, '') <> ''"); - $this->db->where($this->config->item('table_name').'.COL_CALL !=', ''); - $this->db->where($this->config->item('table_name').'.COL_EQSL_QSL_RCVD', 'Y'); + $this->db->where($this->config->item('table_name') . '.COL_CALL !=', ''); + $this->db->where($this->config->item('table_name') . '.COL_EQSL_QSL_RCVD', 'Y'); $this->db->where('qso_id', NULL); $this->db->where_in('station_profile.station_id', $logbooks_locations_array); $this->db->order_by("COL_TIME_ON", "desc"); @@ -423,29 +428,31 @@ class Eqslmethods_model extends CI_Model { } // Returns all the distinct callsign, eqsl nick pair for the current user/supplied user - function all_of_user_with_eqsl_nick_defined($userid = null) { + function all_of_user_with_eqsl_nick_defined($userid = null) { if ($userid == null) { $this->db->where('user_id', $this->session->userdata('user_id')); } else { $this->db->where('user_id', $userid); } - $this->db->where('eqslqthnickname IS NOT NULL'); - $this->db->where('eqslqthnickname !=', ''); - $this->db->from('station_profile'); - $this->db->select('station_callsign, eqslqthnickname, station_id'); - $this->db->distinct(TRUE); + $this->db->where('eqslqthnickname IS NOT NULL'); + $this->db->where('eqslqthnickname !=', ''); + $this->db->from('station_profile'); + $this->db->select('station_callsign, eqslqthnickname, station_id'); + $this->db->distinct(TRUE); - return $this->db->get(); - } + return $this->db->get(); + } // Get the last date we received an eQSL function eqsl_last_qsl_rcvd_date($callsign, $nickname) { $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 AND station_profile.eqslqthnickname != ""'); + $this->db->join( + 'station_profile', + 'station_profile.station_id = ' . $qso_table_name . '.station_id AND station_profile.eqslqthnickname != ""' + ); $this->db->where('station_profile.station_callsign', $callsign); $this->db->where('station_profile.eqslqthnickname', $nickname); @@ -457,7 +464,7 @@ class Eqslmethods_model extends CI_Model { $query = $this->db->get(); $row = $query->row(); - if (isset($row->COL_EQSL_QSLRDATE)){ + if (isset($row->COL_EQSL_QSLRDATE)) { return $row->COL_EQSL_QSLRDATE; } else { // No previous date (first time import has run?), so choose UNIX EPOCH! @@ -476,10 +483,10 @@ class Eqslmethods_model extends CI_Model { 'COL_EQSL_QSL_RCVD' => $qsl_status ); - $this->db->where('COL_TIME_ON >= DATE_ADD(DATE_FORMAT("'.$datetime.'", \'%Y-%m-%d %H:%i\' ), INTERVAL -15 MINUTE )'); - $this->db->where('COL_TIME_ON <= DATE_ADD(DATE_FORMAT("'.$datetime.'", \'%Y-%m-%d %H:%i\' ), INTERVAL 15 MINUTE )'); + $this->db->where('COL_TIME_ON >= DATE_ADD(DATE_FORMAT("' . $datetime . '", \'%Y-%m-%d %H:%i\' ), INTERVAL -15 MINUTE )'); + $this->db->where('COL_TIME_ON <= DATE_ADD(DATE_FORMAT("' . $datetime . '", \'%Y-%m-%d %H:%i\' ), INTERVAL 15 MINUTE )'); $this->db->where('COL_CALL', $callsign); - $this->db->where('COL_STATION_CALLSIGN', $station_callsign); + $this->db->where('COL_STATION_CALLSIGN', $station_callsign); $this->db->where('COL_BAND', $band); $this->db->where('COL_MODE', $mode); $this->db->where('station_id', $station_id); @@ -492,25 +499,22 @@ class Eqslmethods_model extends CI_Model { // Determine if we've already received an eQSL for this QSO function eqsl_dupe_check($datetime, $callsign, $band, $mode, $qsl_status, $station_callsign, $station_id) { $this->db->select('COL_EQSL_QSLRDATE'); - $this->db->where('COL_TIME_ON >= DATE_ADD(DATE_FORMAT("'.$datetime.'", \'%Y-%m-%d %H:%i\' ), INTERVAL -15 MINUTE )'); - $this->db->where('COL_TIME_ON <= DATE_ADD(DATE_FORMAT("'.$datetime.'", \'%Y-%m-%d %H:%i\' ), INTERVAL 15 MINUTE )'); + $this->db->where('COL_TIME_ON >= DATE_ADD(DATE_FORMAT("' . $datetime . '", \'%Y-%m-%d %H:%i\' ), INTERVAL -15 MINUTE )'); + $this->db->where('COL_TIME_ON <= DATE_ADD(DATE_FORMAT("' . $datetime . '", \'%Y-%m-%d %H:%i\' ), INTERVAL 15 MINUTE )'); $this->db->where('COL_CALL', $callsign); $this->db->where('COL_BAND', $band); $this->db->where('COL_MODE', $mode); - $this->db->where('COL_STATION_CALLSIGN', $station_callsign); + $this->db->where('COL_STATION_CALLSIGN', $station_callsign); $this->db->where('COL_EQSL_QSL_RCVD', $qsl_status); $this->db->where('station_id', $station_id); $this->db->limit(1); - + $query = $this->db->get($this->config->item('table_name')); $row = $query->row(); - + if ($row != null) { return true; - } + } return false; } - } - -?> From 551e5ad45d428f9c1768107857a0dbf3b624a328 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Mon, 3 Jun 2024 08:12:12 +0200 Subject: [PATCH 3/5] small stuff --- application/controllers/Eqsl.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/application/controllers/Eqsl.php b/application/controllers/Eqsl.php index c625a3475..79c3a70e9 100644 --- a/application/controllers/Eqsl.php +++ b/application/controllers/Eqsl.php @@ -66,6 +66,7 @@ class eqsl extends CI_Controller { $eqsl_results = array(); if (($this->input->post('eqslimport') == 'fetch') && (!($this->config->item('disable_manual_eqsl')))) { + $this->load->library('EqslImporter'); // Get credentials for eQSL @@ -130,7 +131,7 @@ class eqsl extends CI_Controller { $this->load->view('interface_assets/header', $data); $this->load->view('eqsl/analysis'); $this->load->view('interface_assets/footer'); - } // end function + } public function export() { $this->load->model('user_model'); @@ -207,8 +208,6 @@ class eqsl extends CI_Controller { $this->load->view('interface_assets/footer'); } - - function generateResultTable($custom_date_format, $rows) { $table = ''; $table .= ""; @@ -227,8 +226,6 @@ class eqsl extends CI_Controller { return $table; } - - function writeEqslNotSent($qslsnotsent, $custom_date_format) { $table = '
'; $table .= ""; @@ -288,7 +285,7 @@ class eqsl extends CI_Controller { $password = $q->user_eqsl_password; $image_url = $this->electronicqsl->card_image($username, urlencode($password), $callsign, $band, $mode, $year, $month, $day, $hour, $minute); - $file = file_get_contents($image_url, true); + $file = file_get_contents($image_url, true); // TODO use curl instead $dom = new domDocument; $dom->loadHTML($file); @@ -438,6 +435,7 @@ class eqsl extends CI_Controller { $this->load->view('interface_assets/header', $data); $this->load->view('eqsl/result'); $this->load->view('interface_assets/footer'); + } else { $data['page_title'] = "eQSL Card Image Download"; From 8769858da60889dba9ccd8aabce3d68ee1007161 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Mon, 3 Jun 2024 08:13:56 +0200 Subject: [PATCH 4/5] $CI to $this --- application/models/Eqslmethods_model.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/application/models/Eqslmethods_model.php b/application/models/Eqslmethods_model.php index 65a2a5dfa..5105a74ab 100644 --- a/application/models/Eqslmethods_model.php +++ b/application/models/Eqslmethods_model.php @@ -354,10 +354,9 @@ class Eqslmethods_model extends CI_Model { // 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')); + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); } else { $stations = $this->get_all_user_locations($userid); $logbooks_locations_array = array(); @@ -386,10 +385,9 @@ class Eqslmethods_model extends CI_Model { // Show all QSOs whose eQSL card images we did not download yet function eqsl_not_yet_downloaded($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')); + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); } else { $stations = $this->get_all_user_locations($userid); $logbooks_locations_array = array(); From e672f1d72ad3a7d01b56413ac2020e04ab8cb38c Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Mon, 3 Jun 2024 08:43:38 +0200 Subject: [PATCH 5/5] comment --- application/models/Eqslmethods_model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/models/Eqslmethods_model.php b/application/models/Eqslmethods_model.php index 5105a74ab..a9fc2dc82 100644 --- a/application/models/Eqslmethods_model.php +++ b/application/models/Eqslmethods_model.php @@ -31,7 +31,7 @@ class Eqslmethods_model extends CI_Model { $eqsl_location['station_id'] ); - $eqsl_results[] = $this->eqslimporter->fetch($password); + $eqsl_results[] = $this->eqslimporter->fetch($password); // Hint: for debugging add YYYYMMDD as second argument to force from older date } }