diff --git a/htdocs/lang/de/ocstyle/lib/menu.php b/htdocs/lang/de/ocstyle/lib/menu.php index 83ba746a..364a4eff 100644 --- a/htdocs/lang/de/ocstyle/lib/menu.php +++ b/htdocs/lang/de/ocstyle/lib/menu.php @@ -59,7 +59,7 @@ $menu = array( 'menustring' => t('Search'), 'visible' => true, 'filename' => 'search.php', - 'siteid' => 'search', + 'siteid' => 'search1/search', 'submenu' => array( array( 'title' => t('Show Geocache'), @@ -131,14 +131,14 @@ $menu = array( 'menustring' => t('Select city'), 'visible' => false, 'filename' => 'search.php', - 'siteid' => 'selectlocid' + 'siteid' => 'search1/selectlocid' ), array( 'title' => t('Show search result'), 'menustring' => t('Result'), 'visible' => false, 'filename' => 'search.php', - 'siteid' => 'search.result.caches' + 'siteid' => 'search1/search.result.caches' ), array( 'title' => t('Recommendations'), diff --git a/htdocs/lang/de/ocstyle/search1/search.inc.php b/htdocs/lang/de/ocstyle/search1/search.inc.php new file mode 100644 index 00000000..15cd2e83 --- /dev/null +++ b/htdocs/lang/de/ocstyle/search1/search.inc.php @@ -0,0 +1,152 @@ + ' . t('NEW') . '  '; + $caches_olddays = 14; // changed from 7 to 14 -- following 2013/6/17 + + $caches_oconlystring = 'OConly'; + + $bgcolor1 = 'odd'; // even lines + $bgcolor2 = 'even'; // odd lines + $bgcolor_found = "#66FFCC"; // if cache was found by user + $bgcolor_owner = "#ffffc5"; // if user is owner + $bgcolor_inactive = "#fafafa"; // if cache is inactive + + $string_by = t('by'); + + $logdateformat = 'd.m.Y'; + $logpics[1] = '' . t('Find') . ''; + $logpics[2] = '' . t('Didn\'t find') . ''; + $logpics[3] = '' . t('Note') . ''; + + $diffpics[2] = 'diff-10.gif'; + $diffpics[3] = 'diff-15.gif'; + $diffpics[4] = 'diff-20.gif'; + $diffpics[5] = 'diff-25.gif'; + $diffpics[6] = 'diff-30.gif'; + $diffpics[7] = 'diff-35.gif'; + $diffpics[8] = 'diff-40.gif'; + $diffpics[9] = 'diff-45.gif'; + $diffpics[10] = 'diff-50.gif'; + + $terrpics[2] = 'terr-10.gif'; + $terrpics[3] = 'terr-15.gif'; + $terrpics[4] = 'terr-20.gif'; + $terrpics[5] = 'terr-25.gif'; + $terrpics[6] = 'terr-30.gif'; + $terrpics[7] = 'terr-35.gif'; + $terrpics[8] = 'terr-40.gif'; + $terrpics[9] = 'terr-45.gif'; + $terrpics[10] = 'terr-50.gif'; + + $terrpics[1] = 'rat-10.gif'; + $terrpics[2] = 'rat-20.gif'; + $terrpics[3] = 'rat-30.gif'; + $terrpics[4] = 'rat-40.gif'; + $terrpics[5] = 'rat-50.gif'; + + $difficulty_text_diff = t("Difficulty: %01.1f of 5.0"); + $difficulty_text_terr = t("Terrain: %01.1f of 5.0"); + $rating_text = t("Rating: {rating}%"); + $not_rated = t('No Rating'); + + $error_plz = '' . t('The postal code could not be found') . ''; + $error_ort = '' . t('There does no city exist with this name') . ''; + $error_locidnocoords = '' . t('There are no Koordinates available for the selected city') . ''; + $error_noort = '' . t('The entered city is not valid.') . ''; + $error_nofulltext = '' . t('The entered text is invalid.') . ''; + $error_fulltexttoolong = '' . t('The entered text contains more than 50 words.') . ''; + + $gns_countries['GM'] = t('Germany'); + $gns_countries['AU'] = t('Austria'); + $gns_countries['SZ'] = t('Switzerland'); + + $default_lang = t('EN'); + $search_all_countries = ''; + $search_all_cachetypes = ''; + + $cache_attrib_group = + '
+ + +
{name}
{attribs}
'; + $cache_attrib_jsarray_line = "new Array('{id}', {state}, '{text_long}', '{icon}', '{icon_no}', '{icon_undef}', '{search_default}')"; + $cache_attrib_img_line1 = ' '; + $cache_attrib_img_line2 = ' '; + + $search_in_gm = '' . $translate->t('(in GM)','','',0) . ''; + $search_in_gm_zip = '' . $translate->t('(in GM)','','',0) . ''; + + $unknown_searchtype = t('unknown search type'); + $showonmap = t('Show on map'); + + $converted_from_html = t('converted from HTML'); + $state_temporarily_na = t('Temporary not available'); + $state_archived = t('Archived'); + $state_locked = t('Locked'); + $cache_note_text = t('Personal cache note'); + + +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 + } +} +?> diff --git a/htdocs/lang/de/ocstyle/search1/search.result.caches.kml.head.tpl.php b/htdocs/lang/de/ocstyle/search1/search.result.caches.kml.head.tpl.php new file mode 100644 index 00000000..54fd4cdf --- /dev/null +++ b/htdocs/lang/de/ocstyle/search1/search.result.caches.kml.head.tpl.php @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + Geocaches (Opencaching) + 0 diff --git a/htdocs/lang/de/ocstyle/search1/search.result.caches.row.tpl.php b/htdocs/lang/de/ocstyle/search1/search.result.caches.row.tpl.php new file mode 100644 index 00000000..927d60b1 --- /dev/null +++ b/htdocs/lang/de/ocstyle/search1/search.result.caches.row.tpl.php @@ -0,0 +1,17 @@ + + +  {position}  + {distance}  + {cachetype} + {diffpic}{terrpic} + {new} {cachename}  {string_by} {username} + {oconly} + {logimage1} {logdate1}  + + + +   + {direction}  +

{ratpic}{desclangs} {short_desc}  

+ {lastlogs}  + diff --git a/htdocs/lang/de/ocstyle/search1/search.result.caches.tpl.php b/htdocs/lang/de/ocstyle/search1/search.result.caches.tpl.php new file mode 100644 index 00000000..9072b660 --- /dev/null +++ b/htdocs/lang/de/ocstyle/search1/search.result.caches.tpl.php @@ -0,0 +1,136 @@ + + +
+ + + + + +
+

 {t}{results_count} caches matched{/t} 

+
+ + +

{showonmap}

+

+ [{t}Save options{/t}] +  [{t}Edit options{/t}]

+
+
+
+ + + + + + + + + + + + + + + +
+ + + + + + +
{pages}{t}Download{/t}:  + + +
+
 
+ + + + + + + + + + + + {results} +
 # {distanceunit}{t}Type{/t}{t}D/T{/t}{t}Name{/t} {t}Last logs{/t}{t}Own logs{/t}
+
 
{pages}
+ + + + + + + + +
{t}Download{/t}:   + {t}Results on this page:{/t} + GPX + LOC + KML + {search_in_gm} + OV2 + OVL + TXT +
+ {t}Result {startatp1} to {endat} (as zip):{/t} + GPX + LOC + KML + {search_in_gm_zip} + OV2 + OVL + TXT +
+ {t}With the download you accept the terms of use from opencaching.de.  {/t} +
+ +

({t}old{/t})

+ +
diff --git a/htdocs/lang/de/ocstyle/search1/search.tpl.php b/htdocs/lang/de/ocstyle/search1/search.tpl.php new file mode 100644 index 00000000..9f4466a5 --- /dev/null +++ b/htdocs/lang/de/ocstyle/search1/search.tpl.php @@ -0,0 +1,841 @@ + + + + +
{t}Search for caches{/t}{t}Search for caches{/t}   ({t}old{/t})
+ +
+ +
+ + + + + + + + + + +
{t}Sorting of result:{/t} +
+   +
+   +   + +
  + + +
+
+
+ + + + + + + + + +
{t}Hide following caches:{/t} +    +    +    + {t}Notice{/t}{t}Only usable if signed in.{/t} +
  +   +   + +
+
+
+ + + + + + + + + + + + + + + + + + + + +
{t}Cachetype:{/t}
+
+
+ + + + + + + + + + + + + + + +
{t}Cachesize:{/t}     
+
+
+ + + + + + + + + +
{t}Difficulty:{/t} + +    {t}to{/t}    + +
{t}Terrain:{/t} + +    {t}to{/t}    + +
+
+
+ + + + + +
{t}Country:{/t}   + +
+
+
+ + + + + +
+ {t}Cache attributes:{/t}
+ ({t}Show all{/t}) +
+ +
{cache_attribCat2_list}
+
+
+
+ +
+

{t}JavaScript is not activated, you cannot use the above options (sorting to attributes) - basic search is supported nevertheless.{/t}

+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
 
+
+

+ + {t}Search by cachename{/t} +

+
+ + + + + + + + + + + + + + +
{t}Name:{/t}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
 
+
+

+ + {t}Search by distance{/t} +

+
+ + + + + + + + + + + + + + + + + + +
{t}Of coordinates:{/t} +   +  °  +  '  +
+   +  °  +  '  +
{t}Maximum distance:{/t} +   + +
+
+ +
 
+
+

+ + {t}Search for city{/t} +

+
+ + + + + + + + + + {ortserror} +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{t}Postal code:{/t}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{t}City:{/t}
+
+ + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
 
+
+

+ + {t}Search for text{/t} +

+
+ + + + + + + + + {fulltexterror} + + + + + + + + + + +
Text:
+ + + + + + + + + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
 
+
+

+ + {t}Search for Owner{/t} +

+
+ + + + + + + + + + + + + + +
{t}Owner:{/t}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
 
+
+

+ + {t}Search for Logs{/t} +

+
+ + + + + + + + + + + + + + + + + + +
{t}Logtype:{/t} + +
{t}Username:{/t}
+
+
 
diff --git a/htdocs/lang/de/ocstyle/search1/selectlocid.inc.php b/htdocs/lang/de/ocstyle/search1/selectlocid.inc.php index 64c4e856..1f859288 100644 --- a/htdocs/lang/de/ocstyle/search1/selectlocid.inc.php +++ b/htdocs/lang/de/ocstyle/search1/selectlocid.inc.php @@ -15,7 +15,7 @@ ****************************************************************************/ - $locline = '

{nr}. 

{locationname}{secondlocationname}

+ $locline = '

{nr}. 

{locationname}{secondlocationname}

 

{coords}

 {parentlocations}'; diff --git a/htdocs/lang/de/ocstyle/search1/selectlocid.tpl.php b/htdocs/lang/de/ocstyle/search1/selectlocid.tpl.php new file mode 100644 index 00000000..a043d81d --- /dev/null +++ b/htdocs/lang/de/ocstyle/search1/selectlocid.tpl.php @@ -0,0 +1,21 @@ + + +
{t}Search result{/t}{t}Selection of city{/t} - {t}Total of {resultscount} cities matched{/t}
+ + +

{t}For the search criterion no clear result was found. Please choose the correct location.{/t}

+ + +
{pages}
+ + {locations} +
+ + +
{pages}
\ No newline at end of file diff --git a/htdocs/lib/search1/ftsearch.inc.php b/htdocs/lib/search1/ftsearch.inc.php new file mode 100644 index 00000000..12ade4a2 --- /dev/null +++ b/htdocs/lib/search1/ftsearch.inc.php @@ -0,0 +1,329 @@ + $s) + { + if (strlen($s) > 2) + $astr[$k] = sprintf("%u", crc32($s)); + else + unset($astr[$k]); + } + return $astr; +} + +// str = long text +function ftsearch_split(&$str, $simple) +{ + global $ftsearch_ignores; + + // interpunktion + $str = mb_ereg_replace('\\?', ' ', $str); + $str = mb_ereg_replace('\\)', ' ', $str); + $str = mb_ereg_replace('\\(', ' ', $str); + $str = mb_ereg_replace('\\.', ' ', $str); + $str = mb_ereg_replace('´', ' ', $str); + $str = mb_ereg_replace('`', ' ', $str); + $str = mb_ereg_replace('\'', ' ', $str); + $str = mb_ereg_replace('/', ' ', $str); + $str = mb_ereg_replace(':', ' ', $str); + $str = mb_ereg_replace(',', ' ', $str); + $str = mb_ereg_replace("\r\n", ' ', $str); + $str = mb_ereg_replace("\n", ' ', $str); + $str = mb_ereg_replace("\r", ' ', $str); + + $ostr = ''; + while ($ostr != $str) + { + $ostr = $str; + $str = mb_ereg_replace(' ', ' ', $str); + } + + $astr = mb_split(' ', $str); + $str = ''; + + ftsearch_load_ignores(); + for ($i = count($astr) - 1; $i >= 0; $i--) + { + // ignore? + if (array_search(mb_strtolower($astr[$i]), $ftsearch_ignores) !== false) + unset($astr[$i]); + else + { + if ($simple) + $astr[$i] = ftsearch_text2simple($astr[$i]); + + if ($astr[$i] == '') + unset($astr[$i]); + } + } + + return $astr; +} + +function ftsearch_load_ignores() +{ + global $ftsearch_ignores; + global $ftsearch_ignores_loaded; + + if ($ftsearch_ignores_loaded != true) + { + $ftsearch_ignores = array(); + + $rs = sql('SELECT `word` FROM `search_ignore`'); + while ($r = sql_fetch_assoc($rs)) + $ftsearch_ignores[] = $r['word']; + sql_free_result($rs); + + $ftsearch_ignores_loaded = true; + } +} + +// str = single word +function ftsearch_text2simple($str) +{ + global $ftsearch_simplerules; + + $str = ftsearch_text2sort($str); + + // regeln anwenden + foreach ($ftsearch_simplerules AS $rule) + { + $str = mb_ereg_replace($rule[0], $rule[1], $str); + } + + // doppelte chars ersetzen + for ($c = ord('a'); $c <= ord('z'); $c++) + { + $old_str = ''; + while ($old_str != $str) + { + $old_str = $str; + $str = mb_ereg_replace(chr($c) . chr($c), chr($c), $str); + } + $old_str = ''; + } + + return $str; +} + +// str = single word +function ftsearch_text2sort($str) +{ + $str = mb_strtolower($str); + + // deutsches + $str = mb_ereg_replace('ä', 'ae', $str); + $str = mb_ereg_replace('ö', 'oe', $str); + $str = mb_ereg_replace('ü', 'ue', $str); + $str = mb_ereg_replace('Ä', 'ae', $str); + $str = mb_ereg_replace('Ö', 'oe', $str); + $str = mb_ereg_replace('Ü', 'ue', $str); + $str = mb_ereg_replace('ß', 'ss', $str); + + // akzente usw. + $str = mb_ereg_replace('à', 'a', $str); + $str = mb_ereg_replace('á', 'a', $str); + $str = mb_ereg_replace('â', 'a', $str); + $str = mb_ereg_replace('è', 'e', $str); + $str = mb_ereg_replace('é', 'e', $str); + $str = mb_ereg_replace('ë', 'e', $str); + $str = mb_ereg_replace('É', 'e', $str); + $str = mb_ereg_replace('ô', 'o', $str); + $str = mb_ereg_replace('ó', 'o', $str); + $str = mb_ereg_replace('ò', 'o', $str); + $str = mb_ereg_replace('ê', 'e', $str); + $str = mb_ereg_replace('ě', 'e', $str); + $str = mb_ereg_replace('û', 'u', $str); + $str = mb_ereg_replace('ç', 'c', $str); + $str = mb_ereg_replace('c', 'c', $str); + $str = mb_ereg_replace('ć', 'c', $str); + $str = mb_ereg_replace('î', 'i', $str); + $str = mb_ereg_replace('ï', 'i', $str); + $str = mb_ereg_replace('ì', 'i', $str); + $str = mb_ereg_replace('í', 'i', $str); + $str = mb_ereg_replace('ł', 'l', $str); + $str = mb_ereg_replace('š', 's', $str); + $str = mb_ereg_replace('Š', 's', $str); + $str = mb_ereg_replace('u', 'u', $str); + $str = mb_ereg_replace('ý', 'y', $str); + $str = mb_ereg_replace('ž', 'z', $str); + $str = mb_ereg_replace('Ž', 'Z', $str); + + $str = mb_ereg_replace('Æ', 'ae', $str); + $str = mb_ereg_replace('æ', 'ae', $str); + $str = mb_ereg_replace('œ', 'oe', $str); + + // sonstiges + $str = mb_ereg_replace('[^A-Za-z ]', '', $str); + + return $str; +} + +function ftsearch_refresh() +{ + ftsearch_refresh_all_caches(); + ftsearch_refresh_all_cache_desc(); + ftsearch_refresh_all_pictures(); + ftsearch_refresh_all_cache_logs(); +} + +function ftsearch_refresh_all_caches() +{ + $rs = sql('SELECT `caches`.`cache_id` FROM `caches` LEFT JOIN `search_index_times` ON `caches`.`cache_id`=`search_index_times`.`object_id` AND 2=`search_index_times`.`object_type` WHERE `caches`.`status`!=5 AND ISNULL(`search_index_times`.`object_id`) UNION DISTINCT SELECT `caches`.`cache_id` FROM `caches` INNER JOIN `search_index_times` ON `search_index_times`.`object_type`=2 AND `caches`.`cache_id`=`search_index_times`.`object_id` WHERE `caches`.`last_modified`>`search_index_times`.`last_refresh` AND `caches`.`status`!=5'); + while ($r = sql_fetch_assoc($rs)) + ftsearch_refresh_cache($r['cache_id']); + sql_free_result($rs); +} + +function ftsearch_refresh_cache($cache_id) +{ + $rs = sql("SELECT `name`, `last_modified` FROM `caches` WHERE `cache_id`='&1'", $cache_id); + if ($r = sql_fetch_assoc($rs)) + { + ftsearch_set_entries(2, $cache_id, $cache_id, $r['name'], $r['last_modified']); + } + sql_free_result($rs); +} + +function ftsearch_refresh_all_cache_desc() +{ + $rs = sql('SELECT `cache_desc`.`id` FROM `cache_desc` INNER JOIN `caches` ON `caches`.`cache_id`=`cache_desc`.`cache_id` LEFT JOIN `search_index_times` ON `cache_desc`.`id`=`search_index_times`.`object_id` AND 3=`search_index_times`.`object_type` WHERE `caches`.`status`!=5 AND ISNULL(`search_index_times`.`object_id`) UNION DISTINCT SELECT `cache_desc`.`id` FROM `cache_desc` INNER JOIN `caches` ON `caches`.`cache_id`=`cache_desc`.`cache_id` INNER JOIN `search_index_times` ON `search_index_times`.`object_type`=3 AND `cache_desc`.`id`=`search_index_times`.`object_id` WHERE `cache_desc`.`last_modified`>`search_index_times`.`last_refresh` AND `caches`.`status`!=5'); + while ($r = sql_fetch_assoc($rs)) + ftsearch_refresh_cache_desc($r['id']); + sql_free_result($rs); +} + +function ftsearch_refresh_cache_desc($id) +{ + $rs = sql("SELECT `cache_id`, `desc`, `last_modified` FROM `cache_desc` WHERE `id`='&1'", $id); + if ($r = sql_fetch_assoc($rs)) + { + $r['desc'] = ftsearch_strip_html($r['desc']); + ftsearch_set_entries(3, $id, $r['cache_id'], $r['desc'], $r['last_modified']); + } + sql_free_result($rs); +} + +function ftsearch_refresh_all_pictures() +{ + $rs = sql('SELECT `pictures`.`id` FROM `pictures` LEFT JOIN `search_index_times` ON `pictures`.`id`=`search_index_times`.`object_id` AND 6=`search_index_times`.`object_type` WHERE ISNULL(`search_index_times`.`object_id`) UNION DISTINCT SELECT `pictures`.`id` FROM `pictures` INNER JOIN `search_index_times` ON `search_index_times`.`object_type`=6 AND `pictures`.`id`=`search_index_times`.`object_id` WHERE `pictures`.`last_modified`>`search_index_times`.`last_refresh`'); + while ($r = sql_fetch_assoc($rs)) + ftsearch_refresh_picture($r['id']); + sql_free_result($rs); +} + +function ftsearch_refresh_picture($id) +{ + $rs = sql("SELECT `caches`.`cache_id`, `pictures`.`title`, `pictures`.`last_modified` FROM `pictures` INNER JOIN `caches` ON `pictures`.`object_type`=2 AND `caches`.`cache_id`=`pictures`.`object_id` WHERE `pictures`.`id`='&1' UNION DISTINCT SELECT `cache_logs`.`cache_id` , `pictures`.`title`, `pictures`.`last_modified` FROM `pictures` INNER JOIN `cache_logs` ON `pictures`.`object_type`=1 AND `cache_logs`.`id`=`pictures`.`object_id` WHERE `pictures`.`id`='&1' LIMIT 1", $id); + if ($r = sql_fetch_assoc($rs)) + { + ftsearch_set_entries(6, $id, $r['cache_id'], $r['title'], $r['last_modified']); + } + sql_free_result($rs); +} + +function ftsearch_refresh_all_cache_logs() +{ + $rs = sql('SELECT `cache_logs`.`id` FROM `cache_logs` LEFT JOIN `search_index_times` ON `cache_logs`.`id`=`search_index_times`.`object_id` AND 1=`search_index_times`.`object_type` WHERE ISNULL(`search_index_times`.`object_id`) UNION DISTINCT SELECT `cache_logs`.`id` FROM `cache_logs` INNER JOIN `search_index_times` ON `search_index_times`.`object_type`=1 AND `cache_logs`.`id`=`search_index_times`.`object_id` WHERE `cache_logs`.`last_modified`>`search_index_times`.`last_refresh`'); + while ($r = sql_fetch_assoc($rs)) + ftsearch_refresh_cache_logs($r['id']); + sql_free_result($rs); +} + +function ftsearch_refresh_cache_logs($id) +{ + $rs = sql("SELECT `cache_id`, `text`, `last_modified` FROM `cache_logs` WHERE `id`='&1'", $id); + if ($r = sql_fetch_assoc($rs)) + { + $r['text'] = ftsearch_strip_html($r['text']); + ftsearch_set_entries(1, $id, $r['cache_id'], $r['text'], $r['last_modified']); + } + sql_free_result($rs); +} + +function ftsearch_delete_entries($object_type, $object_id, $cache_id) +{ + sql("DELETE FROM `search_index` WHERE `object_type`='&1' AND `cache_id`='&2'", $object_type, $cache_id); + sql("DELETE FROM `search_index_times` WHERE `object_type`='&1' AND `object_id`='&2'", $object_type, $object_id); +} + +function ftsearch_set_entries($object_type, $object_id, $cache_id, &$text, $last_modified) +{ + ftsearch_delete_entries($object_type, $object_id, $cache_id); + + $ahash = ftsearch_hash($text); + foreach ($ahash AS $k => $h) + { + sql("INSERT INTO `search_index` (`object_type`, `cache_id`, `hash`, `count`) VALUES ('&1', '&2', '&3', '&4') ON DUPLICATE KEY UPDATE `count`=`count`+1", $object_type, $cache_id, $h, 1); + } + sql("INSERT INTO `search_index_times` (`object_id`, `object_type`, `last_refresh`) VALUES ('&1', '&2', '&3') ON DUPLICATE KEY UPDATE `last_refresh`='&3'", $object_id, $object_type, $last_modified); +} + +function ftsearch_strip_html($text) +{ + $text = str_replace("\n", ' ', $text); + $text = str_replace("\r", ' ', $text); + $text = str_replace('
', ' ', $text); + $text = str_replace('
', ' ', $text); + $text = str_replace('
', ' ', $text); + $text = strip_tags($text); + $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8'); + + return $text; +} +?> diff --git a/htdocs/lib/search1/search.gpx.inc.php b/htdocs/lib/search1/search.gpx.inc.php new file mode 100644 index 00000000..55d4923a --- /dev/null +++ b/htdocs/lib/search1/search.gpx.inc.php @@ -0,0 +1,514 @@ + + + Cache listing generated from Opencaching.de + This is a waypoint file generated from Opencaching.de{wpchildren} + Opencaching.de + contact@opencaching.de + http://www.opencaching.de + Opencaching.de - Geocaching in Deutschland, Oesterreich und der Schweiz + + cache, geocache, opencaching, waypoint +'; + + $gpxLine = +' + + {waypoint} + {cachename} + www.opencaching.de + ' . $absolute_server_URI . 'viewcache.php?cacheid={cacheid} + {cachename} + {sym} + Geocache|{type} + + {cachename} + {owner} + {owner} + {type} + {container} + +{attributes} + {difficulty} + {terrain} + {country} + {state} + {shortdesc} + {desc}<br />{images} +{hints} +{logs} + +{geokrety} + + +{cache_waypoints}'; + /* Ocprop: + * + * '; + + $gpxTimeFormat = 'Y-m-d\TH:i:s\Z'; + + $gpxStatus[0] = 'available="False" archived="False"'; // other (unavailable, not archived) + $gpxStatus[1] = 'available="True" archived="False"'; //available, not archived + $gpxStatus[2] = 'available="False" archived="False"'; //unavailable, not archived + $gpxStatus[3] = 'available="False" archived="True"'; //unavailable, archived + $gpxStatus[6] = 'available="False" archived="True"'; //locked, visible + + $gpxContainer[0] = 'Other'; + $gpxContainer[2] = 'Micro'; + $gpxContainer[3] = 'Small'; + $gpxContainer[4] = 'Regular'; + $gpxContainer[5] = 'Large'; + $gpxContainer[6] = 'Large'; + $gpxContainer[7] = 'Virtual'; + $gpxContainer[8] = 'Micro'; + + // cache types known by gpx + $gpxType[0] = 'Unknown Cache'; + $gpxType[2] = 'Traditional Cache'; + $gpxType[3] = 'Multi-cache'; + $gpxType[4] = 'Virtual Cache'; + $gpxType[5] = 'Webcam Cache'; + $gpxType[6] = 'Event Cache'; + + // unknown ... converted + $gpxType[7] = 'Unknown Cache'; + $gpxType[8] = 'Unknown Cache'; + $gpxType[10] = 'Traditional Cache'; + + $gpxLogType[0] = 'Other'; + $gpxLogType[1] = 'Found it'; + $gpxLogType[2] = 'Didn\'t find it'; + $gpxLogType[3] = 'Write note'; + $gpxLogType[7] = 'Attended'; + $gpxLogType[8] = 'Will attend'; + $gpxLogType[9] = 'Archive'; + $gpxLogType[10] = 'Owner Maintenance'; + $gpxLogType[11] = 'Temporarily Disable Listing'; + $gpxLogType[13] = 'Archive'; + $gpxLogType[14] = 'Archive'; + + $gpxSymNormal = 'Geocache'; + $gpxSymFound = 'Geocache Found'; + + $childwphandler = new ChildWp_Handler(); + $children=''; + $rs = sql('SELECT `searchtmp`.`cache_id` `cacheid` FROM `searchtmp`'); + while ($r = sql_fetch_array($rs)) + if (count($childwphandler->getChildWps($r['cacheid']))) + $children=" (HasChildren)"; + mysql_free_result($rs); + + $gpxHead = mb_ereg_replace('{wpchildren}', $children, $gpxHead); + $gpxHead = mb_ereg_replace('{time}', date($gpxTimeFormat, time()), $gpxHead); + append_output($gpxHead); + + if ($usr === false) + $user_id = 0; + else + $user_id = $usr['userid']; + + $rs = sql_slave("SELECT SQL_BUFFER_RESULT `searchtmp`.`cache_id` `cacheid`, `searchtmp`.`longitude` `longitude`, `searchtmp`.`latitude` `latitude`, + `cache_location`.`adm2` `state`, `caches`.`wp_oc` `waypoint`, `caches`.`date_hidden` `date_hidden`, `caches`.`name` `name`, + `caches`.`country` `country`, `countries`.`name` AS `country_name`, `caches`.`terrain` `terrain`, `caches`.`difficulty` `difficulty`, `caches`.`desc_languages` `desc_languages`, + `caches`.`size` `size`, `caches`.`type` `type`, `caches`.`status` `status`, `user`.`username` `username`, `caches`.`user_id` `userid`, `user`.`data_license`, + `cache_desc`.`desc` `desc`, `cache_desc`.`short_desc` `short_desc`, `cache_desc`.`hint` `hint`, + IFNULL(`stat_cache_logs`.`found`, 0) AS `found` + FROM `searchtmp` + INNER JOIN `caches` ON `searchtmp`.`cache_id`=`caches`.`cache_id` + INNER JOIN `countries` ON `caches`.`country`=`countries`.`short` + INNER JOIN `user` ON `searchtmp`.`user_id`=`user`.`user_id` + INNER JOIN `cache_desc` ON `caches`.`cache_id`=`cache_desc`.`cache_id`AND `caches`.`default_desclang`=`cache_desc`.`language` + LEFT JOIN `cache_location` ON `searchtmp`.`cache_id`=`cache_location`.`cache_id` + LEFT JOIN `stat_cache_logs` ON `searchtmp`.`cache_id`=`stat_cache_logs`.`cache_id` AND `stat_cache_logs`.`user_id`='&1'", $user_id); + + while ($r = sql_fetch_array($rs)) + { + $thisline = $gpxLine; + + $lat = sprintf('%01.5f', $r['latitude']); + $thisline = mb_ereg_replace('{lat}', $lat, $thisline); + + $lon = sprintf('%01.5f', $r['longitude']); + $thisline = mb_ereg_replace('{lon}', $lon, $thisline); + + $time = date($gpxTimeFormat, strtotime($r['date_hidden'])); + $thisline = mb_ereg_replace('{time}', $time, $thisline); + $thisline = mb_ereg_replace('{waypoint}', $r['waypoint'], $thisline); + $thisline = mb_ereg_replace('{cacheid}', $r['cacheid'], $thisline); + $thisline = mb_ereg_replace('{cachename}', xmlentities($r['name']), $thisline); + $thisline = mb_ereg_replace('{country}', $r['country_name'], $thisline); + $thisline = mb_ereg_replace('{state}', xmlentities($r['state']), $thisline); + + if ($r['hint'] == '') + $thisline = mb_ereg_replace('{hints}', '', $thisline); + else + // Ocprop: (.*?)<\/groundspeak:encoded_hints> + $hint = html_entity_decode(strip_tags($r['hint']), ENT_COMPAT, "UTF-8"); + $thisline = mb_ereg_replace('{hints}', ' ' . xmlentities($hint) . ' +', $thisline); + + $thisline = mb_ereg_replace('{shortdesc}', xmlentities($r['short_desc']), $thisline); + + $desc = str_replace(' 0) + $thisline = mb_ereg_replace('{sym}', xmlentities($gpxSymFound), $thisline); + else + $thisline = mb_ereg_replace('{sym}', xmlentities($gpxSymNormal), $thisline); + + // clear cache specific data + $logentries = ''; + $cache_note = false; + $attribentries = ''; + $waypoints = ''; + $gkentries = ''; + + // fetch logs + + if ($user_id != 0) + { + // insert personal note + $cacheNote = getCacheNote($user_id, $r['cacheid']); + if ($cacheNote) + { + $thislog = $gpxLog; + + $thislog = mb_ereg_replace('{id}', 0, $thislog); + $thislog = mb_ereg_replace('{date}', date($gpxTimeFormat), $thislog); + $thislog = mb_ereg_replace('{userid}', $user_id, $thislog); + $thislog = mb_ereg_replace('{username}', xmlentities($login->username), $thislog); + $thislog = mb_ereg_replace('{type}', $gpxLogType[3], $thislog); + $thislog = mb_ereg_replace('{text}', xmlentities($cacheNote['note']), $thislog); + + $logentries .= $thislog . "\n"; + } + + // current users logs + $rsLogs = sql_slave("SELECT `cache_logs`.`id`, `cache_logs`.`type`, `cache_logs`.`date`, `cache_logs`.`text`, `user`.`username`, `user`.`user_id` FROM `cache_logs`, `user` WHERE `cache_logs`.`user_id`=`user`.`user_id` AND `cache_logs`.`cache_id`=&1 AND `user`.`user_id`=&2 ORDER BY `cache_logs`.`date` DESC", $r['cacheid'], $user_id); + while ($rLog = sql_fetch_array($rsLogs)) + { + $thislog = $gpxLog; + + $thislog = mb_ereg_replace('{id}', $rLog['id'], $thislog); + $thislog = mb_ereg_replace('{date}', date($gpxTimeFormat, strtotime($rLog['date'])), $thislog); + $thislog = mb_ereg_replace('{userid}', xmlentities($rLog['user_id']), $thislog); + $thislog = mb_ereg_replace('{username}', xmlentities($rLog['username']), $thislog); + + if (isset($gpxLogType[$rLog['type']])) + $logtype = $gpxLogType[$rLog['type']]; + else + $logtype = $gpxLogType[0]; + + $thislog = mb_ereg_replace('{type}', $logtype, $thislog); + $thislog = mb_ereg_replace('{text}', xmlentities(decodeEntities($rLog['text'])), $thislog); + + $logentries .= $thislog . "\n"; + } + mysql_free_result($rsLogs); + } + + // newest 20 logs (except current users) + $rsLogs = sql_slave("SELECT `cache_logs`.`id`, `cache_logs`.`type`, `cache_logs`.`date`, `cache_logs`.`text`, `user`.`username`, `user`.`user_id` FROM `cache_logs`, `user` WHERE `cache_logs`.`user_id`=`user`.`user_id` AND `cache_logs`.`cache_id`=&1 AND `user`.`user_id`!=&2 ORDER BY `cache_logs`.`date` DESC LIMIT 20", $r['cacheid'], $user_id); + while ($rLog = sql_fetch_array($rsLogs)) + { + $thislog = $gpxLog; + + $thislog = mb_ereg_replace('{id}', $rLog['id'], $thislog); + $thislog = mb_ereg_replace('{date}', date($gpxTimeFormat, strtotime($rLog['date'])), $thislog); + $thislog = mb_ereg_replace('{userid}', xmlentities($rLog['user_id']), $thislog); + $thislog = mb_ereg_replace('{username}', xmlentities($rLog['username']), $thislog); + + if (isset($gpxLogType[$rLog['type']])) + $logtype = $gpxLogType[$rLog['type']]; + else + $logtype = $gpxLogType[0]; + + $thislog = mb_ereg_replace('{type}', $logtype, $thislog); + $thislog = mb_ereg_replace('{text}', xmlentities(decodeEntities($rLog['text'])), $thislog); + + $logentries .= $thislog . "\n"; + } + mysql_free_result($rsLogs); + $thisline = mb_ereg_replace('{logs}', $logentries, $thisline); + + // attributes + $rsAttributes = sql_slave("SELECT `gc_id`, `gc_inc`, `gc_name` + FROM `caches_attributes` + INNER JOIN `cache_attrib` ON `cache_attrib`.`id`=`caches_attributes`.`attrib_id` + WHERE `caches_attributes`.`cache_id`=&1", $r['cacheid']); + $gc_ids = array(); + while ($rAttrib = sql_fetch_array($rsAttributes)) + { + // Multiple OC attributes can be mapped to one GC attribute, either with + // the same "inc"s or with different. Both may disturb applications, so we + // output each GC ID only once. + if (!isset($gc_ids[$rAttrib['gc_id']])) + { + $thisattribute = mb_ereg_replace('{attrib_id}', $rAttrib['gc_id'], $gpxAttributes); + $thisattribute = mb_ereg_replace('{attrib_inc}', $rAttrib['gc_inc'], $thisattribute); + $thisattribute = mb_ereg_replace('{attrib_name}', xmlentities($rAttrib['gc_name']), $thisattribute); + $attribentries .= $thisattribute . "\n"; + $gc_ids[$rAttrib['gc_id']] = true; + } + } + + mysql_free_result($rsAttributes); + $thisline = mb_ereg_replace('{attributes}', $attribentries, $thisline); + + // geokrety + $rsGeokrety = sql_slave("SELECT `gk_item`.`id`, `gk_item`.`name`, `caches`.`wp_oc` FROM `gk_item` INNER JOIN `gk_item_waypoint` ON `gk_item`.`id`=`gk_item_waypoint`.`id` INNER JOIN `caches` ON `gk_item_waypoint`.`wp`=`caches`.`wp_oc` WHERE `caches`.`cache_id`=&1", $r['cacheid']); + while ($rGK = sql_fetch_array($rsGeokrety)) + { + $thiskrety = $gpxGeokrety; + + $thiskrety = mb_ereg_replace('{gkid}', $rGK['id'], $thiskrety); + $thiskrety = mb_ereg_replace('{gkref}', sprintf("GK%04X",$rGK['id']), $thiskrety); + $thiskrety = mb_ereg_replace('{gkname}', xmlentities($rGK['name']), $thiskrety); + + $gkentries .= $thiskrety . "\n"; + } + mysql_free_result($rsGeokrety); + $thisline = mb_ereg_replace('{geokrety}', $gkentries, $thisline); + + // additional waypoints, including personal cache note + $childWaypoints = $childwphandler->getChildWps($r['cacheid']); + $n = 1; + $digits = "%0" . strlen(count($childWaypoints)) . "d"; + + foreach ($childWaypoints as $childWaypoint) + { + $thiswp = $gpxWaypoints; + $thiswp = mb_ereg_replace('{wp_lat}', sprintf('%01.5f', $childWaypoint['latitude']), $thiswp); + $thiswp = mb_ereg_replace('{wp_lon}', sprintf('%01.5f', $childWaypoint['longitude']), $thiswp); + $thiswp = mb_ereg_replace('{time}', $time, $thiswp); + $thiswp = mb_ereg_replace('{name}', $r['waypoint'].'-'.sprintf($digits,$n) , $thiswp); + $thiswp = mb_ereg_replace('{cachename}', xmlentities($r['name']), $thiswp); + $thiswp = mb_ereg_replace('{comment}',xmlentities($childWaypoint['description']), $thiswp); + $thiswp = mb_ereg_replace('{desc}', xmlentities($childWaypoint['name']), $thiswp); + switch ($childWaypoint['type']) + { + case 1: $wp_typename = "Parking Area"; break; // well-known garmin symbols + case 2: $wp_typename = "Flag, Green"; break; // stage / ref point + case 3: $wp_typename = "Flag, Blue"; break; // path + case 4: $wp_typename = "Circle with X"; break; // final + case 5: $wp_typename = "Diamond, Green"; break; // point of interest + default: $wp_typename = "Flag, Blue"; break; // for the case new types are forgotten here .. + } + $thiswp = mb_ereg_replace('{type}', $wp_typename, $thiswp); + $thiswp = mb_ereg_replace('{parent}', $r['waypoint'], $thiswp); + $thiswp = mb_ereg_replace('{cacheid}', $r['cacheid'], $thiswp); + $waypoints .= $thiswp; + ++$n; + } + + if ($cacheNote && !empty($cacheNote['latitude']) && !empty($cacheNote['longitude'])) + { + $thiswp = $gpxWaypoints; + $thiswp = mb_ereg_replace('{wp_lat}', sprintf('%01.5f', $cacheNote['latitude']), $thiswp); + $thiswp = mb_ereg_replace('{wp_lon}', sprintf('%01.5f', $cacheNote['longitude']), $thiswp); + $thiswp = mb_ereg_replace('{time}', $time, $thiswp); + $thiswp = mb_ereg_replace('{name}', $r['waypoint'].'NOTE', $thiswp); + $thiswp = mb_ereg_replace('{cachename}', xmlentities($r['name']), $thiswp); + $thiswp = mb_ereg_replace('{comment}', xmlentities($cacheNote['note']), $thiswp); + $thiswp = mb_ereg_replace('{desc}', $cache_note_text, $thiswp); + $thiswp = mb_ereg_replace('{type}', "Reference Point", $thiswp); + $thiswp = mb_ereg_replace('{parent}', $r['waypoint'], $thiswp); + $thiswp = mb_ereg_replace('{cacheid}', $r['cacheid'], $thiswp); + $waypoints .= $thiswp; + } + + $thisline = mb_ereg_replace('{cache_waypoints}', $waypoints, $thisline); + + append_output($thisline); + } + mysql_free_result($rs); + + append_output($gpxFoot); +} + + + function decodeEntities($str) + { + $str = changePlaceholder($str); + $str = html_entity_decode($str, ENT_COMPAT, "UTF-8"); + $str = changePlaceholder($str, true); + return $str; + } + + function changePlaceholder($str, $inverse = false) + { + static $translate = array( + '<' => '{oc-placeholder-lt}', + '>' => '{oc-placeholder-gt}', + '&' => '{oc-placeholder-amp}' + ); + + foreach ($translate as $entity => $placeholder) + { + if (!$inverse) + { + $str = mb_ereg_replace($entity, $placeholder, $str); + } + else + { + $str = mb_ereg_replace($placeholder, $entity, $str); + } + } + return $str; + } + + function xmlentities($str) + { + $str = htmlspecialchars($str, ENT_NOQUOTES, "UTF-8"); + return filterevilchars($str); + } + + function filterevilchars($str) + { + return mb_ereg_replace('[\\x00-\\x09|\\x0B-\\x0C|\\x0E-\\x1F]', '', $str); + } + + function getCacheNote($userid, $cacheid) + { + $cacheNoteHandler = new CacheNote_Handler(); + $cacheNote = $cacheNoteHandler->getCacheNote($userid, $cacheid); + + if (isset($cacheNote['note']) || isset($cacheNote['latitude']) || isset($cacheNote['longitude'])) + return $cacheNote; + + return null; + } + + // based on oc.pl code, but embedded thumbs instead of full pictures + // (also to hide spoilers first) + function getPictures($cacheid) + { + global $translate, $absolute_server_URI; + + $retval = ""; + $rs = sql_slave("SELECT uuid, title, url, spoiler FROM pictures + WHERE object_id='&1' AND object_type=2 AND display=1 + ORDER BY date_created", $cacheid); + + while ($r = sql_fetch_array($rs)) + { + $retval .= '
' . + '' . + '
' . $r['title']; + if ($r['spoiler']) + $retval .= ' (' . $translate->t('click on spoiler to display','',basename(__FILE__), __LINE__) . ')'; + $retval .= "
"; + } + mysql_free_result($rs); + + return $retval; + } + +?> diff --git a/htdocs/lib/search1/search.html.inc.php b/htdocs/lib/search1/search.html.inc.php new file mode 100644 index 00000000..bb70526e --- /dev/null +++ b/htdocs/lib/search1/search.html.inc.php @@ -0,0 +1,262 @@ +'; + $tmpline = mb_ereg_replace('{logimage1}', + $loglink . icon_log_type($row['icon_small'], ""). '{gray_s}' . $loglink. date($logdateformat, strtotime($row['date'])) . '{gray_e}', $tmpline); + $tmpline = mb_ereg_replace('{logdate1}', "", $tmpline); + } + else + { + $tmpline = mb_ereg_replace('{logimage1}', "", $tmpline); + $tmpline = mb_ereg_replace('{logdate1}', "--.--.----", $tmpline); + } + + $lastlogs = ""; + while ($row = sql_fetch_array($result)) + { + $lastlogs .= '' . icon_log_type($row['icon_small'], '') . ' '; + } + $tmpline = mb_ereg_replace('{lastlogs}', $lastlogs, $tmpline); + + // und jetzt noch die Richtung ... + if ($caches_record['distance'] > 0) + { + $tmpline = mb_ereg_replace('{direction}', Bearing2Text(calcBearing($lat_rad / 3.14159 * 180, $lon_rad / 3.14159 * 180, $caches_record['latitude'], $caches_record['longitude']), 1), $tmpline); + } + else + $tmpline = mb_ereg_replace('{direction}', '', $tmpline); + + $desclangs = ''; + $aLangs = mb_split(',', $caches_record['desc_languages']); + foreach ($aLangs AS $thislang) + { + $desclangs .= '' . htmlspecialchars($thislang, ENT_COMPAT, 'UTF-8') . ' '; + } + + // strikeout inavtive caches + // see also res_cachestatus_span.tpl + $status_style = ""; // (colored) strike-through for inactive caches + $line_style = ""; // color of the linked cache name + $name_style = ""; // color of "by " + switch ($caches_record['status']) + { + case 2: // disabled + $status_style = "text-decoration: line-through;"; + break; + case 3: // archived + case 6: // locked + $status_style = "text-decoration: line-through; color: #c00000;"; + // $line_style = "color:grey"; + break; + case 7: // locked, invisible + $status_style = "text-decoration: line-through; color: #e00000"; + $name_style = "color: #e00000"; + // $line_style = "color:grey"; + break; + case 5: // not published yet + $name_style = "color: #e00000"; + break; + default: $status_style = $line_style = ""; + } + + $tmpline = mb_ereg_replace('{line_style}', $line_style, $tmpline); + $tmpline = mb_ereg_replace('{status_style}', $status_style, $tmpline); + $tmpline = mb_ereg_replace('{name_style}', $name_style, $tmpline); + $tmpline = mb_ereg_replace('{desclangs}', $desclangs, $tmpline); + $tmpline = mb_ereg_replace('{cachename}', htmlspecialchars($caches_record['name'], ENT_COMPAT, 'UTF-8'), $tmpline); + $tmpline = mb_ereg_replace('{urlencode_cacheid}', htmlspecialchars(urlencode($caches_record['cache_id']), ENT_COMPAT, 'UTF-8'), $tmpline); + $tmpline = mb_ereg_replace('{urlencode_userid}', htmlspecialchars(urlencode($caches_record['user_id']), ENT_COMPAT, 'UTF-8'), $tmpline); + $tmpline = mb_ereg_replace('{username}', htmlspecialchars($caches_record['username'], ENT_COMPAT, 'UTF-8'), $tmpline); + $tmpline = mb_ereg_replace('{position}', $nRowIndex + $startat + 1, $tmpline); + + if ($caches_record['distance'] == NULL) + $tmpline = mb_ereg_replace('{distance}', '', $tmpline); + else + $tmpline = mb_ereg_replace('{distance}', htmlspecialchars(sprintf("%01.1f", $caches_record['distance']), ENT_COMPAT, 'UTF-8'), $tmpline); + + // backgroundcolor of line + if (($nRowIndex % 2) == 1) $bgcolor = $bgcolor2; + else $bgcolor = $bgcolor1; + + if ($inactive) + { + //$bgcolor = $bgcolor_inactive; + $tmpline = mb_ereg_replace('{gray_s}', "", $tmpline); + $tmpline = mb_ereg_replace('{gray_e}', "", $tmpline); + } + else + { + $tmpline = mb_ereg_replace('{gray_s}', "", $tmpline); + $tmpline = mb_ereg_replace('{gray_e}', "", $tmpline); + } + + $tmpline = mb_ereg_replace('{bgcolor}', $bgcolor, $tmpline); + + $nRowIndex++; + $caches_output .= $tmpline; + } + mysql_free_result($rs_caches); + + tpl_set_var('results', $caches_output); + + // more than one page? + if ($resultcount <= $caches_per_page) + $pages = ''; + else + { + if ($startat > 0) // Ocprop: queryid=([0-9]+) + $pages = ' '; + else + $pages = ' '; + + $frompage = ($startat / $caches_per_page) - 3; + if ($frompage < 1) $frompage = 1; + $maxpage = ceil($resultcount / $caches_per_page); + $topage = $frompage + 8; + if ($topage > $maxpage) $topage = $maxpage; + + for ($i = $frompage; $i <= $topage; $i++) + { + if (($startat / $caches_per_page + 1) == $i) + $pages .= ' ' . $i . ''; + else + $pages .= ' ' . $i . ''; + } + + if ($startat / $caches_per_page < ($maxpage - 1)) + $pages .= ' '; + else + $pages .= ' '; + } + + //'20 40 60 80 100'; + //$caches_per_page + //count($caches) - 1 + tpl_set_var('pages', $pages); + tpl_set_var('showonmap', $showonmap); + + // downloads + tpl_set_var('queryid', $options['queryid']); + tpl_set_var('startat', $startat); + + tpl_set_var('startatp1', min($resultcount,$startat + 1)); + + if (($resultcount - $startat) < 500) + tpl_set_var('endat', $startat + $resultcount - $startat); + else + tpl_set_var('endat', $startat + 500); + + // kompatibilität! + if ($distance_unit == 'sm') + tpl_set_var('distanceunit', 'mi'); + else if ($distance_unit == 'nm') + tpl_set_var('distanceunit', 'sm'); + else + tpl_set_var('distanceunit', $distance_unit); + + tpl_set_var('displaylastlogs', $options['sort'] == 'bymylastlog' ? 'none' : 'inline'); + tpl_set_var('displayownlogs', $options['sort'] == 'bymylastlog' ? 'inline' : 'none'); + + if ($sqldebug == true) + sqldbg_end(); + else + tpl_BuildTemplate(); +} + +?> \ No newline at end of file diff --git a/htdocs/lib/search1/search.inc.php b/htdocs/lib/search1/search.inc.php new file mode 100644 index 00000000..1626123d --- /dev/null +++ b/htdocs/lib/search1/search.inc.php @@ -0,0 +1,153 @@ + \ No newline at end of file diff --git a/htdocs/lib/search1/search.kml.inc.php b/htdocs/lib/search1/search.kml.inc.php new file mode 100644 index 00000000..84cc9ab8 --- /dev/null +++ b/htdocs/lib/search1/search.kml.inc.php @@ -0,0 +1,213 @@ + + Beschreibung ansehen
Von {username}
 
{typeimgurl} Art: {type}
Größe: {size}
Schwierigkeit: {difficulty} von 5.0
Gelände: {terrain} von 5.0
]]>
+ {name}{archivedflag} + + {lon} + {lat} + 5000 + 0 + 3 + + #{icon} + + {lon},{lat},0 + + D: {difficulty}/T: {terrain} {size} von {username} + +'; + + $kmlFoot = '
'; + + $kmlTimeFormat = 'Y-m-d\TH:i:s\Z'; + $kmlDetailHead = read_file($stylepath . '/search.result.caches.kml.head.tpl.php'); + + $rsMinMax = sql_slave(' + SELECT + MIN(`longitude`) `minlon`, + MAX(`longitude`) `maxlon`, + MIN(`latitude`) `minlat`, + MAX(`latitude`) `maxlat` + FROM + `searchtmp`', $sqldebug); + $rMinMax = sql_fetch_array($rsMinMax); + mysql_free_result($rsMinMax); + + $kmlDetailHead = mb_ereg_replace('{minlat}', $rMinMax['minlat'], $kmlDetailHead); + $kmlDetailHead = mb_ereg_replace('{minlon}', $rMinMax['minlon'], $kmlDetailHead); + $kmlDetailHead = mb_ereg_replace('{maxlat}', $rMinMax['maxlat'], $kmlDetailHead); + $kmlDetailHead = mb_ereg_replace('{maxlon}', $rMinMax['maxlon'], $kmlDetailHead); + $kmlDetailHead = mb_ereg_replace('{time}', date($kmlTimeFormat), $kmlDetailHead); + + append_output($kmlDetailHead); + + /* + wp + name + username + type + size + lon + lat + icon + */ + + $rs = sql_slave(' + SELECT SQL_BUFFER_RESULT + `searchtmp`.`cache_id` `cacheid`, + `searchtmp`.`longitude`, + `searchtmp`.`latitude`, + `searchtmp`.`type`, + `caches`.`date_hidden`, + `caches`.`name`, + `caches`.`status`, + `cache_type`.`de` `typedesc`, + `cache_size`.`de` `sizedesc`, + `caches`.`terrain`, + `caches`.`difficulty`, + `user`.`username` + FROM + `searchtmp`, + `caches`, + `cache_type`, + `cache_size`, + `user` + WHERE + `searchtmp`.`cache_id`=`caches`.`cache_id` AND + `searchtmp`.`type`=`cache_type`.`id` AND + `searchtmp`.`size`=`cache_size`.`id` AND + `searchtmp`.`user_id`=`user`.`user_id`', + $sqldebug); + + while ($r = sql_fetch_array($rs)) + { + $thisline = $kmlLine; + + // icon suchen + switch ($r['type']) + { + case 2: + $icon = 'tradi'; + $typeimgurl = 'Normaler Cache'; + break; + case 3: + $icon = 'multi'; + $typeimgurl = 'Multicache'; + break; + case 4: + $icon = 'virtual'; + $typeimgurl = 'virtueller Cache'; + break; + case 5: + $icon = 'webcam'; + $typeimgurl = 'Webcam Cache'; + break; + case 6: + $icon = 'event'; + $typeimgurl = 'Event Cache'; + break; + case 7: + $icon = 'mystery'; + $typeimgurl = 'Rätselcache'; + break; + case 8: + $icon = 'mathe'; + $typeimgurl = 'Mathe-/Physik-Cache'; + break; + case 9: + $icon = 'moving'; + $typeimgurl = 'Moving Cache'; + break; + case 10: + $icon = 'drivein'; + $typeimgurl = 'Drive-In Cache'; + break; + default: + $icon = 'other'; + $typeimgurl = 'unbekannter Cachetyp'; + break; + } + $thisline = mb_ereg_replace('{icon}', $icon, $thisline); + $thisline = mb_ereg_replace('{typeimgurl}', $typeimgurl, $thisline); + + $lat = sprintf('%01.5f', $r['latitude']); + $thisline = mb_ereg_replace('{lat}', $lat, $thisline); + + $lon = sprintf('%01.5f', $r['longitude']); + $thisline = mb_ereg_replace('{lon}', $lon, $thisline); + + $time = date($kmlTimeFormat, strtotime($r['date_hidden'])); + $thisline = mb_ereg_replace('{time}', $time, $thisline); + + $thisline = mb_ereg_replace('{name}', xmlentities($r['name']), $thisline); + + if (($r['status'] == 2) || ($r['status'] == 3) || ($r['status'] == 6)) + { + if ($r['status'] == 2) + $thisline = mb_ereg_replace('{archivedflag}', ' ('.$state_temporarily_na.')', $thisline); + elseif ($r['status'] == 3) + $thisline = mb_ereg_replace('{archivedflag}', ' ('.$state_archived.')', $thisline); + else + $thisline = mb_ereg_replace('{archivedflag}', ' ('.$state_locked.')', $thisline); + } + else + $thisline = mb_ereg_replace('{archivedflag}', '', $thisline); + + $thisline = mb_ereg_replace('{type}', xmlentities($r['typedesc']), $thisline); + $thisline = mb_ereg_replace('{size}', xmlentities($r['sizedesc']), $thisline); + + $difficulty = sprintf('%01.1f', $r['difficulty'] / 2); + $thisline = mb_ereg_replace('{difficulty}', $difficulty, $thisline); + + $terrain = sprintf('%01.1f', $r['terrain'] / 2); + $thisline = mb_ereg_replace('{terrain}', $terrain, $thisline); + + $time = date($kmlTimeFormat, strtotime($r['date_hidden'])); + $thisline = mb_ereg_replace('{time}', $time, $thisline); + + $thisline = mb_ereg_replace('{username}', xmlentities($r['username']), $thisline); + $thisline = mb_ereg_replace('{cacheid}', xmlentities($r['cacheid']), $thisline); + + append_output($thisline); + } + mysql_free_result($rs); + + append_output($kmlFoot); +} + + + function xmlentities($str) + { + $from[0] = '&'; $to[0] = '&'; + $from[1] = '<'; $to[1] = '<'; + $from[2] = '>'; $to[2] = '>'; + $from[3] = '"'; $to[3] = '"'; + $from[4] = '\''; $to[4] = '''; + + for ($i = 0; $i <= 4; $i++) + $str = mb_ereg_replace($from[$i], $to[$i], $str); + + return $str; + } + +?> \ No newline at end of file diff --git a/htdocs/lib/search1/search.loc.inc.php b/htdocs/lib/search1/search.loc.inc.php new file mode 100644 index 00000000..6484d3d5 --- /dev/null +++ b/htdocs/lib/search1/search.loc.inc.php @@ -0,0 +1,111 @@ +' . "\n"; + + $locLine = +' + + + + Geocache + http://www.opencaching.de/viewcache.php?cacheid={cacheid} + +'; + + $locFoot = ''; + + append_output($locHead); + + /* + {waypoint} + status -> {archivedflag} + {name} + {username} + {lon} + {lat} + {cacheid} + */ + + $rs = sql_slave(' + SELECT SQL_BUFFER_RESULT + `searchtmp`.`cache_id` `cacheid`, + `searchtmp`.`longitude`, + `searchtmp`.`latitude`, + `caches`.`name`, + `caches`.`status`, + `caches`.`wp_oc` `waypoint`, + `user`.`username` `username` + FROM + `searchtmp`, + `caches`, + `user` + WHERE + `searchtmp`.`cache_id`=`caches`.`cache_id` AND + `searchtmp`.`user_id`=`user`.`user_id`'); + + while ($r = sql_fetch_array($rs)) + { + $thisline = $locLine; + + $lat = sprintf('%01.5f', $r['latitude']); + $thisline = mb_ereg_replace('{lat}', $lat, $thisline); + + $lon = sprintf('%01.5f', $r['longitude']); + $thisline = mb_ereg_replace('{lon}', $lon, $thisline); + + $thisline = mb_ereg_replace('{waypoint}', $r['waypoint'], $thisline); + $thisline = mb_ereg_replace('{name}', xmlentities($r['name']), $thisline); + + if (($r['status'] == 2) || ($r['status'] == 3) || ($r['status'] == 6)) + { + if ($r['status'] == 2) + $thisline = mb_ereg_replace('{archivedflag}', $state_temporarily_na.'!, ', $thisline); + elseif ($r['status'] == 3) + $thisline = mb_ereg_replace('{archivedflag}', $state_archived.'!, ', $thisline); + else + $thisline = mb_ereg_replace('{archivedflag}', $state_locked.'!, ', $thisline); + } + else + $thisline = mb_ereg_replace('{archivedflag}', '', $thisline); + + $thisline = mb_ereg_replace('{username}', xmlentities($r['username']), $thisline); + $thisline = mb_ereg_replace('{cacheid}', $r['cacheid'], $thisline); + + append_output($thisline); + } + mysql_free_result($rs); + + append_output($locFoot); +} + + + function xmlentities($str) + { + $from[0] = '&'; $to[0] = '&'; + $from[1] = '<'; $to[1] = '<'; + $from[2] = '>'; $to[2] = '>'; + $from[3] = '"'; $to[3] = '"'; + $from[4] = '\''; $to[4] = '''; + + for ($i = 0; $i <= 4; $i++) + $str = mb_ereg_replace($from[$i], $to[$i], $str); + + return $str; + } + +?> diff --git a/htdocs/lib/search1/search.map2.inc.php b/htdocs/lib/search1/search.map2.inc.php new file mode 100644 index 00000000..97bb4a85 --- /dev/null +++ b/htdocs/lib/search1/search.map2.inc.php @@ -0,0 +1,72 @@ +NOW() AND `sqlquery`='&3'", $sqlchecksum, $opt['map']['maxcacheage'], $sqlFilter); + if ($rMapCache = sql_fetch_assoc($rsMapCache)) + { + $resultId = $rMapCache['result_id']; + sql("UPDATE `map2_result` SET `shared_counter`=`shared_counter`+1 WHERE `result_id`='" . ($resultId+0) . "'"); + } + else + { + db_connect_anyslave(); + + // ensure that query is performed without errors before reserving the result_id + sql_slave("CREATE TEMPORARY TABLE `tmpmapresult` (`cache_id` INT UNSIGNED NOT NULL, PRIMARY KEY (`cache_id`)) ENGINE=MEMORY"); + sql_slave("INSERT INTO `tmpmapresult` (`cache_id`) " . $sqlFilter); + + sql("INSERT INTO `map2_result` (`slave_id`, `sqlchecksum`, `sqlquery`, `date_created`, `date_lastqueried`) VALUES ('&1', '&2', '&3', NOW(), NOW())", $dbslaveid, $sqlchecksum, $cachesFilter."\n".$sqlFilter); + $resultId = mysql_insert_id($dblink); + + sql_slave("INSERT IGNORE INTO `map2_data` (`result_id`, `cache_id`) SELECT '&1', `cache_id` FROM `tmpmapresult`", $resultId); + sql_slave("DROP TEMPORARY TABLE `tmpmapresult`"); + } + + if ($map2_bounds) + { + $rs = sql_slave("SELECT MIN(`latitude`) AS `lat_min`, + MAX(`latitude`) AS `lat_max`, + MIN(`longitude`) AS `lon_min`, + MAX(`longitude`) AS `lon_max` + FROM `map2_data`, `caches` + WHERE `result_id`='&1' + AND `caches`.`cache_id`=`map2_data`.`cache_id`", + $resultId); + if (($rBounds = sql_fetch_assoc($rs)) && $rBounds['lat_min'] !== null /* >0 caches */) + { + if ($rBounds['lat_min'] == $rBounds['lat_max'] && + $rBounds['lon_min'] == $rBounds['lon_max']) // 1 Cache + { + $halfwin = 0.02; + $rBounds['lat_min'] -= $halfwin; + $rBounds['lat_max'] += $halfwin; + $rBounds['lon_min'] -= $halfwin; + $rBounds['lon_max'] += $halfwin; + } + $bounds_param = "&lat_min=" . round($rBounds['lat_min'],5) . "&lat_max=" . round($rBounds['lat_max'],5) . '&lon_min=' . round($rBounds['lon_min'],5) . '&lon_max=' . round($rBounds['lon_max'],5); + } + sql_free_result($rs); + + tpl_redirect('map2.php?queryid=' . $options['queryid'] . '&resultid=' . $resultId . $bounds_param); + } + else + echo $resultId; + + exit; +?> \ No newline at end of file diff --git a/htdocs/lib/search1/search.ov2.inc.php b/htdocs/lib/search1/search.ov2.inc.php new file mode 100644 index 00000000..749de4a3 --- /dev/null +++ b/htdocs/lib/search1/search.ov2.inc.php @@ -0,0 +1,87 @@ + \ No newline at end of file diff --git a/htdocs/lib/search1/search.ovl.inc.php b/htdocs/lib/search1/search.ovl.inc.php new file mode 100644 index 00000000..5999b9e9 --- /dev/null +++ b/htdocs/lib/search1/search.ovl.inc.php @@ -0,0 +1,78 @@ + \ No newline at end of file diff --git a/htdocs/lib/search1/search.txt.inc.php b/htdocs/lib/search1/search.txt.inc.php new file mode 100644 index 00000000..cc4e2d4d --- /dev/null +++ b/htdocs/lib/search1/search.txt.inc.php @@ -0,0 +1,210 @@ + +{desc} +<===================> + +Zusätzliche Hinweise: +<===================> +{hints} +<===================> +A|B|C|D|E|F|G|H|I|J|K|L|M +N|O|P|Q|R|S|T|U|V|W|X|Y|Z + +Logeinträge: +{logs} +"; + + $txtLogs = "<===================> +{username} / {date} / {type} + +{text} +"; + + $rs = sql_slave(' + SELECT SQL_BUFFER_RESULT + `searchtmp`.`cache_id` `cacheid`, + `searchtmp`.`longitude` `longitude`, + `searchtmp`.`latitude` `latitude`, + `caches`.`wp_oc` `waypoint`, + `caches`.`date_hidden` `date_hidden`, + `caches`.`name` `name`, + `caches`.`country` `country`, + `caches`.`terrain` `terrain`, + `caches`.`difficulty` `difficulty`, + `caches`.`desc_languages` `desc_languages`, + `cache_size`.`de` `size`, + `cache_type`.`de` `type`, + `cache_status`.`de` `status`, + `user`.`username` `username`, + `cache_desc`.`desc` `desc`, + `cache_desc`.`short_desc` `short_desc`, + `cache_desc`.`hint` `hint`, + `cache_desc`.`desc_html` `html`, + `user`.`user_id`, + `user`.`username`, + `user`.`data_license` + FROM + `searchtmp`, + `caches`, + `user`, + `cache_desc`, + `cache_type`, + `cache_status`, + `cache_size` + WHERE + `searchtmp`.`cache_id`=`caches`.`cache_id` AND + `caches`.`cache_id`=`cache_desc`.`cache_id` AND + `caches`.`default_desclang`=`cache_desc`.`language` AND + `searchtmp`.`user_id`=`user`.`user_id` AND + `caches`.`type`=`cache_type`.`id` AND + `caches`.`status`=`cache_status`.`id` AND + `caches`.`size`=`cache_size`.`id`'); + + while ($r = sql_fetch_array($rs)) + { + $thisline = $txtLine; + + $lat = sprintf('%01.5f', $r['latitude']); + $thisline = mb_ereg_replace('{lat}', help_latToDegreeStr($lat), $thisline); + + $lon = sprintf('%01.5f', $r['longitude']); + $thisline = mb_ereg_replace('{lon}', help_lonToDegreeStr($lon), $thisline); + + $time = date('d.m.Y', strtotime($r['date_hidden'])); + $thisline = mb_ereg_replace('{time}', $time, $thisline); + $thisline = mb_ereg_replace('{waypoint}', $r['waypoint'], $thisline); + $thisline = mb_ereg_replace('{cacheid}', $r['cacheid'], $thisline); + $thisline = mb_ereg_replace('{cachename}', $r['name'], $thisline); + $thisline = mb_ereg_replace('{country}', db_CountryFromShort($r['country']), $thisline); + + if ($r['hint'] == '') + $thisline = mb_ereg_replace('{hints}', '', $thisline); + else + $thisline = mb_ereg_replace('{hints}', str_rot13_html(decodeEntities(strip_tags($r['hint']))), $thisline); + + $thisline = mb_ereg_replace('{shortdesc}', $r['short_desc'], $thisline); + + $license = getLicenseDisclaimer( + $r['user_id'], $r['username'], $r['data_license'], $r['cacheid'], $locale, true, false, true); + if ($license != "") + $license = "\r\n\r\n$license"; + + if ($r['html'] == 0) + { + $thisline = mb_ereg_replace('{htmlwarn}', '', $thisline); + $thisline = mb_ereg_replace('{desc}', decodeEntities(strip_tags($r['desc'])) . $license, $thisline); + } + else + { + $thisline = mb_ereg_replace('{htmlwarn}', " ($converted_from_html)", $thisline); + $thisline = mb_ereg_replace('{desc}', html2txt($r['desc']) . $license, $thisline); + } + + $thisline = mb_ereg_replace('{type}', $r['type'], $thisline); + $thisline = mb_ereg_replace('{container}', $r['size'], $thisline); + $thisline = mb_ereg_replace('{status}', $r['status'], $thisline); + + $difficulty = sprintf('%01.1f', $r['difficulty'] / 2); + $thisline = mb_ereg_replace('{difficulty}', $difficulty, $thisline); + + $terrain = sprintf('%01.1f', $r['terrain'] / 2); + $thisline = mb_ereg_replace('{terrain}', $terrain, $thisline); + + $thisline = mb_ereg_replace('{owner}', $r['username'], $thisline); + + // logs ermitteln + $logentries = ''; + $rsLogs = sql_slave("SELECT `cache_logs`.`id`, `cache_logs`.`text_html`, `log_types`.`de` `type`, `cache_logs`.`date`, `cache_logs`.`text`, `user`.`username` FROM `cache_logs`, `user`, `log_types` WHERE `cache_logs`.`user_id`=`user`.`user_id` AND `cache_logs`.`type`=`log_types`.`id` AND `cache_logs`.`cache_id`=&1 ORDER BY `cache_logs`.`date` DESC LIMIT 20", $r['cacheid']); + while ($rLog = sql_fetch_array($rsLogs)) + { + $thislog = $txtLogs; + + $thislog = mb_ereg_replace('{id}', $rLog['id'], $thislog); + if (substr($rLog['date'],11) == "00:00:00") + $dateformat = "d.m.Y"; + else + $dateformat = "d.m.Y H:i"; + $thislog = mb_ereg_replace('{date}', date($dateformat, strtotime($rLog['date'])), $thislog); + $thislog = mb_ereg_replace('{username}', $rLog['username'], $thislog); + + $logtype = $rLog['type']; + + $thislog = mb_ereg_replace('{type}', $logtype, $thislog); + if ($rLog['text_html'] == 0) + $thislog = mb_ereg_replace('{text}', decodeEntities(strip_tags($rLog['text'])), $thislog); + else + $thislog = mb_ereg_replace('{text}', html2txt($rLog['text']), $thislog); + + $logentries .= $thislog . "\n"; + } + $thisline = mb_ereg_replace('{logs}', $logentries, $thisline); + + $thisline = lf2crlf($thisline); + if (($rCount['count'] == 1) && !$bUseZip) + echo $thisline; + else + { + $phpzip->add_data($r['waypoint'] . '.txt', $thisline); + } + } + mysql_free_result($rs); +} + + + function decodeEntities($str) + { + $str = html_entity_decode($str, ENT_COMPAT, "UTF-8"); + return $str; + } + + function html2txt($html) + { + $str = mb_ereg_replace("\r\n", '', $html); + $str = mb_ereg_replace("\n", '', $str); + $str = mb_ereg_replace('
', "\n", $str); + $str = strip_tags($str); + $str = decodeEntities($str); + return $str; + } + + function lf2crlf($str) + { + return mb_ereg_replace("\r\r\n" ,"\r\n" , mb_ereg_replace("\n" ,"\r\n" , $str)); + } + +?> \ No newline at end of file diff --git a/htdocs/lib/search1/search.xml.inc.php b/htdocs/lib/search1/search.xml.inc.php new file mode 100644 index 00000000..113802fc --- /dev/null +++ b/htdocs/lib/search1/search.xml.inc.php @@ -0,0 +1,195 @@ + + + + {cacheid} + {waypoint} + {time} + {status} + {lon} + {lat} + {distance} + {type} + {difficulty} + {terrain} + {container} + {country} + + + + +"; + + // create temporary table + sql_slave('CREATE TEMPORARY TABLE `searchtmp` + SELECT SQL_BUFFER_RESULT SQL_CALC_FOUND_ROWS ' . $sql . $sqlLimit); + + $resultcount = sql_value_slave('SELECT FOUND_ROWS()', 0); + + $rsCount = sql_slave('SELECT COUNT(*) `count` FROM `searchtmp`'); + $rCount = sql_fetch_array($rsCount); + mysql_free_result($rsCount); + + // start output + if ($sqldebug == false) + { + header("Content-type: application/xml; charset=".$encoding); + //header("Content-Disposition: attachment; filename=" . $sFilebasename . ".txt"); + } + + echo "\n"; + echo "\n"; + + echo " \n"; + echo " " . $rCount['count'] . "\n"; + echo " " . $startat . "\n"; + echo " " . $count . "\n"; + echo " " . $resultcount . "\n"; + echo " \n"; + + $rs = sql_slave('SELECT `searchtmp`.`cache_id` `cacheid`, + `searchtmp`.`longitude` `longitude`, + `searchtmp`.`latitude` `latitude`, + `caches`.`wp_oc` `waypoint`, + `caches`.`date_hidden` `date_hidden`, + `caches`.`name` `name`, + `caches`.`country` `country`, + `caches`.`terrain` `terrain`, + `caches`.`difficulty` `difficulty`, + `caches`.`desc_languages` `desc_languages`, + `cache_size`.`name` `size`, + `cache_size`.`id` `size_id`, + `cache_type`.`name` `type`, + `cache_type`.`id` `type_id`, + `cache_status`.`name` `status`, + `cache_status`.`id` `status_id`, + `user`.`username` `username`, + `user`.`user_id` `user_id`, + `cache_desc`.`desc` `desc`, + `cache_desc`.`short_desc` `short_desc`, + `cache_desc`.`hint` `hint`, + `cache_desc`.`desc_html` `html`, + `searchtmp`.`distance` `distance` + FROM `searchtmp` + INNER JOIN `caches` ON `searchtmp`.`cache_id`=`caches`.`cache_id` + INNER JOIN `user` ON `searchtmp`.`user_id`=`user`.`user_id` + INNER JOIN `cache_desc` ON `caches`.`cache_id`=`cache_desc`.`cache_id` AND `caches`.`default_desclang`=`cache_desc`.`language` + INNER JOIN `cache_type` ON `caches`.`type`=`cache_type`.`id` + INNER JOIN `cache_status` ON `caches`.`status`=`cache_status`.`id` + INNER JOIN `cache_size` ON `caches`.`size`=`cache_size`.`id`'); + while ($r = sql_fetch_array($rs)) + { + $thisline = $xmlLine; + + $lat = sprintf('%01.5f', $r['latitude']); + $thisline = str_replace('{lat}', help_latToDegreeStr($lat), $thisline); + $thisline = str_replace('{latvalue}', $lat, $thisline); + + $lon = sprintf('%01.5f', $r['longitude']); + $thisline = str_replace('{lon}', help_lonToDegreeStr($lon), $thisline); + $thisline = str_replace('{lonvalue}', $lon, $thisline); + + $time = date('d.m.Y', strtotime($r['date_hidden'])); + $thisline = str_replace('{time}', $time, $thisline); + $thisline = str_replace('{waypoint}', $r['waypoint'], $thisline); + $thisline = str_replace('{cacheid}', $r['cacheid'], $thisline); + $thisline = str_replace('{cachename}', filterevilchars($r['name']), $thisline); + $thisline = str_replace('{country}', db_CountryFromShort($r['country']), $thisline); + $thisline = str_replace('{countryid}', $r['country'], $thisline); + + if ($r['hint'] == '') + $thisline = str_replace('{hints}', '', $thisline); + else + $thisline = str_replace('{hints}', str_rot13_html(filterevilchars(strip_tags($r['hint']))), $thisline); + + $thisline = str_replace('{shortdesc}', filterevilchars($r['short_desc']), $thisline); + + if ($r['html'] == 0) + { + $thisline = str_replace('{htmlwarn}', '', $thisline); + $thisline = str_replace('{desc}', filterevilchars(strip_tags($r['desc'])), $thisline); + } + else + { + $thisline = str_replace('{htmlwarn}', ' (Text converted from HTML)', $thisline); + $thisline = str_replace('{desc}', html2txt(filterevilchars($r['desc'])), $thisline); + } + + $thisline = str_replace('{type}', $r['type'], $thisline); + $thisline = str_replace('{typeid}', $r['type_id'], $thisline); + $thisline = str_replace('{container}', $r['size'], $thisline); + $thisline = str_replace('{sizeid}', $r['size_id'], $thisline); + $thisline = str_replace('{status}', $r['status'], $thisline); + $thisline = str_replace('{statusid}', $r['status_id'], $thisline); + + $difficulty = sprintf('%01.1f', $r['difficulty'] / 2); + $thisline = str_replace('{difficulty}', $difficulty, $thisline); + + $terrain = sprintf('%01.1f', $r['terrain'] / 2); + $thisline = str_replace('{terrain}', $terrain, $thisline); + + $thisline = str_replace('{owner}', filterevilchars($r['username']), $thisline); + $thisline = str_replace('{ownerid}', filterevilchars($r['user_id']), $thisline); + $thisline = str_replace('{distance}', htmlspecialchars(sprintf("%01.1f", $r['distance'])), $thisline); + + $thisline = lf2crlf($thisline); + + echo $thisline; + } + mysql_free_result($rs); + sql_slave('DROP TABLE `searchtmp`'); + if ($sqldebug == true) sqldbg_end(); + echo "\n"; +} + + + function html2txt($html) + { + $str = str_replace("\r\n", '', $html); + $str = str_replace("\n", '', $str); + $str = str_replace('
', "\n", $str); + $str = strip_tags($str); + return $str; + } + + function lf2crlf($str) + { + return str_replace("\r\r\n" ,"\r\n" , str_replace("\n" ,"\r\n" , $str)); + } + + function filterevilchars($str) + { + $evilchars = array(31 => 31, 30 => 30, + 29 => 29, 28 => 28, 27 => 27, 26 => 26, 25 => 25, 24 => 24, + 23 => 23, 22 => 22, 21 => 21, 20 => 20, 19 => 19, 18 => 18, + 17 => 17, 16 => 16, 15 => 15, 14 => 14, 12 => 12, 11 => 11, + 9 => 9, 8 => 8, 7 => 7, 6 => 6, 5 => 5, 4 => 4, 3 => 3, + 2 => 2, 1 => 1, 0 => 0); + + foreach ($evilchars AS $ascii) + $str = str_replace(chr($ascii), '', $str); + + $str = preg_replace('/&([a-zA-Z]{1})caron;/', '\\1', $str); + $str = preg_replace('/&([a-zA-Z]{1})acute;/', '\\1', $str); + + return $str; + } + +?> \ No newline at end of file diff --git a/htdocs/search1.php b/htdocs/search1.php new file mode 100644 index 00000000..90196dca --- /dev/null +++ b/htdocs/search1.php @@ -0,0 +1,2150 @@ + target-unit + $multiplier['km'] = 1; + $multiplier['sm'] = 0.62137; + $multiplier['nm'] = 0.53996; + + // Determine if search.php was called by a search function ('Caches' menu, + // stored query etc.) or for other purpose (e.g. user profile cache lists): + if (isset($_REQUEST['calledbysearch']) && !$_REQUEST['calledbysearch']) + tpl_set_var('search_headline_caches', 'display:none'); + else + tpl_set_var('search_headline_caches',''); + + // default template variables + tpl_set_var('search_in_gm', $search_in_gm); + tpl_set_var('search_in_gm_zip', $search_in_gm_zip); + + if (isset($_REQUEST['queryid']) || isset($_REQUEST['showresult'])) + { // Ocprop: showresult, queryid + $bCookieQueryid = false; + $queryid = isset($_REQUEST['queryid']) ? $_REQUEST['queryid'] : 0; + if ($queryid) + { + tpl_set_var('search_in_gm', ''); + tpl_set_var('search_in_gm_zip', ''); + } + } + else + { + $bCookieQueryid = true; + $queryid = get_cookie_setting('lastqueryid'); + if ($queryid == false) $queryid = 0; + + if ($queryid != 0) + { + // check if query exists + $rsCount = sql("SELECT COUNT(*) `count` FROM `queries` WHERE id='&1'", $queryid); + $rCount = sql_fetch_array($rsCount); + mysql_free_result($rsCount); + + if ($rCount['count'] == 0) + $queryid = 0; + } + + newquery: + if ($queryid == 0) + { + // initialize search form with defaults, as we have no parameters + // or saved query to start from + + $_REQUEST['cache_attribs'] = ''; + $rs = sql('SELECT `id` FROM `cache_attrib` WHERE `default`=1 AND NOT IFNULL(`hidden`, 0)=1'); + while ($r = sql_fetch_assoc($rs)) + { + if ($_REQUEST['cache_attribs'] != '') $_REQUEST['cache_attribs'] .= ';'; + $_REQUEST['cache_attribs'] .= $r['id']; + } + mysql_free_result($rs); + + $_REQUEST['cache_attribs_not'] = ''; + $rs = sql('SELECT `id` FROM `cache_attrib` WHERE `default`=2 AND NOT IFNULL(`hidden`, 0)=1'); + while ($r = sql_fetch_assoc($rs)) + { + if ($_REQUEST['cache_attribs_not'] != '') $_REQUEST['cache_attribs_not'] .= ';'; + $_REQUEST['cache_attribs_not'] .= $r['id']; + } + mysql_free_result($rs); + } + } + $queryid = $queryid + 0; + + + //========================================================= + // 3. Build search options ($options) array + //========================================================= + + if ($queryid != 0) + { + // load search options from saved/cached query + + $query_rs = sql(" + SELECT `user_id`, `options` + FROM `queries` + WHERE id='&1' AND (`user_id`=0 OR `user_id`='&2')", + $queryid, $usr['userid']+0); + + if (mysql_num_rows($query_rs) == 0) + { + // can happen if logged out after query was created (fix for RT #3915) + $queryid = 0; + goto newquery; // goto needs PHP 5.3 + /* + $tplname = 'error'; + tpl_set_var('tplname', 'search1.php'); + tpl_set_var('error_msg', $error_query_not_found); + tpl_BuildTemplate(); + exit; + */ + } + else + { + $record = sql_fetch_array($query_rs); + $options = unserialize($record['options']); + if ($record['user_id'] != 0) + $options['userid'] = $record['user_id']; + mysql_free_result($query_rs); + + $options['queryid'] = $queryid; + + sql("UPDATE `queries` SET `last_queried`=NOW() WHERE `id`='&1'", $queryid); + + // overwrite variable options + if (isset($_REQUEST['output'])) + $options['output'] = $_REQUEST['output']; + + if (isset($_REQUEST['showresult'])) + { + $options['showresult'] = $_REQUEST['showresult']; + } + else + { + if ($bCookieQueryid == true) + { + $options['showresult'] = 0; + } + } + + // get findername from finderid + $options['finderid'] = isset($options['finderid']) ? $options['finderid'] + 0 : 0; // Ocprop + if(isset($options['finder']) && $options['finderid'] > 0) + { + $rs_name = sql("SELECT `username` FROM `user` WHERE `user_id`='&1'", $options['finderid']); + if(mysql_num_rows($rs_name) == 1) + { + $record_name = sql_fetch_array($rs_name); + $options['finder'] = $record_name['username']; + } + unset($record_name); + mysql_free_result($rs_name); + } + + // get ownername from ownerid + $options['ownerid'] = isset($options['ownerid']) ? $options['ownerid'] + 0 : 0; // Ocprop + if(isset($options['owner']) && $options['ownerid'] > 0) + { + $rs_name = sql("SELECT `username` FROM `user` WHERE `user_id`='&1'", $options['ownerid']); + if(mysql_num_rows($rs_name) == 1) + { + $record_name = sql_fetch_array($rs_name); + $options['owner'] = $record_name['username']; + } + unset($record_name); + mysql_free_result($rs_name); + } + } + } + else // $queryid == 0 + { + // build search options from GET/POST parameters or default values + + // hack + if(isset($_REQUEST['searchto']) && ($_REQUEST['searchto'] != '')) + { + unset($_REQUEST['searchbyname']); + unset($_REQUEST['searchbydistance']); + unset($_REQUEST['searchbyowner']); + unset($_REQUEST['searchbyfinder']); + unset($_REQUEST['searchbyplz']); + unset($_REQUEST['searchbyort']); + unset($_REQUEST['searchbyfulltext']); + unset($_REQUEST['searchbynofilter']); + $_REQUEST[$_REQUEST['searchto']] = "hoho"; + } + + // get the search options parameters and store them in the queries table (to view "the next page") + $options['f_userowner'] = isset($_REQUEST['f_userowner']) ? $_REQUEST['f_userowner'] : 0; // Ocprop + $options['f_userfound'] = isset($_REQUEST['f_userfound']) ? $_REQUEST['f_userfound'] : 0; // Ocprop + $options['f_disabled'] = isset($_REQUEST['f_disabled']) ? $_REQUEST['f_disabled'] : 0; + $options['f_inactive'] = isset($_REQUEST['f_inactive']) ? $_REQUEST['f_inactive'] : 1; // Ocprop + // f_inactive formerly was used for both, archived and disabled caches. + // After adding the separate f_disabled option, it is used only for archived + // caches, but keeps its name for compatibility with existing stored or + // external searches. + $options['f_ignored'] = isset($_REQUEST['f_ignored']) ? $_REQUEST['f_ignored'] : 1; + $options['f_otherPlatforms'] = isset($_REQUEST['f_otherPlatforms']) ? $_REQUEST['f_otherPlatforms'] : 0; + $options['expert'] = isset($_REQUEST['expert']) ? $_REQUEST['expert'] : 0; // Ocprop: 0 + $options['showresult'] = isset($_REQUEST['showresult']) ? $_REQUEST['showresult'] : 0; + $options['output'] = isset($_REQUEST['output']) ? $_REQUEST['output'] : 'HTML'; // Ocprop: HTML + $options['bbox'] = isset($_REQUEST['bbox']) ? $_REQUEST['bbox'] : false; + + if (isset($_REQUEST['cache_attribs'])) + { + if ($_REQUEST['cache_attribs'] != '') + { + $aAttribs = mb_split(';', $_REQUEST['cache_attribs']); + for ($i = 0; $i < count($aAttribs); $i++) + $options['cache_attribs'][$aAttribs[$i]+0] = $aAttribs[$i]+0; + unset($aAttribs); + } + else + $options['cache_attribs'] = array(); + } + else + $options['cache_attribs'] = array(); + + if (isset($_REQUEST['cache_attribs_not'])) + { + if ($_REQUEST['cache_attribs_not'] != '') + { + $aAttribs = mb_split(';', $_REQUEST['cache_attribs_not']); + for ($i = 0; $i < count($aAttribs); $i++) + $options['cache_attribs_not'][$aAttribs[$i]+0] = $aAttribs[$i]+0; + unset($aAttribs); + } + else + $options['cache_attribs_not'] = array(); + } + else + $options['cache_attribs_not'] = array(); + + if (!isset($_REQUEST['unit'])) + { + $options['unit'] = 'km'; + } + elseif (mb_strtolower($_REQUEST['unit']) == 'sm') + { + $options['unit'] = 'sm'; + } + elseif (mb_strtolower($_REQUEST['unit']) == 'nm') + { + $options['unit'] = 'nm'; + } + else + { + $options['unit'] = 'km'; + } + + if (isset($_REQUEST['searchbyname'])) + { + $options['searchtype'] = 'byname'; + $options['cachename'] = isset($_REQUEST['cachename']) ? stripslashes($_REQUEST['cachename']) : ''; + if (!isset($_REQUEST['utf8'])) + $options['cachename'] = iconv("ISO-8859-1", "UTF-8", $options['cachename']); + } + elseif (isset($_REQUEST['searchbyowner'])) // Ocprop + { + $options['searchtype'] = 'byowner'; + + $options['ownerid'] = isset($_REQUEST['ownerid']) ? $_REQUEST['ownerid'] : 0; + $options['owner'] = isset($_REQUEST['owner']) ? stripslashes($_REQUEST['owner']) : ''; + } + elseif (isset($_REQUEST['searchbyfinder'])) // Ocprop + { + $options['searchtype'] = 'byfinder'; + + $options['finderid'] = isset($_REQUEST['finderid']) ? $_REQUEST['finderid'] : 0; + $options['finder'] = isset($_REQUEST['finder']) ? stripslashes($_REQUEST['finder']) : ''; + $options['logtype'] = isset($_REQUEST['logtype']) ? $_REQUEST['logtype'] : '1,7'; // Ocprop + } + elseif (isset($_REQUEST['searchbyort'])) + { + $options['searchtype'] = 'byort'; + + $options['ort'] = isset($_REQUEST['ort']) ? stripslashes($_REQUEST['ort']) : ''; + $options['locid'] = isset($_REQUEST['locid']) ? $_REQUEST['locid'] : 0; + $options['locid'] = $options['locid'] + 0; + } + elseif (isset($_REQUEST['searchbyplz'])) + { + $options['searchtype'] = 'byplz'; + + $options['plz'] = isset($_REQUEST['plz']) ? stripslashes($_REQUEST['plz']) : ''; + $options['locid'] = isset($_REQUEST['locid']) ? $_REQUEST['locid'] : 0; + $options['locid'] = $options['locid'] + 0; + } + elseif (isset($_REQUEST['searchbydistance'])) + { + $options['searchtype'] = 'bydistance'; + + // Ocprop: all of the following options + if (isset($_REQUEST['lat']) && isset($_REQUEST['lon'])) + { + $options['lat'] = $_REQUEST['lat']+0; + $options['lon'] = $_REQUEST['lon']+0; + } + else + { + $options['latNS'] = isset($_REQUEST['latNS']) ? $_REQUEST['latNS'] : 'N'; + $options['lonEW'] = isset($_REQUEST['lonEW']) ? $_REQUEST['lonEW'] : 'E'; + + $options['lat_h'] = isset($_REQUEST['lat_h']) ? $_REQUEST['lat_h'] : 0; + $options['lon_h'] = isset($_REQUEST['lon_h']) ? $_REQUEST['lon_h'] : 0; + $options['lat_min'] = isset($_REQUEST['lat_min']) ? $_REQUEST['lat_min'] : 0; + $options['lon_min'] = isset($_REQUEST['lon_min']) ? $_REQUEST['lon_min'] : 0; + } + + $options['distance'] = isset($_REQUEST['distance']) ? $_REQUEST['distance'] : 0; + } + elseif (isset($_REQUEST['searchbyfulltext'])) + { + $options['searchtype'] = 'byfulltext'; + + $options['ft_name'] = isset($_REQUEST['ft_name']) ? $_REQUEST['ft_name']+0 : 0; + $options['ft_desc'] = isset($_REQUEST['ft_desc']) ? $_REQUEST['ft_desc']+0 : 0; + $options['ft_logs'] = isset($_REQUEST['ft_logs']) ? $_REQUEST['ft_logs']+0 : 0; + $options['ft_pictures'] = isset($_REQUEST['ft_pictures']) ? $_REQUEST['ft_pictures']+0 : 0; + + $options['fulltext'] = isset($_REQUEST['fulltext']) ? $_REQUEST['fulltext'] : ''; + } + elseif (isset($_REQUEST['searchbycacheid'])) + { + $options['searchtype'] = 'bycacheid'; + $options['cacheid'] = isset($_REQUEST['cacheid']) ? $_REQUEST['cacheid'] : 0; + if (!is_numeric($options['cacheid'])) $options['cacheid'] = 0; + } + elseif (isset($_REQUEST['searchbywp'])) + { + $options['searchtype'] = 'bywp'; + $options['wp'] = isset($_REQUEST['wp']) ? $_REQUEST['wp'] : ''; + } + elseif (isset($_REQUEST['searchbynofilter'])) + { + $options['searchtype'] = 'bynofilter'; + } + else + { + if (isset($_REQUEST['showresult'])) + tpl_errorMsg('search', 'Unknown search option'); + else + { + // Set default search type; this prevents errors in outputSearchForm() + // when initializing searchtype-dependent options: + $options['searchtype'] = 'byname'; + $options['cachename'] = ''; + } + } + + $options['sort'] = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'bydistance'; + + if (isset($_REQUEST['orderRatingFirst']) && $_REQUEST['orderRatingFirst']==1) + $options['orderRatingFirst'] = true; + + $options['country'] = isset($_REQUEST['country']) ? $_REQUEST['country'] : ''; + $options['cachetype'] = isset($_REQUEST['cachetype']) ? $_REQUEST['cachetype'] : ''; + + $options['cachesize'] = isset($_REQUEST['cachesize']) ? $_REQUEST['cachesize'] : ''; + $options['difficultymin'] = isset($_REQUEST['difficultymin']) ? $_REQUEST['difficultymin']+0 : 0; + $options['difficultymax'] = isset($_REQUEST['difficultymax']) ? $_REQUEST['difficultymax']+0 : 0; + $options['terrainmin'] = isset($_REQUEST['terrainmin']) ? $_REQUEST['terrainmin']+0 : 0; + $options['terrainmax'] = isset($_REQUEST['terrainmax']) ? $_REQUEST['terrainmax']+0 : 0; + $options['recommendationmin'] = isset($_REQUEST['recommendationmin']) ? $_REQUEST['recommendationmin']+0 : 0; + + $options['queryid'] = 0; + } // $queryid == 0 + + + //========================================================= + // 4. query caching + //========================================================= + + $bRememberQuery = isset($_REQUEST['skipqueryid']) ? !$_REQUEST['skipqueryid'] : true; + // This is used by the map, which implements its own query-caching. + if ($bRememberQuery) + { + if ($options['showresult'] != 0) // 'showresult' = "execute query" + { + sql("INSERT INTO `queries` (`user_id`, `options`, `last_queried`) VALUES (0, '&1', NOW())", serialize($options)); + $options['queryid'] = mysql_insert_id(); + } + set_cookie_setting('lastqueryid', $options['queryid']); + } + + // remove old queries (after 1 hour without use); + // execute only every 50 search calls + if (rand(1, 50) == 1) + { + sql("DELETE FROM `queries` WHERE `last_queried` < NOW() - INTERVAL 1 HOUR AND `user_id`=0"); + } + + + //========================================================= + // 5. set defaults for new search options + // which may not be present in a stored/cached query + //========================================================= + + if (!isset($options['orderRatingFirst'])) $options['orderRatingFirst'] = false; + if (!isset($options['f_otherPlatforms'])) $options['f_otherPlatforms'] = 0; + if (!isset($options['difficultymin'])) $options['difficultymin'] = 0; + if (!isset($options['difficultymax'])) $options['difficultymax'] = 0; + if (!isset($options['terrainmin'])) $options['terrainmin'] = 0; + if (!isset($options['terrainmax'])) $options['terrainmax'] = 0; + if (!isset($options['recommendationmin'])) $options['recommendationmin'] = 0; + if (!isset($options['cachetype'])) $options['cachetype'] = ''; + if (!isset($options['cachesize'])) $options['cachesize'] = ''; + if (!isset($options['bbox'])) $options['bbox'] = false; + if (!isset($options['f_disabled'])) $options['f_disabled'] = 0; + + if (!isset($options['showresult'])) $options['showresult'] = 0; + if ($options['showresult'] == 1) + { + + //=============================================================== + // X6. build SQL statement from search options + //=============================================================== + + $cachesFilter = ''; + + if(!isset($options['output'])) $options['output']=''; + if ((mb_strpos($options['output'], '.') !== false) || + (mb_strpos($options['output'], '/') !== false) || + (mb_strpos($options['output'], '\\') !== false) + ) + { + $options['output'] = 'HTML'; + } + + // make a list of cache-ids that are in the result + if(!isset($options['expert'])) $options['expert']=''; + if ($options['expert'] == 0) // Ocprop + { + $sql_select = array(); + $sql_from = ''; + $sql_innerjoin = array(); + $sql_leftjoin = array(); + $sql_where = array(); + $sql_having = array(); + $sql_group = array(); + + //check the entered data and build SQL + if(!isset($options['searchtype'])) $options['searchtype']=''; + if ($options['searchtype'] == 'byname') + { + $sql_select[] = '`caches`.`cache_id` `cache_id`'; + $sql_from = '`caches`'; + $sql_where[] = '`caches`.`name` LIKE \'%' . sql_escape($options['cachename']) . '%\''; + } + elseif ($options['searchtype'] == 'byowner') + { + if ($options['ownerid'] != 0) + { + $sql_select[] = '`caches`.`cache_id` `cache_id`'; + $sql_from = '`caches`'; + $sql_where[] = '`user_id`=\'' . sql_escape($options['ownerid']) . '\''; + } + else + { + $sql_select[] = '`caches`.`cache_id` `cache_id`'; + $sql_from = '`caches`'; + $sql_innerjoin[] = '`user` ON `caches`.`user_id`=`user`.`user_id`'; + $sql_where[] = '`user`.`username`=\'' . sql_escape($options['owner']) . '\''; + } + } + elseif (($options['searchtype'] == 'byplz') || ($options['searchtype'] == 'byort')) + { + $locid = $options['locid']; + + if ($options['searchtype'] == 'byplz') + { + if ($locid == 0) + { + $plz = $options['plz']; + + $sql = "SELECT `loc_id` FROM `geodb_textdata` WHERE `text_type`=500300000 AND `text_val`='" . sql_escape($plz) . "'"; + $rs = sql($sql); + if (mysql_num_rows($rs) == 0) + { + $options['error_plz'] = true; + outputSearchForm($options); + exit; + } + elseif (mysql_num_rows($rs) == 1) + { + $r = sql_fetch_array($rs); + mysql_free_result($rs); + $locid = $r['loc_id']; + } + else + { + // ok, viele locations ... alle auflisten ... + outputLocidSelectionForm($sql, $options); + exit; + } + } + + // ok, wir haben einen ort ... koordinaten ermitteln + $locid = $locid + 0; + $rs = sql('SELECT `lon`, `lat` FROM `geodb_coordinates` WHERE `loc_id`=' . $locid . ' AND coord_type=200100000'); + if ($r = sql_fetch_array($rs)) + { + // ok ... wir haben koordinaten ... + + $lat = $r['lat'] + 0; + $lon = $r['lon'] + 0; + + $distance_unit = 'km'; + $distance = 75; + + // ab hier selber code wie bei bydistance ... TODO: in funktion auslagern + + //all target caches are between lat - max_lat_diff and lat + max_lat_diff + $max_lat_diff = $distance / (111.12 * $multiplier[$distance_unit]); + + //all target caches are between lon - max_lon_diff and lon + max_lon_diff + //TODO: check!!! + $max_lon_diff = $distance * 180 / (abs(sin((90 - $lat) * 3.14159 / 180 )) * 6378 * $multiplier[$distance_unit] * 3.14159); + + $lon_rad = $lon * 3.14159 / 180; + $lat_rad = $lat * 3.14159 / 180; + + $cachesFilter = + 'CREATE TEMPORARY TABLE result_caches ENGINE=MEMORY + SELECT + (' . getSqlDistanceFormula($lon, $lat, $distance, $multiplier[$distance_unit]) . ') `distance`, + `caches`.`cache_id` `cache_id` + FROM `caches` FORCE INDEX (`latitude`) + WHERE `longitude` > ' . ($lon - $max_lon_diff) . ' + AND `longitude` < ' . ($lon + $max_lon_diff) . ' + AND `latitude` > ' . ($lat - $max_lat_diff) . ' + AND `latitude` < ' . ($lat + $max_lat_diff) . ' + HAVING `distance` < ' . ($distance+0); + sql_slave($cachesFilter); + sql_slave('ALTER TABLE result_caches ADD PRIMARY KEY ( `cache_id` )'); + + $sql_select[] = '`result_caches`.`cache_id`'; + $sql_from = '`result_caches`'; + $sql_innerjoin[] = '`caches` ON `caches`.`cache_id`=`result_caches`.`cache_id`'; + } + else + { + $options['error_locidnocoords'] = true; + outputSearchForm($options); + exit; + } + } + else if ($options['searchtype'] == 'byort') + { + if ($locid == 0) + { + require_once($opt['rootpath'] . 'lib/search1/search.inc.php'); + + $ort = $options['ort']; + $simpletexts = search_text2sort($ort); + $simpletextsarray = explode_multi($simpletexts, ' -/,'); + + $sqlhashes = ''; + $wordscount = 0; + foreach ($simpletextsarray AS $text) + { + if ($text != '') + { + $searchstring = search_text2simple($text); + + if ($sqlhashes != '') $sqlhashes .= ' OR '; + $sqlhashes .= '`gns_search`.`simplehash`=' . sprintf("%u", crc32($searchstring)); + + $wordscount++; + } + } + + if ($sqlhashes == '') + { + $options['error_noort'] = true; + outputSearchForm($options); + } + + // temporäre tabelle erstellen und dann einträge entfernen, die nicht mindestens so oft vorkommen wie worte gegeben wurden + sql_slave('CREATE TEMPORARY TABLE tmpuniids (`uni_id` int(11) NOT NULL, `cnt` int(11) NOT NULL, `olduni` int(11) NOT NULL, `simplehash` int(11) NOT NULL) ENGINE=MEMORY SELECT `gns_search`.`uni_id` `uni_id`, 0 `cnt`, 0 `olduni`, `simplehash` FROM `gns_search` WHERE ' . $sqlhashes); + sql_slave('ALTER TABLE `tmpuniids` ADD INDEX (`uni_id`)'); +// BUGFIX: dieser Code sollte nur ausgeführt werden, wenn mehr als ein Suchbegriff eingegeben wurde +// damit alle Einträge gefiltert, die nicht alle Suchbegriffe enthalten +// nun wird dieser Quellcode auch ausgeführt, um mehrfache uni_id's zu filtern +// Notwendig, wenn nach Baden gesucht wird => Baden-Baden war doppelt in der Liste +// if ($wordscount > 1) +// { + sql_slave('CREATE TEMPORARY TABLE `tmpuniids2` (`uni_id` int(11) NOT NULL, `cnt` int(11) NOT NULL, `olduni` int(11) NOT NULL) ENGINE=MEMORY SELECT `uni_id`, COUNT(*) `cnt`, 0 olduni FROM `tmpuniids` GROUP BY `uni_id` HAVING `cnt` >= ' . $wordscount); + sql_slave('ALTER TABLE `tmpuniids2` ADD INDEX (`uni_id`)'); + sql_slave('DROP TABLE `tmpuniids`'); + sql_slave('ALTER TABLE `tmpuniids2` RENAME `tmpuniids`'); +// } + +// 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' +// 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' + + // und jetzt noch alle englischen bezeichnungen durch deutsche ersetzen (wo möglich) ... + sql_slave('CREATE TEMPORARY TABLE `tmpuniidsAdd` (`uni` int(11) NOT NULL, `olduni` int(11) NOT NULL, PRIMARY KEY (`uni`)) ENGINE=MEMORY SELECT g2.uni uni, g1.uni olduni 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\' GROUP BY uni'); + sql_slave('CREATE TEMPORARY TABLE `tmpuniidsRemove` (`uni` int(11) NOT NULL, PRIMARY KEY (`uni`)) ENGINE=MEMORY SELECT DISTINCT g1.uni 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\''); + sql_slave('DELETE FROM tmpuniids WHERE uni_id IN (SELECT uni FROM tmpuniidsRemove)'); + sql_slave('DELETE FROM tmpuniidsAdd WHERE uni IN (SELECT uni_id FROM tmpuniids)'); + sql_slave('INSERT INTO tmpuniids (uni_id, olduni) SELECT uni, olduni FROM tmpuniidsAdd'); + sql_slave('DROP TABLE tmpuniidsAdd'); + sql_slave('DROP TABLE tmpuniidsRemove'); + + $rs = sql_slave('SELECT `uni_id` FROM tmpuniids'); + if (mysql_num_rows($rs) == 0) + { + mysql_free_result($rs); + + $options['error_ort'] = true; + outputSearchForm($options); + exit; + } + elseif (mysql_num_rows($rs) == 1) + { + $r = sql_fetch_array($rs); + mysql_free_result($rs); + + // wenn keine 100%ige übereinstimmung nochmals anzeigen + $locid = $r['uni_id'] + 0; + $rsCmp = sql_slave('SELECT `full_name` FROM `gns_locations` WHERE `uni`=' . $locid . ' LIMIT 1'); + $rCmp = sql_fetch_array($rsCmp); + mysql_free_result($rsCmp); + + if (mb_strtolower($rCmp['full_name']) != mb_strtolower($ort)) + { + outputUniidSelectionForm('SELECT `uni_id`, `olduni` FROM `tmpuniids`', $options); + } + } + else + { + mysql_free_result($rs); + outputUniidSelectionForm('SELECT `uni_id`, `olduni` FROM `tmpuniids`', $options); + exit; + } + } + + + // ok, wir haben einen ort ... koordinaten ermitteln + $locid = $locid + 0; + $rs = sql_slave('SELECT `lon`, `lat` FROM `gns_locations` WHERE `uni`=' . $locid . ' LIMIT 1'); + if ($r = sql_fetch_array($rs)) + { + // ok ... wir haben koordinaten ... + + $lat = $r['lat'] + 0; + $lon = $r['lon'] + 0; + + $lon_rad = $lon * 3.14159 / 180; + $lat_rad = $lat * 3.14159 / 180; + + $distance_unit = 'km'; + $distance = 75; + + // ab hier selber code wie bei bydistance ... TODO: in funktion auslagern + + //all target caches are between lat - max_lat_diff and lat + max_lat_diff + $max_lat_diff = $distance / (111.12 * $multiplier[$distance_unit]); + + //all target caches are between lon - max_lon_diff and lon + max_lon_diff + //TODO: check!!! + $max_lon_diff = $distance * 180 / (abs(sin((90 - $lat) * 3.14159 / 180 )) * 6378 * $multiplier[$distance_unit] * 3.14159); + + $cachesFilter = + 'CREATE TEMPORARY TABLE result_caches ENGINE=MEMORY + SELECT + (' . getSqlDistanceFormula($lon, $lat, $distance, $multiplier[$distance_unit]) . ') `distance`, + `caches`.`cache_id` `cache_id` + FROM `caches` FORCE INDEX (`latitude`) + WHERE `longitude` > ' . ($lon - $max_lon_diff) . ' + AND `longitude` < ' . ($lon + $max_lon_diff) . ' + AND `latitude` > ' . ($lat - $max_lat_diff) . ' + AND `latitude` < ' . ($lat + $max_lat_diff) . ' + HAVING `distance` < ' . ($distance+0); + sql_slave($cachesFilter); + sql_slave('ALTER TABLE result_caches ADD PRIMARY KEY ( `cache_id` )'); + + $sql_select[] = '`result_caches`.`cache_id`'; + $sql_from = '`result_caches`'; + $sql_innerjoin[] = '`caches` ON `caches`.`cache_id`=`result_caches`.`cache_id`'; + } + else + { + $options['error_locidnocoords'] = true; + outputSearchForm($options); + exit; + } + } + } + elseif ($options['searchtype'] == 'byfinder') + { + if ($options['finderid'] != 0) + { + $finder_id = $options['finderid']; + } + else + { + //get the userid + $rs = sql_slave("SELECT `user_id` FROM `user` WHERE `username`='&1'", $options['finder']); + $finder_record = sql_fetch_array($rs); + $finder_id = $finder_record['user_id']; + mysql_free_result($rs); + } + + if (!isset($options['logtype'])) $options['logtype'] = '1,7'; + + $sql_select[] = 'distinct `caches`.`cache_id` `cache_id`'; + // needs distinct because there can be multiple matching logs per cache + $sql_from = '`caches`'; + $sql_innerjoin[] = '`cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`'; + $sql_where[] = '`cache_logs`.`user_id`=\'' . sql_escape($finder_id) . '\''; + + if ($options['logtype'] != '0') // 0 = all types + { + $ids = explode(',', $options['logtype']); + $idNumbers = '0'; + foreach ($ids AS $id) + { + if ($idNumbers != '') $idNumbers .= ','; + $idNumbers .= ($id+0); + } + $sql_where[] = '`cache_logs`.`type` IN (' . $idNumbers . ')'; + } + } + elseif ($options['searchtype'] == 'bydistance') // Ocprop + { + //check the entered data + if (isset($options['lat']) && isset($options['lon'])) + { + $lat = $options['lat']+0; + $lon = $options['lon']+0; + } + else + { + $latNS = $options['latNS']; + $lonEW = $options['lonEW']; + + $lat_h = $options['lat_h']; + $lon_h = $options['lon_h']; + $lat_min = $options['lat_min']; + $lon_min = $options['lon_min']; + + if (is_numeric($lon_h) && is_numeric($lon_min)) + { + if (($lon_h >= 0) && ($lon_h < 180) && ($lon_min >= 0) && ($lon_min < 60)) + { + $lon = $lon_h + $lon_min / 60; + if ($lonEW == 'W') $lon = -$lon; + } + } + + if (is_numeric($lat_h) && is_numeric($lat_min)) + { + if (($lat_h >= 0) && ($lat_h < 90) && ($lat_min >= 0) && ($lat_min < 60)) + { + $lat = $lat_h + $lat_min / 60; + if ($latNS == 'S') $lat = -$lat; + } + } + } + + $distance = $options['distance']; + $distance_unit = $options['unit']; + + if ((!isset($lon)) || (!isset($lat)) || (!is_numeric($distance))) + { + outputSearchForm($options); + exit; + } + + //make the sql-String + + //all target caches are between lat - max_lat_diff and lat + max_lat_diff + $max_lat_diff = $distance / (111.12 * $multiplier[$distance_unit]); + + //all target caches are between lon - max_lon_diff and lon + max_lon_diff + //TODO: check!!! + $max_lon_diff = $distance * 180 / (abs(sin((90 - $lat) * 3.14159 / 180 )) * 6378 * $multiplier[$distance_unit] * 3.14159); + + $lon_rad = $lon * 3.14159 / 180; + $lat_rad = $lat * 3.14159 / 180; + + $cachesFilter = + 'CREATE TEMPORARY TABLE result_caches ENGINE=MEMORY + SELECT + (' . getSqlDistanceFormula($lon, $lat, $distance, $multiplier[$distance_unit]) . ') `distance`, + `caches`.`cache_id` `cache_id` + FROM `caches` FORCE INDEX (`latitude`) + WHERE `longitude` > ' . ($lon - $max_lon_diff) . ' + AND `longitude` < ' . ($lon + $max_lon_diff) . ' + AND `latitude` > ' . ($lat - $max_lat_diff) . ' + AND `latitude` < ' . ($lat + $max_lat_diff) . ' + HAVING `distance` < ' . ($distance+0); + sql_slave($cachesFilter); + sql_slave('ALTER TABLE result_caches ADD PRIMARY KEY ( `cache_id` )'); + + $sql_select[] = '`result_caches`.`cache_id`'; + $sql_from = '`result_caches`'; + $sql_innerjoin[] = '`caches` ON `caches`.`cache_id`=`result_caches`.`cache_id`'; + } + elseif ($options['searchtype'] == 'bycacheid') + { + $sql_select[] = '`caches`.`cache_id` `cache_id`'; + $sql_from = '`caches`'; + $sql_where[] = '`caches`.`cache_id`=\'' . sql_escape($options['cacheid']) . '\''; + } + elseif ($options['searchtype'] == 'bywp') + { + $sql_select[] = '`caches`.`cache_id` `cache_id`'; + $sql_from = '`caches`'; + $sql_where[] = '`caches`.`wp_oc`=\'' . sql_escape($options['wp']) . '\''; + } + elseif ($options['searchtype'] == 'byfulltext') + { + require_once($opt['rootpath'] . 'lib/search1/ftsearch.inc.php'); + + $fulltext = $options['fulltext']; + $hashes = ftsearch_hash($fulltext); + + if (count($hashes) == 0) + { + $options['error_nofulltext'] = true; + outputSearchForm($options); + } + else if (count($hashes) > 50) + { + $options['error_fulltexttoolong'] = true; + outputSearchForm($options); + } + + $ft_types = array(); + if (isset($options['ft_name']) && $options['ft_name']) + $ft_types[] = 2; + if (isset($options['ft_logs']) && $options['ft_logs']) + $ft_types[] = 1; + if (isset($options['ft_desc']) && $options['ft_desc']) + $ft_types[] = 3; + if (isset($options['ft_pictures']) && $options['ft_pictures']) + $ft_types[] = 6; + if (count($ft_types) == 0) + $ft_types[] = 0; + + $sql_select[] = '`caches`.`cache_id` `cache_id`'; + $sql_from = '`caches`'; + + $n = 1; + foreach ($hashes AS $k => $h) + { + if ($n > 1) + $sql_innerjoin[] = '`search_index` AS `s' . $n . '` ON `s' . ($n-1) . '`.`cache_id`=`s' . $n . '`.`cache_id`'; + else + $sql_innerjoin[] = '`search_index` AS `s1` ON `s1`.`cache_id`=`caches`.`cache_id`'; + + $sql_where[] = '`s' . $n . '`.`hash`=\'' . sql_escape($h) . '\''; + $sql_where[] = '`s' . $n . '`.`object_type` IN (' . implode(',', $ft_types) . ')'; + + $n++; + } + + $sqlFilter = 'SELECT DISTINCT ' . implode(',', $sql_select) . + ' FROM ' . $sql_from . + ' INNER JOIN ' . implode(' INNER JOIN ', $sql_innerjoin) . + ' WHERE ' . implode(' AND ', $sql_where); + + sql_slave('CREATE TEMPORARY TABLE `tmpFTCaches` (`cache_id` int (11) PRIMARY KEY) ' . $sqlFilter); + + $sql_select = array(); + $sql_from = ''; + $sql_innerjoin = array(); + $sql_leftjoin = array(); + $sql_where = array(); + + $sql_select[] = '`caches`.`cache_id` `cache_id`'; + $sql_from = '`tmpFTCaches`'; + $sql_innerjoin[] = '`caches` ON `caches`.`cache_id`=`tmpFTCaches`.`cache_id`'; + } + elseif ($options['searchtype'] == 'bynofilter') + { + $sql_select[] = '`caches`.`cache_id` `cache_id`'; + $sql_from = '`caches`'; + } + else + { + tpl_errorMsg('search', $unknown_searchtype); + } + + // additional options + if (!isset($options['f_userowner'])) $options['f_userowner']='0'; // Ocprop + if ($options['f_userowner'] != 0) { $sql_where[] = '`caches`.`user_id`!=\'' . $usr['userid'] .'\''; } + + if (!isset($options['f_userfound'])) $options['f_userfound']='0'; // Ocprop + if ($options['f_userfound'] != 0) + { + $sql_where[] = '`caches`.`cache_id` NOT IN (SELECT `cache_logs`.`cache_id` FROM `cache_logs` WHERE `cache_logs`.`user_id`=\'' . sql_escape($usr['userid']) . '\' AND `cache_logs`.`type` IN (1, 7))'; + } + if (!isset($options['f_inactive'])) $options['f_inactive']='0'; // Ocprop + if ($options['f_inactive'] != 0) $sql_where[] = '`caches`.`status` NOT IN (3,6,7)'; + // f_inactive formerly was used for both, archived and disabled caches. + // After adding the separate f_disabled option, it is used only for archived + // caches, but keeps its name for compatibility with existing stored or + // external searches. + if (!isset($options['f_disabled'])) $options['f_disabled']='0'; + if ($options['f_disabled'] != 0) $sql_where[] = '`caches`.`status`<>2'; + + if (isset($usr)) + { + if (!isset($options['f_ignored'])) $options['f_ignored']='0'; + if($options['f_ignored'] != 0) + { + // only use this filter, if it is realy needed - this enables better caching in map2.php with ignored-filter + if (sql_value_slave("SELECT COUNT(*) FROM `cache_ignore` WHERE `user_id`='" . sql_escape($usr['userid']) . "'", 0) > 0) + { + $sql_where[] = '`caches`.`cache_id` NOT IN (SELECT `cache_ignore`.`cache_id` + FROM `cache_ignore` + WHERE `cache_ignore`.`user_id`=\'' . sql_escape($usr['userid']) . '\')'; + } + } + } + if (!isset($options['f_otherPlatforms'])) $options['f_otherPlatforms']='0'; + if ($options['f_otherPlatforms'] != 0) + { + // $sql_where[] = '`caches`.`wp_nc`=\'\' AND `caches`.`wp_gc`=\'\''; + // ignore NC listings, which are mostly unmaintained or dead + $sql_where[] = "`caches`.`wp_gc_maintained`=''"; + } + if (!isset($options['country'])) $options['country']=''; + if ($options['country'] != '') + { + $sql_where[] = '`caches`.`country`=\'' . sql_escape($options['country']) . '\''; + } + + if ($options['cachetype'] != '') + { + $types = explode(';', $options['cachetype']); + if (count($types) < sql_value_slave("SELECT COUNT(*) FROM `cache_type`", 0)) + { + for ($i = 0; $i < count($types); $i++) $types[$i] = "'" . sql_escape($types[$i]) . "'"; + $sql_where[] = '`caches`.`type` IN (' . implode(',', $types) . ')'; + } + } + + if ($options['cachesize'] != '') + { + $sizes = explode(';', $options['cachesize']); + if (count($sizes) < sql_value_slave("SELECT COUNT(*) FROM `cache_size`", 0)) + { + for ($i = 0; $i < count($sizes); $i++) $sizes[$i] = "'" . sql_escape($sizes[$i]) . "'"; + $sql_where[] = '`caches`.`size` IN (' . implode(',', $sizes) . ')'; + } + } + + if ($options['difficultymin'] != 0) + { + $sql_where[] = '`caches`.`difficulty`>=\'' . sql_escape($options['difficultymin']) . '\''; + } + if ($options['difficultymax'] != 0) + { + $sql_where[] = '`caches`.`difficulty`<=\'' . sql_escape($options['difficultymax']) . '\''; + } + if ($options['terrainmin'] != 0) + { + $sql_where[] = '`caches`.`terrain`>=\'' . sql_escape($options['terrainmin']) . '\''; + } + if ($options['terrainmax'] != 0) + { + $sql_where[] = '`caches`.`terrain`<=\'' . sql_escape($options['terrainmax']) . '\''; + } + if ($options['recommendationmin'] > 0) + { + $sql_innerjoin[] = '`stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`'; + $sql_where[] = '`stat_caches`.`toprating`>=\'' . sql_escape($options['recommendationmin']) . '\''; + } + + if (isset($options['cache_attribs']) && count($options['cache_attribs']) > 0) + { + foreach ($options['cache_attribs'] AS $attr) + { + $sql_innerjoin[] = '`caches_attributes` AS `a' . ($attr+0) . '` ON `a' . ($attr+0) . '`.`cache_id`=`caches`.`cache_id`'; + $sql_where[] = '`a' . ($attr+0) . '`.`attrib_id`=' . ($attr+0); + } + } + + if (isset($options['cache_attribs_not']) && count($options['cache_attribs_not']) > 0) + { + foreach ($options['cache_attribs_not'] AS $attr) + { + $sql_where[] = 'NOT EXISTS (SELECT `caches_attributes`.`cache_id` FROM `caches_attributes` WHERE `caches_attributes`.`cache_id`=`caches`.`cache_id` AND `caches_attributes`.`attrib_id`=\'' . sql_escape($attr+0) . '\')'; + } + } + + if (isset($options['bbox']) && ($options['bbox']!==false)) + { + // bbox=,,, + $coords = explode(',', $options['bbox']); + if (count($coords) == 4) + { + $sql_where[] = '`caches`.`longitude`>=' . ($coords[0]+0) . ' AND `caches`.`latitude`>=' . ($coords[1]+0) . ' AND `caches`.`longitude`<=' . ($coords[2]+0) . ' AND `caches`.`latitude`<=' . ($coords[3]+0); + } + } + + $sql_innerjoin[] = '`cache_status` ON `caches`.`status`=`cache_status`.`id`'; + if (isset($usr['userid'])) + $sql_where[] = '(`cache_status`.`allow_user_view`=1 OR `caches`.`user_id`=' . sql_escape($usr['userid']) . ' OR (`caches`.`status`<>5 AND '. sql_escape($login->admin & ADMIN_USER) . '>0))'; + else + $sql_where[] = '`cache_status`.`allow_user_view`=1'; + + //do the search + $innerjoin = sizeof($sql_innerjoin) ? ' INNER JOIN ' . implode(' INNER JOIN ', $sql_innerjoin) : ''; + $leftjoin = sizeof($sql_leftjoin) ? ' LEFT JOIN ' . implode(' LEFT JOIN ', $sql_leftjoin) : ''; + $group = sizeof($sql_group) ? ' GROUP BY ' . implode(', ', $sql_group) : ''; + $having = sizeof($sql_having) ? ' HAVING ' . implode(' AND ', $sql_having) : ''; + + $sqlFilter = 'SELECT ' . implode(',', $sql_select) . + ' FROM ' . $sql_from . + $innerjoin . + $leftjoin . + ' WHERE ' . implode(' AND ', $sql_where) . + $group . + $having; + + // echo "DEBUG ".$sqlFilter." DEBUG
"; + } + else + { + tpl_errorMsg('search', 'Unbekannter Suchtyp'); + } + + //================================================================= + // X7. verify output selection and prepare SQL query + //================================================================= + + $output_module = mb_strtolower($options['output']); // Ocprop: HTML, gpx + + $map2_bounds = ($output_module == 'map2bounds'); + if ($map2_bounds) + $output_module = 'map2'; + + if ($map2_bounds && $options['queryid'] == 0) + { + tpl_set_var('tplname', $tplname); + $tplname = 'error'; + tpl_set_var('error_msg', 'map2bounds requires queryid'); + } + elseif (!file_exists($opt['rootpath'] . 'lib/search1/search.' . $output_module . '.inc.php')) + { + tpl_set_var('tplname', $tplname); + $tplname = 'error'; + tpl_set_var('error_msg', $outputformat_notexist); + } + + if ($tplname != 'error') + { + $caches_per_page = 20; + + // Default parameters; may be modified by output modules + $content_type_plain = 'application/octet-stream'; + $content_type_zipped = 'application/zip'; + $zip_threshold = $caches_per_page; + $add_to_zipfile = true; + $sAddJoin = ''; + $sAddGroupBy = ''; + $sAddFields = ''; + $sGroupBy = ''; + + // *** load output module *** + // + // (map2 module will exit after executing) + + require($opt['rootpath'] . 'lib/search1/search.' . $output_module . '.inc.php'); + + if (!isset($search_output_file_download)) + die("search_output_file_download not set for '$output_module' search"); + + // *** prepare SQL query *** + $sql = ''; + + // If no distance unit is preselected by distance search, use 'km'. + // The unit will be shown e.g. in HTML and XML search results. + if (!isset($distance_unit)) + $distance_unit = 'km'; + + if (isset($lat_rad) && isset($lon_rad)) + { + $sql .= getSqlDistanceFormula($lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, '; + } + else + { + if ($usr === false) + { + $sql .= 'NULL distance, '; + } + else + { + // get the user's home coords + $rs_coords = sql_slave("SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`='&1'", $usr['userid']); + $record_coords = sql_fetch_array($rs_coords); + + if ($record_coords['latitude'] == 0 && $record_coords['longitude'] == 0) + { + $sql .= 'NULL distance, '; + } + else + { + $lon_rad = $record_coords['longitude'] * 3.14159 / 180; + $lat_rad = $record_coords['latitude'] * 3.14159 / 180; + + $sql .= getSqlDistanceFormula($record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, '; + } + mysql_free_result($rs_coords); + } + } + + if ($options['sort'] == 'bylastlog' || $options['sort'] == 'bymylastlog') + { + $sAddFields .= ', MAX(`cache_logs`.`date`) AS `lastLog`'; + $sAddJoin .= ' LEFT JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`'; + if ($options['sort'] == 'bymylastlog') + $sAddJoin .= ' AND `cache_logs`.`user_id`=' . sql_escape($usr === false ? 0 : $usr['userid']); + $sGroupBy .= ' GROUP BY `caches`.`cache_id`'; + } + $sql .= '`caches`.`cache_id`, + `caches`.`status`, + `caches`.`type`, + `caches`.`size`, + `caches`.`longitude`, `caches`.`latitude`, + `caches`.`user_id`, + IF(IFNULL(`stat_caches`.`toprating`,0)>3, 4, IFNULL(`stat_caches`.`toprating`, 0)) `ratingvalue`' . + $sAddFields + . ' FROM `caches` + LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`' . + $sAddJoin + . ' WHERE `caches`.`cache_id` IN (' . $sqlFilter . ')' . + $sGroupBy; + $sortby = $options['sort']; + + $sql .= ' ORDER BY '; + if ($options['orderRatingFirst']) + $sql .= '`ratingvalue` DESC, '; + + if ($sortby == 'bylastlog' || $options['sort'] == 'bymylastlog') + { + $sql .= '`lastLog` DESC, '; + $sortby = 'bydistance'; + } + + if (isset($lat_rad) && isset($lon_rad) && ($sortby == 'bydistance')) + { + $sql .= '`distance` ASC'; + } + else if ($sortby == 'bycreated') + { + $sql .= '`caches`.`date_created` DESC'; + } + else // by name + { + // Some names start with spaces ... + // caches.name is not indexed, so ltrimming won't cost performance. + $sql .= 'LTRIM(`caches`.`name`) ASC'; + } + + // range of output + $startat = isset($_REQUEST['startat']) ? $_REQUEST['startat'] : 0; + if (!is_numeric($startat)) $startat = 0; + + if (isset($_REQUEST['count'])) // Ocprop + $count = $_REQUEST['count']; + else + $count = $caches_per_page; + if ($count == 'max') $count = 500; + if (!is_numeric($count)) $count = 0; + if ($count < 1) $count = 1; + if ($count > 500) $count = 500; + + $sqlLimit = ' LIMIT ' . $startat . ', ' . $count; + + if ($search_output_file_download) + { + //================================================================= + // X8a. run query and output for file downloads (GPX, KML, OVL ...) + //================================================================= + + sql_slave('CREATE TEMPORARY TABLE `searchtmp` SELECT ' . $sql . $sqlLimit, + $sqldebug); + $rsCount = sql_slave('SELECT COUNT(*) `count` FROM `searchtmp`'); + $rCount = sql_fetch_array($rsCount); + mysql_free_result($rsCount); + + if ($rCount['count'] == 1) + { + $rsName = sql_slave(' + SELECT `caches`.`wp_oc` `wp_oc` + FROM `searchtmp`, `caches` + WHERE `searchtmp`.`cache_id`=`caches`.`cache_id` LIMIT 1' + ); + $rName = sql_fetch_array($rsName); + mysql_free_result($rsName); + + $sFilebasename = $rName['wp_oc']; + } + else + $sFilebasename = 'ocde' . $options['queryid']; + + $bUseZip = ($rCount['count'] > $zip_threshold) || + (isset($_REQUEST['zip']) && ($_REQUEST['zip'] == '1')); + if ($bUseZip) + { + require_once($opt['rootpath'] . 'lib2/ss_zip.class.php'); + $phpzip = new ss_zip('',6); + } + + if (!$sqldebug) + { + if ($bUseZip) + { + header('Content-type: ' . $content_type_zipped); + header('Content-disposition: attachment; filename="' . $sFilebasename . '.zip"'); + } + else + { + header('Content-type: '.$content_type_plain); + header('Content-disposition: attachment; filename="' . $sFilebasename . '.' . $output_module .'"'); + } + } + + // helper function for output modules + function append_output($str) + { + global $content, $bUseZip, $sqldebug; + if (!$sqldebug) + { + if ($bUseZip) + $content .= $str; + else + echo $str; + } + } + + // *** run output module *** + // + // Modules will use these variables from search.php: + // + // $phpzip + // $bUseZip + + $content = ''; + search_output(); + + if ($sqldebug) sqldbg_end(); + sql_slave('DROP TABLE `searchtmp`'); + + // output zip file + if ($bUseZip) + { + if ($add_to_zipfile) + { + $phpzip->add_data($sFilebasename . '.' . $output_module, $content); + } + echo $phpzip->save($sFilebasename . '.zip', 'r'); + } + } + else + { + //================================================================= + // X8b. run other output module (XML, HTML, Map) + // + // The following variables from search.php are used by output modules: + // + // $distance_unit + // $lat_rad, $lon_rad + // $startat + // $count + // $caches_per_page + // $sql + // $sqlLimit + // $options['sort'] + // $options['queryid'] + // $cachesFilter + // $map2_bounds + //================================================================= + + search_output(); + } + + exit; + } + } + else // $options['showresult'] == 0 + { + //============================================================= + // F6. present search options form to the user + //============================================================= + + $options['show_all_countries'] = isset($_REQUEST['show_all_countries']) ? $_REQUEST['show_all_countries'] : 0; + + if (isset($_REQUEST['show_all_countries_submit'])) + { + $options['show_all_countries'] = 1; + } + + //return the search form + if ($options['expert'] == 1) + { + //expert mode + tpl_set_var('formmethod', 'post'); + } + else + { + outputSearchForm($options); + exit; + } + } + } // $error != false + + + //============================================================= + // F8. show search options form or error message + //============================================================= + + tpl_BuildTemplate(); + + +//============================================================= +// F7. prepare search options form +//============================================================= + +function outputSearchForm($options) +{ + global $login; + global $stylepath, $usr, $error_plz, $error_locidnocoords, $error_ort, $error_noort, $error_nofulltext, $error_fulltexttoolong; + global $default_lang, $search_all_countries, $cache_attrib_jsarray_line; + global $cache_attrib_group, $cache_attrib_img_line1, $cache_attrib_img_line2, $locale; + + //simple mode (only one easy filter) + //$filters = read_file($stylepath . '/search.simple.tpl.php'); + //tpl_set_var('filters', $filters, false); + tpl_set_var('formmethod', 'get'); + + // checkboxen + tpl_set_var('disable_nologin', $usr === false ? 'disabled' : ''); + tpl_set_var('grey_nologin', $usr === false ? 'style="color:grey"' : ''); + + $homecoords = ($login->userid>0 && sql_value_slave("SELECT `latitude`+`longitude` FROM user WHERE `user_id`='&1'", $login->userid) <> 0); + if (!$homecoords && isset($options['sort']) && $options['sort'] == 'bydistance') + $options['sort'] = 'byname'; + tpl_set_var('bydistance_enabled', ($homecoords ? "" : 'disabled="disabled"')); + + if (isset($options['sort'])) + $bBynameChecked = ($options['sort'] == 'byname'); // Ocprop + else + $bBynameChecked = ($usr['userid'] == 0); + tpl_set_var('byname_checked', ($bBynameChecked == true) ? ' checked="checked"' : ''); + + if (isset($options['sort'])) + $bBydistanceChecked = ($options['sort'] == 'bydistance'); + else + $bBydistanceChecked = ($usr['userid'] != 0); + tpl_set_var('bydistance_checked', ($bBydistanceChecked == true) ? ' checked="checked"' : ''); + + if (isset($options['sort'])) + $bBycreatedChecked = ($options['sort'] == 'bycreated'); + else + $bBycreatedChecked = ($usr['userid'] == 0); + tpl_set_var('bycreated_checked', ($bBycreatedChecked == true) ? ' checked="checked"' : ''); + + if (isset($options['sort'])) + $bBylastlogChecked = ($options['sort'] == 'bylastlog'); + else + $bBylastlogChecked = ($usr['userid'] != 0); + tpl_set_var('bylastlog_checked', ($bBylastlogChecked == true) ? ' checked="checked"' : ''); + + if (isset($options['sort'])) + $bBymylastlogChecked = ($options['sort'] == 'bymylastlog'); + else + $bBymylastlogChecked = ($usr['userid'] != 0); + tpl_set_var('bymylastlog_checked', ($bBymylastlogChecked == true) ? ' checked="checked"' : ''); + + tpl_set_var('hidopt_sort', $options['sort']); + + tpl_set_var('orderRatingFirst_checked', ($options['orderRatingFirst'] == true) ? ' checked="checked"' : ''); + tpl_set_var('hidopt_orderRatingFirst', ($options['orderRatingFirst'] == true) ? '1' : '0'); + + tpl_set_var('f_userfound_disabled', ($usr['userid'] == 0) ? ' disabled="disabled"' : ''); + if ($usr['userid'] != 0) + tpl_set_var('f_userfound_disabled', ($options['f_userfound'] == 1) ? ' checked="checked"' : ''); + tpl_set_var('hidopt_userfound', ($options['f_userfound'] == 1) ? '1' : '0'); + + tpl_set_var('f_userowner_disabled', ($usr['userid'] == 0) ? ' disabled="disabled"' : ''); + if ($usr['userid'] != 0) + tpl_set_var('f_userowner_disabled', ($options['f_userowner'] == 1) ? ' checked="checked"' : ''); + tpl_set_var('hidopt_userowner', ($options['f_userowner'] == 1) ? '1' : '0'); + + tpl_set_var('f_inactive_checked', ($options['f_inactive'] == 1) ? ' checked="checked"' : ''); + tpl_set_var('hidopt_inactive', ($options['f_inactive'] == 1) ? '1' : '0'); + + tpl_set_var('f_disabled_checked', ($options['f_disabled'] == 1) ? ' checked="checked"' : ''); + tpl_set_var('hidopt_disabled', ($options['f_disabled'] == 1) ? '1' : '0'); + + tpl_set_var('f_ignored_disabled', ($usr['userid'] == 0) ? ' disabled="disabled"' : ''); + if ($usr['userid'] != 0) + tpl_set_var('f_ignored_disabled', ($options['f_ignored'] == 1) ? ' checked="checked"' : ''); + tpl_set_var('hidopt_ignored', ($options['f_ignored'] == 1) ? '1' : '0'); + + tpl_set_var('f_otherPlatforms_checked', ($options['f_otherPlatforms'] == 1) ? ' checked="checked"' : ''); + tpl_set_var('hidopt_otherPlatforms', ($options['f_otherPlatforms'] == 1) ? '1' : '0'); + + if (isset($options['country'])) + { + tpl_set_var('country', htmlspecialchars($options['country'], ENT_COMPAT, 'UTF-8')); + } + else + { + tpl_set_var('country', ''); + } + + if (isset($options['cachetype'])) + { + tpl_set_var('cachetype', htmlspecialchars($options['cachetype'], ENT_COMPAT, 'UTF-8')); + } + else + { + tpl_set_var('cachetype', ''); + } + + // cachename + tpl_set_var('cachename', isset($options['cachename']) ? htmlspecialchars($options['cachename'], ENT_COMPAT, 'UTF-8') : ''); + + // koordinaten + if (!isset($options['lat_h'])) + { + if ($usr !== false) + { + $rs = sql('SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`=\'' . sql_escape($usr['userid']) . '\''); + $record = sql_fetch_array($rs); + $lon = $record['longitude']; + $lat = $record['latitude']; + mysql_free_result($rs); + + if ($lon < 0) + { + tpl_set_var('lonE_sel', ''); + tpl_set_var('lonW_sel', ' selected="selected"'); + $lon = -$lon; + } + else + { + tpl_set_var('lonE_sel', ' selected="selected"'); + tpl_set_var('lonW_sel', ''); + } + + if ($lat < 0) + { + tpl_set_var('latN_sel', ''); + tpl_set_var('latS_sel', ' selected="selected"'); + $lat = -$lat; + } + else + { + tpl_set_var('latN_sel', ' selected="selected"'); + tpl_set_var('latS_sel', ''); + } + + $lon_h = floor($lon); + $lat_h = floor($lat); + $lon_min = ($lon - $lon_h) * 60; + $lat_min = ($lat - $lat_h) * 60; + + tpl_set_var('lat_h', $lat_h); + tpl_set_var('lon_h', $lon_h); + tpl_set_var('lat_min', sprintf("%02.3f", $lat_min)); + tpl_set_var('lon_min', sprintf("%02.3f", $lon_min)); + } + else + { + tpl_set_var('lat_h', '00'); + tpl_set_var('lon_h', '000'); + tpl_set_var('lat_min', '00.000'); + tpl_set_var('lon_min', '00.000'); + } + } + else + { + tpl_set_var('lat_h', isset($options['lat_h']) ? $options['lat_h'] : '00'); + tpl_set_var('lon_h', isset($options['lon_h']) ? $options['lon_h'] : '000'); + tpl_set_var('lat_min', isset($options['lat_min']) ? $options['lat_min'] : '00.000'); + tpl_set_var('lon_min', isset($options['lon_min']) ? $options['lon_min'] : '00.000'); + + if ($options['lonEW'] == 'W') + { + tpl_set_var('lonE_sel', ''); + tpl_set_var('lonW_sel', 'selected="selected"'); + } + else + { + tpl_set_var('lonE_sel', 'selected="selected"'); + tpl_set_var('lonW_sel', ''); + } + + if ($options['latNS'] == 'S') + { + tpl_set_var('latS_sel', 'selected="selected"'); + tpl_set_var('latN_sel', ''); + } + else + { + tpl_set_var('latS_sel', ''); + tpl_set_var('latN_sel', 'selected="selected"'); + } + } + tpl_set_var('distance', isset($options['distance']) ? $options['distance'] : 75); + + if (!isset($options['unit'])) $options['unit'] = 'km'; + if ($options['unit'] == 'km') + { + tpl_set_var('sel_km', 'selected="selected"'); + tpl_set_var('sel_sm', ''); + tpl_set_var('sel_nm', ''); + } + else if ($options['unit'] == 'sm') + { + tpl_set_var('sel_km', ''); + tpl_set_var('sel_sm', 'selected="selected"'); + tpl_set_var('sel_nm', ''); + } + else if ($options['unit'] == 'nm') + { + tpl_set_var('sel_km', ''); + tpl_set_var('sel_sm', ''); + tpl_set_var('sel_nm', 'selected="selected"'); + } + + // plz + tpl_set_var('plz', isset($options['plz']) ? htmlspecialchars($options['plz'], ENT_COMPAT, 'UTF-8') : ''); + tpl_set_var('ort', isset($options['ort']) ? htmlspecialchars($options['ort'], ENT_COMPAT, 'UTF-8') : ''); + + // owner + tpl_set_var('owner', isset($options['owner']) ? htmlspecialchars($options['owner'], ENT_COMPAT, 'UTF-8') : ''); + + // finder + tpl_set_var('finder', isset($options['finder']) ? htmlspecialchars($options['finder'], ENT_COMPAT, 'UTF-8') : ''); + + //countryoptions + $countriesoptions = $search_all_countries; + + $rs = sql("SELECT IFNULL(`sys_trans_text`.`text`, `countries`.`name`) AS `name`, `countries`.`short` FROM `countries` LEFT JOIN `sys_trans` ON `countries`.`trans_id`=`sys_trans`.`id` AND `sys_trans`.`text`=`countries`.`name` LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1' WHERE `countries`.`short` IN (SELECT DISTINCT `country` FROM `caches`) ORDER BY `name` ASC", $locale); + for ($i = 0; $i < mysql_num_rows($rs); $i++) + { + $record = sql_fetch_array($rs); + + if ($record['short'] == $options['country']) + $countriesoptions .= ''; + else + $countriesoptions .= ''; + + $countriesoptions .= "\n"; + } + tpl_set_var('countryoptions', $countriesoptions); + + // cachetype + cachesize + $nCount = sqlValue("SELECT COUNT(*) FROM `cache_type`", 0); + for ($n = 1; $n <= $nCount; $n++) + tpl_set_var('cachetype' . $n . 'checked', ((strpos(';' . $options['cachetype'] . ';', ';' . $n . ';') !== false) || ($options['cachetype']=='')) ? ' checked="checked"' : ''); + + $nCount = sqlValue("SELECT COUNT(*) FROM `cache_size`", 0); + tpl_set_var('cachesizes', $nCount); + for ($n = 1; $n <= $nCount; $n++) + tpl_set_var('cachesize' . $n . 'checked', ((strpos(';' . $options['cachesize'] . ';', ';' . $n . ';') !== false) || ($options['cachesize']=='')) ? ' checked="checked"' : ''); + + tpl_set_var('cachetype', $options['cachetype']); + tpl_set_var('cachesize', $options['cachesize']); + + // difficulty + terrain + $difficultymin_options = '' . "\n"; + $difficultymax_options = '' . "\n"; + $terrainmin_options = '' . "\n"; + $terrainmax_options = '' . "\n"; + for ($n = 2; $n <= 10; $n++) + { + $difficultymin_options .= '' . "\n"; + $difficultymax_options .= '' . "\n"; + $terrainmin_options .= '' . "\n"; + $terrainmax_options .= '' . "\n"; + } + tpl_set_var('difficultymin_options', $difficultymin_options); + tpl_set_var('difficultymax_options', $difficultymax_options); + tpl_set_var('terrainmin_options', $terrainmin_options); + tpl_set_var('terrainmax_options', $terrainmax_options); + + tpl_set_var('difficultymin', $options['difficultymin']); + tpl_set_var('difficultymax', $options['difficultymax']); + tpl_set_var('terrainmin', $options['terrainmin']); + tpl_set_var('terrainmax', $options['terrainmax']); + + // logtypen + $logtype_options = ''; + $rs = sql(" + SELECT `id`, + IFNULL(`sys_trans_text`.`text`, `log_types`.`name`) AS `name` + FROM ( + SELECT `id`,`name`,`trans_id` FROM `log_types` + UNION + SELECT 0,'all',(SELECT id FROM sys_trans WHERE `text`='all') + ) `log_types` + LEFT JOIN `sys_trans_text` ON `sys_trans_text`.`trans_id`=`log_types`.`trans_id` AND `sys_trans_text`.`lang`='&1' + ORDER BY `log_types`.`id` ASC", $locale); + + for ($i = 0; $i < mysql_num_rows($rs); $i++) + { + $record = sql_fetch_array($rs); + + if (isset($options['logtype']) && $record['id'] == $options['logtype']) + $logtype_options .= ''; + else + $logtype_options .= ''; + + $logtype_options .= "\n"; + } + tpl_set_var('logtype_options', $logtype_options); + + // cache-attributes + $attributes_jsarray = ''; + + $bBeginLine2 = true; + $nPrevLineAttrCount2 = 0; + $nLineAttrCount2 = 0; + $attributes_img2 = ''; + + /* perpare 'all attributes' */ + $rsAttrGroup = sql("SELECT `attribute_groups`.`id`, IFNULL(`sys_trans_text`.`text`, `attribute_groups`.`name`) AS `name`, `attribute_categories`.`color` FROM `attribute_groups` INNER JOIN `attribute_categories` ON `attribute_groups`.`category_id`=`attribute_categories`.`id` LEFT JOIN `sys_trans` ON `attribute_groups`.`trans_id`=`sys_trans`.`id` AND `sys_trans`.`text`=`attribute_groups`.`name` LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1' ORDER BY `attribute_groups`.`category_id` ASC, `attribute_groups`.`id` ASC", $locale); + while ($rAttrGroup = sql_fetch_assoc($rsAttrGroup)) + { + $group_line = ''; + + $rs = sql("SELECT `cache_attrib`.`id`, IFNULL(`ttname`.`text`, `cache_attrib`.`name`) AS `name`, `cache_attrib`.`icon_large`, `cache_attrib`.`icon_no`, `cache_attrib`.`icon_undef`, `cache_attrib`.`search_default`, IFNULL(`ttdesc`.`text`, `cache_attrib`.`html_desc`) AS `html_desc` + FROM `cache_attrib` + LEFT JOIN `sys_trans` AS `tname` ON `cache_attrib`.`trans_id`=`tname`.`id` AND `cache_attrib`.`name`=`tname`.`text` + LEFT JOIN `sys_trans_text` AS `ttname` ON `tname`.`id`=`ttname`.`trans_id` AND `ttname`.`lang`='&1' + LEFT JOIN `sys_trans` AS `tdesc` ON `cache_attrib`.`html_desc_trans_id`=`tdesc`.`id` AND `cache_attrib`.`html_desc`=`tdesc`.`text` + LEFT JOIN `sys_trans_text` AS `ttdesc` ON `tdesc`.`id`=`ttdesc`.`trans_id` AND `ttdesc`.`lang`='&1' + WHERE `cache_attrib`.`group_id`='&2' AND `selectable` + AND NOT IFNULL(`cache_attrib`.`hidden`, 0)=1 + ORDER BY `cache_attrib`.`id`", $locale, $rAttrGroup['id']); + while ($record = sql_fetch_array($rs)) + { + // icon specified + $line = $cache_attrib_jsarray_line; + $line = mb_ereg_replace('{id}', $record['id'], $line); + + if (!isset($options['cache_attribs'])) + { + $line = mb_ereg_replace('{state}', 0, $line); + } + else if (array_search($record['id'], $options['cache_attribs']) === false) + { + if (array_search($record['id'], $options['cache_attribs_not']) === false) + $line = mb_ereg_replace('{state}', 0, $line); + else + $line = mb_ereg_replace('{state}', 2, $line); + } + else + $line = mb_ereg_replace('{state}', 1, $line); + + $line = mb_ereg_replace('{text_long}', escape_javascript($record['name']), $line); + $line = mb_ereg_replace('{icon}', $record['icon_large'], $line); + $line = mb_ereg_replace('{icon_no}', $record['icon_no'], $line); + $line = mb_ereg_replace('{icon_undef}', $record['icon_undef'], $line); + $line = mb_ereg_replace('{search_default}', $record['search_default'], $line); + if ($attributes_jsarray != '') $attributes_jsarray .= ",\n"; + $attributes_jsarray .= $line; + + $line = $cache_attrib_img_line1; + $line = mb_ereg_replace('{id}', $record['id'], $line); + $line = mb_ereg_replace('{text_long}', escape_javascript($record['name']), $line); + if (!isset($options['cache_attribs'])) + { + $line = mb_ereg_replace('{icon}', $record['icon_undef'], $line); + } + else if (array_search($record['id'], $options['cache_attribs']) === false) + { + if (array_search($record['id'], $options['cache_attribs_not']) === false) + $line = mb_ereg_replace('{icon}', $record['icon_undef'], $line); + else + $line = mb_ereg_replace('{icon}', $record['icon_no'], $line); + } + else + $line = mb_ereg_replace('{icon}', $record['icon_large'], $line); + + $line = mb_ereg_replace('{html_desc}', escape_javascript($record['html_desc']), $line); + $line = mb_ereg_replace('{name}', escape_javascript($record['name']), $line); + $line = mb_ereg_replace('{color}', $rAttrGroup['color'], $line); + + $group_line .= $line; + $nLineAttrCount2++; + } + sql_free_result($rs); + + if ($group_line != '') + { + $group_img = $cache_attrib_group; + $group_img = mb_ereg_replace('{color}', $rAttrGroup['color'], $group_img); + $group_img = mb_ereg_replace('{attribs}', $group_line, $group_img); + $group_img = mb_ereg_replace('{name}', htmlspecialchars($rAttrGroup['name'], ENT_COMPAT, 'UTF-8'), $group_img); + + if ($bBeginLine2 == true) + { + $attributes_img2 .= '
'; + $bBeginLine2 = false; + } + + $attributes_img2 .= $group_img; + $nPrevLineAttrCount2 += $nLineAttrCount2; + + $nLineAttrCount2 = 0; + } + } + sql_free_result($rsAttrGroup); + if ($bBeginLine2 == false) + $attributes_img2 .= '
'; + + /* prepare default attributes */ + $bBeginLine1 = true; + $nPrevLineAttrCount1 = 0; + $nLineAttrCount1 = 0; + $attributes_img1 = ''; + + $rsAttrGroup = sql("SELECT `attribute_groups`.`id`, IFNULL(`sys_trans_text`.`text`, `attribute_groups`.`name`) AS `name`, `attribute_categories`.`color` FROM `attribute_groups` INNER JOIN `attribute_categories` ON `attribute_groups`.`category_id`=`attribute_categories`.`id` LEFT JOIN `sys_trans` ON `attribute_groups`.`trans_id`=`sys_trans`.`id` AND `sys_trans`.`text`=`attribute_groups`.`name` LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1' ORDER BY `attribute_groups`.`category_id` ASC, `attribute_groups`.`id` ASC", $locale); + while ($rAttrGroup = sql_fetch_assoc($rsAttrGroup)) + { + $group_line = ''; + + $rs = sql("SELECT `cache_attrib`.`id`, IFNULL(`ttname`.`text`, `cache_attrib`.`name`) AS `name`, `cache_attrib`.`icon_large`, `cache_attrib`.`icon_no`, `cache_attrib`.`icon_undef`, `cache_attrib`.`search_default`, IFNULL(`ttdesc`.`text`, `cache_attrib`.`html_desc`) AS `html_desc` + FROM `cache_attrib` + LEFT JOIN `sys_trans` AS `tname` ON `cache_attrib`.`trans_id`=`tname`.`id` AND `cache_attrib`.`name`=`tname`.`text` + LEFT JOIN `sys_trans_text` AS `ttname` ON `tname`.`id`=`ttname`.`trans_id` AND `ttname`.`lang`='&1' + LEFT JOIN `sys_trans` AS `tdesc` ON `cache_attrib`.`html_desc_trans_id`=`tdesc`.`id` AND `cache_attrib`.`html_desc`=`tdesc`.`text` + LEFT JOIN `sys_trans_text` AS `ttdesc` ON `tdesc`.`id`=`ttdesc`.`trans_id` AND `ttdesc`.`lang`='&1' + WHERE `cache_attrib`.`group_id`='&2' + AND `cache_attrib`.`search_default`=1 AND `selectable` + AND NOT IFNULL(`cache_attrib`.`hidden`, 0)=1 + ORDER BY `cache_attrib`.`id`", $locale, $rAttrGroup['id']); + while ($record = sql_fetch_array($rs)) + { + $line = $cache_attrib_img_line2; + $line = mb_ereg_replace('{id}', $record['id'], $line); + $line = mb_ereg_replace('{text_long}', escape_javascript($record['name']), $line); + if (!isset($options['cache_attribs'])) + { + $line = mb_ereg_replace('{icon}', $record['icon_undef'], $line); + } + else if (array_search($record['id'], $options['cache_attribs']) === false) + { + if (array_search($record['id'], $options['cache_attribs_not']) === false) + $line = mb_ereg_replace('{icon}', $record['icon_undef'], $line); + else + $line = mb_ereg_replace('{icon}', $record['icon_no'], $line); + } + else + $line = mb_ereg_replace('{icon}', $record['icon_large'], $line); + + $line = mb_ereg_replace('{html_desc}', escape_javascript($record['html_desc']), $line); + $line = mb_ereg_replace('{name}', escape_javascript($record['name']), $line); + $line = mb_ereg_replace('{color}', $rAttrGroup['color'], $line); + + $group_line .= $line; + $nLineAttrCount1++; + } + sql_free_result($rs); + + if ($group_line != '') + { + $group_img = $cache_attrib_group; + $group_img = mb_ereg_replace('{color}', $rAttrGroup['color'], $group_img); + $group_img = mb_ereg_replace('{attribs}', $group_line, $group_img); + $group_img = mb_ereg_replace('{name}', htmlspecialchars($rAttrGroup['name'], ENT_COMPAT, 'UTF-8'), $group_img); + + if ($bBeginLine1 == true) + { + $attributes_img1 .= '
'; + $bBeginLine1 = false; + } + + $attributes_img1 .= $group_img; + $nPrevLineAttrCount1 += $nLineAttrCount1; + + $nLineAttrCount1 = 0; + } + } + sql_free_result($rsAttrGroup); + if ($bBeginLine1 == false) + $attributes_img1 .= '
'; + + tpl_set_var('cache_attribCat1_list', $attributes_img1); + tpl_set_var('cache_attribCat2_list', $attributes_img2); + tpl_set_var('attributes_jsarray', $attributes_jsarray); + tpl_set_var('hidopt_attribs', isset($options['cache_attribs']) ? implode(';', $options['cache_attribs']) : ''); + tpl_set_var('hidopt_attribs_not', isset($options['cache_attribs_not']) ? implode(';', $options['cache_attribs_not']) : ''); + + tpl_set_var('fulltext', ''); + tpl_set_var('ft_name_checked', 'checked="checked"'); + tpl_set_var('ft_desc_checked', ''); + tpl_set_var('ft_logs_checked', ''); + tpl_set_var('ft_pictures_checked', ''); + + // fulltext options + if ($options['searchtype'] == 'byfulltext') + { + if (!isset($options['fulltext'])) $options['fulltext'] = ''; + tpl_set_var('fulltext', htmlspecialchars($options['fulltext'], ENT_COMPAT, 'UTF-8')); + + if (isset($options['ft_name']) && $options['ft_name']==1) + tpl_set_var('ft_name_checked', 'checked="checked"'); + else + tpl_set_var('ft_name_checked', ''); + + if (isset($options['ft_desc']) && $options['ft_desc']==1) + tpl_set_var('ft_desc_checked', 'checked="checked"'); + else + tpl_set_var('ft_desc_checked', ''); + + if (isset($options['ft_logs']) && $options['ft_logs']==1) + tpl_set_var('ft_logs_checked', 'checked="checked"'); + else + tpl_set_var('ft_logs_checked', ''); + + if (isset($options['ft_pictures']) && $options['ft_pictures']==1) + tpl_set_var('ft_pictures_checked', 'checked="checked"'); + else + tpl_set_var('ft_pictures_checked', ''); + } + + // errormeldungen + tpl_set_var('ortserror', ''); + if (isset($options['error_plz'])) + tpl_set_var('ortserror', $error_plz); + else if (isset($options['error_ort'])) + tpl_set_var('ortserror', $error_ort); + else if (isset($options['error_locidnocoords'])) + tpl_set_var('ortserror', $error_locidnocoords); + else if (isset($options['error_noort'])) + tpl_set_var('ortserror', $error_noort); + + tpl_set_var('fulltexterror', ''); + if (isset($options['error_nofulltext'])) + tpl_set_var('fulltexterror', $error_nofulltext); + else if (isset($options['error_fulltexttoolong'])) + tpl_set_var('fulltexterror', $error_fulltexttoolong); + + tpl_BuildTemplate(); + exit; +} + + +//============================================================= +// Prompt the user with a list of locations when the entered +// 'ort' or 'plz' is not unique. +//============================================================= + +function outputUniidSelectionForm($uniSql, $urlparams) +{ + global $tplname, $locline, $stylepath, $bgcolor1, $bgcolor2, $gns_countries; + global $secondlocationname; + + require_once($stylepath . '/search1/selectlocid.inc.php'); + + unset($urlparams['queryid']); + unset($urlparams['locid']); + $urlparams['searchto'] = 'search' . $urlparams['searchtype']; + unset($urlparams['searchtype']); + + $tplname = 'search1/selectlocid'; + + // urlparams zusammenbauen + $urlparamString = ''; + foreach ($urlparams AS $name => $param) + { + // workaround for attribs + if (is_array($param)) + { + $pnew = ''; + foreach ($param AS $p) + if ($pnew != '') + $pnew .= ';' . $p; + else + $pnew .= $p; + + $param = $pnew; + } + + if ($urlparamString != '') + $urlparamString .= '&' . $name . '=' . urlencode($param); + else + $urlparamString = $name . '=' . urlencode($param); + } + $urlparamString .= ''; + + sql_slave('CREATE TEMPORARY TABLE `uniids` ENGINE=MEMORY ' . $uniSql); + sql_slave('ALTER TABLE `uniids` ADD PRIMARY KEY (`uni_id`)'); + + // locidsite + $locidsite = isset($_REQUEST['locidsite']) ? $_REQUEST['locidsite'] : 0; + if (!is_numeric($locidsite)) $locidsite = 0; + + $rsCount = sql_slave('SELECT COUNT(*) `count` FROM `uniids`'); + $rCount = sql_fetch_array($rsCount); + mysql_free_result($rsCount); + + tpl_set_var('resultscount', $rCount['count']); + + // seitennummern erstellen + $maxsite = ceil($rCount['count'] / 20) - 1; + $pages = ''; + + if ($locidsite > 0) + $pages .= '<< < '; + else + $pages .= '<< < '; + + $frompage = $locidsite - 3; + if ($frompage < 1) $frompage = 1; + + $topage = $frompage + 8; + if ($topage > $maxsite) $topage = $maxsite + 1; + + for ($i = $frompage; $i <= $topage; $i++) + { + if (($locidsite + 1) == $i) + { + $pages .= '' . $i . ' '; + } + else + { + $pages .= '' . $i . ' '; + } + } + + if ($locidsite < $maxsite) + $pages .= '> >> '; + else + $pages .= '> >> '; + + tpl_set_var('pages', $pages); + + $rs = sql_slave('SELECT `gns_locations`.`rc` `rc`, `gns_locations`.`cc1` `cc1`, `gns_locations`.`admtxt1` `admtxt1`, `gns_locations`.`admtxt2` `admtxt2`, `gns_locations`.`admtxt3` `admtxt3`, `gns_locations`.`admtxt4` `admtxt4`, `gns_locations`.`uni` `uni_id`, `gns_locations`.`lon` `lon`, `gns_locations`.`lat` `lat`, `gns_locations`.`full_name` `full_name`, `uniids`.`olduni` `olduni` FROM `gns_locations`, `uniids` WHERE `uniids`.`uni_id`=`gns_locations`.`uni` ORDER BY `gns_locations`.`full_name` ASC LIMIT ' . ($locidsite * 20) . ', 20'); + + $nr = $locidsite * 20 + 1; + $locations = ''; + while ($r = sql_fetch_array($rs)) + { + $thislocation = $locline; + + // locationsdings zusammenbauen + $locString = ''; + if ($r['admtxt1'] != '') + { + if ($locString != '') $locString .= ' > '; + $locString .= htmlspecialchars($r['admtxt1'], ENT_COMPAT, 'UTF-8'); + } + if ($r['admtxt2'] != '') + { + if ($locString != '') $locString .= ' > '; + $locString .= htmlspecialchars($r['admtxt2'], ENT_COMPAT, 'UTF-8'); + } +/* if ($r['admtxt3'] != '') + { + if ($locString != '') $locString .= ' > '; + $locString .= htmlspecialchars($r['admtxt3'], ENT_COMPAT, 'UTF-8'); + } +*/ if ($r['admtxt4'] != '') + { + if ($locString != '') $locString .= ' > '; + $locString .= htmlspecialchars($r['admtxt4'], ENT_COMPAT, 'UTF-8'); + } + + $thislocation = mb_ereg_replace('{parentlocations}', $locString, $thislocation); + + // koordinaten ermitteln + $coordString = help_latToDegreeStr($r['lat']) . ' ' . help_lonToDegreeStr($r['lon']); + $thislocation = mb_ereg_replace('{coords}', htmlspecialchars($coordString, ENT_COMPAT, 'UTF-8'), $thislocation); + + if ($r['olduni'] != 0) + { + // der alte name wurde durch den native-wert ersetzt + $thissecloc = $secondlocationname; + + $r['olduni'] = $r['olduni'] + 0; + $rsSecLoc = sql_slave('SELECT full_name FROM gns_locations WHERE uni=' . $r['olduni']); + $rSecLoc = sql_fetch_assoc($rsSecLoc); + $thissecloc = mb_ereg_replace('{secondlocationname}', htmlspecialchars($rSecLoc['full_name'], ENT_COMPAT, 'UTF-8'), $thissecloc); + mysql_free_result($rsSecLoc); + + $thislocation = mb_ereg_replace('{secondlocationname}', $thissecloc, $thislocation); + } + else + $thislocation = mb_ereg_replace('{secondlocationname}', '', $thislocation); + + $thislocation = mb_ereg_replace('{locationname}', htmlspecialchars($r['full_name'], ENT_COMPAT, 'UTF-8'), $thislocation); + $thislocation = mb_ereg_replace('{urlparams}', $urlparamString . '&locid={locid}', $thislocation); + $thislocation = mb_ereg_replace('{locid}', urlencode($r['uni_id']), $thislocation); + $thislocation = mb_ereg_replace('{nr}', $nr, $thislocation); + + if ($nr % 2) + $thislocation = mb_ereg_replace('{bgcolor}', $bgcolor1, $thislocation); + else + $thislocation = mb_ereg_replace('{bgcolor}', $bgcolor2, $thislocation); + + $nr++; + $locations .= $thislocation . "\n"; + } + mysql_free_result($rs); + + tpl_set_var('locations', $locations); + + tpl_BuildTemplate(); + exit; +} + + +function outputLocidSelectionForm($locSql, $urlparams) +{ + global $tplname, $locline, $stylepath, $bgcolor1, $bgcolor2; + + require_once($stylepath . '/search1/selectlocid.inc.php'); + + unset($urlparams['queryid']); + unset($urlparams['locid']); + $urlparams['searchto'] = 'search' . $urlparams['searchtype']; + unset($urlparams['searchtype']); + + $tplname = 'search1/selectlocid'; + + // urlparams zusammenbauen + $urlparamString = ''; + foreach ($urlparams AS $name => $param) + { + // workaround for attribs + if (is_array($param)) + { + $pnew = ''; + foreach ($param AS $p) + if ($pnew != '') + $pnew .= ';' . $p; + else + $pnew .= $p; + + $param = $pnew; + } + + if ($urlparamString != '') + $urlparamString .= '&' . $name . '=' . urlencode($param); + else + $urlparamString = $name . '=' . urlencode($param); + } + $urlparamString .= '&locid={locid}'; + + sql_slave('CREATE TEMPORARY TABLE `locids` ENGINE=MEMORY ' . $locSql); + sql_slave('ALTER TABLE `locids` ADD PRIMARY KEY (`loc_id`)'); + + $rs = sql_slave('SELECT `geodb_textdata`.`loc_id` `loc_id`, `geodb_textdata`.`text_val` `text_val` FROM `geodb_textdata`, `locids` WHERE `locids`.`loc_id`=`geodb_textdata`.`loc_id` AND `geodb_textdata`.`text_type`=500100000 ORDER BY `text_val`'); + + $nr = 1; + $locations = ''; + while ($r = sql_fetch_array($rs)) + { + $thislocation = $locline; + + // locationsdings zusammenbauen + $locString = ''; + $land = landFromLocid($r['loc_id']); + if ($land != '') $locString .= htmlspecialchars($land, ENT_COMPAT, 'UTF-8'); + + $rb = regierungsbezirkFromLocid($r['loc_id']); + if ($rb != '') $locString .= ' > ' . htmlspecialchars($rb, ENT_COMPAT, 'UTF-8'); + + $lk = landkreisFromLocid($r['loc_id']); + if ($lk != '') $locString .= ' > ' . htmlspecialchars($lk, ENT_COMPAT, 'UTF-8'); + + $thislocation = mb_ereg_replace('{parentlocations}', $locString, $thislocation); + + // koordinaten ermitteln + $r['loc_id'] = $r['loc_id'] + 0; + $rsCoords = sql_slave('SELECT `lon`, `lat` FROM `geodb_coordinates` WHERE loc_id=' . $r['loc_id'] . ' LIMIT 1'); + if ($rCoords = sql_fetch_array($rsCoords)) + $coordString = help_latToDegreeStr($rCoords['lat']) . ' ' . help_lonToDegreeStr($rCoords['lon']); + else + $coordString = '[keine Koordinaten vorhanden]'; + + $thislocation = mb_ereg_replace('{coords}', htmlspecialchars($coordString, ENT_COMPAT, 'UTF-8'), $thislocation); + $thislocation = mb_ereg_replace('{locationname}', htmlspecialchars($r['text_val'], ENT_COMPAT, 'UTF-8'), $thislocation); + $thislocation = mb_ereg_replace('{urlparams}', $urlparamString, $thislocation); + $thislocation = mb_ereg_replace('{locid}', urlencode($r['loc_id']), $thislocation); + $thislocation = mb_ereg_replace('{nr}', $nr, $thislocation); + $thislocation = mb_ereg_replace('{secondlocationname}', '', $thislocation); + + if ($nr % 2) + $thislocation = mb_ereg_replace('{bgcolor}', $bgcolor1, $thislocation); + else + $thislocation = mb_ereg_replace('{bgcolor}', $bgcolor2, $thislocation); + + $nr++; + $locations .= $thislocation . "\n"; + } + tpl_set_var('locations', $locations); + + tpl_set_var('resultscount', mysql_num_rows($rs)); + tpl_set_var('pages', '<< < 1 > >>'); + + tpl_BuildTemplate(); + exit; +} + +?> diff --git a/htdocs/templates2/ocstyle/search.tpl b/htdocs/templates2/ocstyle/search.tpl index 7ee7a6a8..a3440f85 100644 --- a/htdocs/templates2/ocstyle/search.tpl +++ b/htdocs/templates2/ocstyle/search.tpl @@ -261,7 +261,7 @@ function switchAttributeCat2() {/literal} -
{t}Search for caches{/t}{t}Search for caches{/t}
+
{t}Search for caches{/t}{t}Search for caches{/t}   (→ {t}old{/t})
@@ -273,7 +273,7 @@ function switchAttributeCat2()
  -
+