3 * Project Management Facility
5 * Copyright 2010, FusionForge Team
6 * http://fusionforge.org
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 if (!file_exists(forge_get_config('jpgraph_path').'/jpgraph.php')) {
25 exit_error(_('Package JPGraph not installed'),'pm');
28 require_once(forge_get_config('jpgraph_path').'/jpgraph.php');
29 require_once(forge_get_config('jpgraph_path').'/jpgraph_gantt.php');
30 require_once $gfcommon.'pm/ProjectTaskFactory.class.php';
31 require_once $gfwww.'include/unicode.php';
33 $ptf = new ProjectTaskFactory($pg);
34 if (!$ptf || !is_object($ptf)) {
35 exit_error(_('Could Not Get ProjectTaskFactory'),'pm');
36 } elseif ($ptf->isError()) {
37 exit_error(_('Error getting PTF: ').$ptf->getErrorMessage(),'pm');
40 $offset = getIntFromRequest('offset');
41 $_assigned_to = getIntFromRequest('_assigned_to');
42 $_status = getIntFromRequest('_status');
43 $_order = getStringFromRequest('_order');
44 $_resolution = getStringFromRequest('_resolution');
45 $_category_id = getIntFromRequest('_category_id');
46 $_size = getIntFromRequest('_size');
47 $max_rows = getIntFromRequest('max_rows',50);
49 $ptf->setup($offset,$_order,$max_rows,'custom',$_assigned_to,$_status,$_category_id);
50 if ($ptf->isError()) {
51 exit_error(_('Error in PTF: ').$ptf->getErrorMessage(),'pm');
54 $pt_arr =& $ptf->getTasks();
55 if ($ptf->isError()) {
56 exit_error($ptf->getErrorMessage(),'pm');
60 $graph = new GanttGraph (640,480, "auto");
61 } elseif ($_size==1024) {
62 $graph = new GanttGraph (1024,768, "auto");
63 } elseif ($_size==1600) {
64 $graph = new GanttGraph (1600,1200, "auto");
66 $graph = new GanttGraph (800,600, "auto");
69 //$graph->SetShadow();
70 $graph->SetMargin(10,10,25,10);
72 // Add title and subtitle
73 $graph->title->Set($pg->getName());
75 if (isset($gantt_title_font_family)) {
76 $graph->title->SetFont( constant($gantt_title_font_family),
77 constant($gantt_title_font_style), $gantt_title_font_size);
80 //$graph->subtitle-> Set("(Draft version)");
82 // Show day, week and month scale
83 if ($_resolution == 'Days') {
84 $graph->ShowHeaders( GANTT_HDAY | GANTT_HWEEK | GANTT_HMONTH);
85 } elseif ($_resolution == 'Weeks') {
86 $graph->ShowHeaders( GANTT_HWEEK | GANTT_HMONTH);
87 } elseif ($_resolution == 'Months') {
88 $graph->ShowHeaders( GANTT_HMONTH | GANTT_HYEAR);
90 $graph->ShowHeaders( GANTT_HYEAR);
93 // Instead of week number show the date for the first day in the week
95 $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY);
97 // Make the week scale font smaller than the default
98 if (isset($gantt_title_font_family)) {
99 $graph->scale->week->SetFont( constant($gantt_title_font_family), FS_NORMAL, 9);
100 $graph->scale->month->SetFont( constant($gantt_title_font_family), FS_NORMAL, 9);
103 // Use the short name of the month together with a 2 digit year
104 // on the month scale
105 $graph->scale->month->SetStyle( MONTHSTYLE_SHORTNAME);
107 $rows=count($pt_arr);
109 for ($i=0; $i<$rows; $i++) {
110 // Format the bar for the first activity
111 // ($row,$title,$startdate,$enddate)
112 $activity[$i] = new GanttBar ($i, convert_unicode($pt_arr[$i]->getSummary()), date('Y-m-d',$pt_arr[$i]->getStartDate()), date('Y-m-d',$pt_arr[$i]->getEndDate()-86400));
114 // Yellow diagonal line pattern on a red background
115 $activity[$i]->SetPattern(BAND_RDIAG, "yellow");
116 $activity[$i]->SetFillColor ("red");
117 $activity[$i]->progress->Set( (( $pt_arr[$i]->getPercentComplete() ) ? ($pt_arr[$i]->getPercentComplete()/100) : 0));
118 $activity[$i]->progress->SetPattern(BAND_RDIAG, "blue");
120 if (isset($gantt_task_font_family)) {
121 $activity[$i]->title->SetFont( constant($gantt_task_font_family),
122 constant($gantt_task_font_style), $gantt_task_font_size);
125 // Finally add the bar to the graph
126 $graph->Add( $activity[$i] );
130 $todayline = new GanttVLine(date('Y-m-d',time()),"Today");
131 $todayline ->SetDayOffset (0.5);
132 $graph->Add( $todayline);
134 // Display the Gantt chart