Web updated
[weathermon.git] / web / index.php
index 37251e653214c0b70ed45d4e11408103d0fe3f1b..92a8e8e6a2dd384896fa8aa01311dcbee353680a 100644 (file)
@@ -9,7 +9,7 @@
   <style type="text/css">
      a:visited { text-decoration: none; color:darkblue; }
      a:link { text-decoration: none; color:blue; }
-     a:hover { text-decoration: none; color:navy; }
+     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; }
 <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');
 
@@ -31,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 
@@ -38,9 +62,10 @@ $q = $db -> prepare(
     sensor_values v,st_parameters p,sensors s 
   where 
     v.timestamp>adddate(now(), -1) 
-    and v.sensor_id=s.id 
+    and v.sensor_id=s.id
+    and v.parameter_id=p.id  
     and s.st_id=p.st_id
-    and p.id>=0
+    and p.id>=0'.$filter.'
   order by s_description,st_description'
   );
 $q -> execute();
@@ -65,7 +90,7 @@ $ql =  $db -> prepare(
 $ql -> execute();
 
 $printable_ts = "?";
-$value = "?";
+$val = "?";
 
 if ($rowl = $ql -> fetch(PDO::FETCH_ASSOC)) {
 
@@ -77,15 +102,17 @@ if ($rowl = $ql -> fetch(PDO::FETCH_ASSOC)) {
   $from_unit = $units['from'];
   $to_unit = $units['to'];
   $param_unit = $units['name'];
-                        
+
   $val = convert_unit($db,$value,$from_unit,$to_unit);
                               
 }
                                   
-echo '<div class="timestamp">'.$printable_ts.'</div>';
-echo '<div class="value">'.$val.' '.$param_unit.'</div>';
+if ($printable_ts != '?') { 
+  echo '<div class="timestamp">'.$printable_ts.'</div>';
+  echo '<div class="value">'.$val.' '.$param_unit.'</div>';
+}
 ?>
-<div class="graph"><img src="image.php?sensor=<?php echo $row['sensor_id']; ?>&param=<?php echo $row['param_id']?>&type=last24small"></div>
+<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>";