|
From: <ma...@sc...> - 2006-04-13 09:51:45
|
Update of /cvsroot/meshdb/www/db2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28443 Added Files: google.php Log Message: page to return single nodes or all mesh nodes as s google earth .kml file --- NEW FILE: google.php --- <? include("config.php"); include("util.php"); /* declare content type */ header("Content-Type: application/keyhole"); function nice_die($error) { echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; echo "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n"; echo " <Document>\n"; echo " <Folder><name>error: $error</name></Folder>\n"; echo " </Document>\n"; echo "</kml>\n"; return; } /* restrict to one node */ if (isset($HTTP_GET_VARS['nodeid'])) { $nodeid = $HTTP_GET_VARS['nodeid']; } /* restrict age of nodes */ if (isset($HTTP_GET_VARS['maxdays'])) { $maxdays = $HTTP_GET_VARS['maxdays']; } else { $maxdays = 365 * 2; /* default approx 2 years */ } /* used to mark an error */ $rows = 0; /* Connect */ $db = mysql_connect($MYSQLHOST, $MYSQLUSER, $MYSQLPASS); mysql_select_db($MYSQLDB, $db) or nice_die(mysql_error($db)); /* Last modified header */ $result = mysql_query("SELECT max(unix_timestamp(updated)) from admin", $db) or nice_die(mysql_error($db)); $row = mysql_fetch_row($result); $updated = intval($row[0]); /* comment this out if testing */ header("Last-Modified: ".gmdate("D, d M Y H:i:s", $updated)." GMT"); /* give back memory */ mysql_free_result($result); /* single or multiple query */ $query = "SELECT a.nodeid,a.nodename,a.status,a.updated,p.e,p.n,p.h,c.contactname,n.channel,n.antspread,n.direction,n.polarisation FROM admin a, physloc p, contact c, config n where a.nodeid = p.nodeid and a.nodeid=c.nodeid and a.nodeid = n.nodeid and p.e is not NULL and p.n is not null and (DATE_SUB(CURDATE(),INTERVAL $maxdays DAY) <= a.updated)"; if (isset($nodeid)) { $query = $query . " and a.nodeid=$nodeid"; } else { $query = $query . " order by a.nodename"; } /* get all nodes (query from hell to trim out garbage nodes) */ $result = mysql_query($query, $db) or nice_die(mysql_error($db)); /* xml header (no nice_die() after here) */ echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; echo "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n"; echo "<Document>\n"; echo "<Folder><name>brismesh.org</name>\n"; while (($row = mysql_fetch_assoc($result))) { /* updated may be null */ $updated = "N/A"; if (isset($row['updated'])) { $updated = $row['updated']; } /* height may be null */ $alt = 0; if (isset($row['h'])) { $alt = $row['h']; } /* convert to lat / lon */ $lat_lon = cvtlatlon($row['e'], $row['n']); $lat = $lat_lon[0]; $lon = $lat_lon[1]; /* display the row */ echo " <Placemark>\n"; echo " <description><![CDATA[Contact's Name: ".$row['contactname']."<br>" . "View <a href=\"http://www.itee.uq.edu.au/~mesh/db-srtm/view.php?nodeid=".$row['nodeid']."\">Node Details</a> on BrisMESH<br>Last Updated: ".$updated."]]></description>\n"; echo " <name>" . $row['nodename'] . "</name>\n"; echo " <LookAt>\n"; echo " <longitude>$lon</longitude>\n"; echo " <latitude>$lat</latitude>\n"; echo " <range>" . ($alt + 500) . "</range>\n"; echo " <tilt>0</tilt>\n"; echo " <heading>3</heading>\n"; echo " </LookAt>\n"; /* default pallette */ $pallette = "root://icons/palette-3.png"; $sizex = 32; $sizey = 32; /* choose a icon for the user */ if ($row['status'] == 'nan') { // landmark icon $offsetx=96; $offsety=64; } else if ($row['status'] == 'interest') { // small icon $pallette = "root://icons/palette-4.png"; $offsetx=32; $offsety=128; } else if ($row['status'] == 'build' || $row['status'] == 'gather') { // bit bigger $pallette = "root://icons/palette-4.png"; $offsetx=64; $offsety=128; } else if ($row['status'] == 'waiting') { // bit bigger $pallette = "root://icons/palette-4.png"; $offsetx=64; $offsety=128; } else if ($row['status'] == 'test') { // looks like an inactive tower $offsetx=0; $offsety=64; } else if ($row['status'] == 'full') { // looks like an active tower $offsetx=0; $offsety=96; } else { // low key icon $pallette = "root://icons/palette-4.png"; $offsetx=0; $offsety=128; } /* the icon to display */ echo " <Style>\n"; echo " <IconStyle>\n"; echo " <Icon>\n"; echo " <href>$pallette</href>\n"; echo " <x>$offsetx</x>\n"; echo " <y>$offsety</y>\n"; echo " <w>$sizex</w>\n"; echo " <h>$sizey</h>\n"; echo " </Icon>\n"; echo " </IconStyle>\n"; echo " </Style>\n"; /* point on the map */ echo " <Point>\n"; echo " <extrude>1</extrude>\n"; echo " <altitudeMode>relativeToGround</altitudeMode>\n"; echo " <coordinates>$lon,$lat,$alt</coordinates>\n"; echo " </Point>\n"; echo " </Placemark>\n"; /* count the rows */ $rows++; } /* give back memory */ mysql_free_result($result); /* if we got no rows, display an error */ if ($rows == 0) { if (isset($nodeid)) { echo "<Folder><name>no results available</name></Folder>"; } else { echo "<Folder><name>Node ".$nodeid." is not valid.</name></Folder>"; } } /* xml footer */ echo "</Folder>\n"; echo "</Document>\n"; echo "</kml>\n"; ?> |