X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=photo-tags.git;a=blobdiff_plain;f=getjson.php;h=d5dab8b20bb637b5a5afbd7c8487de377688093d;hp=83360e6118387d957fdf4a6b139e5c079ce20ab8;hb=f040c97fefa22ffb6e5478fcbdcada36d193ce98;hpb=79761af3ff298c01b9892a3f7e6cd94a325b9005 diff --git a/getjson.php b/getjson.php index 83360e6..d5dab8b 100644 --- a/getjson.php +++ b/getjson.php @@ -23,12 +23,60 @@ if (isset($_REQUEST["S"])) $result = $DB->query("SELECT name FROM tags"); } + else if (isset($_REQUEST["NP"])) + { + /* get +- 5 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 */ + + if (isset($_REQUEST["T"])) + { + /* single tag or part of tag */ + $tags = $_REQUEST["T"]; + $tags = explode(",",$tags); + $nrtags = count($tags); + + foreach ($tags as $key => $value) + $tags[$key]=sqlite_escape_string(trim($value)); + $tags = "'".implode("','",$tags)."'"; + + $DB->query("CREATE TEMP TABLE NEXTPREV AS SELECT base_uri, filename, 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"); + + } + else + { + $DB->query("CREATE TEMP TABLE NEXTPREV AS SELECT base_uri, filename, p.id as id FROM photos p"); + }; + + if (isset($_REQUEST["ID"])) + { + $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"); + } + else + { + $result = $DB->query("SELECT 1 where 1=2"); + } + + } else if (isset($_REQUEST["ID"])) { $id = intval($_REQUEST["ID"]); $result = $DB->query("SELECT base_uri, filename, id FROM photos". " WHERE id=$id"); } + else if (isset($_REQUEST["CLOUD"])) + { + $result = $DB->query("SELECT t.name as name, count(*) as count FROM photo_tags pt ". + " LEFT JOIN tags t on t.id=pt.tag_id". + " GROUP BY t.id"); + } else { if (isset($_REQUEST["P"]))