public function run() { $rsDuplicatePic = sql('SELECT `object_id`, `title` FROM `pictures` WHERE `object_type`=1 GROUP BY `object_id`, `title` HAVING COUNT(*) > 1'); while ($rDuplicatePic = sql_fetch_assoc($rsDuplicatePic)) { $rsInstances = sql(" SELECT `pictures`.`id` `picid`, `cache_logs`.`cache_id` `cache_id`\n FROM `pictures`\n LEFT JOIN `cache_logs` ON `cache_logs`.`id` = `pictures`.`object_id`\n WHERE `pictures`.`object_type`=1 AND `pictures`.`object_id`='&1' AND `pictures`.`title`='&2'\n ORDER BY `pictures`.`date_created`", $rDuplicatePic['object_id'], $rDuplicatePic['title']); $instances = sql_fetch_assoc_table($rsInstances); foreach ($instances as &$instance) { $instance['pic'] = new picture($instance['picid']); $instance['filesize'] = @filesize($instance['pic']->getFilename()); } $countInstances = count($instances); for ($n = 1; $n < $countInstances; ++$n) { if ($instances[$n]['filesize'] !== false) { // ensure that pic is stored locally for ($nn = $n - 1; $nn >= 0; --$nn) { if ($instances[$nn]['filesize'] === $instances[$n]['filesize']) { if (file_get_contents($instances[$nn]['pic']->getFilename()) == file_get_contents($instances[$n]['pic']->getFilename())) { $picture = $instances[$n]['pic']; echo 'deleting duplicate picture ' . $picture->getPictureId() . ' ("' . $picture->getTitle() . '")' . ' from log ' . $rDuplicatePic['object_id'] . ' of cache ' . $instances[$n]['cache_id'] . "\n"; $picture->delete(false); $instances[$n]['filesize'] = false; break; } } } } } } sql_free_result($rsDuplicatePic); }
function outputSearchForm($options) { global $tpl, $login, $opt; global $error_plz, $error_locidnocoords, $error_ort, $error_noort, $error_nofulltext, $error_fulltexttoolong; global $cache_attrib_jsarray_line, $cache_attrib_group, $cache_attrib_img_line1, $cache_attrib_img_line2; global $DEFAULT_SEARCH_DISTANCE; $tpl->assign('formmethod', 'get'); // checkboxen $tpl->assign('logged_in', $login->logged_in()); if (isset($options['sort'])) { $bBynameChecked = $options['sort'] == 'byname'; } else { $bBynameChecked = !$login->logged_in(); } $tpl->assign('byname_checked', $bBynameChecked); if (isset($options['sort'])) { $bBydistanceChecked = $options['sort'] == 'bydistance'; } else { $bBydistanceChecked = $login->logged_in(); } $tpl->assign('bydistance_checked', $bBydistanceChecked); if (isset($options['sort'])) { $bBycreatedChecked = $options['sort'] == 'bycreated'; } else { $bBycreatedChecked = !$login->logged_in(); } $tpl->assign('bycreated_checked', $bBycreatedChecked); if (isset($options['sort'])) { $bBylastlogChecked = $options['sort'] == 'bylastlog'; } else { $bBylastlogChecked = $login->logged_in(); } $tpl->assign('bylastlog_checked', $bBylastlogChecked); if (isset($options['sort'])) { $bBymylastlogChecked = $options['sort'] == 'bymylastlog'; } else { $bBymylastlogChecked = $login->logged_in(); } $tpl->assign('bymylastlog_checked', $bBymylastlogChecked); $tpl->assign('hidopt_sort', $options['sort']); $tpl->assign('orderRatingFirst_checked', $options['orderRatingFirst']); $tpl->assign('hidopt_orderRatingFirst', $options['orderRatingFirst'] ? '1' : '0'); $tpl->assign('f_userowner_checked', $login->logged_in() && $options['f_userowner'] == 1); $tpl->assign('hidopt_userowner', $options['f_userowner'] == 1 ? '1' : '0'); $tpl->assign('f_userfound_checked', $login->logged_in() && $options['f_userfound'] == 1); $tpl->assign('hidopt_userfound', $options['f_userfound'] == 1 ? '1' : '0'); $tpl->assign('f_ignored_checked', $login->logged_in() && $options['f_ignored'] == 1); $tpl->assign('hidopt_ignored', $options['f_ignored'] == 1 ? '1' : '0'); $tpl->assign('f_disabled_checked', $options['f_disabled'] == 1); $tpl->assign('hidopt_disabled', $options['f_disabled'] == 1 ? '1' : '0'); // archived is called "disabled" here for backward compatibility $tpl->assign('f_inactive_checked', $options['f_inactive'] == 1); $tpl->assign('hidopt_inactive', $options['f_inactive'] == 1 ? '1' : '0'); $tpl->assign('f_otherPlatforms_checked', $options['f_otherPlatforms'] == 1); $tpl->assign('hidopt_otherPlatforms', $options['f_otherPlatforms'] == 1 ? '1' : '0'); $tpl->assign('f_geokrets_checked', $options['f_geokrets'] == 1); $tpl->assign('hidopt_geokrets', $options['f_geokrets'] == 1 ? '1' : '0'); if (!isset($options['country'])) { $options['country'] = ''; } $tpl->assign('country', htmlspecialchars($options['country'], ENT_COMPAT, 'UTF-8')); if (!isset($options['language'])) { $options['language'] = ''; } $tpl->assign('language', htmlspecialchars($options['language'], ENT_COMPAT, 'UTF-8')); if (isset($options['cachetype'])) { $tpl->assign('cachetype', htmlspecialchars($options['cachetype'], ENT_COMPAT, 'UTF-8')); } else { $tpl->assign('cachetype', ''); } // cachename $tpl->assign('cachename', isset($options['cachename']) ? htmlspecialchars($options['cachename'], ENT_COMPAT, 'UTF-8') : ''); // koordinaten if (!isset($options['lat_h'])) { if ($login->logged_in()) { $rs = sql('SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`=\'' . sql_escape($login->userid) . '\''); $record = sql_fetch_array($rs); $lon = $record['longitude']; $lat = $record['latitude']; sql_free_result($rs); $tpl->assign('lonE_sel', $lon >= 0); $tpl->assign('lonW_sel', $lon < 0); $tpl->assign('latN_sel', $lat >= 0); $tpl->assign('latS_sel', $lat < 0); $lon_h = floor($lon); $lat_h = floor($lat); $lon_min = ($lon - $lon_h) * 60; $lat_min = ($lat - $lat_h) * 60; $tpl->assign('lat_h', $lat_h); $tpl->assign('lon_h', $lon_h); $tpl->assign('lat_min', sprintf("%02.3f", $lat_min)); $tpl->assign('lon_min', sprintf("%02.3f", $lon_min)); } else { $tpl->assign('lat_h', '00'); $tpl->assign('lon_h', '000'); $tpl->assign('lat_min', '00.000'); $tpl->assign('lon_min', '00.000'); } } else { $tpl->assign('lat_h', isset($options['lat_h']) ? $options['lat_h'] : '00'); $tpl->assign('lon_h', isset($options['lon_h']) ? $options['lon_h'] : '000'); $tpl->assign('lat_min', isset($options['lat_min']) ? $options['lat_min'] : '00.000'); $tpl->assign('lon_min', isset($options['lon_min']) ? $options['lon_min'] : '00.000'); if ($options['lonEW'] == 'W') { $tpl->assign('lonE_sel', ''); $tpl->assign('lonW_sel', 'selected="selected"'); } else { $tpl->assign('lonE_sel', 'selected="selected"'); $tpl->assign('lonW_sel', ''); } if ($options['latNS'] == 'S') { $tpl->assign('latS_sel', 'selected="selected"'); $tpl->assign('latN_sel', ''); } else { $tpl->assign('latS_sel', ''); $tpl->assign('latN_sel', 'selected="selected"'); } } $tpl->assign('distance', isset($options['distance']) ? $options['distance'] : $DEFAULT_SEARCH_DISTANCE); if (!isset($options['unit'])) { $options['unit'] = $DEFAULT_DISTANCE_UNIT; } $tpl->assign('sel_km', $options['unit'] == 'km'); $tpl->assign('sel_sm', $options['unit'] == 'sm'); $tpl->assign('sel_nm', $options['unit'] == 'nm'); // plz $tpl->assign('plz', isset($options['plz']) ? htmlspecialchars($options['plz'], ENT_COMPAT, 'UTF-8') : ''); $tpl->assign('ort', isset($options['ort']) ? htmlspecialchars($options['ort'], ENT_COMPAT, 'UTF-8') : ''); // owner $tpl->assign('owner', isset($options['owner']) ? htmlspecialchars($options['owner'], ENT_COMPAT, 'UTF-8') : ''); // finder $tpl->assign('finder', isset($options['finder']) ? htmlspecialchars($options['finder'], ENT_COMPAT, 'UTF-8') : ''); // country options $rs = sql("\n\t\tSELECT\n\t\t\tIFNULL(`sys_trans_text`.`text`, `countries`.`name`) AS `name`,\n\t\t\t`countries`.`short`,\n\t\t\t`countries`.`short`='&2' AS `selected`\n\t\tFROM\n\t\t\t`countries`\n\t\t\tLEFT JOIN `sys_trans` ON `countries`.`trans_id`=`sys_trans`.`id`AND `sys_trans`.`text`=`countries`.`name`\n\t\t\tLEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1'\n\t\tWHERE\n\t\t\t`countries`.`short` IN (SELECT DISTINCT `country` FROM `caches`) ORDER BY `name` ASC", $opt['template']['locale'], $options['country']); $tpl->assign_rs('countryoptions', $rs); sql_free_result($rs); $tpl->assign('all_countries', $options['country'] == ''); // language options $rs = sql("\n\t\tSELECT\n\t\t\tIFNULL(`sys_trans_text`.`text`,`languages`.`name`) AS `name`,\n\t\t\t`short`,\n\t\t\t`short`='&2' AS `selected`\n\t\tFROM\n\t\t\t`languages`\n\t\t\tLEFT JOIN `sys_trans` ON `sys_trans`.`text`=`languages`.`name`\n\t\t\tLEFT JOIN `sys_trans_text` ON `sys_trans_text`.`trans_id`=`sys_trans`.`id` AND `sys_trans_text`.`lang`='&1'\n\t\t\tORDER BY `name`", $opt['template']['locale'], $options['language']); $tpl->assign_rs('languageoptions', $rs); sql_free_result($rs); $tpl->assign('all_languages', $options['language'] == ''); // cachetype $rs = sql("SELECT `id` FROM `cache_type` ORDER BY `ordinal`"); $rCachetypes = sql_fetch_assoc_table($rs); foreach ($rCachetypes as &$rCachetype) { $rCachetype['checked'] = $options['cachetype'] == '' || strpos(';' . $options['cachetype'] . ';', ';' . $rCachetype['id'] . ';') !== false; $rCachetype['unchecked'] = !$rCachetype['checked']; } $tpl->assign('cachetypes', $rCachetypes); $tpl->assign('cachetype', $options['cachetype']); // cachesize $cachesizes = array(); $rs = sql("SELECT `id` FROM `cache_size`"); while ($r = sql_fetch_assoc($rs)) { $cachesizes[$r['id']]['checked'] = strpos(';' . $options['cachesize'] . ';', ';' . $r['id'] . ';') !== false || $options['cachesize'] == ''; } sql_free_result($rs); $tpl->assign('cachesizes', $cachesizes); $tpl->assign('cachesize', $options['cachesize']); // difficulty + terrain $tpl->assign('difficultymin', $options['difficultymin']); $tpl->assign('difficultymax', $options['difficultymax']); $tpl->assign('difficulty_options', array(0, 2, 3, 4, 5, 6, 7, 8, 9, 10)); $tpl->assign('terrainmin', $options['terrainmin']); $tpl->assign('terrainmax', $options['terrainmax']); $tpl->assign('terrain_options', array(0, 2, 3, 4, 5, 6, 7, 8, 9, 10)); // logtypen if (isset($options['logtype'])) { $logtypes = explode(',', $options['logtype']); } else { $logtypes = array(); } $rs = sql("\n\t\tSELECT `id`,\n\t\tIFNULL(`sys_trans_text`.`text`, `log_types`.`name`) AS `name`,\n\t\t`id`='&2' as `selected`\n\t\tFROM (\n\t\t\tSELECT `id`,`name`,`trans_id` FROM `log_types`\n\t\t\tUNION\n\t\t\tSELECT 0,'all',(SELECT id FROM sys_trans WHERE `text`='all')\n\t\t) `log_types`\n\t\tLEFT JOIN `sys_trans_text` ON `sys_trans_text`.`trans_id`=`log_types`.`trans_id` AND `sys_trans_text`.`lang`='&1'\n\t ORDER BY `log_types`.`id` ASC", $opt['template']['locale'], $logtypes ? $logtypes[0] : 0); $tpl->assign_rs('logtype_options', $rs); sql_free_result($rs); // 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", $opt['template']['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`\n\t\t FROM `cache_attrib`\n\t\t LEFT JOIN `sys_trans` AS `tname` ON `cache_attrib`.`trans_id`=`tname`.`id` AND `cache_attrib`.`name`=`tname`.`text`\n\t\t LEFT JOIN `sys_trans_text` AS `ttname` ON `tname`.`id`=`ttname`.`trans_id` AND `ttname`.`lang`='&1'\n\t\t LEFT JOIN `sys_trans` AS `tdesc` ON `cache_attrib`.`html_desc_trans_id`=`tdesc`.`id` AND `cache_attrib`.`html_desc`=`tdesc`.`text`\n\t\t LEFT JOIN `sys_trans_text` AS `ttdesc` ON `tdesc`.`id`=`ttdesc`.`trans_id` AND `ttdesc`.`lang`='&1'\n\t\t WHERE `cache_attrib`.`group_id`='&2' AND `selectable`\n\t\t\t\t\t AND NOT IFNULL(`cache_attrib`.`hidden`, 0)=1\n\t\t ORDER BY `cache_attrib`.`id`", $opt['template']['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 .= '<div id="attribs2">'; $bBeginLine2 = false; } $attributes_img2 .= $group_img; $nPrevLineAttrCount2 += $nLineAttrCount2; $nLineAttrCount2 = 0; } } sql_free_result($rsAttrGroup); if ($bBeginLine2 == false) { $attributes_img2 .= '</div>'; } /* 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", $opt['template']['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`\n\t\t FROM `cache_attrib`\n\t\t LEFT JOIN `sys_trans` AS `tname` ON `cache_attrib`.`trans_id`=`tname`.`id` AND `cache_attrib`.`name`=`tname`.`text`\n\t\t LEFT JOIN `sys_trans_text` AS `ttname` ON `tname`.`id`=`ttname`.`trans_id` AND `ttname`.`lang`='&1'\n\t\t LEFT JOIN `sys_trans` AS `tdesc` ON `cache_attrib`.`html_desc_trans_id`=`tdesc`.`id` AND `cache_attrib`.`html_desc`=`tdesc`.`text`\n\t\t LEFT JOIN `sys_trans_text` AS `ttdesc` ON `tdesc`.`id`=`ttdesc`.`trans_id` AND `ttdesc`.`lang`='&1'\n\t\t WHERE `cache_attrib`.`group_id`='&2'\n\t\t AND `cache_attrib`.`search_default`=1 AND `selectable`\n\t\t\t\t\t AND NOT IFNULL(`cache_attrib`.`hidden`, 0)=1\n\t\t ORDER BY `cache_attrib`.`id`", $opt['template']['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 .= '<div id="attribs1">'; $bBeginLine1 = false; } $attributes_img1 .= $group_img; $nPrevLineAttrCount1 += $nLineAttrCount1; $nLineAttrCount1 = 0; } } sql_free_result($rsAttrGroup); if ($bBeginLine1 == false) { $attributes_img1 .= '</div>'; } $tpl->assign('cache_attribCat1_list', $attributes_img1); $tpl->assign('cache_attribCat2_list', $attributes_img2); $tpl->assign('attributes_jsarray', $attributes_jsarray); $tpl->assign('hidopt_attribs', isset($options['cache_attribs']) ? implode(';', $options['cache_attribs']) : ''); $tpl->assign('hidopt_attribs_not', isset($options['cache_attribs_not']) ? implode(';', $options['cache_attribs_not']) : ''); $tpl->assign('fulltext', ''); $tpl->assign('ft_desc_checked', true); $tpl->assign('ft_name_checked', true); $tpl->assign('ft_pictures_checked', false); $tpl->assign('ft_logs_checked', false); // fulltext options if ($options['searchtype'] == 'byfulltext') { if (!isset($options['fulltext'])) { $options['fulltext'] = ''; } $tpl->assign('fulltext', htmlspecialchars($options['fulltext'], ENT_COMPAT, 'UTF-8')); if (isset($options['ft_name'])) { $tpl->assign('ft_name_checked', $options['ft_name'] == 1); } if (isset($options['ft_desc'])) { $tpl->assign('ft_desc_checked', $options['ft_desc'] == 1); } if (isset($options['ft_logs'])) { $tpl->assign('ft_logs_checked', $options['ft_logs'] == 1); } if (isset($options['ft_pictures'])) { $tpl->assign('ft_pictures_checked', $options['ft_pictures'] == 1); } } // errormeldungen $tpl->assign('ortserror', ''); if (isset($options['error_plz'])) { $tpl->assign('ortserror', $error_plz); } else { if (isset($options['error_ort'])) { $tpl->assign('ortserror', $error_ort); } else { if (isset($options['error_locidnocoords'])) { $tpl->assign('ortserror', $error_locidnocoords); } else { if (isset($options['error_noort'])) { $tpl->assign('ortserror', $error_noort); } } } } $tpl->assign('fulltexterror', ''); if (isset($options['error_nofulltext'])) { $tpl->assign('fulltexterror', $error_nofulltext); } else { if (isset($options['error_fulltexttoolong'])) { $tpl->assign('fulltexterror', $error_fulltexttoolong); } } $tpl->display(); }
function search_output() { global $opt, $tpl, $login; global $enable_mapdisplay; global $called_by_search, $called_by_profile_query, $options, $lat_rad, $lon_rad, $distance_unit; global $startat, $caches_per_page, $sql, $query_userid, $query_name; $tpl->name = 'search.result.caches'; $tpl->menuitem = MNU_CACHES_SEARCH_RESULT; $startat = floor($startat / $caches_per_page) * $caches_per_page; $sql .= ' LIMIT ' . $startat . ', ' . $caches_per_page; // run SQL query sql_enable_foundrows(); $rs_caches = sql_slave("SELECT SQL_BUFFER_RESULT SQL_CALC_FOUND_ROWS " . $sql); $resultcount = sql_value_slave('SELECT FOUND_ROWS()', 0); sql_foundrows_done(); $tpl->assign('results_count', $resultcount); $tpl->assign('startat', $startat); $caches = array(); while ($rCache = sql_fetch_array($rs_caches)) { // select best-fitting short desc for active language $rCache['short_desc'] = sql_value_slave("\n SELECT `short_desc`\n FROM `cache_desc`\n WHERE `cache_id`='&1'\n AND `language`='&2'", false, $rCache['cache_id'], $opt['template']['locale']); if ($rCache['short_desc'] === false) { $rCache['short_desc'] = sql_value_slave("\n\t\t\t\tSELECT `short_desc`\n\t\t\t\tFROM `cache_desc`\n\t\t\t\tWHERE `cache_id`='&1'\n\t\t\t\tAND `language`='EN'", false, $rCache['cache_id']); } if ($rCache['short_desc'] === false) { $rCache['short_desc'] = sql_value_slave("\n\t\t\t\tSELECT `short_desc`\n\t\t\t\tFROM `cache_desc`\n\t\t\t\tWHERE `cache_id`='&1'\n\t\t\t\tORDER BY `date_created`\n\t\t\t\tLIMIT 1", '', $rCache['cache_id']); } $rCache['desclangs'] = mb_split(',', $rCache['desc_languages']); // decide if the cache is new $dDiff = dateDiff('d', $rCache['date_created'], date('Y-m-d')); $rCache['isnew'] = $dDiff <= NEWCACHES_DAYS; // get last logs if ($options['sort'] != 'bymylastlog' || !$login->logged_in()) { $ownlogs = ""; } else { $ownlogs = " AND `cache_logs`.`user_id`='" . sql_escape($login->userid) . "'"; } $sql = "\n\t\t\t\tSELECT `cache_logs`.`id`, `cache_logs`.`type`, `cache_logs`.`date`, `log_types`.`icon_small`\n\t\t\t\tFROM `cache_logs`, `log_types`\n\t\t\t\tWHERE `cache_logs`.`cache_id`='" . sql_escape($rCache['cache_id']) . "'\n\t\t\t\t AND `log_types`.`id`=`cache_logs`.`type`" . $ownlogs . "\n\t\t\t\tORDER BY `cache_logs`.`order_date` DESC, `cache_logs`.`date_created` DESC, `cache_logs`.`id` DESC\n\t\t\t\tLIMIT 6"; $rs = sql_slave($sql); $rCache['logs'] = sql_fetch_assoc_table($rs); $rCache['firstlog'] = array_shift($rCache['logs']); // get direction from search coordinate if ($rCache['distance'] > 0) { $direction = geomath::calcBearing($lat_rad / 3.14159 * 180, $lon_rad / 3.14159 * 180, $rCache['latitude'], $rCache['longitude']); $rCache['direction_deg'] = round($direction / 22.5) * 22.5; $rCache['direction_txt'] = geomath::Bearing2Text($direction, 0, $opt['template']['locale']); } else { $rCache['direction_deg'] = false; } // other data $rCache['icon'] = getCacheIcon($login->userid, $rCache['cache_id'], $rCache['status'], $rCache['user_id'], $rCache['icon_large']); $rCache['redname'] = $rCache['status'] == 5 || $rCache['status'] == 7; $caches[] = $rCache; } mysql_free_result($rs_caches); $tpl->assign('caches', $caches); $page = 'search.php?queryid=' . $options['queryid'] . '&startat={offset}&sortby=' . $options['sort']; if (isset($options['sortorder']) && $options['sortorder']) { $page .= "&sortorder=" . $options['sortorder']; } if (isset($options['creationdate']) && $options['creationdate']) { $page .= "&creationdate=" . $options['creationdate']; } $pager = new pager($page, 2, 9); $pager->make_from_offset($startat, $resultcount, $caches_per_page); // downloads $tpl->assign('queryid', $options['queryid']); if (isset($query_userid)) { $tpl->assign('query_name', $query_name); } $tpl->assign('startatp1', min($resultcount, $startat + 1)); if ($resultcount - $startat < 500) { $tpl->assign('endat', $startat + $resultcount - $startat); } else { $tpl->assign('endat', $startat + 500); } // kompatibilität! if ($distance_unit == 'sm') { $tpl->assign('distanceunit', 'mi'); } elseif ($distance_unit == 'nm') { $tpl->assign('distanceunit', 'sm'); } else { $tpl->assign('distanceunit', $distance_unit); } $tpl->assign('displayownlogs', $options['sort'] == 'bymylastlog'); $tpl->assign('search_headline_caches', $called_by_search); $tpl->assign('enable_mapdisplay', $enable_mapdisplay); // sort results by $tpl->assign('sortby', $options['sort']); if (isset($options['sortorder'])) { $tpl->assign('sortorder', $options['sortorder']); } if ($options['sort'] == 'bycreated' || isset($options['creationdate'])) { $tpl->assign('creationdate', true); } // cachelist data if (isset($options['cachelist'])) { $tpl->assign('cachelist', $options['cachelist']); $tpl->assign('cachelist_pw', $options['cachelist_pw']); } else { $tpl->assign('cachelist', false); } // disable "edit options" for internally generated searches if ($options['searchtype'] == 'bylist') { $tpl->assign('disable_edit_options', true); } $tpl->display(); }
function get_logpics($purpose, $userid = 0, $cacheid = 0) { global $login; $fields = "`pics`.`uuid` AS `pic_uuid`, `pics`.`url` AS `pic_url`,\n\t\t\t `pics`.`title`, `pics`.`date_created`,\n\t\t\t `logs`.`user_id`, `logs`.`cache_id`,\n\t\t\t `logs`.`date` AS `logdate`, `pics`.`date_created` < LEFT(NOW(),4) AS `oldyear`,\n\t\t\t\t\t\t\t\t\t`logs`.`id` AS `logid`, `logs`.`type` AS `logtype`"; $join_logs = "INNER JOIN `cache_logs` `logs` ON `logs`.`id`=`pics`.`object_id`"; $join_caches = "INNER JOIN `caches` ON `caches`.`cache_id`=`logs`.`cache_id`"; $join_cachestatus = "INNER JOIN `cache_status` ON `caches`.`status`=`cache_status`.`id` AND `allow_user_view`=1"; $join_user = "******"; $rs = false; switch ($purpose) { case LOGPICS_FOR_STARTPAGE_GALLERY: // one pic per user and day, // one pic per cache and day // no spoilers, no bad data, no invisible or unpublished caches // The group-by via nested query make this whole thing sufficiently performant. // Direct group-bys combined with the wheres are awful slow, and no kind of // index seems to be good enough to speed it up. // Indexing the for the inner WHERE seems rather useless, as it filters out // only a few percent of caches. We must rely on fast data caching. $rs = sql_slave("SELECT {$fields}, `user`.`username`, `pics`.`date_created` AS `picdate`\n\t\t\t\t FROM (SELECT * FROM\n\t\t\t\t (SELECT `uuid`, `url`, `title`, `date_created`, `object_id` FROM `pictures`\n \t\t WHERE `local`=1 AND `display`=1 AND `spoiler`=0 AND `unknown_format`=0\n\t \t AND `object_type`=1\n\t ORDER BY `date_created` DESC\n\t\t LIMIT 240) `piics`\n\t\t\t\t \t\t\t /* 20 times reserve for filtering out user dups, cache dups and invisibles */\n GROUP BY `object_id`, LEFT(`date_created`,10)) `pics` /* max. 1 pic per cache and day */\n {$join_logs}\n {$join_caches}\n {$join_cachestatus}\n {$join_user}\n GROUP BY `user`.`user_id`, LEFT(`pics`.`date_created`,10) /* max. 1 pic per user and day */\n\t ORDER BY `pics`.`date_created` DESC\n\t\t\t\t\t LIMIT 6"); break; case LOGPICS_FOR_NEWPICS_GALLERY: // like above, without the "one pic per cache and day" condition // This saves us one grouped subquery. $rs = sql_slave("SELECT {$fields}, `user`.`username`, `pics`.`date_created` AS `picdate`\n FROM (SELECT `uuid`, `url`, `title`, `date_created`, `object_id` FROM `pictures`\n\t\t\t\t\t\t\t\t WHERE `local`=1 AND `display`=1 AND `spoiler`=0 AND `unknown_format`=0\n\t\t\t AND `object_type`=1\n\t\t \t ORDER BY `date_created` DESC\n\t\t\t LIMIT 600) `pics`\n\t\t\t /* 10 times reserve for filtering out user dups and invisibles */\n \t {$join_logs}\n \t {$join_caches}\n \t {$join_cachestatus}\n \t {$join_user}\n\t\t\t GROUP BY `user`.`user_id`, LEFT(`pics`.`date_created`,10)\n\t\t\t ORDER BY `date_created` DESC\n\t\t\t\t\t\t\t LIMIT &1", MAX_PICTURES_PER_GALLERY_PAGE); break; case LOGPICS_FOR_USER_STAT: // just count all the logpics of one user // It's faster, sensible and consistend with cache and log handling to count // also invisible data here. Actually, it is present, the pic was made and // uploaded with a log, and it is still visible for the logger himself // (and hopfully some time for all, independend of the invisible listing!). $result = sql_value_slave("SELECT COUNT(*)\n\t\t FROM `pictures` `pics`\n\t\t\t {$join_logs}\n\t\t\t\t\t WHERE `pics`.`object_type`=1 AND `logs`.`user_id`='&1'", 0, $userid); break; case LOGPICS_FOR_USER_GALLERY: // all pics of one user, except spoilers and invisibles $rs = sql("SELECT {$fields}, `logs`.`date` AS `picdate`\n\t\t\t \t FROM `pictures` `pics`\n\t\t {$join_logs}\n\t\t {$join_caches}\n\t\t {$join_cachestatus}\n\t\t WHERE `object_type`=1 AND `logs`.`user_id`='&1' AND NOT `spoiler`\n\t\t\t\t ORDER BY `logs`.`date` DESC", $userid); break; case LOGPICS_FOR_MYHOME_GALLERY: // all picture of one user, with the only exception of zombie pix hanging // by an old log deletion (we should remove those ...) $rs = sql("SELECT {$fields}, `logs`.`date` AS `picdate`\n\t FROM `pictures` AS `pics`\n {$join_logs}\n WHERE `object_type`=1 AND `logs`.`user_id`='&1' \n ORDER BY `logs`.`date` DESC", $login->userid); break; case LOGPICS_FOR_CACHE_STAT: // all pictures for a cache except license-replacement pics // need not to exclude invisible caches, as this is only displayed in listing view $result = sql_value("SELECT COUNT(*)\n\t\t\t\t FROM `pictures` AS `pics`\n\t\t\t\t {$join_logs}\n\t\t\t\t {$join_user}\n WHERE `object_type`=1 AND `logs`.`cache_id`='&1'\n\t\t\t\t\t\t\t\t\t\t AND NOT (`data_license` IN ('&2','&3'))", 0, $cacheid, NEW_DATA_LICENSE_ACTIVELY_DECLINED, NEW_DATA_LICENSE_PASSIVELY_DECLINED); break; case LOGPICS_FOR_CACHE_GALLERY: // all picture for a cache except license-replacement pics // for all users except owner: also excluding invisble caches $rs = sql("SELECT {$fields}, `user`.`username`, `logs`.`date` AS `picdate`\n\t FROM `pictures` AS `pics`\n\t {$join_logs} " . ($userid == $login->userid ? "" : "{$join_caches} {$join_cachestatus}") . "\n\t {$join_user}\n WHERE `object_type`=1 AND `logs`.`cache_id`='&1'\n\t\t\t\t\t\t\t\t\t\t AND NOT (`data_license` IN ('&2','&3'))\n ORDER BY `logs`.`date` DESC", $cacheid, NEW_DATA_LICENSE_ACTIVELY_DECLINED, NEW_DATA_LICENSE_PASSIVELY_DECLINED); break; default: global $tpl; $tpl->error(ERROR_INVALID_OPERATION); return null; } if ($rs !== false) { $result = sql_fetch_assoc_table($rs); foreach ($result as &$logpic) { $logpic['pic_url'] = use_current_protocol($logpic['pic_url']); } } return $result; }
private function getLists($condition, $prio = 0, $startat = 0, $maxitems = PHP_INT_MAX) { global $login; $login->verify(); $rs = sql("\n\t\t\tSELECT `cache_lists`.`id`, `cache_lists`.`user_id`, `user`.`username`, \n\t\t\t `cache_lists`.`name`, `cache_lists`.`is_public` `visibility`,\n\t\t\t `cache_lists`.`description`, `cache_lists`.`desc_htmledit`,\n\t\t\t `cache_lists`.`user_id`='&1' `own_list`,\n\t\t\t `stat_cache_lists`.`entries`, `stat_cache_lists`.`watchers`,\n\t\t\t `w`.`user_id` IS NOT NULL `watched_by_me`,\n\t\t\t {$prio} `prio`\n\t\t\tFROM `cache_lists`\n\t\t\tLEFT JOIN `stat_cache_lists` ON `stat_cache_lists`.`cache_list_id`=`cache_lists`.`id`\n\t\t\tLEFT JOIN `user` ON `user`.`user_id`=`cache_lists`.`user_id`\n\t\t\tLEFT JOIN `cache_list_watches` `w` ON `w`.`cache_list_id`=`cache_lists`.`id` AND `w`.`user_id`='&1'\n\t\t\tWHERE {$condition}\n\t\t\tORDER BY `prio`,`cache_lists`.`name`\n\t\t\tLIMIT &2,&3", $login->userid, $startat, $maxitems); return sql_fetch_assoc_table($rs); }
if ($rCache['waylength'] < 50) { if (round($rCache['waylength'], 1) != round($rCache['waylength'], 0)) { $digits = 1; } else { $digits = 0; } } else { $digits = 0; } } $rCache['waylength'] = sprintf('%.' . $digits . 'f', $rCache['waylength']); // replace links $rCache['desc'] = use_current_protocol_in_html($rCache['desc']); $rCache['adminlog'] = !$rCache['log_allowed'] && $login->admin & ADMIN_USER; $rs = sql("\n\t\tSELECT `short` `code`, `native_name`, `stt`.`text` AS `name`\n\t\tFROM `languages`\n\t\tJOIN `cache_desc` ON `cache_desc`.`language`=`languages`.`short`\n\t\tLEFT JOIN `sys_trans_text` `stt` ON `stt`.`trans_id`=`languages`.`trans_id` AND `stt`.`lang`='&2'\n\t\tWHERE `cache_desc`.`cache_id`='&1'", $cacheid, $opt['template']['locale']); $desclanguages = sql_fetch_assoc_table($rs); if (count($desclanguages) == 1 && $desclanguages[0]['code'] == $opt['template']['locale']) { $rCache['desclanguages'] = array(); } else { $rCache['desclanguages'] = $desclanguages; } $rCache['sizeName'] = labels::getLabelValue('cache_size', $rCache['size']); $rCache['statusName'] = labels::getLabelValue('cache_status', $rCache['status']); $rCache['typeName'] = labels::getLabelValue('cache_type', $rCache['type']); $rCache['userhasfound'] = false; if ($login->userid != 0) { $rCache['userhasfound'] = sql_value("SELECT COUNT(*) FROM `cache_logs` WHERE `cache_id`='&1' AND `user_id`='&2' AND `type` IN (1,7)", 0, $cacheid, $login->userid) > 0; } $tpl->assign('cache', $rCache); $tpl->title = $rCache['wpoc'] . ' ' . $rCache['name']; $coord = new coordinate($rCache['latitude'], $rCache['longitude']);
public static function getLogsArray($cacheid, $start, $count, $deleted = false, $protect_old_coords = false) { global $login, $translate; // negative or abornally high numbers like 1.0E+15 can crash the LIMIT statement if ($count <= 0 || $count > 10000) { return array(); } $rsCoords = sql("SELECT `date_created` `date`, `latitude`, `longitude`\n\t\t\t FROM `cache_coordinates`\n\t\t\t WHERE `cache_id`='&1'\n\t\t\t ORDER BY `date_created` DESC", $cacheid); $coords = sql_fetch_assoc_table($rsCoords); if ($coords) { $coords[] = ['date' => '0000-00-00', 'latitude' => $coords[count($coords) - 1]['latitude'], 'longitude' => $coords[count($coords) - 1]['longitude']]; $current_coord = new coordinate($coords[0]['latitude'], $coords[0]['longitude']); } if ($deleted && ($login->admin && ADMIN_USER) > 0) { // admins may view owner-deleted logs $table = 'cache_logs_archived'; $delfields = 'IFNULL(`u2`.`username`,"") AS `deleted_by_name`, `deletion_date`, "1" AS `deleted`'; $addjoin = 'LEFT JOIN `user` `u2` ON `u2`.`user_id`=`cache_logs`.`deleted_by`'; } else { $table = 'cache_logs'; $delfields = '"" AS `deleted_by_name`, NULL AS `deletion_date`, "0" AS `deleted`'; $addjoin = ''; } $rsLogs = sql('SELECT `cache_logs`.`user_id` AS `userid`, `cache_logs`.`id` AS `id`, `cache_logs`.`uuid` AS `uuid`, `cache_logs`.`date` AS `date`, `cache_logs`.`order_date` AS `order_date`, `cache_logs`.`entry_last_modified`, DATEDIFF(`cache_logs`.`entry_last_modified`, `cache_logs`.`date_created`) >= 1 AS `late_modified`, substr(`cache_logs`.`date`,12) AS `time`, /* 00:00:01 = 00:00 logged, 00:00:00 = no time */ `cache_logs`.`type` AS `type`, `cache_logs`.`oc_team_comment` AS `oc_team_comment`, `cache_logs`.`needs_maintenance` AS `needs_maintenance`, `cache_logs`.`listing_outdated` AS `listing_outdated`, `cache_logs`.`text` AS `text`, `cache_logs`.`text_html` AS `texthtml`, `cache_logs`.`picture`, ' . $delfields . ",\n\t\t\t\t `user`.`username` AS `username`,\n\t\t\t\t IF(ISNULL(`cache_rating`.`cache_id`), 0, `cache_logs`.`type` IN (1,7)) AS `recommended`\n\t\t\t FROM {$table} AS `cache_logs`\n\t\t\t INNER JOIN `user` \n\t\t\t ON `user`.`user_id` = `cache_logs`.`user_id`\n\t\t\t LEFT JOIN `cache_rating` \n\t\t\t ON `cache_logs`.`cache_id`=`cache_rating`.`cache_id` \n\t\t\t AND `cache_logs`.`user_id`=`cache_rating`.`user_id` \n\t\t\t AND `cache_logs`.`date`=`cache_rating`.`rating_date`\n\t\t\t " . $addjoin . "\n\t\t\t WHERE `cache_logs`.`cache_id`='&1'\n\t\t\t ORDER BY `cache_logs`.`order_date` DESC, `cache_logs`.`date_created` DESC, `id` DESC\n\t\t\t LIMIT &2, &3", $cacheid, $start + 0, $count + 0); $logs = array(); $coordpos = 0; $coord_changes = false; while ($rLog = sql_fetch_assoc($rsLogs)) { $pictures = array(); $rsPictures = sql("SELECT `url`, `title`, `uuid`, `id`, `spoiler`\n\t\t\t\t FROM `pictures`\n\t\t\t\t WHERE `object_id`='&1' \n\t\t\t\t AND `object_type`=1\n\t\t\t\t ORDER BY `seq`", $rLog['id']); while ($rPicture = sql_fetch_assoc($rsPictures)) { if (trim($rPicture['title']) == '') { $rPicture['title'] = $translate->t('Picture', '', '', 0) . ' ' . (count($pictures) + 1); } $pictures[] = $rPicture; } sql_free_result($rsPictures); $rLog['pictures'] = $pictures; $rLog['text'] = use_current_protocol_in_html($rLog['text']); $newcoord = false; while ($coordpos < count($coords) && $coords[$coordpos]['date'] > $rLog['order_date']) { if (!$newcoord) { $newcoord = $coords[$coordpos]; } ++$coordpos; } if ($newcoord) { $distance = geomath::calcDistance($newcoord['latitude'], $newcoord['longitude'], $coords[$coordpos]['latitude'], $coords[$coordpos]['longitude']); if (abs($distance) > 0.005) { $new = new coordinate($newcoord['latitude'], $newcoord['longitude']); $rLog['newcoord'] = $new->getDecimalMinutes($protect_old_coords && $new != $current_coord); if ($protect_old_coords) { $rLog['movedbykm'] = false; } elseif ($distance <= 1) { $rLog['movedbym'] = floor($distance * 1000); } elseif ($distance < 10) { $rLog['movedbykm'] = sprintf('%1.1f', $distance); } else { $rLog['movedbykm'] = round($distance); } $coord_changes = true; } } $logs[] = $rLog; } sql_free_result($rsLogs); if ($coord_changes) { $original = count($coords) - 1; $lastlogdate = $logs[count($logs) - 1]['order_date']; while ($original > 0 && $coords[$original - 1]['date'] < $lastlogdate) { --$original; } $coord = new coordinate($coords[$original]['latitude'], $coords[$original]['longitude']); $logs[] = ['newcoord' => $coord->getDecimalMinutes($protect_old_coords), 'movedby' => false]; } return $logs; }
private function getLists($condition, $prio = 0, $startat = 0, $maxitems = PHP_INT_MAX) { global $login; $login->verify(); $rs = sql("\n\t\t\tSELECT `cache_lists`.`id`, `cache_lists`.`user_id`, `user`.`username`, \n\t\t\t `cache_lists`.`name`, `cache_lists`.`is_public` `visibility`, `cache_lists`.`password`, \n\t\t\t\t\t\t `cache_lists`.`description`, `cache_lists`.`desc_htmledit`,\n\t\t\t `cache_lists`.`user_id`='&1' `own_list`,\n\t\t\t `stat_cache_lists`.`entries`, `stat_cache_lists`.`watchers`,\n\t\t\t `w`.`user_id` IS NOT NULL `watched_by_me`,\n\t\t\t `b`.`user_id` IS NOT NULL `bookmarked`,\n\t\t\t {$prio} `prio`\n\t\t\tFROM `cache_lists`\n\t\t\tLEFT JOIN `stat_cache_lists` ON `stat_cache_lists`.`cache_list_id`=`cache_lists`.`id`\n\t\t\tLEFT JOIN `user` ON `user`.`user_id`=`cache_lists`.`user_id`\n\t\t\tLEFT JOIN `cache_list_watches` `w` ON `w`.`cache_list_id`=`cache_lists`.`id` AND `w`.`user_id`='&1'\n\t\t\tLEFT JOIN `cache_list_bookmarks` `b` ON `b`.`cache_list_id`=`cache_lists`.`id` AND `b`.`user_id`='&1'\n\t\t\tWHERE {$condition}\n\t\t\tORDER BY `prio`,`cache_lists`.`name`\n\t\t\tLIMIT &2,&3", $login->userid, $startat, $maxitems); $lists = sql_fetch_assoc_table($rs); foreach ($lists as &$list) { $list['description_for_display'] = use_current_protocol_in_html($list['description']); } return $lists; }
private static function getLists($condition, $prio = 0, $startat = 0, $maxitems = PHP_INT_MAX, $strip_nagchars = false) { global $login; $login->verify(); $namefield = $strip_nagchars ? 'STRIP_LEADING_NONALNUM(`cache_lists`.`name`)' : '`cache_lists`.`name`'; $rs = sql("SELECT `cache_lists`.`id`, `cache_lists`.`user_id`, `user`.`username`,\n {$namefield} `name`,\n `cache_lists`.`is_public` `visibility`, `cache_lists`.`password`,\n `cache_lists`.`description`, `cache_lists`.`desc_htmledit`,\n `cache_lists`.`user_id`='&1' `own_list`,\n `stat_cache_lists`.`entries`, `stat_cache_lists`.`watchers`,\n `w`.`user_id` IS NOT NULL `watched_by_me`,\n `b`.`user_id` IS NOT NULL `bookmarked`,\n {$prio} `prio`\n FROM `cache_lists`\n LEFT JOIN `stat_cache_lists` ON `stat_cache_lists`.`cache_list_id`=`cache_lists`.`id`\n LEFT JOIN `user` ON `user`.`user_id`=`cache_lists`.`user_id`\n LEFT JOIN `cache_list_watches` `w` ON `w`.`cache_list_id`=`cache_lists`.`id` AND `w`.`user_id`='&1'\n LEFT JOIN `cache_list_bookmarks` `b` ON `b`.`cache_list_id`=`cache_lists`.`id` AND `b`.`user_id`='&1'\n WHERE {$condition}\n ORDER BY `prio`, {$namefield}\n LIMIT &2,&3", $login->userid, $startat, $maxitems); $lists = sql_fetch_assoc_table($rs); foreach ($lists as &$list) { $list['description_for_display'] = use_current_protocol_in_html($list['description']); } return $lists; }