fixed page_index to advance when we click on a thumbnail from another page
authorArun Persaud <arun@nubati.net>
Wed, 8 Feb 2012 05:15:38 +0000 (21:15 -0800)
committerArun Persaud <apersaud@lbl.gov>
Wed, 8 Feb 2012 05:15:38 +0000 (21:15 -0800)
getjson.php
index.php

index d5dab8b20bb637b5a5afbd7c8487de377688093d..3e4cf4d4e9470245a2997c030c200ca27e8e9eb8 100644 (file)
@@ -45,7 +45,6 @@ if (isset($_REQUEST["S"]))
                   " AND (t.name COLLATE NOCASE IN ($tags))".
                   " AND p.id = pt.photo_id ".
                   " GROUP BY p.id HAVING COUNT( p.id )=$nrtags");
-
       }
     else
       {
@@ -65,7 +64,7 @@ if (isset($_REQUEST["S"]))
       }
 
   }
- else if (isset($_REQUEST["ID"]))
+ else if (isset($_REQUEST["ID"]) && !isset($_REQUEST["C"]))
   {
     $id  = intval($_REQUEST["ID"]);
     $result = $DB->query("SELECT base_uri, filename, id FROM photos".
@@ -104,11 +103,19 @@ if (isset($_REQUEST["S"]))
 
        if (isset($_REQUEST["C"]))
          {
-           $result = $DB->query("SELECT count(*) as total from (SELECT p.id FROM photo_tags pt, photos p, tags t".
-                               " WHERE pt.tag_id = t.id".
-                               " AND (t.name COLLATE NOCASE IN ($tags))".
-                               " AND p.id = pt.photo_id ".
-                               " GROUP BY p.id HAVING COUNT( p.id )=$nrtags)");
+           $DB->query("CREATE TEMP TABLE TEMPPICS AS SELECT p.id as id FROM photo_tags pt, photos p, tags t".
+                      " WHERE pt.tag_id = t.id".
+                      " AND (t.name COLLATE NOCASE IN ($tags))".
+                      " AND p.id = pt.photo_id ".
+                      " GROUP BY p.id HAVING COUNT( p.id )=$nrtags");
+
+           if (isset($_REQUEST["ID"]))
+             {
+               $ID = $_REQUEST["ID"];
+               $result = $DB->query("SELECT count(*) as total, (SELECT rowid from TEMPPICS WHERE id = $ID) as row from TEMPPICS");
+             }
+           else
+             $result = $DB->query("SELECT count(*) as total, -1 as row from TEMPPICS");
          }
        else
          {
@@ -118,13 +125,22 @@ if (isset($_REQUEST["S"]))
                                 " AND p.id = pt.photo_id ".
                                 " GROUP BY p.id HAVING COUNT( p.id )=$nrtags".
                                 "    LIMIT $OFFSET, $N");
-
          }
       }
     else
       {
        if (isset($_REQUEST["C"]))
-         $result = $DB->query("SELECT count(*) as total FROM photos");
+         {
+           $DB->query("CREATE TEMP TABLE TEMPPICS AS SELECT id from photos");
+
+           if (isset($_REQUEST["ID"]))
+             {
+               $ID = $_REQUEST["ID"];
+               $result = $DB->query("SELECT count(*) as total, (SELECT rowid FROM TEMPPICS WHERE id=$ID) as row FROM TEMPPICS");
+             }
+           else
+             $result = $DB->query("SELECT count(*) as total, -1 as row FROM TEMPPICS");
+         }
        else
          $result = $DB->query("SELECT * FROM photos LIMIT $OFFSET, $N");
       }
index 93bc9e32cbd82426996dc094f6dc4db92c8644f4..7237d283507d865fec76318b500ac7fa54125d29 100644 (file)
--- a/index.php
+++ b/index.php
@@ -41,8 +41,8 @@ else
 
 <nav>
 <span class="index"></span>
-<button class="prev" type="button" disabled="disabled" onclick="left()"> prev </button>
-<button class="next" type="button" onclick="right()">next </button>
+<button class="prev" type="button" disabled="disabled" onclick="prev_page()"> prev </button>
+<button class="next" type="button" onclick="next_page()">next </button>
 <button class="all"  type="submit" onclick="document.location.href='<?php echo $webbase?>'">all</button>
 </nav>
 
@@ -55,7 +55,7 @@ else
   </datalist>
 </form>
   Current tags:<span id="currenttags"></span>
-  <button class="next" type="button" onclick="cloud()">tag cloud</button>
+  <button class="next" type="button" onclick="tagcloud()">tag cloud</button>
 </div>
 
 <div class="nextprev"> <ul></ul></div>
@@ -239,17 +239,17 @@ function update_permalink(page) {
   d3.select(".permalink").html("Permalink: <a href=\""+permalink+"\">"+permalink+"</a>");
 }
 
-function left() {
+function prev_page() {
   if (page>=2) page=page-1;
   load_content(page);
 }
 
-function right() {
+function next_page() {
   page=page+1;
   load_content(page);
 }
 
-function cloud() {
+function tagcloud() {
 
   url = webbase+"/getjson.php?CLOUD=1";
 
@@ -271,7 +271,6 @@ function cloud() {
 
 function checkbutton()
 {
-
   if (page==1)
     { d3.select("button.prev").attr("disabled","disabled");}
   else
@@ -286,7 +285,6 @@ function checkbutton()
 function update_page_index(mypage)
 {
   /* load number of pictures */
-  
   myID = "";
   if(ID > 0)
     myID = "&ID="+ID;
@@ -299,6 +297,9 @@ function update_page_index(mypage)
   d3.json(url, function(json) {
     /* update index, show only page +-5 pages max */
     n = Math.floor(json[0].total/N);
+    nr = Math.floor( (json[0].row-1)/N); /* rowid starts at 1 not 0 */
+
+    if(nr > 0) mypage = nr+1;
     s = "";
 
     if(n>0)