| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 	Controller to interact with the Cloudlog DXPed Aggregator | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | class Workabledxcc extends CI_Controller | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 	function __construct() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 		parent::__construct(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$this->load->model('user_model'); | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 		if (!$this->user_model->authorize(2)) { | 
					
						
							|  |  |  | 			$this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); | 
					
						
							|  |  |  | 			redirect('dashboard'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function index() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// Load public view
 | 
					
						
							|  |  |  | 		$data['page_title'] = "Upcoming DXPeditions"; | 
					
						
							|  |  |  | 		$this->load->view('interface_assets/header', $data); | 
					
						
							|  |  |  | 		$this->load->view('/workabledxcc/index'); | 
					
						
							|  |  |  | 		$this->load->view('interface_assets/footer'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function dxcclist() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-04-05 01:49:18 +08:00
										 |  |  | 		$json = file_get_contents($this->optionslib->get_option('dxped_url')); | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 		$dataResult = json_decode($json, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-11 21:50:56 +08:00
										 |  |  | 		if (empty($dataResult)) { | 
					
						
							|  |  |  | 			$data['dxcclist'] = array(); | 
					
						
							|  |  |  | 			$this->load->view('/workabledxcc/components/dxcclist', $data); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Get Date format
 | 
					
						
							|  |  |  | 		if ($this->session->userdata('user_date_format')) { | 
					
						
							|  |  |  | 			$custom_date_format = $this->session->userdata('user_date_format'); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$custom_date_format = $this->config->item('qso_date_format'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-11 21:50:56 +08:00
										 |  |  | 		// Load models once
 | 
					
						
							|  |  |  | 		$this->load->model('logbook_model'); | 
					
						
							|  |  |  | 		$this->load->model('Workabledxcc_model'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Get all DXCC entities for all callsigns in one batch
 | 
					
						
							|  |  |  | 		$callsigns = array_column($dataResult, 'callsign'); | 
					
						
							|  |  |  | 		$dates = array_column($dataResult, '0'); | 
					
						
							|  |  |  | 		$dxccEntities = $this->Workabledxcc_model->batchDxccLookup($callsigns, $dates); | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-11 21:50:56 +08:00
										 |  |  | 		// Get worked/confirmed status for all entities in batch
 | 
					
						
							|  |  |  | 		$uniqueEntities = array_unique(array_filter($dxccEntities)); | 
					
						
							|  |  |  | 		$dxccStatus = $this->Workabledxcc_model->batchDxccWorkedStatus($uniqueEntities); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Process results
 | 
					
						
							|  |  |  | 		$requiredData = array(); | 
					
						
							|  |  |  | 		foreach ($dataResult as $index => $item) { | 
					
						
							|  |  |  | 			$oldStartDate = DateTime::createFromFormat('Y-m-d', $item['0']); | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 			$StartDate = $oldStartDate->format($custom_date_format); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$oldEndDate = DateTime::createFromFormat('Y-m-d', $item['1']); | 
					
						
							|  |  |  | 			$EndDate = $oldEndDate->format($custom_date_format); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-11 21:50:56 +08:00
										 |  |  | 			// Get DXCC status for this callsign
 | 
					
						
							|  |  |  | 			$entity = $dxccEntities[$index] ?? null; | 
					
						
							|  |  |  | 			$worked = $entity && isset($dxccStatus[$entity]) ? $dxccStatus[$entity] : ['workedBefore' => false, 'confirmed' => false]; | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			$requiredData[] = array( | 
					
						
							|  |  |  | 				'clean_date' => $item['0'], | 
					
						
							|  |  |  | 				'start_date' => $StartDate, | 
					
						
							|  |  |  | 				'end_date' => $EndDate, | 
					
						
							|  |  |  | 				'country' => $item['2'], | 
					
						
							|  |  |  | 				'notes' => $item['6'], | 
					
						
							|  |  |  | 				'callsign' => $item['callsign'], | 
					
						
							| 
									
										
										
										
											2025-08-11 21:50:56 +08:00
										 |  |  | 				'workedBefore' => $worked['workedBefore'], | 
					
						
							|  |  |  | 				'confirmed' => $worked['confirmed'], | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$data['dxcclist'] = $requiredData; | 
					
						
							|  |  |  | 		$this->load->view('/workabledxcc/components/dxcclist', $data); | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 	function dxccWorked($country) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$return = [ | 
					
						
							|  |  |  | 			"workedBefore" => false, | 
					
						
							|  |  |  | 			"confirmed" => false, | 
					
						
							|  |  |  | 		]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$user_default_confirmation = $this->session->userdata('user_default_confirmation'); | 
					
						
							|  |  |  | 		$this->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 		$this->load->model('logbook_model'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 		if (!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  | 			$this->db->where('COL_PROP_MODE !=', 'SAT'); | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			$this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  | 			$this->db->where('COL_COUNTRY', urldecode($country)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$query = $this->db->get($this->config->item('table_name'), 1, 0); | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 			foreach ($query->result() as $workedBeforeRow) { | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 				$return['workedBefore'] = true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 			$extrawhere = ''; | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Q') !== false) { | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 				$extrawhere = "COL_QSL_RCVD='Y'"; | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'L') !== false) { | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 				if ($extrawhere != '') { | 
					
						
							|  |  |  | 					$extrawhere .= " OR"; | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 				$extrawhere .= " COL_LOTW_QSL_RCVD='Y'"; | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'E') !== false) { | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 				if ($extrawhere != '') { | 
					
						
							|  |  |  | 					$extrawhere .= " OR"; | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 				$extrawhere .= " COL_EQSL_QSL_RCVD='Y'"; | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Z') !== false) { | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 				if ($extrawhere != '') { | 
					
						
							|  |  |  | 					$extrawhere .= " OR"; | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 				$extrawhere .= " COL_QRZCOM_QSO_DOWNLOAD_STATUS='Y'"; | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 			$this->load->model('logbook_model'); | 
					
						
							|  |  |  | 			$this->db->where('COL_PROP_MODE !=', 'SAT'); | 
					
						
							|  |  |  | 			if ($extrawhere != '') { | 
					
						
							|  |  |  | 				$this->db->where('(' . $extrawhere . ')'); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				$this->db->where("1=0"); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  | 			$this->db->where('COL_COUNTRY', urldecode($country)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$query = $this->db->get($this->config->item('table_name'), 1, 0); | 
					
						
							|  |  |  | 			foreach ($query->result() as $workedBeforeRow) { | 
					
						
							| 
									
										
										
										
											2024-02-16 22:26:08 +08:00
										 |  |  | 				$return['confirmed'] = true; | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return $return; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$return['workedBefore'] = false; | 
					
						
							|  |  |  | 			$return['confirmed'] = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return $return;; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-18 01:54:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-15 23:30:23 +08:00
										 |  |  | } |