1 | 1 | simandl | <?php |
2 | 7 | simandl | //<!-- Copyright (C) 2008 Petr Simandl www.simandl.cz --> |
3 | | | //<!-- This file is part of CZFGmap. --> |
4 | | | //<!-- --> |
5 | | | //<!-- CZFGmap is free software: you can redistribute it and/or modify --> |
6 | | | //<!-- it under the terms of the GNU General Public License as published by --> |
7 | | | //<!-- the Free Software Foundation, either version 3 of the License, or --> |
8 | | | //<!-- (at your option) any later version. --> |
9 | | | //<!-- --> |
10 | | | //<!-- CZFGmap is distributed in the hope that it will be useful, --> |
11 | | | //<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of --> |
12 | | | //<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --> |
13 | | | //<!-- GNU General Public License for more details. --> |
14 | | | //<!-- --> |
15 | | | //<!-- You should have received a copy of the GNU General Public License --> |
16 | | | //<!-- along with CZFGmap. If not, see <http://www.gnu.org/licenses/>. --> |
17 | 1 | simandl | |
18 | 5 | simandl | error_reporting(7); |
19 | | | |
20 | | | header("Content-type: text/xml"); |
21 | | | |
22 | | | echo '<nodes>'; |
23 | | | |
24 | | | include("../forum/globalxml.php"); |
25 | | | |
26 | | | echo '<auth username="'.$bbuserinfo['username'].'" '; |
27 | | | echo 'userid="'.$bbuserinfo['userid'].'" '; |
28 | | | echo 'mapperms="'.$bbuserinfo['mapperms'].'" />'; |
29 | | | |
30 | 14 | simandl | //not logged in users gets everyone data |
31 | 5 | simandl | if (!$bbuserinfo['userid']) { |
32 | 13 | simandl | # echo '</nodes>'; |
33 | | | # die(); |
34 | | | $db="gendb"; |
35 | 5 | simandl | } |
36 | | | |
37 | 1 | simandl | $db=str_replace(" ","",@$db); |
38 | | | $latmin=str_replace(" ","",@$latmin); |
39 | | | $latmax=str_replace(" ","",@$latmax); |
40 | | | $lonmin=str_replace(" ","",@$lonmin); |
41 | | | $lonmax=str_replace(" ","",@$lonmax); |
42 | | | $where=str_replace(" ","",@$where); |
43 | | | |
44 | | | switch (@$db) { |
45 | | | case "czfreemapa": |
46 | | | require("mapa_dbinfo_czfreemapa.php"); |
47 | | | break; |
48 | | | case "czfmutf": |
49 | | | require("mapa_dbinfo_czfmutf.php"); |
50 | | | break; |
51 | | | case "ajax": |
52 | | | require("mapa_dbinfo_ajax.php"); |
53 | | | break; |
54 | | | case "gendb": |
55 | | | require("mapa_dbinfo_gendb.php"); |
56 | | | break; |
57 | | | default: |
58 | 4 | simandl | require("mapa_dbinfo_czfmutf.php"); |
59 | 1 | simandl | } |
60 | | | |
61 | | | if(!@$latmin) $latmin="50.11389119307087"; |
62 | | | if(!@$latmax) $latmax="50.13040037545383"; |
63 | | | if(!@$lonmin) $lonmin="14.483671188354492"; |
64 | | | if(!@$lonmax) $lonmax="14.518003463745117"; |
65 | | | #$limit=10; |
66 | | | |
67 | | | if(!@$sortby) { |
68 | | | $sqlorder="ORDER BY name"; |
69 | | | } else { |
70 | | | $sortby=str_replace(" ","",@$sortby); |
71 | | | if(!@$order) { |
72 | | | $sqlorder="ORDER BY $sortby"; |
73 | | | } else { |
74 | | | $order=str_replace(" ","",@$order); |
75 | | | $sqlorder="ORDER BY $sortby $order "; |
76 | | | } |
77 | | | } |
78 | | | |
79 | | | if((!@$limit)) { |
80 | | | $sqllimit=""; |
81 | | | } else { |
82 | | | $limit=str_replace(" ","",@$limit); |
83 | | | if($limit == 0) { |
84 | | | $sqllimit=""; |
85 | | | } else { |
86 | | | $sqllimit="LIMIT $limit"; |
87 | | | } |
88 | | | } |
89 | | | |
90 | | | if((!@$where)) { |
91 | | | $sqlwhere=""; |
92 | | | } else { |
93 | | | $where=str_replace(" ","",@$where); |
94 | | | $sqlwhere="AND $where"; |
95 | | | } |
96 | | | |
97 | | | function parseToXML($htmlStr) |
98 | | | { |
99 | | | $xmlStr=str_replace('<','<',$htmlStr); |
100 | | | $xmlStr=str_replace('>','>',$xmlStr); |
101 | | | $xmlStr=str_replace('"','"',$xmlStr); |
102 | | | $xmlStr=str_replace("'",''',$xmlStr); |
103 | | | $xmlStr=str_replace("&",'&',$xmlStr); |
104 | | | return $xmlStr; |
105 | | | } |
106 | | | |
107 | | | // Opens a connection to a MySQL server |
108 | | | $host="localhost"; |
109 | | | $connection=mysql_connect ($host, $username, $password); |
110 | | | if (!$connection) { |
111 | | | die('Not connected : ' . mysql_error()); |
112 | | | } |
113 | | | |
114 | | | // Set the active MySQL database |
115 | | | $db_selected = mysql_select_db($database, $connection); |
116 | | | if (!$db_selected) { |
117 | | | die ('Can\'t use db : ' . mysql_error()); |
118 | | | } |
119 | | | |
120 | 14 | simandl | // |
121 | | | $lattitude = mysql_real_escape_string($lattitude); |
122 | | | $longitude = mysql_real_escape_string($longitude); |
123 | | | $latmin = mysql_real_escape_string($latmin); |
124 | | | $latmax = mysql_real_escape_string($latmax); |
125 | | | $lonmin = mysql_real_escape_string($lonmin); |
126 | | | $lonmax = mysql_real_escape_string($lonmax); |
127 | | | $sqlwhere = mysql_real_escape_string($sqlwhere); |
128 | | | $sqlorder = mysql_real_escape_string($sqlorder); |
129 | | | $sqllimit = mysql_real_escape_string($sqllimit); |
130 | 1 | simandl | |
131 | | | $query = "SELECT * FROM $table WHERE $lattitude>$latmin AND $lattitude<$latmax AND $longitude>$lonmin AND $longitude<$lonmax $sqlwhere $sqlorder $sqllimit"; |
132 | | | $result = mysql_query($query); |
133 | | | if (!$result) { |
134 | | | die('Invalid query: ' . mysql_error()); |
135 | | | } |
136 | | | |
137 | | | // Iterate through the rows, printing XML nodes for each |
138 | | | while ($row = @mysql_fetch_assoc($result)){ |
139 | | | // ADD TO XML DOCUMENT NODE |
140 | | | echo '<node '; |
141 | | | echo 'id="' . @$row[$id] . '" '; |
142 | | | echo 'name="' . parseToXML(@$row[$name]) . '" '; |
143 | | | echo 'address="' . parseToXML(@$row[$address]) . '" '; |
144 | | | echo 'lat="' . @$row[$lattitude] . '" '; |
145 | | | echo 'lng="' . @$row[$longitude] . '" '; |
146 | | | echo 'type="' . @$row[$type] . '" '; |
147 | | | echo 'status="' . @$row[$status] . '" '; |
148 | | | echo '/>'; |
149 | | | echo ''; |
150 | | | |
151 | | | if (@$row[$id]) { |
152 | | | $query = "SELECT * FROM line WHERE id1=$row[$id]"; |
153 | | | $resultl = mysql_query($query); |
154 | | | if (!$resultl) { |
155 | | | die('Invalid query: ' . mysql_error()); |
156 | | | } |
157 | | | |
158 | | | while ($rowl = @mysql_fetch_assoc($resultl)){ |
159 | | | echo '<link '; |
160 | | | echo 'id1="' . @$rowl[$id1] . '" '; |
161 | | | echo 'id2="' . @$rowl[$id2] . '" '; |
162 | | | echo 'type="' . @$rowl[$type] . '" '; |
163 | | | echo 'status="' . @$rowl[$status] . '" '; |
164 | | | echo 'backbone="' . @$rowl[$backbone] . '" '; |
165 | | | echo 'inplanning="' . @$rowl[$inplanning] . '" '; |
166 | | | echo '/>'; |
167 | | | } |
168 | | | } |
169 | | | |
170 | | | } |
171 | | | |
172 | | | // End XML file |
173 | | | echo '</nodes>'; |
174 | | | |
175 | | | ?> |