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

$count_mast = array();
$mast_y = array();

$query5 = mysql_query("SELECT
    tbl_prn_logs.srv_comp_id,
    SUM(tbl_prn_logs.pages) AS sum_pages,
    tbl_prn_srv_comp.srv_name
    FROM tbl_prn_logs
    JOIN tbl_prn_srv_comp ON tbl_prn_logs.srv_comp_id=tbl_prn_srv_comp.srv_comp_id
    WHERE tbl_prn_logs.prn_data > DATE_ADD(CURDATE(), INTERVAL -12 MONTH)
    GROUP BY tbl_prn_logs.srv_comp_id");
$col_rows = mysql_num_rows($query5);
  while($col_time30 = mysql_fetch_array($query5,MYSQL_ASSOC)){
    $mast_y[] = $col_time30['srv_name'];
    $count_mast[] = intval($col_time30['sum_pages']);
}

$sely = max($count_mast);
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-up';
$delay = 0.5;
$cascade = 1;

// заголовок
$title = new title( $TEXT['prn-srv-stat-all'] );
$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( $mast_y );

$x = new x_axis();
$x->set_3d( 5 );
$x->colour = '#D0D0D0';
$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_3d();
$bar->set_values( $count_mast );
$bar->set_tooltip( '#val# страниц' );
//$bar->set_colour('#ff0000');
$bar->set_on_show(new bar_on_show($animation, $cascade, $delay));

$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();