I'm looking for an easy way to out placemark automatically into
folders. I have written some php scripts that takes a kismet (wifi-
sniffer) logfile and put the data into a mysql-database. Some other
scripts do the kml-outout with php's DOM.
My 'main'-kml file just uses three folder (open, wep, wpa), hence it's
easy to sort placemark into the right folder using some if-clauses.
Now I what to create some more advanced kmls with different sortings
e.g. vendor-lookup based on MAC-Adresse stored in my DB.
Problem now: I won't know how many different 'vendor'-folders there
will be, and I can't handle them all with if-constructs.
As a first try I created the all the folders:
require_once ('dbinfo.php');
function convertstrings($text)
{
return htmlentities(htmlentities($text));
}
// Create header etc...
$Dom = new DOMDocument('1.0', 'UTF-8');
$NameSpace = $Dom->createElementNS('
http://www.opengis.net/kml/2.2',
'kml');
$Dom->appendChild($NameSpace);
$DocumentNode = $Dom->createElement('Document');
$NameSpace->appendChild($DocumentNode);
$DocumentName = $Dom->createElement('name','Vendor-Map');
$DocumentNode->appendChild($DocumentName);
$FolderNodeMain = $Dom->createElement('Folder');
$FolderNodeMain->setAttribute('id','Vendor');
$DocumentNode->appendChild($FolderNodeMain);
$FolderNameMain = $Dom->createElement('name','Vendor');
$FolderNodeMain->appendChild($FolderNameMain);
$query = "SELECT DISTINCT vendor_ID, vendor_OUI, vendor_Name FROM
vendor";
$result = mysql_query($query);
while ($row = @mysql_fetch_assoc($result))
{
$row[vendor_Name] = convertstrings($row[vendor_Name]);
$Folder = $Dom->createElement('Folder');
$Folder->setAttribute('id','vendor_'.$row[vendor_ID]);
$FolderNodeMain->appendChild($Folder);
$FolderName = $Dom->createElement('name',$row[vendor_Name]);
$Folder->appendChild($FolderName);
$Dom->formatOutput = true;
$kmlOutput = $Dom->saveXML();
//header('Content-type: application/vnd.google-earth.kml+xml');
echo $kmlOutput;
}
This will output something like this:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="
http://www.opengis.net/kml/2.2">
<Document>
<name>Vendor-Map</name>
<Folder id="Vendor">
<name>Vendor</name>
<Folder id="vendor_1">
<name>Siemens</name>
</Folder>
<Folder id="vendor_2">
<name>SURECOM</name>
</Folder>
</Folder>
</Document>
</kml>
Everything's fine so far, but how do I get the placemark into the
right folder?
My placemark-query looks like this:
$query = "SELECT *
FROM ap
LEFT OUTER JOIN vendor ON left(ap_BSSID,8) = vendor_OUI
$result = mysql_query($query);
So, when doing a while-loop, $row[vendor_Name] contains the name of
the vendor of the current entry. How to put that entry into the right
folder, e.g. 'Siemens'?
greets
Chris