dolibarr  17.0.4
project.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
6  * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  * or see https://www.gnu.org/
21  */
22 
28 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
29 
30 
38 function project_prepare_head(Project $project, $moreparam = '')
39 {
40  global $db, $langs, $conf, $user;
41 
42  $h = 0;
43  $head = array();
44 
45  $head[$h][0] = DOL_URL_ROOT.'/projet/card.php?id='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
46  $head[$h][1] = $langs->trans("Project");
47  $head[$h][2] = 'project';
48  $h++;
49  $nbContacts = 0;
50  // Enable caching of project count Contacts
51  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
52  $cachekey = 'count_contacts_project_'.$project->id;
53  $dataretrieved = dol_getcache($cachekey);
54 
55  if (!is_null($dataretrieved)) {
56  $nbContacts = $dataretrieved;
57  } else {
58  $nbContacts = count($project->liste_contact(-1, 'internal')) + count($project->liste_contact(-1, 'external'));
59  dol_setcache($cachekey, $nbContacts, 120); // If setting cache fails, this is not a problem, so we do not test result.
60  }
61  $head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
62  $head[$h][1] = $langs->trans("ProjectContact");
63  if ($nbContacts > 0) {
64  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContacts.'</span>';
65  }
66  $head[$h][2] = 'contact';
67  $h++;
68 
69  if (empty($conf->global->PROJECT_HIDE_TASKS)) {
70  // Then tab for sub level of projet, i mean tasks
71  $nbTasks = 0;
72  // Enable caching of project count Tasks
73  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
74  $cachekey = 'count_tasks_project_'.$project->id;
75  $dataretrieved = dol_getcache($cachekey);
76 
77  if (!is_null($dataretrieved)) {
78  $nbTasks = $dataretrieved;
79  } else {
80  require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
81  $taskstatic = new Task($db);
82  $nbTasks = count($taskstatic->getTasksArray(0, 0, $project->id, 0, 0));
83  dol_setcache($cachekey, $nbTasks, 120); // If setting cache fails, this is not a problem, so we do not test result.
84  }
85  $head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
86  $head[$h][1] = $langs->trans("Tasks");
87  if ($nbTasks > 0) {
88  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbTasks).'</span>';
89  }
90  $head[$h][2] = 'tasks';
91  $h++;
92 
93  $nbTimeSpent = 0;
94  // Enable caching of project count Timespent
95  $cachekey = 'count_timespent_project_'.$project->id;
96  $dataretrieved = dol_getcache($cachekey);
97  if (!is_null($dataretrieved)) {
98  $nbTimeSpent = $dataretrieved;
99  } else {
100  $sql = "SELECT t.rowid";
101  //$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
102  //$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
103  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt";
104  $sql .= " WHERE t.fk_task = pt.rowid";
105  $sql .= " AND pt.fk_projet =".((int) $project->id);
106  $resql = $db->query($sql);
107  if ($resql) {
108  $obj = $db->fetch_object($resql);
109  if ($obj) {
110  $nbTimeSpent = 1;
111  dol_setcache($cachekey, $nbTimeSpent, 120); // If setting cache fails, this is not a problem, so we do not test result.
112  }
113  } else {
114  dol_print_error($db);
115  }
116  }
117 
118  $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?withproject=1&projectid='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
119  $head[$h][1] = $langs->trans("TimeSpent");
120  if ($nbTimeSpent > 0) {
121  $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
122  }
123  $head[$h][2] = 'timespent';
124  $h++;
125  }
126 
127  if (((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))
128  || isModEnabled("propal") || isModEnabled('commande')
129  || isModEnabled('facture') || isModEnabled('contrat')
130  || isModEnabled('ficheinter') || isModEnabled('agenda') || isModEnabled('deplacement') || isModEnabled('stock')) {
131  $nbElements = 0;
132  // Enable caching of thirdrparty count Contacts
133  $cachekey = 'count_elements_project_'.$project->id;
134  $dataretrieved = dol_getcache($cachekey);
135  if (!is_null($dataretrieved)) {
136  $nbElements = $dataretrieved;
137  } else {
138  if (isModEnabled('stock')) {
139  $nbElements += $project->getElementCount('stock', 'entrepot', 'fk_project');
140  }
141  if (isModEnabled("propal")) {
142  $nbElements += $project->getElementCount('propal', 'propal');
143  }
144  if (isModEnabled('commande')) {
145  $nbElements += $project->getElementCount('order', 'commande');
146  }
147  if (isModEnabled('facture')) {
148  $nbElements += $project->getElementCount('invoice', 'facture');
149  }
150  if (isModEnabled('facture')) {
151  $nbElements += $project->getElementCount('invoice_predefined', 'facture_rec');
152  }
153  if (isModEnabled('supplier_proposal')) {
154  $nbElements += $project->getElementCount('proposal_supplier', 'supplier_proposal');
155  }
156  if (isModEnabled("supplier_order")) {
157  $nbElements += $project->getElementCount('order_supplier', 'commande_fournisseur');
158  }
159  if (isModEnabled("supplier_invoice")) {
160  $nbElements += $project->getElementCount('invoice_supplier', 'facture_fourn');
161  }
162  if (isModEnabled('contrat')) {
163  $nbElements += $project->getElementCount('contract', 'contrat');
164  }
165  if (isModEnabled('ficheinter')) {
166  $nbElements += $project->getElementCount('intervention', 'fichinter');
167  }
168  if (isModEnabled("expedition")) {
169  $nbElements += $project->getElementCount('shipping', 'expedition');
170  }
171  if (isModEnabled('mrp')) {
172  $nbElements += $project->getElementCount('mrp', 'mrp_mo', 'fk_project');
173  }
174  if (isModEnabled('deplacement')) {
175  $nbElements += $project->getElementCount('trip', 'deplacement');
176  }
177  if (isModEnabled('expensereport')) {
178  $nbElements += $project->getElementCount('expensereport', 'expensereport');
179  }
180  if (isModEnabled('don')) {
181  $nbElements += $project->getElementCount('donation', 'don');
182  }
183  if (!empty($conf->loan->enabled)) {
184  $nbElements += $project->getElementCount('loan', 'loan');
185  }
186  if (isModEnabled('tax')) {
187  $nbElements += $project->getElementCount('chargesociales', 'chargesociales');
188  }
189  if (isModEnabled('project')) {
190  $nbElements += $project->getElementCount('project_task', 'projet_task');
191  }
192  if (isModEnabled('stock')) {
193  $nbElements += $project->getElementCount('stock_mouvement', 'stock');
194  }
195  if (!empty($conf->salaries->enabled)) {
196  $nbElements += $project->getElementCount('salaries', 'payment_salary');
197  }
198  if (isModEnabled("banque")) {
199  $nbElements += $project->getElementCount('variouspayment', 'payment_various');
200  }
201  dol_setcache($cachekey, $nbElements, 120); // If setting cache fails, this is not a problem, so we do not test result.
202  }
203  $head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$project->id;
204  $head[$h][1] = $langs->trans("ProjectOverview");
205  if ($nbElements > 0) {
206  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbElements.'</span>';
207  }
208  $head[$h][2] = 'element';
209  $h++;
210  }
211 
212  if (isModEnabled('ticket') && $user->hasRight('ticket', 'read')) {
213  require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
214  $Tickettatic = new Ticket($db);
215  $nbTicket = count($Tickettatic->getAllItemsLinkedByObjectID($project->id, '*', 'fk_project', 'ticket'));
216  $head[$h][0] = DOL_URL_ROOT.'/ticket/list.php?projectid='.((int) $project->id);
217  $head[$h][1] = $langs->trans("Ticket");
218  if ($nbTicket > 0) {
219  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbTicket).'</span>';
220  }
221  $head[$h][2] = 'ticket';
222  $h++;
223  }
224 
225  if (isModEnabled('eventorganization') && !empty($project->usage_organize_event)) {
226  $langs->load('eventorganization');
227  $head[$h][0] = DOL_URL_ROOT . '/eventorganization/conferenceorbooth_list.php?projectid=' . $project->id;
228  $head[$h][1] = $langs->trans("EventOrganization");
229 
230  // Enable caching of conf or booth count
231  $nbConfOrBooth = 0;
232  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
233  $cachekey = 'count_conferenceorbooth_'.$project->id;
234  $dataretrieved = dol_getcache($cachekey);
235  if (!is_null($dataretrieved)) {
236  $nbConfOrBooth = $dataretrieved;
237  } else {
238  require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php';
239  $conforbooth=new ConferenceOrBooth($db);
240  $result = $conforbooth->fetchAll('', '', 0, 0, array('t.fk_project'=>$project->id));
241  //,
242  if (!is_array($result) && $result<0) {
243  setEventMessages($conforbooth->error, $conforbooth->errors, 'errors');
244  } else {
245  $nbConfOrBooth = count($result);
246  }
247  dol_setcache($cachekey, $nbConfOrBooth, 120); // If setting cache fails, this is not a problem, so we do not test result.
248  }
249  if ($nbConfOrBooth > 0) {
250  $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbConfOrBooth . '</span>';
251  }
252  $head[$h][2] = 'eventorganisation';
253  $h++;
254  }
255 
256  // Show more tabs from modules
257  // Entries must be declared in modules descriptor with line
258  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
259  // $this->tabs = array('entity:-tabname); to remove a tab
260  complete_head_from_modules($conf, $langs, $project, $head, $h, 'project', 'add', 'core');
261 
262 
263  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
264  $nbNote = 0;
265  if (!empty($project->note_private)) {
266  $nbNote++;
267  }
268  if (!empty($project->note_public)) {
269  $nbNote++;
270  }
271  $head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$project->id;
272  $head[$h][1] = $langs->trans('Notes');
273  if ($nbNote > 0) {
274  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
275  }
276  $head[$h][2] = 'notes';
277  $h++;
278  }
279 
280  // Attached files and Links
281  $totalAttached = 0;
282  // Enable caching of thirdrparty count attached files and links
283  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
284  $cachekey = 'count_attached_project_'.$project->id;
285  $dataretrieved = dol_getcache($cachekey);
286  if (!is_null($dataretrieved)) {
287  $totalAttached = $dataretrieved;
288  } else {
289  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
290  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
291  $upload_dir = $conf->project->multidir_output[$project->entity]."/".dol_sanitizeFileName($project->ref);
292  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
293  $nbLinks = Link::count($db, $project->element, $project->id);
294  $totalAttached = $nbFiles + $nbLinks;
295  dol_setcache($cachekey, $totalAttached, 120); // If setting cache fails, this is not a problem, so we do not test result.
296  }
297  $head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$project->id;
298  $head[$h][1] = $langs->trans('Documents');
299  if (($totalAttached) > 0) {
300  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($totalAttached).'</span>';
301  }
302  $head[$h][2] = 'document';
303  $h++;
304 
305  // Manage discussion
306  if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT)) {
307  $nbComments = 0;
308  // Enable caching of thirdrparty count attached files and links
309  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
310  $cachekey = 'count_attached_project_'.$project->id;
311  $dataretrieved = dol_getcache($cachekey);
312  if (!is_null($dataretrieved)) {
313  $nbComments = $dataretrieved;
314  } else {
315  $nbComments = $project->getNbComments();
316  dol_setcache($cachekey, $nbComments, 120); // If setting cache fails, this is not a problem, so we do not test result.
317  }
318  $head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$project->id;
319  $head[$h][1] = $langs->trans("CommentLink");
320  if ($nbComments > 0) {
321  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbComments.'</span>';
322  }
323  $head[$h][2] = 'project_comment';
324  $h++;
325  }
326 
327  $head[$h][0] = DOL_URL_ROOT.'/projet/messaging.php?id='.$project->id;
328  $head[$h][1] = $langs->trans("Events");
329  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
330  $head[$h][1] .= '/';
331  $head[$h][1] .= $langs->trans("Agenda");
332  }
333  $head[$h][2] = 'agenda';
334  $h++;
335 
336  complete_head_from_modules($conf, $langs, $project, $head, $h, 'project', 'add', 'external');
337 
338  complete_head_from_modules($conf, $langs, $project, $head, $h, 'project', 'remove');
339 
340  return $head;
341 }
342 
343 
350 function task_prepare_head($object)
351 {
352  global $db, $langs, $conf, $user;
353  $h = 0;
354  $head = array();
355 
356  $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
357  $head[$h][1] = $langs->trans("Task");
358  $head[$h][2] = 'task_task';
359  $h++;
360 
361  $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
362  $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
363  $head[$h][1] = $langs->trans("TaskRessourceLinks");
364  if ($nbContact > 0) {
365  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
366  }
367  $head[$h][2] = 'task_contact';
368  $h++;
369 
370  // Is there timespent ?
371  $nbTimeSpent = 0;
372  $sql = "SELECT t.rowid";
373  //$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
374  //$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
375  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
376  $sql .= " WHERE t.fk_task = ".((int) $object->id);
377  $resql = $db->query($sql);
378  if ($resql) {
379  $obj = $db->fetch_object($resql);
380  if ($obj) {
381  $nbTimeSpent = 1;
382  }
383  } else {
384  dol_print_error($db);
385  }
386 
387  $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.urlencode($object->id).(GETPOST('withproject') ? '&withproject=1' : '');
388  $head[$h][1] = $langs->trans("TimeSpent");
389  if ($nbTimeSpent > 0) {
390  $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
391  }
392  $head[$h][2] = 'task_time';
393  $h++;
394 
395  // Show more tabs from modules
396  // Entries must be declared in modules descriptor with line
397  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
398  // $this->tabs = array('entity:-tabname); to remove a tab
399  complete_head_from_modules($conf, $langs, $object, $head, $h, 'task', 'add', 'core');
400 
401  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
402  $nbNote = 0;
403  if (!empty($object->note_private)) {
404  $nbNote++;
405  }
406  if (!empty($object->note_public)) {
407  $nbNote++;
408  }
409  $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.urlencode($object->id).(GETPOST('withproject') ? '&withproject=1' : '');
410  $head[$h][1] = $langs->trans('Notes');
411  if ($nbNote > 0) {
412  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
413  }
414  $head[$h][2] = 'task_notes';
415  $h++;
416  }
417 
418  $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
419  $filesdir = $conf->project->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->project->ref).'/'.dol_sanitizeFileName($object->ref);
420  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
421  include_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
422  $nbFiles = count(dol_dir_list($filesdir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
423  $nbLinks = Link::count($db, $object->element, $object->id);
424  $head[$h][1] = $langs->trans('Documents');
425  if (($nbFiles + $nbLinks) > 0) {
426  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
427  }
428  $head[$h][2] = 'task_document';
429  $h++;
430 
431  // Manage discussion
432  if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK)) {
433  $nbComments = $object->getNbComments();
434  $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
435  $head[$h][1] = $langs->trans("CommentLink");
436  if ($nbComments > 0) {
437  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbComments.'</span>';
438  }
439  $head[$h][2] = 'task_comment';
440  $h++;
441  }
442 
443  complete_head_from_modules($conf, $langs, $object, $head, $h, 'task', 'add', 'external');
444 
445  complete_head_from_modules($conf, $langs, $object, $head, $h, 'task', 'remove');
446 
447  return $head;
448 }
449 
457 function project_timesheet_prepare_head($mode, $fuser = null)
458 {
459  global $langs, $conf, $user;
460  $h = 0;
461  $head = array();
462 
463  $h = 0;
464 
465  $param = '';
466  $param .= ($mode ? '&mode='.$mode : '');
467  if (is_object($fuser) && $fuser->id > 0 && $fuser->id != $user->id) {
468  $param .= '&search_usertoprocessid='.$fuser->id;
469  }
470 
471  if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERMONTH)) {
472  $head[$h][0] = DOL_URL_ROOT."/projet/activity/permonth.php".($param ? '?'.$param : '');
473  $head[$h][1] = $langs->trans("InputPerMonth");
474  $head[$h][2] = 'inputpermonth';
475  $h++;
476  }
477 
478  if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERWEEK)) {
479  $head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($param ? '?'.$param : '');
480  $head[$h][1] = $langs->trans("InputPerWeek");
481  $head[$h][2] = 'inputperweek';
482  $h++;
483  }
484 
485  if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERTIME)) {
486  $head[$h][0] = DOL_URL_ROOT."/projet/activity/perday.php".($param ? '?'.$param : '');
487  $head[$h][1] = $langs->trans("InputPerDay");
488  $head[$h][2] = 'inputperday';
489  $h++;
490  }
491 
492  complete_head_from_modules($conf, $langs, null, $head, $h, 'project_timesheet');
493 
494  complete_head_from_modules($conf, $langs, null, $head, $h, 'project_timesheet', 'remove');
495 
496  return $head;
497 }
498 
499 
506 {
507  global $langs, $conf, $user, $db;
508 
509  $extrafields = new ExtraFields($db);
510  $extrafields->fetch_name_optionals_label('projet');
511  $extrafields->fetch_name_optionals_label('projet_task');
512 
513  $h = 0;
514  $head = array();
515 
516  $head[$h][0] = DOL_URL_ROOT."/projet/admin/project.php";
517  $head[$h][1] = $langs->trans("Projects");
518  $head[$h][2] = 'project';
519  $h++;
520 
521  complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin');
522 
523  $head[$h][0] = DOL_URL_ROOT."/projet/admin/project_extrafields.php";
524  $head[$h][1] = $langs->trans("ExtraFieldsProject");
525  $nbExtrafields = $extrafields->attributes['projet']['count'];
526  if ($nbExtrafields > 0) {
527  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
528  }
529  $head[$h][2] = 'attributes';
530  $h++;
531 
532  if (empty($conf->global->PROJECT_HIDE_TASKS)) {
533  $head[$h][0] = DOL_URL_ROOT . '/projet/admin/project_task_extrafields.php';
534  $head[$h][1] = $langs->trans("ExtraFieldsProjectTask");
535  $nbExtrafields = $extrafields->attributes['projet_task']['count'];
536  if ($nbExtrafields > 0) {
537  $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
538  }
539  $head[$h][2] = 'attributes_task';
540  $h++;
541  }
542 
543  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
544  $langs->load("members");
545 
546  $head[$h][0] = DOL_URL_ROOT.'/projet/admin/website.php';
547  $head[$h][1] = $langs->trans("BlankSubscriptionForm");
548  $head[$h][2] = 'website';
549  $h++;
550  }
551 
552  complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin', 'remove');
553 
554  return $head;
555 }
556 
557 
576 function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId = '', $addordertick = 0, $projectidfortotallink = 0, $filterprogresscalc = '', $showbilltime = 0, $arrayfields = array())
577 {
578  global $user, $langs, $conf, $db, $hookmanager;
579  global $projectstatic, $taskstatic, $extrafields;
580 
581  $lastprojectid = 0;
582 
583  $projectsArrayId = explode(',', $projectsListId);
584  if ($filterprogresscalc !== '') {
585  foreach ($lines as $key => $line) {
586  if (!empty($line->planned_workload) && !empty($line->duration)) {
587  $filterprogresscalc = str_replace(' = ', ' == ', $filterprogresscalc);
588  if (!eval($filterprogresscalc)) {
589  unset($lines[$key]);
590  }
591  }
592  }
593  $lines = array_values($lines);
594  }
595  $numlines = count($lines);
596 
597  // We declare counter as global because we want to edit them into recursive call
598  global $total_projectlinesa_spent, $total_projectlinesa_planned, $total_projectlinesa_spent_if_planned, $total_projectlinesa_declared_if_planned, $total_projectlinesa_tobill, $total_projectlinesa_billed, $total_budget_amount;
599 
600  if ($level == 0) {
601  $total_projectlinesa_spent = 0;
602  $total_projectlinesa_planned = 0;
603  $total_projectlinesa_spent_if_planned = 0;
604  $total_projectlinesa_declared_if_planned = 0;
605  $total_projectlinesa_tobill = 0;
606  $total_projectlinesa_billed = 0;
607  $total_budget_amount = 0;
608  }
609 
610  for ($i = 0; $i < $numlines; $i++) {
611  if ($parent == 0 && $level >= 0) {
612  $level = 0; // if $level = -1, we dont' use sublevel recursion, we show all lines
613  }
614 
615  // Process line
616  // print "i:".$i."-".$lines[$i]->fk_project.'<br>';
617 
618  if ($lines[$i]->fk_parent == $parent || $level < 0) { // if $level = -1, we dont' use sublevel recursion, we show all lines
619  // Show task line.
620  $showline = 1;
621  $showlineingray = 0;
622 
623  // If there is filters to use
624  if (is_array($taskrole)) {
625  // If task not legitimate to show, search if a legitimate task exists later in tree
626  if (!isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_parent) {
627  // So search if task has a subtask legitimate to show
628  $foundtaskforuserdeeper = 0;
629  searchTaskInChild($foundtaskforuserdeeper, $lines[$i]->id, $lines, $taskrole);
630  //print '$foundtaskforuserpeeper='.$foundtaskforuserdeeper.'<br>';
631  if ($foundtaskforuserdeeper > 0) {
632  $showlineingray = 1; // We will show line but in gray
633  } else {
634  $showline = 0; // No reason to show line
635  }
636  }
637  } else {
638  // Caller did not ask to filter on tasks of a specific user (this probably means he want also tasks of all users, into public project
639  // or into all other projects if user has permission to).
640  if (empty($user->rights->projet->all->lire)) {
641  // User is not allowed on this project and project is not public, so we hide line
642  if (!in_array($lines[$i]->fk_project, $projectsArrayId)) {
643  // Note that having a user assigned to a task into a project user has no permission on, should not be possible
644  // because assignement on task can be done only on contact of project.
645  // If assignement was done and after, was removed from contact of project, then we can hide the line.
646  $showline = 0;
647  }
648  }
649  }
650 
651  if ($showline) {
652  // Break on a new project
653  if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
654  $var = !$var;
655  $lastprojectid = $lines[$i]->fk_project;
656  }
657 
658  print '<tr class="oddeven" id="row-'.$lines[$i]->id.'">'."\n";
659 
660  $projectstatic->id = $lines[$i]->fk_project;
661  $projectstatic->ref = $lines[$i]->projectref;
662  $projectstatic->public = $lines[$i]->public;
663  $projectstatic->title = $lines[$i]->projectlabel;
664  $projectstatic->usage_bill_time = $lines[$i]->usage_bill_time;
665  $projectstatic->status = $lines[$i]->projectstatus;
666 
667  $taskstatic->id = $lines[$i]->id;
668  $taskstatic->ref = $lines[$i]->ref;
669  $taskstatic->label = (!empty($taskrole[$lines[$i]->id]) ? $langs->trans("YourRole").': '.$taskrole[$lines[$i]->id] : '');
670  $taskstatic->projectstatus = $lines[$i]->projectstatus;
671  $taskstatic->progress = $lines[$i]->progress;
672  $taskstatic->fk_statut = $lines[$i]->status;
673  $taskstatic->date_start = $lines[$i]->date_start;
674  $taskstatic->date_end = $lines[$i]->date_end;
675  $taskstatic->datee = $lines[$i]->date_end; // deprecated
676  $taskstatic->planned_workload = $lines[$i]->planned_workload;
677  $taskstatic->duration_effective = $lines[$i]->duration;
678  $taskstatic->budget_amount = $lines[$i]->budget_amount;
679 
680 
681  if ($showproject) {
682  // Project ref
683  print '<td class="nowraponall">';
684  //if ($showlineingray) print '<i>';
685  if ($lines[$i]->public || in_array($lines[$i]->fk_project, $projectsArrayId) || !empty($user->rights->projet->all->lire)) {
686  print $projectstatic->getNomUrl(1);
687  } else {
688  print $projectstatic->getNomUrl(1, 'nolink');
689  }
690  //if ($showlineingray) print '</i>';
691  print "</td>";
692 
693  // Project status
694  print '<td>';
695  $projectstatic->statut = $lines[$i]->projectstatus;
696  print $projectstatic->getLibStatut(2);
697  print "</td>";
698  }
699 
700  // Ref of task
701  if (count($arrayfields) > 0 && !empty($arrayfields['t.ref']['checked'])) {
702  print '<td class="nowraponall">';
703  if ($showlineingray) {
704  print '<i>'.img_object('', 'projecttask').' '.$lines[$i]->ref.'</i>';
705  } else {
706  print $taskstatic->getNomUrl(1, 'withproject');
707  }
708  print '</td>';
709  }
710 
711  // Title of task
712  if (count($arrayfields) > 0 && !empty($arrayfields['t.label']['checked'])) {
713  $labeltoshow = '';
714  if ($showlineingray) {
715  $labeltoshow .= '<i>';
716  }
717  //else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'&withproject=1">';
718  for ($k = 0; $k < $level; $k++) {
719  $labeltoshow .= '<div class="marginleftonly">';
720  }
721  $labeltoshow .= dol_escape_htmltag($lines[$i]->label);
722  for ($k = 0; $k < $level; $k++) {
723  $labeltoshow .= '</div>';
724  }
725  if ($showlineingray) {
726  $labeltoshow .= '</i>';
727  }
728  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($labeltoshow).'">';
729  print $labeltoshow;
730  print "</td>\n";
731  }
732 
733  if (count($arrayfields) > 0 && !empty($arrayfields['t.description']['checked'])) {
734  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($lines[$i]->description).'">';
735  print $lines[$i]->description;
736  print "</td>\n";
737  }
738 
739  // Date start
740  if (count($arrayfields) > 0 && !empty($arrayfields['t.dateo']['checked'])) {
741  print '<td class="center nowraponall">';
742  print dol_print_date($lines[$i]->date_start, 'dayhour');
743  print '</td>';
744  }
745 
746  // Date end
747  if (count($arrayfields) > 0 && !empty($arrayfields['t.datee']['checked'])) {
748  print '<td class="center nowraponall">';
749  print dol_print_date($lines[$i]->date_end, 'dayhour');
750  if ($taskstatic->hasDelay()) {
751  print img_warning($langs->trans("Late"));
752  }
753  print '</td>';
754  }
755 
756  $plannedworkloadoutputformat = 'allhourmin';
757  $timespentoutputformat = 'allhourmin';
758  if (!empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) {
759  $plannedworkloadoutputformat = $conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
760  }
761  if (!empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) {
762  $timespentoutputformat = $conf->global->PROJECT_TIME_SPENT_FORMAT;
763  }
764 
765  // Planned Workload (in working hours)
766  if (count($arrayfields) > 0 && !empty($arrayfields['t.planned_workload']['checked'])) {
767  print '<td class="right">';
768  $fullhour = convertSecondToTime($lines[$i]->planned_workload, $plannedworkloadoutputformat);
769  $workingdelay = convertSecondToTime($lines[$i]->planned_workload, 'all', 86400, 7); // TODO Replace 86400 and 7 to take account working hours per day and working day per weeks
770  if ($lines[$i]->planned_workload != '') {
771  print $fullhour;
772  // TODO Add delay taking account of working hours per day and working day per week
773  //if ($workingdelay != $fullhour) print '<br>('.$workingdelay.')';
774  }
775  //else print '--:--';
776  print '</td>';
777  }
778 
779  // Time spent
780  if (count($arrayfields) > 0 && !empty($arrayfields['t.duration_effective']['checked'])) {
781  print '<td class="right">';
782  if ($showlineingray) {
783  print '<i>';
784  } else {
785  print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject ? '' : '&withproject=1').'">';
786  }
787  if ($lines[$i]->duration) {
788  print convertSecondToTime($lines[$i]->duration, $timespentoutputformat);
789  } else {
790  print '--:--';
791  }
792  if ($showlineingray) {
793  print '</i>';
794  } else {
795  print '</a>';
796  }
797  print '</td>';
798  }
799 
800  // Progress calculated (Note: ->duration is time spent)
801  if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_calculated']['checked'])) {
802  print '<td class="right">';
803  if ($lines[$i]->planned_workload || $lines[$i]->duration) {
804  if ($lines[$i]->planned_workload) {
805  print round(100 * $lines[$i]->duration / $lines[$i]->planned_workload, 2).' %';
806  } else {
807  print '<span class="opacitymedium">'.$langs->trans('WorkloadNotDefined').'</span>';
808  }
809  }
810  print '</td>';
811  }
812 
813  // Progress declared
814  if (count($arrayfields) > 0 && !empty($arrayfields['t.progress']['checked'])) {
815  print '<td class="right">';
816  if ($lines[$i]->progress != '') {
817  print getTaskProgressBadge($taskstatic);
818  }
819  print '</td>';
820  }
821 
822  // resume
823  if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_summary']['checked'])) {
824  print '<td class="right">';
825  if ($lines[$i]->progress != '' && $lines[$i]->duration) {
826  print getTaskProgressView($taskstatic, false, false);
827  }
828  print '</td>';
829  }
830 
831  if ($showbilltime) {
832  // Time not billed
833  if (count($arrayfields) > 0 && !empty($arrayfields['t.tobill']['checked'])) {
834  print '<td class="right">';
835  if ($lines[$i]->usage_bill_time) {
836  print convertSecondToTime($lines[$i]->tobill, 'allhourmin');
837  $total_projectlinesa_tobill += $lines[$i]->tobill;
838  } else {
839  print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
840  }
841  print '</td>';
842  }
843 
844  // Time billed
845  if (count($arrayfields) > 0 && !empty($arrayfields['t.billed']['checked'])) {
846  print '<td class="right">';
847  if ($lines[$i]->usage_bill_time) {
848  print convertSecondToTime($lines[$i]->billed, 'allhourmin');
849  $total_projectlinesa_billed += $lines[$i]->billed;
850  } else {
851  print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
852  }
853  print '</td>';
854  }
855  }
856 
857  // Budget task
858  if (count($arrayfields) > 0 && !empty($arrayfields['t.budget_amount']['checked'])) {
859  print '<td class="center">';
860  if ($lines[$i]->budget_amount) {
861  print '<span class="amount">'.price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
862  $total_budget_amount += $lines[$i]->budget_amount;
863  }
864  print '</td>';
865  }
866 
867  // Contacts of task
868  if (count($arrayfields) > 0 && !empty($arrayfields['c.assigned']['checked'])) {
869  print '<td class="center">';
870  $ifisrt = 1;
871  foreach (array('internal', 'external') as $source) {
872  $tab = $lines[$i]->liste_contact(-1, $source);
873  $numcontact = count($tab);
874  if (!empty($numcontact)) {
875  foreach ($tab as $contacttask) {
876  //var_dump($contacttask);
877  if ($source == 'internal') {
878  $c = new User($db);
879  } else {
880  $c = new Contact($db);
881  }
882  $c->fetch($contacttask['id']);
883  if (!empty($c->photo)) {
884  if (get_class($c) == 'User') {
885  print $c->getNomUrl(-2, '', 0, 0, 24, 1, '', ($ifisrt ? '' : 'notfirst'));
886  } else {
887  print $c->getNomUrl(-2, '', 0, '', -1, 0, ($ifisrt ? '' : 'notfirst'));
888  }
889  } else {
890  if (get_class($c) == 'User') {
891  print $c->getNomUrl(2, '', 0, 0, 24, 1, '', ($ifisrt ? '' : 'notfirst'));
892  } else {
893  print $c->getNomUrl(2, '', 0, '', -1, 0, ($ifisrt ? '' : 'notfirst'));
894  }
895  }
896  $ifisrt = 0;
897  }
898  }
899  }
900  print '</td>';
901  }
902 
903  // Extra fields
904  $extrafieldsobjectkey = $taskstatic->table_element;
905  $obj = $lines[$i];
906  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
907  // Fields from hook
908  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$lines[$i]);
909  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
910  print $hookmanager->resPrint;
911 
912  // Tick to drag and drop
913  print '<td class="tdlineupdown center"></td>';
914 
915  print "</tr>\n";
916 
917  if (!$showlineingray) {
918  $inc++;
919  }
920 
921  if ($level >= 0) { // Call sublevels
922  $level++;
923  if ($lines[$i]->id) {
924  projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick, $projectidfortotallink, $filterprogresscalc, $showbilltime, $arrayfields);
925  }
926  $level--;
927  }
928 
929  $total_projectlinesa_spent += $lines[$i]->duration;
930  $total_projectlinesa_planned += $lines[$i]->planned_workload;
931  if ($lines[$i]->planned_workload) {
932  $total_projectlinesa_spent_if_planned += $lines[$i]->duration;
933  }
934  if ($lines[$i]->planned_workload) {
935  $total_projectlinesa_declared_if_planned += $lines[$i]->planned_workload * $lines[$i]->progress / 100;
936  }
937  }
938  } else {
939  //$level--;
940  }
941  }
942 
943  if (($total_projectlinesa_planned > 0 || $total_projectlinesa_spent > 0 || $total_projectlinesa_tobill > 0 || $total_projectlinesa_billed > 0 || $total_budget_amount > 0)
944  && $level <= 0) {
945  print '<tr class="liste_total nodrag nodrop">';
946  print '<td class="liste_total">'.$langs->trans("Total").'</td>';
947  if ($showproject) {
948  print '<td></td><td></td>';
949  }
950  if (count($arrayfields) > 0 && ! empty($arrayfields['t.label']['checked'])) {
951  print '<td></td>';
952  }
953  if (count($arrayfields) > 0 && ! empty($arrayfields['t.description']['checked'])) {
954  print '<td></td>';
955  }
956  if (count($arrayfields) > 0 && ! empty($arrayfields['t.dateo']['checked'])) {
957  print '<td></td>';
958  }
959  if (count($arrayfields) > 0 && ! empty($arrayfields['t.datee']['checked'])) {
960  print '<td></td>';
961  }
962  if (count($arrayfields) > 0 && ! empty($arrayfields['t.planned_workload']['checked'])) {
963  print '<td class="nowrap liste_total right">';
964  print convertSecondToTime($total_projectlinesa_planned, 'allhourmin');
965  print '</td>';
966  }
967  if (count($arrayfields) > 0 && ! empty($arrayfields['t.duration_effective']['checked'])) {
968  print '<td class="nowrap liste_total right">';
969  if ($projectidfortotallink > 0) {
970  print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$projectidfortotallink.($showproject ? '' : '&withproject=1').'">';
971  }
972  print convertSecondToTime($total_projectlinesa_spent, 'allhourmin');
973  if ($projectidfortotallink > 0) {
974  print '</a>';
975  }
976  print '</td>';
977  }
978 
979  if ($total_projectlinesa_planned) {
980  $totalAverageDeclaredProgress = round(100 * $total_projectlinesa_declared_if_planned / $total_projectlinesa_planned, 2);
981  $totalCalculatedProgress = round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned, 2);
982 
983  // this conf is actually hidden, by default we use 10% for "be carefull or warning"
984  $warningRatio = !empty($conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT) ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
985 
986  // define progress color according to time spend vs workload
987  $progressBarClass = 'progress-bar-info';
988  $badgeClass = 'badge ';
989 
990  if ($totalCalculatedProgress > $totalAverageDeclaredProgress) {
991  $progressBarClass = 'progress-bar-danger';
992  $badgeClass .= 'badge-danger';
993  } elseif ($totalCalculatedProgress * $warningRatio >= $totalAverageDeclaredProgress) { // warning if close at 1%
994  $progressBarClass = 'progress-bar-warning';
995  $badgeClass .= 'badge-warning';
996  } else {
997  $progressBarClass = 'progress-bar-success';
998  $badgeClass .= 'badge-success';
999  }
1000  }
1001 
1002  // Computed progress
1003  if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_calculated']['checked'])) {
1004  print '<td class="nowrap liste_total right">';
1005  if ($total_projectlinesa_planned) {
1006  print $totalCalculatedProgress.' %';
1007  }
1008  print '</td>';
1009  }
1010 
1011  // Declared progress
1012  if (count($arrayfields) > 0 && !empty($arrayfields['t.progress']['checked'])) {
1013  print '<td class="nowrap liste_total right">';
1014  if ($total_projectlinesa_planned) {
1015  print '<span class="'.$badgeClass.'" >'.$totalAverageDeclaredProgress.' %</span>';
1016  }
1017  print '</td>';
1018  }
1019 
1020 
1021  // Progress
1022  if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_summary']['checked'])) {
1023  print '<td class="right">';
1024  if ($total_projectlinesa_planned) {
1025  print '</span>';
1026  print ' <div class="progress sm" title="'.$totalAverageDeclaredProgress.'%" >';
1027  print ' <div class="progress-bar '.$progressBarClass.'" style="width: '.$totalAverageDeclaredProgress.'%"></div>';
1028  print ' </div>';
1029  print '</div>';
1030  }
1031  print '</td>';
1032  }
1033 
1034  if ($showbilltime) {
1035  if (count($arrayfields) > 0 && !empty($arrayfields['t.tobill']['checked'])) {
1036  print '<td class="nowrap liste_total right">';
1037  print convertSecondToTime($total_projectlinesa_tobill, 'allhourmin');
1038  print '</td>';
1039  }
1040  if (count($arrayfields) > 0 && !empty($arrayfields['t.billed']['checked'])) {
1041  print '<td class="nowrap liste_total right">';
1042  print convertSecondToTime($total_projectlinesa_billed, 'allhourmin');
1043  print '</td>';
1044  }
1045  }
1046 
1047  // Budget task
1048  if (count($arrayfields) > 0 && !empty($arrayfields['t.budget_amount']['checked'])) {
1049  print '<td class="nowrap liste_total center">';
1050  if (strcmp($total_budget_amount, '')) {
1051  print price($total_budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
1052  }
1053  print '</td>';
1054  }
1055 
1056  // Contacts of task for backward compatibility,
1057  if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) {
1058  print '<td></td>';
1059  }
1060  // Contacts of task
1061  if (count($arrayfields) > 0 && !empty($arrayfields['c.assigned']['checked'])) {
1062  print '<td></td>';
1063  }
1064  if (! empty($totalarray['nbfield'])) {
1065  print '<td colspan="'.$totalarray['nbfield'].'" class=""></td>';
1066  }
1067  print '<td class=""></td>';
1068  print '</tr>';
1069  }
1070 
1071  return $inc;
1072 }
1073 
1074 
1094 function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = null)
1095 {
1096  global $conf, $db, $user, $langs;
1097  global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
1098 
1099  $lastprojectid = 0;
1100  $totalforeachday = array();
1101  $workloadforid = array();
1102  $lineswithoutlevel0 = array();
1103 
1104  $numlines = count($lines);
1105 
1106  // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
1107  if ($parent == 0) { // Always and only if at first level
1108  for ($i = 0; $i < $numlines; $i++) {
1109  if ($lines[$i]->fk_task_parent) {
1110  $lineswithoutlevel0[] = $lines[$i];
1111  }
1112  }
1113  }
1114 
1115  if (empty($oldprojectforbreak)) {
1116  $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 to start break , -1 no break
1117  }
1118 
1119  $restrictBefore = null;
1120 
1121  if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1122  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1123  $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
1124  }
1125 
1126  //dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
1127  for ($i = 0; $i < $numlines; $i++) {
1128  if ($parent == 0) {
1129  $level = 0;
1130  }
1131 
1132  if ($lines[$i]->fk_task_parent == $parent) {
1133  $obj = &$lines[$i]; // To display extrafields
1134 
1135  // If we want all or we have a role on task, we show it
1136  if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
1137  //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
1138 
1139  if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id])) { // we have no role on task and we request to hide such cases
1140  continue;
1141  }
1142 
1143  // Break on a new project
1144  if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
1145  $lastprojectid = $lines[$i]->fk_project;
1146  if ($preselectedday) {
1147  $projectstatic->id = $lines[$i]->fk_project;
1148  }
1149  }
1150 
1151  if (empty($workloadforid[$projectstatic->id])) {
1152  if ($preselectedday) {
1153  $projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
1154  $workloadforid[$projectstatic->id] = 1;
1155  }
1156  }
1157 
1158  $projectstatic->id = $lines[$i]->fk_project;
1159  $projectstatic->ref = $lines[$i]->projectref;
1160  $projectstatic->title = $lines[$i]->projectlabel;
1161  $projectstatic->public = $lines[$i]->public;
1162  $projectstatic->status = $lines[$i]->projectstatus;
1163 
1164  $taskstatic->id = $lines[$i]->id;
1165  $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
1166  $taskstatic->label = $lines[$i]->label;
1167  $taskstatic->date_start = $lines[$i]->date_start;
1168  $taskstatic->date_end = $lines[$i]->date_end;
1169 
1170  $thirdpartystatic->id = $lines[$i]->socid;
1171  $thirdpartystatic->name = $lines[$i]->thirdparty_name;
1172  $thirdpartystatic->email = $lines[$i]->thirdparty_email;
1173 
1174  if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
1175  $addcolspan = 0;
1176  if (!empty($arrayfields['t.planned_workload']['checked'])) {
1177  $addcolspan++;
1178  }
1179  if (!empty($arrayfields['t.progress']['checked'])) {
1180  $addcolspan++;
1181  }
1182  foreach ($arrayfields as $key => $val) {
1183  if ($val['checked'] && substr($key, 0, 5) == 'efpt.') {
1184  $addcolspan++;
1185  }
1186  }
1187 
1188  print '<tr class="oddeven trforbreak nobold">'."\n";
1189  print '<td colspan="'.(7 + $addcolspan).'">';
1190  print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
1191  if ($thirdpartystatic->id > 0) {
1192  print ' - '.$thirdpartystatic->getNomUrl(1);
1193  }
1194  if ($projectstatic->title) {
1195  print ' - ';
1196  print '<span class="secondary">'.$projectstatic->title.'</span>';
1197  }
1198  /*
1199  $colspan=5+(empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:2);
1200  print '<table class="">';
1201 
1202  print '<tr class="liste_titre">';
1203 
1204  // PROJECT fields
1205  if (!empty($arrayfields['p.fk_opp_status']['checked'])) print_liste_field_titre($arrayfields['p.fk_opp_status']['label'], $_SERVER["PHP_SELF"], 'p.fk_opp_status', "", $param, '', $sortfield, $sortorder, 'center ');
1206  if (!empty($arrayfields['p.opp_amount']['checked'])) print_liste_field_titre($arrayfields['p.opp_amount']['label'], $_SERVER["PHP_SELF"], 'p.opp_amount', "", $param, '', $sortfield, $sortorder, 'right ');
1207  if (!empty($arrayfields['p.opp_percent']['checked'])) print_liste_field_titre($arrayfields['p.opp_percent']['label'], $_SERVER["PHP_SELF"], 'p.opp_percent', "", $param, '', $sortfield, $sortorder, 'right ');
1208  if (!empty($arrayfields['p.budget_amount']['checked'])) print_liste_field_titre($arrayfields['p.budget_amount']['label'], $_SERVER["PHP_SELF"], 'p.budget_amount', "", $param, '', $sortfield, $sortorder, 'right ');
1209  if (!empty($arrayfields['p.usage_bill_time']['checked'])) print_liste_field_titre($arrayfields['p.usage_bill_time']['label'], $_SERVER["PHP_SELF"], 'p.usage_bill_time', "", $param, '', $sortfield, $sortorder, 'right ');
1210 
1211  $extrafieldsobjectkey='projet';
1212  $extrafieldsobjectprefix='efp.';
1213  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1214 
1215  print '</tr>';
1216  print '<tr>';
1217 
1218  // PROJECT fields
1219  if (!empty($arrayfields['p.fk_opp_status']['checked']))
1220  {
1221  print '<td class="nowrap">';
1222  $code = dol_getIdFromCode($db, $lines[$i]->fk_opp_status, 'c_lead_status', 'rowid', 'code');
1223  if ($code) print $langs->trans("OppStatus".$code);
1224  print "</td>\n";
1225  }
1226  if (!empty($arrayfields['p.opp_amount']['checked']))
1227  {
1228  print '<td class="nowrap">';
1229  print price($lines[$i]->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
1230  print "</td>\n";
1231  }
1232  if (!empty($arrayfields['p.opp_percent']['checked']))
1233  {
1234  print '<td class="nowrap">';
1235  print price($lines[$i]->opp_percent, 0, $langs, 1, 0).' %';
1236  print "</td>\n";
1237  }
1238  if (!empty($arrayfields['p.budget_amount']['checked']))
1239  {
1240  print '<td class="nowrap">';
1241  print price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
1242  print "</td>\n";
1243  }
1244  if (!empty($arrayfields['p.usage_bill_time']['checked']))
1245  {
1246  print '<td class="nowrap">';
1247  print yn($lines[$i]->usage_bill_time);
1248  print "</td>\n";
1249  }
1250 
1251  $extrafieldsobjectkey='projet';
1252  $extrafieldsobjectprefix='efp.';
1253  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1254 
1255  print '</tr>';
1256  print '</table>';
1257 
1258  */
1259  print '</td>';
1260  print '</tr>';
1261  }
1262 
1263  if ($oldprojectforbreak != -1) {
1264  $oldprojectforbreak = $projectstatic->id;
1265  }
1266 
1267  print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
1268 
1269  // User
1270  /*
1271  print '<td class="nowrap">';
1272  print $fuser->getNomUrl(1, 'withproject', 'time');
1273  print '</td>';
1274  */
1275 
1276  // Project
1277  if (!empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) {
1278  print "<td>";
1279  if ($oldprojectforbreak == -1) {
1280  print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
1281  }
1282  print "</td>";
1283  }
1284 
1285  // Thirdparty
1286  if (!empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) {
1287  print '<td class="tdoverflowmax100">';
1288  if ($thirdpartystatic->id > 0) {
1289  print $thirdpartystatic->getNomUrl(1, 'project', 10);
1290  }
1291  print '</td>';
1292  }
1293 
1294  // Ref
1295  print '<td>';
1296  print '<!-- Task id = '.$lines[$i]->id.' -->';
1297  for ($k = 0; $k < $level; $k++) {
1298  print '<div class="marginleftonly">';
1299  }
1300  print $taskstatic->getNomUrl(1, 'withproject', 'time');
1301  // Label task
1302  print '<br>';
1303  print '<span class="opacitymedium">'.$taskstatic->label.'</a>';
1304  for ($k = 0; $k < $level; $k++) {
1305  print "</div>";
1306  }
1307  print "</td>\n";
1308 
1309  // TASK extrafields
1310  $extrafieldsobjectkey = 'projet_task';
1311  $extrafieldsobjectprefix = 'efpt.';
1312  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1313 
1314  // Planned Workload
1315  if (!empty($arrayfields['t.planned_workload']['checked'])) {
1316  print '<td class="leftborder plannedworkload right">';
1317  if ($lines[$i]->planned_workload) {
1318  print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
1319  } else {
1320  print '--:--';
1321  }
1322  print '</td>';
1323  }
1324 
1325  // Progress declared %
1326  if (!empty($arrayfields['t.progress']['checked'])) {
1327  print '<td class="right">';
1328  print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
1329  print '</td>';
1330  }
1331 
1332  if (!empty($arrayfields['timeconsumed']['checked'])) {
1333  // Time spent by everybody
1334  print '<td class="right">';
1335  // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
1336  if ($lines[$i]->duration) {
1337  print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
1338  print convertSecondToTime($lines[$i]->duration, 'allhourmin');
1339  print '</a>';
1340  } else {
1341  print '--:--';
1342  }
1343  print "</td>\n";
1344 
1345  // Time spent by user
1346  print '<td class="right">';
1347  $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
1348  if ($tmptimespent['total_duration']) {
1349  print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
1350  } else {
1351  print '--:--';
1352  }
1353  print "</td>\n";
1354  }
1355 
1356  $disabledproject = 1;
1357  $disabledtask = 1;
1358  //print "x".$lines[$i]->fk_project;
1359  //var_dump($lines[$i]);
1360  //var_dump($projectsrole[$lines[$i]->fk_project]);
1361  // If at least one role for project
1362  if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer) {
1363  $disabledproject = 0;
1364  $disabledtask = 0;
1365  }
1366  // If $restricteditformytask is on and I have no role on task, i disable edit
1367  if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
1368  $disabledtask = 1;
1369  }
1370 
1371  if ($restrictBefore && $preselectedday < $restrictBefore) {
1372  $disabledtask = 1;
1373  }
1374 
1375  // Select hour
1376  print '<td class="nowraponall leftborder center minwidth150imp">';
1377  $tableCell = $form->selectDate($preselectedday, $lines[$i]->id, 1, 1, 2, "addtime", 0, 0, $disabledtask);
1378  print $tableCell;
1379  print '</td>';
1380 
1381  $cssonholiday = '';
1382  if (!$isavailable[$preselectedday]['morning'] && !$isavailable[$preselectedday]['afternoon']) {
1383  $cssonholiday .= 'onholidayallday ';
1384  } elseif (!$isavailable[$preselectedday]['morning']) {
1385  $cssonholiday .= 'onholidaymorning ';
1386  } elseif (!$isavailable[$preselectedday]['afternoon']) {
1387  $cssonholiday .= 'onholidayafternoon ';
1388  }
1389 
1390  global $daytoparse;
1391  $tmparray = dol_getdate($daytoparse, true); // detail of current day
1392 
1393  $idw = ($tmparray['wday'] - (empty($conf->global->MAIN_START_WEEK) ? 0 : 1));
1394  global $numstartworkingday, $numendworkingday;
1395  $cssweekend = '';
1396  if ((($idw + 1) < $numstartworkingday) || (($idw + 1) > $numendworkingday)) { // This is a day is not inside the setup of working days, so we use a week-end css.
1397  $cssweekend = 'weekend';
1398  }
1399 
1400  // Duration
1401  print '<td class="center duration'.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
1402  $dayWorkLoad = !empty($projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id]) ? $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id] : 0;
1403  if (!isset($totalforeachday[$preselectedday])) $totalforeachday[$preselectedday] = 0;
1404  $totalforeachday[$preselectedday] += $dayWorkLoad;
1405 
1406  $alreadyspent = '';
1407  if ($dayWorkLoad > 0) {
1408  $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
1409  }
1410 
1411  $idw = 0;
1412 
1413  $tableCell = '';
1414  $tableCell .= '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
1415  $tableCell .= '<span class="hideonsmartphone"> + </span>';
1416  //$tableCell.='&nbsp;&nbsp;&nbsp;';
1417  $tableCell .= $form->select_duration($lines[$i]->id.'duration', '', $disabledtask, 'text', 0, 1);
1418  //$tableCell.='&nbsp;<input type="submit" class="button"'.($disabledtask?' disabled':'').' value="'.$langs->trans("Add").'">';
1419  print $tableCell;
1420 
1421  // Comment for avoid unnecessary multiple calculation
1422  /*$modeinput = 'hours';
1423 
1424  print '<script type="text/javascript">';
1425  print "jQuery(document).ready(function () {\n";
1426  print " jQuery('.inputhour, .inputminute').bind('keyup', function(e) { updateTotal(0, '".$modeinput."') });";
1427  print "})\n";
1428  print '</script>';*/
1429 
1430  print '</td>';
1431 
1432  // Note
1433  print '<td class="center">';
1434  print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask ? ' disabled="disabled"' : '').'>';
1435  print '</textarea>';
1436  print '</td>';
1437 
1438  // Warning
1439  print '<td class="right">';
1440  if ((!$lines[$i]->public) && $disabledproject) {
1441  print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
1442  } elseif ($disabledtask) {
1443  $titleassigntask = $langs->trans("AssignTaskToMe");
1444  if ($fuser->id != $user->id) {
1445  $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1446  }
1447 
1448  print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1449  }
1450  print '</td>';
1451 
1452  print "</tr>\n";
1453  }
1454 
1455  $inc++;
1456  $level++;
1457  if ($lines[$i]->id > 0) {
1458  //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
1459  //var_dump($totalforeachday);
1460  $ret = projectLinesPerDay($inc, $lines[$i]->id, $fuser, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields);
1461  //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
1462  //var_dump($ret);
1463  foreach ($ret as $key => $val) {
1464  $totalforeachday[$key] += $val;
1465  }
1466  //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
1467  //var_dump($totalforeachday);
1468  }
1469  $level--;
1470  } else {
1471  //$level--;
1472  }
1473  }
1474 
1475  return $totalforeachday;
1476 }
1477 
1478 
1498 function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = null)
1499 {
1500  global $conf, $db, $user, $langs;
1501  global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
1502 
1503  $numlines = count($lines);
1504 
1505  $lastprojectid = 0;
1506  $workloadforid = array();
1507  $totalforeachday = array();
1508  $lineswithoutlevel0 = array();
1509 
1510  // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
1511  if ($parent == 0) { // Always and only if at first level
1512  for ($i = 0; $i < $numlines; $i++) {
1513  if ($lines[$i]->fk_task_parent) {
1514  $lineswithoutlevel0[] = $lines[$i];
1515  }
1516  }
1517  }
1518 
1519  //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
1520 
1521  if (empty($oldprojectforbreak)) {
1522  $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 = start break, -1 = never break
1523  }
1524 
1525  $restrictBefore = null;
1526 
1527  if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1528  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1529  $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
1530  }
1531 
1532  for ($i = 0; $i < $numlines; $i++) {
1533  if ($parent == 0) {
1534  $level = 0;
1535  }
1536 
1537  if ($lines[$i]->fk_task_parent == $parent) {
1538  $obj = &$lines[$i]; // To display extrafields
1539 
1540  // If we want all or we have a role on task, we show it
1541  if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
1542  //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
1543 
1544  if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id])) { // we have no role on task and we request to hide such cases
1545  continue;
1546  }
1547 
1548  // Break on a new project
1549  if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
1550  $lastprojectid = $lines[$i]->fk_project;
1551  $projectstatic->id = $lines[$i]->fk_project;
1552  }
1553 
1554  //var_dump('--- '.$level.' '.$firstdaytoshow.' '.$fuser->id.' '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
1555  //var_dump($projectstatic->weekWorkLoadPerTask);
1556  if (empty($workloadforid[$projectstatic->id])) {
1557  $projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
1558  $workloadforid[$projectstatic->id] = 1;
1559  }
1560  //var_dump($projectstatic->weekWorkLoadPerTask);
1561  //var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
1562 
1563  $projectstatic->id = $lines[$i]->fk_project;
1564  $projectstatic->ref = $lines[$i]->projectref;
1565  $projectstatic->title = $lines[$i]->projectlabel;
1566  $projectstatic->public = $lines[$i]->public;
1567  $projectstatic->thirdparty_name = $lines[$i]->thirdparty_name;
1568  $projectstatic->status = $lines[$i]->projectstatus;
1569 
1570  $taskstatic->id = $lines[$i]->id;
1571  $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
1572  $taskstatic->label = $lines[$i]->label;
1573  $taskstatic->date_start = $lines[$i]->date_start;
1574  $taskstatic->date_end = $lines[$i]->date_end;
1575 
1576  $thirdpartystatic->id = $lines[$i]->thirdparty_id;
1577  $thirdpartystatic->name = $lines[$i]->thirdparty_name;
1578  $thirdpartystatic->email = $lines[$i]->thirdparty_email;
1579 
1580  if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
1581  $addcolspan = 0;
1582  if (!empty($arrayfields['t.planned_workload']['checked'])) {
1583  $addcolspan++;
1584  }
1585  if (!empty($arrayfields['t.progress']['checked'])) {
1586  $addcolspan++;
1587  }
1588  foreach ($arrayfields as $key => $val) {
1589  if ($val['checked'] && substr($key, 0, 5) == 'efpt.') {
1590  $addcolspan++;
1591  }
1592  }
1593 
1594  print '<tr class="oddeven trforbreak nobold">'."\n";
1595  print '<td colspan="'.(11 + $addcolspan).'">';
1596  print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
1597  if ($thirdpartystatic->id > 0) {
1598  print ' - '.$thirdpartystatic->getNomUrl(1);
1599  }
1600  if ($projectstatic->title) {
1601  print ' - ';
1602  print '<span class="secondary">'.$projectstatic->title.'</span>';
1603  }
1604 
1605  /*$colspan=5+(empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:2);
1606  print '<table class="">';
1607 
1608  print '<tr class="liste_titre">';
1609 
1610  // PROJECT fields
1611  if (!empty($arrayfields['p.fk_opp_status']['checked'])) print_liste_field_titre($arrayfields['p.fk_opp_status']['label'], $_SERVER["PHP_SELF"], 'p.fk_opp_status', "", $param, '', $sortfield, $sortorder, 'center ');
1612  if (!empty($arrayfields['p.opp_amount']['checked'])) print_liste_field_titre($arrayfields['p.opp_amount']['label'], $_SERVER["PHP_SELF"], 'p.opp_amount', "", $param, '', $sortfield, $sortorder, 'right ');
1613  if (!empty($arrayfields['p.opp_percent']['checked'])) print_liste_field_titre($arrayfields['p.opp_percent']['label'], $_SERVER["PHP_SELF"], 'p.opp_percent', "", $param, '', $sortfield, $sortorder, 'right ');
1614  if (!empty($arrayfields['p.budget_amount']['checked'])) print_liste_field_titre($arrayfields['p.budget_amount']['label'], $_SERVER["PHP_SELF"], 'p.budget_amount', "", $param, '', $sortfield, $sortorder, 'right ');
1615  if (!empty($arrayfields['p.usage_bill_time']['checked'])) print_liste_field_titre($arrayfields['p.usage_bill_time']['label'], $_SERVER["PHP_SELF"], 'p.usage_bill_time', "", $param, '', $sortfield, $sortorder, 'right ');
1616 
1617  $extrafieldsobjectkey='projet';
1618  $extrafieldsobjectprefix='efp.';
1619  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1620 
1621  print '</tr>';
1622  print '<tr>';
1623 
1624  // PROJECT fields
1625  if (!empty($arrayfields['p.fk_opp_status']['checked']))
1626  {
1627  print '<td class="nowrap">';
1628  $code = dol_getIdFromCode($db, $lines[$i]->fk_opp_status, 'c_lead_status', 'rowid', 'code');
1629  if ($code) print $langs->trans("OppStatus".$code);
1630  print "</td>\n";
1631  }
1632  if (!empty($arrayfields['p.opp_amount']['checked']))
1633  {
1634  print '<td class="nowrap">';
1635  print price($lines[$i]->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
1636  print "</td>\n";
1637  }
1638  if (!empty($arrayfields['p.opp_percent']['checked']))
1639  {
1640  print '<td class="nowrap">';
1641  print price($lines[$i]->opp_percent, 0, $langs, 1, 0).' %';
1642  print "</td>\n";
1643  }
1644  if (!empty($arrayfields['p.budget_amount']['checked']))
1645  {
1646  print '<td class="nowrap">';
1647  print price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
1648  print "</td>\n";
1649  }
1650  if (!empty($arrayfields['p.usage_bill_time']['checked']))
1651  {
1652  print '<td class="nowrap">';
1653  print yn($lines[$i]->usage_bill_time);
1654  print "</td>\n";
1655  }
1656 
1657  $extrafieldsobjectkey='projet';
1658  $extrafieldsobjectprefix='efp.';
1659  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1660 
1661  print '</tr>';
1662  print '</table>';
1663  */
1664 
1665  print '</td>';
1666  print '</tr>';
1667  }
1668 
1669  if ($oldprojectforbreak != -1) {
1670  $oldprojectforbreak = $projectstatic->id;
1671  }
1672 
1673  print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
1674 
1675  // User
1676  /*
1677  print '<td class="nowrap">';
1678  print $fuser->getNomUrl(1, 'withproject', 'time');
1679  print '</td>';
1680  */
1681 
1682  // Project
1683  if (!empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) {
1684  print '<td class="nowrap">';
1685  if ($oldprojectforbreak == -1) {
1686  print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
1687  }
1688  print "</td>";
1689  }
1690 
1691  // Thirdparty
1692  if (!empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) {
1693  print '<td class="tdoverflowmax100">';
1694  if ($thirdpartystatic->id > 0) {
1695  print $thirdpartystatic->getNomUrl(1, 'project');
1696  }
1697  print '</td>';
1698  }
1699 
1700  // Ref
1701  print '<td class="nowrap">';
1702  print '<!-- Task id = '.$lines[$i]->id.' -->';
1703  for ($k = 0; $k < $level; $k++) {
1704  print '<div class="marginleftonly">';
1705  }
1706  print $taskstatic->getNomUrl(1, 'withproject', 'time');
1707  // Label task
1708  print '<br>';
1709  print '<span class="opacitymedium">'.$taskstatic->label.'</span>';
1710  for ($k = 0; $k < $level; $k++) {
1711  print "</div>";
1712  }
1713  print "</td>\n";
1714 
1715  // TASK extrafields
1716  $extrafieldsobjectkey = 'projet_task';
1717  $extrafieldsobjectprefix = 'efpt.';
1718  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1719 
1720  // Planned Workload
1721  if (!empty($arrayfields['t.planned_workload']['checked'])) {
1722  print '<td class="leftborder plannedworkload right">';
1723  if ($lines[$i]->planned_workload) {
1724  print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
1725  } else {
1726  print '--:--';
1727  }
1728  print '</td>';
1729  }
1730 
1731  if (!empty($arrayfields['t.progress']['checked'])) {
1732  // Progress declared %
1733  print '<td class="right">';
1734  print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
1735  print '</td>';
1736  }
1737 
1738  if (!empty($arrayfields['timeconsumed']['checked'])) {
1739  // Time spent by everybody
1740  print '<td class="right">';
1741  // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
1742  if ($lines[$i]->duration) {
1743  print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
1744  print convertSecondToTime($lines[$i]->duration, 'allhourmin');
1745  print '</a>';
1746  } else {
1747  print '--:--';
1748  }
1749  print "</td>\n";
1750 
1751  // Time spent by user
1752  print '<td class="right">';
1753  $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
1754  if ($tmptimespent['total_duration']) {
1755  print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
1756  } else {
1757  print '--:--';
1758  }
1759  print "</td>\n";
1760  }
1761 
1762  $disabledproject = 1;
1763  $disabledtask = 1;
1764  //print "x".$lines[$i]->fk_project;
1765  //var_dump($lines[$i]);
1766  //var_dump($projectsrole[$lines[$i]->fk_project]);
1767  // If at least one role for project
1768  if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer) {
1769  $disabledproject = 0;
1770  $disabledtask = 0;
1771  }
1772  // If $restricteditformytask is on and I have no role on task, i disable edit
1773  if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
1774  $disabledtask = 1;
1775  }
1776 
1777  //var_dump($projectstatic->weekWorkLoadPerTask);
1778 
1779  // Fields to show current time
1780  $tableCell = '';
1781  $modeinput = 'hours';
1782  for ($idw = 0; $idw < 7; $idw++) {
1783  $tmpday = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
1784  if (!isset($totalforeachday[$tmpday])) $totalforeachday[$tmpday] = 0;
1785  $cssonholiday = '';
1786  if (!$isavailable[$tmpday]['morning'] && !$isavailable[$tmpday]['afternoon']) {
1787  $cssonholiday .= 'onholidayallday ';
1788  } elseif (!$isavailable[$tmpday]['morning']) {
1789  $cssonholiday .= 'onholidaymorning ';
1790  } elseif (!$isavailable[$tmpday]['afternoon']) {
1791  $cssonholiday .= 'onholidayafternoon ';
1792  }
1793 
1794  $tmparray = dol_getdate($tmpday);
1795  $dayWorkLoad = (!empty($projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id]) ? $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id] : 0);
1796  $totalforeachday[$tmpday] += $dayWorkLoad;
1797 
1798  $alreadyspent = '';
1799  if ($dayWorkLoad > 0) {
1800  $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
1801  }
1802  $alttitle = $langs->trans("AddHereTimeSpentForDay", !empty($tmparray['day']) ? $tmparray['day'] : 0, $tmparray['mon']);
1803 
1804  global $numstartworkingday, $numendworkingday;
1805  $cssweekend = '';
1806  if (($idw + 1 < $numstartworkingday) || ($idw + 1 > $numendworkingday)) { // This is a day is not inside the setup of working days, so we use a week-end css.
1807  $cssweekend = 'weekend';
1808  }
1809 
1810  $disabledtaskday = $disabledtask;
1811 
1812  if (! $disabledtask && $restrictBefore && $tmpday < $restrictBefore) {
1813  $disabledtaskday = 1;
1814  }
1815 
1816  $tableCell = '<td class="center hide'.$idw.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
1817  //$tableCell .= 'idw='.$idw.' '.$conf->global->MAIN_START_WEEK.' '.$numstartworkingday.'-'.$numendworkingday;
1818  $placeholder = '';
1819  if ($alreadyspent) {
1820  $tableCell .= '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center smallpadd" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
1821  //$placeholder=' placeholder="00:00"';
1822  //$tableCell.='+';
1823  }
1824  $tableCell .= '<input type="text" alt="'.($disabledtaskday ? '' : $alttitle).'" title="'.($disabledtaskday ? '' : $alttitle).'" '.($disabledtaskday ? 'disabled' : $placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2" maxlength="5"';
1825  $tableCell .= ' onkeypress="return regexEvent(this,event,\'timeChar\')"';
1826  $tableCell .= ' onkeyup="updateTotal('.$idw.',\''.$modeinput.'\')"';
1827  $tableCell .= ' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$idw.',\''.$modeinput.'\')" />';
1828  $tableCell .= '</td>';
1829  print $tableCell;
1830  }
1831 
1832  // Warning
1833  print '<td class="right">';
1834  if ((!$lines[$i]->public) && $disabledproject) {
1835  print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
1836  } elseif ($disabledtask) {
1837  $titleassigntask = $langs->trans("AssignTaskToMe");
1838  if ($fuser->id != $user->id) {
1839  $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1840  }
1841 
1842  print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1843  }
1844  print '</td>';
1845 
1846  print "</tr>\n";
1847  }
1848 
1849  // Call to show task with a lower level (task under the current task)
1850  $inc++;
1851  $level++;
1852  if ($lines[$i]->id > 0) {
1853  //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
1854  //var_dump($totalforeachday);
1855  $ret = projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields);
1856  //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
1857  //var_dump($ret);
1858  foreach ($ret as $key => $val) {
1859  $totalforeachday[$key] += $val;
1860  }
1861  //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
1862  //var_dump($totalforeachday);
1863  }
1864  $level--;
1865  } else {
1866  //$level--;
1867  }
1868  }
1869 
1870  return $totalforeachday;
1871 }
1872 
1891 function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $TWeek = array())
1892 {
1893  global $conf, $db, $user, $langs;
1894  global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
1895 
1896  $numlines = count($lines);
1897 
1898  $lastprojectid = 0;
1899  $workloadforid = array();
1900  $totalforeachweek = array();
1901  $lineswithoutlevel0 = array();
1902 
1903  // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
1904  if ($parent == 0) { // Always and only if at first level
1905  for ($i = 0; $i < $numlines; $i++) {
1906  if ($lines[$i]->fk_task_parent) {
1907  $lineswithoutlevel0[] = $lines[$i];
1908  }
1909  }
1910  }
1911 
1912  //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
1913 
1914  if (empty($oldprojectforbreak)) {
1915  $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 = start break, -1 = never break
1916  }
1917 
1918  $restrictBefore = null;
1919 
1920  if (!empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
1921  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1922  $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
1923  }
1924 
1925  for ($i = 0; $i < $numlines; $i++) {
1926  if ($parent == 0) {
1927  $level = 0;
1928  }
1929 
1930  if ($lines[$i]->fk_task_parent == $parent) {
1931  // If we want all or we have a role on task, we show it
1932  if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
1933  //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
1934 
1935  // Break on a new project
1936  if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
1937  $lastprojectid = $lines[$i]->fk_project;
1938  $projectstatic->id = $lines[$i]->fk_project;
1939  }
1940 
1941  //var_dump('--- '.$level.' '.$firstdaytoshow.' '.$fuser->id.' '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
1942  //var_dump($projectstatic->weekWorkLoadPerTask);
1943  if (empty($workloadforid[$projectstatic->id])) {
1944  $projectstatic->loadTimeSpentMonth($firstdaytoshow, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
1945  $workloadforid[$projectstatic->id] = 1;
1946  }
1947  //var_dump($projectstatic->weekWorkLoadPerTask);
1948  //var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
1949 
1950  $projectstatic->id = $lines[$i]->fk_project;
1951  $projectstatic->ref = $lines[$i]->projectref;
1952  $projectstatic->title = $lines[$i]->projectlabel;
1953  $projectstatic->public = $lines[$i]->public;
1954  $projectstatic->thirdparty_name = $lines[$i]->thirdparty_name;
1955  $projectstatic->status = $lines[$i]->projectstatus;
1956 
1957  $taskstatic->id = $lines[$i]->id;
1958  $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
1959  $taskstatic->label = $lines[$i]->label;
1960  $taskstatic->date_start = $lines[$i]->date_start;
1961  $taskstatic->date_end = $lines[$i]->date_end;
1962 
1963  $thirdpartystatic->id = $lines[$i]->thirdparty_id;
1964  $thirdpartystatic->name = $lines[$i]->thirdparty_name;
1965  $thirdpartystatic->email = $lines[$i]->thirdparty_email;
1966 
1967  if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
1968  print '<tr class="oddeven trforbreak nobold">'."\n";
1969  print '<td colspan="'.(6 + count($TWeek)).'">';
1970  print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
1971  if ($thirdpartystatic->id > 0) {
1972  print ' - '.$thirdpartystatic->getNomUrl(1);
1973  }
1974  if ($projectstatic->title) {
1975  print ' - ';
1976  print '<span class="secondary">'.$projectstatic->title.'</span>';
1977  }
1978  print '</td>';
1979  print '</tr>';
1980  }
1981 
1982  if ($oldprojectforbreak != -1) {
1983  $oldprojectforbreak = $projectstatic->id;
1984  }
1985  print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
1986 
1987  // User
1988  /*
1989  print '<td class="nowrap">';
1990  print $fuser->getNomUrl(1, 'withproject', 'time');
1991  print '</td>';
1992  */
1993 
1994  // Project
1995  /*print '<td class="nowrap">';
1996  if ($oldprojectforbreak == -1) print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
1997  print "</td>";*/
1998 
1999  // Thirdparty
2000  /*print '<td class="tdoverflowmax100">';
2001  if ($thirdpartystatic->id > 0) print $thirdpartystatic->getNomUrl(1, 'project');
2002  print '</td>';*/
2003 
2004  // Ref
2005  print '<td class="nowrap">';
2006  print '<!-- Task id = '.$lines[$i]->id.' -->';
2007  for ($k = 0; $k < $level; $k++) {
2008  print '<div class="marginleftonly">';
2009  }
2010  print $taskstatic->getNomUrl(1, 'withproject', 'time');
2011  // Label task
2012  print '<br>';
2013  print '<span class="opacitymedium">'.$taskstatic->label.'</span>';
2014  for ($k = 0; $k < $level; $k++) {
2015  print "</div>";
2016  }
2017  print "</td>\n";
2018 
2019  // Planned Workload
2020  print '<td class="leftborder plannedworkload right">';
2021  if ($lines[$i]->planned_workload) {
2022  print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
2023  } else {
2024  print '--:--';
2025  }
2026  print '</td>';
2027 
2028  // Progress declared %
2029  print '<td class="right">';
2030  print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
2031  print '</td>';
2032 
2033  // Time spent by everybody
2034  print '<td class="right">';
2035  // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
2036  if ($lines[$i]->duration) {
2037  print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
2038  print convertSecondToTime($lines[$i]->duration, 'allhourmin');
2039  print '</a>';
2040  } else {
2041  print '--:--';
2042  }
2043  print "</td>\n";
2044 
2045  // Time spent by user
2046  print '<td class="right">';
2047  $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
2048  if ($tmptimespent['total_duration']) {
2049  print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
2050  } else {
2051  print '--:--';
2052  }
2053  print "</td>\n";
2054 
2055  $disabledproject = 1;
2056  $disabledtask = 1;
2057  //print "x".$lines[$i]->fk_project;
2058  //var_dump($lines[$i]);
2059  //var_dump($projectsrole[$lines[$i]->fk_project]);
2060  // If at least one role for project
2061  if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer) {
2062  $disabledproject = 0;
2063  $disabledtask = 0;
2064  }
2065  // If $restricteditformytask is on and I have no role on task, i disable edit
2066  if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
2067  $disabledtask = 1;
2068  }
2069 
2070  //var_dump($projectstatic->weekWorkLoadPerTask);
2071  //TODO
2072  // Fields to show current time
2073  $tableCell = '';
2074  $modeinput = 'hours';
2075  $TFirstDay = getFirstDayOfEachWeek($TWeek, date('Y', $firstdaytoshow));
2076  $TFirstDay[reset($TWeek)] = 1;
2077 
2078  $firstdaytoshowarray = dol_getdate($firstdaytoshow);
2079  $year = $firstdaytoshowarray['year'];
2080  $month = $firstdaytoshowarray['mon'];
2081  foreach ($TWeek as $weekIndex => $weekNb) {
2082  $weekWorkLoad = !empty($projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id]) ? $projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id] : 0 ;
2083  if (!isset($totalforeachweek[$weekNb])) $totalforeachweek[$weekNb] = 0;
2084  $totalforeachweek[$weekNb] += $weekWorkLoad;
2085 
2086  $alreadyspent = '';
2087  if ($weekWorkLoad > 0) {
2088  $alreadyspent = convertSecondToTime($weekWorkLoad, 'allhourmin');
2089  }
2090  $alttitle = $langs->trans("AddHereTimeSpentForWeek", $weekNb);
2091 
2092  $disabledtaskweek = $disabledtask;
2093  $firstdayofweek = dol_mktime(0, 0, 0, $month, $TFirstDay[$weekIndex], $year);
2094 
2095  if (! $disabledtask && $restrictBefore && $firstdayofweek < $restrictBefore) {
2096  $disabledtaskweek = 1;
2097  }
2098 
2099  $tableCell = '<td class="center hide weekend">';
2100  $placeholder = '';
2101  if ($alreadyspent) {
2102  $tableCell .= '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center smallpadd" size="2" disabled id="timespent['.$inc.']['.((int) $weekNb).']" name="task['.$lines[$i]->id.']['.$weekNb.']" value="'.$alreadyspent.'"></span>';
2103  //$placeholder=' placeholder="00:00"';
2104  //$tableCell.='+';
2105  }
2106 
2107  $tableCell .= '<input type="text" alt="'.($disabledtaskweek ? '' : $alttitle).'" title="'.($disabledtaskweek ? '' : $alttitle).'" '.($disabledtaskweek ? 'disabled' : $placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.((int) $weekNb).']" name="task['.$lines[$i]->id.']['.($TFirstDay[$weekNb] - 1).']" value="" cols="2" maxlength="5"';
2108  $tableCell .= ' onkeypress="return regexEvent(this,event,\'timeChar\')"';
2109  $tableCell .= ' onkeyup="updateTotal('.$weekNb.',\''.$modeinput.'\')"';
2110  $tableCell .= ' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$weekNb.',\''.$modeinput.'\')" />';
2111  $tableCell .= '</td>';
2112  print $tableCell;
2113  }
2114 
2115  // Warning
2116  print '<td class="right">';
2117  if ((!$lines[$i]->public) && $disabledproject) {
2118  print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
2119  } elseif ($disabledtask) {
2120  $titleassigntask = $langs->trans("AssignTaskToMe");
2121  if ($fuser->id != $user->id) {
2122  $titleassigntask = $langs->trans("AssignTaskToUser", '...');
2123  }
2124 
2125  print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
2126  }
2127  print '</td>';
2128 
2129  print "</tr>\n";
2130  }
2131 
2132  // Call to show task with a lower level (task under the current task)
2133  $inc++;
2134  $level++;
2135  if ($lines[$i]->id > 0) {
2136  //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
2137  //var_dump($totalforeachday);
2138  $ret = projectLinesPerMonth($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak, $TWeek);
2139  //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
2140  //var_dump($ret);
2141  foreach ($ret as $key => $val) {
2142  $totalforeachweek[$key] += $val;
2143  }
2144  //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
2145  //var_dump($totalforeachday);
2146  }
2147  $level--;
2148  } else {
2149  //$level--;
2150  }
2151  }
2152 
2153  return $totalforeachweek;
2154 }
2155 
2156 
2166 function searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
2167 {
2168  //print 'Search in line with parent id = '.$parent.'<br>';
2169  $numlines = count($lines);
2170  for ($i = 0; $i < $numlines; $i++) {
2171  // Process line $lines[$i]
2172  if ($lines[$i]->fk_parent == $parent && $lines[$i]->id != $lines[$i]->fk_parent) {
2173  // If task is legitimate to show, no more need to search deeper
2174  if (isset($taskrole[$lines[$i]->id])) {
2175  //print 'Found a legitimate task id='.$lines[$i]->id.'<br>';
2176  $inc++;
2177  return $inc;
2178  }
2179 
2180  searchTaskInChild($inc, $lines[$i]->id, $lines, $taskrole);
2181  //print 'Found inc='.$inc.'<br>';
2182 
2183  if ($inc > 0) {
2184  return $inc;
2185  }
2186  }
2187  }
2188 
2189  return $inc;
2190 }
2191 
2206 function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks = 0, $status = -1, $listofoppstatus = array(), $hiddenfields = array(), $max = 0)
2207 {
2208  global $langs, $conf, $user;
2209  global $theme_datacolor;
2210 
2211  $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
2212 
2213  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
2214 
2215  $listofstatus = array_keys($listofoppstatus);
2216 
2217  if (is_array($listofstatus) && !empty($conf->global->USE_COLOR_FOR_PROSPECTION_STATUS)) {
2218  // Define $themeColorId and array $statusOppList for each $listofstatus
2219  $themeColorId = 0;
2220  $statusOppList = array();
2221  foreach ($listofstatus as $oppStatus) {
2222  $oppStatusCode = dol_getIdFromCode($db, $oppStatus, 'c_lead_status', 'rowid', 'code');
2223  if ($oppStatusCode) {
2224  $statusOppList[$oppStatus]['code'] = $oppStatusCode;
2225  $statusOppList[$oppStatus]['color'] = isset($theme_datacolor[$themeColorId]) ? implode(', ', $theme_datacolor[$themeColorId]) : '';
2226  }
2227  $themeColorId++;
2228  }
2229  }
2230 
2231  $projectstatic = new Project($db);
2232  $thirdpartystatic = new Societe($db);
2233 
2234  $sortfield = '';
2235  $sortorder = '';
2236  $project_year_filter = 0;
2237 
2238  $title = $langs->trans("Projects");
2239  if (strcmp($status, '') && $status >= 0) {
2240  $title = $langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$status]);
2241  }
2242 
2243  print '<!-- print_projecttasks_array -->';
2244  print '<div class="div-table-responsive-no-min">';
2245  print '<table class="noborder centpercent">';
2246 
2247  $sql = " FROM ".MAIN_DB_PREFIX."projet as p";
2248  if ($mytasks) {
2249  $sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
2250  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
2251  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
2252  } else {
2253  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
2254  }
2255  $sql .= " WHERE p.entity IN (".getEntity('project').")";
2256  $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")";
2257  if ($socid) {
2258  $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
2259  }
2260  if ($mytasks) {
2261  $sql .= " AND p.rowid = t.fk_projet";
2262  $sql .= " AND ec.element_id = t.rowid";
2263  $sql .= " AND ec.fk_socpeople = ".((int) $user->id);
2264  $sql .= " AND ec.fk_c_type_contact = ctc.rowid"; // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact
2265  $sql .= " AND ctc.element = 'project_task'";
2266  }
2267  if ($status >= 0) {
2268  $sql .= " AND p.fk_statut = ".(int) $status;
2269  }
2270  if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) {
2271  $project_year_filter = GETPOST("project_year_filter");
2272  //Check if empty or invalid year. Wildcard ignores the sql check
2273  if ($project_year_filter != "*") {
2274  if (empty($project_year_filter) || !ctype_digit($project_year_filter)) {
2275  $project_year_filter = date("Y");
2276  }
2277  $sql .= " AND (p.dateo IS NULL OR p.dateo <= ".$db->idate(dol_get_last_day($project_year_filter, 12, false)).")";
2278  $sql .= " AND (p.datee IS NULL OR p.datee >= ".$db->idate(dol_get_first_day($project_year_filter, 1, false)).")";
2279  }
2280  }
2281 
2282  // Get id of project we must show tasks
2283  $arrayidofprojects = array();
2284  $sql1 = "SELECT p.rowid as projectid";
2285  $sql1 .= $sql;
2286  $resql = $db->query($sql1);
2287  if ($resql) {
2288  $i = 0;
2289  $num = $db->num_rows($resql);
2290  while ($i < $num) {
2291  $objp = $db->fetch_object($resql);
2292  $arrayidofprojects[$objp->projectid] = $objp->projectid;
2293  $i++;
2294  }
2295  } else {
2296  dol_print_error($db);
2297  }
2298  if (empty($arrayidofprojects)) {
2299  $arrayidofprojects[0] = -1;
2300  }
2301 
2302  // Get list of project with calculation on tasks
2303  $sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc,";
2304  $sql2 .= " s.rowid as socid, s.nom as socname, s.name_alias,";
2305  $sql2 .= " s.code_client, s.code_compta, s.client,";
2306  $sql2 .= " s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur,";
2307  $sql2 .= " s.logo, s.email, s.entity,";
2308  $sql2 .= " p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_percent, p.opp_amount,";
2309  $sql2 .= " p.dateo, p.datee,";
2310  $sql2 .= " COUNT(t.rowid) as nb, SUM(t.planned_workload) as planned_workload, SUM(t.planned_workload * t.progress / 100) as declared_progess_workload";
2311  $sql2 .= " FROM ".MAIN_DB_PREFIX."projet as p";
2312  $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
2313  $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
2314  $sql2 .= " WHERE p.rowid IN (".$db->sanitize(join(',', $arrayidofprojects)).")";
2315  $sql2 .= " GROUP BY p.rowid, p.ref, p.title, p.fk_soc, s.rowid, s.nom, s.name_alias, s.code_client, s.code_compta, s.client, s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur,";
2316  $sql2 .= " s.logo, s.email, s.entity, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_percent, p.opp_amount, p.dateo, p.datee";
2317  $sql2 .= " ORDER BY p.title, p.ref";
2318 
2319  $resql = $db->query($sql2);
2320  if ($resql) {
2321  $othernb = 0;
2322  $total_task = 0;
2323  $total_opp_amount = 0;
2324  $ponderated_opp_amount = 0;
2325  $total_plannedworkload = 0;
2326  $total_declaredprogressworkload = 0;
2327 
2328  $num = $db->num_rows($resql);
2329  $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
2330  $i = 0;
2331 
2332  print '<tr class="liste_titre">';
2333  print_liste_field_titre($title.'<a href="'.DOL_URL_ROOT.'/projet/list.php?search_status='.((int) $status).'"><span class="badge marginleftonlyshort">'.$num.'</span></a>', $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
2334  print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
2335  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
2336  if (!in_array('prospectionstatus', $hiddenfields)) {
2337  print_liste_field_titre("OpportunityStatus", "", "", "", "", 'style="max-width: 100px"', $sortfield, $sortorder, 'center ');
2338  }
2339  print_liste_field_titre($form->textwithpicto($langs->trans("Amount"), $langs->trans("OpportunityAmount").' ('.$langs->trans("Tooltip").' = '.$langs->trans("OpportunityWeightedAmount").')'), "", "", "", "", 'style="max-width: 100px"', $sortfield, $sortorder, 'right ');
2340  //print_liste_field_titre('OpportunityWeightedAmount', '', '', '', '', 'align="right"', $sortfield, $sortorder);
2341  }
2342  if (empty($conf->global->PROJECT_HIDE_TASKS)) {
2343  print_liste_field_titre("Tasks", "", "", "", "", 'align="right"', $sortfield, $sortorder);
2344  if (!in_array('plannedworkload', $hiddenfields)) {
2345  print_liste_field_titre("PlannedWorkload", "", "", "", "", 'style="max-width: 100px"', $sortfield, $sortorder, 'right ');
2346  }
2347  if (!in_array('declaredprogress', $hiddenfields)) {
2348  print_liste_field_titre("%", "", "", "", "", '', $sortfield, $sortorder, 'right ', $langs->trans("ProgressDeclared"));
2349  }
2350  }
2351  if (!in_array('projectstatus', $hiddenfields)) {
2352  print_liste_field_titre("Status", "", "", "", "", '', $sortfield, $sortorder, 'right ');
2353  }
2354  print "</tr>\n";
2355 
2356  while ($i < $nbofloop) {
2357  $objp = $db->fetch_object($resql);
2358 
2359  if ($max && $i >= $max) {
2360  $othernb++;
2361  $i++;
2362  $total_task += $objp->nb;
2363  $total_opp_amount += $objp->opp_amount;
2364  $opp_weighted_amount = $objp->opp_percent * $objp->opp_amount / 100;
2365  $ponderated_opp_amount += price2num($opp_weighted_amount);
2366  $plannedworkload = $objp->planned_workload;
2367  $total_plannedworkload += $plannedworkload;
2368  $declaredprogressworkload = $objp->declared_progess_workload;
2369  $total_declaredprogressworkload += $declaredprogressworkload;
2370  continue;
2371  }
2372 
2373  $projectstatic->id = $objp->projectid;
2374  $projectstatic->user_author_id = $objp->fk_user_creat;
2375  $projectstatic->public = $objp->public;
2376 
2377  // Check is user has read permission on project
2378  $userAccess = $projectstatic->restrictedProjectArea($user);
2379  if ($userAccess >= 0) {
2380  $projectstatic->ref = $objp->ref;
2381  $projectstatic->status = $objp->status;
2382  $projectstatic->title = $objp->title;
2383  $projectstatic->date_end = $db->jdate($objp->datee);
2384  $projectstatic->date_start = $db->jdate($objp->dateo);
2385 
2386  print '<tr class="oddeven">';
2387 
2388  print '<td class="tdoverflowmax150">';
2389  print $projectstatic->getNomUrl(1, '', 0, '', '-', 0, -1, 'nowraponall');
2390  if (!in_array('projectlabel', $hiddenfields)) {
2391  print '<br><span class="opacitymedium">'.dol_trunc($objp->title, 24).'</span>';
2392  }
2393  print '</td>';
2394 
2395  print '<td class="nowraponall tdoverflowmax100">';
2396  if ($objp->fk_soc > 0) {
2397  $thirdpartystatic->id = $objp->socid;
2398  $thirdpartystatic->name = $objp->socname;
2399  //$thirdpartystatic->name_alias = $objp->name_alias;
2400  //$thirdpartystatic->code_client = $objp->code_client;
2401  $thirdpartystatic->code_compta = $objp->code_compta;
2402  $thirdpartystatic->client = $objp->client;
2403  //$thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
2404  $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
2405  $thirdpartystatic->fournisseur = $objp->fournisseur;
2406  $thirdpartystatic->logo = $objp->logo;
2407  $thirdpartystatic->email = $objp->email;
2408  $thirdpartystatic->entity = $objp->entity;
2409  print $thirdpartystatic->getNomUrl(1);
2410  }
2411  print '</td>';
2412 
2413  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
2414  if (!in_array('prospectionstatus', $hiddenfields)) {
2415  print '<td class="center tdoverflowmax75">';
2416  // Because color of prospection status has no meaning yet, it is used if hidden constant is set
2417  if (empty($conf->global->USE_COLOR_FOR_PROSPECTION_STATUS)) {
2418  $oppStatusCode = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
2419  if ($langs->trans("OppStatus".$oppStatusCode) != "OppStatus".$oppStatusCode) {
2420  print $langs->trans("OppStatus".$oppStatusCode);
2421  }
2422  } else {
2423  if (isset($statusOppList[$objp->opp_status])) {
2424  $oppStatusCode = $statusOppList[$objp->opp_status]['code'];
2425  $oppStatusColor = $statusOppList[$objp->opp_status]['color'];
2426  } else {
2427  $oppStatusCode = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
2428  $oppStatusColor = '';
2429  }
2430  if ($oppStatusCode) {
2431  if (!empty($oppStatusColor)) {
2432  print '<a href="'.dol_buildpath('/projet/list.php?search_opp_status='.$objp->opp_status, 1).'" style="display: inline-block; width: 4px; border: 5px solid rgb('.$oppStatusColor.'); border-radius: 2px;" title="'.$langs->trans("OppStatus".$oppStatusCode).'"></a>';
2433  } else {
2434  print '<a href="'.dol_buildpath('/projet/list.php?search_opp_status='.$objp->opp_status, 1).'" title="'.$langs->trans("OppStatus".$oppStatusCode).'">'.$oppStatusCode.'</a>';
2435  }
2436  }
2437  }
2438  print '</td>';
2439  }
2440 
2441  print '<td class="right">';
2442  if ($objp->opp_percent && $objp->opp_amount) {
2443  $opp_weighted_amount = $objp->opp_percent * $objp->opp_amount / 100;
2444  $alttext = $langs->trans("OpportunityWeightedAmount").' '.price($opp_weighted_amount, 0, '', 1, -1, 0, $conf->currency);
2445  $ponderated_opp_amount += price2num($opp_weighted_amount);
2446  }
2447  if ($objp->opp_amount) {
2448  print '<span class="amount" title="'.$alttext.'">'.$form->textwithpicto(price($objp->opp_amount, 0, '', 1, -1, 0), $alttext).'</span>';
2449  }
2450  print '</td>';
2451  }
2452 
2453  if (empty($conf->global->PROJECT_HIDE_TASKS)) {
2454  print '<td class="right">'.$objp->nb.'</td>';
2455 
2456  $plannedworkload = $objp->planned_workload;
2457  $total_plannedworkload += $plannedworkload;
2458  if (!in_array('plannedworkload', $hiddenfields)) {
2459  print '<td class="right nowraponall">'.($plannedworkload ?convertSecondToTime($plannedworkload) : '').'</td>';
2460  }
2461  if (!in_array('declaredprogress', $hiddenfields)) {
2462  $declaredprogressworkload = $objp->declared_progess_workload;
2463  $total_declaredprogressworkload += $declaredprogressworkload;
2464  print '<td class="right nowraponall">';
2465  //print $objp->planned_workload.'-'.$objp->declared_progess_workload."<br>";
2466  print ($plannedworkload ?round(100 * $declaredprogressworkload / $plannedworkload, 0).'%' : '');
2467  print '</td>';
2468  }
2469  }
2470 
2471  if (!in_array('projectstatus', $hiddenfields)) {
2472  print '<td class="right">';
2473  print $projectstatic->getLibStatut(3);
2474  print '</td>';
2475  }
2476 
2477  print "</tr>\n";
2478 
2479  $total_task += $objp->nb;
2480  $total_opp_amount += $objp->opp_amount;
2481  }
2482 
2483  $i++;
2484  }
2485 
2486  if ($othernb) {
2487  print '<tr class="oddeven">';
2488  print '<td class="nowrap" colspan="5">';
2489  print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
2490  print '</td>';
2491  print "</tr>\n";
2492  }
2493 
2494  print '<tr class="liste_total">';
2495  print '<td>'.$langs->trans("Total")."</td><td></td>";
2496  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
2497  if (!in_array('prospectionstatus', $hiddenfields)) {
2498  print '<td class="liste_total"></td>';
2499  }
2500  print '<td class="liste_total right">';
2501  //$form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmountDesc"), 1);
2502  print $form->textwithpicto(price($total_opp_amount, 0, '', 1, -1, 0), $langs->trans("OpportunityPonderatedAmountDesc").' : '.price($ponderated_opp_amount, 0, '', 1, -1, 0, $conf->currency));
2503  print '</td>';
2504  }
2505  if (empty($conf->global->PROJECT_HIDE_TASKS)) {
2506  print '<td class="liste_total right">'.$total_task.'</td>';
2507  if (!in_array('plannedworkload', $hiddenfields)) {
2508  print '<td class="liste_total right">'.($total_plannedworkload ?convertSecondToTime($total_plannedworkload) : '').'</td>';
2509  }
2510  if (!in_array('declaredprogress', $hiddenfields)) {
2511  print '<td class="liste_total right">'.($total_plannedworkload ?round(100 * $total_declaredprogressworkload / $total_plannedworkload, 0).'%' : '').'</td>';
2512  }
2513  }
2514  if (!in_array('projectstatus', $hiddenfields)) {
2515  print '<td class="liste_total"></td>';
2516  }
2517  print '</tr>';
2518 
2519  $db->free($resql);
2520  } else {
2521  dol_print_error($db);
2522  }
2523 
2524  print "</table>";
2525  print '</div>';
2526 
2527  if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) {
2528  //Add the year filter input
2529  print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
2530  print '<table width="100%">';
2531  print '<tr>';
2532  print '<td>'.$langs->trans("Year").'</td>';
2533  print '<td class="right"><input type="text" size="4" class="flat" name="project_year_filter" value="'.$project_year_filter.'"/>';
2534  print "</tr>\n";
2535  print '</table></form>';
2536  }
2537 }
2538 
2548 function getTaskProgressView($task, $label = true, $progressNumber = true, $hideOnProgressNull = false, $spaced = false)
2549 {
2550  global $langs, $conf;
2551 
2552  $out = '';
2553 
2554  $plannedworkloadoutputformat = 'allhourmin';
2555  $timespentoutputformat = 'allhourmin';
2556  if (!empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) {
2557  $plannedworkloadoutputformat = $conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
2558  }
2559  if (!empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) {
2560  $timespentoutputformat = $conf->global->PROJECT_TIME_SPENT_FORMAT;
2561  }
2562 
2563  if (empty($task->progress) && !empty($hideOnProgressNull)) {
2564  return '';
2565  }
2566 
2567  $spaced = !empty($spaced) ? 'spaced' : '';
2568 
2569  $diff = '';
2570 
2571  // define progress color according to time spend vs workload
2572  $progressBarClass = 'progress-bar-info';
2573  $progressCalculated = 0;
2574  if ($task->planned_workload) {
2575  $progressCalculated = round(100 * floatval($task->duration_effective) / floatval($task->planned_workload), 2);
2576 
2577  // this conf is actually hidden, by default we use 10% for "be carefull or warning"
2578  $warningRatio = !empty($conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT) ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
2579 
2580  $diffTitle = '<br>'.$langs->trans('ProgressDeclared').' : '.$task->progress.($task->progress ? '%' : '');
2581  $diffTitle .= '<br>'.$langs->trans('ProgressCalculated').' : '.$progressCalculated.($progressCalculated ? '%' : '');
2582 
2583  //var_dump($progressCalculated.' '.$warningRatio.' '.$task->progress.' '.floatval($task->progress * $warningRatio));
2584  if (floatval($progressCalculated) > floatval($task->progress * $warningRatio)) {
2585  $progressBarClass = 'progress-bar-danger';
2586  $title = $langs->trans('TheReportedProgressIsLessThanTheCalculatedProgressionByX', abs($task->progress - $progressCalculated).' '.$langs->trans("point"));
2587  $diff = '<span class="text-danger classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-down"></i> '.($task->progress - $progressCalculated).'%</span>';
2588  } elseif (floatval($progressCalculated) > floatval($task->progress)) { // warning if close at 10%
2589  $progressBarClass = 'progress-bar-warning';
2590  $title = $langs->trans('TheReportedProgressIsLessThanTheCalculatedProgressionByX', abs($task->progress - $progressCalculated).' '.$langs->trans("point"));
2591  $diff = '<span class="text-warning classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-left"></i> '.($task->progress - $progressCalculated).'%</span>';
2592  } else {
2593  $progressBarClass = 'progress-bar-success';
2594  $title = $langs->trans('TheReportedProgressIsMoreThanTheCalculatedProgressionByX', ($task->progress - $progressCalculated).' '.$langs->trans("point"));
2595  $diff = '<span class="text-success classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-up"></i> '.($task->progress - $progressCalculated).'%</span>';
2596  }
2597  }
2598 
2599  $out .= '<div class="progress-group">';
2600 
2601  if ($label !== false) {
2602  $out .= ' <span class="progress-text">';
2603 
2604  if ($label !== true) {
2605  $out .= $label; // replace label by param
2606  } else {
2607  $out .= $task->getNomUrl(1).' '.dol_htmlentities($task->label);
2608  }
2609  $out .= ' </span>';
2610  }
2611 
2612 
2613  if ($progressNumber !== false) {
2614  $out .= ' <span class="progress-number">';
2615  if ($progressNumber !== true) {
2616  $out .= $progressNumber; // replace label by param
2617  } else {
2618  if ($task->hasDelay()) {
2619  $out .= img_warning($langs->trans("Late")).' ';
2620  }
2621 
2622  $url = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$task->id;
2623 
2624  $out .= !empty($diff) ? $diff.' ' : '';
2625  $out .= '<a href="'.$url.'" >';
2626  $out .= '<b title="'.$langs->trans('TimeSpent').'" >';
2627  if ($task->duration_effective) {
2628  $out .= convertSecondToTime($task->duration_effective, $timespentoutputformat);
2629  } else {
2630  $out .= '--:--';
2631  }
2632  $out .= '</b>';
2633  $out .= '</a>';
2634 
2635  $out .= ' / ';
2636 
2637  $out .= '<a href="'.$url.'" >';
2638  $out .= '<span title="'.$langs->trans('PlannedWorkload').'" >';
2639  if ($task->planned_workload) {
2640  $out .= convertSecondToTime($task->planned_workload, $plannedworkloadoutputformat);
2641  } else {
2642  $out .= '--:--';
2643  }
2644  $out .= '</a>';
2645  }
2646  $out .= ' </span>';
2647  }
2648 
2649 
2650  $out .= '</span>';
2651  $out .= ' <div class="progress sm '.$spaced.'">';
2652  $diffval = floatval($task->progress) - floatval($progressCalculated);
2653  if ($diffval >= 0) {
2654  // good
2655  $out .= ' <div class="progress-bar '.$progressBarClass.'" style="width: '.floatval($task->progress).'%" title="'.floatval($task->progress).'%">';
2656  if (!empty($task->progress)) {
2657  $out .= ' <div class="progress-bar progress-bar-consumed" style="width: '.floatval($progressCalculated / (floatval($task->progress) === 0 ? 1 : $task->progress) * 100).'%" title="'.floatval($progressCalculated).'%"></div>';
2658  }
2659  $out .= ' </div>';
2660  } else {
2661  // bad
2662  $out .= ' <div class="progress-bar progress-bar-consumed-late" style="width: '.floatval($progressCalculated).'%" title="'.floatval($progressCalculated).'%">';
2663  $out .= ' <div class="progress-bar '.$progressBarClass.'" style="width: '.($task->progress ? floatval($task->progress / (floatval($progressCalculated) === 0 ? 1 : $progressCalculated) * 100).'%' : '1px').'" title="'.floatval($task->progress).'%"></div>';
2664  $out .= ' </div>';
2665  }
2666  $out .= ' </div>';
2667  $out .= '</div>';
2668 
2669 
2670 
2671  return $out;
2672 }
2680 function getTaskProgressBadge($task, $label = '', $tooltip = '')
2681 {
2682  global $conf, $langs;
2683 
2684  $out = '';
2685  $badgeClass = '';
2686  if ($task->progress != '') {
2687  // TODO : manage 100%
2688 
2689  // define color according to time spend vs workload
2690  $badgeClass = 'badge ';
2691  if ($task->planned_workload) {
2692  $progressCalculated = round(100 * floatval($task->duration_effective) / floatval($task->planned_workload), 2);
2693 
2694  // this conf is actually hidden, by default we use 10% for "be carefull or warning"
2695  $warningRatio = !empty($conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT) ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
2696 
2697  if (floatval($progressCalculated) > floatval($task->progress * $warningRatio)) {
2698  $badgeClass .= 'badge-danger';
2699  if (empty($tooltip)) {
2700  $tooltip = $task->progress.'% < '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
2701  }
2702  } elseif (floatval($progressCalculated) > floatval($task->progress)) { // warning if close at 10%
2703  $badgeClass .= 'badge-warning';
2704  if (empty($tooltip)) {
2705  $tooltip = $task->progress.'% < '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
2706  }
2707  } else {
2708  $badgeClass .= 'badge-success';
2709  if (empty($tooltip)) {
2710  $tooltip = $task->progress.'% >= '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
2711  }
2712  }
2713  }
2714  }
2715 
2716  $title = '';
2717  if (!empty($tooltip)) {
2718  $badgeClass .= ' classfortooltip';
2719  $title = 'title="'.dol_htmlentities($tooltip).'"';
2720  }
2721 
2722  if (empty($label)) {
2723  $label = $task->progress.' %';
2724  }
2725 
2726  if (!empty($label)) {
2727  $out = '<span class="'.$badgeClass.'" '.$title.' >'.$label.'</span>';
2728  }
2729 
2730  return $out;
2731 }
$object ref
Definition: info.php:78
Class for ConferenceOrBooth.
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to manage projects.
Class to manage tasks.
Definition: task.class.php:38
Class to manage Dolibarr users.
Definition: user.class.php:47
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
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:238
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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_now($mode='auto')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
isModEnabled($module)
Is Dolibarr module enabled.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
dol_setcache($memoryid, $data, $expire=0)
Save data into a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:68
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:140
Class to generate the form for creating a new ticket.
projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak=0, $arrayfields=array(), $extrafields=null)
Output a task line into a pertime intput mode.
task_prepare_head($object)
Prepare array with list of tabs.
projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId='', $addordertick=0, $projectidfortotallink=0, $filterprogresscalc='', $showbilltime=0, $arrayfields=array())
Show task lines with a particular parent.
searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
Search in task lines with a particular parent if there is a task for a particular user (in taskrole)
getTaskProgressView($task, $label=true, $progressNumber=true, $hideOnProgressNull=false, $spaced=false)
project_timesheet_prepare_head($mode, $fuser=null)
Prepare array with list of tabs.
project_admin_prepare_head()
Prepare array with list of tabs.
getTaskProgressBadge($task, $label='', $tooltip='')
projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak=0, $arrayfields=array(), $extrafields=null)
Output a task line into a perday intput mode.
project_prepare_head(Project $project, $moreparam='')
Prepare array with list of tabs.
Definition: project.lib.php:38