@@ -1027,6 +1027,32 @@ public static function translation_fam() {
1027
1027
return '' ;
1028
1028
}
1029
1029
1030
+ public static function diagrams_fam () {
1031
+ global $ tmp_dir , $ globalTransaction ;
1032
+ $ header = NULL ;
1033
+ $ delimiter = " " ;
1034
+ $ Connection = new Connection ();
1035
+ if (($ handle = fopen ($ tmp_dir .'diagramspdf ' , 'r ' )) !== FALSE )
1036
+ {
1037
+ $ Connection ->db ->beginTransaction ();
1038
+ while (($ data = fgetcsv ($ handle , 1000 , $ delimiter )) !== FALSE )
1039
+ {
1040
+ $ query = 'UPDATE airport SET diagram_pdf = :diagrampdf, diagram_png = :diagrampng WHERE icao = :icao ' ;
1041
+ $ icao = str_replace ('.pdf ' ,'' ,$ data [2 ]);
1042
+ try {
1043
+ $ sth = $ Connection ->db ->prepare ($ query );
1044
+ $ sth ->execute (array (':icao ' => $ icao ,':diagrampdf ' => 'https://data.flightairmap.com/data/diagrams/ ' .$ icao .'.pdf ' ,':diagrampng ' => 'https://data.flightairmap.com/data/diagrams/ ' .$ icao .'.png ' ));
1045
+ } catch (PDOException $ e ) {
1046
+ echo "error : " .$ e ->getMessage ();
1047
+ return "error : " .$ e ->getMessage ();
1048
+ }
1049
+ }
1050
+ fclose ($ handle );
1051
+ $ Connection ->db ->commit ();
1052
+ }
1053
+ return '' ;
1054
+ }
1055
+
1030
1056
/*
1031
1057
* This function use FAA public data.
1032
1058
* With the help of data from other source, Mfr id is added to manufacturer table. Then ModeS with ICAO are added based on that.
@@ -2655,6 +2681,31 @@ public static function update_satellite_fam() {
2655
2681
}
2656
2682
return '' ;
2657
2683
}
2684
+ public static function update_diagrams_fam () {
2685
+ global $ tmp_dir , $ globalDebug ;
2686
+ update_db::download ('http://data.flightairmap.com/data/diagrams/diagramspdf.md5 ' ,$ tmp_dir .'diagramspdf.md5 ' );
2687
+ if (file_exists ($ tmp_dir .'diagramspdf.md5 ' )) {
2688
+ $ diagrams_md5_file = explode (' ' ,file_get_contents ($ tmp_dir .'diagramspdf.md5 ' ));
2689
+ $ diagrams_md5 = $ diagrams_md5_file [0 ];
2690
+ if (!update_db::check_diagrams_version ($ diagrams_md5 )) {
2691
+ if ($ globalDebug ) echo "Airports diagrams from FlightAirMap website : Download... " ;
2692
+ update_db::download ('http://data.flightairmap.com/data/diagrams/diagramspdf ' ,$ tmp_dir .'diagramspdf ' );
2693
+ if (file_exists ($ tmp_dir .'diagramspdf ' )) {
2694
+ if (md5_file ($ tmp_dir .'diagramspdf ' ) == $ diagrams_md5 ) {
2695
+ if ($ globalDebug ) echo "Add to DB... " ;
2696
+ $ error = update_db::diagrams_fam ();
2697
+ } else $ error = "File " .$ tmp_dir .'diagramspdf ' ." md5 failed. Download failed. " ;
2698
+ } else $ error = "File " .$ tmp_dir .'diagramspdf ' ." doesn't exist. Download failed. " ;
2699
+ if ($ error != '' ) {
2700
+ return $ error ;
2701
+ } else {
2702
+ update_db::insert_diagrams_version ($ diagrams_md5 );
2703
+ if ($ globalDebug ) echo "Done \n" ;
2704
+ }
2705
+ }
2706
+ }
2707
+ return '' ;
2708
+ }
2658
2709
public static function update_banned_fam () {
2659
2710
global $ tmp_dir , $ globalDebug ;
2660
2711
if ($ globalDebug ) echo "Banned airlines in Europe from FlightAirMap website : Download... " ;
@@ -3296,6 +3347,19 @@ public static function check_satellite_version($version) {
3296
3347
if ($ row ['nb ' ] > 0 ) return true ;
3297
3348
else return false ;
3298
3349
}
3350
+ public static function check_diagrams_version ($ version ) {
3351
+ $ query = "SELECT COUNT(*) as nb FROM config WHERE name = 'diagrams_version' AND value = :version " ;
3352
+ try {
3353
+ $ Connection = new Connection ();
3354
+ $ sth = $ Connection ->db ->prepare ($ query );
3355
+ $ sth ->execute (array (':version ' => $ version ));
3356
+ } catch (PDOException $ e ) {
3357
+ return "error : " .$ e ->getMessage ();
3358
+ }
3359
+ $ row = $ sth ->fetch (PDO ::FETCH_ASSOC );
3360
+ if ($ row ['nb ' ] > 0 ) return true ;
3361
+ else return false ;
3362
+ }
3299
3363
3300
3364
public static function check_airlines_version ($ version ) {
3301
3365
$ query = "SELECT COUNT(*) as nb FROM config WHERE name = 'airlines_version' AND value = :version " ;
@@ -3396,6 +3460,17 @@ public static function insert_satellite_version($version) {
3396
3460
return "error : " .$ e ->getMessage ();
3397
3461
}
3398
3462
}
3463
+ public static function insert_diagrams_version ($ version ) {
3464
+ $ query = "DELETE FROM config WHERE name = 'diagrams_version';
3465
+ INSERT INTO config (name,value) VALUES ('diagrams_version',:version); " ;
3466
+ try {
3467
+ $ Connection = new Connection ();
3468
+ $ sth = $ Connection ->db ->prepare ($ query );
3469
+ $ sth ->execute (array (':version ' => $ version ));
3470
+ } catch (PDOException $ e ) {
3471
+ return "error : " .$ e ->getMessage ();
3472
+ }
3473
+ }
3399
3474
3400
3475
public static function check_last_notam_update () {
3401
3476
global $ globalDBdriver ;
@@ -3814,6 +3889,7 @@ public static function update_all() {
3814
3889
echo update_db::fix_icaotype ();
3815
3890
echo update_db::update_banned_fam ();
3816
3891
echo update_db::update_block_fam ();
3892
+ echo update_db::update_diagrams ();
3817
3893
//echo update_db::update_celestrak();
3818
3894
//echo update_db::delete_duplicatemodes();
3819
3895
} else {
@@ -3829,6 +3905,7 @@ public static function update_all() {
3829
3905
//echo update_db::delete_duplicatemodes();
3830
3906
echo update_db::update_banned_fam ();
3831
3907
echo update_db::update_block_fam ();
3908
+ echo update_db::update_diagrams ();
3832
3909
}
3833
3910
}
3834
3911
}
@@ -3865,5 +3942,6 @@ public static function update_all() {
3865
3942
//echo update_db::update_celestrak();
3866
3943
//echo update_db::update_aircraft();
3867
3944
//echo update_db::update_block_fam();
3945
+ //echo update_db::update_diagrams_fam();
3868
3946
3869
3947
?>
0 commit comments