1 <?php // content="text/plain; charset=utf-8"
3 error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);
5 include ('config_local.php');
7 require_once ('jpgraph/jpgraph.php');
8 require_once ('jpgraph/jpgraph_line.php');
9 require_once ('jpgraph/jpgraph_date.php');
10 require_once ('jpgraph/jpgraph_scatter.php');
11 require_once ('jpgraph/jpgraph_regstat.php');
13 if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_schema",$mysql_user,$mysql_pwd,array( PDO::ATTR_PERSISTENT => false)))) {
15 die('Не могу подключиться к БД');
19 $supported = imagetypes();
20 if( $supported & IMG_PNG ) $img_format="png";
21 elseif( $supported & IMG_GIF ) $img_format="gif";
22 elseif( $supported & IMG_JPG ) $img_format="jpeg";
23 elseif( $supported & IMG_WBMP ) $img_format="wbmp";
24 elseif( $supported & IMG_XPM ) $img_format="xpm";
26 $cachefilename = NULL;
28 $db -> exec('SET CHARACTER SET utf8');
30 $type = $_REQUEST['type'];
31 $sensor=$_REQUEST['sensor'];
32 $param=$_REQUEST['param'];
33 $year=$_REQUEST['year'];
34 $month=$_REQUEST['month'];
36 if ($type and $param) {
38 $sensor = intval($sensor);
39 $param = intval($param);
42 'select s_description from sensors where id='.$sensor
46 while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
47 $sensor_name = $row['s_description'];
51 'select st.st_fill_color_top,st.st_fill_color_bottom,st.st_description,u.id,u.unit_group from st_parameters st,units u where st.id='.$param.' and st.st_unit=u.id
56 while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
57 $param_name = $row['st_description'];
58 $from_unit = $row['id'];
59 $unit_group = $row['unit_group'];
60 $fill_color_top=$row['st_fill_color_top'];
61 $fill_color_bottom=$row['st_fill_color_bottom'];
64 if (!empty($_COOKIE['unit_'.$unit_group])) {
65 $to_unit=intval($_COOKIE['unit_'.$unit_group]);
71 'select u.name_short from units u where u.id='.$to_unit
75 while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
76 $param_unit = $row['name_short'];
82 if ($type == 'month') {
85 $next_month = $month+1;
96 if ($curr>$next_year.$next_month) {
98 $cachefilename='meteo.month.'.$sensor.'.'.$param.'.'.$to_unit.'.'.$year.'-'.$month.'.'.$img_format;
106 unitconv(min(min),'.$from_unit.','.$to_unit.') min_value,
107 unitconv(max(max),'.$from_unit.','.$to_unit.') max_value
110 unix_timestamp(day) x,
116 day>=str_to_date(\''.$year.$month.'\',\'%Y%m\')
117 and day<str_to_date(\''.$next_year.$next_month.'\',\'%Y%m\')
118 and sensor='.$sensor.'
119 and parameter='.$param.'
124 } elseif ($type == "year") {
126 $next_year = $year+1;
130 if ($curr>$next_year) {
132 $cachefilename='meteo.year.'.$sensor.'.'.$param.'.'.$year.'.'.$img_format;
140 unitconv(min(min),'.$from_unit.','.$to_unit.') min_value,
141 unitconv(max(max),'.$from_unit.','.$to_unit.') max_value
145 DATE_SUB(day, INTERVAL DAYOFWEEK(day)-1 DAY)
152 day>=str_to_date(\''.$year.'\',\'%Y\')
153 and day<str_to_date(\''.$next_year.'\',\'%Y\')
154 and sensor='.$sensor.'
155 and parameter='.$param.'
162 $g = new Graph(640,480);
164 if ($cachefilename) {
165 if ($g->cache->IsValid($cachefilename)) {
167 $g->cache->StreamImgFile($g->img,$cachefilename);
173 $g->SetupCache($cachefilename,$timeout);
181 while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
183 $xdata[] = $row['x'];
184 $mindata[] = $row['min_value'];
185 $maxdata[] = $row['max_value'];
191 $g->graph_theme = null;
193 //$g->img->SetAntiAliasing();
195 // We need a linlin scale since we provide both
196 // x and y coordinates for the data points.
197 $g->SetScale('datlin');
198 $g->xaxis->SetLabelAngle(90);
199 $g->xaxis->SetPos("min");
200 $g->xaxis->scale->SetTimeAlign( MINADJ_1 );
202 // We use a scatterplot to illustrate the original
205 $bplot = new LinePlot($maxdata,$xdata);
207 $bplot->SetColor($fill_color_top);
208 $bplot->SetFillGradient($fill_color_top.'@0.2',$fill_color_bottom.'@0.9',100,TRUE);
209 $bplot->SetFillFromYMin(TRUE);
210 $bplot->SetWeight(4);
212 $aplot = new LinePlot($mindata,$xdata);
214 $aplot->SetColor($fill_color_bottom);
215 $aplot->SetFillGradient($fill_color_bottom.'@0.2','white@0.9',100,TRUE);
216 $aplot->SetFillFromYMin(TRUE);
217 $aplot->SetWeight(4);
219 $g->SetMargin(60,60,60,130);
220 $g->title->Set($sensor_name.'/'.$param_name.', '.$param_unit);
221 $g->title->SetFont(FF_DV_SANSSERIF,FS_BOLD,12);
222 $g->subtitle->Set('(минимальные и максимальные значения за период)');
223 $g->subtitle->SetColor('darkred');
224 $g->SetMarginColor('silver');
227 $g->xgrid->SetLineStyle('dotted');
229 $g->ygrid->SetLineStyle('dotted');
231 // Add the plots to the graph and stroke
236 header("Content-Type: text/html; charset=UTF-8");
237 die('Сенсор не выбран!');