better display of description and time for a single photo
[photo-tags.git] / getjson.php
index d5dab8b20bb637b5a5afbd7c8487de377688093d..ff41ac46ee498655186d30ecd6643786a5bd79c6 100644 (file)
@@ -1,5 +1,25 @@
 <?php
 
+  /**
+    copyright 2012,2013 Arun Persaud <arun@nubati.net>
+
+    This file is part of photo-tags.
+
+    Photo-tags is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    Photo-tags is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Photo-tags.  If not, see <http://www.gnu.org/licenses/>.
+
+  **/
+
 $N=30;
 
 /* parse ini -file */
@@ -25,7 +45,7 @@ if (isset($_REQUEST["S"]))
   }
  else if (isset($_REQUEST["NP"]))
   {
-    /* get +- 5 pics from ordered list to show next to a large image */
+    /* get +- 3 pics from ordered list to show next to a large image */
 
     /* first create a temp table with all images and then use rowid to get +-5 images */
 
@@ -45,7 +65,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
       {
@@ -56,8 +75,8 @@ if (isset($_REQUEST["S"]))
       {
        $ID=intval($_REQUEST["ID"]);
        $result = $DB->query("SELECT * FROM NEXTPREV".
-                            " WHERE rowid > (select rowid from NEXTPREV where id=$ID) -5".
-                            "   AND rowid < (select rowid from NEXTPREV where id=$ID) +5");
+                            " WHERE rowid > (select rowid from NEXTPREV where id=$ID) -3".
+                            "   AND rowid < (select rowid from NEXTPREV where id=$ID) +3");
       }
     else
       {
@@ -65,12 +84,19 @@ 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".
+    $result = $DB->query("SELECT base_uri, filename, id, description, time FROM photos".
                         " WHERE id=$id");
   }
+ else if (isset($_REQUEST["IDT"]))
+   {  /* tags of a single image */
+    $id  = intval($_REQUEST["IDT"]);
+    $result = $DB->query("SELECT t.name as name FROM photo_tags pt ".
+                        " LEFT JOIN tags t on t.id=pt.tag_id".
+                        " WHERE pt.photo_id=$id");
+  }
  else if (isset($_REQUEST["CLOUD"]))
   {
     $result = $DB->query("SELECT t.name as name, count(*) as count FROM photo_tags pt ".
@@ -104,11 +130,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 +152,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");
       }