display photo index as matrix
[phpfspot.git] / phpfspot.class.php
index 379ad98f5c8b28354cc5a95b48549a443e0d5eff..dbefee8b37f52ec13bd2bb61cf7529df3fa3d8cf 100644 (file)
@@ -39,7 +39,6 @@ class PHPFSPOT {
    public function show()
    {
 
-      $this->prepare_single_photo($this->current_photo);
       $this->tmpl->assign('tags', $this->tags);
       $this->tmpl->show("index.tpl");
 
@@ -117,21 +116,23 @@ class PHPFSPOT {
 
    } // translate_path
 
-   public function prepare_single_photo($photo)
+   public function showPhoto($photo)
    {
       if(isset($photo)) {
-         $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $this->avail_photos[$photo] ."&width=". $this->cfg->photo_width);
+         $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
       }
 
       if($photo > 0) {
          $this->tmpl->assign('previous_url', "javascript:showImage(". ($photo-1) .");");
       }
 
-      if($photo < count($this->avail_photos)) {
+      if($photo < count($this->photos)) {
          $this->tmpl->assign('next_url', "javascript:showImage(". ($photo+1) .");");
       }
 
-   } // prepare_single_photo()
+      $this->tmpl->show("single_photo.tpl");
+
+   } // showPhoto()
 
    public function getAvailableTags()
    {
@@ -186,6 +187,74 @@ class PHPFSPOT {
 
    } // resetTags()
 
+   public function getAllTagPhotos()
+   {  
+      $tagged_photos = Array();
+
+      if(isset($_SESSION['selected_tags'])) {
+         $selected = "";
+         foreach($_SESSION['selected_tags'] as $tag)
+            $selected.= $tag .",";
+         $selected = substr($selected, 0, strlen($selected)-1);
+         $result = $this->db->db_query("
+            SELECT DISTINCT photo_id
+            FROM photo_tags
+            WHERE tag_id IN (". $selected .")
+         ");
+      }
+      else {
+         $result = $this->db->db_query("
+            SELECT DISTINCT photo_id
+            FROM photo_tags
+         ");
+      }
+
+      while($row = $this->db->db_fetch_object($result)) {
+         array_push($tagged_photos, $row['photo_id']);
+      }
+
+      return $tagged_photos;
+
+   } // getAllTagPhotos()
+
+   public function showPhotoIndex()
+   {
+      $photos = $this->getAllTagPhotos();
+      $count = count($photos);
+
+      $rows = 0;
+      $cols = 0;
+      $images[$rows] = Array();
+
+      for($i = 0; $i < $count; $i++) {
+
+         $images[$rows][$cols] = $photos[$i];
+
+         if($cols == $this->cfg->thumbs_per_row-1) {
+            $cols = 0;
+            $rows++;
+            $images[$rows] = Array();
+         }
+         else {
+            $cols++;
+         }
+      } 
+
+      // +1 for for smarty's selection iteration
+      $rows++;
+
+         //$images.= "<img src=\"phpfspot_img.php?idx=". $photo ."&amp;width=". $this->cfg->thumb_width ."\" /><br />\n";
+
+      $this->tmpl->assign('count', $count);
+      $this->tmpl->assign('width', $this->cfg->thumb_width);
+      $this->tmpl->assign('images', $images);
+      $this->tmpl->assign('rows', $rows);
+      $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
+      $this->tmpl->show("photo_index.tpl");
+
+
+   } // showPhotoIndex()
+
 }
 
 ?>