when view is limited to some specifc tags, also display all other tags, of which...
[phpfspot.git] / phpfspot.class.php
index d67c7e39dc4f1b1543296ce209ed7e0071a4beaa..82722529e89790adf21ad110a5736b76f93c6d90 100644 (file)
@@ -196,11 +196,34 @@ class PHPFSPOT {
       $this->avail_tags = Array();
       $count = 0;
    
-      $result = $this->db->db_query("
-         SELECT id,name
-         FROM tags
-         ORDER BY sort_priority ASC
-      ");
+      if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) {
+         $query_str="
+            SELECT
+               DISTINCT t1.id,t1.name
+            FROM  
+               photo_tags pt1
+            INNER JOIN photo_tags
+               pt2 ON pt1.photo_id=pt2.photo_id
+            INNER JOIN tags t1
+               ON t1.id=pt1.tag_id
+            INNER JOIN tags t2
+               ON t2.id=pt2.tag_id
+            WHERE
+               t2.name IN  ('
+                  ".implode("','",$this->cfg->show_tags)."
+               ')
+            ORDER BY
+               t1.sort_priority ASC";
+         $result = $this->db->db_query($query_str);
+      }
+      else
+      {
+         $result = $this->db->db_query("
+            SELECT id,name
+            FROM tags
+            ORDER BY sort_priority ASC
+         ");
+      }
       
       while($row = $this->db->db_fetch_object($result)) {
 
@@ -214,13 +237,14 @@ class PHPFSPOT {
          if(in_array($row['name'], $this->cfg->hide_tags))
             continue;
 
-         /* if the user has specified to only show certain tags which
-            are specified in phpfspot's configuration, ignore all others
-            so they will not be added to the tag list.
-         */
+         /* if you include the following if-clause and the user has specified
+            to only show certain tags which are specified in phpfspot's
+            configuration, ignore all others so they will not be added to the
+            tag list.
          if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags) &&
             !in_array($row['name'], $this->cfg->show_tags))
             continue;
+         */
 
          $this->tags[$tag_id] = $tag_name; 
          $this->avail_tags[$count] = $tag_id;
@@ -739,10 +763,10 @@ class PHPFSPOT {
                INNER JOIN photos p
                   ON pt1.photo_id=p.id
             ";
-            $query_str.= "WHERE pt1.tag_id=". $_SESSION['selected_tags'][0];
+            $query_str.= "WHERE pt2.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] ."
+                  AND pt". ($i+2) .".tag_id=". $_SESSION['selected_tags'][$i] ."
                "; 
             }
             if(isset($additional_where_cond))