| 
									
										
										
										
											2020-12-08 00:32:12 +08:00
										 |  |  | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Map extends CI_Controller { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-28 03:10:45 +08:00
										 |  |  | 	function index() { | 
					
						
							|  |  |  | 		redirect('map/custom'); | 
					
						
							| 
									
										
										
										
											2020-12-08 00:32:12 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 01:28:19 +08:00
										 |  |  |     function custom() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2021-11-13 22:55:17 +08:00
										 |  |  | 		$this->load->model('bands'); | 
					
						
							| 
									
										
										
										
											2022-08-28 01:24:22 +08:00
										 |  |  |         $this->load->model('modes'); | 
					
						
							| 
									
										
										
										
											2021-07-14 18:37:06 +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
 | 
					
						
							| 
									
										
										
										
											2022-08-28 01:24:22 +08:00
										 |  |  | 		$data['modes'] = $this->modes->active(); 					// Used in the view for mode select
 | 
					
						
							| 
									
										
										
										
											2021-07-14 18:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-21 04:03:39 +08:00
										 |  |  |         if ($this->input->post('band') != NULL) {   			// Band is not set when page first loads.
 | 
					
						
							|  |  |  |             if ($this->input->post('band') == 'All') {          // Did the user specify a band? If not, use all bands
 | 
					
						
							| 
									
										
										
										
											2021-07-14 18:37:06 +08:00
										 |  |  |                 $bands = $data['worked_bands']; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 $bands[] = $this->input->post('band'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             $bands = $data['worked_bands']; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $data['bands'] = $bands; // Used for displaying selected band(s) in the table in the view
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 01:28:19 +08:00
										 |  |  |         // Calculate Lat/Lng from Locator to use on Maps
 | 
					
						
							| 
									
										
										
										
											2021-09-21 04:03:39 +08:00
										 |  |  |         if($this->session->userdata('user_locator')) { | 
					
						
							| 
									
										
										
										
											2020-12-08 01:28:19 +08:00
										 |  |  |             $this->load->library('qra'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $qra_position = $this->qra->qra2latlong($this->session->userdata('user_locator')); | 
					
						
							|  |  |  |             $data['qra'] = "set"; | 
					
						
							|  |  |  |             $data['qra_lat'] = $qra_position[0]; | 
					
						
							| 
									
										
										
										
											2021-09-18 23:59:19 +08:00
										 |  |  |             $data['qra_lng'] = $qra_position[1]; | 
					
						
							| 
									
										
										
										
											2020-12-08 01:28:19 +08:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             $data['qra'] = "none"; | 
					
						
							| 
									
										
										
										
											2021-09-21 04:03:39 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-12-08 01:28:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-21 04:03:39 +08:00
										 |  |  | 		$CI =& get_instance(); | 
					
						
							|  |  |  | 		$CI->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$result = $CI->logbooks_model->logbook($this->session->userdata('active_station_logbook'))->result(); | 
					
						
							| 
									
										
										
										
											2021-11-15 00:17:20 +08:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		if ($result) { | 
					
						
							|  |  |  | 			$logbook_name = $result[0]->logbook_name; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$logbook_name = ''; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-12-08 01:28:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // load the view
 | 
					
						
							| 
									
										
										
										
											2021-09-21 04:03:39 +08:00
										 |  |  |         $data['logbook_name'] = $logbook_name; | 
					
						
							| 
									
										
										
										
											2020-12-08 01:28:19 +08:00
										 |  |  | 		$data['page_title'] = "Map QSOs"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-14 05:54:04 +08:00
										 |  |  |         $data['date_from'] = $data['date_to'] = date('Y-m-d'); | 
					
						
							| 
									
										
										
										
											2020-12-08 01:28:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$this->load->view('interface_assets/header', $data); | 
					
						
							|  |  |  | 		$this->load->view('map/custom_date'); | 
					
						
							| 
									
										
										
										
											2023-12-13 14:10:10 +08:00
										 |  |  | 		$this->load->view('interface_assets/footer'); | 
					
						
							| 
									
										
										
										
											2020-12-08 01:28:19 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-12 15:18:42 +08:00
										 |  |  | 	// Generic fonction for return Json for MAP //
 | 
					
						
							| 
									
										
										
										
											2023-12-12 21:58:55 +08:00
										 |  |  | 	public function map_plot_json() { | 
					
						
							| 
									
										
										
										
											2023-12-01 01:11:22 +08:00
										 |  |  | 		$this->load->model('Stations'); | 
					
						
							| 
									
										
										
										
											2020-12-08 00:32:12 +08:00
										 |  |  | 		$this->load->model('logbook_model'); | 
					
						
							| 
									
										
										
										
											2022-05-02 00:06:38 +08:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2023-12-12 15:18:42 +08:00
										 |  |  | 		// set informations //
 | 
					
						
							|  |  |  | 		if ($this->input->post('isCustom') == true) { | 
					
						
							| 
									
										
										
										
											2023-12-12 21:54:13 +08:00
										 |  |  | 			$date_from = xss_clean($this->input->post('date_from')); | 
					
						
							|  |  |  | 			$date_to = xss_clean($this->input->post('date_to')); | 
					
						
							|  |  |  | 			$band = xss_clean($this->input->post('band')); | 
					
						
							|  |  |  | 			$mode = xss_clean($this->input->post('mode')); | 
					
						
							|  |  |  | 			$prop_mode = xss_clean($this->input->post('prop_mode')); | 
					
						
							| 
									
										
										
										
											2023-12-12 15:18:42 +08:00
										 |  |  | 			$qsos = $this->logbook_model->map_custom_qsos($date_from, $date_to, $band, $mode, $prop_mode); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2023-12-12 21:54:13 +08:00
										 |  |  | 			$nb_qso = (intval($this->input->post('nb_qso'))>0)?xss_clean($this->input->post('nb_qso')):18; | 
					
						
							|  |  |  | 			$offset = (intval($this->input->post('offset'))>0)?xss_clean($this->input->post('offset')):null; | 
					
						
							| 
									
										
										
										
											2023-12-12 15:18:42 +08:00
										 |  |  | 			$qsos = $this->logbook_model->get_qsos($nb_qso, $offset); | 
					
						
							| 
									
										
										
										
											2020-12-08 00:32:12 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2023-12-12 15:18:42 +08:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2024-06-19 20:46:31 +08:00
										 |  |  | 		if(empty($qsos)) { | 
					
						
							|  |  |  | 			// Handle the case where $qsos is empty
 | 
					
						
							| 
									
										
										
										
											2023-12-12 15:18:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-19 20:46:31 +08:00
										 |  |  | 			// return json with error "No QSOs found"
 | 
					
						
							|  |  |  | 			header('Content-Type: application/json; charset=utf-8'); | 
					
						
							|  |  |  | 			echo json_encode(array('error' => 'No QSOs found')); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			// Handle the case where $qsos is not empty
 | 
					
						
							|  |  |  | 			// [PLOT] ADD plot //
 | 
					
						
							|  |  |  | 			$plot_array = $this->logbook_model->get_plot_array_for_map($qsos->result()); | 
					
						
							|  |  |  | 			// [MAP Custom] ADD Station //
 | 
					
						
							|  |  |  | 			$station_array = $this->Stations->get_station_array_for_map(); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			header('Content-Type: application/json; charset=utf-8'); | 
					
						
							|  |  |  | 			echo json_encode(array_merge($plot_array, $station_array)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |