issue103, ensure showPhotoIndex() returns to the right page
[phpfspot.git] / phpfspot.class.php
index 85d276e104d29a09a792cae3b5f59d004f83017c..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('current', $current);
+      $this->tmpl->assign('current', $this->getCurrentPage($current, $count));
 
       if($previous_img) {
          $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
@@ -520,8 +520,6 @@ class PHPFSPOT {
 
       $this->tmpl->show("single_photo.tpl");
 
-      print "<script language=\"JavaScript\">self.location.hash = '#image';</script>\n";
-
    } // showPhoto()
 
    /**
@@ -957,12 +955,12 @@ class PHPFSPOT {
       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) {
-
          $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) {
@@ -2466,6 +2464,27 @@ class PHPFSPOT {
 
    } // 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
 
 ?>