2010-05-22 18:53:36 +02:00
< ? php
2018-01-04 13:52:37 +01:00
/* Copyright ( C ) 2010 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2010-05-22 18:53:36 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2010-05-22 18:53:36 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2010-05-22 18:53:36 +02:00
*/
/**
2014-06-14 14:20:58 +02:00
* \file htdocs / projet / ganttchart . inc . php
2010-05-22 18:53:36 +02:00
* \ingroup projet
2011-08-08 18:00:16 +02:00
* \brief Gantt diagram of a project
2010-05-22 18:53:36 +02:00
*/
?>
2013-09-05 20:54:19 +02:00
< div id = " principal_content " style = " margin-left: 0; " >
2015-02-07 03:11:35 +01:00
< div style = " margin-left: 0; position: relative; " class = " gantt " id = " GanttChartDIV " ></ div >
2010-05-22 18:53:36 +02:00
2012-03-09 09:38:31 +01:00
< script type = " text/javascript " >
2010-05-22 18:53:36 +02:00
function DisplayHideRessources ( boxName ) {
graphFormat = g . getFormat ();
if ( boxName . checked == true ) {
booShowRessources = 1 ;
}
else {
booShowRessources = 0 ;
}
reloadGraph ();
}
function DisplayHideDurations ( boxName ) {
graphFormat = g . getFormat ();
if ( boxName . checked == true ) {
booShowDurations = 1 ;
}
else {
booShowDurations = 0 ;
}
reloadGraph ();
}
function DisplayHideComplete ( boxName ) {
graphFormat = g . getFormat ();
if ( boxName . checked == true ) {
booShowComplete = 1 ;
}
else {
booShowComplete = 0 ;
}
reloadGraph ();
}
function selectBarText ( value ) {
graphFormat = g . getFormat ();
id = value . options [ value . selectedIndex ] . value ;
barText = id ;
reloadGraph ();
}
function reloadGraph () {
g . setShowRes ( booShowRessources );
g . setShowComp ( booShowComplete );
g . setShowDur ( booShowDurations );
g . setCaptionType ( barText );
g . setFormat ( graphFormat );
2010-09-06 12:18:31 +02:00
g . Draw ( jQuery ( " #tabs " ) . width () - 40 );
2010-05-22 18:53:36 +02:00
}
2016-07-26 01:59:27 +02:00
//var g = new JSGantt.GanttChart('g', document.getElementById('GanttChartDIV'), 'day');
var g = new JSGantt . GanttChart ( document . getElementById ( 'GanttChartDIV' ), 'day' );
2015-02-07 03:11:35 +01:00
2016-07-26 01:59:27 +02:00
if ( g . getDivId () != null )
//if (g)
2015-02-07 03:11:35 +01:00
{
var booShowRessources = 1 ;
var booShowDurations = 1 ;
var booShowComplete = 1 ;
var barText = " Resource " ;
var graphFormat = " day " ;
2016-07-26 14:41:15 +02:00
g . setDateInputFormat ( '<?php echo $dateformatinput; ?>' ); // Set format of input dates ('mm/dd/yyyy', 'dd/mm/yyyy', does not work with 'yyyy-mm-dd')
2016-07-26 14:45:22 +02:00
g . setDateTaskTableDisplayFormat ( '<?php echo $dateformat; ?>' ); // Format of date used into line
2016-07-26 14:41:15 +02:00
g . setDateTaskDisplayFormat ( '<?php echo $datehourformat; ?>' ); // Format of date used into popup, not into line
2016-07-26 01:59:27 +02:00
g . setDayMajorDateDisplayFormat ( 'dd mon' );
2015-02-07 03:11:35 +01:00
g . setShowRes ( 1 ); // Show/Hide Responsible (0/1)
g . setShowDur ( 1 ); // Show/Hide Duration (0/1)
g . setShowComp ( 1 ); // Show/Hide % Complete(0/1)
g . setShowStartDate ( 1 ); // Show/Hide % Complete(0/1)
g . setShowEndDate ( 1 ); // Show/Hide % Complete(0/1)
2017-10-18 21:24:17 +02:00
g . setShowTaskInfoLink ( 1 );
g . setFormatArr ( " day " , " week " , " month " ) // Set format options (up to 4 : "minute","hour","day","week","month","quarter")
2015-02-07 03:11:35 +01:00
g . setCaptionType ( 'Caption' ); // Set to Show Caption (None,Caption,Resource,Duration,Complete)
2017-10-18 21:24:17 +02:00
g . setUseFade ( 0 );
g . setDayColWidth ( 20 );
2015-02-07 03:11:35 +01:00
/* g.setShowTaskInfoLink(1) */
2020-04-10 10:59:32 +02:00
g . addLang ( '<?php print $langs->getDefaultLang(1); ?>' , vLangs [ '<?php print $langs->getDefaultLang(1); ?>' ]);
g . setLang ( '<?php print $langs->getDefaultLang(1); ?>' );
2015-02-07 03:11:35 +01:00
< ? php
2018-01-04 13:52:37 +01:00
echo " \n " ;
2018-01-04 14:35:02 +01:00
echo " /* g.AddTaskItem(new JSGantt.TaskItem(task_id, 'label', 'start_date', 'end_date', 'css', 'link', milestone, 'Resources', Compl%, Group, Parent, Open, 'Dependency', 'label','note', g)); */ \n " ;
2018-01-04 13:52:37 +01:00
2020-04-10 10:59:32 +02:00
$level = 0 ;
2015-02-07 03:11:35 +01:00
$tnums = count ( $tasks );
2017-10-20 04:04:16 +02:00
$old_project_id = 0 ;
2021-02-26 18:49:22 +01:00
for ( $tcursor = 0 ; $tcursor < $tnums ; $tcursor ++ ) {
2015-02-07 03:11:35 +01:00
$t = $tasks [ $tcursor ];
2017-10-20 04:04:16 +02:00
2021-02-26 18:49:22 +01:00
if ( empty ( $old_project_id ) || $old_project_id != $t [ 'task_project_id' ]) {
2017-10-20 04:04:16 +02:00
// Break on project, create a fictive task for project id $t['task_project_id']
2020-04-10 10:59:32 +02:00
$projecttmp = new Project ( $db );
2017-10-20 04:04:16 +02:00
$projecttmp -> fetch ( $t [ 'task_project_id' ]);
$tmpt = array (
2020-12-15 03:55:46 +01:00
'task_id' => '-' . $t [ 'task_project_id' ],
'task_alternate_id' => '-' . $t [ 'task_project_id' ],
'task_name' => $projecttmp -> ref . ' ' . $projecttmp -> title ,
'task_resources' => '' ,
'task_start_date' => '' ,
'task_end_date' => '' ,
'task_is_group' => 1 , 'task_position' => 0 , 'task_css' => 'ggroupblack' , 'task_milestone' => 0 , 'task_parent' => 0 , 'task_parent_alternate_id' => 0 ,
'task_notes' => '' ,
2018-01-04 19:54:30 +01:00
'task_planned_workload' => 0
2018-01-04 13:52:37 +01:00
);
2017-10-20 04:04:16 +02:00
constructGanttLine ( $tasks , $tmpt , array (), 0 , $t [ 'task_project_id' ]);
$old_project_id = $t [ 'task_project_id' ];
}
2021-02-26 18:49:22 +01:00
if ( $t [ " task_parent " ] <= 0 ) {
2017-10-20 04:04:16 +02:00
constructGanttLine ( $tasks , $t , $task_dependencies , $level , $t [ 'task_project_id' ]);
2020-04-10 10:59:32 +02:00
findChildGanttLine ( $tasks , $t [ " task_id " ], $task_dependencies , $level + 1 );
2015-02-07 03:11:35 +01:00
}
2010-05-22 18:53:36 +02:00
}
2018-01-04 13:52:37 +01:00
echo " \n " ;
2015-02-07 03:11:35 +01:00
?>
2010-09-06 12:18:31 +02:00
g . Draw ( jQuery ( " #tabs " ) . width () - 40 );
2010-05-22 18:53:36 +02:00
setTimeout ( 'g.DrawDependencies()' , 100 );
}
else
{
alert ( " <?php echo $langs->trans ( " FailedToDefinGraph " ); ?> " );
}
2012-03-09 09:38:31 +01:00
</ script >
</ div >
2010-05-22 18:53:36 +02:00
2012-03-09 09:38:31 +01:00
< ? php
/**
* Add a gant chart line
*
2017-10-18 19:13:44 +02:00
* @ param array $tarr Array of all tasks
2016-07-26 21:25:12 +02:00
* @ param array $task Array with properties of one task
2017-10-20 04:04:16 +02:00
* @ param array $task_dependencies Task dependencies ( array ( array ( 0 => idtask , 1 => idtasktofinishfisrt ))
2012-03-09 09:38:31 +01:00
* @ param int $level Level
* @ param int $project_id Id of project
* @ return void
*/
2019-01-27 15:20:16 +01:00
function constructGanttLine ( $tarr , $task , $task_dependencies , $level = 0 , $project_id = null )
2012-03-09 09:38:31 +01:00
{
2018-01-04 19:54:30 +01:00
global $langs ;
2020-03-23 15:54:02 +01:00
global $dateformatinput2 ;
$start_date = $task [ " task_start_date " ];
$end_date = $task [ " task_end_date " ];
2021-02-26 18:49:22 +01:00
if ( ! $end_date ) {
$end_date = $start_date ;
}
2020-03-23 15:54:02 +01:00
$start_date = dol_print_date ( $start_date , $dateformatinput2 );
$end_date = dol_print_date ( $end_date , $dateformatinput2 );
// Resources
$resources = $task [ " task_resources " ];
2020-12-15 03:55:46 +01:00
2020-03-23 15:54:02 +01:00
// Define depend (ex: "", "4,13", ...)
$depend = '' ;
$count = 0 ;
foreach ( $task_dependencies as $value ) {
// Not yet used project_dependencies = array(array(0=>idtask,1=>idtasktofinishfisrt))
if ( $value [ 0 ] == $task [ 'task_id' ]) {
2020-04-10 10:59:32 +02:00
$depend .= ( $count > 0 ? " , " : " " ) . $value [ 1 ];
$count ++ ;
2020-03-23 15:54:02 +01:00
}
}
// $depend .= "\"";
// Define parent
2021-02-26 18:49:22 +01:00
if ( $project_id && $level < 0 ) {
2020-03-23 15:54:02 +01:00
$parent = '-' . $project_id ;
2020-05-21 15:05:19 +02:00
} else {
2020-03-23 15:54:02 +01:00
$parent = $task [ " task_parent_alternate_id " ];
//$parent = $task["task_parent"];
}
// Define percent
2020-04-10 10:59:32 +02:00
$percent = $task [ 'task_percent_complete' ] ? $task [ 'task_percent_complete' ] : 0 ;
2020-03-23 15:54:02 +01:00
// Link (more information)
2021-02-26 18:49:22 +01:00
if ( $task [ " task_id " ] < 0 ) {
2020-03-23 15:54:02 +01:00
//$link=DOL_URL_ROOT.'/projet/tasks.php?withproject=1&id='.abs($task["task_id"]);
2020-04-10 10:59:32 +02:00
$link = '' ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$link = DOL_URL_ROOT . '/projet/tasks/contact.php?withproject=1&id=' . $task [ " task_id " ];
2020-03-23 15:54:02 +01:00
}
// Name
//$name='<a href="'.DOL_URL_ROOT.'/projet/task/tasks.php?id='.$task['task_id'].'">'.$task['task_name'].'</a>';
2020-04-10 10:59:32 +02:00
$name = $task [ 'task_name' ];
2020-03-23 15:54:02 +01:00
/* for ( $i = 0 ; $i < $level ; $i ++ ) {
2021-02-26 18:49:22 +01:00
$name = ' - ' . $name ;
} */
2020-03-23 15:54:02 +01:00
// Add line to gantt
/*
2015-02-07 03:11:35 +01:00
g . AddTaskItem ( new JSGantt . TaskItem ( 1 , 'Define Chart API' , '' , '' , 'ggroupblack' , '' , 0 , 'Brian' , 0 , 1 , 0 , 1 , '' , '' , 'Some Notes text' , g ));
g . AddTaskItem ( new JSGantt . TaskItem ( 11 , 'Chart Object' , '2014-02-20' , '2014-02-20' , 'gmilestone' , '' , 1 , 'Shlomy' , 100 , 0 , 1 , 1 , '' , '' , '' , g ));
</ pre >
< p > Method definition :
< strong > TaskItem ( < em > pID , pName , pStart , pEnd , pColor , pLink , pMile , pRes , pComp , pGroup , pParent , pOpen , pDepend , pCaption , pNotes , pGantt </ em > ) </ strong ></ p >
< dl >
< dt > pID </ dt >< dd > ( required ) a unique numeric ID used to identify each row </ dd >
< dt > pName </ dt >< dd > ( required ) the task Label </ dd >
< dt > pStart </ dt >< dd > ( required ) the task start date , can enter empty date ( '' ) for groups . You can also enter specific time ( 2014 - 02 - 20 12 : 00 ) for additional precision .</ dd >
< dt > pEnd </ dt >< dd > ( required ) the task end date , can enter empty date ( '' ) for groups </ dd >
< dt > pClass </ dt >< dd > ( required ) the css class for this task </ dd >
< dt > pLink </ dt >< dd > ( optional ) any http link to be displayed in tool tip as the " More information " link .</ dd >
< dt > pMile </ dt >< dd > ( optional ) indicates whether this is a milestone task - Numeric ; 1 = milestone , 0 = not milestone </ dd >
< dt > pRes </ dt >< dd > ( optional ) resource name </ dd >
< dt > pComp </ dt >< dd > ( required ) completion percent , numeric </ dd >
< dt > pGroup </ dt >< dd > ( optional ) indicates whether this is a group task ( parent ) - Numeric ; 0 = normal task , 1 = standard group task , 2 = combined group task < a href = '#combinedtasks' class = " footnote " >*</ a ></ dd >
< dt > pParent </ dt >< dd > ( required ) identifies a parent pID , this causes this task to be a child of identified task . Numeric , top level tasks should have pParent set to 0 </ dd >
< dt > pOpen </ dt >< dd > ( required ) indicates whether a standard group task is open when chart is first drawn . Value must be set for all items but is only used by standard group tasks . Numeric , 1 = open , 0 = closed </ dd >
2018-01-17 13:26:57 +01:00
< dt > pDepend </ dt >< dd > ( optional ) comma separated list of id & #39;s this task is dependent on. A line will be drawn from each listed task to this item<br>Each id can optionally be followed by a dependency type suffix. Valid values are:<blockquote>'FS' - Finish to Start (default if suffix is omitted)<br>'SF' - Start to Finish<br>'SS' - Start to Start<br>'FF' - Finish to Finish</blockquote>If present the suffix must be added directly to the id e.g. '123SS'</dd>
2015-02-07 03:11:35 +01:00
< dt > pCaption </ dt >< dd > ( optional ) caption that will be added after task bar if CaptionType set to " Caption " </ dd >
< dt > pNotes </ dt >< dd > ( optional ) Detailed task information that will be displayed in tool tip for this task </ dd >
< dt > pGantt </ dt >< dd > ( required ) javascript JSGantt . GanttChart object from which to take settings . Defaults to & quot ; g & quot ; for backwards compatibility </ dd >
2021-02-26 18:49:22 +01:00
*/
2015-02-07 03:11:35 +01:00
2020-03-23 15:54:02 +01:00
//$note="";
2015-02-07 03:11:35 +01:00
2020-03-23 15:54:02 +01:00
$s = " \n // Add task level = " . $level . " id= " . $task [ " task_id " ] . " parent_id= " . $task [ " task_parent " ] . " aternate_id= " . $task [ " task_alternate_id " ] . " parent_aternate_id= " . $task [ " task_parent_alternate_id " ] . " \n " ;
2017-10-20 04:04:16 +02:00
2020-03-23 15:54:02 +01:00
//$task["task_is_group"]=1; // When task_is_group is 1, content will be autocalculated from sum of all low tasks
2017-10-20 04:04:16 +02:00
2020-03-23 15:54:02 +01:00
// For JSGanttImproved
$css = $task [ 'task_css' ];
$line_is_auto_group = $task [ " task_is_group " ];
//$line_is_auto_group=0;
//if ($line_is_auto_group) $css = 'ggroupblack';
//$dependency = ($depend?$depend:$parent."SS");
$dependency = '' ;
//$name = str_repeat("..", $level).$name;
2017-10-20 04:04:16 +02:00
2020-03-23 15:54:02 +01:00
$taskid = $task [ " task_alternate_id " ];
//$taskid = $task['task_id'];
2018-01-04 13:52:37 +01:00
2020-03-23 15:54:02 +01:00
$note = $task [ 'note' ];
2018-01-04 19:54:30 +01:00
2020-03-23 15:54:02 +01:00
$note = dol_concatdesc ( $note , $langs -> trans ( " Workload " ) . ' : ' . ( $task [ 'task_planned_workload' ] ? convertSecondToTime ( $task [ 'task_planned_workload' ], 'allhourmin' ) : '' ));
2018-01-04 19:54:30 +01:00
2020-04-10 10:59:32 +02:00
$s .= " g.AddTaskItem(new JSGantt.TaskItem(' " . $taskid . " ', ' " . dol_escape_js ( trim ( $name )) . " ', ' " . $start_date . " ', ' " . $end_date . " ', ' " . $css . " ', ' " . $link . " ', " . $task [ 'task_milestone' ] . " , ' " . dol_escape_js ( $resources ) . " ', " . ( $percent >= 0 ? $percent : 0 ) . " , " . $line_is_auto_group . " , ' " . $parent . " ', 1, ' " . $dependency . " ', ' " . ( empty ( $task [ " task_is_group " ]) ? (( $percent >= 0 && $percent != '' ) ? $percent . '%' : '' ) : '' ) . " ', ' " . dol_escape_js ( $note ) . " ', g)); " ;
2020-03-23 15:54:02 +01:00
echo $s ;
2010-05-22 18:53:36 +02:00
}
2012-03-09 09:38:31 +01:00
/**
* Find child Gantt line
*
2017-10-18 19:13:44 +02:00
* @ param array $tarr tarr
2012-03-09 09:38:31 +01:00
* @ param int $parent Parent
2017-10-20 04:04:16 +02:00
* @ param array $task_dependencies Task dependencies
2012-03-09 09:38:31 +01:00
* @ param int $level Level
* @ return void
*/
2017-10-20 04:04:16 +02:00
function findChildGanttLine ( $tarr , $parent , $task_dependencies , $level )
2012-03-09 09:38:31 +01:00
{
2020-04-10 10:59:32 +02:00
$n = count ( $tarr );
2020-03-23 15:54:02 +01:00
$old_parent_id = 0 ;
2021-02-26 18:49:22 +01:00
for ( $x = 0 ; $x < $n ; $x ++ ) {
if ( $tarr [ $x ][ " task_parent " ] == $parent && $tarr [ $x ][ " task_parent " ] != $tarr [ $x ][ " task_id " ]) {
2020-03-23 15:54:02 +01:00
// Create a grouping parent task for the new level
/* if ( empty ( $old_parent_id ) || $old_parent_id != $tarr [ $x ][ 'task_project_id' ])
2017-10-20 04:04:16 +02:00
{
$tmpt = array (
2021-02-26 18:49:22 +01:00
'task_id' => - 98 , 'task_name' => 'Level ' . $level , 'task_resources' => '' , 'task_start_date' => '' , 'task_end_date' => '' ,
'task_is_group' => 1 , 'task_css' => 'ggroupblack' , 'task_milestone' => 0 , 'task_parent' => $tarr [ $x ][ " task_parent " ], 'task_notes' => '' );
constructGanttLine ( $tasks , $tmpt , array (), 0 , $tarr [ $x ][ 'task_project_id' ]);
$old_parent_id = $tarr [ $x ][ 'task_project_id' ];
2017-10-20 04:04:16 +02:00
} */
2020-03-23 15:54:02 +01:00
constructGanttLine ( $tarr , $tarr [ $x ], $task_dependencies , $level , null );
2020-04-10 10:59:32 +02:00
findChildGanttLine ( $tarr , $tarr [ $x ][ " task_id " ], $task_dependencies , $level + 1 );
2020-03-23 15:54:02 +01:00
}
}
2010-05-22 18:53:36 +02:00
}