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',