summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Unterkircher <unki@netshadow.at>2007-07-18 18:03:28 +0000
committerAndreas Unterkircher <unki@netshadow.at>2007-07-18 18:03:28 +0000
commit2f3810822ac7a62e17aebccb286068a8b69e5a19 (patch)
tree820d32144f88ae626d3181a4103d8836910e7a0b
parentf130f65e9268e969c6556c77a3212e267a6da468 (diff)
issue54, sort order can now be modified
git-svn-id: file:///var/lib/svn/phpfspot/trunk@223 fa6a889d-dae6-447d-9e79-4ba9a3039384
-rw-r--r--phpfspot.class.php72
-rw-r--r--phpfspot.js3
-rw-r--r--rpc.php2
-rw-r--r--templates/search.tpl8
4 files changed, 73 insertions, 12 deletions
diff --git a/phpfspot.class.php b/phpfspot.class.php
index 57e3406..f572759 100644
--- a/phpfspot.class.php
+++ b/phpfspot.class.php
@@ -69,6 +69,9 @@ class PHPFSPOT {
if(!isset($_SESSION['tag_condition']))
$_SESSION['tag_condition'] = 'or';
+ if(!isset($_SESSION['sort_order']))
+ $_SESSION['sort_order'] = 'date_asc';
+
if(!isset($_SESSION['searchfor']))
$_SESSION['searchfor'] = '';
@@ -136,6 +139,7 @@ class PHPFSPOT {
$this->tmpl->assign('from_date', $this->get_calendar('from'));
$this->tmpl->assign('to_date', $this->get_calendar('to'));
+ $this->tmpl->assign('sort_field', $this->get_sort_field());
$this->tmpl->assign('content_page', 'welcome.tpl');
$this->tmpl->show("index.tpl");
@@ -557,6 +561,10 @@ class PHPFSPOT {
";
}
+ if(isset($_SESSION['sort_order'])) {
+ $order_str = $this->get_sort_order();
+ }
+
/* return a search result */
if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
$query_str = "
@@ -570,9 +578,9 @@ class PHPFSPOT {
if(isset($additional_where_cond))
$query_str.= "AND ". $additional_where_cond ." ";
- $query_str.= "
- ORDER BY p.time ASC
- ";
+ if(isset($order_str))
+ $query_str.= $order_str;
+
$result = $this->db->db_query($query_str);
while($row = $this->db->db_fetch_object($result)) {
array_push($matched_photos, $row['photo_id']);
@@ -597,10 +605,8 @@ class PHPFSPOT {
";
if(isset($additional_where_cond))
$query_str.= "AND ". $additional_where_cond ." ";
-
- $query_str.= "
- ORDER BY p.time ASC
- ";
+ if(isset($order_str))
+ $query_str.= $order_str;
}
elseif($_SESSION['tag_condition'] == 'and') {
@@ -638,6 +644,8 @@ class PHPFSPOT {
}
if(isset($additional_where_cond))
$query_str.= "AND ". $additional_where_cond;
+ if(isset($order_str))
+ $query_str.= $order_str;
}
$result = $this->db->db_query($query_str);
@@ -656,9 +664,9 @@ class PHPFSPOT {
";
if(isset($additional_where_cond))
$query_str.= "WHERE ". $additional_where_cond ." ";
- $query_str.= "
- ORDER BY p.time ASC
- ";
+ if(isset($order_str))
+ $query_str.= $order_str;
+
$result = $this->db->db_query($query_str);
while($row = $this->db->db_fetch_object($result)) {
array_push($matched_photos, $row['photo_id']);
@@ -1184,11 +1192,12 @@ class PHPFSPOT {
* getPhotoSelection() will then only return the matching
* photos.
*/
- public function startSearch($searchfor, $from, $to)
+ public function startSearch($searchfor, $from, $to, $sort_order)
{
$_SESSION['searchfor'] = $searchfor;
$_SESSION['from_date'] = $from;
$_SESSION['to_date'] = $to;
+ $_SESSION['sort_order'] = $sort_order;
if($searchfor != "") {
/* new search, reset the current selected tags */
@@ -1599,6 +1608,47 @@ class PHPFSPOT {
} // getuid()
+ /**
+ * returns a select-dropdown box to select photo index sort parameters
+ */
+ private function get_sort_field()
+ {
+ $output = "<select name=\"sort_order\">";
+ foreach(array('date_asc', 'date_desc', 'name_asc', 'name_desc') as $sort_order) {
+ $output.= "<option value=\"". $sort_order ."\"";
+ if($sort_order == $_SESSION['sort_order']) {
+ $output.= " selected=\"selected\"";
+ }
+ $output.= ">". $sort_order ."</option>";
+ }
+ $output.= "</select>";
+ return $output;
+
+ } // get_sort_field()
+
+ /**
+ * returns the currently selected sort order
+ */
+ private function get_sort_order()
+ {
+ switch($_SESSION['sort_order']) {
+ case 'date_asc':
+ return "ORDER BY p.time ASC";
+ break;
+ case 'date_desc':
+ return "ORDER BY p.time DESC";
+ break;
+ case 'name_asc':
+ return "ORDER BY p.name ASC";
+ break;
+ case 'name_desc':
+ return "ORDER BY p.name DESC";
+ break;
+ }
+
+ return $_SESSION['sort_order'];
+
+ } // get_sort_order()
}
?>
diff --git a/phpfspot.js b/phpfspot.js
index 5aac788..dff8da9 100644
--- a/phpfspot.js
+++ b/phpfspot.js
@@ -113,6 +113,9 @@ function startSearch()
request = request + '&from='+ from +'&to='+ to;
}
+ var sort_order = document.getElementsByName('sort_order')[0];
+ request = request + '&sort_order='+ sort_order.options[sort_order.selectedIndex].value;
+
HTML_AJAX.grab(encodeURI(request));
refreshAvailableTags();
diff --git a/rpc.php b/rpc.php
index 5d9bb37..937f432 100644
--- a/rpc.php
+++ b/rpc.php
@@ -92,7 +92,7 @@ class PHPFSPOT_RPC {
case 'search':
- $fspot->startSearch($_GET['for'], $_GET['from'], $_GET['to']);
+ $fspot->startSearch($_GET['for'], $_GET['from'], $_GET['to'], $_GET['sort_order']);
break;
case 'get_export':
diff --git a/templates/search.tpl b/templates/search.tpl
index c87d29e..1498e70 100644
--- a/templates/search.tpl
+++ b/templates/search.tpl
@@ -34,6 +34,14 @@
<input type="image" src="resources/doit.png" alt="Tag-Search" />
</td>
</tr>
+ <tr>
+ <td>
+ Sort-Order:
+ </td>
+ <td>
+ {$sort_field}
+ </td>
+ </tr>
</form>
</table>
<div id='calendar'></div>