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