2015-02-14 18:39:45 +01:00
< ? php
/* Copyright ( C ) 2003 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2015-02-21 12:57:17 +01:00
* Copyright ( C ) 2004 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
2015-02-14 18:39:45 +01:00
* Copyright ( C ) 2005 Marc Barilley / Ocebo < marc @ ocebo . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
2015-02-14 18:39:45 +01:00
* Copyright ( C ) 2005 Simon TOSSER < simon @ kornog - computing . com >
* Copyright ( C ) 2011 - 2012 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
* or see https :// www . gnu . org /
2015-02-14 18:39:45 +01:00
*/
/**
2015-02-15 22:49:23 +01:00
* \file htdocs / expensereport / document . php
2015-02-14 18:39:45 +01:00
* \ingroup expensereport
2015-02-21 12:57:17 +01:00
* \brief Page of linked files onto trip and expens reports
2015-02-14 18:39:45 +01:00
*/
require '../main.inc.php' ;
2015-02-21 12:57:17 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2015-02-15 22:49:23 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/expensereport.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php' ;
2015-02-14 18:39:45 +01:00
2018-05-26 20:51:17 +02:00
// Load translation files required by the page
2019-11-13 19:37:08 +01:00
$langs -> loadLangs ( array ( " other " , " trips " , " companies " , " interventions " ));
2015-02-14 18:39:45 +01:00
2019-01-27 11:55:16 +01:00
$id = GETPOST ( 'id' , 'int' );
2015-02-14 18:39:45 +01:00
$ref = GETPOST ( 'ref' , 'alpha' );
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2019-01-27 11:55:16 +01:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
2015-02-14 18:39:45 +01:00
2020-09-18 01:57:23 +02:00
$childids = $user -> getAllChildIds ( 1 );
2015-02-14 18:39:45 +01:00
// Security check
2021-02-25 22:45:02 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2017-03-02 11:46:31 +01:00
$result = restrictedArea ( $user , 'expensereport' , $id , 'expensereport' );
2015-02-14 18:39:45 +01:00
// Get parameters
2020-04-20 15:06:27 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-25 22:45:02 +01: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 ;
2015-02-14 18:39:45 +01:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-25 22:45:02 +01:00
if ( ! $sortorder ) {
$sortorder = " ASC " ;
}
if ( ! $sortfield ) {
$sortfield = " position_name " ;
}
2015-02-14 18:39:45 +01:00
$object = new ExpenseReport ( $db );
2021-02-25 22:45:02 +01:00
if ( ! $object -> fetch ( $id , $ref ) > 0 ) {
2020-09-18 01:57:23 +02:00
dol_print_error ( $db );
}
2015-02-14 18:39:45 +01:00
$upload_dir = $conf -> expensereport -> dir_output . '/' . dol_sanitizeFileName ( $object -> ref );
2019-11-13 19:37:08 +01:00
$modulepart = 'trip' ;
2015-02-14 18:39:45 +01:00
2018-04-16 19:25:27 +02:00
// Load object
//include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
2021-02-25 22:45:02 +01:00
if ( $object -> id > 0 ) {
2020-09-18 01:57:23 +02:00
// Check current user can read this expense report
$canread = 0 ;
2021-02-25 22:45:02 +01:00
if ( ! empty ( $user -> rights -> expensereport -> readall )) {
$canread = 1 ;
}
if ( ! empty ( $user -> rights -> expensereport -> lire ) && in_array ( $object -> fk_user_author , $childids )) {
$canread = 1 ;
}
if ( ! $canread ) {
2020-09-18 01:57:23 +02:00
accessforbidden ();
}
}
2015-02-14 18:39:45 +01:00
/*
* Actions
*/
2019-11-13 19:37:08 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php' ;
2015-02-14 18:39:45 +01:00
/*
* View
*/
$form = new Form ( $db );
2019-11-13 19:37:08 +01:00
$title = $langs -> trans ( " ExpenseReport " ) . " - " . $langs -> trans ( " Documents " );
2021-04-19 17:28:13 +02:00
$help_url = " EN:Module_Expense_Reports|FR:Module_Notes_de_frais " ;
llxHeader ( " " , $title , $help_url );
2015-02-14 18:39:45 +01:00
2021-02-25 22:45:02 +01:00
if ( $object -> id ) {
2015-02-14 18:39:45 +01:00
$object -> fetch_thirdparty ();
2019-11-13 19:37:08 +01:00
$head = expensereport_prepare_head ( $object );
2015-02-14 18:39:45 +01:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'documents' , $langs -> trans ( " ExpenseReport " ), - 1 , 'trip' );
2015-02-14 18:39:45 +01:00
2019-11-13 19:37:08 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/expensereport/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-10-03 16:00:52 +02:00
2019-11-13 19:37:08 +01:00
$morehtmlref = '<div class="refidno">' ;
$morehtmlref .= '</div>' ;
2017-10-03 16:00:52 +02:00
2016-11-30 20:24:36 +01:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
2017-10-03 16:00:52 +02:00
2018-08-04 14:17:51 +02:00
// Build file list
2019-11-13 19:37:08 +01:00
$filearray = dol_dir_list ( $upload_dir , " files " , 0 , '' , '(\.meta|_preview.*\.png)$' , $sortfield , ( strtolower ( $sortorder ) == 'desc' ? SORT_DESC : SORT_ASC ), 1 );
$totalsize = 0 ;
2021-02-25 22:45:02 +01:00
foreach ( $filearray as $key => $file ) {
2019-11-13 19:37:08 +01:00
$totalsize += $file [ 'size' ];
2015-02-14 18:39:45 +01:00
}
2016-11-30 20:24:36 +01:00
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-10-03 16:00:52 +02:00
2020-10-31 14:32:18 +01:00
print '<table class="border tableforfield centpercent">' ;
2015-02-14 18:39:45 +01:00
2020-10-31 14:32:18 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/expensereport/list.php' . ( ! empty ( $socid ) ? '?socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2015-02-14 18:39:45 +01:00
2020-10-31 14:32:18 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " NbOfAttachedFiles " ) . '</td><td colspan="3">' . count ( $filearray ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( " TotalSizeOfAttachedFiles " ) . '</td><td colspan="3">' . dol_print_size ( $totalsize , 1 , 1 ) . '</td></tr>' ;
print '</table>' ;
2015-02-14 18:39:45 +01:00
2020-10-31 14:32:18 +01:00
print '</div>' ;
2015-02-14 18:39:45 +01:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_end ();
2017-10-03 16:00:52 +02:00
2020-10-31 14:32:18 +01:00
$modulepart = 'expensereport' ;
2021-06-08 16:19:21 +02:00
$permissiontoadd = $user -> rights -> expensereport -> creer ;
2020-10-31 14:32:18 +01:00
$permtoedit = $user -> rights -> expensereport -> creer ;
$param = '&id=' . $object -> id ;
2021-04-12 21:25:58 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php' ;
2020-05-21 15:05:19 +02:00
} else {
2015-02-14 18:39:45 +01:00
print $langs -> trans ( " ErrorUnknown " );
}
2018-08-02 14:03:50 +02:00
// End of page
2015-02-14 18:39:45 +01:00
llxFooter ();
$db -> close ();