|
From: <ma...@sc...> - 2006-04-14 17:42:24
|
Update of /cvsroot/meshdb/www/db2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30051 Modified Files: google.php Log Message: added a "save" option to force a save dialog box, and added a "folders" option to categorize nodes by status. Index: google.php =================================================================== RCS file: /cvsroot/meshdb/www/db2/google.php,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- google.php 14 Apr 2006 14:21:05 -0000 1.6 +++ google.php 14 Apr 2006 17:42:11 -0000 1.7 @@ -42,6 +42,18 @@ if (isset($HTTP_GET_VARS['zip'])) { $zip = $HTTP_GET_VARS['zip']; } + + /* dont launch in google earth */ + $save = 0; + if (isset($HTTP_GET_VARS['save'])) { + $save = $HTTP_GET_VARS['save']; + } + + /* categorise by status */ + $folders = 0; + if (isset($HTTP_GET_VARS['folders'])) { + $folders = $HTTP_GET_VARS['folders']; + } /* Connect */ $db = mysql_connect($MYSQLHOST, $MYSQLUSER, $MYSQLPASS); @@ -62,18 +74,15 @@ if (isset($nodeid)) { $query = $query . " and a.nodeid=$nodeid"; } else { - $query = $query . " order by a.nodename"; + $query = $query . " order by a.status, a.nodename"; } /* get all nodes (query from hell to trim out garbage nodes) */ $result = mysql_query($query, $db) or nice_die(mysql_error($db)); - /* kml file as a string */ - $kml_text = ""; - /* xml header (no nice_die() after here) */ - $kml_text .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; + $kml_text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $kml_text .= "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n"; $kml_text .= "<Document>\n"; @@ -169,7 +178,8 @@ $kml_text .= " </Style>\n"; /* default enclosing folder */ - $kml_text .= "<Folder><name>brismesh.org</name>\n"; + $kml_text .= "<Folder><name>BrisMESH Nodes</name>\n"; + $last_status = ""; while (($row = mysql_fetch_assoc($result))) { @@ -192,7 +202,7 @@ /* skip invalid values (out of zone coords) */ if ($lat == 0 || $lon == 0) { - $kml_text .= "<!-- zero lat=$lat OR lon=$lon, skipping node $row['nodeid'] -->/n"; + $kml_text .= "<!-- zero lat=$lat OR lon=$lon, skipping node ".$row['nodeid']." -->/n"; continue; } @@ -203,6 +213,18 @@ $style="#$validStyles[$i]"; } + /* + * break up nodes by status - emitting a folder whenever consecutive status fields change + * this relies on the ORDER BY clause being present in the query above.. + */ + if ($folders == 1 && !isset($nodeid) && $last_status != $row['status']) { + if ($last_status != "") { + $kml_text .= "</Folder>\n"; + } + $kml_text .= "<Folder><name>".$row['status']."</name>\n"; + $last_status = $row['status']; + } + /* display the row */ $kml_text .= " <Placemark>\n"; $kml_text .= " <description><![CDATA[Contact's Name: " . htmlspecialchars($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"; @@ -292,6 +314,10 @@ $kml_text .= "<Folder><name>no results available</name></Folder>"; } } + + if ($folders) { + $kml_text .= "</Folder>\n"; + } /* xml footer */ $kml_text .= "</Folder>\n"; @@ -304,8 +330,11 @@ if ($zip == 0) { /* send headers */ - header("application/vnd.google-earth.kml+xml"); - + header("Content-Type: application/vnd.google-earth.kml+xml"); + if ($save == 1) { + header("Content-disposition: attachment; filename=brismesh.kml"); + } + /* send plain text */ echo $kml_text; @@ -318,8 +347,11 @@ $theZip->add_file($kml_text, "doc.kml"); /* content type */ - header('Content-Type: application/vnd.google-earth.kmz'); - + header('Content-Type: application/vnd.google-earth.kmz'); + if ($save == 1) { + header("Content-disposition: attachment; filename=brismesh.kmz"); + } + /* send zip */ print ($theZip->file); |