2005-08-22 19:10:46 +02:00
< ? php
/* Copyright ( C ) 2001 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2015-06-15 00:12:52 +02:00
* Copyright ( C ) 2006 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2010 Regis Houssin < regis . houssin @ capnetworks . com >
2005-08-22 19:10:46 +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
2005-08-22 19:10:46 +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 />.
2005-08-22 19:10:46 +02:00
*/
/**
2010-02-20 21:24:09 +01:00
* \file htdocs / projet / activity / index . php
2009-06-11 03:19:42 +02:00
* \ingroup projet
* \brief Page activite perso du module projet
2009-01-15 00:36:51 +01:00
*/
2005-08-22 19:10:46 +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' ;
2005-08-22 19:10:46 +02:00
2017-07-31 04:52:27 +02:00
$search_project_user = GETPOST ( 'search_project_user' , 'int' );
$mine = GETPOST ( 'mode' , 'aZ09' ) == 'mine' ? 1 : 0 ;
if ( $search_project_user == $user -> id ) $mine = 1 ;
2008-09-10 22:49:21 +02:00
// Security check
2010-05-30 14:21:32 +02:00
$socid = 0 ;
if ( $user -> societe_id > 0 ) $socid = $user -> societe_id ;
//$result = restrictedArea($user, 'projet', $projectid);
2008-09-10 22:49:21 +02:00
if ( ! $user -> rights -> projet -> lire ) accessforbidden ();
2010-05-30 14:21:32 +02:00
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
2008-09-10 22:49:21 +02:00
$langs -> load ( " projects " );
/*
* View
*/
2005-08-22 19:10:46 +02:00
2010-05-30 14:21:32 +02:00
$now = dol_now ();
2016-02-27 18:42:57 +01:00
$tmp = dol_getdate ( $now );
$day = $tmp [ 'mday' ];
$month = $tmp [ 'mon' ];
$year = $tmp [ 'year' ];
2009-01-15 00:36:51 +01:00
$projectstatic = new Project ( $db );
2016-01-18 16:43:15 +01:00
$taskstatic = new Task ( $db );
2011-04-20 01:21:10 +02:00
$projectsListId = $projectstatic -> getProjectsAuthorizedForUser ( $user , 0 , 1 ); // Return all projects I have permission on because I want my tasks and some of my task may be on a public projet that is not my project
2016-02-27 17:56:59 +01:00
$taskstatic = new Task ( $db );
2015-07-04 18:20:17 +02:00
$tasktmp = new Task ( $db );
2010-02-07 10:49:10 +01:00
$title = $langs -> trans ( " Activities " );
2017-03-14 13:49:04 +01:00
//if ($mine) $title=$langs->trans("MyActivities");
2008-09-10 22:49:21 +02:00
llxHeader ( " " , $title );
2006-06-03 18:50:58 +02:00
2017-03-14 13:49:04 +01:00
// Title for combo list see all projects
$titleall = $langs -> trans ( " AllAllowedProjects " );
if ( ! empty ( $user -> rights -> projet -> all -> lire ) && ! $socid ) $titleall = $langs -> trans ( " AllProjects " );
else $titleall = $langs -> trans ( " AllAllowedProjects " ) . '<br><br>' ;
$morehtml = '' ;
$morehtml .= '<form name="projectform">' ;
$morehtml .= '<SELECT name="mode">' ;
$morehtml .= '<option name="all" value="all"' . ( $mine ? '' : ' selected' ) . '>' . $titleall . '</option>' ;
2017-07-31 06:20:32 +02:00
$morehtml .= '<option name="mine" value="' . $user -> id . '"' . (( $search_project_user == $user -> id ) ? ' selected' : '' ) . '>' . $langs -> trans ( " ProjectsImContactFor " ) . '</option>' ;
2017-03-14 13:49:04 +01:00
$morehtml .= '</SELECT>' ;
$morehtml .= '<input type="submit" class="button" name="refresh" value="' . $langs -> trans ( " Refresh " ) . '">' ;
print_barre_liste ( $title , 0 , $_SERVER [ " PHP_SELF " ], '' , '' , '' , '' , 0 , - 1 , 'title_project.png' , 0 , $morehtml );
//print load_fiche_titre($title, '', 'title_project');
2005-08-22 19:10:46 +02:00
2010-02-20 21:24:09 +01:00
if ( $mine ) print $langs -> trans ( " MyTasksDesc " ) . '<br><br>' ;
else
{
if ( $user -> rights -> projet -> all -> lire && ! $socid ) print $langs -> trans ( " TasksDesc " ) . '<br><br>' ;
else print $langs -> trans ( " TasksPublicDesc " ) . '<br><br>' ;
}
2013-04-12 16:16:39 +02:00
2013-06-05 16:24:32 +02:00
print '<div class="fichecenter"><div class="fichethirdleft">' ;
2013-04-12 16:16:39 +02:00
2015-10-17 02:41:09 +02:00
2017-02-21 14:17:44 +01:00
if ( ! empty ( $conf -> global -> MAIN_SEARCH_FORM_ON_HOME_AREAS )) // This is useless due to the global search combo
2015-10-17 02:41:09 +02:00
{
2017-02-21 14:17:44 +01:00
// Search project
if ( ! empty ( $conf -> projet -> enabled ) && $user -> rights -> projet -> lire )
{
$listofsearchfields [ 'search_task' ] = array ( 'text' => 'Task' );
}
2017-07-31 04:52:27 +02:00
2017-02-21 14:17:44 +01:00
if ( count ( $listofsearchfields ))
{
print '<form method="post" action="' . DOL_URL_ROOT . '/core/search.php">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="noborder nohover centpercent">' ;
$i = 0 ;
foreach ( $listofsearchfields as $key => $value )
{
if ( $i == 0 ) print '<tr class="liste_titre"><td colspan="3">' . $langs -> trans ( " Search " ) . '</td></tr>' ;
print '<tr ' . $bc [ false ] . '>' ;
print '<td class="nowrap"><label for="' . $key . '">' . $langs -> trans ( $value [ " text " ]) . '</label></td><td><input type="text" class="flat inputsearch" name="' . $key . '" id="' . $key . '" size="18"></td>' ;
if ( $i == 0 ) print '<td rowspan="' . count ( $listofsearchfields ) . '"><input type="submit" value="' . $langs -> trans ( " Search " ) . '" class="button"></td>' ;
print '</tr>' ;
$i ++ ;
}
2017-07-31 04:52:27 +02:00
print '</table>' ;
2017-02-21 14:17:44 +01:00
print '</form>' ;
print '<br>' ;
}
2015-07-04 18:20:17 +02:00
}
2009-01-15 00:36:51 +01:00
2005-08-22 19:10:46 +02:00
2008-09-10 22:49:21 +02:00
/* Affichage de la liste des projets d'aujourd'hui */
2015-10-17 02:41:09 +02:00
print '<table class="noborder" width="100%">' ;
2008-09-10 22:49:21 +02:00
print '<tr class="liste_titre">' ;
2015-07-04 18:20:17 +02:00
print '<td width="50%">' . $langs -> trans ( 'ActivityOnProjectToday' ) . '</td>' ;
2008-09-10 22:49:21 +02:00
print '<td width="50%" align="right">' . $langs -> trans ( " Time " ) . '</td>' ;
print " </tr> \n " ;
2005-08-22 19:10:46 +02:00
2016-02-27 19:20:11 +01:00
$sql = " SELECT p.rowid, p.ref, p.title, p.public, SUM(tt.task_duration) as nb " ;
2010-01-27 09:06:44 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet as p " ;
$sql .= " , " . MAIN_DB_PREFIX . " projet_task as t " ;
$sql .= " , " . MAIN_DB_PREFIX . " projet_task_time as tt " ;
$sql .= " WHERE t.fk_projet = p.rowid " ;
$sql .= " AND p.entity = " . $conf -> entity ;
$sql .= " AND tt.fk_task = t.rowid " ;
$sql .= " AND tt.fk_user = " . $user -> id ;
2016-03-02 23:40:11 +01:00
$sql .= " AND task_date BETWEEN ' " . $db -> idate ( dol_mktime ( 0 , 0 , 0 , $month , $day , $year )) . " ' AND ' " . $db -> idate ( dol_mktime ( 23 , 59 , 59 , $month , $day , $year )) . " ' " ;
2011-04-20 00:46:28 +02:00
$sql .= " AND p.rowid in ( " . $projectsListId . " ) " ;
2016-02-27 19:20:11 +01:00
$sql .= " GROUP BY p.rowid, p.ref, p.title, p.public " ;
2010-01-27 09:06:44 +01:00
2008-09-10 22:49:21 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
2010-01-27 09:06:44 +01:00
$total = 0 ;
2010-02-20 21:24:09 +01:00
2009-01-15 00:36:51 +01:00
while ( $row = $db -> fetch_object ( $resql ))
{
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2009-01-15 00:36:51 +01:00
print '<td>' ;
$projectstatic -> id = $row -> rowid ;
$projectstatic -> ref = $row -> ref ;
2015-06-15 00:12:52 +02:00
$projectstatic -> title = $row -> title ;
2016-02-27 19:20:11 +01:00
$projectstatic -> public = $row -> public ;
2015-06-15 00:12:52 +02:00
print $projectstatic -> getNomUrl ( 1 , '' , 1 );
2009-01-15 00:36:51 +01:00
print '</td>' ;
2016-02-27 17:56:59 +01:00
print '<td align="right">' . convertSecondToTime ( $row -> nb , 'allhourmin' ) . '</td>' ;
2009-01-15 00:36:51 +01:00
print " </tr> \n " ;
$total += $row -> nb ;
}
$db -> free ( $resql );
2008-09-10 22:49:21 +02:00
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2008-09-10 22:49:21 +02:00
}
print '<tr class="liste_total">' ;
print '<td>' . $langs -> trans ( 'Total' ) . '</td>' ;
2016-02-27 17:56:59 +01:00
print '<td align="right">' . convertSecondToTime ( $total , 'allhourmin' ) . '</td>' ;
2009-01-15 00:36:51 +01:00
print " </tr> \n " ;
2008-09-10 22:49:21 +02:00
print " </table> " ;
2007-09-24 19:50:49 +02:00
2015-07-04 18:20:17 +02:00
2017-02-21 14:17:44 +01:00
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">' ;
2016-03-02 23:40:11 +01:00
/* Affichage de la liste des projets d'hier */
2017-02-21 14:17:44 +01:00
print '<table class="noborder" width="100%">' ;
2016-03-02 23:40:11 +01:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'ActivityOnProjectYesterday' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " Time " ) . '</td>' ;
print " </tr> \n " ;
2015-07-04 18:20:17 +02:00
2016-03-02 23:40:11 +01:00
$sql = " SELECT p.rowid, p.ref, p.title, p.public, SUM(tt.task_duration) as nb " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " projet as p " ;
$sql .= " , " . MAIN_DB_PREFIX . " projet_task as t " ;
$sql .= " , " . MAIN_DB_PREFIX . " projet_task_time as tt " ;
$sql .= " WHERE t.fk_projet = p.rowid " ;
$sql .= " AND p.entity = " . $conf -> entity ;
$sql .= " AND tt.fk_task = t.rowid " ;
$sql .= " AND tt.fk_user = " . $user -> id ;
$sql .= " AND task_date BETWEEN ' " . $db -> idate ( dol_time_plus_duree ( dol_mktime ( 0 , 0 , 0 , $month , $day , $year ), - 1 , 'd' )) . " ' AND ' " . $db -> idate ( dol_time_plus_duree ( dol_mktime ( 23 , 59 , 59 , $month , $day , $year ), - 1 , 'd' )) . " ' " ;
$sql .= " AND p.rowid in ( " . $projectsListId . " ) " ;
$sql .= " GROUP BY p.rowid, p.ref, p.title, p.public " ;
2015-07-04 18:20:17 +02:00
2016-03-02 23:40:11 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$total = 0 ;
2015-07-04 18:20:17 +02:00
2016-03-02 23:40:11 +01:00
while ( $row = $db -> fetch_object ( $resql ))
2015-07-04 18:20:17 +02:00
{
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2016-03-02 23:40:11 +01:00
print '<td>' ;
$projectstatic -> id = $row -> rowid ;
$projectstatic -> ref = $row -> ref ;
$projectstatic -> title = $row -> title ;
$projectstatic -> public = $row -> public ;
print $projectstatic -> getNomUrl ( 1 , '' , 1 );
print '</td>' ;
print '<td align="right">' . convertSecondToTime ( $row -> nb , 'allhourmin' ) . '</td>' ;
print " </tr> \n " ;
$total += $row -> nb ;
2015-07-04 18:20:17 +02:00
}
2016-03-02 23:40:11 +01:00
$db -> free ( $resql );
2011-07-04 12:56:12 +02:00
}
2016-03-02 23:40:11 +01:00
else
{
dol_print_error ( $db );
}
print '<tr class="liste_total">' ;
print '<td>' . $langs -> trans ( 'Total' ) . '</td>' ;
print '<td align="right">' . convertSecondToTime ( $total , 'allhourmin' ) . '</td>' ;
print " </tr> \n " ;
print " </table> " ;
2011-07-04 12:56:12 +02:00
2016-02-27 18:29:01 +01:00
/*
2011-07-04 12:56:12 +02:00
if ( $db -> type != 'pgsql' )
2016-01-21 14:13:38 +01:00
{
2016-01-18 16:43:15 +01:00
print '<br>' ;
2017-07-31 04:52:27 +02:00
2016-02-27 18:29:01 +01:00
// Affichage de la liste des projets de la semaine
2016-01-18 16:43:15 +01:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " ActivityOnProjectThisWeek " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " Time " ) . '</td>' ;
print " </tr> \n " ;
2017-07-31 04:52:27 +02:00
2016-02-27 19:20:11 +01:00
$sql = " SELECT p.rowid, p.ref, p.title, p.public, SUM(tt.task_duration) as nb " ;
2016-01-18 16:43:15 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet as p " ;
$sql .= " , " . MAIN_DB_PREFIX . " projet_task as t " ;
$sql .= " , " . MAIN_DB_PREFIX . " projet_task_time as tt " ;
$sql .= " WHERE t.fk_projet = p.rowid " ;
$sql .= " AND p.entity = " . $conf -> entity ;
$sql .= " AND tt.fk_task = t.rowid " ;
$sql .= " AND tt.fk_user = " . $user -> id ;
2016-02-27 18:42:57 +01:00
$sql .= " AND task_date >= ' " . $db -> idate ( dol_get_first_day ( $year , $month )) . ' " AND ... " ;
2016-01-18 16:43:15 +01:00
$sql .= " AND p.rowid in ( " . $projectsListId . " ) " ;
$sql .= " GROUP BY p.rowid, p.ref, p.title " ;
2017-07-31 04:52:27 +02:00
2016-01-18 16:43:15 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$total = 0 ;
2017-07-31 04:52:27 +02:00
2016-01-18 16:43:15 +01:00
while ( $row = $db -> fetch_object ( $resql ))
{
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2016-01-18 16:43:15 +01:00
print '<td>' ;
$projectstatic -> id = $row -> rowid ;
$projectstatic -> ref = $row -> ref ;
$projectstatic -> title = $row -> title ;
2016-02-27 19:20:11 +01:00
$projectstatic -> public = $row -> public ;
2016-01-18 16:43:15 +01:00
print $projectstatic -> getNomUrl ( 1 , '' , 1 );
print '</td>' ;
2016-02-27 18:29:01 +01:00
print '<td align="right">' . convertSecondToTime ( $row -> nb , 'allhourmin' ) . '</td>' ;
2016-01-18 16:43:15 +01:00
print " </tr> \n " ;
$total += $row -> nb ;
}
2017-07-31 04:52:27 +02:00
2016-01-18 16:43:15 +01:00
$db -> free ( $resql );
}
else
{
dol_print_error ( $db );
}
print '<tr class="liste_total">' ;
print '<td>' . $langs -> trans ( 'Total' ) . '</td>' ;
2016-02-27 18:29:01 +01:00
print '<td align="right">' . convertSecondToTime ( $total , 'allhourmin' ) . '</td>' ;
2016-01-18 16:43:15 +01:00
print " </tr> \n " ;
print " </table><br> " ;
2009-01-15 00:36:51 +01:00
2011-07-04 12:56:12 +02:00
}
2016-02-27 18:29:01 +01:00
*/
2011-07-04 12:56:12 +02:00
2005-08-22 19:10:46 +02:00
/* Affichage de la liste des projets du mois */
2016-01-21 14:13:38 +01:00
if ( ! empty ( $conf -> global -> PROJECT_TASK_TIME_MONTH ))
2005-08-22 19:10:46 +02:00
{
2016-01-21 14:13:38 +01:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " ActivityOnProjectThisMonth " ) . ': ' . dol_print_date ( $now , " %B %Y " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " Time " ) . '</td>' ;
print " </tr> \n " ;
2017-07-31 04:52:27 +02:00
2016-03-02 23:40:11 +01:00
$sql = " SELECT p.rowid, p.ref, p.title, p.public, SUM(tt.task_duration) as nb " ;
2016-01-21 14:13:38 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet as p " ;
$sql .= " , " . MAIN_DB_PREFIX . " projet_task as t " ;
$sql .= " , " . MAIN_DB_PREFIX . " projet_task_time as tt " ;
$sql .= " WHERE t.fk_projet = p.rowid " ;
$sql .= " AND p.entity = " . $conf -> entity ;
$sql .= " AND tt.fk_task = t.rowid " ;
$sql .= " AND tt.fk_user = " . $user -> id ;
2016-03-02 23:40:11 +01:00
$sql .= " AND task_date BETWEEN ' " . $db -> idate ( dol_get_first_day ( $year , $month )) . " ' AND ' " . $db -> idate ( dol_get_last_day ( $year , $month )) . " ' " ;
2016-01-21 14:13:38 +01:00
$sql .= " AND p.rowid in ( " . $projectsListId . " ) " ;
2016-03-02 23:40:11 +01:00
$sql .= " GROUP BY p.rowid, p.ref, p.title, p.public " ;
2017-07-31 04:52:27 +02:00
2016-01-21 14:13:38 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
while ( $row = $db -> fetch_object ( $resql ))
{
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2016-01-21 14:13:38 +01:00
print '<td>' ;
$projectstatic -> id = $row -> rowid ;
$projectstatic -> ref = $row -> ref ;
$projectstatic -> title = $row -> title ;
print $projectstatic -> getNomUrl ( 1 , '' , 1 );
print '</td>' ;
2016-03-02 23:40:11 +01:00
print '<td align="right">' . convertSecondToTime ( $row -> nb , 'allhourmin' ) . '</td>' ;
2016-01-21 14:13:38 +01:00
print " </tr> \n " ;
2017-07-31 04:52:27 +02:00
2016-01-21 14:13:38 +01:00
}
$db -> free ( $resql );
}
else
{
dol_print_error ( $db );
}
print '<tr class="liste_total">' ;
print '<td>' . $langs -> trans ( 'Total' ) . '</td>' ;
2016-03-02 23:40:11 +01:00
print '<td align="right">' . convertSecondToTime ( $total , 'allhourmin' ) . '</td>' ;
2016-01-21 14:13:38 +01:00
print " </tr> \n " ;
print " </table> " ;
2005-08-22 19:10:46 +02:00
}
2010-01-27 09:06:44 +01:00
/* Affichage de la liste des projets de l'annee */
2015-07-04 18:20:17 +02:00
if ( ! empty ( $conf -> global -> PROJECT_TASK_TIME_YEAR ))
2005-08-22 19:10:46 +02:00
{
2015-07-04 18:20:17 +02:00
print '<br><table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " ActivityOnProjectThisYear " ) . ': ' . strftime ( " %Y " , $now ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " Time " ) . '</td>' ;
print " </tr> \n " ;
2016-02-27 19:20:11 +01:00
$sql = " SELECT p.rowid, p.ref, p.title, p.public, SUM(tt.task_duration) as nb " ;
2015-07-04 18:20:17 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet as p " ;
$sql .= " , " . MAIN_DB_PREFIX . " projet_task as t " ;
$sql .= " , " . MAIN_DB_PREFIX . " projet_task_time as tt " ;
$sql .= " WHERE t.fk_projet = p.rowid " ;
$sql .= " AND p.entity = " . $conf -> entity ;
$sql .= " AND tt.fk_task = t.rowid " ;
$sql .= " AND tt.fk_user = " . $user -> id ;
$sql .= " AND YEAR(task_date) = ' " . strftime ( " %Y " , $now ) . " ' " ;
$sql .= " AND p.rowid in ( " . $projectsListId . " ) " ;
2016-02-27 19:20:11 +01:00
$sql .= " GROUP BY p.rowid, p.ref, p.title, p.public " ;
2015-07-04 18:20:17 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2009-01-15 00:36:51 +01:00
{
2015-07-04 18:20:17 +02:00
while ( $row = $db -> fetch_object ( $resql ))
{
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-07-04 18:20:17 +02:00
print '<td>' ;
$projectstatic -> id = $row -> rowid ;
$projectstatic -> ref = $row -> ref ;
$projectstatic -> title = $row -> title ;
2016-02-27 19:20:11 +01:00
$projectstatic -> public = $row -> public ;
2015-07-04 18:20:17 +02:00
print $projectstatic -> getNomUrl ( 1 , '' , 1 );
print '</td>' ;
2016-02-27 17:56:59 +01:00
print '<td align="right">' . convertSecondToTime ( $row -> nb , 'allhourmin' ) . '</td>' ;
2015-07-04 18:20:17 +02:00
print " </tr> \n " ;
2017-07-31 04:52:27 +02:00
2015-07-04 18:20:17 +02:00
}
$db -> free ( $resql );
2009-01-15 00:36:51 +01:00
}
2015-07-04 18:20:17 +02:00
else
{
dol_print_error ( $db );
}
print '<tr class="liste_total">' ;
print '<td>' . $langs -> trans ( 'Total' ) . '</td>' ;
2016-02-27 17:56:59 +01:00
print '<td align="right">' . convertSecondToTime ( $total , 'allhourmin' ) . '</td>' ;
2015-07-04 18:20:17 +02:00
print " </tr> \n " ;
print " </table> " ;
2005-08-22 19:10:46 +02:00
}
2015-07-04 18:20:17 +02:00
2016-01-18 16:43:15 +01:00
if ( empty ( $conf -> global -> PROJECT_HIDE_TASKS ) && ! empty ( $conf -> global -> PROJECT_SHOW_TASK_LIST_ON_PROJECT_AREA ))
2005-08-22 19:10:46 +02:00
{
2016-02-27 17:56:59 +01:00
// Get id of types of contacts for projects (This list never contains a lot of elements)
$listofprojectcontacttype = array ();
$sql = " SELECT ctc.rowid, ctc.code FROM " . MAIN_DB_PREFIX . " c_type_contact as ctc " ;
$sql .= " WHERE ctc.element = ' " . $projectstatic -> element . " ' " ;
$sql .= " AND ctc.source = 'internal' " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
while ( $obj = $db -> fetch_object ( $resql ))
{
$listofprojectcontacttype [ $obj -> rowid ] = $obj -> code ;
}
}
else dol_print_error ( $db );
if ( count ( $listofprojectcontacttype ) == 0 ) $listofprojectcontacttype [ 0 ] = '0' ; // To avoid sql syntax error if not found
// Get id of types of contacts for tasks (This list never contains a lot of elements)
$listoftaskcontacttype = array ();
$sql = " SELECT ctc.rowid, ctc.code FROM " . MAIN_DB_PREFIX . " c_type_contact as ctc " ;
$sql .= " WHERE ctc.element = ' " . $taskstatic -> element . " ' " ;
$sql .= " AND ctc.source = 'internal' " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
while ( $obj = $db -> fetch_object ( $resql ))
{
$listoftaskcontacttype [ $obj -> rowid ] = $obj -> code ;
}
}
else dol_print_error ( $db );
if ( count ( $listoftaskcontacttype ) == 0 ) $listoftaskcontacttype [ 0 ] = '0' ; // To avoid sql syntax error if not found
2017-07-31 04:52:27 +02:00
2016-02-27 17:56:59 +01:00
2015-07-04 18:20:17 +02:00
// Tasks for all resources of all opened projects and time spent for each task/resource
2016-01-18 16:43:15 +01:00
// This list can be very long, so we don't show it by default on task area. We prefer to use the list page.
// Add constant PROJECT_SHOW_TASK_LIST_ON_PROJECT_AREA to show this list
2017-07-31 04:52:27 +02:00
2015-07-04 18:20:17 +02:00
$max = ( empty ( $conf -> global -> PROJECT_LIMIT_TASK_PROJECT_AREA ) ? 1000 : $conf -> global -> PROJECT_LIMIT_TASK_PROJECT_AREA );
2016-03-02 23:40:11 +01:00
$sql = " SELECT p.ref, p.title, p.rowid as projectid, p.fk_statut as status, p.fk_opp_status as opp_status, p.public, p.dateo as projdateo, p.datee as projdatee, " ;
2016-01-18 16:43:15 +01:00
$sql .= " t.label, t.rowid as taskid, t.planned_workload, t.duration_effective, t.progress, t.dateo, t.datee, SUM(tasktime.task_duration) as timespent " ;
2015-07-04 18:20:17 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet as p " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s on p.fk_soc = s.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " projet_task as t on t.fk_projet = p.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " projet_task_time as tasktime on tasktime.fk_task = t.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " user as u on tasktime.fk_user = u.rowid " ;
2016-02-27 17:56:59 +01:00
if ( $mine )
{
$sql .= " , " . MAIN_DB_PREFIX . " element_contact as ect " ;
}
2018-02-06 10:57:53 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'project' ) . " ) " ;
2016-02-27 17:56:59 +01:00
if ( $mine || empty ( $user -> rights -> projet -> all -> lire )) $sql .= " AND p.rowid IN ( " . $projectsListId . " ) " ; // project i have permission on
if ( $mine ) // this may duplicate record if we are contact twice
{
$sql .= " AND ect.fk_c_type_contact IN ( " . join ( ',' , array_keys ( $listoftaskcontacttype )) . " ) AND ect.element_id = t.rowid AND ect.fk_socpeople = " . $user -> id ;
}
2016-03-02 23:40:11 +01:00
if ( $socid ) $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . " ) " ;
2015-07-04 18:20:17 +02:00
$sql .= " AND p.fk_statut=1 " ;
2016-02-27 19:20:11 +01:00
$sql .= " GROUP BY p.ref, p.title, p.rowid, p.fk_statut, p.fk_opp_status, p.public, t.label, t.rowid, t.planned_workload, t.duration_effective, t.progress, t.dateo, t.datee " ;
2015-07-04 18:20:17 +02:00
$sql .= " ORDER BY t.dateo desc, t.rowid desc, t.datee " ;
$sql .= $db -> plimit ( $max + 1 ); // We want more to know if we have more than limit
dol_syslog ( 'projet:index.php: affectationpercent' , LOG_DEBUG );
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
2015-09-24 18:33:48 +02:00
//print load_fiche_titre($langs->trans("TasksOnOpenedProject"),'','').'<br>';
2015-07-04 18:20:17 +02:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
//print '<th>'.$langs->trans('TaskRessourceLinks').'</th>';
print '<th>' . $langs -> trans ( 'OpenedProjects' ) . '</th>' ;
if ( ! empty ( $conf -> global -> PROJECT_USE_OPPORTUNITIES )) print '<th>' . $langs -> trans ( 'OpportunityStatus' ) . '</th>' ;
print '<th>' . $langs -> trans ( 'Task' ) . '</th>' ;
print '<th align="center">' . $langs -> trans ( 'DateStart' ) . '</th>' ;
print '<th align="center">' . $langs -> trans ( 'DateEnd' ) . '</th>' ;
print '<th align="right">' . $langs -> trans ( 'PlannedWorkload' ) . '</th>' ;
print '<th align="right">' . $langs -> trans ( 'TimeSpent' ) . '</th>' ;
print '<th align="right">' . $langs -> trans ( " ProgressCalculated " ) . '</td>' ;
2016-01-18 16:43:15 +01:00
print '<th align="right">' . $langs -> trans ( " ProgressDeclared " ) . '</td>' ;
2015-07-04 18:20:17 +02:00
print '</tr>' ;
while ( $i < $num && $i < $max )
{
$obj = $db -> fetch_object ( $resql );
2017-07-31 04:52:27 +02:00
2015-07-04 18:20:17 +02:00
$username = '' ;
if ( $obj -> userid && $userstatic -> id != $obj -> userid ) // We have a user and it is not last loaded user
{
$result = $userstatic -> fetch ( $obj -> userid );
if ( ! $result ) $userstatic -> id = 0 ;
}
if ( $userstatic -> id ) $username = $userstatic -> getNomUrl ( 0 , 0 );
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-07-04 18:20:17 +02:00
//print '<td>'.$username.'</td>';
print '<td>' ;
$projectstatic -> id = $obj -> projectid ;
$projectstatic -> ref = $obj -> ref ;
$projectstatic -> title = $obj -> title ;
2016-01-18 16:43:15 +01:00
$projectstatic -> statut = $obj -> status ;
2016-03-02 23:40:11 +01:00
$projectstatic -> public = $obj -> public ;
2016-01-18 16:43:15 +01:00
$projectstatic -> dateo = $db -> jdate ( $obj -> projdateo );
$projectstatic -> datee = $db -> jdate ( $obj -> projdatee );
2017-07-31 04:52:27 +02:00
2016-01-18 16:43:15 +01:00
print $projectstatic -> getNomUrl ( 1 , '' , 0 , '' , '<br>' );
2015-07-04 18:20:17 +02:00
print '</td>' ;
if ( ! empty ( $conf -> global -> PROJECT_USE_OPPORTUNITIES ))
{
print '<td>' ;
$code = dol_getIdFromCode ( $db , $obj -> opp_status , 'c_lead_status' , 'rowid' , 'code' );
if ( $code ) print $langs -> trans ( " OppStatus " . $code );
print '</td>' ;
}
print '<td>' ;
if ( ! empty ( $obj -> taskid ))
{
$tasktmp -> id = $obj -> taskid ;
$tasktmp -> ref = $obj -> ref ;
$tasktmp -> label = $obj -> label ;
print $tasktmp -> getNomUrl ( 1 , 'withproject' , 'task' , 1 , '<br>' );
}
else print $langs -> trans ( " NoTasks " );
print '</td>' ;
2016-01-18 16:43:15 +01:00
$taskstatic -> projectstatus = $obj -> projectstatus ;
$taskstatic -> progress = $obj -> progress ;
$taskstatic -> fk_statut = $obj -> status ;
$taskstatic -> dateo = $db -> jdate ( $obj -> dateo );
$taskstatic -> datee = $db -> jdate ( $obj -> datee );
2015-07-04 18:20:17 +02:00
print '<td align="center">' . dol_print_date ( $db -> jdate ( $obj -> dateo ), 'day' ) . '</td>' ;
2016-01-18 16:43:15 +01:00
print '<td align="center">' . dol_print_date ( $db -> jdate ( $obj -> datee ), 'day' );
2017-07-31 04:52:27 +02:00
print dol_print_date ( $obj -> date_end , 'dayhour' );
2016-01-18 16:43:15 +01:00
if ( $taskstatic -> hasDelay ()) print img_warning ( $langs -> trans ( " Late " ));
print '</td>' ;
2015-07-04 18:20:17 +02:00
print '<td align="right"><a href="' . DOL_URL_ROOT . '/projet/tasks/time.php?id=' . $obj -> taskid . '&withproject=1">' ;
2016-02-27 18:47:02 +01:00
print convertSecondToTime ( $obj -> planned_workload , 'allhourmin' );
2015-07-04 18:20:17 +02:00
print '</a></td>' ;
print '<td align="right"><a href="' . DOL_URL_ROOT . '/projet/tasks/time.php?id=' . $obj -> taskid . '&withproject=1">' ;
2016-02-27 18:47:02 +01:00
print convertSecondToTime ( $obj -> timespent , 'allhourmin' );
2015-07-04 18:20:17 +02:00
print '</a></td>' ;
print '<td align="right">' ;
if ( ! empty ( $obj -> taskid ))
{
if ( empty ( $obj -> planned_workload ) > 0 ) {
$percentcompletion = $langs -> trans ( " WorkloadNotDefined " );
} else {
$percentcompletion = intval ( $obj -> duration_effective * 100 / $obj -> planned_workload ) . '%' ;
}
}
print $percentcompletion ;
print '</td>' ;
2016-01-18 16:43:15 +01:00
print '<td align="right">' ;
print ( $obj -> taskid > 0 ) ? $obj -> progress . '%' : '' ;
print '</td>' ;
2015-07-04 18:20:17 +02:00
print " </tr> \n " ;
$i ++ ;
}
if ( $num > $max )
{
$colspan = 6 ;
if ( ! empty ( $conf -> global -> PROJECT_USE_OPPORTUNITIES )) $colspan ++ ;
print '<tr><td colspan="' . $colspan . '">' . $langs -> trans ( " WarningTooManyDataPleaseUseMoreFilters " ) . '</td></tr>' ;
}
print " </table> " ;
$db -> free ( $resql );
}
else
{
dol_print_error ( $db );
}
2005-08-22 19:10:46 +02:00
}
2013-04-12 16:16:39 +02:00
print '</div></div></div>' ;
2005-08-22 19:10:46 +02:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-02-07 10:25:58 +01:00
$db -> close ();