2004-10-20 22:06:49 +02:00
< ? php
2005-04-05 13:22:28 +02:00
/* Copyright ( C ) 2001 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2010-02-15 02:21:47 +01:00
* Copyright ( C ) 2004 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
2013-05-13 17:08:36 +02:00
* Copyright ( C ) 2005 - 2010 Regis Houssin < regis . houssin @ capnetworks . com >
*
* 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 < http :// www . gnu . org / licenses />.
*/
2004-08-14 15:16:01 +02:00
2005-04-07 02:03:07 +02:00
/**
2008-09-10 22:49:21 +02:00
* \file htdocs / projet / index . php
* \ingroup projet
2010-02-15 02:21:47 +01:00
* \brief Main project home page
2008-09-10 22:49:21 +02:00
*/
2004-08-14 15:16:01 +02:00
2012-08-22 23:24:21 +02: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 . '/core/lib/project.lib.php' ;
2014-03-12 02:43:31 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2010-02-20 21:24:09 +01:00
2004-08-07 03:25:00 +02:00
$langs -> load ( " projects " );
2010-08-20 18:05:07 +02:00
$langs -> load ( " companies " );
2004-08-07 03:25:00 +02:00
2013-04-26 19:13:39 +02:00
$mine = GETPOST ( 'mode' ) == 'mine' ? 1 : 0 ;
2010-05-23 20:51:03 +02:00
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 ;
2010-02-15 02:21:47 +01:00
if ( ! $user -> rights -> projet -> lire ) accessforbidden ();
2003-09-04 13:08:03 +02:00
2011-11-03 01:59:13 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
2008-09-10 22:49:21 +02:00
/*
* View
2013-05-13 17:08:36 +02:00
*/
2008-09-10 22:49:21 +02:00
2010-02-04 16:30:42 +01:00
$socstatic = new Societe ( $db );
2010-01-05 00:33:23 +01:00
$projectstatic = new Project ( $db );
2009-10-17 00:46:16 +02:00
2013-04-26 19:13:39 +02:00
$projectsListId = $projectstatic -> getProjectsAuthorizedForUser ( $user ,( $mine ? $mine : ( empty ( $user -> rights -> projet -> all -> lire ) ? 0 : 2 )), 1 );
2010-05-23 20:51:03 +02:00
//var_dump($projectsListId);
2010-02-04 18:54:00 +01:00
2011-04-20 01:21:10 +02:00
2009-08-12 14:59:14 +02:00
llxHeader ( " " , $langs -> trans ( " Projects " ), " EN:Module_Projects|FR:Module_Projets|ES:Módulo_Proyectos " );
2004-07-21 16:26:46 +02:00
2009-01-15 00:36:51 +01:00
$text = $langs -> trans ( " Projects " );
2010-02-04 18:54:00 +01:00
if ( $mine ) $text = $langs -> trans ( " MyProjects " );
2010-02-07 10:49:10 +01:00
2009-01-15 00:36:51 +01:00
print_fiche_titre ( $text );
2003-09-04 13:08:03 +02:00
2010-05-29 01:26:08 +02:00
// Show description of content
2010-02-20 21:24:09 +01:00
if ( $mine ) print $langs -> trans ( " MyProjectsDesc " ) . '<br><br>' ;
2005-08-21 14:09:51 +02:00
else
{
2013-04-26 19:13:39 +02:00
if ( ! empty ( $user -> rights -> projet -> all -> lire ) && ! $socid ) print $langs -> trans ( " ProjectsDesc " ) . '<br><br>' ;
2010-02-20 21:24:09 +01:00
else print $langs -> trans ( " ProjectsPublicDesc " ) . '<br><br>' ;
2005-08-21 14:09:51 +02:00
}
2010-02-20 21:24:09 +01:00
2013-04-12 16:16:39 +02:00
print '<div class="fichecenter"><div class="fichethirdleft">' ;
2010-02-20 21:24:09 +01:00
2011-04-20 01:21:10 +02:00
print_projecttasks_array ( $db , $socid , $projectsListId );
2005-08-21 14:09:51 +02:00
2013-04-12 16:16:39 +02:00
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">' ;
2010-02-04 18:17:38 +01:00
2004-10-31 14:32:01 +01:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2014-03-12 02:43:31 +01:00
print_liste_field_titre ( $langs -> trans ( " ThirdParties " ), $_SERVER [ " PHP_SELF " ], " s.nom " , " " , " " , " " , $sortfield , $sortorder );
2009-07-15 17:04:58 +02:00
print_liste_field_titre ( $langs -> trans ( " NbOfProjects " ), " " , " " , " " , " " , 'align="right"' , $sortfield , $sortorder );
2004-10-31 14:32:01 +01:00
print " </tr> \n " ;
2003-09-04 13:08:03 +02:00
2010-02-04 16:30:42 +01:00
$sql = " SELECT count(p.rowid) as nb " ;
$sql .= " , s.nom, s.rowid as socid " ;
2009-06-11 03:05:43 +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 .= " WHERE p.entity = " . $conf -> entity ;
2013-04-26 19:13:39 +02:00
if ( $mine || empty ( $user -> rights -> projet -> all -> lire )) $sql .= " AND p.rowid IN ( " . $projectsListId . " ) " ;
2010-09-18 15:38:43 +02:00
if ( $socid ) $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . " ) " ;
2009-10-29 02:26:38 +01:00
$sql .= " GROUP BY s.nom, s.rowid " ;
2003-09-04 13:08:03 +02:00
2004-08-07 03:25:00 +02:00
$var = true ;
2005-04-05 13:22:28 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2003-09-04 13:08:03 +02:00
{
2009-01-15 00:36:51 +01:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
2009-06-11 03:05:43 +02:00
$obj = $db -> fetch_object ( $resql );
2009-01-15 00:36:51 +01:00
$var =! $var ;
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' ;
2009-06-11 03:05:43 +02:00
if ( $obj -> socid )
{
2010-02-04 16:30:42 +01:00
$socstatic -> id = $obj -> socid ;
$socstatic -> nom = $obj -> nom ;
print $socstatic -> getNomUrl ( 1 );
2009-06-11 03:05:43 +02:00
}
else
{
2010-02-15 02:21:47 +01:00
print $langs -> trans ( " OthersNotLinkedToThirdParty " );
2009-06-11 03:05:43 +02:00
}
print '</td>' ;
2009-10-17 00:46:16 +02:00
print '<td align="right"><a href="' . DOL_URL_ROOT . '/projet/liste.php?socid=' . $obj -> socid . '">' . $obj -> nb . '</a></td>' ;
2009-01-15 00:36:51 +01:00
print " </tr> \n " ;
$i ++ ;
}
$db -> free ( $resql );
2003-09-04 13:08:03 +02:00
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2003-09-04 13:08:03 +02:00
}
print " </table> " ;
2013-04-12 16:16:39 +02:00
print '</div></div></div>' ;
2005-08-21 14:09:51 +02:00
2014-03-12 02:43:31 +01:00
// Tasks for all resources of all opened projects and time spent for each task/resource
2013-05-13 17:08:36 +02:00
print '<div class="fichecenter">' ;
2014-03-12 02:43:31 +01:00
$sql = " SELECT p.title, p.rowid as projectid, t.label, t.rowid as taskid, u.rowid as userid, t.planned_workload, t.dateo, t.datee, SUM(tasktime.task_duration) as timespent " ;
2013-05-13 17:08:36 +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 .= " INNER JOIN " . MAIN_DB_PREFIX . " projet_task as t on t.fk_projet = p.rowid " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " projet_task_time as tasktime on tasktime.fk_task = t.rowid " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " user as u on tasktime.fk_user = u.rowid " ;
$sql .= " WHERE p.entity = " . $conf -> entity ;
if ( $mine || ! $user -> rights -> projet -> all -> lire ) $sql .= " AND p.rowid IN ( " . $projectsListId . " ) " ;
if ( $socid ) $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . " ) " ;
2013-05-14 20:22:33 +02:00
$sql .= " AND p.fk_statut=1 " ;
2014-03-12 02:43:31 +01:00
$sql .= " GROUP BY p.title, p.rowid, t.label, t.rowid, u.rowid, t.planned_workload, t.dateo, t.datee " ;
2013-05-13 17:08:36 +02:00
$sql .= " ORDER BY u.rowid, t.dateo, t.datee " ;
$userstatic = new User ( $db );
2013-05-15 14:19:16 +02:00
dol_syslog ( 'projet:index.php: affectationpercent sql=' . $sql , LOG_DEBUG );
2013-05-13 17:08:36 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
2014-03-12 02:43:31 +01:00
if ( $num > ( empty ( $conf -> global -> PROJECT_LIMIT_TASK_PROJECT_AREA ) ? 1000 : $conf -> global -> PROJECT_LIMIT_TASK_PROJECT_AREA ))
2013-05-13 17:08:36 +02:00
{
2014-03-12 02:49:11 +01:00
/* print '<tr ' . $bc [ 0 ] . '>' ;
2014-03-12 02:43:31 +01:00
print '<td colspan="9">' ;
print $langs -> trans ( " TooManyDataPleaseUseMoreFilters " );
2014-03-12 02:49:11 +01:00
print '</td></tr>' ; */
2014-03-12 02:43:31 +01:00
}
else
{
2014-03-12 02:49:11 +01:00
print '<br>' ;
print_fiche_titre ( $langs -> trans ( " TimeSpent " ), '' , '' ) . '<br>' ;
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<th>' . $langs -> trans ( 'TaskRessourceLinks' ) . '</th>' ;
print '<th>' . $langs -> trans ( 'Projects' ) . '</th>' ;
print '<th>' . $langs -> trans ( 'Task' ) . '</th>' ;
print '<th>' . $langs -> trans ( 'DateStart' ) . '</th>' ;
print '<th>' . $langs -> trans ( 'DateEnd' ) . '</th>' ;
print '<th>' . $langs -> trans ( 'TimeSpent' ) . '</th>' ;
print '</tr>' ;
2014-03-12 02:43:31 +01:00
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
$var =! $var ;
$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 );
print " <tr " . $bc [ $var ] . " > " ;
print '<td>' . $username . '</td>' ;
print '<td><a href="' . DOL_URL_ROOT . '/projet/fiche.php?id=' . $obj -> projectid . '">' . $obj -> title . '</a></td>' ;
print '<td><a href="' . DOL_URL_ROOT . '/projet/tasks/task.php?id=' . $obj -> taskid . '&withproject=1">' . $obj -> label . '</a></td>' ;
print '<td>' . dol_print_date ( $db -> jdate ( $obj -> dateo )) . '</td>' ;
print '<td>' . dol_print_date ( $db -> jdate ( $obj -> datee )) . '</td>' ;
/* I disable this because information is wrong . This percent has no meaning for a particular resource . What do we want ?
* Percent of completion ?
* If we want to show completion , we must remove " user " into list ,
if ( empty ( $obj -> planned_workload )) {
$percentcompletion = $langs -> trans ( " Unknown " );
} else {
$percentcompletion = intval ( $obj -> task_duration * 100 / $obj -> planned_workload );
} */
print '<td><a href="' . DOL_URL_ROOT . '/projet/tasks/time.php?id=' . $obj -> taskid . '&withproject=1">' ;
//print $percentcompletion.' %';
print convertSecondToTime ( $obj -> timespent , 'all' );
print '</a></td>' ;
print " </tr> \n " ;
$i ++ ;
2013-05-13 17:08:36 +02:00
}
2014-03-12 02:49:11 +01:00
print " </table> " ;
2013-05-13 17:08:36 +02:00
}
2014-03-12 02:49:11 +01:00
$db -> free ( $resql );
2013-05-13 17:08:36 +02:00
}
else
{
dol_print_error ( $db );
}
2014-03-12 02:43:31 +01:00
print '</div>' ;
2013-05-13 17:08:36 +02:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-02-04 18:34:52 +01:00
$db -> close ();
2003-09-04 13:08:03 +02:00
?>