<?php
/**
 * phpaga
 *
 * Projects chart
 *
 * This module displays a Gantt chart of the available projects.
 *
 * @author Florian Lanthaler <florian@phpaga.net>
 * @version $Id: projects_graph_gantt.php 707 2006-07-31 16:03:37Z 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");

$time1 = mktime();
$result = phpaga_projects_getProjectDatesList($data);
$time2= mktime();

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

    $graph = new GanttGraph(PHPAGA_PRHGRAPH_GANTT_WIDTH);

#    $graph->SetColor(PHPAGA_PRHGRAPH_GANTT_COLOR_BACKGROUND);
    $graph->SetMarginColor(PHPAGA_PRHGRAPH_GANTT_COLOR_BACKGROUND);
    $graph->SetFrame(PHPAGA_PRHGRAPH_GANTT_FRAME);

    $graph->ShowHeaders(GANTT_HMONTH | GANTT_HYEAR);

    $graph->SetBox(true,
                   PHPAGA_PRHGRAPH_GANTT_COLOR_HEADERBAR_DIVIDER,
                   PHPAGA_PRHGRAPH_GANTT_WIDTH_HEADERBAR_DIVIDER);

    $graph->scale->divider->SetWeight(PHPAGA_PRHGRAPH_GANTT_WIDTH_HEADERBAR_DIVIDER);
    $graph->scale->dividerh->SetWeight(PHPAGA_PRHGRAPH_GANTT_WIDTH_HEADERBAR_DIVIDER);

    $graph->scale->divider->SetColor(PHPAGA_PRHGRAPH_GANTT_COLOR_HEADERBAR_DIVIDER);
    $graph->scale->dividerh->SetColor(PHPAGA_PRHGRAPH_GANTT_COLOR_HEADERBAR_DIVIDER);

    $graph->scale->SetTableTitleBackground(PHPAGA_PRHGRAPH_GANTT_COLOR_HEADERBAR_BACKGROUND);

    $graph->scale->year->SetFontColor(PHPAGA_PRHGRAPH_GANTT_COLOR_HEADERBAR_TEXT);
    $graph->scale->year->SetBackgroundColor(PHPAGA_PRHGRAPH_GANTT_COLOR_HEADERBAR_BACKGROUND);

    $graph->scale->month->SetFontColor(PHPAGA_PRHGRAPH_GANTT_COLOR_HEADERBAR_TEXT);
    $graph->scale->month->SetBackgroundColor(PHPAGA_PRHGRAPH_GANTT_COLOR_HEADERBAR_BACKGROUND);

    $graph->scale->month->grid->SetColor("#cccccc");
    $graph->scale->month->grid->Show(true);
    $graph->scale->year->grid->SetColor("#444444");
    $graph->scale->year->grid->Show(true);


    $graph->scale->actinfo->SetColTitles(array(_("Project"),
                                               _("Start date"),
                                               _("End date")
                                             ),
                                         array(150, 70,70)
        );

    $graph->scale->actinfo->SetBackgroundColor(PHPAGA_PRHGRAPH_GANTT_COLOR_HEADERBAR_BACKGROUND);
    $graph->scale->actinfo->SetFontColor(PHPAGA_PRHGRAPH_GANTT_COLOR_HEADERBAR_TEXT);
    $graph->scale->actinfo->SetFont(FF_FONT1,FS_NORMAL,10);
    $graph->scale->actinfo->vgrid->SetStyle('solid');
    $graph->scale->actinfo->vgrid->SetColor('gray');

    /* add the single task bars to the chart */

    for ($i = 0; $i < count($data); ++$i)
    {
        if ($data[$i]["status"] == PHPAGA_PROJECTSTATUS_CLOSED)
            $enddate = $data[$i]["enddate"];
        else
            $enddate = "";

        $t_desc = array($data[$i]["prj_title"], $data[$i]["prj_startdate"], $enddate);

        $bar = new GanttBar($i, $t_desc, $data[$i]["prj_startdate"], $data[$i]["enddate"], "", 0.5);

        $bar->SetColor(PHPAGA_PRHGRAPH_GANTT_COLOR_BAR);

        $bar->caption->SetFont(FF_FONT1);

        $bar->title->SetCSIMTarget("project.php?id=".$data[$i]["prj_id"]);
        $bar->title->SetCSIMAlt(phpaga_sanitize_htmlout($data[$i]["prj_title"]));

        $bar->SetCSIMTarget("project.php?id=".$data[$i]["prj_id"]);
        $bar->SetCSIMAlt(phpaga_sanitize_htmlout($data[$i]["prj_title"]));

        switch ($data[$i]["status"])
        {
            case PHPAGA_PROJECTSTATUS_OPEN:
                $bar->SetFillColor(PHPAGA_PRHGRAPH_GANTT_COLOR_OPEN);
                break;

            case PHPAGA_PROJECTSTATUS_OVERDUE:
                $bar->SetFillColor(PHPAGA_PRHGRAPH_GANTT_COLOR_OVERDUE);
                break;

            case PHPAGA_PROJECTSTATUS_CLOSED:
                $bar->SetFillColor(PHPAGA_PRHGRAPH_GANTT_COLOR_CLOSED);
                break;

            default:
                $bar->SetFillColor(PHPAGA_PRHGRAPH_GANTT_COLOR_CLOSED);
                break;
        }

        $graph->Add($bar);
    }

    $graph->StrokeCSIM(basename(__FILE__));

}

?>