| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Provides outputted kml files for use with Google Map services  | 
					
						
							|  |  |  | 	All maps are stored within /kml in the root directory | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-15 23:51:48 +08:00
										 |  |  | class Kmlexport extends CI_Controller { | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-12 19:45:33 +08:00
										 |  |  |     public function index() { | 
					
						
							| 
									
										
										
										
											2020-12-06 20:21:35 +08:00
										 |  |  |         $this->load->model('user_model'); | 
					
						
							|  |  |  |         $this->load->model('modes'); | 
					
						
							|  |  |  |         $this->load->model('logbook_model'); | 
					
						
							| 
									
										
										
										
											2023-08-09 00:41:33 +08:00
										 |  |  | 	$this->load->model('bands'); | 
					
						
							| 
									
										
										
										
											2020-12-06 20:21:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 00:41:33 +08:00
										 |  |  |         if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } | 
					
						
							| 
									
										
										
										
											2020-12-06 20:21:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-13 22:55:17 +08:00
										 |  |  |         $data['worked_bands'] = $this->bands->get_worked_bands(); // Used in the view for band select
 | 
					
						
							| 
									
										
										
										
											2020-12-06 20:21:35 +08:00
										 |  |  |         $data['modes'] = $this->modes->active(); // Used in the view for mode select
 | 
					
						
							|  |  |  |         $data['dxcc'] = $this->logbook_model->fetchDxcc(); // Used in the view for dxcc select
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $data['page_title'] = "KML Export"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->load->view('interface_assets/header', $data); | 
					
						
							|  |  |  |         $this->load->view('kml/index'); | 
					
						
							|  |  |  |         $this->load->view('interface_assets/footer'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-12 19:45:33 +08:00
										 |  |  | 	public function export() { | 
					
						
							| 
									
										
										
										
											2023-08-09 00:41:33 +08:00
										 |  |  |         $this->load->model('user_model'); | 
					
						
							|  |  |  |         if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } | 
					
						
							| 
									
										
										
										
											2021-11-12 19:45:33 +08:00
										 |  |  | 		// Load Libraries
 | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  | 		$this->load->library('qra'); | 
					
						
							|  |  |  | 		$this->load->helper('file'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Load Database connections
 | 
					
						
							|  |  |  | 		$this->load->model('logbook_model'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-06 20:21:35 +08:00
										 |  |  | 		// Parameters
 | 
					
						
							|  |  |  |         $band = $this->input->post('band'); | 
					
						
							|  |  |  |         $mode = $this->input->post('mode'); | 
					
						
							|  |  |  |         $dxcc = $this->input->post('dxcc_id'); | 
					
						
							|  |  |  |         $cqz = $this->input->post('cqz'); | 
					
						
							|  |  |  |         $propagation = $this->input->post('prop_mode'); | 
					
						
							| 
									
										
										
										
											2023-11-17 20:32:23 +08:00
										 |  |  |         $fromdate = $this->input->post('from'); | 
					
						
							|  |  |  |         $todate = $this->input->post('to'); | 
					
						
							| 
									
										
										
										
											2020-12-06 20:21:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  | 		// Get QSOs with Valid QRAs
 | 
					
						
							| 
									
										
										
										
											2020-12-06 20:21:35 +08:00
										 |  |  | 		$qsos = $this->logbook_model->kml_get_all_qsos($band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate); | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; | 
					
						
							|  |  |  | 		$output .= "<kml xmlns=\"http://www.opengis.net/kml/2.2\">"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$output .= "<Document>"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-12 19:45:33 +08:00
										 |  |  | 		foreach ($qsos->result() as $row) { | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  | 			if($row->COL_GRIDSQUARE != null) { | 
					
						
							|  |  |  | 				$stn_loc = $this->qra->qra2latlong($row->COL_GRIDSQUARE); | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				$lat = $stn_loc[0]; | 
					
						
							|  |  |  | 				$lng = $stn_loc[1]; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				$query = $this->db->query(' | 
					
						
							|  |  |  | 					SELECT * | 
					
						
							| 
									
										
										
										
											2020-12-06 20:21:35 +08:00
										 |  |  | 					FROM dxcc_entities | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  | 					WHERE prefix = SUBSTRING( \''.$row->COL_CALL.'\', 1, LENGTH( prefix ) ) | 
					
						
							|  |  |  | 					ORDER BY LENGTH( prefix ) DESC | 
					
						
							|  |  |  | 					LIMIT 1  | 
					
						
							|  |  |  | 				'); | 
					
						
							| 
									
										
										
										
											2021-11-12 19:45:33 +08:00
										 |  |  | 					foreach ($query->result() as $dxcc) { | 
					
						
							|  |  |  | 						$lat = $dxcc->lat; | 
					
						
							|  |  |  | 						$lng = $dxcc->long; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-12 19:45:33 +08:00
										 |  |  | 			if (isset($lat) && isset($lng)) { | 
					
						
							|  |  |  | 				$output .= "<Placemark>"; | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-12 19:45:33 +08:00
										 |  |  | 				$timestamp = strtotime($row->COL_TIME_ON);  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				$output .= "<name>".$row->COL_CALL."</name>"; | 
					
						
							|  |  |  | 				$output .= "<description><![CDATA[<p>Date/Time: ".date('Y-m-d H:i:s', ($timestamp))."<br/>Band: ".$row->COL_BAND."<br /></p>]]></description>";		 | 
					
						
							|  |  |  | 				$output .= "<Point>"; | 
					
						
							|  |  |  | 				$output .= "<coordinates>".$lng.",".$lat.",0</coordinates>"; | 
					
						
							|  |  |  | 				$output .= "</Point>"; | 
					
						
							|  |  |  | 				$output .= "</Placemark>"; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$output .= "</Document>"; | 
					
						
							|  |  |  | 		$output .= "</kml>"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-09 23:36:30 +08:00
										 |  |  | 		header("Content-Disposition: attachment; filename=\"qsos.kml\""); | 
					
						
							|  |  |  | 		echo $output; | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-05-09 23:36:30 +08:00
										 |  |  | } |