-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewbatt.php
80 lines (78 loc) · 2.81 KB
/
viewbatt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
require "header.php";
require_once "helpers.php";
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>View Battery</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<table>
<?php
$battid = $_GET["id"];
require_once "connect.php";
$conn = connect();
$s = $conn->prepare("select num, make_id, type_id, battype.type as batterytype, whratio, acquired, nominal from battery, batmake, battype where num=? and battype.id=batmake.type_id and battery.make_id=batmake.id") or die ($conn->error);
$s->bind_param("i", intval($battid)) or die($conn->error);
$s->execute();
$rs = $s->get_result();
if ($assoc = $rs->fetch_assoc())
{
$batt_num = $assoc["num"];
$batt_type = $assoc["batterytype"];
$acquired = $assoc["acquired"];
$make_id = $assoc["make_id"];
$height = 100 / $assoc["whratio"];
echo "<tr><td>Number</td><td>$batt_num</td></tr>\n";
echo "<tr><td>Type</td><td>$batt_type</td></tr>\n";
echo "<tr><td>Make</td><td><img src=\"showimg.php?makeid=$make_id\" width=\"100\" height=\"$height\"></td></tr>\n";
echo "<tr><td>Acquired</td><td>$acquired</td></tr>\n";
echo "</tr></table><br><table border=1><tr><td>Event</td><td>device</td><td>date</td><td>Interval</td><td>Measurement</td></tr>";
$sEvents = $conn->prepare("select mydate, mah, device_id, evt_type from evt where batt_id=? order by mydate desc, evt_type") or die($conn->error);
$sEvents->bind_param("i", $battid) or die($conn->error);
$sEvents->execute();
$rsEvents = $sEvents->get_result();
$lastdate = null;
while ($assocEvents = $rsEvents->fetch_assoc())
{
switch ($assocEvents["evt_type"])
{
case 0:
$event = "Charged";
break;
case 1:
$event = "Measured";
break;
case 2:
$event = "Load";
break;
case 3:
case 4:
$event = "Unload";
if ($assocEvents["evt_type"] == 4)
$event .= " (was empty)";
break;
}
echo "<tr><td>$event</td><td><img src=\"showimg.php?devid=".$assocEvents["device_id"]."\" width=50 height=50></td><td>".$assocEvents["mydate"]."</td>";
$curdate = new DateTime($assocEvents["mydate"]);
if ($lastdate == null)
$datediff = "";
else
$datediff = format_interval($curdate->diff($lastdate));
$lastdate = $curdate;
echo "<td>".$datediff."</td>";
echo "<td align=\"right\">".($assocEvents["mah"] == null ? "" : $assocEvents["mah"]." mAh")."</td></tr>";
}
$rsEvents->close();
$sEvents->close();
echo "</table>\n";
}
$rs->close();
$s->close();
?>
</body>
</html>