@@ -19,47 +19,47 @@ discard block  | 
                                                    ||
| 19 | 19 | // Check if schema is at latest version  | 
                                                        
| 20 | 20 | $Connection = new Connection();  | 
                                                        
| 21 | 21 |  if ($Connection->latest() === false) { | 
                                                        
| 22 | - echo "You MUST update to latest schema. Run install/index.php";  | 
                                                        |
| 23 | - exit();  | 
                                                        |
| 22 | + echo "You MUST update to latest schema. Run install/index.php";  | 
                                                        |
| 23 | + exit();  | 
                                                        |
| 24 | 24 | }  | 
                                                        
| 25 | 25 |  if (PHP_SAPI != 'cli') { | 
                                                        
| 26 | - echo "This script MUST be called from console, not a web browser.";  | 
                                                        |
| 26 | + echo "This script MUST be called from console, not a web browser.";  | 
                                                        |
| 27 | 27 | // exit();  | 
                                                        
| 28 | 28 | }  | 
                                                        
| 29 | 29 | |
| 30 | 30 | // This is to be compatible with old version of settings.php  | 
                                                        
| 31 | 31 |  if (!isset($globalSources)) { | 
                                                        
| 32 | -    if (isset($globalSBS1Hosts)) { | 
                                                        |
| 33 | - //$hosts = $globalSBS1Hosts;  | 
                                                        |
| 34 | -        foreach ($globalSBS1Hosts as $host) { | 
                                                        |
| 35 | -	    $globalSources[] = array('host' => $host); | 
                                                        |
| 36 | - }  | 
                                                        |
| 37 | -    } else { | 
                                                        |
| 38 | -        if (!isset($globalSBS1Host)) { | 
                                                        |
| 39 | - echo '$globalSources MUST be defined !';  | 
                                                        |
| 40 | - die;  | 
                                                        |
| 32 | +	if (isset($globalSBS1Hosts)) { | 
                                                        |
| 33 | + //$hosts = $globalSBS1Hosts;  | 
                                                        |
| 34 | +		foreach ($globalSBS1Hosts as $host) { | 
                                                        |
| 35 | +		$globalSources[] = array('host' => $host); | 
                                                        |
| 36 | + }  | 
                                                        |
| 37 | +	} else { | 
                                                        |
| 38 | +		if (!isset($globalSBS1Host)) { | 
                                                        |
| 39 | + echo '$globalSources MUST be defined !';  | 
                                                        |
| 40 | + die;  | 
                                                        |
| 41 | 41 | }  | 
                                                        
| 42 | 42 | //$hosts = array($globalSBS1Host.':'.$globalSBS1Port);  | 
                                                        
| 43 | 43 |  	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port); | 
                                                        
| 44 | - }  | 
                                                        |
| 44 | + }  | 
                                                        |
| 45 | 45 | }  | 
                                                        
| 46 | 46 | |
| 47 | 47 |  $options = getopt('s::',array('source::','server','idsource::')); | 
                                                        
| 48 | 48 | //if (isset($options['s'])) $hosts = array($options['s']);  | 
                                                        
| 49 | 49 | //elseif (isset($options['source'])) $hosts = array($options['source']);  | 
                                                        
| 50 | 50 |  if (isset($options['s'])) { | 
                                                        
| 51 | - $globalSources = array();  | 
                                                        |
| 52 | -    $globalSources[] = array('host' => $options['s']); | 
                                                        |
| 51 | + $globalSources = array();  | 
                                                        |
| 52 | +	$globalSources[] = array('host' => $options['s']); | 
                                                        |
| 53 | 53 |  } elseif (isset($options['source'])) { | 
                                                        
| 54 | - $globalSources = array();  | 
                                                        |
| 55 | -    $globalSources[] = array('host' => $options['source']); | 
                                                        |
| 54 | + $globalSources = array();  | 
                                                        |
| 55 | +	$globalSources[] = array('host' => $options['source']); | 
                                                        |
| 56 | 56 | }  | 
                                                        
| 57 | 57 | if (isset($options['server'])) $globalServer = TRUE;  | 
                                                        
| 58 | 58 | if (isset($options['idsource'])) $id_source = $options['idsource'];  | 
                                                        
| 59 | 59 | else $id_source = 1;  | 
                                                        
| 60 | 60 |  if (isset($globalServer) && $globalServer) { | 
                                                        
| 61 | - if ($globalDebug) echo "Using Server Mode\n";  | 
                                                        |
| 62 | - $SI=new SpotterServer();  | 
                                                        |
| 61 | + if ($globalDebug) echo "Using Server Mode\n";  | 
                                                        |
| 62 | + $SI=new SpotterServer();  | 
                                                        |
| 63 | 63 | } else $SI=new SpotterImport($Connection->db);  | 
                                                        
| 64 | 64 | //$APRS=new APRS($Connection->db);  | 
                                                        
| 65 | 65 | $SBS=new SBS();  | 
                                                        
@@ -69,12 +69,12 @@ discard block  | 
                                                    ||
| 69 | 69 |  //$servertz = system('date +%Z'); | 
                                                        
| 70 | 70 | // signal handler - playing nice with sockets and dump1090  | 
                                                        
| 71 | 71 |  if (function_exists('pcntl_fork')) { | 
                                                        
| 72 | -    pcntl_signal(SIGINT,  function() { | 
                                                        |
| 73 | - global $sockets;  | 
                                                        |
| 74 | - echo "\n\nctrl-c or kill signal received. Tidying up ... ";  | 
                                                        |
| 75 | -        die("Bye!\n"); | 
                                                        |
| 76 | - });  | 
                                                        |
| 77 | - pcntl_signal_dispatch();  | 
                                                        |
| 72 | +	pcntl_signal(SIGINT,  function() { | 
                                                        |
| 73 | + global $sockets;  | 
                                                        |
| 74 | + echo "\n\nctrl-c or kill signal received. Tidying up ... ";  | 
                                                        |
| 75 | +		die("Bye!\n"); | 
                                                        |
| 76 | + });  | 
                                                        |
| 77 | + pcntl_signal_dispatch();  | 
                                                        |
| 78 | 78 | }  | 
                                                        
| 79 | 79 | |
| 80 | 80 | // let's try and connect  | 
                                                        
@@ -84,162 +84,162 @@ discard block  | 
                                                    ||
| 84 | 84 | $reset = 0;  | 
                                                        
| 85 | 85 | |
| 86 | 86 |  function create_socket($host, $port, &$errno, &$errstr) { | 
                                                        
| 87 | - $ip = gethostbyname($host);  | 
                                                        |
| 88 | - $s = socket_create(AF_INET, SOCK_STREAM, 0);  | 
                                                        |
| 89 | - $r = @socket_connect($s, $ip, $port);  | 
                                                        |
| 90 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";  | 
                                                        |
| 91 | -    if ($r || socket_last_error() == 114 || socket_last_error() == 115) { | 
                                                        |
| 92 | - return $s;  | 
                                                        |
| 93 | - }  | 
                                                        |
| 94 | - $errno = socket_last_error($s);  | 
                                                        |
| 95 | - $errstr = socket_strerror($errno);  | 
                                                        |
| 96 | - socket_close($s);  | 
                                                        |
| 97 | - return false;  | 
                                                        |
| 87 | + $ip = gethostbyname($host);  | 
                                                        |
| 88 | + $s = socket_create(AF_INET, SOCK_STREAM, 0);  | 
                                                        |
| 89 | + $r = @socket_connect($s, $ip, $port);  | 
                                                        |
| 90 | + if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";  | 
                                                        |
| 91 | +	if ($r || socket_last_error() == 114 || socket_last_error() == 115) { | 
                                                        |
| 92 | + return $s;  | 
                                                        |
| 93 | + }  | 
                                                        |
| 94 | + $errno = socket_last_error($s);  | 
                                                        |
| 95 | + $errstr = socket_strerror($errno);  | 
                                                        |
| 96 | + socket_close($s);  | 
                                                        |
| 97 | + return false;  | 
                                                        |
| 98 | 98 | }  | 
                                                        
| 99 | 99 | |
| 100 | 100 |  function create_socket_udp($host, $port, &$errno, &$errstr) { | 
                                                        
| 101 | - echo "Create an UDP socket...\n";  | 
                                                        |
| 102 | - $ip = gethostbyname($host);  | 
                                                        |
| 103 | - $s = socket_create(AF_INET, SOCK_DGRAM, 0);  | 
                                                        |
| 104 | - $r = @socket_bind($s, $ip, $port);  | 
                                                        |
| 105 | -    if ($r || socket_last_error() == 114 || socket_last_error() == 115) { | 
                                                        |
| 106 | - return $s;  | 
                                                        |
| 107 | - }  | 
                                                        |
| 108 | - $errno = socket_last_error($s);  | 
                                                        |
| 109 | - $errstr = socket_strerror($errno);  | 
                                                        |
| 110 | - socket_close($s);  | 
                                                        |
| 111 | - return false;  | 
                                                        |
| 101 | + echo "Create an UDP socket...\n";  | 
                                                        |
| 102 | + $ip = gethostbyname($host);  | 
                                                        |
| 103 | + $s = socket_create(AF_INET, SOCK_DGRAM, 0);  | 
                                                        |
| 104 | + $r = @socket_bind($s, $ip, $port);  | 
                                                        |
| 105 | +	if ($r || socket_last_error() == 114 || socket_last_error() == 115) { | 
                                                        |
| 106 | + return $s;  | 
                                                        |
| 107 | + }  | 
                                                        |
| 108 | + $errno = socket_last_error($s);  | 
                                                        |
| 109 | + $errstr = socket_strerror($errno);  | 
                                                        |
| 110 | + socket_close($s);  | 
                                                        |
| 111 | + return false;  | 
                                                        |
| 112 | 112 | }  | 
                                                        
| 113 | 113 | |
| 114 | 114 |  function connect_all($hosts) { | 
                                                        
| 115 | - //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;  | 
                                                        |
| 116 | - global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;  | 
                                                        |
| 117 | - $reset++;  | 
                                                        |
| 118 | - if ($globalDebug) echo 'Connect to all...'."\n";  | 
                                                        |
| 119 | -    foreach ($hosts as $id => $value) { | 
                                                        |
| 115 | + //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;  | 
                                                        |
| 116 | + global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;  | 
                                                        |
| 117 | + $reset++;  | 
                                                        |
| 118 | + if ($globalDebug) echo 'Connect to all...'."\n";  | 
                                                        |
| 119 | +	foreach ($hosts as $id => $value) { | 
                                                        |
| 120 | 120 | $host = $value['host'];  | 
                                                        
| 121 | 121 | $globalSources[$id]['last_exec'] = 0;  | 
                                                        
| 122 | 122 | // Here we check type of source(s)  | 
                                                        
| 123 | 123 |  	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { | 
                                                        
| 124 | -            if (preg_match('/deltadb.txt$/i',$host)) { | 
                                                        |
| 125 | - //$formats[$id] = 'deltadbtxt';  | 
                                                        |
| 126 | - $globalSources[$id]['format'] = 'deltadbtxt';  | 
                                                        |
| 127 | - //$last_exec['deltadbtxt'] = 0;  | 
                                                        |
| 128 | -        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; | 
                                                        |
| 129 | -            } else if (preg_match('/vatsim-data.txt$/i',$host)) { | 
                                                        |
| 130 | - //$formats[$id] = 'vatsimtxt';  | 
                                                        |
| 131 | - $globalSources[$id]['format'] = 'vatsimtxt';  | 
                                                        |
| 132 | - //$last_exec['vatsimtxt'] = 0;  | 
                                                        |
| 133 | -        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; | 
                                                        |
| 134 | -    	    } else if (preg_match('/aircraftlist.json$/i',$host)) { | 
                                                        |
| 135 | - //$formats[$id] = 'aircraftlistjson';  | 
                                                        |
| 136 | - $globalSources[$id]['format'] = 'aircraftlistjson';  | 
                                                        |
| 137 | - //$last_exec['aircraftlistjson'] = 0;  | 
                                                        |
| 138 | -        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; | 
                                                        |
| 139 | -    	    } else if (preg_match('/opensky/i',$host)) { | 
                                                        |
| 140 | - //$formats[$id] = 'aircraftlistjson';  | 
                                                        |
| 141 | - $globalSources[$id]['format'] = 'opensky';  | 
                                                        |
| 142 | - //$last_exec['aircraftlistjson'] = 0;  | 
                                                        |
| 143 | -        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; | 
                                                        |
| 144 | -    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { | 
                                                        |
| 145 | - //$formats[$id] = 'radarvirtueljson';  | 
                                                        |
| 146 | - $globalSources[$id]['format'] = 'radarvirtueljson';  | 
                                                        |
| 147 | - //$last_exec['radarvirtueljson'] = 0;  | 
                                                        |
| 148 | -        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; | 
                                                        |
| 149 | -        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { | 
                                                        |
| 150 | - echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";  | 
                                                        |
| 151 | - exit(0);  | 
                                                        |
| 152 | - }  | 
                                                        |
| 153 | -    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) { | 
                                                        |
| 154 | - //$formats[$id] = 'planeupdatefaa';  | 
                                                        |
| 155 | - $globalSources[$id]['format'] = 'planeupdatefaa';  | 
                                                        |
| 156 | - //$last_exec['planeupdatefaa'] = 0;  | 
                                                        |
| 157 | -        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; | 
                                                        |
| 158 | -        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { | 
                                                        |
| 159 | - echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";  | 
                                                        |
| 160 | - exit(0);  | 
                                                        |
| 161 | - }  | 
                                                        |
| 162 | -            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) { | 
                                                        |
| 163 | - //$formats[$id] = 'phpvmacars';  | 
                                                        |
| 164 | - $globalSources[$id]['format'] = 'phpvmacars';  | 
                                                        |
| 165 | - //$last_exec['phpvmacars'] = 0;  | 
                                                        |
| 166 | -        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; | 
                                                        |
| 167 | -            } else if (preg_match('/VAM-json.php$/i',$host)) { | 
                                                        |
| 168 | - //$formats[$id] = 'phpvmacars';  | 
                                                        |
| 169 | - $globalSources[$id]['format'] = 'vam';  | 
                                                        |
| 170 | -        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; | 
                                                        |
| 171 | -            } else if (preg_match('/whazzup/i',$host)) { | 
                                                        |
| 172 | - //$formats[$id] = 'whazzup';  | 
                                                        |
| 173 | - $globalSources[$id]['format'] = 'whazzup';  | 
                                                        |
| 174 | - //$last_exec['whazzup'] = 0;  | 
                                                        |
| 175 | -        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; | 
                                                        |
| 176 | -            } else if (preg_match('/recentpireps/i',$host)) { | 
                                                        |
| 177 | - //$formats[$id] = 'pirepsjson';  | 
                                                        |
| 178 | - $globalSources[$id]['format'] = 'pirepsjson';  | 
                                                        |
| 179 | - //$last_exec['pirepsjson'] = 0;  | 
                                                        |
| 180 | -        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; | 
                                                        |
| 181 | -            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { | 
                                                        |
| 182 | - //$formats[$id] = 'fr24json';  | 
                                                        |
| 183 | - $globalSources[$id]['format'] = 'fr24json';  | 
                                                        |
| 184 | - //$last_exec['fr24json'] = 0;  | 
                                                        |
| 185 | -        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; | 
                                                        |
| 186 | -        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { | 
                                                        |
| 187 | - echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";  | 
                                                        |
| 188 | - exit(0);  | 
                                                        |
| 189 | - }  | 
                                                        |
| 190 | -            //} else if (preg_match('/10001/',$host)) { | 
                                                        |
| 191 | -            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { | 
                                                        |
| 192 | - //$formats[$id] = 'tsv';  | 
                                                        |
| 193 | - $globalSources[$id]['format'] = 'tsv';  | 
                                                        |
| 194 | -        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; | 
                                                        |
| 195 | - }  | 
                                                        |
| 196 | -        } elseif (filter_var($host,FILTER_VALIDATE_URL)) { | 
                                                        |
| 197 | -        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; | 
                                                        |
| 198 | -        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { | 
                                                        |
| 199 | -	    $hostport = explode(':',$host); | 
                                                        |
| 200 | -	    if (isset($hostport[1])) { | 
                                                        |
| 124 | +			if (preg_match('/deltadb.txt$/i',$host)) { | 
                                                        |
| 125 | + //$formats[$id] = 'deltadbtxt';  | 
                                                        |
| 126 | + $globalSources[$id]['format'] = 'deltadbtxt';  | 
                                                        |
| 127 | + //$last_exec['deltadbtxt'] = 0;  | 
                                                        |
| 128 | +			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; | 
                                                        |
| 129 | +			} else if (preg_match('/vatsim-data.txt$/i',$host)) { | 
                                                        |
| 130 | + //$formats[$id] = 'vatsimtxt';  | 
                                                        |
| 131 | + $globalSources[$id]['format'] = 'vatsimtxt';  | 
                                                        |
| 132 | + //$last_exec['vatsimtxt'] = 0;  | 
                                                        |
| 133 | +			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; | 
                                                        |
| 134 | +			} else if (preg_match('/aircraftlist.json$/i',$host)) { | 
                                                        |
| 135 | + //$formats[$id] = 'aircraftlistjson';  | 
                                                        |
| 136 | + $globalSources[$id]['format'] = 'aircraftlistjson';  | 
                                                        |
| 137 | + //$last_exec['aircraftlistjson'] = 0;  | 
                                                        |
| 138 | +			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; | 
                                                        |
| 139 | +			} else if (preg_match('/opensky/i',$host)) { | 
                                                        |
| 140 | + //$formats[$id] = 'aircraftlistjson';  | 
                                                        |
| 141 | + $globalSources[$id]['format'] = 'opensky';  | 
                                                        |
| 142 | + //$last_exec['aircraftlistjson'] = 0;  | 
                                                        |
| 143 | +			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; | 
                                                        |
| 144 | +			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { | 
                                                        |
| 145 | + //$formats[$id] = 'radarvirtueljson';  | 
                                                        |
| 146 | + $globalSources[$id]['format'] = 'radarvirtueljson';  | 
                                                        |
| 147 | + //$last_exec['radarvirtueljson'] = 0;  | 
                                                        |
| 148 | +			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; | 
                                                        |
| 149 | +			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { | 
                                                        |
| 150 | + echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";  | 
                                                        |
| 151 | + exit(0);  | 
                                                        |
| 152 | + }  | 
                                                        |
| 153 | +			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) { | 
                                                        |
| 154 | + //$formats[$id] = 'planeupdatefaa';  | 
                                                        |
| 155 | + $globalSources[$id]['format'] = 'planeupdatefaa';  | 
                                                        |
| 156 | + //$last_exec['planeupdatefaa'] = 0;  | 
                                                        |
| 157 | +			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; | 
                                                        |
| 158 | +			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { | 
                                                        |
| 159 | + echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";  | 
                                                        |
| 160 | + exit(0);  | 
                                                        |
| 161 | + }  | 
                                                        |
| 162 | +			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) { | 
                                                        |
| 163 | + //$formats[$id] = 'phpvmacars';  | 
                                                        |
| 164 | + $globalSources[$id]['format'] = 'phpvmacars';  | 
                                                        |
| 165 | + //$last_exec['phpvmacars'] = 0;  | 
                                                        |
| 166 | +			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; | 
                                                        |
| 167 | +			} else if (preg_match('/VAM-json.php$/i',$host)) { | 
                                                        |
| 168 | + //$formats[$id] = 'phpvmacars';  | 
                                                        |
| 169 | + $globalSources[$id]['format'] = 'vam';  | 
                                                        |
| 170 | +			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; | 
                                                        |
| 171 | +			} else if (preg_match('/whazzup/i',$host)) { | 
                                                        |
| 172 | + //$formats[$id] = 'whazzup';  | 
                                                        |
| 173 | + $globalSources[$id]['format'] = 'whazzup';  | 
                                                        |
| 174 | + //$last_exec['whazzup'] = 0;  | 
                                                        |
| 175 | +			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; | 
                                                        |
| 176 | +			} else if (preg_match('/recentpireps/i',$host)) { | 
                                                        |
| 177 | + //$formats[$id] = 'pirepsjson';  | 
                                                        |
| 178 | + $globalSources[$id]['format'] = 'pirepsjson';  | 
                                                        |
| 179 | + //$last_exec['pirepsjson'] = 0;  | 
                                                        |
| 180 | +			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; | 
                                                        |
| 181 | +			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { | 
                                                        |
| 182 | + //$formats[$id] = 'fr24json';  | 
                                                        |
| 183 | + $globalSources[$id]['format'] = 'fr24json';  | 
                                                        |
| 184 | + //$last_exec['fr24json'] = 0;  | 
                                                        |
| 185 | +			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; | 
                                                        |
| 186 | +			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { | 
                                                        |
| 187 | + echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";  | 
                                                        |
| 188 | + exit(0);  | 
                                                        |
| 189 | + }  | 
                                                        |
| 190 | +			//} else if (preg_match('/10001/',$host)) { | 
                                                        |
| 191 | +			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { | 
                                                        |
| 192 | + //$formats[$id] = 'tsv';  | 
                                                        |
| 193 | + $globalSources[$id]['format'] = 'tsv';  | 
                                                        |
| 194 | +			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; | 
                                                        |
| 195 | + }  | 
                                                        |
| 196 | +		} elseif (filter_var($host,FILTER_VALIDATE_URL)) { | 
                                                        |
| 197 | +			if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; | 
                                                        |
| 198 | +		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) { | 
                                                        |
| 199 | +		$hostport = explode(':',$host); | 
                                                        |
| 200 | +		if (isset($hostport[1])) { | 
                                                        |
| 201 | 201 | $port = $hostport[1];  | 
                                                        
| 202 | 202 | $hostn = $hostport[0];  | 
                                                        
| 203 | -	    } else { | 
                                                        |
| 203 | +		} else { | 
                                                        |
| 204 | 204 | $port = $globalSources[$id]['port'];  | 
                                                        
| 205 | 205 | $hostn = $globalSources[$id]['host'];  | 
                                                        
| 206 | - }  | 
                                                        |
| 207 | -	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) { | 
                                                        |
| 208 | - $s = create_socket($hostn,$port, $errno, $errstr);  | 
                                                        |
| 209 | -    	    } else { | 
                                                        |
| 210 | - $s = create_socket_udp($hostn,$port, $errno, $errstr);  | 
                                                        |
| 211 | - }  | 
                                                        |
| 212 | -	    if ($s) { | 
                                                        |
| 213 | - $sockets[$id] = $s;  | 
                                                        |
| 214 | -    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') { | 
                                                        |
| 215 | -		    if (preg_match('/aprs/',$hostn)) { | 
                                                        |
| 206 | + }  | 
                                                        |
| 207 | +		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) { | 
                                                        |
| 208 | + $s = create_socket($hostn,$port, $errno, $errstr);  | 
                                                        |
| 209 | +			} else { | 
                                                        |
| 210 | + $s = create_socket_udp($hostn,$port, $errno, $errstr);  | 
                                                        |
| 211 | + }  | 
                                                        |
| 212 | +		if ($s) { | 
                                                        |
| 213 | + $sockets[$id] = $s;  | 
                                                        |
| 214 | +				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') { | 
                                                        |
| 215 | +			if (preg_match('/aprs/',$hostn)) { | 
                                                        |
| 216 | 216 | //$formats[$id] = 'aprs';  | 
                                                        
| 217 | 217 | $globalSources[$id]['format'] = 'aprs';  | 
                                                        
| 218 | 218 | //$aprs_connect = 0;  | 
                                                        
| 219 | 219 | //$use_aprs = true;  | 
                                                        
| 220 | -    		    } elseif ($port == '10001') { | 
                                                        |
| 221 | - //$formats[$id] = 'tsv';  | 
                                                        |
| 222 | - $globalSources[$id]['format'] = 'tsv';  | 
                                                        |
| 223 | -		    } elseif ($port == '30002') { | 
                                                        |
| 224 | - //$formats[$id] = 'raw';  | 
                                                        |
| 225 | - $globalSources[$id]['format'] = 'raw';  | 
                                                        |
| 226 | -		    } elseif ($port == '5001') { | 
                                                        |
| 227 | - //$formats[$id] = 'raw';  | 
                                                        |
| 228 | - $globalSources[$id]['format'] = 'flightgearmp';  | 
                                                        |
| 229 | -		    } elseif ($port == '30005') { | 
                                                        |
| 220 | +				} elseif ($port == '10001') { | 
                                                        |
| 221 | + //$formats[$id] = 'tsv';  | 
                                                        |
| 222 | + $globalSources[$id]['format'] = 'tsv';  | 
                                                        |
| 223 | +			} elseif ($port == '30002') { | 
                                                        |
| 224 | + //$formats[$id] = 'raw';  | 
                                                        |
| 225 | + $globalSources[$id]['format'] = 'raw';  | 
                                                        |
| 226 | +			} elseif ($port == '5001') { | 
                                                        |
| 227 | + //$formats[$id] = 'raw';  | 
                                                        |
| 228 | + $globalSources[$id]['format'] = 'flightgearmp';  | 
                                                        |
| 229 | +			} elseif ($port == '30005') { | 
                                                        |
| 230 | 230 | // Not yet supported  | 
                                                        
| 231 | - //$formats[$id] = 'beast';  | 
                                                        |
| 232 | - $globalSources[$id]['format'] = 'beast';  | 
                                                        |
| 233 | - //} else $formats[$id] = 'sbs';  | 
                                                        |
| 234 | - } else $globalSources[$id]['format'] = 'sbs';  | 
                                                        |
| 235 | -		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; | 
                                                        |
| 231 | + //$formats[$id] = 'beast';  | 
                                                        |
| 232 | + $globalSources[$id]['format'] = 'beast';  | 
                                                        |
| 233 | + //} else $formats[$id] = 'sbs';  | 
                                                        |
| 234 | + } else $globalSources[$id]['format'] = 'sbs';  | 
                                                        |
| 235 | +			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; | 
                                                        |
| 236 | 236 | }  | 
                                                        
| 237 | 237 |  		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; | 
                                                        
| 238 | -            } else { | 
                                                        |
| 238 | +			} else { | 
                                                        |
| 239 | 239 | if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";  | 
                                                        
| 240 | - }  | 
                                                        |
| 241 | - }  | 
                                                        |
| 242 | - }  | 
                                                        |
| 240 | + }  | 
                                                        |
| 241 | + }  | 
                                                        |
| 242 | + }  | 
                                                        |
| 243 | 243 | }  | 
                                                        
| 244 | 244 | if (!isset($globalMinFetch)) $globalMinFetch = 15;  | 
                                                        
| 245 | 245 | |
@@ -266,18 +266,18 @@ discard block  | 
                                                    ||
| 266 | 266 | die;  | 
                                                        
| 267 | 267 | }  | 
                                                        
| 268 | 268 |  foreach ($globalSources as $key => $source) { | 
                                                        
| 269 | -    if (!isset($source['format'])) { | 
                                                        |
| 270 | - $globalSources[$key]['format'] = 'auto';  | 
                                                        |
| 271 | - }  | 
                                                        |
| 269 | +	if (!isset($source['format'])) { | 
                                                        |
| 270 | + $globalSources[$key]['format'] = 'auto';  | 
                                                        |
| 271 | + }  | 
                                                        |
| 272 | 272 | }  | 
                                                        
| 273 | 273 | connect_all($globalSources);  | 
                                                        
| 274 | 274 |  foreach ($globalSources as $key => $source) { | 
                                                        
| 275 | -    if (isset($source['format']) && $source['format'] == 'aprs') { | 
                                                        |
| 275 | +	if (isset($source['format']) && $source['format'] == 'aprs') { | 
                                                        |
| 276 | 276 | $aprs_connect = 0;  | 
                                                        
| 277 | 277 | $use_aprs = true;  | 
                                                        
| 278 | 278 | if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;  | 
                                                        
| 279 | 279 | break;  | 
                                                        
| 280 | - }  | 
                                                        |
| 280 | + }  | 
                                                        |
| 281 | 281 | }  | 
                                                        
| 282 | 282 | |
| 283 | 283 |  if ($use_aprs) { | 
                                                        
@@ -316,70 +316,70 @@ discard block  | 
                                                    ||
| 316 | 316 | |
| 317 | 317 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.  | 
                                                        
| 318 | 318 |  while ($i > 0) { | 
                                                        
| 319 | - if (!$globalDaemon) $i = $endtime-time();  | 
                                                        |
| 320 | - // Delete old ATC  | 
                                                        |
| 321 | -    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { | 
                                                        |
| 319 | + if (!$globalDaemon) $i = $endtime-time();  | 
                                                        |
| 320 | + // Delete old ATC  | 
                                                        |
| 321 | +	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { | 
                                                        |
| 322 | 322 | if ($globalDebug) echo 'Delete old ATC...'."\n";  | 
                                                        
| 323 | - $ATC->deleteOldATC();  | 
                                                        |
| 324 | - }  | 
                                                        |
| 323 | + $ATC->deleteOldATC();  | 
                                                        |
| 324 | + }  | 
                                                        |
| 325 | 325 | |
| 326 | -    if (count($last_exec) > 0) { | 
                                                        |
| 326 | +	if (count($last_exec) > 0) { | 
                                                        |
| 327 | 327 | $max = $globalMinFetch;  | 
                                                        
| 328 | 328 |  	foreach ($last_exec as $last) { | 
                                                        
| 329 | - if ((time() - $last['last']) < $max) $max = time() - $last['last'];  | 
                                                        |
| 329 | + if ((time() - $last['last']) < $max) $max = time() - $last['last'];  | 
                                                        |
| 330 | 330 | }  | 
                                                        
| 331 | 331 |  	if ($max != $globalMinFetch) { | 
                                                        
| 332 | - if ($globalDebug) echo 'Sleeping...'."\n";  | 
                                                        |
| 333 | - sleep($globalMinFetch-$max+2);  | 
                                                        |
| 332 | + if ($globalDebug) echo 'Sleeping...'."\n";  | 
                                                        |
| 333 | + sleep($globalMinFetch-$max+2);  | 
                                                        |
| 334 | + }  | 
                                                        |
| 334 | 335 | }  | 
                                                        
| 335 | - }  | 
                                                        |
| 336 | 336 | |
| 337 | 337 | |
| 338 | -    //foreach ($formats as $id => $value) { | 
                                                        |
| 339 | -    foreach ($globalSources as $id => $value) { | 
                                                        |
| 338 | +	//foreach ($formats as $id => $value) { | 
                                                        |
| 339 | +	foreach ($globalSources as $id => $value) { | 
                                                        |
| 340 | 340 |  	date_default_timezone_set('UTC'); | 
                                                        
| 341 | 341 | if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;  | 
                                                        
| 342 | 342 |  	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        
| 343 | - //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 344 | - $buffer = $Common->getData($value['host']);  | 
                                                        |
| 345 | - if ($buffer != '') $reset = 0;  | 
                                                        |
| 346 | -    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); | 
                                                        |
| 347 | -	    $buffer = explode('\n',$buffer); | 
                                                        |
| 348 | -	    foreach ($buffer as $line) { | 
                                                        |
| 349 | -    		if ($line != '' && count($line) > 7) { | 
                                                        |
| 350 | -    		    $line = explode(',', $line); | 
                                                        |
| 351 | - $data = array();  | 
                                                        |
| 352 | - $data['hex'] = $line[1]; // hex  | 
                                                        |
| 353 | - $data['ident'] = $line[2]; // ident  | 
                                                        |
| 354 | - if (isset($line[3])) $data['altitude'] = $line[3]; // altitude  | 
                                                        |
| 355 | - if (isset($line[4])) $data['speed'] = $line[4]; // speed  | 
                                                        |
| 356 | - if (isset($line[5])) $data['heading'] = $line[5]; // heading  | 
                                                        |
| 357 | - if (isset($line[6])) $data['latitude'] = $line[6]; // lat  | 
                                                        |
| 358 | - if (isset($line[7])) $data['longitude'] = $line[7]; // long  | 
                                                        |
| 359 | - $data['verticalrate'] = ''; // vertical rate  | 
                                                        |
| 360 | - //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk  | 
                                                        |
| 361 | - $data['emergency'] = ''; // emergency  | 
                                                        |
| 362 | -		    $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 363 | - $data['format_source'] = 'deltadbtxt';  | 
                                                        |
| 364 | - $data['id_source'] = $id_source;  | 
                                                        |
| 365 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 366 | - if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];  | 
                                                        |
| 367 | - $SI->add($data);  | 
                                                        |
| 368 | - unset($data);  | 
                                                        |
| 369 | - }  | 
                                                        |
| 370 | - }  | 
                                                        |
| 371 | - $last_exec[$id]['last'] = time();  | 
                                                        |
| 343 | + //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 344 | + $buffer = $Common->getData($value['host']);  | 
                                                        |
| 345 | + if ($buffer != '') $reset = 0;  | 
                                                        |
| 346 | +			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); | 
                                                        |
| 347 | +		$buffer = explode('\n',$buffer); | 
                                                        |
| 348 | +		foreach ($buffer as $line) { | 
                                                        |
| 349 | +			if ($line != '' && count($line) > 7) { | 
                                                        |
| 350 | +				$line = explode(',', $line); | 
                                                        |
| 351 | + $data = array();  | 
                                                        |
| 352 | + $data['hex'] = $line[1]; // hex  | 
                                                        |
| 353 | + $data['ident'] = $line[2]; // ident  | 
                                                        |
| 354 | + if (isset($line[3])) $data['altitude'] = $line[3]; // altitude  | 
                                                        |
| 355 | + if (isset($line[4])) $data['speed'] = $line[4]; // speed  | 
                                                        |
| 356 | + if (isset($line[5])) $data['heading'] = $line[5]; // heading  | 
                                                        |
| 357 | + if (isset($line[6])) $data['latitude'] = $line[6]; // lat  | 
                                                        |
| 358 | + if (isset($line[7])) $data['longitude'] = $line[7]; // long  | 
                                                        |
| 359 | + $data['verticalrate'] = ''; // vertical rate  | 
                                                        |
| 360 | + //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk  | 
                                                        |
| 361 | + $data['emergency'] = ''; // emergency  | 
                                                        |
| 362 | +			$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 363 | + $data['format_source'] = 'deltadbtxt';  | 
                                                        |
| 364 | + $data['id_source'] = $id_source;  | 
                                                        |
| 365 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 366 | + if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];  | 
                                                        |
| 367 | + $SI->add($data);  | 
                                                        |
| 368 | + unset($data);  | 
                                                        |
| 369 | + }  | 
                                                        |
| 370 | + }  | 
                                                        |
| 371 | + $last_exec[$id]['last'] = time();  | 
                                                        |
| 372 | 372 |  	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) { | 
                                                        
| 373 | 373 |  	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) { | 
                                                        
| 374 | - //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 375 | - $buffer = $Common->getData($value['host']);  | 
                                                        |
| 376 | -    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); | 
                                                        |
| 377 | -	    $buffer = explode('\n',$buffer); | 
                                                        |
| 378 | - $reset = 0;  | 
                                                        |
| 379 | -	    foreach ($buffer as $line) { | 
                                                        |
| 380 | -    		if ($line != '') { | 
                                                        |
| 381 | -    		    $line = explode(':', $line); | 
                                                        |
| 382 | -    		    if (count($line) > 30 && $line[0] != 'callsign') { | 
                                                        |
| 374 | + //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 375 | + $buffer = $Common->getData($value['host']);  | 
                                                        |
| 376 | +			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); | 
                                                        |
| 377 | +		$buffer = explode('\n',$buffer); | 
                                                        |
| 378 | + $reset = 0;  | 
                                                        |
| 379 | +		foreach ($buffer as $line) { | 
                                                        |
| 380 | +			if ($line != '') { | 
                                                        |
| 381 | +				$line = explode(':', $line); | 
                                                        |
| 382 | +				if (count($line) > 30 && $line[0] != 'callsign') { | 
                                                        |
| 383 | 383 | $data = array();  | 
                                                        
| 384 | 384 | if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];  | 
                                                        
| 385 | 385 | else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];  | 
                                                        
@@ -392,36 +392,36 @@ discard block  | 
                                                    ||
| 392 | 392 | if (isset($line[45])) $data['heading'] = $line[45]; // heading  | 
                                                        
| 393 | 393 | elseif (isset($line[38])) $data['heading'] = $line[38]; // heading  | 
                                                        
| 394 | 394 | $data['latitude'] = $line[5]; // lat  | 
                                                        
| 395 | - $data['longitude'] = $line[6]; // long  | 
                                                        |
| 396 | - $data['verticalrate'] = ''; // vertical rate  | 
                                                        |
| 397 | - $data['squawk'] = ''; // squawk  | 
                                                        |
| 398 | - $data['emergency'] = ''; // emergency  | 
                                                        |
| 399 | - $data['waypoints'] = $line[30];  | 
                                                        |
| 395 | + $data['longitude'] = $line[6]; // long  | 
                                                        |
| 396 | + $data['verticalrate'] = ''; // vertical rate  | 
                                                        |
| 397 | + $data['squawk'] = ''; // squawk  | 
                                                        |
| 398 | + $data['emergency'] = ''; // emergency  | 
                                                        |
| 399 | + $data['waypoints'] = $line[30];  | 
                                                        |
| 400 | 400 |  			$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        
| 401 | 401 |  			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37])); | 
                                                        
| 402 | 402 | //if (isset($line[37])) $data['last_update'] = $line[37];  | 
                                                        
| 403 | - $data['departure_airport_icao'] = $line[11];  | 
                                                        |
| 404 | - $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');  | 
                                                        |
| 405 | - $data['arrival_airport_icao'] = $line[13];  | 
                                                        |
| 403 | + $data['departure_airport_icao'] = $line[11];  | 
                                                        |
| 404 | + $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');  | 
                                                        |
| 405 | + $data['arrival_airport_icao'] = $line[13];  | 
                                                        |
| 406 | 406 | $data['frequency'] = $line[4];  | 
                                                        
| 407 | 407 | $data['type'] = $line[18];  | 
                                                        
| 408 | 408 | $data['range'] = $line[19];  | 
                                                        
| 409 | 409 | if (isset($line[35])) $data['info'] = $line[35];  | 
                                                        
| 410 | - $data['id_source'] = $id_source;  | 
                                                        |
| 411 | - //$data['arrival_airport_time'] = ;  | 
                                                        |
| 412 | -	    		if ($line[9] != '') { | 
                                                        |
| 413 | -	    		    $aircraft_data = explode('/',$line[9]); | 
                                                        |
| 414 | -	    		    if (isset($aircraft_data[1])) { | 
                                                        |
| 415 | - $data['aircraft_icao'] = $aircraft_data[1];  | 
                                                        |
| 416 | - }  | 
                                                        |
| 417 | - }  | 
                                                        |
| 418 | - /*  | 
                                                        |
| 410 | + $data['id_source'] = $id_source;  | 
                                                        |
| 411 | + //$data['arrival_airport_time'] = ;  | 
                                                        |
| 412 | +				if ($line[9] != '') { | 
                                                        |
| 413 | +					$aircraft_data = explode('/',$line[9]); | 
                                                        |
| 414 | +					if (isset($aircraft_data[1])) { | 
                                                        |
| 415 | + $data['aircraft_icao'] = $aircraft_data[1];  | 
                                                        |
| 416 | + }  | 
                                                        |
| 417 | + }  | 
                                                        |
| 418 | + /*  | 
                                                        |
| 419 | 419 | if ($value == 'whazzup') $data['format_source'] = 'whazzup';  | 
                                                        
| 420 | 420 | elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';  | 
                                                        
| 421 | 421 | */  | 
                                                        
| 422 | - $data['format_source'] = $value['format'];  | 
                                                        |
| 422 | + $data['format_source'] = $value['format'];  | 
                                                        |
| 423 | 423 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        
| 424 | - if ($line[3] == 'PILOT') $SI->add($data);  | 
                                                        |
| 424 | + if ($line[3] == 'PILOT') $SI->add($data);  | 
                                                        |
| 425 | 425 |  			elseif ($line[3] == 'ATC') { | 
                                                        
| 426 | 426 | //print_r($data);  | 
                                                        
| 427 | 427 |  				$data['info'] = str_replace('^§','<br />',$data['info']); | 
                                                        
@@ -439,247 +439,247 @@ discard block  | 
                                                    ||
| 439 | 439 | if (!isset($data['source_name'])) $data['source_name'] = '';  | 
                                                        
| 440 | 440 | if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);  | 
                                                        
| 441 | 441 | }  | 
                                                        
| 442 | - unset($data);  | 
                                                        |
| 443 | - }  | 
                                                        |
| 444 | - }  | 
                                                        |
| 445 | - }  | 
                                                        |
| 446 | - //if ($value == 'whazzup') $last_exec['whazzup'] = time();  | 
                                                        |
| 447 | - //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();  | 
                                                        |
| 448 | - $last_exec[$id]['last'] = time();  | 
                                                        |
| 449 | -    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) { | 
                                                        |
| 450 | -    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 451 | - $buffer = $Common->getData($value['host'],'get','','','','','20');  | 
                                                        |
| 452 | -	    if ($buffer != '') { | 
                                                        |
| 453 | - $all_data = json_decode($buffer,true);  | 
                                                        |
| 454 | -	    if (isset($all_data['acList'])) { | 
                                                        |
| 442 | + unset($data);  | 
                                                        |
| 443 | + }  | 
                                                        |
| 444 | + }  | 
                                                        |
| 445 | + }  | 
                                                        |
| 446 | + //if ($value == 'whazzup') $last_exec['whazzup'] = time();  | 
                                                        |
| 447 | + //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();  | 
                                                        |
| 448 | + $last_exec[$id]['last'] = time();  | 
                                                        |
| 449 | +		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) { | 
                                                        |
| 450 | +		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 451 | + $buffer = $Common->getData($value['host'],'get','','','','','20');  | 
                                                        |
| 452 | +		if ($buffer != '') { | 
                                                        |
| 453 | + $all_data = json_decode($buffer,true);  | 
                                                        |
| 454 | +		if (isset($all_data['acList'])) { | 
                                                        |
| 455 | 455 | $reset = 0;  | 
                                                        
| 456 | 456 |  		foreach ($all_data['acList'] as $line) { | 
                                                        
| 457 | - $data = array();  | 
                                                        |
| 458 | - $data['hex'] = $line['Icao']; // hex  | 
                                                        |
| 459 | - if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident  | 
                                                        |
| 460 | - if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude  | 
                                                        |
| 461 | - if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed  | 
                                                        |
| 462 | - if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading  | 
                                                        |
| 463 | - if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat  | 
                                                        |
| 464 | - if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long  | 
                                                        |
| 465 | - //$data['verticalrate'] = $line['']; // verticale rate  | 
                                                        |
| 466 | - if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk  | 
                                                        |
| 467 | - $data['emergency'] = ''; // emergency  | 
                                                        |
| 468 | - if (isset($line['Reg'])) $data['registration'] = $line['Reg'];  | 
                                                        |
| 469 | - /*  | 
                                                        |
| 457 | + $data = array();  | 
                                                        |
| 458 | + $data['hex'] = $line['Icao']; // hex  | 
                                                        |
| 459 | + if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident  | 
                                                        |
| 460 | + if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude  | 
                                                        |
| 461 | + if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed  | 
                                                        |
| 462 | + if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading  | 
                                                        |
| 463 | + if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat  | 
                                                        |
| 464 | + if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long  | 
                                                        |
| 465 | + //$data['verticalrate'] = $line['']; // verticale rate  | 
                                                        |
| 466 | + if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk  | 
                                                        |
| 467 | + $data['emergency'] = ''; // emergency  | 
                                                        |
| 468 | + if (isset($line['Reg'])) $data['registration'] = $line['Reg'];  | 
                                                        |
| 469 | + /*  | 
                                                        |
| 470 | 470 |  		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000); | 
                                                        
| 471 | 471 |  		    else $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        
| 472 | 472 | */  | 
                                                        
| 473 | -		    $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 474 | - if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];  | 
                                                        |
| 475 | - $data['format_source'] = 'aircraftlistjson';  | 
                                                        |
| 476 | - $data['id_source'] = $id_source;  | 
                                                        |
| 477 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 478 | - if (isset($data['datetime'])) $SI->add($data);  | 
                                                        |
| 479 | - unset($data);  | 
                                                        |
| 473 | +			$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 474 | + if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];  | 
                                                        |
| 475 | + $data['format_source'] = 'aircraftlistjson';  | 
                                                        |
| 476 | + $data['id_source'] = $id_source;  | 
                                                        |
| 477 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 478 | + if (isset($data['datetime'])) $SI->add($data);  | 
                                                        |
| 479 | + unset($data);  | 
                                                        |
| 480 | 480 | }  | 
                                                        
| 481 | -	    } else { | 
                                                        |
| 481 | +		} else { | 
                                                        |
| 482 | 482 | $reset = 0;  | 
                                                        
| 483 | 483 |  		foreach ($all_data as $line) { | 
                                                        
| 484 | - $data = array();  | 
                                                        |
| 485 | - $data['hex'] = $line['hex']; // hex  | 
                                                        |
| 486 | - $data['ident'] = $line['flight']; // ident  | 
                                                        |
| 487 | - $data['altitude'] = $line['altitude']; // altitude  | 
                                                        |
| 488 | - $data['speed'] = $line['speed']; // speed  | 
                                                        |
| 489 | - $data['heading'] = $line['track']; // heading  | 
                                                        |
| 490 | - $data['latitude'] = $line['lat']; // lat  | 
                                                        |
| 491 | - $data['longitude'] = $line['lon']; // long  | 
                                                        |
| 492 | - $data['verticalrate'] = $line['vrt']; // verticale rate  | 
                                                        |
| 493 | - $data['squawk'] = $line['squawk']; // squawk  | 
                                                        |
| 494 | - $data['emergency'] = ''; // emergency  | 
                                                        |
| 495 | -		    $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 496 | - $data['format_source'] = 'aircraftlistjson';  | 
                                                        |
| 497 | - $data['id_source'] = $id_source;  | 
                                                        |
| 498 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 499 | - $SI->add($data);  | 
                                                        |
| 500 | - unset($data);  | 
                                                        |
| 484 | + $data = array();  | 
                                                        |
| 485 | + $data['hex'] = $line['hex']; // hex  | 
                                                        |
| 486 | + $data['ident'] = $line['flight']; // ident  | 
                                                        |
| 487 | + $data['altitude'] = $line['altitude']; // altitude  | 
                                                        |
| 488 | + $data['speed'] = $line['speed']; // speed  | 
                                                        |
| 489 | + $data['heading'] = $line['track']; // heading  | 
                                                        |
| 490 | + $data['latitude'] = $line['lat']; // lat  | 
                                                        |
| 491 | + $data['longitude'] = $line['lon']; // long  | 
                                                        |
| 492 | + $data['verticalrate'] = $line['vrt']; // verticale rate  | 
                                                        |
| 493 | + $data['squawk'] = $line['squawk']; // squawk  | 
                                                        |
| 494 | + $data['emergency'] = ''; // emergency  | 
                                                        |
| 495 | +			$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 496 | + $data['format_source'] = 'aircraftlistjson';  | 
                                                        |
| 497 | + $data['id_source'] = $id_source;  | 
                                                        |
| 498 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 499 | + $SI->add($data);  | 
                                                        |
| 500 | + unset($data);  | 
                                                        |
| 501 | + }  | 
                                                        |
| 501 | 502 | }  | 
                                                        
| 502 | - }  | 
                                                        |
| 503 | - }  | 
                                                        |
| 504 | - //$last_exec['aircraftlistjson'] = time();  | 
                                                        |
| 505 | - $last_exec[$id]['last'] = time();  | 
                                                        |
| 506 | -    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) { | 
                                                        |
| 507 | -    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 508 | - $buffer = $Common->getData($value['host']);  | 
                                                        |
| 509 | - $all_data = json_decode($buffer,true);  | 
                                                        |
| 510 | -	    if (isset($all_data['planes'])) { | 
                                                        |
| 503 | + }  | 
                                                        |
| 504 | + //$last_exec['aircraftlistjson'] = time();  | 
                                                        |
| 505 | + $last_exec[$id]['last'] = time();  | 
                                                        |
| 506 | +		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) { | 
                                                        |
| 507 | +		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 508 | + $buffer = $Common->getData($value['host']);  | 
                                                        |
| 509 | + $all_data = json_decode($buffer,true);  | 
                                                        |
| 510 | +		if (isset($all_data['planes'])) { | 
                                                        |
| 511 | 511 | $reset = 0;  | 
                                                        
| 512 | 512 |  		foreach ($all_data['planes'] as $key => $line) { | 
                                                        
| 513 | - $data = array();  | 
                                                        |
| 514 | - $data['hex'] = $key; // hex  | 
                                                        |
| 515 | - $data['ident'] = $line[3]; // ident  | 
                                                        |
| 516 | - $data['altitude'] = $line[6]; // altitude  | 
                                                        |
| 517 | - $data['speed'] = $line[8]; // speed  | 
                                                        |
| 518 | - $data['heading'] = $line[7]; // heading  | 
                                                        |
| 519 | - $data['latitude'] = $line[4]; // lat  | 
                                                        |
| 520 | - $data['longitude'] = $line[5]; // long  | 
                                                        |
| 521 | - //$data['verticalrate'] = $line[]; // verticale rate  | 
                                                        |
| 522 | - $data['squawk'] = $line[10]; // squawk  | 
                                                        |
| 523 | - $data['emergency'] = ''; // emergency  | 
                                                        |
| 524 | - $data['registration'] = $line[2];  | 
                                                        |
| 525 | - $data['aircraft_icao'] = $line[0];  | 
                                                        |
| 526 | -		    $deparr = explode('-',$line[1]); | 
                                                        |
| 527 | -		    if (count($deparr) == 2) { | 
                                                        |
| 513 | + $data = array();  | 
                                                        |
| 514 | + $data['hex'] = $key; // hex  | 
                                                        |
| 515 | + $data['ident'] = $line[3]; // ident  | 
                                                        |
| 516 | + $data['altitude'] = $line[6]; // altitude  | 
                                                        |
| 517 | + $data['speed'] = $line[8]; // speed  | 
                                                        |
| 518 | + $data['heading'] = $line[7]; // heading  | 
                                                        |
| 519 | + $data['latitude'] = $line[4]; // lat  | 
                                                        |
| 520 | + $data['longitude'] = $line[5]; // long  | 
                                                        |
| 521 | + //$data['verticalrate'] = $line[]; // verticale rate  | 
                                                        |
| 522 | + $data['squawk'] = $line[10]; // squawk  | 
                                                        |
| 523 | + $data['emergency'] = ''; // emergency  | 
                                                        |
| 524 | + $data['registration'] = $line[2];  | 
                                                        |
| 525 | + $data['aircraft_icao'] = $line[0];  | 
                                                        |
| 526 | +			$deparr = explode('-',$line[1]); | 
                                                        |
| 527 | +			if (count($deparr) == 2) { | 
                                                        |
| 528 | 528 | $data['departure_airport_icao'] = $deparr[0];  | 
                                                        
| 529 | 529 | $data['arrival_airport_icao'] = $deparr[1];  | 
                                                        
| 530 | - }  | 
                                                        |
| 531 | -		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]); | 
                                                        |
| 532 | - $data['format_source'] = 'planeupdatefaa';  | 
                                                        |
| 533 | - $data['id_source'] = $id_source;  | 
                                                        |
| 534 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 535 | - $SI->add($data);  | 
                                                        |
| 536 | - unset($data);  | 
                                                        |
| 530 | + }  | 
                                                        |
| 531 | +			$data['datetime'] = date('Y-m-d H:i:s',$line[9]); | 
                                                        |
| 532 | + $data['format_source'] = 'planeupdatefaa';  | 
                                                        |
| 533 | + $data['id_source'] = $id_source;  | 
                                                        |
| 534 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 535 | + $SI->add($data);  | 
                                                        |
| 536 | + unset($data);  | 
                                                        |
| 537 | + }  | 
                                                        |
| 537 | 538 | }  | 
                                                        
| 538 | - }  | 
                                                        |
| 539 | - //$last_exec['planeupdatefaa'] = time();  | 
                                                        |
| 540 | - $last_exec[$id]['last'] = time();  | 
                                                        |
| 541 | -    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 542 | - $buffer = $Common->getData($value['host']);  | 
                                                        |
| 543 | - $all_data = json_decode($buffer,true);  | 
                                                        |
| 544 | -	    if (isset($all_data['states'])) { | 
                                                        |
| 539 | + //$last_exec['planeupdatefaa'] = time();  | 
                                                        |
| 540 | + $last_exec[$id]['last'] = time();  | 
                                                        |
| 541 | +		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 542 | + $buffer = $Common->getData($value['host']);  | 
                                                        |
| 543 | + $all_data = json_decode($buffer,true);  | 
                                                        |
| 544 | +		if (isset($all_data['states'])) { | 
                                                        |
| 545 | 545 | $reset = 0;  | 
                                                        
| 546 | 546 |  		foreach ($all_data['states'] as $key => $line) { | 
                                                        
| 547 | - $data = array();  | 
                                                        |
| 548 | - $data['hex'] = $line[0]; // hex  | 
                                                        |
| 549 | - $data['ident'] = trim($line[1]); // ident  | 
                                                        |
| 550 | - $data['altitude'] = round($line[7]*3.28084); // altitude  | 
                                                        |
| 551 | - $data['speed'] = round($line[9]*1.94384); // speed  | 
                                                        |
| 552 | - $data['heading'] = round($line[10]); // heading  | 
                                                        |
| 553 | - $data['latitude'] = $line[5]; // lat  | 
                                                        |
| 554 | - $data['longitude'] = $line[6]; // long  | 
                                                        |
| 555 | - $data['verticalrate'] = $line[11]; // verticale rate  | 
                                                        |
| 556 | - //$data['squawk'] = $line[10]; // squawk  | 
                                                        |
| 557 | - //$data['emergency'] = ''; // emergency  | 
                                                        |
| 558 | - //$data['registration'] = $line[2];  | 
                                                        |
| 559 | - //$data['aircraft_icao'] = $line[0];  | 
                                                        |
| 560 | -		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]); | 
                                                        |
| 561 | - $data['format_source'] = 'opensky';  | 
                                                        |
| 562 | - $data['id_source'] = $id_source;  | 
                                                        |
| 563 | - $SI->add($data);  | 
                                                        |
| 564 | - unset($data);  | 
                                                        |
| 547 | + $data = array();  | 
                                                        |
| 548 | + $data['hex'] = $line[0]; // hex  | 
                                                        |
| 549 | + $data['ident'] = trim($line[1]); // ident  | 
                                                        |
| 550 | + $data['altitude'] = round($line[7]*3.28084); // altitude  | 
                                                        |
| 551 | + $data['speed'] = round($line[9]*1.94384); // speed  | 
                                                        |
| 552 | + $data['heading'] = round($line[10]); // heading  | 
                                                        |
| 553 | + $data['latitude'] = $line[5]; // lat  | 
                                                        |
| 554 | + $data['longitude'] = $line[6]; // long  | 
                                                        |
| 555 | + $data['verticalrate'] = $line[11]; // verticale rate  | 
                                                        |
| 556 | + //$data['squawk'] = $line[10]; // squawk  | 
                                                        |
| 557 | + //$data['emergency'] = ''; // emergency  | 
                                                        |
| 558 | + //$data['registration'] = $line[2];  | 
                                                        |
| 559 | + //$data['aircraft_icao'] = $line[0];  | 
                                                        |
| 560 | +			$data['datetime'] = date('Y-m-d H:i:s',$line[3]); | 
                                                        |
| 561 | + $data['format_source'] = 'opensky';  | 
                                                        |
| 562 | + $data['id_source'] = $id_source;  | 
                                                        |
| 563 | + $SI->add($data);  | 
                                                        |
| 564 | + unset($data);  | 
                                                        |
| 565 | + }  | 
                                                        |
| 565 | 566 | }  | 
                                                        
| 566 | - }  | 
                                                        |
| 567 | - //$last_exec['planeupdatefaa'] = time();  | 
                                                        |
| 568 | - $last_exec[$id]['last'] = time();  | 
                                                        |
| 569 | -    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) { | 
                                                        |
| 570 | -    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 571 | - //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 572 | - $buffer = $Common->getData($value['host']);  | 
                                                        |
| 573 | - $all_data = json_decode($buffer,true);  | 
                                                        |
| 574 | - if (!empty($all_data)) $reset = 0;  | 
                                                        |
| 575 | -	    foreach ($all_data as $key => $line) { | 
                                                        |
| 567 | + //$last_exec['planeupdatefaa'] = time();  | 
                                                        |
| 568 | + $last_exec[$id]['last'] = time();  | 
                                                        |
| 569 | +		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) { | 
                                                        |
| 570 | +		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 571 | + //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 572 | + $buffer = $Common->getData($value['host']);  | 
                                                        |
| 573 | + $all_data = json_decode($buffer,true);  | 
                                                        |
| 574 | + if (!empty($all_data)) $reset = 0;  | 
                                                        |
| 575 | +		foreach ($all_data as $key => $line) { | 
                                                        |
| 576 | 576 |  		if ($key != 'full_count' && $key != 'version' && $key != 'stats') { | 
                                                        
| 577 | - $data = array();  | 
                                                        |
| 578 | - $data['hex'] = $line[0];  | 
                                                        |
| 579 | - $data['ident'] = $line[16]; //$line[13]  | 
                                                        |
| 580 | - $data['altitude'] = $line[4]; // altitude  | 
                                                        |
| 581 | - $data['speed'] = $line[5]; // speed  | 
                                                        |
| 582 | - $data['heading'] = $line[3]; // heading  | 
                                                        |
| 583 | - $data['latitude'] = $line[1]; // lat  | 
                                                        |
| 584 | - $data['longitude'] = $line[2]; // long  | 
                                                        |
| 585 | - $data['verticalrate'] = $line[15]; // verticale rate  | 
                                                        |
| 586 | - $data['squawk'] = $line[6]; // squawk  | 
                                                        |
| 587 | - $data['aircraft_icao'] = $line[8];  | 
                                                        |
| 588 | - $data['registration'] = $line[9];  | 
                                                        |
| 589 | - $data['departure_airport_iata'] = $line[11];  | 
                                                        |
| 590 | - $data['arrival_airport_iata'] = $line[12];  | 
                                                        |
| 591 | - $data['emergency'] = ''; // emergency  | 
                                                        |
| 592 | -		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] | 
                                                        |
| 593 | - $data['format_source'] = 'fr24json';  | 
                                                        |
| 594 | - $data['id_source'] = $id_source;  | 
                                                        |
| 595 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 596 | - $SI->add($data);  | 
                                                        |
| 597 | - unset($data);  | 
                                                        |
| 577 | + $data = array();  | 
                                                        |
| 578 | + $data['hex'] = $line[0];  | 
                                                        |
| 579 | + $data['ident'] = $line[16]; //$line[13]  | 
                                                        |
| 580 | + $data['altitude'] = $line[4]; // altitude  | 
                                                        |
| 581 | + $data['speed'] = $line[5]; // speed  | 
                                                        |
| 582 | + $data['heading'] = $line[3]; // heading  | 
                                                        |
| 583 | + $data['latitude'] = $line[1]; // lat  | 
                                                        |
| 584 | + $data['longitude'] = $line[2]; // long  | 
                                                        |
| 585 | + $data['verticalrate'] = $line[15]; // verticale rate  | 
                                                        |
| 586 | + $data['squawk'] = $line[6]; // squawk  | 
                                                        |
| 587 | + $data['aircraft_icao'] = $line[8];  | 
                                                        |
| 588 | + $data['registration'] = $line[9];  | 
                                                        |
| 589 | + $data['departure_airport_iata'] = $line[11];  | 
                                                        |
| 590 | + $data['arrival_airport_iata'] = $line[12];  | 
                                                        |
| 591 | + $data['emergency'] = ''; // emergency  | 
                                                        |
| 592 | +			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10] | 
                                                        |
| 593 | + $data['format_source'] = 'fr24json';  | 
                                                        |
| 594 | + $data['id_source'] = $id_source;  | 
                                                        |
| 595 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 596 | + $SI->add($data);  | 
                                                        |
| 597 | + unset($data);  | 
                                                        |
| 598 | + }  | 
                                                        |
| 598 | 599 | }  | 
                                                        
| 599 | - }  | 
                                                        |
| 600 | - //$last_exec['fr24json'] = time();  | 
                                                        |
| 601 | - $last_exec[$id]['last'] = time();  | 
                                                        |
| 602 | -    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) { | 
                                                        |
| 603 | -    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 604 | - //$buffer = $Common->getData($hosts[$id],'get','','','','','150');  | 
                                                        |
| 605 | - $buffer = $Common->getData($value['host'],'get','','','','','150');  | 
                                                        |
| 606 | - //echo $buffer;  | 
                                                        |
| 607 | -	    $buffer = str_replace(array("\n","\r"),"",$buffer); | 
                                                        |
| 608 | -	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer); | 
                                                        |
| 609 | - $all_data = json_decode($buffer,true);  | 
                                                        |
| 610 | -	    if (json_last_error() != JSON_ERROR_NONE) { | 
                                                        |
| 600 | + //$last_exec['fr24json'] = time();  | 
                                                        |
| 601 | + $last_exec[$id]['last'] = time();  | 
                                                        |
| 602 | +		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) { | 
                                                        |
| 603 | +		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 604 | + //$buffer = $Common->getData($hosts[$id],'get','','','','','150');  | 
                                                        |
| 605 | + $buffer = $Common->getData($value['host'],'get','','','','','150');  | 
                                                        |
| 606 | + //echo $buffer;  | 
                                                        |
| 607 | +		$buffer = str_replace(array("\n","\r"),"",$buffer); | 
                                                        |
| 608 | +		$buffer = preg_replace('/,"num":(.+)/','}',$buffer); | 
                                                        |
| 609 | + $all_data = json_decode($buffer,true);  | 
                                                        |
| 610 | +		if (json_last_error() != JSON_ERROR_NONE) { | 
                                                        |
| 611 | 611 | die(json_last_error_msg());  | 
                                                        
| 612 | - }  | 
                                                        |
| 613 | -	    if (isset($all_data['mrkrs'])) { | 
                                                        |
| 612 | + }  | 
                                                        |
| 613 | +		if (isset($all_data['mrkrs'])) { | 
                                                        |
| 614 | 614 | $reset = 0;  | 
                                                        
| 615 | 615 |  		foreach ($all_data['mrkrs'] as $key => $line) { | 
                                                        
| 616 | -		    if (isset($line['inf'])) { | 
                                                        |
| 616 | +			if (isset($line['inf'])) { | 
                                                        |
| 617 | 617 | $data = array();  | 
                                                        
| 618 | 618 | $data['hex'] = $line['inf']['ia'];  | 
                                                        
| 619 | 619 | if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]  | 
                                                        
| 620 | - $data['altitude'] = round($line['inf']['al']*3.28084); // altitude  | 
                                                        |
| 621 | - if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed  | 
                                                        |
| 622 | - if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading  | 
                                                        |
| 623 | - $data['latitude'] = $line['pt'][0]; // lat  | 
                                                        |
| 624 | - $data['longitude'] = $line['pt'][1]; // long  | 
                                                        |
| 625 | - //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate  | 
                                                        |
| 626 | - if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk  | 
                                                        |
| 627 | - //$data['aircraft_icao'] = $line[8];  | 
                                                        |
| 628 | - if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];  | 
                                                        |
| 620 | + $data['altitude'] = round($line['inf']['al']*3.28084); // altitude  | 
                                                        |
| 621 | + if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed  | 
                                                        |
| 622 | + if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading  | 
                                                        |
| 623 | + $data['latitude'] = $line['pt'][0]; // lat  | 
                                                        |
| 624 | + $data['longitude'] = $line['pt'][1]; // long  | 
                                                        |
| 625 | + //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate  | 
                                                        |
| 626 | + if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk  | 
                                                        |
| 627 | + //$data['aircraft_icao'] = $line[8];  | 
                                                        |
| 628 | + if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];  | 
                                                        |
| 629 | 629 | //$data['departure_airport_iata'] = $line[11];  | 
                                                        
| 630 | 630 | //$data['arrival_airport_iata'] = $line[12];  | 
                                                        
| 631 | - //$data['emergency'] = ''; // emergency  | 
                                                        |
| 631 | + //$data['emergency'] = ''; // emergency  | 
                                                        |
| 632 | 632 |  			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] | 
                                                        
| 633 | - $data['format_source'] = 'radarvirtueljson';  | 
                                                        |
| 634 | - $data['id_source'] = $id_source;  | 
                                                        |
| 633 | + $data['format_source'] = 'radarvirtueljson';  | 
                                                        |
| 634 | + $data['id_source'] = $id_source;  | 
                                                        |
| 635 | 635 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        
| 636 | 636 | $SI->add($data);  | 
                                                        
| 637 | 637 | unset($data);  | 
                                                        
| 638 | - }  | 
                                                        |
| 638 | + }  | 
                                                        |
| 639 | + }  | 
                                                        |
| 639 | 640 | }  | 
                                                        
| 640 | - }  | 
                                                        |
| 641 | - //$last_exec['radarvirtueljson'] = time();  | 
                                                        |
| 642 | - $last_exec[$id]['last'] = time();  | 
                                                        |
| 643 | -    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) { | 
                                                        |
| 644 | -    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 645 | - //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 646 | - $buffer = $Common->getData($value['host'].'?'.time());  | 
                                                        |
| 647 | - $all_data = json_decode(utf8_encode($buffer),true);  | 
                                                        |
| 641 | + //$last_exec['radarvirtueljson'] = time();  | 
                                                        |
| 642 | + $last_exec[$id]['last'] = time();  | 
                                                        |
| 643 | +		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) { | 
                                                        |
| 644 | +		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 645 | + //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 646 | + $buffer = $Common->getData($value['host'].'?'.time());  | 
                                                        |
| 647 | + $all_data = json_decode(utf8_encode($buffer),true);  | 
                                                        |
| 648 | 648 | |
| 649 | -	    if (isset($all_data['pireps'])) { | 
                                                        |
| 649 | +		if (isset($all_data['pireps'])) { | 
                                                        |
| 650 | 650 | $reset = 0;  | 
                                                        
| 651 | -	        foreach ($all_data['pireps'] as $line) { | 
                                                        |
| 652 | - $data = array();  | 
                                                        |
| 653 | - $data['id'] = $line['id'];  | 
                                                        |
| 654 | - $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);  | 
                                                        |
| 655 | - $data['ident'] = $line['callsign']; // ident  | 
                                                        |
| 656 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id  | 
                                                        |
| 657 | - if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name  | 
                                                        |
| 658 | - if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude  | 
                                                        |
| 659 | - if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed  | 
                                                        |
| 660 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading  | 
                                                        |
| 661 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route  | 
                                                        |
| 662 | - $data['latitude'] = $line['lat']; // lat  | 
                                                        |
| 663 | - $data['longitude'] = $line['lon']; // long  | 
                                                        |
| 664 | - //$data['verticalrate'] = $line['vrt']; // verticale rate  | 
                                                        |
| 665 | - //$data['squawk'] = $line['squawk']; // squawk  | 
                                                        |
| 666 | - //$data['emergency'] = ''; // emergency  | 
                                                        |
| 667 | - if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];  | 
                                                        |
| 668 | - if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];  | 
                                                        |
| 669 | - if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];  | 
                                                        |
| 670 | - //$data['arrival_airport_time'] = $line['arrtime'];  | 
                                                        |
| 671 | - if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];  | 
                                                        |
| 672 | - if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];  | 
                                                        |
| 673 | - if (isset($line['atis'])) $data['info'] = $line['atis'];  | 
                                                        |
| 674 | - else $data['info'] = '';  | 
                                                        |
| 675 | - $data['format_source'] = 'pireps';  | 
                                                        |
| 676 | - $data['id_source'] = $id_source;  | 
                                                        |
| 677 | -		    $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 678 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 679 | -		    if ($line['icon'] == 'plane') { | 
                                                        |
| 651 | +			foreach ($all_data['pireps'] as $line) { | 
                                                        |
| 652 | + $data = array();  | 
                                                        |
| 653 | + $data['id'] = $line['id'];  | 
                                                        |
| 654 | + $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);  | 
                                                        |
| 655 | + $data['ident'] = $line['callsign']; // ident  | 
                                                        |
| 656 | + if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id  | 
                                                        |
| 657 | + if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name  | 
                                                        |
| 658 | + if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude  | 
                                                        |
| 659 | + if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed  | 
                                                        |
| 660 | + if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading  | 
                                                        |
| 661 | + if (isset($line['route'])) $data['waypoints'] = $line['route']; // route  | 
                                                        |
| 662 | + $data['latitude'] = $line['lat']; // lat  | 
                                                        |
| 663 | + $data['longitude'] = $line['lon']; // long  | 
                                                        |
| 664 | + //$data['verticalrate'] = $line['vrt']; // verticale rate  | 
                                                        |
| 665 | + //$data['squawk'] = $line['squawk']; // squawk  | 
                                                        |
| 666 | + //$data['emergency'] = ''; // emergency  | 
                                                        |
| 667 | + if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];  | 
                                                        |
| 668 | + if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];  | 
                                                        |
| 669 | + if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];  | 
                                                        |
| 670 | + //$data['arrival_airport_time'] = $line['arrtime'];  | 
                                                        |
| 671 | + if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];  | 
                                                        |
| 672 | + if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];  | 
                                                        |
| 673 | + if (isset($line['atis'])) $data['info'] = $line['atis'];  | 
                                                        |
| 674 | + else $data['info'] = '';  | 
                                                        |
| 675 | + $data['format_source'] = 'pireps';  | 
                                                        |
| 676 | + $data['id_source'] = $id_source;  | 
                                                        |
| 677 | +			$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 678 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 679 | +			if ($line['icon'] == 'plane') { | 
                                                        |
| 680 | 680 | $SI->add($data);  | 
                                                        
| 681 | - // print_r($data);  | 
                                                        |
| 682 | -    		    } elseif ($line['icon'] == 'ct') { | 
                                                        |
| 681 | + // print_r($data);  | 
                                                        |
| 682 | +				} elseif ($line['icon'] == 'ct') { | 
                                                        |
| 683 | 683 |  			$data['info'] = str_replace('^§','<br />',$data['info']); | 
                                                        
| 684 | 684 |  			$data['info'] = str_replace('&sect;','',$data['info']); | 
                                                        
| 685 | 685 | $typec = substr($data['ident'],-3);  | 
                                                        
@@ -694,163 +694,163 @@ discard block  | 
                                                    ||
| 694 | 694 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';  | 
                                                        
| 695 | 695 | else $data['type'] = 'Observer';  | 
                                                        
| 696 | 696 | if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);  | 
                                                        
| 697 | - }  | 
                                                        |
| 698 | - unset($data);  | 
                                                        |
| 697 | + }  | 
                                                        |
| 698 | + unset($data);  | 
                                                        |
| 699 | + }  | 
                                                        |
| 699 | 700 | }  | 
                                                        
| 700 | - }  | 
                                                        |
| 701 | - //$last_exec['pirepsjson'] = time();  | 
                                                        |
| 702 | - $last_exec[$id]['last'] = time();  | 
                                                        |
| 703 | -    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) { | 
                                                        |
| 704 | -    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 705 | - //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 706 | - if ($globalDebug) echo 'Get Data...'."\n";  | 
                                                        |
| 707 | - $buffer = $Common->getData($value['host']);  | 
                                                        |
| 708 | - $all_data = json_decode($buffer,true);  | 
                                                        |
| 709 | -	    if ($buffer != '' && is_array($all_data)) { | 
                                                        |
| 701 | + //$last_exec['pirepsjson'] = time();  | 
                                                        |
| 702 | + $last_exec[$id]['last'] = time();  | 
                                                        |
| 703 | +		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) { | 
                                                        |
| 704 | +		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 705 | + //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 706 | + if ($globalDebug) echo 'Get Data...'."\n";  | 
                                                        |
| 707 | + $buffer = $Common->getData($value['host']);  | 
                                                        |
| 708 | + $all_data = json_decode($buffer,true);  | 
                                                        |
| 709 | +		if ($buffer != '' && is_array($all_data)) { | 
                                                        |
| 710 | 710 | $reset = 0;  | 
                                                        
| 711 | 711 |  		foreach ($all_data as $line) { | 
                                                        
| 712 | - $data = array();  | 
                                                        |
| 713 | - //$data['id'] = $line['id']; // id not usable  | 
                                                        |
| 714 | - if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];  | 
                                                        |
| 715 | - $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex  | 
                                                        |
| 716 | - if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];  | 
                                                        |
| 717 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];  | 
                                                        |
| 718 | - $data['ident'] = $line['flightnum']; // ident  | 
                                                        |
| 719 | - $data['altitude'] = $line['alt']; // altitude  | 
                                                        |
| 720 | - $data['speed'] = $line['gs']; // speed  | 
                                                        |
| 721 | - $data['heading'] = $line['heading']; // heading  | 
                                                        |
| 722 | - $data['latitude'] = $line['lat']; // lat  | 
                                                        |
| 723 | - $data['longitude'] = $line['lng']; // long  | 
                                                        |
| 724 | - $data['verticalrate'] = ''; // verticale rate  | 
                                                        |
| 725 | - $data['squawk'] = ''; // squawk  | 
                                                        |
| 726 | - $data['emergency'] = ''; // emergency  | 
                                                        |
| 727 | - //$data['datetime'] = $line['lastupdate'];  | 
                                                        |
| 728 | - $data['last_update'] = $line['lastupdate'];  | 
                                                        |
| 729 | -		    $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 730 | - $data['departure_airport_icao'] = $line['depicao'];  | 
                                                        |
| 731 | - $data['departure_airport_time'] = $line['deptime'];  | 
                                                        |
| 732 | - $data['arrival_airport_icao'] = $line['arricao'];  | 
                                                        |
| 733 | - $data['arrival_airport_time'] = $line['arrtime'];  | 
                                                        |
| 734 | - $data['registration'] = $line['aircraft'];  | 
                                                        |
| 735 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route  | 
                                                        |
| 736 | -		    if (isset($line['aircraftname'])) { | 
                                                        |
| 712 | + $data = array();  | 
                                                        |
| 713 | + //$data['id'] = $line['id']; // id not usable  | 
                                                        |
| 714 | + if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];  | 
                                                        |
| 715 | + $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex  | 
                                                        |
| 716 | + if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];  | 
                                                        |
| 717 | + if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];  | 
                                                        |
| 718 | + $data['ident'] = $line['flightnum']; // ident  | 
                                                        |
| 719 | + $data['altitude'] = $line['alt']; // altitude  | 
                                                        |
| 720 | + $data['speed'] = $line['gs']; // speed  | 
                                                        |
| 721 | + $data['heading'] = $line['heading']; // heading  | 
                                                        |
| 722 | + $data['latitude'] = $line['lat']; // lat  | 
                                                        |
| 723 | + $data['longitude'] = $line['lng']; // long  | 
                                                        |
| 724 | + $data['verticalrate'] = ''; // verticale rate  | 
                                                        |
| 725 | + $data['squawk'] = ''; // squawk  | 
                                                        |
| 726 | + $data['emergency'] = ''; // emergency  | 
                                                        |
| 727 | + //$data['datetime'] = $line['lastupdate'];  | 
                                                        |
| 728 | + $data['last_update'] = $line['lastupdate'];  | 
                                                        |
| 729 | +			$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 730 | + $data['departure_airport_icao'] = $line['depicao'];  | 
                                                        |
| 731 | + $data['departure_airport_time'] = $line['deptime'];  | 
                                                        |
| 732 | + $data['arrival_airport_icao'] = $line['arricao'];  | 
                                                        |
| 733 | + $data['arrival_airport_time'] = $line['arrtime'];  | 
                                                        |
| 734 | + $data['registration'] = $line['aircraft'];  | 
                                                        |
| 735 | + if (isset($line['route'])) $data['waypoints'] = $line['route']; // route  | 
                                                        |
| 736 | +			if (isset($line['aircraftname'])) { | 
                                                        |
| 737 | 737 | $line['aircraftname'] = strtoupper($line['aircraftname']);  | 
                                                        
| 738 | 738 |  			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); | 
                                                        
| 739 | -	    		$aircraft_data = explode('-',$line['aircraftname']); | 
                                                        |
| 740 | - if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];  | 
                                                        |
| 741 | - elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];  | 
                                                        |
| 742 | -	    		else { | 
                                                        |
| 743 | -	    		    $aircraft_data = explode(' ',$line['aircraftname']); | 
                                                        |
| 744 | - if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];  | 
                                                        |
| 745 | - else $data['aircraft_icao'] = $line['aircraftname'];  | 
                                                        |
| 746 | - }  | 
                                                        |
| 747 | - }  | 
                                                        |
| 748 | - if (isset($line['route'])) $data['waypoints'] = $line['route'];  | 
                                                        |
| 749 | - $data['id_source'] = $id_source;  | 
                                                        |
| 750 | - $data['format_source'] = 'phpvmacars';  | 
                                                        |
| 751 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 752 | - $SI->add($data);  | 
                                                        |
| 753 | - unset($data);  | 
                                                        |
| 739 | +				$aircraft_data = explode('-',$line['aircraftname']); | 
                                                        |
| 740 | + if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];  | 
                                                        |
| 741 | + elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];  | 
                                                        |
| 742 | +				else { | 
                                                        |
| 743 | +					$aircraft_data = explode(' ',$line['aircraftname']); | 
                                                        |
| 744 | + if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];  | 
                                                        |
| 745 | + else $data['aircraft_icao'] = $line['aircraftname'];  | 
                                                        |
| 746 | + }  | 
                                                        |
| 747 | + }  | 
                                                        |
| 748 | + if (isset($line['route'])) $data['waypoints'] = $line['route'];  | 
                                                        |
| 749 | + $data['id_source'] = $id_source;  | 
                                                        |
| 750 | + $data['format_source'] = 'phpvmacars';  | 
                                                        |
| 751 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 752 | + $SI->add($data);  | 
                                                        |
| 753 | + unset($data);  | 
                                                        |
| 754 | 754 | }  | 
                                                        
| 755 | 755 | if ($globalDebug) echo 'No more data...'."\n";  | 
                                                        
| 756 | 756 | unset($buffer);  | 
                                                        
| 757 | 757 | unset($all_data);  | 
                                                        
| 758 | - }  | 
                                                        |
| 759 | - //$last_exec['phpvmacars'] = time();  | 
                                                        |
| 760 | - $last_exec[$id]['last'] = time();  | 
                                                        |
| 761 | -    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 762 | - //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 763 | - if ($globalDebug) echo 'Get Data...'."\n";  | 
                                                        |
| 764 | - $buffer = $Common->getData($value['host']);  | 
                                                        |
| 765 | - $all_data = json_decode($buffer,true);  | 
                                                        |
| 766 | -	    if ($buffer != '' && is_array($all_data)) { | 
                                                        |
| 758 | + }  | 
                                                        |
| 759 | + //$last_exec['phpvmacars'] = time();  | 
                                                        |
| 760 | + $last_exec[$id]['last'] = time();  | 
                                                        |
| 761 | +		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        |
| 762 | + //$buffer = $Common->getData($hosts[$id]);  | 
                                                        |
| 763 | + if ($globalDebug) echo 'Get Data...'."\n";  | 
                                                        |
| 764 | + $buffer = $Common->getData($value['host']);  | 
                                                        |
| 765 | + $all_data = json_decode($buffer,true);  | 
                                                        |
| 766 | +		if ($buffer != '' && is_array($all_data)) { | 
                                                        |
| 767 | 767 | $reset = 0;  | 
                                                        
| 768 | 768 |  		foreach ($all_data as $line) { | 
                                                        
| 769 | - $data = array();  | 
                                                        |
| 770 | - //$data['id'] = $line['id']; // id not usable  | 
                                                        |
| 771 | - $data['id'] = trim($line['flight_id']);  | 
                                                        |
| 772 | - $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex  | 
                                                        |
| 773 | - $data['pilot_name'] = $line['pilot_name'];  | 
                                                        |
| 774 | - $data['pilot_id'] = $line['pilot_id'];  | 
                                                        |
| 775 | - $data['ident'] = trim($line['callsign']); // ident  | 
                                                        |
| 776 | - $data['altitude'] = $line['altitude']; // altitude  | 
                                                        |
| 777 | - $data['speed'] = $line['gs']; // speed  | 
                                                        |
| 778 | - $data['heading'] = $line['heading']; // heading  | 
                                                        |
| 779 | - $data['latitude'] = $line['latitude']; // lat  | 
                                                        |
| 780 | - $data['longitude'] = $line['longitude']; // long  | 
                                                        |
| 781 | - $data['verticalrate'] = ''; // verticale rate  | 
                                                        |
| 782 | - $data['squawk'] = ''; // squawk  | 
                                                        |
| 783 | - $data['emergency'] = ''; // emergency  | 
                                                        |
| 784 | - //$data['datetime'] = $line['lastupdate'];  | 
                                                        |
| 785 | - $data['last_update'] = $line['last_update'];  | 
                                                        |
| 786 | -		    $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 787 | - $data['departure_airport_icao'] = $line['departure'];  | 
                                                        |
| 788 | - //$data['departure_airport_time'] = $line['departure_time'];  | 
                                                        |
| 789 | - $data['arrival_airport_icao'] = $line['arrival'];  | 
                                                        |
| 790 | - //$data['arrival_airport_time'] = $line['arrival_time'];  | 
                                                        |
| 791 | - //$data['registration'] = $line['aircraft'];  | 
                                                        |
| 792 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route  | 
                                                        |
| 793 | - $data['aircraft_icao'] = $line['plane_type'];  | 
                                                        |
| 794 | - $data['id_source'] = $id_source;  | 
                                                        |
| 795 | - $data['format_source'] = 'vam';  | 
                                                        |
| 796 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 797 | - $SI->add($data);  | 
                                                        |
| 798 | - unset($data);  | 
                                                        |
| 769 | + $data = array();  | 
                                                        |
| 770 | + //$data['id'] = $line['id']; // id not usable  | 
                                                        |
| 771 | + $data['id'] = trim($line['flight_id']);  | 
                                                        |
| 772 | + $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex  | 
                                                        |
| 773 | + $data['pilot_name'] = $line['pilot_name'];  | 
                                                        |
| 774 | + $data['pilot_id'] = $line['pilot_id'];  | 
                                                        |
| 775 | + $data['ident'] = trim($line['callsign']); // ident  | 
                                                        |
| 776 | + $data['altitude'] = $line['altitude']; // altitude  | 
                                                        |
| 777 | + $data['speed'] = $line['gs']; // speed  | 
                                                        |
| 778 | + $data['heading'] = $line['heading']; // heading  | 
                                                        |
| 779 | + $data['latitude'] = $line['latitude']; // lat  | 
                                                        |
| 780 | + $data['longitude'] = $line['longitude']; // long  | 
                                                        |
| 781 | + $data['verticalrate'] = ''; // verticale rate  | 
                                                        |
| 782 | + $data['squawk'] = ''; // squawk  | 
                                                        |
| 783 | + $data['emergency'] = ''; // emergency  | 
                                                        |
| 784 | + //$data['datetime'] = $line['lastupdate'];  | 
                                                        |
| 785 | + $data['last_update'] = $line['last_update'];  | 
                                                        |
| 786 | +			$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 787 | + $data['departure_airport_icao'] = $line['departure'];  | 
                                                        |
| 788 | + //$data['departure_airport_time'] = $line['departure_time'];  | 
                                                        |
| 789 | + $data['arrival_airport_icao'] = $line['arrival'];  | 
                                                        |
| 790 | + //$data['arrival_airport_time'] = $line['arrival_time'];  | 
                                                        |
| 791 | + //$data['registration'] = $line['aircraft'];  | 
                                                        |
| 792 | + if (isset($line['route'])) $data['waypoints'] = $line['route']; // route  | 
                                                        |
| 793 | + $data['aircraft_icao'] = $line['plane_type'];  | 
                                                        |
| 794 | + $data['id_source'] = $id_source;  | 
                                                        |
| 795 | + $data['format_source'] = 'vam';  | 
                                                        |
| 796 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 797 | + $SI->add($data);  | 
                                                        |
| 798 | + unset($data);  | 
                                                        |
| 799 | 799 | }  | 
                                                        
| 800 | 800 | if ($globalDebug) echo 'No more data...'."\n";  | 
                                                        
| 801 | 801 | unset($buffer);  | 
                                                        
| 802 | 802 | unset($all_data);  | 
                                                        
| 803 | - }  | 
                                                        |
| 804 | - //$last_exec['phpvmacars'] = time();  | 
                                                        |
| 805 | - $last_exec[$id]['last'] = time();  | 
                                                        |
| 803 | + }  | 
                                                        |
| 804 | + //$last_exec['phpvmacars'] = time();  | 
                                                        |
| 805 | + $last_exec[$id]['last'] = time();  | 
                                                        |
| 806 | 806 |  	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') { | 
                                                        
| 807 | 807 |  	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3') { | 
                                                        
| 808 | -	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); | 
                                                        |
| 809 | - //$last_exec[$id]['last'] = time();  | 
                                                        |
| 808 | +		if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); | 
                                                        |
| 809 | + //$last_exec[$id]['last'] = time();  | 
                                                        |
| 810 | 810 | |
| 811 | - //$read = array( $sockets[$id] );  | 
                                                        |
| 812 | - $read = $sockets;  | 
                                                        |
| 813 | - $write = NULL;  | 
                                                        |
| 814 | - $e = NULL;  | 
                                                        |
| 815 | - $n = socket_select($read, $write, $e, $timeout);  | 
                                                        |
| 816 | - if ($e != NULL) var_dump($e);  | 
                                                        |
| 817 | -	    if ($n > 0) { | 
                                                        |
| 811 | + //$read = array( $sockets[$id] );  | 
                                                        |
| 812 | + $read = $sockets;  | 
                                                        |
| 813 | + $write = NULL;  | 
                                                        |
| 814 | + $e = NULL;  | 
                                                        |
| 815 | + $n = socket_select($read, $write, $e, $timeout);  | 
                                                        |
| 816 | + if ($e != NULL) var_dump($e);  | 
                                                        |
| 817 | +		if ($n > 0) { | 
                                                        |
| 818 | 818 | $reset = 0;  | 
                                                        
| 819 | 819 |  		foreach ($read as $nb => $r) { | 
                                                        
| 820 | - //$value = $formats[$nb];  | 
                                                        |
| 821 | - $format = $globalSources[$nb]['format'];  | 
                                                        |
| 822 | -        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') { | 
                                                        |
| 823 | - $buffer = socket_read($r, 6000,PHP_NORMAL_READ);  | 
                                                        |
| 824 | -        	    } else { | 
                                                        |
| 825 | - $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);  | 
                                                        |
| 826 | - }  | 
                                                        |
| 827 | - //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);  | 
                                                        |
| 828 | - //echo $buffer."\n";  | 
                                                        |
| 829 | - // lets play nice and handle signals such as ctrl-c/kill properly  | 
                                                        |
| 830 | -		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); | 
                                                        |
| 831 | - $error = false;  | 
                                                        |
| 832 | - //$SI::del();  | 
                                                        |
| 833 | -		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); | 
                                                        |
| 834 | - // SBS format is CSV format  | 
                                                        |
| 835 | -		    if ($buffer != '') { | 
                                                        |
| 820 | + //$value = $formats[$nb];  | 
                                                        |
| 821 | + $format = $globalSources[$nb]['format'];  | 
                                                        |
| 822 | +				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') { | 
                                                        |
| 823 | + $buffer = socket_read($r, 6000,PHP_NORMAL_READ);  | 
                                                        |
| 824 | +				} else { | 
                                                        |
| 825 | + $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);  | 
                                                        |
| 826 | + }  | 
                                                        |
| 827 | + //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);  | 
                                                        |
| 828 | + //echo $buffer."\n";  | 
                                                        |
| 829 | + // lets play nice and handle signals such as ctrl-c/kill properly  | 
                                                        |
| 830 | +			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); | 
                                                        |
| 831 | + $error = false;  | 
                                                        |
| 832 | + //$SI::del();  | 
                                                        |
| 833 | +			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); | 
                                                        |
| 834 | + // SBS format is CSV format  | 
                                                        |
| 835 | +			if ($buffer != '') { | 
                                                        |
| 836 | 836 | $tt[$format] = 0;  | 
                                                        
| 837 | 837 |  			if ($format == 'acarssbs3') { | 
                                                        
| 838 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n";  | 
                                                        |
| 839 | - $ACARS->add(trim($buffer));  | 
                                                        |
| 840 | - $ACARS->deleteLiveAcarsData();  | 
                                                        |
| 838 | + if ($globalDebug) echo 'ACARS : '.$buffer."\n";  | 
                                                        |
| 839 | + $ACARS->add(trim($buffer));  | 
                                                        |
| 840 | + $ACARS->deleteLiveAcarsData();  | 
                                                        |
| 841 | 841 |  			} elseif ($format == 'raw') { | 
                                                        
| 842 | - // AVR format  | 
                                                        |
| 843 | - $data = $SBS->parse($buffer);  | 
                                                        |
| 844 | -			    if (is_array($data)) { | 
                                                        |
| 842 | + // AVR format  | 
                                                        |
| 843 | + $data = $SBS->parse($buffer);  | 
                                                        |
| 844 | +				if (is_array($data)) { | 
                                                        |
| 845 | 845 |  				$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        
| 846 | 846 | $data['format_source'] = 'raw';  | 
                                                        
| 847 | 847 | if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];  | 
                                                        
| 848 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 849 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);  | 
                                                        |
| 850 | - }  | 
                                                        |
| 851 | -                        } elseif ($format == 'flightgearsp') { | 
                                                        |
| 852 | - //echo $buffer."\n";  | 
                                                        |
| 853 | -                    	    if (strlen($buffer) > 5) { | 
                                                        |
| 848 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 849 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);  | 
                                                        |
| 850 | + }  | 
                                                        |
| 851 | +						} elseif ($format == 'flightgearsp') { | 
                                                        |
| 852 | + //echo $buffer."\n";  | 
                                                        |
| 853 | +							if (strlen($buffer) > 5) { | 
                                                        |
| 854 | 854 |  				$line = explode(',',$buffer); | 
                                                        
| 855 | 855 | $data = array();  | 
                                                        
| 856 | 856 | //XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p  | 
                                                        
@@ -866,124 +866,124 @@ discard block  | 
                                                    ||
| 866 | 866 | $data['format_source'] = 'flightgearsp';  | 
                                                        
| 867 | 867 | if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);  | 
                                                        
| 868 | 868 | $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 );  | 
                                                        
| 869 | - }  | 
                                                        |
| 870 | -                        } elseif ($format == 'acars') { | 
                                                        |
| 871 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n";  | 
                                                        |
| 872 | - $ACARS->add(trim($buffer));  | 
                                                        |
| 873 | - socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);  | 
                                                        |
| 874 | - $ACARS->deleteLiveAcarsData();  | 
                                                        |
| 869 | + }  | 
                                                        |
| 870 | +						} elseif ($format == 'acars') { | 
                                                        |
| 871 | + if ($globalDebug) echo 'ACARS : '.$buffer."\n";  | 
                                                        |
| 872 | + $ACARS->add(trim($buffer));  | 
                                                        |
| 873 | + socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);  | 
                                                        |
| 874 | + $ACARS->deleteLiveAcarsData();  | 
                                                        |
| 875 | 875 |  			} elseif ($format == 'flightgearmp') { | 
                                                        
| 876 | -			    if (substr($buffer,0,1) != '#') { | 
                                                        |
| 876 | +				if (substr($buffer,0,1) != '#') { | 
                                                        |
| 877 | 877 | $data = array();  | 
                                                        
| 878 | 878 | //echo $buffer."\n";  | 
                                                        
| 879 | 879 |  				$line = explode(' ',$buffer); | 
                                                        
| 880 | 880 |  				if (count($line) == 11) { | 
                                                        
| 881 | -				    $userserver = explode('@',$line[0]); | 
                                                        |
| 882 | - $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex  | 
                                                        |
| 883 | - $data['ident'] = $userserver[0];  | 
                                                        |
| 884 | - $data['registration'] = $userserver[0];  | 
                                                        |
| 885 | - $data['latitude'] = $line[4];  | 
                                                        |
| 886 | - $data['longitude'] = $line[5];  | 
                                                        |
| 887 | - $data['altitude'] = $line[6];  | 
                                                        |
| 888 | -				    $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 889 | - $aircraft_type = $line[10];  | 
                                                        |
| 890 | -				    $aircraft_type = preg_split(':/:',$aircraft_type); | 
                                                        |
| 891 | - $data['aircraft_name'] = substr(end($aircraft_type),0,-4);  | 
                                                        |
| 892 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);  | 
                                                        |
| 881 | +					$userserver = explode('@',$line[0]); | 
                                                        |
| 882 | + $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex  | 
                                                        |
| 883 | + $data['ident'] = $userserver[0];  | 
                                                        |
| 884 | + $data['registration'] = $userserver[0];  | 
                                                        |
| 885 | + $data['latitude'] = $line[4];  | 
                                                        |
| 886 | + $data['longitude'] = $line[5];  | 
                                                        |
| 887 | + $data['altitude'] = $line[6];  | 
                                                        |
| 888 | +					$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 889 | + $aircraft_type = $line[10];  | 
                                                        |
| 890 | +					$aircraft_type = preg_split(':/:',$aircraft_type); | 
                                                        |
| 891 | + $data['aircraft_name'] = substr(end($aircraft_type),0,-4);  | 
                                                        |
| 892 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);  | 
                                                        |
| 893 | + }  | 
                                                        |
| 893 | 894 | }  | 
                                                        
| 894 | - }  | 
                                                        |
| 895 | 895 |  			} elseif ($format == 'beast') { | 
                                                        
| 896 | - echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";  | 
                                                        |
| 897 | - die;  | 
                                                        |
| 896 | + echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";  | 
                                                        |
| 897 | + die;  | 
                                                        |
| 898 | 898 |  			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') { | 
                                                        
| 899 | -			    $line = explode("\t", $buffer); | 
                                                        |
| 900 | -			    for($k = 0; $k < count($line); $k=$k+2) { | 
                                                        |
| 899 | +				$line = explode("\t", $buffer); | 
                                                        |
| 900 | +				for($k = 0; $k < count($line); $k=$k+2) { | 
                                                        |
| 901 | 901 | $key = $line[$k];  | 
                                                        
| 902 | - $lined[$key] = $line[$k+1];  | 
                                                        |
| 903 | - }  | 
                                                        |
| 904 | -    			    if (count($lined) > 3) { | 
                                                        |
| 905 | - $data['hex'] = $lined['hexid'];  | 
                                                        |
| 906 | -    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; | 
                                                        |
| 907 | -    				$data['datetime'] = date('Y-m-d H:i:s');; | 
                                                        |
| 908 | - if (isset($lined['ident'])) $data['ident'] = $lined['ident'];  | 
                                                        |
| 909 | - if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];  | 
                                                        |
| 910 | - if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];  | 
                                                        |
| 911 | - if (isset($lined['speed'])) $data['speed'] = $lined['speed'];  | 
                                                        |
| 912 | - if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];  | 
                                                        |
| 913 | - if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];  | 
                                                        |
| 914 | - if (isset($lined['heading'])) $data['heading'] = $lined['heading'];  | 
                                                        |
| 915 | - $data['id_source'] = $id_source;  | 
                                                        |
| 916 | - $data['format_source'] = 'tsv';  | 
                                                        |
| 917 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];  | 
                                                        |
| 918 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 919 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);  | 
                                                        |
| 920 | - unset($lined);  | 
                                                        |
| 921 | - unset($data);  | 
                                                        |
| 922 | - } else $error = true;  | 
                                                        |
| 902 | + $lined[$key] = $line[$k+1];  | 
                                                        |
| 903 | + }  | 
                                                        |
| 904 | +					if (count($lined) > 3) { | 
                                                        |
| 905 | + $data['hex'] = $lined['hexid'];  | 
                                                        |
| 906 | +					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; | 
                                                        |
| 907 | +					$data['datetime'] = date('Y-m-d H:i:s');; | 
                                                        |
| 908 | + if (isset($lined['ident'])) $data['ident'] = $lined['ident'];  | 
                                                        |
| 909 | + if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];  | 
                                                        |
| 910 | + if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];  | 
                                                        |
| 911 | + if (isset($lined['speed'])) $data['speed'] = $lined['speed'];  | 
                                                        |
| 912 | + if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];  | 
                                                        |
| 913 | + if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];  | 
                                                        |
| 914 | + if (isset($lined['heading'])) $data['heading'] = $lined['heading'];  | 
                                                        |
| 915 | + $data['id_source'] = $id_source;  | 
                                                        |
| 916 | + $data['format_source'] = 'tsv';  | 
                                                        |
| 917 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];  | 
                                                        |
| 918 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 919 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);  | 
                                                        |
| 920 | + unset($lined);  | 
                                                        |
| 921 | + unset($data);  | 
                                                        |
| 922 | + } else $error = true;  | 
                                                        |
| 923 | 923 |  			} elseif ($format == 'aprs' && $use_aprs) { | 
                                                        
| 924 | -			    if ($aprs_connect == 0) { | 
                                                        |
| 924 | +				if ($aprs_connect == 0) { | 
                                                        |
| 925 | 925 | $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 );  | 
                                                        
| 926 | 926 | $aprs_connect = 1;  | 
                                                        
| 927 | - }  | 
                                                        |
| 927 | + }  | 
                                                        |
| 928 | 928 | |
| 929 | -			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) { | 
                                                        |
| 929 | +				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) { | 
                                                        |
| 930 | 930 | $aprs_last_tx = time();  | 
                                                        
| 931 | 931 | $data_aprs = "# Keep alive";  | 
                                                        
| 932 | 932 | $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 );  | 
                                                        
| 933 | - }  | 
                                                        |
| 933 | + }  | 
                                                        |
| 934 | 934 | |
| 935 | - //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";  | 
                                                        |
| 936 | -			    $buffer = str_replace('APRS <- ','',$buffer); | 
                                                        |
| 937 | -			    $buffer = str_replace('APRS -> ','',$buffer); | 
                                                        |
| 938 | - //echo $buffer."\n";  | 
                                                        |
| 939 | -			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') { | 
                                                        |
| 935 | + //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";  | 
                                                        |
| 936 | +				$buffer = str_replace('APRS <- ','',$buffer); | 
                                                        |
| 937 | +				$buffer = str_replace('APRS -> ','',$buffer); | 
                                                        |
| 938 | + //echo $buffer."\n";  | 
                                                        |
| 939 | +				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') { | 
                                                        |
| 940 | 940 | $line = $APRS->parse($buffer);  | 
                                                        
| 941 | 941 | //print_r($line);  | 
                                                        
| 942 | 942 |  				if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) { | 
                                                        
| 943 | - $aprs_last_tx = time();  | 
                                                        |
| 944 | - $data = array();  | 
                                                        |
| 945 | - //print_r($line);  | 
                                                        |
| 946 | - $data['hex'] = $line['address'];  | 
                                                        |
| 947 | -				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); | 
                                                        |
| 948 | -				    else $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 949 | -				    //$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 950 | - $data['ident'] = $line['ident'];  | 
                                                        |
| 951 | - $data['latitude'] = $line['latitude'];  | 
                                                        |
| 952 | - $data['longitude'] = $line['longitude'];  | 
                                                        |
| 953 | - //$data['verticalrate'] = $line[16];  | 
                                                        |
| 954 | - if (isset($line['speed'])) $data['speed'] = $line['speed'];  | 
                                                        |
| 955 | - else $data['speed'] = 0;  | 
                                                        |
| 956 | - $data['altitude'] = $line['altitude'];  | 
                                                        |
| 957 | - if (isset($line['heading'])) $data['heading'] = $line['heading'];  | 
                                                        |
| 958 | - //else $data['heading'] = 0;  | 
                                                        |
| 959 | - $data['aircraft_type'] = $line['stealth'];  | 
                                                        |
| 960 | - if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;  | 
                                                        |
| 961 | - $data['id_source'] = $id_source;  | 
                                                        |
| 962 | - $data['format_source'] = 'aprs';  | 
                                                        |
| 963 | - $data['source_name'] = $line['source'];  | 
                                                        |
| 964 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 965 | -				    $currentdate = date('Y-m-d H:i:s'); | 
                                                        |
| 966 | - $aprsdate = strtotime($data['datetime']);  | 
                                                        |
| 967 | - // Accept data if time <= system time + 20s  | 
                                                        |
| 968 | -				    if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { | 
                                                        |
| 943 | + $aprs_last_tx = time();  | 
                                                        |
| 944 | + $data = array();  | 
                                                        |
| 945 | + //print_r($line);  | 
                                                        |
| 946 | + $data['hex'] = $line['address'];  | 
                                                        |
| 947 | +					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); | 
                                                        |
| 948 | +					else $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 949 | +					//$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 950 | + $data['ident'] = $line['ident'];  | 
                                                        |
| 951 | + $data['latitude'] = $line['latitude'];  | 
                                                        |
| 952 | + $data['longitude'] = $line['longitude'];  | 
                                                        |
| 953 | + //$data['verticalrate'] = $line[16];  | 
                                                        |
| 954 | + if (isset($line['speed'])) $data['speed'] = $line['speed'];  | 
                                                        |
| 955 | + else $data['speed'] = 0;  | 
                                                        |
| 956 | + $data['altitude'] = $line['altitude'];  | 
                                                        |
| 957 | + if (isset($line['heading'])) $data['heading'] = $line['heading'];  | 
                                                        |
| 958 | + //else $data['heading'] = 0;  | 
                                                        |
| 959 | + $data['aircraft_type'] = $line['stealth'];  | 
                                                        |
| 960 | + if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;  | 
                                                        |
| 961 | + $data['id_source'] = $id_source;  | 
                                                        |
| 962 | + $data['format_source'] = 'aprs';  | 
                                                        |
| 963 | + $data['source_name'] = $line['source'];  | 
                                                        |
| 964 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 965 | +					$currentdate = date('Y-m-d H:i:s'); | 
                                                        |
| 966 | + $aprsdate = strtotime($data['datetime']);  | 
                                                        |
| 967 | + // Accept data if time <= system time + 20s  | 
                                                        |
| 968 | +					if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { | 
                                                        |
| 969 | 969 | $send = $SI->add($data);  | 
                                                        
| 970 | -				    } else { | 
                                                        |
| 970 | +					} else { | 
                                                        |
| 971 | 971 | if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";  | 
                                                        
| 972 | 972 | else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";  | 
                                                        
| 973 | - }  | 
                                                        |
| 974 | - unset($data);  | 
                                                        |
| 973 | + }  | 
                                                        |
| 974 | + unset($data);  | 
                                                        |
| 975 | 975 | }  | 
                                                        
| 976 | 976 |  				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { | 
                                                        
| 977 | 977 | echo '!! Weather Station not yet supported'."\n";  | 
                                                        
| 978 | 978 | }  | 
                                                        
| 979 | 979 |  				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n"; | 
                                                        
| 980 | 980 | //elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";  | 
                                                        
| 981 | - }  | 
                                                        |
| 981 | + }  | 
                                                        |
| 982 | 982 |  			} else { | 
                                                        
| 983 | -			    $line = explode(',', $buffer); | 
                                                        |
| 984 | -    			    if (count($line) > 20) { | 
                                                        |
| 985 | - $data['hex'] = $line[4];  | 
                                                        |
| 986 | - /*  | 
                                                        |
| 983 | +				$line = explode(',', $buffer); | 
                                                        |
| 984 | +					if (count($line) > 20) { | 
                                                        |
| 985 | + $data['hex'] = $line[4];  | 
                                                        |
| 986 | + /*  | 
                                                        |
| 987 | 987 | $data['datetime'] = $line[6].' '.$line[7];  | 
                                                        
| 988 | 988 | date_default_timezone_set($globalTimezone);  | 
                                                        
| 989 | 989 | $datetime = new DateTime($data['datetime']);  | 
                                                        
@@ -991,29 +991,29 @@ discard block  | 
                                                    ||
| 991 | 991 |      					$data['datetime'] = $datetime->format('Y-m-d H:i:s'); | 
                                                        
| 992 | 992 |      					date_default_timezone_set('UTC'); | 
                                                        
| 993 | 993 | */  | 
                                                        
| 994 | - // Force datetime to current UTC datetime  | 
                                                        |
| 995 | -    				date_default_timezone_set('UTC'); | 
                                                        |
| 996 | -    				$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 997 | - $data['ident'] = trim($line[10]);  | 
                                                        |
| 998 | - $data['latitude'] = $line[14];  | 
                                                        |
| 999 | - $data['longitude'] = $line[15];  | 
                                                        |
| 1000 | - $data['verticalrate'] = $line[16];  | 
                                                        |
| 1001 | - $data['emergency'] = $line[20];  | 
                                                        |
| 1002 | - $data['speed'] = $line[12];  | 
                                                        |
| 1003 | - $data['squawk'] = $line[17];  | 
                                                        |
| 1004 | - $data['altitude'] = $line[11];  | 
                                                        |
| 1005 | - $data['heading'] = $line[13];  | 
                                                        |
| 1006 | - $data['ground'] = $line[21];  | 
                                                        |
| 1007 | - $data['emergency'] = $line[19];  | 
                                                        |
| 1008 | - $data['format_source'] = 'sbs';  | 
                                                        |
| 994 | + // Force datetime to current UTC datetime  | 
                                                        |
| 995 | +					date_default_timezone_set('UTC'); | 
                                                        |
| 996 | +					$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 997 | + $data['ident'] = trim($line[10]);  | 
                                                        |
| 998 | + $data['latitude'] = $line[14];  | 
                                                        |
| 999 | + $data['longitude'] = $line[15];  | 
                                                        |
| 1000 | + $data['verticalrate'] = $line[16];  | 
                                                        |
| 1001 | + $data['emergency'] = $line[20];  | 
                                                        |
| 1002 | + $data['speed'] = $line[12];  | 
                                                        |
| 1003 | + $data['squawk'] = $line[17];  | 
                                                        |
| 1004 | + $data['altitude'] = $line[11];  | 
                                                        |
| 1005 | + $data['heading'] = $line[13];  | 
                                                        |
| 1006 | + $data['ground'] = $line[21];  | 
                                                        |
| 1007 | + $data['emergency'] = $line[19];  | 
                                                        |
| 1008 | + $data['format_source'] = 'sbs';  | 
                                                        |
| 1009 | 1009 | if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];  | 
                                                        
| 1010 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 1011 | - $data['id_source'] = $id_source;  | 
                                                        |
| 1012 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);  | 
                                                        |
| 1013 | - else $error = true;  | 
                                                        |
| 1014 | - unset($data);  | 
                                                        |
| 1015 | - } else $error = true;  | 
                                                        |
| 1016 | -			    if ($error) { | 
                                                        |
| 1010 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 1011 | + $data['id_source'] = $id_source;  | 
                                                        |
| 1012 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);  | 
                                                        |
| 1013 | + else $error = true;  | 
                                                        |
| 1014 | + unset($data);  | 
                                                        |
| 1015 | + } else $error = true;  | 
                                                        |
| 1016 | +				if ($error) { | 
                                                        |
| 1017 | 1017 |  				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) {  | 
                                                        
| 1018 | 1018 | if ($globalDebug) echo "Not a message. Ignoring... \n";  | 
                                                        
| 1019 | 1019 |  				} else { | 
                                                        
@@ -1029,13 +1029,13 @@ discard block  | 
                                                    ||
| 1029 | 1029 | connect_all($sourceer);  | 
                                                        
| 1030 | 1030 | $sourceer = array();  | 
                                                        
| 1031 | 1031 | }  | 
                                                        
| 1032 | - }  | 
                                                        |
| 1032 | + }  | 
                                                        |
| 1033 | 1033 | }  | 
                                                        
| 1034 | 1034 | // Sleep for xxx microseconds  | 
                                                        
| 1035 | 1035 | if (isset($globalSBSSleep)) usleep($globalSBSSleep);  | 
                                                        
| 1036 | -		    } else { | 
                                                        |
| 1036 | +			} else { | 
                                                        |
| 1037 | 1037 |  			if ($format == 'flightgearmp') { | 
                                                        
| 1038 | - if ($globalDebug) echo "Reconnect FlightGear MP...";  | 
                                                        |
| 1038 | + if ($globalDebug) echo "Reconnect FlightGear MP...";  | 
                                                        |
| 1039 | 1039 | //@socket_close($r);  | 
                                                        
| 1040 | 1040 | sleep($globalMinFetch);  | 
                                                        
| 1041 | 1041 | $sourcefg[$nb] = $globalSources[$nb];  | 
                                                        
@@ -1044,9 +1044,9 @@ discard block  | 
                                                    ||
| 1044 | 1044 | break;  | 
                                                        
| 1045 | 1045 | |
| 1046 | 1046 |  			} elseif ($format != 'acars' && $format != 'flightgearsp') { | 
                                                        
| 1047 | - if (isset($tt[$format])) $tt[$format]++;  | 
                                                        |
| 1048 | - else $tt[$format] = 0;  | 
                                                        |
| 1049 | -			    if ($tt[$format] > 30) { | 
                                                        |
| 1047 | + if (isset($tt[$format])) $tt[$format]++;  | 
                                                        |
| 1048 | + else $tt[$format] = 0;  | 
                                                        |
| 1049 | +				if ($tt[$format] > 30) { | 
                                                        |
| 1050 | 1050 | if ($globalDebug) echo "ERROR : Reconnect ".$format."...";  | 
                                                        
| 1051 | 1051 | //@socket_close($r);  | 
                                                        
| 1052 | 1052 | sleep(2);  | 
                                                        
@@ -1057,23 +1057,23 @@ discard block  | 
                                                    ||
| 1057 | 1057 | //connect_all($globalSources);  | 
                                                        
| 1058 | 1058 | $tt[$format]=0;  | 
                                                        
| 1059 | 1059 | break;  | 
                                                        
| 1060 | - }  | 
                                                        |
| 1060 | + }  | 
                                                        |
| 1061 | + }  | 
                                                        |
| 1061 | 1062 | }  | 
                                                        
| 1062 | - }  | 
                                                        |
| 1063 | 1063 | }  | 
                                                        
| 1064 | -	    } else { | 
                                                        |
| 1064 | +		} else { | 
                                                        |
| 1065 | 1065 | $error = socket_strerror(socket_last_error());  | 
                                                        
| 1066 | 1066 | if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";  | 
                                                        
| 1067 | 1067 |  		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) { | 
                                                        
| 1068 | 1068 | if (isset($globalDebug)) echo "Restarting...\n";  | 
                                                        
| 1069 | 1069 | // Restart the script if possible  | 
                                                        
| 1070 | 1070 |  			if (is_array($sockets)) { | 
                                                        
| 1071 | - if ($globalDebug) echo "Shutdown all sockets...";  | 
                                                        |
| 1071 | + if ($globalDebug) echo "Shutdown all sockets...";  | 
                                                        |
| 1072 | 1072 | |
| 1073 | -			    foreach ($sockets as $sock) { | 
                                                        |
| 1073 | +				foreach ($sockets as $sock) { | 
                                                        |
| 1074 | 1074 | @socket_shutdown($sock,2);  | 
                                                        
| 1075 | 1075 | @socket_close($sock);  | 
                                                        
| 1076 | - }  | 
                                                        |
| 1076 | + }  | 
                                                        |
| 1077 | 1077 | |
| 1078 | 1078 | }  | 
                                                        
| 1079 | 1079 | if ($globalDebug) echo "Restart all connections...";  | 
                                                        
@@ -1084,13 +1084,13 @@ discard block  | 
                                                    ||
| 1084 | 1084 |  			if ($reset > 40) exit('Too many attempts...'); | 
                                                        
| 1085 | 1085 | connect_all($globalSources);  | 
                                                        
| 1086 | 1086 | }  | 
                                                        
| 1087 | - }  | 
                                                        |
| 1087 | + }  | 
                                                        |
| 1088 | 1088 | }  | 
                                                        
| 1089 | 1089 |  	if ($globalDaemon === false) { | 
                                                        
| 1090 | - if ($globalDebug) echo 'Check all...'."\n";  | 
                                                        |
| 1091 | - $SI->checkAll();  | 
                                                        |
| 1090 | + if ($globalDebug) echo 'Check all...'."\n";  | 
                                                        |
| 1091 | + $SI->checkAll();  | 
                                                        |
| 1092 | + }  | 
                                                        |
| 1092 | 1093 | }  | 
                                                        
| 1093 | - }  | 
                                                        |
| 1094 | 1094 | }  | 
                                                        
| 1095 | 1095 | |
| 1096 | 1096 | ?>  | 
                                                        
@@ -14,7 +14,9 @@ discard block  | 
                                                    ||
| 14 | 14 | require_once(dirname(__FILE__).'/../require/class.Connection.php');  | 
                                                        
| 15 | 15 | require_once(dirname(__FILE__).'/../require/class.Common.php');  | 
                                                        
| 16 | 16 | |
| 17 | -if (!isset($globalDebug)) $globalDebug = FALSE;  | 
                                                        |
| 17 | +if (!isset($globalDebug)) { | 
                                                        |
| 18 | + $globalDebug = FALSE;  | 
                                                        |
| 19 | +}  | 
                                                        |
| 18 | 20 | |
| 19 | 21 | // Check if schema is at latest version  | 
                                                        
| 20 | 22 | $Connection = new Connection();  | 
                                                        
@@ -54,13 +56,22 @@ discard block  | 
                                                    ||
| 54 | 56 | $globalSources = array();  | 
                                                        
| 55 | 57 |      $globalSources[] = array('host' => $options['source']); | 
                                                        
| 56 | 58 | }  | 
                                                        
| 57 | -if (isset($options['server'])) $globalServer = TRUE;  | 
                                                        |
| 58 | -if (isset($options['idsource'])) $id_source = $options['idsource'];  | 
                                                        |
| 59 | -else $id_source = 1;  | 
                                                        |
| 59 | +if (isset($options['server'])) { | 
                                                        |
| 60 | + $globalServer = TRUE;  | 
                                                        |
| 61 | +}  | 
                                                        |
| 62 | +if (isset($options['idsource'])) { | 
                                                        |
| 63 | + $id_source = $options['idsource'];  | 
                                                        |
| 64 | +} else { | 
                                                        |
| 65 | + $id_source = 1;  | 
                                                        |
| 66 | +}  | 
                                                        |
| 60 | 67 |  if (isset($globalServer) && $globalServer) { | 
                                                        
| 61 | - if ($globalDebug) echo "Using Server Mode\n";  | 
                                                        |
| 68 | +    if ($globalDebug) { | 
                                                        |
| 69 | + echo "Using Server Mode\n";  | 
                                                        |
| 70 | + }  | 
                                                        |
| 62 | 71 | $SI=new SpotterServer();  | 
                                                        
| 63 | -} else $SI=new SpotterImport($Connection->db);  | 
                                                        |
| 72 | +} else { | 
                                                        |
| 73 | + $SI=new SpotterImport($Connection->db);  | 
                                                        |
| 74 | +}  | 
                                                        |
| 64 | 75 | //$APRS=new APRS($Connection->db);  | 
                                                        
| 65 | 76 | $SBS=new SBS();  | 
                                                        
| 66 | 77 | $ACARS=new ACARS($Connection->db);  | 
                                                        
@@ -78,7 +89,9 @@ discard block  | 
                                                    ||
| 78 | 89 | }  | 
                                                        
| 79 | 90 | |
| 80 | 91 | // let's try and connect  | 
                                                        
| 81 | -if ($globalDebug) echo "Connecting...\n";  | 
                                                        |
| 92 | +if ($globalDebug) { | 
                                                        |
| 93 | + echo "Connecting...\n";  | 
                                                        |
| 94 | +}  | 
                                                        |
| 82 | 95 | $use_aprs = false;  | 
                                                        
| 83 | 96 | $aprs_full = false;  | 
                                                        
| 84 | 97 | $reset = 0;  | 
                                                        
@@ -87,7 +100,9 @@ discard block  | 
                                                    ||
| 87 | 100 | $ip = gethostbyname($host);  | 
                                                        
| 88 | 101 | $s = socket_create(AF_INET, SOCK_STREAM, 0);  | 
                                                        
| 89 | 102 | $r = @socket_connect($s, $ip, $port);  | 
                                                        
| 90 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";  | 
                                                        |
| 103 | +    if (!socket_set_nonblock($s)) { | 
                                                        |
| 104 | + echo "Unable to set nonblock on socket\n";  | 
                                                        |
| 105 | + }  | 
                                                        |
| 91 | 106 |      if ($r || socket_last_error() == 114 || socket_last_error() == 115) { | 
                                                        
| 92 | 107 | return $s;  | 
                                                        
| 93 | 108 | }  | 
                                                        
@@ -115,7 +130,9 @@ discard block  | 
                                                    ||
| 115 | 130 | //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;  | 
                                                        
| 116 | 131 | global $sockets, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset;  | 
                                                        
| 117 | 132 | $reset++;  | 
                                                        
| 118 | - if ($globalDebug) echo 'Connect to all...'."\n";  | 
                                                        |
| 133 | +    if ($globalDebug) { | 
                                                        |
| 134 | + echo 'Connect to all...'."\n";  | 
                                                        |
| 135 | + }  | 
                                                        |
| 119 | 136 |      foreach ($hosts as $id => $value) { | 
                                                        
| 120 | 137 | $host = $value['host'];  | 
                                                        
| 121 | 138 | $globalSources[$id]['last_exec'] = 0;  | 
                                                        
@@ -125,27 +142,37 @@ discard block  | 
                                                    ||
| 125 | 142 | //$formats[$id] = 'deltadbtxt';  | 
                                                        
| 126 | 143 | $globalSources[$id]['format'] = 'deltadbtxt';  | 
                                                        
| 127 | 144 | //$last_exec['deltadbtxt'] = 0;  | 
                                                        
| 128 | -        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; | 
                                                        |
| 145 | +        	if ($globalDebug) { | 
                                                        |
| 146 | +        		echo "Connect to deltadb source (".$host.")...\n"; | 
                                                        |
| 147 | + }  | 
                                                        |
| 129 | 148 |              } else if (preg_match('/vatsim-data.txt$/i',$host)) { | 
                                                        
| 130 | 149 | //$formats[$id] = 'vatsimtxt';  | 
                                                        
| 131 | 150 | $globalSources[$id]['format'] = 'vatsimtxt';  | 
                                                        
| 132 | 151 | //$last_exec['vatsimtxt'] = 0;  | 
                                                        
| 133 | -        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; | 
                                                        |
| 152 | +        	if ($globalDebug) { | 
                                                        |
| 153 | +        		echo "Connect to vatsim source (".$host.")...\n"; | 
                                                        |
| 154 | + }  | 
                                                        |
| 134 | 155 |      	    } else if (preg_match('/aircraftlist.json$/i',$host)) { | 
                                                        
| 135 | 156 | //$formats[$id] = 'aircraftlistjson';  | 
                                                        
| 136 | 157 | $globalSources[$id]['format'] = 'aircraftlistjson';  | 
                                                        
| 137 | 158 | //$last_exec['aircraftlistjson'] = 0;  | 
                                                        
| 138 | -        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; | 
                                                        |
| 159 | +        	if ($globalDebug) { | 
                                                        |
| 160 | +        		echo "Connect to aircraftlist.json source (".$host.")...\n"; | 
                                                        |
| 161 | + }  | 
                                                        |
| 139 | 162 |      	    } else if (preg_match('/opensky/i',$host)) { | 
                                                        
| 140 | 163 | //$formats[$id] = 'aircraftlistjson';  | 
                                                        
| 141 | 164 | $globalSources[$id]['format'] = 'opensky';  | 
                                                        
| 142 | 165 | //$last_exec['aircraftlistjson'] = 0;  | 
                                                        
| 143 | -        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; | 
                                                        |
| 166 | +        	if ($globalDebug) { | 
                                                        |
| 167 | +        		echo "Connect to opensky source (".$host.")...\n"; | 
                                                        |
| 168 | + }  | 
                                                        |
| 144 | 169 |      	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) { | 
                                                        
| 145 | 170 | //$formats[$id] = 'radarvirtueljson';  | 
                                                        
| 146 | 171 | $globalSources[$id]['format'] = 'radarvirtueljson';  | 
                                                        
| 147 | 172 | //$last_exec['radarvirtueljson'] = 0;  | 
                                                        
| 148 | -        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; | 
                                                        |
| 173 | +        	if ($globalDebug) { | 
                                                        |
| 174 | +        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n"; | 
                                                        |
| 175 | + }  | 
                                                        |
| 149 | 176 |          	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { | 
                                                        
| 150 | 177 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";  | 
                                                        
| 151 | 178 | exit(0);  | 
                                                        
@@ -154,7 +181,9 @@ discard block  | 
                                                    ||
| 154 | 181 | //$formats[$id] = 'planeupdatefaa';  | 
                                                        
| 155 | 182 | $globalSources[$id]['format'] = 'planeupdatefaa';  | 
                                                        
| 156 | 183 | //$last_exec['planeupdatefaa'] = 0;  | 
                                                        
| 157 | -        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; | 
                                                        |
| 184 | +        	if ($globalDebug) { | 
                                                        |
| 185 | +        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; | 
                                                        |
| 186 | + }  | 
                                                        |
| 158 | 187 |          	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { | 
                                                        
| 159 | 188 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";  | 
                                                        
| 160 | 189 | exit(0);  | 
                                                        
@@ -163,26 +192,36 @@ discard block  | 
                                                    ||
| 163 | 192 | //$formats[$id] = 'phpvmacars';  | 
                                                        
| 164 | 193 | $globalSources[$id]['format'] = 'phpvmacars';  | 
                                                        
| 165 | 194 | //$last_exec['phpvmacars'] = 0;  | 
                                                        
| 166 | -        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; | 
                                                        |
| 195 | +        	if ($globalDebug) { | 
                                                        |
| 196 | +        		echo "Connect to phpvmacars source (".$host.")...\n"; | 
                                                        |
| 197 | + }  | 
                                                        |
| 167 | 198 |              } else if (preg_match('/VAM-json.php$/i',$host)) { | 
                                                        
| 168 | 199 | //$formats[$id] = 'phpvmacars';  | 
                                                        
| 169 | 200 | $globalSources[$id]['format'] = 'vam';  | 
                                                        
| 170 | -        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; | 
                                                        |
| 201 | +        	if ($globalDebug) { | 
                                                        |
| 202 | +        		echo "Connect to Vam source (".$host.")...\n"; | 
                                                        |
| 203 | + }  | 
                                                        |
| 171 | 204 |              } else if (preg_match('/whazzup/i',$host)) { | 
                                                        
| 172 | 205 | //$formats[$id] = 'whazzup';  | 
                                                        
| 173 | 206 | $globalSources[$id]['format'] = 'whazzup';  | 
                                                        
| 174 | 207 | //$last_exec['whazzup'] = 0;  | 
                                                        
| 175 | -        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; | 
                                                        |
| 208 | +        	if ($globalDebug) { | 
                                                        |
| 209 | +        		echo "Connect to whazzup source (".$host.")...\n"; | 
                                                        |
| 210 | + }  | 
                                                        |
| 176 | 211 |              } else if (preg_match('/recentpireps/i',$host)) { | 
                                                        
| 177 | 212 | //$formats[$id] = 'pirepsjson';  | 
                                                        
| 178 | 213 | $globalSources[$id]['format'] = 'pirepsjson';  | 
                                                        
| 179 | 214 | //$last_exec['pirepsjson'] = 0;  | 
                                                        
| 180 | -        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; | 
                                                        |
| 215 | +        	if ($globalDebug) { | 
                                                        |
| 216 | +        		echo "Connect to pirepsjson source (".$host.")...\n"; | 
                                                        |
| 217 | + }  | 
                                                        |
| 181 | 218 |              } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { | 
                                                        
| 182 | 219 | //$formats[$id] = 'fr24json';  | 
                                                        
| 183 | 220 | $globalSources[$id]['format'] = 'fr24json';  | 
                                                        
| 184 | 221 | //$last_exec['fr24json'] = 0;  | 
                                                        
| 185 | -        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; | 
                                                        |
| 222 | +        	if ($globalDebug) { | 
                                                        |
| 223 | +        		echo "Connect to fr24 source (".$host.")...\n"; | 
                                                        |
| 224 | + }  | 
                                                        |
| 186 | 225 |          	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { | 
                                                        
| 187 | 226 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";  | 
                                                        
| 188 | 227 | exit(0);  | 
                                                        
@@ -191,10 +230,14 @@ discard block  | 
                                                    ||
| 191 | 230 |              } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { | 
                                                        
| 192 | 231 | //$formats[$id] = 'tsv';  | 
                                                        
| 193 | 232 | $globalSources[$id]['format'] = 'tsv';  | 
                                                        
| 194 | -        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; | 
                                                        |
| 233 | +        	if ($globalDebug) { | 
                                                        |
| 234 | +        		echo "Connect to tsv source (".$host.")...\n"; | 
                                                        |
| 235 | + }  | 
                                                        |
| 195 | 236 | }  | 
                                                        
| 196 | 237 |          } elseif (filter_var($host,FILTER_VALIDATE_URL)) { | 
                                                        
| 197 | -        	if ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; | 
                                                        |
| 238 | +        	if ($globalDebug) { | 
                                                        |
| 239 | +        		echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; | 
                                                        |
| 240 | + }  | 
                                                        |
| 198 | 241 |          } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { | 
                                                        
| 199 | 242 |  	    $hostport = explode(':',$host); | 
                                                        
| 200 | 243 |  	    if (isset($hostport[1])) { | 
                                                        
@@ -231,17 +274,25 @@ discard block  | 
                                                    ||
| 231 | 274 | //$formats[$id] = 'beast';  | 
                                                        
| 232 | 275 | $globalSources[$id]['format'] = 'beast';  | 
                                                        
| 233 | 276 | //} else $formats[$id] = 'sbs';  | 
                                                        
| 234 | - } else $globalSources[$id]['format'] = 'sbs';  | 
                                                        |
| 277 | +		    } else { | 
                                                        |
| 278 | + $globalSources[$id]['format'] = 'sbs';  | 
                                                        |
| 279 | + }  | 
                                                        |
| 235 | 280 |  		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; | 
                                                        
| 236 | 281 | }  | 
                                                        
| 237 | -		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; | 
                                                        |
| 282 | +		if ($globalDebug) { | 
                                                        |
| 283 | +			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; | 
                                                        |
| 284 | + }  | 
                                                        |
| 238 | 285 |              } else { | 
                                                        
| 239 | - if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";  | 
                                                        |
| 286 | +		if ($globalDebug) { | 
                                                        |
| 287 | + echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";  | 
                                                        |
| 288 | + }  | 
                                                        |
| 240 | 289 | }  | 
                                                        
| 241 | 290 | }  | 
                                                        
| 242 | 291 | }  | 
                                                        
| 243 | 292 | }  | 
                                                        
| 244 | -if (!isset($globalMinFetch)) $globalMinFetch = 15;  | 
                                                        |
| 293 | +if (!isset($globalMinFetch)) { | 
                                                        |
| 294 | + $globalMinFetch = 15;  | 
                                                        |
| 295 | +}  | 
                                                        |
| 245 | 296 | |
| 246 | 297 | // Initialize all  | 
                                                        
| 247 | 298 | $status = array();  | 
                                                        
@@ -249,13 +300,19 @@ discard block  | 
                                                    ||
| 249 | 300 | $formats = array();  | 
                                                        
| 250 | 301 | $last_exec = array();  | 
                                                        
| 251 | 302 | $time = time();  | 
                                                        
| 252 | -if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;  | 
                                                        |
| 253 | -else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;  | 
                                                        |
| 254 | -else $timeout = 20;  | 
                                                        |
| 303 | +if (isset($globalSourcesTimeout)) { | 
                                                        |
| 304 | + $timeout = $globalSourcesTimeOut;  | 
                                                        |
| 305 | +} else if (isset($globalSBS1TimeOut)) { | 
                                                        |
| 306 | + $timeout = $globalSBS1TimeOut;  | 
                                                        |
| 307 | +} else { | 
                                                        |
| 308 | + $timeout = 20;  | 
                                                        |
| 309 | +}  | 
                                                        |
| 255 | 310 | $errno = '';  | 
                                                        
| 256 | 311 | $errstr='';  | 
                                                        
| 257 | 312 | |
| 258 | -if (!isset($globalDaemon)) $globalDaemon = TRUE;  | 
                                                        |
| 313 | +if (!isset($globalDaemon)) { | 
                                                        |
| 314 | + $globalDaemon = TRUE;  | 
                                                        |
| 315 | +}  | 
                                                        |
| 259 | 316 | /* Initiate connections to all the hosts simultaneously */  | 
                                                        
| 260 | 317 | //connect_all($hosts);  | 
                                                        
| 261 | 318 | //connect_all($globalSources);  | 
                                                        
@@ -275,7 +332,9 @@ discard block  | 
                                                    ||
| 275 | 332 |      if (isset($source['format']) && $source['format'] == 'aprs') { | 
                                                        
| 276 | 333 | $aprs_connect = 0;  | 
                                                        
| 277 | 334 | $use_aprs = true;  | 
                                                        
| 278 | - if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;  | 
                                                        |
| 335 | +	if (isset($source['port']) && $source['port'] == '10152') { | 
                                                        |
| 336 | + $aprs_full = true;  | 
                                                        |
| 337 | + }  | 
                                                        |
| 279 | 338 | break;  | 
                                                        
| 280 | 339 | }  | 
                                                        
| 281 | 340 | }  | 
                                                        
@@ -286,23 +345,43 @@ discard block  | 
                                                    ||
| 286 | 345 | $aprs_connect = 0;  | 
                                                        
| 287 | 346 | $aprs_keep = 120;  | 
                                                        
| 288 | 347 | $aprs_last_tx = time();  | 
                                                        
| 289 | - if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;  | 
                                                        |
| 290 | -	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); | 
                                                        |
| 291 | - if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;  | 
                                                        |
| 292 | -	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); | 
                                                        |
| 293 | - if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;  | 
                                                        |
| 294 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';  | 
                                                        |
| 295 | - if ($aprs_full) $aprs_filter = '';  | 
                                                        |
| 348 | +	if (isset($globalAPRSversion)) { | 
                                                        |
| 349 | + $aprs_version = $globalAPRSversion;  | 
                                                        |
| 350 | +	} else { | 
                                                        |
| 351 | +		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); | 
                                                        |
| 352 | + }  | 
                                                        |
| 353 | +	if (isset($globalAPRSssid)) { | 
                                                        |
| 354 | + $aprs_ssid = $globalAPRSssid;  | 
                                                        |
| 355 | +	} else { | 
                                                        |
| 356 | +		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); | 
                                                        |
| 357 | + }  | 
                                                        |
| 358 | +	if (isset($globalAPRSfilter)) { | 
                                                        |
| 359 | + $aprs_filter = $globalAPRSfilter;  | 
                                                        |
| 360 | +	} else { | 
                                                        |
| 361 | + $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';  | 
                                                        |
| 362 | + }  | 
                                                        |
| 363 | +	if ($aprs_full) { | 
                                                        |
| 364 | + $aprs_filter = '';  | 
                                                        |
| 365 | + }  | 
                                                        |
| 296 | 366 | |
| 297 | -	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n"; | 
                                                        |
| 298 | -	else $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n"; | 
                                                        |
| 299 | -}  | 
                                                        |
| 367 | +	if ($aprs_filter != '') { | 
                                                        |
| 368 | +		$aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n"; | 
                                                        |
| 369 | +	} else { | 
                                                        |
| 370 | +		$aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n"; | 
                                                        |
| 371 | + }  | 
                                                        |
| 372 | + }  | 
                                                        |
| 300 | 373 | |
| 301 | 374 | // connected - lets do some work  | 
                                                        
| 302 | -if ($globalDebug) echo "Connected!\n";  | 
                                                        |
| 375 | +if ($globalDebug) { | 
                                                        |
| 376 | + echo "Connected!\n";  | 
                                                        |
| 377 | +}  | 
                                                        |
| 303 | 378 | sleep(1);  | 
                                                        
| 304 | -if ($globalDebug) echo "SCAN MODE \n\n";  | 
                                                        |
| 305 | -if (!isset($globalCronEnd)) $globalCronEnd = 60;  | 
                                                        |
| 379 | +if ($globalDebug) { | 
                                                        |
| 380 | + echo "SCAN MODE \n\n";  | 
                                                        |
| 381 | +}  | 
                                                        |
| 382 | +if (!isset($globalCronEnd)) { | 
                                                        |
| 383 | + $globalCronEnd = 60;  | 
                                                        |
| 384 | +}  | 
                                                        |
| 306 | 385 | $endtime = time()+$globalCronEnd;  | 
                                                        
| 307 | 386 | $i = 1;  | 
                                                        
| 308 | 387 | $tt = array();  | 
                                                        
@@ -316,20 +395,28 @@ discard block  | 
                                                    ||
| 316 | 395 | |
| 317 | 396 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.  | 
                                                        
| 318 | 397 |  while ($i > 0) { | 
                                                        
| 319 | - if (!$globalDaemon) $i = $endtime-time();  | 
                                                        |
| 398 | +    if (!$globalDaemon) { | 
                                                        |
| 399 | + $i = $endtime-time();  | 
                                                        |
| 400 | + }  | 
                                                        |
| 320 | 401 | // Delete old ATC  | 
                                                        
| 321 | 402 |      if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { | 
                                                        
| 322 | - if ($globalDebug) echo 'Delete old ATC...'."\n";  | 
                                                        |
| 403 | +	if ($globalDebug) { | 
                                                        |
| 404 | + echo 'Delete old ATC...'."\n";  | 
                                                        |
| 405 | + }  | 
                                                        |
| 323 | 406 | $ATC->deleteOldATC();  | 
                                                        
| 324 | 407 | }  | 
                                                        
| 325 | 408 | |
| 326 | 409 |      if (count($last_exec) > 0) { | 
                                                        
| 327 | 410 | $max = $globalMinFetch;  | 
                                                        
| 328 | 411 |  	foreach ($last_exec as $last) { | 
                                                        
| 329 | - if ((time() - $last['last']) < $max) $max = time() - $last['last'];  | 
                                                        |
| 412 | +	    if ((time() - $last['last']) < $max) { | 
                                                        |
| 413 | + $max = time() - $last['last'];  | 
                                                        |
| 414 | + }  | 
                                                        |
| 330 | 415 | }  | 
                                                        
| 331 | 416 |  	if ($max != $globalMinFetch) { | 
                                                        
| 332 | - if ($globalDebug) echo 'Sleeping...'."\n";  | 
                                                        |
| 417 | +	    if ($globalDebug) { | 
                                                        |
| 418 | + echo 'Sleeping...'."\n";  | 
                                                        |
| 419 | + }  | 
                                                        |
| 333 | 420 | sleep($globalMinFetch-$max+2);  | 
                                                        
| 334 | 421 | }  | 
                                                        
| 335 | 422 | }  | 
                                                        
@@ -338,11 +425,15 @@ discard block  | 
                                                    ||
| 338 | 425 |      //foreach ($formats as $id => $value) { | 
                                                        
| 339 | 426 |      foreach ($globalSources as $id => $value) { | 
                                                        
| 340 | 427 |  	date_default_timezone_set('UTC'); | 
                                                        
| 341 | - if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;  | 
                                                        |
| 428 | +	if (!isset($last_exec[$id]['last'])) { | 
                                                        |
| 429 | + $last_exec[$id]['last'] = 0;  | 
                                                        |
| 430 | + }  | 
                                                        |
| 342 | 431 |  	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        
| 343 | 432 | //$buffer = $Common->getData($hosts[$id]);  | 
                                                        
| 344 | 433 | $buffer = $Common->getData($value['host']);  | 
                                                        
| 345 | - if ($buffer != '') $reset = 0;  | 
                                                        |
| 434 | +	    if ($buffer != '') { | 
                                                        |
| 435 | + $reset = 0;  | 
                                                        |
| 436 | + }  | 
                                                        |
| 346 | 437 |      	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); | 
                                                        
| 347 | 438 |  	    $buffer = explode('\n',$buffer); | 
                                                        
| 348 | 439 |  	    foreach ($buffer as $line) { | 
                                                        
@@ -351,19 +442,38 @@ discard block  | 
                                                    ||
| 351 | 442 | $data = array();  | 
                                                        
| 352 | 443 | $data['hex'] = $line[1]; // hex  | 
                                                        
| 353 | 444 | $data['ident'] = $line[2]; // ident  | 
                                                        
| 354 | - if (isset($line[3])) $data['altitude'] = $line[3]; // altitude  | 
                                                        |
| 355 | - if (isset($line[4])) $data['speed'] = $line[4]; // speed  | 
                                                        |
| 356 | - if (isset($line[5])) $data['heading'] = $line[5]; // heading  | 
                                                        |
| 357 | - if (isset($line[6])) $data['latitude'] = $line[6]; // lat  | 
                                                        |
| 358 | - if (isset($line[7])) $data['longitude'] = $line[7]; // long  | 
                                                        |
| 445 | +	            if (isset($line[3])) { | 
                                                        |
| 446 | + $data['altitude'] = $line[3];  | 
                                                        |
| 447 | + }  | 
                                                        |
| 448 | + // altitude  | 
                                                        |
| 449 | +	            if (isset($line[4])) { | 
                                                        |
| 450 | + $data['speed'] = $line[4];  | 
                                                        |
| 451 | + }  | 
                                                        |
| 452 | + // speed  | 
                                                        |
| 453 | +	            if (isset($line[5])) { | 
                                                        |
| 454 | + $data['heading'] = $line[5];  | 
                                                        |
| 455 | + }  | 
                                                        |
| 456 | + // heading  | 
                                                        |
| 457 | +	            if (isset($line[6])) { | 
                                                        |
| 458 | + $data['latitude'] = $line[6];  | 
                                                        |
| 459 | + }  | 
                                                        |
| 460 | + // lat  | 
                                                        |
| 461 | +	            if (isset($line[7])) { | 
                                                        |
| 462 | + $data['longitude'] = $line[7];  | 
                                                        |
| 463 | + }  | 
                                                        |
| 464 | + // long  | 
                                                        |
| 359 | 465 | $data['verticalrate'] = ''; // vertical rate  | 
                                                        
| 360 | 466 | //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk  | 
                                                        
| 361 | 467 | $data['emergency'] = ''; // emergency  | 
                                                        
| 362 | 468 |  		    $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        
| 363 | 469 | $data['format_source'] = 'deltadbtxt';  | 
                                                        
| 364 | 470 | $data['id_source'] = $id_source;  | 
                                                        
| 365 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 366 | - if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];  | 
                                                        |
| 471 | +		    if (isset($value['name']) && $value['name'] != '') { | 
                                                        |
| 472 | + $data['source_name'] = $value['name'];  | 
                                                        |
| 473 | + }  | 
                                                        |
| 474 | +		    if (isset($value['sourcestats'])) { | 
                                                        |
| 475 | + $data['sourcestats'] = $value['sourcestats'];  | 
                                                        |
| 476 | + }  | 
                                                        |
| 367 | 477 | $SI->add($data);  | 
                                                        
| 368 | 478 | unset($data);  | 
                                                        
| 369 | 479 | }  | 
                                                        
@@ -381,16 +491,28 @@ discard block  | 
                                                    ||
| 381 | 491 |      		    $line = explode(':', $line); | 
                                                        
| 382 | 492 |      		    if (count($line) > 30 && $line[0] != 'callsign') { | 
                                                        
| 383 | 493 | $data = array();  | 
                                                        
| 384 | - if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];  | 
                                                        |
| 385 | - else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];  | 
                                                        |
| 494 | +			if (isset($line[37]) && $line[37] != '') { | 
                                                        |
| 495 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];  | 
                                                        |
| 496 | +			} else { | 
                                                        |
| 497 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];  | 
                                                        |
| 498 | + }  | 
                                                        |
| 386 | 499 | $data['pilot_id'] = $line[1];  | 
                                                        
| 387 | 500 | $data['pilot_name'] = $line[2];  | 
                                                        
| 388 | 501 | $data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);  | 
                                                        
| 389 | 502 | $data['ident'] = $line[0]; // ident  | 
                                                        
| 390 | - if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude  | 
                                                        |
| 503 | +			if ($line[7] != '' && $line[7] != 0) { | 
                                                        |
| 504 | + $data['altitude'] = $line[7];  | 
                                                        |
| 505 | + }  | 
                                                        |
| 506 | + // altitude  | 
                                                        |
| 391 | 507 | $data['speed'] = $line[8]; // speed  | 
                                                        
| 392 | - if (isset($line[45])) $data['heading'] = $line[45]; // heading  | 
                                                        |
| 393 | - elseif (isset($line[38])) $data['heading'] = $line[38]; // heading  | 
                                                        |
| 508 | +			if (isset($line[45])) { | 
                                                        |
| 509 | + $data['heading'] = $line[45];  | 
                                                        |
| 510 | + }  | 
                                                        |
| 511 | + // heading  | 
                                                        |
| 512 | +			elseif (isset($line[38])) { | 
                                                        |
| 513 | + $data['heading'] = $line[38];  | 
                                                        |
| 514 | + }  | 
                                                        |
| 515 | + // heading  | 
                                                        |
| 394 | 516 | $data['latitude'] = $line[5]; // lat  | 
                                                        
| 395 | 517 | $data['longitude'] = $line[6]; // long  | 
                                                        
| 396 | 518 | $data['verticalrate'] = ''; // vertical rate  | 
                                                        
@@ -406,7 +528,9 @@ discard block  | 
                                                    ||
| 406 | 528 | $data['frequency'] = $line[4];  | 
                                                        
| 407 | 529 | $data['type'] = $line[18];  | 
                                                        
| 408 | 530 | $data['range'] = $line[19];  | 
                                                        
| 409 | - if (isset($line[35])) $data['info'] = $line[35];  | 
                                                        |
| 531 | +			if (isset($line[35])) { | 
                                                        |
| 532 | + $data['info'] = $line[35];  | 
                                                        |
| 533 | + }  | 
                                                        |
| 410 | 534 | $data['id_source'] = $id_source;  | 
                                                        
| 411 | 535 | //$data['arrival_airport_time'] = ;  | 
                                                        
| 412 | 536 |  	    		if ($line[9] != '') { | 
                                                        
@@ -420,24 +544,41 @@ discard block  | 
                                                    ||
| 420 | 544 | elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';  | 
                                                        
| 421 | 545 | */  | 
                                                        
| 422 | 546 | $data['format_source'] = $value['format'];  | 
                                                        
| 423 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 424 | - if ($line[3] == 'PILOT') $SI->add($data);  | 
                                                        |
| 425 | -			elseif ($line[3] == 'ATC') { | 
                                                        |
| 547 | +			if (isset($value['name']) && $value['name'] != '') { | 
                                                        |
| 548 | + $data['source_name'] = $value['name'];  | 
                                                        |
| 549 | + }  | 
                                                        |
| 550 | +    			if ($line[3] == 'PILOT') { | 
                                                        |
| 551 | + $SI->add($data);  | 
                                                        |
| 552 | +    			} elseif ($line[3] == 'ATC') { | 
                                                        |
| 426 | 553 | //print_r($data);  | 
                                                        
| 427 | 554 |  				$data['info'] = str_replace('^§','<br />',$data['info']); | 
                                                        
| 428 | 555 |  				$data['info'] = str_replace('&sect;','',$data['info']); | 
                                                        
| 429 | 556 | $typec = substr($data['ident'],-3);  | 
                                                        
| 430 | - if ($typec == 'APP') $data['type'] = 'Approach';  | 
                                                        |
| 431 | - elseif ($typec == 'TWR') $data['type'] = 'Tower';  | 
                                                        |
| 432 | - elseif ($typec == 'OBS') $data['type'] = 'Observer';  | 
                                                        |
| 433 | - elseif ($typec == 'GND') $data['type'] = 'Ground';  | 
                                                        |
| 434 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery';  | 
                                                        |
| 435 | - elseif ($typec == 'DEP') $data['type'] = 'Departure';  | 
                                                        |
| 436 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';  | 
                                                        |
| 437 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';  | 
                                                        |
| 438 | - elseif ($data['type'] == '') $data['type'] = 'Observer';  | 
                                                        |
| 439 | - if (!isset($data['source_name'])) $data['source_name'] = '';  | 
                                                        |
| 440 | - if (isset($ATC)) echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);  | 
                                                        |
| 557 | +				if ($typec == 'APP') { | 
                                                        |
| 558 | + $data['type'] = 'Approach';  | 
                                                        |
| 559 | +				} elseif ($typec == 'TWR') { | 
                                                        |
| 560 | + $data['type'] = 'Tower';  | 
                                                        |
| 561 | +				} elseif ($typec == 'OBS') { | 
                                                        |
| 562 | + $data['type'] = 'Observer';  | 
                                                        |
| 563 | +				} elseif ($typec == 'GND') { | 
                                                        |
| 564 | + $data['type'] = 'Ground';  | 
                                                        |
| 565 | +				} elseif ($typec == 'DEL') { | 
                                                        |
| 566 | + $data['type'] = 'Delivery';  | 
                                                        |
| 567 | +				} elseif ($typec == 'DEP') { | 
                                                        |
| 568 | + $data['type'] = 'Departure';  | 
                                                        |
| 569 | +				} elseif ($typec == 'FSS') { | 
                                                        |
| 570 | + $data['type'] = 'Flight Service Station';  | 
                                                        |
| 571 | +				} elseif ($typec == 'CTR') { | 
                                                        |
| 572 | + $data['type'] = 'Control Radar or Centre';  | 
                                                        |
| 573 | +				} elseif ($data['type'] == '') { | 
                                                        |
| 574 | + $data['type'] = 'Observer';  | 
                                                        |
| 575 | + }  | 
                                                        |
| 576 | +				if (!isset($data['source_name'])) { | 
                                                        |
| 577 | + $data['source_name'] = '';  | 
                                                        |
| 578 | + }  | 
                                                        |
| 579 | +				if (isset($ATC)) { | 
                                                        |
| 580 | + echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']);  | 
                                                        |
| 581 | + }  | 
                                                        |
| 441 | 582 | }  | 
                                                        
| 442 | 583 | unset($data);  | 
                                                        
| 443 | 584 | }  | 
                                                        
@@ -456,26 +597,55 @@ discard block  | 
                                                    ||
| 456 | 597 |  		foreach ($all_data['acList'] as $line) { | 
                                                        
| 457 | 598 | $data = array();  | 
                                                        
| 458 | 599 | $data['hex'] = $line['Icao']; // hex  | 
                                                        
| 459 | - if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident  | 
                                                        |
| 460 | - if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude  | 
                                                        |
| 461 | - if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed  | 
                                                        |
| 462 | - if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading  | 
                                                        |
| 463 | - if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat  | 
                                                        |
| 464 | - if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long  | 
                                                        |
| 600 | +		    if (isset($line['Call'])) { | 
                                                        |
| 601 | + $data['ident'] = $line['Call'];  | 
                                                        |
| 602 | + }  | 
                                                        |
| 603 | + // ident  | 
                                                        |
| 604 | +		    if (isset($line['Alt'])) { | 
                                                        |
| 605 | + $data['altitude'] = $line['Alt'];  | 
                                                        |
| 606 | + }  | 
                                                        |
| 607 | + // altitude  | 
                                                        |
| 608 | +		    if (isset($line['Spd'])) { | 
                                                        |
| 609 | + $data['speed'] = $line['Spd'];  | 
                                                        |
| 610 | + }  | 
                                                        |
| 611 | + // speed  | 
                                                        |
| 612 | +		    if (isset($line['Trak'])) { | 
                                                        |
| 613 | + $data['heading'] = $line['Trak'];  | 
                                                        |
| 614 | + }  | 
                                                        |
| 615 | + // heading  | 
                                                        |
| 616 | +		    if (isset($line['Lat'])) { | 
                                                        |
| 617 | + $data['latitude'] = $line['Lat'];  | 
                                                        |
| 618 | + }  | 
                                                        |
| 619 | + // lat  | 
                                                        |
| 620 | +		    if (isset($line['Long'])) { | 
                                                        |
| 621 | + $data['longitude'] = $line['Long'];  | 
                                                        |
| 622 | + }  | 
                                                        |
| 623 | + // long  | 
                                                        |
| 465 | 624 | //$data['verticalrate'] = $line['']; // verticale rate  | 
                                                        
| 466 | - if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk  | 
                                                        |
| 625 | +		    if (isset($line['Sqk'])) { | 
                                                        |
| 626 | + $data['squawk'] = $line['Sqk'];  | 
                                                        |
| 627 | + }  | 
                                                        |
| 628 | + // squawk  | 
                                                        |
| 467 | 629 | $data['emergency'] = ''; // emergency  | 
                                                        
| 468 | - if (isset($line['Reg'])) $data['registration'] = $line['Reg'];  | 
                                                        |
| 630 | +		    if (isset($line['Reg'])) { | 
                                                        |
| 631 | + $data['registration'] = $line['Reg'];  | 
                                                        |
| 632 | + }  | 
                                                        |
| 469 | 633 | /*  | 
                                                        
| 470 | 634 |  		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000); | 
                                                        
| 471 | 635 |  		    else $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        
| 472 | 636 | */  | 
                                                        
| 473 | 637 |  		    $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        
| 474 | - if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];  | 
                                                        |
| 638 | +		    if (isset($line['Type'])) { | 
                                                        |
| 639 | + $data['aircraft_icao'] = $line['Type'];  | 
                                                        |
| 640 | + }  | 
                                                        |
| 475 | 641 | $data['format_source'] = 'aircraftlistjson';  | 
                                                        
| 476 | 642 | $data['id_source'] = $id_source;  | 
                                                        
| 477 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 478 | - if (isset($data['datetime'])) $SI->add($data);  | 
                                                        |
| 643 | +		    if (isset($value['name']) && $value['name'] != '') { | 
                                                        |
| 644 | + $data['source_name'] = $value['name'];  | 
                                                        |
| 645 | + }  | 
                                                        |
| 646 | +		    if (isset($data['datetime'])) { | 
                                                        |
| 647 | + $SI->add($data);  | 
                                                        |
| 648 | + }  | 
                                                        |
| 479 | 649 | unset($data);  | 
                                                        
| 480 | 650 | }  | 
                                                        
| 481 | 651 |  	    } else { | 
                                                        
@@ -495,7 +665,9 @@ discard block  | 
                                                    ||
| 495 | 665 |  		    $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        
| 496 | 666 | $data['format_source'] = 'aircraftlistjson';  | 
                                                        
| 497 | 667 | $data['id_source'] = $id_source;  | 
                                                        
| 498 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 668 | +		    if (isset($value['name']) && $value['name'] != '') { | 
                                                        |
| 669 | + $data['source_name'] = $value['name'];  | 
                                                        |
| 670 | + }  | 
                                                        |
| 499 | 671 | $SI->add($data);  | 
                                                        
| 500 | 672 | unset($data);  | 
                                                        
| 501 | 673 | }  | 
                                                        
@@ -531,7 +703,9 @@ discard block  | 
                                                    ||
| 531 | 703 |  		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]); | 
                                                        
| 532 | 704 | $data['format_source'] = 'planeupdatefaa';  | 
                                                        
| 533 | 705 | $data['id_source'] = $id_source;  | 
                                                        
| 534 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 706 | +		    if (isset($value['name']) && $value['name'] != '') { | 
                                                        |
| 707 | + $data['source_name'] = $value['name'];  | 
                                                        |
| 708 | + }  | 
                                                        |
| 535 | 709 | $SI->add($data);  | 
                                                        
| 536 | 710 | unset($data);  | 
                                                        
| 537 | 711 | }  | 
                                                        
@@ -571,7 +745,9 @@ discard block  | 
                                                    ||
| 571 | 745 | //$buffer = $Common->getData($hosts[$id]);  | 
                                                        
| 572 | 746 | $buffer = $Common->getData($value['host']);  | 
                                                        
| 573 | 747 | $all_data = json_decode($buffer,true);  | 
                                                        
| 574 | - if (!empty($all_data)) $reset = 0;  | 
                                                        |
| 748 | +	    if (!empty($all_data)) { | 
                                                        |
| 749 | + $reset = 0;  | 
                                                        |
| 750 | + }  | 
                                                        |
| 575 | 751 |  	    foreach ($all_data as $key => $line) { | 
                                                        
| 576 | 752 |  		if ($key != 'full_count' && $key != 'version' && $key != 'stats') { | 
                                                        
| 577 | 753 | $data = array();  | 
                                                        
@@ -592,7 +768,9 @@ discard block  | 
                                                    ||
| 592 | 768 |  		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] | 
                                                        
| 593 | 769 | $data['format_source'] = 'fr24json';  | 
                                                        
| 594 | 770 | $data['id_source'] = $id_source;  | 
                                                        
| 595 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 771 | +		    if (isset($value['name']) && $value['name'] != '') { | 
                                                        |
| 772 | + $data['source_name'] = $value['name'];  | 
                                                        |
| 773 | + }  | 
                                                        |
| 596 | 774 | $SI->add($data);  | 
                                                        
| 597 | 775 | unset($data);  | 
                                                        
| 598 | 776 | }  | 
                                                        
@@ -616,23 +794,39 @@ discard block  | 
                                                    ||
| 616 | 794 |  		    if (isset($line['inf'])) { | 
                                                        
| 617 | 795 | $data = array();  | 
                                                        
| 618 | 796 | $data['hex'] = $line['inf']['ia'];  | 
                                                        
| 619 | - if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]  | 
                                                        |
| 797 | +			if (isset($line['inf']['cs'])) { | 
                                                        |
| 798 | + $data['ident'] = $line['inf']['cs'];  | 
                                                        |
| 799 | + }  | 
                                                        |
| 800 | + //$line[13]  | 
                                                        |
| 620 | 801 | $data['altitude'] = round($line['inf']['al']*3.28084); // altitude  | 
                                                        
| 621 | - if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed  | 
                                                        |
| 622 | - if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading  | 
                                                        |
| 802 | +	    		if (isset($line['inf']['gs'])) { | 
                                                        |
| 803 | + $data['speed'] = round($line['inf']['gs']*0.539957);  | 
                                                        |
| 804 | + }  | 
                                                        |
| 805 | + // speed  | 
                                                        |
| 806 | +	    		if (isset($line['inf']['tr'])) { | 
                                                        |
| 807 | + $data['heading'] = $line['inf']['tr'];  | 
                                                        |
| 808 | + }  | 
                                                        |
| 809 | + // heading  | 
                                                        |
| 623 | 810 | $data['latitude'] = $line['pt'][0]; // lat  | 
                                                        
| 624 | 811 | $data['longitude'] = $line['pt'][1]; // long  | 
                                                        
| 625 | 812 | //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate  | 
                                                        
| 626 | - if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk  | 
                                                        |
| 813 | +	    		if (isset($line['inf']['sq'])) { | 
                                                        |
| 814 | + $data['squawk'] = $line['inf']['sq'];  | 
                                                        |
| 815 | + }  | 
                                                        |
| 816 | + // squawk  | 
                                                        |
| 627 | 817 | //$data['aircraft_icao'] = $line[8];  | 
                                                        
| 628 | - if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];  | 
                                                        |
| 818 | +	    		if (isset($line['inf']['rc'])) { | 
                                                        |
| 819 | + $data['registration'] = $line['inf']['rc'];  | 
                                                        |
| 820 | + }  | 
                                                        |
| 629 | 821 | //$data['departure_airport_iata'] = $line[11];  | 
                                                        
| 630 | 822 | //$data['arrival_airport_iata'] = $line[12];  | 
                                                        
| 631 | 823 | //$data['emergency'] = ''; // emergency  | 
                                                        
| 632 | 824 |  			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] | 
                                                        
| 633 | 825 | $data['format_source'] = 'radarvirtueljson';  | 
                                                        
| 634 | 826 | $data['id_source'] = $id_source;  | 
                                                        
| 635 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 827 | +			if (isset($value['name']) && $value['name'] != '') { | 
                                                        |
| 828 | + $data['source_name'] = $value['name'];  | 
                                                        |
| 829 | + }  | 
                                                        |
| 636 | 830 | $SI->add($data);  | 
                                                        
| 637 | 831 | unset($data);  | 
                                                        
| 638 | 832 | }  | 
                                                        
@@ -653,29 +847,62 @@ discard block  | 
                                                    ||
| 653 | 847 | $data['id'] = $line['id'];  | 
                                                        
| 654 | 848 | $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);  | 
                                                        
| 655 | 849 | $data['ident'] = $line['callsign']; // ident  | 
                                                        
| 656 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id  | 
                                                        |
| 657 | - if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name  | 
                                                        |
| 658 | - if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude  | 
                                                        |
| 659 | - if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed  | 
                                                        |
| 660 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading  | 
                                                        |
| 661 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route  | 
                                                        |
| 850 | +		    if (isset($line['pilotid'])) { | 
                                                        |
| 851 | + $data['pilot_id'] = $line['pilotid'];  | 
                                                        |
| 852 | + }  | 
                                                        |
| 853 | + // pilot id  | 
                                                        |
| 854 | +		    if (isset($line['name'])) { | 
                                                        |
| 855 | + $data['pilot_name'] = $line['name'];  | 
                                                        |
| 856 | + }  | 
                                                        |
| 857 | + // pilot name  | 
                                                        |
| 858 | +		    if (isset($line['alt'])) { | 
                                                        |
| 859 | + $data['altitude'] = $line['alt'];  | 
                                                        |
| 860 | + }  | 
                                                        |
| 861 | + // altitude  | 
                                                        |
| 862 | +		    if (isset($line['gs'])) { | 
                                                        |
| 863 | + $data['speed'] = $line['gs'];  | 
                                                        |
| 864 | + }  | 
                                                        |
| 865 | + // speed  | 
                                                        |
| 866 | +		    if (isset($line['heading'])) { | 
                                                        |
| 867 | + $data['heading'] = $line['heading'];  | 
                                                        |
| 868 | + }  | 
                                                        |
| 869 | + // heading  | 
                                                        |
| 870 | +		    if (isset($line['route'])) { | 
                                                        |
| 871 | + $data['waypoints'] = $line['route'];  | 
                                                        |
| 872 | + }  | 
                                                        |
| 873 | + // route  | 
                                                        |
| 662 | 874 | $data['latitude'] = $line['lat']; // lat  | 
                                                        
| 663 | 875 | $data['longitude'] = $line['lon']; // long  | 
                                                        
| 664 | 876 | //$data['verticalrate'] = $line['vrt']; // verticale rate  | 
                                                        
| 665 | 877 | //$data['squawk'] = $line['squawk']; // squawk  | 
                                                        
| 666 | 878 | //$data['emergency'] = ''; // emergency  | 
                                                        
| 667 | - if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];  | 
                                                        |
| 668 | - if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];  | 
                                                        |
| 669 | - if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];  | 
                                                        |
| 879 | +		    if (isset($line['depicao'])) { | 
                                                        |
| 880 | + $data['departure_airport_icao'] = $line['depicao'];  | 
                                                        |
| 881 | + }  | 
                                                        |
| 882 | +		    if (isset($line['deptime'])) { | 
                                                        |
| 883 | + $data['departure_airport_time'] = $line['deptime'];  | 
                                                        |
| 884 | + }  | 
                                                        |
| 885 | +		    if (isset($line['arricao'])) { | 
                                                        |
| 886 | + $data['arrival_airport_icao'] = $line['arricao'];  | 
                                                        |
| 887 | + }  | 
                                                        |
| 670 | 888 | //$data['arrival_airport_time'] = $line['arrtime'];  | 
                                                        
| 671 | - if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];  | 
                                                        |
| 672 | - if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];  | 
                                                        |
| 673 | - if (isset($line['atis'])) $data['info'] = $line['atis'];  | 
                                                        |
| 674 | - else $data['info'] = '';  | 
                                                        |
| 889 | +		    if (isset($line['aircraft'])) { | 
                                                        |
| 890 | + $data['aircraft_icao'] = $line['aircraft'];  | 
                                                        |
| 891 | + }  | 
                                                        |
| 892 | +		    if (isset($line['transponder'])) { | 
                                                        |
| 893 | + $data['squawk'] = $line['transponder'];  | 
                                                        |
| 894 | + }  | 
                                                        |
| 895 | +		    if (isset($line['atis'])) { | 
                                                        |
| 896 | + $data['info'] = $line['atis'];  | 
                                                        |
| 897 | +		    } else { | 
                                                        |
| 898 | + $data['info'] = '';  | 
                                                        |
| 899 | + }  | 
                                                        |
| 675 | 900 | $data['format_source'] = 'pireps';  | 
                                                        
| 676 | 901 | $data['id_source'] = $id_source;  | 
                                                        
| 677 | 902 |  		    $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        
| 678 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 903 | +		    if (isset($value['name']) && $value['name'] != '') { | 
                                                        |
| 904 | + $data['source_name'] = $value['name'];  | 
                                                        |
| 905 | + }  | 
                                                        |
| 679 | 906 |  		    if ($line['icon'] == 'plane') { | 
                                                        
| 680 | 907 | $SI->add($data);  | 
                                                        
| 681 | 908 | // print_r($data);  | 
                                                        
@@ -684,16 +911,28 @@ discard block  | 
                                                    ||
| 684 | 911 |  			$data['info'] = str_replace('&sect;','',$data['info']); | 
                                                        
| 685 | 912 | $typec = substr($data['ident'],-3);  | 
                                                        
| 686 | 913 | $data['type'] = '';  | 
                                                        
| 687 | - if ($typec == 'APP') $data['type'] = 'Approach';  | 
                                                        |
| 688 | - elseif ($typec == 'TWR') $data['type'] = 'Tower';  | 
                                                        |
| 689 | - elseif ($typec == 'OBS') $data['type'] = 'Observer';  | 
                                                        |
| 690 | - elseif ($typec == 'GND') $data['type'] = 'Ground';  | 
                                                        |
| 691 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery';  | 
                                                        |
| 692 | - elseif ($typec == 'DEP') $data['type'] = 'Departure';  | 
                                                        |
| 693 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';  | 
                                                        |
| 694 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';  | 
                                                        |
| 695 | - else $data['type'] = 'Observer';  | 
                                                        |
| 696 | - if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);  | 
                                                        |
| 914 | +			if ($typec == 'APP') { | 
                                                        |
| 915 | + $data['type'] = 'Approach';  | 
                                                        |
| 916 | +			} elseif ($typec == 'TWR') { | 
                                                        |
| 917 | + $data['type'] = 'Tower';  | 
                                                        |
| 918 | +			} elseif ($typec == 'OBS') { | 
                                                        |
| 919 | + $data['type'] = 'Observer';  | 
                                                        |
| 920 | +			} elseif ($typec == 'GND') { | 
                                                        |
| 921 | + $data['type'] = 'Ground';  | 
                                                        |
| 922 | +			} elseif ($typec == 'DEL') { | 
                                                        |
| 923 | + $data['type'] = 'Delivery';  | 
                                                        |
| 924 | +			} elseif ($typec == 'DEP') { | 
                                                        |
| 925 | + $data['type'] = 'Departure';  | 
                                                        |
| 926 | +			} elseif ($typec == 'FSS') { | 
                                                        |
| 927 | + $data['type'] = 'Flight Service Station';  | 
                                                        |
| 928 | +			} elseif ($typec == 'CTR') { | 
                                                        |
| 929 | + $data['type'] = 'Control Radar or Centre';  | 
                                                        |
| 930 | +			} else { | 
                                                        |
| 931 | + $data['type'] = 'Observer';  | 
                                                        |
| 932 | + }  | 
                                                        |
| 933 | +			if (isset($ATC)) { | 
                                                        |
| 934 | + echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']);  | 
                                                        |
| 935 | + }  | 
                                                        |
| 697 | 936 | }  | 
                                                        
| 698 | 937 | unset($data);  | 
                                                        
| 699 | 938 | }  | 
                                                        
@@ -703,7 +942,9 @@ discard block  | 
                                                    ||
| 703 | 942 |      	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) { | 
                                                        
| 704 | 943 |      	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        
| 705 | 944 | //$buffer = $Common->getData($hosts[$id]);  | 
                                                        
| 706 | - if ($globalDebug) echo 'Get Data...'."\n";  | 
                                                        |
| 945 | +	    if ($globalDebug) { | 
                                                        |
| 946 | + echo 'Get Data...'."\n";  | 
                                                        |
| 947 | + }  | 
                                                        |
| 707 | 948 | $buffer = $Common->getData($value['host']);  | 
                                                        
| 708 | 949 | $all_data = json_decode($buffer,true);  | 
                                                        
| 709 | 950 |  	    if ($buffer != '' && is_array($all_data)) { | 
                                                        
@@ -711,10 +952,16 @@ discard block  | 
                                                    ||
| 711 | 952 |  		foreach ($all_data as $line) { | 
                                                        
| 712 | 953 | $data = array();  | 
                                                        
| 713 | 954 | //$data['id'] = $line['id']; // id not usable  | 
                                                        
| 714 | - if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];  | 
                                                        |
| 955 | +	    	    if (isset($line['pilotid'])) { | 
                                                        |
| 956 | + $data['id'] = $line['pilotid'].$line['flightnum'];  | 
                                                        |
| 957 | + }  | 
                                                        |
| 715 | 958 | $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex  | 
                                                        
| 716 | - if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];  | 
                                                        |
| 717 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];  | 
                                                        |
| 959 | +	    	    if (isset($line['pilotname'])) { | 
                                                        |
| 960 | + $data['pilot_name'] = $line['pilotname'];  | 
                                                        |
| 961 | + }  | 
                                                        |
| 962 | +	    	    if (isset($line['pilotid'])) { | 
                                                        |
| 963 | + $data['pilot_id'] = $line['pilotid'];  | 
                                                        |
| 964 | + }  | 
                                                        |
| 718 | 965 | $data['ident'] = $line['flightnum']; // ident  | 
                                                        
| 719 | 966 | $data['altitude'] = $line['alt']; // altitude  | 
                                                        
| 720 | 967 | $data['speed'] = $line['gs']; // speed  | 
                                                        
@@ -732,27 +979,41 @@ discard block  | 
                                                    ||
| 732 | 979 | $data['arrival_airport_icao'] = $line['arricao'];  | 
                                                        
| 733 | 980 | $data['arrival_airport_time'] = $line['arrtime'];  | 
                                                        
| 734 | 981 | $data['registration'] = $line['aircraft'];  | 
                                                        
| 735 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route  | 
                                                        |
| 982 | +		    if (isset($line['route'])) { | 
                                                        |
| 983 | + $data['waypoints'] = $line['route'];  | 
                                                        |
| 984 | + }  | 
                                                        |
| 985 | + // route  | 
                                                        |
| 736 | 986 |  		    if (isset($line['aircraftname'])) { | 
                                                        
| 737 | 987 | $line['aircraftname'] = strtoupper($line['aircraftname']);  | 
                                                        
| 738 | 988 |  			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); | 
                                                        
| 739 | 989 |  	    		$aircraft_data = explode('-',$line['aircraftname']); | 
                                                        
| 740 | - if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];  | 
                                                        |
| 741 | - elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];  | 
                                                        |
| 742 | -	    		else { | 
                                                        |
| 990 | +	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) { | 
                                                        |
| 991 | + $data['aircraft_icao'] = $aircraft_data[0];  | 
                                                        |
| 992 | +	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) { | 
                                                        |
| 993 | + $data['aircraft_icao'] = $aircraft_data[1];  | 
                                                        |
| 994 | +	    		} else { | 
                                                        |
| 743 | 995 |  	    		    $aircraft_data = explode(' ',$line['aircraftname']); | 
                                                        
| 744 | - if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];  | 
                                                        |
| 745 | - else $data['aircraft_icao'] = $line['aircraftname'];  | 
                                                        |
| 996 | +	    		    if (isset($aircraft_data[1])) { | 
                                                        |
| 997 | + $data['aircraft_icao'] = $aircraft_data[1];  | 
                                                        |
| 998 | +	    		    } else { | 
                                                        |
| 999 | + $data['aircraft_icao'] = $line['aircraftname'];  | 
                                                        |
| 1000 | + }  | 
                                                        |
| 746 | 1001 | }  | 
                                                        
| 747 | 1002 | }  | 
                                                        
| 748 | - if (isset($line['route'])) $data['waypoints'] = $line['route'];  | 
                                                        |
| 1003 | +    		    if (isset($line['route'])) { | 
                                                        |
| 1004 | + $data['waypoints'] = $line['route'];  | 
                                                        |
| 1005 | + }  | 
                                                        |
| 749 | 1006 | $data['id_source'] = $id_source;  | 
                                                        
| 750 | 1007 | $data['format_source'] = 'phpvmacars';  | 
                                                        
| 751 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 1008 | +		    if (isset($value['name']) && $value['name'] != '') { | 
                                                        |
| 1009 | + $data['source_name'] = $value['name'];  | 
                                                        |
| 1010 | + }  | 
                                                        |
| 752 | 1011 | $SI->add($data);  | 
                                                        
| 753 | 1012 | unset($data);  | 
                                                        
| 754 | 1013 | }  | 
                                                        
| 755 | - if ($globalDebug) echo 'No more data...'."\n";  | 
                                                        |
| 1014 | +		if ($globalDebug) { | 
                                                        |
| 1015 | + echo 'No more data...'."\n";  | 
                                                        |
| 1016 | + }  | 
                                                        |
| 756 | 1017 | unset($buffer);  | 
                                                        
| 757 | 1018 | unset($all_data);  | 
                                                        
| 758 | 1019 | }  | 
                                                        
@@ -760,7 +1021,9 @@ discard block  | 
                                                    ||
| 760 | 1021 | $last_exec[$id]['last'] = time();  | 
                                                        
| 761 | 1022 |      	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) { | 
                                                        
| 762 | 1023 | //$buffer = $Common->getData($hosts[$id]);  | 
                                                        
| 763 | - if ($globalDebug) echo 'Get Data...'."\n";  | 
                                                        |
| 1024 | +	    if ($globalDebug) { | 
                                                        |
| 1025 | + echo 'Get Data...'."\n";  | 
                                                        |
| 1026 | + }  | 
                                                        |
| 764 | 1027 | $buffer = $Common->getData($value['host']);  | 
                                                        
| 765 | 1028 | $all_data = json_decode($buffer,true);  | 
                                                        
| 766 | 1029 |  	    if ($buffer != '' && is_array($all_data)) { | 
                                                        
@@ -789,15 +1052,22 @@ discard block  | 
                                                    ||
| 789 | 1052 | $data['arrival_airport_icao'] = $line['arrival'];  | 
                                                        
| 790 | 1053 | //$data['arrival_airport_time'] = $line['arrival_time'];  | 
                                                        
| 791 | 1054 | //$data['registration'] = $line['aircraft'];  | 
                                                        
| 792 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route  | 
                                                        |
| 1055 | +		    if (isset($line['route'])) { | 
                                                        |
| 1056 | + $data['waypoints'] = $line['route'];  | 
                                                        |
| 1057 | + }  | 
                                                        |
| 1058 | + // route  | 
                                                        |
| 793 | 1059 | $data['aircraft_icao'] = $line['plane_type'];  | 
                                                        
| 794 | 1060 | $data['id_source'] = $id_source;  | 
                                                        
| 795 | 1061 | $data['format_source'] = 'vam';  | 
                                                        
| 796 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];  | 
                                                        |
| 1062 | +		    if (isset($value['name']) && $value['name'] != '') { | 
                                                        |
| 1063 | + $data['source_name'] = $value['name'];  | 
                                                        |
| 1064 | + }  | 
                                                        |
| 797 | 1065 | $SI->add($data);  | 
                                                        
| 798 | 1066 | unset($data);  | 
                                                        
| 799 | 1067 | }  | 
                                                        
| 800 | - if ($globalDebug) echo 'No more data...'."\n";  | 
                                                        |
| 1068 | +		if ($globalDebug) { | 
                                                        |
| 1069 | + echo 'No more data...'."\n";  | 
                                                        |
| 1070 | + }  | 
                                                        |
| 801 | 1071 | unset($buffer);  | 
                                                        
| 802 | 1072 | unset($all_data);  | 
                                                        
| 803 | 1073 | }  | 
                                                        
@@ -805,7 +1075,9 @@ discard block  | 
                                                    ||
| 805 | 1075 | $last_exec[$id]['last'] = time();  | 
                                                        
| 806 | 1076 |  	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') { | 
                                                        
| 807 | 1077 |  	} elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3') { | 
                                                        
| 808 | -	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); | 
                                                        |
| 1078 | +	    if (function_exists('pcntl_fork')) { | 
                                                        |
| 1079 | + pcntl_signal_dispatch();  | 
                                                        |
| 1080 | + }  | 
                                                        |
| 809 | 1081 | //$last_exec[$id]['last'] = time();  | 
                                                        
| 810 | 1082 | |
| 811 | 1083 | //$read = array( $sockets[$id] );  | 
                                                        
@@ -813,7 +1085,9 @@ discard block  | 
                                                    ||
| 813 | 1085 | $write = NULL;  | 
                                                        
| 814 | 1086 | $e = NULL;  | 
                                                        
| 815 | 1087 | $n = socket_select($read, $write, $e, $timeout);  | 
                                                        
| 816 | - if ($e != NULL) var_dump($e);  | 
                                                        |
| 1088 | +	    if ($e != NULL) { | 
                                                        |
| 1089 | + var_dump($e);  | 
                                                        |
| 1090 | + }  | 
                                                        |
| 817 | 1091 |  	    if ($n > 0) { | 
                                                        
| 818 | 1092 | $reset = 0;  | 
                                                        
| 819 | 1093 |  		foreach ($read as $nb => $r) { | 
                                                        
@@ -835,7 +1109,9 @@ discard block  | 
                                                    ||
| 835 | 1109 |  		    if ($buffer != '') { | 
                                                        
| 836 | 1110 | $tt[$format] = 0;  | 
                                                        
| 837 | 1111 |  			if ($format == 'acarssbs3') { | 
                                                        
| 838 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n";  | 
                                                        |
| 1112 | +                    	    if ($globalDebug) { | 
                                                        |
| 1113 | + echo 'ACARS : '.$buffer."\n";  | 
                                                        |
| 1114 | + }  | 
                                                        |
| 839 | 1115 | $ACARS->add(trim($buffer));  | 
                                                        
| 840 | 1116 | $ACARS->deleteLiveAcarsData();  | 
                                                        
| 841 | 1117 |  			} elseif ($format == 'raw') { | 
                                                        
@@ -844,9 +1120,15 @@ discard block  | 
                                                    ||
| 844 | 1120 |  			    if (is_array($data)) { | 
                                                        
| 845 | 1121 |  				$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        
| 846 | 1122 | $data['format_source'] = 'raw';  | 
                                                        
| 847 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];  | 
                                                        |
| 848 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 849 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);  | 
                                                        |
| 1123 | +				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { | 
                                                        |
| 1124 | + $data['source_name'] = $globalSources[$nb]['name'];  | 
                                                        |
| 1125 | + }  | 
                                                        |
| 1126 | +    				if (isset($globalSources[$nb]['sourcestats'])) { | 
                                                        |
| 1127 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 1128 | + }  | 
                                                        |
| 1129 | +                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { | 
                                                        |
| 1130 | + $SI->add($data);  | 
                                                        |
| 1131 | + }  | 
                                                        |
| 850 | 1132 | }  | 
                                                        
| 851 | 1133 |                          } elseif ($format == 'flightgearsp') { | 
                                                        
| 852 | 1134 | //echo $buffer."\n";  | 
                                                        
@@ -864,11 +1146,15 @@ discard block  | 
                                                    ||
| 864 | 1146 | $data['speed'] = round($line[5]*1.94384);  | 
                                                        
| 865 | 1147 |  				$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        
| 866 | 1148 | $data['format_source'] = 'flightgearsp';  | 
                                                        
| 867 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);  | 
                                                        |
| 1149 | +				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { | 
                                                        |
| 1150 | + $SI->add($data);  | 
                                                        |
| 1151 | + }  | 
                                                        |
| 868 | 1152 | $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 );  | 
                                                        
| 869 | 1153 | }  | 
                                                        
| 870 | 1154 |                          } elseif ($format == 'acars') { | 
                                                        
| 871 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n";  | 
                                                        |
| 1155 | +                    	    if ($globalDebug) { | 
                                                        |
| 1156 | + echo 'ACARS : '.$buffer."\n";  | 
                                                        |
| 1157 | + }  | 
                                                        |
| 872 | 1158 | $ACARS->add(trim($buffer));  | 
                                                        
| 873 | 1159 | socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);  | 
                                                        
| 874 | 1160 | $ACARS->deleteLiveAcarsData();  | 
                                                        
@@ -889,7 +1175,9 @@ discard block  | 
                                                    ||
| 889 | 1175 | $aircraft_type = $line[10];  | 
                                                        
| 890 | 1176 |  				    $aircraft_type = preg_split(':/:',$aircraft_type); | 
                                                        
| 891 | 1177 | $data['aircraft_name'] = substr(end($aircraft_type),0,-4);  | 
                                                        
| 892 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);  | 
                                                        |
| 1178 | +				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { | 
                                                        |
| 1179 | + $SI->add($data);  | 
                                                        |
| 1180 | + }  | 
                                                        |
| 893 | 1181 | }  | 
                                                        
| 894 | 1182 | }  | 
                                                        
| 895 | 1183 |  			} elseif ($format == 'beast') { | 
                                                        
@@ -905,21 +1193,43 @@ discard block  | 
                                                    ||
| 905 | 1193 | $data['hex'] = $lined['hexid'];  | 
                                                        
| 906 | 1194 |      				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; | 
                                                        
| 907 | 1195 |      				$data['datetime'] = date('Y-m-d H:i:s');; | 
                                                        
| 908 | - if (isset($lined['ident'])) $data['ident'] = $lined['ident'];  | 
                                                        |
| 909 | - if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];  | 
                                                        |
| 910 | - if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];  | 
                                                        |
| 911 | - if (isset($lined['speed'])) $data['speed'] = $lined['speed'];  | 
                                                        |
| 912 | - if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];  | 
                                                        |
| 913 | - if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];  | 
                                                        |
| 914 | - if (isset($lined['heading'])) $data['heading'] = $lined['heading'];  | 
                                                        |
| 1196 | +    				if (isset($lined['ident'])) { | 
                                                        |
| 1197 | + $data['ident'] = $lined['ident'];  | 
                                                        |
| 1198 | + }  | 
                                                        |
| 1199 | +    				if (isset($lined['lat'])) { | 
                                                        |
| 1200 | + $data['latitude'] = $lined['lat'];  | 
                                                        |
| 1201 | + }  | 
                                                        |
| 1202 | +    				if (isset($lined['lon'])) { | 
                                                        |
| 1203 | + $data['longitude'] = $lined['lon'];  | 
                                                        |
| 1204 | + }  | 
                                                        |
| 1205 | +    				if (isset($lined['speed'])) { | 
                                                        |
| 1206 | + $data['speed'] = $lined['speed'];  | 
                                                        |
| 1207 | + }  | 
                                                        |
| 1208 | +    				if (isset($lined['squawk'])) { | 
                                                        |
| 1209 | + $data['squawk'] = $lined['squawk'];  | 
                                                        |
| 1210 | + }  | 
                                                        |
| 1211 | +    				if (isset($lined['alt'])) { | 
                                                        |
| 1212 | + $data['altitude'] = $lined['alt'];  | 
                                                        |
| 1213 | + }  | 
                                                        |
| 1214 | +    				if (isset($lined['heading'])) { | 
                                                        |
| 1215 | + $data['heading'] = $lined['heading'];  | 
                                                        |
| 1216 | + }  | 
                                                        |
| 915 | 1217 | $data['id_source'] = $id_source;  | 
                                                        
| 916 | 1218 | $data['format_source'] = 'tsv';  | 
                                                        
| 917 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];  | 
                                                        |
| 918 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 919 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);  | 
                                                        |
| 1219 | +    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { | 
                                                        |
| 1220 | + $data['source_name'] = $globalSources[$nb]['name'];  | 
                                                        |
| 1221 | + }  | 
                                                        |
| 1222 | +    				if (isset($globalSources[$nb]['sourcestats'])) { | 
                                                        |
| 1223 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 1224 | + }  | 
                                                        |
| 1225 | +    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { | 
                                                        |
| 1226 | + $SI->add($data);  | 
                                                        |
| 1227 | + }  | 
                                                        |
| 920 | 1228 | unset($lined);  | 
                                                        
| 921 | 1229 | unset($data);  | 
                                                        
| 922 | - } else $error = true;  | 
                                                        |
| 1230 | +    			    } else { | 
                                                        |
| 1231 | + $error = true;  | 
                                                        |
| 1232 | + }  | 
                                                        |
| 923 | 1233 |  			} elseif ($format == 'aprs' && $use_aprs) { | 
                                                        
| 924 | 1234 |  			    if ($aprs_connect == 0) { | 
                                                        
| 925 | 1235 | $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 );  | 
                                                        
@@ -944,36 +1254,50 @@ discard block  | 
                                                    ||
| 944 | 1254 | $data = array();  | 
                                                        
| 945 | 1255 | //print_r($line);  | 
                                                        
| 946 | 1256 | $data['hex'] = $line['address'];  | 
                                                        
| 947 | -				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); | 
                                                        |
| 948 | -				    else $data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 1257 | +				    if (isset($line['timestamp'])) { | 
                                                        |
| 1258 | +				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); | 
                                                        |
| 1259 | +				    } else { | 
                                                        |
| 1260 | +				    	$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        |
| 1261 | + }  | 
                                                        |
| 949 | 1262 |  				    //$data['datetime'] = date('Y-m-d H:i:s'); | 
                                                        
| 950 | 1263 | $data['ident'] = $line['ident'];  | 
                                                        
| 951 | 1264 | $data['latitude'] = $line['latitude'];  | 
                                                        
| 952 | 1265 | $data['longitude'] = $line['longitude'];  | 
                                                        
| 953 | 1266 | //$data['verticalrate'] = $line[16];  | 
                                                        
| 954 | - if (isset($line['speed'])) $data['speed'] = $line['speed'];  | 
                                                        |
| 955 | - else $data['speed'] = 0;  | 
                                                        |
| 1267 | +				    if (isset($line['speed'])) { | 
                                                        |
| 1268 | + $data['speed'] = $line['speed'];  | 
                                                        |
| 1269 | +				    } else { | 
                                                        |
| 1270 | + $data['speed'] = 0;  | 
                                                        |
| 1271 | + }  | 
                                                        |
| 956 | 1272 | $data['altitude'] = $line['altitude'];  | 
                                                        
| 957 | - if (isset($line['heading'])) $data['heading'] = $line['heading'];  | 
                                                        |
| 1273 | +				    if (isset($line['heading'])) { | 
                                                        |
| 1274 | + $data['heading'] = $line['heading'];  | 
                                                        |
| 1275 | + }  | 
                                                        |
| 958 | 1276 | //else $data['heading'] = 0;  | 
                                                        
| 959 | 1277 | $data['aircraft_type'] = $line['stealth'];  | 
                                                        
| 960 | - if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;  | 
                                                        |
| 1278 | +				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) { | 
                                                        |
| 1279 | + $data['noarchive'] = true;  | 
                                                        |
| 1280 | + }  | 
                                                        |
| 961 | 1281 | $data['id_source'] = $id_source;  | 
                                                        
| 962 | 1282 | $data['format_source'] = 'aprs';  | 
                                                        
| 963 | 1283 | $data['source_name'] = $line['source'];  | 
                                                        
| 964 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 1284 | +    				    if (isset($globalSources[$nb]['sourcestats'])) { | 
                                                        |
| 1285 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 1286 | + }  | 
                                                        |
| 965 | 1287 |  				    $currentdate = date('Y-m-d H:i:s'); | 
                                                        
| 966 | 1288 | $aprsdate = strtotime($data['datetime']);  | 
                                                        
| 967 | 1289 | // Accept data if time <= system time + 20s  | 
                                                        
| 968 | 1290 |  				    if (($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { | 
                                                        
| 969 | 1291 | $send = $SI->add($data);  | 
                                                        
| 970 | 1292 |  				    } else { | 
                                                        
| 971 | - if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";  | 
                                                        |
| 972 | - else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";  | 
                                                        |
| 1293 | +					if ($line['stealth'] != 0) { | 
                                                        |
| 1294 | + echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";  | 
                                                        |
| 1295 | +					} else { | 
                                                        |
| 1296 | + echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";  | 
                                                        |
| 1297 | + }  | 
                                                        |
| 973 | 1298 | }  | 
                                                        
| 974 | 1299 | unset($data);  | 
                                                        
| 975 | - }  | 
                                                        |
| 976 | -				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { | 
                                                        |
| 1300 | +				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') { | 
                                                        |
| 977 | 1301 | echo '!! Weather Station not yet supported'."\n";  | 
                                                        
| 978 | 1302 | }  | 
                                                        
| 979 | 1303 |  				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n"; | 
                                                        
@@ -1006,25 +1330,42 @@ discard block  | 
                                                    ||
| 1006 | 1330 | $data['ground'] = $line[21];  | 
                                                        
| 1007 | 1331 | $data['emergency'] = $line[19];  | 
                                                        
| 1008 | 1332 | $data['format_source'] = 'sbs';  | 
                                                        
| 1009 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];  | 
                                                        |
| 1010 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 1333 | +				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { | 
                                                        |
| 1334 | + $data['source_name'] = $globalSources[$nb]['name'];  | 
                                                        |
| 1335 | + }  | 
                                                        |
| 1336 | +    				if (isset($globalSources[$nb]['sourcestats'])) { | 
                                                        |
| 1337 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats'];  | 
                                                        |
| 1338 | + }  | 
                                                        |
| 1011 | 1339 | $data['id_source'] = $id_source;  | 
                                                        
| 1012 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);  | 
                                                        |
| 1013 | - else $error = true;  | 
                                                        |
| 1340 | +    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { | 
                                                        |
| 1341 | + $send = $SI->add($data);  | 
                                                        |
| 1342 | +    				} else { | 
                                                        |
| 1343 | + $error = true;  | 
                                                        |
| 1344 | + }  | 
                                                        |
| 1014 | 1345 | unset($data);  | 
                                                        
| 1015 | - } else $error = true;  | 
                                                        |
| 1346 | +    			    } else { | 
                                                        |
| 1347 | + $error = true;  | 
                                                        |
| 1348 | + }  | 
                                                        |
| 1016 | 1349 |  			    if ($error) { | 
                                                        
| 1017 | 1350 |  				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) {  | 
                                                        
| 1018 | - if ($globalDebug) echo "Not a message. Ignoring... \n";  | 
                                                        |
| 1351 | +					if ($globalDebug) { | 
                                                        |
| 1352 | + echo "Not a message. Ignoring... \n";  | 
                                                        |
| 1353 | + }  | 
                                                        |
| 1019 | 1354 |  				} else { | 
                                                        
| 1020 | - if ($globalDebug) echo "Wrong line format. Ignoring... \n";  | 
                                                        |
| 1355 | +					if ($globalDebug) { | 
                                                        |
| 1356 | + echo "Wrong line format. Ignoring... \n";  | 
                                                        |
| 1357 | + }  | 
                                                        |
| 1021 | 1358 |  					if ($globalDebug) { | 
                                                        
| 1022 | 1359 | echo $buffer;  | 
                                                        
| 1023 | 1360 | print_r($line);  | 
                                                        
| 1024 | 1361 | }  | 
                                                        
| 1025 | 1362 | //socket_close($r);  | 
                                                        
| 1026 | - if ($globalDebug) echo "Reconnect after an error...\n";  | 
                                                        |
| 1027 | - if ($format == 'aprs') $aprs_connect = 0;  | 
                                                        |
| 1363 | +					if ($globalDebug) { | 
                                                        |
| 1364 | + echo "Reconnect after an error...\n";  | 
                                                        |
| 1365 | + }  | 
                                                        |
| 1366 | +					if ($format == 'aprs') { | 
                                                        |
| 1367 | + $aprs_connect = 0;  | 
                                                        |
| 1368 | + }  | 
                                                        |
| 1028 | 1369 | $sourceer[$nb] = $globalSources[$nb];  | 
                                                        
| 1029 | 1370 | connect_all($sourceer);  | 
                                                        
| 1030 | 1371 | $sourceer = array();  | 
                                                        
@@ -1032,10 +1373,14 @@ discard block  | 
                                                    ||
| 1032 | 1373 | }  | 
                                                        
| 1033 | 1374 | }  | 
                                                        
| 1034 | 1375 | // Sleep for xxx microseconds  | 
                                                        
| 1035 | - if (isset($globalSBSSleep)) usleep($globalSBSSleep);  | 
                                                        |
| 1376 | +			if (isset($globalSBSSleep)) { | 
                                                        |
| 1377 | + usleep($globalSBSSleep);  | 
                                                        |
| 1378 | + }  | 
                                                        |
| 1036 | 1379 |  		    } else { | 
                                                        
| 1037 | 1380 |  			if ($format == 'flightgearmp') { | 
                                                        
| 1038 | - if ($globalDebug) echo "Reconnect FlightGear MP...";  | 
                                                        |
| 1381 | +			    	if ($globalDebug) { | 
                                                        |
| 1382 | + echo "Reconnect FlightGear MP...";  | 
                                                        |
| 1383 | + }  | 
                                                        |
| 1039 | 1384 | //@socket_close($r);  | 
                                                        
| 1040 | 1385 | sleep($globalMinFetch);  | 
                                                        
| 1041 | 1386 | $sourcefg[$nb] = $globalSources[$nb];  | 
                                                        
@@ -1044,10 +1389,15 @@ discard block  | 
                                                    ||
| 1044 | 1389 | break;  | 
                                                        
| 1045 | 1390 | |
| 1046 | 1391 |  			} elseif ($format != 'acars' && $format != 'flightgearsp') { | 
                                                        
| 1047 | - if (isset($tt[$format])) $tt[$format]++;  | 
                                                        |
| 1048 | - else $tt[$format] = 0;  | 
                                                        |
| 1392 | +			    if (isset($tt[$format])) { | 
                                                        |
| 1393 | + $tt[$format]++;  | 
                                                        |
| 1394 | +			    } else { | 
                                                        |
| 1395 | + $tt[$format] = 0;  | 
                                                        |
| 1396 | + }  | 
                                                        |
| 1049 | 1397 |  			    if ($tt[$format] > 30) { | 
                                                        
| 1050 | - if ($globalDebug) echo "ERROR : Reconnect ".$format."...";  | 
                                                        |
| 1398 | +				if ($globalDebug) { | 
                                                        |
| 1399 | + echo "ERROR : Reconnect ".$format."...";  | 
                                                        |
| 1400 | + }  | 
                                                        |
| 1051 | 1401 | //@socket_close($r);  | 
                                                        
| 1052 | 1402 | sleep(2);  | 
                                                        
| 1053 | 1403 | $aprs_connect = 0;  | 
                                                        
@@ -1063,12 +1413,18 @@ discard block  | 
                                                    ||
| 1063 | 1413 | }  | 
                                                        
| 1064 | 1414 |  	    } else { | 
                                                        
| 1065 | 1415 | $error = socket_strerror(socket_last_error());  | 
                                                        
| 1066 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";  | 
                                                        |
| 1416 | +		if ($globalDebug) { | 
                                                        |
| 1417 | + echo "ERROR : socket_select give this error ".$error . "\n";  | 
                                                        |
| 1418 | + }  | 
                                                        |
| 1067 | 1419 |  		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || time() - $time >= $timeout) { | 
                                                        
| 1068 | - if (isset($globalDebug)) echo "Restarting...\n";  | 
                                                        |
| 1420 | +			if (isset($globalDebug)) { | 
                                                        |
| 1421 | + echo "Restarting...\n";  | 
                                                        |
| 1422 | + }  | 
                                                        |
| 1069 | 1423 | // Restart the script if possible  | 
                                                        
| 1070 | 1424 |  			if (is_array($sockets)) { | 
                                                        
| 1071 | - if ($globalDebug) echo "Shutdown all sockets...";  | 
                                                        |
| 1425 | +			    if ($globalDebug) { | 
                                                        |
| 1426 | + echo "Shutdown all sockets...";  | 
                                                        |
| 1427 | + }  | 
                                                        |
| 1072 | 1428 | |
| 1073 | 1429 |  			    foreach ($sockets as $sock) { | 
                                                        
| 1074 | 1430 | @socket_shutdown($sock,2);  | 
                                                        
@@ -1076,18 +1432,24 @@ discard block  | 
                                                    ||
| 1076 | 1432 | }  | 
                                                        
| 1077 | 1433 | |
| 1078 | 1434 | }  | 
                                                        
| 1079 | - if ($globalDebug) echo "Restart all connections...";  | 
                                                        |
| 1435 | +			if ($globalDebug) { | 
                                                        |
| 1436 | + echo "Restart all connections...";  | 
                                                        |
| 1437 | + }  | 
                                                        |
| 1080 | 1438 | sleep(2);  | 
                                                        
| 1081 | 1439 | $time = time();  | 
                                                        
| 1082 | 1440 | //connect_all($hosts);  | 
                                                        
| 1083 | 1441 | $aprs_connect = 0;  | 
                                                        
| 1084 | -			if ($reset > 40) exit('Too many attempts...'); | 
                                                        |
| 1442 | +			if ($reset > 40) { | 
                                                        |
| 1443 | +				exit('Too many attempts...'); | 
                                                        |
| 1444 | + }  | 
                                                        |
| 1085 | 1445 | connect_all($globalSources);  | 
                                                        
| 1086 | 1446 | }  | 
                                                        
| 1087 | 1447 | }  | 
                                                        
| 1088 | 1448 | }  | 
                                                        
| 1089 | 1449 |  	if ($globalDaemon === false) { | 
                                                        
| 1090 | - if ($globalDebug) echo 'Check all...'."\n";  | 
                                                        |
| 1450 | +	    if ($globalDebug) { | 
                                                        |
| 1451 | + echo 'Check all...'."\n";  | 
                                                        |
| 1452 | + }  | 
                                                        |
| 1091 | 1453 | $SI->checkAll();  | 
                                                        
| 1092 | 1454 | }  | 
                                                        
| 1093 | 1455 | }  | 
                                                        
@@ -9,16 +9,16 @@ discard block  | 
                                                    ||
| 9 | 9 | require_once(dirname(__FILE__).'/class.Source.php');  | 
                                                        
| 10 | 10 | |
| 11 | 11 |  class SpotterImport { | 
                                                        
| 12 | - private $all_flights = array();  | 
                                                        |
| 13 | - private $last_delete_hourly = 0;  | 
                                                        |
| 14 | - private $last_delete = 0;  | 
                                                        |
| 15 | - private $stats = array();  | 
                                                        |
| 16 | - private $tmd = 0;  | 
                                                        |
| 17 | - private $source_location = array();  | 
                                                        |
| 18 | - public $db = null;  | 
                                                        |
| 19 | - public $nb = 0;  | 
                                                        |
| 20 | -  | 
                                                        |
| 21 | -    public function __construct($dbc = null) { | 
                                                        |
| 12 | + private $all_flights = array();  | 
                                                        |
| 13 | + private $last_delete_hourly = 0;  | 
                                                        |
| 14 | + private $last_delete = 0;  | 
                                                        |
| 15 | + private $stats = array();  | 
                                                        |
| 16 | + private $tmd = 0;  | 
                                                        |
| 17 | + private $source_location = array();  | 
                                                        |
| 18 | + public $db = null;  | 
                                                        |
| 19 | + public $nb = 0;  | 
                                                        |
| 20 | +  | 
                                                        |
| 21 | +	public function __construct($dbc = null) { | 
                                                        |
| 22 | 22 | global $globalBeta;  | 
                                                        
| 23 | 23 | $Connection = new Connection($dbc);  | 
                                                        
| 24 | 24 | $this->db = $Connection->db();  | 
                                                        
@@ -29,18 +29,18 @@ discard block  | 
                                                    ||
| 29 | 29 |  	$currentdate = date('Y-m-d'); | 
                                                        
| 30 | 30 | $sourcestat = $Stats->getStatsSource($currentdate);  | 
                                                        
| 31 | 31 |  	if (!empty($sourcestat)) { | 
                                                        
| 32 | -	    foreach($sourcestat as $srcst) { | 
                                                        |
| 33 | - $type = $srcst['stats_type'];  | 
                                                        |
| 32 | +		foreach($sourcestat as $srcst) { | 
                                                        |
| 33 | + $type = $srcst['stats_type'];  | 
                                                        |
| 34 | 34 |  		if ($type == 'polar' || $type == 'hist') { | 
                                                        
| 35 | - $source = $srcst['source_name'];  | 
                                                        |
| 36 | - $data = $srcst['source_data'];  | 
                                                        |
| 37 | - $this->stats[$currentdate][$source][$type] = json_decode($data,true);  | 
                                                        |
| 38 | - }  | 
                                                        |
| 39 | - }  | 
                                                        |
| 35 | + $source = $srcst['source_name'];  | 
                                                        |
| 36 | + $data = $srcst['source_data'];  | 
                                                        |
| 37 | + $this->stats[$currentdate][$source][$type] = json_decode($data,true);  | 
                                                        |
| 38 | + }  | 
                                                        |
| 39 | + }  | 
                                                        |
| 40 | + }  | 
                                                        |
| 40 | 41 | }  | 
                                                        
| 41 | - }  | 
                                                        |
| 42 | 42 | |
| 43 | -    public function get_Schedule($id,$ident) { | 
                                                        |
| 43 | +	public function get_Schedule($id,$ident) { | 
                                                        |
| 44 | 44 | global $globalDebug, $globalFork, $globalSchedulesFetch;  | 
                                                        
| 45 | 45 | // Get schedule here, so it's done only one time  | 
                                                        
| 46 | 46 | |
@@ -60,42 +60,42 @@ discard block  | 
                                                    ||
| 60 | 60 | $operator = $Spotter->getOperator($ident);  | 
                                                        
| 61 | 61 | $scheduleexist = false;  | 
                                                        
| 62 | 62 |  	if ($Schedule->checkSchedule($operator) == 0) { | 
                                                        
| 63 | - $operator = $Translation->checkTranslation($ident);  | 
                                                        |
| 64 | -	    if ($Schedule->checkSchedule($operator) == 0) { | 
                                                        |
| 63 | + $operator = $Translation->checkTranslation($ident);  | 
                                                        |
| 64 | +		if ($Schedule->checkSchedule($operator) == 0) { | 
                                                        |
| 65 | 65 | $schedule = $Schedule->fetchSchedule($operator);  | 
                                                        
| 66 | 66 |  		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { | 
                                                        
| 67 | -		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; | 
                                                        |
| 68 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); | 
                                                        |
| 69 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); | 
                                                        |
| 70 | - // Should also check if route schedule = route from DB  | 
                                                        |
| 71 | -		    if ($schedule['DepartureAirportIATA'] != '') { | 
                                                        |
| 67 | +			if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; | 
                                                        |
| 68 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); | 
                                                        |
| 69 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); | 
                                                        |
| 70 | + // Should also check if route schedule = route from DB  | 
                                                        |
| 71 | +			if ($schedule['DepartureAirportIATA'] != '') { | 
                                                        |
| 72 | 72 |  			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) { | 
                                                        
| 73 | - $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);  | 
                                                        |
| 74 | -			    if (trim($airport_icao) != '') { | 
                                                        |
| 73 | + $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);  | 
                                                        |
| 74 | +				if (trim($airport_icao) != '') { | 
                                                        |
| 75 | 75 | $this->all_flights[$id]['departure_airport'] = $airport_icao;  | 
                                                        
| 76 | 76 | if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";  | 
                                                        
| 77 | - }  | 
                                                        |
| 77 | + }  | 
                                                        |
| 78 | + }  | 
                                                        |
| 78 | 79 | }  | 
                                                        
| 79 | - }  | 
                                                        |
| 80 | -		    if ($schedule['ArrivalAirportIATA'] != '') { | 
                                                        |
| 80 | +			if ($schedule['ArrivalAirportIATA'] != '') { | 
                                                        |
| 81 | 81 |  			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) { | 
                                                        
| 82 | - $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);  | 
                                                        |
| 83 | -			    if (trim($airport_icao) != '') { | 
                                                        |
| 82 | + $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);  | 
                                                        |
| 83 | +				if (trim($airport_icao) != '') { | 
                                                        |
| 84 | 84 | $this->all_flights[$id]['arrival_airport'] = $airport_icao;  | 
                                                        
| 85 | 85 | if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";  | 
                                                        
| 86 | - }  | 
                                                        |
| 86 | + }  | 
                                                        |
| 87 | + }  | 
                                                        |
| 87 | 88 | }  | 
                                                        
| 88 | - }  | 
                                                        |
| 89 | - $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);  | 
                                                        |
| 89 | + $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);  | 
                                                        |
| 90 | 90 | }  | 
                                                        
| 91 | - } else $scheduleexist = true;  | 
                                                        |
| 91 | + } else $scheduleexist = true;  | 
                                                        |
| 92 | 92 | } else $scheduleexist = true;  | 
                                                        
| 93 | 93 | // close connection, at least one way will work ?  | 
                                                        
| 94 | -       if ($scheduleexist) { | 
                                                        |
| 94 | +	   if ($scheduleexist) { | 
                                                        |
| 95 | 95 | if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";  | 
                                                        
| 96 | - $sch = $Schedule->getSchedule($operator);  | 
                                                        |
| 96 | + $sch = $Schedule->getSchedule($operator);  | 
                                                        |
| 97 | 97 |  		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time'])); | 
                                                        
| 98 | - }  | 
                                                        |
| 98 | + }  | 
                                                        |
| 99 | 99 | $Spotter->db = null;  | 
                                                        
| 100 | 100 | $Schedule->db = null;  | 
                                                        
| 101 | 101 | $Translation->db = null;  | 
                                                        
@@ -110,92 +110,92 @@ discard block  | 
                                                    ||
| 110 | 110 | }  | 
                                                        
| 111 | 111 | */  | 
                                                        
| 112 | 112 | }  | 
                                                        
| 113 | - }  | 
                                                        |
| 113 | + }  | 
                                                        |
| 114 | 114 | |
| 115 | -    public function checkAll() { | 
                                                        |
| 115 | +	public function checkAll() { | 
                                                        |
| 116 | 116 | global $globalDebug;  | 
                                                        
| 117 | 117 | if ($globalDebug) echo "Update last seen flights data...\n";  | 
                                                        
| 118 | 118 |  	foreach ($this->all_flights as $key => $flight) { | 
                                                        
| 119 | -	    if (isset($this->all_flights[$key]['id'])) { | 
                                                        |
| 119 | +		if (isset($this->all_flights[$key]['id'])) { | 
                                                        |
| 120 | 120 | //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n";  | 
                                                        
| 121 | - $Spotter = new Spotter($this->db);  | 
                                                        |
| 122 | - $real_arrival = $this->arrival($key);  | 
                                                        |
| 123 | - $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);  | 
                                                        |
| 124 | - }  | 
                                                        |
| 121 | + $Spotter = new Spotter($this->db);  | 
                                                        |
| 122 | + $real_arrival = $this->arrival($key);  | 
                                                        |
| 123 | + $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);  | 
                                                        |
| 124 | + }  | 
                                                        |
| 125 | + }  | 
                                                        |
| 125 | 126 | }  | 
                                                        
| 126 | - }  | 
                                                        |
| 127 | 127 | |
| 128 | -    public function arrival($key) { | 
                                                        |
| 128 | +	public function arrival($key) { | 
                                                        |
| 129 | 129 | global $globalClosestMinDist, $globalDebug;  | 
                                                        
| 130 | 130 | if ($globalDebug) echo 'Update arrival...'."\n";  | 
                                                        
| 131 | 131 | $Spotter = new Spotter($this->db);  | 
                                                        
| 132 | - $airport_icao = '';  | 
                                                        |
| 133 | - $airport_time = '';  | 
                                                        |
| 134 | - if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;  | 
                                                        |
| 132 | + $airport_icao = '';  | 
                                                        |
| 133 | + $airport_time = '';  | 
                                                        |
| 134 | + if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;  | 
                                                        |
| 135 | 135 |  	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { | 
                                                        
| 136 | - $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);  | 
                                                        |
| 137 | -    	    if (isset($closestAirports[0])) { | 
                                                        |
| 138 | -        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { | 
                                                        |
| 139 | - $airport_icao = $closestAirports[0]['icao'];  | 
                                                        |
| 140 | - $airport_time = $this->all_flights[$key]['datetime'];  | 
                                                        |
| 141 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";  | 
                                                        |
| 142 | -        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { | 
                                                        |
| 143 | -        	    foreach ($closestAirports as $airport) { | 
                                                        |
| 144 | -        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { | 
                                                        |
| 145 | - $airport_icao = $airport['icao'];  | 
                                                        |
| 146 | - $airport_time = $this->all_flights[$key]['datetime'];  | 
                                                        |
| 147 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";  | 
                                                        |
| 148 | - break;  | 
                                                        |
| 149 | - }  | 
                                                        |
| 150 | - }  | 
                                                        |
| 151 | -        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) { | 
                                                        |
| 152 | - $airport_icao = $closestAirports[0]['icao'];  | 
                                                        |
| 153 | - $airport_time = $this->all_flights[$key]['datetime'];  | 
                                                        |
| 154 | -        	} else { | 
                                                        |
| 155 | - if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";  | 
                                                        |
| 156 | - }  | 
                                                        |
| 157 | -    	    } else { | 
                                                        |
| 158 | - if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";  | 
                                                        |
| 159 | - }  | 
                                                        |
| 160 | -  | 
                                                        |
| 161 | -        } else { | 
                                                        |
| 162 | - if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";  | 
                                                        |
| 163 | - }  | 
                                                        |
| 164 | -        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); | 
                                                        |
| 165 | - }  | 
                                                        |
| 166 | -  | 
                                                        |
| 167 | -  | 
                                                        |
| 168 | -  | 
                                                        |
| 169 | -    public function del() { | 
                                                        |
| 136 | + $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);  | 
                                                        |
| 137 | +			if (isset($closestAirports[0])) { | 
                                                        |
| 138 | +			if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { | 
                                                        |
| 139 | + $airport_icao = $closestAirports[0]['icao'];  | 
                                                        |
| 140 | + $airport_time = $this->all_flights[$key]['datetime'];  | 
                                                        |
| 141 | + if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";  | 
                                                        |
| 142 | +			} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { | 
                                                        |
| 143 | +				foreach ($closestAirports as $airport) { | 
                                                        |
| 144 | +				if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { | 
                                                        |
| 145 | + $airport_icao = $airport['icao'];  | 
                                                        |
| 146 | + $airport_time = $this->all_flights[$key]['datetime'];  | 
                                                        |
| 147 | + if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";  | 
                                                        |
| 148 | + break;  | 
                                                        |
| 149 | + }  | 
                                                        |
| 150 | + }  | 
                                                        |
| 151 | +			} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) { | 
                                                        |
| 152 | + $airport_icao = $closestAirports[0]['icao'];  | 
                                                        |
| 153 | + $airport_time = $this->all_flights[$key]['datetime'];  | 
                                                        |
| 154 | +			} else { | 
                                                        |
| 155 | + if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";  | 
                                                        |
| 156 | + }  | 
                                                        |
| 157 | +			} else { | 
                                                        |
| 158 | + if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";  | 
                                                        |
| 159 | + }  | 
                                                        |
| 160 | +  | 
                                                        |
| 161 | +		} else { | 
                                                        |
| 162 | + if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";  | 
                                                        |
| 163 | + }  | 
                                                        |
| 164 | +		return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); | 
                                                        |
| 165 | + }  | 
                                                        |
| 166 | +  | 
                                                        |
| 167 | +  | 
                                                        |
| 168 | +  | 
                                                        |
| 169 | +	public function del() { | 
                                                        |
| 170 | 170 | global $globalDebug;  | 
                                                        
| 171 | 171 | // Delete old infos  | 
                                                        
| 172 | 172 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n";  | 
                                                        
| 173 | 173 |  	foreach ($this->all_flights as $key => $flight) { | 
                                                        
| 174 | -    	    if (isset($flight['lastupdate'])) { | 
                                                        |
| 175 | -        	if ($flight['lastupdate'] < (time()-3000)) { | 
                                                        |
| 176 | -            	    if (isset($this->all_flights[$key]['id'])) { | 
                                                        |
| 177 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";  | 
                                                        |
| 174 | +			if (isset($flight['lastupdate'])) { | 
                                                        |
| 175 | +			if ($flight['lastupdate'] < (time()-3000)) { | 
                                                        |
| 176 | +					if (isset($this->all_flights[$key]['id'])) { | 
                                                        |
| 177 | + if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";  | 
                                                        |
| 178 | 178 | /*  | 
                                                        
| 179 | 179 | $SpotterLive = new SpotterLive();  | 
                                                        
| 180 | 180 | $SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);  | 
                                                        
| 181 | 181 | $SpotterLive->db = null;  | 
                                                        
| 182 | 182 | */  | 
                                                        
| 183 | - $real_arrival = $this->arrival($key);  | 
                                                        |
| 184 | - $Spotter = new Spotter($this->db);  | 
                                                        |
| 185 | -            		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { | 
                                                        |
| 183 | + $real_arrival = $this->arrival($key);  | 
                                                        |
| 184 | + $Spotter = new Spotter($this->db);  | 
                                                        |
| 185 | +					if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { | 
                                                        |
| 186 | 186 | $result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);  | 
                                                        
| 187 | 187 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";  | 
                                                        
| 188 | 188 | }  | 
                                                        
| 189 | 189 | // Put in archive  | 
                                                        
| 190 | 190 | // $Spotter->db = null;  | 
                                                        
| 191 | - }  | 
                                                        |
| 192 | - unset($this->all_flights[$key]);  | 
                                                        |
| 193 | - }  | 
                                                        |
| 194 | - }  | 
                                                        |
| 195 | - }  | 
                                                        |
| 196 | - }  | 
                                                        |
| 197 | -  | 
                                                        |
| 198 | -    public function add($line) { | 
                                                        |
| 191 | + }  | 
                                                        |
| 192 | + unset($this->all_flights[$key]);  | 
                                                        |
| 193 | + }  | 
                                                        |
| 194 | + }  | 
                                                        |
| 195 | + }  | 
                                                        |
| 196 | + }  | 
                                                        |
| 197 | +  | 
                                                        |
| 198 | +	public function add($line) { | 
                                                        |
| 199 | 199 | global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights;  | 
                                                        
| 200 | 200 | //if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;  | 
                                                        
| 201 | 201 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';  | 
                                                        
@@ -220,18 +220,18 @@ discard block  | 
                                                    ||
| 220 | 220 | |
| 221 | 221 | // SBS format is CSV format  | 
                                                        
| 222 | 222 |  	if(is_array($line) && isset($line['hex'])) { | 
                                                        
| 223 | - //print_r($line);  | 
                                                        |
| 224 | -  	    if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) { | 
                                                        |
| 223 | + //print_r($line);  | 
                                                        |
| 224 | +  		if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) { | 
                                                        |
| 225 | 225 | |
| 226 | 226 | // Increment message number  | 
                                                        
| 227 | 227 |  		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { | 
                                                        
| 228 | -		    $current_date = date('Y-m-d'); | 
                                                        |
| 229 | - $source = $line['source_name'];  | 
                                                        |
| 230 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];  | 
                                                        |
| 231 | -		    if (!isset($this->stats[$current_date][$source]['msg'])) { | 
                                                        |
| 232 | - $this->stats[$current_date][$source]['msg']['date'] = time();  | 
                                                        |
| 233 | - $this->stats[$current_date][$source]['msg']['nb'] = 1;  | 
                                                        |
| 234 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1;  | 
                                                        |
| 228 | +			$current_date = date('Y-m-d'); | 
                                                        |
| 229 | + $source = $line['source_name'];  | 
                                                        |
| 230 | + if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];  | 
                                                        |
| 231 | +			if (!isset($this->stats[$current_date][$source]['msg'])) { | 
                                                        |
| 232 | + $this->stats[$current_date][$source]['msg']['date'] = time();  | 
                                                        |
| 233 | + $this->stats[$current_date][$source]['msg']['nb'] = 1;  | 
                                                        |
| 234 | + } else $this->stats[$current_date][$source]['msg']['nb'] += 1;  | 
                                                        |
| 235 | 235 | }  | 
                                                        
| 236 | 236 | |
| 237 | 237 | /*  | 
                                                        
@@ -247,40 +247,40 @@ discard block  | 
                                                    ||
| 247 | 247 | //$this->db = $dbc;  | 
                                                        
| 248 | 248 | |
| 249 | 249 | //$hex = trim($line['hex']);  | 
                                                        
| 250 | - if (!isset($line['id'])) $id = trim($line['hex']);  | 
                                                        |
| 251 | - else $id = trim($line['id']);  | 
                                                        |
| 250 | + if (!isset($line['id'])) $id = trim($line['hex']);  | 
                                                        |
| 251 | + else $id = trim($line['id']);  | 
                                                        |
| 252 | 252 | |
| 253 | 253 |  		if (!isset($this->all_flights[$id])) { | 
                                                        
| 254 | - $this->all_flights[$id] = array();  | 
                                                        |
| 255 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); | 
                                                        |
| 256 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true)); | 
                                                        |
| 257 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); | 
                                                        |
| 258 | -		    if (!isset($line['id'])) { | 
                                                        |
| 254 | + $this->all_flights[$id] = array();  | 
                                                        |
| 255 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); | 
                                                        |
| 256 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true)); | 
                                                        |
| 257 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); | 
                                                        |
| 258 | +			if (!isset($line['id'])) { | 
                                                        |
| 259 | 259 | if (!isset($globalDaemon)) $globalDaemon = TRUE;  | 
                                                        
| 260 | 260 |  //			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); | 
                                                        
| 261 | 261 |  //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); | 
                                                        
| 262 | 262 |  			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); | 
                                                        
| 263 | -		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        |
| 264 | -		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); | 
                                                        |
| 265 | - if ($globalAllFlights !== FALSE) $dataFound = true;  | 
                                                        |
| 263 | +				//else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        |
| 264 | +			 } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); | 
                                                        |
| 265 | + if ($globalAllFlights !== FALSE) $dataFound = true;  | 
                                                        |
| 266 | 266 | }  | 
                                                        
| 267 | 267 | |
| 268 | 268 | //print_r($this->all_flights);  | 
                                                        
| 269 | 269 |  		if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) { | 
                                                        
| 270 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex']))); | 
                                                        |
| 271 | -		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { | 
                                                        |
| 270 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex']))); | 
                                                        |
| 271 | +			//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { | 
                                                        |
| 272 | 272 |  			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); | 
                                                        
| 273 | -		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); | 
                                                        |
| 274 | -		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') { | 
                                                        |
| 273 | +			//} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); | 
                                                        |
| 274 | +			if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') { | 
                                                        |
| 275 | 275 | $timeelapsed = microtime(true);  | 
                                                        
| 276 | 276 | $Spotter = new Spotter($this->db);  | 
                                                        
| 277 | 277 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));  | 
                                                        
| 278 | 278 | $Spotter->db = null;  | 
                                                        
| 279 | 279 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        
| 280 | 280 |  			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); | 
                                                        
| 281 | - }  | 
                                                        |
| 282 | - if ($globalAllFlights !== FALSE) $dataFound = true;  | 
                                                        |
| 283 | - if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";  | 
                                                        |
| 281 | + }  | 
                                                        |
| 282 | + if ($globalAllFlights !== FALSE) $dataFound = true;  | 
                                                        |
| 283 | + if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";  | 
                                                        |
| 284 | 284 | }  | 
                                                        
| 285 | 285 |  		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') { | 
                                                        
| 286 | 286 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); | 
                                                        
@@ -304,9 +304,9 @@ discard block  | 
                                                    ||
| 304 | 304 | }  | 
                                                        
| 305 | 305 |  		//if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { | 
                                                        
| 306 | 306 |  		if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60) { | 
                                                        
| 307 | -		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { | 
                                                        |
| 307 | +			if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { | 
                                                        |
| 308 | 308 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); | 
                                                        
| 309 | -		    } else { | 
                                                        |
| 309 | +			} else { | 
                                                        |
| 310 | 310 | if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";  | 
                                                        
| 311 | 311 |  				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; | 
                                                        
| 312 | 312 | /*  | 
                                                        
@@ -315,41 +315,41 @@ discard block  | 
                                                    ||
| 315 | 315 | print_r($line);  | 
                                                        
| 316 | 316 | */  | 
                                                        
| 317 | 317 | return '';  | 
                                                        
| 318 | - }  | 
                                                        |
| 318 | + }  | 
                                                        |
| 319 | 319 |  		} else { | 
                                                        
| 320 | 320 |  			date_default_timezone_set('UTC'); | 
                                                        
| 321 | 321 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); | 
                                                        
| 322 | 322 | }  | 
                                                        
| 323 | 323 | |
| 324 | 324 |  		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') { | 
                                                        
| 325 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); | 
                                                        |
| 325 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); | 
                                                        |
| 326 | 326 | }  | 
                                                        
| 327 | 327 |  		if (isset($line['waypoints']) && $line['waypoints'] != '') { | 
                                                        
| 328 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); | 
                                                        |
| 328 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); | 
                                                        |
| 329 | 329 | }  | 
                                                        
| 330 | 330 |  		if (isset($line['pilot_id']) && $line['pilot_id'] != '') { | 
                                                        
| 331 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id'])); | 
                                                        |
| 331 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id'])); | 
                                                        |
| 332 | 332 | }  | 
                                                        
| 333 | 333 |  		if (isset($line['pilot_name']) && $line['pilot_name'] != '') { | 
                                                        
| 334 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name'])); | 
                                                        |
| 334 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name'])); | 
                                                        |
| 335 | 335 | }  | 
                                                        
| 336 | 336 | |
| 337 | 337 |  		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) { | 
                                                        
| 338 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); | 
                                                        |
| 339 | -		    if ($this->all_flights[$id]['addedSpotter'] == 1) { | 
                                                        |
| 338 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); | 
                                                        |
| 339 | +			if ($this->all_flights[$id]['addedSpotter'] == 1) { | 
                                                        |
| 340 | 340 | $timeelapsed = microtime(true);  | 
                                                        
| 341 | - $Spotter = new Spotter($this->db);  | 
                                                        |
| 342 | - $fromsource = NULL;  | 
                                                        |
| 343 | - if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;  | 
                                                        |
| 344 | - elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';  | 
                                                        |
| 341 | + $Spotter = new Spotter($this->db);  | 
                                                        |
| 342 | + $fromsource = NULL;  | 
                                                        |
| 343 | + if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;  | 
                                                        |
| 344 | + elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';  | 
                                                        |
| 345 | 345 | elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';  | 
                                                        
| 346 | 346 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';  | 
                                                        
| 347 | 347 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';  | 
                                                        
| 348 | - $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);  | 
                                                        |
| 348 | + $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);  | 
                                                        |
| 349 | 349 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";  | 
                                                        
| 350 | 350 | $Spotter->db = null;  | 
                                                        
| 351 | 351 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        
| 352 | - }  | 
                                                        |
| 352 | + }  | 
                                                        |
| 353 | 353 | |
| 354 | 354 | /*  | 
                                                        
| 355 | 355 |  		    if (!isset($line['id'])) { | 
                                                        
@@ -359,26 +359,26 @@ discard block  | 
                                                    ||
| 359 | 359 |  		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        
| 360 | 360 |  		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); | 
                                                        
| 361 | 361 | */  | 
                                                        
| 362 | -		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        |
| 362 | +			if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        |
| 363 | 363 | |
| 364 | - //$putinarchive = true;  | 
                                                        |
| 365 | -		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { | 
                                                        |
| 364 | + //$putinarchive = true;  | 
                                                        |
| 365 | +			if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { | 
                                                        |
| 366 | 366 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time'])); | 
                                                        
| 367 | - }  | 
                                                        |
| 368 | -		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { | 
                                                        |
| 367 | + }  | 
                                                        |
| 368 | +			if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { | 
                                                        |
| 369 | 369 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time'])); | 
                                                        
| 370 | - }  | 
                                                        |
| 371 | -		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) { | 
                                                        |
| 372 | -		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); | 
                                                        |
| 373 | -		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { | 
                                                        |
| 370 | + }  | 
                                                        |
| 371 | +			if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) { | 
                                                        |
| 372 | +					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); | 
                                                        |
| 373 | +			} elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { | 
                                                        |
| 374 | 374 | $timeelapsed = microtime(true);  | 
                                                        
| 375 | 375 | $Spotter = new Spotter($this->db);  | 
                                                        
| 376 | 376 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);  | 
                                                        
| 377 | 377 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);  | 
                                                        
| 378 | -		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); | 
                                                        |
| 378 | +					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); | 
                                                        |
| 379 | 379 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        
| 380 | 380 | |
| 381 | -		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { | 
                                                        |
| 381 | +			} elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { | 
                                                        |
| 382 | 382 | $timeelapsed = microtime(true);  | 
                                                        
| 383 | 383 | $Spotter = new Spotter($this->db);  | 
                                                        
| 384 | 384 | $route = $Spotter->getRouteInfo(trim($line['ident']));  | 
                                                        
@@ -392,43 +392,43 @@ discard block  | 
                                                    ||
| 392 | 392 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        
| 393 | 393 | |
| 394 | 394 |  			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { | 
                                                        
| 395 | -			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { | 
                                                        |
| 396 | -			    if ($route['fromairport_icao'] != $route['toairport_icao']) { | 
                                                        |
| 395 | +				//if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { | 
                                                        |
| 396 | +				if ($route['fromairport_icao'] != $route['toairport_icao']) { | 
                                                        |
| 397 | 397 |  				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop'])); | 
                                                        
| 398 | -		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); | 
                                                        |
| 399 | - }  | 
                                                        |
| 398 | +					$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); | 
                                                        |
| 399 | + }  | 
                                                        |
| 400 | 400 | }  | 
                                                        
| 401 | 401 | if (!isset($globalFork)) $globalFork = TRUE;  | 
                                                        
| 402 | 402 |  			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { | 
                                                        
| 403 | 403 | if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));  | 
                                                        
| 404 | 404 | }  | 
                                                        
| 405 | - }  | 
                                                        |
| 405 | + }  | 
                                                        |
| 406 | 406 | }  | 
                                                        
| 407 | 407 | |
| 408 | 408 |  		if (isset($line['speed']) && $line['speed'] != '') { | 
                                                        
| 409 | 409 |  		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12])); | 
                                                        
| 410 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed']))); | 
                                                        |
| 411 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true)); | 
                                                        |
| 412 | - //$dataFound = true;  | 
                                                        |
| 410 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed']))); | 
                                                        |
| 411 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true)); | 
                                                        |
| 412 | + //$dataFound = true;  | 
                                                        |
| 413 | 413 |  		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) { | 
                                                        
| 414 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');  | 
                                                        |
| 415 | -		    if ($distance > 1000 && $distance < 10000) { | 
                                                        |
| 416 | - // use datetime  | 
                                                        |
| 414 | + $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');  | 
                                                        |
| 415 | +			if ($distance > 1000 && $distance < 10000) { | 
                                                        |
| 416 | + // use datetime  | 
                                                        |
| 417 | 417 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);  | 
                                                        
| 418 | 418 | $speed = $speed*3.6;  | 
                                                        
| 419 | 419 |  			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); | 
                                                        
| 420 | 420 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";  | 
                                                        
| 421 | - }  | 
                                                        |
| 421 | + }  | 
                                                        |
| 422 | 422 | }  | 
                                                        
| 423 | 423 | |
| 424 | 424 | |
| 425 | 425 | |
| 426 | -	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { | 
                                                        |
| 427 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);  | 
                                                        |
| 428 | - else unset($timediff);  | 
                                                        |
| 429 | -	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) { | 
                                                        |
| 426 | +			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { | 
                                                        |
| 427 | + if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);  | 
                                                        |
| 428 | + else unset($timediff);  | 
                                                        |
| 429 | +				if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) { | 
                                                        |
| 430 | 430 |  			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) { | 
                                                        
| 431 | -			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { | 
                                                        |
| 431 | +				if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { | 
                                                        |
| 432 | 432 | $this->all_flights[$id]['archive_latitude'] = $line['latitude'];  | 
                                                        
| 433 | 433 | $this->all_flights[$id]['archive_longitude'] = $line['longitude'];  | 
                                                        
| 434 | 434 | $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        
@@ -442,16 +442,16 @@ discard block  | 
                                                    ||
| 442 | 442 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        
| 443 | 443 | $this->tmd = 0;  | 
                                                        
| 444 | 444 | if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";  | 
                                                        
| 445 | - }  | 
                                                        |
| 445 | + }  | 
                                                        |
| 446 | 446 | }  | 
                                                        
| 447 | 447 | |
| 448 | 448 |  			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { | 
                                                        
| 449 | -			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { | 
                                                        |
| 449 | +				//if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { | 
                                                        |
| 450 | 450 | if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];  | 
                                                        
| 451 | 451 |  				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') { | 
                                                        
| 452 | - $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];  | 
                                                        |
| 453 | - $dataFound = true;  | 
                                                        |
| 454 | - $this->all_flights[$id]['time_last_coord'] = time();  | 
                                                        |
| 452 | + $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];  | 
                                                        |
| 453 | + $dataFound = true;  | 
                                                        |
| 454 | + $this->all_flights[$id]['time_last_coord'] = time();  | 
                                                        |
| 455 | 455 | }  | 
                                                        
| 456 | 456 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";  | 
                                                        
| 457 | 457 |  				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude'])); | 
                                                        
@@ -462,20 +462,20 @@ discard block  | 
                                                    ||
| 462 | 462 | //$putinarchive = true;  | 
                                                        
| 463 | 463 | }  | 
                                                        
| 464 | 464 | */  | 
                                                        
| 465 | - /*  | 
                                                        |
| 465 | + /*  | 
                                                        |
| 466 | 466 |  			    } elseif (isset($this->all_flights[$id]['latitude'])) { | 
                                                        
| 467 | 467 | if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n";  | 
                                                        
| 468 | 468 | }  | 
                                                        
| 469 | 469 | */  | 
                                                        
| 470 | 470 | }  | 
                                                        
| 471 | 471 |  			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { | 
                                                        
| 472 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;  | 
                                                        |
| 473 | -			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { | 
                                                        |
| 472 | + if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;  | 
                                                        |
| 473 | +				//if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { | 
                                                        |
| 474 | 474 | if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];  | 
                                                        
| 475 | 475 |  				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') { | 
                                                        
| 476 | - $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];  | 
                                                        |
| 477 | - $dataFound = true;  | 
                                                        |
| 478 | - $this->all_flights[$id]['time_last_coord'] = time();  | 
                                                        |
| 476 | + $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];  | 
                                                        |
| 477 | + $dataFound = true;  | 
                                                        |
| 478 | + $this->all_flights[$id]['time_last_coord'] = time();  | 
                                                        |
| 479 | 479 | }  | 
                                                        
| 480 | 480 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";  | 
                                                        
| 481 | 481 |  				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude'])); | 
                                                        
@@ -493,54 +493,54 @@ discard block  | 
                                                    ||
| 493 | 493 | */  | 
                                                        
| 494 | 494 | }  | 
                                                        
| 495 | 495 | |
| 496 | -		    } else if ($globalDebug && $timediff > 20) { | 
                                                        |
| 496 | +			} else if ($globalDebug && $timediff > 20) { | 
                                                        |
| 497 | 497 | $this->tmd = $this->tmd + 1;  | 
                                                        
| 498 | 498 | echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";  | 
                                                        
| 499 | 499 | echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";  | 
                                                        
| 500 | 500 | echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";  | 
                                                        
| 501 | 501 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";  | 
                                                        
| 502 | - }  | 
                                                        |
| 502 | + }  | 
                                                        |
| 503 | 503 | }  | 
                                                        
| 504 | 504 |  		if (isset($line['last_update']) && $line['last_update'] != '') { | 
                                                        
| 505 | - if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;  | 
                                                        |
| 506 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); | 
                                                        |
| 505 | + if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;  | 
                                                        |
| 506 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); | 
                                                        |
| 507 | 507 | }  | 
                                                        
| 508 | 508 |  		if (isset($line['verticalrate']) && $line['verticalrate'] != '') { | 
                                                        
| 509 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); | 
                                                        |
| 510 | - //$dataFound = true;  | 
                                                        |
| 509 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); | 
                                                        |
| 510 | + //$dataFound = true;  | 
                                                        |
| 511 | 511 | }  | 
                                                        
| 512 | 512 |  		if (isset($line['format_source']) && $line['format_source'] != '') { | 
                                                        
| 513 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source'])); | 
                                                        |
| 513 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source'])); | 
                                                        |
| 514 | 514 | }  | 
                                                        
| 515 | 515 |  		if (isset($line['source_name']) && $line['source_name'] != '') { | 
                                                        
| 516 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name'])); | 
                                                        |
| 516 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name'])); | 
                                                        |
| 517 | 517 | }  | 
                                                        
| 518 | 518 |  		if (isset($line['emergency']) && $line['emergency'] != '') { | 
                                                        
| 519 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); | 
                                                        |
| 520 | - //$dataFound = true;  | 
                                                        |
| 519 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); | 
                                                        |
| 520 | + //$dataFound = true;  | 
                                                        |
| 521 | 521 | }  | 
                                                        
| 522 | 522 |  		if (isset($line['ground']) && $line['ground'] != '') { | 
                                                        
| 523 | -		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { | 
                                                        |
| 523 | +			if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { | 
                                                        |
| 524 | 524 | // Here we force archive of flight because after ground it's a new one (or should be)  | 
                                                        
| 525 | 525 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); | 
                                                        
| 526 | 526 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); | 
                                                        
| 527 | 527 |  			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi'))); | 
                                                        
| 528 | -		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); | 
                                                        |
| 528 | +				elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); | 
                                                        |
| 529 | 529 |  			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        
| 530 | - }  | 
                                                        |
| 531 | - if ($line['ground'] != 1) $line['ground'] = 0;  | 
                                                        |
| 532 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); | 
                                                        |
| 533 | - //$dataFound = true;  | 
                                                        |
| 530 | + }  | 
                                                        |
| 531 | + if ($line['ground'] != 1) $line['ground'] = 0;  | 
                                                        |
| 532 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); | 
                                                        |
| 533 | + //$dataFound = true;  | 
                                                        |
| 534 | 534 | }  | 
                                                        
| 535 | 535 |  		if (isset($line['squawk']) && $line['squawk'] != '') { | 
                                                        
| 536 | -		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) { | 
                                                        |
| 537 | - if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 538 | -			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); | 
                                                        |
| 539 | - $highlight = '';  | 
                                                        |
| 540 | -			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 541 | -			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 542 | -			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 543 | -			    if ($highlight != '') { | 
                                                        |
| 536 | +			if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) { | 
                                                        |
| 537 | + if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 538 | +				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); | 
                                                        |
| 539 | + $highlight = '';  | 
                                                        |
| 540 | +				if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 541 | +				if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 542 | +				if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 543 | +				if ($highlight != '') { | 
                                                        |
| 544 | 544 | $timeelapsed = microtime(true);  | 
                                                        
| 545 | 545 | $Spotter = new Spotter($this->db);  | 
                                                        
| 546 | 546 | $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);  | 
                                                        
@@ -549,38 +549,38 @@ discard block  | 
                                                    ||
| 549 | 549 | |
| 550 | 550 | //$putinarchive = true;  | 
                                                        
| 551 | 551 | //$highlight = '';  | 
                                                        
| 552 | - }  | 
                                                        |
| 552 | + }  | 
                                                        |
| 553 | 553 | |
| 554 | -		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); | 
                                                        |
| 555 | - //$dataFound = true;  | 
                                                        |
| 554 | +			} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); | 
                                                        |
| 555 | + //$dataFound = true;  | 
                                                        |
| 556 | 556 | }  | 
                                                        
| 557 | 557 | |
| 558 | 558 |  		if (isset($line['altitude']) && $line['altitude'] != '') { | 
                                                        
| 559 | -		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { | 
                                                        |
| 559 | +			//if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { | 
                                                        |
| 560 | 560 | if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        
| 561 | 561 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); | 
                                                        
| 562 | 562 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); | 
                                                        
| 563 | 563 | //$dataFound = true;  | 
                                                        
| 564 | - //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";  | 
                                                        |
| 564 | + //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";  | 
                                                        |
| 565 | 565 | }  | 
                                                        
| 566 | 566 | |
| 567 | 567 |  		if (isset($line['noarchive']) && $line['noarchive'] === true) { | 
                                                        
| 568 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); | 
                                                        |
| 568 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); | 
                                                        |
| 569 | 569 | }  | 
                                                        
| 570 | 570 | |
| 571 | 571 |  		if (isset($line['heading']) && $line['heading'] != '') { | 
                                                        
| 572 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 573 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); | 
                                                        |
| 574 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); | 
                                                        |
| 575 | - //$dataFound = true;  | 
                                                        |
| 572 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 573 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); | 
                                                        |
| 574 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); | 
                                                        |
| 575 | + //$dataFound = true;  | 
                                                        |
| 576 | 576 |    		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) { | 
                                                        
| 577 | - $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);  | 
                                                        |
| 578 | -		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); | 
                                                        |
| 579 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 580 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";  | 
                                                        |
| 577 | + $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);  | 
                                                        |
| 578 | +			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); | 
                                                        |
| 579 | + if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 580 | + if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";  | 
                                                        |
| 581 | 581 |    		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { | 
                                                        
| 582 | - // If not enough messages and ACARS set heading to 0  | 
                                                        |
| 583 | -  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); | 
                                                        |
| 582 | + // If not enough messages and ACARS set heading to 0  | 
                                                        |
| 583 | +  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); | 
                                                        |
| 584 | 584 | }  | 
                                                        
| 585 | 585 | if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;  | 
                                                        
| 586 | 586 | elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;  | 
                                                        
@@ -591,119 +591,119 @@ discard block  | 
                                                    ||
| 591 | 591 |  		//if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { | 
                                                        
| 592 | 592 |  		//if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { | 
                                                        
| 593 | 593 |  		if ($dataFound === true && isset($this->all_flights[$id]['hex'])) { | 
                                                        
| 594 | - $this->all_flights[$id]['lastupdate'] = time();  | 
                                                        |
| 595 | -		    if ($this->all_flights[$id]['addedSpotter'] == 0) { | 
                                                        |
| 596 | -		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { | 
                                                        |
| 597 | - //print_r($this->all_flights);  | 
                                                        |
| 598 | - //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";  | 
                                                        |
| 599 | - //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);  | 
                                                        |
| 600 | -			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { | 
                                                        |
| 594 | + $this->all_flights[$id]['lastupdate'] = time();  | 
                                                        |
| 595 | +			if ($this->all_flights[$id]['addedSpotter'] == 0) { | 
                                                        |
| 596 | +				if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == ''  || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { | 
                                                        |
| 597 | + //print_r($this->all_flights);  | 
                                                        |
| 598 | + //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";  | 
                                                        |
| 599 | + //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);  | 
                                                        |
| 600 | +				if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { | 
                                                        |
| 601 | 601 | if ($globalDebug) echo "Check if aircraft is already in DB...";  | 
                                                        
| 602 | 602 | $timeelapsed = microtime(true);  | 
                                                        
| 603 | 603 | $SpotterLive = new SpotterLive($this->db);  | 
                                                        
| 604 | 604 |  				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) { | 
                                                        
| 605 | - $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);  | 
                                                        |
| 606 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 605 | + $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);  | 
                                                        |
| 606 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 607 | 607 |  				} elseif (isset($line['id'])) { | 
                                                        
| 608 | - $recent_ident = $SpotterLive->checkIdRecent($line['id']);  | 
                                                        |
| 609 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 608 | + $recent_ident = $SpotterLive->checkIdRecent($line['id']);  | 
                                                        |
| 609 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 610 | 610 |  				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { | 
                                                        
| 611 | - $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);  | 
                                                        |
| 612 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 611 | + $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);  | 
                                                        |
| 612 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 613 | 613 | } else $recent_ident = '';  | 
                                                        
| 614 | 614 | $SpotterLive->db=null;  | 
                                                        
| 615 | 615 | |
| 616 | 616 | if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";  | 
                                                        
| 617 | 617 | elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";  | 
                                                        
| 618 | -			    } else { | 
                                                        |
| 618 | +				} else { | 
                                                        |
| 619 | 619 | $recent_ident = '';  | 
                                                        
| 620 | 620 |  				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); | 
                                                        
| 621 | - }  | 
                                                        |
| 622 | - //if there was no aircraft with the same callsign within the last hour and go post it into the archive  | 
                                                        |
| 623 | - if($recent_ident == "")  | 
                                                        |
| 624 | -			    { | 
                                                        |
| 621 | + }  | 
                                                        |
| 622 | + //if there was no aircraft with the same callsign within the last hour and go post it into the archive  | 
                                                        |
| 623 | + if($recent_ident == "")  | 
                                                        |
| 624 | +				{ | 
                                                        |
| 625 | 625 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";  | 
                                                        
| 626 | 626 |  				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } | 
                                                        
| 627 | 627 |  				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } | 
                                                        
| 628 | 628 | //adds the spotter data for the archive  | 
                                                        
| 629 | 629 | $ignoreImport = false;  | 
                                                        
| 630 | 630 |  				foreach($globalAirportIgnore as $airportIgnore) { | 
                                                        
| 631 | -				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { | 
                                                        |
| 631 | +					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { | 
                                                        |
| 632 | 632 | $ignoreImport = true;  | 
                                                        
| 633 | - }  | 
                                                        |
| 633 | + }  | 
                                                        |
| 634 | 634 | }  | 
                                                        
| 635 | 635 |  				if (count($globalAirportAccept) > 0) { | 
                                                        
| 636 | - $ignoreImport = true;  | 
                                                        |
| 637 | -				    foreach($globalAirportIgnore as $airportIgnore) { | 
                                                        |
| 636 | + $ignoreImport = true;  | 
                                                        |
| 637 | +					foreach($globalAirportIgnore as $airportIgnore) { | 
                                                        |
| 638 | 638 |  					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { | 
                                                        
| 639 | - $ignoreImport = false;  | 
                                                        |
| 639 | + $ignoreImport = false;  | 
                                                        |
| 640 | + }  | 
                                                        |
| 640 | 641 | }  | 
                                                        
| 641 | - }  | 
                                                        |
| 642 | 642 | }  | 
                                                        
| 643 | 643 |  				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { | 
                                                        
| 644 | -				    foreach($globalAirlineIgnore as $airlineIgnore) { | 
                                                        |
| 644 | +					foreach($globalAirlineIgnore as $airlineIgnore) { | 
                                                        |
| 645 | 645 |  					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) { | 
                                                        
| 646 | - $ignoreImport = true;  | 
                                                        |
| 646 | + $ignoreImport = true;  | 
                                                        |
| 647 | + }  | 
                                                        |
| 647 | 648 | }  | 
                                                        
| 648 | - }  | 
                                                        |
| 649 | 649 | }  | 
                                                        
| 650 | 650 |  				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { | 
                                                        
| 651 | - $ignoreImport = true;  | 
                                                        |
| 652 | -				    foreach($globalAirlineAccept as $airlineAccept) { | 
                                                        |
| 651 | + $ignoreImport = true;  | 
                                                        |
| 652 | +					foreach($globalAirlineAccept as $airlineAccept) { | 
                                                        |
| 653 | 653 |  					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) { | 
                                                        
| 654 | - $ignoreImport = false;  | 
                                                        |
| 654 | + $ignoreImport = false;  | 
                                                        |
| 655 | + }  | 
                                                        |
| 655 | 656 | }  | 
                                                        
| 656 | - }  | 
                                                        |
| 657 | 657 | }  | 
                                                        
| 658 | 658 |  				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { | 
                                                        
| 659 | - $ignoreImport = true;  | 
                                                        |
| 660 | -				    foreach($globalPilotIdAccept as $pilotIdAccept) { | 
                                                        |
| 659 | + $ignoreImport = true;  | 
                                                        |
| 660 | +					foreach($globalPilotIdAccept as $pilotIdAccept) { | 
                                                        |
| 661 | 661 |  					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { | 
                                                        
| 662 | - $ignoreImport = false;  | 
                                                        |
| 662 | + $ignoreImport = false;  | 
                                                        |
| 663 | + }  | 
                                                        |
| 663 | 664 | }  | 
                                                        
| 664 | - }  | 
                                                        |
| 665 | 665 | }  | 
                                                        
| 666 | 666 | |
| 667 | 667 |  				if (!$ignoreImport) { | 
                                                        
| 668 | - $highlight = '';  | 
                                                        |
| 669 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';  | 
                                                        |
| 670 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';  | 
                                                        |
| 671 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';  | 
                                                        |
| 672 | -				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); | 
                                                        |
| 673 | - $timeelapsed = microtime(true);  | 
                                                        |
| 674 | - $Spotter = new Spotter($this->db);  | 
                                                        |
| 675 | - $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name']);  | 
                                                        |
| 676 | - $Spotter->db = null;  | 
                                                        |
| 677 | - if ($globalDebug && isset($result)) echo $result."\n";  | 
                                                        |
| 678 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 668 | + $highlight = '';  | 
                                                        |
| 669 | + if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';  | 
                                                        |
| 670 | + if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';  | 
                                                        |
| 671 | + if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';  | 
                                                        |
| 672 | +					if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); | 
                                                        |
| 673 | + $timeelapsed = microtime(true);  | 
                                                        |
| 674 | + $Spotter = new Spotter($this->db);  | 
                                                        |
| 675 | + $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name']);  | 
                                                        |
| 676 | + $Spotter->db = null;  | 
                                                        |
| 677 | + if ($globalDebug && isset($result)) echo $result."\n";  | 
                                                        |
| 678 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 679 | 679 | |
| 680 | - // Add source stat in DB  | 
                                                        |
| 681 | - $Stats = new Stats($this->db);  | 
                                                        |
| 682 | -				    if (!empty($this->stats)) { | 
                                                        |
| 680 | + // Add source stat in DB  | 
                                                        |
| 681 | + $Stats = new Stats($this->db);  | 
                                                        |
| 682 | +					if (!empty($this->stats)) { | 
                                                        |
| 683 | 683 | if ($globalDebug) echo 'Add source stats : ';  | 
                                                        
| 684 | -				        foreach($this->stats as $date => $data) { | 
                                                        |
| 685 | -					    foreach($data as $source => $sourced) { | 
                                                        |
| 686 | - //print_r($sourced);  | 
                                                        |
| 687 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);  | 
                                                        |
| 688 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);  | 
                                                        |
| 689 | -				    		if (isset($sourced['msg'])) { | 
                                                        |
| 690 | -				    		    if (time() - $sourced['msg']['date'] > 10) { | 
                                                        |
| 691 | - $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));  | 
                                                        |
| 692 | - echo $Stats->addStatSource($nbmsg,$source,'msg',$date);  | 
                                                        |
| 693 | - unset($this->stats[$date][$source]['msg']);  | 
                                                        |
| 694 | - }  | 
                                                        |
| 695 | - }  | 
                                                        |
| 696 | - }  | 
                                                        |
| 697 | -			    		    if ($date != date('Y-m-d')) { | 
                                                        |
| 698 | - unset($this->stats[$date]);  | 
                                                        |
| 699 | - }  | 
                                                        |
| 700 | - }  | 
                                                        |
| 701 | - if ($globalDebug) echo 'Done'."\n";  | 
                                                        |
| 702 | -  | 
                                                        |
| 703 | - }  | 
                                                        |
| 704 | - $Stats->db = null;  | 
                                                        |
| 684 | +						foreach($this->stats as $date => $data) { | 
                                                        |
| 685 | +						foreach($data as $source => $sourced) { | 
                                                        |
| 686 | + //print_r($sourced);  | 
                                                        |
| 687 | + if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);  | 
                                                        |
| 688 | + if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);  | 
                                                        |
| 689 | +							if (isset($sourced['msg'])) { | 
                                                        |
| 690 | +								if (time() - $sourced['msg']['date'] > 10) { | 
                                                        |
| 691 | + $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));  | 
                                                        |
| 692 | + echo $Stats->addStatSource($nbmsg,$source,'msg',$date);  | 
                                                        |
| 693 | + unset($this->stats[$date][$source]['msg']);  | 
                                                        |
| 694 | + }  | 
                                                        |
| 695 | + }  | 
                                                        |
| 696 | + }  | 
                                                        |
| 697 | +							if ($date != date('Y-m-d')) { | 
                                                        |
| 698 | + unset($this->stats[$date]);  | 
                                                        |
| 699 | + }  | 
                                                        |
| 700 | + }  | 
                                                        |
| 701 | + if ($globalDebug) echo 'Done'."\n";  | 
                                                        |
| 702 | +  | 
                                                        |
| 703 | + }  | 
                                                        |
| 704 | + $Stats->db = null;  | 
                                                        |
| 705 | 705 | |
| 706 | - $this->del();  | 
                                                        |
| 706 | + $this->del();  | 
                                                        |
| 707 | 707 | } elseif ($globalDebug) echo 'Ignore data'."\n";  | 
                                                        
| 708 | 708 | //$ignoreImport = false;  | 
                                                        
| 709 | 709 | $this->all_flights[$id]['addedSpotter'] = 1;  | 
                                                        
@@ -721,18 +721,18 @@ discard block  | 
                                                    ||
| 721 | 721 | */  | 
                                                        
| 722 | 722 | //SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);  | 
                                                        
| 723 | 723 |  				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { | 
                                                        
| 724 | - if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";  | 
                                                        |
| 725 | - //SpotterLive->deleteLiveSpotterDataNotUpdated();  | 
                                                        |
| 726 | - $SpotterLive = new SpotterLive($this->db);  | 
                                                        |
| 727 | - $SpotterLive->deleteLiveSpotterData();  | 
                                                        |
| 728 | - $SpotterLive->db=null;  | 
                                                        |
| 729 | - if ($globalDebug) echo " Done\n";  | 
                                                        |
| 730 | - $this->last_delete = time();  | 
                                                        |
| 724 | + if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";  | 
                                                        |
| 725 | + //SpotterLive->deleteLiveSpotterDataNotUpdated();  | 
                                                        |
| 726 | + $SpotterLive = new SpotterLive($this->db);  | 
                                                        |
| 727 | + $SpotterLive->deleteLiveSpotterData();  | 
                                                        |
| 728 | + $SpotterLive->db=null;  | 
                                                        |
| 729 | + if ($globalDebug) echo " Done\n";  | 
                                                        |
| 730 | + $this->last_delete = time();  | 
                                                        |
| 731 | 731 | }  | 
                                                        
| 732 | -			    } else { | 
                                                        |
| 732 | +				} else { | 
                                                        |
| 733 | 733 |  				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) { | 
                                                        
| 734 | - $this->all_flights[$id]['id'] = $recent_ident;  | 
                                                        |
| 735 | - $this->all_flights[$id]['addedSpotter'] = 1;  | 
                                                        |
| 734 | + $this->all_flights[$id]['id'] = $recent_ident;  | 
                                                        |
| 735 | + $this->all_flights[$id]['addedSpotter'] = 1;  | 
                                                        |
| 736 | 736 | }  | 
                                                        
| 737 | 737 |  				if (isset($globalDaemon) && !$globalDaemon) { | 
                                                        
| 738 | 738 | $Spotter = new Spotter($this->db);  | 
                                                        
@@ -740,14 +740,14 @@ discard block  | 
                                                    ||
| 740 | 740 | $Spotter->db = null;  | 
                                                        
| 741 | 741 | }  | 
                                                        
| 742 | 742 | |
| 743 | - }  | 
                                                        |
| 743 | + }  | 
                                                        |
| 744 | 744 | }  | 
                                                        
| 745 | - }  | 
                                                        |
| 746 | - //adds the spotter LIVE data  | 
                                                        |
| 747 | - //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);  | 
                                                        |
| 748 | - //echo "\nAdd in Live !! \n";  | 
                                                        |
| 749 | -		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n"; | 
                                                        |
| 750 | -		    if ($globalDebug) { | 
                                                        |
| 745 | + }  | 
                                                        |
| 746 | + //adds the spotter LIVE data  | 
                                                        |
| 747 | + //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);  | 
                                                        |
| 748 | + //echo "\nAdd in Live !! \n";  | 
                                                        |
| 749 | +			//echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n"; | 
                                                        |
| 750 | +			if ($globalDebug) { | 
                                                        |
| 751 | 751 |  			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) { | 
                                                        
| 752 | 752 | if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";  | 
                                                        
| 753 | 753 | else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";  | 
                                                        
@@ -755,49 +755,49 @@ discard block  | 
                                                    ||
| 755 | 755 | if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";  | 
                                                        
| 756 | 756 | else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";  | 
                                                        
| 757 | 757 | }  | 
                                                        
| 758 | - }  | 
                                                        |
| 759 | - $ignoreImport = false;  | 
                                                        |
| 760 | -		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } | 
                                                        |
| 761 | -		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } | 
                                                        |
| 758 | + }  | 
                                                        |
| 759 | + $ignoreImport = false;  | 
                                                        |
| 760 | +			if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } | 
                                                        |
| 761 | +			if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } | 
                                                        |
| 762 | 762 | |
| 763 | -		    foreach($globalAirportIgnore as $airportIgnore) { | 
                                                        |
| 764 | -		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { | 
                                                        |
| 765 | - $ignoreImport = true;  | 
                                                        |
| 763 | +			foreach($globalAirportIgnore as $airportIgnore) { | 
                                                        |
| 764 | +				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { | 
                                                        |
| 765 | + $ignoreImport = true;  | 
                                                        |
| 766 | + }  | 
                                                        |
| 766 | 767 | }  | 
                                                        
| 767 | - }  | 
                                                        |
| 768 | -		    if (count($globalAirportAccept) > 0) { | 
                                                        |
| 769 | - $ignoreImport = true;  | 
                                                        |
| 770 | -		        foreach($globalAirportIgnore as $airportIgnore) { | 
                                                        |
| 771 | -			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { | 
                                                        |
| 768 | +			if (count($globalAirportAccept) > 0) { | 
                                                        |
| 769 | + $ignoreImport = true;  | 
                                                        |
| 770 | +				foreach($globalAirportIgnore as $airportIgnore) { | 
                                                        |
| 771 | +				if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { | 
                                                        |
| 772 | 772 | $ignoreImport = false;  | 
                                                        
| 773 | - }  | 
                                                        |
| 773 | + }  | 
                                                        |
| 774 | 774 | }  | 
                                                        
| 775 | - }  | 
                                                        |
| 776 | -		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { | 
                                                        |
| 775 | + }  | 
                                                        |
| 776 | +			if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { | 
                                                        |
| 777 | 777 |  			foreach($globalAirlineIgnore as $airlineIgnore) { | 
                                                        
| 778 | -			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) { | 
                                                        |
| 778 | +				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) { | 
                                                        |
| 779 | 779 | $ignoreImport = true;  | 
                                                        
| 780 | - }  | 
                                                        |
| 780 | + }  | 
                                                        |
| 781 | 781 | }  | 
                                                        
| 782 | - }  | 
                                                        |
| 783 | -		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { | 
                                                        |
| 782 | + }  | 
                                                        |
| 783 | +			if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { | 
                                                        |
| 784 | 784 | $ignoreImport = true;  | 
                                                        
| 785 | 785 |  			foreach($globalAirlineAccept as $airlineAccept) { | 
                                                        
| 786 | -			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) { | 
                                                        |
| 786 | +				if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) { | 
                                                        |
| 787 | 787 | $ignoreImport = false;  | 
                                                        
| 788 | - }  | 
                                                        |
| 788 | + }  | 
                                                        |
| 789 | 789 | }  | 
                                                        
| 790 | - }  | 
                                                        |
| 791 | -		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { | 
                                                        |
| 790 | + }  | 
                                                        |
| 791 | +			if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { | 
                                                        |
| 792 | 792 | $ignoreImport = true;  | 
                                                        
| 793 | 793 |  			foreach($globalPilotIdAccept as $pilotIdAccept) { | 
                                                        
| 794 | -			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { | 
                                                        |
| 795 | - $ignoreImport = false;  | 
                                                        |
| 796 | - }  | 
                                                        |
| 794 | +				if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { | 
                                                        |
| 795 | + $ignoreImport = false;  | 
                                                        |
| 796 | + }  | 
                                                        |
| 797 | + }  | 
                                                        |
| 797 | 798 | }  | 
                                                        
| 798 | - }  | 
                                                        |
| 799 | 799 | |
| 800 | -		    if (!$ignoreImport) { | 
                                                        |
| 800 | +			if (!$ignoreImport) { | 
                                                        |
| 801 | 801 |  			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { | 
                                                        
| 802 | 802 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";  | 
                                                        
| 803 | 803 | $timeelapsed = microtime(true);  | 
                                                        
@@ -836,7 +836,7 @@ discard block  | 
                                                    ||
| 836 | 836 | if ($stats_heading == 16) $stats_heading = 0;  | 
                                                        
| 837 | 837 |  					if (!isset($this->stats[$current_date][$source]['polar'][1])) { | 
                                                        
| 838 | 838 |  						for ($i=0;$i<=15;$i++) { | 
                                                        
| 839 | - $this->stats[$current_date][$source]['polar'][$i] = 0;  | 
                                                        |
| 839 | + $this->stats[$current_date][$source]['polar'][$i] = 0;  | 
                                                        |
| 840 | 840 | }  | 
                                                        
| 841 | 841 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;  | 
                                                        
| 842 | 842 |  					} else { | 
                                                        
@@ -849,11 +849,11 @@ discard block  | 
                                                    ||
| 849 | 849 | //var_dump($this->stats);  | 
                                                        
| 850 | 850 |  					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { | 
                                                        
| 851 | 851 |  						if (isset($this->stats[$current_date][$source]['hist'][0])) { | 
                                                        
| 852 | - end($this->stats[$current_date][$source]['hist']);  | 
                                                        |
| 853 | - $mini = key($this->stats[$current_date][$source]['hist'])+10;  | 
                                                        |
| 852 | + end($this->stats[$current_date][$source]['hist']);  | 
                                                        |
| 853 | + $mini = key($this->stats[$current_date][$source]['hist'])+10;  | 
                                                        |
| 854 | 854 | } else $mini = 0;  | 
                                                        
| 855 | 855 |  						for ($i=$mini;$i<=$distance;$i+=10) { | 
                                                        
| 856 | - $this->stats[$current_date][$source]['hist'][$i] = 0;  | 
                                                        |
| 856 | + $this->stats[$current_date][$source]['hist'][$i] = 0;  | 
                                                        |
| 857 | 857 | }  | 
                                                        
| 858 | 858 | $this->stats[$current_date][$source]['hist'][$distance] = 1;  | 
                                                        
| 859 | 859 |  					} else { | 
                                                        
@@ -870,22 +870,22 @@ discard block  | 
                                                    ||
| 870 | 870 | |
| 871 | 871 | |
| 872 | 872 |  			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { | 
                                                        
| 873 | - if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";  | 
                                                        |
| 874 | - $SpotterLive = new SpotterLive($this->db);  | 
                                                        |
| 875 | - $SpotterLive->deleteLiveSpotterDataNotUpdated();  | 
                                                        |
| 876 | - $SpotterLive->db = null;  | 
                                                        |
| 877 | - //SpotterLive->deleteLiveSpotterData();  | 
                                                        |
| 878 | - if ($globalDebug) echo " Done\n";  | 
                                                        |
| 879 | - $this->last_delete_hourly = time();  | 
                                                        |
| 873 | + if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";  | 
                                                        |
| 874 | + $SpotterLive = new SpotterLive($this->db);  | 
                                                        |
| 875 | + $SpotterLive->deleteLiveSpotterDataNotUpdated();  | 
                                                        |
| 876 | + $SpotterLive->db = null;  | 
                                                        |
| 877 | + //SpotterLive->deleteLiveSpotterData();  | 
                                                        |
| 878 | + if ($globalDebug) echo " Done\n";  | 
                                                        |
| 879 | + $this->last_delete_hourly = time();  | 
                                                        |
| 880 | 880 | }  | 
                                                        
| 881 | 881 | |
| 882 | - }  | 
                                                        |
| 883 | - //$ignoreImport = false;  | 
                                                        |
| 882 | + }  | 
                                                        |
| 883 | + //$ignoreImport = false;  | 
                                                        |
| 884 | 884 | }  | 
                                                        
| 885 | 885 |  		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); | 
                                                        
| 886 | 886 | if ($send) return $this->all_flights[$id];  | 
                                                        
| 887 | - }  | 
                                                        |
| 887 | + }  | 
                                                        |
| 888 | + }  | 
                                                        |
| 888 | 889 | }  | 
                                                        
| 889 | - }  | 
                                                        |
| 890 | 890 | }  | 
                                                        
| 891 | 891 | ?>  | 
                                                        
@@ -53,7 +53,9 @@ discard block  | 
                                                    ||
| 53 | 53 | $dbc = $this->db;  | 
                                                        
| 54 | 54 | $this->all_flights[$id]['schedule_check'] = true;  | 
                                                        
| 55 | 55 |  	if ($globalSchedulesFetch) { | 
                                                        
| 56 | - if ($globalDebug) echo 'Getting schedule info...'."\n";  | 
                                                        |
| 56 | +	if ($globalDebug) { | 
                                                        |
| 57 | + echo 'Getting schedule info...'."\n";  | 
                                                        |
| 58 | + }  | 
                                                        |
| 57 | 59 | $Spotter = new Spotter($dbc);  | 
                                                        
| 58 | 60 | $Schedule = new Schedule($dbc);  | 
                                                        
| 59 | 61 | $Translation = new Translation($dbc);  | 
                                                        
@@ -64,7 +66,9 @@ discard block  | 
                                                    ||
| 64 | 66 |  	    if ($Schedule->checkSchedule($operator) == 0) { | 
                                                        
| 65 | 67 | $schedule = $Schedule->fetchSchedule($operator);  | 
                                                        
| 66 | 68 |  		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { | 
                                                        
| 67 | -		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; | 
                                                        |
| 69 | +		    if ($globalDebug) { | 
                                                        |
| 70 | +		    	echo "-> Schedule info for ".$operator." (".$ident.")\n"; | 
                                                        |
| 71 | + }  | 
                                                        |
| 68 | 72 |  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); | 
                                                        
| 69 | 73 |  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); | 
                                                        
| 70 | 74 | // Should also check if route schedule = route from DB  | 
                                                        
@@ -73,7 +77,9 @@ discard block  | 
                                                    ||
| 73 | 77 | $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);  | 
                                                        
| 74 | 78 |  			    if (trim($airport_icao) != '') { | 
                                                        
| 75 | 79 | $this->all_flights[$id]['departure_airport'] = $airport_icao;  | 
                                                        
| 76 | - if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";  | 
                                                        |
| 80 | +				if ($globalDebug) { | 
                                                        |
| 81 | + echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";  | 
                                                        |
| 82 | + }  | 
                                                        |
| 77 | 83 | }  | 
                                                        
| 78 | 84 | }  | 
                                                        
| 79 | 85 | }  | 
                                                        
@@ -82,17 +88,25 @@ discard block  | 
                                                    ||
| 82 | 88 | $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);  | 
                                                        
| 83 | 89 |  			    if (trim($airport_icao) != '') { | 
                                                        
| 84 | 90 | $this->all_flights[$id]['arrival_airport'] = $airport_icao;  | 
                                                        
| 85 | - if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";  | 
                                                        |
| 91 | +				if ($globalDebug) { | 
                                                        |
| 92 | + echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";  | 
                                                        |
| 93 | + }  | 
                                                        |
| 86 | 94 | }  | 
                                                        
| 87 | 95 | }  | 
                                                        
| 88 | 96 | }  | 
                                                        
| 89 | 97 | $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);  | 
                                                        
| 90 | 98 | }  | 
                                                        
| 91 | - } else $scheduleexist = true;  | 
                                                        |
| 92 | - } else $scheduleexist = true;  | 
                                                        |
| 99 | +	    } else { | 
                                                        |
| 100 | + $scheduleexist = true;  | 
                                                        |
| 101 | + }  | 
                                                        |
| 102 | +	} else { | 
                                                        |
| 103 | + $scheduleexist = true;  | 
                                                        |
| 104 | + }  | 
                                                        |
| 93 | 105 | // close connection, at least one way will work ?  | 
                                                        
| 94 | 106 |         if ($scheduleexist) { | 
                                                        
| 95 | - if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n";  | 
                                                        |
| 107 | +		if ($globalDebug) { | 
                                                        |
| 108 | + echo "-> get arrival/departure airport info for ".$ident."\n";  | 
                                                        |
| 109 | + }  | 
                                                        |
| 96 | 110 | $sch = $Schedule->getSchedule($operator);  | 
                                                        
| 97 | 111 |  		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time'])); | 
                                                        
| 98 | 112 | }  | 
                                                        
@@ -114,7 +128,9 @@ discard block  | 
                                                    ||
| 114 | 128 | |
| 115 | 129 |      public function checkAll() { | 
                                                        
| 116 | 130 | global $globalDebug;  | 
                                                        
| 117 | - if ($globalDebug) echo "Update last seen flights data...\n";  | 
                                                        |
| 131 | +	if ($globalDebug) { | 
                                                        |
| 132 | + echo "Update last seen flights data...\n";  | 
                                                        |
| 133 | + }  | 
                                                        |
| 118 | 134 |  	foreach ($this->all_flights as $key => $flight) { | 
                                                        
| 119 | 135 |  	    if (isset($this->all_flights[$key]['id'])) { | 
                                                        
| 120 | 136 | //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n";  | 
                                                        
@@ -127,24 +143,32 @@ discard block  | 
                                                    ||
| 127 | 143 | |
| 128 | 144 |      public function arrival($key) { | 
                                                        
| 129 | 145 | global $globalClosestMinDist, $globalDebug;  | 
                                                        
| 130 | - if ($globalDebug) echo 'Update arrival...'."\n";  | 
                                                        |
| 146 | +	if ($globalDebug) { | 
                                                        |
| 147 | + echo 'Update arrival...'."\n";  | 
                                                        |
| 148 | + }  | 
                                                        |
| 131 | 149 | $Spotter = new Spotter($this->db);  | 
                                                        
| 132 | 150 | $airport_icao = '';  | 
                                                        
| 133 | 151 | $airport_time = '';  | 
                                                        
| 134 | - if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;  | 
                                                        |
| 152 | +        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') { | 
                                                        |
| 153 | + $globalClosestMinDist = 50;  | 
                                                        |
| 154 | + }  | 
                                                        |
| 135 | 155 |  	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { | 
                                                        
| 136 | 156 | $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);  | 
                                                        
| 137 | 157 |      	    if (isset($closestAirports[0])) { | 
                                                        
| 138 | 158 |          	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { | 
                                                        
| 139 | 159 | $airport_icao = $closestAirports[0]['icao'];  | 
                                                        
| 140 | 160 | $airport_time = $this->all_flights[$key]['datetime'];  | 
                                                        
| 141 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";  | 
                                                        |
| 161 | +        	    if ($globalDebug) { | 
                                                        |
| 162 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";  | 
                                                        |
| 163 | + }  | 
                                                        |
| 142 | 164 |          	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { | 
                                                        
| 143 | 165 |          	    foreach ($closestAirports as $airport) { | 
                                                        
| 144 | 166 |          		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { | 
                                                        
| 145 | 167 | $airport_icao = $airport['icao'];  | 
                                                        
| 146 | 168 | $airport_time = $this->all_flights[$key]['datetime'];  | 
                                                        
| 147 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";  | 
                                                        |
| 169 | +        		    if ($globalDebug) { | 
                                                        |
| 170 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";  | 
                                                        |
| 171 | + }  | 
                                                        |
| 148 | 172 | break;  | 
                                                        
| 149 | 173 | }  | 
                                                        
| 150 | 174 | }  | 
                                                        
@@ -152,14 +176,20 @@ discard block  | 
                                                    ||
| 152 | 176 | $airport_icao = $closestAirports[0]['icao'];  | 
                                                        
| 153 | 177 | $airport_time = $this->all_flights[$key]['datetime'];  | 
                                                        
| 154 | 178 |          	} else { | 
                                                        
| 155 | - if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";  | 
                                                        |
| 179 | +        		if ($globalDebug) { | 
                                                        |
| 180 | + echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";  | 
                                                        |
| 181 | + }  | 
                                                        |
| 156 | 182 | }  | 
                                                        
| 157 | 183 |      	    } else { | 
                                                        
| 158 | - if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";  | 
                                                        |
| 184 | +    		    if ($globalDebug) { | 
                                                        |
| 185 | + echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";  | 
                                                        |
| 186 | + }  | 
                                                        |
| 159 | 187 | }  | 
                                                        
| 160 | 188 | |
| 161 | 189 |          } else { | 
                                                        
| 162 | - if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";  | 
                                                        |
| 190 | +        	if ($globalDebug) { | 
                                                        |
| 191 | + echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";  | 
                                                        |
| 192 | + }  | 
                                                        |
| 163 | 193 | }  | 
                                                        
| 164 | 194 |          return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); | 
                                                        
| 165 | 195 | }  | 
                                                        
@@ -169,12 +199,16 @@ discard block  | 
                                                    ||
| 169 | 199 |      public function del() { | 
                                                        
| 170 | 200 | global $globalDebug;  | 
                                                        
| 171 | 201 | // Delete old infos  | 
                                                        
| 172 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n";  | 
                                                        |
| 202 | +	if ($globalDebug) { | 
                                                        |
| 203 | + echo 'Delete old values and update latest data...'."\n";  | 
                                                        |
| 204 | + }  | 
                                                        |
| 173 | 205 |  	foreach ($this->all_flights as $key => $flight) { | 
                                                        
| 174 | 206 |      	    if (isset($flight['lastupdate'])) { | 
                                                        
| 175 | 207 |          	if ($flight['lastupdate'] < (time()-3000)) { | 
                                                        
| 176 | 208 |              	    if (isset($this->all_flights[$key]['id'])) { | 
                                                        
| 177 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";  | 
                                                        |
| 209 | +            		if ($globalDebug) { | 
                                                        |
| 210 | + echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";  | 
                                                        |
| 211 | + }  | 
                                                        |
| 178 | 212 | /*  | 
                                                        
| 179 | 213 | $SpotterLive = new SpotterLive();  | 
                                                        
| 180 | 214 | $SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);  | 
                                                        
@@ -184,7 +218,9 @@ discard block  | 
                                                    ||
| 184 | 218 | $Spotter = new Spotter($this->db);  | 
                                                        
| 185 | 219 |              		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { | 
                                                        
| 186 | 220 | $result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);  | 
                                                        
| 187 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";  | 
                                                        |
| 221 | +				if ($globalDebug && $result != 'success') { | 
                                                        |
| 222 | + echo '!!! ERROR : '.$result."\n";  | 
                                                        |
| 223 | + }  | 
                                                        |
| 188 | 224 | }  | 
                                                        
| 189 | 225 | // Put in archive  | 
                                                        
| 190 | 226 | // $Spotter->db = null;  | 
                                                        
@@ -198,8 +234,10 @@ discard block  | 
                                                    ||
| 198 | 234 |      public function add($line) { | 
                                                        
| 199 | 235 | global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights;  | 
                                                        
| 200 | 236 | //if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;  | 
                                                        
| 201 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';  | 
                                                        |
| 202 | -/*  | 
                                                        |
| 237 | +	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { | 
                                                        |
| 238 | + $globalCoordMinChange = '0.02';  | 
                                                        |
| 239 | + }  | 
                                                        |
| 240 | + /*  | 
                                                        |
| 203 | 241 | $Spotter = new Spotter();  | 
                                                        
| 204 | 242 | $dbc = $Spotter->db;  | 
                                                        
| 205 | 243 | $SpotterLive = new SpotterLive($dbc);  | 
                                                        
@@ -227,11 +265,15 @@ discard block  | 
                                                    ||
| 227 | 265 |  		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { | 
                                                        
| 228 | 266 |  		    $current_date = date('Y-m-d'); | 
                                                        
| 229 | 267 | $source = $line['source_name'];  | 
                                                        
| 230 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];  | 
                                                        |
| 268 | +		    if ($source == '' || $line['format_source'] == 'aprs') { | 
                                                        |
| 269 | + $source = $line['format_source'];  | 
                                                        |
| 270 | + }  | 
                                                        |
| 231 | 271 |  		    if (!isset($this->stats[$current_date][$source]['msg'])) { | 
                                                        
| 232 | 272 | $this->stats[$current_date][$source]['msg']['date'] = time();  | 
                                                        
| 233 | 273 | $this->stats[$current_date][$source]['msg']['nb'] = 1;  | 
                                                        
| 234 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1;  | 
                                                        |
| 274 | +		    } else { | 
                                                        |
| 275 | + $this->stats[$current_date][$source]['msg']['nb'] += 1;  | 
                                                        |
| 276 | + }  | 
                                                        |
| 235 | 277 | }  | 
                                                        
| 236 | 278 | |
| 237 | 279 | /*  | 
                                                        
@@ -247,8 +289,11 @@ discard block  | 
                                                    ||
| 247 | 289 | //$this->db = $dbc;  | 
                                                        
| 248 | 290 | |
| 249 | 291 | //$hex = trim($line['hex']);  | 
                                                        
| 250 | - if (!isset($line['id'])) $id = trim($line['hex']);  | 
                                                        |
| 251 | - else $id = trim($line['id']);  | 
                                                        |
| 292 | +	        if (!isset($line['id'])) { | 
                                                        |
| 293 | + $id = trim($line['hex']);  | 
                                                        |
| 294 | +	        } else { | 
                                                        |
| 295 | + $id = trim($line['id']);  | 
                                                        |
| 296 | + }  | 
                                                        |
| 252 | 297 | |
| 253 | 298 |  		if (!isset($this->all_flights[$id])) { | 
                                                        
| 254 | 299 | $this->all_flights[$id] = array();  | 
                                                        
@@ -256,13 +301,21 @@ discard block  | 
                                                    ||
| 256 | 301 |  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true)); | 
                                                        
| 257 | 302 |  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); | 
                                                        
| 258 | 303 |  		    if (!isset($line['id'])) { | 
                                                        
| 259 | - if (!isset($globalDaemon)) $globalDaemon = TRUE;  | 
                                                        |
| 260 | -//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); | 
                                                        |
| 304 | +			if (!isset($globalDaemon)) { | 
                                                        |
| 305 | + $globalDaemon = TRUE;  | 
                                                        |
| 306 | + }  | 
                                                        |
| 307 | +			//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); | 
                                                        |
| 261 | 308 |  //			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); | 
                                                        
| 262 | -			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); | 
                                                        |
| 309 | +			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) { | 
                                                        |
| 310 | +				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); | 
                                                        |
| 311 | + }  | 
                                                        |
| 263 | 312 |  		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        
| 264 | -		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); | 
                                                        |
| 265 | - if ($globalAllFlights !== FALSE) $dataFound = true;  | 
                                                        |
| 313 | +		     } else { | 
                                                        |
| 314 | +		     	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); | 
                                                        |
| 315 | + }  | 
                                                        |
| 316 | +		    if ($globalAllFlights !== FALSE) { | 
                                                        |
| 317 | + $dataFound = true;  | 
                                                        |
| 318 | + }  | 
                                                        |
| 266 | 319 | }  | 
                                                        
| 267 | 320 | |
| 268 | 321 | //print_r($this->all_flights);  | 
                                                        
@@ -276,11 +329,19 @@ discard block  | 
                                                    ||
| 276 | 329 | $Spotter = new Spotter($this->db);  | 
                                                        
| 277 | 330 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']));  | 
                                                        
| 278 | 331 | $Spotter->db = null;  | 
                                                        
| 279 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 280 | -			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); | 
                                                        |
| 332 | +			if ($globalDebugTimeElapsed) { | 
                                                        |
| 333 | + echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 334 | + }  | 
                                                        |
| 335 | +			if ($aircraft_icao != '') { | 
                                                        |
| 336 | +				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); | 
                                                        |
| 337 | + }  | 
                                                        |
| 338 | + }  | 
                                                        |
| 339 | +		    if ($globalAllFlights !== FALSE) { | 
                                                        |
| 340 | + $dataFound = true;  | 
                                                        |
| 341 | + }  | 
                                                        |
| 342 | +		    if ($globalDebug) { | 
                                                        |
| 343 | + echo "*********** New aircraft hex : ".$line['hex']." ***********\n";  | 
                                                        |
| 281 | 344 | }  | 
                                                        
| 282 | - if ($globalAllFlights !== FALSE) $dataFound = true;  | 
                                                        |
| 283 | - if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n";  | 
                                                        |
| 284 | 345 | }  | 
                                                        
| 285 | 346 |  		if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') { | 
                                                        
| 286 | 347 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); | 
                                                        
@@ -290,14 +351,23 @@ discard block  | 
                                                    ||
| 290 | 351 | $Spotter = new Spotter($this->db);  | 
                                                        
| 291 | 352 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);  | 
                                                        
| 292 | 353 | $Spotter->db = null;  | 
                                                        
| 293 | -			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); | 
                                                        |
| 354 | +			if ($aircraft_icao != '') { | 
                                                        |
| 355 | +				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); | 
                                                        |
| 356 | + }  | 
                                                        |
| 294 | 357 | }  | 
                                                        
| 295 | 358 |  		if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) { | 
                                                        
| 296 | - if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';  | 
                                                        |
| 297 | - elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';  | 
                                                        |
| 298 | - elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';  | 
                                                        |
| 299 | - elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';  | 
                                                        |
| 300 | -			if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); | 
                                                        |
| 359 | +			if ($line['aircraft_type'] == 'PARA_GLIDER') { | 
                                                        |
| 360 | + $aircraft_icao = 'GLID';  | 
                                                        |
| 361 | +			} elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') { | 
                                                        |
| 362 | + $aircraft_icao = 'UHEL';  | 
                                                        |
| 363 | +			} elseif ($line['aircraft_type'] == 'TOW_PLANE') { | 
                                                        |
| 364 | + $aircraft_icao = 'TOWPLANE';  | 
                                                        |
| 365 | +			} elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') { | 
                                                        |
| 366 | + $aircraft_icao = 'POWAIRC';  | 
                                                        |
| 367 | + }  | 
                                                        |
| 368 | +			if (isset($aircraft_icao)) { | 
                                                        |
| 369 | +				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); | 
                                                        |
| 370 | + }  | 
                                                        |
| 301 | 371 | }  | 
                                                        
| 302 | 372 |  		if (!isset($this->all_flights[$id]['aircraft_icao'])) { | 
                                                        
| 303 | 373 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); | 
                                                        
@@ -307,8 +377,11 @@ discard block  | 
                                                    ||
| 307 | 377 |  		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { | 
                                                        
| 308 | 378 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); | 
                                                        
| 309 | 379 |  		    } else { | 
                                                        
| 310 | - if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";  | 
                                                        |
| 311 | -				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; | 
                                                        |
| 380 | +				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { | 
                                                        |
| 381 | + echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";  | 
                                                        |
| 382 | +				} elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { | 
                                                        |
| 383 | +					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; | 
                                                        |
| 384 | + }  | 
                                                        |
| 312 | 385 | /*  | 
                                                        
| 313 | 386 | echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);  | 
                                                        
| 314 | 387 | print_r($this->all_flights[$id]);  | 
                                                        
@@ -340,15 +413,25 @@ discard block  | 
                                                    ||
| 340 | 413 | $timeelapsed = microtime(true);  | 
                                                        
| 341 | 414 | $Spotter = new Spotter($this->db);  | 
                                                        
| 342 | 415 | $fromsource = NULL;  | 
                                                        
| 343 | - if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource;  | 
                                                        |
| 344 | - elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim';  | 
                                                        |
| 345 | - elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao';  | 
                                                        |
| 346 | - elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim';  | 
                                                        |
| 347 | - elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao';  | 
                                                        |
| 416 | +            		if (isset($globalAirlinesSource) && $globalAirlinesSource != '') { | 
                                                        |
| 417 | + $fromsource = $globalAirlinesSource;  | 
                                                        |
| 418 | +            		} elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') { | 
                                                        |
| 419 | + $fromsource = 'vatsim';  | 
                                                        |
| 420 | +            		} elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') { | 
                                                        |
| 421 | + $fromsource = 'ivao';  | 
                                                        |
| 422 | +			} elseif (isset($globalVATSIM) && $globalVATSIM) { | 
                                                        |
| 423 | + $fromsource = 'vatsim';  | 
                                                        |
| 424 | +			} elseif (isset($globalIVAO) && $globalIVAO) { | 
                                                        |
| 425 | + $fromsource = 'ivao';  | 
                                                        |
| 426 | + }  | 
                                                        |
| 348 | 427 | $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource);  | 
                                                        
| 349 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";  | 
                                                        |
| 428 | +			if ($globalDebug && $result != 'success') { | 
                                                        |
| 429 | + echo '!!! ERROR : '.$result."\n";  | 
                                                        |
| 430 | + }  | 
                                                        |
| 350 | 431 | $Spotter->db = null;  | 
                                                        
| 351 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 432 | +			if ($globalDebugTimeElapsed) { | 
                                                        |
| 433 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 434 | + }  | 
                                                        |
| 352 | 435 | }  | 
                                                        
| 353 | 436 | |
| 354 | 437 | /*  | 
                                                        
@@ -359,7 +442,9 @@ discard block  | 
                                                    ||
| 359 | 442 |  		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        
| 360 | 443 |  		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); | 
                                                        
| 361 | 444 | */  | 
                                                        
| 362 | -		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        |
| 445 | +		    if (!isset($this->all_flights[$id]['id'])) { | 
                                                        |
| 446 | +		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        |
| 447 | + }  | 
                                                        |
| 363 | 448 | |
| 364 | 449 | //$putinarchive = true;  | 
                                                        
| 365 | 450 |  		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { | 
                                                        
@@ -376,7 +461,9 @@ discard block  | 
                                                    ||
| 376 | 461 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);  | 
                                                        
| 377 | 462 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);  | 
                                                        
| 378 | 463 |  		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); | 
                                                        
| 379 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 464 | +				if ($globalDebugTimeElapsed) { | 
                                                        |
| 465 | + echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 466 | + }  | 
                                                        |
| 380 | 467 | |
| 381 | 468 |  		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { | 
                                                        
| 382 | 469 | $timeelapsed = microtime(true);  | 
                                                        
@@ -389,7 +476,9 @@ discard block  | 
                                                    ||
| 389 | 476 | $Translation->db = null;  | 
                                                        
| 390 | 477 | }  | 
                                                        
| 391 | 478 | $Spotter->db = null;  | 
                                                        
| 392 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 479 | +			if ($globalDebugTimeElapsed) { | 
                                                        |
| 480 | + echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 481 | + }  | 
                                                        |
| 393 | 482 | |
| 394 | 483 |  			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { | 
                                                        
| 395 | 484 |  			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { | 
                                                        
@@ -398,9 +487,13 @@ discard block  | 
                                                    ||
| 398 | 487 |  		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); | 
                                                        
| 399 | 488 | }  | 
                                                        
| 400 | 489 | }  | 
                                                        
| 401 | - if (!isset($globalFork)) $globalFork = TRUE;  | 
                                                        |
| 490 | +			if (!isset($globalFork)) { | 
                                                        |
| 491 | + $globalFork = TRUE;  | 
                                                        |
| 492 | + }  | 
                                                        |
| 402 | 493 |  			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { | 
                                                        
| 403 | - if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident']));  | 
                                                        |
| 494 | +				if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) { | 
                                                        |
| 495 | + $this->get_Schedule($id,trim($line['ident']));  | 
                                                        |
| 496 | + }  | 
                                                        |
| 404 | 497 | }  | 
                                                        
| 405 | 498 | }  | 
                                                        
| 406 | 499 | }  | 
                                                        
@@ -416,16 +509,23 @@ discard block  | 
                                                    ||
| 416 | 509 | // use datetime  | 
                                                        
| 417 | 510 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);  | 
                                                        
| 418 | 511 | $speed = $speed*3.6;  | 
                                                        
| 419 | -			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); | 
                                                        |
| 420 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";  | 
                                                        |
| 512 | +			if ($speed < 1000) { | 
                                                        |
| 513 | +				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); | 
                                                        |
| 514 | + }  | 
                                                        |
| 515 | +  			if ($globalDebug) { | 
                                                        |
| 516 | + echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";  | 
                                                        |
| 517 | + }  | 
                                                        |
| 421 | 518 | }  | 
                                                        
| 422 | 519 | }  | 
                                                        
| 423 | 520 | |
| 424 | 521 | |
| 425 | 522 | |
| 426 | 523 |  	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { | 
                                                        
| 427 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);  | 
                                                        |
| 428 | - else unset($timediff);  | 
                                                        |
| 524 | +	    	    if (isset($this->all_flights[$id]['time_last_coord'])) { | 
                                                        |
| 525 | + $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);  | 
                                                        |
| 526 | +	    	    } else { | 
                                                        |
| 527 | + unset($timediff);  | 
                                                        |
| 528 | + }  | 
                                                        |
| 429 | 529 |  	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) { | 
                                                        
| 430 | 530 |  			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) { | 
                                                        
| 431 | 531 |  			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { | 
                                                        
@@ -433,21 +533,31 @@ discard block  | 
                                                    ||
| 433 | 533 | $this->all_flights[$id]['archive_longitude'] = $line['longitude'];  | 
                                                        
| 434 | 534 | $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        
| 435 | 535 | |
| 436 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';  | 
                                                        |
| 536 | +				if ($globalDebug) { | 
                                                        |
| 537 | + echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';  | 
                                                        |
| 538 | + }  | 
                                                        |
| 437 | 539 | $timeelapsed = microtime(true);  | 
                                                        
| 438 | 540 | $Spotter = new Spotter($this->db);  | 
                                                        
| 439 | 541 | $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);  | 
                                                        
| 440 | - if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];  | 
                                                        |
| 542 | +				if (!empty($all_country)) { | 
                                                        |
| 543 | + $this->all_flights[$id]['over_country'] = $all_country['iso2'];  | 
                                                        |
| 544 | + }  | 
                                                        |
| 441 | 545 | $Spotter->db = null;  | 
                                                        
| 442 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 546 | +				if ($globalDebugTimeElapsed) { | 
                                                        |
| 547 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 548 | + }  | 
                                                        |
| 443 | 549 | $this->tmd = 0;  | 
                                                        
| 444 | - if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";  | 
                                                        |
| 550 | +				if ($globalDebug) { | 
                                                        |
| 551 | + echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";  | 
                                                        |
| 552 | + }  | 
                                                        |
| 445 | 553 | }  | 
                                                        
| 446 | 554 | }  | 
                                                        
| 447 | 555 | |
| 448 | 556 |  			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { | 
                                                        
| 449 | 557 |  			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { | 
                                                        
| 450 | - if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];  | 
                                                        |
| 558 | +				if (!isset($this->all_flights[$id]['archive_latitude'])) { | 
                                                        |
| 559 | + $this->all_flights[$id]['archive_latitude'] = $line['latitude'];  | 
                                                        |
| 560 | + }  | 
                                                        |
| 451 | 561 |  				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') { | 
                                                        
| 452 | 562 | $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];  | 
                                                        
| 453 | 563 | $dataFound = true;  | 
                                                        
@@ -469,9 +579,13 @@ discard block  | 
                                                    ||
| 469 | 579 | */  | 
                                                        
| 470 | 580 | }  | 
                                                        
| 471 | 581 |  			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { | 
                                                        
| 472 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;  | 
                                                        |
| 582 | +			    if ($line['longitude'] > 180) { | 
                                                        |
| 583 | + $line['longitude'] = $line['longitude'] - 360;  | 
                                                        |
| 584 | + }  | 
                                                        |
| 473 | 585 |  			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { | 
                                                        
| 474 | - if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];  | 
                                                        |
| 586 | +				if (!isset($this->all_flights[$id]['archive_longitude'])) { | 
                                                        |
| 587 | + $this->all_flights[$id]['archive_longitude'] = $line['longitude'];  | 
                                                        |
| 588 | + }  | 
                                                        |
| 475 | 589 |  				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') { | 
                                                        
| 476 | 590 | $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];  | 
                                                        
| 477 | 591 | $dataFound = true;  | 
                                                        
@@ -502,7 +616,9 @@ discard block  | 
                                                    ||
| 502 | 616 | }  | 
                                                        
| 503 | 617 | }  | 
                                                        
| 504 | 618 |  		if (isset($line['last_update']) && $line['last_update'] != '') { | 
                                                        
| 505 | - if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true;  | 
                                                        |
| 619 | +		    if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) { | 
                                                        |
| 620 | + $dataFound = true;  | 
                                                        |
| 621 | + }  | 
                                                        |
| 506 | 622 |  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); | 
                                                        
| 507 | 623 | }  | 
                                                        
| 508 | 624 |  		if (isset($line['verticalrate']) && $line['verticalrate'] != '') { | 
                                                        
@@ -524,40 +640,60 @@ discard block  | 
                                                    ||
| 524 | 640 | // Here we force archive of flight because after ground it's a new one (or should be)  | 
                                                        
| 525 | 641 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); | 
                                                        
| 526 | 642 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); | 
                                                        
| 527 | -			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi'))); | 
                                                        |
| 528 | -		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); | 
                                                        |
| 529 | -			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        |
| 643 | +			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) { | 
                                                        |
| 644 | +				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi'))); | 
                                                        |
| 645 | +			} elseif (isset($line['id'])) { | 
                                                        |
| 646 | +		        	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); | 
                                                        |
| 647 | +		        } elseif (isset($this->all_flights[$id]['ident'])) { | 
                                                        |
| 648 | +				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); | 
                                                        |
| 649 | + }  | 
                                                        |
| 650 | + }  | 
                                                        |
| 651 | +		    if ($line['ground'] != 1) { | 
                                                        |
| 652 | + $line['ground'] = 0;  | 
                                                        |
| 530 | 653 | }  | 
                                                        
| 531 | - if ($line['ground'] != 1) $line['ground'] = 0;  | 
                                                        |
| 532 | 654 |  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); | 
                                                        
| 533 | 655 | //$dataFound = true;  | 
                                                        
| 534 | 656 | }  | 
                                                        
| 535 | 657 |  		if (isset($line['squawk']) && $line['squawk'] != '') { | 
                                                        
| 536 | 658 |  		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) { | 
                                                        
| 537 | - if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 659 | +			    if ($this->all_flights[$id]['squawk'] != $line['squawk']) { | 
                                                        |
| 660 | + $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 661 | + }  | 
                                                        |
| 538 | 662 |  			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); | 
                                                        
| 539 | 663 | $highlight = '';  | 
                                                        
| 540 | -			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 541 | -			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 542 | -			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 664 | +			    if ($this->all_flights[$id]['squawk'] == '7500') { | 
                                                        |
| 665 | +			    	$highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 666 | + }  | 
                                                        |
| 667 | +			    if ($this->all_flights[$id]['squawk'] == '7600') { | 
                                                        |
| 668 | +			    	$highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 669 | + }  | 
                                                        |
| 670 | +			    if ($this->all_flights[$id]['squawk'] == '7700') { | 
                                                        |
| 671 | +			    	$highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; | 
                                                        |
| 672 | + }  | 
                                                        |
| 543 | 673 |  			    if ($highlight != '') { | 
                                                        
| 544 | 674 | $timeelapsed = microtime(true);  | 
                                                        
| 545 | 675 | $Spotter = new Spotter($this->db);  | 
                                                        
| 546 | 676 | $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);  | 
                                                        
| 547 | 677 | $Spotter->db = null;  | 
                                                        
| 548 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 678 | +				if ($globalDebugTimeElapsed) { | 
                                                        |
| 679 | + echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 680 | + }  | 
                                                        |
| 549 | 681 | |
| 550 | 682 | //$putinarchive = true;  | 
                                                        
| 551 | 683 | //$highlight = '';  | 
                                                        
| 552 | 684 | }  | 
                                                        
| 553 | 685 | |
| 554 | -		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); | 
                                                        |
| 686 | +		    } else { | 
                                                        |
| 687 | +		    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); | 
                                                        |
| 688 | + }  | 
                                                        |
| 555 | 689 | //$dataFound = true;  | 
                                                        
| 556 | 690 | }  | 
                                                        
| 557 | 691 | |
| 558 | 692 |  		if (isset($line['altitude']) && $line['altitude'] != '') { | 
                                                        
| 559 | 693 |  		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { | 
                                                        
| 560 | - if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 694 | +			if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) { | 
                                                        |
| 695 | + $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 696 | + }  | 
                                                        |
| 561 | 697 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); | 
                                                        
| 562 | 698 |  			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); | 
                                                        
| 563 | 699 | //$dataFound = true;  | 
                                                        
@@ -569,21 +705,30 @@ discard block  | 
                                                    ||
| 569 | 705 | }  | 
                                                        
| 570 | 706 | |
| 571 | 707 |  		if (isset($line['heading']) && $line['heading'] != '') { | 
                                                        
| 572 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 708 | +		    if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) { | 
                                                        |
| 709 | + $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 710 | + }  | 
                                                        |
| 573 | 711 |  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); | 
                                                        
| 574 | 712 |  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); | 
                                                        
| 575 | 713 | //$dataFound = true;  | 
                                                        
| 576 | 714 |    		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) { | 
                                                        
| 577 | 715 | $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);  | 
                                                        
| 578 | 716 |  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); | 
                                                        
| 579 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 580 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";  | 
                                                        |
| 717 | +		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) { | 
                                                        |
| 718 | + $this->all_flights[$id]['putinarchive'] = true;  | 
                                                        |
| 719 | + }  | 
                                                        |
| 720 | +  		    if ($globalDebug) { | 
                                                        |
| 721 | + echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";  | 
                                                        |
| 722 | + }  | 
                                                        |
| 581 | 723 |    		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { | 
                                                        
| 582 | 724 | // If not enough messages and ACARS set heading to 0  | 
                                                        
| 583 | 725 |    		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); | 
                                                        
| 584 | 726 | }  | 
                                                        
| 585 | - if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;  | 
                                                        |
| 586 | - elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;  | 
                                                        |
| 727 | +		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) { | 
                                                        |
| 728 | + $dataFound = false;  | 
                                                        |
| 729 | +		} elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) { | 
                                                        |
| 730 | + $dataFound = false;  | 
                                                        |
| 731 | + }  | 
                                                        |
| 587 | 732 | |
| 588 | 733 | // print_r($this->all_flights[$id]);  | 
                                                        
| 589 | 734 | //gets the callsign from the last hour  | 
                                                        
@@ -598,23 +743,36 @@ discard block  | 
                                                    ||
| 598 | 743 | //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";  | 
                                                        
| 599 | 744 | //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);  | 
                                                        
| 600 | 745 |  			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { | 
                                                        
| 601 | - if ($globalDebug) echo "Check if aircraft is already in DB...";  | 
                                                        |
| 746 | +				if ($globalDebug) { | 
                                                        |
| 747 | + echo "Check if aircraft is already in DB...";  | 
                                                        |
| 748 | + }  | 
                                                        |
| 602 | 749 | $timeelapsed = microtime(true);  | 
                                                        
| 603 | 750 | $SpotterLive = new SpotterLive($this->db);  | 
                                                        
| 604 | 751 |  				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) { | 
                                                        
| 605 | 752 | $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);  | 
                                                        
| 606 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 753 | +				    if ($globalDebugTimeElapsed) { | 
                                                        |
| 754 | + echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 755 | + }  | 
                                                        |
| 607 | 756 |  				} elseif (isset($line['id'])) { | 
                                                        
| 608 | 757 | $recent_ident = $SpotterLive->checkIdRecent($line['id']);  | 
                                                        
| 609 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 758 | +				    if ($globalDebugTimeElapsed) { | 
                                                        |
| 759 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 760 | + }  | 
                                                        |
| 610 | 761 |  				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { | 
                                                        
| 611 | 762 | $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);  | 
                                                        
| 612 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 613 | - } else $recent_ident = '';  | 
                                                        |
| 763 | +				    if ($globalDebugTimeElapsed) { | 
                                                        |
| 764 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 765 | + }  | 
                                                        |
| 766 | +				} else { | 
                                                        |
| 767 | + $recent_ident = '';  | 
                                                        |
| 768 | + }  | 
                                                        |
| 614 | 769 | $SpotterLive->db=null;  | 
                                                        
| 615 | 770 | |
| 616 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";  | 
                                                        |
| 617 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";  | 
                                                        |
| 771 | +				if ($globalDebug && $recent_ident == '') { | 
                                                        |
| 772 | + echo " Not in DB.\n";  | 
                                                        |
| 773 | +				} elseif ($globalDebug && $recent_ident != '') { | 
                                                        |
| 774 | + echo " Already in DB.\n";  | 
                                                        |
| 775 | + }  | 
                                                        |
| 618 | 776 |  			    } else { | 
                                                        
| 619 | 777 | $recent_ident = '';  | 
                                                        
| 620 | 778 |  				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); | 
                                                        
@@ -622,7 +780,9 @@ discard block  | 
                                                    ||
| 622 | 780 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive  | 
                                                        
| 623 | 781 | if($recent_ident == "")  | 
                                                        
| 624 | 782 |  			    { | 
                                                        
| 625 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";  | 
                                                        |
| 783 | +				if ($globalDebug) { | 
                                                        |
| 784 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";  | 
                                                        |
| 785 | + }  | 
                                                        |
| 626 | 786 |  				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } | 
                                                        
| 627 | 787 |  				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } | 
                                                        
| 628 | 788 | //adds the spotter data for the archive  | 
                                                        
@@ -666,26 +826,44 @@ discard block  | 
                                                    ||
| 666 | 826 | |
| 667 | 827 |  				if (!$ignoreImport) { | 
                                                        
| 668 | 828 | $highlight = '';  | 
                                                        
| 669 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';  | 
                                                        |
| 670 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';  | 
                                                        |
| 671 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';  | 
                                                        |
| 672 | -				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); | 
                                                        |
| 829 | +				    if ($this->all_flights[$id]['squawk'] == '7500') { | 
                                                        |
| 830 | + $highlight = 'Squawk 7500 : Hijack';  | 
                                                        |
| 831 | + }  | 
                                                        |
| 832 | +				    if ($this->all_flights[$id]['squawk'] == '7600') { | 
                                                        |
| 833 | + $highlight = 'Squawk 7600 : Lost Comm (radio failure)';  | 
                                                        |
| 834 | + }  | 
                                                        |
| 835 | +				    if ($this->all_flights[$id]['squawk'] == '7700') { | 
                                                        |
| 836 | + $highlight = 'Squawk 7700 : Emergency';  | 
                                                        |
| 837 | + }  | 
                                                        |
| 838 | +				    if (!isset($this->all_flights[$id]['id'])) { | 
                                                        |
| 839 | +				    	$this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); | 
                                                        |
| 840 | + }  | 
                                                        |
| 673 | 841 | $timeelapsed = microtime(true);  | 
                                                        
| 674 | 842 | $Spotter = new Spotter($this->db);  | 
                                                        
| 675 | 843 | $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name']);  | 
                                                        
| 676 | 844 | $Spotter->db = null;  | 
                                                        
| 677 | - if ($globalDebug && isset($result)) echo $result."\n";  | 
                                                        |
| 678 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 845 | +				    if ($globalDebug && isset($result)) { | 
                                                        |
| 846 | + echo $result."\n";  | 
                                                        |
| 847 | + }  | 
                                                        |
| 848 | +				    if ($globalDebugTimeElapsed) { | 
                                                        |
| 849 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 850 | + }  | 
                                                        |
| 679 | 851 | |
| 680 | 852 | // Add source stat in DB  | 
                                                        
| 681 | 853 | $Stats = new Stats($this->db);  | 
                                                        
| 682 | 854 |  				    if (!empty($this->stats)) { | 
                                                        
| 683 | - if ($globalDebug) echo 'Add source stats : ';  | 
                                                        |
| 855 | +					if ($globalDebug) { | 
                                                        |
| 856 | + echo 'Add source stats : ';  | 
                                                        |
| 857 | + }  | 
                                                        |
| 684 | 858 |  				        foreach($this->stats as $date => $data) { | 
                                                        
| 685 | 859 |  					    foreach($data as $source => $sourced) { | 
                                                        
| 686 | 860 | //print_r($sourced);  | 
                                                        
| 687 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);  | 
                                                        |
| 688 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);  | 
                                                        |
| 861 | +				    	        if (isset($sourced['polar'])) { | 
                                                        |
| 862 | + echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);  | 
                                                        |
| 863 | + }  | 
                                                        |
| 864 | +				    	        if (isset($sourced['hist'])) { | 
                                                        |
| 865 | + echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);  | 
                                                        |
| 866 | + }  | 
                                                        |
| 689 | 867 |  				    		if (isset($sourced['msg'])) { | 
                                                        
| 690 | 868 |  				    		    if (time() - $sourced['msg']['date'] > 10) { | 
                                                        
| 691 | 869 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));  | 
                                                        
@@ -698,13 +876,17 @@ discard block  | 
                                                    ||
| 698 | 876 | unset($this->stats[$date]);  | 
                                                        
| 699 | 877 | }  | 
                                                        
| 700 | 878 | }  | 
                                                        
| 701 | - if ($globalDebug) echo 'Done'."\n";  | 
                                                        |
| 879 | +				    	if ($globalDebug) { | 
                                                        |
| 880 | + echo 'Done'."\n";  | 
                                                        |
| 881 | + }  | 
                                                        |
| 702 | 882 | |
| 703 | 883 | }  | 
                                                        
| 704 | 884 | $Stats->db = null;  | 
                                                        
| 705 | 885 | |
| 706 | 886 | $this->del();  | 
                                                        
| 707 | - } elseif ($globalDebug) echo 'Ignore data'."\n";  | 
                                                        |
| 887 | +				} elseif ($globalDebug) { | 
                                                        |
| 888 | + echo 'Ignore data'."\n";  | 
                                                        |
| 889 | + }  | 
                                                        |
| 708 | 890 | //$ignoreImport = false;  | 
                                                        
| 709 | 891 | $this->all_flights[$id]['addedSpotter'] = 1;  | 
                                                        
| 710 | 892 | //print_r($this->all_flights[$id]);  | 
                                                        
@@ -721,12 +903,16 @@ discard block  | 
                                                    ||
| 721 | 903 | */  | 
                                                        
| 722 | 904 | //SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);  | 
                                                        
| 723 | 905 |  				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { | 
                                                        
| 724 | - if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";  | 
                                                        |
| 906 | +				    if ($globalDebug) { | 
                                                        |
| 907 | + echo "---- Deleting Live Spotter data older than 9 hours...";  | 
                                                        |
| 908 | + }  | 
                                                        |
| 725 | 909 | //SpotterLive->deleteLiveSpotterDataNotUpdated();  | 
                                                        
| 726 | 910 | $SpotterLive = new SpotterLive($this->db);  | 
                                                        
| 727 | 911 | $SpotterLive->deleteLiveSpotterData();  | 
                                                        
| 728 | 912 | $SpotterLive->db=null;  | 
                                                        
| 729 | - if ($globalDebug) echo " Done\n";  | 
                                                        |
| 913 | +				    if ($globalDebug) { | 
                                                        |
| 914 | + echo " Done\n";  | 
                                                        |
| 915 | + }  | 
                                                        |
| 730 | 916 | $this->last_delete = time();  | 
                                                        
| 731 | 917 | }  | 
                                                        
| 732 | 918 |  			    } else { | 
                                                        
@@ -749,11 +935,17 @@ discard block  | 
                                                    ||
| 749 | 935 |  		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n"; | 
                                                        
| 750 | 936 |  		    if ($globalDebug) { | 
                                                        
| 751 | 937 |  			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) { | 
                                                        
| 752 | - if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";  | 
                                                        |
| 753 | - else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";  | 
                                                        |
| 938 | +				if (isset($this->all_flights[$id]['source_name'])) { | 
                                                        |
| 939 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";  | 
                                                        |
| 940 | +				} else { | 
                                                        |
| 941 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";  | 
                                                        |
| 942 | + }  | 
                                                        |
| 754 | 943 |  			} else { | 
                                                        
| 755 | - if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";  | 
                                                        |
| 756 | - else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";  | 
                                                        |
| 944 | +				if (isset($this->all_flights[$id]['source_name'])) { | 
                                                        |
| 945 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";  | 
                                                        |
| 946 | +				} else { | 
                                                        |
| 947 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";  | 
                                                        |
| 948 | + }  | 
                                                        |
| 757 | 949 | }  | 
                                                        
| 758 | 950 | }  | 
                                                        
| 759 | 951 | $ignoreImport = false;  | 
                                                        
@@ -799,20 +991,26 @@ discard block  | 
                                                    ||
| 799 | 991 | |
| 800 | 992 |  		    if (!$ignoreImport) { | 
                                                        
| 801 | 993 |  			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { | 
                                                        
| 802 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";  | 
                                                        |
| 994 | +				if ($globalDebug) { | 
                                                        |
| 995 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";  | 
                                                        |
| 996 | + }  | 
                                                        |
| 803 | 997 | $timeelapsed = microtime(true);  | 
                                                        
| 804 | 998 | $SpotterLive = new SpotterLive($this->db);  | 
                                                        
| 805 | 999 | $result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);  | 
                                                        
| 806 | 1000 | $SpotterLive->db = null;  | 
                                                        
| 807 | 1001 | $this->all_flights[$id]['putinarchive'] = false;  | 
                                                        
| 808 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 1002 | +				if ($globalDebugTimeElapsed) { | 
                                                        |
| 1003 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";  | 
                                                        |
| 1004 | + }  | 
                                                        |
| 809 | 1005 | |
| 810 | 1006 | // Put statistics in $this->stats variable  | 
                                                        
| 811 | 1007 |  				//if ($line['format_source'] != 'aprs') { | 
                                                        
| 812 | 1008 |  				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) { | 
                                                        
| 813 | 1009 |  				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { | 
                                                        
| 814 | 1010 | $source = $this->all_flights[$id]['source_name'];  | 
                                                        
| 815 | - if ($source == '') $source = $this->all_flights[$id]['format_source'];  | 
                                                        |
| 1011 | +					if ($source == '') { | 
                                                        |
| 1012 | + $source = $this->all_flights[$id]['format_source'];  | 
                                                        |
| 1013 | + }  | 
                                                        |
| 816 | 1014 |  					if (!isset($this->source_location[$source])) { | 
                                                        
| 817 | 1015 | $Location = new Source();  | 
                                                        
| 818 | 1016 | $coord = $Location->getLocationInfobySourceName($source);  | 
                                                        
@@ -833,7 +1031,9 @@ discard block  | 
                                                    ||
| 833 | 1031 | $stats_heading = round($stats_heading/22.5);  | 
                                                        
| 834 | 1032 | $stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);  | 
                                                        
| 835 | 1033 |  					$current_date = date('Y-m-d'); | 
                                                        
| 836 | - if ($stats_heading == 16) $stats_heading = 0;  | 
                                                        |
| 1034 | +					if ($stats_heading == 16) { | 
                                                        |
| 1035 | + $stats_heading = 0;  | 
                                                        |
| 1036 | + }  | 
                                                        |
| 837 | 1037 |  					if (!isset($this->stats[$current_date][$source]['polar'][1])) { | 
                                                        
| 838 | 1038 |  						for ($i=0;$i<=15;$i++) { | 
                                                        
| 839 | 1039 | $this->stats[$current_date][$source]['polar'][$i] = 0;  | 
                                                        
@@ -851,7 +1051,9 @@ discard block  | 
                                                    ||
| 851 | 1051 |  						if (isset($this->stats[$current_date][$source]['hist'][0])) { | 
                                                        
| 852 | 1052 | end($this->stats[$current_date][$source]['hist']);  | 
                                                        
| 853 | 1053 | $mini = key($this->stats[$current_date][$source]['hist'])+10;  | 
                                                        
| 854 | - } else $mini = 0;  | 
                                                        |
| 1054 | +						} else { | 
                                                        |
| 1055 | + $mini = 0;  | 
                                                        |
| 1056 | + }  | 
                                                        |
| 855 | 1057 |  						for ($i=$mini;$i<=$distance;$i+=10) { | 
                                                        
| 856 | 1058 | $this->stats[$current_date][$source]['hist'][$i] = 0;  | 
                                                        
| 857 | 1059 | }  | 
                                                        
@@ -862,20 +1064,30 @@ discard block  | 
                                                    ||
| 862 | 1064 | }  | 
                                                        
| 863 | 1065 | |
| 864 | 1066 | $this->all_flights[$id]['lastupdate'] = time();  | 
                                                        
| 865 | - if ($this->all_flights[$id]['putinarchive']) $send = true;  | 
                                                        |
| 1067 | +				if ($this->all_flights[$id]['putinarchive']) { | 
                                                        |
| 1068 | + $send = true;  | 
                                                        |
| 1069 | + }  | 
                                                        |
| 866 | 1070 | //if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";  | 
                                                        
| 867 | - if ($globalDebug) echo $result."\n";  | 
                                                        |
| 868 | - } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";  | 
                                                        |
| 1071 | +				if ($globalDebug) { | 
                                                        |
| 1072 | + echo $result."\n";  | 
                                                        |
| 1073 | + }  | 
                                                        |
| 1074 | +			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { | 
                                                        |
| 1075 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";  | 
                                                        |
| 1076 | + }  | 
                                                        |
| 869 | 1077 | //$this->del();  | 
                                                        
| 870 | 1078 | |
| 871 | 1079 | |
| 872 | 1080 |  			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { | 
                                                        
| 873 | - if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";  | 
                                                        |
| 1081 | +			    if ($globalDebug) { | 
                                                        |
| 1082 | + echo "---- Deleting Live Spotter data Not updated since 2 hour...";  | 
                                                        |
| 1083 | + }  | 
                                                        |
| 874 | 1084 | $SpotterLive = new SpotterLive($this->db);  | 
                                                        
| 875 | 1085 | $SpotterLive->deleteLiveSpotterDataNotUpdated();  | 
                                                        
| 876 | 1086 | $SpotterLive->db = null;  | 
                                                        
| 877 | 1087 | //SpotterLive->deleteLiveSpotterData();  | 
                                                        
| 878 | - if ($globalDebug) echo " Done\n";  | 
                                                        |
| 1088 | +			    if ($globalDebug) { | 
                                                        |
| 1089 | + echo " Done\n";  | 
                                                        |
| 1090 | + }  | 
                                                        |
| 879 | 1091 | $this->last_delete_hourly = time();  | 
                                                        
| 880 | 1092 | }  | 
                                                        
| 881 | 1093 | |
@@ -883,7 +1095,9 @@ discard block  | 
                                                    ||
| 883 | 1095 | //$ignoreImport = false;  | 
                                                        
| 884 | 1096 | }  | 
                                                        
| 885 | 1097 |  		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); | 
                                                        
| 886 | - if ($send) return $this->all_flights[$id];  | 
                                                        |
| 1098 | +		if ($send) { | 
                                                        |
| 1099 | + return $this->all_flights[$id];  | 
                                                        |
| 1100 | + }  | 
                                                        |
| 887 | 1101 | }  | 
                                                        
| 888 | 1102 | }  | 
                                                        
| 889 | 1103 | }  | 
                                                        
@@ -12,7 +12,9 @@ discard block  | 
                                                    ||
| 12 | 12 | |
| 13 | 13 |  	public function __construct($dbc = null) { | 
                                                        
| 14 | 14 | global $globalFilterName;  | 
                                                        
| 15 | - if (isset($globalFilterName)) $this->filter_name = $globalFilterName;  | 
                                                        |
| 15 | +		if (isset($globalFilterName)) { | 
                                                        |
| 16 | + $this->filter_name = $globalFilterName;  | 
                                                        |
| 17 | + }  | 
                                                        |
| 16 | 18 | $Connection = new Connection($dbc);  | 
                                                        
| 17 | 19 | $this->db = $Connection->db();  | 
                                                        
| 18 | 20 | }  | 
                                                        
@@ -80,7 +82,9 @@ discard block  | 
                                                    ||
| 80 | 82 | }  | 
                                                        
| 81 | 83 | }  | 
                                                        
| 82 | 84 |  	public function getAllAirlineNames($filter_name = '') { | 
                                                        
| 83 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 85 | +		if ($filter_name == '') { | 
                                                        |
| 86 | + $filter_name = $this->filter_name;  | 
                                                        |
| 87 | + }  | 
                                                        |
| 84 | 88 | $query = "SELECT * FROM stats_airline WHERE filter_name = :filter_name ORDER BY airline_name ASC";  | 
                                                        
| 85 | 89 |                   try { | 
                                                        
| 86 | 90 | $sth = $this->db->prepare($query);  | 
                                                        
@@ -92,7 +96,9 @@ discard block  | 
                                                    ||
| 92 | 96 | return $all;  | 
                                                        
| 93 | 97 | }  | 
                                                        
| 94 | 98 |  	public function getAllAircraftTypes($stats_airline = '',$filter_name = '') { | 
                                                        
| 95 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 99 | +		if ($filter_name == '') { | 
                                                        |
| 100 | + $filter_name = $this->filter_name;  | 
                                                        |
| 101 | + }  | 
                                                        |
| 96 | 102 | $query = "SELECT * FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_manufacturer ASC";  | 
                                                        
| 97 | 103 |                   try { | 
                                                        
| 98 | 104 | $sth = $this->db->prepare($query);  | 
                                                        
@@ -104,7 +110,9 @@ discard block  | 
                                                    ||
| 104 | 110 | return $all;  | 
                                                        
| 105 | 111 | }  | 
                                                        
| 106 | 112 |  	public function getAllManufacturers($stats_airline = '',$filter_name = '') { | 
                                                        
| 107 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 113 | +		if ($filter_name == '') { | 
                                                        |
| 114 | + $filter_name = $this->filter_name;  | 
                                                        |
| 115 | + }  | 
                                                        |
| 108 | 116 | $query = "SELECT DISTINCT(aircraft_manufacturer) FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name AND aircraft_manufacturer <> '' ORDER BY aircraft_manufacturer ASC";  | 
                                                        
| 109 | 117 |                   try { | 
                                                        
| 110 | 118 | $sth = $this->db->prepare($query);  | 
                                                        
@@ -116,7 +124,9 @@ discard block  | 
                                                    ||
| 116 | 124 | return $all;  | 
                                                        
| 117 | 125 | }  | 
                                                        
| 118 | 126 |  	public function getAllAirportNames($stats_airline = '',$filter_name = '') { | 
                                                        
| 119 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 127 | +		if ($filter_name == '') { | 
                                                        |
| 128 | + $filter_name = $this->filter_name;  | 
                                                        |
| 129 | + }  | 
                                                        |
| 120 | 130 | $query = "SELECT airport_icao, airport_name,airport_city,airport_country FROM stats_airport WHERE stats_airline = :stats_airline AND filter_name = :filter_name AND stats_type = 'daily' GROUP BY airport_icao,airport_name,airport_city,airport_country ORDER BY airport_city ASC";  | 
                                                        
| 121 | 131 |                   try { | 
                                                        
| 122 | 132 | $sth = $this->db->prepare($query);  | 
                                                        
@@ -129,7 +139,9 @@ discard block  | 
                                                    ||
| 129 | 139 | }  | 
                                                        
| 130 | 140 | |
| 131 | 141 |  	public function getAllOwnerNames($stats_airline = '',$filter_name = '') { | 
                                                        
| 132 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 142 | +		if ($filter_name == '') { | 
                                                        |
| 143 | + $filter_name = $this->filter_name;  | 
                                                        |
| 144 | + }  | 
                                                        |
| 133 | 145 | $query = "SELECT owner_name FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_name ASC";  | 
                                                        
| 134 | 146 |                   try { | 
                                                        
| 135 | 147 | $sth = $this->db->prepare($query);  | 
                                                        
@@ -142,7 +154,9 @@ discard block  | 
                                                    ||
| 142 | 154 | }  | 
                                                        
| 143 | 155 | |
| 144 | 156 |  	public function getAllPilotNames($stats_airline = '',$filter_name = '') { | 
                                                        
| 145 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 157 | +		if ($filter_name == '') { | 
                                                        |
| 158 | + $filter_name = $this->filter_name;  | 
                                                        |
| 159 | + }  | 
                                                        |
| 146 | 160 | $query = "SELECT pilot_id,pilot_name FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_name ASC";  | 
                                                        
| 147 | 161 |                   try { | 
                                                        
| 148 | 162 | $sth = $this->db->prepare($query);  | 
                                                        
@@ -157,10 +171,15 @@ discard block  | 
                                                    ||
| 157 | 171 | |
| 158 | 172 |  	public function countAllAircraftTypes($limit = true, $stats_airline = '', $filter_name = '',$year = '', $month = '') { | 
                                                        
| 159 | 173 | global $globalStatsFilters;  | 
                                                        
| 160 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 174 | +		if ($filter_name == '') { | 
                                                        |
| 175 | + $filter_name = $this->filter_name;  | 
                                                        |
| 176 | + }  | 
                                                        |
| 161 | 177 |  		if ($year == '' && $month == '') { | 
                                                        
| 162 | - if ($limit) $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 163 | - else $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC";  | 
                                                        |
| 178 | +			if ($limit) { | 
                                                        |
| 179 | + $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 180 | +			} else { | 
                                                        |
| 181 | + $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name, aircraft_manufacturer FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC";  | 
                                                        |
| 182 | + }  | 
                                                        |
| 164 | 183 |  			try { | 
                                                        
| 165 | 184 | $sth = $this->db->prepare($query);  | 
                                                        
| 166 | 185 |  				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); | 
                                                        
@@ -168,7 +187,9 @@ discard block  | 
                                                    ||
| 168 | 187 | echo "error : ".$e->getMessage();  | 
                                                        
| 169 | 188 | }  | 
                                                        
| 170 | 189 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 171 | - } else $all = array();  | 
                                                        |
| 190 | +		} else { | 
                                                        |
| 191 | + $all = array();  | 
                                                        |
| 192 | + }  | 
                                                        |
| 172 | 193 |                  if (empty($all)) { | 
                                                        
| 173 | 194 |              	    $filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
| 174 | 195 |              	    if ($filter_name != '') { | 
                                                        
@@ -182,10 +203,15 @@ discard block  | 
                                                    ||
| 182 | 203 | }  | 
                                                        
| 183 | 204 |  	public function countAllAirlineCountries($limit = true,$filter_name = '',$year = '',$month = '') { | 
                                                        
| 184 | 205 | global $globalStatsFilters;  | 
                                                        
| 185 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 206 | +		if ($filter_name == '') { | 
                                                        |
| 207 | + $filter_name = $this->filter_name;  | 
                                                        |
| 208 | + }  | 
                                                        |
| 186 | 209 |  		if ($year == '' && $month == '') { | 
                                                        
| 187 | - if ($limit) $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country ORDER BY airline_country_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 188 | - else $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country ORDER BY airline_country_count DESC";  | 
                                                        |
| 210 | +			if ($limit) { | 
                                                        |
| 211 | + $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country ORDER BY airline_country_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 212 | +			} else { | 
                                                        |
| 213 | + $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country ORDER BY airline_country_count DESC";  | 
                                                        |
| 214 | + }  | 
                                                        |
| 189 | 215 |  			try { | 
                                                        
| 190 | 216 | $sth = $this->db->prepare($query);  | 
                                                        
| 191 | 217 |  				$sth->execute(array(':filter_name' => $filter_name)); | 
                                                        
@@ -193,7 +219,9 @@ discard block  | 
                                                    ||
| 193 | 219 | echo "error : ".$e->getMessage();  | 
                                                        
| 194 | 220 | }  | 
                                                        
| 195 | 221 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 196 | - } else $all = array();  | 
                                                        |
| 222 | +		} else { | 
                                                        |
| 223 | + $all = array();  | 
                                                        |
| 224 | + }  | 
                                                        |
| 197 | 225 |                  if (empty($all)) { | 
                                                        
| 198 | 226 | $Spotter = new Spotter($this->db);  | 
                                                        
| 199 | 227 | $filters = array();  | 
                                                        
@@ -208,10 +236,15 @@ discard block  | 
                                                    ||
| 208 | 236 | }  | 
                                                        
| 209 | 237 |  	public function countAllAircraftManufacturers($limit = true,$stats_airline = '', $filter_name = '',$year = '', $month = '') { | 
                                                        
| 210 | 238 | global $globalStatsFilters;  | 
                                                        
| 211 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 239 | +		if ($filter_name == '') { | 
                                                        |
| 240 | + $filter_name = $this->filter_name;  | 
                                                        |
| 241 | + }  | 
                                                        |
| 212 | 242 |  		if ($year == '' && $month == '') { | 
                                                        
| 213 | - if ($limit) $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 214 | - else $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC";  | 
                                                        |
| 243 | +			if ($limit) { | 
                                                        |
| 244 | + $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 245 | +			} else { | 
                                                        |
| 246 | + $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC";  | 
                                                        |
| 247 | + }  | 
                                                        |
| 215 | 248 |  			try { | 
                                                        
| 216 | 249 | $sth = $this->db->prepare($query);  | 
                                                        
| 217 | 250 |  				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); | 
                                                        
@@ -219,7 +252,9 @@ discard block  | 
                                                    ||
| 219 | 252 | echo "error : ".$e->getMessage();  | 
                                                        
| 220 | 253 | }  | 
                                                        
| 221 | 254 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 222 | - } else $all = array();  | 
                                                        |
| 255 | +		} else { | 
                                                        |
| 256 | + $all = array();  | 
                                                        |
| 257 | + }  | 
                                                        |
| 223 | 258 |  		if (empty($all)) { | 
                                                        
| 224 | 259 |  			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
| 225 | 260 |  			if ($filter_name != '') { | 
                                                        
@@ -234,10 +269,15 @@ discard block  | 
                                                    ||
| 234 | 269 | |
| 235 | 270 |  	public function countAllArrivalCountries($limit = true, $stats_airline = '', $filter_name = '',$year = '', $month = '') { | 
                                                        
| 236 | 271 | global $globalStatsFilters;  | 
                                                        
| 237 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 272 | +		if ($filter_name == '') { | 
                                                        |
| 273 | + $filter_name = $this->filter_name;  | 
                                                        |
| 274 | + }  | 
                                                        |
| 238 | 275 |  		if ($year == '' && $month == '') { | 
                                                        
| 239 | - if ($limit) $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country ORDER BY airport_arrival_country_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 240 | - else $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country ORDER BY airport_arrival_country_count DESC";  | 
                                                        |
| 276 | +			if ($limit) { | 
                                                        |
| 277 | + $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country ORDER BY airport_arrival_country_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 278 | +			} else { | 
                                                        |
| 279 | + $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country ORDER BY airport_arrival_country_count DESC";  | 
                                                        |
| 280 | + }  | 
                                                        |
| 241 | 281 |  			try { | 
                                                        
| 242 | 282 | $sth = $this->db->prepare($query);  | 
                                                        
| 243 | 283 |  				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); | 
                                                        
@@ -245,7 +285,9 @@ discard block  | 
                                                    ||
| 245 | 285 | echo "error : ".$e->getMessage();  | 
                                                        
| 246 | 286 | }  | 
                                                        
| 247 | 287 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 248 | - } else $all = array();  | 
                                                        |
| 288 | +		} else { | 
                                                        |
| 289 | + $all = array();  | 
                                                        |
| 290 | + }  | 
                                                        |
| 249 | 291 |                  if (empty($all)) { | 
                                                        
| 250 | 292 |  			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
| 251 | 293 |  			if ($filter_name != '') { | 
                                                        
@@ -259,9 +301,14 @@ discard block  | 
                                                    ||
| 259 | 301 | }  | 
                                                        
| 260 | 302 |  	public function countAllDepartureCountries($limit = true, $stats_airline = '', $filter_name = '', $year = '', $month = '') { | 
                                                        
| 261 | 303 | global $globalStatsFilters;  | 
                                                        
| 262 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 263 | - if ($limit) $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 264 | - else $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC";  | 
                                                        |
| 304 | +		if ($filter_name == '') { | 
                                                        |
| 305 | + $filter_name = $this->filter_name;  | 
                                                        |
| 306 | + }  | 
                                                        |
| 307 | +		if ($limit) { | 
                                                        |
| 308 | + $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 309 | +		} else { | 
                                                        |
| 310 | + $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC";  | 
                                                        |
| 311 | + }  | 
                                                        |
| 265 | 312 |                   try { | 
                                                        
| 266 | 313 | $sth = $this->db->prepare($query);  | 
                                                        
| 267 | 314 |                          $sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); | 
                                                        
@@ -283,17 +330,29 @@ discard block  | 
                                                    ||
| 283 | 330 | |
| 284 | 331 |  	public function countAllAirlines($limit = true,$filter_name = '',$year = '',$month = '') { | 
                                                        
| 285 | 332 | global $globalStatsFilters, $globalVATSIM, $globalIVAO;  | 
                                                        
| 286 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 333 | +		if ($filter_name == '') { | 
                                                        |
| 334 | + $filter_name = $this->filter_name;  | 
                                                        |
| 335 | + }  | 
                                                        |
| 287 | 336 |  		if ($year == '' && $month == '') { | 
                                                        
| 288 | - if ($globalVATSIM) $forsource = 'vatsim';  | 
                                                        |
| 289 | - if ($globalIVAO) $forsource = 'ivao';  | 
                                                        |
| 337 | +			if ($globalVATSIM) { | 
                                                        |
| 338 | + $forsource = 'vatsim';  | 
                                                        |
| 339 | + }  | 
                                                        |
| 340 | +			if ($globalIVAO) { | 
                                                        |
| 341 | + $forsource = 'ivao';  | 
                                                        |
| 342 | + }  | 
                                                        |
| 290 | 343 |  			if (isset($forsource)) { | 
                                                        
| 291 | - if ($limit) $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource = :forsource ORDER BY airline_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 292 | - else $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource = :forsource ORDER BY airline_count DESC";  | 
                                                        |
| 344 | +				if ($limit) { | 
                                                        |
| 345 | + $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource = :forsource ORDER BY airline_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 346 | +				} else { | 
                                                        |
| 347 | + $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource = :forsource ORDER BY airline_count DESC";  | 
                                                        |
| 348 | + }  | 
                                                        |
| 293 | 349 |  				$query_values = array(':filter_name' => $filter_name,':forsource' => $forsource); | 
                                                        
| 294 | 350 |  			} else { | 
                                                        
| 295 | - if ($limit) $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource IS NULL ORDER BY airline_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 296 | - else $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource IS NULL ORDER BY airline_count DESC";  | 
                                                        |
| 351 | +				if ($limit) { | 
                                                        |
| 352 | + $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource IS NULL ORDER BY airline_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 353 | +				} else { | 
                                                        |
| 354 | + $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name AND airlines.forsource IS NULL ORDER BY airline_count DESC";  | 
                                                        |
| 355 | + }  | 
                                                        |
| 297 | 356 |  				$query_values = array(':filter_name' => $filter_name); | 
                                                        
| 298 | 357 | }  | 
                                                        
| 299 | 358 |  			try { | 
                                                        
@@ -303,7 +362,9 @@ discard block  | 
                                                    ||
| 303 | 362 | echo "error : ".$e->getMessage();  | 
                                                        
| 304 | 363 | }  | 
                                                        
| 305 | 364 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 306 | - } else $all = array();  | 
                                                        |
| 365 | +		} else { | 
                                                        |
| 366 | + $all = array();  | 
                                                        |
| 367 | + }  | 
                                                        |
| 307 | 368 |                  if (empty($all)) { | 
                                                        
| 308 | 369 | $Spotter = new Spotter($this->db);  | 
                                                        
| 309 | 370 | $filters = array();  | 
                                                        
@@ -318,10 +379,15 @@ discard block  | 
                                                    ||
| 318 | 379 | }  | 
                                                        
| 319 | 380 |  	public function countAllAircraftRegistrations($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') { | 
                                                        
| 320 | 381 | global $globalStatsFilters;  | 
                                                        
| 321 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 382 | +		if ($filter_name == '') { | 
                                                        |
| 383 | + $filter_name = $this->filter_name;  | 
                                                        |
| 384 | + }  | 
                                                        |
| 322 | 385 |  		if ($year == '' && $month == '') { | 
                                                        
| 323 | - if ($limit) $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name, s.registration FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 324 | - else $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC";  | 
                                                        |
| 386 | +			if ($limit) { | 
                                                        |
| 387 | + $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name, s.registration FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 388 | +			} else { | 
                                                        |
| 389 | + $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC";  | 
                                                        |
| 390 | + }  | 
                                                        |
| 325 | 391 |  			try { | 
                                                        
| 326 | 392 | $sth = $this->db->prepare($query);  | 
                                                        
| 327 | 393 |  				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); | 
                                                        
@@ -329,7 +395,9 @@ discard block  | 
                                                    ||
| 329 | 395 | echo "error : ".$e->getMessage();  | 
                                                        
| 330 | 396 | }  | 
                                                        
| 331 | 397 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 332 | - } else $all = array();  | 
                                                        |
| 398 | +		} else { | 
                                                        |
| 399 | + $all = array();  | 
                                                        |
| 400 | + }  | 
                                                        |
| 333 | 401 |                  if (empty($all)) { | 
                                                        
| 334 | 402 |  			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
| 335 | 403 |  			if ($filter_name != '') { | 
                                                        
@@ -343,10 +411,15 @@ discard block  | 
                                                    ||
| 343 | 411 | }  | 
                                                        
| 344 | 412 |  	public function countAllCallsigns($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') { | 
                                                        
| 345 | 413 | global $globalStatsFilters;  | 
                                                        
| 346 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 414 | +		if ($filter_name == '') { | 
                                                        |
| 415 | + $filter_name = $this->filter_name;  | 
                                                        |
| 416 | + }  | 
                                                        |
| 347 | 417 |  		if ($year == '' && $month == '') { | 
                                                        
| 348 | - if ($limit) $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 349 | - else $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC";  | 
                                                        |
| 418 | +			if ($limit) { | 
                                                        |
| 419 | + $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 420 | +			} else { | 
                                                        |
| 421 | + $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC";  | 
                                                        |
| 422 | + }  | 
                                                        |
| 350 | 423 |  			 try { | 
                                                        
| 351 | 424 | $sth = $this->db->prepare($query);  | 
                                                        
| 352 | 425 |  				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); | 
                                                        
@@ -354,7 +427,9 @@ discard block  | 
                                                    ||
| 354 | 427 | echo "error : ".$e->getMessage();  | 
                                                        
| 355 | 428 | }  | 
                                                        
| 356 | 429 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 357 | - } else $all = array();  | 
                                                        |
| 430 | +		} else { | 
                                                        |
| 431 | + $all = array();  | 
                                                        |
| 432 | + }  | 
                                                        |
| 358 | 433 |  		if (empty($all)) { | 
                                                        
| 359 | 434 |  			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
| 360 | 435 |  			if ($filter_name != '') { | 
                                                        
@@ -368,11 +443,16 @@ discard block  | 
                                                    ||
| 368 | 443 | }  | 
                                                        
| 369 | 444 |  	public function countAllFlightOverCountries($limit = true, $stats_airline = '',$filter_name = '',$year = '',$month = '') { | 
                                                        
| 370 | 445 | $Connection = new Connection();  | 
                                                        
| 371 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 446 | +		if ($filter_name == '') { | 
                                                        |
| 447 | + $filter_name = $this->filter_name;  | 
                                                        |
| 448 | + }  | 
                                                        |
| 372 | 449 |  		if ($Connection->tableExists('countries')) { | 
                                                        
| 373 | 450 |  			if ($year == '' && $month == '') { | 
                                                        
| 374 | - if ($limit) $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC LIMIT 20 OFFSET 0";  | 
                                                        |
| 375 | - else $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC";  | 
                                                        |
| 451 | +				if ($limit) { | 
                                                        |
| 452 | + $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC LIMIT 20 OFFSET 0";  | 
                                                        |
| 453 | +				} else { | 
                                                        |
| 454 | + $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC";  | 
                                                        |
| 455 | + }  | 
                                                        |
| 376 | 456 |  				 try { | 
                                                        
| 377 | 457 | $sth = $this->db->prepare($query);  | 
                                                        
| 378 | 458 |  					$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); | 
                                                        
@@ -387,17 +467,24 @@ discard block  | 
                                                    ||
| 387 | 467 | }  | 
                                                        
| 388 | 468 | */  | 
                                                        
| 389 | 469 | return $all;  | 
                                                        
| 390 | - } else return array();  | 
                                                        |
| 470 | +			} else { | 
                                                        |
| 471 | + return array();  | 
                                                        |
| 472 | + }  | 
                                                        |
| 391 | 473 |  		} else { | 
                                                        
| 392 | 474 | return array();  | 
                                                        
| 393 | 475 | }  | 
                                                        
| 394 | 476 | }  | 
                                                        
| 395 | 477 |  	public function countAllPilots($limit = true,$stats_airline = '',$filter_name = '', $year = '',$month = '') { | 
                                                        
| 396 | 478 | global $globalStatsFilters;  | 
                                                        
| 397 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 479 | +		if ($filter_name == '') { | 
                                                        |
| 480 | + $filter_name = $this->filter_name;  | 
                                                        |
| 481 | + }  | 
                                                        |
| 398 | 482 |  		if ($year == '' && $month == '') { | 
                                                        
| 399 | - if ($limit) $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name, format_source FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 400 | - else $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name, format_source FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC";  | 
                                                        |
| 483 | +			if ($limit) { | 
                                                        |
| 484 | + $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name, format_source FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 485 | +			} else { | 
                                                        |
| 486 | + $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name, format_source FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC";  | 
                                                        |
| 487 | + }  | 
                                                        |
| 401 | 488 |  			try { | 
                                                        
| 402 | 489 | $sth = $this->db->prepare($query);  | 
                                                        
| 403 | 490 |  				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); | 
                                                        
@@ -405,7 +492,9 @@ discard block  | 
                                                    ||
| 405 | 492 | echo "error : ".$e->getMessage();  | 
                                                        
| 406 | 493 | }  | 
                                                        
| 407 | 494 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 408 | - } else $all = array();  | 
                                                        |
| 495 | +		} else { | 
                                                        |
| 496 | + $all = array();  | 
                                                        |
| 497 | + }  | 
                                                        |
| 409 | 498 |  		if (empty($all)) { | 
                                                        
| 410 | 499 |  			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
| 411 | 500 |  			if ($filter_name != '') { | 
                                                        
@@ -420,10 +509,15 @@ discard block  | 
                                                    ||
| 420 | 509 | |
| 421 | 510 |  	public function countAllOwners($limit = true,$stats_airline = '', $filter_name = '',$year = '',$month = '') { | 
                                                        
| 422 | 511 | global $globalStatsFilters;  | 
                                                        
| 423 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 512 | +		if ($filter_name == '') { | 
                                                        |
| 513 | + $filter_name = $this->filter_name;  | 
                                                        |
| 514 | + }  | 
                                                        |
| 424 | 515 |  		if ($year == '' && $month == '') { | 
                                                        
| 425 | - if ($limit) $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 426 | - else $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC";  | 
                                                        |
| 516 | +			if ($limit) { | 
                                                        |
| 517 | + $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 518 | +			} else { | 
                                                        |
| 519 | + $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC";  | 
                                                        |
| 520 | + }  | 
                                                        |
| 427 | 521 |  			try { | 
                                                        
| 428 | 522 | $sth = $this->db->prepare($query);  | 
                                                        
| 429 | 523 |  				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); | 
                                                        
@@ -431,7 +525,9 @@ discard block  | 
                                                    ||
| 431 | 525 | echo "error : ".$e->getMessage();  | 
                                                        
| 432 | 526 | }  | 
                                                        
| 433 | 527 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 434 | - } else $all = array();  | 
                                                        |
| 528 | +		} else { | 
                                                        |
| 529 | + $all = array();  | 
                                                        |
| 530 | + }  | 
                                                        |
| 435 | 531 |                  if (empty($all)) { | 
                                                        
| 436 | 532 |  			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
| 437 | 533 |  			if ($filter_name != '') { | 
                                                        
@@ -445,10 +541,15 @@ discard block  | 
                                                    ||
| 445 | 541 | }  | 
                                                        
| 446 | 542 |  	public function countAllDepartureAirports($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') { | 
                                                        
| 447 | 543 | global $globalStatsFilters;  | 
                                                        
| 448 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 544 | +		if ($filter_name == '') { | 
                                                        |
| 545 | + $filter_name = $this->filter_name;  | 
                                                        |
| 546 | + }  | 
                                                        |
| 449 | 547 |  		if ($year == '' && $month == '') { | 
                                                        
| 450 | - if ($limit) $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE departure > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 451 | - else $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE departure > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC";  | 
                                                        |
| 548 | +			if ($limit) { | 
                                                        |
| 549 | + $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE departure > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 550 | +			} else { | 
                                                        |
| 551 | + $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE departure > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC";  | 
                                                        |
| 552 | + }  | 
                                                        |
| 452 | 553 |  			try { | 
                                                        
| 453 | 554 | $sth = $this->db->prepare($query);  | 
                                                        
| 454 | 555 |  				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); | 
                                                        
@@ -456,7 +557,9 @@ discard block  | 
                                                    ||
| 456 | 557 | echo "error : ".$e->getMessage();  | 
                                                        
| 457 | 558 | }  | 
                                                        
| 458 | 559 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 459 | - } else $all = array();  | 
                                                        |
| 560 | +		} else { | 
                                                        |
| 561 | + $all = array();  | 
                                                        |
| 562 | + }  | 
                                                        |
| 460 | 563 |                  if (empty($all)) { | 
                                                        
| 461 | 564 |  			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
| 462 | 565 |              		if ($filter_name != '') { | 
                                                        
@@ -477,7 +580,9 @@ discard block  | 
                                                    ||
| 477 | 580 | $icao = $value['airport_departure_icao'];  | 
                                                        
| 478 | 581 |          			if (isset($all[$icao])) { | 
                                                        
| 479 | 582 | $all[$icao]['airport_departure_icao_count'] = $all[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];  | 
                                                        
| 480 | - } else $all[$icao] = $value;  | 
                                                        |
| 583 | +        			} else { | 
                                                        |
| 584 | + $all[$icao] = $value;  | 
                                                        |
| 585 | + }  | 
                                                        |
| 481 | 586 | }  | 
                                                        
| 482 | 587 | $count = array();  | 
                                                        
| 483 | 588 |          		foreach ($all as $key => $row) { | 
                                                        
@@ -489,10 +594,15 @@ discard block  | 
                                                    ||
| 489 | 594 | }  | 
                                                        
| 490 | 595 |  	public function countAllArrivalAirports($limit = true,$stats_airline = '',$filter_name = '',$year = '',$month = '') { | 
                                                        
| 491 | 596 | global $globalStatsFilters;  | 
                                                        
| 492 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 597 | +		if ($filter_name == '') { | 
                                                        |
| 598 | + $filter_name = $this->filter_name;  | 
                                                        |
| 599 | + }  | 
                                                        |
| 493 | 600 |  		if ($year == '' && $month == '') { | 
                                                        
| 494 | - if ($limit) $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE arrival > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 495 | - else $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE arrival > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC";  | 
                                                        |
| 601 | +			if ($limit) { | 
                                                        |
| 602 | + $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE arrival > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC LIMIT 10 OFFSET 0";  | 
                                                        |
| 603 | +			} else { | 
                                                        |
| 604 | + $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE arrival > 0 AND stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC";  | 
                                                        |
| 605 | + }  | 
                                                        |
| 496 | 606 |  			try { | 
                                                        
| 497 | 607 | $sth = $this->db->prepare($query);  | 
                                                        
| 498 | 608 |  				$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); | 
                                                        
@@ -500,7 +610,9 @@ discard block  | 
                                                    ||
| 500 | 610 | echo "error : ".$e->getMessage();  | 
                                                        
| 501 | 611 | }  | 
                                                        
| 502 | 612 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 503 | - } else $all = array();  | 
                                                        |
| 613 | +		} else { | 
                                                        |
| 614 | + $all = array();  | 
                                                        |
| 615 | + }  | 
                                                        |
| 504 | 616 |  		if (empty($all)) { | 
                                                        
| 505 | 617 |  			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
| 506 | 618 |  			if ($filter_name != '') { | 
                                                        
@@ -521,7 +633,9 @@ discard block  | 
                                                    ||
| 521 | 633 | $icao = $value['airport_arrival_icao'];  | 
                                                        
| 522 | 634 |          			if (isset($all[$icao])) { | 
                                                        
| 523 | 635 | $all[$icao]['airport_arrival_icao_count'] = $all[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];  | 
                                                        
| 524 | - } else $all[$icao] = $value;  | 
                                                        |
| 636 | +        			} else { | 
                                                        |
| 637 | + $all[$icao] = $value;  | 
                                                        |
| 638 | + }  | 
                                                        |
| 525 | 639 | }  | 
                                                        
| 526 | 640 | $count = array();  | 
                                                        
| 527 | 641 |          		foreach ($all as $key => $row) { | 
                                                        
@@ -534,13 +648,21 @@ discard block  | 
                                                    ||
| 534 | 648 | }  | 
                                                        
| 535 | 649 |  	public function countAllMonthsLastYear($limit = true,$stats_airline = '',$filter_name = '') { | 
                                                        
| 536 | 650 | global $globalDBdriver, $globalStatsFilters;  | 
                                                        
| 537 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 651 | +		if ($filter_name == '') { | 
                                                        |
| 652 | + $filter_name = $this->filter_name;  | 
                                                        |
| 653 | + }  | 
                                                        |
| 538 | 654 |  		if ($globalDBdriver == 'mysql') { | 
                                                        
| 539 | - if ($limit) $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 MONTH) AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 540 | - else $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 655 | +			if ($limit) { | 
                                                        |
| 656 | + $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 MONTH) AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 657 | +			} else { | 
                                                        |
| 658 | + $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 659 | + }  | 
                                                        |
| 541 | 660 |  		} else { | 
                                                        
| 542 | - if ($limit) $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '12 MONTHS' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 543 | - else $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 661 | +			if ($limit) { | 
                                                        |
| 662 | + $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '12 MONTHS' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 663 | +			} else { | 
                                                        |
| 664 | + $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 665 | + }  | 
                                                        |
| 544 | 666 | }  | 
                                                        
| 545 | 667 |  		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); | 
                                                        
| 546 | 668 |                   try { | 
                                                        
@@ -564,7 +686,9 @@ discard block  | 
                                                    ||
| 564 | 686 | |
| 565 | 687 |  	public function countAllDatesLastMonth($stats_airline = '',$filter_name = '') { | 
                                                        
| 566 | 688 | global $globalStatsFilters;  | 
                                                        
| 567 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 689 | +		if ($filter_name == '') { | 
                                                        |
| 690 | + $filter_name = $this->filter_name;  | 
                                                        |
| 691 | + }  | 
                                                        |
| 568 | 692 | $query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        
| 569 | 693 |  		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); | 
                                                        
| 570 | 694 |                   try { | 
                                                        
@@ -586,7 +710,9 @@ discard block  | 
                                                    ||
| 586 | 710 | }  | 
                                                        
| 587 | 711 |  	public function countAllDatesLast7Days($stats_airline = '',$filter_name = '') { | 
                                                        
| 588 | 712 | global $globalDBdriver, $globalStatsFilters;  | 
                                                        
| 589 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 713 | +		if ($filter_name == '') { | 
                                                        |
| 714 | + $filter_name = $this->filter_name;  | 
                                                        |
| 715 | + }  | 
                                                        |
| 590 | 716 |  		if ($globalDBdriver == 'mysql') { | 
                                                        
| 591 | 717 | $query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND flight_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        
| 592 | 718 |  		} else { | 
                                                        
@@ -612,7 +738,9 @@ discard block  | 
                                                    ||
| 612 | 738 | }  | 
                                                        
| 613 | 739 |  	public function countAllDates($stats_airline = '',$filter_name = '') { | 
                                                        
| 614 | 740 | global $globalStatsFilters;  | 
                                                        
| 615 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 741 | +		if ($filter_name == '') { | 
                                                        |
| 742 | + $filter_name = $this->filter_name;  | 
                                                        |
| 743 | + }  | 
                                                        |
| 616 | 744 | $query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'date' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        
| 617 | 745 |  		$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); | 
                                                        
| 618 | 746 |                   try { | 
                                                        
@@ -634,7 +762,9 @@ discard block  | 
                                                    ||
| 634 | 762 | }  | 
                                                        
| 635 | 763 |  	public function countAllDatesByAirlines($filter_name = '') { | 
                                                        
| 636 | 764 | global $globalStatsFilters;  | 
                                                        
| 637 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 765 | +		if ($filter_name == '') { | 
                                                        |
| 766 | + $filter_name = $this->filter_name;  | 
                                                        |
| 767 | + }  | 
                                                        |
| 638 | 768 | $query = "SELECT stats_airline as airline_icao, flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'date' AND filter_name = :filter_name";  | 
                                                        
| 639 | 769 |  		$query_data = array('filter_name' => $filter_name); | 
                                                        
| 640 | 770 |                   try { | 
                                                        
@@ -656,7 +786,9 @@ discard block  | 
                                                    ||
| 656 | 786 | }  | 
                                                        
| 657 | 787 |  	public function countAllMonths($stats_airline = '',$filter_name = '') { | 
                                                        
| 658 | 788 | global $globalStatsFilters;  | 
                                                        
| 659 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 789 | +		if ($filter_name == '') { | 
                                                        |
| 790 | + $filter_name = $this->filter_name;  | 
                                                        |
| 791 | + }  | 
                                                        |
| 660 | 792 | $query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        
| 661 | 793 |                   try { | 
                                                        
| 662 | 794 | $sth = $this->db->prepare($query);  | 
                                                        
@@ -679,7 +811,9 @@ discard block  | 
                                                    ||
| 679 | 811 | }  | 
                                                        
| 680 | 812 |  	public function countAllMilitaryMonths($filter_name = '') { | 
                                                        
| 681 | 813 | global $globalStatsFilters;  | 
                                                        
| 682 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 814 | +		if ($filter_name == '') { | 
                                                        |
| 815 | + $filter_name = $this->filter_name;  | 
                                                        |
| 816 | + }  | 
                                                        |
| 683 | 817 | $query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'military_flights_bymonth' AND filter_name = :filter_name";  | 
                                                        
| 684 | 818 |                   try { | 
                                                        
| 685 | 819 | $sth = $this->db->prepare($query);  | 
                                                        
@@ -700,9 +834,14 @@ discard block  | 
                                                    ||
| 700 | 834 | }  | 
                                                        
| 701 | 835 |  	public function countAllHours($orderby = 'hour',$limit = true,$stats_airline = '',$filter_name = '') { | 
                                                        
| 702 | 836 | global $globalTimezone, $globalDBdriver, $globalStatsFilters;  | 
                                                        
| 703 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 704 | - if ($limit) $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 705 | - else $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 837 | +		if ($filter_name == '') { | 
                                                        |
| 838 | + $filter_name = $this->filter_name;  | 
                                                        |
| 839 | + }  | 
                                                        |
| 840 | +		if ($limit) { | 
                                                        |
| 841 | + $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 842 | +		} else { | 
                                                        |
| 843 | + $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        |
| 844 | + }  | 
                                                        |
| 706 | 845 |  		if ($orderby == 'hour') { | 
                                                        
| 707 | 846 | /*  | 
                                                        
| 708 | 847 |  			if ($globalDBdriver == 'mysql') { | 
                                                        
@@ -711,7 +850,9 @@ discard block  | 
                                                    ||
| 711 | 850 | */  | 
                                                        
| 712 | 851 | $query .= " ORDER BY CAST(flight_date AS integer) ASC";  | 
                                                        
| 713 | 852 | }  | 
                                                        
| 714 | - if ($orderby == 'count') $query .= " ORDER BY hour_count DESC";  | 
                                                        |
| 853 | +		if ($orderby == 'count') { | 
                                                        |
| 854 | + $query .= " ORDER BY hour_count DESC";  | 
                                                        |
| 855 | + }  | 
                                                        |
| 715 | 856 |                   try { | 
                                                        
| 716 | 857 | $sth = $this->db->prepare($query);  | 
                                                        
| 717 | 858 |                          $sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name)); | 
                                                        
@@ -732,8 +873,12 @@ discard block  | 
                                                    ||
| 732 | 873 | |
| 733 | 874 |  	public function countOverallFlights($stats_airline = '', $filter_name = '',$year = '',$month = '') { | 
                                                        
| 734 | 875 | global $globalStatsFilters;  | 
                                                        
| 735 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 736 | -		if ($year == '') $year = date('Y'); | 
                                                        |
| 876 | +		if ($filter_name == '') { | 
                                                        |
| 877 | + $filter_name = $this->filter_name;  | 
                                                        |
| 878 | + }  | 
                                                        |
| 879 | +		if ($year == '') { | 
                                                        |
| 880 | +			$year = date('Y'); | 
                                                        |
| 881 | + }  | 
                                                        |
| 737 | 882 |  		$all = $this->getSumStats('flights_bymonth',$year,$stats_airline,$filter_name,$month); | 
                                                        
| 738 | 883 |  		if (empty($all)) { | 
                                                        
| 739 | 884 |  			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
@@ -748,8 +893,12 @@ discard block  | 
                                                    ||
| 748 | 893 | }  | 
                                                        
| 749 | 894 |  	public function countOverallMilitaryFlights($filter_name = '',$year = '', $month = '') { | 
                                                        
| 750 | 895 | global $globalStatsFilters;  | 
                                                        
| 751 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 752 | -		if ($year == '') $year = date('Y'); | 
                                                        |
| 896 | +		if ($filter_name == '') { | 
                                                        |
| 897 | + $filter_name = $this->filter_name;  | 
                                                        |
| 898 | + }  | 
                                                        |
| 899 | +		if ($year == '') { | 
                                                        |
| 900 | +			$year = date('Y'); | 
                                                        |
| 901 | + }  | 
                                                        |
| 753 | 902 |  		$all = $this->getSumStats('military_flights_bymonth',$year,'',$filter_name,$month); | 
                                                        
| 754 | 903 |  		if (empty($all)) { | 
                                                        
| 755 | 904 | $filters = array();  | 
                                                        
@@ -765,8 +914,12 @@ discard block  | 
                                                    ||
| 765 | 914 | }  | 
                                                        
| 766 | 915 |  	public function countOverallArrival($stats_airline = '',$filter_name = '', $year = '', $month = '') { | 
                                                        
| 767 | 916 | global $globalStatsFilters;  | 
                                                        
| 768 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 769 | -		if ($year == '') $year = date('Y'); | 
                                                        |
| 917 | +		if ($filter_name == '') { | 
                                                        |
| 918 | + $filter_name = $this->filter_name;  | 
                                                        |
| 919 | + }  | 
                                                        |
| 920 | +		if ($year == '') { | 
                                                        |
| 921 | +			$year = date('Y'); | 
                                                        |
| 922 | + }  | 
                                                        |
| 770 | 923 |  		$all = $this->getSumStats('realarrivals_bymonth',$year,$stats_airline,$filter_name,$month); | 
                                                        
| 771 | 924 |  		if (empty($all)) { | 
                                                        
| 772 | 925 |  			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
@@ -781,7 +934,9 @@ discard block  | 
                                                    ||
| 781 | 934 | }  | 
                                                        
| 782 | 935 |  	public function countOverallAircrafts($stats_airline = '',$filter_name = '',$year = '', $month = '') { | 
                                                        
| 783 | 936 | global $globalStatsFilters;  | 
                                                        
| 784 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 937 | +		if ($filter_name == '') { | 
                                                        |
| 938 | + $filter_name = $this->filter_name;  | 
                                                        |
| 939 | + }  | 
                                                        |
| 785 | 940 |  		if ($year == '' && $month == '') { | 
                                                        
| 786 | 941 | $query = "SELECT COUNT(*) AS nb FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        
| 787 | 942 |  			try { | 
                                                        
@@ -792,7 +947,9 @@ discard block  | 
                                                    ||
| 792 | 947 | }  | 
                                                        
| 793 | 948 | $result = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 794 | 949 | $all = $result[0]['nb'];  | 
                                                        
| 795 | -		} else $all = $this->getSumStats('aircrafts_bymonth',$year,$stats_airline,$filter_name,$month); | 
                                                        |
| 950 | +		} else { | 
                                                        |
| 951 | +			$all = $this->getSumStats('aircrafts_bymonth',$year,$stats_airline,$filter_name,$month); | 
                                                        |
| 952 | + }  | 
                                                        |
| 796 | 953 |  		if (empty($all)) { | 
                                                        
| 797 | 954 |  			$filters = array('airlines' => array($stats_airline),'year' => $year,'month' => $month); | 
                                                        
| 798 | 955 |  			if ($filter_name != '') { | 
                                                        
@@ -806,7 +963,9 @@ discard block  | 
                                                    ||
| 806 | 963 | }  | 
                                                        
| 807 | 964 |  	public function countOverallAirlines($filter_name = '',$year = '',$month = '') { | 
                                                        
| 808 | 965 | global $globalStatsFilters;  | 
                                                        
| 809 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 966 | +		if ($filter_name == '') { | 
                                                        |
| 967 | + $filter_name = $this->filter_name;  | 
                                                        |
| 968 | + }  | 
                                                        |
| 810 | 969 |  		if ($year == '' && $month == '') { | 
                                                        
| 811 | 970 | $query = "SELECT COUNT(*) AS nb_airline FROM stats_airline WHERE filter_name = :filter_name";  | 
                                                        
| 812 | 971 |  			try { | 
                                                        
@@ -817,7 +976,9 @@ discard block  | 
                                                    ||
| 817 | 976 | }  | 
                                                        
| 818 | 977 | $result = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 819 | 978 | $all = $result[0]['nb_airline'];  | 
                                                        
| 820 | -		} else $all = $this->getSumStats('airlines_bymonth',$year,'',$filter_name,$month); | 
                                                        |
| 979 | +		} else { | 
                                                        |
| 980 | +			$all = $this->getSumStats('airlines_bymonth',$year,'',$filter_name,$month); | 
                                                        |
| 981 | + }  | 
                                                        |
| 821 | 982 |  		if (empty($all)) { | 
                                                        
| 822 | 983 | $filters = array();  | 
                                                        
| 823 | 984 |  			$filters = array('year' => $year,'month' => $month); | 
                                                        
@@ -832,7 +993,9 @@ discard block  | 
                                                    ||
| 832 | 993 | }  | 
                                                        
| 833 | 994 |  	public function countOverallOwners($stats_airline = '',$filter_name = '',$year = '', $month = '') { | 
                                                        
| 834 | 995 | global $globalStatsFilters;  | 
                                                        
| 835 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 996 | +		if ($filter_name == '') { | 
                                                        |
| 997 | + $filter_name = $this->filter_name;  | 
                                                        |
| 998 | + }  | 
                                                        |
| 836 | 999 |  		if ($year == '' && $month == '') { | 
                                                        
| 837 | 1000 | $query = "SELECT count(*) as nb FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        
| 838 | 1001 |  			$query_values = array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name); | 
                                                        
@@ -860,7 +1023,9 @@ discard block  | 
                                                    ||
| 860 | 1023 | }  | 
                                                        
| 861 | 1024 |  	public function countOverallPilots($stats_airline = '',$filter_name = '',$year = '',$month = '') { | 
                                                        
| 862 | 1025 | global $globalStatsFilters;  | 
                                                        
| 863 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1026 | +		if ($filter_name == '') { | 
                                                        |
| 1027 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1028 | + }  | 
                                                        |
| 864 | 1029 |  		//if ($year == '') $year = date('Y'); | 
                                                        
| 865 | 1030 |  		if ($year == '' && $month == '') { | 
                                                        
| 866 | 1031 | $query = "SELECT count(*) as nb FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        
@@ -889,7 +1054,9 @@ discard block  | 
                                                    ||
| 889 | 1054 | }  | 
                                                        
| 890 | 1055 | |
| 891 | 1056 |  	public function getLast7DaysAirports($airport_icao = '', $stats_airline = '',$filter_name = '') { | 
                                                        
| 892 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1057 | +		if ($filter_name == '') { | 
                                                        |
| 1058 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1059 | + }  | 
                                                        |
| 893 | 1060 | $query = "SELECT * FROM stats_airport WHERE stats_type = 'daily' AND airport_icao = :airport_icao AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY date";  | 
                                                        
| 894 | 1061 |  		$query_values = array(':airport_icao' => $airport_icao,':stats_airline' => $stats_airline, ':filter_name' => $filter_name); | 
                                                        
| 895 | 1062 |                   try { | 
                                                        
@@ -902,7 +1069,9 @@ discard block  | 
                                                    ||
| 902 | 1069 | return $all;  | 
                                                        
| 903 | 1070 | }  | 
                                                        
| 904 | 1071 |  	public function getStats($type,$stats_airline = '', $filter_name = '') { | 
                                                        
| 905 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1072 | +		if ($filter_name == '') { | 
                                                        |
| 1073 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1074 | + }  | 
                                                        |
| 906 | 1075 | $query = "SELECT * FROM stats WHERE stats_type = :type AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY stats_date";  | 
                                                        
| 907 | 1076 |                  $query_values = array(':type' => $type,':stats_airline' => $stats_airline,':filter_name' => $filter_name); | 
                                                        
| 908 | 1077 |                   try { | 
                                                        
@@ -915,7 +1084,9 @@ discard block  | 
                                                    ||
| 915 | 1084 | return $all;  | 
                                                        
| 916 | 1085 | }  | 
                                                        
| 917 | 1086 |  	public function getSumStats($type,$year,$stats_airline = '',$filter_name = '',$month = '') { | 
                                                        
| 918 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1087 | +		if ($filter_name == '') { | 
                                                        |
| 1088 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1089 | + }  | 
                                                        |
| 919 | 1090 | global $globalArchiveMonths, $globalDBdriver;  | 
                                                        
| 920 | 1091 |      		if ($globalDBdriver == 'mysql') { | 
                                                        
| 921 | 1092 |      			if ($month == '') { | 
                                                        
@@ -945,7 +1116,9 @@ discard block  | 
                                                    ||
| 945 | 1116 | }  | 
                                                        
| 946 | 1117 |  	public function getStatsTotal($type, $stats_airline = '', $filter_name = '') { | 
                                                        
| 947 | 1118 | global $globalArchiveMonths, $globalDBdriver;  | 
                                                        
| 948 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1119 | +		if ($filter_name == '') { | 
                                                        |
| 1120 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1121 | + }  | 
                                                        |
| 949 | 1122 |      		if ($globalDBdriver == 'mysql') { | 
                                                        
| 950 | 1123 | $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL ".$globalArchiveMonths." MONTH) AND stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        
| 951 | 1124 |  		} else { | 
                                                        
@@ -963,7 +1136,9 @@ discard block  | 
                                                    ||
| 963 | 1136 | }  | 
                                                        
| 964 | 1137 |  	public function getStatsAircraftTotal($stats_airline = '', $filter_name = '') { | 
                                                        
| 965 | 1138 | global $globalArchiveMonths, $globalDBdriver;  | 
                                                        
| 966 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1139 | +		if ($filter_name == '') { | 
                                                        |
| 1140 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1141 | + }  | 
                                                        |
| 967 | 1142 |      		if ($globalDBdriver == 'mysql') { | 
                                                        
| 968 | 1143 | $query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name";  | 
                                                        
| 969 | 1144 |                  } else { | 
                                                        
@@ -980,7 +1155,9 @@ discard block  | 
                                                    ||
| 980 | 1155 | }  | 
                                                        
| 981 | 1156 |  	public function getStatsAirlineTotal($filter_name = '') { | 
                                                        
| 982 | 1157 | global $globalArchiveMonths, $globalDBdriver;  | 
                                                        
| 983 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1158 | +		if ($filter_name == '') { | 
                                                        |
| 1159 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1160 | + }  | 
                                                        |
| 984 | 1161 |      		if ($globalDBdriver == 'mysql') { | 
                                                        
| 985 | 1162 | $query = "SELECT SUM(cnt) as total FROM stats_airline WHERE filter_name = :filter_name";  | 
                                                        
| 986 | 1163 |                  } else { | 
                                                        
@@ -997,7 +1174,9 @@ discard block  | 
                                                    ||
| 997 | 1174 | }  | 
                                                        
| 998 | 1175 |  	public function getStatsOwnerTotal($filter_name = '') { | 
                                                        
| 999 | 1176 | global $globalArchiveMonths, $globalDBdriver;  | 
                                                        
| 1000 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1177 | +		if ($filter_name == '') { | 
                                                        |
| 1178 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1179 | + }  | 
                                                        |
| 1001 | 1180 |      		if ($globalDBdriver == 'mysql') { | 
                                                        
| 1002 | 1181 | $query = "SELECT SUM(cnt) as total FROM stats_owner WHERE filter_name = :filter_name";  | 
                                                        
| 1003 | 1182 |  		} else { | 
                                                        
@@ -1014,7 +1193,9 @@ discard block  | 
                                                    ||
| 1014 | 1193 | }  | 
                                                        
| 1015 | 1194 |  	public function getStatsOwner($owner_name,$filter_name = '') { | 
                                                        
| 1016 | 1195 | global $globalArchiveMonths, $globalDBdriver;  | 
                                                        
| 1017 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1196 | +		if ($filter_name == '') { | 
                                                        |
| 1197 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1198 | + }  | 
                                                        |
| 1018 | 1199 | $query = "SELECT cnt FROM stats_owner WHERE filter_name = :filter_name AND owner_name = :owner_name";  | 
                                                        
| 1019 | 1200 |                   try { | 
                                                        
| 1020 | 1201 | $sth = $this->db->prepare($query);  | 
                                                        
@@ -1023,12 +1204,17 @@ discard block  | 
                                                    ||
| 1023 | 1204 | echo "error : ".$e->getMessage();  | 
                                                        
| 1024 | 1205 | }  | 
                                                        
| 1025 | 1206 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 1026 | - if (isset($all[0]['cnt'])) return $all[0]['cnt'];  | 
                                                        |
| 1027 | - else return 0;  | 
                                                        |
| 1207 | +                if (isset($all[0]['cnt'])) { | 
                                                        |
| 1208 | + return $all[0]['cnt'];  | 
                                                        |
| 1209 | +                } else { | 
                                                        |
| 1210 | + return 0;  | 
                                                        |
| 1211 | + }  | 
                                                        |
| 1028 | 1212 | }  | 
                                                        
| 1029 | 1213 |  	public function getStatsPilotTotal($filter_name = '') { | 
                                                        
| 1030 | 1214 | global $globalArchiveMonths, $globalDBdriver;  | 
                                                        
| 1031 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1215 | +		if ($filter_name == '') { | 
                                                        |
| 1216 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1217 | + }  | 
                                                        |
| 1032 | 1218 |      		if ($globalDBdriver == 'mysql') { | 
                                                        
| 1033 | 1219 | $query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name";  | 
                                                        
| 1034 | 1220 |              	} else { | 
                                                        
@@ -1045,7 +1231,9 @@ discard block  | 
                                                    ||
| 1045 | 1231 | }  | 
                                                        
| 1046 | 1232 |  	public function getStatsPilot($pilot,$filter_name = '') { | 
                                                        
| 1047 | 1233 | global $globalArchiveMonths, $globalDBdriver;  | 
                                                        
| 1048 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1234 | +		if ($filter_name == '') { | 
                                                        |
| 1235 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1236 | + }  | 
                                                        |
| 1049 | 1237 | $query = "SELECT cnt FROM stats_pilot WHERE filter_name = :filter_name AND (pilot_name = :pilot OR pilot_id = :pilot)";  | 
                                                        
| 1050 | 1238 |                   try { | 
                                                        
| 1051 | 1239 | $sth = $this->db->prepare($query);  | 
                                                        
@@ -1054,13 +1242,18 @@ discard block  | 
                                                    ||
| 1054 | 1242 | echo "error : ".$e->getMessage();  | 
                                                        
| 1055 | 1243 | }  | 
                                                        
| 1056 | 1244 | $all = $sth->fetchAll(PDO::FETCH_ASSOC);  | 
                                                        
| 1057 | - if (isset($all[0]['cnt'])) return $all[0]['cnt'];  | 
                                                        |
| 1058 | - else return 0;  | 
                                                        |
| 1245 | +                if (isset($all[0]['cnt'])) { | 
                                                        |
| 1246 | + return $all[0]['cnt'];  | 
                                                        |
| 1247 | +                } else { | 
                                                        |
| 1248 | + return 0;  | 
                                                        |
| 1249 | + }  | 
                                                        |
| 1059 | 1250 | }  | 
                                                        
| 1060 | 1251 | |
| 1061 | 1252 |  	public function addStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') { | 
                                                        
| 1062 | 1253 | global $globalDBdriver;  | 
                                                        
| 1063 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1254 | +		if ($filter_name == '') { | 
                                                        |
| 1255 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1256 | + }  | 
                                                        |
| 1064 | 1257 |  		if ($globalDBdriver == 'mysql') { | 
                                                        
| 1065 | 1258 | $query = "INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) VALUES (:type,:cnt,:stats_date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt";  | 
                                                        
| 1066 | 1259 |                  } else { | 
                                                        
@@ -1076,7 +1269,9 @@ discard block  | 
                                                    ||
| 1076 | 1269 | }  | 
                                                        
| 1077 | 1270 |  	public function updateStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') { | 
                                                        
| 1078 | 1271 | global $globalDBdriver;  | 
                                                        
| 1079 | - if ($filter_name == '') $filter_name = $this->filter_name;  | 
                                                        |
| 1272 | +		if ($filter_name == '') { | 
                                                        |
| 1273 | + $filter_name = $this->filter_name;  | 
                                                        |
| 1274 | + }  | 
                                                        |
| 1080 | 1275 |  		if ($globalDBdriver == 'mysql') { | 
                                                        
| 1081 | 1276 | $query = "INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) VALUES (:type,:cnt,:stats_date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date";  | 
                                                        
| 1082 | 1277 |  		} else { | 
                                                        
@@ -1462,10 +1657,14 @@ discard block  | 
                                                    ||
| 1462 | 1657 | $Connection = new Connection();  | 
                                                        
| 1463 | 1658 |      		date_default_timezone_set('UTC'); | 
                                                        
| 1464 | 1659 |      		$last_update = $this->getLastStatsUpdate('last_update_stats'); | 
                                                        
| 1465 | - if ($globalDebug) echo 'Update stats !'."\n";  | 
                                                        |
| 1660 | +			if ($globalDebug) { | 
                                                        |
| 1661 | + echo 'Update stats !'."\n";  | 
                                                        |
| 1662 | + }  | 
                                                        |
| 1466 | 1663 |  			if (isset($last_update[0]['value'])) { | 
                                                        
| 1467 | 1664 | $last_update_day = $last_update[0]['value'];  | 
                                                        
| 1468 | - } else $last_update_day = '2012-12-12 12:12:12';  | 
                                                        |
| 1665 | +			} else { | 
                                                        |
| 1666 | + $last_update_day = '2012-12-12 12:12:12';  | 
                                                        |
| 1667 | + }  | 
                                                        |
| 1469 | 1668 | $reset = false;  | 
                                                        
| 1470 | 1669 |  			//if ($globalStatsResetYear && date('Y',strtotime($last_update_day)) != date('Y')) { | 
                                                        
| 1471 | 1670 |  			if ($globalStatsResetYear) { | 
                                                        
@@ -1474,42 +1673,60 @@ discard block  | 
                                                    ||
| 1474 | 1673 | }  | 
                                                        
| 1475 | 1674 | $Spotter = new Spotter($this->db);  | 
                                                        
| 1476 | 1675 | |
| 1477 | - if ($globalDebug) echo 'Count all aircraft types...'."\n";  | 
                                                        |
| 1676 | +			if ($globalDebug) { | 
                                                        |
| 1677 | + echo 'Count all aircraft types...'."\n";  | 
                                                        |
| 1678 | + }  | 
                                                        |
| 1478 | 1679 | $alldata = $Spotter->countAllAircraftTypes(false,0,$last_update_day);  | 
                                                        
| 1479 | 1680 |  			foreach ($alldata as $number) { | 
                                                        
| 1480 | 1681 | $this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer'],'','',$reset);  | 
                                                        
| 1481 | 1682 | }  | 
                                                        
| 1482 | - if ($globalDebug) echo 'Count all airlines...'."\n";  | 
                                                        |
| 1683 | +			if ($globalDebug) { | 
                                                        |
| 1684 | + echo 'Count all airlines...'."\n";  | 
                                                        |
| 1685 | + }  | 
                                                        |
| 1483 | 1686 | $alldata = $Spotter->countAllAirlines(false,0,$last_update_day);  | 
                                                        
| 1484 | 1687 |  			foreach ($alldata as $number) { | 
                                                        
| 1485 | 1688 | $this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name'],'',$reset);  | 
                                                        
| 1486 | 1689 | }  | 
                                                        
| 1487 | - if ($globalDebug) echo 'Count all registrations...'."\n";  | 
                                                        |
| 1690 | +			if ($globalDebug) { | 
                                                        |
| 1691 | + echo 'Count all registrations...'."\n";  | 
                                                        |
| 1692 | + }  | 
                                                        |
| 1488 | 1693 | $alldata = $Spotter->countAllAircraftRegistrations(false,0,$last_update_day);  | 
                                                        
| 1489 | 1694 |  			foreach ($alldata as $number) { | 
                                                        
| 1490 | 1695 | $this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao'],'','',$reset);  | 
                                                        
| 1491 | 1696 | }  | 
                                                        
| 1492 | - if ($globalDebug) echo 'Count all callsigns...'."\n";  | 
                                                        |
| 1697 | +			if ($globalDebug) { | 
                                                        |
| 1698 | + echo 'Count all callsigns...'."\n";  | 
                                                        |
| 1699 | + }  | 
                                                        |
| 1493 | 1700 | $alldata = $Spotter->countAllCallsigns(false,0,$last_update_day);  | 
                                                        
| 1494 | 1701 |  			foreach ($alldata as $number) { | 
                                                        
| 1495 | 1702 | $this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao'],'',$reset);  | 
                                                        
| 1496 | 1703 | }  | 
                                                        
| 1497 | - if ($globalDebug) echo 'Count all owners...'."\n";  | 
                                                        |
| 1704 | +			if ($globalDebug) { | 
                                                        |
| 1705 | + echo 'Count all owners...'."\n";  | 
                                                        |
| 1706 | + }  | 
                                                        |
| 1498 | 1707 | $alldata = $Spotter->countAllOwners(false,0,$last_update_day);  | 
                                                        
| 1499 | 1708 |  			foreach ($alldata as $number) { | 
                                                        
| 1500 | 1709 | $this->addStatOwner($number['owner_name'],$number['owner_count'],'','',$reset);  | 
                                                        
| 1501 | 1710 | }  | 
                                                        
| 1502 | - if ($globalDebug) echo 'Count all pilots...'."\n";  | 
                                                        |
| 1711 | +			if ($globalDebug) { | 
                                                        |
| 1712 | + echo 'Count all pilots...'."\n";  | 
                                                        |
| 1713 | + }  | 
                                                        |
| 1503 | 1714 | $alldata = $Spotter->countAllPilots(false,0,$last_update_day);  | 
                                                        
| 1504 | 1715 |  			foreach ($alldata as $number) { | 
                                                        
| 1505 | 1716 | $this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name'],'','',$number['format_source'],$reset);  | 
                                                        
| 1506 | 1717 | }  | 
                                                        
| 1507 | 1718 | |
| 1508 | - if ($globalDebug) echo 'Count all departure airports...'."\n";  | 
                                                        |
| 1719 | +			if ($globalDebug) { | 
                                                        |
| 1720 | + echo 'Count all departure airports...'."\n";  | 
                                                        |
| 1721 | + }  | 
                                                        |
| 1509 | 1722 | $pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day);  | 
                                                        
| 1510 | - if ($globalDebug) echo 'Count all detected departure airports...'."\n";  | 
                                                        |
| 1723 | +			if ($globalDebug) { | 
                                                        |
| 1724 | + echo 'Count all detected departure airports...'."\n";  | 
                                                        |
| 1725 | + }  | 
                                                        |
| 1511 | 1726 | $dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day);  | 
                                                        
| 1512 | - if ($globalDebug) echo 'Order departure airports...'."\n";  | 
                                                        |
| 1727 | +			if ($globalDebug) { | 
                                                        |
| 1728 | + echo 'Order departure airports...'."\n";  | 
                                                        |
| 1729 | + }  | 
                                                        |
| 1513 | 1730 | $alldata = array();  | 
                                                        
| 1514 | 1731 | |
| 1515 | 1732 |      			foreach ($pall as $value) { | 
                                                        
@@ -1520,7 +1737,9 @@ discard block  | 
                                                    ||
| 1520 | 1737 | $icao = $value['airport_departure_icao'];  | 
                                                        
| 1521 | 1738 |          			if (isset($alldata[$icao])) { | 
                                                        
| 1522 | 1739 | $alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];  | 
                                                        
| 1523 | - } else $alldata[$icao] = $value;  | 
                                                        |
| 1740 | +        			} else { | 
                                                        |
| 1741 | + $alldata[$icao] = $value;  | 
                                                        |
| 1742 | + }  | 
                                                        |
| 1524 | 1743 | }  | 
                                                        
| 1525 | 1744 | $count = array();  | 
                                                        
| 1526 | 1745 |      			foreach ($alldata as $key => $row) { | 
                                                        
@@ -1530,11 +1749,17 @@ discard block  | 
                                                    ||
| 1530 | 1749 |  			foreach ($alldata as $number) { | 
                                                        
| 1531 | 1750 | echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],'','',$reset);  | 
                                                        
| 1532 | 1751 | }  | 
                                                        
| 1533 | - if ($globalDebug) echo 'Count all arrival airports...'."\n";  | 
                                                        |
| 1752 | +			if ($globalDebug) { | 
                                                        |
| 1753 | + echo 'Count all arrival airports...'."\n";  | 
                                                        |
| 1754 | + }  | 
                                                        |
| 1534 | 1755 | $pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day);  | 
                                                        
| 1535 | - if ($globalDebug) echo 'Count all detected arrival airports...'."\n";  | 
                                                        |
| 1756 | +			if ($globalDebug) { | 
                                                        |
| 1757 | + echo 'Count all detected arrival airports...'."\n";  | 
                                                        |
| 1758 | + }  | 
                                                        |
| 1536 | 1759 | $dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day);  | 
                                                        
| 1537 | - if ($globalDebug) echo 'Order arrival airports...'."\n";  | 
                                                        |
| 1760 | +			if ($globalDebug) { | 
                                                        |
| 1761 | + echo 'Order arrival airports...'."\n";  | 
                                                        |
| 1762 | + }  | 
                                                        |
| 1538 | 1763 | $alldata = array();  | 
                                                        
| 1539 | 1764 |      			foreach ($pall as $value) { | 
                                                        
| 1540 | 1765 | $icao = $value['airport_arrival_icao'];  | 
                                                        
@@ -1544,7 +1769,9 @@ discard block  | 
                                                    ||
| 1544 | 1769 | $icao = $value['airport_arrival_icao'];  | 
                                                        
| 1545 | 1770 |          			if (isset($alldata[$icao])) { | 
                                                        
| 1546 | 1771 | $alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];  | 
                                                        
| 1547 | - } else $alldata[$icao] = $value;  | 
                                                        |
| 1772 | +	        		} else { | 
                                                        |
| 1773 | + $alldata[$icao] = $value;  | 
                                                        |
| 1774 | + }  | 
                                                        |
| 1548 | 1775 | }  | 
                                                        
| 1549 | 1776 | $count = array();  | 
                                                        
| 1550 | 1777 |          		foreach ($alldata as $key => $row) { | 
                                                        
@@ -1555,7 +1782,9 @@ discard block  | 
                                                    ||
| 1555 | 1782 | echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],'','',$reset);  | 
                                                        
| 1556 | 1783 | }  | 
                                                        
| 1557 | 1784 |  			if ($Connection->tableExists('countries')) { | 
                                                        
| 1558 | - if ($globalDebug) echo 'Count all flights by countries...'."\n";  | 
                                                        |
| 1785 | +				if ($globalDebug) { | 
                                                        |
| 1786 | + echo 'Count all flights by countries...'."\n";  | 
                                                        |
| 1787 | + }  | 
                                                        |
| 1559 | 1788 | $SpotterArchive = new SpotterArchive();  | 
                                                        
| 1560 | 1789 | $alldata = $SpotterArchive->countAllFlightOverCountries(false,0,$last_update_day);  | 
                                                        
| 1561 | 1790 |  				foreach ($alldata as $number) { | 
                                                        
@@ -1567,46 +1796,66 @@ discard block  | 
                                                    ||
| 1567 | 1796 | // Add by month using getstat if month finish...  | 
                                                        
| 1568 | 1797 | |
| 1569 | 1798 |  			//if (date('m',strtotime($last_update_day)) != date('m')) { | 
                                                        
| 1570 | - if ($globalDebug) echo 'Count all flights by months...'."\n";  | 
                                                        |
| 1799 | +			if ($globalDebug) { | 
                                                        |
| 1800 | + echo 'Count all flights by months...'."\n";  | 
                                                        |
| 1801 | + }  | 
                                                        |
| 1571 | 1802 | $Spotter = new Spotter($this->db);  | 
                                                        
| 1572 | 1803 | $alldata = $Spotter->countAllMonths();  | 
                                                        
| 1573 | 1804 | $lastyear = false;  | 
                                                        
| 1574 | 1805 |  			foreach ($alldata as $number) { | 
                                                        
| 1575 | -				if ($number['year_name'] != date('Y')) $lastyear = true; | 
                                                        |
| 1806 | +				if ($number['year_name'] != date('Y')) { | 
                                                        |
| 1807 | + $lastyear = true;  | 
                                                        |
| 1808 | + }  | 
                                                        |
| 1576 | 1809 |  				$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); | 
                                                        
| 1577 | 1810 | }  | 
                                                        
| 1578 | - if ($globalDebug) echo 'Count all military flights by months...'."\n";  | 
                                                        |
| 1811 | +			if ($globalDebug) { | 
                                                        |
| 1812 | + echo 'Count all military flights by months...'."\n";  | 
                                                        |
| 1813 | + }  | 
                                                        |
| 1579 | 1814 | $alldata = $Spotter->countAllMilitaryMonths();  | 
                                                        
| 1580 | 1815 |  			foreach ($alldata as $number) { | 
                                                        
| 1581 | 1816 |  				$this->addStat('military_flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); | 
                                                        
| 1582 | 1817 | }  | 
                                                        
| 1583 | - if ($globalDebug) echo 'Count all owners by months...'."\n";  | 
                                                        |
| 1818 | +			if ($globalDebug) { | 
                                                        |
| 1819 | + echo 'Count all owners by months...'."\n";  | 
                                                        |
| 1820 | + }  | 
                                                        |
| 1584 | 1821 | $alldata = $Spotter->countAllMonthsOwners();  | 
                                                        
| 1585 | 1822 |  			foreach ($alldata as $number) { | 
                                                        
| 1586 | 1823 |  				$this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); | 
                                                        
| 1587 | 1824 | }  | 
                                                        
| 1588 | - if ($globalDebug) echo 'Count all pilots by months...'."\n";  | 
                                                        |
| 1825 | +			if ($globalDebug) { | 
                                                        |
| 1826 | + echo 'Count all pilots by months...'."\n";  | 
                                                        |
| 1827 | + }  | 
                                                        |
| 1589 | 1828 | $alldata = $Spotter->countAllMonthsPilots();  | 
                                                        
| 1590 | 1829 |  			foreach ($alldata as $number) { | 
                                                        
| 1591 | 1830 |  				$this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); | 
                                                        
| 1592 | 1831 | }  | 
                                                        
| 1593 | - if ($globalDebug) echo 'Count all airlines by months...'."\n";  | 
                                                        |
| 1832 | +			if ($globalDebug) { | 
                                                        |
| 1833 | + echo 'Count all airlines by months...'."\n";  | 
                                                        |
| 1834 | + }  | 
                                                        |
| 1594 | 1835 | $alldata = $Spotter->countAllMonthsAirlines();  | 
                                                        
| 1595 | 1836 |  			foreach ($alldata as $number) { | 
                                                        
| 1596 | 1837 |  				$this->addStat('airlines_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); | 
                                                        
| 1597 | 1838 | }  | 
                                                        
| 1598 | - if ($globalDebug) echo 'Count all aircrafts by months...'."\n";  | 
                                                        |
| 1839 | +			if ($globalDebug) { | 
                                                        |
| 1840 | + echo 'Count all aircrafts by months...'."\n";  | 
                                                        |
| 1841 | + }  | 
                                                        |
| 1599 | 1842 | $alldata = $Spotter->countAllMonthsAircrafts();  | 
                                                        
| 1600 | 1843 |  			foreach ($alldata as $number) { | 
                                                        
| 1601 | 1844 |  				$this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); | 
                                                        
| 1602 | 1845 | }  | 
                                                        
| 1603 | - if ($globalDebug) echo 'Count all real arrivals by months...'."\n";  | 
                                                        |
| 1846 | +			if ($globalDebug) { | 
                                                        |
| 1847 | + echo 'Count all real arrivals by months...'."\n";  | 
                                                        |
| 1848 | + }  | 
                                                        |
| 1604 | 1849 | $alldata = $Spotter->countAllMonthsRealArrivals();  | 
                                                        
| 1605 | 1850 |  			foreach ($alldata as $number) { | 
                                                        
| 1606 | 1851 |  				$this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); | 
                                                        
| 1607 | 1852 | }  | 
                                                        
| 1608 | - if ($globalDebug) echo 'Airports data...'."\n";  | 
                                                        |
| 1609 | - if ($globalDebug) echo '...Departure'."\n";  | 
                                                        |
| 1853 | +			if ($globalDebug) { | 
                                                        |
| 1854 | + echo 'Airports data...'."\n";  | 
                                                        |
| 1855 | + }  | 
                                                        |
| 1856 | +			if ($globalDebug) { | 
                                                        |
| 1857 | + echo '...Departure'."\n";  | 
                                                        |
| 1858 | + }  | 
                                                        |
| 1610 | 1859 |  			$this->deleteStatAirport('daily'); | 
                                                        
| 1611 | 1860 | // $pall = $Spotter->getLast7DaysAirportsDeparture();  | 
                                                        
| 1612 | 1861 | // $dall = $Spotter->getLast7DaysDetectedAirportsDeparture();  | 
                                                        
@@ -1727,44 +1976,62 @@ discard block  | 
                                                    ||
| 1727 | 1976 | // Count by airlines  | 
                                                        
| 1728 | 1977 | echo '--- Stats by airlines ---'."\n";  | 
                                                        
| 1729 | 1978 |  			if ($Connection->tableExists('countries')) { | 
                                                        
| 1730 | - if ($globalDebug) echo 'Count all flights by countries by airlines...'."\n";  | 
                                                        |
| 1979 | +				if ($globalDebug) { | 
                                                        |
| 1980 | + echo 'Count all flights by countries by airlines...'."\n";  | 
                                                        |
| 1981 | + }  | 
                                                        |
| 1731 | 1982 | $SpotterArchive = new SpotterArchive();  | 
                                                        
| 1732 | 1983 | $alldata = $SpotterArchive->countAllFlightOverCountriesByAirlines(false,0,$last_update_day);  | 
                                                        
| 1733 | 1984 |  				foreach ($alldata as $number) { | 
                                                        
| 1734 | 1985 | $this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count'],$number['airline_icao'],'',$reset);  | 
                                                        
| 1735 | 1986 | }  | 
                                                        
| 1736 | 1987 | }  | 
                                                        
| 1737 | - if ($globalDebug) echo 'Count all aircraft types by airlines...'."\n";  | 
                                                        |
| 1988 | +			if ($globalDebug) { | 
                                                        |
| 1989 | + echo 'Count all aircraft types by airlines...'."\n";  | 
                                                        |
| 1990 | + }  | 
                                                        |
| 1738 | 1991 | $Spotter = new Spotter($this->db);  | 
                                                        
| 1739 | 1992 | $alldata = $Spotter->countAllAircraftTypesByAirlines(false,0,$last_update_day);  | 
                                                        
| 1740 | 1993 |  			foreach ($alldata as $number) { | 
                                                        
| 1741 | 1994 | $this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer'],$number['airline_icao'],'',$reset);  | 
                                                        
| 1742 | 1995 | }  | 
                                                        
| 1743 | - if ($globalDebug) echo 'Count all aircraft registrations by airlines...'."\n";  | 
                                                        |
| 1996 | +			if ($globalDebug) { | 
                                                        |
| 1997 | + echo 'Count all aircraft registrations by airlines...'."\n";  | 
                                                        |
| 1998 | + }  | 
                                                        |
| 1744 | 1999 | $alldata = $Spotter->countAllAircraftRegistrationsByAirlines(false,0,$last_update_day);  | 
                                                        
| 1745 | 2000 |  			foreach ($alldata as $number) { | 
                                                        
| 1746 | 2001 | $this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao'],$number['airline_icao'],'',$reset);  | 
                                                        
| 1747 | 2002 | }  | 
                                                        
| 1748 | - if ($globalDebug) echo 'Count all callsigns by airlines...'."\n";  | 
                                                        |
| 2003 | +			if ($globalDebug) { | 
                                                        |
| 2004 | + echo 'Count all callsigns by airlines...'."\n";  | 
                                                        |
| 2005 | + }  | 
                                                        |
| 1749 | 2006 | $alldata = $Spotter->countAllCallsignsByAirlines(false,0,$last_update_day);  | 
                                                        
| 1750 | 2007 |  			foreach ($alldata as $number) { | 
                                                        
| 1751 | 2008 | $this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao'],'',$reset);  | 
                                                        
| 1752 | 2009 | }  | 
                                                        
| 1753 | - if ($globalDebug) echo 'Count all owners by airlines...'."\n";  | 
                                                        |
| 2010 | +			if ($globalDebug) { | 
                                                        |
| 2011 | + echo 'Count all owners by airlines...'."\n";  | 
                                                        |
| 2012 | + }  | 
                                                        |
| 1754 | 2013 | $alldata = $Spotter->countAllOwnersByAirlines(false,0,$last_update_day);  | 
                                                        
| 1755 | 2014 |  			foreach ($alldata as $number) { | 
                                                        
| 1756 | 2015 | $this->addStatOwner($number['owner_name'],$number['owner_count'],$number['airline_icao'],'',$reset);  | 
                                                        
| 1757 | 2016 | }  | 
                                                        
| 1758 | - if ($globalDebug) echo 'Count all pilots by airlines...'."\n";  | 
                                                        |
| 2017 | +			if ($globalDebug) { | 
                                                        |
| 2018 | + echo 'Count all pilots by airlines...'."\n";  | 
                                                        |
| 2019 | + }  | 
                                                        |
| 1759 | 2020 | $alldata = $Spotter->countAllPilotsByAirlines(false,0,$last_update_day);  | 
                                                        
| 1760 | 2021 |  			foreach ($alldata as $number) { | 
                                                        
| 1761 | 2022 | $this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name'],$number['airline_icao'],'',$number['format_source'],$reset);  | 
                                                        
| 1762 | 2023 | }  | 
                                                        
| 1763 | - if ($globalDebug) echo 'Count all departure airports by airlines...'."\n";  | 
                                                        |
| 2024 | +			if ($globalDebug) { | 
                                                        |
| 2025 | + echo 'Count all departure airports by airlines...'."\n";  | 
                                                        |
| 2026 | + }  | 
                                                        |
| 1764 | 2027 | $pall = $Spotter->countAllDepartureAirportsByAirlines(false,0,$last_update_day);  | 
                                                        
| 1765 | - if ($globalDebug) echo 'Count all detected departure airports by airlines...'."\n";  | 
                                                        |
| 2028 | +			if ($globalDebug) { | 
                                                        |
| 2029 | + echo 'Count all detected departure airports by airlines...'."\n";  | 
                                                        |
| 2030 | + }  | 
                                                        |
| 1766 | 2031 | $dall = $Spotter->countAllDetectedDepartureAirportsByAirlines(false,0,$last_update_day);  | 
                                                        
| 1767 | - if ($globalDebug) echo 'Order detected departure airports by airlines...'."\n";  | 
                                                        |
| 2032 | +			if ($globalDebug) { | 
                                                        |
| 2033 | + echo 'Order detected departure airports by airlines...'."\n";  | 
                                                        |
| 2034 | + }  | 
                                                        |
| 1768 | 2035 | //$alldata = array();  | 
                                                        
| 1769 | 2036 |      			foreach ($dall as $value) { | 
                                                        
| 1770 | 2037 | $icao = $value['airport_departure_icao'];  | 
                                                        
@@ -1785,11 +2052,17 @@ discard block  | 
                                                    ||
| 1785 | 2052 |  			foreach ($alldata as $number) { | 
                                                        
| 1786 | 2053 | echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],$number['airline_icao'],'',$reset);  | 
                                                        
| 1787 | 2054 | }  | 
                                                        
| 1788 | - if ($globalDebug) echo 'Count all arrival airports by airlines...'."\n";  | 
                                                        |
| 2055 | +			if ($globalDebug) { | 
                                                        |
| 2056 | + echo 'Count all arrival airports by airlines...'."\n";  | 
                                                        |
| 2057 | + }  | 
                                                        |
| 1789 | 2058 | $pall = $Spotter->countAllArrivalAirportsByAirlines(false,0,$last_update_day);  | 
                                                        
| 1790 | - if ($globalDebug) echo 'Count all detected arrival airports by airlines...'."\n";  | 
                                                        |
| 2059 | +			if ($globalDebug) { | 
                                                        |
| 2060 | + echo 'Count all detected arrival airports by airlines...'."\n";  | 
                                                        |
| 2061 | + }  | 
                                                        |
| 1791 | 2062 | $dall = $Spotter->countAllDetectedArrivalAirportsByAirlines(false,0,$last_update_day);  | 
                                                        
| 1792 | - if ($globalDebug) echo 'Order arrival airports by airlines...'."\n";  | 
                                                        |
| 2063 | +			if ($globalDebug) { | 
                                                        |
| 2064 | + echo 'Order arrival airports by airlines...'."\n";  | 
                                                        |
| 2065 | + }  | 
                                                        |
| 1793 | 2066 | //$alldata = array();  | 
                                                        
| 1794 | 2067 |      			foreach ($dall as $value) { | 
                                                        
| 1795 | 2068 | $icao = $value['airport_arrival_icao'];  | 
                                                        
@@ -1808,37 +2081,53 @@ discard block  | 
                                                    ||
| 1808 | 2081 | }  | 
                                                        
| 1809 | 2082 | $alldata = $pall;  | 
                                                        
| 1810 | 2083 |                          foreach ($alldata as $number) { | 
                                                        
| 1811 | - if ($number['airline_icao'] != '') echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],$number['airline_icao'],'',$reset);  | 
                                                        |
| 2084 | +				if ($number['airline_icao'] != '') { | 
                                                        |
| 2085 | + echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],$number['airline_icao'],'',$reset);  | 
                                                        |
| 2086 | + }  | 
                                                        |
| 2087 | + }  | 
                                                        |
| 2088 | +			if ($globalDebug) { | 
                                                        |
| 2089 | + echo 'Count all flights by months by airlines...'."\n";  | 
                                                        |
| 1812 | 2090 | }  | 
                                                        
| 1813 | - if ($globalDebug) echo 'Count all flights by months by airlines...'."\n";  | 
                                                        |
| 1814 | 2091 | $Spotter = new Spotter($this->db);  | 
                                                        
| 1815 | 2092 | $alldata = $Spotter->countAllMonthsByAirlines();  | 
                                                        
| 1816 | 2093 | $lastyear = false;  | 
                                                        
| 1817 | 2094 |  			foreach ($alldata as $number) { | 
                                                        
| 1818 | -				if ($number['year_name'] != date('Y')) $lastyear = true; | 
                                                        |
| 2095 | +				if ($number['year_name'] != date('Y')) { | 
                                                        |
| 2096 | + $lastyear = true;  | 
                                                        |
| 2097 | + }  | 
                                                        |
| 1819 | 2098 |  				$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); | 
                                                        
| 1820 | 2099 | }  | 
                                                        
| 1821 | - if ($globalDebug) echo 'Count all owners by months by airlines...'."\n";  | 
                                                        |
| 2100 | +			if ($globalDebug) { | 
                                                        |
| 2101 | + echo 'Count all owners by months by airlines...'."\n";  | 
                                                        |
| 2102 | + }  | 
                                                        |
| 1822 | 2103 | $alldata = $Spotter->countAllMonthsOwnersByAirlines();  | 
                                                        
| 1823 | 2104 |  			foreach ($alldata as $number) { | 
                                                        
| 1824 | 2105 |  				$this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); | 
                                                        
| 1825 | 2106 | }  | 
                                                        
| 1826 | - if ($globalDebug) echo 'Count all pilots by months by airlines...'."\n";  | 
                                                        |
| 2107 | +			if ($globalDebug) { | 
                                                        |
| 2108 | + echo 'Count all pilots by months by airlines...'."\n";  | 
                                                        |
| 2109 | + }  | 
                                                        |
| 1827 | 2110 | $alldata = $Spotter->countAllMonthsPilotsByAirlines();  | 
                                                        
| 1828 | 2111 |  			foreach ($alldata as $number) { | 
                                                        
| 1829 | 2112 |  				$this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); | 
                                                        
| 1830 | 2113 | }  | 
                                                        
| 1831 | - if ($globalDebug) echo 'Count all aircrafts by months by airlines...'."\n";  | 
                                                        |
| 2114 | +			if ($globalDebug) { | 
                                                        |
| 2115 | + echo 'Count all aircrafts by months by airlines...'."\n";  | 
                                                        |
| 2116 | + }  | 
                                                        |
| 1832 | 2117 | $alldata = $Spotter->countAllMonthsAircraftsByAirlines();  | 
                                                        
| 1833 | 2118 |  			foreach ($alldata as $number) { | 
                                                        
| 1834 | 2119 |  				$this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); | 
                                                        
| 1835 | 2120 | }  | 
                                                        
| 1836 | - if ($globalDebug) echo 'Count all real arrivals by months by airlines...'."\n";  | 
                                                        |
| 2121 | +			if ($globalDebug) { | 
                                                        |
| 2122 | + echo 'Count all real arrivals by months by airlines...'."\n";  | 
                                                        |
| 2123 | + }  | 
                                                        |
| 1837 | 2124 | $alldata = $Spotter->countAllMonthsRealArrivalsByAirlines();  | 
                                                        
| 1838 | 2125 |  			foreach ($alldata as $number) { | 
                                                        
| 1839 | 2126 |  				$this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); | 
                                                        
| 1840 | 2127 | }  | 
                                                        
| 1841 | - if ($globalDebug) echo '...Departure'."\n";  | 
                                                        |
| 2128 | +			if ($globalDebug) { | 
                                                        |
| 2129 | + echo '...Departure'."\n";  | 
                                                        |
| 2130 | + }  | 
                                                        |
| 1842 | 2131 | $pall = $Spotter->getLast7DaysAirportsDepartureByAirlines();  | 
                                                        
| 1843 | 2132 | $dall = $Spotter->getLast7DaysDetectedAirportsDepartureByAirlines();  | 
                                                        
| 1844 | 2133 |      			foreach ($dall as $value) { | 
                                                        
@@ -1861,7 +2150,9 @@ discard block  | 
                                                    ||
| 1861 | 2150 |  			foreach ($alldata as $number) { | 
                                                        
| 1862 | 2151 | $this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count'],$number['airline_icao']);  | 
                                                        
| 1863 | 2152 | }  | 
                                                        
| 1864 | - if ($globalDebug) echo '...Arrival'."\n";  | 
                                                        |
| 2153 | +			if ($globalDebug) { | 
                                                        |
| 2154 | + echo '...Arrival'."\n";  | 
                                                        |
| 2155 | + }  | 
                                                        |
| 1865 | 2156 | $pall = $Spotter->getLast7DaysAirportsArrivalByAirlines();  | 
                                                        
| 1866 | 2157 | $dall = $Spotter->getLast7DaysDetectedAirportsArrivalByAirlines();  | 
                                                        
| 1867 | 2158 |      			foreach ($dall as $value) { | 
                                                        
@@ -1885,13 +2176,19 @@ discard block  | 
                                                    ||
| 1885 | 2176 | $this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count'],$number['airline_icao']);  | 
                                                        
| 1886 | 2177 | }  | 
                                                        
| 1887 | 2178 | |
| 1888 | - if ($globalDebug) echo 'Flights data...'."\n";  | 
                                                        |
| 1889 | - if ($globalDebug) echo '-> countAllDatesLastMonth...'."\n";  | 
                                                        |
| 2179 | +			if ($globalDebug) { | 
                                                        |
| 2180 | + echo 'Flights data...'."\n";  | 
                                                        |
| 2181 | + }  | 
                                                        |
| 2182 | +			if ($globalDebug) { | 
                                                        |
| 2183 | + echo '-> countAllDatesLastMonth...'."\n";  | 
                                                        |
| 2184 | + }  | 
                                                        |
| 1890 | 2185 | $alldata = $Spotter->countAllDatesLastMonthByAirlines();  | 
                                                        
| 1891 | 2186 |  			foreach ($alldata as $number) { | 
                                                        
| 1892 | 2187 |  				$this->addStatFlight('month',$number['date_name'],$number['date_count'], $number['airline_icao']); | 
                                                        
| 1893 | 2188 | }  | 
                                                        
| 1894 | - if ($globalDebug) echo '-> countAllDates...'."\n";  | 
                                                        |
| 2189 | +			if ($globalDebug) { | 
                                                        |
| 2190 | + echo '-> countAllDates...'."\n";  | 
                                                        |
| 2191 | + }  | 
                                                        |
| 1895 | 2192 | //$previousdata = $this->countAllDatesByAirlines();  | 
                                                        
| 1896 | 2193 | $alldata = $Common->array_merge_noappend($previousdatabyairlines,$Spotter->countAllDatesByAirlines());  | 
                                                        
| 1897 | 2194 | $values = array();  | 
                                                        
@@ -1904,7 +2201,9 @@ discard block  | 
                                                    ||
| 1904 | 2201 |  				$this->addStatFlight('date',$number['date_name'],$number['date_count'],$number['airline_icao']); | 
                                                        
| 1905 | 2202 | }  | 
                                                        
| 1906 | 2203 | |
| 1907 | - if ($globalDebug) echo '-> countAllHours...'."\n";  | 
                                                        |
| 2204 | +			if ($globalDebug) { | 
                                                        |
| 2205 | + echo '-> countAllHours...'."\n";  | 
                                                        |
| 2206 | + }  | 
                                                        |
| 1908 | 2207 |  			$alldata = $Spotter->countAllHoursByAirlines('hour'); | 
                                                        
| 1909 | 2208 |  			foreach ($alldata as $number) { | 
                                                        
| 1910 | 2209 |  				$this->addStatFlight('hour',$number['hour_name'],$number['hour_count'],$number['airline_icao']); | 
                                                        
@@ -1912,14 +2211,18 @@ discard block  | 
                                                    ||
| 1912 | 2211 | |
| 1913 | 2212 | |
| 1914 | 2213 | // Stats by filters  | 
                                                        
| 1915 | - if (!isset($globalStatsFilters) || $globalStatsFilters == '') $globalStatsFilters = array();  | 
                                                        |
| 2214 | +			if (!isset($globalStatsFilters) || $globalStatsFilters == '') { | 
                                                        |
| 2215 | + $globalStatsFilters = array();  | 
                                                        |
| 2216 | + }  | 
                                                        |
| 1916 | 2217 |  			foreach ($globalStatsFilters as $name => $filter) { | 
                                                        
| 1917 | 2218 | //$filter_name = $filter['name'];  | 
                                                        
| 1918 | 2219 | $filter_name = $name;  | 
                                                        
| 1919 | 2220 | $reset = false;  | 
                                                        
| 1920 | 2221 |  				$last_update = $this->getLastStatsUpdate('last_update_stats_'.$filter_name); | 
                                                        
| 1921 | 2222 |  				if (isset($filter['resetall']) && isset($last_update[0]['value']) && strtotime($filter['resetall']) > strtotime($last_update[0]['value'])) { | 
                                                        
| 1922 | - if ($globalDebug) echo '!!! Delete stats for filter '.$filter_name.' !!!'."\n";  | 
                                                        |
| 2223 | +					if ($globalDebug) { | 
                                                        |
| 2224 | + echo '!!! Delete stats for filter '.$filter_name.' !!!'."\n";  | 
                                                        |
| 2225 | + }  | 
                                                        |
| 1923 | 2226 | $this->deleteOldStats($filter_name);  | 
                                                        
| 1924 | 2227 | unset($last_update);  | 
                                                        
| 1925 | 2228 | }  | 
                                                        
@@ -1938,7 +2241,9 @@ discard block  | 
                                                    ||
| 1938 | 2241 | |
| 1939 | 2242 | |
| 1940 | 2243 | // Count by filter  | 
                                                        
| 1941 | - if ($globalDebug) echo '--- Stats for filter '.$filter_name.' ---'."\n";  | 
                                                        |
| 2244 | +				if ($globalDebug) { | 
                                                        |
| 2245 | + echo '--- Stats for filter '.$filter_name.' ---'."\n";  | 
                                                        |
| 2246 | + }  | 
                                                        |
| 1942 | 2247 | $Spotter = new Spotter($this->db);  | 
                                                        
| 1943 | 2248 | $alldata = $Spotter->countAllAircraftTypes(false,0,$last_update_day,$filter);  | 
                                                        
| 1944 | 2249 |  				foreach ($alldata as $number) { | 
                                                        
@@ -1975,7 +2280,9 @@ discard block  | 
                                                    ||
| 1975 | 2280 | $icao = $value['airport_departure_icao'];  | 
                                                        
| 1976 | 2281 |          				if (isset($alldata[$icao])) { | 
                                                        
| 1977 | 2282 | $alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];  | 
                                                        
| 1978 | - } else $alldata[$icao] = $value;  | 
                                                        |
| 2283 | +        				} else { | 
                                                        |
| 2284 | + $alldata[$icao] = $value;  | 
                                                        |
| 2285 | + }  | 
                                                        |
| 1979 | 2286 | }  | 
                                                        
| 1980 | 2287 | $count = array();  | 
                                                        
| 1981 | 2288 |      				foreach ($alldata as $key => $row) { | 
                                                        
@@ -1996,7 +2303,9 @@ discard block  | 
                                                    ||
| 1996 | 2303 | $icao = $value['airport_arrival_icao'];  | 
                                                        
| 1997 | 2304 |          				if (isset($alldata[$icao])) { | 
                                                        
| 1998 | 2305 | $alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];  | 
                                                        
| 1999 | - } else $alldata[$icao] = $value;  | 
                                                        |
| 2306 | +		        		} else { | 
                                                        |
| 2307 | + $alldata[$icao] = $value;  | 
                                                        |
| 2308 | + }  | 
                                                        |
| 2000 | 2309 | }  | 
                                                        
| 2001 | 2310 | $count = array();  | 
                                                        
| 2002 | 2311 |          			foreach ($alldata as $key => $row) { | 
                                                        
@@ -2010,7 +2319,9 @@ discard block  | 
                                                    ||
| 2010 | 2319 | $alldata = $Spotter->countAllMonths($filter);  | 
                                                        
| 2011 | 2320 | $lastyear = false;  | 
                                                        
| 2012 | 2321 |  				foreach ($alldata as $number) { | 
                                                        
| 2013 | -					if ($number['year_name'] != date('Y')) $lastyear = true; | 
                                                        |
| 2322 | +					if ($number['year_name'] != date('Y')) { | 
                                                        |
| 2323 | + $lastyear = true;  | 
                                                        |
| 2324 | + }  | 
                                                        |
| 2014 | 2325 |  					$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); | 
                                                        
| 2015 | 2326 | }  | 
                                                        
| 2016 | 2327 | $alldata = $Spotter->countAllMonthsOwners($filter);  |