jablonka.czprosek.czf

czfgmap

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

Compare with Previous - Blame - Download


<?php
//<!-- Copyright (C) 2008  Petr Simandl www.simandl.cz                          -->
//<!-- This file is part of CZFGmap.                                            -->
//<!--                                                                          -->
//<!-- CZFGmap is free software: you can redistribute it and/or modify          -->
//<!-- it under the terms of the GNU General Public License as published by     -->
//<!-- the Free Software Foundation, either version 3 of the License, or        -->
//<!-- (at your option) any later version.                                      -->
//<!--                                                                          -->
//<!-- CZFGmap is distributed in the hope that it will be useful,               -->
//<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of           -->
//<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            -->
//<!-- GNU General Public License for more details.                             -->
//<!--                                                                          -->
//<!-- You should have received a copy of the GNU General Public License        -->
//<!-- along with CZFGmap.  If not, see <http://www.gnu.org/licenses/>.         -->

error_reporting(7);

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

echo '<nodes>';

include("../forum/globalxml.php");

echo '<auth username="'.$bbuserinfo['username'].'" ';
echo 'userid="'.$bbuserinfo['userid'].'" ';
echo 'mapperms="'.$bbuserinfo['mapperms'].'" />';

//not logged in users gets no data
if (!$bbuserinfo['userid']) {
    echo '</nodes>';
    die();
}

$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());
}


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


//if (@$_SERVER['HTTP_REFERER']!="http://connected.czf/mapa/") {
//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