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