issue103, ensure showPhotoIndex() returns to the right page
authorAndreas Unterkircher <unki@netshadow.at>
Fri, 18 Jan 2008 19:26:23 +0000 (20:26 +0100)
committerAndreas Unterkircher <unki@netshadow.at>
Fri, 18 Jan 2008 19:26:23 +0000 (20:26 +0100)
Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
phpfspot.class.php

index cf0a60c2b0a109b12d34c2b4b4202daeba3916a9..17ec45098abd8e4085a9f219f718055bed242a58 100644 (file)
@@ -503,7 +503,7 @@ class PHPFSPOT {
       $this->tmpl->assign('image_filename', $this->parse_uri($details['uri'], 'filename'));
 
       $this->tmpl->assign('tags', $this->get_photo_tags($photo));
       $this->tmpl->assign('image_filename', $this->parse_uri($details['uri'], 'filename'));
 
       $this->tmpl->assign('tags', $this->get_photo_tags($photo));
-      $this->tmpl->assign('current', $current);
+      $this->tmpl->assign('current', $this->getCurrentPage($current, $count));
 
       if($previous_img) {
          $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
 
       if($previous_img) {
          $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
@@ -955,12 +955,12 @@ class PHPFSPOT {
       if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "")
          $anchor = $_SESSION['begin_with'];
 
       if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "")
          $anchor = $_SESSION['begin_with'];
 
+      /* if all thumbnails should be shown on one page */
       if(!isset($this->cfg->thumbs_per_page) || $this->cfg->thumbs_per_page == 0) {
       if(!isset($this->cfg->thumbs_per_page) || $this->cfg->thumbs_per_page == 0) {
-
          $begin_with = 0;
          $end_with = $count;
          $begin_with = 0;
          $end_with = $count;
-
       }
       }
+      /* thumbnails should be splitted up in several pages */
       elseif($this->cfg->thumbs_per_page > 0) {
 
          if(!isset($_SESSION['begin_with']) || $_SESSION['begin_with'] == 0) {
       elseif($this->cfg->thumbs_per_page > 0) {
 
          if(!isset($_SESSION['begin_with']) || $_SESSION['begin_with'] == 0) {
@@ -2464,6 +2464,27 @@ class PHPFSPOT {
 
    } // cleanup_phpfspot_db()
 
 
    } // cleanup_phpfspot_db()
 
+   /**
+    * return first image of the page, the $current photo
+    * lies in.
+    *
+    * this function is used to find out the first photo of the
+    * current page, in which the $current photo lies. this is
+    * used to display the correct photo, when calling showPhotoIndex()
+    * from showImage()
+    */
+   private function getCurrentPage($current, $max)
+   {
+      if(isset($this->cfg->thumbs_per_page) && !empty($this->cfg->thumbs_per_page)) {
+         for($page_start = 0; $page_start <= $max; $page_start+=$this->cfg->thumbs_per_page) {
+            if($current >= $page_start && $current < ($page_start+$this->cfg->thumbs_per_page))
+               return $page_start;
+         }
+      }
+      return 0;
+
+   } // getCurrentPage()
+
 } // class PHPFSPOT
 
 ?>
 } // class PHPFSPOT
 
 ?>