* Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/projet/tasks.php * \ingroup projet * \brief List all tasks of a project */ require ("../main.inc.php"); require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; 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'; $langs->load("users"); $langs->load("projects"); $action = GETPOST('action', 'alpha'); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $backtopage=GETPOST('backtopage','alpha'); $mode = GETPOST('mode', 'alpha'); $mine = ($mode == 'mine' ? 1 : 0); //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects $object = new Project($db); if ($ref) { $object->fetch(0,$ref); $id=$object->id; } // Security check $socid=0; if ($user->societe_id > 0) $socid = $user->societe_id; $result = restrictedArea($user, 'projet', $id); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('projecttaskcard')); $progress=GETPOST('progress', 'int'); $label=GETPOST('label', 'alpha'); $description=GETPOST('description'); $userAccess=0; /* * Actions */ if ($action == 'createtask' && $user->rights->projet->creer) { $error=0; $date_start = dol_mktime(0,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']); $date_end = dol_mktime(0,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']); if (empty($_POST["cancel"])) { if (empty($label)) { $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")); $action='create'; $error++; } else if (empty($_POST['task_parent'])) { $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("ChildOfTask")); $action='create'; $error++; } if (! $error) { $tmparray=explode('_',$_POST['task_parent']); $projectid=$tmparray[0]; if (empty($projectid)) $projectid = $id; // If projectid is '' $task_parent=$tmparray[1]; if (empty($task_parent)) $task_parent = 0; // If task_parent is '' $task = new Task($db); $task->fk_project = $projectid; $task->label = $label; $task->description = $description; $task->fk_task_parent = $task_parent; $task->date_c = dol_now(); $task->date_start = $date_start; $task->date_end = $date_end; $task->progress = $progress; $taskid = $task->create($user); if ($taskid > 0) { $result = $task->add_contact($_POST["userid"], 'TASKEXECUTIVE', 'internal'); } } if (! $error) { if (! empty($backtopage)) { header("Location: ".$backtopage); exit; } else if (empty($projectid)) { header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'.(empty($mode)?'':'?mode='.$mode)); exit; } } } else { if (! empty($backtopage)) { header("Location: ".$backtopage); exit; } else if (empty($id)) { // We go back on task list header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'.(empty($mode)?'':'?mode='.$mode)); exit; } } } /* * View */ $form=new Form($db); $formother=new FormOther($db); $taskstatic = new Task($db); $userstatic=new User($db); $help_url="EN:Module_Projects|FR:Module_Projets|ES:Módulo_Proyectos"; llxHeader("",$langs->trans("Tasks"),$help_url); if ($id > 0 || ! empty($ref)) { $object->fetch($id, $ref); if ($object->societe->id > 0) $result=$object->societe->fetch($object->societe->id); // To verify role of users //$userAccess = $object->restrictedProjectArea($user,'read'); $userWrite = $object->restrictedProjectArea($user,'write'); //$userDelete = $object->restrictedProjectArea($user,'delete'); //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete; $tab=GETPOST('tab')?GETPOST('tab'):'tasks'; $head=project_prepare_head($object); dol_fiche_head($head, $tab, $langs->trans("Project"),0,($object->public?'projectpub':'project')); $param=($mode=='mine'?'&mode=mine':''); print ''; $linkback = ''.$langs->trans("BackToList").''; // Ref print ''; print ''; print ''; print ''; // Visibility print ''; // Statut print ''; // Date start print ''; // Date end print ''; print '
'; print $langs->trans("Ref"); print ''; // Define a complementary filter for search of next/prev ref. if (! $user->rights->projet->all->lire) { $projectsListId = $object->getProjectsAuthorizedForUser($user,$mine,0); $object->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; } print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '', $param); print '
'.$langs->trans("Label").''.$object->title.'
'.$langs->trans("Company").''; if (! empty($object->societe->id)) print $object->societe->getNomUrl(1); else print ' '; print '
'.$langs->trans("Visibility").''; if ($object->public) print $langs->trans('SharedProject'); else print $langs->trans('PrivateProject'); print '
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("DateStart").''; print dol_print_date($object->date_start,'day'); print '
'.$langs->trans("DateEnd").''; print dol_print_date($object->date_end,'day'); print '
'; dol_fiche_end(); } if ($action == 'create' && $user->rights->projet->creer && (empty($object->societe->id) || $userWrite > 0)) { if ($id > 0 || ! empty($ref)) print '
'; print_fiche_titre($langs->trans("NewTask")); dol_htmloutput_errors($mesg); print '
'; print ''; print ''; print ''; if (! empty($object->id)) print ''; if (! empty($mode)) print ''; print ''; print ''; // List of projects print ''; print ''; // Date start print ''; // Date end print ''; // Progress print ''; // Description print ''; print ''; // Other options $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print '
'.$langs->trans("Label").''; print ''; print '
'.$langs->trans("ChildOfTask").''; print $formother->selectProjectTasks('',$projectid?$projectid:$object->id, 'task_parent', 0, 0, 1, 1); print '
'.$langs->trans("AffectedTo").''; print $form->select_users($user->id,'userid',1); print '
'.$langs->trans("DateStart").''; print $form->select_date(($date_start?$date_start:''),'dateo',0,0,0,'',1,1); print '
'.$langs->trans("DateEnd").''; print $form->select_date(($date_end?$date_end:-1),'datee',0,0,0,'',1,1); print '
'.$langs->trans("Progress").''; print $formother->select_percent($progress,'progress'); print '
'.$langs->trans("Description").''; print ''; print '
'; print '

'; print ''; print '     '; print ''; print '
'; print '
'; } else { /* * Fiche projet en mode visu */ /* * Actions */ print '
'; if ($user->rights->projet->all->creer || $user->rights->projet->creer) { if ($object->public || $userWrite > 0) { print ''.$langs->trans('AddTask').''; } else { print ''.$langs->trans('AddTask').''; } } else { print ''.$langs->trans('AddTask').''; } print '
'; print '
'; // Link to switch in "my task" / "all task" print '
'; if ($mode == 'mine') { print ''.$langs->trans("DoNotShowMyTasksOnly").''; //print ' - '; //print $langs->trans("ShowMyTaskOnly"); } else { //print $langs->trans("DoNotShowMyTaskOnly"); //print ' - '; print ''.$langs->trans("ShowMyTasksOnly").''; } print '
'; // 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). $tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $socid, 0); // We load also tasks limited to a particular user $tasksrole=($mode=='mine' ? $taskstatic->getUserRolesForProjectsOrTasks(0,$user,$object->id,0) : ''); //var_dump($tasksarray); //var_dump($tasksrole); if (! empty($conf->use_javascript_ajax)) { include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; } print ''; print ''; // print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; if (count($tasksarray) > 0) { // Show all lines in taskarray (recursive function to go down on tree) $j=0; $nboftaskshown=projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, '', 1); } else { print ''; } print "
'.$langs->trans("Project").''.$langs->trans("RefTask").''.$langs->trans("LabelTask").''.$langs->trans("DateStart").''.$langs->trans("DateEnd").''.$langs->trans("Progress").''.$langs->trans("TimeSpent").' 
'.$langs->trans("NoTasks").'
"; // Test if database is clean. If not we clean it. //print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'
'; if ($mode=='mine') { if ($nboftaskshown < count($tasksrole)) clean_orphelins($db); } else { if ($nboftaskshown < count($tasksarray)) clean_orphelins($db); } } llxFooter(); $db->close(); ?>