| 
									
										
										
										
											2021-09-04 15:30:51 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Dxatlas_model extends CI_Model | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 	 *  Fetches worked and confirmed gridsquare from the logbook | 
					
						
							| 
									
										
										
										
											2021-09-04 15:30:51 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-09-05 16:43:36 +08:00
										 |  |  | 	function get_gridsquares($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate) { | 
					
						
							|  |  |  | 		$gridArray = $this->fetchGrids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate); | 
					
						
							| 
									
										
										
										
											2021-09-04 15:30:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (isset($gridArray)) { | 
					
						
							|  |  |  | 			return $gridArray; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 	/* | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 	 * Builds the array for worked and confirmed gridsquares | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-09-05 16:43:36 +08:00
										 |  |  | 	function fetchGrids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate) { | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 		// Getting all the worked grids
 | 
					
						
							| 
									
										
										
										
											2021-09-05 16:43:36 +08:00
										 |  |  | 		$col_gridsquare_worked = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'none', 'single'); | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$workedGridArray = array(); | 
					
						
							|  |  |  | 		foreach ($col_gridsquare_worked as $workedgrid) { | 
					
						
							|  |  |  | 			array_push($workedGridArray, $workedgrid['gridsquare']); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-05 16:43:36 +08:00
										 |  |  | 		$col_vucc_grids_worked = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'none', 'multi'); | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		foreach ($col_vucc_grids_worked as $gridSplit) { | 
					
						
							|  |  |  | 			$grids = explode(",", $gridSplit['col_vucc_grids']); | 
					
						
							|  |  |  | 			foreach($grids as $key) { | 
					
						
							|  |  |  | 				$grid_four = strtoupper(substr(trim($key),0,4)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if(!in_array($grid_four, $workedGridArray)){ | 
					
						
							|  |  |  | 					array_push($workedGridArray, $grid_four); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Getting all the confirmed grids
 | 
					
						
							| 
									
										
										
										
											2021-09-05 16:43:36 +08:00
										 |  |  | 		$col_gridsquare_confirmed = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'both', 'single'); | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$confirmedGridArray = array(); | 
					
						
							|  |  |  | 		foreach ($col_gridsquare_confirmed as $confirmedgrid) { | 
					
						
							|  |  |  | 			array_push($confirmedGridArray, $confirmedgrid['gridsquare']); | 
					
						
							|  |  |  | 			if(in_array($confirmedgrid['gridsquare'], $workedGridArray)){ | 
					
						
							|  |  |  | 				$index = array_search($confirmedgrid['gridsquare'],$workedGridArray); | 
					
						
							|  |  |  | 				unset($workedGridArray[$index]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-05 16:43:36 +08:00
										 |  |  | 		$col_vucc_grids_confirmed = $this->get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, 'both', 'multi'); | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		foreach ($col_vucc_grids_confirmed as $gridSplit) { | 
					
						
							|  |  |  | 			$grids = explode(",", $gridSplit['col_vucc_grids']); | 
					
						
							|  |  |  | 			foreach($grids as $key) { | 
					
						
							|  |  |  | 				$grid_four = strtoupper(substr(trim($key),0,4)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if(!in_array($grid_four, $confirmedGridArray)){ | 
					
						
							|  |  |  | 					array_push($confirmedGridArray, $grid_four); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if(in_array($grid_four, $workedGridArray)){ | 
					
						
							|  |  |  | 					$index = array_search($grid_four,$workedGridArray); | 
					
						
							|  |  |  | 					unset($workedGridArray[$index]); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$vuccArray['worked'] = $workedGridArray; | 
					
						
							|  |  |  | 		$vuccArray['confirmed'] = $confirmedGridArray; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $vuccArray; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 	 * Gets the grids from the datbase | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Filters: | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * $band = filter on band | 
					
						
							|  |  |  | 	 * $mode = filter on mode | 
					
						
							|  |  |  | 	 * $dxcc = filter on dxx | 
					
						
							|  |  |  | 	 * $cqz = filter on cq zone | 
					
						
							|  |  |  | 	 * $propagation = Filter on propagation | 
					
						
							|  |  |  | 	 * $fromdate = Date range from | 
					
						
							|  |  |  | 	 * $todate = Date range to | 
					
						
							|  |  |  | 	 * $column = Chooses if we fetch from col_gridsquare (only single grids) or col_vucc_grids (multisquares) | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 	 * $confirmationMethod - qsl, lotw or both, use anything else to skip confirmed | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-09-05 16:43:36 +08:00
										 |  |  | 	function get_grids($station_id, $band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate, $confirmationMethod, $column) { | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 		$sql = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($column == 'single') { | 
					
						
							|  |  |  | 			$sql .= "select distinct upper(substring(col_gridsquare, 1, 4)) gridsquare
 | 
					
						
							| 
									
										
										
										
											2021-11-18 16:29:14 +08:00
										 |  |  | 					from " . $this->config->item('table_name') .
 | 
					
						
							|  |  |  | 					' join station_profile on station_profile.station_id = ' . $this->config->item('table_name').'.station_id' . | 
					
						
							| 
									
										
										
										
											2021-09-05 16:43:36 +08:00
										 |  |  | 				" where col_gridsquare <> ''"; | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if ($column == 'multi') { | 
					
						
							|  |  |  | 			$sql .= "select col_vucc_grids
 | 
					
						
							|  |  |  |             	 from " . $this->config->item('table_name') .
 | 
					
						
							| 
									
										
										
										
											2021-11-18 16:29:14 +08:00
										 |  |  | 				 ' join station_profile on station_profile.station_id = ' . $this->config->item('table_name').'.station_id' . | 
					
						
							| 
									
										
										
										
											2021-09-05 16:43:36 +08:00
										 |  |  | 				" where col_vucc_grids <> '' "; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($station_id != "All") { | 
					
						
							| 
									
										
										
										
											2021-11-18 16:29:14 +08:00
										 |  |  | 			$sql .= ' and ' . $this->config->item('table_name'). '.station_id = ' . $station_id; | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ($confirmationMethod == 'both') { | 
					
						
							|  |  |  | 			$sql .= " and (col_qsl_rcvd='Y' or col_lotw_qsl_rcvd='Y')"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if ($confirmationMethod == 'qsl') { | 
					
						
							|  |  |  | 			$sql .= " and col_qsl_rcvd='Y'"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if ($confirmationMethod == 'lotw') { | 
					
						
							|  |  |  | 			$sql .= " and col_lotw_qsl_rcvd='Y'"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($band != 'All') { | 
					
						
							|  |  |  | 			if ($band == 'SAT') { | 
					
						
							|  |  |  | 				$sql .= " and col_prop_mode ='" . $band . "'"; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				$sql .= " and col_prop_mode !='SAT'"; | 
					
						
							|  |  |  | 				$sql .= " and col_band ='" . $band . "'"; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 		if ($mode != 'All') { | 
					
						
							|  |  |  | 			$sql .= " and (COL_MODE = '" . $mode . "' or COL_SUBMODE = '" . $mode . "')"; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 		if ($dxcc != 'All') { | 
					
						
							|  |  |  | 			$sql .= " and COL_DXCC ='" . $dxcc . "'"; | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ($cqz != 'All') { | 
					
						
							|  |  |  | 			$sql .= " and COL_CQZ ='" . $cqz . "'"; | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ($propagation != 'All') { | 
					
						
							|  |  |  | 			$sql .= " and COL_PROP_MODE ='" . $propagation . "'"; | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 		// If date is set, we format the date and add it to the where-statement
 | 
					
						
							|  |  |  | 		if ($fromdate != "") { | 
					
						
							| 
									
										
										
										
											2023-11-17 22:27:44 +08:00
										 |  |  | 			$sql .= " and date(COL_TIME_ON) >='" . $fromdate . "'"; | 
					
						
							| 
									
										
										
										
											2021-09-05 15:24:36 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if ($todate != "") { | 
					
						
							| 
									
										
										
										
											2023-11-17 22:27:44 +08:00
										 |  |  | 			$sql .= " and date(COL_TIME_ON) <='" . $todate . "'"; | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 16:29:14 +08:00
										 |  |  | 		$sql .= ' and station_profile.user_id = ' . $this->session->userdata('user_id'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-05 02:26:51 +08:00
										 |  |  | 		$query = $this->db->query($sql); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $query->result_array(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-09-04 15:30:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | ?>
 |