first tag search functionality
authorAndreas Unterkircher <unki@netshadow.at>
Mon, 11 Jun 2007 19:36:03 +0000 (19:36 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Mon, 11 Jun 2007 19:36:03 +0000 (19:36 +0000)
git-svn-id: file:///var/lib/svn/phpfspot/trunk@79 fa6a889d-dae6-447d-9e79-4ba9a3039384

phpfspot.class.php
phpfspot.js
rpc.php
stylesheet.css
templates/tags.tpl

index 7bccc9e8672489dd294d2c538c9ba1dc03e00230..b635b30256da6c1174dca62f24e429437262db9e 100644 (file)
@@ -32,6 +32,9 @@ class PHPFSPOT {
       if(!isset($_SESSION['tag_condition']))
          $_SESSION['tag_condition'] = 'or';
 
+      if(!isset($_SESSION['searchfor']))
+         $_SESSION['searchfor'] = '';
+
    } // __construct()
 
    public function __destruct()
@@ -41,6 +44,7 @@ class PHPFSPOT {
 
    public function show()
    {
+      $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
       $this->tmpl->assign('page_title', $this->cfg->page_title);
       $this->tmpl->assign('current_condition', $_SESSION['tag_condition']);
       $this->tmpl->show("index.tpl");
@@ -261,7 +265,11 @@ class PHPFSPOT {
 
    public function showPhotoIndex()
    {
-      $photos = $this->getAllTagPhotos();
+      if($_SESSION['searchfor'] == '')
+         $photos = $this->getAllTagPhotos();
+      else
+         $photos = $this->getSearchResult($_SESSION['searchfor']);
+
       $count = count($photos);
 
       $rows = 0;
@@ -480,6 +488,35 @@ class PHPFSPOT {
 
    } // setTagCondition()
 
+   public function startSearch($searchfor)
+   {
+      $_SESSION['searchfor'] = $searchfor;
+
+   } // showSearchResult()
+
+   public function getSearchResult($for)
+   {
+      $tagged_photos = Array();
+
+      $result = $this->db->db_query("
+         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 '%". $for ."%'
+            ORDER BY p.time ASC
+      ");
+
+      while($row = $this->db->db_fetch_object($result)) {
+         array_push($tagged_photos, $row['photo_id']);
+      }
+
+      return $tagged_photos;
+
+   } // getSearchResult()
+
 }
 
 ?>
index 4951fe1fa1f2dbf8d0b97daafed6498b4e9e45f3..b2aebd7e9d74427a4fe05280d99a6d9ec45a92ea 100644 (file)
@@ -92,8 +92,18 @@ function setCheckedValue(condition, value) {
    }
 }
 
-function startsearch()
+function startSearch(searchfor)
 {
-   searchfor = document.getElementsByName('searchfor')[0].value;
    HTML_AJAX.grab(encodeURI('rpc.php?action=search&for=' + searchfor));
+
+/   Tags('reset', 0);
+
+   refreshAvailableTags();
+   refreshSelectedTags();
+   showPhotoIndex();
+}
+
+function clearSearch()
+{
+   document.getElementsByName('searchfor')[0].value = '';
 }
diff --git a/rpc.php b/rpc.php
index ef1be6a42989668cbf5883dd23ffcf3398afca0c..0bdccc9fde733c14972b02f1d8eaab7ab64635cb 100644 (file)
--- a/rpc.php
+++ b/rpc.php
@@ -93,6 +93,11 @@ class PHPFSPOT_RPC {
             $fspot->showCredits();
             break;
 
+         case 'search':
+
+            $fspot->startSearch($_GET['for']);
+            break;
+
       }
 
    } // process_ajax_request();
index e4f5523fb2b20cd36907af18f73c2fbd94360424..b4c69c55c82650524de086f636a65a8bf2bf6a23 100644 (file)
@@ -29,7 +29,7 @@ td.tags {
    border-right:           solid 1px #000000;\r
 }\r
 \r
-td.available_tags,td.selected_tags {\r
+td.available_tags,td.selected_tags,td.searchfor {\r
    border-bottom:          solid 1px #000000;\r
    padding-top:            10px;\r
    padding-bottom:         10px;\r
index 99c8b90784bcabf03267b05e362afa293ac95dc0..4801743653f0a28e2b9d7d94f342ca21b316b248 100644 (file)
@@ -1,4 +1,18 @@
 <table>
+ <tr>
+  <td style="vertical-align: middle; text-decoration: underline;">
+   <input type="image" src="resources/loupe.png" alt="Tag-Search" />
+   Tag-Search:
+  </td>
+ </tr>
+ <tr>
+  <td class="searchfor">
+   <form onsubmit="startSearch(document.getElementsByName('searchfor')[0].value); return false;">
+    <input type="text" name="searchfor" value="{$searchfor}" size="15" />
+    <input type="image" src="resources/doit.png" alt="Tag-Search" />
+   </form>
+  </td>
+ </tr>
  <tr>
   <td style="vertical-align: middle; text-decoration: underline;">
    <img src="resources/available_tags.png" \>Available Tags: