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 >
2016-07-08 10:59:13 +02:00
* Copyright ( C ) 2004 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2014-07-17 01:28:01 +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' ;
2015-03-01 14:03:14 +01:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php' ;
2017-11-16 18:33:56 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2012-08-22 23:11:24 +02:00
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
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'projects' , 'companies' ));
2004-08-07 03:25:00 +02:00
2017-03-14 13:49:04 +01:00
$search_project_user = GETPOST ( 'search_project_user' , 'int' );
2017-07-31 04:52:27 +02:00
$mine = GETPOST ( 'mode' , 'aZ09' ) == 'mine' ? 1 : 0 ;
if ( $search_project_user == $user -> id ) $mine = 1 ;
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 ;
2017-01-12 15:23:30 +01:00
//if ($user->societe_id > 0) $socid = $user->societe_id; // For external user, no check is done on company because readability is managed by public status of project and assignement.
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
2014-07-17 01:28:01 +02:00
*/
2008-09-10 22:49:21 +02:00
2017-11-16 18:33:56 +01:00
$companystatic = new Societe ( $db );
2010-01-05 00:33:23 +01:00
$projectstatic = new Project ( $db );
2014-12-04 11:03:48 +01:00
$userstatic = new User ( $db );
2015-07-04 18:20:17 +02:00
$form = new Form ( $db );
2017-11-16 18:33:56 +01:00
$formfile = new FormFile ( $db );
2009-10-17 00:46:16 +02:00
2017-11-16 18:33:56 +01:00
$projectset = ( $mine ? $mine : ( empty ( $user -> rights -> projet -> all -> lire ) ? 0 : 2 ));
$projectsListId = $projectstatic -> getProjectsAuthorizedForUser ( $user , $projetset , 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
2017-03-14 13:49:04 +01:00
$title = $langs -> trans ( " ProjectsArea " );
//if ($mine) $title=$langs->trans("MyProjectsArea");
2010-02-07 10:49:10 +01: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="search_project_user">' ;
$morehtml .= '<option name="all" value="0"' . ( $mine ? '' : ' selected' ) . '>' . $titleall . '</option>' ;
$morehtml .= '<option name="mine" value="' . $user -> id . '"' . (( $search_project_user == $user -> id ) ? ' selected' : '' ) . '>' . $langs -> trans ( " ProjectsImContactFor " ) . '</option>' ;
$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 );
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
2015-07-04 18:20:17 +02:00
// Get list of ponderated percent for each status
$listofoppstatus = array (); $listofopplabel = array (); $listofoppcode = array ();
$sql = " SELECT cls.rowid, cls.code, cls.percent, cls.label " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_lead_status as cls " ;
2017-10-23 13:48:45 +02:00
$sql .= " WHERE active=1 " ;
2015-07-04 18:20:17 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $resql );
$listofoppstatus [ $objp -> rowid ] = $objp -> percent ;
$listofopplabel [ $objp -> rowid ] = $objp -> label ;
$listofoppcode [ $objp -> rowid ] = $objp -> code ;
$i ++ ;
}
}
else dol_print_error ( $db );
2013-04-12 16:16:39 +02:00
print '<div class="fichecenter"><div class="fichethirdleft">' ;
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_project' ] = array ( 'text' => 'Project' );
}
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>' ;
}
2014-07-17 01:28:01 +02:00
}
2010-02-20 21:24:09 +01:00
2015-07-04 18:20:17 +02:00
/*
* Statistics
*/
2015-11-28 17:35:52 +01:00
include DOL_DOCUMENT_ROOT . '/projet/graph_opportunities.inc.php' ;
2015-07-04 18:20:17 +02:00
2015-06-30 01:34:17 +02:00
// List of draft projects
2015-12-04 12:12:12 +01:00
print_projecttasks_array ( $db , $form , $socid , $projectsListId , 0 , 0 , $listofoppstatus , array ( 'projectlabel' , 'plannedworkload' , 'declaredprogress' ));
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
2017-11-16 18:33:56 +01:00
$max = 5 ;
// Last modified projects
$sql = " SELECT p.rowid, p.ref, p.title, p.fk_statut, p.tms as datem, " ;
$sql .= " s.rowid as socid, s.nom as name, s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.canvas " ;
$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 IN ( " . getEntity ( 'project' ) . " ) " ;
if ( $mine || empty ( $user -> rights -> projet -> all -> lire )) $sql .= " AND p.rowid IN ( " . $projectsListId . " ) " ; // If we have this test true, it also means projectset is not 2
if ( $socid ) $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . " ) " ;
$sql .= " ORDER BY p.tms DESC " ;
$sql .= $db -> plimit ( $max , 0 );
$resql = $db -> query ( $sql );
if ( $resql )
{
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<th colspan="4">' . $langs -> trans ( " LatestModifiedProjects " , $max ) . '</th></tr>' ;
$num = $db -> num_rows ( $resql );
if ( $num )
{
$i = 0 ;
$var = true ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
print '<tr class="oddeven">' ;
print '<td width="20%" class="nowrap">' ;
$projectstatic -> id = $obj -> rowid ;
$projectstatic -> ref = $obj -> ref ;
$projectstatic -> title = $obj -> title ;
$projectstatic -> dateo = $obj -> dateo ;
$projectstatic -> datep = $obj -> datep ;
$projectstatic -> thirdparty_name = $obj -> name ;
$companystatic -> id = $obj -> socid ;
$companystatic -> name = $obj -> name ;
$companystatic -> email = $obj -> email ;
$companystatic -> client = $obj -> client ;
$companystatic -> fournisseur = $obj -> fournisseur ;
$companystatic -> code_client = $obj -> code_client ;
$companystatic -> code_fournisseur = $obj -> code_fournisseur ;
$companystatic -> canvas = $obj -> canvas ;
print '<table class="nobordernopadding"><tr class="nocellnopadd">' ;
print '<td width="96" class="nobordernopadding nowrap">' ;
print $projectstatic -> getNomUrl ( 1 );
print '</td>' ;
print '<td width="16" class="nobordernopadding nowrap">' ;
print ' ' ;
print '</td>' ;
print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">' ;
$filename = dol_sanitizeFileName ( $obj -> ref );
$filedir = $conf -> commande -> dir_output . '/' . dol_sanitizeFileName ( $obj -> ref );
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?id=' . $obj -> rowid ;
print $formfile -> getDocumentsLink ( $projectstatic -> element , $filename , $filedir );
print '</td></tr></table>' ;
print '</td>' ;
print '<td class="nowrap">' ;
if ( $companystatic -> id > 0 )
{
print $companystatic -> getNomUrl ( 1 , 'company' , 16 );
}
print '</td>' ;
print '<td>' . dol_print_date ( $db -> jdate ( $obj -> datem ), 'day' ) . '</td>' ;
print '<td align="right">' . $projectstatic -> LibStatut ( $obj -> fk_statut , 5 ) . '</td>' ;
print '</tr>' ;
$i ++ ;
}
}
print " </table><br> " ;
}
else dol_print_error ( $db );
// Open project per thirdparty
2017-10-19 19:53:29 +02:00
print '<div class="div-table-responsive-no-min">' ;
2004-10-31 14:32:01 +01:00
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " OpenedProjectsByThirdparties " , $_SERVER [ " PHP_SELF " ], " s.nom " , " " , " " , '' , $sortfield , $sortorder );
print_liste_field_titre ( " NbOfProjects " , " " , " " , " " , " " , 'align="right"' , $sortfield , $sortorder );
2004-10-31 14:32:01 +01:00
print " </tr> \n " ;
2003-09-04 13:08:03 +02:00
2015-07-04 18:20:17 +02:00
$sql = " SELECT COUNT(p.rowid) as nb, SUM(p.opp_amount) " ;
2014-10-04 17:20:17 +02:00
$sql .= " , s.nom as name, 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 " ;
2017-11-16 18:33:56 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'project' , $conf -> entity ) . " ) " ;
2015-07-04 18:20:17 +02:00
$sql .= " AND p.fk_statut = 1 " ;
2017-11-16 18:33:56 +01:00
if ( $mine || empty ( $user -> rights -> projet -> all -> lire )) $sql .= " AND p.rowid IN ( " . $projectsListId . " ) " ; // If we have this test true, it also means projectset is not 2
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 " ;
2015-10-13 14:40:02 +02:00
$sql .= $db -> order ( $sortfield , $sortorder );
2003-09-04 13:08:03 +02:00
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 );
2017-07-31 04:52:27 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' ;
2009-06-11 03:05:43 +02:00
if ( $obj -> socid )
{
2017-11-16 18:33:56 +01:00
$companystatic -> id = $obj -> socid ;
$companystatic -> name = $obj -> name ;
print $companystatic -> 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>' ;
2018-05-14 15:16:19 +02:00
print '<td align="right">' ;
if ( $obj -> socid ) print '<a href="' . DOL_URL_ROOT . '/projet/list.php?socid=' . $obj -> socid . '&search_status=1">' . $obj -> nb . '</a>' ;
else print '<a href="' . DOL_URL_ROOT . '/projet/list.php?search_societe=' . urlencode ( '^$' ) . '&search_status=1">' . $obj -> nb . '</a>' ;
print '</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> " ;
2017-10-19 19:53:29 +02:00
print '</div>' ;
2003-09-04 13:08:03 +02:00
2016-01-18 16:43:15 +01:00
if ( ! empty ( $conf -> global -> PROJECT_SHOW_PROJECT_LIST_ON_PROJECT_AREA ))
{
// 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_PROJECT_LIST_ON_PROJECT_AREA to show this list
2017-07-31 04:52:27 +02:00
2016-01-18 16:43:15 +01:00
print '<br>' ;
2017-07-31 04:52:27 +02:00
2016-01-18 16:43:15 +01:00
print_projecttasks_array ( $db , $form , $socid , $projectsListId , 0 , 1 , $listofoppstatus , array ());
}
2015-02-02 21:33:09 +01:00
2015-07-04 18:20:17 +02:00
print '</div></div></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 ();