1 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
 
   4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
 
   5   <meta name="GENERATOR" content="Mozilla/4.72 (X11; U; Linux 2.2.12-20smp i686) [Netscape]">    
 
   6   <title>WeatherMon (архив)</title>                      
 
   7   <link rel="icon" href="favicon.png" />
 
   8   <style type="text/css">
 
  12         border:2px solid darkgrey;
 
  24     a:visited { text-decoration: none; color:darkblue; }
 
  25     a:link { text-decoration: none; color:blue; }
 
  26     a:hover { text-decoration: none; color:navy; }  
 
  29 <body text="black" bgcolor="silver" link="blue" vlink="#000080" alink="#FF0000">         
 
  32 include('config_local.php');
 
  33 include('calendar.php');
 
  35 function get_unit($db,$param) {
 
  37   $qug = $db -> prepare(
 
  38     'select u.id,u.unit_group from st_parameters st,units u where st.id='.$param.' and st.st_unit=u.id'
 
  42   while ($row = $qug -> fetch(PDO::FETCH_ASSOC)) {
 
  43     $from_unit = $row['id'];
 
  44     $unit_group = $row['unit_group'];
 
  47   if (!empty($_COOKIE['unit_'.$unit_group])) {
 
  48     $to_unit=intval($_COOKIE['unit_'.$unit_group]);
 
  54     'select u.name_short from units u where u.id='.$to_unit
 
  58   while ($row = $qu -> fetch(PDO::FETCH_ASSOC)) {
 
  59     $param_unit = $row['name_short'];
 
  70 function convert_unit($db,$value,$from,$to) {
 
  79       'select round(unitconv('.$value.','.$from.','.$to.'),2) res'
 
  83     while ($row = $qv -> fetch(PDO::FETCH_ASSOC)) {
 
  93 $year = $_REQUEST['year']; 
 
  94 $month = $_REQUEST['month'];
 
  95 $day = $_REQUEST['day'];
 
  97 if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_schema",$mysql_user,$mysql_pwd,array( PDO::ATTR_PERSISTENT => false)))) {
 
 101 $db -> exec('SET CHARACTER SET utf8');
 
 107        date_format(day,\'%Y\') as year
 
 114 <h1>Архив метеоданных</h1>
 
 116   while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 
 118   <a class="year" href="?year=<?php echo $row['year']; ?>">Данные за <?php echo $row['year']; ?> год</a><br>
 
 126     $next_year = $year+1;
 
 127     $year      = sprintf('%04d',$year);
 
 128     $next_year = sprintf('%04d',$next_year);
 
 131              date_format(day,\'%m\') as month,
 
 132              date_format(day,\'%d\') as day
 
 136              day>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and 
 
 137              day<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\')
 
 143 <h1 align="center"><?php echo $year; ?> год</h1>
 
 145     $data = $q -> fetchAll(PDO::FETCH_ASSOC);
 
 147     foreach ($data as $row) {
 
 148       $days [$year.$row['month'].$row['day']] = '&month='.$row['month'].'&day='.$row['day'];
 
 149       $months[$row['month']]=1;
 
 152     echo '<table align="center">';
 
 153     for ($i=1; $i<=3; $i++) {
 
 155       for ($j=1; $j<=4; $j++) {
 
 156         echo '<td valign="top">';
 
 157         $month=sprintf('%02d',$m);
 
 158         $month_name = strftime('%B',mktime(0,0,0,$month,1,$year));
 
 159         if (!empty($months[$month])) {
 
 160           echo '<h3 align="center"><a class="month" href="?year='.$year.'&month='.$month.'">'.$month_name.'</a></h3>';
 
 162           echo '<h3 align="center">'.$month_name.'</h3>';
 
 164         calendar($year,$month,$days,'?year='.$year.'%s',0);
 
 172     $next_year = $year+1;
 
 174     $q = $db -> prepare (
 
 176          s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name,
 
 177          count(distinct day) cnt,
 
 178          round(min(v.min),1) min_value,
 
 179          round(max(v.max),1) max_value,
 
 182          sensors_ranges v,sensors s,st_parameters p,units u
 
 187          v.day>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and 
 
 188          v.day<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\')
 
 189       group by s.id,p.id,s.s_description,p.st_description
 
 194     $sensors = $q -> fetchAll(PDO::FETCH_ASSOC);
 
 196     foreach ($sensors as $sensor) {
 
 198       $units = get_unit($db,$sensor['param']);
 
 199       $from_unit = $units['from'];
 
 200       $to_unit = $units['to'];
 
 201       $param_unit = $units['name'];
 
 203       $min_val = convert_unit($db,$sensor['min_value'],$from_unit,$to_unit);
 
 204       $max_val = convert_unit($db,$sensor['max_value'],$from_unit,$to_unit);
 
 206       echo '<h3 align="center">'.$sensor['param_name'].'('.$sensor['sensor_name'].')</h3>';
 
 207       echo '<table align="center">';
 
 209       echo 'Минимальное значение за год <b>'.$min_val.' '.$param_unit.'</b><br>';
 
 210       echo 'Максимальное значение за год <b>'.$max_val.' '.$param_unit.'</b><br>';
 
 214       if ($sensor['cnt']>1) {
 
 216         echo '<center><img src="image_minmax.php?sensor='.$sensor['sensor'].'¶m='.$sensor['param'].
 
 217           '&type=year&year='.$year.'"></center>';
 
 229       $next_month = $month+1;
 
 231       if ($next_month == 13) {
 
 233         $next_year = $next_year+1;
 
 236       $next_month = sprintf('%02d',$next_month); 
 
 237       $next_year  = sprintf('%04d',$next_year);
 
 238       $month      = sprintf('%02d',$month);
 
 239       $year      = sprintf('%04d',$year);
 
 243              date_format(day,\'%d\') as day
 
 247              day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and 
 
 248              day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')
 
 254       $data = $q -> fetchAll(PDO::FETCH_ASSOC);
 
 256       $month_name = strftime('%B %Y',mktime(0,0,0,$month,1,$year));
 
 259 <h1 align="center"><?php echo 'Данные за '.$month_name; ?></h1>
 
 261       foreach ($data as $row) {
 
 262         $days [$year.$month.$row['day']] = $row['day'];
 
 265       calendar($year,$month,$days,'?year='.$year.'&month='.$month.'&day=%s',3);
 
 267       $q = $db -> prepare (
 
 269              s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name,
 
 270              count(distinct day) cnt,
 
 271              round(min(v.min),1) min_value,
 
 272              round(max(v.max),1) max_value,
 
 275              sensors_ranges v,sensors s,st_parameters p,units u
 
 280              v.day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and 
 
 281              v.day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')
 
 282            group by s.id,p.id,s.s_description,p.st_description
 
 287       $sensors = $q -> fetchAll(PDO::FETCH_ASSOC);
 
 289       foreach ($sensors as $sensor) {
 
 291         $units = get_unit($db,$sensor['param']);
 
 292         $from_unit = $units['from'];
 
 293         $to_unit = $units['to'];
 
 294         $param_unit = $units['name'];
 
 296         $min_val = convert_unit($db,$sensor['min_value'],$from_unit,$to_unit);
 
 297         $max_val = convert_unit($db,$sensor['max_value'],$from_unit,$to_unit);
 
 299         echo '<h3 align="center">'.$sensor['param_name'].'('.$sensor['sensor_name'].')</h3>';
 
 300         echo '<table align="center">';
 
 302         echo 'Минимальное значение за месяц <b>'.$min_val.' '.$param_unit.'</b><br>';
 
 303         echo 'Максимальное значение за месяц <b>'.$max_val.' '.$param_unit.'</b><br>';
 
 307         if ($sensor['cnt']>1) {
 
 309           echo '<center><img src="image_minmax.php?sensor='.$sensor['sensor'].'¶m='.$sensor['param'].
 
 310             '&type=month&year='.$year.'&month='.$month.'"></center>';
 
 318       $month      = sprintf('%02d',$month);
 
 319       $year      = sprintf('%04d',$year);
 
 320       $day       = sprintf('%02d',$day);
 
 324                 distinct v.sensor as sensor_id,s.s_description,p.id as param_id,p.st_description 
 
 326                 sensors_ranges v,st_parameters p,sensors s 
 
 328                 v.day=str_to_date(\''.$year.'-'.$month.'-'.$day.'\',\'%Y-%m-%d\')
 
 330                 and v.parameter=p.id'
 
 334       while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 
 336         echo '<h3 align="center">'.$row['s_description'].'/'.$row['st_description'].'</h3>';
 
 338 <center><img src="image.php?sensor=<?php echo $row['sensor_id']; ?>¶m=<?php echo $row['param_id']?>&type=range&fromdate=<?php echo $year.$month.$day.'000000'; ?>&todate=<?php echo $year.$month.$day.'235959'?>"></center>