Old version cleaned
[weathermon.git] / web / index.php
1 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
5   <meta http-equiv="Refresh" content="60"> 
6   <meta name="GENERATOR" content="Mozilla/4.72 (X11; U; Linux 2.2.12-20smp i686) [Netscape]">    
7   <title>WeatherMon (Последние 24 часа)</title>                      
8   <link rel="icon" href="favicon.png" />
9   <style type="text/css">
10      a:visited { text-decoration: none; color:darkblue; }
11      a:link { text-decoration: none; color:blue; }
12      a:hover { text-decoration: none; color:navy; }
13      .header { font-size: 16; float: left; margin: 10px;}
14      .timestamp { font-size: 16; margin: 10px;}
15      .value { font-size: 60; margin: 10px; }
16      .block { float: left; margin: 20px; }
17      .container { clear: both; }
18      .footer { clear: both; margin: 20px; font-size: 20; }
19   </style>
20 </head>
21 <body>         
22 <div class="container">
23 <?php
24
25 include('config_local.php');
26 include('units.php');
27
28 if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_schema",$mysql_user,$mysql_pwd,array( PDO::ATTR_PERSISTENT => false)))) {
29   die($err);
30   }  
31
32 $db -> exec('SET CHARACTER SET utf8');
33
34 $q = $db -> prepare(
35   'select 
36     distinct v.sensor_id,s.s_description,p.id as param_id,p.st_description 
37   from 
38     sensor_values v,st_parameters p,sensors s 
39   where 
40     v.timestamp>adddate(now(), -1) 
41     and v.sensor_id=s.id 
42     and s.st_id=p.st_id
43     and p.id>=0
44   order by s_description,st_description'
45   );
46 $q -> execute();
47
48 while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
49
50   echo '<div class="block">';
51   echo '<div class="header">'.$row['s_description'].'/'.$row['st_description'].'</div>';
52
53 $ql =  $db -> prepare(
54   '
55     SELECT unix_timestamp(timestamp) timestamp,DATE_FORMAT(timestamp,"%H:%i") printable,value
56     FROM
57       meteo.sensor_values 
58     WHERE 
59       sensor_id='.$row['sensor_id'].' and parameter_id='.$row['param_id'].' and timestamp>addtime(now(), -3600)
60     ORDER BY 
61       timestamp desc
62   '
63    );
64
65 $ql -> execute();
66
67 $printable_ts = "?";
68 $value = "?";
69
70 if ($rowl = $ql -> fetch(PDO::FETCH_ASSOC)) {
71
72   $timestamp = $rowl['timestamp'];
73   $printable_ts = $rowl['printable'];
74   $value = $rowl['value'];
75
76   $units = get_unit($db,$row['param_id']);
77   $from_unit = $units['from'];
78   $to_unit = $units['to'];
79   $param_unit = $units['name'];
80                         
81   $val = convert_unit($db,$value,$from_unit,$to_unit);
82                               
83 }
84                                   
85 echo '<div class="timestamp">'.$printable_ts.'</div>';
86 echo '<div class="value">'.$val.' '.$param_unit.'</div>';
87 ?>
88 <div class="graph"><img src="image.php?sensor=<?php echo $row['sensor_id']; ?>&param=<?php echo $row['param_id']?>&type=last24small"></div>
89 <?php  
90
91 echo "</div>";
92
93 }                                                            
94   
95 ?>
96 </div>
97 <div class="footer">
98 <a href="archive.php">Архивные данные</a>
99 <a href="graphs.php">Подробные графики</a>
100 <a href="setup.php">Настройки</a>
101 </div>
102 </body>
103