Merge commit '2545d27aacfe57c8f26fccfd45e382fbf5c111ac'
[weathermon.git] / web / archive.php
index 031bce768e2208451d8da000d84b8dbfde2a7eb4..1b21599236fb7866428a04c4ab09fd0fbb4d46b0 100644 (file)
@@ -23,7 +23,7 @@
     }                                          
     a:visited { text-decoration: none; color:darkblue; }
     a:link { text-decoration: none; color:blue; }
     }                                          
     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; }  
   </style>
 </head>
 <body text="black" bgcolor="silver" link="blue" vlink="#000080" alink="#FF0000">         
   </style>
 </head>
 <body text="black" bgcolor="silver" link="blue" vlink="#000080" alink="#FF0000">         
 
 include('config_local.php');
 include('calendar.php');
 
 include('config_local.php');
 include('calendar.php');
+include('units.php');
 
 
-function get_unit($db,$param) {
+  $client_ip = $_SERVER["REMOTE_ADDR"];
 
 
-  $qug = $db -> prepare(
-    'select u.id,u.unit_group from st_parameters st,units u where st.id='.$param.' and st.st_unit=u.id'
-  );
-  $qug -> execute();
-                                    
-  while ($row = $qug -> fetch(PDO::FETCH_ASSOC)) {
-    $from_unit = $row['id'];
-    $unit_group = $row['unit_group'];
-  }
-                                                                       
-  if (!empty($_COOKIE['unit_'.$unit_group])) {
-    $to_unit=intval($_COOKIE['unit_'.$unit_group]);
-  } else {
-    $to_unit=$from_unit;
-  }
-                                                                                                                
-  $qu = $db -> prepare(
-    'select u.name_short from units u where u.id='.$to_unit
-  );
-  $qu -> execute();
-                                                                                                                                                                 
-  while ($row = $qu -> fetch(PDO::FETCH_ASSOC)) {
-    $param_unit = $row['name_short'];
-  }
-  return Array(
-    'from' => $from_unit,
-    'to' => $to_unit,
-    'name' => $param_unit
-  );                                                                                                                                                                                    
-
-}
-
-function convert_unit($db,$value,$from,$to) {
+  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)) {
 
 
-  if ($from==$to) {
-
-    $val = $value;
+    $local_net = True;
 
   } else {
 
 
   } else {
 
-    $qv = $db -> prepare(
-      'select round(unitconv('.$value.','.$from.','.$to.'),2) res'
-    );
-    $qv -> execute();
-                            
-    while ($row = $qv -> fetch(PDO::FETCH_ASSOC)) {
-      $val = $row['res'];
-    }
+    $local_net = False;
 
   }
 
   }
-                                                        
-  return $val;
 
 
-}
 
 $year = $_REQUEST['year']; 
 $month = $_REQUEST['month'];
 
 $year = $_REQUEST['year']; 
 $month = $_REQUEST['month'];
@@ -115,7 +73,7 @@ if (! $year) {
 <?php
   while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 ?> 
 <?php
   while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 ?> 
-  <a class="year" href="?year=<?php echo $row['year']; ?>">Данные за <?php echo $row['year']; ?> год</a><br>
+  <a class="year" href="?year=<?php echo $row['year']; ?>">Данные за <?php echo $row['year']; ?> год</a>
 <?php
   }
       
 <?php
   }
       
@@ -171,6 +129,18 @@ if (! $year) {
     
     $next_year = $year+1;
 
     
     $next_year = $year+1;
 
+    if (!$local_net) {
+
+      $filter = ' and s.is_public=1';
+  
+    } else {
+  
+      $filter = '';
+    
+    }  
+    
+    
+
     $q = $db -> prepare (
       'select 
          s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name,
     $q = $db -> prepare (
       'select 
          s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name,
@@ -185,7 +155,7 @@ if (! $year) {
          v.parameter=p.id and
          p.st_unit=u.id and
          v.day>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and 
          v.parameter=p.id and
          p.st_unit=u.id and
          v.day>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and 
-         v.day<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\')
+         v.day<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\''.$filter.')
       group by s.id,p.id,s.s_description,p.st_description
       order by s.id,p.id'
       );
       group by s.id,p.id,s.s_description,p.st_description
       order by s.id,p.id'
       );
@@ -238,14 +208,26 @@ if (! $year) {
       $month      = sprintf('%02d',$month);
       $year      = sprintf('%04d',$year);
 
       $month      = sprintf('%02d',$month);
       $year      = sprintf('%04d',$year);
 
+      if (!$local_net) {
+
+        $filter = ' and s.is_public=1';
+  
+      } else {
+  
+        $filter = '';
+    
+      }  
+    
+
       $q = $db -> prepare( 
           'select  
              date_format(day,\'%d\') as day
            from 
       $q = $db -> prepare( 
           'select  
              date_format(day,\'%d\') as day
            from 
-             sensors_ranges
+             sensors_ranges r,sensors s 
            where 
            where 
+             s.id=r.sensor and
              day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and 
              day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and 
-             day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')
+             day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')'.$filter.'
            group by day
            order by day'
           );
            group by day
            order by day'
           );
@@ -263,6 +245,17 @@ if (! $year) {
       }
 
       calendar($year,$month,$days,'?year='.$year.'&month='.$month.'&day=%s',3);
       }
 
       calendar($year,$month,$days,'?year='.$year.'&month='.$month.'&day=%s',3);
+             
+      if (!$local_net) {
+      
+        $filter = ' and s.is_public=1';
+                
+      } else {
+                        
+        $filter = '';
+                                    
+      }
+                                                       
               
       $q = $db -> prepare (
           'select 
               
       $q = $db -> prepare (
           'select 
@@ -278,7 +271,7 @@ if (! $year) {
              v.parameter=p.id and
              p.st_unit=u.id and
              v.day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and 
              v.parameter=p.id and
              p.st_unit=u.id and
              v.day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and 
-             v.day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')
+             v.day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')'.$filter.'
            group by s.id,p.id,s.s_description,p.st_description
            order by s.id,p.id'
         );
            group by s.id,p.id,s.s_description,p.st_description
            order by s.id,p.id'
         );
@@ -319,6 +312,17 @@ if (! $year) {
       $year      = sprintf('%04d',$year);
       $day       = sprintf('%02d',$day);
 
       $year      = sprintf('%04d',$year);
       $day       = sprintf('%02d',$day);
 
+      if (!$local_net) {
+
+        $filter = ' and s.is_public=1';
+  
+      } else {
+  
+        $filter = '';
+    
+      }
+
+
       $q = $db -> prepare(
            'select 
                distinct v.sensor as sensor_id,s.s_description,p.id as param_id,p.st_description 
       $q = $db -> prepare(
            'select 
                distinct v.sensor as sensor_id,s.s_description,p.id as param_id,p.st_description 
@@ -327,7 +331,7 @@ if (! $year) {
             where 
                 v.day=str_to_date(\''.$year.'-'.$month.'-'.$day.'\',\'%Y-%m-%d\')
                 and v.sensor=s.id 
             where 
                 v.day=str_to_date(\''.$year.'-'.$month.'-'.$day.'\',\'%Y-%m-%d\')
                 and v.sensor=s.id 
-                and v.parameter=p.id'
+                and v.parameter=p.id'.$filter
             );
       $q -> execute();
 
             );
       $q -> execute();