<?php
/**
 * phpaga
 *
 * task category stats
 *
 * View task category statistics
 *
 * @author Florian Lanthaler <florian@phpaga.net>
 * @version $Id: opcat_graph.php 745 2006-09-27 21:21:07Z florian $
 *
 * Copyright (c) 2002, Florian Lanthaler <florian@phpaga.net>
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *    * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *    * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in
 *      the documentation and/or other materials provided with the
 *      distribution.
 *
 *    * Neither the name of Florian Lanthaler nor the names of his
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

include_once ("./config.php");

include_once(PHPAGA_LIBPATH."jpgraph_wrapper.php");

$status = "";
$opcat_arr = array ();
$opcatcount_arr = array ();
$opInfo = array ();
$sum_duration = 0;

$opInfo = array('cpn_id' => '',
                'prj_id' => '',
                'pe_id' => '',
                'opcat_id' => '',
                'op_desc' => '',
                'op_startdatefrom' => '',
                'op_startdateto' => '');

if (isset($_REQUEST["pdf"]) && is_numeric($_REQUEST["pdf"])
    && ($_REQUEST["pdf"] == 1)) {
    $graphWidth = PHPAGA_GRAPH_PDF_WIDTH;
    $graphHeight = PHPAGA_GRAPH_PDF_HEIGHT;
}
else
{
    $graphWidth = PHPAGA_GRAPH_WIDTH;
    $graphHeight = PHPAGA_GRAPH_HEIGHT;
}

if (isset($_REQUEST["cpn_id"]) && is_numeric($_REQUEST["cpn_id"]))
    $opInfo["cpn_id"] = $_REQUEST["cpn_id"];

if (isset($_REQUEST["prj_id"]) && is_numeric($_REQUEST["prj_id"]))
    $opInfo["prj_id"] = $_REQUEST["prj_id"];

if (isset($_REQUEST["pe_id"]) && is_numeric($_REQUEST["pe_id"]))
    $opInfo["pe_id"] = $_REQUEST["pe_id"];

if (isset($_REQUEST["opcat_id"]) && is_numeric($_REQUEST["opcat_id"]))
$opInfo["opcat_id"] = $_REQUEST["opcat_id"];

if (isset($_REQUEST["op_desc"]) && strlen($_REQUEST["op_desc"]))
    $opInfo["op_desc"] = $_REQUEST["op_desc"];

if (isset($_REQUEST["op_startdatefrom"]) && strlen($_REQUEST["op_startdatefrom"]))
    $opInfo["op_startdatefrom"] = $_REQUEST["op_startdatefrom"];

if (isset($_REQUEST["op_startdateto"]) && strlen($_REQUEST["op_startdateto"]))
$opInfo["op_startdateto"] = $_REQUEST["op_startdateto"];


$result = phpaga_operations_getOpcatStats($opInfo, $opcatStats, $sum_duration);

if ($result != PHPAGA_ERR_NONE)
    phpaga_error($result);
else {

    $custom_colors = array();
    $custom_defined = false;

    foreach ($opcatStats as $tmp_stats) {

        $opcat_arr[] = $tmp_stats["opcat_title"];
        $opcatcount_arr[] = $tmp_stats["opcat_duration"];

        if (isset($tmp_stats["opcat_color"]) && strlen($tmp_stats["opcat_color"])) {
            $custom_colors[] = $tmp_stats["opcat_color"];
            $custom_defined = true;
        } else
            $custom_colors[] = "#ffffff";

    }

    $graph = new PieGraph($graphWidth, $graphHeight);
    $graph->SetFrame(false);

    $graph->legend->Pos(0.001, 0.01);
    $graph->legend->SetShadow(false);
    $graph->legend->SetFillColor("#ffffff");

    if (PHPAGA_GRAPH_OPCAT_STYLE == PHPAGA_GRAPH_OPCAT_STYLE_PIE2D) {
        $custom_colors =  array_reverse($custom_colors);
        $p1 = new PiePlot ($opcatcount_arr);
    } else {
        $p1 = new PiePlot3d ($opcatcount_arr);
        $p1->SetAngle (PHPAGA_GRAPH_OPCAT_ANGLE);
    }

    if (isset($custom_colors) && is_array($custom_colors)
        && (count($custom_colors) > 0) && $custom_defined)
        $p1->SetSliceColors($custom_colors);

    elseif (isset($phpaga_piecolors) && is_array($phpaga_piecolors))
        $p1->SetSliceColors($phpaga_piecolors);

    $p1->SetSize(0.3);
    $p1->ExplodeAll();

    $p1->SetTheme('sand');
    $p1->SetCenter(0.3);
    $p1->SetLegends($opcat_arr);

    $graph->legend->SetColor("#444444", "white");
    $graph->legend->SetFont(FF_FONT1);
    $graph->Add($p1);
    $graph->Stroke();
}

?>