<?php
  ///////////////////////////////////////////////////
  //2011 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

include '../php-ofc-library/open-flash-chart.php';

$lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
 if(is_file ("../lang/".$lang.".php")) include "../lang/".$lang.".php";
  else include "../lang/ru.php";
require_once "../config.php";

  if(! @mysql_select_db($dbname,$dbcnx))
  {
    echo("<p>At this moment database is not available, therefore correct display of page is impossible.<br />If you do not install project previously, run script <a href=install.php>http://".$_SERVER['SERVER_ADDR']."/personal/install.php</a></p>");
    exit();
  }

$query_tmp_ofc_sel = mysql_query("SELECT * FROM `tbl_tmp_ofc` WHERE `user`='".$_COOKIE['login']."' ");
   if(!$query_tmp_ofc_sel) puterror2(mysql_error());
      $sost_ofc = mysql_fetch_array($query_tmp_ofc_sel,MYSQL_ASSOC);

if($sost_ofc['yea']>0) $ofc_yea = " AND `yea`='".$sost_ofc['yea']."' ";
if($sost_ofc['mon']>0) $ofc_mon = " AND `mon`='".$sost_ofc['mon']."' ";

$data_char_y = array();

$query5 = mysql_query("SELECT COUNT(time_isp) FROM tbl_supp_archive WHERE time_isp < '30' $ofc_yea $ofc_mon");
$col_time30 = mysql_result($query5, 0);
$data_char_y[] = intval($col_time30);

$query6 = mysql_query("SELECT COUNT(time_isp) FROM tbl_supp_archive WHERE (time_isp BETWEEN '30' AND '60') $ofc_yea $ofc_mon");
$col_time60 = mysql_result($query6, 0);
$data_char_y[] = intval($col_time60);

$query7 = mysql_query("SELECT COUNT(time_isp) FROM tbl_supp_archive WHERE (time_isp BETWEEN '61' AND '300') $ofc_yea $ofc_mon");
$col_time300 = mysql_result($query7, 0);
$data_char_y[] = intval($col_time300);

$query8 = mysql_query("SELECT COUNT(time_isp) FROM tbl_supp_archive WHERE (time_isp BETWEEN '301' AND '1440') $ofc_yea $ofc_mon");
$col_time1440 = mysql_result($query8, 0);
$data_char_y[] = intval($col_time1440);

$query9 = mysql_query("SELECT COUNT(time_isp) FROM tbl_supp_archive WHERE time_isp > '1441' $ofc_yea");
$col_time1441 = mysql_result($query9, 0);
$data_char_y[] = intval($col_time1441);

$sely = max($data_char_y);
if($sely > 10000) $sely_range = round($sely/5);
 elseif($sely >= 100 && $sely < 10000) $sely_range = round($sely/5);
 elseif($sely >= 10 && $sely < 100) $sely_range = round($sely/5);
 else $sely_range = 2;

// анимация
$animation = 'pop';
$delay = 1;
$cascade = 1;

// заголовок
$title = new title( $TEXT['chart-by-time'] );
$title->set_style( '{color: #778877; font-size: 14px; font-weight: bold;}' );

//описание оси Y
$y = new y_axis();
$y->set_range( 0, $sely, $sely_range );

//описание оси Х
$x_labels = new x_axis_labels();
$x_labels->set_steps( 1 );
$x_labels->rotate(-25);
$x_labels->set_colour( '#0E' );
$x_labels->set_labels( array("<30 min", "30-60 min","1-5 hour","5-24 hour",">24 hour") );

$x = new x_axis();
$x->set_colour( '#A2ACBA' );
$x->set_grid_colour( '#D7E4A3' );
$x->set_offset( true );
$x->set_steps(4);
// Add the X Axis Labels to the X Axis
$x->set_labels( $x_labels );

// Подпись внизу (legend)
//$x_legend = new x_legend( 'По затраченному времени' );
//$x_legend->set_style( '{font-size: 18px; color: #778877}' );

//область над осью Х
//$area = new area();
//$area->set_colour( '#5B56B6' );
//$area->set_values( $price );
//$area->set_key( 'Заявки', 12 );

//всплывающее описание
$tooltip = new tooltip();
$tooltip->set_hover();
$tooltip->set_stroke( 1 );
$tooltip->set_colour( "#000000" );
$tooltip->set_background_colour( "#ffffff" );

$bar = new bar_sketch( '#81AC00', '#567300', 5 );
$bar->set_values( $data_char_y );
$bar->set_on_show(new bar_on_show($animation, $cascade, $delay));
$bar->set_tooltip( '#val# заявок' );

$chart = new open_flash_chart();
$chart->set_title( $title );
$chart->set_y_axis( $y );
$chart->set_x_axis( $x );
//$chart->set_x_legend( $x_legend );
$chart->add_element( $bar );
//$chart->add_element( $area );
$chart->set_tooltip( $tooltip );

echo $chart->toPrettyString();