2010-03-02 18:13:39 +01:00
< ? php
2018-10-27 14:43:12 +02:00
/* Copyright ( C ) 2010 Regis Houssin < regis . houssin @ inodbox . com >
2012-05-23 14:34:44 +02:00
* Copyright ( C ) 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2013-07-25 18:35:48 +02:00
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
2010-03-02 18:13:39 +01: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
2010-03-02 18:13:39 +01: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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2010-03-02 18:13:39 +01:00
*/
/**
* \file htdocs / projet / document . php
* \ingroup project
2017-09-21 11:50:36 +02:00
* \brief Page to managed related documents linked to a project
2010-03-02 18:13:39 +01: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' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2010-03-02 18:13:39 +01:00
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'projects' , 'other' ));
2010-03-02 18:13:39 +01:00
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
$id = GETPOST ( 'id' , 'int' );
$ref = GETPOST ( 'ref' , 'alpha' );
2020-04-10 10:59:32 +02:00
$mine = ( GETPOST ( 'mode' , 'alpha' ) == 'mine' ? 1 : 0 );
2010-05-29 01:26:08 +02:00
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
2010-05-30 14:21:32 +02:00
// Security check
2020-04-10 10:59:32 +02:00
$socid = 0 ;
2019-10-31 20:46:31 +01:00
//if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
2020-04-10 10:59:32 +02:00
$result = restrictedArea ( $user , 'projet' , $id , 'projet&project' );
2010-03-02 18:13:39 +01:00
2012-06-09 18:37:54 +02:00
$object = new Project ( $db );
2015-03-02 17:54:35 +01:00
2020-04-10 10:59:32 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php' ; // Must be include, not include_once
if ( ! empty ( $conf -> global -> PROJECT_ALLOW_COMMENT_ON_PROJECT ) && method_exists ( $object , 'fetchComments' ) && empty ( $object -> comments )) $object -> fetchComments ();
2015-03-02 17:54:35 +01:00
2020-04-10 10:59:32 +02:00
if ( $id > 0 || ! empty ( $ref )) {
$upload_dir = $conf -> projet -> dir_output . " / " . dol_sanitizeFileName ( $object -> ref );
2012-06-09 18:37:54 +02:00
}
2010-03-02 18:13:39 +01:00
// Get parameters
2020-04-20 15:06:27 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2019-01-27 11:55:16 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2017-06-06 10:53:53 +02:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2020-04-20 15:06:27 +02:00
$offset = $limit * $page ;
2010-03-02 18:13:39 +01:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2019-10-14 15:09:59 +02:00
2020-04-10 10:59:32 +02:00
if ( ! empty ( $conf -> global -> MAIN_DOC_SORT_FIELD )) { $sortfield = $conf -> global -> MAIN_DOC_SORT_FIELD ; }
if ( ! empty ( $conf -> global -> MAIN_DOC_SORT_ORDER )) { $sortorder = $conf -> global -> MAIN_DOC_SORT_ORDER ; }
2019-10-14 15:09:59 +02:00
2020-04-10 10:59:32 +02:00
if ( ! $sortorder ) $sortorder = " ASC " ;
if ( ! $sortfield ) $sortfield = " name " ;
2010-03-02 18:13:39 +01:00
/*
* Actions
*/
2020-04-10 10:59:32 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php' ;
2010-03-02 18:13:39 +01:00
/*
* View
*/
2020-04-10 10:59:32 +02:00
$title = $langs -> trans ( " Project " ) . ' - ' . $langs -> trans ( " Document " ) . ' - ' . $object -> ref . ' ' . $object -> name ;
if ( ! empty ( $conf -> global -> MAIN_HTML_TITLE ) && preg_match ( '/projectnameonly/' , $conf -> global -> MAIN_HTML_TITLE ) && $object -> name ) $title = $object -> ref . ' ' . $object -> name . ' - ' . $langs -> trans ( " Document " );
$help_url = " EN:Module_Projects|FR:Module_Projets|ES:Módulo_Proyectos " ;
2015-03-23 12:44:41 +01:00
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $title , $help_url );
2010-03-02 18:13:39 +01:00
$form = new Form ( $db );
2012-06-09 18:37:54 +02:00
if ( $object -> id > 0 )
2010-03-02 18:13:39 +01:00
{
2012-06-09 18:37:54 +02:00
$upload_dir = $conf -> projet -> dir_output . '/' . dol_sanitizeFileName ( $object -> ref );
2010-05-01 16:28:48 +02:00
2020-03-23 15:54:02 +01:00
// To verify role of users
//$userAccess = $object->restrictedProjectArea($user,'read');
2020-04-10 10:59:32 +02:00
$userWrite = $object -> restrictedProjectArea ( $user , 'write' );
2020-03-23 15:54:02 +01:00
//$userDelete = $object->restrictedProjectArea($user,'delete');
//print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
2010-03-02 18:13:39 +01:00
2012-06-09 18:37:54 +02:00
$head = project_prepare_head ( $object );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'document' , $langs -> trans ( " Project " ), - 1 , ( $object -> public ? 'projectpub' : 'project' ));
2010-03-02 18:13:39 +01:00
// Files list constructor
2020-04-10 10:59:32 +02:00
$filearray = dol_dir_list ( $upload_dir , " files " , 0 , '' , '(\.meta|_preview.*\.png)$' , $sortfield , ( strtolower ( $sortorder ) == 'desc' ? SORT_DESC : SORT_ASC ), 1 );
$totalsize = 0 ;
foreach ( $filearray as $key => $file )
2010-03-02 18:13:39 +01:00
{
2020-04-10 10:59:32 +02:00
$totalsize += $file [ 'size' ];
2010-03-02 18:13:39 +01:00
}
2010-05-01 16:28:48 +02:00
2017-09-21 11:50:36 +02:00
2016-10-17 20:10:53 +02:00
// Project card
2017-09-21 11:50:36 +02:00
2017-05-19 00:52:13 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/projet/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-09-21 11:50:36 +02:00
2020-04-10 10:59:32 +02:00
$morehtmlref = '<div class="refidno">' ;
2016-10-17 20:10:53 +02:00
// Title
2020-04-10 10:59:32 +02:00
$morehtmlref .= $object -> title ;
2016-10-17 20:10:53 +02:00
// Thirdparty
if ( $object -> thirdparty -> id > 0 )
{
2020-04-10 10:59:32 +02:00
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 , 'project' );
2016-10-17 20:10:53 +02:00
}
2020-04-10 10:59:32 +02:00
$morehtmlref .= '</div>' ;
2017-09-21 11:50:36 +02:00
2010-05-23 22:01:10 +02:00
// Define a complementary filter for search of next/prev ref.
2020-04-10 10:59:32 +02:00
if ( ! $user -> rights -> projet -> all -> lire )
2016-10-17 20:10:53 +02:00
{
2020-03-23 15:54:02 +01:00
$objectsListId = $object -> getProjectsAuthorizedForUser ( $user , 0 , 0 );
2020-04-10 10:59:32 +02:00
$object -> next_prev_filter = " rowid in ( " . ( count ( $objectsListId ) ? join ( ',' , array_keys ( $objectsListId )) : '0' ) . " ) " ;
2016-10-17 20:10:53 +02:00
}
2017-09-21 11:50:36 +02:00
2016-10-17 20:10:53 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
2017-09-21 11:50:36 +02:00
2016-10-17 20:10:53 +02:00
print '<div class="fichecenter">' ;
2017-09-21 11:50:36 +02:00
print '<div class="underbanner clearboth"></div>' ;
2016-10-17 20:10:53 +02:00
2019-03-29 13:26:26 +01:00
print '<table class="border tableforfield centpercent">' ;
2010-05-01 16:28:48 +02:00
2010-03-02 18:13:39 +01:00
// Files infos
2016-10-24 20:52:21 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " NbOfAttachedFiles " ) . '</td><td>' . count ( $filearray ) . '</td></tr>' ;
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> trans ( " TotalSizeOfAttachedFiles " ) . '</td><td>' . dol_print_size ( $totalsize , 1 , 1 ) . '</td></tr>' ;
2010-05-01 16:28:48 +02:00
2010-03-02 18:13:39 +01:00
print " </table> \n " ;
2017-09-21 11:50:36 +02:00
2016-10-17 20:10:53 +02:00
print '</div>' ;
2016-10-28 18:40:26 +02:00
2017-09-21 11:50:36 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2010-03-02 18:13:39 +01:00
2014-03-14 02:07:54 +01:00
$modulepart = 'project' ;
2013-09-18 15:55:44 +02:00
$permission = ( $userWrite > 0 );
2016-10-14 18:09:24 +02:00
$permtoedit = ( $userWrite > 0 );
2020-04-10 10:59:32 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php' ;
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
dol_print_error ( '' , 'NoRecordFound' );
2010-03-02 18:13:39 +01:00
}
2018-08-15 12:48:13 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-02-04 18:34:52 +01:00
$db -> close ();