<?php 
/* $Id: mygantt.php,v 1.10 2003/10/27 16:05:00 k-fish Exp $ */

$myEnv["module"] = "tts";
$myEnv["output"] = "html";

//error_reporting(0); //comment it to debug

include("../../config.inc.php");
include(INCLUDEPATH . "container.inc.php");

// graph library
define('CACHE_DIR',CACHE_FOLDER); // for jpgraph.php itself!
include (INCLUDEPATH . "jpgraph/jpgraph.php");
include (INCLUDEPATH . "jpgraph/jpgraph_gantt.php");

// A new graph with automatic size 
$graph = new GanttGraph(0, 0, 'auto'); 

$graph->title->Set(Lang::getLanguageString("historictitle")." ".isset($_GET["id"])?(int) $_GET["id"]:0);
$graph->ShowHeaders(GANTT_HDAY | GANTT_HWEEK | GANTT_HMONTH); 

$graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY);
$graph->scale->week->SetFont(FF_FONT0);
$graph->scale->month->SetStyle(MONTHSTYLE_SHORTNAMEYEAR4); 
$graph->scale->month->SetFontColor("white"); 
$graph->scale->month->SetBackgroundColor("blue"); 

if(empty($_GET["id"])){
    $graph->Stroke(); 
    exit();
}

// get projects
/*
$sql = "SELECT a.*, b.name1, c.lastname as clastname, d.lastname as klastname
			FROM mgw_projects a 
			left join mgw_companies b on a.companyid=b.id
			left join mgw_contacts c on a.contactid = c.id
			left join mgw_users d on a.keyaccountid = d.id";
*/

$sql="SELECT * FROM mgw_tts_history h, mgw_users u WHERE h.id_tts=".(isset($_GET["id"])?(int) $_GET["id"]:0)." AND h.id_owner=u.id ORDER BY h.lu_date";
     
if(!$res = $conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
$o = 0;

// define color toggle array
$mycolor[0] = "yellow";
$mycolor[1] = "green";
$mycolor[2] = "blue";
$mycolor[3] = "red";

if($res->NumRows() == 0){
    $graph->Stroke(); 
    exit();
}
while($row = $res->FetchRow()){
    //$varname = "activity$o";

    //  A new activity on row '0' 
    //    print_r($res->UserTimeStamp($row["start_date"],"Y-m-d"));echo "\n";
    if(strcmp($row["end_date"],"00000000000000")!=0) {//a modifier
        
	$varname = new GanttBar($o,$row["username"],$res->UserTimeStamp($row["start_date"],"Y-m-d"),$res->UserTimeStamp($row["end_date"],"Y-m-d")); 
	$varname->SetPattern(BAND_RDIAG,$mycolor[$row["state"]]); 
	$varname->SetFillColor($mycolor[$row["state"]]);
    }
    else{
	$varname = new GanttBar($o,$row["username"],$res->UserTimeStamp($row["start_date"],"Y-m-d"),date("Y-m-d",time())); 
	$varname->SetPattern(BAND_RDIAG,$mycolor[$row["state"]]); 
	$varname->SetFillColor($mycolor[$row["state"]]); 
    }

/*
	if($row[enddate]!="0000-00-00") {
		$varname = "activity$o";
		$$varname = new GanttBar($o,$row[name],$row[startdate],$row[enddate]); 
		$$varname->SetPattern(BAND_RDIAG,"yellow"); 
		$$varname->SetFillColor($mycolor[$i]); 
		$graph->Add($$varname); 
		$o++;
	}
*/
    $graph->Add($varname); 
    $o++;
}

// Display the Gantt chart 
$graph->Stroke(); 

?> 
