issue46, first slideshow implementation
[phpfspot.git] / phpfspot.class.php
index 57e3406272ebaa37d632147fe809d7cd664cb18d..25d144c2dcbe255b0cd7270b1090b13946d1c8a2 100644 (file)
@@ -69,6 +69,9 @@ class PHPFSPOT {
       if(!isset($_SESSION['tag_condition']))
          $_SESSION['tag_condition'] = 'or';
 
+      if(!isset($_SESSION['sort_order']))
+         $_SESSION['sort_order'] = 'date_asc';
+
       if(!isset($_SESSION['searchfor']))
          $_SESSION['searchfor'] = '';
 
@@ -132,10 +135,15 @@ class PHPFSPOT {
             $this->tmpl->show("export.tpl");
             return;
             break;
+         case 'slideshow':
+            $this->tmpl->show("slideshow.tpl");
+            return;
+            break;
       }
 
       $this->tmpl->assign('from_date', $this->get_calendar('from'));
       $this->tmpl->assign('to_date', $this->get_calendar('to'));
+      $this->tmpl->assign('sort_field', $this->get_sort_field());
       $this->tmpl->assign('content_page', 'welcome.tpl');
       $this->tmpl->show("index.tpl");
 
@@ -557,6 +565,10 @@ class PHPFSPOT {
          ";
       } 
 
+      if(isset($_SESSION['sort_order'])) {
+         $order_str = $this->get_sort_order();
+      }
+
       /* return a search result */
       if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
          $query_str = "
@@ -570,9 +582,9 @@ class PHPFSPOT {
 
          if(isset($additional_where_cond))
             $query_str.= "AND ". $additional_where_cond ." ";
-         $query_str.= "
-            ORDER BY p.time ASC
-         ";
+         if(isset($order_str))
+            $query_str.= $order_str;
+
          $result = $this->db->db_query($query_str);
          while($row = $this->db->db_fetch_object($result)) {
             array_push($matched_photos, $row['photo_id']);
@@ -597,10 +609,8 @@ class PHPFSPOT {
             ";
             if(isset($additional_where_cond)) 
                $query_str.= "AND ". $additional_where_cond ." ";
-
-            $query_str.= "
-               ORDER BY p.time ASC
-            ";
+            if(isset($order_str))
+               $query_str.= $order_str;
          }
          elseif($_SESSION['tag_condition'] == 'and') {
 
@@ -630,6 +640,10 @@ class PHPFSPOT {
                      ON pt1.photo_id=pt". ($i+2) .".photo_id
                ";
             }
+            $query_str.= "
+               INNER JOIN photos p
+                  ON pt1.photo_id=p.id
+            ";
             $query_str.= "WHERE pt1.tag_id=". $_SESSION['selected_tags'][0];
             for($i = 1; $i < count($_SESSION['selected_tags']); $i++) {
                $query_str.= "
@@ -638,6 +652,8 @@ class PHPFSPOT {
             }
             if(isset($additional_where_cond)) 
                $query_str.= "AND ". $additional_where_cond;
+            if(isset($order_str))
+               $query_str.= $order_str;
          }
 
          $result = $this->db->db_query($query_str);
@@ -656,9 +672,9 @@ class PHPFSPOT {
       ";
       if(isset($additional_where_cond)) 
          $query_str.= "WHERE ". $additional_where_cond ." ";
-      $query_str.= "
-         ORDER BY p.time ASC
-      ";
+      if(isset($order_str))
+         $query_str.= $order_str;
+
       $result = $this->db->db_query($query_str);
       while($row = $this->db->db_fetch_object($result)) {
          array_push($matched_photos, $row['photo_id']);
@@ -853,8 +869,10 @@ class PHPFSPOT {
       }
 
       $export_link = "index.php?mode=export";
+      $slideshow_link = "index.php?mode=slideshow";
 
       $this->tmpl->assign('extern_link', $extern_link);
+      $this->tmpl->assign('slideshow_link', $slideshow_link);
       $this->tmpl->assign('export_link', $export_link);
       $this->tmpl->assign('count', $count);
       $this->tmpl->assign('width', $this->cfg->thumb_width);
@@ -1184,11 +1202,12 @@ class PHPFSPOT {
     * getPhotoSelection() will then only return the matching
     * photos.
     */
-   public function startSearch($searchfor, $from, $to)
+   public function startSearch($searchfor, $from, $to, $sort_order)
    {
       $_SESSION['searchfor'] = $searchfor;
       $_SESSION['from_date'] = $from;
       $_SESSION['to_date'] = $to;
+      $_SESSION['sort_order'] = $sort_order;
 
       if($searchfor != "") {
          /* new search, reset the current selected tags */
@@ -1599,6 +1618,68 @@ class PHPFSPOT {
    
    } // getuid()
 
+   /**
+    * returns a select-dropdown box to select photo index sort parameters
+    */
+   private function get_sort_field()
+   {
+      $output = "<select name=\"sort_order\">";
+      foreach(array('date_asc', 'date_desc', 'name_asc', 'name_desc') as $sort_order) {
+         $output.= "<option value=\"". $sort_order ."\"";
+         if($sort_order == $_SESSION['sort_order']) {
+            $output.= " selected=\"selected\"";
+         }
+         $output.= ">". $sort_order ."</option>";
+      }
+      $output.= "</select>";
+      return $output;
+
+   } // get_sort_field()
+
+   /**
+    * returns the currently selected sort order
+    */ 
+   private function get_sort_order()
+   {
+      switch($_SESSION['sort_order']) {
+         case 'date_asc':
+            return " ORDER BY p.time ASC";
+            break;
+         case 'date_desc':
+            return " ORDER BY p.time DESC";
+            break;
+         case 'name_asc':
+            return " ORDER BY p.name ASC";
+            break;
+         case 'name_desc':
+            return " ORDER BY p.name DESC";
+            break;
+      }
+
+   } // get_sort_order()
+
+   public function getNextSlideShowImage()
+   {
+      $all_photos = $this->getPhotoSelection();
+
+      if(!isset($_SESSION['slideshow_img']) || $_SESSION['slideshow_img'] == count($all_photos)-1) 
+         $_SESSION['slideshow_img'] = 0;
+      else
+         $_SESSION['slideshow_img']++;
+
+      $server_name = $_SERVER['SERVER_NAME'];
+      if(!isset($_SERVER['HTTPS'])) $protocol = "http";
+      else $protocol = "https";
+
+      return $protocol ."://". $server_name . $this->cfg->web_path ."phpfspot_img.php?idx=". $all_photos[$_SESSION['slideshow_img']] ."&width=". $this->cfg->photo_width;
+
+   } // getNextSlideShowImage()
+
+   public function resetSlideShow()
+   {
+      if(isset($_SESSION['slideshow_img']))
+         unset($_SESSION['slideshow_img']);
+   } // resetSlideShow()
 }
 
 ?>