Перехват "лишнего" вывода от вызываемых подпроцессов, чтоб не засорять лог.
[weathermon.git] / web / index.php
index d513251323c808f04d1540790eff56a456cc898f..92a8e8e6a2dd384896fa8aa01311dcbee353680a 100644 (file)
@@ -2,14 +2,42 @@
 <html>
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
-  <meta name="GENERATOR" content="Mozilla/4.72 [cp1251] (X11; U; Linux 2.2.12-20smp i686) [Netscape]">    
+  <meta http-equiv="Refresh" content="60"> 
+  <meta name="GENERATOR" content="Mozilla/4.72 (X11; U; Linux 2.2.12-20smp i686) [Netscape]">    
   <title>WeatherMon (Последние 24 часа)</title>                      
   <link rel="icon" href="favicon.png" />
+  <style type="text/css">
+     a:visited { text-decoration: none; color:darkblue; }
+     a:link { text-decoration: none; color:blue; }
+     a:hover { text-decoration: underline; color:navy; }
+     .header { font-size: 16; float: left; margin: 10px;}
+     .timestamp { font-size: 16; margin: 10px;}
+     .value { font-size: 60; margin: 10px; }
+     .block { float: left; margin: 20px; }
+     .container { clear: both; }
+     .footer { clear: both; margin: 20px; font-size: 20; }
+  </style>
 </head>
-<body text="black" bgcolor="silver" link="blue" vlink="#000080" alink="#FF0000">         
+<body>         
+<div class="container">
 <?php
 
+  $client_ip = $_SERVER["REMOTE_ADDR"];
+
+  if ((strpos($client_ip, "192.168.") === 0) || (strpos($client_ip, "10.8.") === 0)
+     || (strpos($client_ip, "2a02:578:5002:8174:") === 0)
+     || (strpos($client_ip, "2a02:578:5002:196::2") === 0)) {
+   
+    $local_net = True;
+            
+  } else {
+  
+    $local_net = False;
+  
+  }
+
 include('config_local.php');
+include('units.php');
 
 if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_schema",$mysql_user,$mysql_pwd,array( PDO::ATTR_PERSISTENT => false)))) {
   die($err);
@@ -17,6 +45,16 @@ if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_sche
 
 $db -> exec('SET CHARACTER SET utf8');
 
+if (!$local_net) {
+
+  $filter = ' and s.is_public=1'; 
+
+} else {
+
+  $filter = '';
+
+}
+
 $q = $db -> prepare(
   'select 
     distinct v.sensor_id,s.s_description,p.id as param_id,p.st_description 
@@ -24,23 +62,69 @@ $q = $db -> prepare(
     sensor_values v,st_parameters p,sensors s 
   where 
     v.timestamp>adddate(now(), -1) 
-    and v.sensor_id=s.id 
-    and s.st_id=p.st_id'
+    and v.sensor_id=s.id
+    and v.parameter_id=p.id  
+    and s.st_id=p.st_id
+    and p.id>=0'.$filter.'
+  order by s_description,st_description'
   );
 $q -> execute();
 
 while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 
-  echo '<h3 align="center">'.$row['s_description'].'/'.$row['st_description'].'</h3>';
+  echo '<div class="block">';
+  echo '<div class="header">'.$row['s_description'].'/'.$row['st_description'].'</div>';
+
+$ql =  $db -> prepare(
+  '
+    SELECT unix_timestamp(timestamp) timestamp,DATE_FORMAT(timestamp,"%H:%i") printable,value
+    FROM
+      meteo.sensor_values 
+    WHERE 
+      sensor_id='.$row['sensor_id'].' and parameter_id='.$row['param_id'].' and timestamp>addtime(now(), -3600)
+    ORDER BY 
+      timestamp desc
+  '
+   );
+
+$ql -> execute();
+
+$printable_ts = "?";
+$val = "?";
+
+if ($rowl = $ql -> fetch(PDO::FETCH_ASSOC)) {
+
+  $timestamp = $rowl['timestamp'];
+  $printable_ts = $rowl['printable'];
+  $value = $rowl['value'];
+
+  $units = get_unit($db,$row['param_id']);
+  $from_unit = $units['from'];
+  $to_unit = $units['to'];
+  $param_unit = $units['name'];
+
+  $val = convert_unit($db,$value,$from_unit,$to_unit);
+                              
+}
+                                  
+if ($printable_ts != '?') { 
+  echo '<div class="timestamp">'.$printable_ts.'</div>';
+  echo '<div class="value">'.$val.' '.$param_unit.'</div>';
+}
 ?>
-<center><img src="image.php?sensor=<?php echo $row['sensor_id']; ?>&param=<?php echo $row['param_id']?>&type=last24"></center>
+<div class="graph"><a href="image.php?sensor=<?php echo $row['sensor_id']; ?>&param=<?php echo $row['param_id']?>&type=last24"><img src="image.php?sensor=<?php echo $row['sensor_id']; ?>&param=<?php echo $row['param_id']?>&type=last24small"></a></div>
 <?php  
 
+echo "</div>";
+
 }                                                            
   
 ?>
+</div>
+<div class="footer">
 <a href="archive.php">Архивные данные</a>
-<br>
+<a href="graphs.php">Подробные графики</a>
 <a href="setup.php">Настройки</a>
+</div>
 </body>
       
\ No newline at end of file