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 $db -> exec('SET CHARACTER SET utf8');
 
  21 $type = $_REQUEST['type'];
 
  22 $sensor=$_REQUEST['sensor'];
 
  23 $param=$_REQUEST['param'];
 
  24 $year=$_REQUEST['year'];
 
  25 $month=$_REQUEST['month'];
 
  27 if ($type and $param) {
 
  29   $sensor = intval($sensor);
 
  30   $param = intval($param);
 
  33     'select s_description from sensors where id='.$sensor
 
  37   while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 
  38     $sensor_name = $row['s_description'];
 
  42     '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
 
  47   while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 
  48     $param_name = $row['st_description'];
 
  49     $from_unit = $row['id'];
 
  50     $unit_group = $row['unit_group'];
 
  51     $fill_color_top=$row['st_fill_color_top'];
 
  52     $fill_color_bottom=$row['st_fill_color_bottom'];
 
  55   if (!empty($_COOKIE['unit_'.$unit_group])) {
 
  56     $to_unit=intval($_COOKIE['unit_'.$unit_group]);
 
  62     'select u.name_short from units u where u.id='.$to_unit
 
  66   while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 
  67     $param_unit = $row['name_short'];
 
  73   if ($type == 'month') { 
 
  76     $next_month = $month+1;
 
  89           unitconv(min(value),'.$from_unit.','.$to_unit.') min_value,
 
  90           unitconv(max(value),'.$from_unit.','.$to_unit.') max_value
 
  93             unix_timestamp(cast(timestamp as date)) x,
 
  98             timestamp>=str_to_date(\''.$year.$month.'\',\'%Y%m\')
 
  99             and timestamp<str_to_date(\''.$next_year.$next_month.'\',\'%Y%m\')
 
 100             and sensor_id='.$sensor.'
 
 101             and parameter_id='.$param.'
 
 106   } elseif ($type == "year") {
 
 108     $next_year = $year+1;
 
 114           unitconv(min(value),'.$from_unit.','.$to_unit.') min_value,
 
 115           unitconv(max(value),'.$from_unit.','.$to_unit.') max_value
 
 119               DATE_SUB(cast(timestamp as date), INTERVAL DAYOFWEEK(cast(timestamp as date))-1 DAY)
 
 125             timestamp>=str_to_date(\''.$year.'\',\'%Y\')
 
 126             and timestamp<str_to_date(\''.$next_year.'\',\'%Y\')
 
 127             and sensor_id='.$sensor.'
 
 128             and parameter_id='.$param.'
 
 137   while ($row = $q -> fetch(PDO::FETCH_ASSOC)) {
 
 139     $xdata[] = $row['x'];
 
 140     $mindata[] = $row['min_value'];
 
 141     $maxdata[] = $row['max_value'];
 
 147   $g = new Graph(640,480);
 
 148   $g->graph_theme = null;
 
 150   //$g->img->SetAntiAliasing();
 
 152   // We need a linlin scale since we provide both
 
 153   // x and y coordinates for the data points.
 
 154   $g->SetScale('datlin');
 
 155   $g->xaxis->SetLabelAngle(90);
 
 156   $g->xaxis->SetPos("min");
 
 158   // We use a scatterplot to illustrate the original
 
 161   $bplot = new LinePlot($maxdata,$xdata);
 
 163   $bplot->SetColor($fill_color_top);
 
 164   $bplot->SetFillGradient($fill_color_top,$fill_color_bottom,100,TRUE);
 
 165   $bplot->SetFillFromYMin(TRUE);        
 
 166   $bplot->SetWeight(4);
 
 168   $aplot = new LinePlot($mindata,$xdata);
 
 170   $aplot->SetColor($fill_color_bottom);
 
 171   $aplot->SetFillGradient($fill_color_bottom,'white',100,TRUE);
 
 172   $aplot->SetFillFromYMin(TRUE);        
 
 173   $aplot->SetWeight(4);
 
 175   $g->SetMargin(60,60,60,130);
 
 176   $g->title->Set($sensor_name.'/'.$param_name.', '.$param_unit);
 
 177   $g->title->SetFont(FF_DV_SANSSERIF,FS_BOLD,12);
 
 178   $g->subtitle->Set('(минимальные и максимальные значения за период)');
 
 179   $g->subtitle->SetColor('darkred');
 
 180   $g->SetMarginColor('silver');
 
 182   // Add the plots to the graph and stroke
 
 187   header("Content-Type: text/html; charset=UTF-8");
 
 188   die('Сенсор не выбран!');