1
|
|
|
<?php |
2
|
|
|
/*************************************************************************** |
3
|
|
|
* For license information see LICENSE.md |
4
|
|
|
* |
5
|
|
|
* |
6
|
|
|
* This module handles everything which results in the output of a list of |
7
|
|
|
* caches, including output formatting. It also handles search requests from |
8
|
|
|
* external tools like the Mozilla Firefox plugin. |
9
|
|
|
* |
10
|
|
|
* Search options will be loaded from |
11
|
|
|
* - a saved query in queries table, if either 'queryid' parameter or |
12
|
|
|
* 'lastqueryid' cookie is present and the query exists; otherwise from |
13
|
|
|
* - supplied HTTP parameters or |
14
|
|
|
* - hard-coded default values |
15
|
|
|
* |
16
|
|
|
* showresult=1 produces an SQL query from search options, executes it and |
17
|
|
|
* calls the output formatting module as specified by the 'output' parameter. |
18
|
|
|
* If 'showresult' != 1, the search options form is presented to the user. |
19
|
|
|
* |
20
|
|
|
* Note that 'showresult' is also stored in saved queries, so it can be |
21
|
|
|
* automatically included when the 'queryid' parameter is given. |
22
|
|
|
* |
23
|
|
|
* search type options: |
24
|
|
|
* searchbyplz (obsolete => mapped to searchbyortplz) |
25
|
|
|
* searchbyort (obsolete => mapped to searchbyortplz) |
26
|
|
|
* searchbyortplz |
27
|
|
|
* searchbywaypoint |
28
|
|
|
* searchbydistance (obsolete => mapped to searchbycoords) |
29
|
|
|
* searchbycoords |
30
|
|
|
* searchbyname |
31
|
|
|
* searchbyowner |
32
|
|
|
* searchbyfinder |
33
|
|
|
* searchbyfulltext |
34
|
|
|
* searchbynofilter |
35
|
|
|
* searchbycacheid |
36
|
|
|
* searchbywp |
37
|
|
|
* searchbylist |
38
|
|
|
* searchall (needs login) |
39
|
|
|
* |
40
|
|
|
* output options: |
41
|
|
|
* html display browsable search results list |
42
|
|
|
* xml undocumented - very old API |
43
|
|
|
* txt plain-text cache listing, zipped if more than one cache |
44
|
|
|
* map2 internally used for map display and filtering |
45
|
|
|
* |
46
|
|
|
* gpx common geocache data files |
47
|
|
|
* loc |
48
|
|
|
* ovl |
49
|
|
|
* ov2 |
50
|
|
|
* kml |
51
|
|
|
* |
52
|
|
|
* |
53
|
|
|
* To do: |
54
|
|
|
* - port attributes code to res_attribgroup.tpl (see outputSearchForm) |
55
|
|
|
* - move output data list generation from prepareLocSelectionForm and |
56
|
|
|
* outputLocidSelectionForm to search_selectlocid.tpl. |
57
|
|
|
* - wtf is "expert mode"? |
58
|
|
|
****************************************************************************/ |
59
|
|
|
|
60
|
|
|
require __DIR__ . '/lib2/web.inc.php'; |
61
|
|
|
require __DIR__ . '/lib2/logic/data-license.inc.php'; |
62
|
|
|
require __DIR__ . '/lib2/search/search.inc.php'; |
63
|
|
|
require __DIR__ . '/templates2/' . $opt['template']['style'] . '/search.tpl.inc.php'; |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
//========================================================= |
67
|
|
|
// 1. initialize searching and template variables |
68
|
|
|
//========================================================= |
69
|
|
|
|
70
|
|
|
$tpl->name = 'search'; |
71
|
|
|
$tpl->menuitem = MNU_CACHES_SEARCH; |
72
|
|
|
|
73
|
|
|
// distance constants |
74
|
|
|
define('DEFAULT_DISTANCE_UNIT', 'km'); |
75
|
|
|
define('DEFAULT_SEARCH_DISTANCE', 75); |
76
|
|
|
|
77
|
|
|
$multiplier['km'] = 1; |
78
|
|
|
$multiplier['sm'] = 0.62137; |
79
|
|
|
$multiplier['nm'] = 0.53996; |
80
|
|
|
|
81
|
|
|
$homecoords = ($login->logged_in() && |
82
|
|
|
sql_value_slave("SELECT `latitude`+`longitude` FROM user WHERE `user_id`='&1'", 0, $login->userid) <> 0); |
|
|
|
|
83
|
|
|
|
84
|
|
|
// Determine if search.php was called by a search function ('Caches' menu, |
85
|
|
|
// stored query etc.) or for other purpose (e.g. user profile cache lists): |
86
|
|
|
$called_by_search = isset($_REQUEST['calledbysearch']) ? $_REQUEST['calledbysearch'] <> 0 : true; |
87
|
|
|
$called_by_profile_query = false; |
88
|
|
|
$load_query = false; |
89
|
|
|
$show_lastsearchbutton = true; |
90
|
|
|
|
91
|
|
|
$list_caches = isset($_REQUEST['addCache']) && $_REQUEST['addCache'] >= 1 ? $_REQUEST['addCache'] : ''; |
92
|
|
|
$added_waypoints = 0; |
93
|
|
|
|
94
|
|
|
if (isset($_REQUEST['queryid']) || isset($_REQUEST['showresult'])) { // Ocprop: showresult, queryid |
95
|
|
|
$bCookieQueryid = false; |
96
|
|
|
$load_query = true; |
97
|
|
|
$queryid = isset($_REQUEST['queryid']) ? $_REQUEST['queryid'] : 0; |
98
|
|
|
if ($queryid && |
99
|
|
|
sql_value("SELECT `user_id` FROM `queries` WHERE `id`='&1'", 0, $queryid) |
|
|
|
|
100
|
|
|
) { |
101
|
|
|
$called_by_profile_query = true; |
102
|
|
|
} |
103
|
|
|
} else { |
104
|
|
|
$bCookieQueryid = true; |
105
|
|
|
$load_query = true; |
106
|
|
|
$queryid = $cookie->get('lastqueryid', false); |
107
|
|
|
if ($queryid === false || |
108
|
|
|
sql_value("SELECT COUNT(*) FROM `queries` WHERE id='&1'", 0, $queryid) == 0 |
|
|
|
|
109
|
|
|
) { |
110
|
|
|
$show_lastsearchbutton = false; |
111
|
|
|
} |
112
|
|
|
if (!isset($_REQUEST['lastsearch'])) { |
113
|
|
|
$queryid = 0; |
114
|
|
|
} |
115
|
|
|
if ($queryid === false || |
116
|
|
|
sql_value("SELECT COUNT(*) FROM `queries` WHERE id='&1'", 0, $queryid) == 0 |
|
|
|
|
117
|
|
|
) { |
118
|
|
|
$queryid = 0; |
119
|
|
|
$load_query = false; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
newquery: |
123
|
|
|
if ($queryid == 0) { |
124
|
|
|
$load_query = false; |
125
|
|
|
// initialize search form with defaults, as we have no parameters |
126
|
|
|
// or saved query to start from |
127
|
|
|
|
128
|
|
|
$_REQUEST['cache_attribs'] = ''; |
129
|
|
|
$rs = sql("SELECT `id` FROM `cache_attrib` WHERE `default`=1 AND NOT IFNULL(`hidden`, 0)=1"); |
|
|
|
|
130
|
|
View Code Duplication |
while ($r = sql_fetch_assoc($rs)) { |
|
|
|
|
131
|
|
|
if ($_REQUEST['cache_attribs'] != '') { |
132
|
|
|
$_REQUEST['cache_attribs'] .= ';'; |
133
|
|
|
} |
134
|
|
|
$_REQUEST['cache_attribs'] .= $r['id']; |
135
|
|
|
} |
136
|
|
|
sql_free_result($rs); |
|
|
|
|
137
|
|
|
|
138
|
|
|
$_REQUEST['cache_attribs_not'] = ''; |
139
|
|
|
$rs = sql("SELECT `id` FROM `cache_attrib` WHERE `default`=2 AND NOT IFNULL(`hidden`, 0)=1"); |
|
|
|
|
140
|
|
View Code Duplication |
while ($r = sql_fetch_assoc($rs)) { |
|
|
|
|
141
|
|
|
if ($_REQUEST['cache_attribs_not'] != '') { |
142
|
|
|
$_REQUEST['cache_attribs_not'] .= ';'; |
143
|
|
|
} |
144
|
|
|
$_REQUEST['cache_attribs_not'] .= $r['id']; |
145
|
|
|
} |
146
|
|
|
sql_free_result($rs); |
|
|
|
|
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
$queryid += 0; // safety measure: force $queryid to be numeric |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
//========================================================= |
154
|
|
|
// 2. Build search options ($options) array |
155
|
|
|
//========================================================= |
156
|
|
|
|
157
|
|
|
if ($queryid != 0) { |
158
|
|
|
// load search options from stored query |
159
|
|
|
|
160
|
|
|
$query_rs = sql( |
|
|
|
|
161
|
|
|
"SELECT `user_id`, `options`, `name` |
162
|
|
|
FROM `queries` |
163
|
|
|
WHERE id='&1' AND (`user_id`=0 OR `user_id`='&2')", |
164
|
|
|
$queryid, |
165
|
|
|
$login->userid |
166
|
|
|
); |
167
|
|
|
|
168
|
|
|
if (sql_num_rows($query_rs) == 0) { |
|
|
|
|
169
|
|
|
// can happen if logged out after query was created (fix for RT #3915) |
170
|
|
|
$queryid = 0; |
171
|
|
|
goto newquery; // goto needs PHP 5.3 |
172
|
|
|
/* |
173
|
|
|
$tpl->error($error_query_not_found); |
174
|
|
|
*/ |
175
|
|
|
} else { |
176
|
|
|
$record = sql_fetch_array($query_rs); |
|
|
|
|
177
|
|
|
$options = unserialize($record['options']); |
178
|
|
|
if ($record['user_id'] != 0) { |
179
|
|
|
$query_userid = $record['user_id']; |
180
|
|
|
$query_name = $record['name']; |
181
|
|
|
} |
182
|
|
|
sql_free_result($query_rs); |
|
|
|
|
183
|
|
|
|
184
|
|
|
$options['queryid'] = $queryid; |
185
|
|
|
|
186
|
|
|
sql("UPDATE `queries` SET `last_queried`=NOW() WHERE `id`='&1'", $queryid); |
|
|
|
|
187
|
|
|
|
188
|
|
|
// overwrite variable options |
189
|
|
|
if (isset($_REQUEST['output'])) { |
190
|
|
|
$options['output'] = $_REQUEST['output']; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
if (isset($_REQUEST['showresult'])) { |
194
|
|
|
$options['showresult'] = $_REQUEST['showresult']; |
195
|
|
|
} else { |
196
|
|
|
if ($bCookieQueryid) { |
197
|
|
|
$options['showresult'] = 0; |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
// overwrite variable options; see 'set common variable options' for more |
202
|
|
|
if (isset($_REQUEST['sortby'])) { |
203
|
|
|
$options['sort'] = $_REQUEST['sortby']; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
// get findername from finderid |
207
|
|
|
$options['finderid'] = isset($options['finderid']) ? $options['finderid'] + 0 : 0; // Ocprop |
208
|
|
View Code Duplication |
if (isset($options['finder']) && $options['finderid'] > 0) { |
209
|
|
|
$rs_name = sql("SELECT `username` FROM `user` WHERE `user_id`='&1'", $options['finderid']); |
|
|
|
|
210
|
|
|
if (sql_num_rows($rs_name) == 1) { |
|
|
|
|
211
|
|
|
$record_name = sql_fetch_array($rs_name); |
|
|
|
|
212
|
|
|
$options['finder'] = $record_name['username']; |
213
|
|
|
} |
214
|
|
|
unset($record_name); |
215
|
|
|
sql_free_result($rs_name); |
|
|
|
|
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
// get ownername from ownerid |
219
|
|
|
$options['ownerid'] = isset($options['ownerid']) ? $options['ownerid'] + 0 : 0; // Ocprop |
220
|
|
View Code Duplication |
if (isset($options['owner']) && $options['ownerid'] > 0) { |
221
|
|
|
$rs_name = sql("SELECT `username` FROM `user` WHERE `user_id`='&1'", $options['ownerid']); |
|
|
|
|
222
|
|
|
if (sql_num_rows($rs_name) == 1) { |
|
|
|
|
223
|
|
|
$record_name = sql_fetch_array($rs_name); |
|
|
|
|
224
|
|
|
$options['owner'] = $record_name['username']; |
225
|
|
|
} |
226
|
|
|
unset($record_name); |
227
|
|
|
sql_free_result($rs_name); |
|
|
|
|
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
// map obsolete search types |
231
|
|
|
if ($options['searchtype'] == 'bydistance') { |
232
|
|
|
$options['searchtype'] = 'bycoords'; |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
} else { // $queryid == 0 |
236
|
|
|
// build search options from GET/POST parameters or default values |
237
|
|
|
|
238
|
|
|
// hack |
239
|
|
|
if (isset($_REQUEST['searchto']) && ($_REQUEST['searchto'] != '')) { |
240
|
|
|
unset( |
241
|
|
|
$_REQUEST['searchbyplz'], |
242
|
|
|
$_REQUEST['searchbyort'], |
243
|
|
|
$_REQUEST['searchbyortplz'], |
244
|
|
|
$_REQUEST['searchbycoords'], |
245
|
|
|
$_REQUEST['searchbydistance'], |
246
|
|
|
$_REQUEST['searchbyname'], |
247
|
|
|
$_REQUEST['searchbyowner'], |
248
|
|
|
$_REQUEST['searchbyfinder'], |
249
|
|
|
$_REQUEST['searchbywaypoint'], |
250
|
|
|
$_REQUEST['searchbyfulltext'], |
251
|
|
|
$_REQUEST['searchbynofilter'], |
252
|
|
|
$_REQUEST['searchall'] |
253
|
|
|
); |
254
|
|
|
$_REQUEST[$_REQUEST['searchto']] = $_REQUEST['searchto']; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
// get the search options parameters and store them in the queries table (to view "the next page") |
258
|
|
|
$options['f_userowner'] = isset($_REQUEST['f_userowner']) ? $_REQUEST['f_userowner'] : 0; // Ocprop |
259
|
|
|
$options['f_userfound'] = isset($_REQUEST['f_userfound']) ? $_REQUEST['f_userfound'] : 0; // Ocprop |
260
|
|
|
$options['f_unpublished'] = isset($_REQUEST['f_unpublished']) ? $_REQUEST['f_unpublished'] : 0; |
261
|
|
|
$options['f_disabled'] = isset($_REQUEST['f_disabled']) ? $_REQUEST['f_disabled'] : 0; |
262
|
|
|
$options['f_inactive'] = isset($_REQUEST['f_inactive']) ? $_REQUEST['f_inactive'] : 1; // Ocprop |
263
|
|
|
// f_inactive formerly was used for both, archived and disabled caches. |
264
|
|
|
// After adding the separate f_disabled option, it is used only for archived |
265
|
|
|
// caches, but keeps its name for compatibility with existing stored or |
266
|
|
|
// external searches. |
267
|
|
|
$options['f_ignored'] = isset($_REQUEST['f_ignored']) ? $_REQUEST['f_ignored'] : 1; |
268
|
|
|
$options['f_otherPlatforms'] = isset($_REQUEST['f_otherPlatforms']) ? $_REQUEST['f_otherPlatforms'] : 0; |
269
|
|
|
$options['f_geokrets'] = isset($_REQUEST['f_geokrets']) ? $_REQUEST['f_geokrets'] : 0; |
270
|
|
|
$options['expert'] = isset($_REQUEST['expert']) ? $_REQUEST['expert'] : 0; // Ocprop: 0 |
271
|
|
|
$options['showresult'] = isset($_REQUEST['showresult']) ? $_REQUEST['showresult'] : 0; |
272
|
|
|
$options['output'] = isset($_REQUEST['output']) ? $_REQUEST['output'] : 'HTML'; // Ocprop: HTML |
273
|
|
|
$options['bbox'] = isset($_REQUEST['bbox']) ? $_REQUEST['bbox'] : false; |
274
|
|
|
|
275
|
|
View Code Duplication |
if (isset($_REQUEST['cache_attribs'])) { |
276
|
|
|
if ($_REQUEST['cache_attribs'] != '') { |
277
|
|
|
$aAttribs = mb_split(';', $_REQUEST['cache_attribs']); |
278
|
|
|
$countAttribs = count($aAttribs); |
279
|
|
|
for ($i = 0; $i < $countAttribs; $i++) { |
280
|
|
|
$options['cache_attribs'][$aAttribs[$i] + 0] = $aAttribs[$i] + 0; |
281
|
|
|
} |
282
|
|
|
unset($aAttribs); |
283
|
|
|
} else { |
284
|
|
|
$options['cache_attribs'] = []; |
285
|
|
|
} |
286
|
|
|
} else { |
287
|
|
|
$options['cache_attribs'] = []; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
View Code Duplication |
if (isset($_REQUEST['cache_attribs_not'])) { |
291
|
|
|
if ($_REQUEST['cache_attribs_not'] != '') { |
292
|
|
|
$aAttribs = mb_split(';', $_REQUEST['cache_attribs_not']); |
293
|
|
|
$countAttribs = count($aAttribs); |
294
|
|
|
for ($i = 0; $i < $countAttribs; $i++) { |
295
|
|
|
$options['cache_attribs_not'][$aAttribs[$i] + 0] = $aAttribs[$i] + 0; |
296
|
|
|
} |
297
|
|
|
unset($aAttribs); |
298
|
|
|
} else { |
299
|
|
|
$options['cache_attribs_not'] = []; |
300
|
|
|
} |
301
|
|
|
} else { |
302
|
|
|
$options['cache_attribs_not'] = []; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
if (!isset($_REQUEST['unit'])) { |
306
|
|
|
$options['unit'] = 'km'; |
307
|
|
|
} elseif (mb_strtolower($_REQUEST['unit']) == 'sm') { |
308
|
|
|
$options['unit'] = 'sm'; |
309
|
|
|
} elseif (mb_strtolower($_REQUEST['unit']) == 'nm') { |
310
|
|
|
$options['unit'] = 'nm'; |
311
|
|
|
} else { |
312
|
|
|
$options['unit'] = DEFAULT_DISTANCE_UNIT; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
if (isset($_REQUEST['searchbyname'])) { |
316
|
|
|
$options['searchtype'] = 'byname'; |
317
|
|
|
$options['cachename'] = isset($_REQUEST['cachename']) ? stripslashes($_REQUEST['cachename']) : ''; |
318
|
|
|
|
319
|
|
View Code Duplication |
if (!isset($_REQUEST['utf8'])) { |
320
|
|
|
$options['cachename'] = iconv("ISO-8859-1", "UTF-8", $options['cachename']); |
321
|
|
|
} |
322
|
|
|
} elseif (isset($_REQUEST['searchbyowner'])) { // Ocprop |
323
|
|
|
$options['searchtype'] = 'byowner'; |
324
|
|
|
|
325
|
|
|
$options['ownerid'] = isset($_REQUEST['ownerid']) ? $_REQUEST['ownerid'] : 0; |
326
|
|
|
$options['owner'] = isset($_REQUEST['owner']) ? stripslashes($_REQUEST['owner']) : ''; |
327
|
|
|
|
328
|
|
View Code Duplication |
if (isset($options['owner'])) { |
329
|
|
|
$rs_name = sql("SELECT `user_id` FROM `user` WHERE `username`='&1'", $options['owner']); |
|
|
|
|
330
|
|
|
if (sql_num_rows($rs_name) == 1) { |
|
|
|
|
331
|
|
|
$record_id = sql_fetch_array($rs_name); |
|
|
|
|
332
|
|
|
$options['ownerid'] = $record_id['user_id']; |
333
|
|
|
$user = new user($options['ownerid']); |
334
|
|
|
} |
335
|
|
|
unset($record_id); |
336
|
|
|
sql_free_result($rs_name); |
|
|
|
|
337
|
|
|
} |
338
|
|
|
} elseif (isset($_REQUEST['searchbyfinder'])) { // Ocprop |
339
|
|
|
$options['searchtype'] = 'byfinder'; |
340
|
|
|
|
341
|
|
|
$options['finderid'] = isset($_REQUEST['finderid']) ? $_REQUEST['finderid'] : 0; |
342
|
|
|
$options['finder'] = isset($_REQUEST['finder']) ? stripslashes($_REQUEST['finder']) : ''; |
343
|
|
|
$options['logtype'] = isset($_REQUEST['logtype']) ? $_REQUEST['logtype'] : '1,7'; // Ocprop |
344
|
|
|
|
345
|
|
View Code Duplication |
if (isset($options['finder'])) { |
346
|
|
|
$rs_name = sql("SELECT `user_id` FROM `user` WHERE `username`='&1'", $options['finder']); |
|
|
|
|
347
|
|
|
if (sql_num_rows($rs_name) == 1) { |
|
|
|
|
348
|
|
|
$record_id = sql_fetch_array($rs_name); |
|
|
|
|
349
|
|
|
$options['finderid'] = $record_id['user_id']; |
350
|
|
|
$user = new user($options['finderid']); |
351
|
|
|
} |
352
|
|
|
unset($record_id); |
353
|
|
|
sql_free_result($rs_name); |
|
|
|
|
354
|
|
|
} |
355
|
|
|
} elseif ((isset($_REQUEST['searchbyortplz']) && is_numeric($_REQUEST['ortplz'])) |
356
|
|
|
|| isset($_REQUEST['searchbyplz'])) { |
357
|
|
|
$options['searchtype'] = 'byplz'; |
358
|
|
View Code Duplication |
if (isset($_REQUEST['searchbyortplz'])) { |
359
|
|
|
$options['ortplz'] = $_REQUEST['ortplz']; |
360
|
|
|
} else { |
361
|
|
|
$options['ortplz'] = $_REQUEST['plz']; |
362
|
|
|
} |
363
|
|
|
$options['locid'] = isset($_REQUEST['locid']) ? $_REQUEST['locid'] + 0 : 0; |
364
|
|
|
$options['distance'] = isset($_REQUEST['distance']) ? $_REQUEST['distance'] + 0 : DEFAULT_SEARCH_DISTANCE; |
365
|
|
|
} elseif (isset($_REQUEST['searchbyortplz']) || isset($_REQUEST['searchbyort'])) { |
366
|
|
|
$options['searchtype'] = 'byort'; |
367
|
|
View Code Duplication |
if (isset($_REQUEST['searchbyortplz'])) { |
368
|
|
|
$options['ortplz'] = $_REQUEST['ortplz']; |
369
|
|
|
} else { |
370
|
|
|
$options['ortplz'] = $_REQUEST['ort']; |
371
|
|
|
} |
372
|
|
|
$options['locid'] = isset($_REQUEST['locid']) ? $_REQUEST['locid'] + 0 : 0; |
373
|
|
|
$options['distance'] = isset($_REQUEST['distance']) ? $_REQUEST['distance'] + 0 : DEFAULT_SEARCH_DISTANCE; |
374
|
|
|
} elseif (isset($_REQUEST['searchbywaypoint'])) { |
375
|
|
|
$options['searchtype'] = 'bywaypoint'; |
376
|
|
|
|
377
|
|
|
$options['waypoint'] = isset($_REQUEST['waypoint']) ? stripslashes($_REQUEST['waypoint']) : ''; |
378
|
|
|
$options['distance'] = isset($_REQUEST['distance']) ? $_REQUEST['distance'] + 0 : DEFAULT_SEARCH_DISTANCE; |
379
|
|
|
} elseif (isset($_REQUEST['searchbycoords']) || isset($_REQUEST['searchbydistance'])) { |
380
|
|
|
$options['searchtype'] = 'bycoords'; |
381
|
|
|
|
382
|
|
|
// Ocprop: all of the following options |
383
|
|
|
if (isset($_REQUEST['lat']) && isset($_REQUEST['lon'])) { |
384
|
|
|
$options['lat'] = $_REQUEST['lat'] + 0; |
385
|
|
|
$options['lon'] = $_REQUEST['lon'] + 0; |
386
|
|
|
} else { |
387
|
|
|
$options['latNS'] = isset($_REQUEST['latNS']) ? $_REQUEST['latNS'] : 'N'; |
388
|
|
|
$options['lonEW'] = isset($_REQUEST['lonEW']) ? $_REQUEST['lonEW'] : 'E'; |
389
|
|
|
|
390
|
|
|
$options['lat_h'] = isset($_REQUEST['lat_h']) ? $_REQUEST['lat_h'] : 0; |
391
|
|
|
$options['lon_h'] = isset($_REQUEST['lon_h']) ? $_REQUEST['lon_h'] : 0; |
392
|
|
|
$options['lat_min'] = isset($_REQUEST['lat_min']) ? $_REQUEST['lat_min'] : 0; |
393
|
|
|
$options['lon_min'] = isset($_REQUEST['lon_min']) ? $_REQUEST['lon_min'] : 0; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
$options['distance'] = isset($_REQUEST['distance']) ? $_REQUEST['distance'] : 0; |
397
|
|
|
} elseif (isset($_REQUEST['searchbyfulltext'])) { |
398
|
|
|
$options['searchtype'] = 'byfulltext'; |
399
|
|
|
|
400
|
|
|
$options['ft_name'] = isset($_REQUEST['ft_name']) ? $_REQUEST['ft_name'] + 0 : 0; |
401
|
|
|
$options['ft_desc'] = isset($_REQUEST['ft_desc']) ? $_REQUEST['ft_desc'] + 0 : 0; |
402
|
|
|
$options['ft_logs'] = isset($_REQUEST['ft_logs']) ? $_REQUEST['ft_logs'] + 0 : 0; |
403
|
|
|
$options['ft_pictures'] = isset($_REQUEST['ft_pictures']) ? $_REQUEST['ft_pictures'] + 0 : 0; |
404
|
|
|
|
405
|
|
|
$options['fulltext'] = isset($_REQUEST['fulltext']) ? $_REQUEST['fulltext'] : ''; |
406
|
|
|
} elseif (isset($_REQUEST['searchbycacheid'])) { |
407
|
|
|
$options['searchtype'] = 'bycacheid'; |
408
|
|
|
$options['cacheid'] = isset($_REQUEST['cacheid']) ? $_REQUEST['cacheid'] : 0; |
409
|
|
|
if (!is_numeric($options['cacheid'])) { |
410
|
|
|
$options['cacheid'] = 0; |
411
|
|
|
} |
412
|
|
|
} elseif (isset($_REQUEST['searchbywp'])) { |
413
|
|
|
$options['searchtype'] = 'bywp'; |
414
|
|
|
$options['wp'] = isset($_REQUEST['wp']) ? $_REQUEST['wp'] : ''; |
415
|
|
|
} elseif (isset($_REQUEST['searchbynofilter'])) { |
416
|
|
|
$options['searchtype'] = 'bynofilter'; |
417
|
|
|
} elseif (isset($_REQUEST['searchbylist'])) { |
418
|
|
|
$options['searchtype'] = 'bylist'; |
419
|
|
|
$options['listid'] = isset($_REQUEST['listid']) ? $_REQUEST['listid'] + 0 : 0; |
420
|
|
|
$invalid_waypoints = isset($_REQUEST['invalidwp']) ? $_REQUEST['invalidwp'] : false; |
421
|
|
|
|
422
|
|
|
$password = isset($_REQUEST['listkey']) ? $_REQUEST['listkey'] : ''; |
423
|
|
|
$list = new cachelist($options['listid']); |
424
|
|
|
if (!$list->allowView($password)) { |
425
|
|
|
$tpl->redirect("cachelists.php"); |
426
|
|
|
} |
427
|
|
|
$options['cachelist'] = cachelist::getListById($options['listid']); // null for invalid ID |
428
|
|
|
$options['cachelist_pw'] = $password; |
429
|
|
|
} elseif (isset($_REQUEST['searchall'])) { |
430
|
|
|
if (!$login->logged_in() && |
431
|
|
|
!(isset($_REQUEST['country']) && $_REQUEST['country'] != '') && |
432
|
|
|
!(isset($_REQUEST['language']) && $_REQUEST['language'] != '') && |
433
|
|
|
!(isset($_REQUEST['cache_attribs']) && $_REQUEST['cache_attribs'] == 61) // map Safari button |
434
|
|
|
) { |
435
|
|
|
// This operation is very expensive and therefore available only |
436
|
|
|
// for logged-in users. |
437
|
|
|
$tpl->error(ERROR_LOGIN_REQUIRED); |
438
|
|
|
} else { |
439
|
|
|
$options['searchtype'] = 'all'; |
440
|
|
|
} |
441
|
|
|
} else { |
442
|
|
|
if (isset($_REQUEST['showresult'])) { |
443
|
|
|
$tpl->error('unknown search option'); |
444
|
|
|
} else { |
445
|
|
|
// Set default search type; this prevents errors in outputSearchForm() |
446
|
|
|
// when initializing searchtype-dependent options: |
447
|
|
|
$options['searchtype'] = 'byname'; |
448
|
|
|
$options['cachename'] = ''; |
449
|
|
|
} |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
$options['sort'] = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : ($homecoords ? 'bydistance' : 'byname'); |
453
|
|
|
if (isset($_REQUEST['orderRatingFirst']) && $_REQUEST['orderRatingFirst'] == 1) { |
454
|
|
|
$options['orderRatingFirst'] = true; |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
$options['country'] = isset($_REQUEST['country']) ? $_REQUEST['country'] : ''; |
458
|
|
|
$options['language'] = isset($_REQUEST['language']) ? $_REQUEST['language'] : ''; |
459
|
|
|
$options['adm2'] = isset($_REQUEST['adm2']) ? $_REQUEST['adm2'] : ''; |
460
|
|
|
$options['cachetype'] = isset($_REQUEST['cachetype']) ? $_REQUEST['cachetype'] : ''; |
461
|
|
|
|
462
|
|
|
$options['cachesize'] = isset($_REQUEST['cachesize']) ? $_REQUEST['cachesize'] : ''; |
463
|
|
|
$options['difficultymin'] = isset($_REQUEST['difficultymin']) ? $_REQUEST['difficultymin'] + 0 : 0; |
464
|
|
|
$options['difficultymax'] = isset($_REQUEST['difficultymax']) ? $_REQUEST['difficultymax'] + 0 : 0; |
465
|
|
|
$options['terrainmin'] = isset($_REQUEST['terrainmin']) ? $_REQUEST['terrainmin'] + 0 : 0; |
466
|
|
|
$options['terrainmax'] = isset($_REQUEST['terrainmax']) ? $_REQUEST['terrainmax'] + 0 : 0; |
467
|
|
|
$options['recommendationmin'] = isset($_REQUEST['recommendationmin']) ? $_REQUEST['recommendationmin'] + 0 : 0; |
468
|
|
|
|
469
|
|
|
if (in_array($options['searchtype'], ['byort', 'byplz', 'bydistance', 'bywaypoint'])) { |
470
|
|
|
// For distance-based searches, sort by distance instead of name. |
471
|
|
|
if ($options['sort'] == 'byname') { |
472
|
|
|
$options['sort'] = 'bydistance'; |
473
|
|
|
} |
474
|
|
|
} else { |
475
|
|
|
// For non-distance-based searches, sort by name instead of distance if |
476
|
|
|
// no reference coords exist. |
477
|
|
|
if (!isset($options['lat']) || !isset($options['lon']) || $options['lat'] + $options['lon'] == 0) { |
478
|
|
|
if (!$homecoords && !$options['sort']) { |
479
|
|
|
$options['sort'] = 'byname'; |
480
|
|
|
} |
481
|
|
|
} |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
$options['queryid'] = 0; |
485
|
|
|
} // $queryid == 0 |
486
|
|
|
|
487
|
|
|
// set common variable options |
488
|
|
|
if (isset($_REQUEST['sortorder'])) { |
489
|
|
|
$options['sortorder'] = $_REQUEST['sortorder']; |
490
|
|
|
} |
491
|
|
|
if (isset($_REQUEST['creationdate'])) { |
492
|
|
|
$options['creationdate'] = $_REQUEST['creationdate']; |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
//========================================================= |
496
|
|
|
// 3. query caching |
497
|
|
|
//========================================================= |
498
|
|
|
|
499
|
|
|
$bRememberQuery = isset($_REQUEST['skipqueryid']) ? !$_REQUEST['skipqueryid'] : true; |
500
|
|
|
// This is used by the map, which implements its own query-caching. |
501
|
|
|
if ($bRememberQuery) { |
502
|
|
|
if ($queryid == 0 && $options['showresult'] != 0) { // 'showresult' = "execute query" |
503
|
|
|
sql( |
|
|
|
|
504
|
|
|
"INSERT INTO `queries` (`user_id`, `options`, `last_queried`) VALUES (0, '&1', NOW())", |
505
|
|
|
serialize($options) |
506
|
|
|
); |
507
|
|
|
$options['queryid'] = sql_insert_id(); |
|
|
|
|
508
|
|
|
$cookie->set('lastqueryid', $options['queryid']); |
509
|
|
|
} |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
// remove old queries (after 1 hour without use); |
513
|
|
|
// execute only every 50 search calls |
514
|
|
|
if (mt_rand(1, 50) == 1) { |
515
|
|
|
sql('DELETE FROM `queries` WHERE `last_queried` < NOW() - INTERVAL 1 HOUR AND `user_id` = 0'); |
|
|
|
|
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
|
519
|
|
|
//========================================================= |
520
|
|
|
// 4. set defaults for new search options |
521
|
|
|
// which may not be present in a stored query |
522
|
|
|
//========================================================= |
523
|
|
|
|
524
|
|
|
if (!isset($options['orderRatingFirst'])) { |
525
|
|
|
$options['orderRatingFirst'] = false; |
526
|
|
|
} |
527
|
|
|
if (!isset($options['f_otherPlatforms'])) { |
528
|
|
|
$options['f_otherPlatforms'] = 0; |
529
|
|
|
} |
530
|
|
|
if (!isset($options['difficultymin'])) { |
531
|
|
|
$options['difficultymin'] = 0; |
532
|
|
|
} |
533
|
|
|
if (!isset($options['difficultymax'])) { |
534
|
|
|
$options['difficultymax'] = 0; |
535
|
|
|
} |
536
|
|
|
if (!isset($options['terrainmin'])) { |
537
|
|
|
$options['terrainmin'] = 0; |
538
|
|
|
} |
539
|
|
|
if (!isset($options['terrainmax'])) { |
540
|
|
|
$options['terrainmax'] = 0; |
541
|
|
|
} |
542
|
|
|
if (!isset($options['recommendationmin'])) { |
543
|
|
|
$options['recommendationmin'] = 0; |
544
|
|
|
} |
545
|
|
|
if (!isset($options['cachetype'])) { |
546
|
|
|
$options['cachetype'] = ''; |
547
|
|
|
} |
548
|
|
|
if (!isset($options['cachesize'])) { |
549
|
|
|
$options['cachesize'] = ''; |
550
|
|
|
} |
551
|
|
|
if (!isset($options['bbox'])) { |
552
|
|
|
$options['bbox'] = false; |
553
|
|
|
} |
554
|
|
|
if (!isset($options['f_disabled'])) { |
555
|
|
|
$options['f_disabled'] = 0; |
556
|
|
|
} |
557
|
|
|
if (!isset($options['f_geokrets'])) { |
558
|
|
|
$options['f_geokrets'] = 0; |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
if (!isset($options['showresult'])) { |
562
|
|
|
$options['showresult'] = 0; |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
if ($options['showresult'] == 1) { |
566
|
|
|
//=============================================================== |
567
|
|
|
// X5. build basic SQL statement depends on search type |
568
|
|
|
// and filtering options |
569
|
|
|
//=============================================================== |
570
|
|
|
|
571
|
|
|
sql_drop_temp_table_slave('result_caches'); |
|
|
|
|
572
|
|
|
$cachesFilter = ''; |
573
|
|
|
|
574
|
|
|
if (!isset($options['output'])) { |
575
|
|
|
$options['output'] = ''; |
576
|
|
|
} |
577
|
|
|
if ((mb_strpos($options['output'], '.') !== false) || |
578
|
|
|
(mb_strpos($options['output'], '/') !== false) || |
579
|
|
|
(mb_strpos($options['output'], '\\') !== false) |
580
|
|
|
) { |
581
|
|
|
$options['output'] = 'HTML'; |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
// make a list of cache-ids that are in the result |
585
|
|
|
if (!isset($options['expert'])) { |
586
|
|
|
$options['expert'] = 0; |
587
|
|
|
} |
588
|
|
|
if ($options['expert'] == 0) { |
589
|
|
|
$sql_select = []; |
590
|
|
|
$sql_from = ''; |
591
|
|
|
$sql_innerjoin = []; |
592
|
|
|
$sql_leftjoin = []; |
593
|
|
|
$sql_where = []; |
594
|
|
|
$sql_having = []; |
595
|
|
|
$sql_group = []; |
596
|
|
|
|
597
|
|
|
//check the entered data and build SQL |
598
|
|
|
if (!isset($options['searchtype'])) { |
599
|
|
|
$options['searchtype'] = ''; |
600
|
|
|
} |
601
|
|
|
if ($options['searchtype'] == 'byname') { |
602
|
|
|
$sql_select[] = '`caches`.`cache_id` `cache_id`'; |
603
|
|
|
$sql_from = '`caches`'; |
604
|
|
|
$sql_where[] = '`caches`.`name` LIKE \'%' . sql_escape($options['cachename']) . '%\''; |
|
|
|
|
605
|
|
|
} elseif ($options['searchtype'] == 'byowner') { |
606
|
|
|
if ($options['ownerid'] != 0) { |
607
|
|
|
$sql_select[] = '`caches`.`cache_id` `cache_id`'; |
608
|
|
|
$sql_from = '`caches`'; |
609
|
|
|
$sql_where[] = '`user_id`=\'' . sql_escape($options['ownerid']) . '\''; |
|
|
|
|
610
|
|
View Code Duplication |
} else { |
611
|
|
|
$sql_select[] = '`caches`.`cache_id` `cache_id`'; |
612
|
|
|
$sql_from = '`caches`'; |
613
|
|
|
$sql_innerjoin[] = '`user` ON `caches`.`user_id`=`user`.`user_id`'; |
614
|
|
|
$sql_where[] = '`user`.`username`=\'' . sql_escape($options['owner']) . '\''; |
|
|
|
|
615
|
|
|
} |
616
|
|
|
} elseif (($options['searchtype'] == 'byplz') || ($options['searchtype'] == 'byort')) { |
617
|
|
|
$locid = $options['locid']; |
618
|
|
|
|
619
|
|
|
if ($options['searchtype'] == 'byplz') { |
620
|
|
|
if ($locid == 0) { |
621
|
|
View Code Duplication |
if (isset($options['ortplz'])) { |
622
|
|
|
$plz = $options['ortplz']; |
623
|
|
|
} else { |
624
|
|
|
$plz = $options['plz']; |
625
|
|
|
} |
626
|
|
|
$sql = |
627
|
|
|
"SELECT `loc_id` |
628
|
|
|
FROM `geodb_textdata` |
629
|
|
|
WHERE `text_type`=500300000 AND `text_val`='" . sql_escape($plz) . "'"; |
|
|
|
|
630
|
|
|
$rs = sql($sql); |
|
|
|
|
631
|
|
|
if (sql_num_rows($rs) == 0) { |
|
|
|
|
632
|
|
|
sql_free_result($rs); |
|
|
|
|
633
|
|
|
$options['error_plz'] = true; |
634
|
|
|
outputSearchForm($options); |
635
|
|
|
exit; |
636
|
|
|
} elseif (sql_num_rows($rs) == 1) { |
|
|
|
|
637
|
|
|
$r = sql_fetch_array($rs); |
|
|
|
|
638
|
|
|
sql_free_result($rs); |
|
|
|
|
639
|
|
|
$locid = $r['loc_id']; |
640
|
|
|
} else { |
641
|
|
|
sql_free_result($rs); |
|
|
|
|
642
|
|
|
// ok, viele locations ... alle auflisten ... |
643
|
|
|
outputLocidSelectionForm($sql, $options); |
644
|
|
|
exit; |
645
|
|
|
} |
646
|
|
|
} |
647
|
|
|
// ok, wir haben einen ort ... koordinaten ermitteln |
648
|
|
|
$locid = $locid + 0; |
649
|
|
|
$rs = sql( |
|
|
|
|
650
|
|
|
"SELECT `lon`, `lat` |
651
|
|
|
FROM `geodb_coordinates` |
652
|
|
|
WHERE `loc_id`='&1' AND coord_type=200100000", |
653
|
|
|
$locid |
654
|
|
|
); |
655
|
|
View Code Duplication |
if (isset($rs) && $r = sql_fetch_array($rs)) { |
|
|
|
|
656
|
|
|
// ok ... wir haben koordinaten ... |
657
|
|
|
$lat = $r['lat'] + 0; |
658
|
|
|
$lon = $r['lon'] + 0; |
659
|
|
|
sql_free_result($rs); |
|
|
|
|
660
|
|
|
|
661
|
|
|
$lon_rad = $lon * 3.14159 / 180; |
662
|
|
|
$lat_rad = $lat * 3.14159 / 180; |
663
|
|
|
|
664
|
|
|
if (isset($options['distance'])) { |
665
|
|
|
$distance = $options['distance']; |
666
|
|
|
} else { |
667
|
|
|
$distance = DEFAULT_SEARCH_DISTANCE; |
668
|
|
|
} |
669
|
|
|
if (isset($options['unit'])) { |
670
|
|
|
$distance_unit = $options['unit']; |
671
|
|
|
} else { |
672
|
|
|
$distance_unit = DEFAULT_DISTANCE_UNIT; |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
sqlStringbySearchradius($distance, $lat, $lon, $multiplier, $distance_unit); |
676
|
|
|
} else { |
677
|
|
|
if (isset($rs)) { |
678
|
|
|
sql_free_result($rs); |
|
|
|
|
679
|
|
|
} |
680
|
|
|
$options['error_locidnocoords'] = true; |
681
|
|
|
outputSearchForm($options); |
682
|
|
|
exit; |
683
|
|
|
} |
684
|
|
|
} else { |
685
|
|
|
if ($options['searchtype'] == 'byort') { |
686
|
|
|
if ($locid == 0) { |
687
|
|
View Code Duplication |
if (isset($options['ortplz'])) { |
688
|
|
|
$ort = $options['ortplz']; |
689
|
|
|
} else { |
690
|
|
|
$ort = $options['ort']; |
691
|
|
|
} |
692
|
|
|
$simpletexts = search_text2sort($ort, true); |
693
|
|
|
$simpletextsarray = explode_multi($simpletexts, ' -/,'); |
694
|
|
|
|
695
|
|
|
$sqlhashes = ''; |
696
|
|
|
$wordscount = 0; |
697
|
|
|
foreach ($simpletextsarray as $text) { |
698
|
|
|
if ($text != '') { |
699
|
|
|
$searchstring = search_text2simple($text); |
700
|
|
|
|
701
|
|
|
if ($sqlhashes != '') { |
702
|
|
|
$sqlhashes .= ' OR '; |
703
|
|
|
} |
704
|
|
|
$sqlhashes .= '`gns_search`.`simplehash`=' . sprintf("%u", crc32($searchstring)); |
705
|
|
|
|
706
|
|
|
$wordscount++; |
707
|
|
|
} |
708
|
|
|
} |
709
|
|
|
|
710
|
|
|
if ($sqlhashes == '') { |
711
|
|
|
$options['error_ort'] = true; |
712
|
|
|
outputSearchForm($options); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
// temporäre tabelle erstellen und dann einträge entfernen, die nicht mindestens so oft vorkommen wie worte gegeben wurden |
716
|
|
|
sql_drop_temp_table_slave('tmpuniids'); |
|
|
|
|
717
|
|
|
sql_temp_table_slave('tmpuniids'); |
|
|
|
|
718
|
|
|
sql_slave( |
|
|
|
|
719
|
|
|
"CREATE TEMPORARY TABLE &tmpuniids ( |
720
|
|
|
`uni_id` int(11) NOT NULL, |
721
|
|
|
`cnt` int(11) NOT NULL, |
722
|
|
|
`olduni` int(11) NOT NULL, |
723
|
|
|
`simplehash` int(11) NOT NULL |
724
|
|
|
) ENGINE=MEMORY |
725
|
|
|
SELECT |
726
|
|
|
`gns_search`.`uni_id` `uni_id`, |
727
|
|
|
0 `cnt`, |
728
|
|
|
0 `olduni`, |
729
|
|
|
`simplehash` |
730
|
|
|
FROM `gns_search` |
731
|
|
|
WHERE " . $sqlhashes |
732
|
|
|
); |
733
|
|
|
sql_slave('ALTER TABLE &tmpuniids ADD INDEX (`uni_id`)'); |
|
|
|
|
734
|
|
|
|
735
|
|
|
// BUGFIX: dieser Code sollte nur ausgeführt werden, wenn mehr als ein Suchbegriff eingegeben wurde |
736
|
|
|
// damit alle Einträge gefiltert, die nicht alle Suchbegriffe enthalten |
737
|
|
|
// nun wird dieser Quellcode auch ausgeführt, um mehrfache uni_id's zu filtern |
738
|
|
|
// Notwendig, wenn nach Baden gesucht wird => Baden-Baden war doppelt in der Liste |
739
|
|
|
// if ($wordscount > 1) |
740
|
|
|
// { |
741
|
|
|
sql_temp_table_slave('tmpuniids2'); |
|
|
|
|
742
|
|
|
sql_slave( |
|
|
|
|
743
|
|
|
"CREATE TEMPORARY TABLE &tmpuniids2 ( |
744
|
|
|
`uni_id` int(11) NOT NULL, |
745
|
|
|
`cnt` int(11) NOT NULL, |
746
|
|
|
`olduni` int(11) NOT NULL |
747
|
|
|
) ENGINE=MEMORY |
748
|
|
|
SELECT `uni_id`, COUNT(*) `cnt`, 0 olduni |
749
|
|
|
FROM &tmpuniids |
750
|
|
|
GROUP BY `uni_id` |
751
|
|
|
HAVING `cnt` >= " . $wordscount |
752
|
|
|
); |
753
|
|
|
sql_slave('ALTER TABLE &tmpuniids2 ADD INDEX (`uni_id`)'); |
|
|
|
|
754
|
|
|
sql_drop_temp_table_slave('tmpuniids'); |
|
|
|
|
755
|
|
|
sql_rename_temp_table_slave('tmpuniids2', 'tmpuniids'); |
|
|
|
|
756
|
|
|
// } |
757
|
|
|
|
758
|
|
|
// add: SELECT g2.uni FROM &tmpuniids JOIN gns_locations g1 ON &tmpuniids.uni_id=g1.uni JOIN gns_locations g2 ON g1.ufi=g2.ufi WHERE g1.nt!='N' AND g2.nt='N' |
759
|
|
|
// remove: SELECT g1.uni FROM &tmpuniids JOIN gns_locations g1 ON &tmpuniids.uni_id=g1.uni JOIN gns_locations g2 ON g1.ufi=g2.ufi WHERE g1.nt!='N' AND g2.nt='N' |
760
|
|
|
|
761
|
|
|
// und jetzt noch alle englischen bezeichnungen durch deutsche ersetzen (wo möglich) ... |
762
|
|
|
sql_temp_table_slave('tmpuniidsAdd'); |
|
|
|
|
763
|
|
|
sql_slave( |
|
|
|
|
764
|
|
|
"CREATE TEMPORARY TABLE &tmpuniidsAdd ( |
765
|
|
|
`uni` int(11) NOT NULL, |
766
|
|
|
`olduni` int(11) NOT NULL, |
767
|
|
|
PRIMARY KEY (`uni`) |
768
|
|
|
) ENGINE=MEMORY |
769
|
|
|
SELECT g2.uni uni, g1.uni olduni |
770
|
|
|
FROM &tmpuniids |
771
|
|
|
JOIN gns_locations g1 ON &tmpuniids.uni_id=g1.uni |
772
|
|
|
JOIN gns_locations g2 ON g1.ufi=g2.ufi |
773
|
|
|
WHERE g1.nt!='N' AND g2.nt='N' GROUP BY uni" |
774
|
|
|
); |
775
|
|
|
sql_temp_table_slave('tmpuniidsRemove'); |
|
|
|
|
776
|
|
|
sql_slave( |
|
|
|
|
777
|
|
|
"CREATE TEMPORARY TABLE &tmpuniidsRemove ( |
778
|
|
|
`uni` int(11) NOT NULL, |
779
|
|
|
PRIMARY KEY (`uni`) |
780
|
|
|
) ENGINE=MEMORY |
781
|
|
|
SELECT DISTINCT g1.uni uni |
782
|
|
|
FROM &tmpuniids |
783
|
|
|
JOIN gns_locations g1 ON &tmpuniids.uni_id=g1.uni |
784
|
|
|
JOIN gns_locations g2 ON g1.ufi=g2.ufi |
785
|
|
|
WHERE g1.nt!='N' AND g2.nt='N'" |
786
|
|
|
); |
787
|
|
|
sql_slave( |
|
|
|
|
788
|
|
|
"DELETE FROM &tmpuniids |
789
|
|
|
WHERE uni_id IN (SELECT uni FROM &tmpuniidsRemove)" |
790
|
|
|
); |
791
|
|
|
sql_slave( |
|
|
|
|
792
|
|
|
"DELETE FROM &tmpuniidsAdd |
793
|
|
|
WHERE uni IN (SELECT uni_id FROM &tmpuniids)" |
794
|
|
|
); |
795
|
|
|
sql_slave( |
|
|
|
|
796
|
|
|
"INSERT INTO &tmpuniids (uni_id, olduni) |
797
|
|
|
SELECT uni, olduni FROM &tmpuniidsAdd" |
798
|
|
|
); |
799
|
|
|
sql_drop_temp_table_slave('tmpuniidsAdd'); |
|
|
|
|
800
|
|
|
sql_drop_temp_table_slave('tmpuniidsRemove'); |
|
|
|
|
801
|
|
|
|
802
|
|
|
$rs = sql_slave("SELECT `uni_id` FROM &tmpuniids"); |
|
|
|
|
803
|
|
|
if (sql_num_rows($rs) == 0) { |
|
|
|
|
804
|
|
|
sql_free_result($rs); |
|
|
|
|
805
|
|
|
|
806
|
|
|
$options['error_ort'] = true; |
807
|
|
|
outputSearchForm($options); |
808
|
|
|
exit; |
809
|
|
|
} elseif (sql_num_rows($rs) == 1) { |
|
|
|
|
810
|
|
|
$r = sql_fetch_array($rs); |
|
|
|
|
811
|
|
|
sql_free_result($rs); |
|
|
|
|
812
|
|
|
|
813
|
|
|
// wenn keine 100%ige übereinstimmung nochmals anzeigen |
814
|
|
|
$locid = $r['uni_id'] + 0; |
815
|
|
|
$rsCmp = sql_slave( |
|
|
|
|
816
|
|
|
"SELECT `full_name` FROM `gns_locations` WHERE `uni`='&1' LIMIT 1", |
817
|
|
|
$locid |
818
|
|
|
); |
819
|
|
|
$rCmp = sql_fetch_array($rsCmp); |
|
|
|
|
820
|
|
|
sql_free_result($rsCmp); |
|
|
|
|
821
|
|
|
|
822
|
|
|
if (mb_strtolower($rCmp['full_name']) != mb_strtolower($ort)) { |
823
|
|
|
outputUniidSelectionForm( |
824
|
|
|
"SELECT `uni_id`, `olduni` FROM `&tmpuniids`", |
825
|
|
|
$options |
826
|
|
|
); |
827
|
|
|
} |
828
|
|
|
} else { |
829
|
|
|
sql_free_result($rs); |
|
|
|
|
830
|
|
|
outputUniidSelectionForm( |
831
|
|
|
"SELECT `uni_id`, `olduni` FROM `&tmpuniids`", |
832
|
|
|
$options |
833
|
|
|
); |
834
|
|
|
exit; |
835
|
|
|
} |
836
|
|
|
} |
837
|
|
|
|
838
|
|
|
|
839
|
|
|
// ok, wir haben einen ort ... koordinaten ermitteln |
840
|
|
|
$locid = $locid + 0; |
841
|
|
|
$rs = sql_slave( |
|
|
|
|
842
|
|
|
"SELECT `lon`, `lat` FROM `gns_locations` WHERE `uni`='&1' LIMIT 1", |
843
|
|
|
$locid |
844
|
|
|
); |
845
|
|
View Code Duplication |
if (isset($rs) && $r = sql_fetch_array($rs)) { |
|
|
|
|
846
|
|
|
// ok ... wir haben koordinaten ... |
847
|
|
|
|
848
|
|
|
$lat = $r['lat'] + 0; |
849
|
|
|
$lon = $r['lon'] + 0; |
850
|
|
|
sql_free_result($rs); |
|
|
|
|
851
|
|
|
|
852
|
|
|
$lon_rad = $lon * 3.14159 / 180; |
853
|
|
|
$lat_rad = $lat * 3.14159 / 180; |
854
|
|
|
|
855
|
|
|
if (isset($options['distance'])) { |
856
|
|
|
$distance = $options['distance']; |
857
|
|
|
} else { |
858
|
|
|
$distance = DEFAULT_SEARCH_DISTANCE; |
859
|
|
|
} |
860
|
|
|
if (isset($options['unit'])) { |
861
|
|
|
$distance_unit = $options['unit']; |
862
|
|
|
} else { |
863
|
|
|
$distance_unit = DEFAULT_DISTANCE_UNIT; |
864
|
|
|
} |
865
|
|
|
|
866
|
|
|
sqlStringbySearchradius($distance, $lat, $lon, $multiplier, $distance_unit); |
867
|
|
|
} else { |
868
|
|
|
if (isset($rs)) { |
869
|
|
|
sql_free_result($rs); |
|
|
|
|
870
|
|
|
} |
871
|
|
|
$options['error_locidnocoords'] = true; |
872
|
|
|
outputSearchForm($options); |
873
|
|
|
exit; |
874
|
|
|
} |
875
|
|
|
} |
876
|
|
|
} |
877
|
|
|
} elseif ($options['searchtype'] == 'bywaypoint') { |
878
|
|
|
if (preg_match('/gc[0-9a-z]{2,}/i', $options['waypoint'])) { |
879
|
|
|
$rs = sql_slave( |
|
|
|
|
880
|
|
|
"SELECT `longitude`, `latitude` |
881
|
|
|
FROM `caches` |
882
|
|
|
WHERE `wp_gc_maintained`='&1' ", |
883
|
|
|
$options['waypoint'] |
884
|
|
|
); |
885
|
|
|
} else { |
886
|
|
|
$rs = sql_slave( |
|
|
|
|
887
|
|
|
"SELECT `longitude`, `latitude` |
888
|
|
|
FROM `caches` |
889
|
|
|
WHERE `wp_oc`='&1' ", |
890
|
|
|
$options['waypoint'] |
891
|
|
|
); |
892
|
|
|
} |
893
|
|
|
$r = sql_fetch_array($rs); |
|
|
|
|
894
|
|
|
|
895
|
|
|
if ($r) { |
|
|
|
|
896
|
|
|
$lat = $r['latitude']; |
897
|
|
|
$lon = $r['longitude']; |
898
|
|
|
sql_free_result($rs); |
|
|
|
|
899
|
|
|
|
900
|
|
|
$distance = $options['distance']; |
901
|
|
|
$distance_unit = $options['unit']; |
902
|
|
|
|
903
|
|
|
$lon_rad = $lon * 3.14159 / 180; |
904
|
|
|
$lat_rad = $lat * 3.14159 / 180; |
905
|
|
|
|
906
|
|
|
sqlStringbySearchradius($distance, $lat, $lon, $multiplier, $distance_unit); |
907
|
|
|
} else { |
908
|
|
|
$options['error_nowaypointfound'] = true; |
909
|
|
|
outputSearchForm($options); |
910
|
|
|
exit; |
911
|
|
|
} |
912
|
|
|
} elseif ($options['searchtype'] == 'bycoords') { // Ocprop |
913
|
|
|
//check the entered data |
914
|
|
|
if (isset($options['lat']) && isset($options['lon'])) { |
915
|
|
|
$lat = $options['lat'] + 0; |
916
|
|
|
$lon = $options['lon'] + 0; |
917
|
|
|
} else { |
918
|
|
|
$latNS = $options['latNS']; |
919
|
|
|
$lonEW = $options['lonEW']; |
920
|
|
|
|
921
|
|
|
$lon_h = $options['lon_h']; |
922
|
|
|
$lat_h = $options['lat_h']; |
923
|
|
|
$lon_min = $options['lon_min']; |
924
|
|
|
$lat_min = $options['lat_min']; |
925
|
|
|
|
926
|
|
|
if (is_numeric($lon_h) |
927
|
|
|
&& is_numeric($lon_min) |
928
|
|
|
&& ($lon_h >= 0) |
929
|
|
|
&& ($lon_h < 180) |
930
|
|
|
&& ($lon_min >= 0) |
931
|
|
|
&& ($lon_min < 60) |
932
|
|
|
) { |
933
|
|
|
$lon = $lon_h + $lon_min / 60; |
934
|
|
|
if ($lonEW == 'W') { |
935
|
|
|
$lon = -$lon; |
936
|
|
|
} |
937
|
|
|
} |
938
|
|
|
|
939
|
|
|
if (is_numeric($lat_h) |
940
|
|
|
&& is_numeric($lat_min) |
941
|
|
|
&& ($lat_h >= 0) |
942
|
|
|
&& ($lat_h < 90) |
943
|
|
|
&& ($lat_min >= 0) |
944
|
|
|
&& ($lat_min < 60) |
945
|
|
|
) { |
946
|
|
|
$lat = $lat_h + $lat_min / 60; |
947
|
|
|
if ($latNS == 'S') { |
948
|
|
|
$lat = - $lat; |
949
|
|
|
} |
950
|
|
|
} |
951
|
|
|
} |
952
|
|
|
|
953
|
|
|
$distance = $options['distance']; |
954
|
|
|
$distance_unit = $options['unit']; |
955
|
|
|
|
956
|
|
|
if ((!isset($lon)) || (!isset($lat)) || (!is_numeric($distance))) { |
957
|
|
|
$options['error_nocoords'] = true; |
958
|
|
|
outputSearchForm($options); |
959
|
|
|
exit; |
960
|
|
|
} |
961
|
|
|
|
962
|
|
|
$lon_rad = $lon * 3.14159 / 180; |
963
|
|
|
$lat_rad = $lat * 3.14159 / 180; |
964
|
|
|
|
965
|
|
|
sqlStringbySearchradius($distance, $lat, $lon, $multiplier, $distance_unit); |
966
|
|
|
} elseif ($options['searchtype'] == 'byfinder') { |
967
|
|
|
if ($options['finderid'] != 0) { |
968
|
|
|
$finder_id = $options['finderid']; |
969
|
|
|
} else { |
970
|
|
|
$rs = sql_slave( |
|
|
|
|
971
|
|
|
"SELECT `user_id` FROM `user` WHERE `username`='&1'", |
972
|
|
|
$options['finder'] |
973
|
|
|
); |
974
|
|
|
$finder_record = sql_fetch_array($rs); |
|
|
|
|
975
|
|
|
$finder_id = $finder_record['user_id']; |
976
|
|
|
sql_free_result($rs); |
|
|
|
|
977
|
|
|
} |
978
|
|
|
|
979
|
|
|
if (!isset($options['logtype'])) { |
980
|
|
|
$options['logtype'] = '1,7'; |
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
$sql_select[] = 'distinct `caches`.`cache_id` `cache_id`'; |
984
|
|
|
// needs distinct because there can be multiple matching logs per cache |
985
|
|
|
$sql_from = '`caches`'; |
986
|
|
|
$sql_innerjoin[] = '`cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`'; |
987
|
|
|
$sql_where[] = '`cache_logs`.`user_id`=\'' . sql_escape($finder_id) . '\''; |
|
|
|
|
988
|
|
|
|
989
|
|
|
if ($options['logtype'] != '0') { // 0 = all types |
990
|
|
|
$ids = explode(',', $options['logtype']); |
991
|
|
|
$idNumbers = '0'; |
992
|
|
|
foreach ($ids as $id) { |
993
|
|
|
if ($idNumbers != '') { |
994
|
|
|
$idNumbers .= ','; |
995
|
|
|
} |
996
|
|
|
$idNumbers .= ($id + 0); |
997
|
|
|
} |
998
|
|
|
$sql_where[] = '`cache_logs`.`type` IN (' . $idNumbers . ')'; |
999
|
|
|
} |
1000
|
|
View Code Duplication |
} elseif ($options['searchtype'] == 'bycacheid') { |
1001
|
|
|
$sql_select[] = '`caches`.`cache_id` `cache_id`'; |
1002
|
|
|
$sql_from = '`caches`'; |
1003
|
|
|
$sql_where[] = '`caches`.`cache_id`=\'' . sql_escape($options['cacheid']) . '\''; |
|
|
|
|
1004
|
|
|
} elseif ($options['searchtype'] == 'bywp') { |
1005
|
|
|
$sql_select[] = '`caches`.`cache_id` `cache_id`'; |
1006
|
|
|
$sql_from = '`caches`'; |
1007
|
|
|
$sql_where[] = '`caches`.`wp_oc`=\'' . sql_escape($options['wp']) . '\''; |
|
|
|
|
1008
|
|
|
} elseif ($options['searchtype'] == 'byfulltext') { |
1009
|
|
|
require_once __DIR__ . '/lib2/search/ftsearch.inc.php'; |
1010
|
|
|
|
1011
|
|
|
$fulltext = $options['fulltext']; |
1012
|
|
|
$hashes = ftsearch_hash($fulltext); |
1013
|
|
|
|
1014
|
|
|
if (count($hashes) == 0) { |
1015
|
|
|
$options['error_nofulltext'] = true; |
1016
|
|
|
outputSearchForm($options); |
1017
|
|
|
} else { |
1018
|
|
|
if (count($hashes) > 50) { |
1019
|
|
|
$options['error_fulltexttoolong'] = true; |
1020
|
|
|
outputSearchForm($options); |
1021
|
|
|
} |
1022
|
|
|
} |
1023
|
|
|
|
1024
|
|
|
$ft_types = []; |
1025
|
|
|
if (isset($options['ft_name']) && $options['ft_name']) { |
1026
|
|
|
$ft_types[] = 2; |
1027
|
|
|
} |
1028
|
|
|
if (isset($options['ft_logs']) && $options['ft_logs']) { |
1029
|
|
|
$ft_types[] = 1; |
1030
|
|
|
} |
1031
|
|
|
if (isset($options['ft_desc']) && $options['ft_desc']) { |
1032
|
|
|
$ft_types[] = 3; |
1033
|
|
|
} |
1034
|
|
|
if (isset($options['ft_pictures']) && $options['ft_pictures']) { |
1035
|
|
|
$ft_types[] = 6; |
1036
|
|
|
} |
1037
|
|
|
if (count($ft_types) == 0) { |
1038
|
|
|
$ft_types[] = 0; |
1039
|
|
|
} |
1040
|
|
|
|
1041
|
|
|
$sql_select[] = '`caches`.`cache_id` `cache_id`'; |
1042
|
|
|
$sql_from = '`caches`'; |
1043
|
|
|
|
1044
|
|
|
$n = 1; |
1045
|
|
|
foreach ($hashes as $k => $h) { |
1046
|
|
|
if ($n > 1) { |
1047
|
|
|
$sql_innerjoin[] = '`search_index` AS `s' . $n . '` ON `s' . |
1048
|
|
|
($n - 1) . '`.`cache_id`=`s' . $n . '`.`cache_id`'; |
1049
|
|
|
} else { |
1050
|
|
|
$sql_innerjoin[] = '`search_index` AS `s1` ON `s1`.`cache_id`=`caches`.`cache_id`'; |
1051
|
|
|
} |
1052
|
|
|
|
1053
|
|
|
$sql_where[] = '`s' . $n . '`.`hash`=\'' . sql_escape($h) . '\''; |
|
|
|
|
1054
|
|
|
$sql_where[] = '`s' . $n . '`.`object_type` IN (' . implode(',', $ft_types) . ')'; |
1055
|
|
|
|
1056
|
|
|
$n++; |
1057
|
|
|
} |
1058
|
|
|
|
1059
|
|
|
$sqlFilter = |
1060
|
|
|
'SELECT DISTINCT ' . implode(',', $sql_select) . |
1061
|
|
|
' FROM ' . $sql_from . |
1062
|
|
|
' INNER JOIN ' . implode(' INNER JOIN ', $sql_innerjoin) . |
1063
|
|
|
' WHERE ' . implode(' AND ', $sql_where); |
1064
|
|
|
|
1065
|
|
|
sql_drop_temp_table_slave('tmpFTCaches'); |
|
|
|
|
1066
|
|
|
sql_temp_table_slave('tmpFTCaches'); |
|
|
|
|
1067
|
|
|
sql_slave( |
|
|
|
|
1068
|
|
|
"CREATE TEMPORARY TABLE &tmpFTCaches (`cache_id` int (11) PRIMARY KEY) " . $sqlFilter |
1069
|
|
|
); |
1070
|
|
|
|
1071
|
|
|
$sql_select = []; |
1072
|
|
|
$sql_from = ''; |
1073
|
|
|
$sql_innerjoin = []; |
1074
|
|
|
$sql_leftjoin = []; |
1075
|
|
|
$sql_where = []; |
1076
|
|
|
|
1077
|
|
|
$sql_select[] = '`caches`.`cache_id` `cache_id`'; |
1078
|
|
|
$sql_from = '&tmpFTCaches'; |
1079
|
|
|
$sql_innerjoin[] = '`caches` ON `caches`.`cache_id`=&tmpFTCaches.`cache_id`'; |
1080
|
|
|
} elseif ($options['searchtype'] == 'bynofilter') { |
1081
|
|
|
$sql_select[] = '`caches`.`cache_id` `cache_id`'; |
1082
|
|
|
$sql_from = '`caches`'; |
1083
|
|
|
} elseif ($options['searchtype'] == 'bylist') { |
1084
|
|
|
sql_temp_table_slave('result_caches'); |
|
|
|
|
1085
|
|
|
$list = new cachelist($options['listid']); |
1086
|
|
|
if ($list->allowView($options['cachelist_pw'])) { |
1087
|
|
|
$cachesFilter = |
1088
|
|
|
"CREATE TEMPORARY TABLE &result_caches ENGINE=MEMORY |
1089
|
|
|
SELECT `cache_id` |
1090
|
|
|
FROM `cache_list_items` |
1091
|
|
|
LEFT JOIN `cache_lists` ON `cache_lists`.`id`=`cache_list_items`.`cache_list_id` |
1092
|
|
|
WHERE `cache_list_id`='" . sql_escape($options['listid']) . "'"; |
|
|
|
|
1093
|
|
|
sql_slave($cachesFilter); |
|
|
|
|
1094
|
|
|
sql_slave('ALTER TABLE &result_caches ADD PRIMARY KEY (`cache_id`)'); |
|
|
|
|
1095
|
|
|
|
1096
|
|
|
$sql_select[] = '&result_caches.`cache_id`'; |
1097
|
|
|
$sql_from = '&result_caches'; |
1098
|
|
|
$sql_innerjoin[] = '`caches` ON `caches`.`cache_id`=&result_caches.`cache_id`'; |
1099
|
|
|
} else { |
1100
|
|
|
// should not happen, but just for the case ... |
1101
|
|
|
$sql_select[] = '`caches`.`cache_id` `cache_id`'; |
1102
|
|
|
$sql_from = '`caches`'; |
1103
|
|
|
$sql_where[] = 'FALSE'; |
1104
|
|
|
} |
1105
|
|
|
} else { |
1106
|
|
|
if ($options['searchtype'] == 'all') { |
1107
|
|
|
$sql_select[] = '`caches`.`cache_id` `cache_id`'; |
1108
|
|
|
$sql_from = '`caches`'; |
1109
|
|
|
$sql_where[] = 'TRUE'; |
1110
|
|
|
} else { |
1111
|
|
|
$tpl->error($unknown_searchtype); |
1112
|
|
|
} |
1113
|
|
|
} |
1114
|
|
|
|
1115
|
|
|
// additional options |
1116
|
|
|
if (!isset($options['f_userowner'])) { |
1117
|
|
|
$options['f_userowner'] = '0'; |
1118
|
|
|
} |
1119
|
|
|
if ($options['f_userowner'] != 0) { // Ocprop |
1120
|
|
|
$sql_where[] = '`caches`.`user_id`!=\'' . $login->userid . '\''; |
1121
|
|
|
} |
1122
|
|
|
|
1123
|
|
|
if (!isset($options['f_userfound'])) { |
1124
|
|
|
$options['f_userfound'] = '0'; |
1125
|
|
|
} |
1126
|
|
|
if ($options['f_userfound'] != 0) { // Ocprop |
1127
|
|
|
$sql_where[] = |
1128
|
|
|
"`caches`.`cache_id` NOT IN |
1129
|
|
|
(SELECT `cache_logs`.`cache_id` |
1130
|
|
|
FROM `cache_logs` |
1131
|
|
|
WHERE |
1132
|
|
|
`cache_logs`.`user_id`='" . sql_escape($login->userid) . "' |
|
|
|
|
1133
|
|
|
AND `cache_logs`.`type` IN (1, 7))"; |
1134
|
|
|
} |
1135
|
|
|
if (!isset($options['f_unpublished'])) { |
1136
|
|
|
$options['f_unpublished'] = '0'; |
1137
|
|
|
} |
1138
|
|
|
if ($options['f_unpublished'] != 0) { |
1139
|
|
|
$sql_where[] = '`caches`.`status`<>5'; |
1140
|
|
|
} |
1141
|
|
|
if (!isset($options['f_inactive'])) { |
1142
|
|
|
$options['f_inactive'] = '0'; |
1143
|
|
|
} |
1144
|
|
|
if ($options['f_inactive'] != 0) { // Ocprop |
1145
|
|
|
$sql_where[] = '`caches`.`status` NOT IN (3,6,7)'; |
1146
|
|
|
} |
1147
|
|
|
// f_inactive formerly was used for both, archived and disabled caches. |
1148
|
|
|
// After adding the separate f_disabled option, it is used only for archived |
1149
|
|
|
// caches, but keeps its name for compatibility with existing stored or |
1150
|
|
|
// external searches. |
1151
|
|
|
if (!isset($options['f_disabled'])) { |
1152
|
|
|
$options['f_disabled'] = '0'; |
1153
|
|
|
} |
1154
|
|
|
if ($options['f_disabled'] != 0) { |
1155
|
|
|
$sql_where[] = '`caches`.`status`<>2'; |
1156
|
|
|
} |
1157
|
|
|
|
1158
|
|
|
if ($login->logged_in()) { |
1159
|
|
|
if (!isset($options['f_ignored'])) { |
1160
|
|
|
$options['f_ignored'] = '0'; |
1161
|
|
|
} |
1162
|
|
|
if ($options['f_ignored'] != 0) { |
1163
|
|
|
// only use this filter, if it is really needed |
1164
|
|
|
// this enables better caching in map2.php with ignored-filter |
1165
|
|
|
if (sql_value_slave( |
|
|
|
|
1166
|
|
|
"SELECT COUNT(*) FROM `cache_ignore` WHERE `user_id`='" . sql_escape($login->userid) . "'", |
|
|
|
|
1167
|
|
|
0 |
1168
|
|
|
) > 0) { |
1169
|
|
|
$sql_where[] = |
1170
|
|
|
"`caches`.`cache_id` NOT IN |
1171
|
|
|
(SELECT `cache_ignore`.`cache_id` |
1172
|
|
|
FROM `cache_ignore` |
1173
|
|
|
WHERE `cache_ignore`.`user_id`='" . sql_escape($login->userid) . "')"; |
|
|
|
|
1174
|
|
|
} |
1175
|
|
|
} |
1176
|
|
|
} |
1177
|
|
|
if (!isset($options['f_otherPlatforms'])) { |
1178
|
|
|
$options['f_otherPlatforms'] = '0'; |
1179
|
|
|
} |
1180
|
|
|
if ($options['f_otherPlatforms'] != 0) { |
1181
|
|
|
$sql_where[] = "`caches`.`wp_gc_maintained`=''"; |
1182
|
|
|
} |
1183
|
|
|
|
1184
|
|
|
if (!isset($options['f_geokrets'])) { |
1185
|
|
|
$options['f_geokrets'] = '0'; |
1186
|
|
|
} |
1187
|
|
|
if ($options['f_geokrets'] != 0) { |
1188
|
|
|
$sql_where[] = "(SELECT COUNT(*) FROM `gk_item_waypoint` WHERE `wp`=`caches`.`wp_oc`)"; |
1189
|
|
|
} |
1190
|
|
|
|
1191
|
|
|
if (!isset($options['country'])) { |
1192
|
|
|
$options['country'] = ''; |
1193
|
|
|
} |
1194
|
|
|
if ($options['country'] != '') { |
1195
|
|
|
$sql_where[] = '`caches`.`country`=\'' . sql_escape($options['country']) . '\''; |
|
|
|
|
1196
|
|
|
} |
1197
|
|
|
|
1198
|
|
|
if (!isset($options['language'])) { |
1199
|
|
|
$options['language'] = ''; |
1200
|
|
|
} |
1201
|
|
|
if ($options['language'] != '') { |
1202
|
|
|
/* |
1203
|
|
|
$sql_innerjoin[] = '`cache_desc` ON `cache_desc`.`cache_id`=`caches`.`cache_id`'; |
1204
|
|
|
$sql_where[] = '`cache_desc`.`language`=\'' . sql_escape($options['language']) . '\''; |
1205
|
|
|
*/ |
1206
|
|
|
// optimized query: |
1207
|
|
|
$sql_where[] = 'INSTR(`caches`.`desc_languages`,\'' . sql_escape($options['language']) . '\')'; |
|
|
|
|
1208
|
|
|
} |
1209
|
|
|
|
1210
|
|
|
if (!isset($options['adm2'])) { |
1211
|
|
|
$options['adm2'] = ''; |
1212
|
|
|
} |
1213
|
|
View Code Duplication |
if ($options['adm2'] != '') { |
1214
|
|
|
$sql_innerjoin[] = '`cache_location` ON `cache_location`.`cache_id`=`caches`.`cache_id`'; |
1215
|
|
|
$sql_where[] = '`cache_location`.`code2`=\'' . sql_escape($options['adm2']) . '\''; |
|
|
|
|
1216
|
|
|
} |
1217
|
|
|
|
1218
|
|
View Code Duplication |
if ($options['cachetype'] != '') { |
1219
|
|
|
$types = explode(';', $options['cachetype']); |
1220
|
|
|
if (count($types) < sql_value_slave("SELECT COUNT(*) FROM `cache_type`", 0)) { |
|
|
|
|
1221
|
|
|
$countTypes = count($types); |
1222
|
|
|
for ($i = 0; $i < $countTypes; $i++) { |
1223
|
|
|
$types[$i] = "'" . sql_escape($types[$i]) . "'"; |
|
|
|
|
1224
|
|
|
} |
1225
|
|
|
$sql_where[] = '`caches`.`type` IN (' . implode(',', $types) . ')'; |
1226
|
|
|
} |
1227
|
|
|
} |
1228
|
|
|
|
1229
|
|
View Code Duplication |
if ($options['cachesize'] != '') { |
1230
|
|
|
$sizes = explode(';', $options['cachesize']); |
1231
|
|
|
if (count($sizes) < sql_value_slave('SELECT COUNT(*) FROM `cache_size`', 0)) { |
|
|
|
|
1232
|
|
|
$countSizes = count($sizes); |
1233
|
|
|
for ($i = 0; $i < $countSizes; $i++) { |
1234
|
|
|
$sizes[$i] = "'" . sql_escape($sizes[$i]) . "'"; |
|
|
|
|
1235
|
|
|
} |
1236
|
|
|
$sql_where[] = '`caches`.`size` IN (' . implode(',', $sizes) . ')'; |
1237
|
|
|
} |
1238
|
|
|
} |
1239
|
|
|
|
1240
|
|
|
if ($options['difficultymin'] != 0) { |
1241
|
|
|
$sql_where[] = '`caches`.`difficulty`>=\'' . sql_escape($options['difficultymin']) . '\''; |
|
|
|
|
1242
|
|
|
} |
1243
|
|
|
if ($options['difficultymax'] != 0) { |
1244
|
|
|
$sql_where[] = '`caches`.`difficulty`<=\'' . sql_escape($options['difficultymax']) . '\''; |
|
|
|
|
1245
|
|
|
} |
1246
|
|
|
if ($options['terrainmin'] != 0) { |
1247
|
|
|
$sql_where[] = '`caches`.`terrain`>=\'' . sql_escape($options['terrainmin']) . '\''; |
|
|
|
|
1248
|
|
|
} |
1249
|
|
|
if ($options['terrainmax'] != 0) { |
1250
|
|
|
$sql_where[] = '`caches`.`terrain`<=\'' . sql_escape($options['terrainmax']) . '\''; |
|
|
|
|
1251
|
|
|
} |
1252
|
|
View Code Duplication |
if ($options['recommendationmin'] > 0) { |
1253
|
|
|
$sql_innerjoin[] = '`stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`'; |
1254
|
|
|
$sql_where[] = '`stat_caches`.`toprating`>=\'' . sql_escape($options['recommendationmin']) . '\''; |
|
|
|
|
1255
|
|
|
} |
1256
|
|
|
|
1257
|
|
|
if (isset($options['cache_attribs']) && count($options['cache_attribs']) > 0) { |
1258
|
|
|
foreach ($options['cache_attribs'] as $attr) { |
1259
|
|
|
$sql_innerjoin[] = '`caches_attributes` AS `a' . ($attr + 0) . '` ON `a' . |
1260
|
|
|
($attr + 0) . '`.`cache_id`=`caches`.`cache_id`'; |
1261
|
|
|
$sql_where[] = '`a' . ($attr + 0) . '`.`attrib_id`=' . ($attr + 0); |
1262
|
|
|
} |
1263
|
|
|
} |
1264
|
|
|
|
1265
|
|
|
if (isset($options['cache_attribs_not']) && count($options['cache_attribs_not']) > 0) { |
1266
|
|
|
foreach ($options['cache_attribs_not'] as $attr) { |
1267
|
|
|
$sql_where[] = |
1268
|
|
|
"NOT EXISTS |
1269
|
|
|
(SELECT `caches_attributes`.`cache_id` |
1270
|
|
|
FROM `caches_attributes` |
1271
|
|
|
WHERE |
1272
|
|
|
`caches_attributes`.`cache_id`=`caches`.`cache_id` |
1273
|
|
|
AND `caches_attributes`.`attrib_id`='" . sql_escape($attr + 0) . "' |
|
|
|
|
1274
|
|
|
)"; |
1275
|
|
|
} |
1276
|
|
|
} |
1277
|
|
|
|
1278
|
|
|
if (isset($options['bbox']) && ($options['bbox'] !== false)) { |
1279
|
|
|
// bbox=<lon_from>,<lat_from>,<lon_to>,<lat_to> |
1280
|
|
|
$coords = explode(',', $options['bbox']); |
1281
|
|
|
if (count($coords) == 4) { |
1282
|
|
|
$sql_where[] = '`caches`.`longitude`>=' . ($coords[0] + 0) . ' AND `caches`.`latitude`>=' . |
1283
|
|
|
($coords[1] + 0) . ' AND `caches`.`longitude`<=' . ($coords[2] + 0) . |
1284
|
|
|
' AND `caches`.`latitude`<=' . ($coords[3] + 0); |
1285
|
|
|
} |
1286
|
|
|
} |
1287
|
|
|
|
1288
|
|
|
$sql_innerjoin[] = '`cache_status` ON `caches`.`status`=`cache_status`.`id`'; |
1289
|
|
|
if ($login->logged_in()) { |
1290
|
|
|
$sql_where[] = |
1291
|
|
|
'(`cache_status`.`allow_user_view`=1 OR `caches`.`user_id`=' |
1292
|
|
|
. sql_escape($login->userid) |
|
|
|
|
1293
|
|
|
. ' OR (`caches`.`status`<>5 AND ' . ($login->hasAdminPriv(ADMIN_USER) ? '1' : '0') . '))'; |
1294
|
|
|
} else { |
1295
|
|
|
$sql_where[] = '`cache_status`.`allow_user_view`=1'; |
1296
|
|
|
} |
1297
|
|
|
|
1298
|
|
|
//add selected caches to selected cachelist |
1299
|
|
|
if (isset($_REQUEST['addToList']) && isset($_REQUEST['addCache']) && isset($_REQUEST['selectCachelist'])) { |
1300
|
|
|
$list_caches_= $_REQUEST['addToList']; |
1301
|
|
|
$added_waypoints = addToList($list_caches); |
1302
|
|
|
$addCachelist= cachelist::getListById((int) $_REQUEST['selectCachelist']); // null for invalid ID |
1303
|
|
|
} elseif (isset($_REQUEST['addToList'])) { |
1304
|
|
|
$addCachelist= cachelist::getListById((int) $_REQUEST['selectCachelist']); // null for invalid ID |
1305
|
|
|
$error_addCaches = true; |
1306
|
|
|
} |
1307
|
|
|
|
1308
|
|
|
// do the search |
1309
|
|
|
$innerjoin = sizeof($sql_innerjoin) ? ' INNER JOIN ' . implode(' INNER JOIN ', $sql_innerjoin) : ''; |
1310
|
|
|
$leftjoin = sizeof($sql_leftjoin) ? ' LEFT JOIN ' . implode(' LEFT JOIN ', $sql_leftjoin) : ''; |
1311
|
|
|
$group = sizeof($sql_group) ? ' GROUP BY ' . implode(', ', $sql_group) : ''; |
1312
|
|
|
$having = sizeof($sql_having) ? ' HAVING ' . implode(' AND ', $sql_having) : ''; |
1313
|
|
|
|
1314
|
|
|
$sqlFilter = 'SELECT ' . implode(',', $sql_select) . |
1315
|
|
|
' FROM ' . $sql_from . |
1316
|
|
|
$innerjoin . |
1317
|
|
|
$leftjoin . |
1318
|
|
|
' WHERE ' . implode(' AND ', $sql_where) . |
1319
|
|
|
$group . |
1320
|
|
|
$having; |
1321
|
|
|
|
1322
|
|
|
// echo "DEBUG ".$sqlFilter." DEBUG<br>"; |
1323
|
|
|
} else { |
1324
|
|
|
$tpl->error($unknown_searchtype); |
1325
|
|
|
} |
1326
|
|
|
|
1327
|
|
|
//================================================================= |
1328
|
|
|
// X6. load output module and output-dependent options |
1329
|
|
|
//================================================================= |
1330
|
|
|
|
1331
|
|
|
$output_module = mb_strtolower($options['output']); // Ocprop: HTML, gpx |
1332
|
|
|
|
1333
|
|
|
$map2_bounds = ($output_module == 'map2bounds'); |
1334
|
|
|
if ($map2_bounds) { |
1335
|
|
|
$output_module = 'map2'; |
1336
|
|
|
} |
1337
|
|
|
|
1338
|
|
|
if ($map2_bounds && $options['queryid'] == 0) { |
1339
|
|
|
$tpl->error('map2bounds requires queryid'); |
1340
|
|
|
} elseif (!file_exists(__DIR__ . '/lib2/search/search.' . $output_module . '.inc.php')) { |
1341
|
|
|
$tpl->error($outputformat_notexist); |
1342
|
|
|
} |
1343
|
|
|
|
1344
|
|
|
$caches_per_page = 20; |
1345
|
|
|
|
1346
|
|
|
// Default parameters; may be modified by output modules |
1347
|
|
|
$content_type_plain = 'application/octet-stream'; |
1348
|
|
|
$content_type_zipped = 'application/zip'; |
1349
|
|
|
$zip_threshold = $caches_per_page; |
1350
|
|
|
$add_to_zipfile = true; |
1351
|
|
|
$sAddJoin = ''; |
1352
|
|
|
$sAddGroupBy = ''; |
1353
|
|
|
$sAddFields = ''; |
1354
|
|
|
$sAddWhere = ''; |
1355
|
|
|
$sGroupBy = ''; |
1356
|
|
|
|
1357
|
|
|
// disallow mapping other users' logs for data protection reasons |
1358
|
|
|
$enable_mapdisplay = ($options['searchtype'] != 'byfinder') || |
1359
|
|
|
($options['finderid'] == $login->userid); |
1360
|
|
|
|
1361
|
|
|
// *** load output module *** |
1362
|
|
|
// |
1363
|
|
|
// (map2 module will execute and exit; it will use the variables |
1364
|
|
|
// $cachesFilter, $sqlFilter and $map2_bounds and $options['queryid'].) |
1365
|
|
|
|
1366
|
|
|
require __DIR__ . '/lib2/search/search.' . $output_module . '.inc.php'; |
1367
|
|
|
|
1368
|
|
|
if (!isset($search_output_file_download)) { |
1369
|
|
|
die("search_output_file_download flag not set for '$output_module' search"); |
1370
|
|
|
} |
1371
|
|
|
|
1372
|
|
|
//================================================================= |
1373
|
|
|
// X7. complete SQL statement with output-dependend options, |
1374
|
|
|
// sorting and Limits |
1375
|
|
|
//================================================================= |
1376
|
|
|
|
1377
|
|
|
$sql = ''; |
1378
|
|
|
|
1379
|
|
|
// If no distance unit is preselected by distance search, use 'km'. |
1380
|
|
|
// The unit will be shown e.g. in HTML and XML search results. |
1381
|
|
|
if (!isset($distance_unit)) { |
1382
|
|
|
$distance_unit = DEFAULT_DISTANCE_UNIT; |
1383
|
|
|
} |
1384
|
|
|
|
1385
|
|
|
if (isset($lat_rad) && isset($lon_rad)) { |
1386
|
|
|
$sql .= geomath::getSqlDistanceFormula( |
1387
|
|
|
$lon_rad * 180 / 3.14159, |
1388
|
|
|
$lat_rad * 180 / 3.14159, |
1389
|
|
|
0, |
1390
|
|
|
$multiplier[$distance_unit] |
1391
|
|
|
) . ' `distance`, '; |
1392
|
|
|
} else { |
1393
|
|
|
if (!$login->logged_in()) { |
1394
|
|
|
$sql .= 'NULL distance, '; |
1395
|
|
|
} else { |
1396
|
|
|
// get the user's home coords |
1397
|
|
|
$rs_coords = sql_slave( |
|
|
|
|
1398
|
|
|
"SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`='&1'", |
1399
|
|
|
$login->userid |
1400
|
|
|
); |
1401
|
|
|
$record_coords = sql_fetch_array($rs_coords); |
|
|
|
|
1402
|
|
|
|
1403
|
|
|
if ($record_coords['latitude'] == 0 && $record_coords['longitude'] == 0) { |
1404
|
|
|
$sql .= 'NULL distance, '; |
1405
|
|
|
} else { |
1406
|
|
|
$lon_rad = $record_coords['longitude'] * 3.14159 / 180; |
1407
|
|
|
$lat_rad = $record_coords['latitude'] * 3.14159 / 180; |
1408
|
|
|
|
1409
|
|
|
$sql .= geomath::getSqlDistanceFormula( |
1410
|
|
|
$record_coords['longitude'], |
1411
|
|
|
$record_coords['latitude'], |
1412
|
|
|
0, |
1413
|
|
|
$multiplier[$distance_unit] |
1414
|
|
|
) . ' `distance`, '; |
1415
|
|
|
} |
1416
|
|
|
sql_free_result($rs_coords); |
|
|
|
|
1417
|
|
|
} |
1418
|
|
|
} |
1419
|
|
|
|
1420
|
|
|
if ($options['sort'] == 'bylastlog' || $options['sort'] == 'bymylastlog') { |
1421
|
|
|
$sAddFields .= ', MAX(`cache_logs`.`date`) AS `lastLog`'; |
1422
|
|
|
$sAddJoin .= ' LEFT JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`'; |
1423
|
|
|
if ($options['sort'] == 'bymylastlog') { |
1424
|
|
|
$sAddJoin .= ' AND `cache_logs`.`user_id`=' . sql_escape($login->userid); |
|
|
|
|
1425
|
|
|
} |
1426
|
|
|
$sGroupBy .= ' GROUP BY `caches`.`cache_id`'; |
1427
|
|
|
} |
1428
|
|
|
|
1429
|
|
|
$sql .= '`caches`.`cache_id`, |
1430
|
|
|
`caches`.`status`, |
1431
|
|
|
`caches`.`type`, |
1432
|
|
|
`caches`.`size`, |
1433
|
|
|
`caches`.`longitude`, `caches`.`latitude`, |
1434
|
|
|
`caches`.`user_id`, |
1435
|
|
|
IFNULL(`stat_caches`.`toprating`, 0) `ratingvalue`' . |
1436
|
|
|
$sAddFields |
1437
|
|
|
. ' FROM `caches` |
1438
|
|
|
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`' . |
1439
|
|
|
$sAddJoin |
1440
|
|
|
. ' WHERE `caches`.`cache_id` IN (' . $sqlFilter . ')' . |
1441
|
|
|
$sAddWhere . ' ' . |
1442
|
|
|
$sGroupBy; |
1443
|
|
|
$sortby = $options['sort']; |
1444
|
|
|
|
1445
|
|
|
$sql .= ' ORDER BY '; |
1446
|
|
|
if ($options['orderRatingFirst']) { |
1447
|
|
|
$sql .= '`ratingvalue` DESC, '; |
1448
|
|
|
} |
1449
|
|
|
|
1450
|
|
|
if ($sortby == 'bylastlog' || $options['sort'] == 'bymylastlog') { |
1451
|
|
|
$sql .= '`lastLog`'; |
1452
|
|
View Code Duplication |
if (isset($options['sortorder']) && $options['sortorder'] == 'asc') { |
1453
|
|
|
$sql .= ' ASC, `caches`.`date_created` DESC,'; |
1454
|
|
|
} else { |
1455
|
|
|
$sql .= ' DESC, `caches`.`date_created` DESC,'; |
1456
|
|
|
} |
1457
|
|
|
$sortby = 'bydistance'; |
1458
|
|
|
} |
1459
|
|
|
|
1460
|
|
|
if (isset($lat_rad) && isset($lon_rad) && $sortby == 'bydistance') { |
1461
|
|
|
$sql .= '`distance`'; |
1462
|
|
View Code Duplication |
if (isset($options['sortorder']) && $options['sortorder'] == 'desc') { |
1463
|
|
|
$sql .= ' DESC'; |
1464
|
|
|
} else { |
1465
|
|
|
$sql .= ' ASC'; |
1466
|
|
|
} |
1467
|
|
|
} else { |
1468
|
|
|
if ($sortby == 'bycreated') { |
1469
|
|
|
$sql .= '`caches`.`date_created`'; |
1470
|
|
View Code Duplication |
if (isset($options['sortorder']) && $options['sortorder'] == 'asc') { |
1471
|
|
|
$sql .= ' ASC'; |
1472
|
|
|
} else { |
1473
|
|
|
$sql .= ' DESC'; |
1474
|
|
|
} |
1475
|
|
View Code Duplication |
} else { // by name |
1476
|
|
|
$sql .= '`caches`.`name`'; |
1477
|
|
|
if (isset($options['sortorder']) && $options['sortorder'] == 'desc') { |
1478
|
|
|
$sql .= ' DESC'; |
1479
|
|
|
} else { |
1480
|
|
|
$sql .= ' ASC'; |
1481
|
|
|
} |
1482
|
|
|
} |
1483
|
|
|
} |
1484
|
|
|
|
1485
|
|
|
// range of output |
1486
|
|
|
$startat = isset($_REQUEST['startat']) ? floor($_REQUEST['startat'] + 0) : 0; |
1487
|
|
|
if (!is_numeric($startat)) { |
1488
|
|
|
$startat = 0; |
1489
|
|
|
} |
1490
|
|
|
|
1491
|
|
|
$count = $caches_per_page; |
1492
|
|
|
if (isset($_REQUEST['count'])) { // Ocprop |
1493
|
|
|
$count = floor($_REQUEST['count'] + 0); |
1494
|
|
|
} |
1495
|
|
|
if ($count == 'max') { |
1496
|
|
|
$count = 500; |
1497
|
|
|
} |
1498
|
|
|
if ($count < 1) { |
1499
|
|
|
$count = 1; |
1500
|
|
|
} |
1501
|
|
|
if ($count > 500) { |
1502
|
|
|
$count = 500; |
1503
|
|
|
} |
1504
|
|
|
|
1505
|
|
|
$sqlLimit = ' LIMIT ' . $startat . ', ' . $count; |
1506
|
|
|
|
1507
|
|
|
if ($search_output_file_download) { |
1508
|
|
|
//=================================================================== |
1509
|
|
|
// X8a. run query and output for file downloads (GPX, KML, OVL ...) |
1510
|
|
|
//=================================================================== |
1511
|
|
|
|
1512
|
|
|
sql_drop_temp_table_slave('searchtmp'); |
|
|
|
|
1513
|
|
|
// for the case something went wrong and it was not propery cleaned up |
1514
|
|
|
|
1515
|
|
|
sql_temp_table_slave('searchtmp'); |
|
|
|
|
1516
|
|
|
sql_slave("CREATE TEMPORARY TABLE &searchtmp SELECT " . $sql . $sqlLimit); |
|
|
|
|
1517
|
|
|
|
1518
|
|
|
$count = sql_value_slave("SELECT COUNT(*) FROM &searchtmp", 0); |
|
|
|
|
1519
|
|
|
if ($count == 1) { |
1520
|
|
|
$sFilebasename = sql_value_slave( |
|
|
|
|
1521
|
|
|
"SELECT `caches`.`wp_oc` |
1522
|
|
|
FROM &searchtmp, `caches` |
1523
|
|
|
WHERE &searchtmp.`cache_id`=`caches`.`cache_id` |
1524
|
|
|
LIMIT 1", |
1525
|
|
|
'?' |
1526
|
|
|
); |
1527
|
|
|
} else { |
1528
|
|
|
$sFilebasename = 'ocde' . $options['queryid']; |
1529
|
|
|
} |
1530
|
|
|
|
1531
|
|
|
$bUseZip = ($count > $zip_threshold) || |
1532
|
|
|
(isset($_REQUEST['zip']) && ($_REQUEST['zip'] == '1')); |
1533
|
|
|
if ($bUseZip) { |
1534
|
|
|
$phpzip = new ss_zip('', 6); |
1535
|
|
|
} |
1536
|
|
|
|
1537
|
|
|
if (!$db['debug']) { |
1538
|
|
|
if ($bUseZip) { |
1539
|
|
|
header('Content-type: ' . $content_type_zipped); |
1540
|
|
|
header('Content-disposition: attachment; filename="' . $sFilebasename . '.zip"'); |
|
|
|
|
1541
|
|
|
} else { |
1542
|
|
|
header('Content-type: ' . $content_type_plain); |
1543
|
|
|
header('Content-disposition: attachment; filename="' . $sFilebasename . '.' . $output_module . '"'); |
|
|
|
|
1544
|
|
|
} |
1545
|
|
|
} |
1546
|
|
|
|
1547
|
|
|
// helper function for output modules |
1548
|
|
|
|
1549
|
|
|
/** |
1550
|
|
|
* @param string $str |
1551
|
|
|
*/ |
1552
|
|
|
function append_output($str) |
1553
|
|
|
{ |
1554
|
|
|
global $db, $content, $bUseZip; |
1555
|
|
|
|
1556
|
|
|
if (!$db['debug']) { |
1557
|
|
|
if ($bUseZip) { |
1558
|
|
|
$content .= $str; |
1559
|
|
|
} else { |
1560
|
|
|
echo $str; |
1561
|
|
|
} |
1562
|
|
|
} |
1563
|
|
|
} |
1564
|
|
|
|
1565
|
|
|
// *** run output module *** |
1566
|
|
|
// |
1567
|
|
|
// Modules will use these variables from search.php: |
1568
|
|
|
// |
1569
|
|
|
// $phpzip |
1570
|
|
|
// $bUseZip |
1571
|
|
|
|
1572
|
|
|
$content = ''; |
1573
|
|
|
search_output(); |
1574
|
|
|
|
1575
|
|
|
sql_drop_temp_table_slave('searchtmp'); |
|
|
|
|
1576
|
|
|
|
1577
|
|
|
// output zip file |
1578
|
|
|
if ($bUseZip && !$db['debug']) { |
1579
|
|
|
if ($add_to_zipfile) { |
1580
|
|
|
$phpzip->add_data($sFilebasename . '.' . $output_module, $content); |
1581
|
|
|
} |
1582
|
|
|
echo $phpzip->save($sFilebasename . '.zip', 'r'); |
1583
|
|
|
} |
1584
|
|
|
} else { |
1585
|
|
|
//=================================================================== |
1586
|
|
|
// X8b. run other output module (XML, HTML) |
1587
|
|
|
// |
1588
|
|
|
// The following variables from search.php are used by output modules: |
1589
|
|
|
// |
1590
|
|
|
// $called_by_search |
1591
|
|
|
// $called_by_profile_query |
1592
|
|
|
// $distance_unit |
1593
|
|
|
// $lat_rad, $lon_rad |
1594
|
|
|
// $startat |
1595
|
|
|
// $count |
1596
|
|
|
// $caches_per_page |
1597
|
|
|
// $sql |
1598
|
|
|
// $sqlLimit |
1599
|
|
|
// $options['sort'] |
1600
|
|
|
// $options['sortorder'] |
1601
|
|
|
// $options['creationdate'] |
1602
|
|
|
// $options['queryid'] |
1603
|
|
|
// $options['query_name'] |
1604
|
|
|
// $enable_mapdisplay |
1605
|
|
|
// $invalid_waypoints |
1606
|
|
|
//================================================================= |
1607
|
|
|
|
1608
|
|
|
search_output(); |
1609
|
|
|
} |
1610
|
|
|
|
1611
|
|
|
if ($db['debug']) { |
1612
|
|
|
$tpl->display(); |
1613
|
|
|
} else { |
1614
|
|
|
exit; |
1615
|
|
|
} |
1616
|
|
|
} else { // $options['showresult'] == 0 |
1617
|
|
|
//============================================================= |
1618
|
|
|
// F5. present search options form to the user |
1619
|
|
|
//============================================================= |
1620
|
|
|
|
1621
|
|
|
if ($options['expert'] == 1) { |
1622
|
|
|
// "expert mode" - what is this? |
1623
|
|
|
$tpl->assign('formmethod', 'post'); |
1624
|
|
|
$tpl->display(); |
1625
|
|
|
} else { |
1626
|
|
|
outputSearchForm($options); |
1627
|
|
|
} |
1628
|
|
|
} |
1629
|
|
|
|
1630
|
|
|
|
1631
|
|
|
//============================================================= |
1632
|
|
|
// F6. build and output search options form |
1633
|
|
|
//============================================================= |
1634
|
|
|
|
1635
|
|
|
function sqlStringbySearchradius($distance, $lat, $lon, $multiplier, $distance_unit) |
1636
|
|
|
{ |
1637
|
|
|
global $sql_select, $sql_from, $sql_innerjoin; |
1638
|
|
|
|
1639
|
|
|
//all target caches are between lat - max_lat_diff and lat + max_lat_diff |
1640
|
|
|
$max_lat_diff = $distance / (111.12 * $multiplier[$distance_unit]); |
1641
|
|
|
|
1642
|
|
|
//all target caches are between lon - max_lon_diff and lon + max_lon_diff |
1643
|
|
|
//TODO: check!!! |
1644
|
|
|
$max_lon_diff = |
1645
|
|
|
$distance * 180 |
1646
|
|
|
/ (abs(sin((90 - $lat) * 3.14159 / 180)) * 6378 * $multiplier[$distance_unit] * 3.14159); |
1647
|
|
|
|
1648
|
|
|
$lon_rad = $lon * 3.14159 / 180; |
|
|
|
|
1649
|
|
|
$lat_rad = $lat * 3.14159 / 180; |
|
|
|
|
1650
|
|
|
|
1651
|
|
|
sql_temp_table_slave('result_caches'); |
|
|
|
|
1652
|
|
|
$cachesFilter = |
1653
|
|
|
"CREATE TEMPORARY TABLE &result_caches ENGINE=MEMORY |
1654
|
|
|
SELECT |
1655
|
|
|
(" . geomath::getSqlDistanceFormula($lon, $lat, $distance, $multiplier[$distance_unit]) . ") `distance`, |
1656
|
|
|
`caches`.`cache_id` `cache_id` |
1657
|
|
|
FROM `caches` FORCE INDEX (`latitude`) |
1658
|
|
|
WHERE |
1659
|
|
|
`longitude` > " . ($lon - $max_lon_diff) . " |
1660
|
|
|
AND `longitude` < " . ($lon + $max_lon_diff) . " |
1661
|
|
|
AND `latitude` > " . ($lat - $max_lat_diff) . " |
1662
|
|
|
AND `latitude` < " . ($lat + $max_lat_diff) . " |
1663
|
|
|
HAVING `distance` < " . ($distance + 0); |
1664
|
|
|
sql_slave($cachesFilter); |
|
|
|
|
1665
|
|
|
sql_slave("ALTER TABLE &result_caches ADD PRIMARY KEY ( `cache_id` )"); |
|
|
|
|
1666
|
|
|
|
1667
|
|
|
$sql_select[] = '&result_caches.`cache_id`'; |
1668
|
|
|
$sql_from = '&result_caches'; |
1669
|
|
|
$sql_innerjoin[] = '`caches` ON `caches`.`cache_id`=&result_caches.`cache_id`'; |
1670
|
|
|
} |
1671
|
|
|
|
1672
|
|
|
function outputSearchForm($options) |
1673
|
|
|
{ |
1674
|
|
|
global $tpl, $login, $opt; |
1675
|
|
|
global $error_ort, $error_plz, $error_locidnocoords, $error_nowaypointfound; |
1676
|
|
|
global $error_nocoords, $error_nofulltext, $error_fulltexttoolong; |
1677
|
|
|
global $cache_attrib_jsarray_line, $cache_attrib_group, $cache_attrib_img_line1, $cache_attrib_img_line2; |
1678
|
|
|
global $load_query, $show_lastsearchbutton; |
1679
|
|
|
|
1680
|
|
|
$tpl->assign('formmethod', 'get'); |
1681
|
|
|
|
1682
|
|
|
$tpl->assign('logged_in', $login->logged_in()); |
1683
|
|
|
$tpl->assign('load_query', $load_query == false); |
1684
|
|
|
$tpl->assign('show_lastsearchbutton', $show_lastsearchbutton == true); |
1685
|
|
|
|
1686
|
|
|
//sort search by (radio button + 1 checkbox) |
1687
|
|
|
|
1688
|
|
|
if (isset($options['sort'])) { |
1689
|
|
|
$bBynameChecked = ($options['sort'] == 'byname'); |
1690
|
|
|
} else { // Ocprop |
1691
|
|
|
$bBynameChecked = (!$login->logged_in()); |
1692
|
|
|
} |
1693
|
|
|
$tpl->assign('byname_checked', $bBynameChecked); |
1694
|
|
|
|
1695
|
|
|
if (isset($options['sort'])) { |
1696
|
|
|
$bBydistanceChecked = ($options['sort'] == 'bydistance'); |
1697
|
|
|
} else { |
1698
|
|
|
$bBydistanceChecked = ($login->logged_in()); |
1699
|
|
|
} |
1700
|
|
|
$tpl->assign('bydistance_checked', $bBydistanceChecked); |
1701
|
|
|
|
1702
|
|
|
if (isset($options['sort'])) { |
1703
|
|
|
$bBycreatedChecked = ($options['sort'] == 'bycreated'); |
1704
|
|
|
} else { |
1705
|
|
|
$bBycreatedChecked = (!$login->logged_in()); |
1706
|
|
|
} |
1707
|
|
|
$tpl->assign('bycreated_checked', $bBycreatedChecked); |
1708
|
|
|
|
1709
|
|
|
if (isset($options['sort'])) { |
1710
|
|
|
$bBylastlogChecked = ($options['sort'] == 'bylastlog'); |
1711
|
|
|
} else { |
1712
|
|
|
$bBylastlogChecked = ($login->logged_in()); |
1713
|
|
|
} |
1714
|
|
|
$tpl->assign('bylastlog_checked', $bBylastlogChecked); |
1715
|
|
|
|
1716
|
|
|
if (isset($options['sort'])) { |
1717
|
|
|
$bBymylastlogChecked = ($options['sort'] == 'bymylastlog'); |
1718
|
|
|
} else { |
1719
|
|
|
$bBymylastlogChecked = ($login->logged_in()); |
1720
|
|
|
} |
1721
|
|
|
$tpl->assign('bymylastlog_checked', $bBymylastlogChecked); |
1722
|
|
|
|
1723
|
|
|
$tpl->assign('hidopt_sort', $options['sort']); |
1724
|
|
|
|
1725
|
|
|
$tpl->assign('orderRatingFirst_checked', $options['orderRatingFirst']); |
1726
|
|
|
$tpl->assign('hidopt_orderRatingFirst', $options['orderRatingFirst'] ? '1' : '0'); |
1727
|
|
|
|
1728
|
|
|
//hide caches... (checkboxes) |
1729
|
|
|
|
1730
|
|
|
$tpl->assign('f_userowner_checked', $login->logged_in() && ($options['f_userowner'] == 1)); |
1731
|
|
|
$tpl->assign('hidopt_userowner', ($options['f_userowner'] == 1) ? '1' : '0'); |
1732
|
|
|
|
1733
|
|
|
$tpl->assign('f_userfound_checked', $login->logged_in() && ($options['f_userfound'] == 1)); |
1734
|
|
|
$tpl->assign('hidopt_userfound', ($options['f_userfound'] == 1) ? '1' : '0'); |
1735
|
|
|
|
1736
|
|
|
$tpl->assign('f_ignored_checked', $login->logged_in() && ($options['f_ignored'] == 1)); |
1737
|
|
|
$tpl->assign('hidopt_ignored', ($options['f_ignored'] == 1) ? '1' : '0'); |
1738
|
|
|
|
1739
|
|
|
$tpl->assign('f_disabled_checked', $options['f_disabled'] == 1); |
1740
|
|
|
$tpl->assign('hidopt_disabled', ($options['f_disabled'] == 1) ? '1' : '0'); |
1741
|
|
|
|
1742
|
|
|
// archived is called "disabled" here for backward compatibility |
1743
|
|
|
$tpl->assign('f_inactive_checked', $options['f_inactive'] == 1); |
1744
|
|
|
$tpl->assign('hidopt_inactive', ($options['f_inactive'] == 1) ? '1' : '0'); |
1745
|
|
|
|
1746
|
|
|
$tpl->assign('f_otherPlatforms_checked', $options['f_otherPlatforms'] == 1); |
1747
|
|
|
$tpl->assign('hidopt_otherPlatforms', ($options['f_otherPlatforms'] == 1) ? '1' : '0'); |
1748
|
|
|
|
1749
|
|
|
$tpl->assign('f_geokrets_checked', $options['f_geokrets'] == 1); |
1750
|
|
|
$tpl->assign('hidopt_geokrets', ($options['f_geokrets'] == 1) ? '1' : '0'); |
1751
|
|
|
|
1752
|
|
|
if (!isset($options['country'])) { |
1753
|
|
|
$options['country'] = ''; |
1754
|
|
|
} |
1755
|
|
|
$tpl->assign('country', htmlspecialchars($options['country'], ENT_COMPAT, 'UTF-8')); |
1756
|
|
|
|
1757
|
|
|
if (!isset($options['language'])) { |
1758
|
|
|
$options['language'] = ''; |
1759
|
|
|
} |
1760
|
|
|
$tpl->assign('language', htmlspecialchars($options['language'], ENT_COMPAT, 'UTF-8')); |
1761
|
|
|
|
1762
|
|
|
if (isset($options['cachetype'])) { |
1763
|
|
|
$tpl->assign('cachetype', htmlspecialchars($options['cachetype'], ENT_COMPAT, 'UTF-8')); |
1764
|
|
|
} else { |
1765
|
|
|
$tpl->assign('cachetype', ''); |
1766
|
|
|
} |
1767
|
|
|
|
1768
|
|
|
// cachename |
1769
|
|
|
$tpl->assign( |
1770
|
|
|
'cachename', |
1771
|
|
|
isset($options['cachename']) ? htmlspecialchars($options['cachename'], ENT_COMPAT, 'UTF-8') : '' |
1772
|
|
|
); |
1773
|
|
|
$tpl->assign('searchtype_byname', $options['searchtype'] == 'byname'); |
1774
|
|
|
|
1775
|
|
|
// distance |
1776
|
|
|
$tpl->assign('distance', isset($options['distance']) ? $options['distance'] : DEFAULT_SEARCH_DISTANCE); |
1777
|
|
|
|
1778
|
|
|
if (!isset($options['unit'])) { |
1779
|
|
|
$options['unit'] = DEFAULT_DISTANCE_UNIT; |
1780
|
|
|
} |
1781
|
|
|
$tpl->assign('sel_km', $options['unit'] == 'km'); |
1782
|
|
|
$tpl->assign('sel_sm', $options['unit'] == 'sm'); |
1783
|
|
|
$tpl->assign('sel_nm', $options['unit'] == 'nm'); |
1784
|
|
|
|
1785
|
|
|
// ... from ortplz |
1786
|
|
|
if (isset($options['ortplz'])) { |
1787
|
|
|
$ortplz = htmlspecialchars($options['ortplz'], ENT_COMPAT, 'UTF-8'); |
1788
|
|
|
} elseif (isset($options['ort'])) { |
1789
|
|
|
$ortplz = htmlspecialchars($options['ort'], ENT_COMPAT, 'UTF-8'); |
1790
|
|
|
} elseif (isset($options['plz'])) { |
1791
|
|
|
$ortplz = htmlspecialchars($options['plz'], ENT_COMPAT, 'UTF-8'); |
1792
|
|
|
} else { |
1793
|
|
|
$ortplz = ''; |
1794
|
|
|
} |
1795
|
|
|
$tpl->assign('ortplz', $ortplz); |
1796
|
|
|
|
1797
|
|
|
// ... from waypoint |
1798
|
|
|
$tpl->assign( |
1799
|
|
|
'waypoint', |
1800
|
|
|
isset($options['waypoint']) ? htmlspecialchars($options['waypoint'], ENT_COMPAT, 'UTF-8') : '' |
1801
|
|
|
); |
1802
|
|
|
|
1803
|
|
|
// ... from coords |
1804
|
|
|
if (!isset($options['lat_h'])) { |
1805
|
|
|
if ($login->logged_in()) { |
1806
|
|
|
$rs = sql( |
|
|
|
|
1807
|
|
|
"SELECT `latitude`, `longitude` |
1808
|
|
|
FROM `user` |
1809
|
|
|
WHERE `user_id`='" . sql_escape($login->userid) . "'" |
|
|
|
|
1810
|
|
|
); |
1811
|
|
|
$record = sql_fetch_array($rs); |
|
|
|
|
1812
|
|
|
$lon = $record['longitude']; |
1813
|
|
|
$lat = $record['latitude']; |
1814
|
|
|
sql_free_result($rs); |
|
|
|
|
1815
|
|
|
|
1816
|
|
|
$tpl->assign('lonE_sel', $lon >= 0); |
1817
|
|
|
$tpl->assign('lonW_sel', $lon < 0); |
1818
|
|
|
$tpl->assign('latN_sel', $lat >= 0); |
1819
|
|
|
$tpl->assign('latS_sel', $lat < 0); |
1820
|
|
|
|
1821
|
|
|
$lon_h = floor($lon); |
1822
|
|
|
$lat_h = floor($lat); |
1823
|
|
|
|
1824
|
|
|
$lon_min = ($lon - $lon_h) * 60; |
1825
|
|
|
$lat_min = ($lat - $lat_h) * 60; |
1826
|
|
|
|
1827
|
|
|
if ($lat < 0 && $lat_h < 0) { |
1828
|
|
|
$lat_min = 60 - $lat_min; |
1829
|
|
|
} |
1830
|
|
|
if ($lon < 0 && $lon_h < 0) { |
1831
|
|
|
$lon_min = 60 - $lon_min; |
1832
|
|
|
} |
1833
|
|
|
|
1834
|
|
|
$tpl->assign('lat_min', sprintf('%02.3f', $lat_min)); |
1835
|
|
|
$tpl->assign('lon_min', sprintf('%02.3f', $lon_min)); |
1836
|
|
|
|
1837
|
|
|
if ($lat < 0 && $lat_h < 0) { |
1838
|
|
|
$lat_h = - $lat_h; |
1839
|
|
|
if ($lat_min != 0) { |
1840
|
|
|
$lat_h = $lat_h - 1; |
1841
|
|
|
} |
1842
|
|
|
} |
1843
|
|
|
if ($lon < 0 && $lon_h < 0) { |
1844
|
|
|
$lon_h = - $lon_h; |
1845
|
|
|
if ($lon_min != 0) { |
1846
|
|
|
$lon_h = $lon_h - 1; |
1847
|
|
|
} |
1848
|
|
|
} |
1849
|
|
|
$tpl->assign('lat_h', $lat_h); |
1850
|
|
|
$tpl->assign('lon_h', $lon_h); |
1851
|
|
|
} else { |
1852
|
|
|
$tpl->assign('lat_h', '00'); |
1853
|
|
|
$tpl->assign('lon_h', '000'); |
1854
|
|
|
$tpl->assign('lat_min', '00.000'); |
1855
|
|
|
$tpl->assign('lon_min', '00.000'); |
1856
|
|
|
} |
1857
|
|
|
} else { |
1858
|
|
|
$tpl->assign('lat_h', isset($options['lat_h']) ? $options['lat_h'] : '00'); |
1859
|
|
|
$tpl->assign('lon_h', isset($options['lon_h']) ? $options['lon_h'] : '000'); |
1860
|
|
|
$tpl->assign('lat_min', isset($options['lat_min']) ? $options['lat_min'] : '00.000'); |
1861
|
|
|
$tpl->assign('lon_min', isset($options['lon_min']) ? $options['lon_min'] : '00.000'); |
1862
|
|
|
|
1863
|
|
|
if ($options['lonEW'] == 'W') { |
1864
|
|
|
$tpl->assign('lonE_sel', ''); |
1865
|
|
|
$tpl->assign('lonW_sel', 'selected="selected"'); |
1866
|
|
|
} else { |
1867
|
|
|
$tpl->assign('lonE_sel', 'selected="selected"'); |
1868
|
|
|
$tpl->assign('lonW_sel', ''); |
1869
|
|
|
} |
1870
|
|
|
|
1871
|
|
|
if ($options['latNS'] == 'S') { |
1872
|
|
|
$tpl->assign('latS_sel', 'selected="selected"'); |
1873
|
|
|
$tpl->assign('latN_sel', ''); |
1874
|
|
|
} else { |
1875
|
|
|
$tpl->assign('latS_sel', ''); |
1876
|
|
|
$tpl->assign('latN_sel', 'selected="selected"'); |
1877
|
|
|
} |
1878
|
|
|
} |
1879
|
|
|
|
1880
|
|
|
$dfromortplz_checked = in_array($options['searchtype'], ['byplz', 'byort']); |
1881
|
|
|
$dfromwaypoint_checked = ($options['searchtype'] == 'bywaypoint'); |
1882
|
|
|
$dfromcoords_checked = ($options['searchtype'] == 'bycoords'); |
1883
|
|
|
if (!$dfromortplz_checked && !$dfromwaypoint_checked && !$dfromcoords_checked) { |
1884
|
|
|
$dfromcoords_checked = true; // default |
1885
|
|
|
} |
1886
|
|
|
$tpl->assign('dfromortplz_checked', $dfromortplz_checked); |
1887
|
|
|
$tpl->assign('dfromwaypoint_checked', $dfromwaypoint_checked); |
1888
|
|
|
$tpl->assign('dfromcoords_checked', $dfromcoords_checked); |
1889
|
|
|
|
1890
|
|
|
$tpl->assign('searchtype_byortplz', in_array($options['searchtype'], ['byplz', 'byort'])); |
1891
|
|
|
$tpl->assign('searchtype_bywaypoint', $options['searchtype'] == 'bywaypoint'); |
1892
|
|
|
$tpl->assign('searchtype_bycoords', $options['searchtype'] == 'bycoords'); |
1893
|
|
|
|
1894
|
|
|
// owner |
1895
|
|
|
$tpl->assign('owner', isset($options['owner']) ? htmlspecialchars($options['owner'], ENT_COMPAT, 'UTF-8') : ''); |
1896
|
|
|
$tpl->assign('searchtype_byowner', $options['searchtype'] == 'byowner'); |
1897
|
|
|
|
1898
|
|
|
// finder |
1899
|
|
|
$tpl->assign('finder', isset($options['finder']) ? htmlspecialchars($options['finder'], ENT_COMPAT, 'UTF-8') : ''); |
1900
|
|
|
$tpl->assign('searchtype_byfinder', $options['searchtype'] == 'byfinder'); |
1901
|
|
|
|
1902
|
|
|
// country options |
1903
|
|
|
$rs = sql( |
|
|
|
|
1904
|
|
|
"SELECT IFNULL(`sys_trans_text`.`text`, `countries`.`name`) AS `name`, |
1905
|
|
|
`countries`.`short`, |
1906
|
|
|
`countries`.`short`='&2' AS `selected` |
1907
|
|
|
FROM `countries` |
1908
|
|
|
LEFT JOIN `sys_trans` |
1909
|
|
|
ON `countries`.`trans_id`=`sys_trans`.`id` |
1910
|
|
|
AND `sys_trans`.`text`=`countries`.`name` |
1911
|
|
|
LEFT JOIN `sys_trans_text` |
1912
|
|
|
ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` |
1913
|
|
|
AND `sys_trans_text`.`lang`='&1' |
1914
|
|
|
WHERE `countries`.`short` IN (SELECT DISTINCT `country` FROM `caches`) |
1915
|
|
|
ORDER BY `name` ASC", |
1916
|
|
|
$opt['template']['locale'], |
1917
|
|
|
$options['country'] |
1918
|
|
|
); |
1919
|
|
|
$tpl->assign_rs('countryoptions', $rs); |
1920
|
|
|
sql_free_result($rs); |
|
|
|
|
1921
|
|
|
$tpl->assign('all_countries', $options['country'] == ''); |
1922
|
|
|
|
1923
|
|
|
// language options |
1924
|
|
|
$rs = sql( |
|
|
|
|
1925
|
|
|
"SELECT IFNULL(`sys_trans_text`.`text`,`languages`.`name`) AS `name`, |
1926
|
|
|
`short`, |
1927
|
|
|
`short`='&2' AS `selected` |
1928
|
|
|
FROM `languages` |
1929
|
|
|
LEFT JOIN `sys_trans` |
1930
|
|
|
ON `sys_trans`.`text`=`languages`.`name` |
1931
|
|
|
LEFT JOIN `sys_trans_text` |
1932
|
|
|
ON `sys_trans_text`.`trans_id`=`sys_trans`.`id` |
1933
|
|
|
AND `sys_trans_text`.`lang`='&1' |
1934
|
|
|
ORDER BY `name`", |
1935
|
|
|
$opt['template']['locale'], |
1936
|
|
|
$options['language'] |
1937
|
|
|
); |
1938
|
|
|
$tpl->assign_rs('languageoptions', $rs); |
1939
|
|
|
sql_free_result($rs); |
|
|
|
|
1940
|
|
|
$tpl->assign('all_languages', $options['language'] == ''); |
1941
|
|
|
|
1942
|
|
|
$rs = sql('SELECT `id` FROM `cache_type` ORDER BY `ordinal`'); |
|
|
|
|
1943
|
|
|
$rCachetypes = sql_fetch_assoc_table($rs); |
|
|
|
|
1944
|
|
|
foreach ($rCachetypes as &$rCachetype) { |
1945
|
|
|
$rCachetype['checked'] = |
1946
|
|
|
($options['cachetype'] == '') |
1947
|
|
|
|| (strpos( |
1948
|
|
|
';' . $options['cachetype'] . ';', |
1949
|
|
|
';' . $rCachetype['id'] . ';' |
1950
|
|
|
) !== false); |
1951
|
|
|
$rCachetype['unchecked'] = !$rCachetype['checked']; |
1952
|
|
|
} |
1953
|
|
|
$tpl->assign('cachetypes', $rCachetypes); |
1954
|
|
|
$tpl->assign('cachetype', $options['cachetype']); |
1955
|
|
|
|
1956
|
|
|
$cachesizes = []; |
1957
|
|
|
$rs = sql("SELECT `id` FROM `cache_size`"); |
|
|
|
|
1958
|
|
|
while ($r = sql_fetch_assoc($rs)) { |
|
|
|
|
1959
|
|
|
$cachesizes[$r['id']]['checked'] = |
1960
|
|
|
(strpos( |
1961
|
|
|
';' . $options['cachesize'] . ';', |
1962
|
|
|
';' . $r['id'] . ';' |
1963
|
|
|
) !== false) |
1964
|
|
|
|| ($options['cachesize'] == ''); |
1965
|
|
|
} |
1966
|
|
|
sql_free_result($rs); |
|
|
|
|
1967
|
|
|
$tpl->assign('cachesizes', $cachesizes); |
1968
|
|
|
$tpl->assign('cachesize', $options['cachesize']); |
1969
|
|
|
|
1970
|
|
|
// difficulty + terrain |
1971
|
|
|
$tpl->assign('difficultymin', $options['difficultymin']); |
1972
|
|
|
$tpl->assign('difficultymax', $options['difficultymax']); |
1973
|
|
|
$tpl->assign('difficulty_options', [0, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
1974
|
|
|
$tpl->assign('terrainmin', $options['terrainmin']); |
1975
|
|
|
$tpl->assign('terrainmax', $options['terrainmax']); |
1976
|
|
|
$tpl->assign('terrain_options', [0, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
1977
|
|
|
|
1978
|
|
|
$logtypes = []; |
1979
|
|
|
if (isset($options['logtype'])) { |
1980
|
|
|
$logtypes = explode(',', $options['logtype']); |
1981
|
|
|
} |
1982
|
|
|
|
1983
|
|
|
$rs = sql( |
|
|
|
|
1984
|
|
|
"SELECT `id`, |
1985
|
|
|
IFNULL(`sys_trans_text`.`text`, `log_types`.`name`) AS `name`, |
1986
|
|
|
`id`='&2' AS `selected` |
1987
|
|
|
FROM |
1988
|
|
|
(SELECT `id`,`name`,`trans_id` FROM `log_types` |
1989
|
|
|
UNION |
1990
|
|
|
SELECT 0, 'all', (SELECT id FROM sys_trans WHERE `text`='all') |
1991
|
|
|
) `log_types` |
1992
|
|
|
LEFT JOIN `sys_trans_text` |
1993
|
|
|
ON `sys_trans_text`.`trans_id`=`log_types`.`trans_id` |
1994
|
|
|
AND `sys_trans_text`.`lang`='&1' |
1995
|
|
|
ORDER BY `log_types`.`id` ASC", |
1996
|
|
|
$opt['template']['locale'], |
1997
|
|
|
$logtypes ? $logtypes[0] : 0 |
1998
|
|
|
); |
1999
|
|
|
|
2000
|
|
|
$tpl->assign_rs('logtype_options', $rs); |
2001
|
|
|
sql_free_result($rs); |
|
|
|
|
2002
|
|
|
|
2003
|
|
|
// cache-attributes |
2004
|
|
|
$attributes_jsarray = ''; |
2005
|
|
|
|
2006
|
|
|
$bBeginLine2 = true; |
2007
|
|
|
$nPrevLineAttrCount2 = 0; |
2008
|
|
|
$nLineAttrCount2 = 0; |
2009
|
|
|
$attributes_img2 = ''; |
2010
|
|
|
|
2011
|
|
|
/* perpare 'all attributes' */ |
2012
|
|
|
$rsAttrGroup = sql( |
|
|
|
|
2013
|
|
|
"SELECT `attribute_groups`.`id`, |
2014
|
|
|
IFNULL(`sys_trans_text`.`text`, `attribute_groups`.`name`) AS `name`, |
2015
|
|
|
`attribute_categories`.`color` |
2016
|
|
|
FROM `attribute_groups` |
2017
|
|
|
INNER JOIN `attribute_categories` |
2018
|
|
|
ON `attribute_groups`.`category_id`=`attribute_categories`.`id` |
2019
|
|
|
LEFT JOIN `sys_trans` |
2020
|
|
|
ON `attribute_groups`.`trans_id`=`sys_trans`.`id` |
2021
|
|
|
AND `sys_trans`.`text`=`attribute_groups`.`name` |
2022
|
|
|
LEFT JOIN `sys_trans_text` |
2023
|
|
|
ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` |
2024
|
|
|
AND `sys_trans_text`.`lang`='&1' |
2025
|
|
|
ORDER BY `attribute_groups`.`category_id` ASC, `attribute_groups`.`id` ASC", |
2026
|
|
|
$opt['template']['locale'] |
2027
|
|
|
); |
2028
|
|
|
while ($rAttrGroup = sql_fetch_assoc($rsAttrGroup)) { |
|
|
|
|
2029
|
|
|
$group_line = ''; |
2030
|
|
|
|
2031
|
|
|
$rs = sql( |
|
|
|
|
2032
|
|
|
"SELECT `cache_attrib`.`id`, |
2033
|
|
|
IFNULL(`ttname`.`text`, `cache_attrib`.`name`) AS `name`, |
2034
|
|
|
`cache_attrib`.`icon_large`, |
2035
|
|
|
`cache_attrib`.`icon_no`, |
2036
|
|
|
`cache_attrib`.`icon_undef`, |
2037
|
|
|
`cache_attrib`.`search_default`, |
2038
|
|
|
IFNULL(`ttdesc`.`text`, `cache_attrib`.`html_desc`) AS `html_desc` |
2039
|
|
|
FROM `cache_attrib` |
2040
|
|
|
LEFT JOIN `sys_trans` AS `tname` |
2041
|
|
|
ON `cache_attrib`.`trans_id`=`tname`.`id` |
2042
|
|
|
AND `cache_attrib`.`name`=`tname`.`text` |
2043
|
|
|
LEFT JOIN `sys_trans_text` AS `ttname` |
2044
|
|
|
ON `tname`.`id`=`ttname`.`trans_id` |
2045
|
|
|
AND `ttname`.`lang`='&1' |
2046
|
|
|
LEFT JOIN `sys_trans` AS `tdesc` |
2047
|
|
|
ON `cache_attrib`.`html_desc_trans_id`=`tdesc`.`id` |
2048
|
|
|
AND `cache_attrib`.`html_desc`=`tdesc`.`text` |
2049
|
|
|
LEFT JOIN `sys_trans_text` AS `ttdesc` |
2050
|
|
|
ON `tdesc`.`id`=`ttdesc`.`trans_id` |
2051
|
|
|
AND `ttdesc`.`lang`='&1' |
2052
|
|
|
WHERE `cache_attrib`.`group_id` = '&2' |
2053
|
|
|
AND `selectable` |
2054
|
|
|
AND NOT IFNULL(`cache_attrib`.`hidden`, 0)=1 |
2055
|
|
|
ORDER BY `cache_attrib`.`id`", |
2056
|
|
|
$opt['template']['locale'], |
2057
|
|
|
$rAttrGroup['id'] |
2058
|
|
|
); |
2059
|
|
|
while ($record = sql_fetch_array($rs)) { |
|
|
|
|
2060
|
|
|
// icon specified |
2061
|
|
|
$line = $cache_attrib_jsarray_line; |
2062
|
|
|
$line = mb_ereg_replace('{id}', $record['id'], $line); |
2063
|
|
|
|
2064
|
|
|
if (!isset($options['cache_attribs'])) { |
2065
|
|
|
$line = mb_ereg_replace('{state}', 0, $line); |
2066
|
|
|
} else { |
2067
|
|
|
if (array_search($record['id'], $options['cache_attribs']) === false) { |
2068
|
|
|
if (array_search($record['id'], $options['cache_attribs_not']) === false) { |
2069
|
|
|
$line = mb_ereg_replace('{state}', 0, $line); |
2070
|
|
|
} else { |
2071
|
|
|
$line = mb_ereg_replace('{state}', 2, $line); |
2072
|
|
|
} |
2073
|
|
|
} else { |
2074
|
|
|
$line = mb_ereg_replace('{state}', 1, $line); |
2075
|
|
|
} |
2076
|
|
|
} |
2077
|
|
|
|
2078
|
|
|
$line = mb_ereg_replace('{text_long}', escape_javascript($record['name']), $line); |
2079
|
|
|
$line = mb_ereg_replace('{icon}', $record['icon_large'], $line); |
2080
|
|
|
$line = mb_ereg_replace('{icon_no}', $record['icon_no'], $line); |
2081
|
|
|
$line = mb_ereg_replace('{icon_undef}', $record['icon_undef'], $line); |
2082
|
|
|
$line = mb_ereg_replace('{search_default}', $record['search_default'], $line); |
2083
|
|
|
if ($attributes_jsarray != '') { |
2084
|
|
|
$attributes_jsarray .= ",\n"; |
2085
|
|
|
} |
2086
|
|
|
$attributes_jsarray .= $line; |
2087
|
|
|
|
2088
|
|
|
$line = $cache_attrib_img_line1; |
2089
|
|
|
$line = mb_ereg_replace('{id}', $record['id'], $line); |
2090
|
|
|
$line = mb_ereg_replace('{text_long}', escape_javascript($record['name']), $line); |
2091
|
|
View Code Duplication |
if (!isset($options['cache_attribs'])) { |
2092
|
|
|
$line = mb_ereg_replace('{icon}', $record['icon_undef'], $line); |
2093
|
|
|
} else { |
2094
|
|
|
if (array_search($record['id'], $options['cache_attribs']) === false) { |
2095
|
|
|
if (array_search($record['id'], $options['cache_attribs_not']) === false) { |
2096
|
|
|
$line = mb_ereg_replace('{icon}', $record['icon_undef'], $line); |
2097
|
|
|
} else { |
2098
|
|
|
$line = mb_ereg_replace('{icon}', $record['icon_no'], $line); |
2099
|
|
|
} |
2100
|
|
|
} else { |
2101
|
|
|
$line = mb_ereg_replace('{icon}', $record['icon_large'], $line); |
2102
|
|
|
} |
2103
|
|
|
} |
2104
|
|
|
|
2105
|
|
|
$line = mb_ereg_replace('{html_desc}', escape_javascript($record['html_desc']), $line); |
2106
|
|
|
$line = mb_ereg_replace('{name}', escape_javascript($record['name']), $line); |
2107
|
|
|
$line = mb_ereg_replace('{color}', $rAttrGroup['color'], $line); |
2108
|
|
|
|
2109
|
|
|
$group_line .= $line; |
2110
|
|
|
$nLineAttrCount2++; |
2111
|
|
|
} |
2112
|
|
|
sql_free_result($rs); |
|
|
|
|
2113
|
|
|
|
2114
|
|
View Code Duplication |
if ($group_line != '') { |
2115
|
|
|
$group_img = $cache_attrib_group; |
2116
|
|
|
$group_img = mb_ereg_replace('{color}', $rAttrGroup['color'], $group_img); |
2117
|
|
|
$group_img = mb_ereg_replace('{attribs}', $group_line, $group_img); |
2118
|
|
|
$group_img = mb_ereg_replace( |
2119
|
|
|
'{name}', |
2120
|
|
|
htmlspecialchars($rAttrGroup['name'], ENT_COMPAT, 'UTF-8'), |
2121
|
|
|
$group_img |
2122
|
|
|
); |
2123
|
|
|
|
2124
|
|
|
if ($bBeginLine2 == true) { |
|
|
|
|
2125
|
|
|
$attributes_img2 .= '<div id="attribs2">'; |
2126
|
|
|
$bBeginLine2 = false; |
2127
|
|
|
} |
2128
|
|
|
|
2129
|
|
|
$attributes_img2 .= $group_img; |
2130
|
|
|
$nPrevLineAttrCount2 += $nLineAttrCount2; |
2131
|
|
|
|
2132
|
|
|
$nLineAttrCount2 = 0; |
2133
|
|
|
} |
2134
|
|
|
} |
2135
|
|
|
sql_free_result($rsAttrGroup); |
|
|
|
|
2136
|
|
|
if ($bBeginLine2 == false) { |
|
|
|
|
2137
|
|
|
$attributes_img2 .= '</div>'; |
2138
|
|
|
} |
2139
|
|
|
|
2140
|
|
|
/* prepare default attributes */ |
2141
|
|
|
$bBeginLine1 = true; |
2142
|
|
|
$nPrevLineAttrCount1 = 0; |
2143
|
|
|
$nLineAttrCount1 = 0; |
2144
|
|
|
$attributes_img1 = ''; |
2145
|
|
|
|
2146
|
|
|
$rsAttrGroup = sql( |
|
|
|
|
2147
|
|
|
"SELECT `attribute_groups`.`id`, |
2148
|
|
|
IFNULL(`sys_trans_text`.`text`, `attribute_groups`.`name`) AS `name`, |
2149
|
|
|
`attribute_categories`.`color` |
2150
|
|
|
FROM `attribute_groups` |
2151
|
|
|
INNER JOIN `attribute_categories` |
2152
|
|
|
ON `attribute_groups`.`category_id`=`attribute_categories`.`id` |
2153
|
|
|
LEFT JOIN `sys_trans` |
2154
|
|
|
ON `attribute_groups`.`trans_id`=`sys_trans`.`id` |
2155
|
|
|
AND `sys_trans`.`text`=`attribute_groups`.`name` |
2156
|
|
|
LEFT JOIN `sys_trans_text` |
2157
|
|
|
ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` |
2158
|
|
|
AND `sys_trans_text`.`lang`='&1' |
2159
|
|
|
ORDER BY `attribute_groups`.`category_id` ASC, |
2160
|
|
|
`attribute_groups`.`id` ASC", |
2161
|
|
|
$opt['template']['locale'] |
2162
|
|
|
); |
2163
|
|
|
while ($rAttrGroup = sql_fetch_assoc($rsAttrGroup)) { |
|
|
|
|
2164
|
|
|
$group_line = ''; |
2165
|
|
|
|
2166
|
|
|
$rs = sql( |
|
|
|
|
2167
|
|
|
"SELECT `cache_attrib`.`id`, |
2168
|
|
|
IFNULL(`ttname`.`text`, `cache_attrib`.`name`) AS `name`, |
2169
|
|
|
`cache_attrib`.`icon_large`, |
2170
|
|
|
`cache_attrib`.`icon_no`, |
2171
|
|
|
`cache_attrib`.`icon_undef`, |
2172
|
|
|
`cache_attrib`.`search_default`, |
2173
|
|
|
IFNULL(`ttdesc`.`text`, `cache_attrib`.`html_desc`) AS `html_desc` |
2174
|
|
|
FROM `cache_attrib` |
2175
|
|
|
LEFT JOIN `sys_trans` AS `tname` |
2176
|
|
|
ON `cache_attrib`.`trans_id`=`tname`.`id` |
2177
|
|
|
AND `cache_attrib`.`name`=`tname`.`text` |
2178
|
|
|
LEFT JOIN `sys_trans_text` AS `ttname` |
2179
|
|
|
ON `tname`.`id`=`ttname`.`trans_id` |
2180
|
|
|
AND `ttname`.`lang`='&1' |
2181
|
|
|
LEFT JOIN `sys_trans` AS `tdesc` |
2182
|
|
|
ON `cache_attrib`.`html_desc_trans_id`=`tdesc`.`id` |
2183
|
|
|
AND `cache_attrib`.`html_desc`=`tdesc`.`text` |
2184
|
|
|
LEFT JOIN `sys_trans_text` AS `ttdesc` |
2185
|
|
|
ON `tdesc`.`id`=`ttdesc`.`trans_id` |
2186
|
|
|
AND `ttdesc`.`lang`='&1' |
2187
|
|
|
WHERE `cache_attrib`.`group_id`='&2' |
2188
|
|
|
AND `cache_attrib`.`search_default` = 1 |
2189
|
|
|
AND `selectable` |
2190
|
|
|
AND NOT IFNULL(`cache_attrib`.`hidden`, 0)=1 |
2191
|
|
|
ORDER BY `cache_attrib`.`id`", |
2192
|
|
|
$opt['template']['locale'], |
2193
|
|
|
$rAttrGroup['id'] |
2194
|
|
|
); |
2195
|
|
|
while ($record = sql_fetch_array($rs)) { |
|
|
|
|
2196
|
|
|
$line = $cache_attrib_img_line2; |
2197
|
|
|
$line = mb_ereg_replace('{id}', $record['id'], $line); |
2198
|
|
|
$line = mb_ereg_replace('{text_long}', escape_javascript($record['name']), $line); |
2199
|
|
View Code Duplication |
if (!isset($options['cache_attribs'])) { |
2200
|
|
|
$line = mb_ereg_replace('{icon}', $record['icon_undef'], $line); |
2201
|
|
|
} else { |
2202
|
|
|
if (array_search($record['id'], $options['cache_attribs']) === false) { |
2203
|
|
|
if (array_search($record['id'], $options['cache_attribs_not']) === false) { |
2204
|
|
|
$line = mb_ereg_replace('{icon}', $record['icon_undef'], $line); |
2205
|
|
|
} else { |
2206
|
|
|
$line = mb_ereg_replace('{icon}', $record['icon_no'], $line); |
2207
|
|
|
} |
2208
|
|
|
} else { |
2209
|
|
|
$line = mb_ereg_replace('{icon}', $record['icon_large'], $line); |
2210
|
|
|
} |
2211
|
|
|
} |
2212
|
|
|
|
2213
|
|
|
$line = mb_ereg_replace('{html_desc}', escape_javascript($record['html_desc']), $line); |
2214
|
|
|
$line = mb_ereg_replace('{name}', escape_javascript($record['name']), $line); |
2215
|
|
|
$line = mb_ereg_replace('{color}', $rAttrGroup['color'], $line); |
2216
|
|
|
|
2217
|
|
|
$group_line .= $line; |
2218
|
|
|
$nLineAttrCount1++; |
2219
|
|
|
} |
2220
|
|
|
sql_free_result($rs); |
|
|
|
|
2221
|
|
|
|
2222
|
|
View Code Duplication |
if ($group_line != '') { |
2223
|
|
|
$group_img = $cache_attrib_group; |
2224
|
|
|
$group_img = mb_ereg_replace('{color}', $rAttrGroup['color'], $group_img); |
2225
|
|
|
$group_img = mb_ereg_replace('{attribs}', $group_line, $group_img); |
2226
|
|
|
$group_img = mb_ereg_replace( |
2227
|
|
|
'{name}', |
2228
|
|
|
htmlspecialchars($rAttrGroup['name'], ENT_COMPAT, 'UTF-8'), |
2229
|
|
|
$group_img |
2230
|
|
|
); |
2231
|
|
|
|
2232
|
|
|
if ($bBeginLine1 == true) { |
|
|
|
|
2233
|
|
|
$attributes_img1 .= '<div id="attribs1">'; |
2234
|
|
|
$bBeginLine1 = false; |
2235
|
|
|
} |
2236
|
|
|
|
2237
|
|
|
$attributes_img1 .= $group_img; |
2238
|
|
|
$nPrevLineAttrCount1 += $nLineAttrCount1; |
2239
|
|
|
|
2240
|
|
|
$nLineAttrCount1 = 0; |
2241
|
|
|
} |
2242
|
|
|
} |
2243
|
|
|
sql_free_result($rsAttrGroup); |
|
|
|
|
2244
|
|
|
if ($bBeginLine1 == false) { |
|
|
|
|
2245
|
|
|
$attributes_img1 .= '</div>'; |
2246
|
|
|
} |
2247
|
|
|
|
2248
|
|
|
$tpl->assign('cache_attribCat1_list', $attributes_img1); |
2249
|
|
|
$tpl->assign('cache_attribCat2_list', $attributes_img2); |
2250
|
|
|
$tpl->assign('attributes_jsarray', $attributes_jsarray); |
2251
|
|
|
$tpl->assign('hidopt_attribs', isset($options['cache_attribs']) ? implode(';', $options['cache_attribs']) : ''); |
2252
|
|
|
$tpl->assign( |
2253
|
|
|
'hidopt_attribs_not', |
2254
|
|
|
isset($options['cache_attribs_not']) ? implode(';', $options['cache_attribs_not']) : '' |
2255
|
|
|
); |
2256
|
|
|
|
2257
|
|
|
$tpl->assign('fulltext', ''); |
2258
|
|
|
$tpl->assign('ft_desc_checked', true); |
2259
|
|
|
$tpl->assign('ft_name_checked', true); |
2260
|
|
|
$tpl->assign('ft_pictures_checked', false); |
2261
|
|
|
$tpl->assign('ft_logs_checked', false); |
2262
|
|
|
|
2263
|
|
|
// fulltext options |
2264
|
|
|
if ($options['searchtype'] == 'byfulltext') { |
2265
|
|
|
if (!isset($options['fulltext'])) { |
2266
|
|
|
$options['fulltext'] = ''; |
2267
|
|
|
} |
2268
|
|
|
$tpl->assign('fulltext', htmlspecialchars($options['fulltext'], ENT_COMPAT, 'UTF-8')); |
2269
|
|
|
|
2270
|
|
|
if (isset($options['ft_name'])) { |
2271
|
|
|
$tpl->assign('ft_name_checked', $options['ft_name'] == 1); |
2272
|
|
|
} |
2273
|
|
|
|
2274
|
|
|
if (isset($options['ft_desc'])) { |
2275
|
|
|
$tpl->assign('ft_desc_checked', $options['ft_desc'] == 1); |
2276
|
|
|
} |
2277
|
|
|
|
2278
|
|
|
if (isset($options['ft_logs'])) { |
2279
|
|
|
$tpl->assign('ft_logs_checked', $options['ft_logs'] == 1); |
2280
|
|
|
} |
2281
|
|
|
|
2282
|
|
|
if (isset($options['ft_pictures'])) { |
2283
|
|
|
$tpl->assign('ft_pictures_checked', $options['ft_pictures'] == 1); |
2284
|
|
|
} |
2285
|
|
|
} |
2286
|
|
|
$tpl->assign('searchtype_byfulltext', $options['searchtype'] == 'byfulltext'); |
2287
|
|
|
|
2288
|
|
|
//all |
2289
|
|
|
$tpl->assign('searchtype_byall', $options['searchtype'] == 'all'); |
2290
|
|
|
|
2291
|
|
|
// error messages |
2292
|
|
|
$tpl->assign('ortserror', ''); |
2293
|
|
|
if (isset($options['error_plz'])) { |
2294
|
|
|
$tpl->assign('ortserror', $error_plz); |
2295
|
|
|
} elseif (isset($options['error_ort'])) { |
2296
|
|
|
$tpl->assign('ortserror', $error_ort); |
2297
|
|
|
} elseif (isset($options['error_locidnocoords'])) { |
2298
|
|
|
$tpl->assign('ortserror', $error_locidnocoords); |
2299
|
|
|
} elseif (isset($options['error_nowaypointfound'])) { |
2300
|
|
|
$tpl->assign('ortserror', $error_nowaypointfound); |
2301
|
|
|
} elseif (isset($options['error_nocoords'])) { |
2302
|
|
|
$tpl->assign('ortserror', $error_nocoords); |
2303
|
|
|
} |
2304
|
|
|
|
2305
|
|
|
$tpl->assign('fulltexterror', ''); |
2306
|
|
|
if (isset($options['error_nofulltext'])) { |
2307
|
|
|
$tpl->assign('fulltexterror', $error_nofulltext); |
2308
|
|
|
} else { |
2309
|
|
|
if (isset($options['error_fulltexttoolong'])) { |
2310
|
|
|
$tpl->assign('fulltexterror', $error_fulltexttoolong); |
2311
|
|
|
} |
2312
|
|
|
} |
2313
|
|
|
|
2314
|
|
|
$tpl->display(); |
2315
|
|
|
} |
2316
|
|
|
|
2317
|
|
|
|
2318
|
|
|
//============================================================= |
2319
|
|
|
// Prompt the user with a list of locations when the entered |
2320
|
|
|
// 'ort' or 'plz' is not unique. |
2321
|
|
|
//============================================================= |
2322
|
|
|
|
2323
|
|
|
function prepareLocSelectionForm($options) |
2324
|
|
|
{ |
2325
|
|
|
global $tpl; |
2326
|
|
|
|
2327
|
|
|
$tpl->name = 'search_selectlocid'; |
2328
|
|
|
|
2329
|
|
|
unset($options['queryid']); |
2330
|
|
|
unset($options['locid']); |
2331
|
|
|
$options['searchto'] = 'searchbyortplz'; |
2332
|
|
|
unset($options['searchtype']); |
2333
|
|
|
|
2334
|
|
|
// urlparams zusammenbauen |
2335
|
|
|
$urlparamString = ''; |
2336
|
|
|
foreach ($options as $name => $param) { |
2337
|
|
|
// workaround for attribs |
2338
|
|
|
if (is_array($param)) { |
2339
|
|
|
$pnew = ''; |
2340
|
|
|
foreach ($param as $p) { |
2341
|
|
|
if ($pnew != '') { |
2342
|
|
|
$pnew .= ';' . $p; |
2343
|
|
|
} else { |
2344
|
|
|
$pnew .= $p; |
2345
|
|
|
} |
2346
|
|
|
} |
2347
|
|
|
|
2348
|
|
|
$param = $pnew; |
2349
|
|
|
} |
2350
|
|
|
|
2351
|
|
|
if ($urlparamString != '') { |
2352
|
|
|
$urlparamString .= '&' . $name . '=' . urlencode($param); |
2353
|
|
|
} else { |
2354
|
|
|
$urlparamString = $name . '=' . urlencode($param); |
2355
|
|
|
} |
2356
|
|
|
} |
2357
|
|
|
$urlparamString .= ''; |
2358
|
|
|
|
2359
|
|
|
return $urlparamString; |
2360
|
|
|
} |
2361
|
|
|
|
2362
|
|
|
|
2363
|
|
|
function outputUniidSelectionForm($uniSql, $options) |
2364
|
|
|
{ |
2365
|
|
|
global $tpl; // settings |
2366
|
|
|
global $locline, $secondlocationname; |
2367
|
|
|
|
2368
|
|
|
$urlparamString = prepareLocSelectionForm($options); |
2369
|
|
|
|
2370
|
|
|
sql_temp_table_slave('uniids'); |
|
|
|
|
2371
|
|
|
sql_slave("CREATE TEMPORARY TABLE &uniids ENGINE=MEMORY " . $uniSql); |
|
|
|
|
2372
|
|
|
sql_slave("ALTER TABLE &uniids ADD PRIMARY KEY (`uni_id`)"); |
|
|
|
|
2373
|
|
|
|
2374
|
|
|
// locidsite |
2375
|
|
|
$locidsite = isset($_REQUEST['locidsite']) ? $_REQUEST['locidsite'] : 0; |
2376
|
|
|
if (!is_numeric($locidsite)) { |
2377
|
|
|
$locidsite = 0; |
2378
|
|
|
} |
2379
|
|
|
|
2380
|
|
|
$count = sql_value_slave("SELECT COUNT(*) FROM &uniids", 0); |
|
|
|
|
2381
|
|
|
$tpl->assign('resultscount', $count); |
2382
|
|
|
|
2383
|
|
|
// create page browser |
2384
|
|
|
$pager = new pager('search.php?' . $urlparamString . '&locidsite={offset}'); |
2385
|
|
|
$pager->make_from_offset($locidsite, ceil($count / 20), 1); |
2386
|
|
|
|
2387
|
|
|
// create locations list |
2388
|
|
|
$rs = sql_slave( |
|
|
|
|
2389
|
|
|
"SELECT `gns_locations`.`rc` `rc`, |
2390
|
|
|
`gns_locations`.`cc1` `cc1`, |
2391
|
|
|
`gns_locations`.`admtxt1` `admtxt1`, |
2392
|
|
|
`gns_locations`.`admtxt2` `admtxt2`, |
2393
|
|
|
`gns_locations`.`admtxt3` `admtxt3`, |
2394
|
|
|
`gns_locations`.`admtxt4` `admtxt4`, |
2395
|
|
|
`gns_locations`.`uni` `uni_id`, |
2396
|
|
|
`gns_locations`.`lon` `lon`, |
2397
|
|
|
`gns_locations`.`lat` `lat`, |
2398
|
|
|
`gns_locations`.`full_name` `full_name`, |
2399
|
|
|
&uniids.`olduni` `olduni` |
2400
|
|
|
FROM `gns_locations`, &uniids |
2401
|
|
|
WHERE &uniids.`uni_id`=`gns_locations`.`uni` |
2402
|
|
|
ORDER BY `gns_locations`.`full_name` ASC |
2403
|
|
|
LIMIT " . ($locidsite * 20) . ', 20' |
2404
|
|
|
); |
2405
|
|
|
|
2406
|
|
|
$nr = $locidsite * 20 + 1; |
2407
|
|
|
$locations = ''; |
2408
|
|
|
while ($r = sql_fetch_array($rs)) { |
|
|
|
|
2409
|
|
|
$thislocation = $locline; |
2410
|
|
|
|
2411
|
|
|
$locString = ''; |
2412
|
|
View Code Duplication |
if ($r['admtxt1'] != '') { |
2413
|
|
|
if ($locString != '') { |
2414
|
|
|
$locString .= ' > '; |
2415
|
|
|
} |
2416
|
|
|
$locString .= htmlspecialchars($r['admtxt1'], ENT_COMPAT, 'UTF-8'); |
2417
|
|
|
} |
2418
|
|
View Code Duplication |
if ($r['admtxt2'] != '') { |
2419
|
|
|
if ($locString != '') { |
2420
|
|
|
$locString .= ' > '; |
2421
|
|
|
} |
2422
|
|
|
$locString .= htmlspecialchars($r['admtxt2'], ENT_COMPAT, 'UTF-8'); |
2423
|
|
|
} |
2424
|
|
View Code Duplication |
if ($r['admtxt4'] != '') { |
2425
|
|
|
if ($locString != '') { |
2426
|
|
|
$locString .= ' > '; |
2427
|
|
|
} |
2428
|
|
|
$locString .= htmlspecialchars($r['admtxt4'], ENT_COMPAT, 'UTF-8'); |
2429
|
|
|
} |
2430
|
|
|
|
2431
|
|
|
$thislocation = mb_ereg_replace('{parentlocations}', $locString, $thislocation); |
2432
|
|
|
|
2433
|
|
|
// koordinaten ermitteln |
2434
|
|
|
$coordString = help_latToDegreeStr($r['lat']) . ' ' . help_lonToDegreeStr($r['lon']); |
2435
|
|
|
$thislocation = mb_ereg_replace('{coords}', htmlspecialchars($coordString, ENT_COMPAT, 'UTF-8'), $thislocation); |
2436
|
|
|
|
2437
|
|
|
if ($r['olduni'] != 0) { |
2438
|
|
|
// der alte name wurde durch den native-wert ersetzt |
2439
|
|
|
$thissecloc = $secondlocationname; |
2440
|
|
|
|
2441
|
|
|
$r['olduni'] = $r['olduni'] + 0; |
2442
|
|
|
$rsSecLoc = sql_slave( |
|
|
|
|
2443
|
|
|
"SELECT full_name FROM gns_locations WHERE uni='&1'", |
2444
|
|
|
$r['olduni'] |
2445
|
|
|
); |
2446
|
|
|
$rSecLoc = sql_fetch_assoc($rsSecLoc); |
|
|
|
|
2447
|
|
|
$thissecloc = mb_ereg_replace( |
2448
|
|
|
'{secondlocationname}', |
2449
|
|
|
htmlspecialchars($rSecLoc['full_name'], ENT_COMPAT, 'UTF-8'), |
2450
|
|
|
$thissecloc |
2451
|
|
|
); |
2452
|
|
|
sql_free_result($rsSecLoc); |
|
|
|
|
2453
|
|
|
|
2454
|
|
|
$thislocation = mb_ereg_replace('{secondlocationname}', $thissecloc, $thislocation); |
2455
|
|
|
} else { |
2456
|
|
|
$thislocation = mb_ereg_replace('{secondlocationname}', '', $thislocation); |
2457
|
|
|
} |
2458
|
|
|
|
2459
|
|
|
$thislocation = mb_ereg_replace( |
2460
|
|
|
'{locationname}', |
2461
|
|
|
htmlspecialchars($r['full_name'], ENT_COMPAT, 'UTF-8'), |
2462
|
|
|
$thislocation |
2463
|
|
|
); |
2464
|
|
|
$thislocation = mb_ereg_replace('{urlparams}', $urlparamString . '&locid={locid}', $thislocation); |
|
|
|
|
2465
|
|
|
$thislocation = mb_ereg_replace('{locid}', urlencode($r['uni_id']), $thislocation); |
2466
|
|
|
$thislocation = mb_ereg_replace('{nr}', $nr, $thislocation); |
2467
|
|
|
|
2468
|
|
|
$nr++; |
2469
|
|
|
$locations .= $thislocation . "\n"; |
2470
|
|
|
} |
2471
|
|
|
sql_free_result($rs); |
|
|
|
|
2472
|
|
|
sql_drop_temp_table_slave('uniids'); |
|
|
|
|
2473
|
|
|
|
2474
|
|
|
$tpl->assign('locations', $locations); |
2475
|
|
|
|
2476
|
|
|
$tpl->display(); |
2477
|
|
|
exit; |
2478
|
|
|
} |
2479
|
|
|
|
2480
|
|
|
|
2481
|
|
|
function outputLocidSelectionForm($locSql, $options) |
2482
|
|
|
{ |
2483
|
|
|
global $tpl; |
2484
|
|
|
global $locline, $bgcolor1, $bgcolor2; |
2485
|
|
|
|
2486
|
|
|
require_once __DIR__ . '/lib2/logic/geodb.class.php'; |
2487
|
|
|
|
2488
|
|
|
$urlparamString = prepareLocSelectionForm($options) . '&locid={locid}'; |
2489
|
|
|
|
2490
|
|
|
sql_temp_table_slave('locids'); |
|
|
|
|
2491
|
|
|
sql_slave("CREATE TEMPORARY TABLE &locids ENGINE=MEMORY " . $locSql); |
|
|
|
|
2492
|
|
|
sql_slave("ALTER TABLE &locids ADD PRIMARY KEY (`loc_id`)"); |
|
|
|
|
2493
|
|
|
|
2494
|
|
|
$rs = sql_slave( |
|
|
|
|
2495
|
|
|
"SELECT `geodb_textdata`.`loc_id` `loc_id`, |
2496
|
|
|
`geodb_textdata`.`text_val` `text_val` |
2497
|
|
|
FROM `geodb_textdata`, &locids |
2498
|
|
|
WHERE &locids.`loc_id`=`geodb_textdata`.`loc_id` |
2499
|
|
|
AND `geodb_textdata`.`text_type` = 500100000 |
2500
|
|
|
ORDER BY `text_val`" |
2501
|
|
|
); |
2502
|
|
|
|
2503
|
|
|
$nr = 1; |
2504
|
|
|
$locations = ''; |
2505
|
|
|
while ($r = sql_fetch_array($rs)) { |
|
|
|
|
2506
|
|
|
$thislocation = $locline; |
2507
|
|
|
|
2508
|
|
|
// locationsdings zusammenbauen |
2509
|
|
|
$locString = ''; |
2510
|
|
|
$land = GeoDb::landFromLocid($r['loc_id']); |
2511
|
|
|
if ($land != '') { |
2512
|
|
|
$locString .= htmlspecialchars($land, ENT_COMPAT, 'UTF-8'); |
2513
|
|
|
} |
2514
|
|
|
|
2515
|
|
|
$rb = GeoDb::regierungsbezirkFromLocid($r['loc_id']); |
2516
|
|
|
if ($rb != '') { |
2517
|
|
|
$locString .= ' > ' . htmlspecialchars($rb, ENT_COMPAT, 'UTF-8'); |
2518
|
|
|
} |
2519
|
|
|
|
2520
|
|
|
$lk = GeoDb::landkreisFromLocid($r['loc_id']); |
2521
|
|
|
if ($lk != '') { |
2522
|
|
|
$locString .= ' > ' . htmlspecialchars($lk, ENT_COMPAT, 'UTF-8'); |
2523
|
|
|
} |
2524
|
|
|
|
2525
|
|
|
$thislocation = mb_ereg_replace('{parentlocations}', $locString, $thislocation); |
2526
|
|
|
|
2527
|
|
|
// koordinaten ermitteln |
2528
|
|
|
$r['loc_id'] = $r['loc_id'] + 0; |
2529
|
|
|
$rsCoords = sql_slave( |
|
|
|
|
2530
|
|
|
"SELECT `lon`, `lat` |
2531
|
|
|
FROM `geodb_coordinates` |
2532
|
|
|
WHERE loc_id='&1' |
2533
|
|
|
LIMIT 1", |
2534
|
|
|
$r['loc_id'] |
2535
|
|
|
); |
2536
|
|
|
if ($rCoords = sql_fetch_array($rsCoords)) { |
|
|
|
|
2537
|
|
|
$coordString = help_latToDegreeStr($rCoords['lat']) . ' ' . help_lonToDegreeStr($rCoords['lon']); |
2538
|
|
|
} else { |
2539
|
|
|
$coordString = '[' . $no_location_coords . ']'; |
|
|
|
|
2540
|
|
|
} |
2541
|
|
|
|
2542
|
|
|
$thislocation = mb_ereg_replace('{coords}', htmlspecialchars($coordString, ENT_COMPAT, 'UTF-8'), $thislocation); |
2543
|
|
|
$thislocation = mb_ereg_replace( |
2544
|
|
|
'{locationname}', |
2545
|
|
|
htmlspecialchars($r['text_val'], ENT_COMPAT, 'UTF-8'), |
2546
|
|
|
$thislocation |
2547
|
|
|
); |
2548
|
|
|
$thislocation = mb_ereg_replace('{urlparams}', $urlparamString, $thislocation); |
|
|
|
|
2549
|
|
|
$thislocation = mb_ereg_replace('{locid}', urlencode($r['loc_id']), $thislocation); |
2550
|
|
|
$thislocation = mb_ereg_replace('{nr}', $nr, $thislocation); |
2551
|
|
|
$thislocation = mb_ereg_replace('{secondlocationname}', '', $thislocation); |
2552
|
|
|
|
2553
|
|
|
if ($nr % 2) { |
2554
|
|
|
$thislocation = mb_ereg_replace('{bgcolor}', $bgcolor1, $thislocation); |
2555
|
|
|
} else { |
2556
|
|
|
$thislocation = mb_ereg_replace('{bgcolor}', $bgcolor2, $thislocation); |
2557
|
|
|
} |
2558
|
|
|
|
2559
|
|
|
$nr++; |
2560
|
|
|
$locations .= $thislocation . "\n"; |
2561
|
|
|
} |
2562
|
|
|
|
2563
|
|
|
$tpl->assign('locations', $locations); |
2564
|
|
|
|
2565
|
|
|
$tpl->assign('resultscount', sql_num_rows($rs)); |
|
|
|
|
2566
|
|
|
$tpl->assign('pages', ''); |
2567
|
|
|
|
2568
|
|
|
sql_free_result($rs); |
|
|
|
|
2569
|
|
|
sql_drop_temp_table_slave('locids'); |
|
|
|
|
2570
|
|
|
|
2571
|
|
|
$tpl->display(); |
2572
|
|
|
exit; |
2573
|
|
|
} |
2574
|
|
|
|
2575
|
|
|
//add cache to cachelist |
2576
|
|
|
function addToList($list_caches) |
2577
|
|
|
{ |
2578
|
|
|
global $login; |
2579
|
|
|
$added_waypoints = 0; |
2580
|
|
|
$list = new cachelist($_REQUEST['selectCachelist'] + 0); |
2581
|
|
|
if ($list->exist() && $list->getUserId() == $login->userid) { |
2582
|
|
|
if ($list_caches != '') { |
2583
|
|
|
$added_waypoints = $list->addCachesByIDs($list_caches); |
2584
|
|
|
} |
2585
|
|
|
} |
2586
|
|
|
return $added_waypoints; |
2587
|
|
|
} |
2588
|
|
|
|
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.