| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | require_once(dirname(__FILE__).'/class.Image.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | $global_query = "SELECT marine_output.* FROM marine_output"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | class Marine{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | 	public $db; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 	public function __construct($dbc = null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 		$Connection = new Connection($dbc); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 		$this->db = $Connection->db(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 		if ($this->db === null) die('Error: No DB connection. (Marine)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	* Get SQL query part for filter used | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	* @param Array $filter the filter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	* @return Array the SQL part | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	public function getFilter($filter = array(),$where = false,$and = false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		$filters = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		if (is_array($globalStatsFilters) && isset($globalStatsFilters[$globalFilterName])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 			if (isset($globalStatsFilters[$globalFilterName][0]['source'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 				$filters = $globalStatsFilters[$globalFilterName]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 				$filter = array_merge($filter,$globalStatsFilters[$globalFilterName]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		if (isset($filter[0]['source'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 			$filters = array_merge($filters,$filter); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		$filter_query_join = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		$filter_query_where = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		foreach($filters as $flt) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 			if (isset($flt['idents']) && !empty($flt['idents'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 				if (isset($flt['source'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."') AND spotter_output.format_source IN ('".implode("','",$flt['source'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 				} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 					$filter_query_join .= " INNER JOIN (SELECT fammarine_id FROM marine_output WHERE marine_output.ident IN ('".implode("','",$flt['idents'])."')) spfi ON spfi.fammarine_id = marine_output.fammarine_id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		if (isset($filter['source']) && !empty($filter['source'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 			$filter_query_where .= " AND format_source IN ('".implode("','",$filter['source'])."')"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		if (isset($filter['ident']) && !empty($filter['ident'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			$filter_query_where .= " AND ident = '".$filter['ident']."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		if (isset($filter['mmsi']) && !empty($filter['mmsi'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			$filter_query_where .= " AND mmsi = '".$filter['mmsi']."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		if (isset($filter['year']) && $filter['year'] != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 				$filter_query_where .= " AND YEAR(marine_output.date) = '".$filter['year']."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 				$filter_query_where .= " AND EXTRACT(YEAR FROM marine_output.date) = '".$filter['year']."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		if (isset($filter['month']) && $filter['month'] != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 				$filter_query_where .= " AND MONTH(marine_output.date) = '".$filter['month']."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 				$filter_query_where .= " AND EXTRACT(MONTH FROM marine_output.date) = '".$filter['month']."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		if (isset($filter['day']) && $filter['day'] != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 				$filter_query_where .= " AND DAY(marine_output.date) = '".$filter['day']."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 				$filter_query_where .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		if ($filter_query_where != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		$filter_query = $filter_query_join.$filter_query_where; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		return $filter_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	* Executes the SQL statements to get the spotter information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	* @param String $query the SQL query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	* @param Array $params parameter of the query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	* @param String $limitQuery the limit query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	* @return Array the spotter information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	* | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 92 |  |  | 	*/ | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  | 	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  | 		date_default_timezone_set('UTC'); | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  | 		if (!is_string($query)) | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  | 		{ | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  | 			return false; | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  | 		 | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  | 		if ($limitQuery != "") | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  | 		{ | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  | 			if (!is_string($limitQuery)) | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  | 			{ | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  | 				return false; | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  | 		try { | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  | 			$sth = $this->db->prepare($query.$limitQuery); | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  | 			$sth->execute($params); | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  | 		} catch (PDOException $e) { | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  | 			printf("Invalid query : %s\nWhole query: %s\n",$e->getMessage(), $query.$limitQuery); | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  | 			exit(); | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  | 		 | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  | 		$num_rows = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  | 		$spotter_array = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  | 		{ | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  | 			$num_rows++; | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  | 			$temp_array = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  | 			if (isset($row['marine_live_id'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  | 				$temp_array['marine_id'] = $this->getMarineIDBasedOnFamMarineID($row['fammarine_id']); | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  | 			/* | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  | 			} elseif (isset($row['spotter_archive_id'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  | 				$temp_array['spotter_id'] = $row['spotter_archive_id']; | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  | 			} elseif (isset($row['spotter_archive_output_id'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  | 				$temp_array['spotter_id'] = $row['spotter_archive_output_id']; | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  | 			*/}  | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  | 			elseif (isset($row['marineid'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  | 				$temp_array['marine_id'] = $row['marineid']; | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  | 			} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  | 				$temp_array['marine_id'] = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  | 			if (isset($row['fammarine_id'])) $temp_array['fammarine_id'] = $row['fammarine_id']; | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  | 			if (isset($row['mmsi'])) $temp_array['mmsi'] = $row['mmsi']; | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  | 			if (isset($row['type'])) $temp_array['type'] = $row['type']; | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  | 			if (isset($row['type_id'])) $temp_array['type_id'] = $row['type_id']; | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  | 			if (isset($row['status'])) $temp_array['status'] = $row['status']; | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  | 			if (isset($row['status_id'])) $temp_array['status_id'] = $row['status_id']; | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  | 			if (isset($row['ident'])) $temp_array['ident'] = $row['ident']; | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  | 			if (isset($row['arrival_port_name'])) $temp_array['arrival_port_name'] = $row['arrival_port_name']; | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  | 			if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude']; | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  | 			if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude']; | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  | 			if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source']; | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  | 			if (isset($row['heading'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  | 				$temp_array['heading'] = $row['heading']; | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  | 				$heading_direction = $this->parseDirection($row['heading']); | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  | 				if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname']; | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  | 			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed']; | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  | 			if(isset($temp_array['mmsi']) && $temp_array['mmsi'] != "") | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  | 			{ | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  | 				$Image = new Image($this->db); | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  | 				if (isset($temp_array['ident']) && $temp_array['ident'] != '') $image_array = $Image->getMarineImage($temp_array['mmsi'],'',$temp_array['ident']); | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  | 				else $image_array = $Image->getMarineImage($temp_array['mmsi']); | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  | 				unset($Image); | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  | 				if (count($image_array) > 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  | 					$temp_array['image'] = $image_array[0]['image']; | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  | 					$temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  | 					$temp_array['image_source'] = $image_array[0]['image_source']; | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  | 					$temp_array['image_source_website'] = $image_array[0]['image_source_website']; | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  | 					$temp_array['image_copyright'] = $image_array[0]['image_copyright']; | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  | 				} | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  | 			 | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  | 			if (isset($row['date'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  | 				$dateArray = $this->parseDateString($row['date']); | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  | 				if ($dateArray['seconds'] < 10) | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  | 				{ | 
            
                                                                        
                            
            
                                    
            
            
                | 173 |  |  | 					$temp_array['date'] = "a few seconds ago"; | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  | 				} elseif ($dateArray['seconds'] >= 5 && $dateArray['seconds'] < 30) | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  | 				{ | 
            
                                                                        
                            
            
                                    
            
            
                | 176 |  |  | 					$temp_array['date'] = "half a minute ago"; | 
            
                                                                        
                            
            
                                    
            
            
                | 177 |  |  | 				} elseif ($dateArray['seconds'] >= 30 && $dateArray['seconds'] < 60) | 
            
                                                                        
                            
            
                                    
            
            
                | 178 |  |  | 				{ | 
            
                                                                        
                            
            
                                    
            
            
                | 179 |  |  | 					$temp_array['date'] = "about a minute ago"; | 
            
                                                                        
                            
            
                                    
            
            
                | 180 |  |  | 				} elseif ($dateArray['minutes'] < 5) | 
            
                                                                        
                            
            
                                    
            
            
                | 181 |  |  | 				{ | 
            
                                                                        
                            
            
                                    
            
            
                | 182 |  |  | 					$temp_array['date'] = "a few minutes ago"; | 
            
                                                                        
                            
            
                                    
            
            
                | 183 |  |  | 				} elseif ($dateArray['minutes'] >= 5 && $dateArray['minutes'] < 60) | 
            
                                                                        
                            
            
                                    
            
            
                | 184 |  |  | 				{ | 
            
                                                                        
                            
            
                                    
            
            
                | 185 |  |  | 					$temp_array['date'] = "about ".$dateArray['minutes']." minutes ago"; | 
            
                                                                        
                            
            
                                    
            
            
                | 186 |  |  | 				} elseif ($dateArray['hours'] < 2) | 
            
                                                                        
                            
            
                                    
            
            
                | 187 |  |  | 				{ | 
            
                                                                        
                            
            
                                    
            
            
                | 188 |  |  | 					$temp_array['date'] = "about an hour ago"; | 
            
                                                                        
                            
            
                                    
            
            
                | 189 |  |  | 				} elseif ($dateArray['hours'] >= 2 && $dateArray['hours'] < 24) | 
            
                                                                        
                            
            
                                    
            
            
                | 190 |  |  | 				{ | 
            
                                                                        
                            
            
                                    
            
            
                | 191 |  |  | 					$temp_array['date'] = "about ".$dateArray['hours']." hours ago"; | 
            
                                                                        
                            
            
                                    
            
            
                | 192 |  |  | 				} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 193 |  |  | 					$temp_array['date'] = date("M j Y, g:i a",strtotime($row['date']." UTC")); | 
            
                                                                        
                            
            
                                    
            
            
                | 194 |  |  | 				} | 
            
                                                                        
                            
            
                                    
            
            
                | 195 |  |  | 				$temp_array['date_minutes_past'] = $dateArray['minutes']; | 
            
                                                                        
                            
            
                                    
            
            
                | 196 |  |  | 				$temp_array['date_iso_8601'] = date("c",strtotime($row['date']." UTC")); | 
            
                                                                        
                            
            
                                    
            
            
                | 197 |  |  | 				$temp_array['date_rfc_2822'] = date("r",strtotime($row['date']." UTC")); | 
            
                                                                        
                            
            
                                    
            
            
                | 198 |  |  | 				$temp_array['date_unix'] = strtotime($row['date']." UTC"); | 
            
                                                                        
                            
            
                                    
            
            
                | 199 |  |  | 				if (isset($row['last_seen']) && $row['last_seen'] != '') { | 
            
                                                                        
                            
            
                                    
            
            
                | 200 |  |  | 					if (strtotime($row['last_seen']) > strtotime($row['date'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 201 |  |  | 						$temp_array['duration'] = strtotime($row['last_seen']) - strtotime($row['date']); | 
            
                                                                        
                            
            
                                    
            
            
                | 202 |  |  | 						$temp_array['last_seen_date_iso_8601'] = date("c",strtotime($row['last_seen']." UTC")); | 
            
                                                                        
                            
            
                                    
            
            
                | 203 |  |  | 						$temp_array['last_seen_date_rfc_2822'] = date("r",strtotime($row['last_seen']." UTC")); | 
            
                                                                        
                            
            
                                    
            
            
                | 204 |  |  | 						$temp_array['last_seen_date_unix'] = strtotime($row['last_seen']." UTC"); | 
            
                                                                        
                            
            
                                    
            
            
                | 205 |  |  | 					} | 
            
                                                                        
                            
            
                                    
            
            
                | 206 |  |  | 				} | 
            
                                                                        
                            
            
                                    
            
            
                | 207 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 208 |  |  | 			 | 
            
                                                                        
                            
            
                                    
            
            
                | 209 |  |  | 			$fromsource = NULL; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 210 |  |  | 			if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name']; | 
            
                                                                        
                            
            
                                    
            
            
                | 211 |  |  | 			if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country']; | 
            
                                                                        
                            
            
                                    
            
            
                | 212 |  |  | 			if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance']; | 
            
                                                                        
                            
            
                                    
            
            
                | 213 |  |  | 			$temp_array['query_number_rows'] = $num_rows; | 
            
                                                                        
                            
            
                                    
            
            
                | 214 |  |  | 			$spotter_array[] = $temp_array; | 
            
                                                                        
                            
            
                                    
            
            
                | 215 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 216 |  |  | 		if ($num_rows == 0) return array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 217 |  |  | 		$spotter_array[0]['query_number_rows'] = $num_rows; | 
            
                                                                        
                            
            
                                    
            
            
                | 218 |  |  | 		return $spotter_array; | 
            
                                                                        
                            
            
                                    
            
            
                | 219 |  |  | 	}	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | 	* Gets all the spotter information based on the latest data entry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 	* @return Array the spotter information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  | 	public function getLatestMarineData($limit = '', $sort = '', $filter = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | 		global $global_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  | 		date_default_timezone_set('UTC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  | 		$filter_query = $this->getFilter($filter); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | 		if ($limit != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | 			$limit_array = explode(",", $limit); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | 			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  | 			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  | 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  | 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  | 			} else $limit_query = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  | 		} else $limit_query = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | 		if ($sort != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | 			$search_orderby_array = $this->getOrderBy(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 			$orderby_query = $search_orderby_array[$sort]['sql']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | 			$orderby_query = " ORDER BY marine_output.date DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 		$query  = $global_query.$filter_query." ".$orderby_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  | 		$spotter_array = $this->getDataFromDB($query, array(),$limit_query,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | 		return $spotter_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  | 	/* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 	* Gets all the spotter information based on the spotter id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | 	* @return Array the spotter information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | 	public function getMarineDataByID($id = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | 		global $global_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  | 		date_default_timezone_set('UTC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 		if ($id == '') return array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  | 		$additional_query = "marine_output.fammarine_id = :id"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | 		$query_values = array(':id' => $id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  | 		$query  = $global_query." WHERE ".$additional_query." "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  | 		$spotter_array = $this->getDataFromDB($query,$query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  | 		return $spotter_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  | 	* Gets all the spotter information based on the callsign | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  | 	* @return Array the spotter information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  | 	public function getMarineDataByIdent($ident = '', $limit = '', $sort = '', $filter = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  | 		global $global_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  | 		date_default_timezone_set('UTC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  | 		$query_values = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  | 		$limit_query = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  | 		$additional_query = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  | 		$filter_query = $this->getFilter($filter,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  | 		if ($ident != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  | 			if (!is_string($ident)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  | 				$additional_query = " AND (marine_output.ident = :ident)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  | 				$query_values = array(':ident' => $ident); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  | 		if ($limit != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  | 			$limit_array = explode(",", $limit); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  | 			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  | 			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  | 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  | 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  | 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  | 		if ($sort != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  | 			$search_orderby_array = $this->getOrderBy(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  | 			$orderby_query = $search_orderby_array[$sort]['sql']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  | 			$orderby_query = " ORDER BY marine_output.date DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  | 		$query = $global_query.$filter_query." marine_output.ident <> '' ".$additional_query." ".$orderby_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  | 		//echo $query."\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  | 		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  | 		return $spotter_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  | 	* Gets all the marine information based on the type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  | 	* @return Array the marine information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  | 	public function getMarineDataByType($type = '', $limit = '', $sort = '', $filter = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  | 		global $global_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  | 		date_default_timezone_set('UTC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  | 		$query_values = array(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  | 		$limit_query = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  | 		$additional_query = ''; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  | 		$filter_query = $this->getFilter($filter,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  | 		if (!is_string($type)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  | 			return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  | 			$additional_query = " AND marine_output.type_id = :type"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  | 			$query_values = array(':type' => $type); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  | 		if ($limit != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  | 			$limit_array = explode(",", $limit); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  | 			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  | 			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  | 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  | 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  | 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  | 		if ($sort != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  | 			$search_orderby_array = $this->getOrderBy(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  | 			$orderby_query = $search_orderby_array[$sort]['sql']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  | 			$orderby_query = " ORDER BY marine_output.date DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  | 		$query = $global_query.$filter_query." marine_output.type <> '' ".$additional_query." ".$orderby_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  | 		//echo $query."\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  | 		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  | 		return $spotter_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  | 	public function getMarineDataByDate($date = '', $limit = '', $sort = '',$filter = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  | 		global $global_query, $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  | 		$query_values = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  | 		$limit_query = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  | 		$additional_query = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  | 		$filter_query = $this->getFilter($filter,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  | 		if ($date != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  | 			if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  | 				date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  | 				$datetime = new DateTime($date); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  | 				$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  | 				date_default_timezone_set('UTC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  | 				$datetime = new DateTime($date); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  | 				$offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  | 				$additional_query = " AND DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  | 				$query_values = array(':date' => $datetime->format('Y-m-d'), ':offset' => $offset); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  | 			} elseif ($globalDBdriver == 'pgsql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  | 				$additional_query = " AND to_char(marine_output.date AT TIME ZONE :timezone,'YYYY-mm-dd') = :date "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  | 				$query_values = array(':date' => $datetime->format('Y-m-d'), ':timezone' => $globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  | 		if ($limit != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  | 			$limit_array = explode(",", $limit); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  | 			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  | 			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  | 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  | 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  | 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  | 		if ($sort != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  | 			$search_orderby_array = $this->getOrderBy(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  | 			$orderby_query = $search_orderby_array[$sort]['sql']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  | 			$orderby_query = " ORDER BY marine_output.date DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  | 		$query = $global_query.$filter_query." marine_output.ident <> '' ".$additional_query.$orderby_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  | 		$spotter_array = $this->getDataFromDB($query, $query_values, $limit_query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  | 		return $spotter_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  | 	* Gets all source name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  | 	* @param String type format of source | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  | 	* @return Array list of source name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  | 	public function getAllSourceName($type = '',$filters = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  | 		$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  | 		$query_values = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  | 		$query  = "SELECT DISTINCT marine_output.source_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  | 				FROM marine_output".$filter_query." marine_output.source_name <> ''"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  | 		if ($type != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  | 			$query_values = array(':type' => $type); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  | 			$query .= " AND format_source = :type"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  | 		$query .= " ORDER BY marine_output.source_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  | 		if (!empty($query_values)) $sth->execute($query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  | 		else $sth->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  | 		$source_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  | 			$temp_array['source_name'] = $row['source_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  | 			$source_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  | 		return $source_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  | 	* Gets a list of all idents/callsigns | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  | 	* @return Array list of ident/callsign names | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  | 	public function getAllIdents($filters = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  | 		$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  | 		$query  = "SELECT DISTINCT marine_output.ident | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  | 								FROM marine_output".$filter_query." marine_output.ident <> ''  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  | 								ORDER BY marine_output.date ASC LIMIT 700 OFFSET 0"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  | 		$sth->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  | 		$ident_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  | 			$temp_array['ident'] = $row['ident']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  | 			$ident_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  | 		return $ident_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  | 	* Gets all info from a mmsi | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  | 	* @return Array ident | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  | 	public function getIdentity($mmsi) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  | 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  | 		$query  = "SELECT * FROM marine_identity WHERE mmsi = :mmsi LIMIT 1"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  | 		$sth->execute(array(':mmsi' => $mmsi)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  | 		$result = $sth->fetchAll(PDO::FETCH_ASSOC); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  | 		if (isset($result[0])) return $result[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  | 		else return array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  | 	* Add identity | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  | 	public function addIdentity($mmsi,$imo,$ident,$callsign,$type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  | 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  | 		if ($mmsi != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 531 |  |  | 			$imo = filter_var($imo,FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  | 			$ident = filter_var($ident,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  | 			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  | 			$type = filter_var($type,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  | 			$identinfo = $this->getIdentity($mmsi); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  | 			if (empty($identinfo)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  | 				$query  = "INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:type)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  | 				$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  | 				$sth->execute(array(':mmsi' => $mmsi,':imo' => $imo,':call_sign' => $callsign,':ship_name' => $ident,':type' => $type)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  | 			} elseif ($ident != '' && $identinfo['ship_name'] != $ident) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  | 				$query  = "UPDATE marine_identity SET ship_name = :ship_name,type = :type WHERE mmsi = :mmsi"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  | 				$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  | 				$sth->execute(array(':mmsi' => $mmsi,':ship_name' => $ident,':type' => $type)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 544 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 545 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 546 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 547 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 548 |  |  | 	/* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  | 	* Gets a list of all dates | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  | 	* @return Array list of date names | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  | 	public function getAllDates() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 556 |  |  | 		global $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 557 |  |  | 		if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 558 |  |  | 			date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 559 |  |  | 			$datetime = new DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 560 |  |  | 			$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 561 |  |  | 		} else $offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 562 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 563 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 564 |  |  | 			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 565 |  |  | 								FROM marine_output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 566 |  |  | 								WHERE marine_output.date <> ''  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 567 |  |  | 								ORDER BY marine_output.date ASC LIMIT 0,100"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 568 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 569 |  |  | 			$query  = "SELECT DISTINCT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') as date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 570 |  |  | 								FROM marine_output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 571 |  |  | 								WHERE marine_output.date <> ''  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 572 |  |  | 								ORDER BY marine_output.date ASC LIMIT 0,100"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 573 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 574 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 575 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 576 |  |  | 		$sth->execute(array(':offset' => $offset)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 577 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 578 |  |  | 		$date_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 579 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 580 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 581 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 582 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 583 |  |  | 			$temp_array['date'] = $row['date']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 584 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 585 |  |  | 			$date_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 586 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 587 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 588 |  |  | 		return $date_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 589 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 590 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 591 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 592 |  |  | 	* Update ident tracker data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 593 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 594 |  |  | 	* @param String $fammarine_id the ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 595 |  |  | 	* @param String $ident the marine ident | 
            
                                                                                                            
                            
            
                                    
            
            
                | 596 |  |  | 	* @return String success or false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 597 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 598 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 599 |  |  | 	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 600 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 601 |  |  | 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 602 |  |  | 		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 603 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 604 |  |  | 			$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 605 |  |  | 			$sth->execute($query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 606 |  |  | 		} catch (PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 607 |  |  | 			return "error : ".$e->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 608 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 609 |  |  | 		return "success"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 610 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 611 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 612 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 613 |  |  | 	* Update arrival marine data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 614 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 615 |  |  | 	* @param String $fammarine_id the ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 616 |  |  | 	* @param String $arrival_code the marine ident | 
            
                                                                                                            
                            
            
                                    
            
            
                | 617 |  |  | 	* @return String success or false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 618 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 619 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 620 |  |  | 	public function updateArrivalPortNameMarineData($fammarine_id = '', $arrival_code = '',$fromsource = NULL) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 621 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 622 |  |  | 		$query = 'UPDATE marine_output SET arrival_port_name = :arrival_code WHERE fammarine_id = :fammarine_id'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 623 |  |  | 		$query_values = array(':fammarine_id' => $fammarine_id,':arrival_code' => $arrival_code); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 624 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 625 |  |  | 			$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 626 |  |  | 			$sth->execute($query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 627 |  |  | 		} catch (PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 628 |  |  | 			return "error : ".$e->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 629 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 630 |  |  | 		return "success"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 631 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 632 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 633 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 634 |  |  | 	* Update Status data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 635 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 636 |  |  | 	* @param String $fammarine_id the ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 637 |  |  | 	* @param String $status_id the marine status id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 638 |  |  | 	* @param String $status the marine status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 639 |  |  | 	* @return String success or false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 640 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 641 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 642 |  |  | 	public function updateStatusMarineData($fammarine_id = '', $status_id = '',$status = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 643 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 644 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 645 |  |  | 		$query = 'UPDATE marine_output SET status = :status, status_id = :status_id WHERE fammarine_id = :fammarine_id'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 646 |  |  |                 $query_values = array(':fammarine_id' => $fammarine_id,':status' => $status,':status_id' => $status_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 647 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 648 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 649 |  |  | 			$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 650 |  |  | 			$sth->execute($query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 651 |  |  | 		} catch (PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 652 |  |  | 			return "error : ".$e->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 653 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 654 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 655 |  |  | 		return "success"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 656 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 657 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 658 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 659 |  |  | 	* Update latest marine data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 660 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 661 |  |  | 	* @param String $fammarine_id the ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 662 |  |  | 	* @param String $ident the marine ident | 
            
                                                                                                            
                            
            
                                    
            
            
                | 663 |  |  | 	* @return String success or false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 664 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 665 |  |  | 	*/	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 666 |  |  | 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 667 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 668 |  |  | 		$query = 'UPDATE marine_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_seen = :last_seen, last_ground_speed = :last_ground_speed WHERE fammarine_id = :fammarine_id'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 669 |  |  |                 $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 670 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 671 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 672 |  |  | 			$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 673 |  |  | 			$sth->execute($query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 674 |  |  | 		} catch (PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 675 |  |  | 			return "error : ".$e->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 676 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 677 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 678 |  |  | 		return "success"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 679 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 680 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 681 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 682 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 683 |  |  | 	* Adds a new spotter data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 684 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 685 |  |  | 	* @param String $fammarine_id the ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 686 |  |  | 	* @param String $ident the marine ident | 
            
                                                                                                            
                            
            
                                    
            
            
                | 687 |  |  | 	* @param String $departure_airport_icao the departure airport | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 688 |  |  | 	* @param String $arrival_airport_icao the arrival airport | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 689 |  |  | 	* @param String $latitude latitude of flight | 
            
                                                                                                            
                            
            
                                    
            
            
                | 690 |  |  | 	* @param String $longitude latitude of flight | 
            
                                                                                                            
                            
            
                                    
            
            
                | 691 |  |  | 	* @param String $waypoints waypoints of flight | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 692 |  |  | 	* @param String $heading heading of flight | 
            
                                                                                                            
                            
            
                                    
            
            
                | 693 |  |  | 	* @param String $groundspeed speed of flight | 
            
                                                                                                            
                            
            
                                    
            
            
                | 694 |  |  | 	* @param String $date date of flight | 
            
                                                                                                            
                            
            
                                    
            
            
                | 695 |  |  | 	* @param String $departure_airport_time departure time of flight | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 696 |  |  | 	* @param String $arrival_airport_time arrival time of flight | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 697 |  |  | 	* @param String $squawk squawk code of flight | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 698 |  |  | 	* @param String $route_stop route stop of flight | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 699 |  |  | 	* @param String $highlight highlight or not | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 700 |  |  | 	* @param String $ModeS ModesS code of flight | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 701 |  |  | 	* @param String $registration registration code of flight | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 702 |  |  | 	* @param String $pilot_id pilot id of flight (for virtual airlines) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 703 |  |  | 	* @param String $pilot_name pilot name of flight (for virtual airlines) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 704 |  |  | 	* @param String $verticalrate vertival rate of flight | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 705 |  |  | 	* @return String success or false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 706 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 707 |  |  | 	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$typeid = '',$imo = '',$callsign = '',$arrival_code = '',$arrival_date = '',$status = '',$statusid = '',$format_source = '', $source_name = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 708 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 709 |  |  | 		global $globalURL, $globalMarineImageFetch; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 710 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 711 |  |  | 		//$Image = new Image($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 712 |  |  | 		$Common = new Common(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 713 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 714 |  |  | 		date_default_timezone_set('UTC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 715 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 716 |  |  | 		//getting the registration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 717 |  |  | 		if ($fammarine_id != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 718 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 719 |  |  | 			if (!is_string($fammarine_id)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 720 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 721 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 722 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 723 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 724 |  |  | 		$fromsource = NULL; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 725 |  |  | 		//getting the airline information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 726 |  |  | 		if ($ident != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 727 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 728 |  |  | 			if (!is_string($ident)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 729 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 730 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 731 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 732 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 733 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 734 |  |  | 		if ($latitude != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 735 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 736 |  |  | 			if (!is_numeric($latitude)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 737 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 738 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 739 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 740 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 741 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 742 |  |  | 		if ($longitude != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 743 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 744 |  |  | 			if (!is_numeric($longitude)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 745 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 746 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 747 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 748 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 749 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 750 |  |  | 		if ($heading != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 751 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 752 |  |  | 			if (!is_numeric($heading)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 753 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 754 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 755 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 756 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 757 |  |  | 		if ($mmsi != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 758 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 759 |  |  | 			if (!is_numeric($mmsi)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 760 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 761 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 762 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 763 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 764 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 765 |  |  | 		if ($groundspeed != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 766 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 767 |  |  | 			if (!is_numeric($groundspeed)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 768 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 769 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 770 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 771 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 772 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 773 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 774 |  |  | 		if ($date == "" || strtotime($date) < time()-20*60) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 775 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 776 |  |  | 			$date = date("Y-m-d H:i:s", time()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 777 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 778 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 779 |  |  | 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 780 |  |  | 		$ident = filter_var($ident,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 781 |  |  | 		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 782 |  |  | 		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 783 |  |  | 		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 784 |  |  | 		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 785 |  |  | 		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 786 |  |  | 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 787 |  |  | 		$type = filter_var($type,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 788 |  |  | 		$status = filter_var($status,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 789 |  |  | 		$type_id = filter_var($typeid,FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 790 |  |  | 		$status_id = filter_var($statusid,FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 791 |  |  | 		$imo = filter_var($imo,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 792 |  |  | 		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 793 |  |  | 		$arrival_code = filter_var($arrival_code,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 794 |  |  | 		$arrival_date = filter_var($arrival_date,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 795 |  |  | 		if (isset($globalMarineImageFetch) && $globalMarineImageFetch === TRUE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 796 |  |  | 			$Image = new Image($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 797 |  |  | 			$image_array = $Image->getMarineImage($mmsi,$imo,$ident); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 798 |  |  | 			if (!isset($image_array[0]['mmsi'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 799 |  |  | 				$Image->addMarineImage($mmsi,$imo,$ident); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 800 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 801 |  |  | 			unset($Image); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 802 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 803 |  |  | 		if ($latitude == '' && $longitude == '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 804 |  |  | 			$latitude = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 805 |  |  | 			$longitude = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 806 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 807 |  |  | 		if ($type_id == '') $type_id = NULL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 808 |  |  | 		if ($status_id == '') $status_id = NULL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 809 |  |  | 		if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 810 |  |  | 		if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 811 |  |  | 		if ($arrival_date == '') $arrival_date = NULL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 812 |  |  | 		$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, type_id, status,status_id,imo,arrival_port_name,arrival_port_date)  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 813 |  |  | 		    VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:type_id,:status,:status_id,:imo,:arrival_port_name,:arrival_port_date)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 814 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 815 |  |  | 		$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':speed' => $groundspeed,':date' => $date,':format_source' => $format_source, ':source_name' => $source_name,':mmsi' => $mmsi,':type' => $type,':type_id' => $type_id,':status' => $status,':status_id' => $status_id,':imo' => $imo,':arrival_port_name' => $arrival_code,':arrival_port_date' => $arrival_date); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 816 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 817 |  |  | 			$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 818 |  |  | 			$sth->execute($query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 819 |  |  | 			$this->db = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 820 |  |  | 		} catch (PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 821 |  |  | 		    return "error : ".$e->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 822 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 823 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 824 |  |  | 		return "success"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 825 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 826 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 827 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 828 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 829 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 830 |  |  | 	* Gets the aircraft ident within the last hour | 
            
                                                                                                            
                            
            
                                    
            
            
                | 831 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 832 |  |  | 	* @return String the ident | 
            
                                                                                                            
                            
            
                                    
            
            
                | 833 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 834 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 835 |  |  | 	public function getIdentFromLastHour($ident) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 836 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 837 |  |  | 		global $globalDBdriver, $globalTimezone; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 838 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 839 |  |  | 			$query  = "SELECT marine_output.ident FROM marine_output  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 840 |  |  | 								WHERE marine_output.ident = :ident  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 841 |  |  | 								AND marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR)  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 842 |  |  | 								AND marine_output.date < UTC_TIMESTAMP()"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 843 |  |  | 			$query_data = array(':ident' => $ident); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 844 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 845 |  |  | 			$query  = "SELECT marine_output.ident FROM marine_output  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 846 |  |  | 								WHERE marine_output.ident = :ident  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 847 |  |  | 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 848 |  |  | 								AND marine_output.date < now() AT TIME ZONE 'UTC'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 849 |  |  | 			$query_data = array(':ident' => $ident); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 850 |  |  |     		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 851 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 852 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 853 |  |  | 		$sth->execute($query_data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 854 |  |  |     		$ident_result=''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 855 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 856 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 857 |  |  | 			$ident_result = $row['ident']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 858 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 859 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 860 |  |  | 		return $ident_result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 861 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 862 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 863 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 864 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 865 |  |  | 	* Gets the aircraft data from the last 20 seconds | 
            
                                                                                                            
                            
            
                                    
            
            
                | 866 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 867 |  |  | 	* @return Array the spotter data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 868 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 869 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 870 |  |  | 	public function getRealTimeData($q = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 871 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 872 |  |  | 		global $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 873 |  |  | 		$additional_query = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 874 |  |  | 		if ($q != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 875 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 876 |  |  | 			if (!is_string($q)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 877 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 878 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 879 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 880 |  |  | 				$q_array = explode(" ", $q); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 881 |  |  | 				foreach ($q_array as $q_item){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 882 |  |  | 					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 883 |  |  | 					$additional_query .= " AND ("; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 884 |  |  | 					$additional_query .= "(marine_output.ident like '%".$q_item."%')"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 885 |  |  | 					$additional_query .= ")"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 886 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 887 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 888 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 889 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 890 |  |  | 			$query  = "SELECT marine_output.* FROM marine_output  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 891 |  |  | 				WHERE marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 20 SECOND) ".$additional_query."  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 892 |  |  | 				AND marine_output.date < UTC_TIMESTAMP()"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 893 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 894 |  |  | 			$query  = "SELECT marine_output.* FROM marine_output  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 895 |  |  | 				WHERE marine_output.date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '20 SECONDS' ".$additional_query."  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 896 |  |  | 				AND marine_output.date::timestamp < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 897 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 898 |  |  | 		$spotter_array = $this->getDataFromDB($query, array()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 899 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 900 |  |  | 		return $spotter_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 901 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 902 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 903 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 904 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 905 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 906 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 907 |  |  | 	* Gets all number of flight over countries | 
            
                                                                                                            
                            
            
                                    
            
            
                | 908 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 909 |  |  | 	* @return Array the airline country list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 910 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 911 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 912 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 913 |  |  | 	public function countAllMarineOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 914 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 915 |  |  | 		global $globalDBdriver, $globalArchive; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 916 |  |  | 		//$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 917 |  |  | 		$Connection= new Connection($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 918 |  |  | 		if (!$Connection->tableExists('countries')) return array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 919 |  |  | 		require_once('class.SpotterLive.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 920 |  |  | 		if (!isset($globalArchive) || $globalArchive !== TRUE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 921 |  |  | 			$MarineLive = new MarineLive($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 922 |  |  | 			$filter_query = $MarineLive->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 923 |  |  | 			$filter_query .= " over_country IS NOT NULL AND over_country <> ''"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 924 |  |  | 			if ($olderthanmonths > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 925 |  |  | 				if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 926 |  |  | 					$filter_query .= ' AND marine_live.date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 927 |  |  | 				} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 928 |  |  | 					$filter_query .= " AND marine_live.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 929 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 930 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 931 |  |  | 			if ($sincedate != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 932 |  |  | 				if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 933 |  |  | 					$filter_query .= " AND marine_live.date > '".$sincedate."' "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 934 |  |  | 				} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 935 |  |  | 					$filter_query .= " AND marine_live.date > CAST('".$sincedate."' AS TIMESTAMP)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 936 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 937 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 938 |  |  | 			$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb FROM countries c INNER JOIN (SELECT DISTINCT fammarine_id,over_country FROM marine_live".$filter_query.") l ON c.iso2 = l.over_country "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 939 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 940 |  |  | 			require_once(dirname(__FILE__)."/class.MarineArchive.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 941 |  |  | 			$MarineArchive = new MarineArchive($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 942 |  |  | 			$filter_query = $MarineArchive->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 943 |  |  | 			$filter_query .= " over_country <> ''"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 944 |  |  | 			if ($olderthanmonths > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 945 |  |  | 				if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 946 |  |  | 					$filter_query .= ' AND marine_archive.date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH) '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 947 |  |  | 				} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 948 |  |  | 					$filter_query .= " AND marine_archive.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 949 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 950 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 951 |  |  | 			if ($sincedate != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 952 |  |  | 				if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 953 |  |  | 					$filter_query .= " AND marine_archive.date > '".$sincedate."' "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 954 |  |  | 				} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 955 |  |  | 					$filter_query .= " AND marine_archive.date > CAST('".$sincedate."' AS TIMESTAMP)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 956 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 957 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 958 |  |  | 			$filter_query .= " LIMIT 100 OFFSET 0"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 959 |  |  | 			$query = "SELECT c.name, c.iso3, c.iso2, count(c.name) as nb FROM countries c INNER JOIN (SELECT DISTINCT fammarine_id,over_country FROM marine_archive".$filter_query.") l ON c.iso2 = l.over_country "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 960 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 961 |  |  | 		$query .= "GROUP BY c.name,c.iso3,c.iso2 ORDER BY nb DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 962 |  |  | 		if ($limit) $query .= " LIMIT 10 OFFSET 0"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 963 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 964 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 965 |  |  | 		$sth->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 966 |  |  |   | 
            
                                                                                                            
                            
            
                                    
            
            
                | 967 |  |  | 		$flight_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 968 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 969 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 970 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 971 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 972 |  |  | 			$temp_array['marine_count'] = $row['nb']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 973 |  |  | 			$temp_array['marine_country'] = $row['name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 974 |  |  | 			$temp_array['marine_country_iso3'] = $row['iso3']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 975 |  |  | 			$temp_array['marine_country_iso2'] = $row['iso2']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 976 |  |  | 			$flight_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 977 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 978 |  |  | 		return $flight_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 979 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 980 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 981 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 982 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 983 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 984 |  |  | 	* Gets all callsigns that have flown over | 
            
                                                                                                            
                            
            
                                    
            
            
                | 985 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 986 |  |  | 	* @return Array the callsign list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 987 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 988 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 989 |  |  | 	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 990 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 991 |  |  | 		global $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 992 |  |  | 		$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 993 |  |  | 		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 994 |  |  |                     FROM marine_output".$filter_query." marine_output.ident <> ''"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 995 |  |  | 		 if ($olderthanmonths > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 996 |  |  | 			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 997 |  |  | 			else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 998 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 999 |  |  | 		if ($sincedate != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1000 |  |  | 			if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1001 |  |  | 			else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1002 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1003 |  |  | 		$query_values = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1004 |  |  | 		if ($year != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1005 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1006 |  |  | 				$query .= " AND YEAR(marine_output.date) = :year"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1007 |  |  | 				$query_values = array_merge($query_values,array(':year' => $year)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1008 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1009 |  |  | 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1010 |  |  | 				$query_values = array_merge($query_values,array(':year' => $year)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1011 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1012 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1013 |  |  | 		if ($month != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1014 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1015 |  |  | 				$query .= " AND MONTH(marine_output.date) = :month"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1016 |  |  | 				$query_values = array_merge($query_values,array(':month' => $month)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1017 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1018 |  |  | 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1019 |  |  | 				$query_values = array_merge($query_values,array(':month' => $month)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1020 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1021 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1022 |  |  | 		if ($day != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1023 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1024 |  |  | 				$query .= " AND DAY(marine_output.date) = :day"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1025 |  |  | 				$query_values = array_merge($query_values,array(':day' => $day)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1026 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1027 |  |  | 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1028 |  |  | 				$query_values = array_merge($query_values,array(':day' => $day)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1029 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1030 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1031 |  |  | 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1032 |  |  | 		if ($limit) $query .= " LIMIT 10 OFFSET 0"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1033 |  |  |       		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1034 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1035 |  |  | 		$sth->execute($query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1036 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1037 |  |  | 		$callsign_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1038 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1039 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1040 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1041 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1042 |  |  | 			$temp_array['callsign_icao'] = $row['ident']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1043 |  |  | 			$temp_array['airline_name'] = $row['airline_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1044 |  |  | 			$temp_array['airline_icao'] = $row['airline_icao']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1045 |  |  | 			$temp_array['callsign_icao_count'] = $row['callsign_icao_count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1046 |  |  |            | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1047 |  |  | 			$callsign_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1048 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1049 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1050 |  |  | 		return $callsign_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1051 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1052 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1053 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1054 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1055 |  |  | 	* Counts all dates | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1056 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1057 |  |  | 	* @return Array the date list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1058 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1059 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1060 |  |  | 	public function countAllDates($filters = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1061 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1062 |  |  | 		global $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1063 |  |  | 		if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1064 |  |  | 			date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1065 |  |  | 			$datetime = new DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1066 |  |  | 			$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1067 |  |  | 		} else $offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1068 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1069 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1070 |  |  | 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1071 |  |  | 								FROM marine_output"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1072 |  |  | 			$query .= $this->getFilter($filters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1073 |  |  | 			$query .= " GROUP BY date_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1074 |  |  | 								ORDER BY date_count DESC | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1075 |  |  | 								LIMIT 10 OFFSET 0"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1076 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1077 |  |  | 			$query  = "SELECT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1078 |  |  | 								FROM marine_output"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1079 |  |  | 			$query .= $this->getFilter($filters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1080 |  |  | 			$query .= " GROUP BY date_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1081 |  |  | 								ORDER BY date_count DESC | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1082 |  |  | 								LIMIT 10 OFFSET 0"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1083 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1084 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1085 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1086 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1087 |  |  | 		$sth->execute(array(':offset' => $offset)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1088 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1089 |  |  | 		$date_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1090 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1091 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1092 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1093 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1094 |  |  | 			$temp_array['date_name'] = $row['date_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1095 |  |  | 			$temp_array['date_count'] = $row['date_count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1096 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1097 |  |  | 			$date_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1098 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1099 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1100 |  |  | 		return $date_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1101 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1102 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1103 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1104 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1105 |  |  | 	* Counts all dates during the last 7 days | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1106 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1107 |  |  | 	* @return Array the date list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1108 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1109 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1110 |  |  | 	public function countAllDatesLast7Days($filters = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1111 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1112 |  |  | 		global $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1113 |  |  | 		if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1114 |  |  | 			date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1115 |  |  | 			$datetime = new DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1116 |  |  | 			$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1117 |  |  | 		} else $offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1118 |  |  | 		$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1119 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1120 |  |  | 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1121 |  |  | 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1122 |  |  | 			$query .= " GROUP BY date_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1123 |  |  | 								ORDER BY marine_output.date ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1124 |  |  | 			$query_data = array(':offset' => $offset); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1125 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1126 |  |  | 			$query  = "SELECT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1127 |  |  | 								FROM marine_output".$filter_query." marine_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '7 DAYS'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1128 |  |  | 			$query .= " GROUP BY date_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1129 |  |  | 								ORDER BY date_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1130 |  |  | 			$query_data = array(':offset' => $offset); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1131 |  |  |     		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1132 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1133 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1134 |  |  | 		$sth->execute($query_data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1135 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1136 |  |  | 		$date_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1137 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1138 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1139 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1140 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1141 |  |  | 			$temp_array['date_name'] = $row['date_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1142 |  |  | 			$temp_array['date_count'] = $row['date_count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1143 |  |  |            | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1144 |  |  | 			$date_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1145 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1147 |  |  | 		return $date_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1148 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1150 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1151 |  |  | 	* Counts all dates during the last month | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1152 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1153 |  |  | 	* @return Array the date list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1154 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1155 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1156 |  |  | 	public function countAllDatesLastMonth($filters = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1157 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1158 |  |  | 		global $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1159 |  |  | 		if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1160 |  |  | 			date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1161 |  |  | 			$datetime = new DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1162 |  |  | 			$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1163 |  |  | 		} else $offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1164 |  |  | 		$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1165 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1166 |  |  | 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1167 |  |  | 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MONTH)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1168 |  |  | 			$query .= " GROUP BY date_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1169 |  |  | 								ORDER BY marine_output.date ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1170 |  |  | 			$query_data = array(':offset' => $offset); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1171 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1172 |  |  | 			$query  = "SELECT to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') AS date_name, count(*) as date_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1173 |  |  | 								FROM marine_output".$filter_query." marine_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '1 MONTHS'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1174 |  |  | 			$query .= " GROUP BY date_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1175 |  |  | 								ORDER BY date_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1176 |  |  | 			$query_data = array(':offset' => $offset); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1177 |  |  |     		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1178 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1179 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1180 |  |  | 		$sth->execute($query_data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1181 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1182 |  |  | 		$date_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1183 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1184 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1185 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1186 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1187 |  |  | 			$temp_array['date_name'] = $row['date_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1188 |  |  | 			$temp_array['date_count'] = $row['date_count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1189 |  |  |            | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1190 |  |  | 			$date_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1191 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1193 |  |  | 		return $date_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1194 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1196 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1197 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1198 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1199 |  |  | 	* Counts all month | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1200 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1201 |  |  | 	* @return Array the month list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1202 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1203 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1204 |  |  | 	public function countAllMonths($filters = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1205 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1206 |  |  | 		global $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1207 |  |  | 		if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1208 |  |  | 			date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1209 |  |  | 			$datetime = new DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1210 |  |  | 			$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1211 |  |  | 		} else $offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1212 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1213 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1214 |  |  | 			$query  = "SELECT YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1215 |  |  | 								FROM marine_output"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1216 |  |  | 			$query .= $this->getFilter($filters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1217 |  |  | 			$query .= " GROUP BY year_name, month_name ORDER BY date_count DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1218 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1219 |  |  | 			$query  = "SELECT EXTRACT(YEAR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS year_name,EXTRACT(MONTH FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS month_name, count(*) as date_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1220 |  |  | 								FROM marine_output"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1221 |  |  | 			$query .= $this->getFilter($filters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1222 |  |  | 			$query .= " GROUP BY year_name, month_name ORDER BY date_count DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1223 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1224 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1225 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1226 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1227 |  |  | 		$sth->execute(array(':offset' => $offset)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1228 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1229 |  |  | 		$date_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1230 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1231 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1232 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1233 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1234 |  |  | 			$temp_array['month_name'] = $row['month_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1235 |  |  | 			$temp_array['year_name'] = $row['year_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1236 |  |  | 			$temp_array['date_count'] = $row['date_count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1237 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1238 |  |  | 			$date_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1239 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1240 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1241 |  |  | 		return $date_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1242 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1243 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1244 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1245 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1246 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1247 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1248 |  |  | 	* Counts all dates during the last year | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1249 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1250 |  |  | 	* @return Array the date list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1251 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1252 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1253 |  |  | 	public function countAllMonthsLastYear($filters) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1254 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1255 |  |  | 		global $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1256 |  |  | 		if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1257 |  |  | 			date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1258 |  |  | 			$datetime = new DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1259 |  |  | 			$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1260 |  |  | 		} else $offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1261 |  |  | 		$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1262 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1263 |  |  | 			$query  = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1264 |  |  | 								FROM marine_output".$filter_query." marine_output.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 YEAR)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1265 |  |  | 			$query .= " GROUP BY year_name, month_name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1266 |  |  | 								ORDER BY year_name, month_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1267 |  |  | 			$query_data = array(':offset' => $offset); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1268 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1269 |  |  | 			$query  = "SELECT EXTRACT(MONTH FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS month_name, EXTRACT(YEAR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS year_name, count(*) as date_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1270 |  |  | 								FROM marine_output".$filter_query." marine_output.date >= CURRENT_TIMESTAMP AT TIME ZONE INTERVAL :offset - INTERVAL '1 YEARS'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1271 |  |  | 			$query .= " GROUP BY year_name, month_name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1272 |  |  | 								ORDER BY year_name, month_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1273 |  |  | 			$query_data = array(':offset' => $offset); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1274 |  |  |     		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1275 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1276 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1277 |  |  | 		$sth->execute($query_data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1278 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1279 |  |  | 		$date_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1280 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1281 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1282 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1283 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1284 |  |  | 			$temp_array['year_name'] = $row['year_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1285 |  |  | 			$temp_array['month_name'] = $row['month_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1286 |  |  | 			$temp_array['date_count'] = $row['date_count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1287 |  |  |            | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1288 |  |  | 			$date_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1289 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1290 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1291 |  |  | 		return $date_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1292 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1293 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1294 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1295 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1296 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1297 |  |  | 	* Counts all hours | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1298 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1299 |  |  | 	* @return Array the hour list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1300 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1301 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1302 |  |  | 	public function countAllHours($orderby,$filters = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1303 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1304 |  |  | 		global $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1305 |  |  | 		if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1306 |  |  | 			date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1307 |  |  | 			$datetime = new DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1308 |  |  | 			$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1309 |  |  | 		} else $offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1310 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1311 |  |  | 		$orderby_sql = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1312 |  |  | 		if ($orderby == "hour") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1313 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1314 |  |  | 			$orderby_sql = "ORDER BY hour_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1315 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1316 |  |  | 		if ($orderby == "count") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1317 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1318 |  |  | 			$orderby_sql = "ORDER BY hour_count DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1319 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1320 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1321 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1322 |  |  | 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1323 |  |  | 								FROM marine_output"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1324 |  |  | 			$query .= $this->getFilter($filters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1325 |  |  | 			$query .= " GROUP BY hour_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1326 |  |  | 								".$orderby_sql; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1327 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1328 |  |  | /*		$query  = "SELECT HOUR(marine_output.date) AS hour_name, count(*) as hour_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1329 |  |  | 								FROM marine_output  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1330 |  |  | 								GROUP BY hour_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1331 |  |  | 								".$orderby_sql." | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1332 |  |  | 								LIMIT 10 OFFSET 00"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1333 |  |  |   */     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1334 |  |  | 		$query_data = array(':offset' => $offset); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1335 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1336 |  |  | 			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1337 |  |  | 								FROM marine_output"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1338 |  |  | 			$query .= $this->getFilter($filters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1339 |  |  | 			$query .= " GROUP BY hour_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1340 |  |  | 								".$orderby_sql; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1341 |  |  | 			$query_data = array(':offset' => $offset); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1342 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1343 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1344 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1345 |  |  | 		$sth->execute($query_data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1346 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1347 |  |  | 		$hour_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1348 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1349 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1350 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1351 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1352 |  |  | 			$temp_array['hour_name'] = $row['hour_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1353 |  |  | 			$temp_array['hour_count'] = $row['hour_count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1354 |  |  |            | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1355 |  |  | 			$hour_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1356 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1357 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1358 |  |  | 		return $hour_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1359 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1360 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1361 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1362 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1363 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1364 |  |  | 	* Counts all hours by date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1365 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1366 |  |  | 	* @return Array the hour list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1367 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1368 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1369 |  |  | 	public function countAllHoursByDate($date, $filters = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1370 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1371 |  |  | 		global $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1372 |  |  | 		$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1373 |  |  | 		$date = filter_var($date,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1374 |  |  | 		if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1375 |  |  | 			date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1376 |  |  | 			$datetime = new DateTime($date); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1377 |  |  | 			$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1378 |  |  | 		} else $offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1379 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1380 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1381 |  |  | 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1382 |  |  | 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = :date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1383 |  |  | 								GROUP BY hour_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1384 |  |  | 								ORDER BY hour_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1385 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1386 |  |  | 			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1387 |  |  | 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset, 'YYYY-mm-dd') = :date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1388 |  |  | 								GROUP BY hour_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1389 |  |  | 								ORDER BY hour_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1390 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1391 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1392 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1393 |  |  | 		$sth->execute(array(':date' => $date, ':offset' => $offset)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1394 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1395 |  |  | 		$hour_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1396 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1397 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1398 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1399 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1400 |  |  | 			$temp_array['hour_name'] = $row['hour_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1401 |  |  | 			$temp_array['hour_count'] = $row['hour_count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1402 |  |  |            | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1403 |  |  | 			$hour_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1404 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1405 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1406 |  |  | 		return $hour_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1407 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1408 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1409 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1410 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1411 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1412 |  |  | 	* Counts all hours by a ident/callsign | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1413 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1414 |  |  | 	* @return Array the hour list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1415 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1416 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1417 |  |  | 	public function countAllHoursByIdent($ident, $filters = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1418 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1419 |  |  | 		global $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1420 |  |  | 		$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1421 |  |  | 		$ident = filter_var($ident,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1422 |  |  | 		if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1423 |  |  | 			date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1424 |  |  | 			$datetime = new DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1425 |  |  | 			$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1426 |  |  | 		} else $offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1427 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1428 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1429 |  |  | 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1430 |  |  | 								FROM marine_output".$filter_query." marine_output.ident = :ident  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1431 |  |  | 								GROUP BY hour_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1432 |  |  | 								ORDER BY hour_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1433 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1434 |  |  | 			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1435 |  |  | 								FROM marine_output".$filter_query." marine_output.ident = :ident  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1436 |  |  | 								GROUP BY hour_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1437 |  |  | 								ORDER BY hour_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1438 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1439 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1440 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1441 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1442 |  |  | 		$sth->execute(array(':ident' => $ident,':offset' => $offset)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1443 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1444 |  |  | 		$hour_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1445 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1446 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1447 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1448 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1449 |  |  | 			$temp_array['hour_name'] = $row['hour_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1450 |  |  | 			$temp_array['hour_count'] = $row['hour_count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1451 |  |  |            | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1452 |  |  | 			$hour_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1453 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1454 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1455 |  |  | 		return $hour_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1456 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1457 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1458 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1459 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1460 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1461 |  |  | 	* Counts all vessels | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1462 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1463 |  |  | 	* @return Integer the number of vessels | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1464 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1465 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1466 |  |  | 	public function countOverallMarine($filters = array(),$year = '',$month = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1467 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1468 |  |  | 		global $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1469 |  |  | 		//$queryi  = "SELECT COUNT(marine_output.marine_id) AS flight_count FROM marine_output"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1470 |  |  | 		$queryi  = "SELECT COUNT(DISTINCT marine_output.mmsi) AS flight_count FROM marine_output"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1471 |  |  | 		$query_values = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1472 |  |  | 		$query = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1473 |  |  | 		if ($year != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1474 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1475 |  |  | 				$query .= " AND YEAR(marine_output.date) = :year"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1476 |  |  | 				$query_values = array_merge($query_values,array(':year' => $year)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1477 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1478 |  |  | 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1479 |  |  | 				$query_values = array_merge($query_values,array(':year' => $year)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1480 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1481 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1482 |  |  | 		if ($month != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1483 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1484 |  |  | 				$query .= " AND MONTH(marine_output.date) = :month"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1485 |  |  | 				$query_values = array_merge($query_values,array(':month' => $month)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1486 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1487 |  |  | 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1488 |  |  | 				$query_values = array_merge($query_values,array(':month' => $month)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1489 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1490 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1491 |  |  | 		if (empty($query_values)) $queryi .= $this->getFilter($filters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1492 |  |  | 		else $queryi .= $this->getFilter($filters,true,true).substr($query,4); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1493 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1494 |  |  | 		$sth = $this->db->prepare($queryi); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1495 |  |  | 		$sth->execute($query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1496 |  |  | 		return $sth->fetchColumn(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1497 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1498 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1499 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1500 |  |  | 	* Counts all vessel type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1501 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1502 |  |  | 	* @return Integer the number of vessels | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1503 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1504 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1505 |  |  | 	public function countOverallMarineTypes($filters = array(),$year = '',$month = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1506 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1507 |  |  | 		global $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1508 |  |  | 		$queryi  = "SELECT COUNT(DISTINCT marine_output.type) AS marine_count FROM marine_output"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1509 |  |  | 		$query_values = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1510 |  |  | 		$query = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1511 |  |  | 		if ($year != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1512 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1513 |  |  | 				$query .= " AND YEAR(marine_output.date) = :year"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1514 |  |  | 				$query_values = array_merge($query_values,array(':year' => $year)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1515 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1516 |  |  | 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1517 |  |  | 				$query_values = array_merge($query_values,array(':year' => $year)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1518 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1519 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1520 |  |  | 		if ($month != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1521 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1522 |  |  | 				$query .= " AND MONTH(marine_output.date) = :month"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1523 |  |  | 				$query_values = array_merge($query_values,array(':month' => $month)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1524 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1525 |  |  | 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1526 |  |  | 				$query_values = array_merge($query_values,array(':month' => $month)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1527 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1528 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1529 |  |  | 		if (empty($query_values)) $queryi .= $this->getFilter($filters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1530 |  |  | 		else $queryi .= $this->getFilter($filters,true,true).substr($query,4); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1531 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1532 |  |  | 		$sth = $this->db->prepare($queryi); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1533 |  |  | 		$sth->execute($query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1534 |  |  | 		return $sth->fetchColumn(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1535 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1536 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1537 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1538 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1539 |  |  | 	* Counts all hours of today | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1540 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1541 |  |  | 	* @return Array the hour list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1542 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1543 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1544 |  |  | 	public function countAllHoursFromToday($filters = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1545 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1546 |  |  | 		global $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1547 |  |  | 		$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1548 |  |  | 		if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1549 |  |  | 			date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1550 |  |  | 			$datetime = new DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1551 |  |  | 			$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1552 |  |  | 		} else $offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1553 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1554 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1555 |  |  | 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1556 |  |  | 								FROM marine_output".$filter_query." DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) = CURDATE() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1557 |  |  | 								GROUP BY hour_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1558 |  |  | 								ORDER BY hour_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1559 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1560 |  |  | 			$query  = "SELECT EXTRACT(HOUR FROM marine_output.date AT TIME ZONE INTERVAL :offset) AS hour_name, count(*) as hour_count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1561 |  |  | 								FROM marine_output".$filter_query." to_char(marine_output.date AT TIME ZONE INTERVAL :offset,'YYYY-mm-dd') = CAST(NOW() AS date) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1562 |  |  | 								GROUP BY hour_name  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1563 |  |  | 								ORDER BY hour_name ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1564 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1565 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1566 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1567 |  |  | 		$sth->execute(array(':offset' => $offset)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1568 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1569 |  |  | 		$hour_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1570 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1571 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1572 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1573 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1574 |  |  | 			$temp_array['hour_name'] = $row['hour_name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1575 |  |  | 			$temp_array['hour_count'] = $row['hour_count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1576 |  |  | 			$hour_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1577 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1578 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1579 |  |  | 		return $hour_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1580 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1581 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1582 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1583 |  |  |      /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1584 |  |  | 	* Gets the Barrie Spotter ID based on the FlightAware ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1585 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1586 |  |  | 	* @return Integer the Barrie Spotter ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1587 |  |  | q	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1588 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1589 |  |  | 	public function getMarineIDBasedOnFamMarineID($fammarine_id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1590 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1591 |  |  | 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1592 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1593 |  |  | 		$query  = "SELECT marine_output.marine_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1594 |  |  | 				FROM marine_output  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1595 |  |  | 				WHERE marine_output.fammarine_id = '".$fammarine_id."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1596 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1597 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1598 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1599 |  |  | 		$sth->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1600 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1601 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1602 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1603 |  |  | 			return $row['marine_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1604 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1605 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1606 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1607 |  |  |   | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1608 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1609 |  |  | 	* Parses a date string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1610 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1611 |  |  | 	* @param String $dateString the date string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1612 |  |  | 	* @param String $timezone the timezone of a user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1613 |  |  | 	* @return Array the time information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1614 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1615 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1616 |  |  | 	public function parseDateString($dateString, $timezone = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1617 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1618 |  |  | 		$time_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1619 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1620 |  |  | 		if ($timezone != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1621 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1622 |  |  | 			date_default_timezone_set($timezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1623 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1624 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1625 |  |  | 		$current_date = date("Y-m-d H:i:s"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1626 |  |  | 		$date = date("Y-m-d H:i:s",strtotime($dateString." UTC")); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1627 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1628 |  |  | 		$diff = abs(strtotime($current_date) - strtotime($date)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1629 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1630 |  |  | 		$time_array['years'] = floor($diff / (365*60*60*24));  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1631 |  |  | 		$years = $time_array['years']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1632 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1633 |  |  | 		$time_array['months'] = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1634 |  |  | 		$months = $time_array['months']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1635 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1636 |  |  | 		$time_array['days'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1637 |  |  | 		$days = $time_array['days']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1638 |  |  | 		$time_array['hours'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1639 |  |  | 		$hours = $time_array['hours']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1640 |  |  | 		$time_array['minutes'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1641 |  |  | 		$minutes = $time_array['minutes']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1642 |  |  | 		$time_array['seconds'] = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));   | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1643 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1644 |  |  | 		return $time_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1645 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1646 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1647 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1648 |  |  | 	* Parses the direction degrees to working | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1649 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1650 |  |  | 	* @param Float $direction the direction in degrees | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1651 |  |  | 	* @return Array the direction information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1652 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1653 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1654 |  |  | 	public function parseDirection($direction = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1655 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1656 |  |  | 		if ($direction == '') $direction = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1657 |  |  | 		$direction_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1658 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1659 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1660 |  |  | 		if ($direction == 360 || ($direction >= 0 && $direction < 22.5)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1661 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1662 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1663 |  |  | 			$temp_array['direction_shortname'] = "N"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1664 |  |  | 			$temp_array['direction_fullname'] = "North"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1665 |  |  | 		} elseif ($direction >= 22.5 && $direction < 45){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1666 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1667 |  |  | 			$temp_array['direction_shortname'] = "NNE"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1668 |  |  | 			$temp_array['direction_fullname'] = "North-Northeast"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1669 |  |  | 		} elseif ($direction >= 45 && $direction < 67.5){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1670 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1671 |  |  | 			$temp_array['direction_shortname'] = "NE"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1672 |  |  | 			$temp_array['direction_fullname'] = "Northeast"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1673 |  |  | 		} elseif ($direction >= 67.5 && $direction < 90){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1674 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1675 |  |  | 			$temp_array['direction_shortname'] = "ENE"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1676 |  |  | 			$temp_array['direction_fullname'] = "East-Northeast"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1677 |  |  | 		} elseif ($direction >= 90 && $direction < 112.5){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1678 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1679 |  |  | 			$temp_array['direction_shortname'] = "E"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1680 |  |  | 			$temp_array['direction_fullname'] = "East"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1681 |  |  | 		} elseif ($direction >= 112.5 && $direction < 135){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1682 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1683 |  |  | 			$temp_array['direction_shortname'] = "ESE"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1684 |  |  | 			$temp_array['direction_fullname'] = "East-Southeast"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1685 |  |  | 		} elseif ($direction >= 135 && $direction < 157.5){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1686 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1687 |  |  | 			$temp_array['direction_shortname'] = "SE"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1688 |  |  | 			$temp_array['direction_fullname'] = "Southeast"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1689 |  |  | 		} elseif ($direction >= 157.5 && $direction < 180){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1690 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1691 |  |  | 			$temp_array['direction_shortname'] = "SSE"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1692 |  |  | 			$temp_array['direction_fullname'] = "South-Southeast"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1693 |  |  | 		} elseif ($direction >= 180 && $direction < 202.5){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1694 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1695 |  |  | 			$temp_array['direction_shortname'] = "S"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1696 |  |  | 			$temp_array['direction_fullname'] = "South"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1697 |  |  | 		} elseif ($direction >= 202.5 && $direction < 225){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1698 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1699 |  |  | 			$temp_array['direction_shortname'] = "SSW"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1700 |  |  | 			$temp_array['direction_fullname'] = "South-Southwest"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1701 |  |  | 		} elseif ($direction >= 225 && $direction < 247.5){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1702 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1703 |  |  | 			$temp_array['direction_shortname'] = "SW"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1704 |  |  | 			$temp_array['direction_fullname'] = "Southwest"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1705 |  |  | 		} elseif ($direction >= 247.5 && $direction < 270){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1706 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1707 |  |  | 			$temp_array['direction_shortname'] = "WSW"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1708 |  |  | 			$temp_array['direction_fullname'] = "West-Southwest"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1709 |  |  | 		} elseif ($direction >= 270 && $direction < 292.5){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1710 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1711 |  |  | 			$temp_array['direction_shortname'] = "W"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1712 |  |  | 			$temp_array['direction_fullname'] = "West"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1713 |  |  | 		} elseif ($direction >= 292.5 && $direction < 315){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1714 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1715 |  |  | 			$temp_array['direction_shortname'] = "WNW"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1716 |  |  | 			$temp_array['direction_fullname'] = "West-Northwest"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1717 |  |  | 		} elseif ($direction >= 315 && $direction < 337.5){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1718 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1719 |  |  | 			$temp_array['direction_shortname'] = "NW"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1720 |  |  | 			$temp_array['direction_fullname'] = "Northwest"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1721 |  |  | 		} elseif ($direction >= 337.5 && $direction < 360){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1722 |  |  | 			$temp_array['direction_degree'] = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1723 |  |  | 			$temp_array['direction_shortname'] = "NNW"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1724 |  |  | 			$temp_array['direction_fullname'] = "North-Northwest"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1725 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1726 |  |  | 		$direction_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1727 |  |  | 		return $direction_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1728 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1729 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1730 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1731 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1732 |  |  | 	* Gets Country from latitude/longitude | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1733 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1734 |  |  | 	* @param Float $latitude latitute of the flight | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1735 |  |  | 	* @param Float $longitude longitute of the flight | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1736 |  |  | 	* @return String the countrie | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1737 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1738 |  |  | 	public function getCountryFromLatitudeLongitude($latitude,$longitude) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1739 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1740 |  |  | 		global $globalDBdriver, $globalDebug; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1741 |  |  | 		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1742 |  |  | 		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1743 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1744 |  |  | 		$Connection = new Connection($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1745 |  |  | 		if (!$Connection->tableExists('countries')) return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1746 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1747 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1748 |  |  | 			/* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1749 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1750 |  |  | 				//$query  = "SELECT name, iso2, iso3 FROM countries WHERE Within(GeomFromText('POINT(:latitude :longitude)'), ogc_geom) LIMIT 1"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1751 |  |  | 				$query = "SELECT name, iso2, iso3 FROM countries WHERE Within(GeomFromText('POINT(".$longitude.' '.$latitude.")'), ogc_geom) LIMIT 1"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1752 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1753 |  |  | 			*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1754 |  |  | 			// This query seems to work both for MariaDB and PostgreSQL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1755 |  |  | 			$query = "SELECT name,iso2,iso3 FROM countries WHERE ST_Within(ST_GeomFromText('POINT(".$longitude." ".$latitude.")',4326), ogc_geom) LIMIT 1"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1756 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1757 |  |  | 			$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1758 |  |  | 			//$sth->execute(array(':latitude' => $latitude,':longitude' => $longitude)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1759 |  |  | 			$sth->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1760 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1761 |  |  | 			$row = $sth->fetch(PDO::FETCH_ASSOC); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1762 |  |  | 			$sth->closeCursor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1763 |  |  | 			if (count($row) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1764 |  |  | 				return $row; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1765 |  |  | 			} else return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1766 |  |  | 		} catch (PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1767 |  |  | 			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1768 |  |  | 			return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1769 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1770 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1771 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1772 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1773 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1774 |  |  | 	* Gets Country from iso2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1775 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1776 |  |  | 	* @param String $iso2 ISO2 country code | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1777 |  |  | 	* @return String the countrie | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1778 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1779 |  |  | 	public function getCountryFromISO2($iso2) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1780 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1781 |  |  | 		global $globalDBdriver, $globalDebug; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1782 |  |  | 		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1783 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1784 |  |  | 		$Connection = new Connection($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1785 |  |  | 		if (!$Connection->tableExists('countries')) return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1786 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1787 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1788 |  |  | 			$query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1789 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1790 |  |  | 			$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1791 |  |  | 			$sth->execute(array(':iso2' => $iso2)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1792 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1793 |  |  | 			$row = $sth->fetch(PDO::FETCH_ASSOC); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1794 |  |  | 			$sth->closeCursor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1795 |  |  | 			if (count($row) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1796 |  |  | 				return $row; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1797 |  |  | 			} else return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1798 |  |  | 		} catch (PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1799 |  |  | 			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1800 |  |  | 			return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1801 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1802 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1803 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1804 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1805 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1806 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1807 |  |  | 	* Gets the short url from bit.ly | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1808 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1809 |  |  | 	* @param String $url the full url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1810 |  |  | 	* @return String the bit.ly url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1811 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1812 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1813 |  |  | 	public function getBitlyURL($url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1814 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1815 |  |  | 		global $globalBitlyAccessToken; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1816 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1817 |  |  | 		if ($globalBitlyAccessToken == '') return $url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1818 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1819 |  |  | 		$google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1820 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1821 |  |  | 		$ch = curl_init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1822 |  |  | 		curl_setopt($ch, CURLOPT_HEADER, 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1823 |  |  | 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1824 |  |  | 		curl_setopt($ch, CURLOPT_URL, $google_url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1825 |  |  | 		$bitly_data = curl_exec($ch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1826 |  |  | 		curl_close($ch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1827 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1828 |  |  | 		$bitly_data = json_decode($bitly_data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1829 |  |  | 		$bitly_url = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1830 |  |  | 		if ($bitly_data->status_txt = "OK"){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1831 |  |  | 			$bitly_url = $bitly_data->data->url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1832 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1833 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1834 |  |  | 		return $bitly_url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1835 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1836 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1837 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1838 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1839 |  |  | 	* Gets all vessels types that have flown over | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1840 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1841 |  |  | 	* @return Array the vessel type list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1842 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1843 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1844 |  |  | 	public function countAllMarineTypes($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array(),$year = '',$month = '',$day = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1845 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1846 |  |  | 		global $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1847 |  |  | 		$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1848 |  |  | 		$query  = "SELECT marine_output.type AS marine_type, COUNT(marine_output.type) AS marine_type_count, marine_output.type_id AS marine_type_id  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1849 |  |  | 		    FROM marine_output ".$filter_query." marine_output.type <> '' AND marine_output.type_id IS NOT NULL"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1850 |  |  | 		if ($olderthanmonths > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1851 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1852 |  |  | 				$query .= ' AND marine_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$olderthanmonths.' MONTH)'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1853 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1854 |  |  | 				$query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1855 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1856 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1857 |  |  | 		if ($sincedate != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1858 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1859 |  |  | 				$query .= " AND marine_output.date > '".$sincedate."'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1860 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1861 |  |  | 				$query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1862 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1863 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1864 |  |  | 		$query_values = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1865 |  |  | 		if ($year != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1866 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1867 |  |  | 				$query .= " AND YEAR(marine_output.date) = :year"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1868 |  |  | 				$query_values = array_merge($query_values,array(':year' => $year)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1869 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1870 |  |  | 				$query .= " AND EXTRACT(YEAR FROM marine_output.date) = :year"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1871 |  |  | 				$query_values = array_merge($query_values,array(':year' => $year)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1872 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1873 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1874 |  |  | 		if ($month != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1875 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1876 |  |  | 				$query .= " AND MONTH(marine_output.date) = :month"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1877 |  |  | 				$query_values = array_merge($query_values,array(':month' => $month)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1878 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1879 |  |  | 				$query .= " AND EXTRACT(MONTH FROM marine_output.date) = :month"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1880 |  |  | 				$query_values = array_merge($query_values,array(':month' => $month)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1881 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1882 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1883 |  |  | 		if ($day != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1884 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1885 |  |  | 				$query .= " AND DAY(marine_output.date) = :day"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1886 |  |  | 				$query_values = array_merge($query_values,array(':day' => $day)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1887 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1888 |  |  | 				$query .= " AND EXTRACT(DAY FROM marine_output.date) = :day"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1889 |  |  | 				$query_values = array_merge($query_values,array(':day' => $day)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1890 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1891 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1892 |  |  | 		$query .= " GROUP BY marine_output.type, marine_output.type_id ORDER BY marine_type_count DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1893 |  |  | 		if ($limit) $query .= " LIMIT 10 OFFSET 0"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1894 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1895 |  |  | 		$sth->execute($query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1896 |  |  | 		$marine_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1897 |  |  | 		$temp_array = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1898 |  |  | 		while($row = $sth->fetch(PDO::FETCH_ASSOC)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1899 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1900 |  |  | 			$temp_array['marine_type'] = $row['marine_type']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1901 |  |  | 			$temp_array['marine_type_id'] = $row['marine_type_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1902 |  |  | 			$temp_array['marine_type_count'] = $row['marine_type_count']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1903 |  |  | 			$marine_array[] = $temp_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1904 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1905 |  |  | 		return $marine_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1906 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1907 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1908 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1909 |  |  | 	* Gets all the tracker information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1910 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1911 |  |  | 	* @return Array the tracker information | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1912 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1913 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1914 |  |  | 	public function searchMarineData($q = '', $callsign = '',$mmsi = '', $imo = '', $date_posted = '', $limit = '', $sort = '', $includegeodata = '',$origLat = '',$origLon = '',$dist = '',$filters = array()) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1915 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1916 |  |  | 		global $globalTimezone, $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1917 |  |  | 		date_default_timezone_set('UTC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1918 |  |  | 		$query_values = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1919 |  |  | 		$additional_query = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1920 |  |  | 		$filter_query = $this->getFilter($filters,true,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1921 |  |  | 		if ($q != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1922 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1923 |  |  | 			if (!is_string($q)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1924 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1925 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1926 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1927 |  |  | 				$q_array = explode(" ", $q); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1928 |  |  | 				foreach ($q_array as $q_item){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1929 |  |  | 					$q_item = filter_var($q_item,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1930 |  |  | 					$additional_query .= " AND ("; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1931 |  |  | 					if (is_int($q_item)) $additional_query .= "(marine_output.marine_id = '".$q_item."') OR "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1932 |  |  | 					if (is_int($q_item)) $additional_query .= "(marine_output.mmsi = '".$q_item."') OR "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1933 |  |  | 					if (is_int($q_item)) $additional_query .= "(marine_output.imo = '".$q_item."') OR "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1934 |  |  | 					$additional_query .= "(marine_output.ident like '%".$q_item."%') OR "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1935 |  |  | 					$additional_query .= ")"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1936 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1937 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1938 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1939 |  |  | 		if ($callsign != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1940 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1941 |  |  | 			$callsign = filter_var($callsign,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1942 |  |  | 			if (!is_string($callsign)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1943 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1944 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1945 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1946 |  |  | 				$additional_query .= " AND marine_output.ident = :callsign"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1947 |  |  | 				$query_values = array_merge($query_values,array(':callsign' => $callsign)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1948 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1949 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1950 |  |  | 		if ($mmsi != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1951 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1952 |  |  | 			$mmsi = filter_var($mmsi,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1953 |  |  | 			if (!is_numeric($mmsi)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1954 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1955 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1956 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1957 |  |  | 				$additional_query .= " AND marine_output.mmsi = :mmsi"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1958 |  |  | 				$query_values = array_merge($query_values,array(':mmsi' => $mmsi)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1959 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1960 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1961 |  |  | 		if ($imo != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1962 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1963 |  |  | 			$imo = filter_var($imo,FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1964 |  |  | 			if (!is_numeric($imo)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1965 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1966 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1967 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1968 |  |  | 				$additional_query .= " AND marine_output.imo = :imo"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1969 |  |  | 				$query_values = array_merge($query_values,array(':imo' => $imo)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1970 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1971 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1972 |  |  | 		if ($date_posted != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1973 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1974 |  |  | 			$date_array = explode(",", $date_posted); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1975 |  |  | 			$date_array[0] = filter_var($date_array[0],FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1976 |  |  | 			$date_array[1] = filter_var($date_array[1],FILTER_SANITIZE_STRING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1977 |  |  | 			if ($globalTimezone != '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1978 |  |  | 				date_default_timezone_set($globalTimezone); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1979 |  |  | 				$datetime = new DateTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1980 |  |  | 				$offset = $datetime->format('P'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1981 |  |  | 			} else $offset = '+00:00'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1982 |  |  | 			if ($date_array[1] != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1983 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1984 |  |  | 				$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1985 |  |  | 				$date_array[1] = date("Y-m-d H:i:s", strtotime($date_array[1])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1986 |  |  | 				if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1987 |  |  | 					$additional_query .= " AND TIMESTAMP(CONVERT_TZ(marine_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' AND TIMESTAMP(CONVERT_TZ(marine_output.date,'+00:00', '".$offset."')) <= '".$date_array[1]."' "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1988 |  |  | 				} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1989 |  |  | 					$additional_query .= " AND CAST(marine_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) >= '".$date_array[0]."' AND CAST(marine_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) <= '".$date_array[1]."' "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1990 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1991 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1992 |  |  | 				$date_array[0] = date("Y-m-d H:i:s", strtotime($date_array[0])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1993 |  |  | 				if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1994 |  |  | 					$additional_query .= " AND TIMESTAMP(CONVERT_TZ(marine_output.date,'+00:00', '".$offset."')) >= '".$date_array[0]."' "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1995 |  |  | 				} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1996 |  |  | 					$additional_query .= " AND CAST(marine_output.date AT TIME ZONE INTERVAL ".$offset." AS TIMESTAMP) >= '".$date_array[0]."' "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1997 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1998 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 1999 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2000 |  |  | 		if ($limit != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2001 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2002 |  |  | 			$limit_array = explode(",", $limit); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2003 |  |  | 			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2004 |  |  | 			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2005 |  |  | 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2006 |  |  | 			{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2007 |  |  | 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2008 |  |  | 			} else $limit_query = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2009 |  |  | 		} else $limit_query = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2010 |  |  | 		if ($sort != "") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2011 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2012 |  |  | 			$search_orderby_array = $this->getOrderBy(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2013 |  |  | 			$orderby_query = $search_orderby_array[$sort]['sql']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2014 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2015 |  |  | 			if ($origLat != "" && $origLon != "" && $dist != "") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2016 |  |  | 				$orderby_query = " ORDER BY distance ASC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2017 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2018 |  |  | 				$orderby_query = " ORDER BY marine_output.date DESC"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2019 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2020 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2021 |  |  | 		if ($origLat != "" && $origLon != "" && $dist != "") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2022 |  |  | 			$dist = number_format($dist*0.621371,2,'.',''); // convert km to mile | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2023 |  |  | 			if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2024 |  |  | 				$query="SELECT marine_output.*, 1.60935*3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - marine_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(marine_archive.latitude*pi()/180)*POWER(SIN(($origLon-marine_archive.longitude)*pi()/180/2),2))) as distance  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2025 |  |  | 				    FROM marine_archive,marine_output".$filter_query." marine_output.fammarine_id = marine_archive.fammarine_id AND marine_output.ident <> '' ".$additional_query."AND marine_archive.longitude between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat)*69)) and marine_archive.latitude between ($origLat-($dist/69)) and ($origLat+($dist/69))  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2026 |  |  | 				    AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - marine_archive.latitude)*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(marine_archive.latitude*pi()/180)*POWER(SIN(($origLon-marine_archive.longitude)*pi()/180/2),2)))) < $dist".$orderby_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2027 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2028 |  |  | 				$query="SELECT marine_output.*, 1.60935 * 3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(marine_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(marine_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(marine_archive.longitude as double precision))*pi()/180/2),2))) as distance  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2029 |  |  | 				    FROM marine_archive,marine_output".$filter_query." marine_output.fammarine_id = marine_archive.fammarine_id AND marine_output.ident <> '' ".$additional_query."AND CAST(marine_archive.longitude as double precision) between ($origLon-$dist/cos(radians($origLat))*69) and ($origLon+$dist/cos(radians($origLat))*69) and CAST(marine_archive.latitude as double precision) between ($origLat-($dist/69)) and ($origLat+($dist/69))  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2030 |  |  | 				    AND (3956 * 2 * ASIN(SQRT( POWER(SIN(($origLat - CAST(marine_archive.latitude as double precision))*pi()/180/2),2)+COS( $origLat *pi()/180)*COS(CAST(marine_archive.latitude as double precision)*pi()/180)*POWER(SIN(($origLon-CAST(marine_archive.longitude as double precision))*pi()/180/2),2)))) < $dist".$filter_query.$orderby_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2031 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2032 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2033 |  |  | 			$query  = "SELECT marine_output.* FROM marine_output".$filter_query." marine_output.ident <> ''  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2034 |  |  | 			    ".$additional_query." | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2035 |  |  | 			    ".$orderby_query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2036 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2037 |  |  | 		$marine_array = $this->getDataFromDB($query, $query_values,$limit_query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2038 |  |  | 		return $marine_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2039 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2040 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2041 |  |  | 	public function getOrderBy() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2042 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2043 |  |  | 		$orderby = array("type_asc" => array("key" => "type_asc", "value" => "Type - ASC", "sql" => "ORDER BY marine_output.type ASC"), "type_desc" => array("key" => "type_desc", "value" => "Type - DESC", "sql" => "ORDER BY marine_output.type DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY marine_output.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY marine_output.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY marine_output.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY marine_output.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY marine_output.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY marine_output.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY marine_output.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY marine_output.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY marine_output.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY marine_output.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY marine_output.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY marine_output.date DESC"),"distance_asc" => array("key" => "distance_asc","value" => "Distance - ASC","sql" => "ORDER BY distance ASC"),"distance_desc" => array("key" => "distance_desc","value" => "Distance - DESC","sql" => "ORDER BY distance DESC")); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2044 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2045 |  |  | 		return $orderby; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2046 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2047 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2048 |  |  |      | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 2049 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 2050 |  |  | ?> | 
            
                        
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.