issue50, further code changes to be able to combine tag- and date-search
authorAndreas Unterkircher <unki@netshadow.at>
Tue, 17 Jul 2007 20:24:56 +0000 (20:24 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Tue, 17 Jul 2007 20:24:56 +0000 (20:24 +0000)
git-svn-id: file:///var/lib/svn/phpfspot/trunk@219 fa6a889d-dae6-447d-9e79-4ba9a3039384

phpfspot.class.php
phpfspot.js
rpc.php
stylesheet.css
templates/photo_index.tpl
templates/search.tpl
templates/single_photo.tpl

index 0113fe6c7848bd4818b285a55279a109934108fe..f71a0db1d3418cd74a5cae20699b9a9bd5762d2f 100644 (file)
@@ -457,9 +457,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 +547,33 @@ 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 ."'
+         ";
+      } 
+
       /* 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 ." ";
+         $query_str.= "
+            ORDER BY p.time ASC
+         ";
+         $result = $this->db->db_query($query_str);
          while($row = $this->db->db_fetch_object($result)) {
             array_push($matched_photos, $row['photo_id']);
          }
@@ -576,14 +588,19 @@ 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 .")
+            ";
+            if(isset($additional_where_cond)) 
+               $query_str.= "AND ". $additional_where_cond ." ";
+
+            $query_str.= "
                ORDER BY p.time ASC
-            ");
+            ";
          }
          elseif($_SESSION['tag_condition'] == 'and') {
 
@@ -619,43 +636,30 @@ class PHPFSPOT {
                   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;
          }
 
+         $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
+      ";
+      if(isset($additional_where_cond)) 
+         $query_str.= "WHERE ". $additional_where_cond ." ";
+      $query_str.= "
          ORDER BY p.time ASC
-      ");
+      ";
+      $result = $this->db->db_query($query_str);
       while($row = $this->db->db_fetch_object($result)) {
          array_push($matched_photos, $row['photo_id']);
       }
@@ -1172,39 +1176,29 @@ 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)
    {
       $_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;
-   }
+
+      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 +1400,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 = "<input type=\"text\" size=\"3\" id=\"". $mode ."year\" value=\"". $year ."\" />\n";
-      $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."month\" value=\"". $month ."\" />\n";
-      $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."day\" value=\"". $day ."\" />\n";
+      $output = "<input type=\"text\" size=\"3\" id=\"". $mode ."year\" value=\"". $year ."\"";
+      if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\"";
+      $output.= " />\n";
+      $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."month\" value=\"". $month ."\"";
+      if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\"";
+      $output.= " />\n";
+      $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."day\" value=\"". $day ."\"";
+      if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\"";
+      $output.= " />\n";
       return $output;
 
    } // get_calendar()
index 58e48de6e026d9e8adf257cbdd44d15947036f8b..5aac78800011fd5c8008dec6e295fda099531361 100644 (file)
@@ -90,16 +90,10 @@ function setCheckedValue(condition, value) {
    }
 }
 
-function startTagSearch(searchfor)
+function startSearch()
 {
-   HTML_AJAX.grab(encodeURI('rpc.php?action=tag_search&for=' + searchfor));
-   refreshAvailableTags();
-   refreshSelectedTags();
-   showPhotoIndex();
-}
+   var searchfor = document.getElementsByName('searchfor')[0].value
 
-function startDateSearch()
-{
    from_year = document.getElementById('fromyear').value;
    from_month = document.getElementById('frommonth').value;
    from_day = document.getElementById('fromday').value;
@@ -109,10 +103,39 @@ function startDateSearch()
    to_day = document.getElementById('today').value;
    to = to_year +"-"+ to_month +"-"+ to_day;
 
-   HTML_AJAX.grab(encodeURI('rpc.php?action=date_search&from='+ from +'&to='+ to));
+   var request = 'rpc.php?action=search';
 
-   refreshPhotoIndex();
+   if(searchfor != "") {
+      request = request + '&for=' + searchfor;
+   }
    
+   if(document.getElementsByName('consider_date')[0].checked == true) {
+      request = request + '&from='+ from +'&to='+ to;
+   }
+
+   HTML_AJAX.grab(encodeURI(request));
+
+   refreshAvailableTags();
+   refreshSelectedTags();
+   showPhotoIndex();
+   
+}
+
+function datesearch()
+{
+   var mode = true;
+
+   if(document.getElementsByName('consider_date')[0].checked == true) {
+      mode = false;
+   }
+      
+   document.getElementById('fromyear').disabled = mode;
+   document.getElementById('frommonth').disabled = mode;
+   document.getElementById('fromday').disabled = mode;
+   document.getElementById('toyear').disabled = mode;
+   document.getElementById('tomonth').disabled = mode;
+   document.getElementById('today').disabled = mode;
 }
 
 function setViewMode(mode)
diff --git a/rpc.php b/rpc.php
index 2e3045923c6c0052fdfb476165355e2732b2ee31..5d9bb37af8519ce86242f4627812b2b2874810ec 100644 (file)
--- a/rpc.php
+++ b/rpc.php
@@ -90,17 +90,9 @@ class PHPFSPOT_RPC {
             $fspot->showCredits();
             break;
 
-         case 'tag_search':
+         case 'search':
 
-            $fspot->resetDateSearch();
-            $fspot->startTagSearch($_GET['for']);
-            break;
-
-         case 'date_search':
-   
-            $fspot->resetTagSearch();
-            $fspot->resetTags();
-            $fspot->startDateSearch($_GET['from'], $_GET['to']);
+            $fspot->startSearch($_GET['for'], $_GET['from'], $_GET['to']);
             break;
 
          case 'get_export':
index fe2b2efbe112fdd45cd45a1a70d7479592c98968..610e7aadabaae4e4d571398721ee989bb51700bc 100644 (file)
@@ -65,7 +65,7 @@ td.index_header {
    white-space:            nowrap;\r
 }\r
 \r
-td.photo_name {\r
+td.content_title {\r
    background-color:       #eeeeee;\r
    padding:                10px;\r
    vertical-align:         middle;\r
index 2b4c82744354c750886731ab8f1dab59616681fd..f9c651da8e97cbf608d48aa51a7179c000469c42 100644 (file)
@@ -4,33 +4,30 @@
   <td colspan="3">
    <table style="width: 100%;">
     <tr>
-     <td class="index_header">
+     <td class="content_title">
       <b>Photo Index</b>
       {if $searchfor }
        {if $count == 1}
-        {$count} image is the result for your search about "{$searchfor}"
+        {$count} image is the result for your search about "{$searchfor}".
        {else}
-        {$count} images are the result for your search about "{$searchfor}"
-       {/if}
-      {elseif $from_date }
-       {if $count == 1}
-        {$count} image is the result for your search between {$from_date} to {$to_date}
-       {else}
-        {$count} images are the result for your search between {$from_date} to {$to_date}
+        {$count} images are the result for your search about "{$searchfor}".
        {/if}
       {elseif $tag_result}
        {if $count == 1}
-        {$count} image has been found for the selected tags
+        {$count} image has been found for the selected tags.
        {else}
-        {$count} images have been found for the selected tags
+        {$count} images have been found for the selected tags.
        {/if}
       {else}
        {if $count == 1}
-        {$count} image has been found
+        {$count} image has been found.
        {else}
-        {$count} images have been found
+        {$count} images have been found.
        {/if}
       {/if}
+      {if $from_date && $to_date }
+       Results are limited to a date between {$from_date} to {$to_date}.
+      {/if}
      </td>
      <td class="index_header" style="text-align: right">
       {if $extern_link }
index f0f8c0d457812740a0e7895fe1b1ba46b5fbdd42..c87d29effb21d3ed019a926cb13762a6203d3087 100644 (file)
@@ -7,7 +7,7 @@
  <tr>
   <td class="searchfor">
    <table>
-    <form action="" onsubmit="startTagSearch(document.getElementsByName('searchfor')[0].value); return false;">
+    <form action="" onsubmit="startSearch(); return false;">
     <tr>
      <td>Tag:</td>
      <td>
       <input type="image" src="resources/doit.png" alt="Tag-Search" />
      </td>
     </tr>
-    </form>
-    <form action="" onsubmit="startDateSearch(); return false;">
     <tr>
      <td>Date:</td>
-     <td>{$from_date} <a href="javascript:showCalendar('from');"><img src="resources/date.png" id="frompic"/></a></td>
+     <td><input type="checkbox" name="consider_date" value="Y" onclick="datesearch();">consider date-search
+    </tr>
+    <tr>
      <td>&nbsp;</td>
+     <td>{$from_date} <a href="javascript:showCalendar('from');"><img src="resources/date.png" id="frompic"/></a></td>
     </tr>
     <tr>
      <td>&nbsp;</td>
index 527584368ef43842cc6f646981c9ce328391c587..8dfd4336005e52900aa31dc4d7d47d8981f5c999 100644 (file)
@@ -1,7 +1,7 @@
 <!-- Single photo -->
 <table>
  <tr>
-  <td class="photo_name" style="text-align: left;">
+  <td class="content_title" style="text-align: left;">
    <b>Photo {$image_name}</b><br />
    &nbsp;{$description}<br />
   </td>