issue54, sort order can now be modified
authorAndreas Unterkircher <unki@netshadow.at>
Wed, 18 Jul 2007 18:03:28 +0000 (18:03 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Wed, 18 Jul 2007 18:03:28 +0000 (18:03 +0000)
git-svn-id: file:///var/lib/svn/phpfspot/trunk@223 fa6a889d-dae6-447d-9e79-4ba9a3039384

phpfspot.class.php
phpfspot.js
rpc.php
templates/search.tpl

index 57e3406272ebaa37d632147fe809d7cd664cb18d..f572759ed1262c8d98d01ef61ed009168b0f696f 100644 (file)
@@ -69,6 +69,9 @@ class PHPFSPOT {
       if(!isset($_SESSION['tag_condition']))
          $_SESSION['tag_condition'] = 'or';
 
       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'] = '';
 
       if(!isset($_SESSION['searchfor']))
          $_SESSION['searchfor'] = '';
 
@@ -136,6 +139,7 @@ class PHPFSPOT {
 
       $this->tmpl->assign('from_date', $this->get_calendar('from'));
       $this->tmpl->assign('to_date', $this->get_calendar('to'));
 
       $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");
 
       $this->tmpl->assign('content_page', 'welcome.tpl');
       $this->tmpl->show("index.tpl");
 
@@ -557,6 +561,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 = "
       /* return a search result */
       if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
          $query_str = "
@@ -570,9 +578,9 @@ class PHPFSPOT {
 
          if(isset($additional_where_cond))
             $query_str.= "AND ". $additional_where_cond ." ";
 
          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']);
          $result = $this->db->db_query($query_str);
          while($row = $this->db->db_fetch_object($result)) {
             array_push($matched_photos, $row['photo_id']);
@@ -597,10 +605,8 @@ class PHPFSPOT {
             ";
             if(isset($additional_where_cond)) 
                $query_str.= "AND ". $additional_where_cond ." ";
             ";
             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') {
 
          }
          elseif($_SESSION['tag_condition'] == 'and') {
 
@@ -638,6 +644,8 @@ class PHPFSPOT {
             }
             if(isset($additional_where_cond)) 
                $query_str.= "AND ". $additional_where_cond;
             }
             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);
          }
 
          $result = $this->db->db_query($query_str);
@@ -656,9 +664,9 @@ class PHPFSPOT {
       ";
       if(isset($additional_where_cond)) 
          $query_str.= "WHERE ". $additional_where_cond ." ";
       ";
       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']);
       $result = $this->db->db_query($query_str);
       while($row = $this->db->db_fetch_object($result)) {
          array_push($matched_photos, $row['photo_id']);
@@ -1184,11 +1192,12 @@ class PHPFSPOT {
     * getPhotoSelection() will then only return the matching
     * photos.
     */
     * 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['searchfor'] = $searchfor;
       $_SESSION['from_date'] = $from;
       $_SESSION['to_date'] = $to;
+      $_SESSION['sort_order'] = $sort_order;
 
       if($searchfor != "") {
          /* new search, reset the current selected tags */
 
       if($searchfor != "") {
          /* new search, reset the current selected tags */
@@ -1599,6 +1608,47 @@ class PHPFSPOT {
    
    } // getuid()
 
    
    } // 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;
+      }
+
+      return $_SESSION['sort_order'];
+
+   } // get_sort_order()
 }
 
 ?>
 }
 
 ?>
index 5aac78800011fd5c8008dec6e295fda099531361..dff8da9e68c4aa536061b272c9df3f3bfdf4cef6 100644 (file)
@@ -113,6 +113,9 @@ function startSearch()
       request = request + '&from='+ from +'&to='+ to;
    }
 
       request = request + '&from='+ from +'&to='+ to;
    }
 
+   var sort_order = document.getElementsByName('sort_order')[0];
+   request = request + '&sort_order='+ sort_order.options[sort_order.selectedIndex].value;
+
    HTML_AJAX.grab(encodeURI(request));
 
    refreshAvailableTags();
    HTML_AJAX.grab(encodeURI(request));
 
    refreshAvailableTags();
diff --git a/rpc.php b/rpc.php
index 5d9bb37af8519ce86242f4627812b2b2874810ec..937f4323d803d15a03aac5d1d01831cf8ea96172 100644 (file)
--- a/rpc.php
+++ b/rpc.php
@@ -92,7 +92,7 @@ class PHPFSPOT_RPC {
 
          case 'search':
 
 
          case 'search':
 
-            $fspot->startSearch($_GET['for'], $_GET['from'], $_GET['to']);
+            $fspot->startSearch($_GET['for'], $_GET['from'], $_GET['to'], $_GET['sort_order']);
             break;
 
          case 'get_export':
             break;
 
          case 'get_export':
index c87d29effb21d3ed019a926cb13762a6203d3087..1498e70b1228d0cd2f14b6f177cb43a42d47038a 100644 (file)
       <input type="image" src="resources/doit.png" alt="Tag-Search" />
      </td>
     </tr>
       <input type="image" src="resources/doit.png" alt="Tag-Search" />
      </td>
     </tr>
+    <tr>
+     <td>
+      Sort-Order:
+     </td>
+     <td>
+      {$sort_field}
+     </td>
+    </tr>
     </form>
    </table>
    <div id='calendar'></div>
     </form>
    </table>
    <div id='calendar'></div>