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