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