Completed
Push — master ( 34c6fd...b81903 )
by Yannick
06:41
created
install/class.update_schema.php 1 patch
Braces   +240 added lines, -90 removed lines patch added patch discarded remove patch
@@ -258,7 +258,9 @@  discard block
 block discarded – undo
258 258
     		// Update table countries
259 259
     		if ($Connection->tableExists('airspace')) {
260 260
     		    $error .= update_db::update_countries();
261
-		    if ($error != '') return $error;
261
+		    if ($error != '') {
262
+		    	return $error;
263
+		    }
262 264
 		}
263 265
 		// Update schema_version to 7
264 266
 		$query = "UPDATE `config` SET `value` = '7' WHERE `name` = 'schema_version'";
@@ -314,7 +316,9 @@  discard block
 block discarded – undo
314 316
     		$error = '';
315 317
     		// Update table aircraft
316 318
 		$error .= create_db::import_file('../db/source_location.sql');
317
-		if ($error != '') return $error;
319
+		if ($error != '') {
320
+			return $error;
321
+		}
318 322
 		// Update schema_version to 6
319 323
 		$query = "UPDATE `config` SET `value` = '8' WHERE `name` = 'schema_version'";
320 324
         	try {
@@ -331,7 +335,9 @@  discard block
 block discarded – undo
331 335
     		$error = '';
332 336
     		// Update table aircraft
333 337
 		$error .= create_db::import_file('../db/notam.sql');
334
-		if ($error != '') return $error;
338
+		if ($error != '') {
339
+			return $error;
340
+		}
335 341
 		$query = "DELETE FROM config WHERE name = 'last_update_db';
336 342
                         INSERT INTO config (name,value) VALUES ('last_update_db',NOW());
337 343
                         DELETE FROM config WHERE name = 'last_update_notam_db';
@@ -365,7 +371,9 @@  discard block
 block discarded – undo
365 371
 		$error = '';
366 372
     		// Update table atc
367 373
 		$error .= create_db::import_file('../db/atc.sql');
368
-		if ($error != '') return $error;
374
+		if ($error != '') {
375
+			return $error;
376
+		}
369 377
 		
370 378
 		$query = "UPDATE `config` SET `value` = '10' WHERE `name` = 'schema_version'";
371 379
         	try {
@@ -389,13 +397,21 @@  discard block
 block discarded – undo
389 397
 		$error = '';
390 398
     		// Add tables
391 399
 		$error .= create_db::import_file('../db/aircraft_owner.sql');
392
-		if ($error != '') return $error;
400
+		if ($error != '') {
401
+			return $error;
402
+		}
393 403
 		$error .= create_db::import_file('../db/metar.sql');
394
-		if ($error != '') return $error;
404
+		if ($error != '') {
405
+			return $error;
406
+		}
395 407
 		$error .= create_db::import_file('../db/taf.sql');
396
-		if ($error != '') return $error;
408
+		if ($error != '') {
409
+			return $error;
410
+		}
397 411
 		$error .= create_db::import_file('../db/airport.sql');
398
-		if ($error != '') return $error;
412
+		if ($error != '') {
413
+			return $error;
414
+		}
399 415
 		
400 416
 		$query = "UPDATE `config` SET `value` = '11' WHERE `name` = 'schema_version'";
401 417
         	try {
@@ -469,19 +485,33 @@  discard block
 block discarded – undo
469 485
 		$error = '';
470 486
     		// Add tables
471 487
 		$error .= create_db::import_file('../db/stats.sql');
472
-		if ($error != '') return $error;
488
+		if ($error != '') {
489
+			return $error;
490
+		}
473 491
 		$error .= create_db::import_file('../db/stats_aircraft.sql');
474
-		if ($error != '') return $error;
492
+		if ($error != '') {
493
+			return $error;
494
+		}
475 495
 		$error .= create_db::import_file('../db/stats_airline.sql');
476
-		if ($error != '') return $error;
496
+		if ($error != '') {
497
+			return $error;
498
+		}
477 499
 		$error .= create_db::import_file('../db/stats_airport.sql');
478
-		if ($error != '') return $error;
500
+		if ($error != '') {
501
+			return $error;
502
+		}
479 503
 		$error .= create_db::import_file('../db/stats_owner.sql');
480
-		if ($error != '') return $error;
504
+		if ($error != '') {
505
+			return $error;
506
+		}
481 507
 		$error .= create_db::import_file('../db/stats_pilot.sql');
482
-		if ($error != '') return $error;
508
+		if ($error != '') {
509
+			return $error;
510
+		}
483 511
 		$error .= create_db::import_file('../db/spotter_archive_output.sql');
484
-		if ($error != '') return $error;
512
+		if ($error != '') {
513
+			return $error;
514
+		}
485 515
 		
486 516
 		$query = "UPDATE `config` SET `value` = '13' WHERE `name` = 'schema_version'";
487 517
         	try {
@@ -521,7 +551,9 @@  discard block
 block discarded – undo
521 551
     		// Add tables
522 552
     		if (!$Connection->tableExists('stats_flight')) {
523 553
 			$error .= create_db::import_file('../db/stats_flight.sql');
524
-			if ($error != '') return $error;
554
+			if ($error != '') {
555
+				return $error;
556
+			}
525 557
 		}
526 558
 		$query = "UPDATE `config` SET `value` = '15' WHERE `name` = 'schema_version'";
527 559
         	try {
@@ -545,7 +577,9 @@  discard block
 block discarded – undo
545 577
     		} catch(PDOException $e) {
546 578
 		    return "error (update stats) : ".$e->getMessage()."\n";
547 579
     		}
548
-		if ($error != '') return $error;
580
+		if ($error != '') {
581
+			return $error;
582
+		}
549 583
 		$query = "UPDATE `config` SET `value` = '16' WHERE `name` = 'schema_version'";
550 584
         	try {
551 585
             	    $sth = $Connection->db->prepare($query);
@@ -566,7 +600,9 @@  discard block
 block discarded – undo
566 600
     		if (!$Connection->tableExists('stats_callsign')) {
567 601
 			$error .= create_db::import_file('../db/stats_callsign.sql');
568 602
 		}
569
-		if ($error != '') return $error;
603
+		if ($error != '') {
604
+			return $error;
605
+		}
570 606
 		$query = "UPDATE `config` SET `value` = '17' WHERE `name` = 'schema_version'";
571 607
         	try {
572 608
             	    $sth = $Connection->db->prepare($query);
@@ -584,7 +620,9 @@  discard block
 block discarded – undo
584 620
     		if (!$Connection->tableExists('stats_country')) {
585 621
 			$error .= create_db::import_file('../db/stats_country.sql');
586 622
 		}
587
-		if ($error != '') return $error;
623
+		if ($error != '') {
624
+			return $error;
625
+		}
588 626
 		$query = "UPDATE `config` SET `value` = '18' WHERE `name` = 'schema_version'";
589 627
         	try {
590 628
             	    $sth = $Connection->db->prepare($query);
@@ -607,7 +645,9 @@  discard block
 block discarded – undo
607 645
 			    return "error (update stats) : ".$e->getMessage()."\n";
608 646
     			}
609 647
     		}
610
-		if ($error != '') return $error;
648
+		if ($error != '') {
649
+			return $error;
650
+		}
611 651
 		$query = "UPDATE `config` SET `value` = '19' WHERE `name` = 'schema_version'";
612 652
         	try {
613 653
             	    $sth = $Connection->db->prepare($query);
@@ -623,7 +663,9 @@  discard block
 block discarded – undo
623 663
 		$error = '';
624 664
     		// Update airport table
625 665
 		$error .= create_db::import_file('../db/airport.sql');
626
-		if ($error != '') return 'Import airport.sql : '.$error;
666
+		if ($error != '') {
667
+			return 'Import airport.sql : '.$error;
668
+		}
627 669
 		// Remove primary key on Spotter_Archive
628 670
 		$query = "alter table spotter_archive drop spotter_archive_id";
629 671
         	try {
@@ -699,7 +741,9 @@  discard block
 block discarded – undo
699 741
 				return "error (add source_name column) : ".$e->getMessage()."\n";
700 742
     			}
701 743
     		}
702
-		if ($error != '') return $error;
744
+		if ($error != '') {
745
+			return $error;
746
+		}
703 747
 		$query = "UPDATE `config` SET `value` = '20' WHERE `name` = 'schema_version'";
704 748
         	try {
705 749
             	    $sth = $Connection->db->prepare($query);
@@ -717,7 +761,9 @@  discard block
 block discarded – undo
717 761
     		// Update airline table
718 762
     		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
719 763
 			$error .= create_db::import_file('../db/airlines.sql');
720
-			if ($error != '') return 'Import airlines.sql : '.$error;
764
+			if ($error != '') {
765
+				return 'Import airlines.sql : '.$error;
766
+			}
721 767
 		}
722 768
 		if (!$Connection->checkColumnName('aircraft_modes','type_flight')) {
723 769
 			// Add column over_country
@@ -729,7 +775,9 @@  discard block
 block discarded – undo
729 775
 				return "error (add over_country) : ".$e->getMessage()."\n";
730 776
     			}
731 777
     		}
732
-		if ($error != '') return $error;
778
+		if ($error != '') {
779
+			return $error;
780
+		}
733 781
 		/*
734 782
     		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
735 783
 			// Force update ModeS (this will put type_flight data
@@ -759,7 +807,9 @@  discard block
 block discarded – undo
759 807
 			} catch(PDOException $e) {
760 808
 				return "error (rename type to stats_type on stats*) : ".$e->getMessage()."\n";
761 809
 			}
762
-			if ($error != '') return $error;
810
+			if ($error != '') {
811
+				return $error;
812
+			}
763 813
 		}
764 814
 		$query = "UPDATE `config` SET `value` = '22' WHERE `name` = 'schema_version'";
765 815
         	try {
@@ -782,7 +832,9 @@  discard block
 block discarded – undo
782 832
 			} else {
783 833
 				$error .= create_db::import_file('../db/pgsql/stats_source.sql');
784 834
 			}
785
-			if ($error != '') return $error;
835
+			if ($error != '') {
836
+				return $error;
837
+			}
786 838
 		}
787 839
 		$query = "UPDATE config SET value = '23' WHERE name = 'schema_version'";
788 840
         	try {
@@ -804,12 +856,16 @@  discard block
 block discarded – undo
804 856
 		if ($globalDBdriver == 'mysql') {
805 857
 			if (!$Connection->tableExists('tle')) {
806 858
 				$error .= create_db::import_file('../db/tle.sql');
807
-				if ($error != '') return $error;
859
+				if ($error != '') {
860
+					return $error;
861
+				}
808 862
 			}
809 863
 		} else {
810 864
 			if (!$Connection->tableExists('tle')) {
811 865
 				$error .= create_db::import_file('../db/pgsql/tle.sql');
812
-				if ($error != '') return $error;
866
+				if ($error != '') {
867
+					return $error;
868
+				}
813 869
 			}
814 870
 			$query = "create index flightaware_id_idx ON spotter_archive USING btree(flightaware_id)";
815 871
 			try {
@@ -849,7 +905,9 @@  discard block
 block discarded – undo
849 905
 		} else {
850 906
 			$error .= create_db::import_file('../db/pgsql/airlines.sql');
851 907
 		}
852
-		if ($error != '') return 'Import airlines.sql : '.$error;
908
+		if ($error != '') {
909
+			return 'Import airlines.sql : '.$error;
910
+		}
853 911
 		if (!$Connection->checkColumnName('airlines','forsource')) {
854 912
 			// Add forsource to airlines
855 913
 			$query = "ALTER TABLE airlines ADD forsource VARCHAR(255) NULL DEFAULT NULL";
@@ -1245,8 +1303,11 @@  discard block
 block discarded – undo
1245 1303
     	    if ($Connection->tableExists('aircraft')) {
1246 1304
     		if (!$Connection->tableExists('config')) {
1247 1305
     		    $version = '1';
1248
-    		    if ($update) return self::update_from_1();
1249
-    		    else return $version;
1306
+    		    if ($update) {
1307
+    		    	return self::update_from_1();
1308
+    		    } else {
1309
+    		    	return $version;
1310
+    		    }
1250 1311
 		} else {
1251 1312
     		    $Connection = new Connection();
1252 1313
 		    $query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
@@ -1260,122 +1321,211 @@  discard block
 block discarded – undo
1260 1321
     		    if ($update) {
1261 1322
     			if ($result['value'] == '2') {
1262 1323
     			    $error = self::update_from_2();
1263
-    			    if ($error != '') return $error;
1264
-    			    else return self::check_version(true);
1324
+    			    if ($error != '') {
1325
+    			    	return $error;
1326
+    			    } else {
1327
+    			    	return self::check_version(true);
1328
+    			    }
1265 1329
     			} elseif ($result['value'] == '3') {
1266 1330
     			    $error = self::update_from_3();
1267
-    			    if ($error != '') return $error;
1268
-    			    else return self::check_version(true);
1331
+    			    if ($error != '') {
1332
+    			    	return $error;
1333
+    			    } else {
1334
+    			    	return self::check_version(true);
1335
+    			    }
1269 1336
     			} elseif ($result['value'] == '4') {
1270 1337
     			    $error = self::update_from_4();
1271
-    			    if ($error != '') return $error;
1272
-    			    else return self::check_version(true);
1338
+    			    if ($error != '') {
1339
+    			    	return $error;
1340
+    			    } else {
1341
+    			    	return self::check_version(true);
1342
+    			    }
1273 1343
     			} elseif ($result['value'] == '5') {
1274 1344
     			    $error = self::update_from_5();
1275
-    			    if ($error != '') return $error;
1276
-    			    else return self::check_version(true);
1345
+    			    if ($error != '') {
1346
+    			    	return $error;
1347
+    			    } else {
1348
+    			    	return self::check_version(true);
1349
+    			    }
1277 1350
     			} elseif ($result['value'] == '6') {
1278 1351
     			    $error = self::update_from_6();
1279
-    			    if ($error != '') return $error;
1280
-    			    else return self::check_version(true);
1352
+    			    if ($error != '') {
1353
+    			    	return $error;
1354
+    			    } else {
1355
+    			    	return self::check_version(true);
1356
+    			    }
1281 1357
     			} elseif ($result['value'] == '7') {
1282 1358
     			    $error = self::update_from_7();
1283
-    			    if ($error != '') return $error;
1284
-    			    else return self::check_version(true);
1359
+    			    if ($error != '') {
1360
+    			    	return $error;
1361
+    			    } else {
1362
+    			    	return self::check_version(true);
1363
+    			    }
1285 1364
     			} elseif ($result['value'] == '8') {
1286 1365
     			    $error = self::update_from_8();
1287
-    			    if ($error != '') return $error;
1288
-    			    else return self::check_version(true);
1366
+    			    if ($error != '') {
1367
+    			    	return $error;
1368
+    			    } else {
1369
+    			    	return self::check_version(true);
1370
+    			    }
1289 1371
     			} elseif ($result['value'] == '9') {
1290 1372
     			    $error = self::update_from_9();
1291
-    			    if ($error != '') return $error;
1292
-    			    else return self::check_version(true);
1373
+    			    if ($error != '') {
1374
+    			    	return $error;
1375
+    			    } else {
1376
+    			    	return self::check_version(true);
1377
+    			    }
1293 1378
     			} elseif ($result['value'] == '10') {
1294 1379
     			    $error = self::update_from_10();
1295
-    			    if ($error != '') return $error;
1296
-    			    else return self::check_version(true);
1380
+    			    if ($error != '') {
1381
+    			    	return $error;
1382
+    			    } else {
1383
+    			    	return self::check_version(true);
1384
+    			    }
1297 1385
     			} elseif ($result['value'] == '11') {
1298 1386
     			    $error = self::update_from_11();
1299
-    			    if ($error != '') return $error;
1300
-    			    else return self::check_version(true);
1387
+    			    if ($error != '') {
1388
+    			    	return $error;
1389
+    			    } else {
1390
+    			    	return self::check_version(true);
1391
+    			    }
1301 1392
     			} elseif ($result['value'] == '12') {
1302 1393
     			    $error = self::update_from_12();
1303
-    			    if ($error != '') return $error;
1304
-    			    else return self::check_version(true);
1394
+    			    if ($error != '') {
1395
+    			    	return $error;
1396
+    			    } else {
1397
+    			    	return self::check_version(true);
1398
+    			    }
1305 1399
     			} elseif ($result['value'] == '13') {
1306 1400
     			    $error = self::update_from_13();
1307
-    			    if ($error != '') return $error;
1308
-    			    else return self::check_version(true);
1401
+    			    if ($error != '') {
1402
+    			    	return $error;
1403
+    			    } else {
1404
+    			    	return self::check_version(true);
1405
+    			    }
1309 1406
     			} elseif ($result['value'] == '14') {
1310 1407
     			    $error = self::update_from_14();
1311
-    			    if ($error != '') return $error;
1312
-    			    else return self::check_version(true);
1408
+    			    if ($error != '') {
1409
+    			    	return $error;
1410
+    			    } else {
1411
+    			    	return self::check_version(true);
1412
+    			    }
1313 1413
     			} elseif ($result['value'] == '15') {
1314 1414
     			    $error = self::update_from_15();
1315
-    			    if ($error != '') return $error;
1316
-    			    else return self::check_version(true);
1415
+    			    if ($error != '') {
1416
+    			    	return $error;
1417
+    			    } else {
1418
+    			    	return self::check_version(true);
1419
+    			    }
1317 1420
     			} elseif ($result['value'] == '16') {
1318 1421
     			    $error = self::update_from_16();
1319
-    			    if ($error != '') return $error;
1320
-    			    else return self::check_version(true);
1422
+    			    if ($error != '') {
1423
+    			    	return $error;
1424
+    			    } else {
1425
+    			    	return self::check_version(true);
1426
+    			    }
1321 1427
     			} elseif ($result['value'] == '17') {
1322 1428
     			    $error = self::update_from_17();
1323
-    			    if ($error != '') return $error;
1324
-    			    else return self::check_version(true);
1429
+    			    if ($error != '') {
1430
+    			    	return $error;
1431
+    			    } else {
1432
+    			    	return self::check_version(true);
1433
+    			    }
1325 1434
     			} elseif ($result['value'] == '18') {
1326 1435
     			    $error = self::update_from_18();
1327
-    			    if ($error != '') return $error;
1328
-    			    else return self::check_version(true);
1436
+    			    if ($error != '') {
1437
+    			    	return $error;
1438
+    			    } else {
1439
+    			    	return self::check_version(true);
1440
+    			    }
1329 1441
     			} elseif ($result['value'] == '19') {
1330 1442
     			    $error = self::update_from_19();
1331
-    			    if ($error != '') return $error;
1332
-    			    else return self::check_version(true);
1443
+    			    if ($error != '') {
1444
+    			    	return $error;
1445
+    			    } else {
1446
+    			    	return self::check_version(true);
1447
+    			    }
1333 1448
     			} elseif ($result['value'] == '20') {
1334 1449
     			    $error = self::update_from_20();
1335
-    			    if ($error != '') return $error;
1336
-    			    else return self::check_version(true);
1450
+    			    if ($error != '') {
1451
+    			    	return $error;
1452
+    			    } else {
1453
+    			    	return self::check_version(true);
1454
+    			    }
1337 1455
     			} elseif ($result['value'] == '21') {
1338 1456
     			    $error = self::update_from_21();
1339
-    			    if ($error != '') return $error;
1340
-    			    else return self::check_version(true);
1457
+    			    if ($error != '') {
1458
+    			    	return $error;
1459
+    			    } else {
1460
+    			    	return self::check_version(true);
1461
+    			    }
1341 1462
     			} elseif ($result['value'] == '22') {
1342 1463
     			    $error = self::update_from_22();
1343
-    			    if ($error != '') return $error;
1344
-    			    else return self::check_version(true);
1464
+    			    if ($error != '') {
1465
+    			    	return $error;
1466
+    			    } else {
1467
+    			    	return self::check_version(true);
1468
+    			    }
1345 1469
     			} elseif ($result['value'] == '23') {
1346 1470
     			    $error = self::update_from_23();
1347
-    			    if ($error != '') return $error;
1348
-    			    else return self::check_version(true);
1471
+    			    if ($error != '') {
1472
+    			    	return $error;
1473
+    			    } else {
1474
+    			    	return self::check_version(true);
1475
+    			    }
1349 1476
     			} elseif ($result['value'] == '24') {
1350 1477
     			    $error = self::update_from_24();
1351
-    			    if ($error != '') return $error;
1352
-    			    else return self::check_version(true);
1478
+    			    if ($error != '') {
1479
+    			    	return $error;
1480
+    			    } else {
1481
+    			    	return self::check_version(true);
1482
+    			    }
1353 1483
     			} elseif ($result['value'] == '25') {
1354 1484
     			    $error = self::update_from_25();
1355
-    			    if ($error != '') return $error;
1356
-    			    else return self::check_version(true);
1485
+    			    if ($error != '') {
1486
+    			    	return $error;
1487
+    			    } else {
1488
+    			    	return self::check_version(true);
1489
+    			    }
1357 1490
     			} elseif ($result['value'] == '26') {
1358 1491
     			    $error = self::update_from_26();
1359
-    			    if ($error != '') return $error;
1360
-    			    else return self::check_version(true);
1492
+    			    if ($error != '') {
1493
+    			    	return $error;
1494
+    			    } else {
1495
+    			    	return self::check_version(true);
1496
+    			    }
1361 1497
     			} elseif ($result['value'] == '27') {
1362 1498
     			    $error = self::update_from_27();
1363
-    			    if ($error != '') return $error;
1364
-    			    else return self::check_version(true);
1499
+    			    if ($error != '') {
1500
+    			    	return $error;
1501
+    			    } else {
1502
+    			    	return self::check_version(true);
1503
+    			    }
1365 1504
     			} elseif ($result['value'] == '28') {
1366 1505
     			    $error = self::update_from_28();
1367
-    			    if ($error != '') return $error;
1368
-    			    else return self::check_version(true);
1506
+    			    if ($error != '') {
1507
+    			    	return $error;
1508
+    			    } else {
1509
+    			    	return self::check_version(true);
1510
+    			    }
1369 1511
     			} elseif ($result['value'] == '29') {
1370 1512
     			    $error = self::update_from_29();
1371
-    			    if ($error != '') return $error;
1372
-    			    else return self::check_version(true);
1373
-    			} else return '';
1513
+    			    if ($error != '') {
1514
+    			    	return $error;
1515
+    			    } else {
1516
+    			    	return self::check_version(true);
1517
+    			    }
1518
+    			} else {
1519
+    				return '';
1520
+    			}
1521
+    		    } else {
1522
+    		    	return $result['value'];
1374 1523
     		    }
1375
-    		    else return $result['value'];
1376 1524
 		}
1377 1525
 		
1378
-	    } else return $version;
1526
+	    } else {
1527
+	    	return $version;
1528
+	    }
1379 1529
     	}
1380 1530
     	
1381 1531
 }
Please login to merge, or discard this patch.
require/class.METAR.php 1 patch
Braces   +94 added lines, -36 removed lines patch added patch discarded remove patch
@@ -59,8 +59,11 @@  discard block
 block discarded – undo
59 59
                 }
60 60
                 $row = $sth->fetch(PDO::FETCH_ASSOC);
61 61
                 $sth->closeCursor();
62
-                if ($row['nb'] > 0) return false;
63
-                else return true;
62
+                if ($row['nb'] > 0) {
63
+                	return false;
64
+                } else {
65
+                	return true;
66
+                }
64 67
         }
65 68
 
66 69
         public static function insert_last_update() {
@@ -84,9 +87,14 @@  discard block
 block discarded – undo
84 87
     		//$pieces = explode(' ',$data);
85 88
     		$pieces = preg_split('/\s/',$data);
86 89
     		$pos = 0;
87
-    		if ($pieces[0] == 'METAR') $pos++;
88
-    		elseif ($pieces[0] == 'SPECI') $pos++;
89
-    		if (strlen($pieces[$pos]) != 4) $pos++;
90
+    		if ($pieces[0] == 'METAR') {
91
+    			$pos++;
92
+    		} elseif ($pieces[0] == 'SPECI') {
93
+    			$pos++;
94
+    		}
95
+    		if (strlen($pieces[$pos]) != 4) {
96
+    			$pos++;
97
+    		}
90 98
     		$result = array();
91 99
     		$result['location'] = $pieces[$pos];
92 100
     		$pos++;
@@ -95,16 +103,26 @@  discard block
 block discarded – undo
95 103
     		$c = count($pieces);
96 104
     		for($pos++; $pos < $c; $pos++) {
97 105
     			$piece = $pieces[$pos];
98
-    			if ($piece == 'RMK') break;
99
-    			if ($piece == 'AUTO') $result['auto'] = true;
100
-    			if ($piece == 'COR') $result['correction'] = true;
106
+    			if ($piece == 'RMK') {
107
+    				break;
108
+    			}
109
+    			if ($piece == 'AUTO') {
110
+    				$result['auto'] = true;
111
+    			}
112
+    			if ($piece == 'COR') {
113
+    				$result['correction'] = true;
114
+    			}
101 115
     			// Wind Speed
102 116
     			if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) {
103 117
     				$result['wind']['direction'] = (float)$matches[1];
104 118
 				$result['wind']['unit'] = $matches[4];
105
-    				if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
106
-    				elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2);
107
-    				elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2);
119
+    				if ($result['wind']['unit'] == 'KT') {
120
+    					$result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2);
121
+    				} elseif ($result['wind']['unit'] == 'KPH') {
122
+    					$result['wind']['speed'] = round(((float)$matches[2])*1000,2);
123
+    				} elseif ($result['wind']['unit'] == 'MPS') {
124
+    					$result['wind']['speed'] = round(((float)$matches[2]),2);
125
+    				}
108 126
 				$result['wind']['gust'] = (float)$matches[3];
109 127
 				$result['wind']['unit'] = $matches[4];
110 128
 				$result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0;
@@ -186,14 +204,23 @@  discard block
 block discarded – undo
186 204
     				//$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : '');
187 205
     				$type = $matches[1];
188 206
     				$cloud = array();
189
-    				if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear';
190
-    				elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)';
191
-    				elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud';
192
-    				elseif ($type == 'FEW') $cloud['type'] = 'Few';
193
-    				elseif ($type == 'SCT') $cloud['type'] = 'Scattered';
194
-    				elseif ($type == 'BKN') $cloud['type'] = 'Broken';
195
-    				elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage';
196
-    				elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility';
207
+    				if ($type == 'SKC') {
208
+    					$cloud['type'] = 'No cloud/Sky clear';
209
+    				} elseif ($type == 'CLR') {
210
+    					$cloud['type'] = 'No cloud below 12,000ft (3700m)';
211
+    				} elseif ($type == 'NSC') {
212
+    					$cloud['type'] = 'No significant cloud';
213
+    				} elseif ($type == 'FEW') {
214
+    					$cloud['type'] = 'Few';
215
+    				} elseif ($type == 'SCT') {
216
+    					$cloud['type'] = 'Scattered';
217
+    				} elseif ($type == 'BKN') {
218
+    					$cloud['type'] = 'Broken';
219
+    				} elseif ($type == 'OVC') {
220
+    					$cloud['type'] = 'Overcast/Full cloud coverage';
221
+    				} elseif ($type == 'VV') {
222
+    					$cloud['type'] = 'Vertical visibility';
223
+    				}
197 224
     				$cloud['type_code'] = $type;
198 225
     				$cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048);
199 226
     				$cloud['significant'] = isset($matches[3]) ? $matches[3] : '';
@@ -223,8 +250,11 @@  discard block
 block discarded – undo
223 250
     			if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) {
224 251
     				//echo $piece;
225 252
     				//print_r($matches);
226
-    				if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
227
-    				else $range = array('exact' => (float)$matches[2], 'unit' => 'M');
253
+    				if (isset($matches[5])) {
254
+    					$range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M');
255
+    				} else {
256
+    					$range = array('exact' => (float)$matches[2], 'unit' => 'M');
257
+    				}
228 258
 				if (isset($matches[3])) {
229 259
 					$range = Array(
230 260
 					    'from' => (float)$matches[2],
@@ -257,8 +287,11 @@  discard block
 block discarded – undo
257 287
 				if (isset($matches[3])) {
258 288
 					$text[] = $this->texts[$matches[3]];
259 289
 				}
260
-				if (!isset($result['weather'])) $result['weather'] = implode(' ', $text);
261
-				else $result['weather'] = $result['weather'].' / '.implode(' ', $text);
290
+				if (!isset($result['weather'])) {
291
+					$result['weather'] = implode(' ', $text);
292
+				} else {
293
+					$result['weather'] = $result['weather'].' / '.implode(' ', $text);
294
+				}
262 295
     			}
263 296
     		}
264 297
     		return $result;
@@ -270,8 +303,11 @@  discard block
 block discarded – undo
270 303
     		if (isset($globalMETARcycle) && $globalMETARcycle) {
271 304
             		$query = "SELECT * FROM metar WHERE metar_location = :icao";
272 305
                 } else {
273
-            		if ($globalDBdriver == 'mysql') $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
274
-            		else $query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
306
+            		if ($globalDBdriver == 'mysql') {
307
+            			$query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 HOUR) LIMIT 1";
308
+            		} else {
309
+            			$query = "SELECT * FROM metar WHERE metar_location = :icao AND metar_date >= now() AT TIMEZONE 'UTC' - '10 HOUR'->INTERVAL LIMIT 0,1";
310
+            		}
275 311
                 }
276 312
                 $query_values = array(':icao' => $icao);
277 313
                  try {
@@ -326,7 +362,9 @@  discard block
 block discarded – undo
326 362
         
327 363
         public function addMETARCycle() {
328 364
     		global $globalDebug, $globalIVAO;
329
-    		if (isset($globalDebug) && $globalDebug) echo "Downloading METAR cycle...";
365
+    		if (isset($globalDebug) && $globalDebug) {
366
+    			echo "Downloading METAR cycle...";
367
+    		}
330 368
     		date_default_timezone_set("UTC");
331 369
     		$Common = new Common();
332 370
     		if (isset($globalIVAO) && $globalIVAO) {
@@ -339,7 +377,9 @@  discard block
 block discarded – undo
339 377
     			$handle = fopen(dirname(__FILE__).'/../install/tmp/'.date('H').'Z.TXT',"r");
340 378
     		}
341 379
     		if ($handle) {
342
-			if (isset($globalDebug) && $globalDebug) echo "Done - Updating DB...";
380
+			if (isset($globalDebug) && $globalDebug) {
381
+				echo "Done - Updating DB...";
382
+			}
343 383
 			$date = '';
344 384
     			//foreach(explode("\n",$cycle) as $line) {
345 385
 	    		while(($line = fgets($handle,4096)) !== false) {
@@ -347,23 +387,33 @@  discard block
 block discarded – undo
347 387
 					$date = $line;
348 388
     				} elseif ($line != '') {
349 389
     				    //$this->parse($line);
350
-    				    if ($date == '') $date = date('Y/m/d H:m');
390
+    				    if ($date == '') {
391
+    				    	$date = date('Y/m/d H:m');
392
+    				    }
351 393
         			    $pos = 0;
352 394
         			    $pieces = preg_split('/\s/',$line);
353
-        			    if ($pieces[0] == 'METAR') $pos++;
354
-        			    if (strlen($pieces[$pos]) != 4) $pos++;
395
+        			    if ($pieces[0] == 'METAR') {
396
+        			    	$pos++;
397
+        			    }
398
+        			    if (strlen($pieces[$pos]) != 4) {
399
+        			    	$pos++;
400
+        			    }
355 401
 		        	    $location = $pieces[$pos];
356 402
         	        	    echo $this->addMETAR($location,$line,$date);
357 403
     				}
358 404
     			}
359 405
     			fclose($handle);
360 406
     		}
361
-    		if (isset($globalDebug) && $globalDebug) echo "Done\n";
407
+    		if (isset($globalDebug) && $globalDebug) {
408
+    			echo "Done\n";
409
+    		}
362 410
         
363 411
         }
364 412
         public function downloadMETAR($icao) {
365 413
     		global $globalMETARurl;
366
-    		if ($globalMETARurl == '') return array();
414
+    		if ($globalMETARurl == '') {
415
+    			return array();
416
+    		}
367 417
     		date_default_timezone_set("UTC");
368 418
     		$Common = new Common();
369 419
     		$url = str_replace('{icao}',$icao,$globalMETARurl);
@@ -377,16 +427,24 @@  discard block
 block discarded – undo
377 427
     			if ($line != '') {
378 428
     			    //$this->parse($line);
379 429
     			    //echo $line;
380
-    			    if ($date == '') $date = date('Y/m/d H:m');
430
+    			    if ($date == '') {
431
+    			    	$date = date('Y/m/d H:m');
432
+    			    }
381 433
     			    $pos = 0;
382 434
     			    $pieces = preg_split('/\s/',$line);
383
-    			    if ($pieces[0] == 'METAR') $pos++;
384
-    			    if (strlen($pieces[$pos]) != 4) $pos++;
435
+    			    if ($pieces[0] == 'METAR') {
436
+    			    	$pos++;
437
+    			    }
438
+    			    if (strlen($pieces[$pos]) != 4) {
439
+    			    	$pos++;
440
+    			    }
385 441
 	        	    $location = $pieces[$pos];
386 442
 	        	    if (strlen($location == 4)) {
387 443
 	        		$this->addMETAR($location,$line,$date);
388 444
 	        		return array('0' => array('metar_date' => $date, 'metar_location' => $location, 'metar' => $line));
389
-	        	    } else return array();
445
+	        	    } else {
446
+	        	    	return array();
447
+	        	    }
390 448
     			}
391 449
     			//echo $line."\n";
392 450
     		}
Please login to merge, or discard this patch.