From 1b4dcefcb0bb30207478e88298989c050485b058 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Fri, 18 May 2018 08:52:13 +0200 Subject: [PATCH 1/7] fix hookname as uniq by card --- htdocs/projet/tasks.php | 2 +- htdocs/projet/tasks/comment.php | 2 +- htdocs/projet/tasks/time.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 69c62416e9b..17e89b7d21a 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -64,7 +64,7 @@ $socid=0; $result = restrictedArea($user, 'projet', $id, 'projet&project'); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context -$hookmanager->initHooks(array('projecttaskcard','globalcard')); +$hookmanager->initHooks(array('projecttaskscard','globalcard')); $progress=GETPOST('progress', 'int'); $label=GETPOST('label', 'alpha'); diff --git a/htdocs/projet/tasks/comment.php b/htdocs/projet/tasks/comment.php index cf6e29d5ef6..fff98bc3c5f 100644 --- a/htdocs/projet/tasks/comment.php +++ b/htdocs/projet/tasks/comment.php @@ -53,7 +53,7 @@ $socid=0; if (! $user->rights->projet->lire) accessforbidden(); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context -$hookmanager->initHooks(array('projecttaskcard','globalcard')); +$hookmanager->initHooks(array('projecttaskcommentcard','globalcard')); $object = new Task($db); $extrafields = new ExtraFields($db); diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 86a2027b3b7..7e4122262f7 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -74,7 +74,7 @@ if (! $sortorder) $sortorder='DESC'; // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context //$object = new TaskTime($db); -$hookmanager->initHooks(array('projecttaskcard','globalcard')); +$hookmanager->initHooks(array('projecttasktime','globalcard')); $object = new Task($db); $projectstatic = new Project($db); From a27c2637470c64a4dcc3b03b12f94fef25841ccd Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Fri, 18 May 2018 10:33:32 +0200 Subject: [PATCH 2/7] NEW: add filter on project task list --- htdocs/core/lib/project.lib.php | 14 ++- htdocs/projet/tasks.php | 176 ++++++++++++++++++++++++++++---- 2 files changed, 169 insertions(+), 21 deletions(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 6a8ef760a04..f7068998e26 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -327,9 +327,10 @@ function project_admin_prepare_head() * @param int $projectsListId List of id of project allowed to user (string separated with comma) * @param int $addordertick Add a tick to move task * @param int $projectidfortotallink 0 or Id of project to use on total line (link to see all time consumed for project) + * @param string $filterprogresscalc filter text * @return void */ -function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId='', $addordertick=0, $projectidfortotallink=0) +function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId='', $addordertick=0, $projectidfortotallink=0, $filterprogresscalc='') { global $user, $bc, $langs, $conf; global $projectstatic, $taskstatic; @@ -337,6 +338,17 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t $lastprojectid=0; $projectsArrayId=explode(',',$projectsListId); + if ($filterprogresscalc!=='') { + foreach ($lines as $key=>$line) { + if (!empty($line->planned_workload) && !empty($line->duration)) { + $filterprogresscalc = str_replace(' = ', ' == ', $filterprogresscalc); + if (!eval($filterprogresscalc)) { + unset($lines[$key]); + $lines=array_values($lines); + } + } + } + } $numlines=count($lines); diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 17e89b7d21a..0205f2b5e33 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -30,6 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; $langs->loadLangs(array("users", "projects")); @@ -41,6 +42,18 @@ $backtopage=GETPOST('backtopage','alpha'); $cancel=GETPOST('cancel','alpha'); $search_user_id = GETPOST('search_user_id', 'int'); +$search_taskref=GETPOST('search_taskref'); +$search_tasklabel=GETPOST('search_tasklabel'); +$search_dtstartday=GETPOST('search_dtstartday'); +$search_dtstartmonth=GETPOST('search_dtstartmonth'); +$search_dtstartyear=GETPOST('search_dtstartyear'); +$search_dtendday=GETPOST('search_dtendday'); +$search_dtendmonth=GETPOST('search_dtendmonth'); +$search_dtendyear=GETPOST('search_dtendyear'); +$search_planedworkload=GETPOST('search_planedworkload'); +$search_timespend=GETPOST('search_timespend'); +$search_progresscalc=GETPOST('search_progresscalc'); +$search_progressdeclare=GETPOST('search_progressdeclare'); //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects @@ -87,10 +100,86 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers { $search_user_id=""; + $search_taskref=''; + $search_tasklabel=''; + $search_dtstartday=''; + $search_dtstartmonth=''; + $search_dtstartyear=''; + $search_dtendday=''; + $search_dtendmonth=''; + $search_dtendyear=''; + $search_planedworkload=''; + $search_timespend=''; + $search_progresscalc=''; + $search_progressdeclare=''; $toselect=''; $search_array_options=array(); } +$morewherefilterarray=array(); + +if (!empty($search_taskref)) { + $morewherefilterarray[]= natural_search('t.ref', $search_taskref, 0, 1); +} + +if (!empty($search_tasklabel)) { + $morewherefilterarray[]= natural_search('t.label', $search_tasklabel, 0, 1); +} + +if ($search_dtstartmonth > 0) +{ + if ($search_dtstartyear > 0 && empty($search_dtstartday)) { + $morewherefilterarray[]= " (t.dateo BETWEEN '".$db->idate(dol_get_first_day($search_dtstartyear,$search_dtstartmonth,false))."' AND '".$db->idate(dol_get_last_day($search_dtstartyear,$search_dtstartmonth,false))."')"; + }else if ($search_dtstartyear > 0 && ! empty($search_dtstartday)) { + $morewherefilterarray[]= " (t.dateo BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_dtstartmonth, $search_dtstartday, $search_dtstartyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_dtstartmonth, $search_dtstartday, $search_dtstartyear))."')"; + }else { + $morewherefilterarray[]= " date_format(t.dateo, '%m') = '".$search_dtstartmonth."'"; + } +} +else if ($search_dtstartyear > 0) +{ + $morewherefilterarray[]= " (t.dateo BETWEEN '".$db->idate(dol_get_first_day($search_dtstartyear,1,false))."' AND '".$db->idate(dol_get_last_day($search_dtstartyear,12,false))."')"; +} + +if ($search_dtendmonth > 0) +{ + if ($search_dtendyear > 0 && empty($search_dtendday)) { + $morewherefilterarray[]= " (t.datee BETWEEN '".$db->idate(dol_get_first_day($search_dtendyear,$search_dtendmonth,false))."' AND '".$db->idate(dol_get_last_day($search_dtendyear,$search_dtendmonth,false))."')"; + }else if ($search_dtendyear > 0 && ! empty($search_dtendday)) { + $morewherefilterarray[]= " (t.datee BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_dtendmonth, $search_dtendday, $search_dtendyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_dtendmonth, $search_dtendday, $search_dtendyear))."')"; + }else { + $morewherefilterarray[]= " date_format(t.datee, '%m') = '".$search_dtendmonth."'"; + } +} +else if ($search_dtendyear > 0) +{ + $morewherefilterarray[]= " (t.datee BETWEEN '".$db->idate(dol_get_first_day($search_dtendyear,1,false))."' AND '".$db->idate(dol_get_last_day($search_dtendyear,12,false))."')"; +} + +if (!empty($search_planedworkload)) { + $morewherefilterarray[]= natural_search('t.planned_workload', $search_planedworkload, 1, 1); +} + +if (!empty($search_timespend)) { + $morewherefilterarray[]= natural_search('t.duration_effective', $search_timespend, 1, 1); +} + +if (!empty($search_progresscalc)) { + $filterprogresscalc='if '.natural_search('round(100 * $line->duration / $line->planned_workload,2)',$search_progresscalc,1,1). '{return 1;} else {return 0;}'; +} else { + $filterprogresscalc=''; +} + +if (!empty($search_progressdeclare)) { + $morewherefilterarray[]= natural_search('t.progress', $search_progressdeclare, 1, 1); +} + + +$morewherefilter=''; +if (count($morewherefilterarray)>0) { + $morewherefilter= ' AND '. implode(' AND ', $morewherefilterarray); +} + if ($action == 'createtask' && $user->rights->projet->creer) { $error=0; @@ -208,7 +297,7 @@ if ($id > 0 || ! empty($ref)) { $object->fetch($id, $ref); $object->fetch_thirdparty(); - $res=$object->fetch_optionals(); + $res=$object->fetch_optionals($object->id,$extralabels_projet); // To verify role of users @@ -282,9 +371,9 @@ if ($id > 0 || ! empty($ref)) // Date start - end print ''.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").''; - $start = dol_print_date($object->date_start,'day'); + $start = dol_print_date($object->date_start,'dayhour'); print ($start?$start:'?'); - $end = dol_print_date($object->date_end,'day'); + $end = dol_print_date($object->date_end,'dayhour'); print ' - '; print ($end?$end:'?'); if ($object->hasDelay()) print img_warning("Late"); @@ -417,7 +506,7 @@ if ($action == 'create' && $user->rights->projet->creer && (empty($object->third $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields_task->attribute_label)) { print $object->showOptionals($extrafields_task,'edit'); } @@ -496,7 +585,7 @@ else if ($id > 0 || ! empty($ref)) // Get list of tasks in tasksarray and taskarrayfiltered // We need all tasks (even not limited to a user because a task to user can have a parent that is not affected to him). $filteronthirdpartyid = $socid; - $tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $filteronthirdpartyid, 0); + $tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $filteronthirdpartyid, 0,'',-1,$morewherefilter); // We load also tasks limited to a particular user $tmpuser=new User($db); if ($search_user_id > 0) $tmpuser->fetch($search_user_id); @@ -510,26 +599,73 @@ else if ($id > 0 || ! empty($ref)) include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; } + // Filter on categories + $moreforfilter=''; + if (count($tasksarray) > 0) + { + $moreforfilter.='
'; + $moreforfilter.=$langs->trans("TasksAssignedTo").': '; + $moreforfilter.=$form->select_dolusers($tmpuser->id > 0 ? $tmpuser->id : '', 'search_user_id', 1); + $moreforfilter.='
'; + } + if ($moreforfilter) + { + print '
'; + print $moreforfilter; + print '
'; + } + $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields print '
'; - print ''; + print '
'; - if (count($tasksarray) > 0) - { - // Link to switch in "my task" / "all task" - print ''; + // Fields title search + print ''; - // Action column - print ''; - } + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + // Action column + print ''; + print "\n"; print ''; // print ''; @@ -549,7 +685,7 @@ else if ($id > 0 || ! empty($ref)) { // Show all lines in taskarray (recursive function to go down on tree) $j=0; $level=0; - $nboftaskshown=projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, $object->id, 1, $object->id); + $nboftaskshown=projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, $object->id, 1, $object->id, $filterprogresscalc); } else { From 986b4f78ba2921528ce190e530eac0d24fac2f24 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Fri, 18 May 2018 13:54:07 +0200 Subject: [PATCH 3/7] fix eldy comment --- htdocs/core/lib/project.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index f7068998e26..3c1ea553a66 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -344,10 +344,10 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t $filterprogresscalc = str_replace(' = ', ' == ', $filterprogresscalc); if (!eval($filterprogresscalc)) { unset($lines[$key]); - $lines=array_values($lines); } } } + $lines=array_values($lines); } $numlines=count($lines); From dd946dd1970179e7bacedd27f21b8406e77b7667 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 21 May 2018 11:03:48 +0200 Subject: [PATCH 4/7] add ressource --- htdocs/core/lib/project.lib.php | 21 ++++++++++++++++++++- htdocs/projet/tasks.php | 6 ++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 3c1ea553a66..99e9055c6a3 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -332,7 +332,7 @@ function project_admin_prepare_head() */ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId='', $addordertick=0, $projectidfortotallink=0, $filterprogresscalc='') { - global $user, $bc, $langs, $conf; + global $user, $bc, $langs, $conf, $db; global $projectstatic, $taskstatic; $lastprojectid=0; @@ -531,6 +531,24 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t } print ''; + // Ressources + print ''; + // Tick to drag and drop if ($addordertick) { @@ -579,6 +597,7 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t if ($total_projectlinesa_planned) print round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned,2).' %'; print ''; print ''; + print ''; if ($addordertick) print ''; print ''; } diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 0205f2b5e33..922bfafcbf6 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -660,6 +660,8 @@ else if ($id > 0 || ! empty($ref)) print ''; print ''; + print ''; + // Action column print '\n"; @@ -689,7 +691,7 @@ else if ($id > 0 || ! empty($ref)) } else { - print ''; + print ''; } print "
'; - print $langs->trans("TasksAssignedTo"); - print $form->select_dolusers($tmpuser->id > 0 ? $tmpuser->id : '', 'search_user_id', 1); - print '
'; - $searchpicto=$form->showFilterButtons(); - print $searchpicto; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $formother->select_year($search_dtstartyear?$search_dtstartyear:-1,'search_dtstartyear',1, 20, 5); + print ''; + print ''; + print ''; + $formother->select_year($search_dtendyear?$search_dtendyear:-1,'search_dtendyear',1, 20, 5); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $searchpicto=$form->showFilterButtons(); + print $searchpicto; + print '
'.$langs->trans("Project").''; + foreach(array('internal','external') as $source) + { + $tab = $lines[$i]->liste_contact(-1,$source); + $num=count($tab); + if (!empty($num)){ + foreach ($tab as $contacttask){ + //var_dump($contacttask); + if ($source == 'internal') $c = new User($db); + else $c = new Contact($db); + $c->fetch($contacttask['id']); + print $c->getNomUrl(1) . ' (' . $contacttask['libelle'] . ')' . '
'; + } + } + } + print '
'; $searchpicto=$form->showFilterButtons(); @@ -677,7 +679,7 @@ else if ($id > 0 || ! empty($ref)) print_liste_field_titre("TimeSpent", $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,''); print_liste_field_titre("ProgressCalculated", $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,''); print_liste_field_titre("ProgressDeclared", $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,''); - //print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center" width="80"',$sortfield,$sortorder,'maxwidthsearch '); + print_liste_field_titre("TaskRessourceLinks",$_SERVER["PHP_SELF"],'','','',$sortfield,$sortorder,''); print_liste_field_titre('', $_SERVER["PHP_SELF"],"",'','','align="center" width="80"',$sortfield,$sortorder,'maxwidthsearch '); print "
'.$langs->trans("NoTasks").'
'.$langs->trans("NoTasks").'
"; From c56ef86bc366cb782316ac3ff34d3ebf0d8e6828 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 25 May 2018 10:50:16 +0200 Subject: [PATCH 5/7] Update project.lib.php --- htdocs/core/lib/project.lib.php | 35 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 99e9055c6a3..e11fd409a6e 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -531,23 +531,26 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t } print ''; - // Ressources - print ''; - foreach(array('internal','external') as $source) + // Contacts of task + if (! empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) { - $tab = $lines[$i]->liste_contact(-1,$source); - $num=count($tab); - if (!empty($num)){ - foreach ($tab as $contacttask){ - //var_dump($contacttask); - if ($source == 'internal') $c = new User($db); - else $c = new Contact($db); - $c->fetch($contacttask['id']); - print $c->getNomUrl(1) . ' (' . $contacttask['libelle'] . ')' . '
'; + print ''; + foreach(array('internal','external') as $source) + { + $tab = $lines[$i]->liste_contact(-1,$source); + $num=count($tab); + if (!empty($num)){ + foreach ($tab as $contacttask){ + //var_dump($contacttask); + if ($source == 'internal') $c = new User($db); + else $c = new Contact($db); + $c->fetch($contacttask['id']); + print $c->getNomUrl(1) . ' (' . $contacttask['libelle'] . ')' . '
'; + } } } + print ''; } - print ''; // Tick to drag and drop if ($addordertick) @@ -597,7 +600,11 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t if ($total_projectlinesa_planned) print round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned,2).' %'; print ''; print ''; - print ''; + // Contacts of task + if (! empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) + { + print ''; + } if ($addordertick) print ''; print ''; } From e7cfad0e6073c496b652ada0b4dfe582ea7ef3f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 25 May 2018 10:52:24 +0200 Subject: [PATCH 6/7] Update tasks.php --- htdocs/projet/tasks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 922bfafcbf6..9a3bcb6f6e3 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -297,7 +297,7 @@ if ($id > 0 || ! empty($ref)) { $object->fetch($id, $ref); $object->fetch_thirdparty(); - $res=$object->fetch_optionals($object->id,$extralabels_projet); + $res=$object->fetch_optionals(); // To verify role of users From 034752dc0b250b131522f997eb5cffed6c93f0b6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 25 May 2018 10:54:17 +0200 Subject: [PATCH 7/7] Update tasks.php --- htdocs/projet/tasks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 9a3bcb6f6e3..e0f9ecea1e6 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -660,7 +660,7 @@ else if ($id > 0 || ! empty($ref)) print ''; print ''; - print ''; + if (! empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) print ''; // Action column print ''; @@ -679,7 +679,7 @@ else if ($id > 0 || ! empty($ref)) print_liste_field_titre("TimeSpent", $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,''); print_liste_field_titre("ProgressCalculated", $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,''); print_liste_field_titre("ProgressDeclared", $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,''); - print_liste_field_titre("TaskRessourceLinks",$_SERVER["PHP_SELF"],'','','',$sortfield,$sortorder,''); + if (! empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) print_liste_field_titre("TaskRessourceLinks",$_SERVER["PHP_SELF"],'','','',$sortfield,$sortorder,''); print_liste_field_titre('', $_SERVER["PHP_SELF"],"",'','','align="center" width="80"',$sortfield,$sortorder,'maxwidthsearch '); print "\n";