Web page to reset the counter
[ampy.git] / html / counterset.php
1 <?php
2 require_once("ampy.inc.php");
3
4 if (!empty($_POST['counter'])) {
5         ampy_set_counter($_POST['counter']);
6         echo("New value recorded!");
7 }
8
9 $counter_mtime = ampy_get_old_counter_info();
10 $counter = $counter_mtime[0];
11 $mtime = $counter_mtime[1];
12 $kwh_since = ampy_get_kwh_since($mtime);
13 ?>
14
15 <script>
16 timestamp=<?php echo($mtime); ?>*1000;
17 counter=<?php echo($counter); ?>;
18 kwh_since=<?php echo($kwh_since); ?>;
19
20 function userchanged(value) {
21         value=parseFloat(value);
22         valuechange = value-counter;
23         document.getElementById('valuechange').innerHTML = valuechange;
24         errorvalue = (valuechange-kwh_since)/kwh_since;
25         errorvalue = (errorvalue*100).toFixed(2);
26         if (errorvalue > 0)
27                 errorvalue = '+' + errorvalue;
28         document.getElementById('errorvalue').innerHTML = errorvalue + '%';
29 }
30
31 </script>
32
33 <h1>Counter set</h1>
34 <fieldset>
35         <legend>Last known value</legend>
36
37         Time: <script>document.write(new Date(timestamp));</script><br>
38         Value: <?php echo($counter); ?> kWh<br>
39 </fieldset>
40
41 <form method=post>
42 <fieldset>
43         <legend>New value</legend>
44
45         <input name=counter oninput="userchanged(this.value);" value="<?php echo($counter+$kwh_since); ?>">
46         <input type=submit value=Save>
47 </fieldset>
48 </form>
49
50 <fieldset>
51         <legend>Error correction</legend>
52
53         Expected value: <script>document.write(counter+kwh_since);</script> kWh<br>
54         Expected value since last update: <script>document.write(kwh_since);</script> kWh<br>
55         Value since laste update: <span id=valuechange>N/A</span><br>
56         Error: <span id=errorvalue>N/A</span>
57 </fieldset>
58
59 <script>
60 </script>