diff options
Diffstat (limited to 'phpfspot.class.php')
-rw-r--r-- | phpfspot.class.php | 72 |
1 files changed, 61 insertions, 11 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() } ?> |