Completed
Push — master ( c4688e...41b901 )
by Yannick
06:49
created
scripts/daemon-spotter.php 2 patches
Indentation   +832 added lines, -832 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16 16
 if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
17 17
 if (isset($globalMarine) && $globalMarine) {
18
-    require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
-    require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
18
+	require_once(dirname(__FILE__).'/../require/class.AIS.php');
19
+	require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 20
 }
21 21
 
22 22
 if (!isset($globalDebug)) $globalDebug = FALSE;
@@ -24,52 +24,52 @@  discard block
 block discarded – undo
24 24
 // Check if schema is at latest version
25 25
 $Connection = new Connection();
26 26
 if ($Connection->latest() === false) {
27
-    echo "You MUST update to latest schema. Run install/index.php";
28
-    exit();
27
+	echo "You MUST update to latest schema. Run install/index.php";
28
+	exit();
29 29
 }
30 30
 if (PHP_SAPI != 'cli') {
31
-    echo "This script MUST be called from console, not a web browser.";
31
+	echo "This script MUST be called from console, not a web browser.";
32 32
 //    exit();
33 33
 }
34 34
 
35 35
 // This is to be compatible with old version of settings.php
36 36
 if (!isset($globalSources)) {
37
-    if (isset($globalSBS1Hosts)) {
38
-        //$hosts = $globalSBS1Hosts;
39
-        foreach ($globalSBS1Hosts as $host) {
40
-	    $globalSources[] = array('host' => $host);
41
-    	}
42
-    } else {
43
-        if (!isset($globalSBS1Host)) {
44
-	    echo '$globalSources MUST be defined !';
45
-	    die;
37
+	if (isset($globalSBS1Hosts)) {
38
+		//$hosts = $globalSBS1Hosts;
39
+		foreach ($globalSBS1Hosts as $host) {
40
+		$globalSources[] = array('host' => $host);
41
+		}
42
+	} else {
43
+		if (!isset($globalSBS1Host)) {
44
+		echo '$globalSources MUST be defined !';
45
+		die;
46 46
 	}
47 47
 	//$hosts = array($globalSBS1Host.':'.$globalSBS1Port);
48 48
 	$globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port);
49
-    }
49
+	}
50 50
 }
51 51
 
52 52
 $options = getopt('s::',array('source::','server','idsource::'));
53 53
 //if (isset($options['s'])) $hosts = array($options['s']);
54 54
 //elseif (isset($options['source'])) $hosts = array($options['source']);
55 55
 if (isset($options['s'])) {
56
-    $globalSources = array();
57
-    $globalSources[] = array('host' => $options['s']);
56
+	$globalSources = array();
57
+	$globalSources[] = array('host' => $options['s']);
58 58
 } elseif (isset($options['source'])) {
59
-    $globalSources = array();
60
-    $globalSources[] = array('host' => $options['source']);
59
+	$globalSources = array();
60
+	$globalSources[] = array('host' => $options['source']);
61 61
 }
62 62
 if (isset($options['server'])) $globalServer = TRUE;
63 63
 if (isset($options['idsource'])) $id_source = $options['idsource'];
64 64
 else $id_source = 1;
65 65
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
67
-    $SI=new SpotterServer();
66
+	if ($globalDebug) echo "Using Server Mode\n";
67
+	$SI=new SpotterServer();
68 68
 } else $SI=new SpotterImport($Connection->db);
69 69
 if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
70 70
 if (isset($globalMarine) && $globalMarine) {
71
-    $AIS = new AIS();
72
-    $MI = new MarineImport($Connection->db);
71
+	$AIS = new AIS();
72
+	$MI = new MarineImport($Connection->db);
73 73
 }
74 74
 //$APRS=new APRS($Connection->db);
75 75
 $SBS=new SBS();
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
 //$servertz = system('date +%Z');
80 80
 // signal handler - playing nice with sockets and dump1090
81 81
 if (function_exists('pcntl_fork')) {
82
-    pcntl_signal(SIGINT,  function() {
83
-        global $sockets;
84
-        echo "\n\nctrl-c or kill signal received. Tidying up ... ";
85
-        die("Bye!\n");
86
-    });
87
-    pcntl_signal_dispatch();
82
+	pcntl_signal(SIGINT,  function() {
83
+		global $sockets;
84
+		echo "\n\nctrl-c or kill signal received. Tidying up ... ";
85
+		die("Bye!\n");
86
+	});
87
+	pcntl_signal_dispatch();
88 88
 }
89 89
 
90 90
 // let's try and connect
@@ -94,169 +94,169 @@  discard block
 block discarded – undo
94 94
 $reset = 0;
95 95
 
96 96
 function create_socket($host, $port, &$errno, &$errstr) {
97
-    $ip = gethostbyname($host);
98
-    $s = socket_create(AF_INET, SOCK_STREAM, 0);
99
-    $r = @socket_connect($s, $ip, $port);
100
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
101
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
102
-        return $s;
103
-    }
104
-    $errno = socket_last_error($s);
105
-    $errstr = socket_strerror($errno);
106
-    socket_close($s);
107
-    return false;
97
+	$ip = gethostbyname($host);
98
+	$s = socket_create(AF_INET, SOCK_STREAM, 0);
99
+	$r = @socket_connect($s, $ip, $port);
100
+	if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
101
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
102
+		return $s;
103
+	}
104
+	$errno = socket_last_error($s);
105
+	$errstr = socket_strerror($errno);
106
+	socket_close($s);
107
+	return false;
108 108
 }
109 109
 
110 110
 function create_socket_udp($host, $port, &$errno, &$errstr) {
111
-    echo "Create an UDP socket...\n";
112
-    $ip = gethostbyname($host);
113
-    $s = socket_create(AF_INET, SOCK_DGRAM, 0);
114
-    $r = @socket_bind($s, $ip, $port);
115
-    if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
116
-        return $s;
117
-    }
118
-    $errno = socket_last_error($s);
119
-    $errstr = socket_strerror($errno);
120
-    socket_close($s);
121
-    return false;
111
+	echo "Create an UDP socket...\n";
112
+	$ip = gethostbyname($host);
113
+	$s = socket_create(AF_INET, SOCK_DGRAM, 0);
114
+	$r = @socket_bind($s, $ip, $port);
115
+	if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
116
+		return $s;
117
+	}
118
+	$errno = socket_last_error($s);
119
+	$errstr = socket_strerror($errno);
120
+	socket_close($s);
121
+	return false;
122 122
 }
123 123
 
124 124
 function connect_all($hosts) {
125
-    //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
126
-    global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
127
-    $reset++;
128
-    if ($globalDebug) echo 'Connect to all...'."\n";
129
-    foreach ($hosts as $id => $value) {
125
+	//global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
126
+	global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
127
+	$reset++;
128
+	if ($globalDebug) echo 'Connect to all...'."\n";
129
+	foreach ($hosts as $id => $value) {
130 130
 	$host = $value['host'];
131 131
 	$globalSources[$id]['last_exec'] = 0;
132 132
 	// Here we check type of source(s)
133 133
 	if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) {
134
-            if (preg_match('/deltadb.txt$/i',$host)) {
135
-        	//$formats[$id] = 'deltadbtxt';
136
-        	$globalSources[$id]['format'] = 'deltadbtxt';
137
-        	//$last_exec['deltadbtxt'] = 0;
138
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
139
-            } else if (preg_match('/vatsim-data.txt$/i',$host)) {
140
-        	//$formats[$id] = 'vatsimtxt';
141
-        	$globalSources[$id]['format'] = 'vatsimtxt';
142
-        	//$last_exec['vatsimtxt'] = 0;
143
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
144
-    	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
145
-        	//$formats[$id] = 'aircraftlistjson';
146
-        	$globalSources[$id]['format'] = 'aircraftlistjson';
147
-        	//$last_exec['aircraftlistjson'] = 0;
148
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
149
-    	    } else if (preg_match('/opensky/i',$host)) {
150
-        	//$formats[$id] = 'aircraftlistjson';
151
-        	$globalSources[$id]['format'] = 'opensky';
152
-        	//$last_exec['aircraftlistjson'] = 0;
153
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
154
-    	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
155
-        	//$formats[$id] = 'radarvirtueljson';
156
-        	$globalSources[$id]['format'] = 'radarvirtueljson';
157
-        	//$last_exec['radarvirtueljson'] = 0;
158
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
159
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
160
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
161
-        	    exit(0);
162
-        	}
163
-    	    } else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
164
-        	//$formats[$id] = 'planeupdatefaa';
165
-        	$globalSources[$id]['format'] = 'planeupdatefaa';
166
-        	//$last_exec['planeupdatefaa'] = 0;
167
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
168
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
169
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
170
-        	    exit(0);
171
-        	}
172
-            } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
173
-        	//$formats[$id] = 'phpvmacars';
174
-        	$globalSources[$id]['format'] = 'phpvmacars';
175
-        	//$last_exec['phpvmacars'] = 0;
176
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
177
-            } else if (preg_match('/VAM-json.php$/i',$host)) {
178
-        	//$formats[$id] = 'phpvmacars';
179
-        	$globalSources[$id]['format'] = 'vam';
180
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
181
-            } else if (preg_match('/whazzup/i',$host)) {
182
-        	//$formats[$id] = 'whazzup';
183
-        	$globalSources[$id]['format'] = 'whazzup';
184
-        	//$last_exec['whazzup'] = 0;
185
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
186
-            } else if (preg_match('/recentpireps/i',$host)) {
187
-        	//$formats[$id] = 'pirepsjson';
188
-        	$globalSources[$id]['format'] = 'pirepsjson';
189
-        	//$last_exec['pirepsjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
191
-            } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
192
-        	//$formats[$id] = 'fr24json';
193
-        	$globalSources[$id]['format'] = 'fr24json';
194
-        	//$last_exec['fr24json'] = 0;
195
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
196
-        	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
197
-        	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
198
-        	    exit(0);
199
-        	}
200
-            //} else if (preg_match('/10001/',$host)) {
201
-            } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
202
-        	//$formats[$id] = 'tsv';
203
-        	$globalSources[$id]['format'] = 'tsv';
204
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
205
-            }
206
-        } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
207
-    		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
208
-    		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
209
-    		    if ($idf !== false) {
210
-    			$httpfeeds[$id] = $idf;
211
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
212
-    		    }
213
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
214
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
215
-        } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
216
-	    $hostport = explode(':',$host);
217
-	    if (isset($hostport[1])) {
134
+			if (preg_match('/deltadb.txt$/i',$host)) {
135
+			//$formats[$id] = 'deltadbtxt';
136
+			$globalSources[$id]['format'] = 'deltadbtxt';
137
+			//$last_exec['deltadbtxt'] = 0;
138
+			if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
139
+			} else if (preg_match('/vatsim-data.txt$/i',$host)) {
140
+			//$formats[$id] = 'vatsimtxt';
141
+			$globalSources[$id]['format'] = 'vatsimtxt';
142
+			//$last_exec['vatsimtxt'] = 0;
143
+			if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
144
+			} else if (preg_match('/aircraftlist.json$/i',$host)) {
145
+			//$formats[$id] = 'aircraftlistjson';
146
+			$globalSources[$id]['format'] = 'aircraftlistjson';
147
+			//$last_exec['aircraftlistjson'] = 0;
148
+			if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
149
+			} else if (preg_match('/opensky/i',$host)) {
150
+			//$formats[$id] = 'aircraftlistjson';
151
+			$globalSources[$id]['format'] = 'opensky';
152
+			//$last_exec['aircraftlistjson'] = 0;
153
+			if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
154
+			} else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
155
+			//$formats[$id] = 'radarvirtueljson';
156
+			$globalSources[$id]['format'] = 'radarvirtueljson';
157
+			//$last_exec['radarvirtueljson'] = 0;
158
+			if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
159
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
160
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
161
+				exit(0);
162
+			}
163
+			} else if (preg_match('/planeUpdateFAA.php$/i',$host)) {
164
+			//$formats[$id] = 'planeupdatefaa';
165
+			$globalSources[$id]['format'] = 'planeupdatefaa';
166
+			//$last_exec['planeupdatefaa'] = 0;
167
+			if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
168
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
169
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
170
+				exit(0);
171
+			}
172
+			} else if (preg_match('/\/action.php\/acars\/data$/i',$host)) {
173
+			//$formats[$id] = 'phpvmacars';
174
+			$globalSources[$id]['format'] = 'phpvmacars';
175
+			//$last_exec['phpvmacars'] = 0;
176
+			if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
177
+			} else if (preg_match('/VAM-json.php$/i',$host)) {
178
+			//$formats[$id] = 'phpvmacars';
179
+			$globalSources[$id]['format'] = 'vam';
180
+			if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
181
+			} else if (preg_match('/whazzup/i',$host)) {
182
+			//$formats[$id] = 'whazzup';
183
+			$globalSources[$id]['format'] = 'whazzup';
184
+			//$last_exec['whazzup'] = 0;
185
+			if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
186
+			} else if (preg_match('/recentpireps/i',$host)) {
187
+			//$formats[$id] = 'pirepsjson';
188
+			$globalSources[$id]['format'] = 'pirepsjson';
189
+			//$last_exec['pirepsjson'] = 0;
190
+			if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
191
+			} else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
192
+			//$formats[$id] = 'fr24json';
193
+			$globalSources[$id]['format'] = 'fr24json';
194
+			//$last_exec['fr24json'] = 0;
195
+			if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
196
+			if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
197
+				echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
198
+				exit(0);
199
+			}
200
+			//} else if (preg_match('/10001/',$host)) {
201
+			} else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
202
+			//$formats[$id] = 'tsv';
203
+			$globalSources[$id]['format'] = 'tsv';
204
+			if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
205
+			}
206
+		} elseif (filter_var($host,FILTER_VALIDATE_URL)) {
207
+			if ($globalSources[$id]['format'] == 'aisnmeahttp') {
208
+				$idf = fopen($globalSources[$id]['host'],'r',false,$context);
209
+				if ($idf !== false) {
210
+				$httpfeeds[$id] = $idf;
211
+				if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
212
+				}
213
+				elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
214
+			} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
215
+		} elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
216
+		$hostport = explode(':',$host);
217
+		if (isset($hostport[1])) {
218 218
 		$port = $hostport[1];
219 219
 		$hostn = $hostport[0];
220
-	    } else {
220
+		} else {
221 221
 		$port = $globalSources[$id]['port'];
222 222
 		$hostn = $globalSources[$id]['host'];
223
-	    }
224
-	    if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
225
-        	$s = create_socket($hostn,$port, $errno, $errstr);
226
-    	    } else {
227
-        	$s = create_socket_udp($hostn,$port, $errno, $errstr);
228
-	    }
229
-	    if ($s) {
230
-    	        $sockets[$id] = $s;
231
-    	        if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
232
-		    if (preg_match('/aprs/',$hostn)) {
223
+		}
224
+		if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) {
225
+			$s = create_socket($hostn,$port, $errno, $errstr);
226
+			} else {
227
+			$s = create_socket_udp($hostn,$port, $errno, $errstr);
228
+		}
229
+		if ($s) {
230
+				$sockets[$id] = $s;
231
+				if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') {
232
+			if (preg_match('/aprs/',$hostn)) {
233 233
 			//$formats[$id] = 'aprs';
234 234
 			$globalSources[$id]['format'] = 'aprs';
235 235
 			//$aprs_connect = 0;
236 236
 			//$use_aprs = true;
237
-    		    } elseif ($port == '10001') {
238
-        		//$formats[$id] = 'tsv';
239
-        		$globalSources[$id]['format'] = 'tsv';
240
-		    } elseif ($port == '30002') {
241
-        		//$formats[$id] = 'raw';
242
-        		$globalSources[$id]['format'] = 'raw';
243
-		    } elseif ($port == '5001') {
244
-        		//$formats[$id] = 'raw';
245
-        		$globalSources[$id]['format'] = 'flightgearmp';
246
-		    } elseif ($port == '30005') {
237
+				} elseif ($port == '10001') {
238
+				//$formats[$id] = 'tsv';
239
+				$globalSources[$id]['format'] = 'tsv';
240
+			} elseif ($port == '30002') {
241
+				//$formats[$id] = 'raw';
242
+				$globalSources[$id]['format'] = 'raw';
243
+			} elseif ($port == '5001') {
244
+				//$formats[$id] = 'raw';
245
+				$globalSources[$id]['format'] = 'flightgearmp';
246
+			} elseif ($port == '30005') {
247 247
 			// Not yet supported
248
-        		//$formats[$id] = 'beast';
249
-        		$globalSources[$id]['format'] = 'beast';
250
-		    //} else $formats[$id] = 'sbs';
251
-		    } else $globalSources[$id]['format'] = 'sbs';
252
-		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
248
+				//$formats[$id] = 'beast';
249
+				$globalSources[$id]['format'] = 'beast';
250
+			//} else $formats[$id] = 'sbs';
251
+			} else $globalSources[$id]['format'] = 'sbs';
252
+			//if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
253 253
 		}
254 254
 		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
255
-            } else {
255
+			} else {
256 256
 		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
257
-    	    }
258
-        }
259
-    }
257
+			}
258
+		}
259
+	}
260 260
 }
261 261
 if (!isset($globalMinFetch)) $globalMinFetch = 15;
262 262
 
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 //connect_all($globalSources);
280 280
 
281 281
 if (isset($globalProxy) && $globalProxy) {
282
-    $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
282
+	$context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true)));
283 283
 } else {
284
-    $context = stream_context_create(array('http' => array('timeout' => $timeout)));
284
+	$context = stream_context_create(array('http' => array('timeout' => $timeout)));
285 285
 }
286 286
 
287 287
 // APRS Configuration
@@ -290,18 +290,18 @@  discard block
 block discarded – undo
290 290
 	die;
291 291
 }
292 292
 foreach ($globalSources as $key => $source) {
293
-    if (!isset($source['format'])) {
294
-        $globalSources[$key]['format'] = 'auto';
295
-    }
293
+	if (!isset($source['format'])) {
294
+		$globalSources[$key]['format'] = 'auto';
295
+	}
296 296
 }
297 297
 connect_all($globalSources);
298 298
 foreach ($globalSources as $key => $source) {
299
-    if (isset($source['format']) && $source['format'] == 'aprs') {
299
+	if (isset($source['format']) && $source['format'] == 'aprs') {
300 300
 	$aprs_connect = 0;
301 301
 	$use_aprs = true;
302 302
 	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
303 303
 	break;
304
-    }
304
+	}
305 305
 }
306 306
 
307 307
 if ($use_aprs) {
@@ -340,188 +340,188 @@  discard block
 block discarded – undo
340 340
 
341 341
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
342 342
 while ($i > 0) {
343
-    if (!$globalDaemon) $i = $endtime-time();
344
-    // Delete old ATC
345
-    if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
343
+	if (!$globalDaemon) $i = $endtime-time();
344
+	// Delete old ATC
345
+	if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
346 346
 	if ($globalDebug) echo 'Delete old ATC...'."\n";
347
-        $ATC->deleteOldATC();
348
-    }
347
+		$ATC->deleteOldATC();
348
+	}
349 349
     
350
-    //if (count($last_exec) > 0) {
351
-    if (count($last_exec) == count($globalSources)) {
350
+	//if (count($last_exec) > 0) {
351
+	if (count($last_exec) == count($globalSources)) {
352 352
 	$max = $globalMinFetch;
353 353
 	foreach ($last_exec as $last) {
354
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
354
+		if ((time() - $last['last']) < $max) $max = time() - $last['last'];
355 355
 	}
356 356
 	if ($max != $globalMinFetch) {
357
-	    if ($globalDebug) echo 'Sleeping...'."\n";
358
-	    sleep($globalMinFetch-$max+2);
357
+		if ($globalDebug) echo 'Sleeping...'."\n";
358
+		sleep($globalMinFetch-$max+2);
359
+	}
359 360
 	}
360
-    }
361 361
 
362 362
     
363
-    //foreach ($formats as $id => $value) {
364
-    foreach ($globalSources as $id => $value) {
363
+	//foreach ($formats as $id => $value) {
364
+	foreach ($globalSources as $id => $value) {
365 365
 	date_default_timezone_set('UTC');
366 366
 	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
367 367
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
368
-	    //$buffer = $Common->getData($hosts[$id]);
369
-	    $buffer = $Common->getData($value['host']);
370
-	    if ($buffer != '') $reset = 0;
371
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
372
-	    $buffer = explode('\n',$buffer);
373
-	    foreach ($buffer as $line) {
374
-    		if ($line != '' && count($line) > 7) {
375
-    		    $line = explode(',', $line);
376
-	            $data = array();
377
-	            $data['hex'] = $line[1]; // hex
378
-	            $data['ident'] = $line[2]; // ident
379
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
380
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
381
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
382
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
383
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
384
-	            $data['verticalrate'] = ''; // vertical rate
385
-	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
386
-	            $data['emergency'] = ''; // emergency
387
-		    $data['datetime'] = date('Y-m-d H:i:s');
388
-		    $data['format_source'] = 'deltadbtxt';
389
-    		    $data['id_source'] = $id_source;
390
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
391
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
392
-    		    $SI->add($data);
393
-		    unset($data);
394
-    		}
395
-    	    }
396
-    	    $last_exec[$id]['last'] = time();
368
+		//$buffer = $Common->getData($hosts[$id]);
369
+		$buffer = $Common->getData($value['host']);
370
+		if ($buffer != '') $reset = 0;
371
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
372
+		$buffer = explode('\n',$buffer);
373
+		foreach ($buffer as $line) {
374
+			if ($line != '' && count($line) > 7) {
375
+				$line = explode(',', $line);
376
+				$data = array();
377
+				$data['hex'] = $line[1]; // hex
378
+				$data['ident'] = $line[2]; // ident
379
+				if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
380
+				if (isset($line[4])) $data['speed'] = $line[4]; // speed
381
+				if (isset($line[5])) $data['heading'] = $line[5]; // heading
382
+				if (isset($line[6])) $data['latitude'] = $line[6]; // lat
383
+				if (isset($line[7])) $data['longitude'] = $line[7]; // long
384
+				$data['verticalrate'] = ''; // vertical rate
385
+				//if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
386
+				$data['emergency'] = ''; // emergency
387
+			$data['datetime'] = date('Y-m-d H:i:s');
388
+			$data['format_source'] = 'deltadbtxt';
389
+				$data['id_source'] = $id_source;
390
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
391
+			if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
392
+				$SI->add($data);
393
+			unset($data);
394
+			}
395
+			}
396
+			$last_exec[$id]['last'] = time();
397 397
 	} elseif ($value['format'] == 'aisnmeatxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
398
-	    date_default_timezone_set('CET');
399
-	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
400
-	    date_default_timezone_set('UTC');
401
-	    if ($buffer != '') $reset = 0;
402
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
403
-	    $buffer = explode('\n',$buffer);
404
-	    foreach ($buffer as $line) {
398
+		date_default_timezone_set('CET');
399
+		$buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
400
+		date_default_timezone_set('UTC');
401
+		if ($buffer != '') $reset = 0;
402
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
403
+		$buffer = explode('\n',$buffer);
404
+		foreach ($buffer as $line) {
405 405
 		if ($line != '') {
406
-		    echo "'".$line."'\n";
407
-		    $add = false;
408
-		    $ais_data = $AIS->parse_line(trim($line));
409
-		    $data = array();
410
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
411
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
412
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
413
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
414
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
415
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
416
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
417
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
418
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
419
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
420
-		    if (isset($ais_data['timestamp'])) {
406
+			echo "'".$line."'\n";
407
+			$add = false;
408
+			$ais_data = $AIS->parse_line(trim($line));
409
+			$data = array();
410
+			if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
411
+			if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
412
+			if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
413
+			if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
414
+			if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
415
+			if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
416
+			if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
417
+			if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
418
+			if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
419
+			if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
420
+			if (isset($ais_data['timestamp'])) {
421 421
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
422 422
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
423
-			    $last_exec[$id]['timestamp'] = $ais_data['timestamp'];
424
-			    $add = true;
423
+				$last_exec[$id]['timestamp'] = $ais_data['timestamp'];
424
+				$add = true;
425 425
 			}
426
-		    } else {
426
+			} else {
427 427
 			$data['datetime'] = date('Y-m-d H:i:s');
428 428
 			$add = true;
429
-		    }
430
-		    $data['format_source'] = 'aisnmeatxt';
431
-    		    $data['id_source'] = $id_source;
432
-		    print_r($data);
433
-		    echo 'Add...'."\n";
434
-		    if ($add) $MI->add($data);
435
-		    unset($data);
429
+			}
430
+			$data['format_source'] = 'aisnmeatxt';
431
+				$data['id_source'] = $id_source;
432
+			print_r($data);
433
+			echo 'Add...'."\n";
434
+			if ($add) $MI->add($data);
435
+			unset($data);
436 436
 		}
437
-    	    }
438
-    	    $last_exec[$id]['last'] = time();
437
+			}
438
+			$last_exec[$id]['last'] = time();
439 439
 	} elseif ($value['format'] == 'aisnmeahttp') {
440
-	    $arr = $httpfeeds;
441
-	    $w = $e = null;
440
+		$arr = $httpfeeds;
441
+		$w = $e = null;
442 442
 	    
443
-	    if (isset($arr[$id])) {
444
-	    $nn = stream_select($arr,$w,$e,$timeout);
445
-	    if ($nn > 0) {
443
+		if (isset($arr[$id])) {
444
+		$nn = stream_select($arr,$w,$e,$timeout);
445
+		if ($nn > 0) {
446 446
 		foreach ($httpfeeds as $feed) {
447
-		    $buffer = stream_get_line($feed,2000,"\n");
448
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
449
-		    $buffer = explode('\n',$buffer);
450
-		    foreach ($buffer as $line) {
447
+			$buffer = stream_get_line($feed,2000,"\n");
448
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
449
+			$buffer = explode('\n',$buffer);
450
+			foreach ($buffer as $line) {
451 451
 			if ($line != '') {
452
-			    $ais_data = $AIS->parse_line(trim($line));
453
-			    $data = array();
454
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
455
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
456
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
457
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
458
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
459
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
460
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
461
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
462
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
463
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
464
-			    if (isset($ais_data['timestamp'])) {
452
+				$ais_data = $AIS->parse_line(trim($line));
453
+				$data = array();
454
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
455
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
456
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
457
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
458
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
459
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
460
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
461
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
462
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
463
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
464
+				if (isset($ais_data['timestamp'])) {
465 465
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
466
-			    } else {
466
+				} else {
467 467
 				$data['datetime'] = date('Y-m-d H:i:s');
468
-			    }
469
-			    $data['format_source'] = 'aisnmeahttp';
470
-			    $data['id_source'] = $id_source;
471
-			    $MI->add($data);
472
-			    unset($data);
468
+				}
469
+				$data['format_source'] = 'aisnmeahttp';
470
+				$data['id_source'] = $id_source;
471
+				$MI->add($data);
472
+				unset($data);
473 473
 			}
474
-		    }
474
+			}
475
+		}
475 476
 		}
476 477
 		}
477
-	    }
478 478
 	} elseif ($value['format'] == 'shipplotter' && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) {
479
-	    echo 'download...';
480
-	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
481
-	    echo 'done !'."\n";
482
-	    if ($buffer != '') $reset = 0;
483
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
484
-	    $buffer = explode('\n',$buffer);
485
-	    foreach ($buffer as $line) {
479
+		echo 'download...';
480
+		$buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
481
+		echo 'done !'."\n";
482
+		if ($buffer != '') $reset = 0;
483
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
484
+		$buffer = explode('\n',$buffer);
485
+		foreach ($buffer as $line) {
486 486
 		if ($line != '') {
487
-		    $data = array();
488
-		    $data['mmsi'] = (int)substr($line,0,9);
489
-		    $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
490
-		    //$data['status'] = substr($line,21,2);
491
-		    //$data['type'] = substr($line,24,3);
492
-		    $data['latitude'] = substr($line,29,9);
493
-		    $data['longitude'] = substr($line,41,9);
494
-		    $data['speed'] = round(substr($line,51,5));
495
-		    //$data['course'] = substr($line,57,5);
496
-		    $data['heading'] = round(substr($line,63,3));
497
-		    //$data['draft'] = substr($line,67,4);
498
-		    //$data['length'] = substr($line,72,3);
499
-		    //$data['beam'] = substr($line,76,2);
500
-		    $data['ident'] = trim(utf8_encode(substr($line,79,20)));
501
-		    //$data['callsign'] = trim(substr($line,100,7);
502
-		    //$data['dest'] = substr($line,108,20);
503
-		    //$data['etaDate'] = substr($line,129,5);
504
-		    //$data['etaTime'] = substr($line,135,5);
505
-		    $data['format_source'] = 'shipplotter';
506
-    		    $data['id_source'] = $id_source;
507
-		    print_r($data);
508
-		    echo 'Add...'."\n";
509
-		    $MI->add($data);
510
-		    unset($data);
487
+			$data = array();
488
+			$data['mmsi'] = (int)substr($line,0,9);
489
+			$data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10));
490
+			//$data['status'] = substr($line,21,2);
491
+			//$data['type'] = substr($line,24,3);
492
+			$data['latitude'] = substr($line,29,9);
493
+			$data['longitude'] = substr($line,41,9);
494
+			$data['speed'] = round(substr($line,51,5));
495
+			//$data['course'] = substr($line,57,5);
496
+			$data['heading'] = round(substr($line,63,3));
497
+			//$data['draft'] = substr($line,67,4);
498
+			//$data['length'] = substr($line,72,3);
499
+			//$data['beam'] = substr($line,76,2);
500
+			$data['ident'] = trim(utf8_encode(substr($line,79,20)));
501
+			//$data['callsign'] = trim(substr($line,100,7);
502
+			//$data['dest'] = substr($line,108,20);
503
+			//$data['etaDate'] = substr($line,129,5);
504
+			//$data['etaTime'] = substr($line,135,5);
505
+			$data['format_source'] = 'shipplotter';
506
+				$data['id_source'] = $id_source;
507
+			print_r($data);
508
+			echo 'Add...'."\n";
509
+			$MI->add($data);
510
+			unset($data);
511 511
 		}
512
-    	    }
513
-    	    $last_exec[$id]['last'] = time();
512
+			}
513
+			$last_exec[$id]['last'] = time();
514 514
 	//} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) {
515 515
 	} elseif (($value['format'] == 'whazzup' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) || ($value['format'] == 'vatsimtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch))) {
516
-	    //$buffer = $Common->getData($hosts[$id]);
517
-	    $buffer = $Common->getData($value['host']);
518
-    	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
519
-	    $buffer = explode('\n',$buffer);
520
-	    $reset = 0;
521
-	    foreach ($buffer as $line) {
522
-    		if ($line != '') {
523
-    		    $line = explode(':', $line);
524
-    		    if (count($line) > 30 && $line[0] != 'callsign') {
516
+		//$buffer = $Common->getData($hosts[$id]);
517
+		$buffer = $Common->getData($value['host']);
518
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
519
+		$buffer = explode('\n',$buffer);
520
+		$reset = 0;
521
+		foreach ($buffer as $line) {
522
+			if ($line != '') {
523
+				$line = explode(':', $line);
524
+				if (count($line) > 30 && $line[0] != 'callsign') {
525 525
 			$data = array();
526 526
 			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
527 527
 			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
@@ -534,36 +534,36 @@  discard block
 block discarded – undo
534 534
 			if (isset($line[45])) $data['heading'] = $line[45]; // heading
535 535
 			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
536 536
 			$data['latitude'] = $line[5]; // lat
537
-	        	$data['longitude'] = $line[6]; // long
538
-	        	$data['verticalrate'] = ''; // vertical rate
539
-	        	$data['squawk'] = ''; // squawk
540
-	        	$data['emergency'] = ''; // emergency
541
-	        	$data['waypoints'] = $line[30];
537
+				$data['longitude'] = $line[6]; // long
538
+				$data['verticalrate'] = ''; // vertical rate
539
+				$data['squawk'] = ''; // squawk
540
+				$data['emergency'] = ''; // emergency
541
+				$data['waypoints'] = $line[30];
542 542
 			$data['datetime'] = date('Y-m-d H:i:s');
543 543
 			//$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37]));
544 544
 			//if (isset($line[37])) $data['last_update'] = $line[37];
545
-		        $data['departure_airport_icao'] = $line[11];
546
-		        $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
547
-		        $data['arrival_airport_icao'] = $line[13];
545
+				$data['departure_airport_icao'] = $line[11];
546
+				$data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':');
547
+				$data['arrival_airport_icao'] = $line[13];
548 548
 			$data['frequency'] = $line[4];
549 549
 			$data['type'] = $line[18];
550 550
 			$data['range'] = $line[19];
551 551
 			if (isset($line[35])) $data['info'] = $line[35];
552
-    			$data['id_source'] = $id_source;
553
-	    		//$data['arrival_airport_time'] = ;
554
-	    		if ($line[9] != '') {
555
-	    		    $aircraft_data = explode('/',$line[9]);
556
-	    		    if (isset($aircraft_data[1])) {
557
-	    			$data['aircraft_icao'] = $aircraft_data[1];
558
-	    		    }
559
-        		}
560
-	    		/*
552
+				$data['id_source'] = $id_source;
553
+				//$data['arrival_airport_time'] = ;
554
+				if ($line[9] != '') {
555
+					$aircraft_data = explode('/',$line[9]);
556
+					if (isset($aircraft_data[1])) {
557
+					$data['aircraft_icao'] = $aircraft_data[1];
558
+					}
559
+				}
560
+				/*
561 561
 	    		if ($value == 'whazzup') $data['format_source'] = 'whazzup';
562 562
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
563 563
 	    		*/
564
-	    		$data['format_source'] = $value['format'];
564
+				$data['format_source'] = $value['format'];
565 565
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
566
-    			if ($line[3] == 'PILOT') $SI->add($data);
566
+				if ($line[3] == 'PILOT') $SI->add($data);
567 567
 			elseif ($line[3] == 'ATC') {
568 568
 				//print_r($data);
569 569
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
@@ -581,247 +581,247 @@  discard block
 block discarded – undo
581 581
 				if (!isset($data['source_name'])) $data['source_name'] = '';
582 582
 				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']);
583 583
 			}
584
-    			unset($data);
585
-    		    }
586
-    		}
587
-    	    }
588
-    	    //if ($value == 'whazzup') $last_exec['whazzup'] = time();
589
-    	    //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
590
-    	    $last_exec[$id]['last'] = time();
591
-    	//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
592
-    	} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
593
-	    $buffer = $Common->getData($value['host'],'get','','','','','20');
594
-	    if ($buffer != '') {
595
-	    $all_data = json_decode($buffer,true);
596
-	    if (isset($all_data['acList'])) {
584
+				unset($data);
585
+				}
586
+			}
587
+			}
588
+			//if ($value == 'whazzup') $last_exec['whazzup'] = time();
589
+			//elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time();
590
+			$last_exec[$id]['last'] = time();
591
+		//} elseif ($value == 'aircraftlistjson' && (time() - $last_exec['aircraftlistjson'] > $globalMinFetch)) {
592
+		} elseif ($value['format'] == 'aircraftlistjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
593
+		$buffer = $Common->getData($value['host'],'get','','','','','20');
594
+		if ($buffer != '') {
595
+		$all_data = json_decode($buffer,true);
596
+		if (isset($all_data['acList'])) {
597 597
 		$reset = 0;
598 598
 		foreach ($all_data['acList'] as $line) {
599
-		    $data = array();
600
-		    $data['hex'] = $line['Icao']; // hex
601
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
602
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
603
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
604
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
605
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
606
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
607
-		    //$data['verticalrate'] = $line['']; // verticale rate
608
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
609
-		    $data['emergency'] = ''; // emergency
610
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
611
-		    /*
599
+			$data = array();
600
+			$data['hex'] = $line['Icao']; // hex
601
+			if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
602
+			if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
603
+			if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
604
+			if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
605
+			if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
606
+			if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
607
+			//$data['verticalrate'] = $line['']; // verticale rate
608
+			if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
609
+			$data['emergency'] = ''; // emergency
610
+			if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
611
+			/*
612 612
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
613 613
 		    else $data['datetime'] = date('Y-m-d H:i:s');
614 614
 		    */
615
-		    $data['datetime'] = date('Y-m-d H:i:s');
616
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
617
-	    	    $data['format_source'] = 'aircraftlistjson';
618
-		    $data['id_source'] = $id_source;
619
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
620
-		    if (isset($data['datetime'])) $SI->add($data);
621
-		    unset($data);
615
+			$data['datetime'] = date('Y-m-d H:i:s');
616
+			if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
617
+				$data['format_source'] = 'aircraftlistjson';
618
+			$data['id_source'] = $id_source;
619
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
620
+			if (isset($data['datetime'])) $SI->add($data);
621
+			unset($data);
622 622
 		}
623
-	    } else {
623
+		} else {
624 624
 		$reset = 0;
625 625
 		foreach ($all_data as $line) {
626
-		    $data = array();
627
-		    $data['hex'] = $line['hex']; // hex
628
-		    $data['ident'] = $line['flight']; // ident
629
-		    $data['altitude'] = $line['altitude']; // altitude
630
-		    $data['speed'] = $line['speed']; // speed
631
-		    $data['heading'] = $line['track']; // heading
632
-		    $data['latitude'] = $line['lat']; // lat
633
-		    $data['longitude'] = $line['lon']; // long
634
-		    $data['verticalrate'] = $line['vrt']; // verticale rate
635
-		    $data['squawk'] = $line['squawk']; // squawk
636
-		    $data['emergency'] = ''; // emergency
637
-		    $data['datetime'] = date('Y-m-d H:i:s');
638
-	    	    $data['format_source'] = 'aircraftlistjson';
639
-    		    $data['id_source'] = $id_source;
640
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
641
-		    $SI->add($data);
642
-		    unset($data);
626
+			$data = array();
627
+			$data['hex'] = $line['hex']; // hex
628
+			$data['ident'] = $line['flight']; // ident
629
+			$data['altitude'] = $line['altitude']; // altitude
630
+			$data['speed'] = $line['speed']; // speed
631
+			$data['heading'] = $line['track']; // heading
632
+			$data['latitude'] = $line['lat']; // lat
633
+			$data['longitude'] = $line['lon']; // long
634
+			$data['verticalrate'] = $line['vrt']; // verticale rate
635
+			$data['squawk'] = $line['squawk']; // squawk
636
+			$data['emergency'] = ''; // emergency
637
+			$data['datetime'] = date('Y-m-d H:i:s');
638
+				$data['format_source'] = 'aircraftlistjson';
639
+				$data['id_source'] = $id_source;
640
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
641
+			$SI->add($data);
642
+			unset($data);
643
+		}
643 644
 		}
644
-	    }
645
-	    }
646
-    	    //$last_exec['aircraftlistjson'] = time();
647
-    	    $last_exec[$id]['last'] = time();
648
-    	//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
649
-    	} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
650
-	    $buffer = $Common->getData($value['host']);
651
-	    $all_data = json_decode($buffer,true);
652
-	    if (isset($all_data['planes'])) {
645
+		}
646
+			//$last_exec['aircraftlistjson'] = time();
647
+			$last_exec[$id]['last'] = time();
648
+		//} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) {
649
+		} elseif ($value['format'] == 'planeupdatefaa' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
650
+		$buffer = $Common->getData($value['host']);
651
+		$all_data = json_decode($buffer,true);
652
+		if (isset($all_data['planes'])) {
653 653
 		$reset = 0;
654 654
 		foreach ($all_data['planes'] as $key => $line) {
655
-		    $data = array();
656
-		    $data['hex'] = $key; // hex
657
-		    $data['ident'] = $line[3]; // ident
658
-		    $data['altitude'] = $line[6]; // altitude
659
-		    $data['speed'] = $line[8]; // speed
660
-		    $data['heading'] = $line[7]; // heading
661
-		    $data['latitude'] = $line[4]; // lat
662
-		    $data['longitude'] = $line[5]; // long
663
-		    //$data['verticalrate'] = $line[]; // verticale rate
664
-		    $data['squawk'] = $line[10]; // squawk
665
-		    $data['emergency'] = ''; // emergency
666
-		    $data['registration'] = $line[2];
667
-		    $data['aircraft_icao'] = $line[0];
668
-		    $deparr = explode('-',$line[1]);
669
-		    if (count($deparr) == 2) {
655
+			$data = array();
656
+			$data['hex'] = $key; // hex
657
+			$data['ident'] = $line[3]; // ident
658
+			$data['altitude'] = $line[6]; // altitude
659
+			$data['speed'] = $line[8]; // speed
660
+			$data['heading'] = $line[7]; // heading
661
+			$data['latitude'] = $line[4]; // lat
662
+			$data['longitude'] = $line[5]; // long
663
+			//$data['verticalrate'] = $line[]; // verticale rate
664
+			$data['squawk'] = $line[10]; // squawk
665
+			$data['emergency'] = ''; // emergency
666
+			$data['registration'] = $line[2];
667
+			$data['aircraft_icao'] = $line[0];
668
+			$deparr = explode('-',$line[1]);
669
+			if (count($deparr) == 2) {
670 670
 			$data['departure_airport_icao'] = $deparr[0];
671 671
 			$data['arrival_airport_icao'] = $deparr[1];
672
-		    }
673
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
674
-	    	    $data['format_source'] = 'planeupdatefaa';
675
-    		    $data['id_source'] = $id_source;
676
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
677
-		    $SI->add($data);
678
-		    unset($data);
672
+			}
673
+			$data['datetime'] = date('Y-m-d H:i:s',$line[9]);
674
+				$data['format_source'] = 'planeupdatefaa';
675
+				$data['id_source'] = $id_source;
676
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
677
+			$SI->add($data);
678
+			unset($data);
679 679
 		}
680
-	    }
681
-    	    //$last_exec['planeupdatefaa'] = time();
682
-    	    $last_exec[$id]['last'] = time();
683
-    	} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
684
-	    $buffer = $Common->getData($value['host']);
685
-	    $all_data = json_decode($buffer,true);
686
-	    if (isset($all_data['states'])) {
680
+		}
681
+			//$last_exec['planeupdatefaa'] = time();
682
+			$last_exec[$id]['last'] = time();
683
+		} elseif ($value['format'] == 'opensky' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
684
+		$buffer = $Common->getData($value['host']);
685
+		$all_data = json_decode($buffer,true);
686
+		if (isset($all_data['states'])) {
687 687
 		$reset = 0;
688 688
 		foreach ($all_data['states'] as $key => $line) {
689
-		    $data = array();
690
-		    $data['hex'] = $line[0]; // hex
691
-		    $data['ident'] = trim($line[1]); // ident
692
-		    $data['altitude'] = round($line[7]*3.28084); // altitude
693
-		    $data['speed'] = round($line[9]*1.94384); // speed
694
-		    $data['heading'] = round($line[10]); // heading
695
-		    $data['latitude'] = $line[5]; // lat
696
-		    $data['longitude'] = $line[6]; // long
697
-		    $data['verticalrate'] = $line[11]; // verticale rate
698
-		    //$data['squawk'] = $line[10]; // squawk
699
-		    //$data['emergency'] = ''; // emergency
700
-		    //$data['registration'] = $line[2];
701
-		    //$data['aircraft_icao'] = $line[0];
702
-		    $data['datetime'] = date('Y-m-d H:i:s',$line[3]);
703
-	    	    $data['format_source'] = 'opensky';
704
-    		    $data['id_source'] = $id_source;
705
-		    $SI->add($data);
706
-		    unset($data);
689
+			$data = array();
690
+			$data['hex'] = $line[0]; // hex
691
+			$data['ident'] = trim($line[1]); // ident
692
+			$data['altitude'] = round($line[7]*3.28084); // altitude
693
+			$data['speed'] = round($line[9]*1.94384); // speed
694
+			$data['heading'] = round($line[10]); // heading
695
+			$data['latitude'] = $line[5]; // lat
696
+			$data['longitude'] = $line[6]; // long
697
+			$data['verticalrate'] = $line[11]; // verticale rate
698
+			//$data['squawk'] = $line[10]; // squawk
699
+			//$data['emergency'] = ''; // emergency
700
+			//$data['registration'] = $line[2];
701
+			//$data['aircraft_icao'] = $line[0];
702
+			$data['datetime'] = date('Y-m-d H:i:s',$line[3]);
703
+				$data['format_source'] = 'opensky';
704
+				$data['id_source'] = $id_source;
705
+			$SI->add($data);
706
+			unset($data);
707
+		}
707 708
 		}
708
-	    }
709
-    	    //$last_exec['planeupdatefaa'] = time();
710
-    	    $last_exec[$id]['last'] = time();
711
-    	//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
712
-    	} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
713
-	    //$buffer = $Common->getData($hosts[$id]);
714
-	    $buffer = $Common->getData($value['host']);
715
-	    $all_data = json_decode($buffer,true);
716
-	    if (!empty($all_data)) $reset = 0;
717
-	    foreach ($all_data as $key => $line) {
709
+			//$last_exec['planeupdatefaa'] = time();
710
+			$last_exec[$id]['last'] = time();
711
+		//} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) {
712
+		} elseif ($value['format'] == 'fr24json' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
713
+		//$buffer = $Common->getData($hosts[$id]);
714
+		$buffer = $Common->getData($value['host']);
715
+		$all_data = json_decode($buffer,true);
716
+		if (!empty($all_data)) $reset = 0;
717
+		foreach ($all_data as $key => $line) {
718 718
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
719
-		    $data = array();
720
-		    $data['hex'] = $line[0];
721
-		    $data['ident'] = $line[16]; //$line[13]
722
-	    	    $data['altitude'] = $line[4]; // altitude
723
-	    	    $data['speed'] = $line[5]; // speed
724
-	    	    $data['heading'] = $line[3]; // heading
725
-	    	    $data['latitude'] = $line[1]; // lat
726
-	    	    $data['longitude'] = $line[2]; // long
727
-	    	    $data['verticalrate'] = $line[15]; // verticale rate
728
-	    	    $data['squawk'] = $line[6]; // squawk
729
-	    	    $data['aircraft_icao'] = $line[8];
730
-	    	    $data['registration'] = $line[9];
731
-		    $data['departure_airport_iata'] = $line[11];
732
-		    $data['arrival_airport_iata'] = $line[12];
733
-	    	    $data['emergency'] = ''; // emergency
734
-		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
735
-	    	    $data['format_source'] = 'fr24json';
736
-    		    $data['id_source'] = $id_source;
737
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
738
-		    $SI->add($data);
739
-		    unset($data);
719
+			$data = array();
720
+			$data['hex'] = $line[0];
721
+			$data['ident'] = $line[16]; //$line[13]
722
+				$data['altitude'] = $line[4]; // altitude
723
+				$data['speed'] = $line[5]; // speed
724
+				$data['heading'] = $line[3]; // heading
725
+				$data['latitude'] = $line[1]; // lat
726
+				$data['longitude'] = $line[2]; // long
727
+				$data['verticalrate'] = $line[15]; // verticale rate
728
+				$data['squawk'] = $line[6]; // squawk
729
+				$data['aircraft_icao'] = $line[8];
730
+				$data['registration'] = $line[9];
731
+			$data['departure_airport_iata'] = $line[11];
732
+			$data['arrival_airport_iata'] = $line[12];
733
+				$data['emergency'] = ''; // emergency
734
+			$data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
735
+				$data['format_source'] = 'fr24json';
736
+				$data['id_source'] = $id_source;
737
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
738
+			$SI->add($data);
739
+			unset($data);
740
+		}
740 741
 		}
741
-	    }
742
-    	    //$last_exec['fr24json'] = time();
743
-    	    $last_exec[$id]['last'] = time();
744
-    	//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
745
-    	} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
746
-	    //$buffer = $Common->getData($hosts[$id],'get','','','','','150');
747
-	    $buffer = $Common->getData($value['host'],'get','','','','','150');
748
-	    //echo $buffer;
749
-	    $buffer = str_replace(array("\n","\r"),"",$buffer);
750
-	    $buffer = preg_replace('/,"num":(.+)/','}',$buffer);
751
-	    $all_data = json_decode($buffer,true);
752
-	    if (json_last_error() != JSON_ERROR_NONE) {
742
+			//$last_exec['fr24json'] = time();
743
+			$last_exec[$id]['last'] = time();
744
+		//} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) {
745
+		} elseif ($value['format'] == 'radarvirtueljson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
746
+		//$buffer = $Common->getData($hosts[$id],'get','','','','','150');
747
+		$buffer = $Common->getData($value['host'],'get','','','','','150');
748
+		//echo $buffer;
749
+		$buffer = str_replace(array("\n","\r"),"",$buffer);
750
+		$buffer = preg_replace('/,"num":(.+)/','}',$buffer);
751
+		$all_data = json_decode($buffer,true);
752
+		if (json_last_error() != JSON_ERROR_NONE) {
753 753
 		die(json_last_error_msg());
754
-	    }
755
-	    if (isset($all_data['mrkrs'])) {
754
+		}
755
+		if (isset($all_data['mrkrs'])) {
756 756
 		$reset = 0;
757 757
 		foreach ($all_data['mrkrs'] as $key => $line) {
758
-		    if (isset($line['inf'])) {
758
+			if (isset($line['inf'])) {
759 759
 			$data = array();
760 760
 			$data['hex'] = $line['inf']['ia'];
761 761
 			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
762
-	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
763
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
764
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
765
-	    		$data['latitude'] = $line['pt'][0]; // lat
766
-	    		$data['longitude'] = $line['pt'][1]; // long
767
-	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
768
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
769
-	    		//$data['aircraft_icao'] = $line[8];
770
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
762
+				$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
763
+				if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
764
+				if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
765
+				$data['latitude'] = $line['pt'][0]; // lat
766
+				$data['longitude'] = $line['pt'][1]; // long
767
+				//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
768
+				if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
769
+				//$data['aircraft_icao'] = $line[8];
770
+				if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
771 771
 			//$data['departure_airport_iata'] = $line[11];
772 772
 			//$data['arrival_airport_iata'] = $line[12];
773
-	    		//$data['emergency'] = ''; // emergency
773
+				//$data['emergency'] = ''; // emergency
774 774
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
775
-	    		$data['format_source'] = 'radarvirtueljson';
776
-    			$data['id_source'] = $id_source;
775
+				$data['format_source'] = 'radarvirtueljson';
776
+				$data['id_source'] = $id_source;
777 777
 			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
778 778
 			$SI->add($data);
779 779
 			unset($data);
780
-		    }
780
+			}
781 781
 		}
782
-	    }
783
-    	    //$last_exec['radarvirtueljson'] = time();
784
-    	    $last_exec[$id]['last'] = time();
785
-    	//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
786
-    	} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
787
-	    //$buffer = $Common->getData($hosts[$id]);
788
-	    $buffer = $Common->getData($value['host'].'?'.time());
789
-	    $all_data = json_decode(utf8_encode($buffer),true);
782
+		}
783
+			//$last_exec['radarvirtueljson'] = time();
784
+			$last_exec[$id]['last'] = time();
785
+		//} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) {
786
+		} elseif ($value['format'] == 'pirepsjson' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
787
+		//$buffer = $Common->getData($hosts[$id]);
788
+		$buffer = $Common->getData($value['host'].'?'.time());
789
+		$all_data = json_decode(utf8_encode($buffer),true);
790 790
 	    
791
-	    if (isset($all_data['pireps'])) {
791
+		if (isset($all_data['pireps'])) {
792 792
 		$reset = 0;
793
-	        foreach ($all_data['pireps'] as $line) {
794
-		    $data = array();
795
-		    $data['id'] = $line['id'];
796
-		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
797
-		    $data['ident'] = $line['callsign']; // ident
798
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
799
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
800
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
801
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
802
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
803
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
804
-		    $data['latitude'] = $line['lat']; // lat
805
-		    $data['longitude'] = $line['lon']; // long
806
-		    //$data['verticalrate'] = $line['vrt']; // verticale rate
807
-		    //$data['squawk'] = $line['squawk']; // squawk
808
-		    //$data['emergency'] = ''; // emergency
809
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
810
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
811
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
812
-		    //$data['arrival_airport_time'] = $line['arrtime'];
813
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
814
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
815
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
816
-		    else $data['info'] = '';
817
-		    $data['format_source'] = 'pireps';
818
-    		    $data['id_source'] = $id_source;
819
-		    $data['datetime'] = date('Y-m-d H:i:s');
820
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
821
-		    if ($line['icon'] == 'plane') {
793
+			foreach ($all_data['pireps'] as $line) {
794
+			$data = array();
795
+			$data['id'] = $line['id'];
796
+			$data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
797
+			$data['ident'] = $line['callsign']; // ident
798
+			if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
799
+			if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
800
+			if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
801
+			if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
802
+			if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
803
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
804
+			$data['latitude'] = $line['lat']; // lat
805
+			$data['longitude'] = $line['lon']; // long
806
+			//$data['verticalrate'] = $line['vrt']; // verticale rate
807
+			//$data['squawk'] = $line['squawk']; // squawk
808
+			//$data['emergency'] = ''; // emergency
809
+			if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
810
+			if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
811
+			if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
812
+			//$data['arrival_airport_time'] = $line['arrtime'];
813
+			if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
814
+			if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
815
+			if (isset($line['atis'])) $data['info'] = $line['atis'];
816
+			else $data['info'] = '';
817
+			$data['format_source'] = 'pireps';
818
+				$data['id_source'] = $id_source;
819
+			$data['datetime'] = date('Y-m-d H:i:s');
820
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
821
+			if ($line['icon'] == 'plane') {
822 822
 			$SI->add($data);
823
-		    //    print_r($data);
824
-    		    } elseif ($line['icon'] == 'ct') {
823
+			//    print_r($data);
824
+				} elseif ($line['icon'] == 'ct') {
825 825
 			$data['info'] = str_replace('^&sect;','<br />',$data['info']);
826 826
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
827 827
 			$typec = substr($data['ident'],-3);
@@ -836,186 +836,186 @@  discard block
 block discarded – undo
836 836
 			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
837 837
 			else $data['type'] = 'Observer';
838 838
 			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']);
839
-		    }
840
-		    unset($data);
839
+			}
840
+			unset($data);
841 841
 		}
842
-	    }
843
-    	    //$last_exec['pirepsjson'] = time();
844
-    	    $last_exec[$id]['last'] = time();
845
-    	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
846
-    	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
847
-	    //$buffer = $Common->getData($hosts[$id]);
848
-	    if ($globalDebug) echo 'Get Data...'."\n";
849
-	    $buffer = $Common->getData($value['host']);
850
-	    $all_data = json_decode($buffer,true);
851
-	    if ($buffer != '' && is_array($all_data)) {
842
+		}
843
+			//$last_exec['pirepsjson'] = time();
844
+			$last_exec[$id]['last'] = time();
845
+		//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
846
+		} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
847
+		//$buffer = $Common->getData($hosts[$id]);
848
+		if ($globalDebug) echo 'Get Data...'."\n";
849
+		$buffer = $Common->getData($value['host']);
850
+		$all_data = json_decode($buffer,true);
851
+		if ($buffer != '' && is_array($all_data)) {
852 852
 		$reset = 0;
853 853
 		foreach ($all_data as $line) {
854
-	    	    $data = array();
855
-	    	    //$data['id'] = $line['id']; // id not usable
856
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
857
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
858
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
859
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
860
-	    	    $data['ident'] = $line['flightnum']; // ident
861
-	    	    $data['altitude'] = $line['alt']; // altitude
862
-	    	    $data['speed'] = $line['gs']; // speed
863
-	    	    $data['heading'] = $line['heading']; // heading
864
-	    	    $data['latitude'] = $line['lat']; // lat
865
-	    	    $data['longitude'] = $line['lng']; // long
866
-	    	    $data['verticalrate'] = ''; // verticale rate
867
-	    	    $data['squawk'] = ''; // squawk
868
-	    	    $data['emergency'] = ''; // emergency
869
-	    	    //$data['datetime'] = $line['lastupdate'];
870
-	    	    $data['last_update'] = $line['lastupdate'];
871
-		    $data['datetime'] = date('Y-m-d H:i:s');
872
-	    	    $data['departure_airport_icao'] = $line['depicao'];
873
-	    	    $data['departure_airport_time'] = $line['deptime'];
874
-	    	    $data['arrival_airport_icao'] = $line['arricao'];
875
-    		    $data['arrival_airport_time'] = $line['arrtime'];
876
-    		    $data['registration'] = $line['aircraft'];
877
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
878
-		    if (isset($line['aircraftname'])) {
854
+				$data = array();
855
+				//$data['id'] = $line['id']; // id not usable
856
+				if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
857
+				$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
858
+				if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
859
+				if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
860
+				$data['ident'] = $line['flightnum']; // ident
861
+				$data['altitude'] = $line['alt']; // altitude
862
+				$data['speed'] = $line['gs']; // speed
863
+				$data['heading'] = $line['heading']; // heading
864
+				$data['latitude'] = $line['lat']; // lat
865
+				$data['longitude'] = $line['lng']; // long
866
+				$data['verticalrate'] = ''; // verticale rate
867
+				$data['squawk'] = ''; // squawk
868
+				$data['emergency'] = ''; // emergency
869
+				//$data['datetime'] = $line['lastupdate'];
870
+				$data['last_update'] = $line['lastupdate'];
871
+			$data['datetime'] = date('Y-m-d H:i:s');
872
+				$data['departure_airport_icao'] = $line['depicao'];
873
+				$data['departure_airport_time'] = $line['deptime'];
874
+				$data['arrival_airport_icao'] = $line['arricao'];
875
+				$data['arrival_airport_time'] = $line['arrtime'];
876
+				$data['registration'] = $line['aircraft'];
877
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
878
+			if (isset($line['aircraftname'])) {
879 879
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
880 880
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
881
-	    		$aircraft_data = explode('-',$line['aircraftname']);
882
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
883
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
884
-	    		else {
885
-	    		    $aircraft_data = explode(' ',$line['aircraftname']);
886
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
887
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
888
-	    		}
889
-	    	    }
890
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
891
-    		    $data['id_source'] = $id_source;
892
-	    	    $data['format_source'] = 'phpvmacars';
893
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
894
-		    $SI->add($data);
895
-		    unset($data);
881
+				$aircraft_data = explode('-',$line['aircraftname']);
882
+				if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
883
+				elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
884
+				else {
885
+					$aircraft_data = explode(' ',$line['aircraftname']);
886
+					if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
887
+					else $data['aircraft_icao'] = $line['aircraftname'];
888
+				}
889
+				}
890
+				if (isset($line['route'])) $data['waypoints'] = $line['route'];
891
+				$data['id_source'] = $id_source;
892
+				$data['format_source'] = 'phpvmacars';
893
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
894
+			$SI->add($data);
895
+			unset($data);
896 896
 		}
897 897
 		if ($globalDebug) echo 'No more data...'."\n";
898 898
 		unset($buffer);
899 899
 		unset($all_data);
900
-	    }
901
-    	    //$last_exec['phpvmacars'] = time();
902
-    	    $last_exec[$id]['last'] = time();
903
-    	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
904
-	    //$buffer = $Common->getData($hosts[$id]);
905
-	    if ($globalDebug) echo 'Get Data...'."\n";
906
-	    $buffer = $Common->getData($value['host']);
907
-	    $all_data = json_decode($buffer,true);
908
-	    if ($buffer != '' && is_array($all_data)) {
900
+		}
901
+			//$last_exec['phpvmacars'] = time();
902
+			$last_exec[$id]['last'] = time();
903
+		} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
904
+		//$buffer = $Common->getData($hosts[$id]);
905
+		if ($globalDebug) echo 'Get Data...'."\n";
906
+		$buffer = $Common->getData($value['host']);
907
+		$all_data = json_decode($buffer,true);
908
+		if ($buffer != '' && is_array($all_data)) {
909 909
 		$reset = 0;
910 910
 		foreach ($all_data as $line) {
911
-	    	    $data = array();
912
-	    	    //$data['id'] = $line['id']; // id not usable
913
-	    	    $data['id'] = trim($line['flight_id']);
914
-	    	    $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
915
-	    	    $data['pilot_name'] = $line['pilot_name'];
916
-	    	    $data['pilot_id'] = $line['pilot_id'];
917
-	    	    $data['ident'] = trim($line['callsign']); // ident
918
-	    	    $data['altitude'] = $line['altitude']; // altitude
919
-	    	    $data['speed'] = $line['gs']; // speed
920
-	    	    $data['heading'] = $line['heading']; // heading
921
-	    	    $data['latitude'] = $line['latitude']; // lat
922
-	    	    $data['longitude'] = $line['longitude']; // long
923
-	    	    $data['verticalrate'] = ''; // verticale rate
924
-	    	    $data['squawk'] = ''; // squawk
925
-	    	    $data['emergency'] = ''; // emergency
926
-	    	    //$data['datetime'] = $line['lastupdate'];
927
-	    	    $data['last_update'] = $line['last_update'];
928
-		    $data['datetime'] = date('Y-m-d H:i:s');
929
-	    	    $data['departure_airport_icao'] = $line['departure'];
930
-	    	    //$data['departure_airport_time'] = $line['departure_time'];
931
-	    	    $data['arrival_airport_icao'] = $line['arrival'];
932
-    		    //$data['arrival_airport_time'] = $line['arrival_time'];
933
-    		    //$data['registration'] = $line['aircraft'];
934
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
935
-	    	    $data['aircraft_icao'] = $line['plane_type'];
936
-    		    $data['id_source'] = $id_source;
937
-	    	    $data['format_source'] = 'vam';
938
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
939
-		    $SI->add($data);
940
-		    unset($data);
911
+				$data = array();
912
+				//$data['id'] = $line['id']; // id not usable
913
+				$data['id'] = trim($line['flight_id']);
914
+				$data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex
915
+				$data['pilot_name'] = $line['pilot_name'];
916
+				$data['pilot_id'] = $line['pilot_id'];
917
+				$data['ident'] = trim($line['callsign']); // ident
918
+				$data['altitude'] = $line['altitude']; // altitude
919
+				$data['speed'] = $line['gs']; // speed
920
+				$data['heading'] = $line['heading']; // heading
921
+				$data['latitude'] = $line['latitude']; // lat
922
+				$data['longitude'] = $line['longitude']; // long
923
+				$data['verticalrate'] = ''; // verticale rate
924
+				$data['squawk'] = ''; // squawk
925
+				$data['emergency'] = ''; // emergency
926
+				//$data['datetime'] = $line['lastupdate'];
927
+				$data['last_update'] = $line['last_update'];
928
+			$data['datetime'] = date('Y-m-d H:i:s');
929
+				$data['departure_airport_icao'] = $line['departure'];
930
+				//$data['departure_airport_time'] = $line['departure_time'];
931
+				$data['arrival_airport_icao'] = $line['arrival'];
932
+				//$data['arrival_airport_time'] = $line['arrival_time'];
933
+				//$data['registration'] = $line['aircraft'];
934
+			if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
935
+				$data['aircraft_icao'] = $line['plane_type'];
936
+				$data['id_source'] = $id_source;
937
+				$data['format_source'] = 'vam';
938
+			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
939
+			$SI->add($data);
940
+			unset($data);
941 941
 		}
942 942
 		if ($globalDebug) echo 'No more data...'."\n";
943 943
 		unset($buffer);
944 944
 		unset($all_data);
945
-	    }
946
-    	    //$last_exec['phpvmacars'] = time();
947
-    	    $last_exec[$id]['last'] = time();
945
+		}
946
+			//$last_exec['phpvmacars'] = time();
947
+			$last_exec[$id]['last'] = time();
948 948
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
949 949
 	} 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' || $value['format'] == 'ais') {
950
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
951
-    	    //$last_exec[$id]['last'] = time();
950
+		if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
951
+			//$last_exec[$id]['last'] = time();
952 952
 
953
-	    //$read = array( $sockets[$id] );
954
-	    $read = $sockets;
955
-	    $write = NULL;
956
-	    $e = NULL;
957
-	    $n = socket_select($read, $write, $e, $timeout);
958
-	    if ($e != NULL) var_dump($e);
959
-	    if ($n > 0) {
953
+		//$read = array( $sockets[$id] );
954
+		$read = $sockets;
955
+		$write = NULL;
956
+		$e = NULL;
957
+		$n = socket_select($read, $write, $e, $timeout);
958
+		if ($e != NULL) var_dump($e);
959
+		if ($n > 0) {
960 960
 		$reset = 0;
961 961
 		foreach ($read as $nb => $r) {
962
-		    //$value = $formats[$nb];
963
-		    $format = $globalSources[$nb]['format'];
964
-        	    if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
965
-        		$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
966
-        	    } else {
967
-	    	        $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
968
-	    	    }
969
-        	    //$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
970
-        	    //echo $buffer."\n";
971
-		    // lets play nice and handle signals such as ctrl-c/kill properly
972
-		    //if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
973
-		    $error = false;
974
-		    //$SI::del();
975
-		    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
976
-		    // SBS format is CSV format
977
-		    if ($buffer != '') {
962
+			//$value = $formats[$nb];
963
+			$format = $globalSources[$nb]['format'];
964
+				if ($format == 'sbs' || $format == 'aprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') {
965
+				$buffer = socket_read($r, 6000,PHP_NORMAL_READ);
966
+				} else {
967
+					$az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port);
968
+				}
969
+				//$buffer = socket_read($r, 60000,PHP_NORMAL_READ);
970
+				//echo $buffer."\n";
971
+			// lets play nice and handle signals such as ctrl-c/kill properly
972
+			//if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
973
+			$error = false;
974
+			//$SI::del();
975
+			$buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer));
976
+			// SBS format is CSV format
977
+			if ($buffer != '') {
978 978
 			$tt[$format] = 0;
979 979
 			if ($format == 'acarssbs3') {
980
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
981
-			    $ACARS->add(trim($buffer));
982
-			    $ACARS->deleteLiveAcarsData();
980
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
981
+				$ACARS->add(trim($buffer));
982
+				$ACARS->deleteLiveAcarsData();
983 983
 			} elseif ($format == 'raw') {
984
-			    // AVR format
985
-			    $data = $SBS->parse($buffer);
986
-			    if (is_array($data)) {
984
+				// AVR format
985
+				$data = $SBS->parse($buffer);
986
+				if (is_array($data)) {
987 987
 				$data['datetime'] = date('Y-m-d H:i:s');
988 988
 				$data['format_source'] = 'raw';
989 989
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
990
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
991
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
992
-                            }
993
-                        } elseif ($format == 'ais') {
994
-			    $ais_data = $AIS->parse_line(trim($buffer));
995
-			    $data = array();
996
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
997
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
998
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
999
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1000
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1001
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1002
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1003
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1004
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1005
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
990
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
991
+								if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
992
+							}
993
+						} elseif ($format == 'ais') {
994
+				$ais_data = $AIS->parse_line(trim($buffer));
995
+				$data = array();
996
+				if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
997
+				if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
998
+				if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
999
+				if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1000
+				if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1001
+				if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1002
+				if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1003
+				if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1004
+				if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1005
+				if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1006 1006
 
1007
-			    if (isset($ais_data['timestamp'])) {
1007
+				if (isset($ais_data['timestamp'])) {
1008 1008
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
1009
-			    } else {
1009
+				} else {
1010 1010
 				$data['datetime'] = date('Y-m-d H:i:s');
1011
-			    }
1012
-			    $data['format_source'] = 'nmeatxt';
1013
-    			    $data['id_source'] = $id_source;
1014
-			    $MI->add($data);
1015
-			    unset($data);
1016
-                        } elseif ($format == 'flightgearsp') {
1017
-                    	    //echo $buffer."\n";
1018
-                    	    if (strlen($buffer) > 5) {
1011
+				}
1012
+				$data['format_source'] = 'nmeatxt';
1013
+					$data['id_source'] = $id_source;
1014
+				$MI->add($data);
1015
+				unset($data);
1016
+						} elseif ($format == 'flightgearsp') {
1017
+							//echo $buffer."\n";
1018
+							if (strlen($buffer) > 5) {
1019 1019
 				$line = explode(',',$buffer);
1020 1020
 				$data = array();
1021 1021
 				//XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p
@@ -1031,120 +1031,120 @@  discard block
 block discarded – undo
1031 1031
 				$data['format_source'] = 'flightgearsp';
1032 1032
 				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1033 1033
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1034
-			    }
1035
-                        } elseif ($format == 'acars') {
1036
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1037
-			    $ACARS->add(trim($buffer));
1038
-			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1039
-			    $ACARS->deleteLiveAcarsData();
1034
+				}
1035
+						} elseif ($format == 'acars') {
1036
+							if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1037
+				$ACARS->add(trim($buffer));
1038
+				socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1039
+				$ACARS->deleteLiveAcarsData();
1040 1040
 			} elseif ($format == 'flightgearmp') {
1041
-			    if (substr($buffer,0,1) != '#') {
1041
+				if (substr($buffer,0,1) != '#') {
1042 1042
 				$data = array();
1043 1043
 				//echo $buffer."\n";
1044 1044
 				$line = explode(' ',$buffer);
1045 1045
 				if (count($line) == 11) {
1046
-				    $userserver = explode('@',$line[0]);
1047
-				    $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1048
-				    $data['ident'] = $userserver[0];
1049
-				    $data['registration'] = $userserver[0];
1050
-				    $data['latitude'] = $line[4];
1051
-				    $data['longitude'] = $line[5];
1052
-				    $data['altitude'] = $line[6];
1053
-				    $data['datetime'] = date('Y-m-d H:i:s');
1054
-				    $aircraft_type = $line[10];
1055
-				    $aircraft_type = preg_split(':/:',$aircraft_type);
1056
-				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1057
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1046
+					$userserver = explode('@',$line[0]);
1047
+					$data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex
1048
+					$data['ident'] = $userserver[0];
1049
+					$data['registration'] = $userserver[0];
1050
+					$data['latitude'] = $line[4];
1051
+					$data['longitude'] = $line[5];
1052
+					$data['altitude'] = $line[6];
1053
+					$data['datetime'] = date('Y-m-d H:i:s');
1054
+					$aircraft_type = $line[10];
1055
+					$aircraft_type = preg_split(':/:',$aircraft_type);
1056
+					$data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1057
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1058
+				}
1058 1059
 				}
1059
-			    }
1060 1060
 			} elseif ($format == 'beast') {
1061
-			    echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1062
-			    die;
1061
+				echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n";
1062
+				die;
1063 1063
 			} elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') {
1064
-			    $line = explode("\t", $buffer);
1065
-			    for($k = 0; $k < count($line); $k=$k+2) {
1064
+				$line = explode("\t", $buffer);
1065
+				for($k = 0; $k < count($line); $k=$k+2) {
1066 1066
 				$key = $line[$k];
1067
-			        $lined[$key] = $line[$k+1];
1068
-			    }
1069
-    			    if (count($lined) > 3) {
1070
-    				$data['hex'] = $lined['hexid'];
1071
-    				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1072
-    				$data['datetime'] = date('Y-m-d H:i:s');;
1073
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1074
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1075
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1076
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1077
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1078
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1079
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1080
-    				$data['id_source'] = $id_source;
1081
-    				$data['format_source'] = 'tsv';
1082
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1083
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1084
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1085
-    				unset($lined);
1086
-    				unset($data);
1087
-    			    } else $error = true;
1067
+					$lined[$key] = $line[$k+1];
1068
+				}
1069
+					if (count($lined) > 3) {
1070
+					$data['hex'] = $lined['hexid'];
1071
+					//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1072
+					$data['datetime'] = date('Y-m-d H:i:s');;
1073
+					if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1074
+					if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1075
+					if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1076
+					if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1077
+					if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1078
+					if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1079
+					if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1080
+					$data['id_source'] = $id_source;
1081
+					$data['format_source'] = 'tsv';
1082
+					if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1083
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1084
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1085
+					unset($lined);
1086
+					unset($data);
1087
+					} else $error = true;
1088 1088
 			} elseif ($format == 'aprs' && $use_aprs) {
1089
-			    if ($aprs_connect == 0) {
1089
+				if ($aprs_connect == 0) {
1090 1090
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
1091 1091
 				$aprs_connect = 1;
1092
-			    }
1092
+				}
1093 1093
 			    
1094
-			    if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1094
+				if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) {
1095 1095
 				$aprs_last_tx = time();
1096 1096
 				$data_aprs = "# Keep alive";
1097 1097
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1098
-			    }
1098
+				}
1099 1099
 			    
1100
-			    //echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1101
-			    $buffer = str_replace('APRS <- ','',$buffer);
1102
-			    $buffer = str_replace('APRS -> ','',$buffer);
1103
-			    //echo $buffer."\n";
1104
-			    if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1100
+				//echo 'Connect : '.$aprs_connect.' '.$buffer."\n";
1101
+				$buffer = str_replace('APRS <- ','',$buffer);
1102
+				$buffer = str_replace('APRS -> ','',$buffer);
1103
+				//echo $buffer."\n";
1104
+				if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') {
1105 1105
 				$line = $APRS->parse($buffer);
1106 1106
 				//print_r($line);
1107 1107
 				//if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) {
1108 1108
 				if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && isset($line['ident'])) {
1109
-				    $aprs_last_tx = time();
1110
-				    $data = array();
1111
-				    //print_r($line);
1112
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1113
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1114
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1115
-				    //$data['datetime'] = date('Y-m-d H:i:s');
1116
-				    $data['ident'] = $line['ident'];
1117
-				    $data['latitude'] = $line['latitude'];
1118
-				    $data['longitude'] = $line['longitude'];
1119
-				    //$data['verticalrate'] = $line[16];
1120
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1121
-				    else $data['speed'] = 0;
1122
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1123
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1124
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1125
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1126
-				    //else $data['heading'] = 0;
1127
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1128
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1129
-    				    $data['id_source'] = $id_source;
1130
-				    $data['format_source'] = 'aprs';
1131
-				    $data['source_name'] = $line['source'];
1132
-				    $data['source_type'] = 'flarm';
1133
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1134
-				    $currentdate = date('Y-m-d H:i:s');
1135
-				    $aprsdate = strtotime($data['datetime']);
1136
-				    // Accept data if time <= system time + 20s
1137
-				    if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1109
+					$aprs_last_tx = time();
1110
+					$data = array();
1111
+					//print_r($line);
1112
+					if (isset($line['address'])) $data['hex'] = $line['address'];
1113
+					if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1114
+					else $data['datetime'] = date('Y-m-d H:i:s');
1115
+					//$data['datetime'] = date('Y-m-d H:i:s');
1116
+					$data['ident'] = $line['ident'];
1117
+					$data['latitude'] = $line['latitude'];
1118
+					$data['longitude'] = $line['longitude'];
1119
+					//$data['verticalrate'] = $line[16];
1120
+					if (isset($line['speed'])) $data['speed'] = $line['speed'];
1121
+					else $data['speed'] = 0;
1122
+					if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1123
+					if (isset($line['comment'])) $data['comment'] = $line['comment'];
1124
+					if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1125
+					if (isset($line['heading'])) $data['heading'] = $line['heading'];
1126
+					//else $data['heading'] = 0;
1127
+					if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1128
+					if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1129
+						$data['id_source'] = $id_source;
1130
+					$data['format_source'] = 'aprs';
1131
+					$data['source_name'] = $line['source'];
1132
+					$data['source_type'] = 'flarm';
1133
+						if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1134
+					$currentdate = date('Y-m-d H:i:s');
1135
+					$aprsdate = strtotime($data['datetime']);
1136
+					// Accept data if time <= system time + 20s
1137
+					if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1138 1138
 					$send = $SI->add($data);
1139
-				    } elseif (isset($line['stealth'])) {
1139
+					} elseif (isset($line['stealth'])) {
1140 1140
 					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1141 1141
 					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1142
-				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1143
-				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1142
+					//} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1143
+					} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1144 1144
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1145 1145
 					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1146
-				    }
1147
-				    unset($data);
1146
+					}
1147
+					unset($data);
1148 1148
 				} 
1149 1149
 				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1150 1150
 					echo '!! Weather Station not yet supported'."\n";
@@ -1154,12 +1154,12 @@  discard block
 block discarded – undo
1154 1154
 				}
1155 1155
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
1156 1156
 				//elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n";
1157
-			    }
1157
+				}
1158 1158
 			} else {
1159
-			    $line = explode(',', $buffer);
1160
-    			    if (count($line) > 20) {
1161
-    			    	$data['hex'] = $line[4];
1162
-    				/*
1159
+				$line = explode(',', $buffer);
1160
+					if (count($line) > 20) {
1161
+						$data['hex'] = $line[4];
1162
+					/*
1163 1163
     				$data['datetime'] = $line[6].' '.$line[7];
1164 1164
     					date_default_timezone_set($globalTimezone);
1165 1165
     					$datetime = new DateTime($data['datetime']);
@@ -1167,29 +1167,29 @@  discard block
 block discarded – undo
1167 1167
     					$data['datetime'] = $datetime->format('Y-m-d H:i:s');
1168 1168
     					date_default_timezone_set('UTC');
1169 1169
     				*/
1170
-    				// Force datetime to current UTC datetime
1171
-    				date_default_timezone_set('UTC');
1172
-    				$data['datetime'] = date('Y-m-d H:i:s');
1173
-    				$data['ident'] = trim($line[10]);
1174
-    				$data['latitude'] = $line[14];
1175
-    				$data['longitude'] = $line[15];
1176
-    				$data['verticalrate'] = $line[16];
1177
-    				$data['emergency'] = $line[20];
1178
-    				$data['speed'] = $line[12];
1179
-    				$data['squawk'] = $line[17];
1180
-    				$data['altitude'] = $line[11];
1181
-    				$data['heading'] = $line[13];
1182
-    				$data['ground'] = $line[21];
1183
-    				$data['emergency'] = $line[19];
1184
-    				$data['format_source'] = 'sbs';
1170
+					// Force datetime to current UTC datetime
1171
+					date_default_timezone_set('UTC');
1172
+					$data['datetime'] = date('Y-m-d H:i:s');
1173
+					$data['ident'] = trim($line[10]);
1174
+					$data['latitude'] = $line[14];
1175
+					$data['longitude'] = $line[15];
1176
+					$data['verticalrate'] = $line[16];
1177
+					$data['emergency'] = $line[20];
1178
+					$data['speed'] = $line[12];
1179
+					$data['squawk'] = $line[17];
1180
+					$data['altitude'] = $line[11];
1181
+					$data['heading'] = $line[13];
1182
+					$data['ground'] = $line[21];
1183
+					$data['emergency'] = $line[19];
1184
+					$data['format_source'] = 'sbs';
1185 1185
 				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1186
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1187
-    				$data['id_source'] = $id_source;
1188
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1189
-    				else $error = true;
1190
-    				unset($data);
1191
-    			    } else $error = true;
1192
-			    if ($error) {
1186
+					if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1187
+					$data['id_source'] = $id_source;
1188
+					if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1189
+					else $error = true;
1190
+					unset($data);
1191
+					} else $error = true;
1192
+				if ($error) {
1193 1193
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1194 1194
 					if ($globalDebug) echo "Not a message. Ignoring... \n";
1195 1195
 				} else {
@@ -1205,13 +1205,13 @@  discard block
 block discarded – undo
1205 1205
 					connect_all($sourceer);
1206 1206
 					$sourceer = array();
1207 1207
 				}
1208
-			    }
1208
+				}
1209 1209
 			}
1210 1210
 			// Sleep for xxx microseconds
1211 1211
 			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1212
-		    } else {
1212
+			} else {
1213 1213
 			if ($format == 'flightgearmp') {
1214
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1214
+					if ($globalDebug) echo "Reconnect FlightGear MP...";
1215 1215
 				//@socket_close($r);
1216 1216
 				sleep($globalMinFetch);
1217 1217
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1220,9 +1220,9 @@  discard block
 block discarded – undo
1220 1220
 				break;
1221 1221
 				
1222 1222
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1223
-			    if (isset($tt[$format])) $tt[$format]++;
1224
-			    else $tt[$format] = 0;
1225
-			    if ($tt[$format] > 30) {
1223
+				if (isset($tt[$format])) $tt[$format]++;
1224
+				else $tt[$format] = 0;
1225
+				if ($tt[$format] > 30) {
1226 1226
 				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1227 1227
 				//@socket_close($r);
1228 1228
 				sleep(2);
@@ -1233,23 +1233,23 @@  discard block
 block discarded – undo
1233 1233
 				//connect_all($globalSources);
1234 1234
 				$tt[$format]=0;
1235 1235
 				break;
1236
-			    }
1236
+				}
1237
+			}
1237 1238
 			}
1238
-		    }
1239 1239
 		}
1240
-	    } else {
1240
+		} else {
1241 1241
 		$error = socket_strerror(socket_last_error());
1242 1242
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1243 1243
 			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1244 1244
 			if (isset($globalDebug)) echo "Restarting...\n";
1245 1245
 			// Restart the script if possible
1246 1246
 			if (is_array($sockets)) {
1247
-			    if ($globalDebug) echo "Shutdown all sockets...";
1247
+				if ($globalDebug) echo "Shutdown all sockets...";
1248 1248
 			    
1249
-			    foreach ($sockets as $sock) {
1249
+				foreach ($sockets as $sock) {
1250 1250
 				@socket_shutdown($sock,2);
1251 1251
 				@socket_close($sock);
1252
-			    }
1252
+				}
1253 1253
 			    
1254 1254
 			}
1255 1255
 			if ($globalDebug) echo "Restart all connections...";
@@ -1260,13 +1260,13 @@  discard block
 block discarded – undo
1260 1260
 			if ($reset > 40) exit('Too many attempts...');
1261 1261
 			connect_all($globalSources);
1262 1262
 		}
1263
-	    }
1263
+		}
1264 1264
 	}
1265 1265
 	if ($globalDaemon === false) {
1266
-	    if ($globalDebug) echo 'Check all...'."\n";
1267
-	    $SI->checkAll();
1266
+		if ($globalDebug) echo 'Check all...'."\n";
1267
+		$SI->checkAll();
1268
+	}
1268 1269
 	}
1269
-    }
1270 1270
 }
1271 1271
 
1272 1272
 ?>
Please login to merge, or discard this patch.
Braces   +681 added lines, -235 removed lines patch added patch discarded remove patch
@@ -13,13 +13,17 @@  discard block
 block discarded – undo
13 13
 require_once(dirname(__FILE__).'/../require/class.SBS.php');
14 14
 require_once(dirname(__FILE__).'/../require/class.Connection.php');
15 15
 require_once(dirname(__FILE__).'/../require/class.Common.php');
16
-if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
16
+if (isset($globalTracker) && $globalTracker) {
17
+	require_once(dirname(__FILE__).'/../require/class.TrackerImport.php');
18
+}
17 19
 if (isset($globalMarine) && $globalMarine) {
18 20
     require_once(dirname(__FILE__).'/../require/class.AIS.php');
19 21
     require_once(dirname(__FILE__).'/../require/class.MarineImport.php');
20 22
 }
21 23
 
22
-if (!isset($globalDebug)) $globalDebug = FALSE;
24
+if (!isset($globalDebug)) {
25
+	$globalDebug = FALSE;
26
+}
23 27
 
24 28
 // Check if schema is at latest version
25 29
 $Connection = new Connection();
@@ -59,14 +63,25 @@  discard block
 block discarded – undo
59 63
     $globalSources = array();
60 64
     $globalSources[] = array('host' => $options['source']);
61 65
 }
62
-if (isset($options['server'])) $globalServer = TRUE;
63
-if (isset($options['idsource'])) $id_source = $options['idsource'];
64
-else $id_source = 1;
66
+if (isset($options['server'])) {
67
+	$globalServer = TRUE;
68
+}
69
+if (isset($options['idsource'])) {
70
+	$id_source = $options['idsource'];
71
+} else {
72
+	$id_source = 1;
73
+}
65 74
 if (isset($globalServer) && $globalServer) {
66
-    if ($globalDebug) echo "Using Server Mode\n";
75
+    if ($globalDebug) {
76
+    	echo "Using Server Mode\n";
77
+    }
67 78
     $SI=new SpotterServer();
68
-} else $SI=new SpotterImport($Connection->db);
69
-if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db);
79
+} else {
80
+	$SI=new SpotterImport($Connection->db);
81
+}
82
+if (isset($globalTracker) && $globalTracker) {
83
+	$TI = new TrackerImport($Connection->db);
84
+}
70 85
 if (isset($globalMarine) && $globalMarine) {
71 86
     $AIS = new AIS();
72 87
     $MI = new MarineImport($Connection->db);
@@ -88,7 +103,9 @@  discard block
 block discarded – undo
88 103
 }
89 104
 
90 105
 // let's try and connect
91
-if ($globalDebug) echo "Connecting...\n";
106
+if ($globalDebug) {
107
+	echo "Connecting...\n";
108
+}
92 109
 $use_aprs = false;
93 110
 $aprs_full = false;
94 111
 $reset = 0;
@@ -97,7 +114,9 @@  discard block
 block discarded – undo
97 114
     $ip = gethostbyname($host);
98 115
     $s = socket_create(AF_INET, SOCK_STREAM, 0);
99 116
     $r = @socket_connect($s, $ip, $port);
100
-    if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
117
+    if (!socket_set_nonblock($s)) {
118
+    	echo "Unable to set nonblock on socket\n";
119
+    }
101 120
     if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
102 121
         return $s;
103 122
     }
@@ -125,7 +144,9 @@  discard block
 block discarded – undo
125 144
     //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs;
126 145
     global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context;
127 146
     $reset++;
128
-    if ($globalDebug) echo 'Connect to all...'."\n";
147
+    if ($globalDebug) {
148
+    	echo 'Connect to all...'."\n";
149
+    }
129 150
     foreach ($hosts as $id => $value) {
130 151
 	$host = $value['host'];
131 152
 	$globalSources[$id]['last_exec'] = 0;
@@ -135,27 +156,37 @@  discard block
 block discarded – undo
135 156
         	//$formats[$id] = 'deltadbtxt';
136 157
         	$globalSources[$id]['format'] = 'deltadbtxt';
137 158
         	//$last_exec['deltadbtxt'] = 0;
138
-        	if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n";
159
+        	if ($globalDebug) {
160
+        		echo "Connect to deltadb source (".$host.")...\n";
161
+        	}
139 162
             } else if (preg_match('/vatsim-data.txt$/i',$host)) {
140 163
         	//$formats[$id] = 'vatsimtxt';
141 164
         	$globalSources[$id]['format'] = 'vatsimtxt';
142 165
         	//$last_exec['vatsimtxt'] = 0;
143
-        	if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n";
166
+        	if ($globalDebug) {
167
+        		echo "Connect to vatsim source (".$host.")...\n";
168
+        	}
144 169
     	    } else if (preg_match('/aircraftlist.json$/i',$host)) {
145 170
         	//$formats[$id] = 'aircraftlistjson';
146 171
         	$globalSources[$id]['format'] = 'aircraftlistjson';
147 172
         	//$last_exec['aircraftlistjson'] = 0;
148
-        	if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n";
173
+        	if ($globalDebug) {
174
+        		echo "Connect to aircraftlist.json source (".$host.")...\n";
175
+        	}
149 176
     	    } else if (preg_match('/opensky/i',$host)) {
150 177
         	//$formats[$id] = 'aircraftlistjson';
151 178
         	$globalSources[$id]['format'] = 'opensky';
152 179
         	//$last_exec['aircraftlistjson'] = 0;
153
-        	if ($globalDebug) echo "Connect to opensky source (".$host.")...\n";
180
+        	if ($globalDebug) {
181
+        		echo "Connect to opensky source (".$host.")...\n";
182
+        	}
154 183
     	    } else if (preg_match('/radarvirtuel.com\/file.json$/i',$host)) {
155 184
         	//$formats[$id] = 'radarvirtueljson';
156 185
         	$globalSources[$id]['format'] = 'radarvirtueljson';
157 186
         	//$last_exec['radarvirtueljson'] = 0;
158
-        	if ($globalDebug) echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
187
+        	if ($globalDebug) {
188
+        		echo "Connect to radarvirtuel.com/file.json source (".$host.")...\n";
189
+        	}
159 190
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
160 191
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
161 192
         	    exit(0);
@@ -164,7 +195,9 @@  discard block
 block discarded – undo
164 195
         	//$formats[$id] = 'planeupdatefaa';
165 196
         	$globalSources[$id]['format'] = 'planeupdatefaa';
166 197
         	//$last_exec['planeupdatefaa'] = 0;
167
-        	if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
198
+        	if ($globalDebug) {
199
+        		echo "Connect to planeUpdateFAA.php source (".$host.")...\n";
200
+        	}
168 201
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
169 202
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
170 203
         	    exit(0);
@@ -173,26 +206,36 @@  discard block
 block discarded – undo
173 206
         	//$formats[$id] = 'phpvmacars';
174 207
         	$globalSources[$id]['format'] = 'phpvmacars';
175 208
         	//$last_exec['phpvmacars'] = 0;
176
-        	if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n";
209
+        	if ($globalDebug) {
210
+        		echo "Connect to phpvmacars source (".$host.")...\n";
211
+        	}
177 212
             } else if (preg_match('/VAM-json.php$/i',$host)) {
178 213
         	//$formats[$id] = 'phpvmacars';
179 214
         	$globalSources[$id]['format'] = 'vam';
180
-        	if ($globalDebug) echo "Connect to Vam source (".$host.")...\n";
215
+        	if ($globalDebug) {
216
+        		echo "Connect to Vam source (".$host.")...\n";
217
+        	}
181 218
             } else if (preg_match('/whazzup/i',$host)) {
182 219
         	//$formats[$id] = 'whazzup';
183 220
         	$globalSources[$id]['format'] = 'whazzup';
184 221
         	//$last_exec['whazzup'] = 0;
185
-        	if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n";
222
+        	if ($globalDebug) {
223
+        		echo "Connect to whazzup source (".$host.")...\n";
224
+        	}
186 225
             } else if (preg_match('/recentpireps/i',$host)) {
187 226
         	//$formats[$id] = 'pirepsjson';
188 227
         	$globalSources[$id]['format'] = 'pirepsjson';
189 228
         	//$last_exec['pirepsjson'] = 0;
190
-        	if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n";
229
+        	if ($globalDebug) {
230
+        		echo "Connect to pirepsjson source (".$host.")...\n";
231
+        	}
191 232
             } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) {
192 233
         	//$formats[$id] = 'fr24json';
193 234
         	$globalSources[$id]['format'] = 'fr24json';
194 235
         	//$last_exec['fr24json'] = 0;
195
-        	if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n";
236
+        	if ($globalDebug) {
237
+        		echo "Connect to fr24 source (".$host.")...\n";
238
+        	}
196 239
         	if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) {
197 240
         	    echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n";
198 241
         	    exit(0);
@@ -201,17 +244,24 @@  discard block
 block discarded – undo
201 244
             } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) {
202 245
         	//$formats[$id] = 'tsv';
203 246
         	$globalSources[$id]['format'] = 'tsv';
204
-        	if ($globalDebug) echo "Connect to tsv source (".$host.")...\n";
247
+        	if ($globalDebug) {
248
+        		echo "Connect to tsv source (".$host.")...\n";
249
+        	}
205 250
             }
206 251
         } elseif (filter_var($host,FILTER_VALIDATE_URL)) {
207 252
     		if ($globalSources[$id]['format'] == 'aisnmeahttp') {
208 253
     		    $idf = fopen($globalSources[$id]['host'],'r',false,$context);
209 254
     		    if ($idf !== false) {
210 255
     			$httpfeeds[$id] = $idf;
211
-        		if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
256
+        		if ($globalDebug) {
257
+        			echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n";
258
+        		}
259
+    		    } elseif ($globalDebug) {
260
+    		    	echo "Can't connect to ".$globalSources[$id]['host']."\n";
212 261
     		    }
213
-    		    elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n";
214
-    		} elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
262
+    		} elseif ($globalDebug) {
263
+    			echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n";
264
+    		}
215 265
         } elseif (!filter_var($host,FILTER_VALIDATE_URL)) {
216 266
 	    $hostport = explode(':',$host);
217 267
 	    if (isset($hostport[1])) {
@@ -248,17 +298,25 @@  discard block
 block discarded – undo
248 298
         		//$formats[$id] = 'beast';
249 299
         		$globalSources[$id]['format'] = 'beast';
250 300
 		    //} else $formats[$id] = 'sbs';
251
-		    } else $globalSources[$id]['format'] = 'sbs';
301
+		    } else {
302
+		    	$globalSources[$id]['format'] = 'sbs';
303
+		    }
252 304
 		    //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n";
253 305
 		}
254
-		if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
306
+		if ($globalDebug) {
307
+			echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n";
308
+		}
255 309
             } else {
256
-		if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
310
+		if ($globalDebug) {
311
+			echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n";
312
+		}
257 313
     	    }
258 314
         }
259 315
     }
260 316
 }
261
-if (!isset($globalMinFetch)) $globalMinFetch = 15;
317
+if (!isset($globalMinFetch)) {
318
+	$globalMinFetch = 15;
319
+}
262 320
 
263 321
 // Initialize all
264 322
 $status = array();
@@ -267,13 +325,19 @@  discard block
 block discarded – undo
267 325
 $formats = array();
268 326
 $last_exec = array();
269 327
 $time = time();
270
-if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut;
271
-else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut;
272
-else $timeout = 20;
328
+if (isset($globalSourcesTimeout)) {
329
+	$timeout = $globalSourcesTimeOut;
330
+} else if (isset($globalSBS1TimeOut)) {
331
+	$timeout = $globalSBS1TimeOut;
332
+} else {
333
+	$timeout = 20;
334
+}
273 335
 $errno = '';
274 336
 $errstr='';
275 337
 
276
-if (!isset($globalDaemon)) $globalDaemon = TRUE;
338
+if (!isset($globalDaemon)) {
339
+	$globalDaemon = TRUE;
340
+}
277 341
 /* Initiate connections to all the hosts simultaneously */
278 342
 //connect_all($hosts);
279 343
 //connect_all($globalSources);
@@ -299,7 +363,9 @@  discard block
 block discarded – undo
299 363
     if (isset($source['format']) && $source['format'] == 'aprs') {
300 364
 	$aprs_connect = 0;
301 365
 	$use_aprs = true;
302
-	if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true;
366
+	if (isset($source['port']) && $source['port'] == '10152') {
367
+		$aprs_full = true;
368
+	}
303 369
 	break;
304 370
     }
305 371
 }
@@ -310,23 +376,43 @@  discard block
 block discarded – undo
310 376
 	$aprs_connect = 0;
311 377
 	$aprs_keep = 120;
312 378
 	$aprs_last_tx = time();
313
-	if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion;
314
-	else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
315
-	if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid;
316
-	else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
317
-	if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter;
318
-	else $aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
319
-	if ($aprs_full) $aprs_filter = '';
379
+	if (isset($globalAPRSversion)) {
380
+		$aprs_version = $globalAPRSversion;
381
+	} else {
382
+		$aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName);
383
+	}
384
+	if (isset($globalAPRSssid)) {
385
+		$aprs_ssid = $globalAPRSssid;
386
+	} else {
387
+		$aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8);
388
+	}
389
+	if (isset($globalAPRSfilter)) {
390
+		$aprs_filter = $globalAPRSfilter;
391
+	} else {
392
+		$aprs_filter =  'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0';
393
+	}
394
+	if ($aprs_full) {
395
+		$aprs_filter = '';
396
+	}
320 397
 
321
-	if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n";
322
-	else $aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n";
323
-}
398
+	if ($aprs_filter != '') {
399
+		$aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version} filter {$aprs_filter}\n";
400
+	} else {
401
+		$aprs_login = "user {$aprs_ssid} pass -1 vers {$aprs_version}\n";
402
+	}
403
+	}
324 404
 
325 405
 // connected - lets do some work
326
-if ($globalDebug) echo "Connected!\n";
406
+if ($globalDebug) {
407
+	echo "Connected!\n";
408
+}
327 409
 sleep(1);
328
-if ($globalDebug) echo "SCAN MODE \n\n";
329
-if (!isset($globalCronEnd)) $globalCronEnd = 60;
410
+if ($globalDebug) {
411
+	echo "SCAN MODE \n\n";
412
+}
413
+if (!isset($globalCronEnd)) {
414
+	$globalCronEnd = 60;
415
+}
330 416
 $endtime = time()+$globalCronEnd;
331 417
 $i = 1;
332 418
 $tt = array();
@@ -340,10 +426,14 @@  discard block
 block discarded – undo
340 426
 
341 427
 // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time.
342 428
 while ($i > 0) {
343
-    if (!$globalDaemon) $i = $endtime-time();
429
+    if (!$globalDaemon) {
430
+    	$i = $endtime-time();
431
+    }
344 432
     // Delete old ATC
345 433
     if ($globalDaemon && ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) {
346
-	if ($globalDebug) echo 'Delete old ATC...'."\n";
434
+	if ($globalDebug) {
435
+		echo 'Delete old ATC...'."\n";
436
+	}
347 437
         $ATC->deleteOldATC();
348 438
     }
349 439
     
@@ -351,10 +441,14 @@  discard block
 block discarded – undo
351 441
     if (count($last_exec) == count($globalSources)) {
352 442
 	$max = $globalMinFetch;
353 443
 	foreach ($last_exec as $last) {
354
-	    if ((time() - $last['last']) < $max) $max = time() - $last['last'];
444
+	    if ((time() - $last['last']) < $max) {
445
+	    	$max = time() - $last['last'];
446
+	    }
355 447
 	}
356 448
 	if ($max != $globalMinFetch) {
357
-	    if ($globalDebug) echo 'Sleeping...'."\n";
449
+	    if ($globalDebug) {
450
+	    	echo 'Sleeping...'."\n";
451
+	    }
358 452
 	    sleep($globalMinFetch-$max+2);
359 453
 	}
360 454
     }
@@ -363,11 +457,15 @@  discard block
 block discarded – undo
363 457
     //foreach ($formats as $id => $value) {
364 458
     foreach ($globalSources as $id => $value) {
365 459
 	date_default_timezone_set('UTC');
366
-	if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0;
460
+	if (!isset($last_exec[$id]['last'])) {
461
+		$last_exec[$id]['last'] = 0;
462
+	}
367 463
 	if ($value['format'] == 'deltadbtxt' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
368 464
 	    //$buffer = $Common->getData($hosts[$id]);
369 465
 	    $buffer = $Common->getData($value['host']);
370
-	    if ($buffer != '') $reset = 0;
466
+	    if ($buffer != '') {
467
+	    	$reset = 0;
468
+	    }
371 469
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
372 470
 	    $buffer = explode('\n',$buffer);
373 471
 	    foreach ($buffer as $line) {
@@ -376,19 +474,38 @@  discard block
 block discarded – undo
376 474
 	            $data = array();
377 475
 	            $data['hex'] = $line[1]; // hex
378 476
 	            $data['ident'] = $line[2]; // ident
379
-	            if (isset($line[3])) $data['altitude'] = $line[3]; // altitude
380
-	            if (isset($line[4])) $data['speed'] = $line[4]; // speed
381
-	            if (isset($line[5])) $data['heading'] = $line[5]; // heading
382
-	            if (isset($line[6])) $data['latitude'] = $line[6]; // lat
383
-	            if (isset($line[7])) $data['longitude'] = $line[7]; // long
477
+	            if (isset($line[3])) {
478
+	            	$data['altitude'] = $line[3];
479
+	            }
480
+	            // altitude
481
+	            if (isset($line[4])) {
482
+	            	$data['speed'] = $line[4];
483
+	            }
484
+	            // speed
485
+	            if (isset($line[5])) {
486
+	            	$data['heading'] = $line[5];
487
+	            }
488
+	            // heading
489
+	            if (isset($line[6])) {
490
+	            	$data['latitude'] = $line[6];
491
+	            }
492
+	            // lat
493
+	            if (isset($line[7])) {
494
+	            	$data['longitude'] = $line[7];
495
+	            }
496
+	            // long
384 497
 	            $data['verticalrate'] = ''; // vertical rate
385 498
 	            //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk
386 499
 	            $data['emergency'] = ''; // emergency
387 500
 		    $data['datetime'] = date('Y-m-d H:i:s');
388 501
 		    $data['format_source'] = 'deltadbtxt';
389 502
     		    $data['id_source'] = $id_source;
390
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
391
-		    if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats'];
503
+		    if (isset($value['name']) && $value['name'] != '') {
504
+		    	$data['source_name'] = $value['name'];
505
+		    }
506
+		    if (isset($value['sourcestats'])) {
507
+		    	$data['sourcestats'] = $value['sourcestats'];
508
+		    }
392 509
     		    $SI->add($data);
393 510
 		    unset($data);
394 511
     		}
@@ -398,7 +515,9 @@  discard block
 block discarded – undo
398 515
 	    date_default_timezone_set('CET');
399 516
 	    $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host']));
400 517
 	    date_default_timezone_set('UTC');
401
-	    if ($buffer != '') $reset = 0;
518
+	    if ($buffer != '') {
519
+	    	$reset = 0;
520
+	    }
402 521
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
403 522
 	    $buffer = explode('\n',$buffer);
404 523
 	    foreach ($buffer as $line) {
@@ -407,16 +526,36 @@  discard block
 block discarded – undo
407 526
 		    $add = false;
408 527
 		    $ais_data = $AIS->parse_line(trim($line));
409 528
 		    $data = array();
410
-		    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
411
-		    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
412
-		    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
413
-		    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
414
-		    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
415
-		    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
416
-		    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
417
-		    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
418
-		    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
419
-		    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
529
+		    if (isset($ais_data['ident'])) {
530
+		    	$data['ident'] = $ais_data['ident'];
531
+		    }
532
+		    if (isset($ais_data['mmsi'])) {
533
+		    	$data['mmsi'] = $ais_data['mmsi'];
534
+		    }
535
+		    if (isset($ais_data['speed'])) {
536
+		    	$data['speed'] = $ais_data['speed'];
537
+		    }
538
+		    if (isset($ais_data['heading'])) {
539
+		    	$data['heading'] = $ais_data['heading'];
540
+		    }
541
+		    if (isset($ais_data['latitude'])) {
542
+		    	$data['latitude'] = $ais_data['latitude'];
543
+		    }
544
+		    if (isset($ais_data['longitude'])) {
545
+		    	$data['longitude'] = $ais_data['longitude'];
546
+		    }
547
+		    if (isset($ais_data['status'])) {
548
+		    	$data['status'] = $ais_data['status'];
549
+		    }
550
+		    if (isset($ais_data['type'])) {
551
+		    	$data['type'] = $ais_data['type'];
552
+		    }
553
+		    if (isset($ais_data['imo'])) {
554
+		    	$data['imo'] = $ais_data['imo'];
555
+		    }
556
+		    if (isset($ais_data['callsign'])) {
557
+		    	$data['callsign'] = $ais_data['callsign'];
558
+		    }
420 559
 		    if (isset($ais_data['timestamp'])) {
421 560
 			$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
422 561
 			if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) {
@@ -431,7 +570,9 @@  discard block
 block discarded – undo
431 570
     		    $data['id_source'] = $id_source;
432 571
 		    print_r($data);
433 572
 		    echo 'Add...'."\n";
434
-		    if ($add) $MI->add($data);
573
+		    if ($add) {
574
+		    	$MI->add($data);
575
+		    }
435 576
 		    unset($data);
436 577
 		}
437 578
     	    }
@@ -451,16 +592,36 @@  discard block
 block discarded – undo
451 592
 			if ($line != '') {
452 593
 			    $ais_data = $AIS->parse_line(trim($line));
453 594
 			    $data = array();
454
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
455
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
456
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
457
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
458
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
459
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
460
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
461
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
462
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
463
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
595
+			    if (isset($ais_data['ident'])) {
596
+			    	$data['ident'] = $ais_data['ident'];
597
+			    }
598
+			    if (isset($ais_data['mmsi'])) {
599
+			    	$data['mmsi'] = $ais_data['mmsi'];
600
+			    }
601
+			    if (isset($ais_data['speed'])) {
602
+			    	$data['speed'] = $ais_data['speed'];
603
+			    }
604
+			    if (isset($ais_data['heading'])) {
605
+			    	$data['heading'] = $ais_data['heading'];
606
+			    }
607
+			    if (isset($ais_data['latitude'])) {
608
+			    	$data['latitude'] = $ais_data['latitude'];
609
+			    }
610
+			    if (isset($ais_data['longitude'])) {
611
+			    	$data['longitude'] = $ais_data['longitude'];
612
+			    }
613
+			    if (isset($ais_data['status'])) {
614
+			    	$data['status'] = $ais_data['status'];
615
+			    }
616
+			    if (isset($ais_data['type'])) {
617
+			    	$data['type'] = $ais_data['type'];
618
+			    }
619
+			    if (isset($ais_data['imo'])) {
620
+			    	$data['imo'] = $ais_data['imo'];
621
+			    }
622
+			    if (isset($ais_data['callsign'])) {
623
+			    	$data['callsign'] = $ais_data['callsign'];
624
+			    }
464 625
 			    if (isset($ais_data['timestamp'])) {
465 626
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
466 627
 			    } else {
@@ -479,7 +640,9 @@  discard block
 block discarded – undo
479 640
 	    echo 'download...';
480 641
 	    $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter');
481 642
 	    echo 'done !'."\n";
482
-	    if ($buffer != '') $reset = 0;
643
+	    if ($buffer != '') {
644
+	    	$reset = 0;
645
+	    }
483 646
     	    $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer));
484 647
 	    $buffer = explode('\n',$buffer);
485 648
 	    foreach ($buffer as $line) {
@@ -523,16 +686,28 @@  discard block
 block discarded – undo
523 686
     		    $line = explode(':', $line);
524 687
     		    if (count($line) > 30 && $line[0] != 'callsign') {
525 688
 			$data = array();
526
-			if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
527
-			else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
689
+			if (isset($line[37]) && $line[37] != '') {
690
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37];
691
+			} else {
692
+				$data['id'] = $value['format'].'-'.$line[1].'-'.$line[0];
693
+			}
528 694
 			$data['pilot_id'] = $line[1];
529 695
 			$data['pilot_name'] = $line[2];
530 696
 			$data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT);
531 697
 			$data['ident'] = $line[0]; // ident
532
-			if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude
698
+			if ($line[7] != '' && $line[7] != 0) {
699
+				$data['altitude'] = $line[7];
700
+			}
701
+			// altitude
533 702
 			$data['speed'] = $line[8]; // speed
534
-			if (isset($line[45])) $data['heading'] = $line[45]; // heading
535
-			elseif (isset($line[38])) $data['heading'] = $line[38]; // heading
703
+			if (isset($line[45])) {
704
+				$data['heading'] = $line[45];
705
+			}
706
+			// heading
707
+			elseif (isset($line[38])) {
708
+				$data['heading'] = $line[38];
709
+			}
710
+			// heading
536 711
 			$data['latitude'] = $line[5]; // lat
537 712
 	        	$data['longitude'] = $line[6]; // long
538 713
 	        	$data['verticalrate'] = ''; // vertical rate
@@ -548,7 +723,9 @@  discard block
 block discarded – undo
548 723
 			$data['frequency'] = $line[4];
549 724
 			$data['type'] = $line[18];
550 725
 			$data['range'] = $line[19];
551
-			if (isset($line[35])) $data['info'] = $line[35];
726
+			if (isset($line[35])) {
727
+				$data['info'] = $line[35];
728
+			}
552 729
     			$data['id_source'] = $id_source;
553 730
 	    		//$data['arrival_airport_time'] = ;
554 731
 	    		if ($line[9] != '') {
@@ -562,24 +739,41 @@  discard block
 block discarded – undo
562 739
 	    		elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt';
563 740
 	    		*/
564 741
 	    		$data['format_source'] = $value['format'];
565
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
566
-    			if ($line[3] == 'PILOT') $SI->add($data);
567
-			elseif ($line[3] == 'ATC') {
742
+			if (isset($value['name']) && $value['name'] != '') {
743
+				$data['source_name'] = $value['name'];
744
+			}
745
+    			if ($line[3] == 'PILOT') {
746
+    				$SI->add($data);
747
+    			} elseif ($line[3] == 'ATC') {
568 748
 				//print_r($data);
569 749
 				$data['info'] = str_replace('^&sect;','<br />',$data['info']);
570 750
 				$data['info'] = str_replace('&amp;sect;','',$data['info']);
571 751
 				$typec = substr($data['ident'],-3);
572
-				if ($typec == 'APP') $data['type'] = 'Approach';
573
-				elseif ($typec == 'TWR') $data['type'] = 'Tower';
574
-				elseif ($typec == 'OBS') $data['type'] = 'Observer';
575
-				elseif ($typec == 'GND') $data['type'] = 'Ground';
576
-				elseif ($typec == 'DEL') $data['type'] = 'Delivery';
577
-				elseif ($typec == 'DEP') $data['type'] = 'Departure';
578
-				elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
579
-				elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
580
-				elseif ($data['type'] == '') $data['type'] = 'Observer';
581
-				if (!isset($data['source_name'])) $data['source_name'] = '';
582
-				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']);
752
+				if ($typec == 'APP') {
753
+					$data['type'] = 'Approach';
754
+				} elseif ($typec == 'TWR') {
755
+					$data['type'] = 'Tower';
756
+				} elseif ($typec == 'OBS') {
757
+					$data['type'] = 'Observer';
758
+				} elseif ($typec == 'GND') {
759
+					$data['type'] = 'Ground';
760
+				} elseif ($typec == 'DEL') {
761
+					$data['type'] = 'Delivery';
762
+				} elseif ($typec == 'DEP') {
763
+					$data['type'] = 'Departure';
764
+				} elseif ($typec == 'FSS') {
765
+					$data['type'] = 'Flight Service Station';
766
+				} elseif ($typec == 'CTR') {
767
+					$data['type'] = 'Control Radar or Centre';
768
+				} elseif ($data['type'] == '') {
769
+					$data['type'] = 'Observer';
770
+				}
771
+				if (!isset($data['source_name'])) {
772
+					$data['source_name'] = '';
773
+				}
774
+				if (isset($ATC)) {
775
+					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']);
776
+				}
583 777
 			}
584 778
     			unset($data);
585 779
     		    }
@@ -598,26 +792,55 @@  discard block
 block discarded – undo
598 792
 		foreach ($all_data['acList'] as $line) {
599 793
 		    $data = array();
600 794
 		    $data['hex'] = $line['Icao']; // hex
601
-		    if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident
602
-		    if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude
603
-		    if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed
604
-		    if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading
605
-		    if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat
606
-		    if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long
795
+		    if (isset($line['Call'])) {
796
+		    	$data['ident'] = $line['Call'];
797
+		    }
798
+		    // ident
799
+		    if (isset($line['Alt'])) {
800
+		    	$data['altitude'] = $line['Alt'];
801
+		    }
802
+		    // altitude
803
+		    if (isset($line['Spd'])) {
804
+		    	$data['speed'] = $line['Spd'];
805
+		    }
806
+		    // speed
807
+		    if (isset($line['Trak'])) {
808
+		    	$data['heading'] = $line['Trak'];
809
+		    }
810
+		    // heading
811
+		    if (isset($line['Lat'])) {
812
+		    	$data['latitude'] = $line['Lat'];
813
+		    }
814
+		    // lat
815
+		    if (isset($line['Long'])) {
816
+		    	$data['longitude'] = $line['Long'];
817
+		    }
818
+		    // long
607 819
 		    //$data['verticalrate'] = $line['']; // verticale rate
608
-		    if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk
820
+		    if (isset($line['Sqk'])) {
821
+		    	$data['squawk'] = $line['Sqk'];
822
+		    }
823
+		    // squawk
609 824
 		    $data['emergency'] = ''; // emergency
610
-		    if (isset($line['Reg'])) $data['registration'] = $line['Reg'];
825
+		    if (isset($line['Reg'])) {
826
+		    	$data['registration'] = $line['Reg'];
827
+		    }
611 828
 		    /*
612 829
 		    if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000);
613 830
 		    else $data['datetime'] = date('Y-m-d H:i:s');
614 831
 		    */
615 832
 		    $data['datetime'] = date('Y-m-d H:i:s');
616
-		    if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type'];
833
+		    if (isset($line['Type'])) {
834
+		    	$data['aircraft_icao'] = $line['Type'];
835
+		    }
617 836
 	    	    $data['format_source'] = 'aircraftlistjson';
618 837
 		    $data['id_source'] = $id_source;
619
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
620
-		    if (isset($data['datetime'])) $SI->add($data);
838
+		    if (isset($value['name']) && $value['name'] != '') {
839
+		    	$data['source_name'] = $value['name'];
840
+		    }
841
+		    if (isset($data['datetime'])) {
842
+		    	$SI->add($data);
843
+		    }
621 844
 		    unset($data);
622 845
 		}
623 846
 	    } else {
@@ -637,7 +860,9 @@  discard block
 block discarded – undo
637 860
 		    $data['datetime'] = date('Y-m-d H:i:s');
638 861
 	    	    $data['format_source'] = 'aircraftlistjson';
639 862
     		    $data['id_source'] = $id_source;
640
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
863
+		    if (isset($value['name']) && $value['name'] != '') {
864
+		    	$data['source_name'] = $value['name'];
865
+		    }
641 866
 		    $SI->add($data);
642 867
 		    unset($data);
643 868
 		}
@@ -673,7 +898,9 @@  discard block
 block discarded – undo
673 898
 		    $data['datetime'] = date('Y-m-d H:i:s',$line[9]);
674 899
 	    	    $data['format_source'] = 'planeupdatefaa';
675 900
     		    $data['id_source'] = $id_source;
676
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
901
+		    if (isset($value['name']) && $value['name'] != '') {
902
+		    	$data['source_name'] = $value['name'];
903
+		    }
677 904
 		    $SI->add($data);
678 905
 		    unset($data);
679 906
 		}
@@ -713,7 +940,9 @@  discard block
 block discarded – undo
713 940
 	    //$buffer = $Common->getData($hosts[$id]);
714 941
 	    $buffer = $Common->getData($value['host']);
715 942
 	    $all_data = json_decode($buffer,true);
716
-	    if (!empty($all_data)) $reset = 0;
943
+	    if (!empty($all_data)) {
944
+	    	$reset = 0;
945
+	    }
717 946
 	    foreach ($all_data as $key => $line) {
718 947
 		if ($key != 'full_count' && $key != 'version' && $key != 'stats') {
719 948
 		    $data = array();
@@ -734,7 +963,9 @@  discard block
 block discarded – undo
734 963
 		    $data['datetime'] = date('Y-m-d H:i:s'); //$line[10]
735 964
 	    	    $data['format_source'] = 'fr24json';
736 965
     		    $data['id_source'] = $id_source;
737
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
966
+		    if (isset($value['name']) && $value['name'] != '') {
967
+		    	$data['source_name'] = $value['name'];
968
+		    }
738 969
 		    $SI->add($data);
739 970
 		    unset($data);
740 971
 		}
@@ -758,23 +989,39 @@  discard block
 block discarded – undo
758 989
 		    if (isset($line['inf'])) {
759 990
 			$data = array();
760 991
 			$data['hex'] = $line['inf']['ia'];
761
-			if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13]
992
+			if (isset($line['inf']['cs'])) {
993
+				$data['ident'] = $line['inf']['cs'];
994
+			}
995
+			//$line[13]
762 996
 	    		$data['altitude'] = round($line['inf']['al']*3.28084); // altitude
763
-	    		if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed
764
-	    		if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading
997
+	    		if (isset($line['inf']['gs'])) {
998
+	    			$data['speed'] = round($line['inf']['gs']*0.539957);
999
+	    		}
1000
+	    		// speed
1001
+	    		if (isset($line['inf']['tr'])) {
1002
+	    			$data['heading'] = $line['inf']['tr'];
1003
+	    		}
1004
+	    		// heading
765 1005
 	    		$data['latitude'] = $line['pt'][0]; // lat
766 1006
 	    		$data['longitude'] = $line['pt'][1]; // long
767 1007
 	    		//if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate
768
-	    		if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk
1008
+	    		if (isset($line['inf']['sq'])) {
1009
+	    			$data['squawk'] = $line['inf']['sq'];
1010
+	    		}
1011
+	    		// squawk
769 1012
 	    		//$data['aircraft_icao'] = $line[8];
770
-	    		if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc'];
1013
+	    		if (isset($line['inf']['rc'])) {
1014
+	    			$data['registration'] = $line['inf']['rc'];
1015
+	    		}
771 1016
 			//$data['departure_airport_iata'] = $line[11];
772 1017
 			//$data['arrival_airport_iata'] = $line[12];
773 1018
 	    		//$data['emergency'] = ''; // emergency
774 1019
 			$data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10]
775 1020
 	    		$data['format_source'] = 'radarvirtueljson';
776 1021
     			$data['id_source'] = $id_source;
777
-			if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1022
+			if (isset($value['name']) && $value['name'] != '') {
1023
+				$data['source_name'] = $value['name'];
1024
+			}
778 1025
 			$SI->add($data);
779 1026
 			unset($data);
780 1027
 		    }
@@ -795,29 +1042,62 @@  discard block
 block discarded – undo
795 1042
 		    $data['id'] = $line['id'];
796 1043
 		    $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6);
797 1044
 		    $data['ident'] = $line['callsign']; // ident
798
-		    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id
799
-		    if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name
800
-		    if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude
801
-		    if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed
802
-		    if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading
803
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1045
+		    if (isset($line['pilotid'])) {
1046
+		    	$data['pilot_id'] = $line['pilotid'];
1047
+		    }
1048
+		    // pilot id
1049
+		    if (isset($line['name'])) {
1050
+		    	$data['pilot_name'] = $line['name'];
1051
+		    }
1052
+		    // pilot name
1053
+		    if (isset($line['alt'])) {
1054
+		    	$data['altitude'] = $line['alt'];
1055
+		    }
1056
+		    // altitude
1057
+		    if (isset($line['gs'])) {
1058
+		    	$data['speed'] = $line['gs'];
1059
+		    }
1060
+		    // speed
1061
+		    if (isset($line['heading'])) {
1062
+		    	$data['heading'] = $line['heading'];
1063
+		    }
1064
+		    // heading
1065
+		    if (isset($line['route'])) {
1066
+		    	$data['waypoints'] = $line['route'];
1067
+		    }
1068
+		    // route
804 1069
 		    $data['latitude'] = $line['lat']; // lat
805 1070
 		    $data['longitude'] = $line['lon']; // long
806 1071
 		    //$data['verticalrate'] = $line['vrt']; // verticale rate
807 1072
 		    //$data['squawk'] = $line['squawk']; // squawk
808 1073
 		    //$data['emergency'] = ''; // emergency
809
-		    if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao'];
810
-		    if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime'];
811
-		    if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao'];
1074
+		    if (isset($line['depicao'])) {
1075
+		    	$data['departure_airport_icao'] = $line['depicao'];
1076
+		    }
1077
+		    if (isset($line['deptime'])) {
1078
+		    	$data['departure_airport_time'] = $line['deptime'];
1079
+		    }
1080
+		    if (isset($line['arricao'])) {
1081
+		    	$data['arrival_airport_icao'] = $line['arricao'];
1082
+		    }
812 1083
 		    //$data['arrival_airport_time'] = $line['arrtime'];
813
-		    if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft'];
814
-		    if (isset($line['transponder'])) $data['squawk'] = $line['transponder'];
815
-		    if (isset($line['atis'])) $data['info'] = $line['atis'];
816
-		    else $data['info'] = '';
1084
+		    if (isset($line['aircraft'])) {
1085
+		    	$data['aircraft_icao'] = $line['aircraft'];
1086
+		    }
1087
+		    if (isset($line['transponder'])) {
1088
+		    	$data['squawk'] = $line['transponder'];
1089
+		    }
1090
+		    if (isset($line['atis'])) {
1091
+		    	$data['info'] = $line['atis'];
1092
+		    } else {
1093
+		    	$data['info'] = '';
1094
+		    }
817 1095
 		    $data['format_source'] = 'pireps';
818 1096
     		    $data['id_source'] = $id_source;
819 1097
 		    $data['datetime'] = date('Y-m-d H:i:s');
820
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1098
+		    if (isset($value['name']) && $value['name'] != '') {
1099
+		    	$data['source_name'] = $value['name'];
1100
+		    }
821 1101
 		    if ($line['icon'] == 'plane') {
822 1102
 			$SI->add($data);
823 1103
 		    //    print_r($data);
@@ -826,16 +1106,28 @@  discard block
 block discarded – undo
826 1106
 			$data['info'] = str_replace('&amp;sect;','',$data['info']);
827 1107
 			$typec = substr($data['ident'],-3);
828 1108
 			$data['type'] = '';
829
-			if ($typec == 'APP') $data['type'] = 'Approach';
830
-			elseif ($typec == 'TWR') $data['type'] = 'Tower';
831
-			elseif ($typec == 'OBS') $data['type'] = 'Observer';
832
-			elseif ($typec == 'GND') $data['type'] = 'Ground';
833
-			elseif ($typec == 'DEL') $data['type'] = 'Delivery';
834
-			elseif ($typec == 'DEP') $data['type'] = 'Departure';
835
-			elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station';
836
-			elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre';
837
-			else $data['type'] = 'Observer';
838
-			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']);
1109
+			if ($typec == 'APP') {
1110
+				$data['type'] = 'Approach';
1111
+			} elseif ($typec == 'TWR') {
1112
+				$data['type'] = 'Tower';
1113
+			} elseif ($typec == 'OBS') {
1114
+				$data['type'] = 'Observer';
1115
+			} elseif ($typec == 'GND') {
1116
+				$data['type'] = 'Ground';
1117
+			} elseif ($typec == 'DEL') {
1118
+				$data['type'] = 'Delivery';
1119
+			} elseif ($typec == 'DEP') {
1120
+				$data['type'] = 'Departure';
1121
+			} elseif ($typec == 'FSS') {
1122
+				$data['type'] = 'Flight Service Station';
1123
+			} elseif ($typec == 'CTR') {
1124
+				$data['type'] = 'Control Radar or Centre';
1125
+			} else {
1126
+				$data['type'] = 'Observer';
1127
+			}
1128
+			if (isset($ATC)) {
1129
+				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']);
1130
+			}
839 1131
 		    }
840 1132
 		    unset($data);
841 1133
 		}
@@ -845,7 +1137,9 @@  discard block
 block discarded – undo
845 1137
     	//} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) {
846 1138
     	} elseif ($value['format'] == 'phpvmacars' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
847 1139
 	    //$buffer = $Common->getData($hosts[$id]);
848
-	    if ($globalDebug) echo 'Get Data...'."\n";
1140
+	    if ($globalDebug) {
1141
+	    	echo 'Get Data...'."\n";
1142
+	    }
849 1143
 	    $buffer = $Common->getData($value['host']);
850 1144
 	    $all_data = json_decode($buffer,true);
851 1145
 	    if ($buffer != '' && is_array($all_data)) {
@@ -853,10 +1147,16 @@  discard block
 block discarded – undo
853 1147
 		foreach ($all_data as $line) {
854 1148
 	    	    $data = array();
855 1149
 	    	    //$data['id'] = $line['id']; // id not usable
856
-	    	    if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum'];
1150
+	    	    if (isset($line['pilotid'])) {
1151
+	    	    	$data['id'] = $line['pilotid'].$line['flightnum'];
1152
+	    	    }
857 1153
 	    	    $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex
858
-	    	    if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname'];
859
-	    	    if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid'];
1154
+	    	    if (isset($line['pilotname'])) {
1155
+	    	    	$data['pilot_name'] = $line['pilotname'];
1156
+	    	    }
1157
+	    	    if (isset($line['pilotid'])) {
1158
+	    	    	$data['pilot_id'] = $line['pilotid'];
1159
+	    	    }
860 1160
 	    	    $data['ident'] = $line['flightnum']; // ident
861 1161
 	    	    $data['altitude'] = $line['alt']; // altitude
862 1162
 	    	    $data['speed'] = $line['gs']; // speed
@@ -874,27 +1174,41 @@  discard block
 block discarded – undo
874 1174
 	    	    $data['arrival_airport_icao'] = $line['arricao'];
875 1175
     		    $data['arrival_airport_time'] = $line['arrtime'];
876 1176
     		    $data['registration'] = $line['aircraft'];
877
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1177
+		    if (isset($line['route'])) {
1178
+		    	$data['waypoints'] = $line['route'];
1179
+		    }
1180
+		    // route
878 1181
 		    if (isset($line['aircraftname'])) {
879 1182
 			$line['aircraftname'] = strtoupper($line['aircraftname']);
880 1183
 			$line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']);
881 1184
 	    		$aircraft_data = explode('-',$line['aircraftname']);
882
-	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) $data['aircraft_icao'] = $aircraft_data[0];
883
-	    		elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) $data['aircraft_icao'] = $aircraft_data[1];
884
-	    		else {
1185
+	    		if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) < 5) {
1186
+	    			$data['aircraft_icao'] = $aircraft_data[0];
1187
+	    		} elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) < 5) {
1188
+	    			$data['aircraft_icao'] = $aircraft_data[1];
1189
+	    		} else {
885 1190
 	    		    $aircraft_data = explode(' ',$line['aircraftname']);
886
-	    		    if (isset($aircraft_data[1])) $data['aircraft_icao'] = $aircraft_data[1];
887
-	    		    else $data['aircraft_icao'] = $line['aircraftname'];
1191
+	    		    if (isset($aircraft_data[1])) {
1192
+	    		    	$data['aircraft_icao'] = $aircraft_data[1];
1193
+	    		    } else {
1194
+	    		    	$data['aircraft_icao'] = $line['aircraftname'];
1195
+	    		    }
888 1196
 	    		}
889 1197
 	    	    }
890
-    		    if (isset($line['route'])) $data['waypoints'] = $line['route'];
1198
+    		    if (isset($line['route'])) {
1199
+    		    	$data['waypoints'] = $line['route'];
1200
+    		    }
891 1201
     		    $data['id_source'] = $id_source;
892 1202
 	    	    $data['format_source'] = 'phpvmacars';
893
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1203
+		    if (isset($value['name']) && $value['name'] != '') {
1204
+		    	$data['source_name'] = $value['name'];
1205
+		    }
894 1206
 		    $SI->add($data);
895 1207
 		    unset($data);
896 1208
 		}
897
-		if ($globalDebug) echo 'No more data...'."\n";
1209
+		if ($globalDebug) {
1210
+			echo 'No more data...'."\n";
1211
+		}
898 1212
 		unset($buffer);
899 1213
 		unset($all_data);
900 1214
 	    }
@@ -902,7 +1216,9 @@  discard block
 block discarded – undo
902 1216
     	    $last_exec[$id]['last'] = time();
903 1217
     	} elseif ($value['format'] == 'vam' && (time() - $last_exec[$id]['last'] > $globalMinFetch)) {
904 1218
 	    //$buffer = $Common->getData($hosts[$id]);
905
-	    if ($globalDebug) echo 'Get Data...'."\n";
1219
+	    if ($globalDebug) {
1220
+	    	echo 'Get Data...'."\n";
1221
+	    }
906 1222
 	    $buffer = $Common->getData($value['host']);
907 1223
 	    $all_data = json_decode($buffer,true);
908 1224
 	    if ($buffer != '' && is_array($all_data)) {
@@ -931,15 +1247,22 @@  discard block
 block discarded – undo
931 1247
 	    	    $data['arrival_airport_icao'] = $line['arrival'];
932 1248
     		    //$data['arrival_airport_time'] = $line['arrival_time'];
933 1249
     		    //$data['registration'] = $line['aircraft'];
934
-		    if (isset($line['route'])) $data['waypoints'] = $line['route']; // route
1250
+		    if (isset($line['route'])) {
1251
+		    	$data['waypoints'] = $line['route'];
1252
+		    }
1253
+		    // route
935 1254
 	    	    $data['aircraft_icao'] = $line['plane_type'];
936 1255
     		    $data['id_source'] = $id_source;
937 1256
 	    	    $data['format_source'] = 'vam';
938
-		    if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name'];
1257
+		    if (isset($value['name']) && $value['name'] != '') {
1258
+		    	$data['source_name'] = $value['name'];
1259
+		    }
939 1260
 		    $SI->add($data);
940 1261
 		    unset($data);
941 1262
 		}
942
-		if ($globalDebug) echo 'No more data...'."\n";
1263
+		if ($globalDebug) {
1264
+			echo 'No more data...'."\n";
1265
+		}
943 1266
 		unset($buffer);
944 1267
 		unset($all_data);
945 1268
 	    }
@@ -947,7 +1270,9 @@  discard block
 block discarded – undo
947 1270
     	    $last_exec[$id]['last'] = time();
948 1271
 	//} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') {
949 1272
 	} 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' || $value['format'] == 'ais') {
950
-	    if (function_exists('pcntl_fork')) pcntl_signal_dispatch();
1273
+	    if (function_exists('pcntl_fork')) {
1274
+	    	pcntl_signal_dispatch();
1275
+	    }
951 1276
     	    //$last_exec[$id]['last'] = time();
952 1277
 
953 1278
 	    //$read = array( $sockets[$id] );
@@ -955,7 +1280,9 @@  discard block
 block discarded – undo
955 1280
 	    $write = NULL;
956 1281
 	    $e = NULL;
957 1282
 	    $n = socket_select($read, $write, $e, $timeout);
958
-	    if ($e != NULL) var_dump($e);
1283
+	    if ($e != NULL) {
1284
+	    	var_dump($e);
1285
+	    }
959 1286
 	    if ($n > 0) {
960 1287
 		$reset = 0;
961 1288
 		foreach ($read as $nb => $r) {
@@ -977,7 +1304,9 @@  discard block
 block discarded – undo
977 1304
 		    if ($buffer != '') {
978 1305
 			$tt[$format] = 0;
979 1306
 			if ($format == 'acarssbs3') {
980
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1307
+                    	    if ($globalDebug) {
1308
+                    	    	echo 'ACARS : '.$buffer."\n";
1309
+                    	    }
981 1310
 			    $ACARS->add(trim($buffer));
982 1311
 			    $ACARS->deleteLiveAcarsData();
983 1312
 			} elseif ($format == 'raw') {
@@ -986,23 +1315,49 @@  discard block
 block discarded – undo
986 1315
 			    if (is_array($data)) {
987 1316
 				$data['datetime'] = date('Y-m-d H:i:s');
988 1317
 				$data['format_source'] = 'raw';
989
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
990
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
991
-                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1318
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1319
+					$data['source_name'] = $globalSources[$nb]['name'];
1320
+				}
1321
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1322
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1323
+    				}
1324
+                                if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1325
+                                	$SI->add($data);
1326
+                                }
992 1327
                             }
993 1328
                         } elseif ($format == 'ais') {
994 1329
 			    $ais_data = $AIS->parse_line(trim($buffer));
995 1330
 			    $data = array();
996
-			    if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident'];
997
-			    if (isset($ais_data['mmsi'])) $data['mmsi'] = $ais_data['mmsi'];
998
-			    if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed'];
999
-			    if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading'];
1000
-			    if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude'];
1001
-			    if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude'];
1002
-			    if (isset($ais_data['status'])) $data['status'] = $ais_data['status'];
1003
-			    if (isset($ais_data['type'])) $data['type'] = $ais_data['type'];
1004
-			    if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo'];
1005
-			    if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign'];
1331
+			    if (isset($ais_data['ident'])) {
1332
+			    	$data['ident'] = $ais_data['ident'];
1333
+			    }
1334
+			    if (isset($ais_data['mmsi'])) {
1335
+			    	$data['mmsi'] = $ais_data['mmsi'];
1336
+			    }
1337
+			    if (isset($ais_data['speed'])) {
1338
+			    	$data['speed'] = $ais_data['speed'];
1339
+			    }
1340
+			    if (isset($ais_data['heading'])) {
1341
+			    	$data['heading'] = $ais_data['heading'];
1342
+			    }
1343
+			    if (isset($ais_data['latitude'])) {
1344
+			    	$data['latitude'] = $ais_data['latitude'];
1345
+			    }
1346
+			    if (isset($ais_data['longitude'])) {
1347
+			    	$data['longitude'] = $ais_data['longitude'];
1348
+			    }
1349
+			    if (isset($ais_data['status'])) {
1350
+			    	$data['status'] = $ais_data['status'];
1351
+			    }
1352
+			    if (isset($ais_data['type'])) {
1353
+			    	$data['type'] = $ais_data['type'];
1354
+			    }
1355
+			    if (isset($ais_data['imo'])) {
1356
+			    	$data['imo'] = $ais_data['imo'];
1357
+			    }
1358
+			    if (isset($ais_data['callsign'])) {
1359
+			    	$data['callsign'] = $ais_data['callsign'];
1360
+			    }
1006 1361
 
1007 1362
 			    if (isset($ais_data['timestamp'])) {
1008 1363
 				$data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']);
@@ -1029,11 +1384,15 @@  discard block
 block discarded – undo
1029 1384
 				$data['speed'] = round($line[5]*1.94384);
1030 1385
 				$data['datetime'] = date('Y-m-d H:i:s');
1031 1386
 				$data['format_source'] = 'flightgearsp';
1032
-				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1387
+				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1388
+					$SI->add($data);
1389
+				}
1033 1390
 				$send = @ socket_send( $r  , $data_aprs , strlen($data_aprs) , 0 );
1034 1391
 			    }
1035 1392
                         } elseif ($format == 'acars') {
1036
-                    	    if ($globalDebug) echo 'ACARS : '.$buffer."\n";
1393
+                    	    if ($globalDebug) {
1394
+                    	    	echo 'ACARS : '.$buffer."\n";
1395
+                    	    }
1037 1396
 			    $ACARS->add(trim($buffer));
1038 1397
 			    socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port);
1039 1398
 			    $ACARS->deleteLiveAcarsData();
@@ -1054,7 +1413,9 @@  discard block
 block discarded – undo
1054 1413
 				    $aircraft_type = $line[10];
1055 1414
 				    $aircraft_type = preg_split(':/:',$aircraft_type);
1056 1415
 				    $data['aircraft_name'] = substr(end($aircraft_type),0,-4);
1057
-				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1416
+				    if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1417
+				    	$SI->add($data);
1418
+				    }
1058 1419
 				}
1059 1420
 			    }
1060 1421
 			} elseif ($format == 'beast') {
@@ -1070,21 +1431,43 @@  discard block
 block discarded – undo
1070 1431
     				$data['hex'] = $lined['hexid'];
1071 1432
     				//$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));;
1072 1433
     				$data['datetime'] = date('Y-m-d H:i:s');;
1073
-    				if (isset($lined['ident'])) $data['ident'] = $lined['ident'];
1074
-    				if (isset($lined['lat'])) $data['latitude'] = $lined['lat'];
1075
-    				if (isset($lined['lon'])) $data['longitude'] = $lined['lon'];
1076
-    				if (isset($lined['speed'])) $data['speed'] = $lined['speed'];
1077
-    				if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk'];
1078
-    				if (isset($lined['alt'])) $data['altitude'] = $lined['alt'];
1079
-    				if (isset($lined['heading'])) $data['heading'] = $lined['heading'];
1434
+    				if (isset($lined['ident'])) {
1435
+    					$data['ident'] = $lined['ident'];
1436
+    				}
1437
+    				if (isset($lined['lat'])) {
1438
+    					$data['latitude'] = $lined['lat'];
1439
+    				}
1440
+    				if (isset($lined['lon'])) {
1441
+    					$data['longitude'] = $lined['lon'];
1442
+    				}
1443
+    				if (isset($lined['speed'])) {
1444
+    					$data['speed'] = $lined['speed'];
1445
+    				}
1446
+    				if (isset($lined['squawk'])) {
1447
+    					$data['squawk'] = $lined['squawk'];
1448
+    				}
1449
+    				if (isset($lined['alt'])) {
1450
+    					$data['altitude'] = $lined['alt'];
1451
+    				}
1452
+    				if (isset($lined['heading'])) {
1453
+    					$data['heading'] = $lined['heading'];
1454
+    				}
1080 1455
     				$data['id_source'] = $id_source;
1081 1456
     				$data['format_source'] = 'tsv';
1082
-    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1083
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1084
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data);
1457
+    				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1458
+    					$data['source_name'] = $globalSources[$nb]['name'];
1459
+    				}
1460
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1461
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1462
+    				}
1463
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1464
+    					$SI->add($data);
1465
+    				}
1085 1466
     				unset($lined);
1086 1467
     				unset($data);
1087
-    			    } else $error = true;
1468
+    			    } else {
1469
+    			    	$error = true;
1470
+    			    }
1088 1471
 			} elseif ($format == 'aprs' && $use_aprs) {
1089 1472
 			    if ($aprs_connect == 0) {
1090 1473
 				$send = @ socket_send( $r  , $aprs_login , strlen($aprs_login) , 0 );
@@ -1109,47 +1492,72 @@  discard block
 block discarded – undo
1109 1492
 				    $aprs_last_tx = time();
1110 1493
 				    $data = array();
1111 1494
 				    //print_r($line);
1112
-				    if (isset($line['address'])) $data['hex'] = $line['address'];
1113
-				    if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1114
-				    else $data['datetime'] = date('Y-m-d H:i:s');
1495
+				    if (isset($line['address'])) {
1496
+				    	$data['hex'] = $line['address'];
1497
+				    }
1498
+				    if (isset($line['timestamp'])) {
1499
+				    	$data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']);
1500
+				    } else {
1501
+				    	$data['datetime'] = date('Y-m-d H:i:s');
1502
+				    }
1115 1503
 				    //$data['datetime'] = date('Y-m-d H:i:s');
1116 1504
 				    $data['ident'] = $line['ident'];
1117 1505
 				    $data['latitude'] = $line['latitude'];
1118 1506
 				    $data['longitude'] = $line['longitude'];
1119 1507
 				    //$data['verticalrate'] = $line[16];
1120
-				    if (isset($line['speed'])) $data['speed'] = $line['speed'];
1121
-				    else $data['speed'] = 0;
1122
-				    if (isset($line['altitude'])) $data['altitude'] = $line['altitude'];
1123
-				    if (isset($line['comment'])) $data['comment'] = $line['comment'];
1124
-				    if (isset($line['symbol'])) $data['type'] = $line['symbol'];
1125
-				    if (isset($line['heading'])) $data['heading'] = $line['heading'];
1508
+				    if (isset($line['speed'])) {
1509
+				    	$data['speed'] = $line['speed'];
1510
+				    } else {
1511
+				    	$data['speed'] = 0;
1512
+				    }
1513
+				    if (isset($line['altitude'])) {
1514
+				    	$data['altitude'] = $line['altitude'];
1515
+				    }
1516
+				    if (isset($line['comment'])) {
1517
+				    	$data['comment'] = $line['comment'];
1518
+				    }
1519
+				    if (isset($line['symbol'])) {
1520
+				    	$data['type'] = $line['symbol'];
1521
+				    }
1522
+				    if (isset($line['heading'])) {
1523
+				    	$data['heading'] = $line['heading'];
1524
+				    }
1126 1525
 				    //else $data['heading'] = 0;
1127
-				    if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth'];
1128
-				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) $data['noarchive'] = true;
1526
+				    if (isset($line['stealth'])) {
1527
+				    	$data['aircraft_type'] = $line['stealth'];
1528
+				    }
1529
+				    if (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive == FALSE)) {
1530
+				    	$data['noarchive'] = true;
1531
+				    }
1129 1532
     				    $data['id_source'] = $id_source;
1130 1533
 				    $data['format_source'] = 'aprs';
1131 1534
 				    $data['source_name'] = $line['source'];
1132 1535
 				    $data['source_type'] = 'flarm';
1133
-    				    if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1536
+    				    if (isset($globalSources[$nb]['sourcestats'])) {
1537
+    				    	$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1538
+    				    }
1134 1539
 				    $currentdate = date('Y-m-d H:i:s');
1135 1540
 				    $aprsdate = strtotime($data['datetime']);
1136 1541
 				    // Accept data if time <= system time + 20s
1137 1542
 				    if (isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) {
1138 1543
 					$send = $SI->add($data);
1139 1544
 				    } elseif (isset($line['stealth'])) {
1140
-					if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1141
-					else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1545
+					if ($line['stealth'] != 0) {
1546
+						echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n";
1547
+					} else {
1548
+						echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n";
1549
+					}
1142 1550
 				    //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle' || $line['symbol'] == 'Police' || $line['symbol'] == 'Bike' || $line['symbol'] == 'Jogger' || $line['symbol'] == 'Bus' || $line['symbol'] == 'Jeep' || $line['symbol'] == 'Recreational Vehicle' || $line['symbol'] == 'Yacht (Sail)' || $line['symbol'] == 'Ship (Power Boat)' || $line['symbol'] == 'Firetruck' || $line['symbol'] == 'Balloon' || $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) {
1143 1551
 				    } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') {
1144 1552
 					//echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n";
1145
-					if (isset($globalTracker) && $globalTracker) $send = $TI->add($data);
1553
+					if (isset($globalTracker) && $globalTracker) {
1554
+						$send = $TI->add($data);
1555
+					}
1146 1556
 				    }
1147 1557
 				    unset($data);
1148
-				} 
1149
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1558
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && $line['symbol'] == 'Weather Station') {
1150 1559
 					echo '!! Weather Station not yet supported'."\n";
1151
-				}
1152
-				elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1560
+				} elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) {
1153 1561
 					echo '!! Car & Trucks not yet supported'."\n";
1154 1562
 				}
1155 1563
 				//elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n";
@@ -1182,25 +1590,42 @@  discard block
 block discarded – undo
1182 1590
     				$data['ground'] = $line[21];
1183 1591
     				$data['emergency'] = $line[19];
1184 1592
     				$data['format_source'] = 'sbs';
1185
-				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name'];
1186
-    				if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1593
+				if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') {
1594
+					$data['source_name'] = $globalSources[$nb]['name'];
1595
+				}
1596
+    				if (isset($globalSources[$nb]['sourcestats'])) {
1597
+    					$data['sourcestats'] = $globalSources[$nb]['sourcestats'];
1598
+    				}
1187 1599
     				$data['id_source'] = $id_source;
1188
-    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data);
1189
-    				else $error = true;
1600
+    				if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) {
1601
+    					$send = $SI->add($data);
1602
+    				} else {
1603
+    					$error = true;
1604
+    				}
1190 1605
     				unset($data);
1191
-    			    } else $error = true;
1606
+    			    } else {
1607
+    			    	$error = true;
1608
+    			    }
1192 1609
 			    if ($error) {
1193 1610
 				if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { 
1194
-					if ($globalDebug) echo "Not a message. Ignoring... \n";
1611
+					if ($globalDebug) {
1612
+						echo "Not a message. Ignoring... \n";
1613
+					}
1195 1614
 				} else {
1196
-					if ($globalDebug) echo "Wrong line format. Ignoring... \n";
1615
+					if ($globalDebug) {
1616
+						echo "Wrong line format. Ignoring... \n";
1617
+					}
1197 1618
 					if ($globalDebug) {
1198 1619
 						echo $buffer;
1199 1620
 						print_r($line);
1200 1621
 					}
1201 1622
 					//socket_close($r);
1202
-					if ($globalDebug) echo "Reconnect after an error...\n";
1203
-					if ($format == 'aprs') $aprs_connect = 0;
1623
+					if ($globalDebug) {
1624
+						echo "Reconnect after an error...\n";
1625
+					}
1626
+					if ($format == 'aprs') {
1627
+						$aprs_connect = 0;
1628
+					}
1204 1629
 					$sourceer[$nb] = $globalSources[$nb];
1205 1630
 					connect_all($sourceer);
1206 1631
 					$sourceer = array();
@@ -1208,10 +1633,14 @@  discard block
 block discarded – undo
1208 1633
 			    }
1209 1634
 			}
1210 1635
 			// Sleep for xxx microseconds
1211
-			if (isset($globalSBSSleep)) usleep($globalSBSSleep);
1636
+			if (isset($globalSBSSleep)) {
1637
+				usleep($globalSBSSleep);
1638
+			}
1212 1639
 		    } else {
1213 1640
 			if ($format == 'flightgearmp') {
1214
-			    	if ($globalDebug) echo "Reconnect FlightGear MP...";
1641
+			    	if ($globalDebug) {
1642
+			    		echo "Reconnect FlightGear MP...";
1643
+			    	}
1215 1644
 				//@socket_close($r);
1216 1645
 				sleep($globalMinFetch);
1217 1646
 				$sourcefg[$nb] = $globalSources[$nb];
@@ -1220,10 +1649,15 @@  discard block
 block discarded – undo
1220 1649
 				break;
1221 1650
 				
1222 1651
 			} elseif ($format != 'acars' && $format != 'flightgearsp') {
1223
-			    if (isset($tt[$format])) $tt[$format]++;
1224
-			    else $tt[$format] = 0;
1652
+			    if (isset($tt[$format])) {
1653
+			    	$tt[$format]++;
1654
+			    } else {
1655
+			    	$tt[$format] = 0;
1656
+			    }
1225 1657
 			    if ($tt[$format] > 30) {
1226
-				if ($globalDebug) echo "ERROR : Reconnect ".$format."...";
1658
+				if ($globalDebug) {
1659
+					echo "ERROR : Reconnect ".$format."...";
1660
+				}
1227 1661
 				//@socket_close($r);
1228 1662
 				sleep(2);
1229 1663
 				$aprs_connect = 0;
@@ -1240,11 +1674,17 @@  discard block
 block discarded – undo
1240 1674
 	    } else {
1241 1675
 		$error = socket_strerror(socket_last_error());
1242 1676
 		if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) {
1243
-			if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n";
1244
-			if (isset($globalDebug)) echo "Restarting...\n";
1677
+			if ($globalDebug) {
1678
+				echo "ERROR : socket_select give this error ".$error . "\n";
1679
+			}
1680
+			if (isset($globalDebug)) {
1681
+				echo "Restarting...\n";
1682
+			}
1245 1683
 			// Restart the script if possible
1246 1684
 			if (is_array($sockets)) {
1247
-			    if ($globalDebug) echo "Shutdown all sockets...";
1685
+			    if ($globalDebug) {
1686
+			    	echo "Shutdown all sockets...";
1687
+			    }
1248 1688
 			    
1249 1689
 			    foreach ($sockets as $sock) {
1250 1690
 				@socket_shutdown($sock,2);
@@ -1252,18 +1692,24 @@  discard block
 block discarded – undo
1252 1692
 			    }
1253 1693
 			    
1254 1694
 			}
1255
-			if ($globalDebug) echo "Restart all connections...";
1695
+			if ($globalDebug) {
1696
+				echo "Restart all connections...";
1697
+			}
1256 1698
 			sleep(2);
1257 1699
 			$time = time();
1258 1700
 			//connect_all($hosts);
1259 1701
 			$aprs_connect = 0;
1260
-			if ($reset > 40) exit('Too many attempts...');
1702
+			if ($reset > 40) {
1703
+				exit('Too many attempts...');
1704
+			}
1261 1705
 			connect_all($globalSources);
1262 1706
 		}
1263 1707
 	    }
1264 1708
 	}
1265 1709
 	if ($globalDaemon === false) {
1266
-	    if ($globalDebug) echo 'Check all...'."\n";
1710
+	    if ($globalDebug) {
1711
+	    	echo 'Check all...'."\n";
1712
+	    }
1267 1713
 	    $SI->checkAll();
1268 1714
 	}
1269 1715
     }
Please login to merge, or discard this patch.
require/class.Marine.php 2 patches
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@  discard block
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	/**
16
-	* Get SQL query part for filter used
17
-	* @param Array $filter the filter
18
-	* @return Array the SQL part
19
-	*/
16
+	 * Get SQL query part for filter used
17
+	 * @param Array $filter the filter
18
+	 * @return Array the SQL part
19
+	 */
20 20
 	
21 21
 	public function getFilter($filter = array(),$where = false,$and = false) {
22 22
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 	}
81 81
 
82 82
 	/**
83
-	* Executes the SQL statements to get the spotter information
84
-	*
85
-	* @param String $query the SQL query
86
-	* @param Array $params parameter of the query
87
-	* @param String $limitQuery the limit query
88
-	* @return Array the spotter information
89
-	*
90
-	*/
83
+	 * Executes the SQL statements to get the spotter information
84
+	 *
85
+	 * @param String $query the SQL query
86
+	 * @param Array $params parameter of the query
87
+	 * @param String $limitQuery the limit query
88
+	 * @return Array the spotter information
89
+	 *
90
+	 */
91 91
 	public function getDataFromDB($query, $params = array(), $limitQuery = '',$schedules = false)
92 92
 	{
93 93
 		date_default_timezone_set('UTC');
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	
200 200
 	
201 201
 	/**
202
-	* Gets all the spotter information based on the latest data entry
203
-	*
204
-	* @return Array the spotter information
205
-	*
206
-	*/
202
+	 * Gets all the spotter information based on the latest data entry
203
+	 *
204
+	 * @return Array the spotter information
205
+	 *
206
+	 */
207 207
 	public function getLatestMarineData($limit = '', $sort = '', $filter = array())
208 208
 	{
209 209
 		global $global_query;
@@ -261,11 +261,11 @@  discard block
 block discarded – undo
261 261
 	}
262 262
 
263 263
 	/**
264
-	* Gets all the spotter information based on the callsign
265
-	*
266
-	* @return Array the spotter information
267
-	*
268
-	*/
264
+	 * Gets all the spotter information based on the callsign
265
+	 *
266
+	 * @return Array the spotter information
267
+	 *
268
+	 */
269 269
 	public function getMarineDataByIdent($ident = '', $limit = '', $sort = '', $filter = array())
270 270
 	{
271 271
 		global $global_query;
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
 
377 377
 
378 378
 	/**
379
-	* Gets all source name
380
-	*
381
-	* @param String type format of source
382
-	* @return Array list of source name
383
-	*
384
-	*/
379
+	 * Gets all source name
380
+	 *
381
+	 * @param String type format of source
382
+	 * @return Array list of source name
383
+	 *
384
+	 */
385 385
 	public function getAllSourceName($type = '',$filters = array())
386 386
 	{
387 387
 		$filter_query = $this->getFilter($filters,true,true);
@@ -411,11 +411,11 @@  discard block
 block discarded – undo
411 411
 
412 412
 
413 413
 	/**
414
-	* Gets a list of all idents/callsigns
415
-	*
416
-	* @return Array list of ident/callsign names
417
-	*
418
-	*/
414
+	 * Gets a list of all idents/callsigns
415
+	 *
416
+	 * @return Array list of ident/callsign names
417
+	 *
418
+	 */
419 419
 	public function getAllIdents($filters = array())
420 420
 	{
421 421
 		$filter_query = $this->getFilter($filters,true,true);
@@ -439,11 +439,11 @@  discard block
 block discarded – undo
439 439
 	}
440 440
 
441 441
 	/**
442
-	* Gets all info from a mmsi
443
-	*
444
-	* @return Array list of mmsi info
445
-	*
446
-	*/
442
+	 * Gets all info from a mmsi
443
+	 *
444
+	 * @return Array list of mmsi info
445
+	 *
446
+	 */
447 447
 	public function getIdentity($mmsi)
448 448
 	{
449 449
 		$mmsi = filter_var($mmsi,FILTER_SANITIZE_NUMBER_INT);
@@ -500,18 +500,18 @@  discard block
 block discarded – undo
500 500
 	
501 501
 	
502 502
 	/**
503
-	* Update ident tracker data
504
-	*
505
-	* @param String $fammarine_id the ID
506
-	* @param String $ident the marine ident
507
-	* @return String success or false
508
-	*
509
-	*/	
503
+	 * Update ident tracker data
504
+	 *
505
+	 * @param String $fammarine_id the ID
506
+	 * @param String $ident the marine ident
507
+	 * @return String success or false
508
+	 *
509
+	 */	
510 510
 	public function updateIdentMarineData($fammarine_id = '', $ident = '',$fromsource = NULL)
511 511
 	{
512 512
 
513 513
 		$query = 'UPDATE marine_output SET ident = :ident WHERE fammarine_id = :fammarine_id';
514
-                $query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
514
+				$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident);
515 515
 
516 516
 		try {
517 517
 			$sth = $this->db->prepare($query);
@@ -524,17 +524,17 @@  discard block
 block discarded – undo
524 524
 
525 525
 	}
526 526
 	/**
527
-	* Update latest marine data
528
-	*
529
-	* @param String $fammarine_id the ID
530
-	* @param String $ident the marine ident
531
-	* @return String success or false
532
-	*
533
-	*/	
527
+	 * Update latest marine data
528
+	 *
529
+	 * @param String $fammarine_id the ID
530
+	 * @param String $ident the marine ident
531
+	 * @return String success or false
532
+	 *
533
+	 */	
534 534
 	public function updateLatestMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $groundspeed = NULL, $date = '')
535 535
 	{
536 536
 		$query = 'UPDATE marine_output SET ident = :ident, last_latitude = :last_latitude, last_longitude = :last_longitude, last_seen = :last_seen, last_ground_speed = :last_ground_speed WHERE fammarine_id = :fammarine_id';
537
-                $query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
537
+				$query_values = array(':fammarine_id' => $fammarine_id,':last_latitude' => $latitude,':last_longitude' => $longitude, ':last_ground_speed' => $groundspeed,':last_seen' => $date,':ident' => $ident);
538 538
 
539 539
 		try {
540 540
 			$sth = $this->db->prepare($query);
@@ -548,30 +548,30 @@  discard block
 block discarded – undo
548 548
 	}
549 549
 
550 550
 	/**
551
-	* Adds a new spotter data
552
-	*
553
-	* @param String $fammarine_id the ID
554
-	* @param String $ident the marine ident
555
-	* @param String $departure_airport_icao the departure airport
556
-	* @param String $arrival_airport_icao the arrival airport
557
-	* @param String $latitude latitude of flight
558
-	* @param String $longitude latitude of flight
559
-	* @param String $waypoints waypoints of flight
560
-	* @param String $heading heading of flight
561
-	* @param String $groundspeed speed of flight
562
-	* @param String $date date of flight
563
-	* @param String $departure_airport_time departure time of flight
564
-	* @param String $arrival_airport_time arrival time of flight
565
-	* @param String $squawk squawk code of flight
566
-	* @param String $route_stop route stop of flight
567
-	* @param String $highlight highlight or not
568
-	* @param String $ModeS ModesS code of flight
569
-	* @param String $registration registration code of flight
570
-	* @param String $pilot_id pilot id of flight (for virtual airlines)
571
-	* @param String $pilot_name pilot name of flight (for virtual airlines)
572
-	* @param String $verticalrate vertival rate of flight
573
-	* @return String success or false
574
-	*/
551
+	 * Adds a new spotter data
552
+	 *
553
+	 * @param String $fammarine_id the ID
554
+	 * @param String $ident the marine ident
555
+	 * @param String $departure_airport_icao the departure airport
556
+	 * @param String $arrival_airport_icao the arrival airport
557
+	 * @param String $latitude latitude of flight
558
+	 * @param String $longitude latitude of flight
559
+	 * @param String $waypoints waypoints of flight
560
+	 * @param String $heading heading of flight
561
+	 * @param String $groundspeed speed of flight
562
+	 * @param String $date date of flight
563
+	 * @param String $departure_airport_time departure time of flight
564
+	 * @param String $arrival_airport_time arrival time of flight
565
+	 * @param String $squawk squawk code of flight
566
+	 * @param String $route_stop route stop of flight
567
+	 * @param String $highlight highlight or not
568
+	 * @param String $ModeS ModesS code of flight
569
+	 * @param String $registration registration code of flight
570
+	 * @param String $pilot_id pilot id of flight (for virtual airlines)
571
+	 * @param String $pilot_name pilot name of flight (for virtual airlines)
572
+	 * @param String $verticalrate vertival rate of flight
573
+	 * @return String success or false
574
+	 */
575 575
 	public function addMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $mmsi = '',$type = '',$imo = '',$callsign = '',$status = '',$format_source = '', $source_name = '')
576 576
 	{
577 577
 		global $globalURL;
@@ -657,16 +657,16 @@  discard block
 block discarded – undo
657 657
 		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
658 658
 		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
659 659
 	
660
-                if ($latitude == '' && $longitude == '') {
661
-            		$latitude = 0;
662
-            		$longitude = 0;
663
-            	}
664
-                if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
665
-                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
666
-                $query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo) 
660
+				if ($latitude == '' && $longitude == '') {
661
+					$latitude = 0;
662
+					$longitude = 0;
663
+				}
664
+				if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
665
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
666
+				$query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo) 
667 667
                 VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo)";
668 668
 
669
-                $query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':speed' => $groundspeed,':date' => $date,':format_source' => $format_source, ':source_name' => $source_name,':mmsi' => $mmsi,':type' => $type,':status' => $status,':imo' => $imo);
669
+				$query_values = array(':fammarine_id' => $fammarine_id,':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':heading' => $heading,':speed' => $groundspeed,':date' => $date,':format_source' => $format_source, ':source_name' => $source_name,':mmsi' => $mmsi,':type' => $type,':status' => $status,':imo' => $imo);
670 670
 
671 671
 		try {
672 672
 		        
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
 			$sth->execute($query_values);
675 675
 			$this->db = null;
676 676
 		} catch (PDOException $e) {
677
-		    return "error : ".$e->getMessage();
677
+			return "error : ".$e->getMessage();
678 678
 		}
679 679
 		
680 680
 		return "success";
@@ -683,11 +683,11 @@  discard block
 block discarded – undo
683 683
 	
684 684
   
685 685
 	/**
686
-	* Gets the aircraft ident within the last hour
687
-	*
688
-	* @return String the ident
689
-	*
690
-	*/
686
+	 * Gets the aircraft ident within the last hour
687
+	 *
688
+	 * @return String the ident
689
+	 *
690
+	 */
691 691
 	public function getIdentFromLastHour($ident)
692 692
 	{
693 693
 		global $globalDBdriver, $globalTimezone;
@@ -703,11 +703,11 @@  discard block
 block discarded – undo
703 703
 								AND marine_output.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
704 704
 								AND marine_output.date < now() AT TIME ZONE 'UTC'";
705 705
 			$query_data = array(':ident' => $ident);
706
-    		}
706
+			}
707 707
 		
708 708
 		$sth = $this->db->prepare($query);
709 709
 		$sth->execute($query_data);
710
-    		$ident_result='';
710
+			$ident_result='';
711 711
 		while($row = $sth->fetch(PDO::FETCH_ASSOC))
712 712
 		{
713 713
 			$ident_result = $row['ident'];
@@ -718,11 +718,11 @@  discard block
 block discarded – undo
718 718
 	
719 719
 	
720 720
 	/**
721
-	* Gets the aircraft data from the last 20 seconds
722
-	*
723
-	* @return Array the spotter data
724
-	*
725
-	*/
721
+	 * Gets the aircraft data from the last 20 seconds
722
+	 *
723
+	 * @return Array the spotter data
724
+	 *
725
+	 */
726 726
 	public function getRealTimeData($q = '')
727 727
 	{
728 728
 		global $globalDBdriver;
@@ -760,11 +760,11 @@  discard block
 block discarded – undo
760 760
 	
761 761
 
762 762
 	/**
763
-	* Gets all number of flight over countries
764
-	*
765
-	* @return Array the airline country list
766
-	*
767
-	*/
763
+	 * Gets all number of flight over countries
764
+	 *
765
+	 * @return Array the airline country list
766
+	 *
767
+	 */
768 768
 /*
769 769
 	public function countAllTrackedOverCountries($limit = true,$olderthanmonths = 0,$sincedate = '',$filters = array())
770 770
 	{
@@ -815,11 +815,11 @@  discard block
 block discarded – undo
815 815
 	
816 816
 	
817 817
 	/**
818
-	* Gets all callsigns that have flown over
819
-	*
820
-	* @return Array the callsign list
821
-	*
822
-	*/
818
+	 * Gets all callsigns that have flown over
819
+	 *
820
+	 * @return Array the callsign list
821
+	 *
822
+	 */
823 823
 	public function countAllCallsigns($limit = true, $olderthanmonths = 0, $sincedate = '',$filters = array(),$year = '', $month = '', $day = '')
824 824
 	{
825 825
 		global $globalDBdriver;
@@ -886,11 +886,11 @@  discard block
 block discarded – undo
886 886
 
887 887
 
888 888
 	/**
889
-	* Counts all dates
890
-	*
891
-	* @return Array the date list
892
-	*
893
-	*/
889
+	 * Counts all dates
890
+	 *
891
+	 * @return Array the date list
892
+	 *
893
+	 */
894 894
 	public function countAllDates($filters = array())
895 895
 	{
896 896
 		global $globalTimezone, $globalDBdriver;
@@ -936,11 +936,11 @@  discard block
 block discarded – undo
936 936
 	
937 937
 	
938 938
 	/**
939
-	* Counts all dates during the last 7 days
940
-	*
941
-	* @return Array the date list
942
-	*
943
-	*/
939
+	 * Counts all dates during the last 7 days
940
+	 *
941
+	 * @return Array the date list
942
+	 *
943
+	 */
944 944
 	public function countAllDatesLast7Days($filters = array())
945 945
 	{
946 946
 		global $globalTimezone, $globalDBdriver;
@@ -962,7 +962,7 @@  discard block
 block discarded – undo
962 962
 			$query .= " GROUP BY date_name 
963 963
 								ORDER BY date_name ASC";
964 964
 			$query_data = array(':offset' => $offset);
965
-    		}
965
+			}
966 966
 		
967 967
 		$sth = $this->db->prepare($query);
968 968
 		$sth->execute($query_data);
@@ -982,11 +982,11 @@  discard block
 block discarded – undo
982 982
 	}
983 983
 
984 984
 	/**
985
-	* Counts all dates during the last month
986
-	*
987
-	* @return Array the date list
988
-	*
989
-	*/
985
+	 * Counts all dates during the last month
986
+	 *
987
+	 * @return Array the date list
988
+	 *
989
+	 */
990 990
 	public function countAllDatesLastMonth($filters = array())
991 991
 	{
992 992
 		global $globalTimezone, $globalDBdriver;
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
 			$query .= " GROUP BY date_name 
1009 1009
 								ORDER BY date_name ASC";
1010 1010
 			$query_data = array(':offset' => $offset);
1011
-    		}
1011
+			}
1012 1012
 		
1013 1013
 		$sth = $this->db->prepare($query);
1014 1014
 		$sth->execute($query_data);
@@ -1030,11 +1030,11 @@  discard block
 block discarded – undo
1030 1030
 
1031 1031
 
1032 1032
 	/**
1033
-	* Counts all month
1034
-	*
1035
-	* @return Array the month list
1036
-	*
1037
-	*/
1033
+	 * Counts all month
1034
+	 *
1035
+	 * @return Array the month list
1036
+	 *
1037
+	 */
1038 1038
 	public function countAllMonths($filters = array())
1039 1039
 	{
1040 1040
 		global $globalTimezone, $globalDBdriver;
@@ -1079,11 +1079,11 @@  discard block
 block discarded – undo
1079 1079
 	
1080 1080
 
1081 1081
 	/**
1082
-	* Counts all dates during the last year
1083
-	*
1084
-	* @return Array the date list
1085
-	*
1086
-	*/
1082
+	 * Counts all dates during the last year
1083
+	 *
1084
+	 * @return Array the date list
1085
+	 *
1086
+	 */
1087 1087
 	public function countAllMonthsLastYear($filters)
1088 1088
 	{
1089 1089
 		global $globalTimezone, $globalDBdriver;
@@ -1105,7 +1105,7 @@  discard block
 block discarded – undo
1105 1105
 			$query .= " GROUP BY year_name, month_name
1106 1106
 								ORDER BY year_name, month_name ASC";
1107 1107
 			$query_data = array(':offset' => $offset);
1108
-    		}
1108
+			}
1109 1109
 		
1110 1110
 		$sth = $this->db->prepare($query);
1111 1111
 		$sth->execute($query_data);
@@ -1128,11 +1128,11 @@  discard block
 block discarded – undo
1128 1128
 	
1129 1129
 	
1130 1130
 	/**
1131
-	* Counts all hours
1132
-	*
1133
-	* @return Array the hour list
1134
-	*
1135
-	*/
1131
+	 * Counts all hours
1132
+	 *
1133
+	 * @return Array the hour list
1134
+	 *
1135
+	 */
1136 1136
 	public function countAllHours($orderby,$filters = array())
1137 1137
 	{
1138 1138
 		global $globalTimezone, $globalDBdriver;
@@ -1195,11 +1195,11 @@  discard block
 block discarded – undo
1195 1195
 	
1196 1196
 	
1197 1197
 	/**
1198
-	* Counts all hours by date
1199
-	*
1200
-	* @return Array the hour list
1201
-	*
1202
-	*/
1198
+	 * Counts all hours by date
1199
+	 *
1200
+	 * @return Array the hour list
1201
+	 *
1202
+	 */
1203 1203
 	public function countAllHoursByDate($date, $filters = array())
1204 1204
 	{
1205 1205
 		global $globalTimezone, $globalDBdriver;
@@ -1243,11 +1243,11 @@  discard block
 block discarded – undo
1243 1243
 	
1244 1244
 	
1245 1245
 	/**
1246
-	* Counts all hours by a ident/callsign
1247
-	*
1248
-	* @return Array the hour list
1249
-	*
1250
-	*/
1246
+	 * Counts all hours by a ident/callsign
1247
+	 *
1248
+	 * @return Array the hour list
1249
+	 *
1250
+	 */
1251 1251
 	public function countAllHoursByIdent($ident, $filters = array())
1252 1252
 	{
1253 1253
 		global $globalTimezone, $globalDBdriver;
@@ -1292,11 +1292,11 @@  discard block
 block discarded – undo
1292 1292
 	
1293 1293
 	
1294 1294
 	/**
1295
-	* Counts all flights that have flown over
1296
-	*
1297
-	* @return Integer the number of flights
1298
-	*
1299
-	*/
1295
+	 * Counts all flights that have flown over
1296
+	 *
1297
+	 * @return Integer the number of flights
1298
+	 *
1299
+	 */
1300 1300
 	public function countOverallTracked($filters = array(),$year = '',$month = '')
1301 1301
 	{
1302 1302
 		global $globalDBdriver;
@@ -1331,11 +1331,11 @@  discard block
 block discarded – undo
1331 1331
 	
1332 1332
   
1333 1333
 	/**
1334
-	* Counts all hours of today
1335
-	*
1336
-	* @return Array the hour list
1337
-	*
1338
-	*/
1334
+	 * Counts all hours of today
1335
+	 *
1336
+	 * @return Array the hour list
1337
+	 *
1338
+	 */
1339 1339
 	public function countAllHoursFromToday($filters = array())
1340 1340
 	{
1341 1341
 		global $globalTimezone, $globalDBdriver;
@@ -1375,12 +1375,12 @@  discard block
 block discarded – undo
1375 1375
 	}
1376 1376
     
1377 1377
     
1378
-     /**
1379
-	* Gets the Barrie Spotter ID based on the FlightAware ID
1380
-	*
1381
-	* @return Integer the Barrie Spotter ID
1378
+	 /**
1379
+	  * Gets the Barrie Spotter ID based on the FlightAware ID
1380
+	  *
1381
+	  * @return Integer the Barrie Spotter ID
1382 1382
 q	*
1383
-	*/
1383
+	  */
1384 1384
 	public function getMarineIDBasedOnFamMarineID($fammarine_id)
1385 1385
 	{
1386 1386
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -1401,13 +1401,13 @@  discard block
 block discarded – undo
1401 1401
   
1402 1402
  
1403 1403
 	/**
1404
-	* Parses a date string
1405
-	*
1406
-	* @param String $dateString the date string
1407
-	* @param String $timezone the timezone of a user
1408
-	* @return Array the time information
1409
-	*
1410
-	*/
1404
+	 * Parses a date string
1405
+	 *
1406
+	 * @param String $dateString the date string
1407
+	 * @param String $timezone the timezone of a user
1408
+	 * @return Array the time information
1409
+	 *
1410
+	 */
1411 1411
 	public function parseDateString($dateString, $timezone = '')
1412 1412
 	{
1413 1413
 		$time_array = array();
@@ -1440,12 +1440,12 @@  discard block
 block discarded – undo
1440 1440
 	}
1441 1441
 	
1442 1442
 	/**
1443
-	* Parses the direction degrees to working
1444
-	*
1445
-	* @param Float $direction the direction in degrees
1446
-	* @return Array the direction information
1447
-	*
1448
-	*/
1443
+	 * Parses the direction degrees to working
1444
+	 *
1445
+	 * @param Float $direction the direction in degrees
1446
+	 * @return Array the direction information
1447
+	 *
1448
+	 */
1449 1449
 	public function parseDirection($direction = 0)
1450 1450
 	{
1451 1451
 		if ($direction == '') $direction = 0;
@@ -1524,12 +1524,12 @@  discard block
 block discarded – undo
1524 1524
 	
1525 1525
 	
1526 1526
 	/**
1527
-	* Gets Country from latitude/longitude
1528
-	*
1529
-	* @param Float $latitude latitute of the flight
1530
-	* @param Float $longitude longitute of the flight
1531
-	* @return String the countrie
1532
-	*/
1527
+	 * Gets Country from latitude/longitude
1528
+	 *
1529
+	 * @param Float $latitude latitute of the flight
1530
+	 * @param Float $longitude longitute of the flight
1531
+	 * @return String the countrie
1532
+	 */
1533 1533
 	public function getCountryFromLatitudeLongitude($latitude,$longitude)
1534 1534
 	{
1535 1535
 		global $globalDBdriver, $globalDebug;
@@ -1566,11 +1566,11 @@  discard block
 block discarded – undo
1566 1566
 	}
1567 1567
 
1568 1568
 	/**
1569
-	* Gets Country from iso2
1570
-	*
1571
-	* @param String $iso2 ISO2 country code
1572
-	* @return String the countrie
1573
-	*/
1569
+	 * Gets Country from iso2
1570
+	 *
1571
+	 * @param String $iso2 ISO2 country code
1572
+	 * @return String the countrie
1573
+	 */
1574 1574
 	public function getCountryFromISO2($iso2)
1575 1575
 	{
1576 1576
 		global $globalDBdriver, $globalDebug;
@@ -1599,12 +1599,12 @@  discard block
 block discarded – undo
1599 1599
 
1600 1600
 	
1601 1601
 	/**
1602
-	* Gets the short url from bit.ly
1603
-	*
1604
-	* @param String $url the full url
1605
-	* @return String the bit.ly url
1606
-	*
1607
-	*/
1602
+	 * Gets the short url from bit.ly
1603
+	 *
1604
+	 * @param String $url the full url
1605
+	 * @return String the bit.ly url
1606
+	 *
1607
+	 */
1608 1608
 	public function getBitlyURL($url)
1609 1609
 	{
1610 1610
 		global $globalBitlyAccessToken;
Please login to merge, or discard this patch.
Braces   +142 added lines, -51 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@  discard block
 block discarded – undo
31 31
 		if (isset($filter[0]['source'])) {
32 32
 			$filters = array_merge($filters,$filter);
33 33
 		}
34
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
34
+		if (is_array($globalFilter)) {
35
+			$filter = array_merge($filter,$globalFilter);
36
+		}
35 37
 		$filter_query_join = '';
36 38
 		$filter_query_where = '';
37 39
 		foreach($filters as $flt) {
@@ -70,8 +72,11 @@  discard block
 block discarded – undo
70 72
 				$filter_query_where .= " AND EXTRACT(DAY FROM marine_output.date) = '".$filter['day']."'";
71 73
 			}
72 74
 		}
73
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
74
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
75
+		if ($filter_query_where == '' && $where) {
76
+			$filter_query_where = ' WHERE';
77
+		} elseif ($filter_query_where != '' && $and) {
78
+			$filter_query_where .= ' AND';
79
+		}
75 80
 		if ($filter_query_where != '') {
76 81
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
77 82
 		}
@@ -125,25 +130,40 @@  discard block
 block discarded – undo
125 130
 				$temp_array['spotter_id'] = $row['spotter_archive_id'];
126 131
 			} elseif (isset($row['spotter_archive_output_id'])) {
127 132
 				$temp_array['spotter_id'] = $row['spotter_archive_output_id'];
128
-			*/} 
129
-			elseif (isset($row['marineid'])) {
133
+			*/} elseif (isset($row['marineid'])) {
130 134
 				$temp_array['marineid'] = $row['marineid'];
131 135
 			} else {
132 136
 				$temp_array['marineid'] = '';
133 137
 			}
134
-			if (isset($row['fammarine_id'])) $temp_array['fammarine_id'] = $row['fammarine_id'];
135
-			if (isset($row['mmsi'])) $temp_array['mmsi'] = $row['mmsi'];
136
-			if (isset($row['type'])) $temp_array['type'] = $row['type'];
138
+			if (isset($row['fammarine_id'])) {
139
+				$temp_array['fammarine_id'] = $row['fammarine_id'];
140
+			}
141
+			if (isset($row['mmsi'])) {
142
+				$temp_array['mmsi'] = $row['mmsi'];
143
+			}
144
+			if (isset($row['type'])) {
145
+				$temp_array['type'] = $row['type'];
146
+			}
137 147
 			$temp_array['ident'] = $row['ident'];
138
-			if (isset($row['latitude'])) $temp_array['latitude'] = $row['latitude'];
139
-			if (isset($row['longitude'])) $temp_array['longitude'] = $row['longitude'];
140
-			if (isset($row['format_source'])) $temp_array['format_source'] = $row['format_source'];
148
+			if (isset($row['latitude'])) {
149
+				$temp_array['latitude'] = $row['latitude'];
150
+			}
151
+			if (isset($row['longitude'])) {
152
+				$temp_array['longitude'] = $row['longitude'];
153
+			}
154
+			if (isset($row['format_source'])) {
155
+				$temp_array['format_source'] = $row['format_source'];
156
+			}
141 157
 			if (isset($row['heading'])) {
142 158
 				$temp_array['heading'] = $row['heading'];
143 159
 				$heading_direction = $this->parseDirection($row['heading']);
144
-				if (isset($heading_direction[0]['direction_fullname'])) $temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
160
+				if (isset($heading_direction[0]['direction_fullname'])) {
161
+					$temp_array['heading_name'] = $heading_direction[0]['direction_fullname'];
162
+				}
163
+			}
164
+			if (isset($row['ground_speed'])) {
165
+				$temp_array['ground_speed'] = $row['ground_speed'];
145 166
 			}
146
-			if (isset($row['ground_speed'])) $temp_array['ground_speed'] = $row['ground_speed'];
147 167
 			
148 168
 			if (isset($row['date'])) {
149 169
 				$dateArray = $this->parseDateString($row['date']);
@@ -186,13 +206,21 @@  discard block
 block discarded – undo
186 206
 			}
187 207
 			
188 208
 			$fromsource = NULL;
189
-			if (isset($row['source_name']) && $row['source_name'] != '') $temp_array['source_name'] = $row['source_name'];
190
-			if (isset($row['over_country']) && $row['over_country'] != '') $temp_array['over_country'] = $row['over_country'];
191
-			if (isset($row['distance']) && $row['distance'] != '') $temp_array['distance'] = $row['distance'];
209
+			if (isset($row['source_name']) && $row['source_name'] != '') {
210
+				$temp_array['source_name'] = $row['source_name'];
211
+			}
212
+			if (isset($row['over_country']) && $row['over_country'] != '') {
213
+				$temp_array['over_country'] = $row['over_country'];
214
+			}
215
+			if (isset($row['distance']) && $row['distance'] != '') {
216
+				$temp_array['distance'] = $row['distance'];
217
+			}
192 218
 			$temp_array['query_number_rows'] = $num_rows;
193 219
 			$spotter_array[] = $temp_array;
194 220
 		}
195
-		if ($num_rows == 0) return array();
221
+		if ($num_rows == 0) {
222
+			return array();
223
+		}
196 224
 		$spotter_array[0]['query_number_rows'] = $num_rows;
197 225
 		return $spotter_array;
198 226
 	}	
@@ -223,8 +251,12 @@  discard block
 block discarded – undo
223 251
 			{
224 252
 				//$limit_query = " LIMIT ".$limit_array[0].",".$limit_array[1];
225 253
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
226
-			} else $limit_query = "";
227
-		} else $limit_query = "";
254
+			} else {
255
+				$limit_query = "";
256
+			}
257
+		} else {
258
+			$limit_query = "";
259
+		}
228 260
 		
229 261
 		if ($sort != "")
230 262
 		{
@@ -252,7 +284,9 @@  discard block
 block discarded – undo
252 284
 		global $global_query;
253 285
 		
254 286
 		date_default_timezone_set('UTC');
255
-		if ($id == '') return array();
287
+		if ($id == '') {
288
+			return array();
289
+		}
256 290
 		$additional_query = "marine_output.fammarine_id = :id";
257 291
 		$query_values = array(':id' => $id);
258 292
 		$query  = $global_query." WHERE ".$additional_query." ";
@@ -395,8 +429,11 @@  discard block
 block discarded – undo
395 429
 		$query .= " ORDER BY marine_output.source_name ASC";
396 430
 
397 431
 		$sth = $this->db->prepare($query);
398
-		if (!empty($query_values)) $sth->execute($query_values);
399
-		else $sth->execute();
432
+		if (!empty($query_values)) {
433
+			$sth->execute($query_values);
434
+		} else {
435
+			$sth->execute();
436
+		}
400 437
 
401 438
 		$source_array = array();
402 439
 		$temp_array = array();
@@ -451,8 +488,11 @@  discard block
 block discarded – undo
451 488
 		$sth = $this->db->prepare($query);
452 489
 		$sth->execute(array(':mmsi' => $mmsi));
453 490
 		$result = $sth->fetchAll(PDO::FETCH_ASSOC);
454
-		if (isset($result[0])) return $result[0];
455
-		else return array();
491
+		if (isset($result[0])) {
492
+			return $result[0];
493
+		} else {
494
+			return array();
495
+		}
456 496
 	}
457 497
 
458 498
 	/*
@@ -468,7 +508,9 @@  discard block
 block discarded – undo
468 508
 			date_default_timezone_set($globalTimezone);
469 509
 			$datetime = new DateTime();
470 510
 			$offset = $datetime->format('P');
471
-		} else $offset = '+00:00';
511
+		} else {
512
+			$offset = '+00:00';
513
+		}
472 514
 
473 515
 		if ($globalDBdriver == 'mysql') {
474 516
 			$query  = "SELECT DISTINCT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) as date
@@ -661,8 +703,12 @@  discard block
 block discarded – undo
661 703
             		$latitude = 0;
662 704
             		$longitude = 0;
663 705
             	}
664
-                if ($heading == '' || $Common->isInteger($heading) === false) $heading = 0;
665
-                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) $groundspeed = 0;
706
+                if ($heading == '' || $Common->isInteger($heading) === false) {
707
+                	$heading = 0;
708
+                }
709
+                if ($groundspeed == '' || $Common->isInteger($groundspeed) === false) {
710
+                	$groundspeed = 0;
711
+                }
666 712
                 $query  = "INSERT INTO marine_output (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, mmsi, type, status,imo) 
667 713
                 VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:speed,:date,:format_source, :source_name,:mmsi,:type,:status,:imo)";
668 714
 
@@ -827,12 +873,18 @@  discard block
 block discarded – undo
827 873
 		$query  = "SELECT DISTINCT marine_output.ident, COUNT(marine_output.ident) AS callsign_icao_count 
828 874
                     FROM marine_output".$filter_query." marine_output.ident <> ''";
829 875
 		 if ($olderthanmonths > 0) {
830
-			if ($globalDBdriver == 'mysql') $query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
831
-			else $query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
876
+			if ($globalDBdriver == 'mysql') {
877
+				$query .= ' AND date < DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$olderthanmonths.' MONTH)';
878
+			} else {
879
+				$query .= " AND marine_output.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$olderthanmonths." MONTHS'";
880
+			}
832 881
 		}
833 882
 		if ($sincedate != '') {
834
-			if ($globalDBdriver == 'mysql') $query .= " AND marine_output.date > '".$sincedate."'";
835
-			else $query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
883
+			if ($globalDBdriver == 'mysql') {
884
+				$query .= " AND marine_output.date > '".$sincedate."'";
885
+			} else {
886
+				$query .= " AND marine_output.date > CAST('".$sincedate."' AS TIMESTAMP)";
887
+			}
836 888
 		}
837 889
 		$query_values = array();
838 890
 		if ($year != '') {
@@ -863,7 +915,9 @@  discard block
 block discarded – undo
863 915
 			}
864 916
 		}
865 917
 		$query .= " GROUP BY marine_output.ident ORDER BY callsign_icao_count DESC";
866
-		if ($limit) $query .= " LIMIT 10 OFFSET 0";
918
+		if ($limit) {
919
+			$query .= " LIMIT 10 OFFSET 0";
920
+		}
867 921
       		
868 922
 		$sth = $this->db->prepare($query);
869 923
 		$sth->execute($query_values);
@@ -898,7 +952,9 @@  discard block
 block discarded – undo
898 952
 			date_default_timezone_set($globalTimezone);
899 953
 			$datetime = new DateTime();
900 954
 			$offset = $datetime->format('P');
901
-		} else $offset = '+00:00';
955
+		} else {
956
+			$offset = '+00:00';
957
+		}
902 958
 
903 959
 		if ($globalDBdriver == 'mysql') {
904 960
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -948,7 +1004,9 @@  discard block
 block discarded – undo
948 1004
 			date_default_timezone_set($globalTimezone);
949 1005
 			$datetime = new DateTime();
950 1006
 			$offset = $datetime->format('P');
951
-		} else $offset = '+00:00';
1007
+		} else {
1008
+			$offset = '+00:00';
1009
+		}
952 1010
 		$filter_query = $this->getFilter($filters,true,true);
953 1011
 		if ($globalDBdriver == 'mysql') {
954 1012
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -994,7 +1052,9 @@  discard block
 block discarded – undo
994 1052
 			date_default_timezone_set($globalTimezone);
995 1053
 			$datetime = new DateTime();
996 1054
 			$offset = $datetime->format('P');
997
-		} else $offset = '+00:00';
1055
+		} else {
1056
+			$offset = '+00:00';
1057
+		}
998 1058
 		$filter_query = $this->getFilter($filters,true,true);
999 1059
 		if ($globalDBdriver == 'mysql') {
1000 1060
 			$query  = "SELECT DATE(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS date_name, count(*) as date_count
@@ -1042,7 +1102,9 @@  discard block
 block discarded – undo
1042 1102
 			date_default_timezone_set($globalTimezone);
1043 1103
 			$datetime = new DateTime();
1044 1104
 			$offset = $datetime->format('P');
1045
-		} else $offset = '+00:00';
1105
+		} else {
1106
+			$offset = '+00:00';
1107
+		}
1046 1108
 
1047 1109
 		if ($globalDBdriver == 'mysql') {
1048 1110
 			$query  = "SELECT YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name,MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, count(*) as date_count
@@ -1091,7 +1153,9 @@  discard block
 block discarded – undo
1091 1153
 			date_default_timezone_set($globalTimezone);
1092 1154
 			$datetime = new DateTime();
1093 1155
 			$offset = $datetime->format('P');
1094
-		} else $offset = '+00:00';
1156
+		} else {
1157
+			$offset = '+00:00';
1158
+		}
1095 1159
 		$filter_query = $this->getFilter($filters,true,true);
1096 1160
 		if ($globalDBdriver == 'mysql') {
1097 1161
 			$query  = "SELECT MONTH(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS month_name, YEAR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS year_name, count(*) as date_count
@@ -1140,7 +1204,9 @@  discard block
 block discarded – undo
1140 1204
 			date_default_timezone_set($globalTimezone);
1141 1205
 			$datetime = new DateTime();
1142 1206
 			$offset = $datetime->format('P');
1143
-		} else $offset = '+00:00';
1207
+		} else {
1208
+			$offset = '+00:00';
1209
+		}
1144 1210
 
1145 1211
 		$orderby_sql = '';
1146 1212
 		if ($orderby == "hour")
@@ -1209,7 +1275,9 @@  discard block
 block discarded – undo
1209 1275
 			date_default_timezone_set($globalTimezone);
1210 1276
 			$datetime = new DateTime($date);
1211 1277
 			$offset = $datetime->format('P');
1212
-		} else $offset = '+00:00';
1278
+		} else {
1279
+			$offset = '+00:00';
1280
+		}
1213 1281
 
1214 1282
 		if ($globalDBdriver == 'mysql') {
1215 1283
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1257,7 +1325,9 @@  discard block
 block discarded – undo
1257 1325
 			date_default_timezone_set($globalTimezone);
1258 1326
 			$datetime = new DateTime();
1259 1327
 			$offset = $datetime->format('P');
1260
-		} else $offset = '+00:00';
1328
+		} else {
1329
+			$offset = '+00:00';
1330
+		}
1261 1331
 
1262 1332
 		if ($globalDBdriver == 'mysql') {
1263 1333
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1321,8 +1391,11 @@  discard block
 block discarded – undo
1321 1391
 				$query_values = array_merge($query_values,array(':month' => $month));
1322 1392
 			}
1323 1393
 		}
1324
-		if (empty($query_values)) $queryi .= $this->getFilter($filters);
1325
-		else $queryi .= $this->getFilter($filters,true,true).substr($query,4);
1394
+		if (empty($query_values)) {
1395
+			$queryi .= $this->getFilter($filters);
1396
+		} else {
1397
+			$queryi .= $this->getFilter($filters,true,true).substr($query,4);
1398
+		}
1326 1399
 		
1327 1400
 		$sth = $this->db->prepare($queryi);
1328 1401
 		$sth->execute($query_values);
@@ -1344,7 +1417,9 @@  discard block
 block discarded – undo
1344 1417
 			date_default_timezone_set($globalTimezone);
1345 1418
 			$datetime = new DateTime();
1346 1419
 			$offset = $datetime->format('P');
1347
-		} else $offset = '+00:00';
1420
+		} else {
1421
+			$offset = '+00:00';
1422
+		}
1348 1423
 
1349 1424
 		if ($globalDBdriver == 'mysql') {
1350 1425
 			$query  = "SELECT HOUR(CONVERT_TZ(marine_output.date,'+00:00', :offset)) AS hour_name, count(*) as hour_count
@@ -1448,7 +1523,9 @@  discard block
 block discarded – undo
1448 1523
 	*/
1449 1524
 	public function parseDirection($direction = 0)
1450 1525
 	{
1451
-		if ($direction == '') $direction = 0;
1526
+		if ($direction == '') {
1527
+			$direction = 0;
1528
+		}
1452 1529
 		$direction_array = array();
1453 1530
 		$temp_array = array();
1454 1531
 
@@ -1537,7 +1614,9 @@  discard block
 block discarded – undo
1537 1614
 		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1538 1615
 	
1539 1616
 		$Connection = new Connection($this->db);
1540
-		if (!$Connection->tableExists('countries')) return '';
1617
+		if (!$Connection->tableExists('countries')) {
1618
+			return '';
1619
+		}
1541 1620
 	
1542 1621
 		try {
1543 1622
 			/*
@@ -1557,9 +1636,13 @@  discard block
 block discarded – undo
1557 1636
 			$sth->closeCursor();
1558 1637
 			if (count($row) > 0) {
1559 1638
 				return $row;
1560
-			} else return '';
1639
+			} else {
1640
+				return '';
1641
+			}
1561 1642
 		} catch (PDOException $e) {
1562
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1643
+			if (isset($globalDebug) && $globalDebug) {
1644
+				echo 'Error : '.$e->getMessage()."\n";
1645
+			}
1563 1646
 			return '';
1564 1647
 		}
1565 1648
 	
@@ -1577,7 +1660,9 @@  discard block
 block discarded – undo
1577 1660
 		$iso2 = filter_var($iso2,FILTER_SANITIZE_STRING);
1578 1661
 	
1579 1662
 		$Connection = new Connection($this->db);
1580
-		if (!$Connection->tableExists('countries')) return '';
1663
+		if (!$Connection->tableExists('countries')) {
1664
+			return '';
1665
+		}
1581 1666
 	
1582 1667
 		try {
1583 1668
 			$query = "SELECT name,iso2,iso3 FROM countries WHERE iso2 = :iso2 LIMIT 1";
@@ -1589,9 +1674,13 @@  discard block
 block discarded – undo
1589 1674
 			$sth->closeCursor();
1590 1675
 			if (count($row) > 0) {
1591 1676
 				return $row;
1592
-			} else return '';
1677
+			} else {
1678
+				return '';
1679
+			}
1593 1680
 		} catch (PDOException $e) {
1594
-			if (isset($globalDebug) && $globalDebug) echo 'Error : '.$e->getMessage()."\n";
1681
+			if (isset($globalDebug) && $globalDebug) {
1682
+				echo 'Error : '.$e->getMessage()."\n";
1683
+			}
1595 1684
 			return '';
1596 1685
 		}
1597 1686
 	
@@ -1609,7 +1698,9 @@  discard block
 block discarded – undo
1609 1698
 	{
1610 1699
 		global $globalBitlyAccessToken;
1611 1700
 		
1612
-		if ($globalBitlyAccessToken == '') return $url;
1701
+		if ($globalBitlyAccessToken == '') {
1702
+			return $url;
1703
+		}
1613 1704
         
1614 1705
 		$google_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$globalBitlyAccessToken.'&longUrl='.$url;
1615 1706
 		
Please login to merge, or discard this patch.
require/class.MarineLive.php 2 patches
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 
13 13
 
14 14
 	/**
15
-	* Get SQL query part for filter used
16
-	* @param Array $filter the filter
17
-	* @return Array the SQL part
18
-	*/
15
+	 * Get SQL query part for filter used
16
+	 * @param Array $filter the filter
17
+	 * @return Array the SQL part
18
+	 */
19 19
 	public function getFilter($filter = array(),$where = false,$and = false) {
20 20
 		global $globalFilter, $globalStatsFilters, $globalFilterName, $globalDBdriver;
21 21
 		$filters = array();
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 	}
87 87
 
88 88
 	/**
89
-	* Gets all the spotter information based on the latest data entry
90
-	*
91
-	* @return Array the spotter information
92
-	*
93
-	*/
89
+	 * Gets all the spotter information based on the latest data entry
90
+	 *
91
+	 * @return Array the spotter information
92
+	 *
93
+	 */
94 94
 	public function getLiveMarineData($limit = '', $sort = '', $filter = array())
95 95
 	{
96 96
 		global $globalDBdriver, $globalLiveInterval;
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 
134 134
 	/**
135
-	* Gets Minimal Live Spotter data
136
-	*
137
-	* @return Array the spotter information
138
-	*
139
-	*/
135
+	 * Gets Minimal Live Spotter data
136
+	 *
137
+	 * @return Array the spotter information
138
+	 *
139
+	 */
140 140
 	public function getMinLiveMarineData($filter = array())
141 141
 	{
142 142
 		global $globalDBdriver, $globalLiveInterval;
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 	}
167 167
 
168 168
 	/**
169
-	* Gets Minimal Live Spotter data since xx seconds
170
-	*
171
-	* @return Array the spotter information
172
-	*
173
-	*/
169
+	 * Gets Minimal Live Spotter data since xx seconds
170
+	 *
171
+	 * @return Array the spotter information
172
+	 *
173
+	 */
174 174
 	public function getMinLastLiveMarineData($filter = array())
175 175
 	{
176 176
 		global $globalDBdriver, $globalLiveInterval;
@@ -183,13 +183,13 @@  discard block
 block discarded – undo
183 183
 			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
184 184
 			FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
185 185
 			ORDER BY marine_live.fammarine_id, marine_live.date";
186
-                } else {
186
+				} else {
187 187
 			$query  = "SELECT marine_live.ident, marine_live.fammarine_id, marine_live.type,marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
188 188
 			FROM marine_live".$filter_query." CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
189 189
 			ORDER BY marine_live.fammarine_id, marine_live.date";
190 190
 		}
191 191
 
192
-    		try {
192
+			try {
193 193
 			$sth = $this->db->prepare($query);
194 194
 			$sth->execute();
195 195
 		} catch(PDOException $e) {
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
 	}
202 202
 
203 203
 	/**
204
-	* Gets number of latest data entry
205
-	*
206
-	* @return String number of entry
207
-	*
208
-	*/
204
+	 * Gets number of latest data entry
205
+	 *
206
+	 * @return String number of entry
207
+	 *
208
+	 */
209 209
 	public function getLiveMarineCount($filter = array())
210 210
 	{
211 211
 		global $globalDBdriver, $globalLiveInterval;
@@ -230,11 +230,11 @@  discard block
 block discarded – undo
230 230
 	}
231 231
 
232 232
 	/**
233
-	* Gets all the spotter information based on the latest data entry and coord
234
-	*
235
-	* @return Array the spotter information
236
-	*
237
-	*/
233
+	 * Gets all the spotter information based on the latest data entry and coord
234
+	 *
235
+	 * @return Array the spotter information
236
+	 *
237
+	 */
238 238
 	public function getLiveMarineDatabyCoord($coord, $filter = array())
239 239
 	{
240 240
 		global $globalDBdriver, $globalLiveInterval;
@@ -258,11 +258,11 @@  discard block
 block discarded – undo
258 258
 	}
259 259
 
260 260
 	/**
261
-	* Gets all the spotter information based on a user's latitude and longitude
262
-	*
263
-	* @return Array the spotter information
264
-	*
265
-	*/
261
+	 * Gets all the spotter information based on a user's latitude and longitude
262
+	 *
263
+	 * @return Array the spotter information
264
+	 *
265
+	 */
266 266
 	public function getLatestMarineForLayar($lat, $lng, $radius, $interval)
267 267
 	{
268 268
 		$Marine = new Marine($this->db);
@@ -275,134 +275,134 @@  discard block
 block discarded – undo
275 275
 		if ($lng != '')
276 276
 		{
277 277
 			if (!is_numeric($lng))
278
-                        {
279
-                                return false;
280
-                        }
281
-                }
282
-
283
-                if ($radius != '')
284
-                {
285
-                        if (!is_numeric($radius))
286
-                        {
287
-                                return false;
288
-                        }
289
-                }
278
+						{
279
+								return false;
280
+						}
281
+				}
282
+
283
+				if ($radius != '')
284
+				{
285
+						if (!is_numeric($radius))
286
+						{
287
+								return false;
288
+						}
289
+				}
290 290
 		$additional_query = '';
291 291
 		if ($interval != '')
292
-                {
293
-                        if (!is_string($interval))
294
-                        {
295
-                                //$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
296
-			        return false;
297
-                        } else {
298
-                if ($interval == '1m')
299
-                {
300
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
301
-                } else if ($interval == '15m'){
302
-                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
303
-                } 
304
-            }
305
-                } else {
306
-         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
307
-        }
308
-
309
-                $query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
292
+				{
293
+						if (!is_string($interval))
294
+						{
295
+								//$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
296
+					return false;
297
+						} else {
298
+				if ($interval == '1m')
299
+				{
300
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';
301
+				} else if ($interval == '15m'){
302
+					$additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= marine_live.date ';
303
+				} 
304
+			}
305
+				} else {
306
+		 $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= marine_live.date ';   
307
+		}
308
+
309
+				$query  = "SELECT marine_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM marine_live 
310 310
                    WHERE marine_live.latitude <> '' 
311 311
                                    AND marine_live.longitude <> '' 
312 312
                    ".$additional_query."
313 313
                    HAVING distance < :radius  
314 314
                                    ORDER BY distance";
315 315
 
316
-                $spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
316
+				$spotter_array = $Marine->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius));
317 317
 
318
-                return $spotter_array;
319
-        }
318
+				return $spotter_array;
319
+		}
320 320
 
321 321
     
322
-        /**
323
-	* Gets all the spotter information based on a particular callsign
324
-	*
325
-	* @return Array the spotter information
326
-	*
327
-	*/
322
+		/**
323
+		 * Gets all the spotter information based on a particular callsign
324
+		 *
325
+		 * @return Array the spotter information
326
+		 *
327
+		 */
328 328
 	public function getLastLiveMarineDataByIdent($ident)
329 329
 	{
330 330
 		$Marine = new Marine($this->db);
331 331
 		date_default_timezone_set('UTC');
332 332
 
333 333
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
334
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
334
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
335 335
 
336 336
 		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident),'',true);
337 337
 
338 338
 		return $spotter_array;
339 339
 	}
340 340
 
341
-        /**
342
-	* Gets all the spotter information based on a particular callsign
343
-	*
344
-	* @return Array the spotter information
345
-	*
346
-	*/
341
+		/**
342
+		 * Gets all the spotter information based on a particular callsign
343
+		 *
344
+		 * @return Array the spotter information
345
+		 *
346
+		 */
347 347
 	public function getDateLiveMarineDataByIdent($ident,$date)
348 348
 	{
349 349
 		$Marine = new Marine($this->db);
350 350
 		date_default_timezone_set('UTC');
351 351
 
352 352
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
353
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
353
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
354 354
 
355
-                $date = date('c',$date);
355
+				$date = date('c',$date);
356 356
 		$spotter_array = $Marine->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
357 357
 
358 358
 		return $spotter_array;
359 359
 	}
360 360
 
361
-        /**
362
-	* Gets last spotter information based on a particular callsign
363
-	*
364
-	* @return Array the spotter information
365
-	*
366
-	*/
361
+		/**
362
+		 * Gets last spotter information based on a particular callsign
363
+		 *
364
+		 * @return Array the spotter information
365
+		 *
366
+		 */
367 367
 	public function getLastLiveMarineDataById($id)
368 368
 	{
369 369
 		$Marine = new Marine($this->db);
370 370
 		date_default_timezone_set('UTC');
371 371
 
372 372
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
373
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
373
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
374 374
 
375 375
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id),'',true);
376 376
 
377 377
 		return $spotter_array;
378 378
 	}
379 379
 
380
-        /**
381
-	* Gets last spotter information based on a particular callsign
382
-	*
383
-	* @return Array the spotter information
384
-	*
385
-	*/
380
+		/**
381
+		 * Gets last spotter information based on a particular callsign
382
+		 *
383
+		 * @return Array the spotter information
384
+		 *
385
+		 */
386 386
 	public function getDateLiveMarineDataById($id,$date)
387 387
 	{
388 388
 		$Marine = new Marine($this->db);
389 389
 		date_default_timezone_set('UTC');
390 390
 
391 391
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
392
-                $query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
-                $date = date('c',$date);
392
+				$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE l.fammarine_id = :id AND l.date <= :date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate ORDER BY marine_live.date DESC';
393
+				$date = date('c',$date);
394 394
 		$spotter_array = $Marine->getDataFromDB($query,array(':id' => $id,':date' => $date),'',true);
395 395
 
396 396
 		return $spotter_array;
397 397
 	}
398 398
 
399 399
 
400
-        /**
401
-	* Gets all the spotter information based on a particular id
402
-	*
403
-	* @return Array the spotter information
404
-	*
405
-	*/
400
+		/**
401
+		 * Gets all the spotter information based on a particular id
402
+		 *
403
+		 * @return Array the spotter information
404
+		 *
405
+		 */
406 406
 	public function getAllLiveMarineDataById($id,$liveinterval = false)
407 407
 	{
408 408
 		global $globalDBdriver, $globalLiveInterval;
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
 		return $spotter_array;
431 431
 	}
432 432
 
433
-        /**
434
-	* Gets all the spotter information based on a particular ident
435
-	*
436
-	* @return Array the spotter information
437
-	*
438
-	*/
433
+		/**
434
+		 * Gets all the spotter information based on a particular ident
435
+		 *
436
+		 * @return Array the spotter information
437
+		 *
438
+		 */
439 439
 	public function getAllLiveMarineDataByIdent($ident)
440 440
 	{
441 441
 		date_default_timezone_set('UTC');
442 442
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
443 443
 		$query  = self::$global_query.' WHERE marine_live.ident = :ident';
444
-    		try {
444
+			try {
445 445
 			
446 446
 			$sth = $this->db->prepare($query);
447 447
 			$sth->execute(array(':ident' => $ident));
@@ -455,23 +455,23 @@  discard block
 block discarded – undo
455 455
 
456 456
 
457 457
 	/**
458
-	* Deletes all info in the table
459
-	*
460
-	* @return String success or false
461
-	*
462
-	*/
458
+	 * Deletes all info in the table
459
+	 *
460
+	 * @return String success or false
461
+	 *
462
+	 */
463 463
 	public function deleteLiveMarineData()
464 464
 	{
465 465
 		global $globalDBdriver;
466 466
 		if ($globalDBdriver == 'mysql') {
467 467
 			//$query  = "DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= marine_live.date";
468 468
 			$query  = 'DELETE FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= marine_live.date';
469
-            		//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
469
+					//$query  = "DELETE FROM marine_live WHERE marine_live.id IN (SELECT marine_live.id FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= marine_live.date)";
470 470
 		} else {
471 471
 			$query  = "DELETE FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date";
472 472
 		}
473 473
         
474
-    		try {
474
+			try {
475 475
 			
476 476
 			$sth = $this->db->prepare($query);
477 477
 			$sth->execute();
@@ -483,18 +483,18 @@  discard block
 block discarded – undo
483 483
 	}
484 484
 
485 485
 	/**
486
-	* Deletes all info in the table for aircraft not seen since 2 HOUR
487
-	*
488
-	* @return String success or false
489
-	*
490
-	*/
486
+	 * Deletes all info in the table for aircraft not seen since 2 HOUR
487
+	 *
488
+	 * @return String success or false
489
+	 *
490
+	 */
491 491
 	public function deleteLiveMarineDataNotUpdated()
492 492
 	{
493 493
 		global $globalDBdriver, $globalDebug;
494 494
 		if ($globalDBdriver == 'mysql') {
495 495
 			//$query = 'SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < marine_live.date) LIMIT 800 OFFSET 0';
496
-    			$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
497
-    			try {
496
+				$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
497
+				try {
498 498
 				
499 499
 				$sth = $this->db->prepare($query);
500 500
 				$sth->execute();
@@ -502,8 +502,8 @@  discard block
 block discarded – undo
502 502
 				return "error";
503 503
 			}
504 504
 			$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
505
-                        $i = 0;
506
-                        $j =0;
505
+						$i = 0;
506
+						$j =0;
507 507
 			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
508 508
 			foreach($all as $row)
509 509
 			{
@@ -511,20 +511,20 @@  discard block
 block discarded – undo
511 511
 				$j++;
512 512
 				if ($j == 30) {
513 513
 					if ($globalDebug) echo ".";
514
-				    	try {
514
+						try {
515 515
 						
516 516
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
517 517
 						$sth->execute();
518 518
 					} catch(PDOException $e) {
519 519
 						return "error";
520 520
 					}
521
-                                	$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
522
-                                	$j = 0;
521
+									$query_delete = 'DELETE FROM marine_live WHERE fammarine_id IN (';
522
+									$j = 0;
523 523
 				}
524 524
 				$query_delete .= "'".$row['fammarine_id']."',";
525 525
 			}
526 526
 			if ($i > 0) {
527
-    				try {
527
+					try {
528 528
 					
529 529
 					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
530 530
 					$sth->execute();
@@ -535,9 +535,9 @@  discard block
 block discarded – undo
535 535
 			return "success";
536 536
 		} elseif ($globalDBdriver == 'pgsql') {
537 537
 			//$query = "SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= marine_live.date AND marine_live.fammarine_id NOT IN (SELECT fammarine_id FROM marine_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < marine_live.date) LIMIT 800 OFFSET 0";
538
-    			//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
539
-    			$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
540
-    			try {
538
+				//$query = "SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
539
+				$query = "DELETE FROM marine_live WHERE fammarine_id IN (SELECT marine_live.fammarine_id FROM marine_live INNER JOIN (SELECT fammarine_id,MAX(date) as max_date FROM marine_live GROUP BY fammarine_id) s ON s.fammarine_id = marine_live.fammarine_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
540
+				try {
541 541
 				
542 542
 				$sth = $this->db->prepare($query);
543 543
 				$sth->execute();
@@ -581,17 +581,17 @@  discard block
 block discarded – undo
581 581
 	}
582 582
 
583 583
 	/**
584
-	* Deletes all info in the table for an ident
585
-	*
586
-	* @return String success or false
587
-	*
588
-	*/
584
+	 * Deletes all info in the table for an ident
585
+	 *
586
+	 * @return String success or false
587
+	 *
588
+	 */
589 589
 	public function deleteLiveMarineDataByIdent($ident)
590 590
 	{
591 591
 		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
592 592
 		$query  = 'DELETE FROM marine_live WHERE ident = :ident';
593 593
         
594
-    		try {
594
+			try {
595 595
 			
596 596
 			$sth = $this->db->prepare($query);
597 597
 			$sth->execute(array(':ident' => $ident));
@@ -603,17 +603,17 @@  discard block
 block discarded – undo
603 603
 	}
604 604
 
605 605
 	/**
606
-	* Deletes all info in the table for an id
607
-	*
608
-	* @return String success or false
609
-	*
610
-	*/
606
+	 * Deletes all info in the table for an id
607
+	 *
608
+	 * @return String success or false
609
+	 *
610
+	 */
611 611
 	public function deleteLiveMarineDataById($id)
612 612
 	{
613 613
 		$id = filter_var($id, FILTER_SANITIZE_STRING);
614 614
 		$query  = 'DELETE FROM marine_live WHERE fammarine_id = :id';
615 615
         
616
-    		try {
616
+			try {
617 617
 			
618 618
 			$sth = $this->db->prepare($query);
619 619
 			$sth->execute(array(':id' => $id));
@@ -626,11 +626,11 @@  discard block
 block discarded – undo
626 626
 
627 627
 
628 628
 	/**
629
-	* Gets the aircraft ident within the last hour
630
-	*
631
-	* @return String the ident
632
-	*
633
-	*/
629
+	 * Gets the aircraft ident within the last hour
630
+	 *
631
+	 * @return String the ident
632
+	 *
633
+	 */
634 634
 	public function getIdentFromLastHour($ident)
635 635
 	{
636 636
 		global $globalDBdriver, $globalTimezone;
@@ -656,14 +656,14 @@  discard block
 block discarded – undo
656 656
 			$ident_result = $row['ident'];
657 657
 		}
658 658
 		return $ident_result;
659
-        }
659
+		}
660 660
 
661 661
 	/**
662
-	* Check recent aircraft
663
-	*
664
-	* @return String the ident
665
-	*
666
-	*/
662
+	 * Check recent aircraft
663
+	 *
664
+	 * @return String the ident
665
+	 *
666
+	 */
667 667
 	public function checkIdentRecent($ident)
668 668
 	{
669 669
 		global $globalDBdriver, $globalTimezone;
@@ -689,14 +689,14 @@  discard block
 block discarded – undo
689 689
 			$ident_result = $row['fammarine_id'];
690 690
 		}
691 691
 		return $ident_result;
692
-        }
692
+		}
693 693
 
694 694
 	/**
695
-	* Check recent aircraft by id
696
-	*
697
-	* @return String the ident
698
-	*
699
-	*/
695
+	 * Check recent aircraft by id
696
+	 *
697
+	 * @return String the ident
698
+	 *
699
+	 */
700 700
 	public function checkIdRecent($id)
701 701
 	{
702 702
 		global $globalDBdriver, $globalTimezone;
@@ -722,14 +722,14 @@  discard block
 block discarded – undo
722 722
 			$ident_result = $row['fammarine_id'];
723 723
 		}
724 724
 		return $ident_result;
725
-        }
725
+		}
726 726
 
727 727
 	/**
728
-	* Check recent aircraft by mmsi
729
-	*
730
-	* @return String the ident
731
-	*
732
-	*/
728
+	 * Check recent aircraft by mmsi
729
+	 *
730
+	 * @return String the ident
731
+	 *
732
+	 */
733 733
 	public function checkMMSIRecent($mmsi)
734 734
 	{
735 735
 		global $globalDBdriver, $globalTimezone;
@@ -755,19 +755,19 @@  discard block
 block discarded – undo
755 755
 			$ident_result = $row['fammarine_id'];
756 756
 		}
757 757
 		return $ident_result;
758
-        }
758
+		}
759 759
 
760 760
 	/**
761
-	* Adds a new spotter data
762
-	*
763
-	* @param String $fammarine_id the ID from flightaware
764
-	* @param String $ident the flight ident
765
-	* @param String $aircraft_icao the aircraft type
766
-	* @param String $departure_airport_icao the departure airport
767
-	* @param String $arrival_airport_icao the arrival airport
768
-	* @return String success or false
769
-	*
770
-	*/
761
+	 * Adds a new spotter data
762
+	 *
763
+	 * @param String $fammarine_id the ID from flightaware
764
+	 * @param String $ident the flight ident
765
+	 * @param String $aircraft_icao the aircraft type
766
+	 * @param String $departure_airport_icao the departure airport
767
+	 * @param String $arrival_airport_icao the arrival airport
768
+	 * @return String success or false
769
+	 *
770
+	 */
771 771
 	public function addLiveMarineData($fammarine_id = '', $ident = '', $latitude = '', $longitude = '', $heading = '', $groundspeed = '', $date = '', $putinarchive = false, $mmsi = '',$type = '',$imo = '', $callsign = '',$status = '',$noarchive = false,$format_source = '', $source_name = '', $over_country = '')
772 772
 	{
773 773
 		global $globalURL, $globalArchive, $globalDebug;
@@ -835,8 +835,8 @@  discard block
 block discarded – undo
835 835
 		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
836 836
 		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
837 837
 
838
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
839
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
838
+				if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
839
+				if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
840 840
             	
841 841
 		$query  = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo) 
842 842
 		VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:status,:imo)';
@@ -846,9 +846,9 @@  discard block
 block discarded – undo
846 846
 			
847 847
 			$sth = $this->db->prepare($query);
848 848
 			$sth->execute($query_values);
849
-                } catch(PDOException $e) {
850
-                	return "error : ".$e->getMessage();
851
-                }
849
+				} catch(PDOException $e) {
850
+					return "error : ".$e->getMessage();
851
+				}
852 852
 		/*
853 853
 		if (isset($globalArchive) && $globalArchive && $putinarchive && $noarchive !== true) {
854 854
 		    if ($globalDebug) echo '(Add to SBS archive : ';
Please login to merge, or discard this patch.
Braces   +56 added lines, -19 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
 		if (isset($filter[0]['source'])) {
30 30
 			$filters = array_merge($filters,$filter);
31 31
 		}
32
-		if (is_array($globalFilter)) $filter = array_merge($filter,$globalFilter);
32
+		if (is_array($globalFilter)) {
33
+			$filter = array_merge($filter,$globalFilter);
34
+		}
33 35
 		$filter_query_join = '';
34 36
 		$filter_query_where = '';
35 37
 		foreach($filters as $flt) {
@@ -76,8 +78,11 @@  discard block
 block discarded – undo
76 78
 		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
77 79
 			$filter_query_where .= " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
78 80
 		}
79
-		if ($filter_query_where == '' && $where) $filter_query_where = ' WHERE';
80
-		elseif ($filter_query_where != '' && $and) $filter_query_where .= ' AND';
81
+		if ($filter_query_where == '' && $where) {
82
+			$filter_query_where = ' WHERE';
83
+		} elseif ($filter_query_where != '' && $and) {
84
+			$filter_query_where .= ' AND';
85
+		}
81 86
 		if ($filter_query_where != '') {
82 87
 			$filter_query_where = preg_replace('/^ AND/',' WHERE',$filter_query_where);
83 88
 		}
@@ -119,7 +124,9 @@  discard block
 block discarded – undo
119 124
 			}
120 125
 		}
121 126
 
122
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
127
+		if (!isset($globalLiveInterval)) {
128
+			$globalLiveInterval = '200';
129
+		}
123 130
 		if ($globalDBdriver == 'mysql') {
124 131
 			//$query  = "SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate";
125 132
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query.$orderby_query;
@@ -144,7 +151,9 @@  discard block
 block discarded – undo
144 151
 
145 152
 		$filter_query = $this->getFilter($filter,true,true);
146 153
 
147
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
154
+		if (!isset($globalLiveInterval)) {
155
+			$globalLiveInterval = '200';
156
+		}
148 157
 		if ($globalDBdriver == 'mysql') {
149 158
 			$query  = 'SELECT marine_live.mmsi, marine_live.ident, marine_live.type,marine_live.fammarine_id, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
150 159
 			FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate'.$filter_query." marine_live.latitude <> 0 AND marine_live.longitude <> 0";
@@ -178,7 +187,9 @@  discard block
 block discarded – undo
178 187
 
179 188
 		$filter_query = $this->getFilter($filter,true,true);
180 189
 
181
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
190
+		if (!isset($globalLiveInterval)) {
191
+			$globalLiveInterval = '200';
192
+		}
182 193
 		if ($globalDBdriver == 'mysql') {
183 194
 			$query  = 'SELECT marine_live.ident, marine_live.fammarine_id,marine_live.type, marine_live.latitude, marine_live.longitude, marine_live.heading, marine_live.ground_speed, marine_live.date, marine_live.format_source 
184 195
 			FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval." SECOND) <= marine_live.date AND marine_live.latitude <> '0' AND marine_live.longitude <> '0' 
@@ -211,7 +222,9 @@  discard block
 block discarded – undo
211 222
 		global $globalDBdriver, $globalLiveInterval;
212 223
 		$filter_query = $this->getFilter($filter,true,true);
213 224
 
214
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
225
+		if (!isset($globalLiveInterval)) {
226
+			$globalLiveInterval = '200';
227
+		}
215 228
 		if ($globalDBdriver == 'mysql') {
216 229
 			$query = 'SELECT COUNT(DISTINCT marine_live.fammarine_id) as nb FROM marine_live'.$filter_query.' DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
217 230
 		} else {
@@ -239,7 +252,9 @@  discard block
 block discarded – undo
239 252
 	{
240 253
 		global $globalDBdriver, $globalLiveInterval;
241 254
 		$Spotter = new Spotter($this->db);
242
-		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
255
+		if (!isset($globalLiveInterval)) {
256
+			$globalLiveInterval = '200';
257
+		}
243 258
 		$filter_query = $this->getFilter($filter);
244 259
 
245 260
 		if (is_array($coord)) {
@@ -247,7 +262,9 @@  discard block
 block discarded – undo
247 262
 			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
248 263
 			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
249 264
 			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
250
-		} else return array();
265
+		} else {
266
+			return array();
267
+		}
251 268
 		if ($globalDBdriver == 'mysql') {
252 269
 			$query  = 'SELECT marine_live.* FROM marine_live INNER JOIN (SELECT l.fammarine_id, max(l.date) as maxdate FROM marine_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.fammarine_id) s on marine_live.fammarine_id = s.fammarine_id AND marine_live.date = s.maxdate AND marine_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND marine_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY marine_live.fammarine_id'.$filter_query;
253 270
 		} else {
@@ -411,11 +428,15 @@  discard block
 block discarded – undo
411 428
 		//$query  = self::$global_query.' WHERE marine_live.fammarine_id = :id ORDER BY date';
412 429
 		if ($globalDBdriver == 'mysql') {
413 430
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
414
-			if ($liveinterval) $query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
431
+			if ($liveinterval) {
432
+				$query .= ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date';
433
+			}
415 434
 			$query .= ' ORDER BY date';
416 435
 		} else {
417 436
 			$query = 'SELECT marine_live.* FROM marine_live WHERE marine_live.fammarine_id = :id';
418
-			if ($liveinterval) $query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
437
+			if ($liveinterval) {
438
+				$query .= " AND CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date";
439
+			}
419 440
 			$query .= ' ORDER BY date';
420 441
 		}
421 442
 
@@ -510,7 +531,9 @@  discard block
 block discarded – undo
510 531
 				$i++;
511 532
 				$j++;
512 533
 				if ($j == 30) {
513
-					if ($globalDebug) echo ".";
534
+					if ($globalDebug) {
535
+						echo ".";
536
+					}
514 537
 				    	try {
515 538
 						
516 539
 						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
@@ -790,7 +813,9 @@  discard block
 block discarded – undo
790 813
 			{
791 814
 				return false;
792 815
 			}
793
-		} else return '';
816
+		} else {
817
+			return '';
818
+		}
794 819
 
795 820
 		if ($longitude != '')
796 821
 		{
@@ -798,7 +823,9 @@  discard block
 block discarded – undo
798 823
 			{
799 824
 				return false;
800 825
 			}
801
-		} else return '';
826
+		} else {
827
+			return '';
828
+		}
802 829
 
803 830
 
804 831
 		if ($heading != '')
@@ -807,7 +834,9 @@  discard block
 block discarded – undo
807 834
 			{
808 835
 				return false;
809 836
 			}
810
-		} else $heading = 0;
837
+		} else {
838
+			$heading = 0;
839
+		}
811 840
 
812 841
 		if ($groundspeed != '')
813 842
 		{
@@ -815,9 +844,13 @@  discard block
 block discarded – undo
815 844
 			{
816 845
 				return false;
817 846
 			}
818
-		} else $groundspeed = 0;
847
+		} else {
848
+			$groundspeed = 0;
849
+		}
819 850
 		date_default_timezone_set('UTC');
820
-		if ($date == '') $date = date("Y-m-d H:i:s", time());
851
+		if ($date == '') {
852
+			$date = date("Y-m-d H:i:s", time());
853
+		}
821 854
 
822 855
         
823 856
 		$fammarine_id = filter_var($fammarine_id,FILTER_SANITIZE_STRING);
@@ -835,8 +868,12 @@  discard block
 block discarded – undo
835 868
 		$imo = filter_var($imo,FILTER_SANITIZE_STRING);
836 869
 		$callsign = filter_var($callsign,FILTER_SANITIZE_STRING);
837 870
 
838
-            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) $groundspeed = 0;
839
-            	if ($heading == '' || $Common->isInteger($heading) === false ) $heading = 0;
871
+            	if ($groundspeed == '' || $Common->isInteger($groundspeed) === false ) {
872
+            		$groundspeed = 0;
873
+            	}
874
+            	if ($heading == '' || $Common->isInteger($heading) === false ) {
875
+            		$heading = 0;
876
+            	}
840 877
             	
841 878
 		$query  = 'INSERT INTO marine_live (fammarine_id, ident, latitude, longitude, heading, ground_speed, date, format_source, source_name, over_country, mmsi, type,status,imo) 
842 879
 		VALUES (:fammarine_id,:ident,:latitude,:longitude,:heading,:groundspeed,:date,:format_source, :source_name, :over_country,:mmsi,:type,:status,:imo)';
Please login to merge, or discard this patch.
require/class.MarineImport.php 2 patches
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -9,16 +9,16 @@  discard block
 block discarded – undo
9 9
 require_once(dirname(__FILE__).'/class.Source.php');
10 10
 
11 11
 class MarineImport {
12
-    private $all_tracked = 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;
12
+	private $all_tracked = 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 20
 
21
-    public function __construct($dbc = null) {
21
+	public function __construct($dbc = null) {
22 22
 	global $globalBeta;
23 23
 	$Connection = new Connection($dbc);
24 24
 	$this->db = $Connection->db();
@@ -40,50 +40,50 @@  discard block
 block discarded – undo
40 40
 	    }
41 41
 	}
42 42
 	*/
43
-    }
43
+	}
44 44
 
45
-    public function checkAll() {
45
+	public function checkAll() {
46 46
 	global $globalDebug;
47 47
 	if ($globalDebug) echo "Update last seen tracked data...\n";
48 48
 	foreach ($this->all_tracked as $key => $flight) {
49
-	    if (isset($this->all_tracked[$key]['id'])) {
49
+		if (isset($this->all_tracked[$key]['id'])) {
50 50
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
51
-    		$Marine = new Marine($this->db);
52
-        	$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
53
-            }
51
+			$Marine = new Marine($this->db);
52
+			$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']);
53
+			}
54
+	}
54 55
 	}
55
-    }
56 56
 
57
-    public function del() {
57
+	public function del() {
58 58
 	global $globalDebug;
59 59
 	// Delete old infos
60 60
 	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
61 61
 	foreach ($this->all_tracked as $key => $flight) {
62
-    	    if (isset($flight['lastupdate'])) {
63
-        	if ($flight['lastupdate'] < (time()-3000)) {
64
-            	    if (isset($this->all_tracked[$key]['id'])) {
65
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
62
+			if (isset($flight['lastupdate'])) {
63
+			if ($flight['lastupdate'] < (time()-3000)) {
64
+					if (isset($this->all_tracked[$key]['id'])) {
65
+					if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
66 66
 			/*
67 67
 			$MarineLive = new MarineLive();
68 68
             		$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
69 69
 			$MarineLive->db = null;
70 70
 			*/
71
-            		//$real_arrival = $this->arrival($key);
72
-            		$Marine = new Marine($this->db);
73
-            		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
71
+					//$real_arrival = $this->arrival($key);
72
+					$Marine = new Marine($this->db);
73
+					if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
74 74
 				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed']);
75 75
 				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
76 76
 			}
77 77
 			// Put in archive
78 78
 //			$Marine->db = null;
79
-            	    }
80
-            	    unset($this->all_tracked[$key]);
81
-    	        }
82
-	    }
83
-        }
84
-    }
79
+					}
80
+					unset($this->all_tracked[$key]);
81
+				}
82
+		}
83
+		}
84
+	}
85 85
 
86
-    public function add($line) {
86
+	public function add($line) {
87 87
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
88 88
 	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
89 89
 	date_default_timezone_set('UTC');
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 	
93 93
 	// SBS format is CSV format
94 94
 	if(is_array($line) && isset($line['mmsi'])) {
95
-	    //print_r($line);
96
-  	    if (isset($line['mmsi'])) {
95
+		//print_r($line);
96
+  		if (isset($line['mmsi'])) {
97 97
 
98 98
 		/*
99 99
 		// Increment message number
@@ -109,78 +109,78 @@  discard block
 block discarded – undo
109 109
 		*/
110 110
 		
111 111
 		$Common = new Common();
112
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
113
-	        else $id = trim($line['id']);
112
+			if (!isset($line['id'])) $id = trim($line['mmsi']);
113
+			else $id = trim($line['id']);
114 114
 		
115 115
 		if (!isset($this->all_tracked[$id])) {
116
-		    $this->all_tracked[$id] = array();
117
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
118
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => ''));
119
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
120
-		    if (!isset($line['id'])) {
116
+			$this->all_tracked[$id] = array();
117
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
118
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => ''));
119
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
120
+			if (!isset($line['id'])) {
121 121
 			if (!isset($globalDaemon)) $globalDaemon = TRUE;
122 122
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
123
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
123
+			 } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
+			if ($globalAllTracked !== FALSE) $dataFound = true;
125 125
 		}
126 126
 		
127 127
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
128
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
129
-		    $Marine = new Marine($this->db);
130
-		    $identity = $Marine->getIdentity($line['mmsi']);
131
-		    if (!empty($identity)) {
128
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
129
+			$Marine = new Marine($this->db);
130
+			$identity = $Marine->getIdentity($line['mmsi']);
131
+			if (!empty($identity)) {
132 132
 			$this->all_tracked[$id]['ident'] = $identity['ship_name'];
133 133
 			$this->all_tracked[$id]['type'] = $identity['type'];
134
-		    }
135
-		    //print_r($identity);
136
-		    unset($Marine);
137
-		    //$dataFound = true;
134
+			}
135
+			//print_r($identity);
136
+			unset($Marine);
137
+			//$dataFound = true;
138 138
 		}
139 139
 		if (isset($line['type']) && $line['type'] != '') {
140
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
140
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type']));
141 141
 		}
142 142
 		if (isset($line['imo']) && $line['imo'] != '') {
143
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
143
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo']));
144 144
 		}
145 145
 		if (isset($line['callsign']) && $line['callsign'] != '') {
146
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
146
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign']));
147 147
 		}
148 148
 
149 149
 
150 150
 		//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) {
151 151
 		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
152
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
153
-		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
152
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
153
+			if ($this->all_tracked[$id]['addedMarine'] == 1) {
154 154
 			$timeelapsed = microtime(true);
155
-            		$Marine = new Marine($this->db);
156
-            		$fromsource = NULL;
157
-            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
155
+					$Marine = new Marine($this->db);
156
+					$fromsource = NULL;
157
+					$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
158 158
 			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
159 159
 			$Marine->db = null;
160 160
 			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
161
-		    }
162
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
161
+			}
162
+			if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
163 163
 		}
164 164
 
165 165
 		if (isset($line['speed']) && $line['speed'] != '') {
166
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
167
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
166
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
167
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
168 168
 		} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
169
-		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
170
-		    if ($distance > 1000 && $distance < 10000) {
169
+			$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
170
+			if ($distance > 1000 && $distance < 10000) {
171 171
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
172 172
 			$speed = $speed*3.6;
173 173
 			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
174 174
   			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
175
-		    }
175
+			}
176 176
 		}
177 177
 
178
-	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
179
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
180
-	    	    else unset($timediff);
181
-	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
178
+			if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
179
+				if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
180
+				else unset($timediff);
181
+				if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
182 182
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
183
-			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
183
+				if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
184 184
 				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
185 185
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
186 186
 				$this->all_tracked[$id]['putinarchive'] = true;
@@ -194,76 +194,76 @@  discard block
 block discarded – undo
194 194
 				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
195 195
 				$this->tmd = 0;
196 196
 				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
197
-			    }
197
+				}
198 198
 			}
199 199
 
200 200
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
201 201
 				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
202 202
 				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
203
-				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
204
-				    $dataFound = true;
205
-				    $this->all_tracked[$id]['time_last_coord'] = time();
203
+					$this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
204
+					$dataFound = true;
205
+					$this->all_tracked[$id]['time_last_coord'] = time();
206 206
 				}
207 207
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
208 208
 			}
209 209
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
210
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
210
+				if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
211 211
 				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
212 212
 				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
213
-				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
214
-				    $dataFound = true;
215
-				    $this->all_tracked[$id]['time_last_coord'] = time();
213
+					$this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
214
+					$dataFound = true;
215
+					$this->all_tracked[$id]['time_last_coord'] = time();
216 216
 				}
217 217
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
218 218
 			}
219 219
 
220
-		    } else if ($globalDebug && $timediff > 20) {
220
+			} else if ($globalDebug && $timediff > 20) {
221 221
 			$this->tmd = $this->tmd + 1;
222 222
 			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
223 223
 			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
224 224
 			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
225 225
 			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
226
-		    }
226
+			}
227 227
 		}
228 228
 		if (isset($line['last_update']) && $line['last_update'] != '') {
229
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
230
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
229
+			if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
230
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
231 231
 		}
232 232
 		if (isset($line['format_source']) && $line['format_source'] != '') {
233
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
233
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
234 234
 		}
235 235
 		if (isset($line['source_name']) && $line['source_name'] != '') {
236
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
236
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
237 237
 		}
238 238
 		if (isset($line['status']) && $line['status'] != '') {
239
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
239
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
240 240
 		}
241 241
 
242 242
 		if (isset($line['noarchive']) && $line['noarchive'] === true) {
243
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
243
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
244 244
 		}
245 245
 		
246 246
 		if (isset($line['heading']) && $line['heading'] != '') {
247
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
248
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
249
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
250
-		    //$dataFound = true;
247
+			if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
248
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
249
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
250
+			//$dataFound = true;
251 251
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
252
-  		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
253
-		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
254
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
255
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
252
+  			$heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
253
+			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
254
+			if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
255
+  			if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
256 256
   		}
257 257
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
258 258
 
259 259
 		if (isset($line['datetime'])) {
260
-		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
260
+			if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
261 261
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
262
-		    } else {
262
+			} else {
263 263
 				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
264 264
 				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
265 265
 				return '';
266
-		    }
266
+			}
267 267
 		} else {
268 268
 			date_default_timezone_set('UTC');
269 269
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
@@ -271,45 +271,45 @@  discard block
 block discarded – undo
271 271
 
272 272
 
273 273
 		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
274
-		    $this->all_tracked[$id]['lastupdate'] = time();
275
-		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
276
-		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
277
-			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
274
+			$this->all_tracked[$id]['lastupdate'] = time();
275
+			if ($this->all_tracked[$id]['addedMarine'] == 0) {
276
+				if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
277
+				if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
278 278
 				if ($globalDebug) echo "Check if aircraft is already in DB...";
279 279
 				$timeelapsed = microtime(true);
280 280
 				$MarineLive = new MarineLive($this->db);
281 281
 				if (isset($line['id'])) {
282
-				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
283
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
282
+					$recent_ident = $MarineLive->checkIdRecent($line['id']);
283
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
284 284
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
285
-				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
286
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
285
+					$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
286
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
287 287
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
288
-				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
289
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
288
+					$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
289
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
290 290
 				} else $recent_ident = '';
291 291
 				$MarineLive->db=null;
292 292
 				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
293 293
 				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
294
-			    } else {
294
+				} else {
295 295
 				$recent_ident = '';
296 296
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
297
-			    }
298
-			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
299
-			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
300
-			    {
297
+				}
298
+				//if there was no aircraft with the same callsign within the last hour and go post it into the archive
299
+				if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
300
+				{
301 301
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
302 302
 				//adds the spotter data for the archive
303
-				    $highlight = '';
304
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
305
-				    $timeelapsed = microtime(true);
306
-				    $Marine = new Marine($this->db);
307
-				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
308
-				    $Marine->db = null;
309
-				    if ($globalDebug && isset($result)) echo $result."\n";
310
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
303
+					$highlight = '';
304
+					if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
305
+					$timeelapsed = microtime(true);
306
+					$Marine = new Marine($this->db);
307
+					$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
308
+					$Marine->db = null;
309
+					if ($globalDebug && isset($result)) echo $result."\n";
310
+					if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
311 311
 				    
312
-				    /*
312
+					/*
313 313
 				    // Add source stat in DB
314 314
 				    $Stats = new Stats($this->db);
315 315
 				    if (!empty($this->stats)) {
@@ -336,20 +336,20 @@  discard block
 block discarded – undo
336 336
 				    }
337 337
 				    $Stats->db = null;
338 338
 				    */
339
-				    $this->del();
339
+					$this->del();
340 340
 				//$ignoreImport = false;
341 341
 				$this->all_tracked[$id]['addedMarine'] = 1;
342 342
 				//print_r($this->all_tracked[$id]);
343 343
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
344
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
345
-				    //MarineLive->deleteLiveMarineDataNotUpdated();
346
-				    $MarineLive = new MarineLive($this->db);
347
-				    $MarineLive->deleteLiveMarineData();
348
-				    $MarineLive->db=null;
349
-				    if ($globalDebug) echo " Done\n";
350
-				    $this->last_delete = time();
344
+					if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
345
+					//MarineLive->deleteLiveMarineDataNotUpdated();
346
+					$MarineLive = new MarineLive($this->db);
347
+					$MarineLive->deleteLiveMarineData();
348
+					$MarineLive->db=null;
349
+					if ($globalDebug) echo " Done\n";
350
+					$this->last_delete = time();
351 351
 				}
352
-			    } elseif ($recent_ident != '') {
352
+				} elseif ($recent_ident != '') {
353 353
 				$this->all_tracked[$id]['id'] = $recent_ident;
354 354
 				$this->all_tracked[$id]['addedMarine'] = 1;
355 355
 				if (isset($globalDaemon) && !$globalDaemon) {
@@ -358,16 +358,16 @@  discard block
 block discarded – undo
358 358
 					$Marine->db = null;
359 359
 				}
360 360
 				
361
-			    }
361
+				}
362
+			}
362 363
 			}
363
-		    }
364
-		    //adds the spotter LIVE data
365
-		    if ($globalDebug) {
364
+			//adds the spotter LIVE data
365
+			if ($globalDebug) {
366 366
 			echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n";
367
-		    }
368
-		    $ignoreImport = false;
367
+			}
368
+			$ignoreImport = false;
369 369
 
370
-		    if (!$ignoreImport) {
370
+			if (!$ignoreImport) {
371 371
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
372 372
 				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
373 373
 				$timeelapsed = microtime(true);
@@ -439,22 +439,22 @@  discard block
 block discarded – undo
439 439
 			
440 440
 			
441 441
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
442
-			    if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
443
-			    $MarineLive = new MarineLive($this->db);
444
-			    $MarineLive->deleteLiveMarineDataNotUpdated();
445
-			    $MarineLive->db = null;
446
-			    //MarineLive->deleteLiveMarineData();
447
-			    if ($globalDebug) echo " Done\n";
448
-			    $this->last_delete_hourly = time();
442
+				if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
443
+				$MarineLive = new MarineLive($this->db);
444
+				$MarineLive->deleteLiveMarineDataNotUpdated();
445
+				$MarineLive->db = null;
446
+				//MarineLive->deleteLiveMarineData();
447
+				if ($globalDebug) echo " Done\n";
448
+				$this->last_delete_hourly = time();
449 449
 			}
450 450
 			
451
-		    }
452
-		    //$ignoreImport = false;
451
+			}
452
+			//$ignoreImport = false;
453 453
 		}
454 454
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
455 455
 		if ($send) return $this->all_tracked[$id];
456
-	    }
456
+		}
457
+	}
457 458
 	}
458
-    }
459 459
 }
460 460
 ?>
Please login to merge, or discard this patch.
Braces   +149 added lines, -51 removed lines patch added patch discarded remove patch
@@ -44,7 +44,9 @@  discard block
 block discarded – undo
44 44
 
45 45
     public function checkAll() {
46 46
 	global $globalDebug;
47
-	if ($globalDebug) echo "Update last seen tracked data...\n";
47
+	if ($globalDebug) {
48
+		echo "Update last seen tracked data...\n";
49
+	}
48 50
 	foreach ($this->all_tracked as $key => $flight) {
49 51
 	    if (isset($this->all_tracked[$key]['id'])) {
50 52
 		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
@@ -57,12 +59,16 @@  discard block
 block discarded – undo
57 59
     public function del() {
58 60
 	global $globalDebug;
59 61
 	// Delete old infos
60
-	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
62
+	if ($globalDebug) {
63
+		echo 'Delete old values and update latest data...'."\n";
64
+	}
61 65
 	foreach ($this->all_tracked as $key => $flight) {
62 66
     	    if (isset($flight['lastupdate'])) {
63 67
         	if ($flight['lastupdate'] < (time()-3000)) {
64 68
             	    if (isset($this->all_tracked[$key]['id'])) {
65
-            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
69
+            		if ($globalDebug) {
70
+            			echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
71
+            		}
66 72
 			/*
67 73
 			$MarineLive = new MarineLive();
68 74
             		$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
@@ -72,7 +78,9 @@  discard block
 block discarded – undo
72 78
             		$Marine = new Marine($this->db);
73 79
             		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
74 80
 				$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed']);
75
-				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
81
+				if ($globalDebug && $result != 'success') {
82
+					echo '!!! ERROR : '.$result."\n";
83
+				}
76 84
 			}
77 85
 			// Put in archive
78 86
 //			$Marine->db = null;
@@ -85,7 +93,9 @@  discard block
 block discarded – undo
85 93
 
86 94
     public function add($line) {
87 95
 	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
88
-	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
96
+	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') {
97
+		$globalCoordMinChange = '0.02';
98
+	}
89 99
 	date_default_timezone_set('UTC');
90 100
 	$dataFound = false;
91 101
 	$send = false;
@@ -109,8 +119,11 @@  discard block
 block discarded – undo
109 119
 		*/
110 120
 		
111 121
 		$Common = new Common();
112
-	        if (!isset($line['id'])) $id = trim($line['mmsi']);
113
-	        else $id = trim($line['id']);
122
+	        if (!isset($line['id'])) {
123
+	        	$id = trim($line['mmsi']);
124
+	        } else {
125
+	        	$id = trim($line['id']);
126
+	        }
114 127
 		
115 128
 		if (!isset($this->all_tracked[$id])) {
116 129
 		    $this->all_tracked[$id] = array();
@@ -118,10 +131,16 @@  discard block
 block discarded – undo
118 131
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => ''));
119 132
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
120 133
 		    if (!isset($line['id'])) {
121
-			if (!isset($globalDaemon)) $globalDaemon = TRUE;
134
+			if (!isset($globalDaemon)) {
135
+				$globalDaemon = TRUE;
136
+			}
122 137
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
123
-		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
-		    if ($globalAllTracked !== FALSE) $dataFound = true;
138
+		     } else {
139
+		     	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
140
+		     }
141
+		    if ($globalAllTracked !== FALSE) {
142
+		    	$dataFound = true;
143
+		    }
125 144
 		}
126 145
 		
127 146
 		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
@@ -155,11 +174,17 @@  discard block
 block discarded – undo
155 174
             		$Marine = new Marine($this->db);
156 175
             		$fromsource = NULL;
157 176
             		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
158
-			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
177
+			if ($globalDebug && $result != 'success') {
178
+				echo '!!! ERROR : '.$result."\n";
179
+			}
159 180
 			$Marine->db = null;
160
-			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
181
+			if ($globalDebugTimeElapsed) {
182
+				echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
183
+			}
184
+		    }
185
+		    if (!isset($this->all_tracked[$id]['id'])) {
186
+		    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
161 187
 		    }
162
-		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
163 188
 		}
164 189
 
165 190
 		if (isset($line['speed']) && $line['speed'] != '') {
@@ -170,14 +195,21 @@  discard block
 block discarded – undo
170 195
 		    if ($distance > 1000 && $distance < 10000) {
171 196
 			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
172 197
 			$speed = $speed*3.6;
173
-			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
174
-  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
198
+			if ($speed < 1000) {
199
+				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
200
+			}
201
+  			if ($globalDebug) {
202
+  				echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
203
+  			}
175 204
 		    }
176 205
 		}
177 206
 
178 207
 	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
179
-	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
180
-	    	    else unset($timediff);
208
+	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) {
209
+	    	    	$timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
210
+	    	    } else {
211
+	    	    	unset($timediff);
212
+	    	    }
181 213
 	    	    if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) {
182 214
 			if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) {
183 215
 			    if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
@@ -185,20 +217,30 @@  discard block
 block discarded – undo
185 217
 				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
186 218
 				$this->all_tracked[$id]['putinarchive'] = true;
187 219
 				
188
-				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
220
+				if ($globalDebug) {
221
+					echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
222
+				}
189 223
 				$timeelapsed = microtime(true);
190 224
 				$Marine = new Marine($this->db);
191 225
 				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
192
-				if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
226
+				if (!empty($all_country)) {
227
+					$this->all_tracked[$id]['over_country'] = $all_country['iso2'];
228
+				}
193 229
 				$Marine->db = null;
194
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
230
+				if ($globalDebugTimeElapsed) {
231
+					echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
232
+				}
195 233
 				$this->tmd = 0;
196
-				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
234
+				if ($globalDebug) {
235
+					echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
236
+				}
197 237
 			    }
198 238
 			}
199 239
 
200 240
 			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
201
-				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
241
+				if (!isset($this->all_tracked[$id]['archive_latitude'])) {
242
+					$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
243
+				}
202 244
 				if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
203 245
 				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
204 246
 				    $dataFound = true;
@@ -207,8 +249,12 @@  discard block
 block discarded – undo
207 249
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
208 250
 			}
209 251
 			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
210
-			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
211
-				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
252
+			    if ($line['longitude'] > 180) {
253
+			    	$line['longitude'] = $line['longitude'] - 360;
254
+			    }
255
+				if (!isset($this->all_tracked[$id]['archive_longitude'])) {
256
+					$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
257
+				}
212 258
 				if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') {
213 259
 				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
214 260
 				    $dataFound = true;
@@ -226,7 +272,9 @@  discard block
 block discarded – undo
226 272
 		    }
227 273
 		}
228 274
 		if (isset($line['last_update']) && $line['last_update'] != '') {
229
-		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
275
+		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) {
276
+		    	$dataFound = true;
277
+		    }
230 278
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
231 279
 		}
232 280
 		if (isset($line['format_source']) && $line['format_source'] != '') {
@@ -244,15 +292,21 @@  discard block
 block discarded – undo
244 292
 		}
245 293
 		
246 294
 		if (isset($line['heading']) && $line['heading'] != '') {
247
-		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
295
+		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) {
296
+		    	$this->all_tracked[$id]['putinarchive'] = true;
297
+		    }
248 298
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
249 299
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
250 300
 		    //$dataFound = true;
251 301
   		} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) {
252 302
   		    $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
253 303
 		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
254
-		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
255
-  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
304
+		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) {
305
+		    	$this->all_tracked[$id]['putinarchive'] = true;
306
+		    }
307
+  		    if ($globalDebug) {
308
+  		    	echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
309
+  		    }
256 310
   		}
257 311
 		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
258 312
 
@@ -260,8 +314,11 @@  discard block
 block discarded – undo
260 314
 		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
261 315
 			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
262 316
 		    } else {
263
-				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
264
-				elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
317
+				if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
318
+					echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n";
319
+				} elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) {
320
+					echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n";
321
+				}
265 322
 				return '';
266 323
 		    }
267 324
 		} else {
@@ -275,22 +332,35 @@  discard block
 block discarded – undo
275 332
 		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
276 333
 		        if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == ''  || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
277 334
 			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
278
-				if ($globalDebug) echo "Check if aircraft is already in DB...";
335
+				if ($globalDebug) {
336
+					echo "Check if aircraft is already in DB...";
337
+				}
279 338
 				$timeelapsed = microtime(true);
280 339
 				$MarineLive = new MarineLive($this->db);
281 340
 				if (isset($line['id'])) {
282 341
 				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
283
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
342
+				    if ($globalDebugTimeElapsed) {
343
+				    	echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
344
+				    }
284 345
 				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
285 346
 				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
286
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
347
+				    if ($globalDebugTimeElapsed) {
348
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
349
+				    }
287 350
 				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
288 351
 				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
289
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
290
-				} else $recent_ident = '';
352
+				    if ($globalDebugTimeElapsed) {
353
+				    	echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
354
+				    }
355
+				} else {
356
+					$recent_ident = '';
357
+				}
291 358
 				$MarineLive->db=null;
292
-				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
293
-				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
359
+				if ($globalDebug && $recent_ident == '') {
360
+					echo " Not in DB.\n";
361
+				} elseif ($globalDebug && $recent_ident != '') {
362
+					echo " Already in DB.\n";
363
+				}
294 364
 			    } else {
295 365
 				$recent_ident = '';
296 366
 				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
@@ -298,16 +368,24 @@  discard block
 block discarded – undo
298 368
 			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
299 369
 			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
300 370
 			    {
301
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
371
+				if ($globalDebug) {
372
+					echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
373
+				}
302 374
 				//adds the spotter data for the archive
303 375
 				    $highlight = '';
304
-				    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
376
+				    if (!isset($this->all_tracked[$id]['id'])) {
377
+				    	$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi')));
378
+				    }
305 379
 				    $timeelapsed = microtime(true);
306 380
 				    $Marine = new Marine($this->db);
307 381
 				    $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
308 382
 				    $Marine->db = null;
309
-				    if ($globalDebug && isset($result)) echo $result."\n";
310
-				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
383
+				    if ($globalDebug && isset($result)) {
384
+				    	echo $result."\n";
385
+				    }
386
+				    if ($globalDebugTimeElapsed) {
387
+				    	echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
388
+				    }
311 389
 				    
312 390
 				    /*
313 391
 				    // Add source stat in DB
@@ -341,12 +419,16 @@  discard block
 block discarded – undo
341 419
 				$this->all_tracked[$id]['addedMarine'] = 1;
342 420
 				//print_r($this->all_tracked[$id]);
343 421
 				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
344
-				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
422
+				    if ($globalDebug) {
423
+				    	echo "---- Deleting Live Marine data older than 9 hours...";
424
+				    }
345 425
 				    //MarineLive->deleteLiveMarineDataNotUpdated();
346 426
 				    $MarineLive = new MarineLive($this->db);
347 427
 				    $MarineLive->deleteLiveMarineData();
348 428
 				    $MarineLive->db=null;
349
-				    if ($globalDebug) echo " Done\n";
429
+				    if ($globalDebug) {
430
+				    	echo " Done\n";
431
+				    }
350 432
 				    $this->last_delete = time();
351 433
 				}
352 434
 			    } elseif ($recent_ident != '') {
@@ -369,13 +451,17 @@  discard block
 block discarded – undo
369 451
 
370 452
 		    if (!$ignoreImport) {
371 453
 			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
372
-				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
454
+				if ($globalDebug) {
455
+					echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
456
+				}
373 457
 				$timeelapsed = microtime(true);
374 458
 				$MarineLive = new MarineLive($this->db);
375 459
 				$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
376 460
 				$MarineLive->db = null;
377 461
 				$this->all_tracked[$id]['putinarchive'] = false;
378
-				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
462
+				if ($globalDebugTimeElapsed) {
463
+					echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
464
+				}
379 465
 
380 466
 				// Put statistics in $this->stats variable
381 467
 				/*
@@ -432,19 +518,29 @@  discard block
 block discarded – undo
432 518
 				*/
433 519
 
434 520
 				$this->all_tracked[$id]['lastupdate'] = time();
435
-				if ($this->all_tracked[$id]['putinarchive']) $send = true;
436
-				if ($globalDebug) echo $result."\n";
437
-			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
521
+				if ($this->all_tracked[$id]['putinarchive']) {
522
+					$send = true;
523
+				}
524
+				if ($globalDebug) {
525
+					echo $result."\n";
526
+				}
527
+			} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) {
528
+				echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
529
+			}
438 530
 			//$this->del();
439 531
 			
440 532
 			
441 533
 			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
442
-			    if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
534
+			    if ($globalDebug) {
535
+			    	echo "---- Deleting Live Marine data Not updated since 2 hour...";
536
+			    }
443 537
 			    $MarineLive = new MarineLive($this->db);
444 538
 			    $MarineLive->deleteLiveMarineDataNotUpdated();
445 539
 			    $MarineLive->db = null;
446 540
 			    //MarineLive->deleteLiveMarineData();
447
-			    if ($globalDebug) echo " Done\n";
541
+			    if ($globalDebug) {
542
+			    	echo " Done\n";
543
+			    }
448 544
 			    $this->last_delete_hourly = time();
449 545
 			}
450 546
 			
@@ -452,7 +548,9 @@  discard block
 block discarded – undo
452 548
 		    //$ignoreImport = false;
453 549
 		}
454 550
 		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
455
-		if ($send) return $this->all_tracked[$id];
551
+		if ($send) {
552
+			return $this->all_tracked[$id];
553
+		}
456 554
 	    }
457 555
 	}
458 556
     }
Please login to merge, or discard this patch.
require/class.AIS.php 1 patch
Braces   +297 added lines, -129 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
35 35
 			$temp += 1;
36 36
 			$flat = (float)($temp / (60.0 * 10000.0));
37 37
 			$flat *= -1.0;
38
-		} else $flat = (float)($temp / (60.0 * 10000.0));
38
+		} else {
39
+			$flat = (float)($temp / (60.0 * 10000.0));
40
+		}
39 41
 		return $flat; // float
40 42
 	}
41 43
 
@@ -47,7 +49,9 @@  discard block
 block discarded – undo
47 49
 			$temp += 1;
48 50
 			$flon = (float)($temp / (60.0 * 10000.0));
49 51
 			$flon *= -1.0;
50
-		} else $flon = (float)($temp / (60.0 * 10000.0));
52
+		} else {
53
+			$flon = (float)($temp / (60.0 * 10000.0));
54
+		}
51 55
 		return $flon;
52 56
 	}
53 57
 
@@ -70,10 +74,8 @@  discard block
 block discarded – undo
70 74
     */
71 75
 	private function asciidec_2_8bit($ascii) {
72 76
 		//only process in the following range: 48-87, 96-119
73
-		if ($ascii < 48) { }
74
-		else {
75
-			if($ascii>119) { }
76
-			else {
77
+		if ($ascii < 48) { } else {
78
+			if($ascii>119) { } else {
77 79
 				if ($ascii>87 && $ascii<96) ;
78 80
 				else {
79 81
 					$ascii=$ascii+40;
@@ -169,7 +171,9 @@  discard block
 block discarded – undo
169 171
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28)));
170 172
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27)));
171 173
 			$ro->heading = bindec(substr($_aisdata,124,9));
172
-			if ($ro->heading == 511) $ro->heading = '';
174
+			if ($ro->heading == 511) {
175
+				$ro->heading = '';
176
+			}
173 177
 			$ro->cls = 2; // class B
174 178
 		} else if ($ro->id == 19) {
175 179
 			$ro->cog = bindec(substr($_aisdata,112,12))/10;
@@ -179,7 +183,9 @@  discard block
 block discarded – undo
179 183
 			$ro->name = $this->binchar($_aisdata,143,120);
180 184
 			$ro->cls = 2; // class B
181 185
 			$ro->heading = bindec(substr($_aisdata,124,9));
182
-			if ($ro->heading == 511) $ro->heading = '';
186
+			if ($ro->heading == 511) {
187
+				$ro->heading = '';
188
+			}
183 189
 			$ro->typeid = bindec(substr($_aisdata,263,8));
184 190
 			$ro->type = $this->getShipType($ro->typeid);
185 191
 			//$ro->to_bow = bindec(substr($_aisdata,271,9));
@@ -210,9 +216,13 @@  discard block
 block discarded – undo
210 216
 			$ro->cls = 2; // class B
211 217
 		} else if ($ro->id == 27) {
212 218
 			$ro->cog = bindec(substr($_aisdata,85,9));
213
-			if ($ro->cog == 511) $ro->cog = 0.0;
219
+			if ($ro->cog == 511) {
220
+				$ro->cog = 0.0;
221
+			}
214 222
 			$ro->sog = bindec(substr($_aisdata,79,6));
215
-			if ($ro->sog == 63) $ro->sog = 0.0;
223
+			if ($ro->sog == 63) {
224
+				$ro->sog = 0.0;
225
+			}
216 226
 			$ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10);
217 227
 			$ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10);
218 228
 			$ro->cls = 1; // class A
@@ -261,88 +271,171 @@  discard block
 block discarded – undo
261 271
 	}
262 272
 	
263 273
 	public function getShipType($code) {
264
-		if ($code == 0) return 'Not available (default)';
265
-		elseif ($code >= 1 && $code <= 19) return 'Reserved for future use';
266
-		elseif ($code == 20) return 'Wing in ground (WIG), all ships of this type';
267
-		elseif ($code == 21) return 'Wing in ground (WIG), Hazardous category A';
268
-		elseif ($code == 22) return 'Wing in ground (WIG), Hazardous category B';
269
-		elseif ($code == 23) return 'Wing in ground (WIG), Hazardous category C';
270
-		elseif ($code == 24) return 'Wing in ground (WIG), Hazardous category D';
271
-		elseif ($code == 25) return 'Wing in ground (WIG), Reserved for future use';
272
-		elseif ($code == 26) return 'Wing in ground (WIG), Reserved for future use';
273
-		elseif ($code == 27) return 'Wing in ground (WIG), Reserved for future use';
274
-		elseif ($code == 28) return 'Wing in ground (WIG), Reserved for future use';
275
-		elseif ($code == 29) return 'Wing in ground (WIG), Reserved for future use';
276
-		elseif ($code == 30) return 'Fishing';
277
-		elseif ($code == 31) return 'Towing';
278
-		elseif ($code == 32) return 'Towing: length exceeds 200m or breadth exceeds 25m';
279
-		elseif ($code == 33) return 'Dredging or underwater ops';
280
-		elseif ($code == 34) return 'Diving ops';
281
-		elseif ($code == 35) return 'Military ops';
282
-		elseif ($code == 36) return 'Sailing';
283
-		elseif ($code == 37) return 'Pleasure Craft';
284
-		elseif ($code == 38) return 'Reserved';
285
-		elseif ($code == 39) return 'Reserved';
286
-		elseif ($code == 40) return 'High speed craft (HSC), all ships of this type';
287
-		elseif ($code == 41) return 'High speed craft (HSC), Hazardous category A';
288
-		elseif ($code == 42) return 'High speed craft (HSC), Hazardous category B';
289
-		elseif ($code == 43) return 'High speed craft (HSC), Hazardous category C';
290
-		elseif ($code == 44) return 'High speed craft (HSC), Hazardous category D';
291
-		elseif ($code == 45) return 'High speed craft (HSC), Reserved for future use';
292
-		elseif ($code == 46) return 'High speed craft (HSC), Reserved for future use';
293
-		elseif ($code == 47) return 'High speed craft (HSC), Reserved for future use';
294
-		elseif ($code == 48) return 'High speed craft (HSC), Reserved for future use';
295
-		elseif ($code == 49) return 'High speed craft (HSC), No additional information';
296
-		elseif ($code == 50) return 'Pilot Vessel';
297
-		elseif ($code == 51) return 'Search and Rescue vessel';
298
-		elseif ($code == 52) return 'Tug';
299
-		elseif ($code == 53) return 'Port Tender';
300
-		elseif ($code == 54) return 'Anti-pollution equipment';
301
-		elseif ($code == 55) return 'Law Enforcement';
302
-		elseif ($code == 56) return 'Spare - Local Vessel';
303
-		elseif ($code == 57) return 'Spare - Local Vessel';
304
-		elseif ($code == 58) return 'Medical Transport';
305
-		elseif ($code == 59) return 'Noncombatant ship according to RR Resolution No. 18';
306
-		elseif ($code == 60) return 'Passenger, all ships of this type';
307
-		elseif ($code == 61) return 'Passenger, Hazardous category A';
308
-		elseif ($code == 62) return 'Passenger, Hazardous category B';
309
-		elseif ($code == 63) return 'Passenger, Hazardous category C';
310
-		elseif ($code == 64) return 'Passenger, Hazardous category D';
311
-		elseif ($code == 65) return 'Passenger, Reserved for future use';
312
-		elseif ($code == 66) return 'Passenger, Reserved for future use';
313
-		elseif ($code == 67) return 'Passenger, Reserved for future use';
314
-		elseif ($code == 68) return 'Passenger, Reserved for future use';
315
-		elseif ($code == 69) return 'Passenger, No additional information';
316
-		elseif ($code == 70) return 'Cargo, all ships of this type';
317
-		elseif ($code == 71) return 'Cargo, Hazardous category A';
318
-		elseif ($code == 72) return 'Cargo, Hazardous category B';
319
-		elseif ($code == 73) return 'Cargo, Hazardous category C';
320
-		elseif ($code == 74) return 'Cargo, Hazardous category D';
321
-		elseif ($code == 75) return 'Cargo, Reserved for future use';
322
-		elseif ($code == 76) return 'Cargo, Reserved for future use';
323
-		elseif ($code == 77) return 'Cargo, Reserved for future use';
324
-		elseif ($code == 78) return 'Cargo, Reserved for future use';
325
-		elseif ($code == 79) return 'Cargo, No additional information';
326
-		elseif ($code == 80) return 'Tanker, all ships of this type';
327
-		elseif ($code == 81) return 'Tanker, Hazardous category A';
328
-		elseif ($code == 82) return 'Tanker, Hazardous category B';
329
-		elseif ($code == 83) return 'Tanker, Hazardous category C';
330
-		elseif ($code == 84) return 'Tanker, Hazardous category D';
331
-		elseif ($code == 85) return 'Tanker, Reserved for future use';
332
-		elseif ($code == 86) return 'Tanker, Reserved for future use';
333
-		elseif ($code == 87) return 'Tanker, Reserved for future use';
334
-		elseif ($code == 88) return 'Tanker, Reserved for future use';
335
-		elseif ($code == 89) return 'Tanker, No additional information';
336
-		elseif ($code == 90) return 'Other Type, all ships of this type';
337
-		elseif ($code == 91) return 'Other Type, Hazardous category A';
338
-		elseif ($code == 92) return 'Other Type, Hazardous category B';
339
-		elseif ($code == 93) return 'Other Type, Hazardous category C';
340
-		elseif ($code == 94) return 'Other Type, Hazardous category D';
341
-		elseif ($code == 95) return 'Other Type, Reserved for future use';
342
-		elseif ($code == 96) return 'Other Type, Reserved for future use';
343
-		elseif ($code == 97) return 'Other Type, Reserved for future use';
344
-		elseif ($code == 98) return 'Other Type, Reserved for future use';
345
-		elseif ($code == 99) return 'Other Type, no additional information';
274
+		if ($code == 0) {
275
+			return 'Not available (default)';
276
+		} elseif ($code >= 1 && $code <= 19) {
277
+			return 'Reserved for future use';
278
+		} elseif ($code == 20) {
279
+			return 'Wing in ground (WIG), all ships of this type';
280
+		} elseif ($code == 21) {
281
+			return 'Wing in ground (WIG), Hazardous category A';
282
+		} elseif ($code == 22) {
283
+			return 'Wing in ground (WIG), Hazardous category B';
284
+		} elseif ($code == 23) {
285
+			return 'Wing in ground (WIG), Hazardous category C';
286
+		} elseif ($code == 24) {
287
+			return 'Wing in ground (WIG), Hazardous category D';
288
+		} elseif ($code == 25) {
289
+			return 'Wing in ground (WIG), Reserved for future use';
290
+		} elseif ($code == 26) {
291
+			return 'Wing in ground (WIG), Reserved for future use';
292
+		} elseif ($code == 27) {
293
+			return 'Wing in ground (WIG), Reserved for future use';
294
+		} elseif ($code == 28) {
295
+			return 'Wing in ground (WIG), Reserved for future use';
296
+		} elseif ($code == 29) {
297
+			return 'Wing in ground (WIG), Reserved for future use';
298
+		} elseif ($code == 30) {
299
+			return 'Fishing';
300
+		} elseif ($code == 31) {
301
+			return 'Towing';
302
+		} elseif ($code == 32) {
303
+			return 'Towing: length exceeds 200m or breadth exceeds 25m';
304
+		} elseif ($code == 33) {
305
+			return 'Dredging or underwater ops';
306
+		} elseif ($code == 34) {
307
+			return 'Diving ops';
308
+		} elseif ($code == 35) {
309
+			return 'Military ops';
310
+		} elseif ($code == 36) {
311
+			return 'Sailing';
312
+		} elseif ($code == 37) {
313
+			return 'Pleasure Craft';
314
+		} elseif ($code == 38) {
315
+			return 'Reserved';
316
+		} elseif ($code == 39) {
317
+			return 'Reserved';
318
+		} elseif ($code == 40) {
319
+			return 'High speed craft (HSC), all ships of this type';
320
+		} elseif ($code == 41) {
321
+			return 'High speed craft (HSC), Hazardous category A';
322
+		} elseif ($code == 42) {
323
+			return 'High speed craft (HSC), Hazardous category B';
324
+		} elseif ($code == 43) {
325
+			return 'High speed craft (HSC), Hazardous category C';
326
+		} elseif ($code == 44) {
327
+			return 'High speed craft (HSC), Hazardous category D';
328
+		} elseif ($code == 45) {
329
+			return 'High speed craft (HSC), Reserved for future use';
330
+		} elseif ($code == 46) {
331
+			return 'High speed craft (HSC), Reserved for future use';
332
+		} elseif ($code == 47) {
333
+			return 'High speed craft (HSC), Reserved for future use';
334
+		} elseif ($code == 48) {
335
+			return 'High speed craft (HSC), Reserved for future use';
336
+		} elseif ($code == 49) {
337
+			return 'High speed craft (HSC), No additional information';
338
+		} elseif ($code == 50) {
339
+			return 'Pilot Vessel';
340
+		} elseif ($code == 51) {
341
+			return 'Search and Rescue vessel';
342
+		} elseif ($code == 52) {
343
+			return 'Tug';
344
+		} elseif ($code == 53) {
345
+			return 'Port Tender';
346
+		} elseif ($code == 54) {
347
+			return 'Anti-pollution equipment';
348
+		} elseif ($code == 55) {
349
+			return 'Law Enforcement';
350
+		} elseif ($code == 56) {
351
+			return 'Spare - Local Vessel';
352
+		} elseif ($code == 57) {
353
+			return 'Spare - Local Vessel';
354
+		} elseif ($code == 58) {
355
+			return 'Medical Transport';
356
+		} elseif ($code == 59) {
357
+			return 'Noncombatant ship according to RR Resolution No. 18';
358
+		} elseif ($code == 60) {
359
+			return 'Passenger, all ships of this type';
360
+		} elseif ($code == 61) {
361
+			return 'Passenger, Hazardous category A';
362
+		} elseif ($code == 62) {
363
+			return 'Passenger, Hazardous category B';
364
+		} elseif ($code == 63) {
365
+			return 'Passenger, Hazardous category C';
366
+		} elseif ($code == 64) {
367
+			return 'Passenger, Hazardous category D';
368
+		} elseif ($code == 65) {
369
+			return 'Passenger, Reserved for future use';
370
+		} elseif ($code == 66) {
371
+			return 'Passenger, Reserved for future use';
372
+		} elseif ($code == 67) {
373
+			return 'Passenger, Reserved for future use';
374
+		} elseif ($code == 68) {
375
+			return 'Passenger, Reserved for future use';
376
+		} elseif ($code == 69) {
377
+			return 'Passenger, No additional information';
378
+		} elseif ($code == 70) {
379
+			return 'Cargo, all ships of this type';
380
+		} elseif ($code == 71) {
381
+			return 'Cargo, Hazardous category A';
382
+		} elseif ($code == 72) {
383
+			return 'Cargo, Hazardous category B';
384
+		} elseif ($code == 73) {
385
+			return 'Cargo, Hazardous category C';
386
+		} elseif ($code == 74) {
387
+			return 'Cargo, Hazardous category D';
388
+		} elseif ($code == 75) {
389
+			return 'Cargo, Reserved for future use';
390
+		} elseif ($code == 76) {
391
+			return 'Cargo, Reserved for future use';
392
+		} elseif ($code == 77) {
393
+			return 'Cargo, Reserved for future use';
394
+		} elseif ($code == 78) {
395
+			return 'Cargo, Reserved for future use';
396
+		} elseif ($code == 79) {
397
+			return 'Cargo, No additional information';
398
+		} elseif ($code == 80) {
399
+			return 'Tanker, all ships of this type';
400
+		} elseif ($code == 81) {
401
+			return 'Tanker, Hazardous category A';
402
+		} elseif ($code == 82) {
403
+			return 'Tanker, Hazardous category B';
404
+		} elseif ($code == 83) {
405
+			return 'Tanker, Hazardous category C';
406
+		} elseif ($code == 84) {
407
+			return 'Tanker, Hazardous category D';
408
+		} elseif ($code == 85) {
409
+			return 'Tanker, Reserved for future use';
410
+		} elseif ($code == 86) {
411
+			return 'Tanker, Reserved for future use';
412
+		} elseif ($code == 87) {
413
+			return 'Tanker, Reserved for future use';
414
+		} elseif ($code == 88) {
415
+			return 'Tanker, Reserved for future use';
416
+		} elseif ($code == 89) {
417
+			return 'Tanker, No additional information';
418
+		} elseif ($code == 90) {
419
+			return 'Other Type, all ships of this type';
420
+		} elseif ($code == 91) {
421
+			return 'Other Type, Hazardous category A';
422
+		} elseif ($code == 92) {
423
+			return 'Other Type, Hazardous category B';
424
+		} elseif ($code == 93) {
425
+			return 'Other Type, Hazardous category C';
426
+		} elseif ($code == 94) {
427
+			return 'Other Type, Hazardous category D';
428
+		} elseif ($code == 95) {
429
+			return 'Other Type, Reserved for future use';
430
+		} elseif ($code == 96) {
431
+			return 'Other Type, Reserved for future use';
432
+		} elseif ($code == 97) {
433
+			return 'Other Type, Reserved for future use';
434
+		} elseif ($code == 98) {
435
+			return 'Other Type, Reserved for future use';
436
+		} elseif ($code == 99) {
437
+			return 'Other Type, no additional information';
438
+		}
346 439
 	}
347 440
 
348 441
 	public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) {
@@ -380,19 +473,34 @@  discard block
 block discarded – undo
380 473
 		// assume 1st ! is valid
381 474
 		// find * ensure that it is at correct position
382 475
 		$end = strrpos ( $rawdata , '*' );
383
-		if ($end === FALSE) return -1; // check for NULLS!!!
476
+		if ($end === FALSE) {
477
+			return -1;
478
+		}
479
+		// check for NULLS!!!
384 480
 		$cs = substr( $rawdata, $end + 1 );
385
-		if ( strlen($cs) != 2 ) return -1; // correct cs length
481
+		if ( strlen($cs) != 2 ) {
482
+			return -1;
483
+		}
484
+		// correct cs length
386 485
 		$dcs = (int)hexdec( $cs );
387
-		for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum
486
+		for ( $alias=1; $alias<$end; $alias++) {
487
+			$chksum ^= ord( $rawdata[$alias] );
488
+		}
489
+		// perform XOR for NMEA checksum
388 490
 		if ( $chksum == $dcs ) { // NMEA checksum pass
389 491
 			$pcs = explode(',', $rawdata);
390 492
 			// !AI??? identifier
391 493
 			$num_seq = (int)$pcs[1]; // number of sequences
392 494
 			$seq = (int)$pcs[2]; // get sequence
393 495
 			// get msg sequence id
394
-			if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1
395
-			else $msg_sid = (int)$pcs[3]; // multipart message
496
+			if ($pcs[3] == '') {
497
+				$msg_sid = -1;
498
+			}
499
+			// non-multipart message, set to -1
500
+			else {
501
+				$msg_sid = (int)$pcs[3];
502
+			}
503
+			// multipart message
396 504
 			$ais_ch = $pcs[4]; // get AIS channel
397 505
 			// message sequence checking
398 506
 			if ($num_seq < 1 || $num_seq > 9) {
@@ -453,10 +561,18 @@  discard block
 block discarded – undo
453 561
 				//DEBUG echo "[$start $end $tst]\n";
454 562
 				$result = $this->process_ais_raw( $tst, "" );
455 563
 				$last_pos = $end + 1;
456
-			} else break;
564
+			} else {
565
+				break;
566
+			}
567
+		}
568
+		if ($last_pos > 0) {
569
+			$cbuf = substr($cbuf, $last_pos);
570
+		}
571
+		// move...
572
+		if (strlen($cbuf) > 1024) {
573
+			$cbuf = "";
457 574
 		}
458
-		if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move...
459
-		if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode...
575
+		// prevent overflow simple mode...
460 576
 		return $result;
461 577
 	}
462 578
 
@@ -476,7 +592,9 @@  discard block
 block discarded – undo
476 592
 		if ($lat<0.0) {
477 593
 			$lat = -$lat;
478 594
 			$neg=true;
479
-		} else $neg=false;
595
+		} else {
596
+			$neg=false;
597
+		}
480 598
 		$latd = 0x00000000;
481 599
 		$latd = intval ($lat * 600000.0);
482 600
 		if ($neg==true) {
@@ -492,7 +610,9 @@  discard block
 block discarded – undo
492 610
 		if ($lon<0.0) {
493 611
 			$lon = -$lon;
494 612
 			$neg=true;
495
-		} else $neg=false;
613
+		} else {
614
+			$neg=false;
615
+		}
496 616
 		$lond = 0x00000000;
497 617
 		$lond = intval ($lon * 600000.0);
498 618
 		if ($neg==true) {
@@ -505,9 +625,14 @@  discard block
 block discarded – undo
505 625
 
506 626
 	private function char2bin($name, $max_len) {
507 627
 		$len = strlen($name);
508
-		if ($len > $max_len) $name = substr($name,0,$max_len);
509
-		if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6);
510
-		else $pad = '';
628
+		if ($len > $max_len) {
629
+			$name = substr($name,0,$max_len);
630
+		}
631
+		if ($len < $max_len) {
632
+			$pad = str_repeat('0', ($max_len - $len) * 6);
633
+		} else {
634
+			$pad = '';
635
+		}
511 636
 		$rv = '';
512 637
 		$ais_chars = array(
513 638
 		    '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9,
@@ -519,9 +644,12 @@  discard block
 block discarded – undo
519 644
 		    '<'=>60, '='=>61, '>'=>62, '?'=>63
520 645
 		);
521 646
 		$_a = str_split($name);
522
-		if ($_a) foreach ($_a as $_1) {
647
+		if ($_a) {
648
+			foreach ($_a as $_1) {
523 649
 			if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1];
524
-			else $dec = 0;
650
+		} else {
651
+				$dec = 0;
652
+			}
525 653
 			$bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT);
526 654
 			$rv .= $bin;
527 655
 			//echo "$_1 $dec ($bin)<br/>";
@@ -533,7 +661,9 @@  discard block
 block discarded – undo
533 661
 		$len_bit = strlen($_enc);
534 662
 		$rem6 = $len_bit % 6;
535 663
 		$pad6_len = 0;
536
-		if ($rem6) $pad6_len = 6 - $rem6;
664
+		if ($rem6) {
665
+			$pad6_len = 6 - $rem6;
666
+		}
537 667
 		//echo  $pad6_len.'<br>';
538 668
 		$_enc .= str_repeat("0", $pad6_len); // pad the text...
539 669
 		$len_enc = strlen($_enc) / 6;
@@ -542,8 +672,11 @@  discard block
 block discarded – undo
542 672
 		for ($i=0; $i<$len_enc; $i++) {
543 673
 			$offset = $i * 6;
544 674
 			$dec = bindec(substr($_enc,$offset,6));
545
-			if ($dec < 40) $dec += 48;
546
-			else $dec += 56;
675
+			if ($dec < 40) {
676
+				$dec += 48;
677
+			} else {
678
+				$dec += 56;
679
+			}
547 680
 			//echo chr($dec)." $dec<br/>";
548 681
 			$itu .= chr($dec);
549 682
 		}
@@ -556,25 +689,41 @@  discard block
 block discarded – undo
556 689
 		}
557 690
 		$hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
558 691
 		$lsb = $chksum & 0x0F;
559
-		if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb];
560
-		else $lsbc = '0';
692
+		if ($lsb >=0 && $lsb <= 15 ) {
693
+			$lsbc = $hex_arr[$lsb];
694
+		} else {
695
+			$lsbc = '0';
696
+		}
561 697
 		$msb = (($chksum & 0xF0) >> 4) & 0x0F;
562
-		if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb];
563
-		else $msbc = '0';
698
+		if ($msb >=0 && $msb <= 15 ) {
699
+			$msbc = $hex_arr[$msb];
700
+		} else {
701
+			$msbc = '0';
702
+		}
564 703
 		$itu = '!'.$itu."*{$msbc}{$lsbc}\r\n";
565 704
 		return $itu;
566 705
 	}
567 706
 
568 707
 	public function parse($buffer) {
569 708
 		$data = $this->process_ais_buf($buffer);
570
-		if (!is_object($data)) return array();
571
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
572
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
709
+		if (!is_object($data)) {
710
+			return array();
711
+		}
712
+		if ($data->lon != 0) {
713
+			$result['longitude'] = $data->lon;
714
+		}
715
+		if ($data->lat != 0) {
716
+			$result['latitude'] = $data->lat;
717
+		}
573 718
 		$result['ident'] = trim($data->name);
574 719
 		$result['timestamp'] = $data->ts;
575 720
 		$result['mmsi'] = $data->mmsi;
576
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
577
-		if ($data->cog != 0) $result['heading'] = $data->cog;
721
+		if ($data->sog != -1.0) {
722
+			$result['speed'] = $data->sog;
723
+		}
724
+		if ($data->cog != 0) {
725
+			$result['heading'] = $data->cog;
726
+		}
578 727
 		/*
579 728
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
580 729
 		    $ro->id = bindec(substr($_aisdata,0,6));
@@ -588,19 +737,38 @@  discard block
 block discarded – undo
588 737
 		$start = strpos($buffer,"VDM");
589 738
 		$tst = substr($buffer, $start - 3);
590 739
 		$data = $this->process_ais_raw( $tst, "" );
591
-		if (!is_object($data)) return array();
592
-		if ($data->lon != 0) $result['longitude'] = $data->lon;
593
-		if ($data->lat != 0) $result['latitude'] = $data->lat;
740
+		if (!is_object($data)) {
741
+			return array();
742
+		}
743
+		if ($data->lon != 0) {
744
+			$result['longitude'] = $data->lon;
745
+		}
746
+		if ($data->lat != 0) {
747
+			$result['latitude'] = $data->lat;
748
+		}
594 749
 		$result['ident'] = trim(str_replace('@','',$data->name));
595 750
 		$result['timestamp'] = $data->ts;
596 751
 		$result['mmsi'] = $data->mmsi;
597
-		if ($data->sog != -1.0) $result['speed'] = $data->sog;
598
-		if ($data->heading != '') $result['heading'] = $data->heading;
599
-		elseif ($data->cog != 0) $result['heading'] = $data->cog;
600
-		if ($data->status != '') $result['status'] = $data->status;
601
-		if ($data->type != '') $result['type'] = $data->type;
602
-		if ($data->imo != '') $result['imo'] = $data->imo;
603
-		if ($data->callsign != '') $result['callsign'] = $data->callsign;
752
+		if ($data->sog != -1.0) {
753
+			$result['speed'] = $data->sog;
754
+		}
755
+		if ($data->heading != '') {
756
+			$result['heading'] = $data->heading;
757
+		} elseif ($data->cog != 0) {
758
+			$result['heading'] = $data->cog;
759
+		}
760
+		if ($data->status != '') {
761
+			$result['status'] = $data->status;
762
+		}
763
+		if ($data->type != '') {
764
+			$result['type'] = $data->type;
765
+		}
766
+		if ($data->imo != '') {
767
+			$result['imo'] = $data->imo;
768
+		}
769
+		if ($data->callsign != '') {
770
+			$result['callsign'] = $data->callsign;
771
+		}
604 772
 		$result['all'] = (array) $data;
605 773
 		/*
606 774
 		    $ro->cls = 0; // AIS class undefined, also indicate unparsed msg
Please login to merge, or discard this patch.