6 $iniarray=parse_ini_file("config.ini");
7 $DBFILE=$iniarray["fspotdb"];
8 $usePDO=$iniarray["usePDO"];
9 $N=$iniarray["pics_per_page"];
10 /* end parse ini-file */
13 $DB = new PDO("sqlite:$DBFILE");
15 $DB = new SQlite3($DBFILE);
18 /* do database query */
19 if (isset($_REQUEST["S"]))
21 /* single tag or part of tag */
22 $tag = sqlite_escape_string($_REQUEST["S"]);
24 $result = $DB->query("SELECT name FROM tags");
25 $count = $DB->query("SELECT 1");
29 if (isset($_REQUEST["P"]))
30 $OFFSET = "".(intval($_REQUEST["P"])*$N-$N);
34 if (isset($_REQUEST["T"]))
36 /* single tag or part of tag */
37 $tags = $_REQUEST["T"];
38 $tags = explode(",",$tags);
39 foreach ($tags as $key => $value)
40 $tags[$key]=sqlite_escape_string(trim($value));
41 $tags = "'".implode("','",$tags)."'";
43 /* individual tags are seperated by ',' */
44 $result = $DB->query("SELECT base_uri, filename FROM photos ".
45 " left join photo_tags on photos.id=photo_tags.photo_id ".
46 " left join tags on tags.id=photo_tags.tag_id ".
47 " where tags.name COLLATE NOCASE in ($tags) LIMIT $OFFSET, $N");
49 $count = $DB->query("SELECT count(*) as total FROM photos ".
50 " left join photo_tags on photos.id=photo_tags.photo_id ".
51 " left join tags on tags.id=photo_tags.tag_id ".
52 " where tags.name COLLATE NOCASE in ($tags)");
57 $result = $DB->query("SELECT * FROM photos LIMIT $OFFSET, $N");
58 $count = $DB->query("SELECT count(*) as total FROM photos");
62 /* encode result as an array */
66 /* convert results into array */
67 while($res = $result->fetchArray(SQLITE3_ASSOC))
72 foreach($result as $res)
77 /* encode count as an array */
81 /* convert results into array */
82 while($res = $count->fetchArray(SQLITE3_ASSOC))
87 foreach($count as $res)
92 $return=array($count,$result);
94 echo json_encode($return);
96 /* close the database */