dolibarr 25.0.0-alpha
task.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Vincent de Grandpré <vincent@de-grandpre.quebec>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29require "../../main.inc.php";
37require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
38require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
46
47// Load translation files required by the page
48$langs->loadlangs(array('projects', 'companies'));
49
50$action = GETPOST('action', 'aZ09');
51$confirm = GETPOST('confirm', 'alpha');
52//$cancel = GETPOST('cancel');
53//$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
54//$backtopage = GETPOST('backtopage', 'alpha'); // if not set, a default page will be used
55//$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used
56
57$id = GETPOSTINT('id');
58$ref = GETPOST("ref", 'alpha', 1); // task ref
59$taskref = GETPOST("taskref", 'alpha'); // task ref
60$withproject = GETPOSTINT('withproject');
61$project_ref = GETPOST('project_ref', 'alpha');
62$planned_workload = ((GETPOST('planned_workloadhour') != '' || GETPOST('planned_workloadmin') != '') ? (GETPOSTINT('planned_workloadhour') > 0 ? GETPOSTINT('planned_workloadhour') * 3600 : 0) + (GETPOSTINT('planned_workloadmin') > 0 ? GETPOSTINT('planned_workloadmin') * 60 : 0) : '');
63$mode = GETPOST('mode', 'alpha');
64
65// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
66$hookmanager->initHooks(array('projecttaskcard', 'globalcard'));
67
68$object = new Task($db);
69$extrafields = new ExtraFields($db);
70$projectstatic = new Project($db);
71
72// fetch optionals attributes and labels
73$extrafields->fetch_name_optionals_label($object->table_element);
74
75$parameters = array('id' => $id);
76$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
77if ($reshook < 0) {
78 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
79}
80
81if ($id > 0 || $ref) {
82 $ret = $object->fetch($id, $ref);
83 if ($ret > 0) {
84 $projectstatic->fetch((int) $object->fk_project);
85 }
86}
87
88// Security check
89$socid = 0;
90
91restrictedArea($user, 'projet', $object->fk_project, 'projet&project');
92
93
94
95/*
96 * Actions
97 */
98
99$error = 0;
100
101if ($action == 'update' && !GETPOST("cancel") && $user->hasRight('projet', 'creer')) {
102 if (empty($taskref)) {
103 $error++;
104 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
105 }
106 if (!GETPOST("label")) {
107 $error++;
108 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
109 }
110 if (!$error) {
111 $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty
112
113 $tmparray = explode('_', GETPOST('task_parent'));
114 $task_parent = $tmparray[1];
115 if (empty($task_parent)) {
116 $task_parent = 0; // If task_parent is ''
117 }
118
119 $object->ref = $taskref ? $taskref : GETPOST("ref", 'alpha', 2);
120 $object->label = GETPOST("label", "alphanohtml");
121 if (!getDolGlobalString('FCKEDITOR_ENABLE_SOCIETE')) {
122 $object->description = GETPOST('description', "alphanohtml");
123 } else {
124 $object->description = GETPOST('description', "restricthtml");
125 }
126 $object->fk_task_parent = $task_parent;
127 $object->planned_workload = $planned_workload;
128 $object->date_start = dol_mktime(GETPOSTINT('date_starthour'), GETPOSTINT('date_startmin'), 0, GETPOSTINT('date_startmonth'), GETPOSTINT('date_startday'), GETPOSTINT('date_startyear'));
129 $object->date_end = dol_mktime(GETPOSTINT('date_endhour'), GETPOSTINT('date_endmin'), 0, GETPOSTINT('date_endmonth'), GETPOSTINT('date_endday'), GETPOSTINT('date_endyear'));
130 $object->progress = price2num(GETPOST('progress', 'alphanohtml'));
131 $object->budget_amount = (GETPOST('budget_amount') != '' ? GETPOSTFLOAT('budget_amount'): null);
132 $object->billable = (GETPOST('billable', 'aZ') == 'yes' ? 1 : 0);
133 // The progress selector offers an empty choice that posts -1, so only move the status when a
134 // real percentage was submitted, and never pull a closed task back to ongoing (the ReOpen
135 // button is there for that).
136 $progresstouse = GETPOST('progress');
137 if ($progresstouse !== '' && $progresstouse >= 0) {
138 if ($progresstouse == '100') {
139 $object->status = $object::STATUS_CLOSED;
140 } elseif ($progresstouse != '0' && $object->status != $object::STATUS_CLOSED) {
141 $object->status = $object::STATUS_ONGOING;
142 }
143 }
144
145 // Fill array 'array_options' with data from add form
146 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
147 if ($ret < 0) {
148 $error++;
149 }
150
151 if (!$error) {
152 $result = $object->update($user);
153 if ($result < 0) {
154 setEventMessages($object->error, $object->errors, 'errors');
155 $action = 'edit';
156 }
157 } else {
158 $action = 'edit';
159 }
160 } else {
161 $action = 'edit';
162 }
163}
164
165if ($action == 'confirm_merge' && $confirm == 'yes' && $user->hasRight('projet', 'creer')) {
166 $task_origin_id = GETPOSTINT('task_origin');
167 $task_origin = new Task($db); // The Task that we will delete
168
169 if ($task_origin_id <= 0) {
170 $langs->load('errors');
171 setEventMessages($langs->trans('ErrorTaskIdIsMandatory', $langs->transnoentitiesnoconv('MergeOriginTask')), null, 'errors');
172 } else {
173 if (!$error && $task_origin->fetch($task_origin_id) < 1) {
174 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
175 $error++;
176 }
177 if (!$error) {
178 $result = $object->mergeTask($task_origin_id);
179 if ($result < 0) {
180 $error++;
181 setEventMessages($object->error, $object->errors, 'errors');
182 } else {
183 setEventMessages($langs->trans('TaskMergeSuccess'), null, 'mesgs');
184 }
185 }
186 }
187}
188
189if ($action == 'confirm_clone' && $confirm == 'yes' && $user->hasRight('projet', 'creer')) {
190 //$clone_contacts = GETPOST('clone_contacts') ? 1 : 0;
191 $clone_prog = GETPOST('clone_prog') ? 1 : 0;
192 $clone_time = GETPOST('clone_time') ? 1 : 0;
193 $clone_affectation = GETPOST('clone_affectation') ? 1 : 0;
194 $clone_change_dt = GETPOST('clone_change_dt') ? 1 : 0;
195 $clone_notes = GETPOST('clone_notes') ? 1 : 0;
196 $clone_file = GETPOST('clone_file') ? 1 : 0;
197 $result = $object->createFromClone($user, $object->id, $object->fk_project, $object->fk_task_parent, $clone_change_dt, $clone_affectation, $clone_time, $clone_file, $clone_notes, $clone_prog);
198 if ($result <= 0) {
199 setEventMessages($object->error, $object->errors, 'errors');
200 } else {
201 // Load new object
202 $newobject = new Task($db);
203 $newobject->fetch($result);
204 $newobject->fetch_optionals();
205 $newobject->fetch_thirdparty(); // Load new object
206 $object = $newobject;
207 $action = '';
208 }
209}
210
211if ($action == 'confirm_delete' && $confirm == "yes" && $user->hasRight('projet', 'supprimer')) {
212 $result = $projectstatic->fetch($object->fk_project);
213 $projectstatic->fetch_thirdparty();
214
215 // $object is task to delete
216 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
217 if ($object->delete($user) > 0) {
218 header('Location: '.DOL_URL_ROOT.'/projet/tasks.php?restore_lastsearch_values=1&id='.$projectstatic->id.($withproject ? '&withproject=1' : ''));
219 exit;
220 } else {
221 setEventMessages($object->error, $object->errors, 'errors');
222 $action = '';
223 }
224}
225
226if ($action == 'confirm_close' && $confirm == "yes" && $user->hasRight('projet', 'creer')) {
227 $result = $projectstatic->fetch($object->fk_project);
228 $projectstatic->fetch_thirdparty();
229
230 // $object is task to close
231 if ($object->setStatusCommon($user, Task::STATUS_CLOSED) <= 0) {
232 setEventMessages($object->error, $object->errors, 'errors');
233 }
234 $action = '';
235}
236
237// Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
238if (!empty($project_ref) && !empty($withproject)) {
239 if ($projectstatic->fetch(0, $project_ref) > 0) {
240 $tasksarray = $object->getTasksArray(null, null, $projectstatic->id, $socid, 0);
241 if (count($tasksarray) > 0) {
242 $id = $tasksarray[0]->id;
243 } else {
244 header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.(empty($mode) ? '' : '&mode='.$mode));
245 }
246 }
247}
248
249// Build doc
250if ($action == 'builddoc' && $user->hasRight('projet', 'creer')) {
251 // Save last template used to generate document
252 if (GETPOST('model')) {
253 $object->setDocModel($user, GETPOST('model', 'alpha'));
254 }
255
256 $outputlangs = $langs;
257 if (GETPOST('lang_id', 'aZ09')) {
258 $outputlangs = new Translate("", $conf);
259 $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
260 }
261 $result = $object->generateDocument($object->model_pdf, $outputlangs);
262 if ($result <= 0) {
263 setEventMessages($object->error, $object->errors, 'errors');
264 $action = '';
265 }
266}
267
268// Delete file in doc form
269if ($action == 'remove_file' && $user->hasRight('projet', 'creer')) {
270 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
271
272 $langs->load("other");
273 $upload_dir = $conf->project->dir_output."/".dol_sanitizeFileName($projectstatic->ref)."/".dol_sanitizeFileName($object->ref);
274 $file = $upload_dir.'/'.dol_sanitizeFileName(GETPOST('file'));
275
276 $ret = dol_delete_file($file, 1);
277 if ($ret) {
278 setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
279 } else {
280 setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
281 }
282}
283
284// Reopen task
285if ($action == 'reopen' && $user->hasRight('projet', 'creer')) {
286 $result = $object->setStatusCommon($user, Task::STATUS_DRAFT);
287 if ($result >= 0) {
288 setEventMessages($langs->trans("TaskBackToDraft"), null, 'mesgs');
289 } else {
290 $error++;
291 setEventMessages($object->error, $object->errors, 'errors');
292 }
293}
294
295// Validate status of task
296if ($action == 'valid' && $user->hasRight('projet', 'creer')) {
297 $result = $object->setStatusCommon($user, Task::STATUS_VALIDATED);
298 if ($result >= 0) {
299 setEventMessages($langs->trans("TaskValidated"), null, 'mesgs');
300 } else {
301 $error++;
302 setEventMessages($object->error, $object->errors, 'errors');
303 }
304}
305
306
307/*
308 * View
309 */
310
311$form = new Form($db);
312$formother = new FormOther($db);
313$formfile = new FormFile($db);
314$formproject = new FormProjets($db);
315
316$title = (string) $object->ref;
317if (!empty($withproject)) {
318 $title .= ' | ' . $langs->trans("Project") . (!empty($projectstatic->ref) ? ': '.$projectstatic->ref : '') ;
319}
320$help_url = '';
321
322llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-project project-tasks page-task');
323
324
325if ($id > 0 || !empty($ref)) {
326 $res = $object->fetch_optionals();
327 if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_TASK') && empty($object->comments)) {
328 $object->fetchComments();
329 }
330
331 if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
332 $projectstatic->fetchComments();
333 }
334 if (!empty($projectstatic->socid)) {
335 $projectstatic->fetch_thirdparty();
336 }
337
338 $object->project = clone $projectstatic;
339
340 //$userWrite = $projectstatic->restrictedProjectArea($user, 'write');
341
342 if (!empty($withproject)) {
343 // Tabs for project
344 $tab = 'tasks';
345 $head = project_prepare_head($projectstatic);
346 print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'), 0, '', '');
347
348 $param = ($mode == 'mine' ? '&mode=mine' : '');
349
350 // Project card
351
352 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
353
354 $morehtmlref = '<div class="refidno">';
355 // Title
356 $morehtmlref .= $projectstatic->title;
357 // Thirdparty
358 if (!empty($projectstatic->thirdparty->id) && $projectstatic->thirdparty->id > 0) {
359 $morehtmlref .= '<br>'.$projectstatic->thirdparty->getNomUrl(1, 'project');
360 }
361 $morehtmlref .= '</div>';
362
363 // Define a complementary filter for search of next/prev ref.
364 if (!$user->hasRight('projet', 'all', 'lire')) {
365 $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
366 $projectstatic->next_prev_filter = "rowid:IN:".$db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0');
367 }
368
369 dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
370
371 print '<div class="fichecenter">';
372 print '<div class="fichehalfleft">';
373 print '<div class="underbanner clearboth"></div>';
374
375 print '<table class="border tableforfield centpercent">';
376
377 // Usage
378 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') || !getDolGlobalString('PROJECT_HIDE_TASKS') || isModEnabled('eventorganization')) {
379 print '<tr><td class="tdtop">';
380 print $langs->trans("Usage");
381 print '</td>';
382 print '<td>';
383 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
384 print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
385 $htmltext = $langs->trans("ProjectFollowOpportunity");
386 print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
387 print '<br>';
388 }
389 if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
390 print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
391 $htmltext = $langs->trans("ProjectFollowTasks");
392 print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
393 print '<br>';
394 }
395 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
396 print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_bill_time ? ' checked="checked"' : '')).'"> ';
397 $htmltext = $langs->trans("ProjectBillTimeDescription");
398 print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
399 print '<br>';
400 }
401 if (isModEnabled('eventorganization')) {
402 print '<input type="checkbox" disabled name="usage_organize_event"'.(GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_organize_event ? ' checked="checked"' : '')).'"> ';
403 $htmltext = $langs->trans("EventOrganizationDescriptionLong");
404 print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
405 }
406 print '</td></tr>';
407 }
408
409 // Budget
410 print '<tr><td>'.$langs->trans("Budget").'</td><td>';
411 if (isset($projectstatic->budget_amount) && strcmp($projectstatic->budget_amount, '')) {
412 print '<span class="amount">'.price($projectstatic->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
413 }
414 print '</td></tr>';
415
416 // Date start - end project
417 print '<tr><td>'.$langs->trans("Dates").'</td><td>';
418 $start = dol_print_date($projectstatic->date_start, 'day');
419 print($start ? $start : '?');
420 $end = dol_print_date($projectstatic->date_end, 'day');
421 print ' - ';
422 print($end ? $end : '?');
423 if ($projectstatic->hasDelay()) {
424 print img_warning("Late");
425 }
426 print '</td></tr>';
427
428 // Visibility
429 print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
430 if ($projectstatic->public) {
431 print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
432 print $langs->trans('SharedProject');
433 } else {
434 print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
435 print $langs->trans('PrivateProject');
436 }
437 print '</td></tr>';
438
439 // Other attributes
440 $cols = 2;
441 $savobject = $object;
442 $object = $projectstatic;
443 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
444 $object = $savobject;
445
446 print '</table>';
447
448 print '</div>';
449
450 print '<div class="fichehalfright">';
451 print '<div class="underbanner clearboth"></div>';
452
453 print '<table class="border tableforfield centpercent">';
454
455 // Categories
456 if (isModEnabled('category')) {
457 print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
458 print $form->showCategories($projectstatic->id, 'project', 1);
459 print "</td></tr>";
460 }
461
462 // Description
463 print '<tr><td class="titlefield'.($projectstatic->description ? ' noborderbottom' : '').'" colspan="2">'.$langs->trans("Description").'</td></tr>';
464 if ($projectstatic->description) {
465 print '<tr><td class="nottitleforfield" colspan="2">';
466 print '<div class="longmessagecut">';
467 print dolPrintHTML($projectstatic->description);
468 print '</div>';
469 print '</td></tr>';
470 }
471
472 print '</table>';
473
474 print '</div>';
475 print '</div>';
476
477 print '<div class="clearboth"></div>';
478
479 print dol_get_fiche_end();
480
481 print '<br>';
482 }
483
484
485 // To verify role of users
486 //$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project
487 //$arrayofuseridoftask=$object->getListContactId('internal');
488
489
490 $head = task_prepare_head($object);
491
492 if ($action == 'edit' && $user->hasRight('projet', 'creer')) {
493 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
494 print '<input type="hidden" name="token" value="'.newToken().'">';
495 print '<input type="hidden" name="action" value="update">';
496 print '<input type="hidden" name="withproject" value="'.$withproject.'">';
497 print '<input type="hidden" name="id" value="'.$object->id.'">';
498
499 print dol_get_fiche_head($head, 'task_task', $langs->trans("Task"), 0, 'projecttask', 0, '', '');
500
501 $param = (GETPOST('withproject') ? '&withproject=1' : '');
502 $linkback = GETPOST('withproject') ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
503
504 if (!GETPOST('withproject') || empty($projectstatic->id)) {
505 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
506 $object->next_prev_filter = "fk_projet:IN:".$db->sanitize($projectsListId);
507 } else {
508 $object->next_prev_filter = "fk_projet:=:".((int) $projectstatic->id);
509 }
510
511 print '<table class="border centpercent">';
512
513 // Ref
514 print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Ref").'</td>';
515 print '<td><input class="minwidth100" name="taskref" value="'.dolPrintHTMLForAttribute($object->ref).'"></td></tr>';
516
517 // Label
518 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td>';
519 print '<td><input class="minwidth500" name="label" value="'.dolPrintHTMLForAttribute($object->label).'"></td></tr>';
520
521 // Project
522 if (empty($withproject)) {
523 print '<tr><td>'.$langs->trans("Project").'</td><td>';
524 print $projectstatic->getNomUrl(1);
525 print '</td></tr>';
526
527 // Third party
528 print '<td>'.$langs->trans("ThirdParty").'</td><td>';
529 if (!empty($projectstatic->thirdparty->id)) {
530 print $projectstatic->thirdparty->getNomUrl(1);
531 } else {
532 print '&nbsp;';
533 }
534 print '</td></tr>';
535 }
536
537 // Task parent
538 print '<tr><td>'.$langs->trans("ChildOfProjectTask").'</td><td>';
539 print img_picto('', 'projecttask');
540 $formother->selectProjectTasks($object->fk_task_parent, $projectstatic->id, 'task_parent', ($user->admin ? 0 : 1), 0, 0, 0, $object->id, '', 'minwidth100 widthcentpercentminusxx maxwidth500');
541 print '</td></tr>';
542
543 // Date start
544 print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
545 print $form->selectDate($object->date_start, 'date_start', 1, 1, 0, '', 1, 0);
546 print '</td></tr>';
547
548 // Date end
549 print '<tr><td>'.$langs->trans("Deadline").'</td><td>';
550 print $form->selectDate($object->date_end ? $object->date_end : -1, 'date_end', 1, 1, 0, '', 1, 0);
551 print '</td></tr>';
552
553 // Planned workload
554 print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
555 print $form->select_duration('planned_workload', $object->planned_workload, 0, 'text');
556 print '</td></tr>';
557
558 // Progress declared
559 print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td>';
560 print $formother->select_percent($object->progress, 'progress', 0, 5, 0, 100, 1);
561 print '</td></tr>';
562
563 // Billable
564 print '<tr><td>'.$langs->trans("Billable").'</td><td>';
565 print $form->selectyesno('billable', $object->billable);
566 print '</td></tr>';
567
568 // Description
569
570 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
571 print '<td>';
572
573 // WYSIWYG editor
574 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
575 $nbrows = getDolGlobalInt('MAIN_INPUT_DESC_HEIGHT', 0);
576 $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_details', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), $nbrows, '90%');
577 print $doleditor->Create();
578
579 print '</td></tr>';
580
581
582 print '<tr><td>'.$langs->trans("Budget").'</td>';
583 print '<td><input class="width75" type="text" name="budget_amount" value="'.dol_escape_htmltag(GETPOSTISSET('budget_amount') ? GETPOST('budget_amount') : price2num($object->budget_amount)).'"></td>';
584 print '</tr>';
585
586 // Other options
587 $parameters = array();
588 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
589 print $hookmanager->resPrint;
590 if (empty($reshook)) {
591 print $object->showOptionals($extrafields, 'edit');
592 }
593
594 print '</table>';
595
596 print dol_get_fiche_end();
597
598 print $form->buttonsSaveCancel("Modify");
599
600 print '</form>';
601 } else {
602 /*
603 * Fiche tache en mode visu
604 */
605 $param = ($withproject ? '&withproject=1' : '');
606 $linkback = $withproject ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'&restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>' : '';
607
608 print dol_get_fiche_head($head, 'task_task', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition', 0, '', 1);
609
610 if ($action == 'clone') {
611 $formquestion = array(
612 'text' => $langs->trans("ConfirmClone"),
613 //array('type' => 'checkbox', 'name' => 'clone_contacts', 'label' => $langs->trans("CloneContacts"), 'value' => true),
614 0 => array('type' => 'checkbox', 'name' => 'clone_change_dt', 'label' => $langs->trans("CloneChanges"), 'value' => true),
615 1 => array('type' => 'checkbox', 'name' => 'clone_affectation', 'label' => $langs->trans("CloneAffectation"), 'value' => true),
616 2 => array('type' => 'checkbox', 'name' => 'clone_prog', 'label' => $langs->trans("CloneProgression"), 'value' => true),
617 3 => array('type' => 'checkbox', 'name' => 'clone_time', 'label' => $langs->trans("CloneTimes"), 'value' => true),
618 4 => array('type' => 'checkbox', 'name' => 'clone_file', 'label' => $langs->trans("CloneFile"), 'value' => true),
619 );
620
621 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ToClone"), $langs->trans("ConfirmCloneTask"), "confirm_clone", $formquestion, '', 1, 0, 600);
622 }
623
624 if ($action == 'close') {
625 $formquestion = array(
626 'text' => $langs->trans("ConfirmClosed"),
627 );
628 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ToClose"), $langs->trans("ConfirmCloseTask"), "confirm_close", $formquestion, '', 1, 0, 600);
629 }
630
631
632 if ($action == 'merge') {
633 $formquestion = array(
634 array(
635 'name' => 'task_origin',
636 'label' => $langs->trans('MergeOriginTask'),
637 'type' => 'other',
638 'value' => $formproject->selectTasks(-1, 0, 'task_origin', 24, 0, $langs->trans('SelectTask'), 0, 0, 0, 'maxwidth500 minwidth200', '', '', null, 1)
639 )
640 );
641 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.(GETPOST('withproject') ? "&withproject=1" : ""), $langs->trans("MergeTasks"), $langs->trans("ConfirmMergeTasks"), "confirm_merge", $formquestion, 'yes', 1, 250);
642 }
643
644 if ($action == 'delete') {
645 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".GETPOSTINT("id").'&withproject='.$withproject, $langs->trans("DeleteATask"), $langs->trans("ConfirmDeleteATask"), "confirm_delete");
646 }
647
648 if (!GETPOST('withproject') || empty($projectstatic->id)) {
649 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
650 $object->next_prev_filter = "fk_projet:IN:".$db->sanitize($projectsListId);
651 } else {
652 $object->next_prev_filter = "fk_projet:=:".((int) $projectstatic->id);
653 }
654
655 $morehtmlref = '';
656
657 // Project
658 if (empty($withproject)) {
659 $morehtmlref .= '<div class="refidno">';
660 $morehtmlref .= $langs->trans("Project").': ';
661 $morehtmlref .= $projectstatic->getNomUrl(1);
662 $morehtmlref .= '<br>';
663
664 // Third party
665 $morehtmlref .= $langs->trans("ThirdParty").': ';
666 if (!empty($projectstatic->thirdparty) && is_object($projectstatic->thirdparty)) {
667 $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
668 }
669 $morehtmlref .= '</div>';
670 }
671
672 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
673
674 print '<div class="fichecenter">';
675 print '<div class="fichehalfleft">';
676
677 print '<div class="underbanner clearboth"></div>';
678 print '<table class="border centpercent tableforfield">';
679
680 // Task parent
681 print '<tr><td class="titlefieldmiddle">'.$langs->trans("ChildOfTask").'</td><td>';
682 if ($object->fk_task_parent > 0) {
683 $tasktmp = new Task($db);
684 $tasktmp->fetch($object->fk_task_parent);
685 print $tasktmp->getNomUrl(1);
686 }
687 print '</td></tr>';
688
689 // Date start - Date end task
690 print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("Deadline").'</td><td colspan="3">';
691 $start = dol_print_date($object->date_start, 'dayhour');
692 print($start ? $start : '?');
693 $end = dol_print_date($object->date_end, 'dayhour');
694 print ' - ';
695 print($end ? $end : '?');
696 if ($object->hasDelay()) {
697 print img_warning("Late");
698 }
699 print '</td></tr>';
700
701 // Planned workload
702 print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td colspan="3">';
703 if ($object->planned_workload != '') {
704 print convertSecondToTime($object->planned_workload, 'allhourmin');
705 }
706 print '</td></tr>';
707
708 // Description
709 print '<td class="tdtop">'.$langs->trans("Description").'</td><td colspan="3">';
710 print dol_htmlentitiesbr($object->description);
711 print '</td></tr>';
712
713 print '</table>';
714 print '</div>';
715
716 print '<div class="fichehalfright">';
717
718 print '<div class="underbanner clearboth"></div>';
719 print '<table class="border centpercent tableforfield">';
720
721 // Progress declared
722 print '<tr><td class="titlefieldmiddle">'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
723 if ($object->progress != '' && $object->progress != '-1') {
724 print $object->progress.' %';
725 }
726 print '</td></tr>';
727
728 // Progress calculated
729 print '<tr><td>'.$langs->trans("ProgressCalculated").'</td><td colspan="3">';
730 if ($object->planned_workload != '') {
731 $tmparray = $object->getSummaryOfTimeSpent();
732 if ($tmparray['total_duration'] > 0 && !empty($object->planned_workload)) {
733 print round($tmparray['total_duration'] / $object->planned_workload * 100, 2).' %';
734 } else {
735 print '0 %';
736 }
737 } else {
738 print '<span class="opacitymedium">'.$langs->trans("WorkloadNotDefined").'</span>';
739 }
740 print '</td></tr>';
741
742 // Budget
743 print '<tr><td>'.$langs->trans("Budget").'</td><td>';
744 if (!is_null($object->budget_amount) && strcmp((string) $object->budget_amount, '')) {
745 print '<span class="amount">'.price($object->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
746 }
747 print '</td></tr>';
748
749 // Billable
750 print '<tr><td>'.$langs->trans("Billable").'</td><td>';
751 print '<span>'.($object->billable ? $langs->trans('Yes') : $langs->trans('No')).'</span>';
752 print '</td></tr>';
753
754
755 // Other attributes
756 $cols = 3;
757 $parameters = array('socid' => $socid);
758 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
759
760 print '</table>';
761
762 print '</div>';
763
764 print '</div>';
765 print '<div class="clearboth"></div>';
766
767 print dol_get_fiche_end();
768 }
769
770
771 if ($action != 'edit') {
772 /*
773 * Actions
774 */
775
776 print '<div class="tabsAction">';
777
778 $parameters = array();
779 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
780 // modified by hook
781 if (empty($reshook)) {
782 // Modify
783 if ($user->hasRight('projet', 'creer')) {
784 if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_ONGOING) {
785 print '<a class="butAction classfortooltip reposition" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken().'&withproject='.((int) $withproject).'" title="'.$langs->trans("SetToDraft").'">'.$langs->trans('SetToDraft').'</a>';
786 } elseif ($object->status == $object::STATUS_DRAFT) {
787 print '<a class="butAction reposition" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=valid&token='.newToken().'&withproject='.((int) $withproject).'">'.$langs->trans('Validate').'</a>';
788 } elseif ($object->status == $object::STATUS_CLOSED) {
789 // A closed task had no way back, the reopen action above already accepts it
790 print '<a class="butAction reposition" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken().'&withproject='.((int) $withproject).'">'.$langs->trans('ReOpen').'</a>';
791 }
792 //if ($object->status != $object::STATUS_CLOSED) {
793 print '<a class="butAction reposition" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'&withproject='.((int) $withproject).'">'.$langs->trans('Modify').'</a>';
794 //}
795
796 if ($object->status != $object::STATUS_CLOSED) {
797 print '<a class="butAction classfortooltip reposition" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_close&confirm=yes&token='.newToken().'&withproject='.((int) $withproject).'" title="'.$langs->trans("Close").'">'.$langs->trans('Close').'</a>';
798 }
799
800 print dolGetButtonAction($langs->trans('ToClone'), $langs->trans('ToClone'), 'clone', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&token='.newToken().'&withproject='.((int) $withproject), '', true, array('attr' => array('class' => 'reposition')));
801
802 print '<a class="butActionDelete classfortooltip reposition" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=merge&token='.newToken().'&withproject='.((int) $withproject).'" title="'.$langs->trans("MergeTasks").'">'.$langs->trans('Merge').'</a>';
803 } else {
804 print '<a class="butActionRefused classfortooltip reposition" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Modify').'</a>';
805 }
806
807 // Delete
808 $permissiontodelete = $user->hasRight('projet', 'supprimer');
809 if ($permissiontodelete) {
810 if (!$object->hasChildren() && !$object->hasTimeSpent()) {
811 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&withproject='.((int) $withproject), 'delete', $permissiontodelete, array('attr' => array('class' => 'reposition')))."\n";
812 } else {
813 print dolGetButtonAction($langs->trans("TaskHasChild"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&withproject='.((int) $withproject), 'delete', -1, array('attr' => array('class' => 'reposition')));
814 }
815 } else {
816 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&withproject='.((int) $withproject), 'delete', $permissiontodelete, array('attr' => array('class' => 'reposition')))."\n";
817 }
818
819 print '</div>';
820 }
821
822 print '<div class="fichecenter"><div class="fichehalfleft">';
823 print '<a name="builddoc"></a>'; // ancre
824
825 /*
826 * Generated documents
827 */
828 $subdir = dol_sanitizeFileName($projectstatic->ref)."/".dol_sanitizeFileName($object->ref);
829 $filedir = $conf->project->multidir_output[$object->entity ?? $conf->entity]."/".$subdir;
830 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
831 $genallowed = ($user->hasRight('projet', 'lire'));
832 $delallowed = ($user->hasRight('projet', 'creer'));
833
834 print $formfile->showdocuments('project_task', $subdir, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 0, 0, '', '', '', '', '', $object);
835
836 // Show links to link elements
837 $tmparray = $form->showLinkToObjectBlock($object, array(), array('project_task'), 1);
838 $linktoelem = $tmparray['linktoelem'];
839 $htmltoenteralink = $tmparray['htmltoenteralink'];
840 print $htmltoenteralink;
841
842 $compatibleImportElementsList = array();
843 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
844
845 print '</div><div class="fichehalfright">';
846
847 // List of actions on element
848 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
849 $formactions = new FormActions($db);
850 $formactions->showactions($object, 'project_task', 0, 1, '', 10, 'withproject='.$withproject);
851
852 print '</div></div>';
853 }
854}
855
856// End of page
857llxFooter();
858$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage a WYSIWYG editor.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
Class to manage building of HTML components.
Class to manage projects.
Class to manage tasks.
const STATUS_VALIDATED
Validated status (To do).
const STATUS_DRAFT
Draft status.
const STATUS_CLOSED
Finished status.
Class to manage translations.
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:263
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
task_prepare_head($object)
Prepare array with list of tabs.
project_prepare_head(Project $project, $moreparam='')
Prepare array with list of tabs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.