Builds and uploads TQ8 File to LOTW, Marks QSOs as sent to LOTW if successful
这个提交包含在:
		
							父节点
							
								
									94f3060419
								
							
						
					
					
						当前提交
						25f620a486
					
				
					共有  3 个文件被更改,包括 115 次插入 和 11 次删除
				
			
		|  | @ -150,7 +150,12 @@ class Lotw extends CI_Controller { | ||||||
| 
 | 
 | ||||||
| 			$station_profiles = $this->Stations->all(); | 			$station_profiles = $this->Stations->all(); | ||||||
| 
 | 
 | ||||||
|  | 			// Array of QSO IDs being Uploaded
 | ||||||
|  | 
 | ||||||
|  | 			$qso_id_array = array(); | ||||||
|  | 
 | ||||||
| 			if ($station_profiles->num_rows() >= 1) { | 			if ($station_profiles->num_rows() >= 1) { | ||||||
|  | 
 | ||||||
| 				foreach ($station_profiles->result() as $station_profile) | 				foreach ($station_profiles->result() as $station_profile) | ||||||
| 				{ | 				{ | ||||||
| 
 | 
 | ||||||
|  | @ -168,7 +173,94 @@ class Lotw extends CI_Controller { | ||||||
| 
 | 
 | ||||||
| 					$data['qsos'] = $this->Logbook_model->get_lotw_qsos_to_upload($data['station_profile']->station_id); | 					$data['qsos'] = $this->Logbook_model->get_lotw_qsos_to_upload($data['station_profile']->station_id); | ||||||
| 
 | 
 | ||||||
| 					$this->load->view('lotw_views/adif_views/adif_export', $data); | 					foreach ($data['qsos']->result() as $temp_qso) {  | ||||||
|  | 						array_push($qso_id_array, $temp_qso->COL_PRIMARY_KEY); | ||||||
|  | 					} | ||||||
|  | 
 | ||||||
|  | 					//$this->load->view('lotw_views/adif_views/adif_export', $data);
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 					// Build File to save
 | ||||||
|  | 					$adif_to_save = $this->load->view('lotw_views/adif_views/adif_export', $data, TRUE); | ||||||
|  | 
 | ||||||
|  | 					// Build Filename
 | ||||||
|  | 
 | ||||||
|  | 					$filename_for_saving = $data['lotw_cert_info']->callsign."-".date("Y-m-d-H-i-s")."-cloudlog.tq8"; | ||||||
|  | 
 | ||||||
|  | 					$gzdata = gzencode($adif_to_save, 9); | ||||||
|  | 					$fp = fopen($filename_for_saving, "w"); | ||||||
|  | 					fwrite($fp, $gzdata); | ||||||
|  | 					fclose($fp); | ||||||
|  | 
 | ||||||
|  | 					//The URL that accepts the file upload.
 | ||||||
|  | 					$url = 'https://lotw.arrl.org/lotw/upload'; | ||||||
|  | 					  | ||||||
|  | 					//The name of the field for the uploaded file.
 | ||||||
|  | 					$uploadFieldName = 'upfile'; | ||||||
|  | 					  | ||||||
|  | 					//The full path to the file that you want to upload
 | ||||||
|  | 					$filePath = realpath($filename_for_saving); | ||||||
|  | 					  | ||||||
|  | 					//Initiate cURL
 | ||||||
|  | 					$ch = curl_init(); | ||||||
|  | 					  | ||||||
|  | 					//Set the URL
 | ||||||
|  | 					curl_setopt($ch, CURLOPT_URL, $url); | ||||||
|  | 					  | ||||||
|  | 					//Set the HTTP request to POST
 | ||||||
|  | 					curl_setopt($ch, CURLOPT_POST, true); | ||||||
|  | 					  | ||||||
|  | 					//Tell cURL to return the output as a string.
 | ||||||
|  | 					curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||||||
|  | 					  | ||||||
|  | 					//If the function curl_file_create exists
 | ||||||
|  | 					if(function_exists('curl_file_create')){ | ||||||
|  | 					    //Use the recommended way, creating a CURLFile object.
 | ||||||
|  | 					    $filePath = curl_file_create($filePath); | ||||||
|  | 					} else{ | ||||||
|  | 					    //Otherwise, do it the old way.
 | ||||||
|  | 					    //Get the canonicalized pathname of our file and prepend
 | ||||||
|  | 					    //the @ character.
 | ||||||
|  | 					    $filePath = '@' . realpath($filePath); | ||||||
|  | 					    //Turn off SAFE UPLOAD so that it accepts files
 | ||||||
|  | 					    //starting with an @
 | ||||||
|  | 					    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); | ||||||
|  | 					} | ||||||
|  | 					  | ||||||
|  | 					//Setup our POST fields
 | ||||||
|  | 					$postFields = array( | ||||||
|  | 					    $uploadFieldName => $filePath | ||||||
|  | 					); | ||||||
|  | 					  | ||||||
|  | 					curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); | ||||||
|  | 					  | ||||||
|  | 					//Execute the request
 | ||||||
|  | 					$result = curl_exec($ch); | ||||||
|  | 					  | ||||||
|  | 					//If an error occured, throw an exception
 | ||||||
|  | 					//with the error message.
 | ||||||
|  | 					if(curl_errno($ch)){ | ||||||
|  | 					    throw new Exception(curl_error($ch)); | ||||||
|  | 					} | ||||||
|  | 					  | ||||||
|  | 					$pos = strpos($result, "<!-- .UPL.  accepted -->"); | ||||||
|  | 
 | ||||||
|  | 					if ($pos === false) { | ||||||
|  | 						// Upload of TQ8 Failed for unknown reason
 | ||||||
|  | 					    echo "Upload Failed"; | ||||||
|  | 					} else { | ||||||
|  | 						// Upload of TQ8 was successfull
 | ||||||
|  | 
 | ||||||
|  | 					    echo "Upload Successful - ".$filename_for_saving; | ||||||
|  | 
 | ||||||
|  | 					    // Mark QSOs as Sent
 | ||||||
|  | 					    foreach ($qso_id_array as $qso_number) { | ||||||
|  | 					    	$this->Logbook_model->mark_lotw_sent($qso_number); | ||||||
|  | 					    } | ||||||
|  | 					} | ||||||
|  | 
 | ||||||
|  | 					// Delete TQ8 File - This is done regardless of whether upload was succcessful
 | ||||||
|  | 					unlink(realpath($filename_for_saving)); | ||||||
| 				} | 				} | ||||||
| 			} else { | 			} else { | ||||||
| 				echo "No Station Profiles"; | 				echo "No Station Profiles"; | ||||||
|  |  | ||||||
|  | @ -2160,10 +2160,11 @@ class Logbook_model extends CI_Model { | ||||||
|   |   | ||||||
|   function get_lotw_qsos_to_upload($station_id) { |   function get_lotw_qsos_to_upload($station_id) { | ||||||
| 
 | 
 | ||||||
|     $this->db->select('COL_CALL, COL_BAND, COL_BAND_RX, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_FREQ, COL_FREQ_RX, COL_GRIDSQUARE, COL_SAT_NAME, COL_PROP_MODE'); |     $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_FREQ, COL_FREQ_RX, COL_GRIDSQUARE, COL_SAT_NAME, COL_PROP_MODE, COL_LOTW_QSL_SENT, station_id'); | ||||||
| 
 | 
 | ||||||
|     $this->db->where("station_id", 1); |     $this->db->where("station_id", 1); | ||||||
| 
 |     $this->db->where('COL_LOTW_QSL_SENT !=', "Y"); | ||||||
|  |     $this->db->where('COL_PROP_MODE !=', "INTERNET"); | ||||||
|     $this->db->order_by("COL_TIME_ON", "desc"); |     $this->db->order_by("COL_TIME_ON", "desc"); | ||||||
|     $this->db->limit(1); |     $this->db->limit(1); | ||||||
|     $query = $this->db->get($this->config->item('table_name')); |     $query = $this->db->get($this->config->item('table_name')); | ||||||
|  | @ -2171,6 +2172,20 @@ class Logbook_model extends CI_Model { | ||||||
|     return $query; |     return $query; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   function mark_lotw_sent($qso_id) { | ||||||
|  | 
 | ||||||
|  |       $data = array( | ||||||
|  |            'COL_LOTW_QSLSDATE' => date("Y-m-d H:i:s"), | ||||||
|  |            'COL_LOTW_QSL_SENT' => 'Y', | ||||||
|  |       ); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     $this->db->where('COL_PRIMARY_KEY', $qso_id); | ||||||
|  | 
 | ||||||
|  |     $this->db->update($this->config->item('table_name'), $data); | ||||||
|  | 
 | ||||||
|  |     return "Updated"; | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function validateADIFDate($date, $format = 'Ymd') | function validateADIFDate($date, $format = 'Ymd') | ||||||
|  |  | ||||||
|  | @ -1,6 +1,3 @@ | ||||||
| <?php |  | ||||||
| 	header('Content-Type: text/plain; charset=utf-8'); |  | ||||||
| ?>
 |  | ||||||
| <?php  | <?php  | ||||||
| $clean_cert = trim($lotw_cert_info->cert); | $clean_cert = trim($lotw_cert_info->cert); | ||||||
| $cert1 = str_replace("-----BEGIN CERTIFICATE-----", "", $clean_cert); | $cert1 = str_replace("-----BEGIN CERTIFICATE-----", "", $clean_cert); | ||||||
|  | @ -21,7 +18,7 @@ $cert2 = str_replace("-----END CERTIFICATE-----", "", $cert1); | ||||||
| 
 | 
 | ||||||
| <DXCC:<?php echo strlen($station_profile_dxcc->adif); ?>><?php echo $station_profile_dxcc->adif; ?>
 | <DXCC:<?php echo strlen($station_profile_dxcc->adif); ?>><?php echo $station_profile_dxcc->adif; ?>
 | ||||||
| 
 | 
 | ||||||
| <GRIDSQUARE:<?php echo strlen($station_profile->station_gridsquare); ?>><?php echo $station_profile->station_gridsquare; ?>
 | <?php if(isset($station_profile->station_gridsquare)) { ?><GRIDSQUARE:<?php echo strlen($station_profile->station_gridsquare); ?>><?php echo $station_profile->station_gridsquare; ?><?php } ?>
 | ||||||
| 
 | 
 | ||||||
| <?php if(isset($station_profile->station_itu)) { ?><ITUZ:<?php echo strlen($station_profile->station_itu); ?>><?php echo $station_profile->station_itu; ?><?php } ?>
 | <?php if(isset($station_profile->station_itu)) { ?><ITUZ:<?php echo strlen($station_profile->station_itu); ?>><?php echo $station_profile->station_itu; ?><?php } ?>
 | ||||||
| 
 | 
 | ||||||
|  | @ -42,11 +39,11 @@ $cert2 = str_replace("-----END CERTIFICATE-----", "", $cert1); | ||||||
| 
 | 
 | ||||||
| <?php if($qso->COL_FREQ != "0") { ?><?php $freq_in_mhz = $qso->COL_FREQ / 1000000; ?><FREQ:<?php echo strlen($freq_in_mhz); ?>><?php echo $freq_in_mhz; ?><?php } ?>
 | <?php if($qso->COL_FREQ != "0") { ?><?php $freq_in_mhz = $qso->COL_FREQ / 1000000; ?><FREQ:<?php echo strlen($freq_in_mhz); ?>><?php echo $freq_in_mhz; ?><?php } ?>
 | ||||||
| 
 | 
 | ||||||
| <?php if($qso->COL_FREQ_RX) { ?><?php $freq_in_mhz_rx = $qso->COL_FREQ_RX / 1000000; ?><FREQ_RX:<?php echo strlen($freq_in_mhz_rx); ?>><?php echo $freq_in_mhz_rx; ?><?php } ?>
 | <?php if($qso->COL_FREQ_RX != "" || $qso->COL_FREQ_RX != "0") { ?><?php $freq_in_mhz_rx = $qso->COL_FREQ_RX / 1000000; ?><FREQ_RX:<?php echo strlen($freq_in_mhz_rx); ?>><?php echo $freq_in_mhz_rx; ?><?php } ?>
 | ||||||
| 
 | 
 | ||||||
| <PROP_MODE:<?php echo strlen($qso->COL_PROP_MODE); ?>><?php echo strtoupper($qso->COL_PROP_MODE); ?>
 | <?php if($qso->COL_PROP_MODE) { ?><PROP_MODE:<?php echo strlen($qso->COL_PROP_MODE); ?>><?php echo strtoupper($qso->COL_PROP_MODE); ?><?php } ?>
 | ||||||
| 
 | 
 | ||||||
| <SAT_NAME:<?php echo strlen($qso->COL_SAT_NAME); ?>><?php echo strtoupper($qso->COL_SAT_NAME); ?>
 | <?php if($qso->COL_SAT_NAME) { ?><SAT_NAME:<?php echo strlen($qso->COL_SAT_NAME); ?>><?php echo strtoupper($qso->COL_SAT_NAME); ?><?php } ?>
 | ||||||
| 
 | 
 | ||||||
| <?php if($qso->COL_BAND_RX) { ?><BAND_RX:<?php echo strlen($qso->COL_BAND_RX); ?>><?php echo strtoupper($qso->COL_BAND_RX); ?><?php } ?>
 | <?php if($qso->COL_BAND_RX) { ?><BAND_RX:<?php echo strlen($qso->COL_BAND_RX); ?>><?php echo strtoupper($qso->COL_BAND_RX); ?><?php } ?>
 | ||||||
| 
 | 
 | ||||||
|  | @ -95,7 +92,7 @@ if($freq_in_mhz) { | ||||||
| 	$sign_string .= strtoupper($freq_in_mhz); | 	$sign_string .= strtoupper($freq_in_mhz); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| if($freq_in_mhz_rx) { | if($qso->COL_FREQ_RX != "" || $qso->COL_FREQ_RX != "0") { | ||||||
| 	$sign_string .= strtoupper($freq_in_mhz_rx); | 	$sign_string .= strtoupper($freq_in_mhz_rx); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		正在加载…
	
		在新工单中引用