diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index a4953cbf475..406bf024ebc 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -1,6 +1,6 @@ - * Copyright (C) 2006-2020 Laurent Destailleur + * Copyright (C) 2006-2021 Laurent Destailleur * Copyright (C) 2010-2012 Regis Houssin * Copyright (C) 2011 Juanjo Menent * Copyright (C) 2018 Ferran Marcet @@ -108,11 +108,20 @@ $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($projectstatic->table_element); $extrafields->fetch_name_optionals_label($object->table_element); +// Load task if ($id > 0 || $ref) { $object->fetch($id, $ref); } -restrictedArea($user, 'projet', $object->fk_project, 'projet&project'); +if ($object->fk_project > 0) { + restrictedArea($user, 'projet', $object->fk_project, 'projet&project'); +} else { + restrictedArea($user, 'projet', null, 'projet&project'); + // We check user has permission to see all taks of all users + if (empty($projectid) && !$user->hasRight('projet', 'all', 'lire')) { + $search_user = $user->id; + } +} @@ -335,6 +344,10 @@ if (GETPOST('projectid', 'int') > 0) { $object->fetch($id); $result = $projectstatic->fetch($object->fk_project); } +// If not task selected and no project selected +if ($id <= 0 && $projectidforalltimes == 0) { + $allprojectforuser = $user->id; +} if ($action == 'confirm_generateinvoice') { if (!empty($projectstatic->socid)) { @@ -678,7 +691,7 @@ $formother = new FormOther($db); $formproject = new FormProjets($db); $userstatic = new User($db); -if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { +if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser > 0) { /* * Fiche projet en mode visu */ @@ -888,7 +901,7 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { $massactionbutton = $form->selectMassAction('', $arrayofmassactions); // Show section with information of task. If id of task is not defined and project id defined, then $projectidforalltimes is not empty. - if (empty($projectidforalltimes)) { + if (empty($projectidforalltimes) && empty($allprojectforuser)) { $head = task_prepare_head($object); print dol_get_fiche_head($head, 'task_time', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition'); @@ -990,7 +1003,7 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { } - if ($projectstatic->id > 0) { + if ($projectstatic->id > 0 || $allprojectforuser > 0) { if ($action == 'deleteline' && !empty($projectidforalltimes)) { print $form->formconfirm($_SERVER["PHP_SELF"]."?".($object->id > 0 ? "id=".$object->id : 'projectid='.$projectstatic->id).'&lineid='.GETPOST('lineid', 'int').($withproject ? '&withproject=1' : ''), $langs->trans("DeleteATimeSpent"), $langs->trans("ConfirmDeleteATimeSpent"), "confirm_delete", '', '', 1); } @@ -1216,7 +1229,7 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { $tasks = array(); $sql = "SELECT t.rowid, t.fk_task, t.task_date, t.task_datehour, t.task_date_withhour, t.task_duration, t.fk_user, t.note, t.thm,"; - $sql .= " pt.ref, pt.label,"; + $sql .= " pt.ref, pt.label, pt.fk_projet,"; $sql .= " u.lastname, u.firstname, u.login, u.photo, u.statut as user_status,"; $sql .= " il.fk_facture as invoice_id, inv.fk_statut"; $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t"; @@ -1225,11 +1238,20 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { $sql .= " ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid"; - if (empty($projectidforalltimes)) { + if (empty($projectidforalltimes) && empty($allprojectforuser)) { + // Limit on one task $sql .= " AND t.fk_task =".((int) $object->id); - } else { + } elseif (!empty($projectidforalltimes)) { + // Limit on one project $sql .= " AND pt.fk_projet IN (".$db->sanitize($projectidforalltimes).")"; + } elseif (!empty($allprojectforuser)) { + // Limit on on user + if (empty($search_user)) { + $search_user = $user->id; + } + $sql .= " AND t.fk_user = ".((int) $search_user); } + if ($search_note) { $sql .= natural_search('t.note', $search_note); } @@ -1290,7 +1312,7 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'clock', 0, $linktocreatetime, '', $limit, 0, 0, 1); } else { - print ''."\n"; + print ''."\n"; $title = $langs->trans("ListTaskTimeForTask"); @@ -1322,6 +1344,9 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { print ''; print ''.$langs->trans("Date").''; + if (!empty($allprojectforuser)) { + print ''.$langs->trans("Project").''; + } if (empty($id)) { print ''.$langs->trans("Task").''; } @@ -1343,6 +1368,12 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { print $form->selectDate($newdate, 'time', ($conf->browser->layout == 'phone' ? 2 : 1), 1, 2, "timespent_date", 1, 0); print ''; + if (!empty($allprojectforuser)) { + print ''; + // Add project selector + print ''; + } + // Task $nboftasks = 0; if (empty($id)) { @@ -1445,6 +1476,10 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { $formother->select_year($search_year, 'search_year', 1, 20, 5); print ''; } + if (!empty($allprojectforuser)) { + print ''; + } + // Task if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task if (!empty($arrayfields['t.task_ref']['checked'])) { print ''; @@ -1493,6 +1528,9 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { if (!empty($arrayfields['t.task_date']['checked'])) { print_liste_field_titre($arrayfields['t.task_date']['label'], $_SERVER['PHP_SELF'], 't.task_date,t.task_datehour,t.rowid', '', $param, '', $sortfield, $sortorder); } + if (!empty($allprojectforuser)) { + print_liste_field_titre($langs->trans("Project"), $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder); + } if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task if (!empty($arrayfields['t.task_ref']['checked'])) { print_liste_field_titre($arrayfields['t.task_ref']['label'], $_SERVER['PHP_SELF'], 'pt.ref', '', $param, '', $sortfield, $sortorder); @@ -1565,6 +1603,20 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { } } + // Project ref + if (!empty($allprojectforuser)) { + print ''; + if (empty($conf->cache['project'][$task_time->fk_projet])) { + $tmpproject = new Project($db); + $tmpproject->fetch($task_time->fk_projet); + $conf->cache['project'][$task_time->fk_projet] = $tmpproject; + } else { + $tmpproject = $conf->cache['project'][$task_time->fk_projet]; + } + print $tmpproject->getNomUrl(1); + print ''; + } + // Task ref if (!empty($arrayfields['t.task_ref']['checked'])) { if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task