diff --git a/application/controllers/Dcl.php b/application/controllers/Dcl.php
index 172a08f86..0970583f1 100644
--- a/application/controllers/Dcl.php
+++ b/application/controllers/Dcl.php
@@ -42,41 +42,7 @@ class Dcl extends CI_Controller {
$this->load->view('interface_assets/footer');
}
- /*
- |--------------------------------------------------------------------------
- | Function: cert_upload
- |--------------------------------------------------------------------------
- |
- | Nothing fancy just shows the cert_upload form for uploading p12 files
- |
- */
- public function cert_upload() {
- $this->load->model('user_model');
- $this->load->model('dxcc');
- if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }
-
- // Load DXCC Countrys List
- $data['dxcc_list'] = $this->dxcc->list();
-
- // Set Page Title
- $data['page_title'] = __("Logbook of the World");
-
- // Load Views
- $this->load->view('interface_assets/header', $data);
- $this->load->view('lotw_views/upload_cert', array('error' => ' ' ));
- $this->load->view('interface_assets/footer');
- }
-
-
- /*
- |--------------------------------------------------------------------------
- | Function: lotw_upload
- |--------------------------------------------------------------------------
- |
- | This function Uploads to LoTW
- |
- */
- public function lotw_upload() {
+ public function dcl_upload() {
$this->load->model('user_model');
$this->user_model->authorize(2);
@@ -88,6 +54,10 @@ class Dcl extends CI_Controller {
// Get Station Profile Data
$this->load->model('Stations');
+ if (!$this->load->is_loaded('AdifHelper')) {
+ $this->load->library('AdifHelper');
+ }
+
if ($this->user_model->authorize(2)) {
if (!($this->config->item('disable_manual_lotw'))) {
$station_profiles = $this->Stations->all_of_user($this->session->userdata('user_id'));
@@ -111,37 +81,28 @@ class Dcl extends CI_Controller {
foreach ($station_profiles->result() as $station_profile) {
+ log_message("Error",$station_profile->station_id);
// Get Certificate Data
- $this->load->model('Lotw_model');
+ $this->load->model('Dcl_model');
$data['station_profile'] = $station_profile;
- $data['lotw_cert_info'] = $this->Lotw_model->lotw_cert_details($station_profile->station_callsign, $station_profile->station_dxcc, $station_profile->user_id);
-
- // If Station Profile has no LoTW Cert continue on.
- if(!isset($data['lotw_cert_info']->cert_dxcc_id)) {
- echo $station_profile->station_callsign.": No LoTW certificate for station callsign found.
";
+ $key_info = $this->Dcl_model->find_key($station_profile->station_callsign, $station_profile->user_id);
+ if (($key_info ?? '') == '') {
continue;
}
- // Check if LoTW certificate itself is valid
- // Validty of QSO dates will be checked later
- $current_date = date('Y-m-d H:i:s');
- if ($current_date <= $data['lotw_cert_info']->date_created) {
- echo $data['lotw_cert_info']->callsign.": LoTW certificate not valid yet!";
- continue;
- }
- if ($current_date >= $data['lotw_cert_info']->date_expires) {
- echo $data['lotw_cert_info']->callsign.": LoTW certificate expired!";
- continue;
- }
+ $data['dcl_key_info']=new stdClass();
+ $data['dcl_key_info']->call = $key_info[0]->option_key ?? '';
+ $data['dcl_key_info'] = json_decode($key_info[0]->option_value ?? '');
- // Get QSOs
+ // If Station Profile has no DCL Key continue on.
+ if (($data['dcl_key_info']->call ?? '') == '') {
+ echo $station_profile->station_callsign.": No DCL Key for station callsign found.
";
+ continue;
+ }
$this->load->model('Logbook_model');
- // First mark QSOs with unsupported propagation modes as ignore
- $this->Logbook_model->mark_lotw_ignore($data['station_profile']->station_id);
-
- $data['qsos'] = $this->Logbook_model->get_lotw_qsos_to_upload($data['station_profile']->station_id, $data['lotw_cert_info']->qso_start_date, $data['lotw_cert_info']->qso_end_date);
+ $data['qsos'] = $this->Logbook_model->get_dcl_qsos_to_upload($data['station_profile']->station_id);
// Nothing to upload
if(empty($data['qsos']->result())){
@@ -156,28 +117,22 @@ class Dcl extends CI_Controller {
}
// Build File to save
- $adif_to_save = $this->load->view('lotw_views/adif_views/adif_export', $data, TRUE);
- if (strpos($adif_to_save, '')) {
- // Signing failed
- echo "Signing failed.";
- continue;
- }
-
+ $adif_to_save = $this->load->view('adif/data/dcl.php', $data, TRUE);
+
// create folder to store upload file
- if (!file_exists('./uploads/lotw')) {
- mkdir('./uploads/lotw', 0775, true);
+ if (!file_exists('./uploads/dcl')) {
+ mkdir('./uploads/dcl', 0775, true);
}
// Build Filename
- $filename_for_saving = './uploads/lotw/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($data['lotw_cert_info']->callsign))."-".date("Y-m-d-H-i-s")."-wavelog.tq8";
+ $filename_for_saving = './uploads/dcl/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($data['dcl_key_info']->call))."-".date("Y-m-d-H-i-s")."-wavelog.adif";
- $gzdata = gzencode($adif_to_save, 9);
$fp = fopen($filename_for_saving, "w");
- fwrite($fp, $gzdata);
+ fwrite($fp, $adif_to_save);
fclose($fp);
//The URL that accepts the file upload.
- $url = 'https://lotw.arrl.org/lotw/upload';
+ $url = 'https://dclnext.darc.de';
//The name of the field for the uploaded file.
$uploadFieldName = 'upfile';
@@ -210,11 +165,11 @@ class Dcl extends CI_Controller {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
//Execute the request
- $result = curl_exec($ch);
+ // $result = curl_exec($ch);
if(curl_errno($ch)){
echo $station_profile->station_callsign." (".$station_profile->station_profile_name."): Upload Failed - ".curl_strerror(curl_errno($ch))." (".curl_errno($ch).")
";
- $this->Lotw_model->last_upload($data['lotw_cert_info']->lotw_cert_id, "Upload failed");
+ $this->Dcl_model->last_upload($data['dcl_key_info']->call, "Upload failed", $this->session->userdata('user_id'));
if (curl_errno($ch) == 28) { // break on timeout
echo "Timeout reached. Stopping subsequent uploads.
";
break;
@@ -223,12 +178,13 @@ class Dcl extends CI_Controller {
}
}
- $pos = strpos($result, "");
+ // $pos = strpos($result, "");
+ $pos = true;
if ($pos === false) {
// Upload of TQ8 Failed for unknown reason
echo $station_profile->station_callsign." (".$station_profile->station_profile_name."): Upload Failed - ".curl_strerror(curl_errno($ch))." (".curl_errno($ch).")
";
- $this->Lotw_model->last_upload($data['lotw_cert_info']->lotw_cert_id, "Upload failed");
+ $this->Dcl_model->last_upload($data['dcl_key_info']->call, "Upload failed", $this->session->userdata('user_id'));
if (curl_errno($ch) == 28) { // break on timeout
echo "Timeout reached. Stopping subsequent uploads.
";
break;
@@ -240,16 +196,16 @@ class Dcl extends CI_Controller {
echo $station_profile->station_callsign." (".$station_profile->station_profile_name."): Upload Successful - ".$filename_for_saving."
";
- $this->Lotw_model->last_upload($data['lotw_cert_info']->lotw_cert_id, "Success");
+ $this->Dcl_model->last_upload($data['dcl_key_info']->call, "Success", $this->session->userdata('user_id'));
// Mark QSOs as Sent
foreach ($qso_id_array as $qso_number) {
- $this->Logbook_model->mark_lotw_sent($qso_number);
+ // $this->Logbook_model->mark_dcl_sent($qso_number);
}
}
// Delete TQ8 File - This is done regardless of whether upload was succcessful
- unlink(realpath($filename_for_saving));
+ // unlink(realpath($filename_for_saving));
}
} else {
echo "No Station Profiles found to upload to LoTW";
diff --git a/application/models/Dcl_model.php b/application/models/Dcl_model.php
index 4e6e52e77..1f9ba7c1a 100644
--- a/application/models/Dcl_model.php
+++ b/application/models/Dcl_model.php
@@ -31,53 +31,18 @@ class Dcl_model extends CI_Model {
$this->user_options_model->del_option('dcl', 'dcl_key',array('option_key' => $call));
}
- function last_upload($key, $message) {
+ function last_upload($key, $message, $user_id) {
+ $this->load->model('user_options_model');
+ $dclrkey=$this->user_options_model->get_options('dcl', array('option_name'=>'dcl_key'), $user_id)->result();
+ $dclkey = json_decode($dclrkey[0]->option_value ?? '');
+ $dclkey->call = $dclrkey[0]->option_key ?? '';
+ $dclnewkey=$dclkey;
if ($message == "Success") {
- $data = array(
- 'last_upload' => date("Y-m-d H:i:s"),
- 'last_upload_status' => $message,
- );
-
- $this->db->where('lotw_cert_id', $certID);
- $this->db->update('lotw_certs', $data);
- return "Updated";
- }
- else if ($message == "Upload failed") {
- $data = array(
- 'last_upload_fail' => date("Y-m-d H:i:s"),
- 'last_upload_status' => $message,
- );
-
- $this->db->where('lotw_cert_id', $certID);
- $this->db->update('lotw_certs', $data);
- return "Updated";
+ $dclnewkey->last_sync=date("Y-m-d H:i:s");
+ $this->user_options_model->set_option('dcl', 'dcl_key', array($dclkey->call => json_encode($dclnewkey)), $user_id);
}
+ return "Updated";
}
-
- function lotw_cert_expired($user_id, $date) {
- $array = array('user_id' => $user_id, 'date_expires <' => $date);
- $this->db->where($array);
- $query = $this->db->get('lotw_certs');
-
- if ($query->num_rows() > 0) {
- return true;
- } else {
- return false;
- }
- }
-
- function lotw_cert_expiring($user_id, $date) {
- $array = array('user_id' => $user_id, 'DATE_SUB(date_expires, INTERVAL 30 DAY) <' => $date, 'date_expires >' => $date);
- $this->db->where($array);
- $query = $this->db->get('lotw_certs');
-
- if ($query->num_rows() > 0) {
- return true;
- } else {
- return false;
- }
- }
-
}
?>
diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php
index 1b3de21fd..81641c728 100644
--- a/application/models/Logbook_model.php
+++ b/application/models/Logbook_model.php
@@ -5343,6 +5343,19 @@ class Logbook_model extends CI_Model {
return $query->result();
}
+ function get_dcl_qsos_to_upload($station_id) {
+
+ $sql = 'select *, dxcc_entities.name as station_country from ' . $this->config->item('table_name') . ' thcv ' .
+ ' left join station_profile on thcv.station_id = station_profile.station_id' .
+ ' left outer join dxcc_entities on thcv.col_my_dxcc = dxcc_entities.adif' .
+ ' where thcv.station_id = ?' .
+ ' and (COL_DCL_QSL_SENT not in ("Y","I") OR COL_DCL_QSL_SENT is null)';
+ $binding[] = $station_id;
+
+ $query = $this->db->query($sql, $binding);
+ return $query;
+ }
+
function get_lotw_qsos_to_upload($station_id, $start_date, $end_date) {
$this->db->select('COL_PRIMARY_KEY,COL_CALL, COL_BAND, COL_BAND_RX, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_SUBMODE, COL_FREQ, COL_FREQ_RX, COL_GRIDSQUARE, COL_SAT_NAME, COL_PROP_MODE, COL_LOTW_QSL_SENT, station_id');
@@ -5362,6 +5375,21 @@ class Logbook_model extends CI_Model {
return $query;
}
+ function mark_dcl_sent($qso_id) {
+
+ $data = array(
+ 'COL_DCL_QSLSDATE' => date("Y-m-d H:i:s"),
+ 'COL_DCL_QSL_SENT' => 'Y',
+ );
+
+
+ $this->db->where('COL_PRIMARY_KEY', $qso_id);
+
+ $this->db->update($this->config->item('table_name'), $data);
+
+ return "Updated";
+ }
+
function mark_lotw_sent($qso_id) {
$data = array(
diff --git a/application/models/User_options_model.php b/application/models/User_options_model.php
index d69094d5c..a8d3e174c 100644
--- a/application/models/User_options_model.php
+++ b/application/models/User_options_model.php
@@ -8,8 +8,10 @@ class User_options_model extends CI_Model {
return $this->db->get('user_options');
}
- public function set_option($option_type, $option_name, $option_array) {
- $uid=$this->session->userdata('user_id');
+ public function set_option($option_type, $option_name, $option_array, $uid=null) {
+ if (($uid ?? '') == '') {
+ $uid=$this->session->userdata('user_id');
+ }
$sql='insert into user_options (user_id,option_type,option_name,option_key,option_value) values (?,?,?,?,?) ON DUPLICATE KEY UPDATE option_value=?';
foreach($option_array as $option_key => $option_value) {
$query = $this->db->query($sql, array($uid, $option_type, $option_name, $option_key, $option_value, $option_value));
diff --git a/application/views/dcl_views/adif_views/adif_export.php b/application/views/dcl_views/adif_views/adif_export.php
deleted file mode 100644
index 7be4e772e..000000000
--- a/application/views/dcl_views/adif_views/adif_export.php
+++ /dev/null
@@ -1,172 +0,0 @@
-cert);
-$cert1 = str_replace("-----BEGIN CERTIFICATE-----", "", $clean_cert);
-$cert2 = str_replace("-----END CERTIFICATE-----", "", $cert1);
-?>
-TQSL V2.5.4 Lib: V2.5 Config: V11.12 AllowDupes: false
-
-tCERT
-1
->
-
-
-
-tSTATION
-1
-1
-callsign); ?>>callsign; ?>
-
-cert_dxcc_id); ?>>cert_dxcc_id; ?>
-
-station_gridsquare) { ?>station_gridsquare); ?>>station_gridsquare; } ?>
-
-station_itu) { ?>station_itu); ?>>station_itu; } ?>
-
-station_cq) { ?>station_cq); ?>>station_cq; } ?>
-
-station_iota) { ?>station_iota); ?>>station_iota; } ?>
-
-state != "" && $station_profile->station_country == "CANADA") { ?>lotw_ca_province_map($station_profile->state)); ?>>lotw_ca_province_map($station_profile->state); } ?>
-
-state != "" && $station_profile->station_country == "UNITED STATES OF AMERICA") { ?>state); ?>>state; } ?>
-
-state != "" && $station_profile->station_country == "CHINA") { ?>state); ?>>state; } ?>
-
-station_cnty != "" && $station_profile->station_country == "UNITED STATES OF AMERICA") { ?>station_cnty); ?>>station_cnty; } ?>
-
-
-
-result() as $qso) {
- unset($freq_in_mhz);
- unset($freq_in_mhz_rx);
-?>
-tCONTACT
-1
-COL_CALL); ?>>COL_CALL; ?>
-
-COL_BAND); ?>>COL_BAND); ?>
-
-mode_map($qso->COL_MODE, $qso->COL_SUBMODE)); ?>>mode_map(($qso->COL_MODE == null ? '' : strtoupper($qso->COL_MODE)), ($qso->COL_SUBMODE == null ? '' : strtoupper($qso->COL_SUBMODE)))); ?>
-
-COL_FREQ != "" && $qso->COL_FREQ != "0") { $freq_in_mhz = $qso->COL_FREQ / 1000000; ?>>
-
-COL_FREQ_RX != "" && $qso->COL_FREQ_RX != "0") { $freq_in_mhz_rx = $qso->COL_FREQ_RX / 1000000; ?>>
-
-COL_PROP_MODE) { ?>COL_PROP_MODE); ?>>COL_PROP_MODE); } ?>
-
-COL_SAT_NAME) { ?>COL_SAT_NAME); ?>>COL_SAT_NAME); } ?>
-
-COL_BAND_RX) { ?>COL_BAND_RX); ?>>COL_BAND_RX); } ?>
-
-COL_TIME_ON); $new_date = date('Y-m-d', $date_on); ?>
->
-
-COL_TIME_ON); $new_on = date('H:i:s', $time_on); ?>
->
-
-state != "" && $station_profile->station_country == "CANADA") {
- $sign_string .= strtoupper($CI->lotw_ca_province_map($station_profile->state));
-}
-
-// Adds CN Province
-if($station_profile->state != "" && $station_profile->station_country == "CHINA") {
- $sign_string .= strtoupper($station_profile->state);
-}
-
-// Add CQ Zone
-if($station_profile->station_cq) {
- $sign_string .= $station_profile->station_cq;
-}
-
-// Add Gridsquare
-if($station_profile->station_gridsquare) {
- $sign_string .= strtoupper($station_profile->station_gridsquare);
-}
-
-if($station_profile->station_iota) {
- $sign_string .= strtoupper($station_profile->station_iota);
-}
-
-if($station_profile->station_itu) {
- $sign_string .= $station_profile->station_itu;
-}
-
-if($station_profile->station_cnty != "" && $station_profile->station_country == "UNITED STATES OF AMERICA") {
- $sign_string .= strtoupper($station_profile->station_cnty);
-}
-
-if($station_profile->station_cnty != "" && $station_profile->station_country == "ALASKA") {
- $sign_string .= strtoupper($station_profile->station_cnty);
-}
-
-if($station_profile->station_cnty != "" && $station_profile->station_country == "HAWAII") {
- $sign_string .= strtoupper($station_profile->station_cnty);
-}
-
-if($station_profile->state != "" && $station_profile->station_country == "UNITED STATES OF AMERICA") {
- $sign_string .= strtoupper($station_profile->state);
-}
-
-if($station_profile->state != "" && $station_profile->station_country == "ALASKA") {
- $sign_string .= strtoupper($station_profile->state);
-}
-
-if($station_profile->state != "" && $station_profile->station_country == "HAWAII") {
- $sign_string .= strtoupper($station_profile->state);
-}
-
-if($qso->COL_BAND) {
- $sign_string .= strtoupper($qso->COL_BAND);
-}
-
-if($qso->COL_BAND_RX) {
- $sign_string .= strtoupper($qso->COL_BAND_RX);
-}
-
-if($qso->COL_CALL) {
- $sign_string .= strtoupper($qso->COL_CALL);
-}
-
-if(isset($freq_in_mhz)) {
- $sign_string .= strtoupper($freq_in_mhz);
-}
-
-if(isset($freq_in_mhz_rx)) {
- $sign_string .= strtoupper($freq_in_mhz_rx);
-}
-
-if($qso->COL_MODE) {
- $sign_string .= strtoupper($CI->mode_map($qso->COL_MODE, $qso->COL_SUBMODE));
-}
-
-
-if($qso->COL_PROP_MODE) {
- $sign_string .= strtoupper($qso->COL_PROP_MODE);
-}
-
-$sign_string .= $new_date;
-
-$sign_string .= $new_on."Z";
-
-if($qso->COL_SAT_NAME) {
- $sign_string .= strtoupper($qso->COL_SAT_NAME);
-}
-
- ?>
-signlog($lotw_cert_info->cert_key, $sign_string);
-?>
-:6>
-
->
-
-
-
-