2008-09-10 22:49:21 +02:00
< ? php
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2013-11-05 11:17:54 +01:00
* Copyright ( C ) 2004 - 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2010 Regis Houssin < regis . houssin @ capnetworks . com >
2010-11-06 21:55:52 +01:00
* Copyright ( C ) 2010 François Legastelois < flegastelois @ teclib . com >
2008-09-10 22:49:21 +02:00
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2008-09-10 22:49:21 +02:00
* ( 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
2011-08-01 01:19:04 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2008-09-10 22:49:21 +02:00
*/
/**
2010-02-21 01:16:47 +01:00
* \file htdocs / projet / activity / list . php
2008-09-10 22:49:21 +02:00
* \ingroup projet
2010-02-21 01:16:47 +01:00
* \brief List activities of tasks
2008-09-10 22:49:21 +02:00
*/
2010-03-01 09:42:10 +01:00
require ( " ../../main.inc.php " );
2012-08-22 23:11:24 +02:00
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' ;
2010-03-01 20:36:58 +01:00
$langs -> load ( 'projects' );
2008-09-10 22:49:21 +02:00
2012-02-15 23:08:20 +01:00
$action = GETPOST ( 'action' );
2011-12-04 15:26:32 +01:00
$mode = GETPOST ( " mode " );
2012-02-27 22:26:22 +01:00
$id = GETPOST ( 'id' , 'int' );
2008-09-10 22:49:21 +02:00
2010-09-18 15:38:43 +02:00
$mine = 0 ;
if ( $mode == 'mine' ) $mine = 1 ;
2010-01-22 21:20:41 +01:00
$projectid = '' ;
2010-01-27 08:58:31 +01:00
$projectid = isset ( $_GET [ " id " ]) ? $_GET [ " id " ] : $_POST [ " projectid " ];
2008-09-10 22:49:21 +02:00
// Security check
2010-02-14 16:43:37 +01:00
$socid = 0 ;
2010-05-30 14:21:32 +02:00
if ( $user -> societe_id > 0 ) $socid = $user -> societe_id ;
2010-01-22 21:20:41 +01:00
$result = restrictedArea ( $user , 'projet' , $projectid );
2008-09-10 22:49:21 +02:00
2011-12-04 15:26:32 +01:00
2008-09-10 22:49:21 +02:00
/*
* Actions
*/
2012-02-15 23:08:20 +01:00
if ( $action == 'addtime' && $user -> rights -> projet -> creer )
2008-09-10 22:49:21 +02:00
{
2011-09-20 17:59:46 +02:00
$task = new Task ( $db );
2013-11-05 11:17:54 +01:00
$timespent_duration = array ();
2011-09-20 17:59:46 +02:00
foreach ( $_POST as $key => $time )
{
2013-11-05 11:17:54 +01:00
if ( intval ( $time ) > 0 )
2011-09-20 17:59:46 +02:00
{
// Hours or minutes
2013-11-05 11:17:54 +01:00
if ( preg_match ( " /([0-9]+)(hour|min)/ " , $key , $matches ))
2011-09-20 17:59:46 +02:00
{
$id = $matches [ 1 ];
2013-11-05 11:17:54 +01:00
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 ;
}
2011-09-20 17:59:46 +02:00
}
}
}
2013-11-05 11:17:54 +01:00
if ( count ( $timespent_duration ) > 0 )
2011-09-20 17:59:46 +02:00
{
2013-11-05 11:17:54 +01:00
foreach ( $timespent_duration as $key => $val )
{
$task -> fetch ( $key );
$task -> timespent_duration = $val ;
$task -> timespent_fk_user = $user -> id ;
$task -> timespent_date = dol_mktime ( 12 , 0 , 0 , $_POST [ " { $key } month " ], $_POST [ " { $key } day " ], $_POST [ " { $key } year " ]);
$task -> addTimeSpent ( $user );
}
setEventMessage ( $langs -> trans ( " RecordSaved " ));
// Redirect to avoid submit twice on back
2012-02-15 23:08:20 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $projectid . ( $mode ? '&mode=' . $mode : '' ));
2011-12-04 15:26:32 +01:00
exit ;
2011-09-20 17:59:46 +02:00
}
else
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorTimeSpentIsEmpty " ) . '</div>' ;
}
}
2008-09-10 22:49:21 +02:00
/*
* View
*/
$form = new Form ( $db );
2010-09-18 15:38:43 +02:00
$projectstatic = new Project ( $db );
$project = new Project ( $db );
$taskstatic = new Task ( $db );
2008-09-10 22:49:21 +02:00
$title = $langs -> trans ( " TimeSpent " );
2010-09-18 15:38:43 +02:00
if ( $mine ) $title = $langs -> trans ( " MyTimeSpent " );
2008-09-10 22:49:21 +02:00
llxHeader ( " " , $title , " " );
2010-09-18 15:38:43 +02:00
//$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1);
$projectsListId = $projectstatic -> getProjectsAuthorizedForUser ( $user , 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
2010-01-27 08:58:31 +01:00
2012-02-15 23:08:20 +01:00
if ( $id )
2008-09-10 22:49:21 +02:00
{
2012-02-15 23:08:20 +01:00
$project -> fetch ( $id );
2011-09-20 17:59:46 +02:00
$project -> societe -> fetch ( $project -> societe -> id );
2008-09-10 22:49:21 +02:00
}
2010-09-18 15:38:43 +02:00
$tasksarray = $taskstatic -> getTasksArray ( 0 , 0 ,( $project -> id ? $project -> id : $projectsListId ), $socid , 0 ); // We want to see all task of project i am allowed to see, not only mine. Later only mine will be editable later.
$projectsrole = $taskstatic -> getUserRolesForProjectsOrTasks ( $user , 0 ,( $project -> id ? $project -> id : $projectsListId ), 0 );
$tasksrole = $taskstatic -> getUserRolesForProjectsOrTasks ( 0 , $user ,( $project -> id ? $project -> id : $projectsListId ), 0 );
//var_dump($tasksarray);
//var_dump($projectsrole);
//var_dump($taskrole);
2008-09-10 22:49:21 +02:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], " " , $sortfield , $sortorder , " " , $num );
2011-12-04 15:26:32 +01:00
dol_htmloutput_mesg ( $mesg );
2008-09-10 22:49:21 +02:00
2010-01-27 08:58:31 +01:00
print '<form name="addtime" method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $project -> id . '">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2008-09-10 22:49:21 +02:00
print '<input type="hidden" name="action" value="addtime">' ;
2012-02-15 23:08:20 +01:00
print '<input type="hidden" name="mode" value="' . $mode . '">' ;
2008-09-10 22:49:21 +02:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2010-02-21 01:16:47 +01:00
print '<td>' . $langs -> trans ( " Project " ) . '</td>' ;
2008-09-10 22:49:21 +02:00
print '<td>' . $langs -> trans ( " RefTask " ) . '</td>' ;
print '<td>' . $langs -> trans ( " LabelTask " ) . '</td>' ;
2012-02-15 23:08:20 +01:00
print '<td align="center">' . $langs -> trans ( " DateStart " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " DateEnd " ) . '</td>' ;
2013-11-05 11:17:54 +01:00
print '<td align="right">' . $langs -> trans ( " PlannedWorkload " ) . '</td>' ;
2012-02-15 23:08:20 +01:00
print '<td align="right">' . $langs -> trans ( " Progress " ) . '</td>' ;
2008-09-10 22:49:21 +02:00
print '<td align="right">' . $langs -> trans ( " TimeSpent " ) . '</td>' ;
print '<td colspan="2">' . $langs -> trans ( " AddDuration " ) . '</td>' ;
print " </tr> \n " ;
2012-02-15 13:55:00 +01:00
projectLinesb ( $j , 0 , $tasksarray , $level , $projectsrole , $tasksrole , $mine );
2008-09-10 22:49:21 +02:00
print " </table> " ;
2012-02-15 23:08:20 +01:00
print '</form>' ;
2008-09-10 22:49:21 +02:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2011-12-04 15:26:32 +01:00
$db -> close ();
2008-09-10 22:49:21 +02:00
?>