add a basic index of all pages...
[photo-tags.git] / index.php
1 <?php
2 /* parse ini -file */
3 $iniarray=parse_ini_file("config.ini");
4 $webbase=$iniarray["webbase"];
5 $dbprefix=$iniarray["dbprefix"];
6 $admin=$iniarray["admin"];
7 $title=$iniarray["title"];
8 $N=$iniarray["pics_per_page"];
9 /* end parse ini-file */
10
11 /* parse flags */
12 if(isset($_REQUEST["page"]))
13   $page = intval($_REQUEST["page"]);
14 else
15   $page = 1;
16
17 ?>
18 <html>
19 <title><?php echo htmlspecialchars($title) ?></title>
20 <script src="<?php echo $webbase?>/d3.min.js"></script>
21 <link rel="stylesheet" type="text/css" href="<?php echo $webbase?>/normalize.css" />
22 <link rel="stylesheet" type="text/css" href="<?php echo $webbase?>/style.css" />
23
24 <body>
25
26 <div class="debug">test</div>
27 <h1><?php echo htmlspecialchars($title) ?></h1>
28
29 <button class="prev" disabled="disabled" onclick="left()"> prev </button>
30 <button class="next"   onclick="right()">next </button>
31
32 <div class="permalink"></div>
33 <div class="index"></div>
34 <div class="pics"> </div>
35
36 <footer>
37   This gallery belongs to <?php echo htmlspecialchars($admin) ?>.
38   <div class="copyright"> code: copyright 2011 Arun Persaud arun@nubati.net, code available at nubati.net/git/f-spot-gallery</div>
39 </footer>
40
41
42 <script type="text/javascript" >
43
44
45 var pics = d3.select(".pics").append("ul");
46
47 var page=<?php echo $page ?>;
48 var N=<?php echo $N ?>;
49 var count=0;
50
51 function myreload(a) {
52   d3.json("<?php echo $webbase?>/getjson.php?T=1", function(json) {
53       s="page ";
54       n = json[0].total/N;
55       for(i=1;i<=n+1;i++)
56         {
57           s+=" <a href=\"<?php echo $webbase?>/page/"+i+"\">"+i+"</a>";
58         }
59       d3.select(".index").html(s);
60     });
61   d3.json("<?php echo $webbase?>/getjson.php?P="+a, function(json) {
62       count=0;
63       pics.selectAll("li").remove();
64       pics.selectAll("li").data(json)
65         .enter().append("li")
66         .append("a")
67         .attr("href",function(d) {
68             s= d.base_uri+'/'+d.filename;
69             s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase; ?>/Photos-small/');
70             return s;
71           })
72         .append("img")
73         .attr("src",function(d) {
74             count++;
75             s= d.base_uri+'/'+d.filename;
76             s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase?>/Photos-tiny/');
77             return s;
78           });
79       checkbutton();
80     });
81
82   permalink="<?php echo $webbase ?>/page/"+page;
83   d3.select(".permalink").html("Permalink: <a href=\""+permalink+"\">"+permalink+"</a>");
84   d3.select(".debug").text("P,N ="+a+" "+N);
85 }
86
87 function left() {
88   if (page>=2) page=page-1;
89   myreload(page);
90 }
91
92 function right() {
93   page=page+1;
94   myreload(page);
95 }
96
97 function checkbutton() {
98
99   if (page==1)
100     { d3.select("button.prev").attr("disabled","disabled");}
101   else
102     { d3.select("button.prev").attr("disabled", null);};
103
104   if (count<N)
105     { d3.select("button.next").attr("disabled","disabled");}
106   else
107     { d3.select("button.next").attr("disabled",null);}
108 }
109
110 myreload(page);
111
112 </script>
113
114 </body>
115 </html>