forked from leonardoxc/leonardoxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleo_live_org.php
166 lines (137 loc) · 5.31 KB
/
leo_live_org.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?
/************************************************************************/
/* Leonardo: Gliding XC Server */
/* ============================================ */
/* */
/* Copyright (c) 2004-5 by Andreadakis Manolis */
/* http://sourceforge.net/projects/leonardoserver */
/* */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License. */
/************************************************************************/
require_once "EXT_config_pre.php";
require_once "config.php";
require_once "EXT_config.php";
require_once "CL_flightData.php";
require_once "FN_functions.php";
require_once "FN_UTM.php";
require_once "FN_waypoint.php";
require_once "FN_output.php";
require_once "FN_pilot.php";
require_once "FN_flight.php";
setDEBUGfromGET();
$op=$_REQUEST['op'];
if (!$op) $op="ge";
$encoding="iso-8859-1";
if ($op=="ge") {
/* $lat=$_GET['lat']+0;
$lon=-$_GET['lon']+0;
$firstPoint=new gpsPoint();
$firstPoint->lat=$lat;
$firstPoint->lon=$lon;
*/
$query="SELECT * FROM leonardo_live_tmp ORDER BY time desc LIMIT 10 ";
//echo $query;
$res= $db->sql_query($query);
if($res <= 0){
echo("<H3> Error in query! $query </H3>\n");
exit();
}
$XML_str="NO DATA - ERROR";
while ($row = mysql_fetch_assoc($res)) {
$time =$row["time"];
$phone =$row["phone"];
$msg =$row["msg"];
// !P03384852N<<091083W<<214<<0<<169
if ( preg_match("/\!P03(.+)<<(.+)<<(.+)<<(.+)<<(.+)/",$msg,$matches)) {
$lat=$matches[1];
$lon=$matches[2];
$alt=$matches[3];
$speed=$matches[4];
$cog=$matches[5];
$d=substr($lat,0,2);
$m=substr($lat,2,2);
$s=substr($lat,4,2);
$orientation=strtolower(substr($lat,6,1));
$lat=$d+($m+$s/100)/60 ;
if ($orientation=='s') $lat=-$lat;
// now lon (West/East)
$d=substr($lon,0,2);
$m=substr($lon,2,2);
$s=substr($lon,4,2);
$orientation=strtolower(substr($lon,6,1));
// $lon=$d+$m/100;// + $s/60000
$lon=$d+($m+$s/100)/60;
if ($orientation=='w') $lon=-$lon;
$thisPoint=new gpsPoint();
$thisPoint->lat=$lat;
$thisPoint->lon=$lon;
$timeStr=substr($time,0,4)."-".substr($time,4,2)."-".substr($time,6,2)." ".
substr($time,8,2).":".substr($time,10,2).":".substr($time,12,2);
$XML_str="$time :: $phone :: $msg -> $lat , $lon , $alt, $speed , $cog";
break;
}
} // end while
$xml=makeKMLpoint($lat,$lon,"Last known Position $timeStr");
// echo $XML_str;
// send_XML($XML_str);
}
list($browser_agent,$browser_version)=getBrowser();
if ($browser_agent == 'opera') $attachmentMIME = 'application/kml';
else if ($browser_agent == 'ie' || $browser_agent == 'netscape' || $browser_agent == 'mozilla' )
$attachmentMIME ="application/vnd.google-earth.kml+xml";
else $attachmentMIME ='application/octet-stream';
DEBUG("DL",1,"browser_agent=$browser_agent, browser version=$browser_version<BR>");
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-type: $attachmentMIME");
//header("Content-Disposition: attachment; filename=\"$kml_file_name\"", true);
header('Content-Disposition: inline; filename="' . htmlspecialchars($file_name) . '"');
header("Content-Transfer-Encoding: binary");
$size = strlen($xml);
header("Content-length: $size");
echo $xml;
function send_XML($XML_str) {
if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2'))
header ('Cache-Control: no-cache, pre-check=0, post-check=0, max-age=0');
else header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
header ('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
header ('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header ('Content-Type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n";
echo $XML_str;
}
function makeKMLpoint($lat,$lon,$desc="") {
$icons = array (1 => array ("root://icons/palette-3.png", 0, 192),
2 => array ("root://icons/palette-3.png", 32, 192), 3 => array ("root://icons/palette-3.png", 64, 192),
4 => array ("root://icons/palette-3.png", 96, 192), 5 => array ("root://icons/palette-3.png", 128, 192) );
$num=1;
$res = "
<Placemark>
<name>".$desc."</name>".
/* "<Style>
<IconStyle>
<scale>0.4</scale>
<Icon>
<href>".$this->icons[$$num +1][0]."</href>
<x>".$this->icons[$num +1][1]."</x>
<y>".$this->icons[$num +1][2]."</y>
<w>32</w>
<h>32</h>
</Icon>
</IconStyle>
</Style>".
*/
"<Point>
<extrude>1</extrude>
<tessellate>1</tessellate>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>". $lon.",".$lat.",0</coordinates>
</Point>
</Placemark>";
return $res;
}
?>