/
search.html.inc.php
249 lines (201 loc) · 7.63 KB
/
search.html.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
/***************************************************************************
For license information see doc/license.txt
Unicode Reminder メモ
HTML search output
(Used by Ocprop)
****************************************************************************/
$search_output_file_download = false;
$sAddFields .= ', `caches`.`name`, `caches`.`difficulty`, `caches`.`terrain`,
`caches`.`desc_languages`, `caches`.`date_created`,
`user`.`username`,
`cache_type`.`icon_large`,
`stt`.`text` AS `cacheTypeName`,
IFNULL(`stat_caches`.`found`, 0) `founds`,
IFNULL(`stat_caches`.`toprating`, 0) `topratings`,
IF(ISNULL(`tbloconly`.`cache_id`), 0, 1) AS `oconly`';
$sAddJoin .= ' INNER JOIN `user` ON `caches`.`user_id`=`user`.`user_id`
INNER JOIN `cache_type` ON `cache_type`.`id`=`caches`.`type`
LEFT JOIN `caches_attributes` AS `tbloconly`
ON `caches`.`cache_id`=`tbloconly`.`cache_id` AND `tbloconly`.`attrib_id`=6
LEFT JOIN `sys_trans_text` `stt` ON `stt`.`trans_id`=`cache_type`.`trans_id`';
$sAddWhere .= ' AND `stt`.`lang`=\'' . sql_escape($opt['template']['locale']) . '\'';
function search_output()
{
global $opt, $tpl, $login;
global $enable_mapdisplay, $search_in_gm, $search_in_gm_zip;
global $called_by_search, $called_by_profile_query, $options, $lat_rad, $lon_rad, $distance_unit;
global $startat, $caches_per_page, $sql;
$tpl->name = 'search.result.caches';
$tpl->menuitem = MNU_CACHES_SEARCH_RESULT;
$startat = floor($startat / $caches_per_page) * $caches_per_page;
$sql .= ' LIMIT ' . $startat . ', ' . $caches_per_page;
// run SQL query
sql_enable_foundrows();
$rs_caches = sql_slave("SELECT SQL_BUFFER_RESULT SQL_CALC_FOUND_ROWS " . $sql);
$resultcount = sql_value_slave('SELECT FOUND_ROWS()', 0);
sql_foundrows_done();
$tpl->assign('results_count', $resultcount);
$tpl->assign('startat',$startat);
$caches = array();
while ($rCache = sql_fetch_array($rs_caches))
{
// select best-fitting short desc for active language
$rCache['short_desc'] = sql_value_slave("
SELECT `short_desc`
FROM `cache_desc`
WHERE `cache_id`='&1' AND `language`='&2'",
false, $rCache['cache_id'], $opt['template']['locale']);
if ($rCache['short_desc'] === false) $rCache['short_desc'] = sql_value_slave("
SELECT `short_desc`
FROM `cache_desc`
WHERE `cache_id`='&1' AND `language`='EN'",
false, $rCache['cache_id']);
if ($rCache['short_desc'] === false) $rCache['short_desc'] = sql_value_slave("
SELECT `short_desc`
FROM `cache_desc`
WHERE `cache_id`='&1'
ORDER BY `date_created`
LIMIT 1",
'', $rCache['cache_id']);
$rCache['desclangs'] = mb_split(',', $rCache['desc_languages']);
// decide if the cache is new
$dDiff = dateDiff('d', $rCache['date_created'], date('Y-m-d'));
$rCache['isnew'] = ($dDiff <= NEWCACHES_DAYS);
// get last logs
if ($options['sort'] != 'bymylastlog' || !$login->logged_in())
$ownlogs = "";
else
$ownlogs = " AND `cache_logs`.`user_id`='" . sql_escape($login->userid) . "'";
$sql = "
SELECT `cache_logs`.`id`, `cache_logs`.`type`, `cache_logs`.`date`, `log_types`.`icon_small`
FROM `cache_logs`, `log_types`
WHERE `cache_logs`.`cache_id`='" . sql_escape($rCache['cache_id']) . "'
AND `log_types`.`id`=`cache_logs`.`type`" . $ownlogs . "
ORDER BY `cache_logs`.`date` DESC, `cache_logs`.`date_created` DESC
LIMIT 6";
$rs = sql_slave($sql);
$rCache['logs'] = sql_fetch_assoc_table($rs);
$rCache['firstlog'] = array_shift($rCache['logs']);
// get direction from search coordinate
if ($rCache['distance'] > 0)
{
$direction = geomath::calcBearing($lat_rad / 3.14159 * 180, $lon_rad / 3.14159 * 180, $rCache['latitude'], $rCache['longitude']);
$rCache['direction_deg'] = round($direction / 22.5) * 22.5;
$rCache['direction_txt'] = geomath::Bearing2Text($direction, 1);
}
else
$rCache['direction_deg'] = false;
// other data
$rCache['icon'] = getCacheIcon($login->userid, $rCache['cache_id'], $rCache['status'], $rCache['user_id'], $rCache['icon_large']);
$rCache['redname'] = ($rCache['status']==5 || $rCache['status']==7);
$caches[] = $rCache;
}
mysql_free_result($rs_caches);
$tpl->assign('caches', $caches);
$pager = new pager('search.php?queryid=' . $options['queryid'] . '&startat={offset}', 2, 9);
$pager->make_from_offset($startat, $resultcount, $caches_per_page);
// downloads
$tpl->assign('queryid', $options['queryid']);
$tpl->assign('startatp1', min($resultcount,$startat + 1));
if (($resultcount - $startat) < 500)
$tpl->assign('endat', $startat + $resultcount - $startat);
else
$tpl->assign('endat', $startat + 500);
// kompatibilität!
if ($distance_unit == 'sm')
$tpl->assign('distanceunit', 'mi');
else if ($distance_unit == 'nm')
$tpl->assign('distanceunit', 'sm');
else
$tpl->assign('distanceunit', $distance_unit);
$tpl->assign('displayownlogs', $options['sort'] == 'bymylastlog');
$tpl->assign('search_headline_caches', $called_by_search);
$tpl->assign('enable_mapdisplay', $enable_mapdisplay);
if ($called_by_profile_query)
{
$tpl->assign('search_in_gm', '');
$tpl->assign('search_in_gm_zip', '');
}
else
{
$tpl->assign('search_in_gm', $search_in_gm);
$tpl->assign('search_in_gm_zip', $search_in_gm_zip);
}
$tpl->display();
}
function dateDiff($interval, $dateTimeBegin, $dateTimeEnd)
{
//Parse about any English textual datetime
//$dateTimeBegin, $dateTimeEnd
$dateTimeBegin = strtotime($dateTimeBegin);
if ($dateTimeBegin === -1)
return("..begin date Invalid");
$dateTimeEnd = strtotime($dateTimeEnd);
if ($dateTimeEnd === -1)
return("..end date Invalid");
$dif = $dateTimeEnd - $dateTimeBegin;
switch($interval)
{
case "s"://seconds
return($dif);
case "n"://minutes
return(floor($dif/60)); //60s=1m
case "h"://hours
return(floor($dif/3600)); //3600s=1h
case "d"://days
return(floor($dif/86400)); //86400s=1d
case "ww"://Week
return(floor($dif/604800)); //604800s=1week=1semana
case "m": //similar result "m" dateDiff Microsoft
$monthBegin = (date("Y",$dateTimeBegin)*12) + date("n",$dateTimeBegin);
$monthEnd = (date("Y",$dateTimeEnd)*12) + date("n",$dateTimeEnd);
$monthDiff = $monthEnd - $monthBegin;
return($monthDiff);
case "yyyy": //similar result "yyyy" dateDiff Microsoft
return(date("Y",$dateTimeEnd) - date("Y",$dateTimeBegin));
default:
return(floor($dif/86400)); //86400s=1d
}
}
function getCacheIcon($user_id, $cache_id, $cache_status, $cache_userid, $iconname)
{
$iconname = mb_eregi_replace("cache/", "", $iconname);
$iconext = "." . mb_eregi_replace("^.*\.", "", $iconname);
$iconname = mb_eregi_replace("\..*", "", $iconname);
// add status
switch ($cache_status)
{
case 1: $iconname .= "-s"; break;
case 2: $iconname .= "-n"; break;
case 3: $iconname .= "-a"; break;
case 4: $iconname .= "-a"; break;
case 5: $iconname .= "-s"; break; // fix for RT ticket #3403
case 6: $iconname .= "-a"; break;
case 7: $iconname .= "-a"; break;
}
// mark if (not) found
if ($user_id)
{
if ($cache_userid == $user_id)
{
$iconname .= "-owner";
}
else
{
$logtype = sql_value_slave("
SELECT `type`
FROM `cache_logs`
WHERE `cache_id`='&1' AND `user_id`='&2' AND `type` IN (1,2,7)
ORDER BY `type`
LIMIT 1",
0, $cache_id, $user_id);
if ($logtype == 1 || $logtype == 7)
$iconname .= '-found';
elseif ($logtype == 2)
$iconname .= '-dnf';
}
}
return $iconname . $iconext;
}
?>