X-Git-Url: https://git.rvb.name/weathermon.git/blobdiff_plain/e4e1557426f8e5ca10ca616140528939d86426cd..299b29f352765c8fa399aea6157f62356ef036e8:/web/archive.php?ds=inline diff --git a/web/archive.php b/web/archive.php index 79ef6c4..1b21599 100644 --- a/web/archive.php +++ b/web/archive.php @@ -23,7 +23,7 @@ } 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"> @@ -31,6 +31,22 @@ include('config_local.php'); include('calendar.php'); +include('units.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; + + } + $year = $_REQUEST['year']; $month = $_REQUEST['month']; @@ -57,7 +73,7 @@ if (! $year) { <?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 } @@ -113,6 +129,18 @@ if (! $year) { $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, @@ -127,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.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' ); @@ -136,12 +164,20 @@ if (! $year) { $sensors = $q -> fetchAll(PDO::FETCH_ASSOC); foreach ($sensors as $sensor) { - + + $units = get_unit($db,$sensor['param']); + $from_unit = $units['from']; + $to_unit = $units['to']; + $param_unit = $units['name']; + + $min_val = convert_unit($db,$sensor['min_value'],$from_unit,$to_unit); + $max_val = convert_unit($db,$sensor['max_value'],$from_unit,$to_unit); + echo '<h3 align="center">'.$sensor['param_name'].'('.$sensor['sensor_name'].')</h3>'; echo '<table align="center">'; echo '<tr><td>'; - echo 'ÐинималÑное знаÑение за год <b>'.$sensor['min_value'].' '.$sensor['unit'].'</b><br>'; - echo 'ÐакÑималÑное знаÑение за год <b>'.$sensor['max_value'].' '.$sensor['unit'].'</b><br>'; + echo 'ÐинималÑное знаÑение за год <b>'.$min_val.' '.$param_unit.'</b><br>'; + echo 'ÐакÑималÑное знаÑение за год <b>'.$max_val.' '.$param_unit.'</b><br>'; echo '</td></tr>'; echo '</table>'; @@ -172,14 +208,26 @@ if (! $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 - sensors_ranges + sensors_ranges r,sensors s where + s.id=r.sensor 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' ); @@ -197,6 +245,17 @@ if (! $year) { } 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 @@ -212,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.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' ); @@ -221,12 +280,20 @@ if (! $year) { $sensors = $q -> fetchAll(PDO::FETCH_ASSOC); foreach ($sensors as $sensor) { + + $units = get_unit($db,$sensor['param']); + $from_unit = $units['from']; + $to_unit = $units['to']; + $param_unit = $units['name']; + + $min_val = convert_unit($db,$sensor['min_value'],$from_unit,$to_unit); + $max_val = convert_unit($db,$sensor['max_value'],$from_unit,$to_unit); echo '<h3 align="center">'.$sensor['param_name'].'('.$sensor['sensor_name'].')</h3>'; echo '<table align="center">'; echo '<tr><td>'; - echo 'ÐинималÑное знаÑение за меÑÑÑ <b>'.$sensor['min_value'].' '.$sensor['unit'].'</b><br>'; - echo 'ÐакÑималÑное знаÑение за меÑÑÑ <b>'.$sensor['max_value'].' '.$sensor['unit'].'</b><br>'; + echo 'ÐинималÑное знаÑение за меÑÑÑ <b>'.$min_val.' '.$param_unit.'</b><br>'; + echo 'ÐакÑималÑное знаÑение за меÑÑÑ <b>'.$max_val.' '.$param_unit.'</b><br>'; echo '</td></tr>'; echo '</table>'; @@ -245,6 +312,17 @@ if (! $year) { $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 @@ -253,7 +331,7 @@ if (! $year) { 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();