summaryrefslogtreecommitdiff
path: root/html/index.php
blob: 2c15cdef7a24d16114e7e32ba25c860fc4898798 (plain)
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
<?php

include "db.php";

$result = $db -> query(
  'SELECT machines.id as machine, MIN(states.id) as min_state' .
  ' FROM machines' .
  ' JOIN "values" ON machines.id = "values".machine_id' .
  ' JOIN states ON "values".state_id = states.id' .
  ' WHERE "values".value IS NOT NULL' .
  ' GROUP BY machines.id'
);

$stm = $db -> prepare(
  'SELECT machines.name as machine, states.name as state, "values".value' .
  ' FROM machines' .
  ' JOIN "values" ON "values".machine_id = machines.id' .
  ' JOIN states ON "values".state_id = states.id' .
  ' WHERE machines.id = :machine' .
  ' AND states.id = :state'
);
$values = array();

while ($row = $result -> fetchArray()) {
  $stm -> bindValue('machine', $row['machine']);
  $stm -> bindValue('state', $row['min_state']);
  $stmres = $stm -> execute();
  $values[$row['machine']] = $stmres -> fetchArray();
}
$stm -> close();

?>
<html><body><table>
<tr>
  <th>machine</th>
  <th>state</th>
  <th>last update</th>
</tr>
<?php

function print_colorized($value, $text) {
  echo '<font color="';
  if ($value == 1)
    echo '#008000';
  else
    echo '#800000';
  echo '">' . $text . '</font>';
}

foreach ($values as $value) {
?> <tr>
  <td><?php print_colorized($value['value'], $value['machine']); ?></td>
  <td><?php print_colorized($value['value'], ($value['value'] == 1 ? '' : 'not ') . $value['state']); ?></td>
  <td><?php print_colorized($value['value'], $row['last_update']); ?></td>
</tr>
<?php
}
?>
</table></body></html>