dolibarr 24.0.0-beta
ganttchart.inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2010-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
34'
35@phan-var-force string $dateformatinput
36@phan-var-force string $dateformat
37@phan-var-force string $datehourformat
38@phan-var-force array<int,array{task_id:int,task_alternate_id:int,task_project_id:int,task_parent:int,task_is_group:int<0,1>,task_css:string,task_position:int,task_planned_workload:int,task_milestone:int,task_percent_complete:float,task_name:string,task_start_date:int,task_end_date:int,task_color:string,task_resources:string,note:string,task_parent_alternate_id:int}> $tasks
39@phan-var-force array{} $task_dependencies
40';
41?>
42
43<!-- ganttchart.inc.php::begin -->
44<div id="principal_content" style="margin-left: 0;">
45 <div style="margin-left: 0; position: relative;" class="gantt" id="GanttChartDIV"></div>
46
47 <script type="text/javascript">
48
49function DisplayHideRessources(boxName) {
50 graphFormat = g.getFormat();
51 if(boxName.checked == true) {
52 booShowRessources = 1;
53 }
54 else {
55 booShowRessources = 0;
56 }
57 reloadGraph();
58}
59
60function DisplayHideDurations(boxName) {
61 graphFormat = g.getFormat();
62 if(boxName.checked == true) {
63 booShowDurations = 1;
64 }
65 else {
66 booShowDurations = 0;
67 }
68 reloadGraph();
69}
70
71function DisplayHideComplete(boxName) {
72 graphFormat = g.getFormat();
73 if(boxName.checked == true) {
74 booShowComplete = 1;
75 }
76 else {
77 booShowComplete = 0;
78 }
79 reloadGraph();
80}
81
82function selectBarText(value) {
83 graphFormat = g.getFormat();
84 id=value.options[value.selectedIndex].value;
85 barText = id;
86 reloadGraph();
87}
88
89function reloadGraph() {
90 g.setShowRes(booShowRessources);
91 g.setShowComp(booShowComplete);
92 g.setShowDur(booShowDurations);
93 g.setCaptionType(barText);
94 g.setFormat(graphFormat);
95 g.Draw(jQuery("#tabs").width()-40);
96}
97
98
99//var g = new JSGantt.GanttChart('g', document.getElementById('GanttChartDIV'), 'day');
100var g = new JSGantt.GanttChart(document.getElementById('GanttChartDIV'), 'day');
101
102if (g.getDivId() != null)
103//if (g)
104{
105 var booShowRessources = 1;
106 var booShowDurations = 1;
107 var booShowComplete = 1;
108 var barText = "Resource";
109 var graphFormat = "day";
110
111 g.setDateInputFormat('<?php echo $dateformatinput; ?>'); // Set format of input dates ('mm/dd/yyyy', 'dd/mm/yyyy', does not work with 'yyyy-mm-dd')
112 g.setDateTaskTableDisplayFormat('<?php echo $dateformat; ?>'); // Format of date used into line
113 g.setDateTaskDisplayFormat('<?php echo $datehourformat; ?>'); // Format of date used into popup, not into line
114 g.setDayMajorDateDisplayFormat('dd mon');
115 g.setShowRes(1); // Show/Hide Responsible (0/1)
116 g.setShowDur(1); // Show/Hide Duration (0/1)
117 g.setShowComp(1); // Show/Hide % Complete(0/1)
118 g.setShowStartDate(1); // Show/Hide % Complete(0/1)
119 g.setShowEndDate(1); // Show/Hide % Complete(0/1)
120 g.setShowTaskInfoLink(1);
121 g.setFormatArr("day","week","month") // Set format options (up to 4 : "minute","hour","day","week","month","quarter")
122 g.setCaptionType('Caption'); // Set to Show Caption (None,Caption,Resource,Duration,Complete)
123 g.setUseFade(0);
124 g.setDayColWidth(20);
125 /* g.setShowTaskInfoLink(1) */
126 g.addLang('<?php print $langs->getDefaultLang(1); ?>', vLangs['<?php print $langs->getDefaultLang(1); ?>']);
127 g.setLang('<?php print $langs->getDefaultLang(1); ?>');
128
129 <?php
130
131 echo "\n";
132 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";
133
134 $level = 0;
135 $tnums = count($tasks);
136 $old_project_id = 0;
137 for ($tcursor = 0; $tcursor < $tnums; $tcursor++) {
138 $t = $tasks[$tcursor];
139
140 if (empty($old_project_id) || $old_project_id != $t['task_project_id']) {
141 // Break on project, create a fictive task for project id $t['task_project_id']
142 $projecttmp = new Project($db);
143 $projecttmp->fetch($t['task_project_id']);
144 $tmpt = array(
145 'task_id' => (int) -$t['task_project_id'],
146 'task_alternate_id' => (int) -$t['task_project_id'],
147 'task_name' => $projecttmp->ref.' '.$projecttmp->title,
148 'task_resources' => '',
149 'task_start_date' => $projecttmp->date_start,
150 'task_end_date' => (!empty($projecttmp->date_end) ? $projecttmp->date_end : 0),
151 'task_is_group' => 1, 'task_position' => 0, 'task_css' => 'ggroupblack', 'task_milestone' => 0, 'task_parent' => 0, 'task_parent_alternate_id' => 0,
152 'note' => '',
153 'task_planned_workload' => 0
154 );
155 constructGanttLine($tasks, $tmpt, array(), 0, $t['task_project_id']);
156 $old_project_id = $t['task_project_id'];
157 }
158
159 if ($t["task_parent"] <= 0) {
160 constructGanttLine($tasks, $t, $task_dependencies, $level, $t['task_project_id']);
161 findChildGanttLine($tasks, $t["task_id"], $task_dependencies, $level + 1);
162 }
163 }
164
165 echo "\n";
166 ?>
167
168 g.Draw(jQuery("#tabs").width()-40);
169 setTimeout('g.DrawDependencies()',100);
170}
171else
172{
173 alert("<?php echo $langs->trans("FailedToDefinGraph"); ?>");
174}
175</script>
176</div>
177<!-- ganttchart.inc.php::end -->
178
179
180
181<?php
192function constructGanttLine($tarr, $task, $task_dependencies, $level = 0, $project_id = null)
193{
194 global $langs, $db;
195 global $dateformatinput2;
196 $projectstatic = new Project($db);
197 $taskstatic = new Task($db);
198
199
200 $start_date = $task["task_start_date"];
201 $end_date = $task["task_end_date"];
202 if (!$end_date) {
203 $end_date = $start_date;
204 }
205 $start_date = dol_print_date($start_date, $dateformatinput2);
206 $end_date = dol_print_date($end_date, $dateformatinput2);
207 // Resources
208 $resources = $task["task_resources"];
209
210 // Define depend (ex: "", "4,13", ...)
211 $depend = '';
212 $count = 0;
213 foreach ($task_dependencies as $value) {
214 // Not yet used project_dependencies = array(array(0=>idtask,1=>idtasktofinishfisrt))
215 if ($value[0] == $task['task_id']) {
216 $depend .= ($count > 0 ? "," : "").$value[1];
217 $count++;
218 }
219 }
220 // $depend .= "\"";
221 // Define parent
222 if ($project_id && $level < 0) {
223 $parent = '-'.$project_id;
224 } else {
225 $parent = $task["task_parent_alternate_id"];
226 //$parent = $task["task_parent"];
227 }
228 // Define percent
229 $percent = empty($task['task_percent_complete']) ? 0 : $task['task_percent_complete'];
230
231 // Link and name (more information)
232 if ($task["task_id"] < 0) {
233 $link=DOL_URL_ROOT.'/projet/card.php?id='.abs($task["task_id"]);
234 $fetchresult = $projectstatic->fetch(abs($task["task_id"]));
235 if ($fetchresult > 0) {
236 $tmpname = $projectstatic->getNomUrl(0, 'withproject', 1);
237 $name = '<span style="font-size: 1.2em; font-weight: bold;">' . $tmpname . '</span>';
238 } else {
239 $name = $task['task_name'];
240 }
241 //$name = $task['task_name'];
242 } else {
243 $link = DOL_URL_ROOT.'/projet/tasks/contact.php?withproject=1&id='.$task["task_id"];
244 $fetchresult = $taskstatic->fetch($task["task_id"]);
245 if ($fetchresult > 0) {
246 $name = $taskstatic->getNomUrl(0, 'withproject', 'task', 1);
247 } else {
248 $name = $task['task_name'];
249 }
250 //$name = $task['task_name'];
251 }
252
253 // Add line to gantt
254 /*
255 g.AddTaskItem(new JSGantt.TaskItem(1, 'Define Chart API','', '', 'ggroupblack','', 0, 'Brian', 0, 1,0,1,'','','Some Notes text',g));
256 g.AddTaskItem(new JSGantt.TaskItem(11,'Chart Object', '2014-02-20','2014-02-20','gmilestone', '', 1, 'Shlomy',100,0,1,1,'','','',g));
257 </pre>
258 <p>Method definition:
259 <strong>TaskItem(<em>pID, pName, pStart, pEnd, pColor, pLink, pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption, pNotes, pGantt</em>)</strong></p>
260 <dl>
261 <dt>pID</dt><dd>(required) a unique numeric ID used to identify each row</dd>
262 <dt>pName</dt><dd>(required) the task Label</dd>
263 <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>
264 <dt>pEnd</dt><dd>(required) the task end date, can enter empty date ('') for groups</dd>
265 <dt>pClass</dt><dd>(required) the css class for this task</dd>
266 <dt>pLink</dt><dd>(optional) any http link to be displayed in tool tip as the "More information" link.</dd>
267 <dt>pMile</dt><dd>(optional) indicates whether this is a milestone task - Numeric; 1 = milestone, 0 = not milestone</dd>
268 <dt>press</dt><dd>(optional) resource name</dd>
269 <dt>pComp</dt><dd>(required) completion percent, numeric</dd>
270 <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>
271 <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>
272 <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>
273 <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>
274 <dt>pCaption</dt><dd>(optional) caption that will be added after task bar if CaptionType set to "Caption"</dd>
275 <dt>pNotes</dt><dd>(optional) Detailed task information that will be displayed in tool tip for this task</dd>
276 <dt>pGantt</dt><dd>(required) javascript JSGantt.GanttChart object from which to take settings. Defaults to &quot;g&quot; for backwards compatibility</dd>
277 */
278
279 //$note="";
280
281 $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";
282
283 //$task["task_is_group"]=1; // When task_is_group is 1, content will be autocalculated from sum of all low tasks
284
285 // For JSGanttImproved
286 $css = $task['task_css'];
287 $line_is_auto_group = $task["task_is_group"];
288 //$line_is_auto_group=0;
289 //if ($line_is_auto_group) $css = 'ggroupblack';
290 //$dependency = ($depend?$depend:$parent."SS");
291 $dependency = '';
292 //$name = str_repeat("..", $level).$name;
293
294 $taskid = $task["task_alternate_id"];
295 //$taskid = $task['task_id'];
296
297 $note = empty($task['note']) ? '' : $task['note'];
298
299 $note = dol_concatdesc($note, $langs->trans("Workload").' : '.(empty($task['task_planned_workload']) ? '' : convertSecondToTime($task['task_planned_workload'], 'allhourmin')));
300
301 $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));";
302 echo $s;
303}
304
314function findChildGanttLine($tarr, $parent, $task_dependencies, $level)
315{
316 $n = count($tarr);
317
318 $old_parent_id = 0;
319 for ($x = 0; $x < $n; $x++) {
320 if ($tarr[$x]["task_parent"] == $parent && $tarr[$x]["task_parent"] != $tarr[$x]["task_id"]) {
321 // Create a grouping parent task for the new level
322 /*if (empty($old_parent_id) || $old_parent_id != $tarr[$x]['task_project_id'])
323 {
324 $tmpt = array(
325 'task_id'=> -98, 'task_name'=>'Level '.$level, 'task_resources'=>'', 'task_start_date'=>'', 'task_end_date'=>'',
326 'task_is_group'=>1, 'task_css'=>'ggroupblack', 'task_milestone'=> 0, 'task_parent'=>$tarr[$x]["task_parent"], 'note'=>'');
327 constructGanttLine($tasks, $tmpt, array(), 0, $tarr[$x]['task_project_id']);
328 $old_parent_id = $tarr[$x]['task_project_id'];
329 }*/
330
331 constructGanttLine($tarr, $tarr[$x], $task_dependencies, $level, 0);
332 findChildGanttLine($tarr, $tarr[$x]["task_id"], $task_dependencies, $level + 1);
333 }
334 }
335}
Class to manage projects.
Class to manage tasks.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition date.lib.php:248
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
findChildGanttLine($tarr, $parent, $task_dependencies, $level)
Find child Gantt line.
constructGanttLine($tarr, $task, $task_dependencies, $level=0, $project_id=null)
Add a gantt chart line.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130