<?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();
  }

$month["1"] = $TEXT['month01r'];
$month["2"] = $TEXT['month02r'];
$month["3"] = $TEXT['month03r'];
$month["4"] = $TEXT['month04r'];
$month["5"] = $TEXT['month05r'];
$month["6"] = $TEXT['month06r'];
$month["7"] = $TEXT['month07r'];
$month["8"] = $TEXT['month08r'];
$month["9"] = $TEXT['month09r'];
$month["10"] = $TEXT['month10r'];
$month["11"] = $TEXT['month11r'];
$month["12"] = $TEXT['month12r'];

$count_month = array();
$mon_y = array();

$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 = " WHERE `yea`='".$sost_ofc['yea']."' ";
 $char_tit = $TEXT['chart-by-year'];
}
else $char_tit = $TEXT['chart-by-mon2'];

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

$query5 = mysql_query("SELECT DISTINCT(`mon`), (SELECT COUNT(`arch_id`) FROM tbl_supp_archive WHERE `mon` = z.mon) AS `count_mon`
    FROM tbl_supp_archive z
     $ofc_yea ");
$col_rows = mysql_num_rows($query5);
while ($col_time30 = mysql_fetch_array($query5,MYSQL_ASSOC)){
    $mon_y[] = $month[$col_time30['mon']];
    $count_month[] = intval($col_time30['count_mon']);
}

$sely = max($count_month);
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 = 'fade-in';
$delay = 1.5;
$cascade = 1;

// заголовок
$title = new title( $char_tit );
$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( $mon_y );

$x = new x_axis();
//$x->set_3d( 10 );
$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_filled( '#E2D66A', '#577261' );
$bar->set_values( $count_month );
$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();