<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="GENERATOR" content="Mozilla/4.72 [cp1251] (X11; U; Linux 2.2.12-20smp i686) [Netscape]"> <title>WeatherMon (архив)</title> <link rel="icon" href="favicon.png" /> </head> <body text="black" bgcolor="silver" link="blue" vlink="#000080" alink="#FF0000"> <?php include('config_local.php'); include('calendar.php'); $year = $_REQUEST['year']; $month = $_REQUEST['month']; $day = $_REQUEST['day']; if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_schema",$mysql_user,$mysql_pwd,array( PDO::ATTR_PERSISTENT => false)))) { die($err); } $db -> exec('SET CHARACTER SET utf8'); if (! $year) { $q = $db -> prepare( 'select date_format(timestamp,\'%Y\') as year from sensor_values group by year order by year'); $q -> execute(); ?> <h1>Ðрхив метеоданных</h1> <?php while ($row = $q -> fetch(PDO::FETCH_ASSOC)) { ?> <a href="?year=<?php echo $row['year']; ?>">Данные за <?php echo $row['year']; ?> год</a><br> <?php } } else { if (! $month) { $next_year = $year+1; $year = sprintf('%04d',$year); $next_year = sprintf('%04d',$next_year); $q = $db -> prepare( 'select date_format(timestamp,\'%m\') as month, date_format(timestamp,\'%d\') as day from sensor_values where timestamp>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and timestamp<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\') group by month,day order by month,day' ); $q -> execute(); ?> <h1 align="center"><?php echo $year; ?> год</h1> <?php $data = $q -> fetchAll(PDO::FETCH_ASSOC); $months = []; foreach ($data as $row) { $days [$year.$row['month'].$row['day']] = '&month='.$row['month'].'&day='.$row['day']; $months[$row['month']]=1; } $m = 1; echo '<table align="center">'; for ($i=1; $i<=3; $i++) { echo '<tr>'; for ($j=1; $j<=4; $j++) { echo '<td valign="top">'; $month=sprintf('%02d',$m); $month_name = strftime('%B',mktime(0,0,0,$month,1,$year)); if (!empty($months[$month])) { echo '<h3 align="center"><a href="?year='.$year.'&month='.$month.'">'.$month_name.'</a></h3>'; } else { echo '<h3 align="center">'.$month_name.'</h3>'; } calendar($year,$month,$days,'?year='.$year.'%s',0); echo '</td>'; $m++; } echo '</tr>'; } echo '</table>'; $next_year = $year+1; $q = $db -> prepare ( 'select s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name, count(distinct date_format(v.timestamp,\'%d\')) cnt, round(min(v.value),1) min_value, round(max(v.value),1) max_value, u.name_short unit from sensor_values v,sensors s,st_parameters p,units u where v.sensor_id=s.id and v.parameter_id=p.id and p.st_unit=u.id and v.timestamp>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and v.timestamp<str_to_date(\''.$next_year.'-01-01\',\'%Y-%m-%d\') group by s.id,p.id,s.s_description,p.st_description order by s.id,p.id' ); $q -> execute(); $sensors = $q -> fetchAll(PDO::FETCH_ASSOC); foreach ($sensors as $sensor) { 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 '</td></tr>'; echo '</table>'; if ($sensor['cnt']>1) { echo '<center><img src="image_minmax.php?sensor='.$sensor['sensor'].'¶m='.$sensor['param']. '&type=year&year='.$year.'"></center>'; } } } else { if (!$day) { $next_year = $year; $next_month = $month+1; if ($next_month == 13) { $next_month = 1; $next_year = $next_year+1; } $next_month = sprintf('%02d',$next_month); $next_year = sprintf('%04d',$next_year); $month = sprintf('%02d',$month); $year = sprintf('%04d',$year); $q = $db -> prepare( 'select date_format(timestamp,\'%d\') as day from sensor_values where timestamp>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and timestamp<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\') group by day order by day' ); $q -> execute(); $data = $q -> fetchAll(PDO::FETCH_ASSOC); $month_name = strftime('%B %Y',mktime(0,0,0,$month,1,$year)); ?> <h1 align="center"><?php echo 'Данные за '.$month_name; ?></h1> <?php foreach ($data as $row) { $days [$year.$month.$row['day']] = $row['day']; } calendar($year,$month,$days,'?year='.$year.'&month='.$month.'&day=%s',3); $q = $db -> prepare ( 'select s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name, count(distinct date_format(v.timestamp,\'%d\')) cnt, round(min(v.value),1) min_value, round(max(v.value),1) max_value, u.name_short unit from sensor_values v,sensors s,st_parameters p,units u where v.sensor_id=s.id and v.parameter_id=p.id and p.st_unit=u.id and v.timestamp>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and v.timestamp<str_to_date(\''.$next_year.'-'.$next_month.'-01\',\'%Y-%m-%d\') group by s.id,p.id,s.s_description,p.st_description order by s.id,p.id' ); $q -> execute(); $sensors = $q -> fetchAll(PDO::FETCH_ASSOC); foreach ($sensors as $sensor) { 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 '</td></tr>'; echo '</table>'; if ($sensor['cnt']>1) { echo '<center><img src="image_minmax.php?sensor='.$sensor['sensor'].'¶m='.$sensor['param']. '&type=month&year='.$year.'&month='.$month.'"></center>'; } } } else { $month = sprintf('%02d',$month); $year = sprintf('%04d',$year); $day = sprintf('%02d',$day); $q = $db -> prepare( 'select distinct v.sensor_id,s.s_description,p.id as param_id,p.st_description from sensor_values v,st_parameters p,sensors s where v.timestamp>=str_to_date(\''.$year.'-'.$month.'-'.$day.'\',\'%Y-%m-%d\') and v.timestamp<date_add(str_to_date(\''.$year.'-'.$month.'-'.$day.'\',\'%Y-%m-%d\'),interval 1 day) and v.sensor_id=s.id and s.st_id=p.st_id' ); $q -> execute(); while ($row = $q -> fetch(PDO::FETCH_ASSOC)) { echo '<h3 align="center">'.$row['s_description'].'/'.$row['st_description'].'</h3>'; ?> <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> <?php } } } } ?> </body>