<?php // Gantt example to create CSIM include "../jpgraph.php"; include "../jpgraph_gantt.php"; $bar1 = new GanttBar(0, "Activity 1", "2001-12-21", "2002-01-20"); $bar1->SetCSIMTarget('#', 'Go back 1'); $bar1->title->SetCSIMTarget('#', 'Go back 1 (title)'); $bar2 = new GanttBar(1, "Activity 2", "2002-01-03", "2002-01-25"); $bar2->SetCSIMTarget('#', 'Go back 2'); $bar2->title->SetCSIMTarget('#', 'Go back 2 (title)'); $graph = new GanttGraph(500); $graph->title->Set("Example with image map"); $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HDAY | GANTT_HWEEK); $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY); $graph->scale->week->SetFont(FF_FONT1); $graph->Add(array($bar1, $bar2)); // And stroke $graph->StrokeCSIM(); ?>
$bar->rightMark->SetType(MARK_RIGHTTRIANGLE); $bar->rightMark->SetWidth(3); $bar->rightMark->SetColor('black'); $bar->rightMark->SetFillColor('black'); $bar->leftMark->Show(); $bar->leftMark->SetType(MARK_LEFTTRIANGLE); $bar->leftMark->SetWidth(3); $bar->leftMark->SetColor('black'); $bar->leftMark->SetFillColor('black'); $bar->SetPattern(BAND_SOLID, 'black'); } } //add hyperlinks to the tasks and bars if ($addLinksToGantt == 1) { $bar->title->SetCSIMTarget('./index.php?m=tasks&a=view&task_id=' . $a['task_id'] . '" target="_blank"', 'Click here to see details'); $bar->SetCSIMTarget('./index.php?m=tasks&a=view&task_id=' . $a['task_id'] . '" target="_blank"', 'Click here to see details'); } //adding captions $bar->caption = new TextProperty($caption); $bar->caption->Align('left', 'center'); if ($monospacefont) { $bar->caption->SetFont(FF_DEJAVUMONO, FS_NORMAL, 8); //specify the use of VeraMono } else { $bar->caption->SetFont(FF_DEJAVU, FS_NORMAL, 8); } // show tasks which are both finished and past in (dark)gray if ($progress >= 100 && $end_date->isPast() && get_class($bar) == 'ganttbar') { $bar->caption->SetColor('gray'); $bar->title->SetColor('gray'); $bar->setColor('gray');
function prj_drawProjectTasksGanttBar(&$graph, &$row, &$count, $pid = 0, $nameIndent = '', $tid = 0, $sampleCounting = 0, $sm, $stm) { global $_TABLES, $_CONF, $showMonitor, $showTeamMember, $userid, $_PRJCONF, $filterCSV; $sql = 'SELECT tid,name,start_date, estimated_end_date,parent_task, progress, progress_id '; $sql .= "FROM {$_TABLES['prj_tasks']} "; if ($pid == 0) { $sql .= 'WHERE pid=0 '; } else { $sql .= "WHERE pid='{$pid}' "; } $sql .= "and parent_task={$tid} "; if ($filterCSV != '') { $sql .= "AND {$_TABLES['prj_tasks']}.pid in ({$filterCSV}) "; } $sql .= ' ORDER BY lhs ASC'; $result = DB_query($sql, true); $testnumrows = DB_numRows($result); if ($testnumrows == 0) { //this is to help overcome any COOKIE issues with the filtercsv $sql = 'SELECT tid,name,start_date, estimated_end_date,parent_task, progress, progress_id '; $sql .= "FROM {$_TABLES['prj_tasks']} "; if ($pid == 0) { $sql .= 'WHERE pid=0 '; } else { $sql .= "WHERE pid='{$pid}' "; } $sql .= "and parent_task={$tid} "; $sql .= ' ORDER BY lhs ASC'; $result = DB_query($sql); } for ($j = 0; $j < DB_numrows($result); $j++) { list($tid, $name, $startdate, $enddate, $parent_task, $progress, $status) = DB_fetchArray($result); $permsArray = prj_getProjectPermissions($pid, $userid, $tid); $ownertoken = getTaskToken($tid, $userid, "{$_TABLES['prj_task_users']}", "{$_TABLES['prj_tasks']}"); if ($sm == '1' && $stm == '1') { // all projects if ($permsArray['monitor'] == '1' || $permsArray['teammember'] == '1' || $ownertoken != 0) { $name = html_entity_decode($name); $strdate = strftime("%Y/%m/%d", $startdate); $edate = strftime("%Y/%m/%d", $enddate); $sql = "SELECT c.fullname "; $sql .= "FROM {$_TABLES['prj_task_users']} a "; $sql .= "INNER JOIN {$_TABLES['prj_tasks']} b on a.tid=b.tid "; $sql .= "INNER JOIN {$_TABLES['users']} c on a.uid=c.uid "; $sql .= "WHERE a.role='o' AND a.tid={$tid} "; $result2 = DB_query($sql); list($owner) = DB_fetchArray($result2); $link = $_CONF['site_url'] . "/nexproject/viewproject.php?mode=view&id=" . $tid; $count = $count + 1; if (strlen($name) > $_PRJCONF['project_name_length']) { $name = substr($name, 0, $_PRJCONF['project_name_length']); $name .= "..."; } $name = $nameIndent . $name; if ($strdate == $edate) { $milestone = new Milestone($row, $name, $strdate); $milestone->mark->SetType(MARK_DIAMOND); $graph->Add($milestone); } else { $taskActivity = new GanttBar($count, $name, "{$strdate}", "{$edate}", ""); if ($status == 0) { // Yellow diagonal line pattern on a red background $taskActivity->SetPattern(BAND_RDIAG, "green"); $taskActivity->progress->SetPattern(GANTT_RDIAG, "black"); $taskActivity->progress->SetFillColor("white"); } elseif ($status == 1) { $taskActivity->SetPattern(BAND_RDIAG, "yellow"); $taskActivity->progress->SetPattern(GANTT_RDIAG, "black"); $taskActivity->progress->SetFillColor("white"); } else { $taskActivity->SetPattern(BAND_RDIAG, "red"); $taskActivity->progress->SetPattern(GANTT_RDIAG, "black"); $taskActivity->progress->SetFillColor("white"); } $taskActivity->caption->SetFont(FF_FONT1, FS_NORMAL, 10); $taskActivity->caption->SetColor('black'); $taskActivity->caption->Set($name); // Set absolute height $taskActivity->SetHeight(10); $taskActivity->progress->Set($progress / 100); // Specify progress $taskActivity->SetCSIMTarget("{$link}"); $taskActivity->SetCSIMAlt($progress . "% completed"); $tempval = $_GET['expanded']; $tempval2 = $_SERVER['PHP_SELF']; $taskActivity->title->SetCSIMTarget(""); $taskActivity->title->SetCSIMAlt($progress . "% completed"); $qconstraints = DB_query("SELECT tid FROM {$_TABLES['prj_tasks']} WHERE parent_task='{$tid}' ORDER BY lhs ASC"); $numconstraints = DB_numRows($qconstraints); for ($c = 1; $c <= $numconstraints; $c++) { //$taskActivity->SetConstrain($row+$c,CONSTRAIN_STARTSTART,"maroon4"); } // Add line to Gantt Chart if (!$sampleCounting) { $graph->Add($taskActivity); } } $row++; } } else { // my projects if ($ownertoken != 0) { $name = html_entity_decode($name); $strdate = strftime("%Y/%m/%d", $startdate); $edate = strftime("%Y/%m/%d", $enddate); $sql = "SELECT c.fullname "; $sql .= "FROM {$_TABLES['prj_task_users']} a "; $sql .= "INNER JOIN {$_TABLES['prj_tasks']} b on a.tid=b.tid "; $sql .= "INNER JOIN {$_TABLES['users']} c on a.uid=c.uid "; $sql .= "WHERE a.role='o' AND a.tid={$tid}"; $result2 = DB_query($sql); list($owner) = DB_fetchArray($result2); $link = $_CONF['site_url'] . "/nexproject/viewproject.php?mode=view&id=" . $tid; $count = $count + 1; if (strlen($name) > $_PRJCONF['project_name_length']) { $name = substr($name, 0, $_PRJCONF['project_name_length']); $name .= "..."; } $name = $nameIndent . $name; if ($strdate == $edate) { $milestone = new Milestone($row, $name, $strdate); $milestone->mark->SetType(MARK_DIAMOND); $graph->Add($milestone); } else { $taskActivity = new GanttBar($count, $name, "{$strdate}", "{$edate}", ""); if ($status == 0) { // Yellow diagonal line pattern on a red background $taskActivity->SetPattern(BAND_RDIAG, "green"); $taskActivity->progress->SetPattern(GANTT_RDIAG, "black"); $taskActivity->progress->SetFillColor("white"); } elseif ($status == 1) { $taskActivity->SetPattern(BAND_RDIAG, "yellow"); $taskActivity->progress->SetPattern(GANTT_RDIAG, "black"); $taskActivity->progress->SetFillColor("white"); } else { $taskActivity->SetPattern(BAND_RDIAG, "red"); $taskActivity->progress->SetPattern(GANTT_RDIAG, "black"); $taskActivity->progress->SetFillColor("white"); } $taskActivity->caption->SetFont(FF_FONT1, FS_NORMAL, 10); $taskActivity->caption->SetColor('black'); $taskActivity->caption->Set($name); // Set absolute height $taskActivity->SetHeight(10); $taskActivity->progress->Set($progress / 100); // Specify progress $taskActivity->SetCSIMTarget("{$link}"); $taskActivity->SetCSIMAlt($progress . "% completed"); $tempval = $_GET['expanded']; $tempval2 = $_SERVER['PHP_SELF']; $taskActivity->title->SetCSIMTarget(""); $taskActivity->title->SetCSIMAlt($progress . "% completed"); $qconstraints = DB_query("SELECT tid FROM {$_TABLES['prj_tasks']} WHERE parent_task='{$tid}' ORDER BY lhs ASC"); $numconstraints = DB_numRows($qconstraints); for ($c = 1; $c <= $numconstraints; $c++) { //$taskActivity->SetConstrain($row+$c,CONSTRAIN_STARTSTART,"maroon4"); } // Add line to Gantt Chart if (!$sampleCounting) { $graph->Add($taskActivity); } } $row++; } } if (DB_count($_TABLES['prj_tasks'], 'parent_task', $tid) > 0) { prj_drawProjectTasksGanttBar($graph, $row, $count, $pid, $nameIndent . " ", $tid, $sampleCounting, $sm, $stm); } } //end for }
//put the information in a new array $gantt_data[$id] = $equipment_reservations[$id]['reservations']; } else { $gantt_data[$id][] = array('reservation_idx' => NULL, 'start_date' => '0000-00-00', 'end_date' => '0000-00-00'); } } if ($gantt_data) { foreach ($gantt_data as $id => $item) { foreach ($item as $reservation) { if ($id != $current_id) { //this makes it so that it will only add the item on the same line if it has multiple dates $counter++; $current_id = $id; } $activity = new GanttBar($counter, $id, $reservation['start_date'], $reservation['end_date']); $activity->SetCSIMTarget($GLOBALS['BASE_URL'] . '/admin/reservation/search/id/' . $reservation['reservation_idx'], "Reservation ID: " . $reservation['reservation_idx']); $graph->Add($activity); } } } //DRAW GRAPH $is_rendering_image = (bool) $_GET['_jpg_csimd']; // if jpgraph isn't rendering the image, it is instead rendering the image map. // turn on outputbuffering to capture the html if (!$is_rendering_image) { ob_start(); } //end if // generate the graph (this dumps either the HTML OR the image contents) $graph->StrokeCSIM(); // if jpgraph is not rendering the image, pull the HTML from the buffer and assign to a variable
function prj_drawGanttBar(&$graph, $pid, $tid = 0, &$row, &$count) { global $_TABLES, $_CONF, $_PRJCONF; $sql = "SELECT tid,name,start_date, estimated_end_date,parent_task, progress, progress_id "; $sql .= "FROM {$_TABLES['prj_tasks']} "; if ($tid == 0) { $sql .= "WHERE pid={$pid} AND parent_task=0 ORDER BY lhs ASC"; } else { $sql .= "WHERE parent_task='{$tid}' ORDER BY lhs ASC"; } $result = DB_query($sql); for ($j = 0; $j < DB_numrows($result); $j++) { list($tid, $name, $startdate, $enddate, $parent_task, $progress, $status) = DB_fetchArray($result); $name = html_entity_decode($name); $strdate = strftime("%Y/%m/%d", $startdate); $edate = strftime("%Y/%m/%d", $enddate); $sql = "SELECT fullname FROM {$_TABLES['users']}, {$_TABLES['prj_task_users']} "; $sql .= "WHERE {$_TABLES['prj_task_users']}.tid={$tid} AND {$_TABLES['prj_task_users']}.uid={$_TABLES['users']}.uid"; $result2 = DB_query($sql); list($owner) = DB_fetchArray($result2); $link = $_CONF['site_url'] . "/nexproject/viewproject.php?mode=view&id=" . $tid; $count = $count + 1; //echo "<br>Count:$count, row:$row"; //$constrains[$j]=array($count, $parentcount, "CONSTRAIN_STARTEND"); if (strlen($name) > $_PRJCONF['project_name_length']) { $name = substr($name, 0, $_PRJCONF['project_name_length']); $name .= "..."; } if ($strdate == $edate) { $milestone = new Milestone($row, $name, $strdate); $milestone->mark->SetType(MARK_DIAMOND); $graph->Add($milestone); } else { $activity = new GanttBar($count, "{$name}", "{$strdate}", "{$edate}", "{$owner}"); if ($status == 0) { // Yellow diagonal line pattern on a red background $activity->SetPattern(GANTT_SOLID, "darkgreen"); $activity->progress->SetPattern(GANTT_RDIAG, "black"); $activity->progress->SetFillColor("white"); } elseif ($status == 1) { $activity->SetPattern(GANTT_SOLID, "yellow"); $activity->progress->SetPattern(GANTT_RDIAG, "black"); $activity->progress->SetFillColor("white"); } else { $activity->SetPattern(GANTT_SOLID, "red"); $activity->progress->SetPattern(GANTT_RDIAG, "black"); $activity->progress->SetFillColor("white"); } // Set absolute height $activity->SetHeight(10); $activity->progress->Set($progress / 100); // Specify progress $activity->SetCSIMTarget("{$link}"); $activity->SetCSIMAlt($progress . "% completed"); $activity->title->SetCSIMTarget("{$link}"); $activity->title->SetCSIMAlt($progress . "% completed"); $qconstraints = DB_query("SELECT tid FROM {$_TABLES['prj_tasks']} WHERE parent_task='{$tid}' ORDER BY lhs ASC"); $numconstraints = DB_numRows($qconstraints); for ($c = 1; $c <= $numconstraints; $c++) { $activity->SetConstrain($row + $c, CONSTRAIN_STARTSTART, "maroon4"); } // Add line to Gnatt Chart $graph->Add($activity); } $row++; if (DB_count($_TABLES['prj_tasks'], 'parent_task', $tid) > 0) { prj_drawGanttBar($graph, $pid, $tid, $row, $count); } } }