improved search sorting options logic

This commit is contained in:
following
2013-07-19 18:42:49 +02:00
parent 81147f6f04
commit 4e2d4e2668
5 changed files with 46 additions and 29 deletions
+2 -2
View File
@@ -841,7 +841,7 @@ INSERT INTO `sys_menu` (`id`, `id_string`, `title`, `title_trans_id`, `menustrin
INSERT INTO `sys_menu` (`id`, `id_string`, `title`, `title_trans_id`, `menustring`, `menustring_trans_id`, `access`, `href`, `visible`, `parent`, `position`, `color`, `sitemap`, `only_if_parent`) VALUES ('27', 'MNU_START_CONTACT', 'Contact', '16', 'Contact', '16', '0', 'articles.php?page=contact', '0', '1', '12', '', '1', NULL);
INSERT INTO `sys_menu` (`id`, `id_string`, `title`, `title_trans_id`, `menustring`, `menustring_trans_id`, `access`, `href`, `visible`, `parent`, `position`, `color`, `sitemap`, `only_if_parent`) VALUES ('28', 'MNU_START_PRIVACY', 'Privacy statement', '14', 'Privacy statement', '14', '0', 'articles.php?page=dsb', '0', '1', '13', '', '1', NULL);
INSERT INTO `sys_menu` (`id`, `id_string`, `title`, `title_trans_id`, `menustring`, `menustring_trans_id`, `access`, `href`, `visible`, `parent`, `position`, `color`, `sitemap`, `only_if_parent`) VALUES ('29', 'MNU_START_REGISTER_ACTIVATION', 'Activation', '127', 'Activation', '127', '0', 'activation.php', '0', '3', '1', '', '1', NULL);
INSERT INTO `sys_menu` (`id`, `id_string`, `title`, `title_trans_id`, `menustring`, `menustring_trans_id`, `access`, `href`, `visible`, `parent`, `position`, `color`, `sitemap`, `only_if_parent`) VALUES ('31', 'MNU_START_NEWS_POST', 'Post some news', '180', 'Post some news', '180', '0', 'newstopic.php', '0', '4', '1', '', '0', NULL);
INSERT INTO `sys_menu` (`id`, `id_string`, `title`, `title_trans_id`, `menustring`, `menustring_trans_id`, `access`, `href`, `visible`, `parent`, `position`, `color`, `sitemap`, `only_if_parent`) VALUES ('30', 'MNU_CACHES_USERPROFILE', 'Userprofile', '128', 'Userprofile', '128', '0', 'viewprofile.php', '0', '10', '4', '', '0', NULL);INSERT INTO `sys_menu` (`id`, `id_string`, `title`, `title_trans_id`, `menustring`, `menustring_trans_id`, `access`, `href`, `visible`, `parent`, `position`, `color`, `sitemap`, `only_if_parent`) VALUES ('31', 'MNU_START_NEWS_POST', 'Post some news', '180', 'Post some news', '180', '0', 'newstopic.php', '0', '4', '1', '', '0', NULL);
INSERT INTO `sys_menu` (`id`, `id_string`, `title`, `title_trans_id`, `menustring`, `menustring_trans_id`, `access`, `href`, `visible`, `parent`, `position`, `color`, `sitemap`, `only_if_parent`) VALUES ('32', 'MNU_LOGIN', 'Login', '207', 'Login', '207', '0', 'login.php', '0', '0', '8', '#D5D9FF', '1', NULL);
INSERT INTO `sys_menu` (`id`, `id_string`, `title`, `title_trans_id`, `menustring`, `menustring_trans_id`, `access`, `href`, `visible`, `parent`, `position`, `color`, `sitemap`, `only_if_parent`) VALUES ('33', 'MNU_CACHES_USERTOPS', 'Show recommendations', '248', 'Show recommendations', '248', '0', 'usertops.php', '0', '10', '5', '', '0', NULL);
INSERT INTO `sys_menu` (`id`, `id_string`, `title`, `title_trans_id`, `menustring`, `menustring_trans_id`, `access`, `href`, `visible`, `parent`, `position`, `color`, `sitemap`, `only_if_parent`) VALUES ('34', 'MNU_ERROR', 'Error message', '133', 'Error message', '133', '0', '', '0', '0', '9', '#D5D9FF', '0', NULL);
@@ -5853,7 +5853,7 @@ INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUE
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1379', 'DE', 'weniger', '2010-09-10 23:52:53');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1380', 'DE', 'Cachesuche', '2010-09-10 23:52:44');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1381', 'DE', 'JavaScript ist bei dir deaktiviert, daher kannst du die obenstehenden Optionen (Caches ausblenden .. Sortierung) nicht nutzen - die Suche funktioniert aber trotzdem.', '2010-09-10 23:52:36');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1382', 'DE', 'Ausgabe sortieren nach:', '2010-09-10 23:52:28');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1382', 'DE', 'Ausgabe<br />sortieren nach:', '2010-09-10 23:52:28');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1383', 'DE', 'letztes Log', '2012-07-24 21:30:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1384', 'DE', 'von anderen Benutzern empfohlene Caches zuerst anzeigen', '2010-09-10 23:51:58');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1385', 'DE', 'Entfernung nur nutzbar falls eingeloggt und Heimkoordinaten vorhanden.<br />Bei Suche nach Entfernung wird die Entfernung von den eingegebenen Koordinaten verwendet.', '2010-09-10 23:51:48');
+1 -1
View File
@@ -60,7 +60,7 @@
// threshold for caches to be marked as "new"
// changed from 7 to 14 -- following 2013/6/17
$NEWCACHES_DAYS = 14;
define('NEWCACHES_DAYS', 14);
// constants for user options (must match values in DB!)
define('USR_OPT_GMZOOM', 1);
+38 -21
View File
@@ -9,14 +9,14 @@
external tools like the Mozilla Firefox plugin.
Search options will be loaded from
- a saved or caches query in queries table, if either 'queryid' parameter
or 'lastqueryid' cookie is present and the query exists; otherwise from
- a saved query in queries table, if either 'queryid' parameter or
'lastqueryid' cookie is present and the query exists; otherwise from
- supplied HTTP parameters or
- hard-coded default values
showresult=1 produces an SQL query from search options, executes it and
calls the output formatting module as specified by the 'output' parameter.
If 'showresult' != 1, the query search form is presented to the user.
If 'showresult' != 1, the search options form is presented to the user.
Note that 'showresult' is also stored in saved queries, so it can be
automatically included when the 'queryid' parameter is given.
@@ -32,7 +32,7 @@
searchbynofilter
searchbycacheid
searchbywp
searchall
searchall (needs login)
output options:
html display browsable search results list
@@ -49,7 +49,7 @@
To do:
- port attributes code to res_attribgroup.tpl (see outputSearchForm)
- port output data list generation from prepareLocSelectionForm and
- move output data list generation from prepareLocSelectionForm and
outputLocidSelectionForm to search_selectlocid.tpl.
- wtf is "expert mode"?
@@ -68,11 +68,17 @@
$tpl->name = 'search';
$tpl->menuitem = MNU_CACHES_SEARCH;
// km => target-unit
// distance constants
$DEFAULT_DISTANCE_UNIT = 'km';
$DEFAULT_SEARCH_DISTANCE = 75;
$multiplier['km'] = 1;
$multiplier['sm'] = 0.62137;
$multiplier['nm'] = 0.53996;
$homecoords = ($login->logged_in() &&
sql_value_slave("SELECT `latitude`+`longitude` FROM user WHERE `user_id`='&1'", 0, $login->userid) <> 0);
// 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):
$called_by_search = isset($_REQUEST['calledbysearch']) && $_REQUEST['calledbysearch'];
@@ -284,7 +290,7 @@
}
else
{
$options['unit'] = 'km';
$options['unit'] = $DEFAULT_DISTANCE_UNIT;
}
if (isset($_REQUEST['searchbyname']))
@@ -398,7 +404,7 @@
}
}
$options['sort'] = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'bydistance';
$options['sort'] = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : ($homecoords ? 'bydistance' : 'byname');
if (isset($_REQUEST['orderRatingFirst']) && $_REQUEST['orderRatingFirst']==1)
$options['orderRatingFirst'] = true;
@@ -413,6 +419,21 @@
$options['terrainmax'] = isset($_REQUEST['terrainmax']) ? $_REQUEST['terrainmax']+0 : 0;
$options['recommendationmin'] = isset($_REQUEST['recommendationmin']) ? $_REQUEST['recommendationmin']+0 : 0;
if (in_array($options['searchtype'], array('byort','byplz','bydistance')))
{
// For distance-based searches, sort by distance instead of name.
if ($options['sort'] == 'byname')
$options['sort'] = 'bydistance';
}
else
{
// For non-distance-based searches, sort by name instead of distance if
// no reference coords exist.
if (!isset($options['lat']) || !isset($options['lon']) || $options['lat']+$options['lon'] == 0)
if (!$homecoords)
$options['sort'] = 'byname';
}
$options['queryid'] = 0;
} // $queryid == 0
@@ -560,8 +581,8 @@
$lat = $r['lat'] + 0;
$lon = $r['lon'] + 0;
$distance_unit = 'km';
$distance = 75;
$distance_unit = $DEFAULT_DISTANCE_UNIT;
$distance = $DEFAULT_SEARCH_DISTANCE;
// ab hier selber code wie bei bydistance ... TODO: in funktion auslagern
@@ -710,8 +731,8 @@
$lon_rad = $lon * 3.14159 / 180;
$lat_rad = $lat * 3.14159 / 180;
$distance_unit = 'km';
$distance = 75;
$distance_unit = $DEFAULT_DISTANCE_UNIT;
$distance = $DEFAULT_SEARCH_DISTANCE;
// ab hier selber code wie bei bydistance ... TODO: in funktion auslagern
@@ -1147,7 +1168,7 @@
// 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';
$distance_unit = $DEFAULT_DISTANCE_UNIT;
if (isset($lat_rad) && isset($lon_rad))
{
@@ -1215,7 +1236,7 @@
$sortby = 'bydistance';
}
if (isset($lat_rad) && isset($lon_rad) && ($sortby == 'bydistance'))
if (isset($lat_rad) && isset($lon_rad) && $sortby == 'bydistance')
{
$sql .= '`distance` ASC';
}
@@ -1383,17 +1404,13 @@ 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());
$homecoords = ($login->logged_in() && 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->assign('bydistance_enabled', $homecoords);
if (isset($options['sort']))
$bBynameChecked = ($options['sort'] == 'byname'); // Ocprop
else
@@ -1531,9 +1548,9 @@ function outputSearchForm($options)
$tpl->assign('latN_sel', 'selected="selected"');
}
}
$tpl->assign('distance', isset($options['distance']) ? $options['distance'] : 75);
$tpl->assign('distance', isset($options['distance']) ? $options['distance'] : $DEFAULT_SEARCH_DISTANCE);
if (!isset($options['unit'])) $options['unit'] = 'km';
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');
@@ -3,7 +3,7 @@
<!--m-->
<tr>
<td width="18" class="{$listcolor}">&nbsp;{$position}&nbsp;</td>
<td width="45" class="{$listcolor}">{$cache.distance|sprintf:"%1.1f"|escape}&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>
+4 -4
View File
@@ -423,12 +423,12 @@ function switchAttributeCat2()
<div class="searchdiv2">
<table class="table">
<tr>
<td class="formlabel" style="vertical-align:top">{t}Sorting of result:{/t}</td>
<td class="formlabel">{t}Sorting of result:{/t}</td>
<td colspan="4">
<input type="radio" name="sort" value="byname" index="0" id="l_sortbyname" class="radio" onclick="sync_options(this)" {if $byname_checked}checked="checked"{/if} > <label for="l_sortbyname">{t}Cachename{/t}</label> &nbsp;
<input type="radio" name="sort" value="bydistance" index="1" id="l_sortbydistance" class="radio" onclick="sync_options(this)" {if $bydistance_checked}checked="checked"{/if} {if !$bydistance_enabled}disabled="disabled"{/if} {if !$logged_in}disabled="disabled"{/if}> <label for="l_sortbydistance" {if !$logged_in}class="disabled"{/if}>{t}Distance from <a href="myprofile.php">home coordinates</a>{/t}</label> &nbsp;
<nobr><input type="radio" name="sort" value="bycreated" index="2" id="l_sortbycreated" class="radio" onclick="sync_options(this)" {if $bycreated_checked}checked="checked"{/if}> <label for="l_sortbycreated">{t}Listed since{/t}</label> &nbsp;
<input type="radio" name="sort" value="bylastlog" index="3" id="l_sortbylastlog" class="radio" onclick="sync_options(this)" {if $bylastlog_checked}checked="checked"{/if}> <label for="l_sortbylastlog" >{t}Last log{/t}</label> &nbsp;
<input type="radio" name="sort" value="bydistance" index="1" id="l_sortbydistance" class="radio" onclick="sync_options(this)" {if $bydistance_checked}checked="checked"{/if}> <label for="l_sortbydistance">{t}Distance{/t}</label> &nbsp;
<input type="radio" name="sort" value="bycreated" index="2" id="l_sortbycreated" class="radio" onclick="sync_options(this)" {if $bycreated_checked}checked="checked"{/if}> <label for="l_sortbycreated">{t}Listed since{/t}</label> &nbsp;
<nobr><input type="radio" name="sort" value="bylastlog" index="3" id="l_sortbylastlog" class="radio" onclick="sync_options(this)" {if $bylastlog_checked}checked="checked"{/if}> <label for="l_sortbylastlog" >{t}Last log{/t}</label> &nbsp;
<input type="radio" name="sort" value="bymylastlog" index="4" id="l_sortbymylastlog" class="radio" onclick="sync_options(this)" {if $bymylastlog_checked}checked="checked"{/if} {if !$logged_in}disabled="disabled"{/if}> <label for="l_sortbymylastlog" {if !$logged_in}class="disabled"{/if}>{t}My last log{/t}</label></nobr>
<br />
<input id="orderRatingFirst" type="checkbox" name="orderRatingFirst" class="checkbox" value="1" onclick="sync_options(this)" {if $orderRatingFirst_checked}checked="checked"{/if} />