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