[API] Adds API call "logbook_check_callsign" to check if a callsign is in the logbook
这个提交包含在:
		
							父节点
							
								
									9c4882c79b
								
							
						
					
					
						当前提交
						0be6f42999
					
				
					共有  2 个文件被更改,包括 101 次插入 和 1 次删除
				
			
		|  | @ -471,6 +471,79 @@ class API extends CI_Controller { | ||||||
| 
 | 
 | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	// API function to check if a callsign is in the logbook already
 | ||||||
|  | 	function logbook_check_callsign() { | ||||||
|  | 		header('Content-type: application/json'); | ||||||
|  | 
 | ||||||
|  | 		$this->load->model('api_model'); | ||||||
|  | 
 | ||||||
|  | 		// Decode JSON and store
 | ||||||
|  | 		$obj = json_decode(file_get_contents("php://input"), true); | ||||||
|  | 		if ($obj === NULL) { | ||||||
|  | 		    echo json_encode(['status' => 'failed', 'reason' => "wrong JSON"]); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if(!isset($obj['key']) || $this->api_model->authorize($obj['key']) == 0) { | ||||||
|  | 		   http_response_code(401); | ||||||
|  | 		   echo json_encode(['status' => 'failed', 'reason' => "missing api key"]); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if($obj['logbook_public_slug'] != "" && $obj['callsign'] != "") { | ||||||
|  | 
 | ||||||
|  | 			$logbook_slug = $obj['logbook_public_slug']; | ||||||
|  | 			$callsign = $obj['callsign']; | ||||||
|  | 
 | ||||||
|  | 			// If $obj['band'] exists
 | ||||||
|  | 			if(isset($obj['band'])) { | ||||||
|  | 				$band = $obj['band']; | ||||||
|  | 			} else { | ||||||
|  | 				$band = null; | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			$this->load->model('logbooks_model'); | ||||||
|  | 
 | ||||||
|  | 			if($this->logbooks_model->public_slug_exists($logbook_slug)) { | ||||||
|  | 				$logbook_id = $this->logbooks_model->public_slug_exists_logbook_id($logbook_slug); | ||||||
|  | 				if($logbook_id != false) | ||||||
|  | 				{ | ||||||
|  | 					// Get associated station locations for mysql queries
 | ||||||
|  | 					$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($logbook_id); | ||||||
|  | 	 | ||||||
|  | 					if (!$logbooks_locations_array) { | ||||||
|  | 						// Logbook not found
 | ||||||
|  | 						http_response_code(404); | ||||||
|  | 						echo json_encode(['status' => 'failed', 'reason' => "Empty Logbook"]); | ||||||
|  | 						die(); | ||||||
|  | 					} | ||||||
|  | 				} else { | ||||||
|  | 					// Logbook not found
 | ||||||
|  | 					http_response_code(404); | ||||||
|  | 					echo json_encode(['status' => 'failed', 'reason' => $logbook_slug." has no associated station locations"]); | ||||||
|  | 					die(); | ||||||
|  | 				} | ||||||
|  | 				// Search Logbook for callsign
 | ||||||
|  | 				$this->load->model('logbook_model'); | ||||||
|  | 
 | ||||||
|  | 				$result = $this->logbook_model->check_if_callsign_worked_in_logbook($logbooks_locations_array, $callsign, $band); | ||||||
|  | 
 | ||||||
|  | 				http_response_code(201); | ||||||
|  | 				if($result > 0) | ||||||
|  | 				{ | ||||||
|  | 					echo json_encode(['callsign' => $callsign, 'result' => 'Found']); | ||||||
|  | 				} else { | ||||||
|  | 					echo json_encode(['callsign' => $callsign, 'result' => 'Not Found']); | ||||||
|  | 				} | ||||||
|  | 			} else { | ||||||
|  | 				// Logbook not found
 | ||||||
|  | 				http_response_code(404); | ||||||
|  | 				echo json_encode(['status' => 'failed', 'reason' => "logbook not found"]); | ||||||
|  | 				die(); | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	function country_worked($dxcc_num, $band, $mode = NULL) { | 	function country_worked($dxcc_num, $band, $mode = NULL) { | ||||||
| 		$this->load->model('api_model'); | 		$this->load->model('api_model'); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1387,6 +1387,33 @@ class Logbook_model extends CI_Model { | ||||||
|       return null; |       return null; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   function check_if_callsign_worked_in_logbook($StationLocationsArray = null, $callsign, $band = null) { | ||||||
|  | 
 | ||||||
|  |     if($StationLocationsArray == null) { | ||||||
|  |       $CI =& get_instance(); | ||||||
|  |       $CI->load->model('logbooks_model'); | ||||||
|  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | ||||||
|  |     } else { | ||||||
|  |       $logbooks_locations_array = $StationLocationsArray; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     $this->db->select('COL_CALL'); | ||||||
|  |     $this->db->where_in('station_id', $logbooks_locations_array); | ||||||
|  |     $this->db->where('COL_CALL', $callsign); | ||||||
|  | 
 | ||||||
|  |     if($band != null && $band != 'SAT') { | ||||||
|  |       $this->db->where('COL_BAND', $band); | ||||||
|  |     } else if($band == 'SAT') { | ||||||
|  |       // Where col_sat_name is not empty
 | ||||||
|  |       $this->db->where('COL_SAT_NAME !=', ''); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     $query = $this->db->get($this->config->item('table_name')); | ||||||
|  | 
 | ||||||
|  |     return $query->num_rows(); | ||||||
|  | 
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|     /* Get all QSOs with a valid grid for use in the KML export */ |     /* Get all QSOs with a valid grid for use in the KML export */ | ||||||
|  |  | ||||||
		正在加载…
	
		在新工单中引用