Skip to content
Permalink
Browse files

added possibility on search.php to sort search result by distance, na…

…me, created_date and mylastlog or lastlog updates #865
  • Loading branch information...
Slini11 committed Jan 20, 2016
1 parent 54c288e commit cbad95cfbef1f493035cad3c8d485693dac42bee
@@ -2806,6 +2806,7 @@ INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2520', 'Show in
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2521', 'This table contains some false positives. References from the \"libse\" code (personal cache notes, additional waypoints) are not detected, as well as textes which are passed by variable to translation functions and multiline texts. \"Help\", \"Forum\", \"Teamblog\" and \"Informations\" are referenced in local configuration files. So be very careful before deleting anything.', '2013-11-03 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2522', 'OConly', '2013-11-03 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2523', 'Official OC logos (up-to-date):', '2015-11-24 23:30:00');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2524', 'Stored querie', '2015-01-20 20:37:00');

-- Table sys_trans_ref
SET NAMES 'utf8';
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2521', 'DE', 'Diese Tabelle enthält einige Fehleinträge. Referenzen aus dem \"libse\"-Code (persönliche Cachenotizen, zusätzliche Wegpunkte) werden nicht erkannt, ebenso wie Texte, die als Variable an Übersetzungsfunktionen übergeben werden, und mehrzeilige Texte. \"Help\", \"Forum\", \"Teamblog\" and \"Informations\" werden in lokalen Konfigurationsdateien verwendet. Daher ist beim Löschen von Einträgen Vorsicht geboten.', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2522', 'DE', 'OConly', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2523', 'DE', 'Offizielle OC logos (up-to-date):', '2015-11-24 23:30:00');

INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2524', 'DE', 'Gespeicherte Suche', '2015-01-20 20:37:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1', 'EN', 'Reorder IDs', '2010-09-02 00:15:30');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2', 'EN', 'The database could not be reconnected.', '2010-08-28 11:48:07');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('3', 'EN', 'Testing – please do not login', '2010-08-28 11:48:07');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2392', 'EN', 'Zürich', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2522', 'EN', 'OConly', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2523', 'EN', 'Official OC logos (up-to-date):', '2015-11-24 23:30:00');

INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2524', 'EN', 'Stored querie', '2015-01-20 20:37:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2', 'ES', 'La base de datos no se pudo conectar.', '2010-12-09 00:17:55');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('3', 'ES', 'En pruebas - por favor, no entre.', '2010-12-09 00:17:55');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('4', 'ES', 'Usuario', '2010-12-09 00:17:55');
@@ -35,7 +35,7 @@ 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;
global $startat, $caches_per_page, $sql, $sortarray;
$tpl->name = 'search.result.caches';
$tpl->menuitem = MNU_CACHES_SEARCH_RESULT;
@@ -49,11 +49,10 @@ function search_output()
$resultcount = sql_value_slave('SELECT FOUND_ROWS()', 0);
sql_foundrows_done();
$tpl->assign('results_count', $resultcount);
$tpl->assign('startat',$startat);
$tpl->assign('startat', $startat);
$caches = array();
while ($rCache = sql_fetch_array($rs_caches))
{
while ($rCache = sql_fetch_array($rs_caches)) {
// select best-fitting short desc for active language
$rCache['short_desc'] = sql_value_slave("
SELECT `short_desc`
@@ -78,7 +77,7 @@ function search_output()
// 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 = "";
@@ -90,25 +89,23 @@ function search_output()
WHERE `cache_logs`.`cache_id`='" . sql_escape($rCache['cache_id']) . "'
AND `log_types`.`id`=`cache_logs`.`type`" . $ownlogs . "
ORDER BY `cache_logs`.`date` DESC, `cache_logs`.`date_created` DESC
LIMIT 6";
LIMIT 5";
$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)
{
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
} 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);
$rCache['redname'] = ($rCache['status'] == 5 || $rCache['status'] == 7);
$caches[] = $rCache;
}
mysql_free_result($rs_caches);
@@ -120,8 +117,12 @@ function search_output()
// downloads
$tpl->assign('queryid', $options['queryid']);
if (isset($options['userid'])) {
$tpl->assign('userid', $options['userid']);
$tpl->assign('query_name', $options['query_name']);
}
$tpl->assign('startatp1', min($resultcount,$startat + 1));
$tpl->assign('startatp1', min($resultcount, $startat + 1));
if (($resultcount - $startat) < 500)
$tpl->assign('endat', $startat + $resultcount - $startat);
else
@@ -139,6 +140,34 @@ function search_output()
$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']);
}else{
$options['sortorder']="";
}
if (($options['sort']=='bydistance' && $options['sortorder']=='DESC') || (!isset($_REQUEST['queryid']) && $options['sort']!='bydistance') || (isset($_REQUEST['queryid']) && $options['sort']!='bydistance')) {
$tpl->assign('bydistance', true);
}
if (($options['sort']=='byname' && $options['sortorder']=='DESC') || (!isset($_REQUEST['queryid']) && $options['sort']!='byname') || (isset($_REQUEST['queryid']) && $options['sort']!='byname')){
$tpl->assign('byname', true);
}
if (($options['sort']=='bycreated' && $options['sortorder']=='ASC') || (!isset($_REQUEST['queryid']) && $options['sort']!='bycreated') || (isset($_REQUEST['queryid']) && $options['sort']!='bycreated')){
$tpl->assign('bycreated', true);
}
if (($options['sort']=='bymylastlog' && $options['sortorder']=='ASC') || (!isset($_REQUEST['queryid']) && $options['sort']!='bymylastlog') || (isset($_REQUEST['queryid']) && $options['sort']!='bymylastlog')){
$tpl->assign('bymylastlog', true);
}
if (($options['sort']=='bylastlog' && $options['sortorder']=='ASC') || (!isset($_REQUEST['queryid']) && $options['sort']!='bylastlog') || (isset($_REQUEST['queryid']) && $options['sort']!='bylastlog')){
$tpl->assign('bylastlog', true);
}
if (isset($options['bycreated'])||$options['sort']=='bycreated'){
$tpl->assign('sbycreated', true);
}
// cachelist data
if (isset($options['cachelist']))
{
@@ -150,7 +179,8 @@ function search_output()
// disable "edit options" for internally generated searches
if ($options['searchtype'] == 'bylist')
$tpl->assign('disable_edit_options',true);
$tpl->assign('disable_edit_options',true);
$tpl->display();
}
@@ -143,7 +143,7 @@
// load search options from stored query
$query_rs = sql("
SELECT `user_id`, `options`
SELECT `user_id`, `options`, `name`
FROM `queries`
WHERE id='&1' AND (`user_id`=0 OR `user_id`='&2')",
$queryid, $login->userid);
@@ -161,8 +161,10 @@
{
$record = sql_fetch_array($query_rs);
$options = unserialize($record['options']);
if ($record['user_id'] != 0)
if ($record['user_id'] != 0) {
$options['userid'] = $record['user_id'];
$options['query_name'] = $record['name'];
}
sql_free_result($query_rs);
$options['queryid'] = $queryid;
@@ -183,6 +185,24 @@
$options['showresult'] = 0;
}
// overwrite variable options for sort direction & sort type
if (isset($_REQUEST['sortby'])){
$options['sort'] = $_REQUEST['sortby'];
$saveopt = serialize($options);
sql("UPDATE queries SET `options`='&1' WHERE `id`='&2'", $saveopt, $options['queryid']);
}
if (isset($_REQUEST['sortorder'])){
$options['sortorder'] = $_REQUEST['sortorder'];
$saveopt = serialize($options);
sql("UPDATE queries SET `options`='&1' WHERE `id`='&2'", $saveopt, $options['queryid']);
}
//check if user searched "bycreated" first --> display "bycreated"
if(isset($_REQUEST['bycreated'])){
$options['bycreated'] = $_REQUEST['bycreated'];
}
// get findername from finderid
$options['finderid'] = isset($options['finderid']) ? $options['finderid'] + 0 : 0; // Ocprop
if (isset($options['finder']) && $options['finderid'] > 0)
@@ -299,7 +319,7 @@
{
$options['searchtype'] = 'byname';
$options['cachename'] = isset($_REQUEST['cachename']) ? stripslashes($_REQUEST['cachename']) : '';
if (!isset($_REQUEST['utf8']))
if (!isset($_REQUEST['utf8']))
$options['cachename'] = iconv("ISO-8859-1", "UTF-8", $options['cachename']);
}
elseif (isset($_REQUEST['searchbyowner'])) // Ocprop
@@ -1305,21 +1325,45 @@
if ($sortby == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sql .= '`lastLog` DESC, `caches`.`date_created` DESC, ';
$sql .= '`lastLog`';
if(isset($options['sortorder'])&&$options['sortorder']=='ASC'){
$sql .= ' ASC, ';
}
else{
$sql .= ' DESC, ';
}
$sortby = 'bydistance';
}
if (isset($lat_rad) && isset($lon_rad) && $sortby == 'bydistance')
{
$sql .= '`distance` ASC';
$sql .= '`distance`';
if(isset($options['sortorder'])&&$options['sortorder']=='DESC'){
$sql .= ' DESC';
}
else{
$sql .= ' ASC';
}
}
else if ($sortby == 'bycreated')
{
$sql .= '`caches`.`date_created` DESC';
$sql .= '`caches`.`date_created`';
if(isset($options['sortorder'])&&$options['sortorder']=='ASC'){
$sql .= ' ASC';
}
else{
$sql .= ' DESC';
}
}
else // by name
{
$sql .= '`caches`.`name` ASC';
$sql .= '`caches`.`name`';
if(isset($options['sortorder'])&&$options['sortorder']=='DESC'){
$sql .= ' DESC';
}
else{
$sql .= ' ASC';
}
}
// range of output
@@ -1435,7 +1479,9 @@ function append_output($str)
// $sql
// $sqlLimit
// $options['sort']
// $options['sortorder']
// $options['queryid']
// $options['query_name']
// $enable_mapdisplay
//=================================================================
@@ -8,25 +8,33 @@
***************************************************************************}
<!--m-->
<tr>
<td width="18" class="{$listcolor}">&nbsp;{$position}&nbsp;&nbsp;</td>
<td width="45" class="{$listcolor}">{if $cache.distance !== null}{$cache.distance|sprintf:"%1.1f"|escape}&nbsp;{/if}</td>
<td width="32" class="{$listcolor}" rowspan="2"><img src="resource2/{$opt.template.style}/images/cacheicon/{$cache.icon}" title="{$cache.cacheTypeName}" /></td>
<td width="46" class="{$listcolor}" rowspan="2"><nobr>{include file="res_difficon.tpl" difficulty=$cache.difficulty}{include file="res_terricon.tpl" terrain=$cache.terrain}</nobr></td>
<td width="448" class="{$listcolor}">{if $cache.isnew}<b class="newsymbol">&nbsp;{t}NEW{/t}&nbsp;</b>&nbsp; {/if}<span style="{include file="res_cachestatus_span.tpl" status=$cache.status}"><a href="viewcache.php?cacheid={$cache.cache_id|escape}"><span style="{if $cache.redname}color: #e00000{/if}">{$cache.name|escape}</span></a></span> &nbsp;{t}by{/t} <a href="viewprofile.php?userid={$cache.user_id|escape}">{$cache.username|escape}</a><!-- Ocprop: <a href="viewcache.php?cacheid={$cache.cache_id|escape}">{$cache.name|escape}</a> {t}by{/t} <a href="viewprofile.php?userid={$cache.user_id|escape}">{$cache.username|escape}</a> --></td>
<td width="74" class="{$listcolor}" rowspan="2" style="padding: 0px">{if $cache.oconly}<img src="resource2/ocstyle/images/misc/is_oconly.png" alt="OConly" title="OConly" style="margin:0px; padding:0px" width="64" height="35" />{/if}</td>
<td width="110" valign="top" class="{$listcolor}"><nobr>
<td class="{$listcolor}">&nbsp;</td>
<td class="{$listcolor}">{if $cache.distance !== null}{$cache.distance|sprintf:"%1.1f"|escape}&nbsp;{/if}</td>
<td class="{$listcolor}" rowspan="2"><img src="resource2/{$opt.template.style}/images/cacheicon/{$cache.icon}" title="{$cache.cacheTypeName}" /></td>
<td class="{$listcolor}" rowspan="2"><nobr>{include file="res_difficon.tpl" difficulty=$cache.difficulty}</nobr></td>
<td class="{$listcolor}" rowspan="2"><nobr>{include file="res_terricon.tpl" terrain=$cache.terrain}</nobr></td>
<td class="{$listcolor}" colspan="2">{if $cache.isnew}<b class="newsymbol">&nbsp;{t}NEW{/t}&nbsp;</b>&nbsp; {/if}<span style="{include file="res_cachestatus_span.tpl" status=$cache.status}"><a href="viewcache.php?cacheid={$cache.cache_id|escape}"><span style="{if $cache.redname}color: #e00000{/if}">{$cache.name|escape}</span></a></span> &nbsp;{t}by{/t} <a href="viewprofile.php?userid={$cache.user_id|escape}">{$cache.username|escape}</a><!-- Ocprop: <a href="viewcache.php?cacheid={$cache.cache_id|escape}">{$cache.name|escape}</a> {t}by{/t} <a href="viewprofile.php?userid={$cache.user_id|escape}">{$cache.username|escape}</a> --></td>
{if $sbycreated}
<td class="{$listcolor}">{$cache.date_created|date_format:$opt.format.date}</td>
{else}
<td class="{$listcolor}" rowspan="2" style="padding: 0px">
&nbsp;{if $cache.oconly}<img src="resource2/ocstyle/images/misc/is_oconly.png" alt="OConly" title="OConly" style="margin:0px; padding:0px" width="64" height="35" />{/if}
</td>
{/if}
<td class="{$listcolor}" valign="top"><nobr>
{if $cache.firstlog}
<a href="viewcache.php?cacheid={$cache.cache_id}&log=A#log{$cache.firstlog.id}">{include file="res_logtype.tpl" type=$cache.firstlog.type}</a><a href="viewcache.php?cacheid={$cache.cache_id}&log=A#log{$cache.firstlog.id}">{$cache.firstlog.date|date_format:$opt.format.date}</a>&nbsp;
<nobr><a href="viewcache.php?cacheid={$cache.cache_id}&log=A#log{$cache.firstlog.id}">{include file="res_logtype.tpl" type=$cache.firstlog.type}</a>&nbsp;<a href="viewcache.php?cacheid={$cache.cache_id}&log=A#log{$cache.firstlog.id}">{$cache.firstlog.date|date_format:$opt.format.date}</a>&nbsp;&nbsp;&nbsp;&nbsp;</nobr>
{else}
<img src="resource2/{$opt.template.style}/images/log/16x16-none.png" width="16" height="16" /> --.--.----&nbsp;
<img src="resource2/{$opt.template.style}/images/log/16x16-none.png" width="16" height="16" />&nbsp;--.--.----&nbsp;
{/if}
</nobr></td>
</nobr>
</td>
</tr>
<!--n-->
<tr>
<td width="25" class="{$listcolor}">&nbsp;</td>
<td width="32" class="{$listcolor}" valign="top">{if $cache.direction_deg !== false}<img src="resource2/ocstyle/images/direction/16x16-{$cache.direction_deg}deg.png" title="{t}Cardinal direction:{/t} {$cache.direction_txt}" />&nbsp;{/if}</td>
<td width="448" class="{$listcolor}" valign="top">
<td class="{$listcolor}">&nbsp;</td>
<td class="{$listcolor}" valign="top">{if $cache.direction_deg !== false}<img src="resource2/ocstyle/images/direction/16x16-{$cache.direction_deg}deg.png" title="{t}Cardinal direction:{/t} {$cache.direction_txt}" />&nbsp;{/if}</td>
<td class="{$listcolor}" colspan="2" valign="top">
<p>
{strip}
{if $cache.topratings<4}
@@ -42,6 +50,10 @@
{foreach from=$cache.desclangs item=desclang}
<a href="viewcache.php?cacheid={$cache.cache_id}&desclang={$desclang|escape}" style="text-decoration:none"><b><span style="color:blue">{$desclang|escape}</span></b></a>
{/foreach}
{$cache.short_desc} &nbsp;</p></td>
<td width="110" class="{$listcolor}" valign="top">{foreach from=$cache.logs item=log}<a href="viewcache.php?cacheid={$cache.cache_id}&log=A#log{$log.id}">{include file="res_logtype.tpl" type=$log.type}</a>&nbsp;{/foreach}</td>
{$cache.short_desc} &nbsp;</p>
</td>
{if $sbycreated}
<td class="{$listcolor}" valign="top">{if $cache.oconly}<img src="resource2/ocstyle/images/misc/15x15-oc.png"/>{/if}&nbsp;</td>
{/if}
<td class="{$listcolor}" valign="top"><nobr>{foreach from=$cache.logs item=log}<a href="viewcache.php?cacheid={$cache.cache_id}&log=A#log{$log.id}">{include file="res_logtype.tpl" type=$log.type}</a>&nbsp;{/foreach}&nbsp;&nbsp;&nbsp;</nobr></td>
</tr>
Oops, something went wrong.

0 comments on commit cbad95c

Please sign in to comment.
You can’t perform that action at this time.