Merge branch 'master' of ssh://git.cweiske.de/~/git/usb-wde1-tools
[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 if (!function_exists('rrd_lastupdate')) {
11     echo "rrd PHP extension is missing\n";
12     exit(2);
13 }
14
15 $data = array();
16 foreach ($names as $id => $name) {
17     $data[$id]['name'] = $name;
18     foreach (array('humidity', 'temperature') as $item) {
19         $lu = rrd_lastupdate(
20             str_replace(
21                 array('{item}', '{id}'),
22                 array($item, $id),
23                 $filetemplate
24             )
25         );
26         if ($lu === false) {
27             throw new Exception(rrd_error());
28         }
29                       
30         $data[$id][$item] = reset($lu['data']);
31     }
32 }
33
34 foreach (glob(__DIR__ . '/templates/*.php') as $tplfile) {
35     $outfile = $outdir . basename($tplfile, '.php');
36     ob_start();
37     include $tplfile;
38     $content = ob_get_contents();
39     ob_end_clean();
40     file_put_contents($outfile, $content);
41 }
42 ?>