Completed
Push — master ( e82150...90b671 )
by Yannick
08:57
created
require/class.NOTAM.php 1 patch
Braces   +210 added lines, -89 removed lines patch added patch discarded remove patch
@@ -1033,8 +1033,11 @@  discard block
 block discarded – undo
1033 1033
 		$data = file_get_contents($filename);
1034 1034
 		preg_match_all("/%%(.+?)%%/is", $data, $matches);
1035 1035
 		//print_r($matches);
1036
-		if (isset($matches[1])) return $matches[1];
1037
-		else return array();
1036
+		if (isset($matches[1])) {
1037
+			return $matches[1];
1038
+		} else {
1039
+			return array();
1040
+		}
1038 1041
 	}
1039 1042
 	public function getAllNOTAMbyScope($scope) {
1040 1043
 		global $globalDBdriver;
@@ -1071,7 +1074,9 @@  discard block
 block discarded – undo
1071 1074
 				$minlong = $maxlong;
1072 1075
 				$maxlong = $tmplong;
1073 1076
 			}
1074
-		} else return array();
1077
+		} else {
1078
+			return array();
1079
+		}
1075 1080
 		if ($globalDBdriver == 'mysql') {
1076 1081
 			$query  = 'SELECT * FROM notam WHERE center_latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND center_longitude BETWEEN '.$minlong.' AND '.$maxlong.' AND radius > 0 AND date_end > UTC_TIMESTAMP() AND date_begin < UTC_TIMESTAMP()';
1077 1082
 		} else {
@@ -1095,7 +1100,9 @@  discard block
 block discarded – undo
1095 1100
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1096 1101
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1097 1102
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1098
-		} else return array();
1103
+		} else {
1104
+			return array();
1105
+		}
1099 1106
 		if ($globalDBdriver == 'mysql') {
1100 1107
 			$query  = 'SELECT * FROM notam WHERE center_latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND center_longitude BETWEEN '.$minlong.' AND '.$maxlong.' AND radius > 0 AND date_end > UTC_TIMESTAMP() AND date_begin < UTC_TIMESTAMP() AND scope = :scope';
1101 1108
 		} else {
@@ -1122,8 +1129,11 @@  discard block
 block discarded – undo
1122 1129
 			return "error : ".$e->getMessage();
1123 1130
 		}
1124 1131
 		$all = $sth->fetchAll(PDO::FETCH_ASSOC);
1125
-		if (isset($all[0])) return $all[0];
1126
-		else return array();
1132
+		if (isset($all[0])) {
1133
+			return $all[0];
1134
+		} else {
1135
+			return array();
1136
+		}
1127 1137
 	}
1128 1138
 
1129 1139
 	public function addNOTAM($ref,$title,$type,$fir,$code,$rules,$scope,$lower_limit,$upper_limit,$center_latitude,$center_longitude,$radius,$date_begin,$date_end,$permanent,$text,$full_notam) {
@@ -1201,7 +1211,9 @@  discard block
 block discarded – undo
1201 1211
 					foreach ($alldata as $initial_data) {
1202 1212
 						$data = $this->parse($initial_data);
1203 1213
 						$notamref = $this->getNOTAMbyRef($data['ref']);
1204
-						if (count($notamref) == 0) $this->addNOTAM($data['ref'],$data['title'],'',$data['fir'],$data['code'],'',$data['scope'],$data['lower_limit'],$data['upper_limit'],$data['latitude'],$data['longitude'],$data['radius'],$data['date_begin'],$data['date_end'],$data['permanent'],$data['text'],$data['full_notam']);
1214
+						if (count($notamref) == 0) {
1215
+							$this->addNOTAM($data['ref'],$data['title'],'',$data['fir'],$data['code'],'',$data['scope'],$data['lower_limit'],$data['upper_limit'],$data['latitude'],$data['longitude'],$data['radius'],$data['date_begin'],$data['date_end'],$data['permanent'],$data['text'],$data['full_notam']);
1216
+						}
1205 1217
 					}
1206 1218
 				}
1207 1219
 			}
@@ -1214,7 +1226,9 @@  discard block
 block discarded – undo
1214 1226
 			foreach ($alldata as $initial_data) {
1215 1227
 				$data = $this->parse($initial_data);
1216 1228
 				$notamref = $this->getNOTAMbyRef($data['ref']);
1217
-				if (!isset($notamref['notam_id'])) $this->addNOTAM($data['ref'],$data['title'],'',$data['fir'],$data['code'],'',$data['scope'],$data['lower_limit'],$data['upper_limit'],$data['latitude'],$data['longitude'],$data['radius'],$data['date_begin'],$data['date_end'],$data['permanent'],$data['text'],$data['full_notam']);
1229
+				if (!isset($notamref['notam_id'])) {
1230
+					$this->addNOTAM($data['ref'],$data['title'],'',$data['fir'],$data['code'],'',$data['scope'],$data['lower_limit'],$data['upper_limit'],$data['latitude'],$data['longitude'],$data['radius'],$data['date_begin'],$data['date_end'],$data['permanent'],$data['text'],$data['full_notam']);
1231
+				}
1218 1232
 			}
1219 1233
 		}
1220 1234
 	}
@@ -1226,11 +1240,15 @@  discard block
 block discarded – undo
1226 1240
 		foreach (array_chunk($allairports,20) as $airport) {
1227 1241
 			$airports_icao = array();
1228 1242
 			foreach($airport as $icao) {
1229
-				if (isset($icao['icao'])) $airports_icao[] = $icao['icao'];
1243
+				if (isset($icao['icao'])) {
1244
+					$airports_icao[] = $icao['icao'];
1245
+				}
1230 1246
 			}
1231 1247
 			$airport_icao = implode(',',$airports_icao);
1232 1248
 			$alldata = $this->downloadNOTAM($airport_icao);
1233
-			if ($globalTransaction) $this->db->beginTransaction();
1249
+			if ($globalTransaction) {
1250
+				$this->db->beginTransaction();
1251
+			}
1234 1252
 			if (count($alldata) > 0) {
1235 1253
 				foreach ($alldata as $initial_data) {
1236 1254
 					//print_r($initial_data);
@@ -1239,14 +1257,23 @@  discard block
 block discarded – undo
1239 1257
 					if (isset($data['ref'])) {
1240 1258
 						$notamref = $this->getNOTAMbyRef($data['ref']);
1241 1259
 						if (count($notamref) == 0) {
1242
-							if (isset($data['ref_replaced'])) $this->deleteNOTAMbyRef($data['ref_replaced']);
1243
-							if (isset($data['ref_cancelled'])) $this->deleteNOTAMbyRef($data['ref_cancelled']);
1244
-							elseif (isset($data['latitude']) && isset($data['scope']) && isset($data['text']) && isset($data['permanent'])) echo $this->addNOTAM($data['ref'],'','',$data['fir'],$data['code'],'',$data['scope'],$data['lower_limit'],$data['upper_limit'],$data['latitude'],$data['longitude'],$data['radius'],$data['date_begin'],$data['date_end'],$data['permanent'],$data['text'],$data['full_notam']);
1260
+							if (isset($data['ref_replaced'])) {
1261
+								$this->deleteNOTAMbyRef($data['ref_replaced']);
1262
+							}
1263
+							if (isset($data['ref_cancelled'])) {
1264
+								$this->deleteNOTAMbyRef($data['ref_cancelled']);
1265
+							} elseif (isset($data['latitude']) && isset($data['scope']) && isset($data['text']) && isset($data['permanent'])) {
1266
+								echo $this->addNOTAM($data['ref'],'','',$data['fir'],$data['code'],'',$data['scope'],$data['lower_limit'],$data['upper_limit'],$data['latitude'],$data['longitude'],$data['radius'],$data['date_begin'],$data['date_end'],$data['permanent'],$data['text'],$data['full_notam']);
1267
+							}
1245 1268
 						}
1246 1269
 					}
1247 1270
 				}
1248
-			} else echo 'Error on download. Nothing matches for '.$airport_icao."\n";
1249
-			if ($globalTransaction) $this->db->commit();
1271
+			} else {
1272
+				echo 'Error on download. Nothing matches for '.$airport_icao."\n";
1273
+			}
1274
+			if ($globalTransaction) {
1275
+				$this->db->commit();
1276
+			}
1250 1277
 			sleep(5);
1251 1278
 		}
1252 1279
 	}
@@ -1259,8 +1286,11 @@  discard block
 block discarded – undo
1259 1286
 		$data = $Common->getData($url);
1260 1287
 		preg_match_all("/<pre>(.+?)<\/pre>/is", $data, $matches);
1261 1288
 		//print_r($matches);
1262
-		if (isset($matches[1])) return $matches[1];
1263
-		else return array();
1289
+		if (isset($matches[1])) {
1290
+			return $matches[1];
1291
+		} else {
1292
+			return array();
1293
+		}
1264 1294
 	}
1265 1295
 
1266 1296
 	public function parse($data) {
@@ -1289,93 +1319,150 @@  discard block
 block discarded – undo
1289 1319
 					$rules = str_split($matches[3]);
1290 1320
 					foreach ($rules as $rule) {
1291 1321
 						if ($rule == 'I') {
1292
-							if (isset($result['rules'])) $result['rules'] = $result['rules'].'/IFR';
1293
-							else $result['rules'] = 'IFR';
1322
+							if (isset($result['rules'])) {
1323
+								$result['rules'] = $result['rules'].'/IFR';
1324
+							} else {
1325
+								$result['rules'] = 'IFR';
1326
+							}
1294 1327
 						} elseif ($rule == 'V') {
1295
-							if (isset($result['rules'])) $result['rules'] = $result['rules'].'/VFR';
1296
-							else $result['rules'] = 'VFR';
1328
+							if (isset($result['rules'])) {
1329
+								$result['rules'] = $result['rules'].'/VFR';
1330
+							} else {
1331
+								$result['rules'] = 'VFR';
1332
+							}
1297 1333
 						} elseif ($rule == 'K') {
1298
-							if (isset($result['rules'])) $result['rules'] = $result['rules'].'/Checklist';
1299
-							else $result['rules'] = 'Checklist';
1334
+							if (isset($result['rules'])) {
1335
+								$result['rules'] = $result['rules'].'/Checklist';
1336
+							} else {
1337
+								$result['rules'] = 'Checklist';
1338
+							}
1300 1339
 						}
1301 1340
 					}
1302 1341
 					$attentions = str_split($matches[4]);
1303 1342
 					foreach ($attentions as $attention) {
1304 1343
 						if ($attention == 'N') {
1305
-							if (isset($result['attention'])) $result['attention'] = $result['attention'].' / Immediate attention';
1306
-							else $result['rules'] = 'Immediate attention';
1344
+							if (isset($result['attention'])) {
1345
+								$result['attention'] = $result['attention'].' / Immediate attention';
1346
+							} else {
1347
+								$result['rules'] = 'Immediate attention';
1348
+							}
1307 1349
 						} elseif ($attention == 'B') {
1308
-							if (isset($result['attention'])) $result['attention'] = $result['attention'].' / Operational significance';
1309
-							else $result['rules'] = 'Operational significance';
1350
+							if (isset($result['attention'])) {
1351
+								$result['attention'] = $result['attention'].' / Operational significance';
1352
+							} else {
1353
+								$result['rules'] = 'Operational significance';
1354
+							}
1310 1355
 						} elseif ($attention == 'O') {
1311
-							if (isset($result['attention'])) $result['attention'] = $result['attention'].' / Flight operations';
1312
-							else $result['rules'] = 'Flight operations';
1356
+							if (isset($result['attention'])) {
1357
+								$result['attention'] = $result['attention'].' / Flight operations';
1358
+							} else {
1359
+								$result['rules'] = 'Flight operations';
1360
+							}
1313 1361
 						} elseif ($attention == 'M') {
1314
-							if (isset($result['attention'])) $result['attention'] = $result['attention'].' / Misc';
1315
-							else $result['rules'] = 'Misc';
1362
+							if (isset($result['attention'])) {
1363
+								$result['attention'] = $result['attention'].' / Misc';
1364
+							} else {
1365
+								$result['rules'] = 'Misc';
1366
+							}
1316 1367
 						} elseif ($attention == 'K') {
1317
-							if (isset($result['attention'])) $result['attention'] = $result['attention'].' / Checklist';
1318
-							else $result['rules'] = 'Checklist';
1368
+							if (isset($result['attention'])) {
1369
+								$result['attention'] = $result['attention'].' / Checklist';
1370
+							} else {
1371
+								$result['rules'] = 'Checklist';
1372
+							}
1319 1373
 						}
1320 1374
 					}
1321
-					if ($matches[5] == 'A') $result['scope'] = 'Airport warning';
1322
-					elseif ($matches[5] == 'E') $result['scope'] = 'Enroute warning';
1323
-					elseif ($matches[5] == 'W') $result['scope'] = 'Navigation warning';
1324
-					elseif ($matches[5] == 'K') $result['scope'] = 'Checklist';
1325
-					elseif ($matches[5] == 'AE') $result['scope'] = 'Airport/Enroute warning';
1326
-					elseif ($matches[5] == 'AW') $result['scope'] = 'Airport/Navigation warning';
1375
+					if ($matches[5] == 'A') {
1376
+						$result['scope'] = 'Airport warning';
1377
+					} elseif ($matches[5] == 'E') {
1378
+						$result['scope'] = 'Enroute warning';
1379
+					} elseif ($matches[5] == 'W') {
1380
+						$result['scope'] = 'Navigation warning';
1381
+					} elseif ($matches[5] == 'K') {
1382
+						$result['scope'] = 'Checklist';
1383
+					} elseif ($matches[5] == 'AE') {
1384
+						$result['scope'] = 'Airport/Enroute warning';
1385
+					} elseif ($matches[5] == 'AW') {
1386
+						$result['scope'] = 'Airport/Navigation warning';
1387
+					}
1327 1388
 					$result['lower_limit'] = $matches[6];
1328 1389
 					$result['upper_limit'] = $matches[7];
1329 1390
 					$latitude = $Common->convertDec($matches[8],'latitude');
1330
-					if ($matches[9] == 'S') $latitude = -$latitude;
1391
+					if ($matches[9] == 'S') {
1392
+						$latitude = -$latitude;
1393
+					}
1331 1394
 					$longitude = $Common->convertDec($matches[10],'longitude');
1332
-					if ($matches[11] == 'W') $longitude = -$longitude;
1395
+					if ($matches[11] == 'W') {
1396
+						$longitude = -$longitude;
1397
+					}
1333 1398
 					$result['latitude'] = $latitude;
1334 1399
 					$result['longitude'] = $longitude;
1335
-					if ($matches[12] != '') $result['radius'] = intval($matches[12]);
1336
-					else $result['radius'] = 0;
1400
+					if ($matches[12] != '') {
1401
+						$result['radius'] = intval($matches[12]);
1402
+					} else {
1403
+						$result['radius'] = 0;
1404
+					}
1337 1405
 				} elseif ($globalDebug) {
1338 1406
 					echo 'ERROR NOTAM : '.$notam."\n";
1339 1407
 					echo "Can't parse : ".$line."\n";
1340 1408
 				}
1341
-			}
1342
-			elseif (preg_match('#A\) (.*)#',$line,$matches)) {
1409
+			} elseif (preg_match('#A\) (.*)#',$line,$matches)) {
1343 1410
 				$result['icao'] = $matches[1];
1344
-			}
1345
-			elseif (preg_match('#B\) ([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})#',$line,$matches)) {
1346
-				if ($matches[1] > 50) $year = '19'.$matches[1];
1347
-				else $year = '20'.$matches[1];
1411
+			} elseif (preg_match('#B\) ([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})#',$line,$matches)) {
1412
+				if ($matches[1] > 50) {
1413
+					$year = '19'.$matches[1];
1414
+				} else {
1415
+					$year = '20'.$matches[1];
1416
+				}
1348 1417
 				$result['date_begin'] = $year.'/'.$matches[2].'/'.$matches[3].' '.$matches[4].':'.$matches[5];
1349
-			}
1350
-			elseif (preg_match('#C\) ([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#',$line,$matches)) {
1351
-				if ($matches[1] > 50) $year = '19'.$matches[1];
1352
-				else $year = '20'.$matches[1];
1418
+			} elseif (preg_match('#C\) ([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#',$line,$matches)) {
1419
+				if ($matches[1] > 50) {
1420
+					$year = '19'.$matches[1];
1421
+				} else {
1422
+					$year = '20'.$matches[1];
1423
+				}
1353 1424
 				$result['date_end'] = $year.'/'.$matches[2].'/'.$matches[3].' '.$matches[4].':'.$matches[5];
1354 1425
 				$result['permanent'] = 0;
1355
-			}
1356
-			elseif (preg_match('#C\) ([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2}) (EST|PERM)$#',$line,$matches)) {
1357
-				if ($matches[1] > 50) $year = '19'.$matches[1];
1358
-				else $year = '20'.$matches[1];
1426
+			} elseif (preg_match('#C\) ([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2}) (EST|PERM)$#',$line,$matches)) {
1427
+				if ($matches[1] > 50) {
1428
+					$year = '19'.$matches[1];
1429
+				} else {
1430
+					$year = '20'.$matches[1];
1431
+				}
1359 1432
 				$result['date_end'] = $year.'/'.$matches[2].'/'.$matches[3].' '.$matches[4].':'.$matches[5];
1360
-				if ($matches[6] == 'EST') $result['estimated'] = 1;
1361
-				else $result['estimated'] = 0;
1362
-				if ($matches[6] == 'PERM') $result['permanent'] = 1;
1363
-				else $result['permanent'] = 0;
1364
-			}
1365
-			elseif (preg_match('#C\) (EST|PERM)$#',$line,$matches)) {
1433
+				if ($matches[6] == 'EST') {
1434
+					$result['estimated'] = 1;
1435
+				} else {
1436
+					$result['estimated'] = 0;
1437
+				}
1438
+				if ($matches[6] == 'PERM') {
1439
+					$result['permanent'] = 1;
1440
+				} else {
1441
+					$result['permanent'] = 0;
1442
+				}
1443
+			} elseif (preg_match('#C\) (EST|PERM)$#',$line,$matches)) {
1366 1444
 				$result['date_end'] = '2030/12/20 12:00';
1367
-				if ($matches[1] == 'EST') $result['estimated'] = 1;
1368
-				else $result['estimated'] = 0;
1369
-				if ($matches[1] == 'PERM') $result['permanent'] = 1;
1370
-				else $result['permanent'] = 0;
1371
-			}
1372
-			elseif (preg_match('#E\) (.*)#',$line,$matches)) {
1445
+				if ($matches[1] == 'EST') {
1446
+					$result['estimated'] = 1;
1447
+				} else {
1448
+					$result['estimated'] = 0;
1449
+				}
1450
+				if ($matches[1] == 'PERM') {
1451
+					$result['permanent'] = 1;
1452
+				} else {
1453
+					$result['permanent'] = 0;
1454
+				}
1455
+			} elseif (preg_match('#E\) (.*)#',$line,$matches)) {
1373 1456
 				$rtext = array();
1374 1457
 				$text = explode(' ',$matches[1]);
1375 1458
 				foreach ($text as $word) {
1376
-					if (isset($this->abbr[$word])) $rtext[] = strtoupper($this->abbr[$word]);
1377
-					elseif (ctype_digit(strval(substr($word,3))) && isset($this->abbr[substr($word,0,3)])) $rtext[] = strtoupper($this->abbr[substr($word,0,3)]).' '.substr($word,3);
1378
-					else $rtext[] = $word;
1459
+					if (isset($this->abbr[$word])) {
1460
+						$rtext[] = strtoupper($this->abbr[$word]);
1461
+					} elseif (ctype_digit(strval(substr($word,3))) && isset($this->abbr[substr($word,0,3)])) {
1462
+						$rtext[] = strtoupper($this->abbr[substr($word,0,3)]).' '.substr($word,3);
1463
+					} else {
1464
+						$rtext[] = $word;
1465
+					}
1379 1466
 				}
1380 1467
 				$result['text'] = implode(' ',$rtext);
1381 1468
 			//} elseif (preg_match('#F\) (.*)#',$line,$matches)) {
@@ -1383,7 +1470,9 @@  discard block
 block discarded – undo
1383 1470
 			} elseif (preg_match('#(NOTAMN|NOTAMR|NOTAMC)#',$line,$matches)) {
1384 1471
 				$text = explode(' ',$line);
1385 1472
 				$result['ref'] = $text[0];
1386
-				if ($matches[1] == 'NOTAMN') $result['type'] = 'new';
1473
+				if ($matches[1] == 'NOTAMN') {
1474
+					$result['type'] = 'new';
1475
+				}
1387 1476
 				if ($matches[1] == 'NOTAMC') {
1388 1477
 					$result['type'] = 'cancel';
1389 1478
 					$result['ref_cancelled'] = $text[2];
@@ -1405,69 +1494,101 @@  discard block
 block discarded – undo
1405 1494
 		switch ($code[1]) {
1406 1495
 			case 'A':
1407 1496
 				$result = 'Airspace organization ';
1408
-				if (isset($this->code_airspace[$code_fp])) $result .= $this->code_airspace[$code_fp];
1497
+				if (isset($this->code_airspace[$code_fp])) {
1498
+					$result .= $this->code_airspace[$code_fp];
1499
+				}
1409 1500
 				break;
1410 1501
 			case 'C':
1411 1502
 				$result = 'Communications and radar facilities ';
1412
-				if (isset($this->code_comradar[$code_fp])) $result .= $this->code_comradar[$code_fp];
1503
+				if (isset($this->code_comradar[$code_fp])) {
1504
+					$result .= $this->code_comradar[$code_fp];
1505
+				}
1413 1506
 				break;
1414 1507
 			case 'F':
1415 1508
 				$result = 'Facilities and services ';
1416
-				if (isset($this->code_facilities[$code_fp])) $result .= $this->code_facilities[$code_fp];
1509
+				if (isset($this->code_facilities[$code_fp])) {
1510
+					$result .= $this->code_facilities[$code_fp];
1511
+				}
1417 1512
 				break;
1418 1513
 			case 'I':
1419 1514
 				$result = 'Instrument and Microwave Landing System ';
1420
-				if (isset($this->code_instrumentlanding[$code_fp])) $result .= $this->code_instrumentlanding[$code_fp];
1515
+				if (isset($this->code_instrumentlanding[$code_fp])) {
1516
+					$result .= $this->code_instrumentlanding[$code_fp];
1517
+				}
1421 1518
 				break;
1422 1519
 			case 'L':
1423 1520
 				$result = 'Lighting facilities ';
1424
-				if (isset($this->code_lightingfacilities[$code_fp])) $result .= $this->code_lightingfacilities[$code_fp];
1521
+				if (isset($this->code_lightingfacilities[$code_fp])) {
1522
+					$result .= $this->code_lightingfacilities[$code_fp];
1523
+				}
1425 1524
 				break;
1426 1525
 			case 'M':
1427 1526
 				$result = 'Movement and landing areas ';
1428
-				if (isset($this->code_movementareas[$code_fp])) $result .= $this->code_movementareas[$code_fp];
1527
+				if (isset($this->code_movementareas[$code_fp])) {
1528
+					$result .= $this->code_movementareas[$code_fp];
1529
+				}
1429 1530
 				break;
1430 1531
 			case 'N':
1431 1532
 				$result = 'Terminal and En Route Navigation Facilities ';
1432
-				if (isset($this->code_terminalfacilities[$code_fp])) $result .= $this->code_terminalfacilities[$code_fp];
1533
+				if (isset($this->code_terminalfacilities[$code_fp])) {
1534
+					$result .= $this->code_terminalfacilities[$code_fp];
1535
+				}
1433 1536
 				break;
1434 1537
 			case 'O':
1435 1538
 				$result = 'Other information ';
1436
-				if (isset($this->code_information[$code_fp])) $result .= $this->code_information[$code_fp];
1539
+				if (isset($this->code_information[$code_fp])) {
1540
+					$result .= $this->code_information[$code_fp];
1541
+				}
1437 1542
 				break;
1438 1543
 			case 'P':
1439 1544
 				$result = 'Air Traffic procedures ';
1440
-				if (isset($this->code_airtraffic[$code_fp])) $result .= $this->code_airtraffic[$code_fp];
1545
+				if (isset($this->code_airtraffic[$code_fp])) {
1546
+					$result .= $this->code_airtraffic[$code_fp];
1547
+				}
1441 1548
 				break;
1442 1549
 			case 'R':
1443 1550
 				$result = 'Navigation Warnings: Airspace Restrictions ';
1444
-				if (isset($this->code_navigationw[$code_fp])) $result .= $this->code_navigationw[$code_fp];
1551
+				if (isset($this->code_navigationw[$code_fp])) {
1552
+					$result .= $this->code_navigationw[$code_fp];
1553
+				}
1445 1554
 				break;
1446 1555
 			case 'S':
1447 1556
 				$result = 'Air Traffic and VOLMET Services ';
1448
-				if (isset($this->code_volmet[$code_fp])) $result .= $this->code_volmet[$code_fp];
1557
+				if (isset($this->code_volmet[$code_fp])) {
1558
+					$result .= $this->code_volmet[$code_fp];
1559
+				}
1449 1560
 				break;
1450 1561
 			case 'W':
1451 1562
 				$result = 'Navigation Warnings: Warnings ';
1452
-				if (isset($this->code_warnings[$code_fp])) $result .= $this->code_warnings[$code_fp];
1563
+				if (isset($this->code_warnings[$code_fp])) {
1564
+					$result .= $this->code_warnings[$code_fp];
1565
+				}
1453 1566
 				break;
1454 1567
 		}
1455 1568
 		switch ($code[3]) {
1456 1569
 			case 'A':
1457 1570
 				// Availability
1458
-				if (isset($this->code_sp_availabity[$code_sp])) $result .= ' '.$this->code_sp_availabity[$code_sp];
1571
+				if (isset($this->code_sp_availabity[$code_sp])) {
1572
+					$result .= ' '.$this->code_sp_availabity[$code_sp];
1573
+				}
1459 1574
 				break;
1460 1575
 			case 'C':
1461 1576
 				// Changes
1462
-				if (isset($this->code_sp_changes[$code_sp])) $result .= ' '.$this->code_sp_changes[$code_sp];
1577
+				if (isset($this->code_sp_changes[$code_sp])) {
1578
+					$result .= ' '.$this->code_sp_changes[$code_sp];
1579
+				}
1463 1580
 				break;
1464 1581
 			case 'H':
1465 1582
 				// Hazardous conditions
1466
-				if (isset($this->code_sp_hazardous[$code_sp])) $result .= ' '.$this->code_sp_hazardous[$code_sp];
1583
+				if (isset($this->code_sp_hazardous[$code_sp])) {
1584
+					$result .= ' '.$this->code_sp_hazardous[$code_sp];
1585
+				}
1467 1586
 				break;
1468 1587
 			case 'L':
1469 1588
 				// Limitations
1470
-				if (isset($this->code_sp_limitations[$code_sp])) $result .= ' '.$this->code_sp_limitations[$code_sp];
1589
+				if (isset($this->code_sp_limitations[$code_sp])) {
1590
+					$result .= ' '.$this->code_sp_limitations[$code_sp];
1591
+				}
1471 1592
 				break;
1472 1593
 			case 'X':
1473 1594
 				// Other Information
Please login to merge, or discard this patch.
require/class.Accident.php 1 patch
Braces   +84 added lines, -30 removed lines patch added patch discarded remove patch
@@ -113,8 +113,11 @@  discard block
 block discarded – undo
113 113
 				$data = array();
114 114
 				if ($row['registration'] != '') {
115 115
 					$image_array = $Image->getSpotterImage($row['registration']);
116
-					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']));
117
-					else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
116
+					if (count($image_array) > 0) {
117
+						$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']));
118
+					} else {
119
+						$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
120
+					}
118 121
 					$aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']);
119 122
 					$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type);
120 123
 					if (!empty($aircraft_info)) {
@@ -130,17 +133,30 @@  discard block
 block discarded – undo
130 133
 						$data['aircraft_base'] = $owner_data['base'];
131 134
 						$data['aircraft_date_first_reg'] = $owner_data['date_first_reg'];
132 135
 					}
133
-				} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
134
-				if ($row['registration'] == '') $row['registration'] = 'NA';
135
-				if ($row['ident'] == '') $row['ident'] = 'NA';
136
+				} else {
137
+					$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
138
+				}
139
+				if ($row['registration'] == '') {
140
+					$row['registration'] = 'NA';
141
+				}
142
+				if ($row['ident'] == '') {
143
+					$row['ident'] = 'NA';
144
+				}
136 145
 				$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3));
137 146
 				if (isset($identicao[0])) {
138 147
 					if (substr($row['ident'],0,2) == 'AF') {
139
-						if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
140
-						else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
141
-					} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
148
+						if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
149
+							$icao = $row['ident'];
150
+						} else {
151
+							$icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
152
+						}
153
+					} else {
154
+						$icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
155
+					}
142 156
 					$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
143
-				} else $icao = $row['ident'];
157
+				} else {
158
+					$icao = $row['ident'];
159
+				}
144 160
 				$icao = $Translation->checkTranslation($icao,false);
145 161
 				//$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url']));
146 162
 				if ($row['airline_name'] != '' && !isset($data['airline_name'])) {
@@ -155,10 +171,14 @@  discard block
 block discarded – undo
155 171
 					//else echo 'No data...'."\n";
156 172
 				}
157 173
 				$data = array_merge($row,$data);
158
-				if ($data['ident'] == null) $data['ident'] = $icao;
174
+				if ($data['ident'] == null) {
175
+					$data['ident'] = $icao;
176
+				}
159 177
 				if ($data['title'] == null) {
160 178
 					$data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country'];
161
-				} else $data['message'] = strtolower($data['title']);
179
+				} else {
180
+					$data['message'] = strtolower($data['title']);
181
+				}
162 182
 				$ids = $Spotter->getAllIDByRegistration($data['registration']);
163 183
 				$date = $data['date'];
164 184
 				if (isset($ids[$date])) {
@@ -177,8 +197,9 @@  discard block
 block discarded – undo
177 197
 		if (isset($result)) {
178 198
 			$result[0]['query_number_rows'] = $i;
179 199
 			return $result;
200
+		} else {
201
+			return array();
180 202
 		}
181
-		else return array();
182 203
 	}
183 204
 	
184 205
 	/*
@@ -222,7 +243,9 @@  discard block
 block discarded – undo
222 243
 	*/
223 244
 	public function import($file) {
224 245
 		global $globalTransaction, $globalDebug;
225
-		if ($globalDebug) echo 'Import '.$file."\n";
246
+		if ($globalDebug) {
247
+			echo 'Import '.$file."\n";
248
+		}
226 249
 		$result = array();
227 250
 		if (file_exists($file)) {
228 251
 			if (($handle = fopen($file,'r')) !== FALSE) {
@@ -233,8 +256,11 @@  discard block
 block discarded – undo
233 256
 				}
234 257
 				fclose($handle);
235 258
 			}
236
-			if (!empty($result)) $this->add($result,true);
237
-			elseif ($globalDebug) echo 'Nothing to import';
259
+			if (!empty($result)) {
260
+				$this->add($result,true);
261
+			} elseif ($globalDebug) {
262
+				echo 'Nothing to import';
263
+			}
238 264
 		}
239 265
 	}
240 266
 
@@ -270,14 +296,23 @@  discard block
 block discarded – undo
270 296
 					}
271 297
 				}
272 298
 				fclose($handle);
273
-			} elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5';
274
-		} elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
299
+			} elseif ($globalDebug) {
300
+				echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5';
301
+			}
302
+		} elseif ($globalDebug) {
303
+			echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
304
+		}
275 305
 		$result = $Common->arr_diff($all_md5_new,$all_md5);
276
-		if (empty($result) && $globalDebug) echo 'Nothing to update';
306
+		if (empty($result) && $globalDebug) {
307
+			echo 'Nothing to update';
308
+		}
277 309
 		foreach ($result as $file => $md5) {
278 310
 			$Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file);
279
-			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file);
280
-			elseif ($globalDebug) echo 'Download '.$file.' failed';
311
+			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) {
312
+				$this->import(dirname(__FILE__).'/../install/tmp/'.$file);
313
+			} elseif ($globalDebug) {
314
+				echo 'Download '.$file.' failed';
315
+			}
281 316
 		}
282 317
 	}
283 318
 
@@ -294,13 +329,17 @@  discard block
 block discarded – undo
294 329
 		$Image = new Image();
295 330
 		$Spotter = new Spotter();
296 331
 
297
-		if (empty($crash)) return false;
332
+		if (empty($crash)) {
333
+			return false;
334
+		}
298 335
 		if (!$new) {
299 336
 			$query_delete = 'DELETE FROM accidents WHERE source = :source';
300 337
 			$sthd = $Connection->db->prepare($query_delete);
301 338
 			$sthd->execute(array(':source' => $crash[0]['source']));
302 339
 		}
303
-		if ($globalTransaction) $Connection->db->beginTransaction();
340
+		if ($globalTransaction) {
341
+			$Connection->db->beginTransaction();
342
+		}
304 343
 		$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,'operator' => null);
305 344
 		$query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source';
306 345
 		$sth_check = $Connection->db->prepare($query_check);
@@ -315,7 +354,9 @@  discard block
 block discarded – undo
315 354
 					return $value === "" ? NULL : $value;
316 355
 				}, $cr);
317 356
 				if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) {
318
-					if (strpos($cr['registration'],'-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
357
+					if (strpos($cr['registration'],'-') === FALSE) {
358
+						$cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
359
+					}
319 360
 					$query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']);
320 361
 					$sth_check->execute($query_check_values);
321 362
 					$result_check = $sth_check->fetch(PDO::FETCH_ASSOC);
@@ -324,13 +365,19 @@  discard block
 block discarded – undo
324 365
 						$sth->execute($query_values);
325 366
 						if ($cr['date'] > time()-(30*86400)) {
326 367
 							if (empty($Image->getSpotterImage($cr['registration']))) {
327
-								if ($globalDebug) echo "\t".'Get image for '.$cr['registration'].'...';
368
+								if ($globalDebug) {
369
+									echo "\t".'Get image for '.$cr['registration'].'...';
370
+								}
328 371
 								$Image->addSpotterImage($cr['registration']);
329
-								if ($globalDebug) echo "\t".'Done'."\n";
372
+								if ($globalDebug) {
373
+									echo "\t".'Done'."\n";
374
+								}
330 375
 							}
331 376
 							// elseif ($globalDebug) echo 'Image already in DB'."\n";
332 377
 						}
333
-						if ($cr['title'] == '') $cr['title'] = $cr['registration'].' '.$cr['type'];
378
+						if ($cr['title'] == '') {
379
+							$cr['title'] = $cr['registration'].' '.$cr['type'];
380
+						}
334 381
 						$Spotter->setHighlightFlightByRegistration($cr['registration'],$cr['title'],date('Y-m-d',$cr['date']));
335 382
 					}
336 383
 				}
@@ -339,9 +386,13 @@  discard block
 block discarded – undo
339 386
 					$Connection->db->beginTransaction();
340 387
 				}
341 388
 			}
342
-			if ($globalTransaction) $Connection->db->commit();
389
+			if ($globalTransaction) {
390
+				$Connection->db->commit();
391
+			}
343 392
 		} catch(PDOException $e) {
344
-			if ($globalTransaction) $Connection->db->rollBack();
393
+			if ($globalTransaction) {
394
+				$Connection->db->rollBack();
395
+			}
345 396
 			echo $e->getMessage();
346 397
 		}
347 398
 		$sth_check->closeCursor();
@@ -380,8 +431,11 @@  discard block
 block discarded – undo
380 431
 			return "error : ".$e->getMessage();
381 432
 		}
382 433
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
383
-		if ($row['nb'] > 0) return false;
384
-		else return true;
434
+		if ($row['nb'] > 0) {
435
+			return false;
436
+		} else {
437
+			return true;
438
+		}
385 439
 	}
386 440
 
387 441
 	public static function insert_last_accidents_update() {
Please login to merge, or discard this patch.