initial support for tag search
[photo-tags.git] / index.php
index 5f045433d197bff0dca0c7a0c4ca2803b9605271..78f77e18f6bdd5608d40a97dc23dffce4ca14284 100644 (file)
--- a/index.php
+++ b/index.php
@@ -14,6 +14,11 @@ if(isset($_REQUEST["page"]))
 else
   $page = 1;
 
 else
   $page = 1;
 
+if(isset($_REQUEST["tag"]))
+  $tags = $_REQUEST["tag"];
+else
+  $tags = "";
+
 ?>
 <html>
 <title><?php echo htmlspecialchars($title) ?></title>
 ?>
 <html>
 <title><?php echo htmlspecialchars($title) ?></title>
@@ -31,6 +36,15 @@ else
 
 <div class="permalink"></div>
 
 
 <div class="permalink"></div>
 
+<div class="tagsearch">
+<form method="get" action="">
+ Tags: <input list="MyTags" id="MyTagsInput" type="text" value="" />
+  <datalist id="MyTags">
+  </datalist>
+</form>
+</div>
+
+<div class="index"></div>
 <div class="pics"> </div>
 
 <footer>
 <div class="pics"> </div>
 
 <footer>
@@ -41,18 +55,51 @@ else
 
 <script type="text/javascript" >
 
 
 <script type="text/javascript" >
 
-
 var pics = d3.select(".pics").append("ul");
 
 var page=<?php echo $page ?>;
 var N=<?php echo $N ?>;
 var pics = d3.select(".pics").append("ul");
 
 var page=<?php echo $page ?>;
 var N=<?php echo $N ?>;
+var T="<?php echo $tags ?>";
 var count=0;
 
 var count=0;
 
+/* populate data list with tags*/
+d3.json("<?php echo $webbase?>/getjson.php?S", function(json) {
+    d3.select("#MyTags").selectAll("option").data(json)
+      .enter().append("option").attr("value",function(d) {return d.name});
+  });
+
+/* update form to point to new link */
+d3.select("input").on("keyup", function(d) {
+    d3.select('form').attr("action","<?php echo $webbase?>/tag/"+document.getElementById('MyTagsInput').value);
+});
+
 function myreload(a) {
 function myreload(a) {
-  d3.json("<?php echo $webbase?>/getjson.php?P="+a, function(json) {
+  d3.select(".debug").text("T,P,N ="+T+" "+a+" "+N);
+
+  if(T!="")
+    url = "<?php echo $webbase?>/getjson.php?T="+T+"&P="+a;
+  else
+    url = "<?php echo $webbase?>/getjson.php?P="+a;
+
+  d3.json(url, function(json) {
+
+      /* update index */
+      s="page ";
+      n = json[0][0].total/N;
+      for(i=1;i<=n+1;i++)
+       {
+         s+=" <a href=\"<?php echo $webbase?>";
+         if(T!="")
+           s+="/tag/"+T;
+         s+="/page/"+i+"\">"+i+"</a>";
+       }
+      d3.select(".index").html(s);
+
+      /* update pics */
       count=0;
       pics.selectAll("li").remove();
       count=0;
       pics.selectAll("li").remove();
-      pics.selectAll("li").data(json)
+      picdata=json[1];
+      pics.selectAll("li").data(picdata)
        .enter().append("li")
        .append("a")
        .attr("href",function(d) {
        .enter().append("li")
        .append("a")
        .attr("href",function(d) {
@@ -72,7 +119,6 @@ function myreload(a) {
 
   permalink="<?php echo $webbase ?>/page/"+page;
   d3.select(".permalink").html("Permalink: <a href=\""+permalink+"\">"+permalink+"</a>");
 
   permalink="<?php echo $webbase ?>/page/"+page;
   d3.select(".permalink").html("Permalink: <a href=\""+permalink+"\">"+permalink+"</a>");
-  d3.select(".debug").text("P, count= "+a+" "+count);
 }
 
 function left() {
 }
 
 function left() {