* Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2010 François Legastelois * * 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/activity/perday.php * \ingroup projet * \brief List activities of tasks (per day entry) */ 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'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; $langs->load('projects'); $action=GETPOST('action'); $mode=GETPOST("mode"); $id=GETPOST('id','int'); $taskid=GETPOST('taskid'); $mine=0; if ($mode == 'mine') $mine=1; $projectid=''; $projectid=isset($_GET["id"])?$_GET["id"]:$_POST["projectid"]; // Security check $socid=0; if ($user->societe_id > 0) $socid=$user->societe_id; $result = restrictedArea($user, 'projet', $projectid); $now=dol_now(); $nowtmp=dol_getdate($now); $nowday=$nowtmp['mday']; $nowmonth=$nowtmp['mon']; $nowyear=$nowtmp['year']; $year=GETPOST('reyear')?GETPOST('reyear'):(GETPOST("year","int")?GETPOST("year","int"):date("Y")); $month=GETPOST('remonth')?GETPOST('remonth'):(GETPOST("month","int")?GETPOST("month","int"):date("m")); $day=GETPOST('reday')?GETPOST('reday'):(GETPOST("day","int")?GETPOST("day","int"):date("d")); $day = (int) $day; $week=GETPOST("week","int")?GETPOST("week","int"):date("W"); $monthofday=GETPOST('addtimemonth'); $dayofday=GETPOST('addtimeday'); $yearofday=GETPOST('addtimeyear'); $daytoparse = $now; if ($yearofday && $monthofday && $dayofday) $daytoparse=dol_mktime(0, 0, 0, $monthofday, $dayofday, $yearofday); // xxxofday is value of day after submit action 'addtime' else if ($year && $month && $day) $daytoparse=dol_mktime(0, 0, 0, $month, $day, $year); // this are value submited after submit of action 'submitdateselect' $object=new Task($db); /* * Actions */ if (GETPOST('submitdateselect')) { $daytoparse = dol_mktime(0, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $action = ''; } if ($action == 'assign') { if ($taskid > 0) { $result = $object->fetch($taskid, $ref); if ($result < 0) $error++; } else { setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Task")), '', 'errors'); $error++; } if (! GETPOST('type')) { setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), '', 'errors'); $error++; } if (! $error) { $idfortaskuser=$user->id; $result = $object->add_contact($idfortaskuser, GETPOST("type"), 'internal'); } if ($result < 0) { $error++; if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'warnings'); } else { setEventMessages($object->error, $object->errors, 'errors'); } } if (! $error) { setEventMessages("TaskAssignedToEnterTime", null); } $action=''; } if ($action == 'addtime' && $user->rights->projet->creer) { $timespent_duration=array(); foreach($_POST as $key => $time) { if (intval($time) > 0) { // Hours or minutes of duration if (preg_match("/([0-9]+)duration(hour|min)/",$key,$matches)) { $id = $matches[1]; if ($id > 0) { // We store HOURS in seconds if($matches[2]=='hour') $timespent_duration[$id] += $time*60*60; // We store MINUTES in seconds if($matches[2]=='min') $timespent_duration[$id] += $time*60; } } } } if (count($timespent_duration) > 0) { foreach($timespent_duration as $key => $val) { $object->fetch($key); $object->progress = GETPOST($key . 'progress', 'int'); $object->timespent_duration = $val; $object->timespent_fk_user = $user->id; if (GETPOST($key."hour") != '' && GETPOST($key."hour") >= 0) // If hour was entered { $object->timespent_date = dol_mktime(GETPOST($key."hour"),GETPOST($key."min"),0,$monthofday,$dayofday,$yearofday); $object->timespent_withhour = 1; } else { $object->timespent_date = dol_mktime(12,0,0,$monthofday,$dayofday,$yearofday); } if ($object->timespent_date > 0) { $result=$object->addTimeSpent($user); } else { setEventMessages("ErrorBadDate", null, 'errors'); $error++; break; } if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; break; } } if (! $error) { setEventMessage($langs->trans("RecordSaved")); // Redirect to avoid submit twice on back header('Location: '.$_SERVER["PHP_SELF"].($projectid?'?id='.$projectid:'?').($mode?'&mode='.$mode:'').'&year='.$yearofday.'&month='.$monthofday.'&day='.$dayofday); exit; } } else { setEventMessage($langs->trans("ErrorTimeSpentIsEmpty"), 'errors'); } } /* * View */ $form=new Form($db); $formother = new FormOther($db); $formcompany=new FormCompany($db); $formproject=new FormProjets($db); $projectstatic=new Project($db); $project = new Project($db); $taskstatic = new Task($db); $prev = dol_getdate($daytoparse - (24 * 3600)); $prev_year = $prev['year']; $prev_month = $prev['mon']; $prev_day = $prev['mday']; $next = dol_getdate($daytoparse + (24 * 3600)); $next_year = $next['year']; $next_month = $next['mon']; $next_day = $next['mday']; $title=$langs->trans("TimeSpent"); if ($mine) $title=$langs->trans("MyTimeSpent"); $usertoprocess = $user; $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertoprocess,0,1); // Return all project i have permission on. I want my tasks and some of my task may be on a public projet that is not my project if ($id) { $project->fetch($id); $project->fetch_thirdparty(); } $onlyopened=1; // or -1 $tasksarray=$taskstatic->getTasksArray(0,0,($project->id?$project->id:$projectsListId),$socid,0,'',$onlyopened); // We want to see all task of opened project i am allowed to see, not only mine. Later only mine will be editable later. $projectsrole=$taskstatic->getUserRolesForProjectsOrTasks($usertoprocess,0,($project->id?$project->id:$projectsListId),0); $tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0,$usertoprocess,($project->id?$project->id:$projectsListId),0); //var_dump($tasksarray); //var_dump($projectsrole); //var_dump($taskrole); llxHeader("",$title,""); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num, '', 'title_project'); $param=($mode?'&mode='.$mode:''); // Show navigation bar $nav ="".img_previous($langs->trans("Previous"))."\n"; $nav.=" ".dol_print_date(dol_mktime(0,0,0,$month,$day,$year),"day")." \n"; $nav.="".img_next($langs->trans("Next"))."\n"; $nav.="   (".$langs->trans("Today").")"; $nav.='
'.$form->select_date(-1,'',0,0,2,"addtime",1,0,1).' '; $nav.=' '; $picto='calendarweek'; print '
id > 0 ? '?id='.$project->id : '').'">'; print ''; print ''; print ''; $tmp = dol_getdate($daytoparse); print ''; print ''; print ''; $head=project_timesheet_prepare_head($mode); dol_fiche_head($head, 'inputperday', '', 0, 'task'); // Show description of content if ($mine) print $langs->trans("MyTasksDesc").($onlyopened?' '.$langs->trans("OnlyOpenedProject"):'').'
'; else { if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").($onlyopened?' '.$langs->trans("OnlyOpenedProject"):'').'
'; else print $langs->trans("ProjectsPublicTaskDesc").($onlyopened?' '.$langs->trans("AlsoOnlyOpenedProject"):'').'
'; } if ($mine) { print $langs->trans("OnlyYourTaskAreVisible").'
'; } else { print $langs->trans("AllTaskVisibleButEditIfYouAreAssigned").'
'; } print '
'; print "\n"; // Filter on user /* dol_fiche_head(''); print ''; print ''; print '
'.$langs->trans("User").''; if ($mine) print $user->getLoginUrl(1); print '
'; dol_fiche_end(); */ // Filter on user /* dol_fiche_head(''); print ''; print ''; print '
'.$langs->trans("User").''; if ($mine) print $user->getLoginUrl(1); print '
'; dol_fiche_end(); */ print '
'.$nav.'
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($usertoprocess->id == $user->id) print ''; else print ''; print ''; print ''; print "\n"; // By default, we can edit only tasks we are assigned to $restrictviewformytask=(empty($conf->global->PROJECT_TIME_SHOW_TASK_NOT_ASSIGNED)?1:0); if (count($tasksarray) > 0) { $j=0; projectLinesPerDay($j, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask, $daytoparse); } else { print ''; } print "
'.$langs->trans("Project").''.$langs->trans("RefTask").''.$langs->trans("LabelTask").''.$langs->trans("PlannedWorkload").''.$langs->trans("ProgressDeclared").''.$langs->trans("TimeSpent").''.$langs->trans("TimeSpentByYou").''.$langs->trans("TimeSpentByUser").''.$langs->trans("HourStart").''.$langs->trans("Duration").'
'.$langs->trans("NoTasks").'
"; dol_fiche_end(); print '
'; print ''; print '
'; print '
'; print ''; // Add a new project/task print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print $langs->trans("AssignTaskToMe").'
'; $formproject->selectTasks($socid?$socid:-1, $taskid, 'taskid', 32, 0, 1, 1); print $formcompany->selectTypeContact($object, '', 'type','internal','rowid', 1); print ''; print '
'; llxFooter(); $db->close();