Completed
Push — master ( 7ff9c7...665628 )
by Yannick
06:59
created
scripts/update_db.php 1 patch
Braces   +22 added lines, -8 removed lines patch added patch discarded remove patch
@@ -9,7 +9,9 @@  discard block
 block discarded – undo
9 9
 if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
10 10
 	exec("ps ux", $output, $result);
11 11
 	$j = 0;
12
-	foreach ($output as $line) if(strpos($line, "update_db.php") && !strpos($line, "sh ")) $j++;
12
+	foreach ($output as $line) {
13
+		if(strpos($line, "update_db.php") && !strpos($line, "sh ")) $j++;
14
+	}
13 15
 	if ($j > 1) {
14 16
 		echo "Script is already runnning...";
15 17
 		die();
@@ -29,14 +31,18 @@  discard block
 block discarded – undo
29 31
 			$update_db->update_notam();
30 32
 		}
31 33
 		$update_db->insert_last_notam_update();
32
-	} elseif (isset($globalDebug) && $globalDebug && isset($globalNOTAM) && $globalNOTAM) echo "NOTAM are only updated once a day.\n";
34
+	} elseif (isset($globalDebug) && $globalDebug && isset($globalNOTAM) && $globalNOTAM) {
35
+		echo "NOTAM are only updated once a day.\n";
36
+	}
33 37
 	if ($update_db->check_last_update() && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) {
34 38
 		$update_db->update_all();
35 39
 	//	require_once(dirname(__FILE__).'/../require/class.Spotter.php');
36 40
 	//	$Spotter = new Spotter();
37 41
 	//	$Spotter->updateFieldsFromOtherTables();
38 42
 		$update_db->insert_last_update();
39
-	} elseif (isset($globalDebug) && $globalDebug && (!isset($globalphpVMS) || !$globalphpVMS) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM)) echo "DB are populated with external data only every 15 days ! Files are not updated more often.\n";
43
+	} elseif (isset($globalDebug) && $globalDebug && (!isset($globalphpVMS) || !$globalphpVMS) && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM)) {
44
+		echo "DB are populated with external data only every 15 days ! Files are not updated more often.\n";
45
+	}
40 46
 	if (isset($globalWaypoints) && $globalWaypoints && $update_db->check_last_airspace_update()) {
41 47
 		echo "Check if new airspace version exist...";
42 48
 		echo $update_db->update_airspace_fam();
@@ -51,7 +57,9 @@  discard block
 block discarded – undo
51 57
 			$update_db->delete_duplicateowner();
52 58
 		}
53 59
 		$update_db->insert_last_owner_update();
54
-	} elseif (isset($globalDebug) && $globalDebug && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) echo "Owner are only updated every 15 days.\n";
60
+	} elseif (isset($globalDebug) && $globalDebug && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) {
61
+		echo "Owner are only updated every 15 days.\n";
62
+	}
55 63
 
56 64
 	if (isset($globalAccidents) && $globalAccidents && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) {
57 65
 		require_once(dirname(__FILE__).'/../require/class.Accident.php');
@@ -60,7 +68,9 @@  discard block
 block discarded – undo
60 68
 		if ($Accident->check_last_accidents_update()) {
61 69
 			$Accident->download_update();
62 70
 			$Accident->insert_last_accidents_update();
63
-		} else echo "Accidents are update once a day.\n";
71
+		} else {
72
+			echo "Accidents are update once a day.\n";
73
+		}
64 74
 	}
65 75
 
66 76
 }
@@ -73,15 +83,19 @@  discard block
 block discarded – undo
73 83
 	if ($METAR->check_last_update()) {
74 84
 		$METAR->addMETARCycle();
75 85
 		$METAR->insert_last_update();
76
-	} else echo "METAR are only updated every 30 minutes.\n";
77
-}
86
+	} else {
87
+		echo "METAR are only updated every 30 minutes.\n";
88
+	}
89
+	}
78 90
 
79 91
 if (isset($globalSchedules) && $globalSchedules && $update_db->check_last_schedules_update() && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) {
80 92
 	echo "Updating schedules...";
81 93
 	//$update_db->update_oneworld();
82 94
 	$update_db->update_skyteam();
83 95
 	$update_db->insert_last_schedules_update();
84
-} elseif (isset($globalDebug) && $globalDebug && isset($globalOwner) && $globalOwner && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) echo "Schedules are only updated every 15 days.\n";
96
+} elseif (isset($globalDebug) && $globalDebug && isset($globalOwner) && $globalOwner && (!isset($globalIVAO) || !$globalIVAO) && (!isset($globalVATSIM) || !$globalVATSIM) && (!isset($globalphpVMS) || !$globalphpVMS)) {
97
+	echo "Schedules are only updated every 15 days.\n";
98
+}
85 99
 
86 100
 if (isset($globalArchiveMonths) && $globalArchiveMonths > 0) {
87 101
 	echo "Updating statistics and archive old data...";
Please login to merge, or discard this patch.
require/class.Accident.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@
 block discarded – undo
22 22
 	}
23 23
 	
24 24
 	/**
25
-	* Get Latest Accidents data from DB
26
-	*
27
-	* @return Array Return Accidents data in array
28
-	*/
25
+	 * Get Latest Accidents data from DB
26
+	 *
27
+	 * @return Array Return Accidents data in array
28
+	 */
29 29
 	public function getLatestAccidentData($limit = '',$type = '') {
30 30
 		global $globalURL, $globalDBdriver;
31 31
 		$Image = new Image($this->db);
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	*
27 27
 	* @return Array Return Accidents data in array
28 28
 	*/
29
-	public function getLatestAccidentData($limit = '',$type = '') {
29
+	public function getLatestAccidentData($limit = '', $type = '') {
30 30
 		global $globalURL, $globalDBdriver;
31 31
 		$Image = new Image($this->db);
32 32
 		$Spotter = new Spotter($this->db);
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 		if ($limit != "")
38 38
 		{
39 39
 			$limit_array = explode(",", $limit);
40
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
41
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
40
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
41
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
42 42
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
43 43
 			{
44 44
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		try {
58 58
 			$sth = $this->db->prepare($query);
59 59
 			$sth->execute($query_values);
60
-		} catch(PDOException $e) {
60
+		} catch (PDOException $e) {
61 61
 			return "error : ".$e->getMessage();
62 62
 		}
63 63
 		$i = 0;
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 			$data = array();
66 66
 			if ($row['registration'] != '') {
67 67
 				$image_array = $Image->getSpotterImage($row['registration']);
68
-				if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
69
-				else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
68
+				if (count($image_array) > 0) $data = array_merge($data, array('image' => $image_array[0]['image'], 'image_thumbnail' => $image_array[0]['image_thumbnail'], 'image_copyright' => $image_array[0]['image_copyright'], 'image_source' => $image_array[0]['image_source'], 'image_source_website' => $image_array[0]['image_source_website']));
69
+				else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => ''));
70 70
 				$aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']);
71 71
 				$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type);
72 72
 				if (!empty($aircraft_info)) {
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 					$data['aircraft_name'] = $aircraft_info[0]['type'];
75 75
 					$data['aircraft_manufacturer'] = $aircraft_info[0]['manufacturer'];
76 76
 				} else {
77
-					$data = array_merge($data,array('aircraft_type' => 'NA'));
77
+					$data = array_merge($data, array('aircraft_type' => 'NA'));
78 78
 				}
79 79
 				$owner_data = $Spotter->getAircraftOwnerByRegistration($row['registration']);
80 80
 				if (!empty($owner_data)) {
@@ -82,20 +82,20 @@  discard block
 block discarded – undo
82 82
 					$data['aircraft_base'] = $owner_data['base'];
83 83
 					$data['aircraft_date_first_reg'] = $owner_data['date_first_reg'];
84 84
 				}
85
-			} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
85
+			} else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => ''));
86 86
 			if ($row['registration'] == '') $row['registration'] = 'NA';
87 87
 			if ($row['ident'] == '') $row['ident'] = 'NA';
88
-			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2));
88
+			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'], 0, 2));
89 89
 			if (isset($identicao[0])) {
90
-				if (substr($row['ident'],0,2) == 'AF') {
91
-					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
92
-					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
93
-				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
94
-				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
90
+				if (substr($row['ident'], 0, 2) == 'AF') {
91
+					if (filter_var(substr($row['ident'], 2), FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
92
+					else $icao = 'AFR'.ltrim(substr($row['ident'], 2), '0');
93
+				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'], 2), '0');
94
+				$data = array_merge($data, array('airline_icao' => $identicao[0]['icao'], 'airline_name' => $identicao[0]['name']));
95 95
 			} else $icao = $row['ident'];
96
-			$icao = $Translation->checkTranslation($icao,false);
96
+			$icao = $Translation->checkTranslation($icao, false);
97 97
 			//$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url']));
98
-			$data = array_merge($row,$data);
98
+			$data = array_merge($row, $data);
99 99
 			if ($data['ident'] == null) $data['ident'] = $icao;
100 100
 			if ($data['title'] == null) {
101 101
 				$data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country'];
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 		echo 'Import '.$file."\n";
122 122
 		$Connection = new Connection();
123 123
 		$result = array();
124
-		if (($handle = fopen($file,'r')) !== FALSE) {
125
-			while (($data = fgetcsv($handle,2000,",")) !== FALSE) {
124
+		if (($handle = fopen($file, 'r')) !== FALSE) {
125
+			while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) {
126 126
 				if (isset($data[1]) && $data[1] != '0000-00-00 00:00:00') {
127
-					$result[] = array('registration' => $data[0],'date' => strtotime($data[1]),'url' => $data[2],'country' => $data[3],'place' => $data[4],'title' => $data[5],'fatalities' => $data[6],'latitude' => $data[7],'longitude' => $data[8],'type' => $data[9],'ident' => $data[10],'aircraft_manufacturer' => $data[11],'aircraft_name' => $data[12],'source' => 'website_fam');
127
+					$result[] = array('registration' => $data[0], 'date' => strtotime($data[1]), 'url' => $data[2], 'country' => $data[3], 'place' => $data[4], 'title' => $data[5], 'fatalities' => $data[6], 'latitude' => $data[7], 'longitude' => $data[8], 'type' => $data[9], 'ident' => $data[10], 'aircraft_manufacturer' => $data[11], 'aircraft_name' => $data[12], 'source' => 'website_fam');
128 128
 				}
129 129
 			}
130 130
 			fclose($handle);
131 131
 		}
132
-		if (!empty($result)) $this->add($result,true);
132
+		if (!empty($result)) $this->add($result, true);
133 133
 	}
134 134
 
135 135
 	public function download_update() {
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
 		$all_md5 = array();
139 139
 		$all_md5_new = array();
140 140
 		if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) {
141
-			if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) {
142
-				while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) {
141
+			if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) {
142
+				while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) {
143 143
 					if (isset($data[1])) {
144 144
 						$year = $data[0];
145 145
 						$all_md5[$year] = $data[1];
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
 				fclose($handle);
149 149
 			}
150 150
 		}
151
-		$Common->download('https://data.flightairmap.fr/data/cr/cr-all.md5',dirname(__FILE__).'/../install/tmp/cr-all.md5');
151
+		$Common->download('https://data.flightairmap.fr/data/cr/cr-all.md5', dirname(__FILE__).'/../install/tmp/cr-all.md5');
152 152
 		if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) {
153
-			if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) {
154
-				while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) {
153
+			if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) {
154
+				while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) {
155 155
 					if (isset($data[1])) {
156 156
 						$year = $data[0];
157 157
 						$all_md5_new[$year] = $data[1];
@@ -162,15 +162,15 @@  discard block
 block discarded – undo
162 162
 		}
163 163
 		//print_r($all_md5_new);
164 164
 		//print_r($all_md5);
165
-		$result = $Common->arr_diff($all_md5_new,$all_md5);
165
+		$result = $Common->arr_diff($all_md5_new, $all_md5);
166 166
 		//print_r($result);
167 167
 		foreach ($result as $file => $md5) {
168
-			$Common->download('https://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file);
168
+			$Common->download('https://data.flightairmap.fr/data/cr/'.$file, dirname(__FILE__).'/../install/tmp/'.$file);
169 169
 			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file);
170 170
 		}
171 171
 	}
172 172
 
173
-	public function add($crash,$new = false) {
173
+	public function add($crash, $new = false) {
174 174
 		global $globalTransaction, $globalDebug;
175 175
 		require_once('class.Connection.php');
176 176
 		require_once('class.Image.php');
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 			$sthd->execute(array(':source' => $crash[0]['source']));
185 185
 		}
186 186
 		if ($globalTransaction) $Connection->db->beginTransaction();
187
-		$initial_array = array('ident' => null,'type' => 'accident','url' => null,'registration' => null, 'date' => null, 'place' => null,'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '','source' => '','aircraft_manufacturer' => null,'aircraft_name' => null);
187
+		$initial_array = array('ident' => null, 'type' => 'accident', 'url' => null, 'registration' => null, 'date' => null, 'place' => null, 'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '', 'source' => '', 'aircraft_manufacturer' => null, 'aircraft_name' => null);
188 188
 		$query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source';
189 189
 		$sth_check = $Connection->db->prepare($query_check);
190 190
 		$query = 'INSERT INTO accidents (aircraft_manufacturer,aircraft_name,ident,registration,date,url,country,place,title,fatalities,latitude,longitude,type,source) VALUES (:aircraft_manufacturer,:aircraft_name,:ident,:registration,:date,:url,:country,:place,:title,:fatalities,:latitude,:longitude,:type,:source)';
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
 				$cr = array_map(function($value) {
198 198
 					return $value === "" ? NULL : $value;
199 199
 				}, $cr);
200
-				if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) {
201
-					$query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']);
200
+				if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && $cr['date'] < time() && !preg_match('/\s/', $cr['registration'])) {
201
+					$query_check_values = array(':registration' => $cr['registration'], ':date' => date('Y-m-d', $cr['date']), ':type' => $cr['type'], ':source' => $cr['source']);
202 202
 					$sth_check->execute($query_check_values);
203 203
 					$result_check = $sth_check->fetch(PDO::FETCH_ASSOC);
204 204
 					if ($result_check['nb'] == 0) {
205
-						$query_values = array(':registration' => trim($cr['registration']),':date' => date('Y-m-d',$cr['date']),':url' => $cr['url'],':country' => $cr['country'],':place' => $cr['place'],':title' => $cr['title'],':fatalities' => $cr['fatalities'],':latitude' => $cr['latitude'],':longitude' => $cr['longitude'],':type' => $cr['type'],':source' => $cr['source'],':ident' => $cr['ident'],':aircraft_manufacturer' => $cr['aircraft_manufacturer'],':aircraft_name' => $cr['aircraft_name']);
205
+						$query_values = array(':registration' => trim($cr['registration']), ':date' => date('Y-m-d', $cr['date']), ':url' => $cr['url'], ':country' => $cr['country'], ':place' => $cr['place'], ':title' => $cr['title'], ':fatalities' => $cr['fatalities'], ':latitude' => $cr['latitude'], ':longitude' => $cr['longitude'], ':type' => $cr['type'], ':source' => $cr['source'], ':ident' => $cr['ident'], ':aircraft_manufacturer' => $cr['aircraft_manufacturer'], ':aircraft_name' => $cr['aircraft_name']);
206 206
 						$sth->execute($query_values);
207
-						if ($cr['date'] > time()-(30*86400)) {
207
+						if ($cr['date'] > time() - (30*86400)) {
208 208
 							if (empty($Image->getSpotterImage($cr['registration']))) {
209 209
 								//if ($globalDebug) echo 'Get image...'."\n";
210 210
 								$Image->addSpotterImage($cr['registration']);
@@ -213,13 +213,13 @@  discard block
 block discarded – undo
213 213
 						}
214 214
 					}
215 215
 				}
216
-				if ($globalTransaction && $j % 90 == 0) {
216
+				if ($globalTransaction && $j%90 == 0) {
217 217
 					$Connection->db->commit();
218 218
 					$Connection->db->beginTransaction();
219 219
 				}
220 220
 			}
221 221
 			if ($globalTransaction) $Connection->db->commit();
222
-		} catch(PDOException $e) {
222
+		} catch (PDOException $e) {
223 223
 			if ($globalTransaction) $Connection->db->rollBack();
224 224
 			echo $e->getMessage();
225 225
 		}
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 			$Connection = new Connection();
238 238
 			$sth = $Connection->db->prepare($query);
239 239
 			$sth->execute();
240
-		} catch(PDOException $e) {
240
+		} catch (PDOException $e) {
241 241
 			return "error : ".$e->getMessage();
242 242
 		}
243 243
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 			$Connection = new Connection();
253 253
 			$sth = $Connection->db->prepare($query);
254 254
 			$sth->execute();
255
-		} catch(PDOException $e) {
255
+		} catch (PDOException $e) {
256 256
 			return "error : ".$e->getMessage();
257 257
 		}
258 258
 	}
Please login to merge, or discard this patch.
Braces   +56 added lines, -20 removed lines patch added patch discarded remove patch
@@ -65,8 +65,11 @@  discard block
 block discarded – undo
65 65
 			$data = array();
66 66
 			if ($row['registration'] != '') {
67 67
 				$image_array = $Image->getSpotterImage($row['registration']);
68
-				if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
69
-				else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
68
+				if (count($image_array) > 0) {
69
+					$data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website']));
70
+				} else {
71
+					$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
72
+				}
70 73
 				$aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']);
71 74
 				$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type);
72 75
 				if (!empty($aircraft_info)) {
@@ -82,32 +85,50 @@  discard block
 block discarded – undo
82 85
 					$data['aircraft_base'] = $owner_data['base'];
83 86
 					$data['aircraft_date_first_reg'] = $owner_data['date_first_reg'];
84 87
 				}
85
-			} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
86
-			if ($row['registration'] == '') $row['registration'] = 'NA';
87
-			if ($row['ident'] == '') $row['ident'] = 'NA';
88
+			} else {
89
+				$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
90
+			}
91
+			if ($row['registration'] == '') {
92
+				$row['registration'] = 'NA';
93
+			}
94
+			if ($row['ident'] == '') {
95
+				$row['ident'] = 'NA';
96
+			}
88 97
 			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2));
89 98
 			if (isset($identicao[0])) {
90 99
 				if (substr($row['ident'],0,2) == 'AF') {
91
-					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
92
-					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
93
-				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
100
+					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
101
+						$icao = $row['ident'];
102
+					} else {
103
+						$icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
104
+					}
105
+				} else {
106
+					$icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
107
+				}
94 108
 				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
95
-			} else $icao = $row['ident'];
109
+			} else {
110
+				$icao = $row['ident'];
111
+			}
96 112
 			$icao = $Translation->checkTranslation($icao,false);
97 113
 			//$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url']));
98 114
 			$data = array_merge($row,$data);
99
-			if ($data['ident'] == null) $data['ident'] = $icao;
115
+			if ($data['ident'] == null) {
116
+				$data['ident'] = $icao;
117
+			}
100 118
 			if ($data['title'] == null) {
101 119
 				$data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country'];
102
-			} else $data['message'] = strtolower($data['title']);
120
+			} else {
121
+				$data['message'] = strtolower($data['title']);
122
+			}
103 123
 			$result[] = $data;
104 124
 			$i++;
105 125
 		}
106 126
 		if (isset($result)) {
107 127
 			$result[0]['query_number_rows'] = $i;
108 128
 			return $result;
129
+		} else {
130
+			return array();
109 131
 		}
110
-		else return array();
111 132
 	}
112 133
 	
113 134
 	
@@ -129,7 +150,9 @@  discard block
 block discarded – undo
129 150
 			}
130 151
 			fclose($handle);
131 152
 		}
132
-		if (!empty($result)) $this->add($result,true);
153
+		if (!empty($result)) {
154
+			$this->add($result,true);
155
+		}
133 156
 	}
134 157
 
135 158
 	public function download_update() {
@@ -166,7 +189,9 @@  discard block
 block discarded – undo
166 189
 		//print_r($result);
167 190
 		foreach ($result as $file => $md5) {
168 191
 			$Common->download('https://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file);
169
-			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file);
192
+			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) {
193
+				$this->import(dirname(__FILE__).'/../install/tmp/'.$file);
194
+			}
170 195
 		}
171 196
 	}
172 197
 
@@ -177,13 +202,17 @@  discard block
 block discarded – undo
177 202
 		$Connection = new Connection();
178 203
 		$Image = new Image();
179 204
 
180
-		if (empty($crash)) return false;
205
+		if (empty($crash)) {
206
+			return false;
207
+		}
181 208
 		if (!$new) {
182 209
 			$query_delete = 'DELETE FROM accidents WHERE source = :source';
183 210
 			$sthd = $Connection->db->prepare($query_delete);
184 211
 			$sthd->execute(array(':source' => $crash[0]['source']));
185 212
 		}
186
-		if ($globalTransaction) $Connection->db->beginTransaction();
213
+		if ($globalTransaction) {
214
+			$Connection->db->beginTransaction();
215
+		}
187 216
 		$initial_array = array('ident' => null,'type' => 'accident','url' => null,'registration' => null, 'date' => null, 'place' => null,'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '','source' => '','aircraft_manufacturer' => null,'aircraft_name' => null);
188 217
 		$query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source';
189 218
 		$sth_check = $Connection->db->prepare($query_check);
@@ -218,9 +247,13 @@  discard block
 block discarded – undo
218 247
 					$Connection->db->beginTransaction();
219 248
 				}
220 249
 			}
221
-			if ($globalTransaction) $Connection->db->commit();
250
+			if ($globalTransaction) {
251
+				$Connection->db->commit();
252
+			}
222 253
 		} catch(PDOException $e) {
223
-			if ($globalTransaction) $Connection->db->rollBack();
254
+			if ($globalTransaction) {
255
+				$Connection->db->rollBack();
256
+			}
224 257
 			echo $e->getMessage();
225 258
 		}
226 259
 		$sth_check->closeCursor();
@@ -241,8 +274,11 @@  discard block
 block discarded – undo
241 274
 			return "error : ".$e->getMessage();
242 275
 		}
243 276
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
244
-		if ($row['nb'] > 0) return false;
245
-		else return true;
277
+		if ($row['nb'] > 0) {
278
+			return false;
279
+		} else {
280
+			return true;
281
+		}
246 282
 	}
247 283
 
248 284
 	public static function insert_last_accidents_update() {
Please login to merge, or discard this patch.