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' );
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2015-02-14 18:39:45 +01:00
// Security check
2020-04-10 10:59:32 +02: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 ;
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 ;
2015-02-14 18:39:45 +01:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2019-11-13 19:37:08 +01:00
if ( ! $sortorder ) $sortorder = " ASC " ;
if ( ! $sortfield ) $sortfield = " position_name " ;
2015-02-14 18:39:45 +01:00
$object = new ExpenseReport ( $db );
$object -> fetch ( $id , $ref );
$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
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 " );
$helpurl = " EN:Module_Expense_Reports " ;
2019-01-27 11:55:16 +01:00
llxHeader ( " " , $title , $helpurl );
2015-02-14 18:39:45 +01:00
if ( $object -> id )
{
$object -> fetch_thirdparty ();
2019-11-13 19:37:08 +01:00
$head = expensereport_prepare_head ( $object );
2015-02-14 18:39:45 +01:00
2019-02-09 12:00:49 +01:00
dol_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 ;
foreach ( $filearray as $key => $file )
2015-02-14 18:39:45 +01:00
{
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
2019-03-29 13:26:26 +01:00
print '<table class="border tableforfield centpercent">' ;
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' . ( ! empty ( $socid ) ? '?socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2015-02-14 18:39:45 +01:00
2016-11-30 20:24:36 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " NbOfAttachedFiles " ) . '</td><td colspan="3">' . count ( $filearray ) . '</td></tr>' ;
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> trans ( " TotalSizeOfAttachedFiles " ) . '</td><td colspan="3">' . dol_print_size ( $totalsize , 1 , 1 ) . '</td></tr>' ;
2015-02-14 18:39:45 +01:00
print '</table>' ;
print '</div>' ;
2016-11-30 20:24:36 +01:00
dol_fiche_end ();
2017-10-03 16:00:52 +02:00
2015-02-14 18:39:45 +01:00
$modulepart = 'expensereport' ;
$permission = $user -> rights -> expensereport -> creer ;
2016-09-07 01:54:16 +02:00
$permtoedit = $user -> rights -> expensereport -> creer ;
2019-11-13 19:37:08 +01:00
$param = '&id=' . $object -> id ;
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php' ;
2015-02-14 18:39:45 +01:00
}
else
{
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 ();