1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Copyright (C) 2010-2017 Laurent Destailleur <[email protected]> |
4
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
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
|
|
|
|
20
|
|
|
use Dolibarr\Lib\ViewMain; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* \file htdocs/projet/ganttchart.inc.php |
24
|
|
|
* \ingroup projet |
25
|
|
|
* \brief Gantt diagram of a project |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
?> |
29
|
|
|
|
30
|
|
|
<div id="principal_content" style="margin-left: 0;"> |
31
|
|
|
<div style="margin-left: 0; position: relative;" class="gantt" id="GanttChartDIV"></div> |
32
|
|
|
|
33
|
|
|
<script type="text/javascript"> |
34
|
|
|
|
35
|
|
|
function DisplayHideRessources(boxName) { |
36
|
|
|
graphFormat = g.getFormat(); |
37
|
|
|
if (boxName.checked == true) { |
38
|
|
|
booShowRessources = 1; |
39
|
|
|
} else { |
40
|
|
|
booShowRessources = 0; |
41
|
|
|
} |
42
|
|
|
reloadGraph(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function DisplayHideDurations(boxName) { |
46
|
|
|
graphFormat = g.getFormat(); |
47
|
|
|
if (boxName.checked == true) { |
48
|
|
|
booShowDurations = 1; |
49
|
|
|
} else { |
50
|
|
|
booShowDurations = 0; |
51
|
|
|
} |
52
|
|
|
reloadGraph(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
function DisplayHideComplete(boxName) { |
56
|
|
|
graphFormat = g.getFormat(); |
57
|
|
|
if (boxName.checked == true) { |
58
|
|
|
booShowComplete = 1; |
59
|
|
|
} else { |
60
|
|
|
booShowComplete = 0; |
61
|
|
|
} |
62
|
|
|
reloadGraph(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
function selectBarText(value) { |
66
|
|
|
graphFormat = g.getFormat(); |
67
|
|
|
id = value.options[value.selectedIndex].value; |
68
|
|
|
barText = id; |
69
|
|
|
reloadGraph(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
function reloadGraph() { |
73
|
|
|
g.setShowRes(booShowRessources); |
74
|
|
|
g.setShowComp(booShowComplete); |
75
|
|
|
g.setShowDur(booShowDurations); |
76
|
|
|
g.setCaptionType(barText); |
77
|
|
|
g.setFormat(graphFormat); |
78
|
|
|
g.Draw(jQuery("#tabs").width() - 40); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
//var g = new JSGantt.GanttChart('g', document.getElementById('GanttChartDIV'), 'day'); |
83
|
|
|
var g = new JSGantt.GanttChart(document.getElementById('GanttChartDIV'), 'day'); |
84
|
|
|
|
85
|
|
|
if (g.getDivId() != null) |
86
|
|
|
//if (g) |
87
|
|
|
{ |
88
|
|
|
var booShowRessources = 1; |
89
|
|
|
var booShowDurations = 1; |
90
|
|
|
var booShowComplete = 1; |
91
|
|
|
var barText = "Resource"; |
92
|
|
|
var graphFormat = "day"; |
93
|
|
|
|
94
|
|
|
g.setDateInputFormat('<?php echo $dateformatinput; ?>'); // Set format of input dates ('mm/dd/yyyy', 'dd/mm/yyyy', does not work with 'yyyy-mm-dd') |
95
|
|
|
g.setDateTaskTableDisplayFormat('<?php echo $dateformat; ?>'); // Format of date used into line |
96
|
|
|
g.setDateTaskDisplayFormat('<?php echo $datehourformat; ?>'); // Format of date used into popup, not into line |
97
|
|
|
g.setDayMajorDateDisplayFormat('dd mon'); |
98
|
|
|
g.setShowRes(1); // Show/Hide Responsible (0/1) |
99
|
|
|
g.setShowDur(1); // Show/Hide Duration (0/1) |
100
|
|
|
g.setShowComp(1); // Show/Hide % Complete(0/1) |
101
|
|
|
g.setShowStartDate(1); // Show/Hide % Complete(0/1) |
102
|
|
|
g.setShowEndDate(1); // Show/Hide % Complete(0/1) |
103
|
|
|
g.setShowTaskInfoLink(1); |
104
|
|
|
g.setFormatArr("day", "week", "month") // Set format options (up to 4 : "minute","hour","day","week","month","quarter") |
105
|
|
|
g.setCaptionType('Caption'); // Set to Show Caption (None,Caption,Resource,Duration,Complete) |
106
|
|
|
g.setUseFade(0); |
107
|
|
|
g.setDayColWidth(20); |
108
|
|
|
/* g.setShowTaskInfoLink(1) */ |
109
|
|
|
g.addLang('<?php print $langs->getDefaultLang(1); ?>', vLangs['<?php print $langs->getDefaultLang(1); ?>']); |
110
|
|
|
g.setLang('<?php print $langs->getDefaultLang(1); ?>'); |
111
|
|
|
|
112
|
|
|
<?php |
113
|
|
|
|
114
|
|
|
echo "\n"; |
115
|
|
|
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"; |
116
|
|
|
|
117
|
|
|
$level = 0; |
118
|
|
|
$tnums = count($tasks); |
119
|
|
|
$old_project_id = 0; |
120
|
|
|
for ($tcursor = 0; $tcursor < $tnums; $tcursor++) { |
121
|
|
|
$t = $tasks[$tcursor]; |
122
|
|
|
|
123
|
|
|
if (empty($old_project_id) || $old_project_id != $t['task_project_id']) { |
124
|
|
|
// Break on project, create a fictive task for project id $t['task_project_id'] |
125
|
|
|
$projecttmp = new Project($db); |
126
|
|
|
$projecttmp->fetch($t['task_project_id']); |
127
|
|
|
$tmpt = array( |
128
|
|
|
'task_id' => '-' . $t['task_project_id'], |
129
|
|
|
'task_alternate_id' => '-' . $t['task_project_id'], |
130
|
|
|
'task_name' => $projecttmp->ref . ' ' . $projecttmp->title, |
131
|
|
|
'task_resources' => '', |
132
|
|
|
'task_start_date' => '', |
133
|
|
|
'task_end_date' => '', |
134
|
|
|
'task_is_group' => 1, 'task_position' => 0, 'task_css' => 'ggroupblack', 'task_milestone' => 0, 'task_parent' => 0, 'task_parent_alternate_id' => 0, |
135
|
|
|
'task_notes' => '', |
136
|
|
|
'task_planned_workload' => 0 |
137
|
|
|
); |
138
|
|
|
constructGanttLine($tasks, $tmpt, array(), 0, $t['task_project_id']); |
139
|
|
|
$old_project_id = $t['task_project_id']; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
if ($t["task_parent"] <= 0) { |
143
|
|
|
constructGanttLine($tasks, $t, $task_dependencies, $level, $t['task_project_id']); |
144
|
|
|
findChildGanttLine($tasks, $t["task_id"], $task_dependencies, $level + 1); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
echo "\n"; |
149
|
|
|
?> |
150
|
|
|
|
151
|
|
|
g.Draw(jQuery("#tabs").width() - 40); |
152
|
|
|
setTimeout('g.DrawDependencies()', 100); |
153
|
|
|
} else { |
154
|
|
|
alert("<?php echo $langs->trans("FailedToDefinGraph"); ?>"); |
155
|
|
|
} |
156
|
|
|
</script> |
157
|
|
|
</div> |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
<?php |
161
|
|
|
/** |
162
|
|
|
* Add a gant chart line |
163
|
|
|
* |
164
|
|
|
* @param array $tarr Array of all tasks |
165
|
|
|
* @param array $task Array with properties of one task |
166
|
|
|
* @param array $task_dependencies Task dependencies (array(array(0=>idtask,1=>idtasktofinishfisrt)) |
167
|
|
|
* @param int $level Level |
168
|
|
|
* @param int $project_id Id of project |
169
|
|
|
* @return void |
170
|
|
|
*/ |
171
|
|
|
function constructGanttLine($tarr, $task, $task_dependencies, $level = 0, $project_id = null) |
172
|
|
|
{ |
173
|
|
|
global $langs; |
174
|
|
|
global $dateformatinput2; |
175
|
|
|
|
176
|
|
|
$start_date = $task["task_start_date"]; |
177
|
|
|
$end_date = $task["task_end_date"]; |
178
|
|
|
if (!$end_date) { |
179
|
|
|
$end_date = $start_date; |
180
|
|
|
} |
181
|
|
|
$start_date = dol_print_date($start_date, $dateformatinput2); |
182
|
|
|
$end_date = dol_print_date($end_date, $dateformatinput2); |
183
|
|
|
// Resources |
184
|
|
|
$resources = $task["task_resources"]; |
185
|
|
|
|
186
|
|
|
// Define depend (ex: "", "4,13", ...) |
187
|
|
|
$depend = ''; |
188
|
|
|
$count = 0; |
189
|
|
|
foreach ($task_dependencies as $value) { |
190
|
|
|
// Not yet used project_dependencies = array(array(0=>idtask,1=>idtasktofinishfisrt)) |
191
|
|
|
if ($value[0] == $task['task_id']) { |
192
|
|
|
$depend .= ($count > 0 ? "," : "") . $value[1]; |
193
|
|
|
$count++; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
// $depend .= "\""; |
197
|
|
|
// Define parent |
198
|
|
|
if ($project_id && $level < 0) { |
|
|
|
|
199
|
|
|
$parent = '-' . $project_id; |
200
|
|
|
} else { |
201
|
|
|
$parent = $task["task_parent_alternate_id"]; |
202
|
|
|
//$parent = $task["task_parent"]; |
203
|
|
|
} |
204
|
|
|
// Define percent |
205
|
|
|
$percent = empty($task['task_percent_complete']) ? 0 : $task['task_percent_complete']; |
206
|
|
|
// Link (more information) |
207
|
|
|
if ($task["task_id"] < 0) { |
208
|
|
|
//$link=DOL_URL_ROOT.'/projet/tasks.php?withproject=1&id='.abs($task["task_id"]); |
209
|
|
|
$link = ''; |
210
|
|
|
} else { |
211
|
|
|
$link = constant('BASE_URL') . '/projet/tasks/contact.php?withproject=1&id=' . $task["task_id"]; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
// Name |
215
|
|
|
//$name='<a href="'.DOL_URL_ROOT.'/projet/task/tasks.php?id='.$task['task_id'].'">'.$task['task_name'].'</a>'; |
216
|
|
|
$name = $task['task_name']; |
217
|
|
|
|
218
|
|
|
/*for($i=0; $i < $level; $i++) { |
219
|
|
|
$name=' - '.$name; |
220
|
|
|
}*/ |
221
|
|
|
// Add line to gantt |
222
|
|
|
/* |
223
|
|
|
g.AddTaskItem(new JSGantt.TaskItem(1, 'Define Chart API','', '', 'ggroupblack','', 0, 'Brian', 0, 1,0,1,'','','Some Notes text',g)); |
224
|
|
|
g.AddTaskItem(new JSGantt.TaskItem(11,'Chart Object', '2014-02-20','2014-02-20','gmilestone', '', 1, 'Shlomy',100,0,1,1,'','','',g)); |
225
|
|
|
</pre> |
226
|
|
|
<p>Method definition: |
227
|
|
|
<strong>TaskItem(<em>pID, pName, pStart, pEnd, pColor, pLink, pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption, pNotes, pGantt</em>)</strong></p> |
228
|
|
|
<dl> |
229
|
|
|
<dt>pID</dt><dd>(required) a unique numeric ID used to identify each row</dd> |
230
|
|
|
<dt>pName</dt><dd>(required) the task Label</dd> |
231
|
|
|
<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> |
232
|
|
|
<dt>pEnd</dt><dd>(required) the task end date, can enter empty date ('') for groups</dd> |
233
|
|
|
<dt>pClass</dt><dd>(required) the css class for this task</dd> |
234
|
|
|
<dt>pLink</dt><dd>(optional) any http link to be displayed in tool tip as the "More information" link.</dd> |
235
|
|
|
<dt>pMile</dt><dd>(optional) indicates whether this is a milestone task - Numeric; 1 = milestone, 0 = not milestone</dd> |
236
|
|
|
<dt>press</dt><dd>(optional) resource name</dd> |
237
|
|
|
<dt>pComp</dt><dd>(required) completion percent, numeric</dd> |
238
|
|
|
<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> |
239
|
|
|
<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> |
240
|
|
|
<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> |
241
|
|
|
<dt>pDepend</dt><dd>(optional) comma separated list of id'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> |
242
|
|
|
<dt>pCaption</dt><dd>(optional) caption that will be added after task bar if CaptionType set to "Caption"</dd> |
243
|
|
|
<dt>pNotes</dt><dd>(optional) Detailed task information that will be displayed in tool tip for this task</dd> |
244
|
|
|
<dt>pGantt</dt><dd>(required) javascript JSGantt.GanttChart object from which to take settings. Defaults to "g" for backwards compatibility</dd> |
245
|
|
|
*/ |
246
|
|
|
|
247
|
|
|
//$note=""; |
248
|
|
|
|
249
|
|
|
$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"; |
250
|
|
|
|
251
|
|
|
//$task["task_is_group"]=1; // When task_is_group is 1, content will be autocalculated from sum of all low tasks |
252
|
|
|
|
253
|
|
|
// For JSGanttImproved |
254
|
|
|
$css = $task['task_css']; |
255
|
|
|
$line_is_auto_group = $task["task_is_group"]; |
256
|
|
|
//$line_is_auto_group=0; |
257
|
|
|
//if ($line_is_auto_group) $css = 'ggroupblack'; |
258
|
|
|
//$dependency = ($depend?$depend:$parent."SS"); |
259
|
|
|
$dependency = ''; |
260
|
|
|
//$name = str_repeat("..", $level).$name; |
261
|
|
|
|
262
|
|
|
$taskid = $task["task_alternate_id"]; |
263
|
|
|
//$taskid = $task['task_id']; |
264
|
|
|
|
265
|
|
|
$note = empty($task['note']) ? '' : $task['note']; |
266
|
|
|
|
267
|
|
|
$note = dol_concatdesc($note, $langs->trans("Workload") . ' : ' . (empty($task['task_planned_workload']) ? '' : convertSecondToTime($task['task_planned_workload'], 'allhourmin'))); |
268
|
|
|
|
269
|
|
|
$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));"; |
270
|
|
|
echo $s; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Find child Gantt line |
275
|
|
|
* |
276
|
|
|
* @param array $tarr tarr |
277
|
|
|
* @param int $parent Parent |
278
|
|
|
* @param array $task_dependencies Task dependencies |
279
|
|
|
* @param int $level Level |
280
|
|
|
* @return void |
281
|
|
|
*/ |
282
|
|
|
function findChildGanttLine($tarr, $parent, $task_dependencies, $level) |
283
|
|
|
{ |
284
|
|
|
$n = count($tarr); |
285
|
|
|
|
286
|
|
|
$old_parent_id = 0; |
287
|
|
|
for ($x = 0; $x < $n; $x++) { |
288
|
|
|
if ($tarr[$x]["task_parent"] == $parent && $tarr[$x]["task_parent"] != $tarr[$x]["task_id"]) { |
289
|
|
|
// Create a grouping parent task for the new level |
290
|
|
|
/*if (empty($old_parent_id) || $old_parent_id != $tarr[$x]['task_project_id']) |
291
|
|
|
{ |
292
|
|
|
$tmpt = array( |
293
|
|
|
'task_id'=> -98, 'task_name'=>'Level '.$level, 'task_resources'=>'', 'task_start_date'=>'', 'task_end_date'=>'', |
294
|
|
|
'task_is_group'=>1, 'task_css'=>'ggroupblack', 'task_milestone'=> 0, 'task_parent'=>$tarr[$x]["task_parent"], 'task_notes'=>''); |
295
|
|
|
constructGanttLine($tasks, $tmpt, array(), 0, $tarr[$x]['task_project_id']); |
296
|
|
|
$old_parent_id = $tarr[$x]['task_project_id']; |
297
|
|
|
}*/ |
298
|
|
|
|
299
|
|
|
constructGanttLine($tarr, $tarr[$x], $task_dependencies, $level, null); |
300
|
|
|
findChildGanttLine($tarr, $tarr[$x]["task_id"], $task_dependencies, $level + 1); |
301
|
|
|
} |
302
|
|
|
} |
303
|
|
|
} |
304
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: