diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index f1d407d3bba..9f03213a16d 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -292,7 +292,7 @@ class FormProjets } /** - * Output a combo list with projects qualified for a third party + * Output a combo list with tasks qualified for a third party * * @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id) * @param int $selected Id task preselected @@ -304,9 +304,11 @@ class FormProjets * @param int $forcefocus Force focus on field (works with javascript only) * @param int $disabled Disabled * @param string $morecss More css added to the select component + * @param string $projectsListId ''=Automatic filter on project allowed. List of id=Filter on project ids. + * @param string $showproject 'all' = Show project info, ''=Hide project info * @return int Nbr of project if OK, <0 if KO */ - function selectTasks($socid=-1, $selected='', $htmlname='taskid', $maxlength=24, $option_only=0, $show_empty='1', $discard_closed=0, $forcefocus=0, $disabled=0, $morecss='maxwidth500') + function selectTasks($socid=-1, $selected='', $htmlname='taskid', $maxlength=24, $option_only=0, $show_empty='1', $discard_closed=0, $forcefocus=0, $disabled=0, $morecss='maxwidth500', $projectsListId='', $showproject='all') { global $user,$conf,$langs; @@ -317,11 +319,13 @@ class FormProjets $hideunselectables = false; if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true; - $projectsListId = false; - if (empty($user->rights->projet->all->lire)) + if (empty($projectsListId)) { - $projectstatic=new Project($this->db); - $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1); + if (empty($user->rights->projet->all->lire)) + { + $projectstatic=new Project($this->db); + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1); + } } // Search all projects @@ -332,7 +336,7 @@ class FormProjets $sql.= ', '.MAIN_DB_PREFIX.'projet_task as t'; $sql.= " WHERE p.entity IN (".getEntity('project').")"; $sql.= " AND t.fk_projet = p.rowid"; - if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")"; + if ($projectsListId) $sql.= " AND p.rowid IN (".$projectsListId.")"; if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)"; if ($socid > 0) $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)"; $sql.= " ORDER BY p.ref, t.ref ASC"; @@ -378,31 +382,38 @@ class FormProjets continue; } - $labeltoshow=dol_trunc($obj->ref,18); // Project ref - //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')'; - //else $labeltoshow.=' ('.$langs->trans("Private").')'; - $labeltoshow.=' '.dol_trunc($obj->title,$maxlength); + $labeltoshow = ''; - if ($obj->name) $labeltoshow.=' ('.$obj->name.')'; + if ($showproject == 'all') + { + $labeltoshow.=dol_trunc($obj->ref,18); // Project ref + //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')'; + //else $labeltoshow.=' ('.$langs->trans("Private").')'; + $labeltoshow.=' '.dol_trunc($obj->title,$maxlength); - $disabled=0; - if ($obj->fk_statut == 0) - { - $disabled=1; - $labeltoshow.=' - '.$langs->trans("Draft"); - } - else if ($obj->fk_statut == 2) - { - if ($discard_closed == 2) $disabled=1; - $labeltoshow.=' - '.$langs->trans("Closed"); - } - else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) - { - $disabled=1; - $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); + if ($obj->name) $labeltoshow.=' ('.$obj->name.')'; + + $disabled=0; + if ($obj->fk_statut == 0) + { + $disabled=1; + $labeltoshow.=' - '.$langs->trans("Draft"); + } + else if ($obj->fk_statut == 2) + { + if ($discard_closed == 2) $disabled=1; + $labeltoshow.=' - '.$langs->trans("Closed"); + } + else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) + { + $disabled=1; + $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); + } + $labeltoshow.=' - '; } + // Label for task - $labeltoshow.=' - '.$obj->tref.' '.dol_trunc($obj->tlabel,$maxlength); + $labeltoshow.=$obj->tref.' '.dol_trunc($obj->tlabel,$maxlength); if (!empty($selected) && $selected == $obj->rowid) { diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index c8096559c9c..6e8c12793cc 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1141,10 +1141,10 @@ class Project extends CommonObject * * @param User $user User object * @param int $mode 0=All project I have permission on (assigned to me and public), 1=Projects assigned to me only, 2=Will return list of all projects with no test on contacts - * @param int $list 0=Return array,1=Return string list + * @param int $list 0=Return array, 1=Return string list * @param int $socid 0=No filter on third party, id of third party - * @param string $filter additionnal filter on project (statut, ref, ...) - * @return array or string Array of projects id, or string with projects id separated with "," + * @param string $filter additionnal filter on project (statut, ref, ...) + * @return array or string Array of projects id, or string with projects id separated with "," if list is 1 */ function getProjectsAuthorizedForUser($user, $mode=0, $list=0, $socid=0, $filter='') { diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 11367951976..2eb9bc1e44f 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -455,29 +455,25 @@ else if ($id > 0 || ! empty($ref)) } } + print '
'; - /* - * Actions - */ - print '
'; - + // Link to create task if ($user->rights->projet->all->creer || $user->rights->projet->creer) { if ($object->public || $userWrite > 0) { - print ''.$langs->trans('AddTask').''; + $linktocreatetask = ''.$langs->trans('AddTask').''; } else { - print ''.$langs->trans('AddTask').''; + $linktocreatetask = ''.$langs->trans('AddTask').''; } } else { - print ''.$langs->trans('AddTask').''; + $linktocreatetask = ''.$langs->trans('AddTask').''; } - print '
'; print '
'; @@ -492,8 +488,9 @@ else if ($id > 0 || ! empty($ref)) $title=$langs->trans("ListOfTasks"); $linktotasks=''.$langs->trans("GoToListOfTimeConsumed").''; + //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'title_generic.png', 0, '', '', 0, 1); - print load_fiche_titre($title,$linktotasks,'title_generic.png'); + print load_fiche_titre($title, $linktotasks.'   '.$linktocreatetask, 'title_generic.png'); // 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). diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 49e917e4b61..44bed2119d2 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -30,6 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; 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/html.formprojet.class.php'; $langs->load('projects'); @@ -38,6 +39,7 @@ $projectid=GETPOST('projectid','int'); $ref=GETPOST('ref','alpha'); $action=GETPOST('action','alpha'); $confirm=GETPOST('confirm','alpha'); +$cancel=GETPOST('cancel','alpha'); $withproject=GETPOST('withproject','int'); $project_ref=GETPOST('project_ref','alpha'); @@ -89,6 +91,8 @@ $extralabels_task=$extrafields_task->fetch_name_optionals_label($object->table_e * Actions */ +if (GETPOST('cancel','alpha')) { $action=''; } + $parameters=array('socid'=>$socid, 'projectid'=>$projectid); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); @@ -137,10 +141,17 @@ if ($action == 'addtimespent' && $user->rights->projet->lire) if (! $error) { - $object->fetch($id, $ref); + if ($id || $ref) + { + $object->fetch($id, $ref); + } + else + { + $object->fetch(GETPOST('taskid','int')); + } $object->fetch_projet(); - if (empty($object->projet->statut)) + if (empty($object->project->statut)) { setEventMessages($langs->trans("ProjectMustBeValidatedFirst"), null, 'errors'); $error++; @@ -175,7 +186,8 @@ if ($action == 'addtimespent' && $user->rights->projet->lire) } else { - $action=''; + if (empty($id)) $action='createtime'; + else $action='createtime'; } } @@ -277,6 +289,7 @@ llxHeader("",$langs->trans("Task")); $form = new Form($db); $formother = new FormOther($db); +$formproject = new FormProjets($db); $userstatic = new User($db); if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) @@ -398,35 +411,26 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) dol_fiche_end(); - /* - * Actions - */ + print '
'; + // Link to create time if ((empty($id) && empty($ref)) || ! empty($projectidforalltimes)) { - print '
'; - if ($user->rights->projet->all->creer || $user->rights->projet->creer) { if ($object->public || $userWrite > 0) { - print ''.$langs->trans('AddTask').''; + $linktocreatetime = ''.$langs->trans('AddTimeSpent').''; } else { - print ''.$langs->trans('AddTask').''; + $linktocreatetime = ''.$langs->trans('AddTime').''; } } else { - print ''.$langs->trans('AddTask').''; + $linktocreatetime = ''.$langs->trans('AddTime').''; } - - print '
'; - } - else - { - print '
'; } } } @@ -528,12 +532,14 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) /* - * Form to add time spent + * Form to add time spent on task */ + if ($user->rights->projet->lire) { print '
'; + print ''."\n"; print ''; print ''; print ''; @@ -676,7 +682,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) $title=$langs->trans("ListTaskTimeUserProject"); $linktotasks=''.$langs->trans("GoToListOfTasks").''; //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'title_generic.png', 0, '', '', 0, 1); - print load_fiche_titre($title,$linktotasks,'title_generic.png'); + print load_fiche_titre($title,$linktotasks.'   '.$linktocreatetime,'title_generic.png'); } $i = 0; @@ -694,6 +700,88 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) } + /* + * Form to add time spent + */ + if ($action == 'createtime' && empty($id) && $user->rights->projet->lire) + { + print ''."\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + print ''; + + // Date + print ''; + + // Task + print ''; + + // Contributor + print ''; + + // Note + print ''; + + // Duration - Time spent + print ''; + + // Progress declared + print ''; + + print ''; + + print '
'.$langs->trans("Date").''.$langs->trans("Task").''.$langs->trans("By").''.$langs->trans("Note").''.$langs->trans("NewTimeSpent").''.$langs->trans("ProgressDeclared").'
'; + //$newdate=dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]); + $newdate=''; + print $form->select_date($newdate, 'time', ($conf->browser->layout == 'phone'?2:1), 1, 2, "timespent_date", 1, 0, 1); + print ''; + $formproject->selectTasks(-1, GETPOST('taskid','int'), 'taskid', 0, 0, 1, 1, 0, 0, 'maxwidth300', $projectstatic->id, ''); + print ''; + print img_object('','user','class="hideonsmartphone"'); + $contactsofproject=$projectstatic->getListContactId('internal'); + if (count($contactsofproject)>0) + { + if (in_array($user->id, $userid=$contactsofproject)) $userid = $user->id; + else $userid=$contactsofproject[0]; + if ($projectstatic->public) $contactsofproject = array(); + print $form->select_dolusers((GETPOST('userid')?GETPOST('userid'):$userid), 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 0, $langs->trans("ResourceNotAssignedToProject"), 'maxwidth200'); + } + else + { + print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime'); + } + print ''; + print ''; + print ''; + print $form->select_duration('timespent_duration', ($_POST['timespent_duration']?$_POST['timespent_duration']:''), 0, 'text'); + print ''; + print $formother->select_percent(GETPOST('progress')?GETPOST('progress'):$object->progress,'progress'); + print ''; + print ''; + print '   '; + print ''; + print '
'; + + print '
'; + } + + $arrayofselected=is_array($toselect)?$toselect:array(); $params='';