Merge pull request #2382 from AndreasK79/cleanup_json_lookup_qso_entry
[QSO Entry] Cleanup and tighten up db lookup from QSO entry
这个提交包含在:
		
						当前提交
						84dbe52b5a
					
				
					共有  2 个文件被更改,包括 126 次插入 和 141 次删除
				
			
		|  | @ -89,8 +89,15 @@ class Logbook extends CI_Controller { | |||
|         echo json_encode($return, JSON_PRETTY_PRINT); | ||||
|     } | ||||
| 
 | ||||
| 	function json($callsign, $type, $band, $mode, $station_id = null) | ||||
| 	function json($tempcallsign, $temptype, $tempband, $tempmode, $tempstation_id = null) | ||||
| 	{ | ||||
| 		// Cleaning for security purposes
 | ||||
| 		$callsign = $this->security->xss_clean($tempcallsign); | ||||
| 		$type = $this->security->xss_clean($temptype); | ||||
| 		$band = $this->security->xss_clean($tempband); | ||||
| 		$mode = $this->security->xss_clean($tempmode); | ||||
| 		$station_id = $this->security->xss_clean($tempstation_id); | ||||
| 
 | ||||
| 		$this->load->model('user_model'); | ||||
| 		if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; } | ||||
| 
 | ||||
|  | @ -120,6 +127,7 @@ class Logbook extends CI_Controller { | |||
| 			"callsign_us_county" => "", | ||||
| 			"qsl_manager" => "", | ||||
| 			"bearing" 		=> "", | ||||
| 			"latlng" 		=> "", | ||||
| 			"workedBefore" => false, | ||||
| 			"lotw_member" => $lotw_member, | ||||
| 			"lotw_days" => $lotw_days, | ||||
|  | @ -131,84 +139,49 @@ class Logbook extends CI_Controller { | |||
| 
 | ||||
| 		$callbook = $this->logbook_model->loadCallBook($callsign, $this->config->item('use_fullname')); | ||||
| 
 | ||||
| 		// Do we have local data for the Callsign?
 | ||||
| 		if($this->logbook_model->call_name($callsign) != null) | ||||
| 		{ | ||||
| 			if ($this->session->userdata('user_measurement_base') == NULL) { | ||||
| 				$measurement_base = $this->config->item('measurement_base'); | ||||
| 			} else { | ||||
| 				$measurement_base = $this->session->userdata('user_measurement_base'); | ||||
| 			} | ||||
| 
 | ||||
| 			$return['callsign_name'] =  $this->logbook_model->call_name($callsign); | ||||
| 			$return['callsign_qra'] = $this->logbook_model->call_qra($callsign); | ||||
| 			$return['callsign_distance'] = $this->distance($return['callsign_qra'], $station_id); | ||||
| 			$return['callsign_qth'] = $this->logbook_model->call_qth($callsign); | ||||
| 			$return['callsign_iota'] = $this->logbook_model->call_iota($callsign); | ||||
| 			$return['qsl_manager'] = $this->logbook_model->call_qslvia($callsign); | ||||
| 			$return['callsign_state'] = $this->logbook_model->call_state($callsign); | ||||
| 			$return['callsign_us_county'] = $this->logbook_model->call_us_county($callsign); | ||||
| 			$return['bearing'] = $this->bearing($return['callsign_qra'], $measurement_base, $station_id); | ||||
| 			$return['workedBefore'] = $this->worked_grid_before($return['callsign_qra'], $type, $band, $mode); | ||||
| 			if ($this->session->userdata('user_show_profile_image')) { | ||||
| 				if (isset($callbook)) { | ||||
| 					if ($callbook['image'] == "") { | ||||
| 						$return['image'] = "n/a"; | ||||
| 					} else { | ||||
| 						$return['image'] = $callbook['image']; | ||||
| 					} | ||||
| 				} else { | ||||
| 					$return['image'] = "n/a"; | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			if ($return['callsign_qra'] != "") { | ||||
| 				$return['latlng'] = $this->qralatlng($return['callsign_qra']); | ||||
| 			} | ||||
| 
 | ||||
| 			echo json_encode($return, JSON_PRETTY_PRINT); | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
| 		if (isset($callbook)) | ||||
| 		{ | ||||
| 			$return['callsign_name'] = $callbook['name']; | ||||
| 			$return['callsign_qra'] = $callbook['gridsquare']; | ||||
| 			$return['callsign_distance'] = $this->distance($callbook['gridsquare'], $station_id); | ||||
| 			$return['callsign_qth'] = $callbook['city']; | ||||
| 			$return['callsign_iota'] = $callbook['iota']; | ||||
| 			$return['callsign_state'] = $callbook['state']; | ||||
| 			$return['callsign_us_county'] = $callbook['us_county']; | ||||
| 			if ($this->session->userdata('user_show_profile_image')) { | ||||
| 				if ($callbook['image'] == "") { | ||||
| 					$return['image'] = "n/a"; | ||||
| 				} else { | ||||
| 					$return['image'] = $callbook['image']; | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			if(isset($callbook['qslmgr'])) { | ||||
| 				$return['qsl_manager'] = $callbook['qslmgr']; | ||||
| 			} | ||||
| 			if ($return['callsign_qra'] != "") { | ||||
| 				$return['latlng'] = $this->qralatlng($return['callsign_qra']); | ||||
| 			} | ||||
| 			$return['workedBefore'] = $this->worked_grid_before($return['callsign_qra'], $type, $band, $mode); | ||||
| 		} | ||||
| 
 | ||||
| 		if ($this->session->userdata('user_measurement_base') == NULL) { | ||||
| 			$measurement_base = $this->config->item('measurement_base'); | ||||
| 		} else { | ||||
| 			$measurement_base = $this->session->userdata('user_measurement_base'); | ||||
| 		} | ||||
| 
 | ||||
| 		$return['bearing'] = $this->bearing($return['callsign_qra'], $measurement_base, $station_id); | ||||
| 		$return['callsign_name'] 		= $this->nval($callbook['name'], $this->logbook_model->call_name($callsign)); | ||||
| 		$return['callsign_qra'] 		= $this->nval($callbook['gridsquare'],  $this->logbook_model->call_qra($callsign)); | ||||
| 		$return['callsign_distance'] 	= $this->distance($return['callsign_qra']); | ||||
| 		$return['callsign_qth'] 		= $this->nval($callbook['city'], $this->logbook_model->call_qth($callsign)); | ||||
| 		$return['callsign_iota'] 		= $this->nval($callbook['iota'], $this->logbook_model->call_iota($callsign)); | ||||
| 		$return['qsl_manager'] 			= $this->nval($callbook['qslmgr'], $this->logbook_model->call_qslvia($callsign)); | ||||
| 		$return['callsign_state'] 		= $this->nval($callbook['state'], $this->logbook_model->call_state($callsign)); | ||||
| 		$return['callsign_us_county'] 	= $this->nval($callbook['us_county'], $this->logbook_model->call_us_county($callsign)); | ||||
| 		$return['workedBefore'] 		= $this->worked_grid_before($return['callsign_qra'], $type, $band, $mode); | ||||
| 
 | ||||
| 		if ($this->session->userdata('user_show_profile_image')) { | ||||
| 			if (isset($callbook)) { | ||||
| 				if ($callbook['image'] == "") { | ||||
| 					$return['image'] = "n/a"; | ||||
| 				} else { | ||||
| 					$return['image'] = $callbook['image']; | ||||
| 				} | ||||
| 			} else { | ||||
| 				$return['image'] = "n/a"; | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		if ($return['callsign_qra'] != "") { | ||||
| 			$return['latlng'] = $this->qralatlng($return['callsign_qra']); | ||||
| 			$return['bearing'] = $this->bearing($return['callsign_qra'], $measurement_base, $station_id); | ||||
| 		} | ||||
| 
 | ||||
| 		echo json_encode($return, JSON_PRETTY_PRINT); | ||||
| 
 | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	// Returns $val2 first if it has value, even if it is null or empty string, if not return $val1.
 | ||||
| 	function nval($val1, $val2) { | ||||
| 		return (($val2 ?? "") === "" ? ($val1 ?? "") : ($val2 ?? "")); | ||||
| 	} | ||||
| 
 | ||||
| 	function worked_grid_before($gridsquare, $type, $band, $mode) | ||||
| 	{ | ||||
| 		if (strlen($gridsquare) < 4) | ||||
|  | @ -500,18 +473,18 @@ class Logbook extends CI_Controller { | |||
| 		$html = ""; | ||||
| 
 | ||||
| 		if(!empty($logbooks_locations_array)) { | ||||
| 	    $this->db->select(''.$this->config->item('table_name').'.COL_CALL, '.$this->config->item('table_name').'.COL_BAND, '.$this->config->item('table_name').'.COL_FREQ, '.$this->config->item('table_name').'.COL_TIME_ON, '.$this->config->item('table_name').'.COL_RST_RCVD, '.$this->config->item('table_name').'.COL_RST_SENT, '.$this->config->item('table_name').'.COL_MODE, '.$this->config->item('table_name').'.COL_SUBMODE, '.$this->config->item('table_name').'.COL_PRIMARY_KEY, '.$this->config->item('table_name').'.COL_SAT_NAME, '.$this->config->item('table_name').'.COL_GRIDSQUARE, '.$this->config->item('table_name').'.COL_QSL_RCVD, '.$this->config->item('table_name').'.COL_EQSL_QSL_RCVD, '.$this->config->item('table_name').'.COL_EQSL_QSL_SENT, '.$this->config->item('table_name').'.COL_QSL_SENT, '.$this->config->item('table_name').'.COL_STX, '.$this->config->item('table_name').'.COL_STX_STRING, '.$this->config->item('table_name').'.COL_SRX, '.$this->config->item('table_name').'.COL_SRX_STRING, '.$this->config->item('table_name').'.COL_LOTW_QSL_SENT, '.$this->config->item('table_name').'.COL_LOTW_QSL_RCVD, '.$this->config->item('table_name').'.COL_VUCC_GRIDS, station_profile.*'); | ||||
| 	    $this->db->from($this->config->item('table_name')); | ||||
| 			$this->db->select(''.$this->config->item('table_name').'.COL_CALL, '.$this->config->item('table_name').'.COL_BAND, '.$this->config->item('table_name').'.COL_FREQ, '.$this->config->item('table_name').'.COL_TIME_ON, '.$this->config->item('table_name').'.COL_RST_RCVD, '.$this->config->item('table_name').'.COL_RST_SENT, '.$this->config->item('table_name').'.COL_MODE, '.$this->config->item('table_name').'.COL_SUBMODE, '.$this->config->item('table_name').'.COL_PRIMARY_KEY, '.$this->config->item('table_name').'.COL_SAT_NAME, '.$this->config->item('table_name').'.COL_GRIDSQUARE, '.$this->config->item('table_name').'.COL_QSL_RCVD, '.$this->config->item('table_name').'.COL_EQSL_QSL_RCVD, '.$this->config->item('table_name').'.COL_EQSL_QSL_SENT, '.$this->config->item('table_name').'.COL_QSL_SENT, '.$this->config->item('table_name').'.COL_STX, '.$this->config->item('table_name').'.COL_STX_STRING, '.$this->config->item('table_name').'.COL_SRX, '.$this->config->item('table_name').'.COL_SRX_STRING, '.$this->config->item('table_name').'.COL_LOTW_QSL_SENT, '.$this->config->item('table_name').'.COL_LOTW_QSL_RCVD, '.$this->config->item('table_name').'.COL_VUCC_GRIDS, station_profile.*'); | ||||
| 			$this->db->from($this->config->item('table_name')); | ||||
| 
 | ||||
| 	    $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | ||||
| 	    $this->db->where_in('station_profile.station_id', $logbooks_locations_array); | ||||
| 	    $this->db->order_by(''.$this->config->item('table_name').'.COL_TIME_ON', "desc"); | ||||
| 			$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | ||||
| 			$this->db->where_in('station_profile.station_id', $logbooks_locations_array); | ||||
| 			$this->db->order_by(''.$this->config->item('table_name').'.COL_TIME_ON', "desc"); | ||||
| 
 | ||||
| 		$this->db->like($this->config->item('table_name').'.COL_CALL', $id); | ||||
| 		$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "desc"); | ||||
| 		$this->db->limit(5); | ||||
| 			$this->db->like($this->config->item('table_name').'.COL_CALL', $id); | ||||
| 			$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "desc"); | ||||
| 			$this->db->limit(5); | ||||
| 
 | ||||
| 		$query = $this->db->get(); | ||||
| 			$query = $this->db->get(); | ||||
| 		} | ||||
| 
 | ||||
| 		if (!empty($logbooks_locations_array) && $query->num_rows() > 0) | ||||
|  |  | |||
|  | @ -1150,7 +1150,9 @@ class Logbook_model extends CI_Model { | |||
|   /* Callsign QRA */ | ||||
| 	function call_qra($callsign) { | ||||
| 		$this->db->select('COL_CALL, COL_GRIDSQUARE, COL_TIME_ON'); | ||||
| 		$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | ||||
| 		$this->db->where('COL_CALL', $callsign); | ||||
| 		$this->db->where('station_profile.user_id', $this->session->userdata('user_id')); | ||||
| 		$where = "COL_GRIDSQUARE != \"\""; | ||||
| 
 | ||||
| 		$this->db->where($where); | ||||
|  | @ -1170,7 +1172,9 @@ class Logbook_model extends CI_Model { | |||
| 
 | ||||
| 	function call_name($callsign) { | ||||
| 		$this->db->select('COL_CALL, COL_NAME, COL_TIME_ON'); | ||||
| 		$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | ||||
| 		$this->db->where('COL_CALL', $callsign); | ||||
| 		$this->db->where('station_profile.user_id', $this->session->userdata('user_id')); | ||||
| 		$where = "COL_NAME != \"\""; | ||||
| 
 | ||||
| 		$this->db->where($where); | ||||
|  | @ -1188,38 +1192,42 @@ class Logbook_model extends CI_Model { | |||
| 		return $name; | ||||
| 	} | ||||
| 
 | ||||
|   function call_qslvia($callsign) { | ||||
|     $this->db->select('COL_CALL, COL_QSL_VIA, COL_TIME_ON'); | ||||
|     $this->db->where('COL_CALL', $callsign); | ||||
|     $where = "COL_NAME != \"\""; | ||||
| 	function call_qslvia($callsign) { | ||||
| 		$this->db->select('COL_CALL, COL_QSL_VIA, COL_TIME_ON'); | ||||
| 		$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | ||||
| 		$this->db->where('COL_CALL', $callsign); | ||||
| 		$this->db->where('station_profile.user_id', $this->session->userdata('user_id')); | ||||
| 		$where = "COL_QSL_VIA != \"\""; | ||||
| 
 | ||||
|     $this->db->where($where); | ||||
| 		$this->db->where($where); | ||||
| 
 | ||||
|     $this->db->order_by("COL_TIME_ON", "desc"); | ||||
|     $this->db->limit(1); | ||||
|     $query = $this->db->get($this->config->item('table_name')); | ||||
|     $name = ""; | ||||
|     if ($query->num_rows() > 0) | ||||
|     { | ||||
|       $data = $query->row(); | ||||
|       $qsl_via = $data->COL_QSL_VIA; | ||||
|     } | ||||
| 		$this->db->order_by("COL_TIME_ON", "desc"); | ||||
| 		$this->db->limit(1); | ||||
| 		$query = $this->db->get($this->config->item('table_name')); | ||||
| 		$qsl_via = ""; | ||||
| 		if ($query->num_rows() > 0) | ||||
| 		{ | ||||
| 			$data = $query->row(); | ||||
| 			$qsl_via = $data->COL_QSL_VIA; | ||||
| 		} | ||||
| 
 | ||||
|     return $qsl_via; | ||||
|   } | ||||
| 		return $qsl_via; | ||||
| 	} | ||||
| 
 | ||||
|     function call_state($callsign) { | ||||
|         $this->db->select('COL_CALL, COL_STATE'); | ||||
| 		$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | ||||
|         $this->db->where('COL_CALL', $callsign); | ||||
|         $where = "COL_NAME != \"\""; | ||||
| 		$this->db->where('station_profile.user_id', $this->session->userdata('user_id')); | ||||
|         $where = "COL_STATE != \"\""; | ||||
| 
 | ||||
|         $this->db->where($where); | ||||
| 
 | ||||
|         $this->db->order_by("COL_TIME_ON", "desc"); | ||||
|         $this->db->limit(1); | ||||
|         $query = $this->db->get($this->config->item('table_name')); | ||||
|         $name = ""; | ||||
|         if ($query->num_rows() > 0) | ||||
| 		$qsl_state = ""; | ||||
| 		if ($query->num_rows() > 0) | ||||
|         { | ||||
|             $data = $query->row(); | ||||
|             $qsl_state = $data->COL_STATE; | ||||
|  | @ -1230,7 +1238,9 @@ class Logbook_model extends CI_Model { | |||
| 
 | ||||
|     function call_us_county($callsign) { | ||||
|         $this->db->select('COL_CALL, COL_CNTY'); | ||||
| 		$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | ||||
|         $this->db->where('COL_CALL', $callsign); | ||||
| 		$this->db->where('station_profile.user_id', $this->session->userdata('user_id')); | ||||
|         $where = "COL_CNTY != \"\""; | ||||
| 
 | ||||
|         $this->db->where($where); | ||||
|  | @ -1245,12 +1255,13 @@ class Logbook_model extends CI_Model { | |||
|             $qsl_county = substr($qsl_county, (strpos($qsl_county, ',')+1)); | ||||
|             return $qsl_county; | ||||
|         } else { | ||||
|           return NULL; | ||||
| 			return NULL; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 	function call_qth($callsign) { | ||||
| 		$this->db->select('COL_CALL, COL_QTH, COL_TIME_ON'); | ||||
| 		$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | ||||
| 		$this->db->where('COL_CALL', $callsign); | ||||
| 		$where = "COL_QTH != \"\""; | ||||
| 
 | ||||
|  | @ -1271,6 +1282,7 @@ class Logbook_model extends CI_Model { | |||
| 
 | ||||
| 	function call_iota($callsign) { | ||||
| 		$this->db->select('COL_CALL, COL_IOTA, COL_TIME_ON'); | ||||
| 		$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | ||||
| 		$this->db->where('COL_CALL', $callsign); | ||||
| 		$where = "COL_IOTA != \"\""; | ||||
| 
 | ||||
|  |  | |||
		正在加载…
	
		在新工单中引用