jablonka.czprosek.czf

czfgmap

Subversion Repositories:
[/] [mapa_genxml.php] - Rev 4 Go to most recent revision

Compare with Previous - Blame - Download


<?php

$db=str_replace(" ","",@$db);
$latmin=str_replace(" ","",@$latmin);
$latmax=str_replace(" ","",@$latmax);
$lonmin=str_replace(" ","",@$lonmin);
$lonmax=str_replace(" ","",@$lonmax);
$where=str_replace(" ","",@$where);

switch (@$db) {
    case "czfreemapa":
        require("mapa_dbinfo_czfreemapa.php");
        break;
    case "czfmutf":
        require("mapa_dbinfo_czfmutf.php");
        break;
    case "ajax":
        require("mapa_dbinfo_ajax.php");
        break;
    case "gendb":
        require("mapa_dbinfo_gendb.php");
        break;
    default:
        require("mapa_dbinfo_czfmutf.php");
}

if(!@$latmin) $latmin="50.11389119307087";
if(!@$latmax) $latmax="50.13040037545383";
if(!@$lonmin) $lonmin="14.483671188354492";
if(!@$lonmax) $lonmax="14.518003463745117";
#$limit=10;

if(!@$sortby) {
  $sqlorder="ORDER BY name";
} else {
  $sortby=str_replace(" ","",@$sortby);
  if(!@$order) {
    $sqlorder="ORDER BY $sortby";
  } else {
    $order=str_replace(" ","",@$order);
    $sqlorder="ORDER BY $sortby $order ";
  }
}

if((!@$limit)) {
  $sqllimit="";
} else {
  $limit=str_replace(" ","",@$limit);
  if($limit == 0) {
    $sqllimit="";
  } else {
    $sqllimit="LIMIT $limit";
  }
}

if((!@$where)) {
  $sqlwhere="";
} else {
  $where=str_replace(" ","",@$where);
  $sqlwhere="AND $where";
}

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

// Opens a connection to a MySQL server
$host="localhost";
$connection=mysql_connect ($host, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$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 $table WHERE $lattitude>$latmin AND $lattitude<$latmax AND $longitude>$lonmin AND $longitude<$lonmax $sqlwhere $sqlorder $sqllimit";
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
$allowed_args = ',f_name,l_name,subject,msg,';

echo '<nodes>';

if (@$_SERVER['HTTP_REFERER']!="http://mapa.prosek.czf/") {
//foreach(array_keys($_SERVER) as $k) {
//echo $k.".......".$_SERVER[$k]."<br>";
//}
    if (@$_ENV['HOSTNAME']!="ztop") {
    echo "fatal - response too slow";
        die();
    }
}

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<node ';
  echo 'id="' . @$row[$id] . '" ';
  echo 'name="' . parseToXML(@$row[$name]) . '" ';
  echo 'address="' . parseToXML(@$row[$address]) . '" ';
  echo 'lat="' . @$row[$lattitude] . '" ';
  echo 'lng="' . @$row[$longitude] . '" ';
  echo 'type="' . @$row[$type] . '" ';
  echo 'status="' . @$row[$status] . '" ';
  echo '/>';
  echo '';

  if (@$row[$id]) {
    $query = "SELECT * FROM line WHERE id1=$row[$id]";
    $resultl = mysql_query($query);
    if (!$resultl) {
      die('Invalid query: ' . mysql_error());
    }

    while ($rowl = @mysql_fetch_assoc($resultl)){
      echo '<link ';
      echo 'id1="' . @$rowl[$id1] . '" ';
      echo 'id2="' . @$rowl[$id2] . '" ';
      echo 'type="' . @$rowl[$type] . '" ';
      echo 'status="' . @$rowl[$status] . '" ';
      echo 'backbone="' . @$rowl[$backbone] . '" ';
      echo 'inplanning="' . @$rowl[$inplanning] . '" ';
      echo '/>';
    }
  }


}

// End XML file
echo '</nodes>';

?>

Powered by WebSVN 2.2.1