92dc41c6fcdee70787ff8eccd4c05a8871680945
[usb-wde1-tools.git] / htmlreport / gen-html.php
1 #!/usr/bin/env php
2 <?php
3 $cfgfile = __DIR__ . '/config.php';
4 if (!file_exists($cfgfile)) {
5     echo "Copy config.php.dist to config.php and adjust it\n";
6     exit(1);
7 }
8 require $cfgfile;
9
10 $data = array();
11 foreach ($names as $id => $name) {
12     $data[$id]['name'] = $name;
13     foreach (array('humidity', 'temperature') as $item) {
14         $lu = rrd_lastupdate(
15             str_replace(
16                 array('{item}', '{id}'),
17                 array($item, $id),
18                 $filetemplate
19             )
20         );
21         if ($lu === false) {
22             throw new Exception(rrd_error());
23         }
24                       
25         $data[$id][$item] = reset($lu['data']);
26     }
27 }
28
29 foreach (glob(__DIR__ . '/templates/*.php') as $tplfile) {
30     $outfile = $outdir . basename($tplfile, '.php');
31     ob_start();
32     include $tplfile;
33     $content = ob_get_contents();
34     ob_end_clean();
35     file_put_contents($outfile, $content);
36 }
37 ?>