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');
 
  36 $year = $_REQUEST['year']; 
 
  37 $month = $_REQUEST['month'];
 
  38 $day = $_REQUEST['day'];
 
  40 if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_schema",$mysql_user,$mysql_pwd,array( PDO::ATTR_PERSISTENT => false)))) {
 
  44 $db -> exec('SET CHARACTER SET utf8');
 
  50        date_format(day,\'%Y\') as year
 
  57 <h1>Архив метеоданных</h1>
 
  59   while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 
  61   <a class="year" href="?year=<?php echo $row['year']; ?>">Данные за <?php echo $row['year']; ?> год</a><br>
 
  70     $year      = sprintf('%04d',$year);
 
  71     $next_year = sprintf('%04d',$next_year);
 
  74              date_format(day,\'%m\') as month,
 
  75              date_format(day,\'%d\') as day
 
  79              day>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and 
 
  80              day<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\')
 
  86 <h1 align="center"><?php echo $year; ?> год</h1>
 
  88     $data = $q -> fetchAll(PDO::FETCH_ASSOC);
 
  90     foreach ($data as $row) {
 
  91       $days [$year.$row['month'].$row['day']] = '&month='.$row['month'].'&day='.$row['day'];
 
  92       $months[$row['month']]=1;
 
  95     echo '<table align="center">';
 
  96     for ($i=1; $i<=3; $i++) {
 
  98       for ($j=1; $j<=4; $j++) {
 
  99         echo '<td valign="top">';
 
 100         $month=sprintf('%02d',$m);
 
 101         $month_name = strftime('%B',mktime(0,0,0,$month,1,$year));
 
 102         if (!empty($months[$month])) {
 
 103           echo '<h3 align="center"><a class="month" href="?year='.$year.'&month='.$month.'">'.$month_name.'</a></h3>';
 
 105           echo '<h3 align="center">'.$month_name.'</h3>';
 
 107         calendar($year,$month,$days,'?year='.$year.'%s',0);
 
 115     $next_year = $year+1;
 
 117     $q = $db -> prepare (
 
 119          s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name,
 
 120          count(distinct day) cnt,
 
 121          round(min(v.min),1) min_value,
 
 122          round(max(v.max),1) max_value,
 
 125          sensors_ranges v,sensors s,st_parameters p,units u
 
 130          v.day>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and 
 
 131          v.day<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\')
 
 132       group by s.id,p.id,s.s_description,p.st_description
 
 137     $sensors = $q -> fetchAll(PDO::FETCH_ASSOC);
 
 139     foreach ($sensors as $sensor) {
 
 141       $units = get_unit($db,$sensor['param']);
 
 142       $from_unit = $units['from'];
 
 143       $to_unit = $units['to'];
 
 144       $param_unit = $units['name'];
 
 146       $min_val = convert_unit($db,$sensor['min_value'],$from_unit,$to_unit);
 
 147       $max_val = convert_unit($db,$sensor['max_value'],$from_unit,$to_unit);
 
 149       echo '<h3 align="center">'.$sensor['param_name'].'('.$sensor['sensor_name'].')</h3>';
 
 150       echo '<table align="center">';
 
 152       echo 'Минимальное значение за год <b>'.$min_val.' '.$param_unit.'</b><br>';
 
 153       echo 'Максимальное значение за год <b>'.$max_val.' '.$param_unit.'</b><br>';
 
 157       if ($sensor['cnt']>1) {
 
 159         echo '<center><img src="image_minmax.php?sensor='.$sensor['sensor'].'¶m='.$sensor['param'].
 
 160           '&type=year&year='.$year.'"></center>';
 
 172       $next_month = $month+1;
 
 174       if ($next_month == 13) {
 
 176         $next_year = $next_year+1;
 
 179       $next_month = sprintf('%02d',$next_month); 
 
 180       $next_year  = sprintf('%04d',$next_year);
 
 181       $month      = sprintf('%02d',$month);
 
 182       $year      = sprintf('%04d',$year);
 
 186              date_format(day,\'%d\') as day
 
 190              day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and 
 
 191              day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')
 
 197       $data = $q -> fetchAll(PDO::FETCH_ASSOC);
 
 199       $month_name = strftime('%B %Y',mktime(0,0,0,$month,1,$year));
 
 202 <h1 align="center"><?php echo 'Данные за '.$month_name; ?></h1>
 
 204       foreach ($data as $row) {
 
 205         $days [$year.$month.$row['day']] = $row['day'];
 
 208       calendar($year,$month,$days,'?year='.$year.'&month='.$month.'&day=%s',3);
 
 210       $q = $db -> prepare (
 
 212              s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name,
 
 213              count(distinct day) cnt,
 
 214              round(min(v.min),1) min_value,
 
 215              round(max(v.max),1) max_value,
 
 218              sensors_ranges v,sensors s,st_parameters p,units u
 
 223              v.day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and 
 
 224              v.day<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\')
 
 225            group by s.id,p.id,s.s_description,p.st_description
 
 230       $sensors = $q -> fetchAll(PDO::FETCH_ASSOC);
 
 232       foreach ($sensors as $sensor) {
 
 234         $units = get_unit($db,$sensor['param']);
 
 235         $from_unit = $units['from'];
 
 236         $to_unit = $units['to'];
 
 237         $param_unit = $units['name'];
 
 239         $min_val = convert_unit($db,$sensor['min_value'],$from_unit,$to_unit);
 
 240         $max_val = convert_unit($db,$sensor['max_value'],$from_unit,$to_unit);
 
 242         echo '<h3 align="center">'.$sensor['param_name'].'('.$sensor['sensor_name'].')</h3>';
 
 243         echo '<table align="center">';
 
 245         echo 'Минимальное значение за месяц <b>'.$min_val.' '.$param_unit.'</b><br>';
 
 246         echo 'Максимальное значение за месяц <b>'.$max_val.' '.$param_unit.'</b><br>';
 
 250         if ($sensor['cnt']>1) {
 
 252           echo '<center><img src="image_minmax.php?sensor='.$sensor['sensor'].'¶m='.$sensor['param'].
 
 253             '&type=month&year='.$year.'&month='.$month.'"></center>';
 
 261       $month      = sprintf('%02d',$month);
 
 262       $year      = sprintf('%04d',$year);
 
 263       $day       = sprintf('%02d',$day);
 
 267                 distinct v.sensor as sensor_id,s.s_description,p.id as param_id,p.st_description 
 
 269                 sensors_ranges v,st_parameters p,sensors s 
 
 271                 v.day=str_to_date(\''.$year.'-'.$month.'-'.$day.'\',\'%Y-%m-%d\')
 
 273                 and v.parameter=p.id'
 
 277       while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 
 279         echo '<h3 align="center">'.$row['s_description'].'/'.$row['st_description'].'</h3>';
 
 281 <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>