make index.php page aware; make default page start at 1
[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="d3.min.js"></script>
21 <link rel="stylesheet" type="text/css" href="normalize.css" />
22 <link rel="stylesheet" type="text/css" href="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="pics"> </div>
33
34 <footer>
35   This gallery belongs to <?php echo htmlspecialchars($admin) ?>.
36   <div class="copyright"> code: copyright 2011 Arun Persaud arun@nubati.net, code available at nubati.net/git/f-spot-gallery</div>
37 </footer>
38
39
40 <script type="text/javascript" >
41
42
43 var pics = d3.select(".pics").append("ul");
44
45 var page=<?php echo $page ?>;
46 var N=<?php echo $N ?>;
47 var count=0;
48
49 function myreload(a) {
50   d3.json("<?php echo $webbase?>/getjson.php?P="+a, function(json) {
51       count=0;
52       pics.selectAll("li").remove();
53       pics.selectAll("li").data(json)
54         .enter().append("li")
55         .append("a")
56         .attr("href",function(d) {
57             s= d.base_uri+'/'+d.filename;
58             s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase; ?>/Photos-small/');
59             return s;
60           })
61         .append("img")
62         .attr("src",function(d) {
63             count++;
64             s= d.base_uri+'/'+d.filename;
65             s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase?>/Photos-tiny/');
66             return s;
67           });
68       checkbutton();
69     });
70
71   d3.select(".debug").text("P, count= "+a+" "+count);
72 }
73
74 function left() {
75   if (page>=2) page=page-1;
76   myreload(page);
77 }
78
79 function right() {
80   page=page+1;
81   myreload(page);
82 }
83
84 function checkbutton() {
85
86   if (page==1)
87     { d3.select("button.prev").attr("disabled","disabled");}
88   else
89     { d3.select("button.prev").attr("disabled", null);};
90
91   if (count<N)
92     { d3.select("button.next").attr("disabled","disabled");}
93   else
94     { d3.select("button.next").attr("disabled",null);}
95 }
96
97 myreload(page);
98
99 </script>
100
101 </body>
102 </html>