Merge pull request #694 from jsb2092/master
Added support for lookups in services for more detailed information when logged in
这个提交包含在:
		
						当前提交
						fa1bb549ee
					
				
					共有  5 个文件被更改,包括 143 次插入 和 101 次删除
				
			
		|  | @ -137,7 +137,7 @@ class Logbook extends CI_Controller { | ||||||
|             $measurement_base = $this->session->userdata('user_measurement_base'); |             $measurement_base = $this->session->userdata('user_measurement_base'); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 		$return['callsign_name'] = $this->logbook_model->call_name($callsign); | 		$return['callsign_name'] =  $this->logbook_model->call_name($callsign); | ||||||
| 		$return['callsign_qra'] = $this->logbook_model->call_qra($callsign); | 		$return['callsign_qra'] = $this->logbook_model->call_qra($callsign); | ||||||
| 		$return['callsign_qth'] = $this->logbook_model->call_qth($callsign); | 		$return['callsign_qth'] = $this->logbook_model->call_qth($callsign); | ||||||
| 		$return['callsign_iota'] = $this->logbook_model->call_iota($callsign); | 		$return['callsign_iota'] = $this->logbook_model->call_iota($callsign); | ||||||
|  | @ -155,38 +155,8 @@ class Logbook extends CI_Controller { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) | 	$callbook = $this->logbook_model->loadCallBook($callsign, $this->config->item('use_fullname')); | ||||||
| 	{ |  | ||||||
| 		// Lookup using QRZ
 |  | ||||||
| 		$this->load->library('qrz'); |  | ||||||
| 
 | 
 | ||||||
| 		if(!$this->session->userdata('qrz_session_key')) { |  | ||||||
| 			$qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); |  | ||||||
| 			$this->session->set_userdata('qrz_session_key', $qrz_session_key); |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		$callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key')); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) |  | ||||||
| 	{ |  | ||||||
| 		// Load the HamQTH library
 |  | ||||||
| 		$this->load->library('hamqth'); |  | ||||||
| 
 |  | ||||||
| 		if(!$this->session->userdata('hamqth_session_key')) { |  | ||||||
| 			$hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); |  | ||||||
| 			$this->session->set_userdata('hamqth_session_key', $hamqth_session_key); |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		$callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); |  | ||||||
| 
 |  | ||||||
| 		// If HamQTH session has expired, start a new session and retry the search.
 |  | ||||||
| 		if($callbook['error'] == "Session does not exist or expired") { |  | ||||||
| 			$hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); |  | ||||||
| 			$this->session->set_userdata('hamqth_session_key', $hamqth_session_key); |  | ||||||
| 			$callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	if (isset($callbook)) | 	if (isset($callbook)) | ||||||
| 	{ | 	{ | ||||||
|  | @ -553,8 +523,14 @@ class Logbook extends CI_Controller { | ||||||
| 						$qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); | 						$qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); | ||||||
| 						$this->session->set_userdata('qrz_session_key', $qrz_session_key); | 						$this->session->set_userdata('qrz_session_key', $qrz_session_key); | ||||||
| 					} | 					} | ||||||
|  |                     $data= $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); | ||||||
| 
 | 
 | ||||||
| 					$data['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key')); |                     if (empty($data['callsign'])) | ||||||
|  |                     { | ||||||
|  |                         $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); | ||||||
|  |                         $this->session->set_userdata('qrz_session_key', $qrz_session_key); | ||||||
|  |                         $data = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); | ||||||
|  |                     } | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				// There's no hamli integration? Disabled for now.
 | 				// There's no hamli integration? Disabled for now.
 | ||||||
|  | @ -611,7 +587,7 @@ class Logbook extends CI_Controller { | ||||||
| 						$this->session->set_userdata('qrz_session_key', $qrz_session_key); | 						$this->session->set_userdata('qrz_session_key', $qrz_session_key); | ||||||
| 					} | 					} | ||||||
| 
 | 
 | ||||||
| 					$data['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key')); | 					$data['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); | ||||||
| 				} else { | 				} else { | ||||||
| 					// Lookup using hamli
 | 					// Lookup using hamli
 | ||||||
| 					$this->load->library('hamli'); | 					$this->load->library('hamli'); | ||||||
|  |  | ||||||
|  | @ -56,41 +56,44 @@ class Hamqth { | ||||||
| 
 | 
 | ||||||
| 	public function search($callsign, $key) | 	public function search($callsign, $key) | ||||||
| 	{ | 	{ | ||||||
|  | 	    $data = null; | ||||||
|  |         try { | ||||||
|  |             // URL to the XML Source
 | ||||||
|  |             $xml_feed_url = 'https://www.hamqth.com/xml.php?id=' . $key . '&callsign=' . $callsign . '&prg=cloudlog'; | ||||||
| 
 | 
 | ||||||
| 		// URL to the XML Source
 |             // CURL Functions
 | ||||||
| 		$xml_feed_url = 'https://www.hamqth.com/xml.php?id='.$key.'&callsign='.$callsign.'&prg=cloudlog'; |             $ch = curl_init(); | ||||||
|  |             curl_setopt($ch, CURLOPT_URL, $xml_feed_url); | ||||||
|  |             curl_setopt($ch, CURLOPT_HEADER, false); | ||||||
|  |             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||||||
|  |             $xml = curl_exec($ch); | ||||||
|  |             curl_close($ch); | ||||||
| 
 | 
 | ||||||
| 		// CURL Functions
 |             // Create XML object
 | ||||||
| 		$ch = curl_init(); |             $xml = simplexml_load_string($xml); | ||||||
| 		curl_setopt($ch, CURLOPT_URL, $xml_feed_url); |             if (empty($xml)) return; | ||||||
| 		curl_setopt($ch, CURLOPT_HEADER, false); |  | ||||||
| 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |  | ||||||
| 		$xml = curl_exec($ch); |  | ||||||
| 		curl_close($ch); |  | ||||||
| 
 | 
 | ||||||
| 		// Create XML object
 |             // Return Required Fields
 | ||||||
| 		$xml = simplexml_load_string($xml); |             $data['callsign'] = (string)$xml->search->callsign; | ||||||
|  |             $data['name'] = (string)$xml->search->nick; | ||||||
|  |             $data['gridsquare'] = (string)$xml->search->grid; | ||||||
|  |             $data['city'] = (string)$xml->search->adr_city; | ||||||
|  |             $data['lat'] = (string)$xml->search->latitude; | ||||||
|  |             $data['long'] = (string)$xml->search->longitude; | ||||||
|  |             $data['iota'] = (string)$xml->search->iota; | ||||||
|  |             $data['us_state'] = (string)$xml->search->us_state; | ||||||
|  |             $data['us_county'] = (string)$xml->search->us_county; | ||||||
|  |             $data['error'] = (string)$xml->session->error; | ||||||
| 
 | 
 | ||||||
| 		// Return Required Fields
 |             if ($xml->search->country == "United States") { | ||||||
| 		$data['callsign'] = (string) $xml->search->callsign; |                 $data['state'] = (string)$xml->search->us_state; | ||||||
| 		$data['name'] = (string) $xml->search->nick; |                 $data['us_county'] = (string)$xml->search->us_county; | ||||||
| 		$data['gridsquare'] = (string) $xml->search->grid; |             } else { | ||||||
| 		$data['city'] = (string) $xml->search->adr_city; |                 $data['state'] = null; | ||||||
| 		$data['lat'] = (string) $xml->search->latitude; |                 $data['us_county'] = null; | ||||||
| 		$data['long'] = (string) $xml->search->longitude; |             } | ||||||
| 		$data['iota'] = (string) $xml->search->iota; |         } finally { | ||||||
| 		$data['us_state'] = (string) $xml->search->us_state; |             return $data; | ||||||
| 		$data['us_county'] = (string) $xml->search->us_county; |         } | ||||||
| 		$data['error'] = (string) $xml->session->error; |  | ||||||
| 
 |  | ||||||
| 		if($xml->search->country == "United States") { |  | ||||||
| 			$data['state'] = (string) $xml->search->us_state; |  | ||||||
| 			$data['us_county'] = (string) $xml->search->us_county;	 |  | ||||||
| 		} else { |  | ||||||
| 			$data['state'] = null; |  | ||||||
| 			$data['us_county'] = null;		 |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		return $data; |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -54,42 +54,51 @@ class Qrz { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	public function search($callsign, $key) | 	public function search($callsign, $key, $use_fullname) | ||||||
| 	{ | 	{ | ||||||
|  |         $data = null; | ||||||
|  |         try { | ||||||
|  |             // URL to the XML Source
 | ||||||
|  |             $xml_feed_url = 'http://xmldata.qrz.com/xml/current/?s=' . $key . ';callsign=' . $callsign . ''; | ||||||
| 
 | 
 | ||||||
| 		// URL to the XML Source
 |             // CURL Functions
 | ||||||
| 		$xml_feed_url = 'http://xmldata.qrz.com/xml/current/?s='.$key.';callsign='.$callsign.''; |             $ch = curl_init(); | ||||||
|  |             curl_setopt($ch, CURLOPT_URL, $xml_feed_url); | ||||||
|  |             curl_setopt($ch, CURLOPT_HEADER, false); | ||||||
|  |             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||||||
|  |             $xml = curl_exec($ch); | ||||||
|  |             curl_close($ch); | ||||||
| 
 | 
 | ||||||
| 		// CURL Functions
 |             // Create XML object
 | ||||||
| 		$ch = curl_init(); |             $xml = simplexml_load_string($xml); | ||||||
| 		curl_setopt($ch, CURLOPT_URL, $xml_feed_url); |             if (empty($xml)) return; | ||||||
| 		curl_setopt($ch, CURLOPT_HEADER, false); |  | ||||||
| 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |  | ||||||
| 		$xml = curl_exec($ch); |  | ||||||
| 		curl_close($ch); |  | ||||||
| 
 | 
 | ||||||
| 		// Create XML object
 |             // Return Required Fields
 | ||||||
| 		$xml = simplexml_load_string($xml); |             $data['callsign'] = (string)$xml->Callsign->call; | ||||||
| 
 | 
 | ||||||
| 		// Return Required Fields
 |             if ($use_fullname === true) { | ||||||
| 		$data['callsign'] = (string) $xml->Callsign->call; |                 $data['name'] =  (string)$xml->Callsign->fname. ' ' . (string)$xml->Callsign->name; | ||||||
| 		$data['name'] = (string) $xml->Callsign->fname; |             } else { | ||||||
| 		$data['gridsquare'] = (string) $xml->Callsign->grid;	 |                 $data['name'] = (string)$xml->Callsign->fname; | ||||||
| 		$data['city'] = (string) $xml->Callsign->addr2; |             } | ||||||
| 		$data['lat'] = (string) $xml->Callsign->lat; |             $data['name'] = trim($data['name']); | ||||||
| 		$data['long'] = (string) $xml->Callsign->lon; |             $data['gridsquare'] = (string)$xml->Callsign->grid; | ||||||
| 		$data['iota'] = (string) $xml->Callsign->iota; |             $data['city'] = (string)$xml->Callsign->addr2; | ||||||
| 		$data['qslmgr'] = (string) $xml->Callsign->qslmgr; |             $data['lat'] = (string)$xml->Callsign->lat; | ||||||
|  |             $data['long'] = (string)$xml->Callsign->lon; | ||||||
|  |             $data['iota'] = (string)$xml->Callsign->iota; | ||||||
|  |             $data['qslmgr'] = (string)$xml->Callsign->qslmgr; | ||||||
| 
 | 
 | ||||||
| 		if($xml->Callsign->country == "United States") { |             if ($xml->Callsign->country == "United States") { | ||||||
| 			$data['state'] = (string) $xml->Callsign->state; |                 $data['state'] = (string)$xml->Callsign->state; | ||||||
| 			$data['us_county'] = (string) $xml->Callsign->county; |                 $data['us_county'] = (string)$xml->Callsign->county; | ||||||
| 		} else { |             } else { | ||||||
| 			$data['state'] = null;  |                 $data['state'] = null; | ||||||
| 			$data['us_county'] = null;  |                 $data['us_county'] = null; | ||||||
| 		} |             } | ||||||
|  |         } finally { | ||||||
| 
 | 
 | ||||||
| 		 |             return $data; | ||||||
| 		return $data; |         } | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1594,7 +1594,7 @@ class Logbook_model extends CI_Model { | ||||||
|                   $entity = $this->get_entity($record['dxcc']); |                   $entity = $this->get_entity($record['dxcc']); | ||||||
|                   $dxcc = array($record['dxcc'], $entity['name']); |                   $dxcc = array($record['dxcc'], $entity['name']); | ||||||
|               } else { |               } else { | ||||||
|                   $dxcc = NULL; |                   $dxcc = $this->check_dxcc_table($record['call'], $time_off); | ||||||
|               } |               } | ||||||
|           } else { |           } else { | ||||||
|             $dxcc = $this->check_dxcc_table($record['call'], $time_off); |             $dxcc = $this->check_dxcc_table($record['call'], $time_off); | ||||||
|  | @ -1607,7 +1607,9 @@ class Logbook_model extends CI_Model { | ||||||
|         if(isset($record['country'])) { |         if(isset($record['country'])) { | ||||||
|             $country = $record['country']; |             $country = $record['country']; | ||||||
|         } else { |         } else { | ||||||
|             $country = ucwords(strtolower($dxcc[1])); |             if (isset($dxcc[1])) { | ||||||
|  |                 $country = ucwords(strtolower($dxcc[1])); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // RST recevied
 |         // RST recevied
 | ||||||
|  | @ -2337,6 +2339,54 @@ class Logbook_model extends CI_Model { | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public function loadCallBook($callsign, $use_fullname=false) | ||||||
|  |     { | ||||||
|  |         $callbook = null; | ||||||
|  |         try { | ||||||
|  |             if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) { | ||||||
|  |                 // Lookup using QRZ
 | ||||||
|  |                 $this->load->library('qrz'); | ||||||
|  | 
 | ||||||
|  |                 if (!$this->session->userdata('qrz_session_key')) { | ||||||
|  |                     $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); | ||||||
|  |                     $this->session->set_userdata('qrz_session_key', $qrz_session_key); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |                 $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'), $use_fullname); | ||||||
|  | 
 | ||||||
|  |                 // if we got nothing, it's probably because our session key is invalid, try again
 | ||||||
|  |                 if (!isset($callbook['callsign'])) | ||||||
|  |                 { | ||||||
|  |                     $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); | ||||||
|  |                     $this->session->set_userdata('qrz_session_key', $qrz_session_key); | ||||||
|  |                     $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'), $use_fullname); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) { | ||||||
|  |                 // Load the HamQTH library
 | ||||||
|  |                 $this->load->library('hamqth'); | ||||||
|  | 
 | ||||||
|  |                 if (!$this->session->userdata('hamqth_session_key')) { | ||||||
|  |                     $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); | ||||||
|  |                     $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); | ||||||
|  | 
 | ||||||
|  |                 // If HamQTH session has expired, start a new session and retry the search.
 | ||||||
|  |                 if ($callbook['error'] == "Session does not exist or expired") { | ||||||
|  |                     $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); | ||||||
|  |                     $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); | ||||||
|  |                     $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } finally { | ||||||
|  |             return $callbook; | ||||||
|  |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     public function update_all_station_ids() { |     public function update_all_station_ids() { | ||||||
| 
 | 
 | ||||||
|  | @ -2464,4 +2514,6 @@ function validateADIFDate($date, $format = 'Ymd') | ||||||
|   $d = DateTime::createFromFormat($format, $date); |   $d = DateTime::createFromFormat($format, $date); | ||||||
|   return $d && $d->format($format) == $date; |   return $d && $d->format($format) == $date; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| ?>
 | ?>
 | ||||||
|  |  | ||||||
|  | @ -40,10 +40,12 @@ $config['display_freq'] = false; | ||||||
| | | | | ||||||
| | 	'qrz_username'	QRZ.com user login | | 	'qrz_username'	QRZ.com user login | ||||||
| |	'qrz_password'	QRZ.com user password | |	'qrz_password'	QRZ.com user password | ||||||
|  | |   'use_fullname'  Get full names from QRZ, may not be GDPR compliant | ||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
| $config['qrz_username'] = ""; | $config['qrz_username'] = ""; | ||||||
| $config['qrz_password'] = ""; | $config['qrz_password'] = ""; | ||||||
|  | $config['use_fullname'] = false; | ||||||
| 
 | 
 | ||||||
| /* | /* | ||||||
| |-------------------------------------------------------------------------- | |-------------------------------------------------------------------------- | ||||||
|  |  | ||||||
		正在加载…
	
		在新工单中引用