X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=blobdiff_plain;f=phpfspot.class.php;h=2c3170c869e7395d5bd64bff9e7965f6d1f8fdfa;hp=0113fe6c7848bd4818b285a55279a109934108fe;hb=51ab51f6a487cd793e523aebb61ed43c2b7314bf;hpb=87148067c543f8d0af056fdef437f18d72e50c9d diff --git a/phpfspot.class.php b/phpfspot.class.php index 0113fe6..2c3170c 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"); @@ -457,9 +461,6 @@ class PHPFSPOT { */ public function addTag($tag) { - // if the result of a date search are displayed, reset them - $this->resetDateSearch(); - if(!isset($_SESSION['selected_tags'])) $_SESSION['selected_tags'] = Array(); @@ -550,18 +551,37 @@ class PHPFSPOT { { $matched_photos = Array(); + if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) { + $from_date = strtotime($_SESSION['from_date']); + $to_date = strtotime($_SESSION['to_date']); + $additional_where_cond = " + p.time>='". $from_date ."' + AND + p.time<='". $to_date ."' + "; + } + + if(isset($_SESSION['sort_order'])) { + $order_str = $this->get_sort_order(); + } + /* return a search result */ if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') { - $result = $this->db->db_query(" + $query_str = " SELECT DISTINCT photo_id FROM photo_tags pt INNER JOIN photos p ON p.id=pt.photo_id INNER JOIN tags t ON pt.tag_id=t.id - WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%' - ORDER BY p.time ASC - "); + WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'"; + + 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); while($row = $this->db->db_fetch_object($result)) { array_push($matched_photos, $row['photo_id']); } @@ -576,14 +596,17 @@ class PHPFSPOT { $selected = substr($selected, 0, strlen($selected)-1); if($_SESSION['tag_condition'] == 'or') { - $result = $this->db->db_query(" + $query_str = " SELECT DISTINCT photo_id FROM photo_tags pt INNER JOIN photos p ON p.id=pt.photo_id WHERE pt.tag_id IN (". $selected .") - ORDER BY p.time ASC - "); + "; + if(isset($additional_where_cond)) + $query_str.= "AND ". $additional_where_cond ." "; + if(isset($order_str)) + $query_str.= $order_str; } elseif($_SESSION['tag_condition'] == 'and') { @@ -613,49 +636,42 @@ class PHPFSPOT { ON pt1.photo_id=pt". ($i+2) .".photo_id "; } + $query_str.= " + INNER JOIN photos p + ON pt1.photo_id=p.id + "; $query_str.= "WHERE pt1.tag_id=". $_SESSION['selected_tags'][0]; for($i = 1; $i < count($_SESSION['selected_tags']); $i++) { $query_str.= " AND pt". ($i+1) .".tag_id=". $_SESSION['selected_tags'][$i] ." "; } - $result = $this->db->db_query($query_str); + 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); while($row = $this->db->db_fetch_object($result)) { array_push($matched_photos, $row['photo_id']); } return $matched_photos; } - if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) { - $from_date = strtotime($_SESSION['from_date']); - $to_date = strtotime($_SESSION['to_date']); - $result = $this->db->db_query(" - SELECT DISTINCT photo_id - FROM photo_tags pt - INNER JOIN photos p - ON p.id=pt.photo_id - WHERE - time>='". $from_date ."' - AND - time<='". $to_date ."' - ORDER BY p.time ASC - "); - while($row = $this->db->db_fetch_object($result)) { - array_push($matched_photos, $row['photo_id']); - } - return $matched_photos; - } - /* return all available photos */ - $result = $this->db->db_query(" + $query_str = " SELECT DISTINCT photo_id FROM photo_tags pt INNER JOIN photos p ON p.id=pt.photo_id - ORDER BY p.time ASC - "); + "; + if(isset($additional_where_cond)) + $query_str.= "WHERE ". $additional_where_cond ." "; + 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']); } @@ -1172,39 +1188,30 @@ class PHPFSPOT { } // setTagCondition() /** - * invoke tag search + * invoke tag & date search * * this function will return all matching tags and store - * them in the session variable selected_tags. + * them in the session variable selected_tags. furthermore + * it also handles the date search. * getPhotoSelection() will then only return the matching * photos. */ - public function startTagSearch($searchfor) + public function startSearch($searchfor, $from, $to, $sort_order) { $_SESSION['searchfor'] = $searchfor; - $_SESSION['selected_tags'] = Array(); - - foreach($this->avail_tags as $tag) { - if(preg_match('/'. $searchfor .'/i', $this->tags[$tag])) - array_push($_SESSION['selected_tags'], $tag); - } - - $this->resetDateSearch(); - - } // startTagSearch() - - /** - * invoke date search - * - * this function in fact does nothing then only setting - * the from- and to-date in the users session variables. - * the result is generated by getPhotoSelection(). - */ - public function startDateSearch($from, $to) - { $_SESSION['from_date'] = $from; $_SESSION['to_date'] = $to; - } + $_SESSION['sort_order'] = $sort_order; + + if($searchfor != "") { + /* new search, reset the current selected tags */ + $_SESSION['selected_tags'] = Array(); + foreach($this->avail_tags as $tag) { + if(preg_match('/'. $searchfor .'/i', $this->tags[$tag])) + array_push($_SESSION['selected_tags'], $tag); + } + } + } // startSearch() /** * rotate image @@ -1406,9 +1413,15 @@ class PHPFSPOT { $month = $_SESSION[$mode .'_date'] ? date("m", strtotime($_SESSION[$mode .'_date'])) : date("m"); $day = $_SESSION[$mode .'_date'] ? date("d", strtotime($_SESSION[$mode .'_date'])) : date("d"); - $output = "\n"; - $output.= "\n"; - $output.= "\n"; + $output = ""; + foreach(array('date_asc', 'date_desc', 'name_asc', 'name_desc') as $sort_order) { + $output.= "