<?php
include_once("cookbook/mapwiki.php");

$connection = dbconnect();

// Set the active MySQL database
$database = "nopark";
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table
$query = "SELECT * FROM `locations` WHERE 1";
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}
// Start XML file, echo parent node
$xmlfile .= '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)) {
  $query = "SELECT category FROM `category` AS t1, `cat-loc` AS t2 WHERE t1.id = t2.cat_id AND t2.loc_id = $row[id] LIMIT 1";
  $result2 = mysql_query($query);
  mysql_num_rows($result2);
  $type = "";
  if($result2) {
    $type = mysql_fetch_assoc($result2);
    $type = $type['category'];
  }

  // ADD TO XML DOCUMENT NODE
  list($group,$name) = explode(".",$row['name']);
  $url = "$PubDirUrl/$group/$row[image]";
  $xmlfile .= '<marker ';
  $xmlfile .= 'name="' . parseToXML($name) . '" ';
  $xmlfile .= 'address="' . parseToXML($row['address']) . '" ';
  $xmlfile .= 'lat="' . $row['lat'] . '" ';
  $xmlfile .= 'lng="' . $row['lng'] . '" ';
  $xmlfile .= 'type="' . parseToXML($type) . '" ';
  $xmlfile .= 'group="' . parseToXML($group) . '" ';
  $xmlfile .= 'imgurl="' . parseToXML($url) . '" ';
  $xmlfile .= '/>';
}

// Print XML
header("Content-type: text/xml");
echo $xmlfile .= '</markers>';
?>