2010-05-03 10:43:32 +02:00
< ? php
2025-01-13 20:04:35 +01:00
2014-08-28 15:52:20 +02:00
/* Copyright ( C ) 2008 - 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2010 - 2014 Regis Houssin < regis . houssin @ inodbox . com >
2016-03-23 22:45:04 +01:00
* Copyright ( C ) 2010 - 2016 Juanjo Menent < jmenent @ 2 byte . es >
2014-08-28 15:52:20 +02:00
* Copyright ( C ) 2013 Charles - Fr BENKE < charles . fr @ benke . fr >
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
* Copyright ( C ) 2014 Marcos García < marcosgdf @ gmail . com >
2015-05-12 09:53:09 +02:00
* Copyright ( C ) 2015 Bahfir Abbes < bafbes @ gmail . com >
2017-12-07 18:44:33 +01:00
* Copyright ( C ) 2016 - 2017 Ferran Marcet < fmarcet @ 2 byte . es >
2024-09-20 02:20:33 +02:00
* Copyright ( C ) 2019 - 2024 Frédéric France < frederic . france @ free . fr >
2025-01-13 20:04:35 +01:00
* Copyright ( C ) 2024 - 2025 MDW < mdeweerd @ users . noreply . github . com >
2019-02-23 16:52:26 +01:00
*
2010-05-03 10:43:32 +02: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-05-03 10:43:32 +02: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-05-03 10:43:32 +02:00
*/
/**
2010-06-08 01:52:43 +02:00
* \file htdocs / core / class / html . formfile . class . php
2010-11-22 10:18:53 +01:00
* \ingroup core
2010-10-30 12:09:04 +02:00
* \brief File of class to offer components to list and upload files
2010-05-03 10:43:32 +02:00
*/
/**
2012-01-27 15:17:36 +01:00
* Class to offer components to list and upload files
2010-05-03 10:43:32 +02:00
*/
class FormFile
{
2024-09-29 21:52:31 +02:00
/**
* @ var DoliDB
*/
2017-10-16 08:47:05 +02:00
private $db ;
2017-06-10 13:44:20 +02:00
2018-08-23 11:34:55 +02:00
/**
* @ var string Error code ( or message )
*/
2017-10-16 08:47:05 +02:00
public $error ;
2011-08-16 11:36:00 +02:00
2024-09-29 21:52:31 +02:00
/**
* @ var int
*/
2017-10-16 08:47:05 +02:00
public $numoffiles ;
2024-09-29 21:52:31 +02:00
/**
* @ var array { nboffiles : int , extensions : array < string , int > , files : string []} Used to return information by function getDocumentsLink
*/
public $infofiles ;
2011-08-16 11:36:00 +02:00
2017-10-16 08:47:05 +02:00
/**
2011-09-11 20:35:38 +02:00
* Constructor
*
2011-12-19 23:38:40 +01:00
* @ param DoliDB $db Database handler
2017-10-16 08:47:05 +02:00
*/
2019-02-27 20:45:07 +01:00
public function __construct ( $db )
2017-10-16 08:47:05 +02:00
{
$this -> db = $db ;
2019-11-12 09:46:08 +01:00
$this -> numoffiles = 0 ;
2017-10-16 08:47:05 +02:00
}
2011-08-16 11:36:00 +02:00
2024-11-04 13:56:05 +01:00
/**
* Show an image with feature to edit it
*
* @ param string $htmlname HTML name
* @ param string $modulepart Module part
* @ param string $dirformainimage Main directory of module
2025-02-11 22:21:59 +01:00
* @ param string $subdirformainimage Subdirectory into main directory . Often '' , can be 'logos/' .
2024-11-04 13:56:05 +01:00
* @ param string $fileformainimage File name of image to show
* @ return string HTML code to show and edit image
*/
public function showImageToEdit ( string $htmlname , string $modulepart , string $dirformainimage , string $subdirformainimage , string $fileformainimage )
{
global $langs ;
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php' ;
include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php' ;
include_once DOL_DOCUMENT_ROOT . '/core/lib/security.lib.php' ;
$tmparraysize = getDefaultImageSizes ();
$maxwidthsmall = $tmparraysize [ 'maxwidthsmall' ];
$maxheightsmall = $tmparraysize [ 'maxheightsmall' ];
$maxwidthmini = $tmparraysize [ 'maxwidthmini' ];
$maxheightmini = $tmparraysize [ 'maxheightmini' ];
$quality = $tmparraysize [ 'quality' ];
$imgheight = 80 ;
$imgwidth = 200 ;
$max = 'max-' ;
if ( $htmlname == 'logo_squarred' ) {
$imgheight = 80 ;
$imgwidth = 80 ;
$max = '' ;
}
$maxfilesizearray = getMaxFileSizeArray ();
$maxmin = $maxfilesizearray [ 'maxmin' ];
2025-02-11 22:21:59 +01:00
$fileformainimagesmall = getImageFileNameForSize ( $fileformainimage , '_small' ); // This include the "thumbs/..." in path
$fileformainimagemini = getImageFileNameForSize ( $fileformainimage , '_mini' ); // This include the "thumbs/..." in path
2024-11-04 13:56:05 +01:00
$out = '' ;
$out .= '<div class="centpercent nobordernopadding valignmiddle"><div class="inline-block marginrightonly">' ;
if ( $maxmin > 0 ) {
$out .= '<input type="hidden" name="MAX_FILE_SIZE" value="' . ( $maxmin * 1024 ) . '">' ; // MAX_FILE_SIZE must precede the field type=file
}
$out .= '<input type="file" class="flat minwidth100 maxwidthinputfileonsmartphone" name="' . $htmlname . '" id="' . $htmlname . '" accept="image/*">' ;
$out .= '</div>' ;
if ( ! empty ( $fileformainimagesmall )) {
$out .= '<div class="inline-block valignmiddle marginrightonly">' ;
$out .= '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?action=remove' . $htmlname . '&token=' . newToken () . '">' . img_delete ( $langs -> trans ( " Delete " ), '' , 'marginleftonly' ) . '</a>' ;
$out .= '</div>' ;
2025-02-11 22:21:59 +01:00
if ( file_exists ( $dirformainimage . '/' . $subdirformainimage . $fileformainimagesmall )) {
2024-11-04 13:56:05 +01:00
$out .= '<div class="inline-block valignmiddle marginrightonly">' ;
2025-02-11 22:21:59 +01:00
$out .= '<img id="' . $htmlname . '" style="' . $max . 'height: ' . $imgheight . 'px; ' . $max . 'width: ' . $imgwidth . 'px;" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&file=' . urlencode ( $subdirformainimage . $fileformainimagesmall ) . '">' ;
2024-11-04 13:56:05 +01:00
$out .= '</div>' ;
} elseif ( ! empty ( $fileformainimage )) {
// Regenerate the thumbs
2025-02-11 22:21:59 +01:00
if ( ! file_exists ( $dirformainimage . '/' . $subdirformainimage . $fileformainimagemini )) {
2024-11-04 13:56:05 +01:00
$imgThumbMini = vignette ( $dirformainimage . '/' . $subdirformainimage . $fileformainimage , $maxwidthmini , $maxheightmini , '_mini' , $quality );
}
2025-02-11 22:21:59 +01:00
$imgThumbSmall = vignette ( $dirformainimage . '/' . $subdirformainimage . $fileformainimage , $maxwidthsmall , $maxheightsmall , '_small' , $quality );
2024-11-04 13:56:05 +01:00
$out .= '<div class="inline-block valignmiddle">' ;
$out .= '<img id="' . $htmlname . '" style="' . $max . 'height: ' . $imgheight . 'px; ' . $max . 'width: ' . $imgwidth . 'px;" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&file=' . urlencode ( $subdirformainimage . 'thumbs/' . basename ( $imgThumbSmall )) . '">' ;
$out .= '</div>' ;
}
} elseif ( ! empty ( $fileformainimage )) {
if ( file_exists ( $dirformainimage . '/' . $subdirformainimage . $fileformainimage )) {
$out .= '<div class="inline-block valignmiddle">' ;
$out .= '<img id="' . $htmlname . '" style="' . $max . 'height: ' . $imgheight . 'px; ' . $max . 'width: ' . $imgwidth . 'px;" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&file=' . urlencode ( $subdirformainimage . $fileformainimage ) . '">' ;
$out .= '</div>' ;
$out .= '<div class="inline-block valignmiddle marginrightonly"><a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?action=remove' . $htmlname . '&token=' . newToken () . '">' . img_delete ( $langs -> trans ( " Delete " ), '' , 'marginleftonly' ) . '</a></div>' ;
} else {
$out .= '<div class="inline-block valignmiddle">' ;
$out .= '<img id="' . $htmlname . '" height="' . $imgheight . '" src="' . DOL_URL_ROOT . '/public/theme/common/nophoto.png" title="File has been removed from disk">' ;
$out .= '</div>' ;
}
}
$out .= '</div>' ;
return $out ;
}
2011-08-16 11:36:00 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-16 08:47:05 +02:00
/**
2017-11-18 15:41:30 +01:00
* Show form to upload a new file .
2011-10-19 22:05:54 +02:00
*
2017-10-16 08:47:05 +02:00
* @ param string $url Url
* @ param string $title Title zone ( Title or '' or 'none' )
2024-09-18 03:27:25 +02:00
* @ param int < 0 , 1 > $addcancel 1 = Add 'Cancel' button
2017-11-18 15:41:30 +01:00
* @ param int $sectionid If upload must be done inside a particular ECM section ( is sectionid defined , sectiondir must not be )
* @ param int $perm Value of permission to allow upload
2019-02-24 08:50:35 +01:00
* @ param int $size Length of input file area . Deprecated .
2024-09-18 03:27:25 +02:00
* @ param ? CommonObject $object Object to use ( when attachment is done on an element )
2017-10-16 08:47:05 +02:00
* @ param string $options Add an option column
2024-09-18 03:27:25 +02:00
* @ param int < 0 , 1 > $useajax Use fileupload ajax ( 0 = never , 1 = if enabled , 2 = always whatever is option ) .
2022-09-03 20:08:13 +02:00
* Deprecated 2 should never be used and if 1 is used , option should not be enabled .
2019-02-24 08:50:35 +01:00
* @ param string $savingdocmask Mask to use to define output filename . For example 'XXXXX-__YYYYMMDD__-__file__'
2024-09-18 03:27:25 +02:00
* @ param int < 0 , 1 > $linkfiles 1 = Also add form to link files , 0 = Do not show form to link files
2017-10-16 08:47:05 +02:00
* @ param string $htmlname Name and id of HTML form ( 'formuserfile' by default , 'formuserfileecm' when used to upload a file in ECM )
* @ param string $accept Specifies the types of files accepted ( This is not a security check but an user interface facility . eg '.pdf,image/*' or '.png,.jpg' or 'video/*' )
2020-04-17 13:10:18 +02:00
* @ param string $sectiondir If upload must be done inside a particular directory ( if sectiondir defined , sectionid must not be )
2024-09-18 03:27:25 +02:00
* @ param int < 0 , 2 > $usewithoutform 0 = Default , 1 = Disable < form > and < input hidden > to use in existing form area , 2 = Disable the tag < form > only
* @ param int < 0 , 1 > $capture 1 = Add tag capture = " capture " to force use of micro or video recording to generate file . When setting this to 1 , you must also provide a value for $accept .
* @ param int < 0 , 1 > $disablemulti 0 = Default , 1 = Disable multiple file upload
* @ param int < 0 , 1 > $nooutput 0 = Output result with print , 1 = Return result
2024-10-26 18:24:40 +02:00
* @ return int | string | array { formToUploadAFile : string , formToAddALink : string } Return integer < 0 if KO , > 0 if OK , or string if $nooutput = 1 or array if $nooutput = 2
2017-10-16 08:47:05 +02:00
*/
2023-11-21 23:09:09 +01:00
public function form_attach_new_file ( $url , $title = '' , $addcancel = 0 , $sectionid = 0 , $perm = 1 , $size = 50 , $object = null , $options = '' , $useajax = 1 , $savingdocmask = '' , $linkfiles = 1 , $htmlname = 'formuserfile' , $accept = '' , $sectiondir = '' , $usewithoutform = 0 , $capture = 0 , $disablemulti = 0 , $nooutput = 0 )
2017-10-16 08:47:05 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-12 09:46:08 +01:00
global $conf , $langs , $hookmanager ;
2017-10-16 08:47:05 +02:00
$hookmanager -> initHooks ( array ( 'formfile' ));
2020-09-07 10:18:17 +02:00
// Deprecation warning
if ( $useajax == 2 ) {
dol_syslog ( __METHOD__ . " : using 2 for useajax is deprecated and should be not used " , LOG_WARNING );
}
2017-10-16 08:47:05 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> browser -> layout ) && $conf -> browser -> layout != 'classic' ) {
$useajax = 0 ;
}
2013-04-03 18:37:54 +02:00
2024-10-24 18:56:43 +02:00
//If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed
if ( ! $perm && getDolGlobalString ( 'MAIN_BUTTON_HIDE_UNAUTHORIZED' )) {
if ( $nooutput ) {
return '' ;
} else {
return 1 ;
2017-10-16 08:47:05 +02:00
}
2024-10-24 18:56:43 +02:00
}
2017-05-10 15:01:27 +02:00
2024-10-24 18:56:43 +02:00
// Section to generate the form to upload a new file
$out = " \n " . '<!-- Start form attach new file --><div class="formattachnewfile">' . " \n " ;
2011-08-16 11:36:00 +02:00
2024-10-24 18:56:43 +02:00
if ( $nooutput != 2 ) {
if ( empty ( $title )) {
$title = $langs -> trans ( " AttachANewFile " );
2021-02-23 22:03:23 +01:00
}
2024-10-24 18:56:43 +02:00
if ( $title != 'none' ) {
$out .= load_fiche_titre ( $title , '' , '' );
}
}
2013-11-01 17:36:22 +01:00
2024-10-24 18:56:43 +02:00
if ( empty ( $usewithoutform )) { // Try to avoid this and set instead the form by the caller.
// Add a param as GET parameter to detect when POST were cleaned by PHP because a file larger than post_max_size
$url .= ( strpos ( $url , '?' ) === false ? '?' : '&' ) . 'uploadform=1' ;
2020-10-03 14:02:53 +02:00
2024-10-24 18:56:43 +02:00
$out .= '<form name="' . $htmlname . '" id="' . $htmlname . '" action="' . $url . '" enctype="multipart/form-data" method="POST">' . " \n " ;
}
if ( empty ( $usewithoutform ) || $usewithoutform == 2 ) {
$out .= '<input type="hidden" name="token" value="' . newToken () . '">' . " \n " ;
$out .= '<input type="hidden" id="' . $htmlname . '_section_dir" name="section_dir" value="' . $sectiondir . '">' . " \n " ;
$out .= '<input type="hidden" id="' . $htmlname . '_section_id" name="section_id" value="' . $sectionid . '">' . " \n " ;
$out .= '<input type="hidden" name="sortfield" value="' . GETPOST ( 'sortfield' , 'aZ09comma' ) . '">' . " \n " ;
$out .= '<input type="hidden" name="sortorder" value="' . GETPOST ( 'sortorder' , 'aZ09comma' ) . '">' . " \n " ;
$out .= '<input type="hidden" name="page_y" value="">' . " \n " ;
}
2017-10-16 08:47:05 +02:00
2024-10-24 18:56:43 +02:00
$out .= '<table class="nobordernopadding centpercent">' ;
$out .= '<tr>' ;
2017-10-16 08:47:05 +02:00
2024-10-24 18:56:43 +02:00
if ( ! empty ( $options )) {
$out .= '<td>' . $options . '</td>' ;
}
2017-10-16 08:47:05 +02:00
2024-10-24 18:56:43 +02:00
$out .= '<td class="valignmiddle nowrap">' ;
2017-10-16 08:47:05 +02:00
2024-10-24 18:56:43 +02:00
$maxfilesizearray = getMaxFileSizeArray ();
$max = $maxfilesizearray [ 'max' ];
$maxmin = $maxfilesizearray [ 'maxmin' ];
$maxphptoshow = $maxfilesizearray [ 'maxphptoshow' ];
$maxphptoshowparam = $maxfilesizearray [ 'maxphptoshowparam' ];
if ( $maxmin > 0 ) {
$out .= '<input type="hidden" name="MAX_FILE_SIZE" value="' . ( $maxmin * 1024 ) . '">' ; // MAX_FILE_SIZE must precede the field type=file
}
$out .= '<input class="flat minwidth400 maxwidth200onsmartphone" type="file"' ;
$out .= (( getDolGlobalString ( 'MAIN_DISABLE_MULTIPLE_FILEUPLOAD' ) || $disablemulti ) ? ' name="userfile"' : ' name="userfile[]" multiple' );
$out .= ( ! getDolGlobalString ( 'MAIN_UPLOAD_DOC' ) || empty ( $perm ) ? ' disabled' : '' );
$out .= ( ! empty ( $accept ) ? ' accept="' . $accept . '"' : ' accept=""' );
$out .= ( ! empty ( $capture ) ? ' capture="capture"' : '' );
$out .= '>' ;
$out .= ' ' ;
if ( $sectionid ) { // Show overwrite if exists for ECM module only
$langs -> load ( 'link' );
$out .= '<span class="nowraponsmartphone"><input style="margin-right: 2px;" type="checkbox" id="overwritefile" name="overwritefile" value="1">' ;
$out .= '<label for="overwritefile" class="opacitylow paddingright">' . $langs -> trans ( " OverwriteIfExists " ) . '</label>' ;
$out .= '</span>' ;
}
$out .= '<input type="submit" class="button small reposition" name="sendit" value="' . $langs -> trans ( " Upload " ) . '"' ;
$out .= ( ! getDolGlobalString ( 'MAIN_UPLOAD_DOC' ) || empty ( $perm ) ? ' disabled' : '' );
$out .= '>' ;
2017-10-16 08:47:05 +02:00
2024-10-24 18:56:43 +02:00
if ( $addcancel ) {
$out .= ' ' ;
$out .= '<input type="submit" class="button small button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
}
2017-10-16 08:47:05 +02:00
2024-10-24 18:56:43 +02:00
if ( getDolGlobalString ( 'MAIN_UPLOAD_DOC' )) {
2024-12-03 11:18:35 +01:00
if ( $perm && empty ( $conf -> dol_optimize_smallscreen )) {
2024-10-24 18:56:43 +02:00
$langs -> load ( 'other' );
2024-11-09 03:20:15 +01:00
$menudolibarrsetupmax = $langs -> transnoentitiesnoconv ( " Home " ) . ' - ' . $langs -> transnoentitiesnoconv ( " Setup " ) . ' - ' . $langs -> transnoentitiesnoconv ( " Security " );
$tooltiptext = $langs -> trans ( " ThisLimitIsDefinedInSetupAt " , $menudolibarrsetupmax , $max , $maxphptoshowparam , $maxphptoshow );
2024-11-13 00:01:18 +01:00
if ( getDolGlobalString ( 'MAIN_SAVE_FILE_CONTENT_AS_TEXT' )) {
$tooltiptext .= '<br><br>Option to extract the file content in text to save it in database is ON <span class="opacitymedium">(' . getDolGlobalString ( 'MAIN_SAVE_FILE_CONTENT_AS_TEXT' ) . ')</span>' ;
2024-11-09 03:20:15 +01:00
}
2024-10-24 18:56:43 +02:00
$out .= ' ' ;
2024-11-09 03:20:15 +01:00
$out .= info_admin ( $tooltiptext , 1 , 0 , '1' , 'classfortooltip' );
2020-09-07 10:18:17 +02:00
}
2024-10-24 18:56:43 +02:00
} else {
$out .= ' (' . $langs -> trans ( " UploadDisabled " ) . ')' ;
}
$out .= " </td></tr> " ;
2013-11-01 17:36:22 +01:00
2024-10-24 18:56:43 +02:00
if ( $savingdocmask ) {
//add a global variable for disable the auto renaming on upload
2024-11-09 03:20:15 +01:00
$rename = getDolGlobalString ( 'MAIN_DOC_UPLOAD_NOT_RENAME_BY_DEFAULT' ) ? '' : 'checked' ;
2011-08-16 11:36:00 +02:00
2024-10-24 18:56:43 +02:00
$out .= '<tr>' ;
if ( ! empty ( $options )) {
$out .= '<td>' . $options . '</td>' ;
2019-03-07 20:53:03 +01:00
}
2024-10-24 18:56:43 +02:00
$out .= '<td valign="middle" class="nowrap">' ;
$out .= '<input type="checkbox" ' . $rename . ' class="savingdocmask" name="savingdocmask" id="savingdocmask" value="' . dol_escape_js ( $savingdocmask ) . '"> ' ;
$out .= '<label class="opacitymedium small" for="savingdocmask">' ;
$out .= $langs -> trans ( " SaveUploadedFileWithMask " , preg_replace ( '/__file__/' , $langs -> transnoentitiesnoconv ( " OriginFileName " ), $savingdocmask ), $langs -> transnoentitiesnoconv ( " OriginFileName " ));
$out .= '</label>' ;
$out .= '</td>' ;
$out .= '</tr>' ;
}
2011-08-16 11:36:00 +02:00
2024-10-24 18:56:43 +02:00
$out .= " </table> " ;
if ( empty ( $usewithoutform )) {
$out .= '</form>' ;
if ( empty ( $sectionid )) {
$out .= '<br>' ;
2024-10-24 18:05:46 +02:00
}
2024-10-24 18:56:43 +02:00
}
2024-10-24 18:05:46 +02:00
2024-10-24 18:56:43 +02:00
$parameters = array ( 'socid' => ( isset ( $GLOBALS [ 'socid' ]) ? $GLOBALS [ 'socid' ] : '' ), 'id' => ( isset ( $GLOBALS [ 'id' ]) ? $GLOBALS [ 'id' ] : '' ), 'url' => $url , 'perm' => $perm , 'options' => $options );
2025-01-13 20:04:35 +01:00
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable
2024-10-24 18:56:43 +02:00
$res = $hookmanager -> executeHooks ( 'formattachOptionsUpload' , $parameters , $object );
if ( empty ( $res )) {
$out = '<div class="' . ( $usewithoutform ? 'inline-block valignmiddle' : (( $nooutput == 2 ? '' : 'attacharea ' ) . 'attacharea' . $htmlname )) . '">' . $out . '</div>' ;
}
$out .= $hookmanager -> resPrint ;
2024-10-24 18:05:46 +02:00
2024-10-24 18:56:43 +02:00
$out .= " \n </div><!-- End form class=formattachnewfile --> \n " ;
2013-07-29 14:22:19 +02:00
2024-10-24 18:05:46 +02:00
2024-10-24 18:56:43 +02:00
$out2 = " " ;
2024-10-24 18:05:46 +02:00
2024-10-24 18:56:43 +02:00
// Section to generate the form to upload a new file
if ( $linkfiles ) {
$out2 .= " \n " . '<!-- Start form link new url --><div class="formlinknewurl">' . " \n " ;
$langs -> load ( 'link' );
2017-10-16 08:47:05 +02:00
2024-10-24 18:56:43 +02:00
if ( $nooutput != 2 ) {
$title = $langs -> trans ( " LinkANewFile " );
$out2 .= load_fiche_titre ( $title , '' , '' );
}
2019-03-07 20:53:03 +01:00
2024-10-24 18:56:43 +02:00
if ( empty ( $usewithoutform )) {
$out2 .= '<form name="' . $htmlname . '_link" id="' . $htmlname . '_link" action="' . $url . '" method="POST">' . " \n " ;
$out2 .= '<input type="hidden" name="token" value="' . newToken () . '">' . " \n " ;
$out2 .= '<input type="hidden" id="' . $htmlname . '_link_section_dir" name="link_section_dir" value="">' . " \n " ;
$out2 .= '<input type="hidden" id="' . $htmlname . '_link_section_id" name="link_section_id" value="' . $sectionid . '">' . " \n " ;
$out2 .= '<input type="hidden" name="page_y" value="">' . " \n " ;
}
2017-10-16 08:47:05 +02:00
2024-10-24 18:56:43 +02:00
$out2 .= '<div class="valignmiddle">' ;
$out2 .= '<div class="inline-block" style="padding-right: 10px;">' ;
if ( getDolGlobalString ( 'OPTIMIZEFORTEXTBROWSER' )) {
$out2 .= '<label for="link">' . $langs -> trans ( " URLToLink " ) . ':</label> ' ;
}
$out2 .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="' . dol_escape_htmltag ( $langs -> trans ( " URLToLink " )) . '">' ;
$out2 .= '</div>' ;
$out2 .= '<div class="inline-block" style="padding-right: 10px;">' ;
if ( getDolGlobalString ( 'OPTIMIZEFORTEXTBROWSER' )) {
$out2 .= '<label for="label">' . $langs -> trans ( " Label " ) . ':</label> ' ;
}
$out2 .= '<input type="text" class="flat" name="label" id="label" placeholder="' . dol_escape_htmltag ( $langs -> trans ( " Label " )) . '">' ;
$out2 .= '<input type="hidden" name="objecttype" value="' . $object -> element . '">' ;
$out2 .= '<input type="hidden" name="objectid" value="' . $object -> id . '">' ;
$out2 .= '</div>' ;
$out2 .= '<div class="inline-block" style="padding-right: 10px;">' ;
$out2 .= '<input type="submit" class="button small reposition" name="linkit" value="' . $langs -> trans ( " ToLink " ) . '"' ;
$out2 .= ( ! getDolGlobalString ( 'MAIN_UPLOAD_DOC' ) || empty ( $perm ) ? ' disabled' : '' );
$out2 .= '>' ;
$out2 .= '</div>' ;
$out2 .= '</div>' ;
if ( empty ( $usewithoutform )) {
$out2 .= '<div class="clearboth"></div>' ;
$out2 .= '</form><br>' ;
}
2013-07-29 14:22:19 +02:00
2024-10-24 18:56:43 +02:00
$parameters = array ( 'socid' => ( isset ( $GLOBALS [ 'socid' ]) ? $GLOBALS [ 'socid' ] : '' ), 'id' => ( isset ( $GLOBALS [ 'id' ]) ? $GLOBALS [ 'id' ] : '' ), 'url' => $url , 'perm' => $perm , 'options' => $options );
$res = $hookmanager -> executeHooks ( 'formattachOptions' , $parameters , $object );
if ( empty ( $res )) {
$out2 = '<div class="' . ( $usewithoutform ? 'inline-block valignmiddle' : (( $nooutput == 2 ? '' : 'attacharea ' ) . $htmlname )) . '">' . $out2 . '</div>' ;
2017-10-16 08:47:05 +02:00
}
2024-10-24 18:56:43 +02:00
$out2 .= $hookmanager -> resPrint ;
2013-11-07 02:56:56 +01:00
2024-10-24 18:56:43 +02:00
$out2 .= " \n </div><!-- End form class=formlinknewurl --> \n " ;
}
2024-10-24 18:05:46 +02:00
2024-10-24 18:56:43 +02:00
if ( $nooutput == 2 ) {
return array ( 'formToUploadAFile' => $out , 'formToAddALink' => $out2 );
} elseif ( $nooutput ) {
return $out . $out2 ;
} else {
print $out . $out2 ;
return 1 ;
2017-10-16 08:47:05 +02:00
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-16 08:47:05 +02:00
/**
* Show the box with list of available documents for object
*
* @ param string $modulepart propal , facture , facture_fourn , ...
* @ param string $modulesubdir Sub - directory to scan ( Example : '0/1/10' , 'FA/DD/MM/YY/9999' ) . Use '' if file is not into subdir of module .
* @ param string $filedir Directory to scan
* @ param string $urlsource Url of origin page ( for return )
2025-02-10 11:15:08 +01:00
* @ param int < 0 , 1 > $genallowed Generation is allowed ( 1 / 0 or array of formats )
* @ param int < 0 , 1 > $delallowed Remove is allowed ( 1 / 0 )
2017-10-16 08:47:05 +02:00
* @ param string $modelselected Model to preselect by default
* @ param integer $allowgenifempty Show warning if no model activated
* @ param integer $forcenomultilang Do not show language option ( even if MAIN_MULTILANGS defined )
* @ param int $iconPDF Show only PDF icon with link ( 1 / 0 )
* @ param int $notused Not used
* @ param integer $noform Do not output html form tags
* @ param string $param More param on http links
* @ param string $title Title to show on top of form
* @ param string $buttonlabel Label on submit button
* @ param string $codelang Default language code to use on lang combo box if multilang is enabled
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if KO , number of shown files if OK
2017-10-16 08:47:05 +02:00
* @ deprecated Use print xxx -> showdocuments () instead .
*/
2019-02-27 20:45:07 +01:00
public function show_documents ( $modulepart , $modulesubdir , $filedir , $urlsource , $genallowed , $delallowed = 0 , $modelselected = '' , $allowgenifempty = 1 , $forcenomultilang = 0 , $iconPDF = 0 , $notused = 0 , $noform = 0 , $param = '' , $title = '' , $buttonlabel = '' , $codelang = '' )
2017-10-16 08:47:05 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-11-12 09:46:08 +01:00
$this -> numoffiles = 0 ;
2019-01-27 11:55:16 +01:00
print $this -> showdocuments ( $modulepart , $modulesubdir , $filedir , $urlsource , $genallowed , $delallowed , $modelselected , $allowgenifempty , $forcenomultilang , $iconPDF , $notused , $noform , $param , $title , $buttonlabel , $codelang );
2017-10-16 08:47:05 +02:00
return $this -> numoffiles ;
}
/**
* Return a string to show the box with list of available documents for object .
* This also set the property $this -> numoffiles
*
2022-02-07 09:50:07 +01:00
* @ param string $modulepart Module the files are related to ( 'propal' , 'facture' , 'facture_fourn' , 'mymodule' , 'mymodule:MyObject' , 'mymodule_temp' , ... )
2022-03-07 13:21:32 +01:00
* @ param string $modulesubdir Existing ( so sanitized ) sub - directory to scan ( Example : '0/1/10' , 'FA/DD/MM/YY/9999' ) . Use '' if file is not into a subdir of module .
* @ param string $filedir Directory to scan ( must not end with a / ) . Example : '/mydolibarrdocuments/facture/FAYYMM-1234'
2017-10-16 08:47:05 +02:00
* @ param string $urlsource Url of origin page ( for return )
2025-02-10 11:15:08 +01:00
* @ param int < 0 , 1 >| string [] $genallowed Generation is allowed ( 1 / 0 or array list of templates )
* @ param int < 0 , 1 > $delallowed Remove is allowed ( 1 / 0 )
2017-10-16 08:47:05 +02:00
* @ param string $modelselected Model to preselect by default
2025-02-10 11:15:08 +01:00
* @ param int < 0 , 1 > $allowgenifempty Allow generation even if list of template ( $genallowed ) is empty ( show however a warning )
* @ param int < 0 , 1 > $forcenomultilang Do not show language option ( even if MAIN_MULTILANGS defined )
2017-10-16 08:47:05 +02:00
* @ param int $iconPDF Deprecated , see getDocumentsLink
* @ param int $notused Not used
2025-02-10 11:15:08 +01:00
* @ param int < 0 , 1 > $noform Do not output html form tags
2017-10-16 08:47:05 +02:00
* @ param string $param More param on http links
2020-02-11 10:38:09 +01:00
* @ param string $title Title to show on top of form . Example : '' ( Default to " Documents " ) or 'none'
2017-10-16 08:47:05 +02:00
* @ param string $buttonlabel Label on submit button
* @ param string $codelang Default language code to use on lang combo box if multilang is enabled
* @ param string $morepicto Add more HTML content into cell with picto
2024-04-25 10:47:55 +02:00
* @ param Object | null $object Object when method is called from an object card .
2025-02-10 11:15:08 +01:00
* @ param int < 0 , 1 > $hideifempty Hide section of generated files if there is no file
2020-04-08 10:24:32 +02:00
* @ param string $removeaction ( optional ) The action to remove a file
2022-01-22 14:03:39 +01:00
* @ param string $tooltipontemplatecombo Text to show on a tooltip after the combo list of templates
2025-02-10 11:15:08 +01:00
* @ return string | int <- 1 , - 1 > Output string with HTML array of documents ( might be empty string )
2017-10-16 08:47:05 +02:00
*/
2022-01-22 14:03:39 +01:00
public function showdocuments ( $modulepart , $modulesubdir , $filedir , $urlsource , $genallowed , $delallowed = 0 , $modelselected = '' , $allowgenifempty = 1 , $forcenomultilang = 0 , $iconPDF = 0 , $notused = 0 , $noform = 0 , $param = '' , $title = '' , $buttonlabel = '' , $codelang = '' , $morepicto = '' , $object = null , $hideifempty = 0 , $removeaction = 'remove_file' , $tooltipontemplatecombo = '' )
2017-10-16 08:47:05 +02:00
{
2021-04-15 17:56:55 +02:00
global $dolibarr_main_url_root ;
2015-04-23 23:21:06 +02:00
// Deprecation warning
2019-11-12 09:46:08 +01:00
if ( ! empty ( $iconPDF )) {
dol_syslog ( __METHOD__ . " : passing iconPDF parameter is deprecated " , LOG_WARNING );
2015-04-23 23:21:06 +02:00
}
2017-01-15 12:09:26 +01:00
2017-10-16 08:47:05 +02:00
global $langs , $conf , $user , $hookmanager ;
2018-02-21 11:02:45 +01:00
global $form ;
2011-08-16 11:36:00 +02:00
2021-09-21 18:47:34 +02:00
$reshook = 0 ;
2021-09-21 18:49:00 +02:00
if ( is_object ( $hookmanager )) {
2021-09-21 22:23:14 +02:00
$parameters = array (
2024-03-13 00:29:31 +01:00
'modulepart' => & $modulepart ,
'modulesubdir' => & $modulesubdir ,
'filedir' => & $filedir ,
'urlsource' => & $urlsource ,
'genallowed' => & $genallowed ,
'delallowed' => & $delallowed ,
'modelselected' => & $modelselected ,
'allowgenifempty' => & $allowgenifempty ,
'forcenomultilang' => & $forcenomultilang ,
'noform' => & $noform ,
'param' => & $param ,
'title' => & $title ,
'buttonlabel' => & $buttonlabel ,
'codelang' => & $codelang ,
'morepicto' => & $morepicto ,
'hideifempty' => & $hideifempty ,
'removeaction' => & $removeaction
2021-09-21 22:23:14 +02:00
);
2021-10-04 19:20:37 +02:00
$reshook = $hookmanager -> executeHooks ( 'showDocuments' , $parameters , $object ); // Note that parameters may have been updated by hook
2021-09-21 18:47:34 +02:00
// May report error
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2021-09-21 18:49:00 +02:00
}
2021-09-21 18:47:34 +02:00
}
// Remode default action if $reskook > 0
if ( $reshook > 0 ) {
2021-10-04 19:20:37 +02:00
return $hookmanager -> resPrint ;
2021-09-21 18:47:34 +02:00
}
2021-02-23 22:03:23 +01:00
if ( ! is_object ( $form )) {
$form = new Form ( $this -> db );
}
2011-08-16 11:36:00 +02:00
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2011-08-16 11:36:00 +02:00
2017-10-16 08:47:05 +02:00
// For backward compatibility
2019-11-12 09:46:08 +01:00
if ( ! empty ( $iconPDF )) {
2017-10-16 08:47:05 +02:00
return $this -> getDocumentsLink ( $modulepart , $modulesubdir , $filedir );
}
2013-06-16 20:08:45 +02:00
2018-12-21 11:23:44 +01:00
// Add entity in $param if not already exists
if ( ! preg_match ( '/entity\=[0-9]+/' , $param )) {
2023-12-28 12:37:34 +01:00
$param .= ( $param ? '&' : '' ) . 'entity=' . ( empty ( $object -> entity ) ? $conf -> entity : $object -> entity );
2018-12-21 11:23:44 +01:00
}
2018-02-25 17:43:19 +01:00
2019-11-12 09:46:08 +01:00
$printer = 0 ;
2021-11-28 20:55:17 +01:00
// The direct print feature is implemented only for such elements
if ( in_array ( $modulepart , array ( 'contract' , 'facture' , 'supplier_proposal' , 'propal' , 'proposal' , 'order' , 'commande' , 'expedition' , 'commande_fournisseur' , 'expensereport' , 'delivery' , 'ticket' ))) {
2024-11-15 23:00:56 +01:00
$printer = ( $user -> hasRight ( 'printing' , 'read' ) && isModEnabled ( 'printing' ));
2017-10-16 08:47:05 +02:00
}
2017-01-15 12:09:26 +01:00
2017-10-16 08:47:05 +02:00
$hookmanager -> initHooks ( array ( 'formfile' ));
2014-12-07 18:24:45 +01:00
2018-02-21 11:02:45 +01:00
// Get list of files
2024-10-26 18:24:40 +02:00
$file_list = array ();
2021-02-23 22:03:23 +01:00
if ( ! empty ( $filedir )) {
2019-11-12 09:46:08 +01:00
$file_list = dol_dir_list ( $filedir , 'files' , 0 , '' , '(\.meta|_preview.*.*\.png)$' , 'date' , SORT_DESC );
2018-02-21 11:02:45 +01:00
}
2021-02-23 22:03:23 +01:00
if ( $hideifempty && empty ( $file_list )) {
return '' ;
}
2011-08-16 11:36:00 +02:00
2019-11-12 09:46:08 +01:00
$out = '' ;
$forname = 'builddoc' ;
$headershown = 0 ;
$showempty = 0 ;
$i = 0 ;
2010-05-03 10:43:32 +02:00
2019-11-12 09:46:08 +01:00
$out .= " \n " . '<!-- Start show_document -->' . " \n " ;
2017-10-16 08:47:05 +02:00
//print 'filedir='.$filedir;
2011-08-16 11:36:00 +02:00
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/massfilesarea_/' , $modulepart )) {
2019-11-12 09:46:08 +01:00
$out .= '<div id="show_files"><br></div>' . " \n " ;
$title = $langs -> trans ( " MassFilesArea " ) . ' <a href="" id="togglemassfilesarea" ref="shown">(' . $langs -> trans ( " Hide " ) . ')</a>' ;
2023-02-18 15:10:05 +01:00
$title .= '<script nonce="' . getNonce () . ' " >
2016-10-28 12:00:30 +02:00
jQuery ( document ) . ready ( function () {
jQuery ( \ ' #togglemassfilesarea\').click(function() {
if ( jQuery ( \ ' #togglemassfilesarea\').attr(\'ref\') == "shown")
{
jQuery ( \ '#' . $modulepart . ' _table\ ' ) . hide ();
jQuery ( \ ' #togglemassfilesarea\').attr("ref", "hidden");
jQuery ( \ '#togglemassfilesarea\').text("(' . dol_escape_js ( $langs -> trans ( " Show " )) . ' ) " );
}
else
{
jQuery ( \ '#' . $modulepart . ' _table\ ' ) . show ();
jQuery ( \ ' #togglemassfilesarea\').attr("ref","shown");
jQuery ( \ '#togglemassfilesarea\').text("(' . dol_escape_js ( $langs -> trans ( " Hide " )) . ' ) " );
}
return false ;
2017-06-10 13:44:20 +02:00
});
2016-10-28 12:00:30 +02:00
});
</ script > ' ;
2017-10-16 08:47:05 +02:00
}
2017-06-10 13:44:20 +02:00
2019-11-12 09:46:08 +01:00
$titletoshow = $langs -> trans ( " Documents " );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $title )) {
$titletoshow = ( $title == 'none' ? '' : $title );
}
2020-10-06 16:10:48 +02:00
2023-01-11 17:31:37 +01:00
$submodulepart = $modulepart ;
// modulepart = 'nameofmodule' or 'nameofmodule:NameOfObject'
$tmp = explode ( ':' , $modulepart );
if ( ! empty ( $tmp [ 1 ])) {
$modulepart = $tmp [ 0 ];
$submodulepart = $tmp [ 1 ];
}
2023-02-09 18:01:59 +01:00
$addcolumforpicto = ( $delallowed || $printer || $morepicto );
$colspan = ( 4 + ( $addcolumforpicto ? 1 : 0 ));
$colspanmore = 0 ;
2017-10-16 08:47:05 +02:00
// Show table
2021-02-23 22:03:23 +01:00
if ( $genallowed ) {
2019-11-12 09:46:08 +01:00
$modellist = array ();
2011-08-16 11:36:00 +02:00
2021-02-23 22:03:23 +01:00
if ( $modulepart == 'company' ) {
2021-10-25 22:07:31 +02:00
$showempty = 1 ; // can have no template active
2021-02-23 22:03:23 +01:00
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/societe/modules_societe.class.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModeleThirdPartyDoc :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'propal' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/propale/modules_propale.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFPropales :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'supplier_proposal' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_proposal/modules_supplier_proposal.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFSupplierProposal :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'commande' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/commande/modules_commande.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFCommandes :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'expedition' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php' ;
2023-08-05 14:11:44 +02:00
$modellist = ModelePdfExpedition :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'reception' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2018-10-05 16:21:50 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/reception/modules_reception.php' ;
$modellist = ModelePdfReception :: liste_modeles ( $this -> db );
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'delivery' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2020-10-06 13:32:02 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/delivery/modules_delivery.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFDeliveryOrder :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'ficheinter' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/fichinter/modules_fichinter.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFFicheinter :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'facture' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFFactures :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'contract' ) {
2021-10-25 22:07:31 +02:00
$showempty = 1 ; // can have no template active
2021-02-23 22:03:23 +01:00
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/contract/modules_contract.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFContract :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'project' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/project/modules_project.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFProjects :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'project_task' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/project/task/modules_task.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFTask :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'product' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/product/modules_product.class.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFProduct :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'product_batch' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2018-04-12 15:10:37 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/product_batch/modules_product_batch.class.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFProductBatch :: liste_modeles ( $this -> db );
2018-04-12 15:10:37 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'stock' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2018-05-25 11:19:38 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/stock/modules_stock.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFStock :: liste_modeles ( $this -> db );
2018-05-22 02:09:52 +02:00
}
2023-11-26 15:51:00 +01:00
} elseif ( $modulepart == 'hrm' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
include_once DOL_DOCUMENT_ROOT . '/core/modules/hrm/modules_evaluation.php' ;
$modellist = ModelePDFEvaluation :: liste_modeles ( $this -> db );
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'movement' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2024-11-12 23:18:02 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/movement/modules_movement.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFMovement :: liste_modeles ( $this -> db );
2018-05-22 02:09:52 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'export' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/export/modules_export.php' ;
2023-08-24 16:15:18 +02:00
//$modellist = ModeleExports::liste_modeles($this->db); // liste_modeles() does not exists. We are using listOfAvailableExportFormat() method instead that return a different array format.
2024-05-30 13:37:17 +02:00
$modellist = array ();
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_order/modules_commandefournisseur.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFSuppliersOrders :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice' ) {
2021-10-25 22:07:31 +02:00
$showempty = 1 ; // can have no template active
2021-02-23 22:03:23 +01:00
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFSuppliersInvoices :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'supplier_payment' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_payment/modules_supplier_payment.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFSuppliersPayments :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'remisecheque' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/cheque/modules_chequereceipts.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModeleChequeReceipts :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'donation' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/dons/modules_don.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModeleDon :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'member' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/member/modules_cards.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFCards :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'agenda' || $modulepart == 'actions' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/action/modules_action.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModeleAction :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'expensereport' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/expensereport/modules_expensereport.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModeleExpenseReport :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'unpaid' ) {
2019-11-12 09:46:08 +01:00
$modellist = '' ;
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'user' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/user/modules_user.class.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFUser :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'usergroup' ) {
if ( is_array ( $genallowed )) {
$modellist = $genallowed ;
} else {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/usergroup/modules_usergroup.class.php' ;
2019-11-12 09:46:08 +01:00
$modellist = ModelePDFUserGroup :: liste_modeles ( $this -> db );
2017-10-16 08:47:05 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-09-07 10:18:17 +02:00
// For normalized standard modules
2020-06-01 16:44:22 +02:00
$file = dol_buildpath ( '/core/modules/' . $modulepart . '/modules_' . strtolower ( $submodulepart ) . '.php' , 0 );
2021-02-23 22:03:23 +01:00
if ( file_exists ( $file )) {
2019-11-12 09:46:08 +01:00
$res = include_once $file ;
2021-03-01 20:37:16 +01:00
} else {
// For normalized external modules.
2020-09-07 10:18:17 +02:00
$file = dol_buildpath ( '/' . $modulepart . '/core/modules/' . $modulepart . '/modules_' . strtolower ( $submodulepart ) . '.php' , 0 );
2019-11-12 09:46:08 +01:00
$res = include_once $file ;
2017-10-16 08:47:05 +02:00
}
2020-06-01 16:44:22 +02:00
2021-06-20 04:10:25 +02:00
$class = 'ModelePDF' . ucfirst ( $submodulepart );
2019-11-04 14:13:36 +01:00
2021-02-23 22:03:23 +01:00
if ( class_exists ( $class )) {
2019-11-12 09:46:08 +01:00
$modellist = call_user_func ( $class . '::liste_modeles' , $this -> db );
2020-05-21 15:05:19 +02:00
} else {
2022-02-07 09:50:07 +01:00
dol_print_error ( $this -> db , " Bad value for modulepart ' " . $modulepart . " ' in showdocuments (class " . $class . " for Doc generation not found) " );
2017-10-16 08:47:05 +02:00
return - 1 ;
}
}
2011-08-16 11:36:00 +02:00
2018-02-15 12:57:04 +01:00
// Set headershown to avoid to have table opened a second time later
2019-11-12 09:46:08 +01:00
$headershown = 1 ;
2011-08-16 11:36:00 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $buttonlabel )) {
$buttonlabel = $langs -> trans ( 'Generate' );
}
2017-01-15 12:09:26 +01:00
2021-02-23 22:03:23 +01:00
if ( $conf -> browser -> layout == 'phone' ) {
$urlsource .= '#' . $forname . '_form' ; // So we switch to form after a generation
}
if ( empty ( $noform )) {
2021-10-05 11:03:51 +02:00
$out .= '<form action="' . $urlsource . '" id="' . $forname . '_form" method="post">' ;
2021-02-23 22:03:23 +01:00
}
2019-11-12 09:46:08 +01:00
$out .= '<input type="hidden" name="action" value="builddoc">' ;
2021-10-05 11:03:51 +02:00
$out .= '<input type="hidden" name="page_y" value="">' ;
2019-12-01 10:20:11 +01:00
$out .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2011-08-16 11:36:00 +02:00
2019-11-12 09:46:08 +01:00
$out .= load_fiche_titre ( $titletoshow , '' , '' );
$out .= '<div class="div-table-responsive-no-min">' ;
$out .= '<table class="liste formdoc noborder centpercent">' ;
2011-08-16 11:36:00 +02:00
2019-11-12 09:46:08 +01:00
$out .= '<tr class="liste_titre">' ;
2023-06-13 02:13:09 +02:00
$addcolumforpicto = ( $delallowed || $printer || $morepicto );
$colspan = ( 4 + ( $addcolumforpicto ? 1 : 0 ));
2024-05-30 13:37:17 +02:00
$colspanmore = 0 ;
2011-08-16 11:36:00 +02:00
2019-11-12 09:46:08 +01:00
$out .= '<th colspan="' . $colspan . '" class="formdoc liste_titre maxwidthonsmartphone center">' ;
2011-08-16 11:36:00 +02:00
2017-10-16 08:47:05 +02:00
// Model
2021-02-23 22:03:23 +01:00
if ( ! empty ( $modellist )) {
2019-03-06 17:21:44 +01:00
asort ( $modellist );
2019-11-12 09:46:08 +01:00
$out .= '<span class="hideonsmartphone">' . $langs -> trans ( 'Model' ) . ' </span>' ;
2021-02-23 22:03:23 +01:00
if ( is_array ( $modellist ) && count ( $modellist ) == 1 ) { // If there is only one element
2019-11-12 09:46:08 +01:00
$arraykeys = array_keys ( $modellist );
$modelselected = $arraykeys [ 0 ];
2017-10-16 08:47:05 +02:00
}
2021-12-25 12:44:46 +01:00
$morecss = 'minwidth75 maxwidth200' ;
2021-02-23 22:03:23 +01:00
if ( $conf -> browser -> layout == 'phone' ) {
$morecss = 'maxwidth100' ;
}
2023-06-13 02:13:09 +02:00
$out .= $form -> selectarray ( 'model' , $modellist , $modelselected , $showempty , 0 , 0 , '' , 0 , 0 , 0 , '' , $morecss , 1 , '' , 0 , 0 );
2021-02-23 22:03:23 +01:00
if ( $conf -> use_javascript_ajax ) {
2019-11-12 09:46:08 +01:00
$out .= ajax_combobox ( 'model' );
2017-11-14 17:51:04 +01:00
}
2022-01-22 14:03:39 +01:00
$out .= $form -> textwithpicto ( '' , $tooltipontemplatecombo , 1 , 'help' , 'marginrightonly' , 0 , 3 , '' , 0 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 09:46:08 +01:00
$out .= '<div class="float">' . $langs -> trans ( " Files " ) . '</div>' ;
2017-10-16 08:47:05 +02:00
}
// Language code (if multilang)
2022-09-24 14:42:35 +02:00
if (( $allowgenifempty || ( is_array ( $modellist ) && count ( $modellist ) > 0 )) && getDolGlobalInt ( 'MAIN_MULTILANGS' ) && ! $forcenomultilang && ( ! empty ( $modellist ) || $showempty )) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php' ;
2019-11-12 09:46:08 +01:00
$formadmin = new FormAdmin ( $this -> db );
2021-06-20 04:10:25 +02:00
$defaultlang = ( $codelang && $codelang != 'auto' ) ? $codelang : $langs -> getDefaultLang ();
2019-11-12 09:46:08 +01:00
$morecss = 'maxwidth150' ;
2021-02-23 22:03:23 +01:00
if ( $conf -> browser -> layout == 'phone' ) {
$morecss = 'maxwidth100' ;
}
2024-10-26 18:24:40 +02:00
$out .= $formadmin -> select_language ( $defaultlang , 'lang_id' , 0 , array (), 0 , 0 , 0 , $morecss );
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 09:46:08 +01:00
$out .= ' ' ;
2017-10-16 08:47:05 +02:00
}
2011-08-16 11:36:00 +02:00
2025-01-02 20:40:22 +01:00
// Button to generate document
2022-04-11 19:21:04 +02:00
$genbutton = '<input class="button buttongen reposition nomargintop nomarginbottom" id="' . $forname . '_generatebutton" name="' . $forname . '_generatebutton"' ;
2019-11-12 09:46:08 +01:00
$genbutton .= ' type="submit" value="' . $buttonlabel . '"' ;
2021-02-23 22:03:23 +01:00
if ( ! $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist )) {
$genbutton .= ' disabled' ;
}
2019-11-12 09:46:08 +01:00
$genbutton .= '>' ;
2021-02-23 22:03:23 +01:00
if ( $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist ) && empty ( $conf -> dol_no_mouse_hover ) && $modulepart != 'unpaid' ) {
$langs -> load ( " errors " );
$genbutton .= ' ' . img_warning ( $langs -> transnoentitiesnoconv ( " WarningNoDocumentModelActivated " ));
2025-01-02 20:40:22 +01:00
/* if ( empty ( $modellist )) {
$genbutton .= '<input type="hidden" name="model" value="auto">' ;
} */
2021-02-23 22:03:23 +01:00
}
if ( ! $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist ) && empty ( $conf -> dol_no_mouse_hover ) && $modulepart != 'unpaid' ) {
$genbutton = '' ;
}
if ( empty ( $modellist ) && ! $showempty && $modulepart != 'unpaid' ) {
$genbutton = '' ;
2017-10-16 08:47:05 +02:00
}
2019-11-12 09:46:08 +01:00
$out .= $genbutton ;
$out .= '</th>' ;
2016-09-12 18:37:40 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $hookmanager -> hooks [ 'formfile' ])) {
foreach ( $hookmanager -> hooks [ 'formfile' ] as $module ) {
if ( method_exists ( $module , 'formBuilddocLineOptions' )) {
2019-05-27 13:28:10 +02:00
$colspanmore ++ ;
$out .= '<th></th>' ;
}
2017-10-16 08:47:05 +02:00
}
}
2019-11-12 09:46:08 +01:00
$out .= '</tr>' ;
2011-08-16 11:36:00 +02:00
2017-10-16 08:47:05 +02:00
// Execute hooks
2024-03-13 00:29:31 +01:00
$parameters = array ( 'colspan' => ( $colspan + $colspanmore ), 'socid' => ( isset ( $GLOBALS [ 'socid' ]) ? $GLOBALS [ 'socid' ] : '' ), 'id' => ( isset ( $GLOBALS [ 'id' ]) ? $GLOBALS [ 'id' ] : '' ), 'modulepart' => $modulepart );
2021-02-23 22:03:23 +01:00
if ( is_object ( $hookmanager )) {
2019-01-27 11:55:16 +01:00
$reshook = $hookmanager -> executeHooks ( 'formBuilddocOptions' , $parameters , $GLOBALS [ 'object' ]);
2019-11-12 09:46:08 +01:00
$out .= $hookmanager -> resPrint ;
2017-10-16 08:47:05 +02:00
}
}
2017-06-10 13:44:20 +02:00
2017-10-16 08:47:05 +02:00
// Get list of files
2021-02-23 22:03:23 +01:00
if ( ! empty ( $filedir )) {
2017-10-16 08:47:05 +02:00
$link_list = array ();
2021-02-23 22:03:23 +01:00
if ( is_object ( $object )) {
2019-11-12 09:46:08 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php' ;
2017-10-16 08:47:05 +02:00
$link = new Link ( $this -> db );
2024-10-26 18:24:40 +02:00
$sortfield = $sortorder = '' ;
2017-10-16 08:47:05 +02:00
$res = $link -> fetchAll ( $link_list , $object -> element , $object -> id , $sortfield , $sortorder );
}
2011-08-16 11:36:00 +02:00
2019-11-12 09:46:08 +01:00
$out .= '<!-- html.formfile::showdocuments -->' . " \n " ;
2017-10-16 08:47:05 +02:00
// Show title of array if not already shown
2019-11-12 09:46:08 +01:00
if (( ! empty ( $file_list ) || ! empty ( $link_list ) || preg_match ( '/^massfilesarea/' , $modulepart ))
2021-02-23 22:03:23 +01:00
&& ! $headershown ) {
2019-11-12 09:46:08 +01:00
$headershown = 1 ;
$out .= '<div class="titre">' . $titletoshow . '</div>' . " \n " ;
$out .= '<div class="div-table-responsive-no-min">' ;
$out .= '<table class="noborder centpercent" id="' . $modulepart . '_table">' . " \n " ;
2017-10-16 08:47:05 +02:00
}
// Loop on each file found
2021-02-23 22:03:23 +01:00
if ( is_array ( $file_list )) {
2024-10-26 18:24:40 +02:00
'@phan-var-force array<array{name:string,path:string,level1name:string,relativename:string,fullname:string,date:string,size:int,perm:int,type:string}> $file_list' ; // phan limitations loose typing information with empty() tests, etc. Force again.
2021-04-15 17:56:55 +02:00
// Defined relative dir to DOL_DATA_ROOT
$relativedir = '' ;
if ( $filedir ) {
$relativedir = preg_replace ( '/^' . preg_quote ( DOL_DATA_ROOT , '/' ) . '/' , '' , $filedir );
$relativedir = preg_replace ( '/^[\\/]/' , '' , $relativedir );
}
// Get list of files stored into database for same relative directory
if ( $relativedir ) {
completeFileArrayWithDatabaseInfo ( $file_list , $relativedir );
2024-11-11 14:48:18 +01:00
'@phan-var-force array<array{name:string,path:string,level1name:string,relativename:string,fullname:string,date:string,size:int,perm:int,type:string,position_name:string,cover:string,keywords:string,acl:string,rowid:int,label:string,share:string}> $file_list' ;
2021-04-15 17:56:55 +02:00
//var_dump($sortfield.' - '.$sortorder);
2021-05-20 17:40:44 +02:00
if ( ! empty ( $sortfield ) && ! empty ( $sortorder )) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
2021-04-15 17:56:55 +02:00
$file_list = dol_sort_array ( $file_list , $sortfield , $sortorder );
}
}
2025-02-10 11:15:08 +01:00
'@phan-var-force array<array{name:string,path:string,level1name:string,relativename:string,fullname:string,date:string,size:int,perm:int,type:string,position_name:string,cover:string,keywords:string,acl:string,rowid:int,label:string,share:string}> $file_list' ;
2024-11-12 19:41:21 +01:00
require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmfiles.class.php' ;
2024-10-27 02:40:58 +01:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
foreach ( $file_list as $file ) {
2024-10-27 02:40:58 +01:00
$i ++ ;
2024-11-12 19:41:21 +01:00
if ( ! empty ( $file [ 'rowid' ])) {
$ecmfile = new EcmFiles ( $this -> db );
$ecmfile -> fetch ( $file [ 'rowid' ]);
} else {
$ecmfile = null ;
}
2024-10-27 02:40:58 +01:00
2012-09-18 18:00:05 +02:00
// Define relative path for download link (depends on module)
2024-10-26 18:24:40 +02:00
$relativepath = ( string ) $file [ " name " ]; // Cas general
2021-02-23 22:03:23 +01:00
if ( $modulesubdir ) {
2024-10-26 18:24:40 +02:00
$relativepath = ( string ) $modulesubdir . " / " . $file [ " name " ]; // Cas propal, facture...
2021-02-23 22:03:23 +01:00
}
if ( $modulepart == 'export' ) {
2024-10-26 18:24:40 +02:00
$relativepath = ( string ) $file [ " name " ]; // Other case
2021-02-23 22:03:23 +01:00
}
2013-07-10 15:45:16 +02:00
2024-10-27 02:40:58 +01:00
$out .= '<tr class="oddeven' . (( ! $genallowed && $i == 1 ) ? ' trfirstline' : '' ) . '">' ;
2012-09-18 18:00:05 +02:00
2014-06-05 23:30:20 +02:00
$documenturl = DOL_URL_ROOT . '/document.php' ;
2021-02-23 22:03:23 +01:00
if ( isset ( $conf -> global -> DOL_URL_ROOT_DOCUMENT_PHP )) {
2024-01-05 04:18:53 +01:00
$documenturl = getDolGlobalString ( 'DOL_URL_ROOT_DOCUMENT_PHP' ); // To use another wrapper
2021-02-23 22:03:23 +01:00
}
2017-06-10 13:44:20 +02:00
2012-09-18 18:00:05 +02:00
// Show file name with link to download
2022-12-28 16:20:35 +01:00
$imgpreview = $this -> showPreview ( $file , $modulepart , $relativepath , 0 , $param );
2022-10-17 14:31:48 +02:00
2021-06-26 00:08:19 +02:00
$out .= '<td class="minwidth200 tdoverflowmax300">' ;
2022-10-17 14:31:48 +02:00
if ( $imgpreview ) {
2022-11-02 02:42:14 +01:00
$out .= '<span class="spanoverflow widthcentpercentminusx valignmiddle">' ;
2022-10-17 14:31:48 +02:00
} else {
$out .= '<span class="spanoverflow">' ;
}
2024-11-12 19:41:21 +01:00
if ( is_object ( $ecmfile )) {
$out .= $ecmfile -> getNomUrl ( 1 , $modulepart , 0 , 0 , ' documentdownload' );
} else {
$out .= '<a class="documentdownload paddingright" ' ;
if ( getDolGlobalInt ( 'MAIN_DISABLE_FORCE_SAVEAS' ) == 2 ) {
$out .= 'target="_blank" ' ;
}
$out .= 'href="' . $documenturl . '?modulepart=' . $modulepart . '&file=' . urlencode ( $relativepath ) . ( $param ? '&' . $param : '' ) . '"' ;
$mime = dol_mimetype ( $relativepath , '' , 0 );
if ( preg_match ( '/text/' , $mime )) {
$out .= ' target="_blank" rel="noopener noreferrer"' ;
}
$out .= ' title="' . dol_escape_htmltag ( $file [ " name " ]) . '"' ;
$out .= '>' ;
$out .= img_mime ( $file [ " name " ], $langs -> trans ( " File " ) . ': ' . $file [ " name " ]);
$out .= dol_trunc ( $file [ " name " ], 150 );
$out .= '</a>' ;
}
2022-10-17 13:58:34 +02:00
$out .= '</span>' . " \n " ;
2022-10-17 14:31:48 +02:00
$out .= $imgpreview ;
2019-11-12 09:46:08 +01:00
$out .= '</td>' ;
2012-09-18 18:00:05 +02:00
// Show file size
2019-11-12 09:46:08 +01:00
$size = ( ! empty ( $file [ 'size' ]) ? $file [ 'size' ] : dol_filesize ( $filedir . " / " . $file [ " name " ]));
2024-10-16 20:46:52 +02:00
$out .= '<td class="nowraponall right" title="' . dolPrintHTML ( $size . ' ' . $langs -> trans ( " Bytes " )) . '">' . dol_print_size ( $size , 1 , 1 ) . '</td>' ;
2012-09-18 18:00:05 +02:00
// Show file date
2019-11-12 09:46:08 +01:00
$date = ( ! empty ( $file [ 'date' ]) ? $file [ 'date' ] : dol_filemtime ( $filedir . " / " . $file [ " name " ]));
$out .= '<td class="nowrap right">' . dol_print_date ( $date , 'dayhour' , 'tzuser' ) . '</td>' ;
2012-09-18 18:00:05 +02:00
2021-04-15 17:56:55 +02:00
// Show share link
2021-06-26 00:08:19 +02:00
$out .= '<td class="nowraponall">' ;
2021-06-20 16:24:58 +02:00
if ( ! empty ( $file [ 'share' ])) {
2021-04-15 17:56:55 +02:00
// Define $urlwithroot
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
//print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
$forcedownload = 0 ;
$paramlink = '' ;
if ( ! empty ( $file [ 'share' ])) {
$paramlink .= ( $paramlink ? '&' : '' ) . 'hashp=' . $file [ 'share' ]; // Hash for public share
}
if ( $forcedownload ) {
$paramlink .= ( $paramlink ? '&' : '' ) . 'attachment=1' ;
}
$fulllink = $urlwithroot . '/document.php' . ( $paramlink ? '?' . $paramlink : '' );
2022-10-08 03:05:19 +02:00
$out .= '<a href="' . $fulllink . '" target="_blank" rel="noopener">' . img_picto ( $langs -> trans ( " FileSharedViaALink " ), 'globe' ) . '</a> ' ;
2022-04-11 19:21:04 +02:00
$out .= '<input type="text" class="quatrevingtpercentminusx width75 nopadding small" id="downloadlink' . $file [ 'rowid' ] . '" name="downloadexternallink" title="' . dol_escape_htmltag ( $langs -> trans ( " FileSharedViaALink " )) . '" value="' . dol_escape_htmltag ( $fulllink ) . '">' ;
2021-04-15 17:56:55 +02:00
$out .= ajax_autoselect ( 'downloadlink' . $file [ 'rowid' ]);
} else {
//print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
}
$out .= '</td>' ;
2021-10-05 10:24:31 +02:00
// Show picto delete, print...
2021-02-23 22:03:23 +01:00
if ( $delallowed || $printer || $morepicto ) {
2019-11-12 09:46:08 +01:00
$out .= '<td class="right nowraponall">' ;
2021-02-23 22:03:23 +01:00
if ( $delallowed ) {
2018-08-19 03:00:11 +02:00
$tmpurlsource = preg_replace ( '/#[a-zA-Z0-9_]*$/' , '' , $urlsource );
2021-10-05 11:03:51 +02:00
$out .= '<a class="reposition" href="' . $tmpurlsource . (( strpos ( $tmpurlsource , '?' ) === false ) ? '?' : '&' ) . 'action=' . urlencode ( $removeaction ) . '&token=' . newToken () . '&file=' . urlencode ( $relativepath );
2021-09-18 22:09:55 +02:00
$out .= ( $param ? '&' . $param : '' );
2013-07-12 15:10:32 +02:00
//$out.= '&modulepart='.$modulepart; // TODO obsolete ?
//$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
2019-11-12 09:46:08 +01:00
$out .= '">' . img_picto ( $langs -> trans ( " Delete " ), 'delete' ) . '</a>' ;
2013-07-12 15:10:32 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $printer ) {
2021-11-28 20:55:17 +01:00
$out .= '<a class="marginleftonly reposition" href="' . $urlsource . ( strpos ( $urlsource , '?' ) ? '&' : '?' ) . 'action=print_file&token=' . newToken () . '&printer=' . urlencode ( $modulepart ) . '&file=' . urlencode ( $relativepath );
2021-09-18 22:09:55 +02:00
$out .= ( $param ? '&' . $param : '' );
2019-11-12 09:46:08 +01:00
$out .= '">' . img_picto ( $langs -> trans ( " PrintFile " , $relativepath ), 'printer.png' ) . '</a>' ;
2013-07-12 15:10:32 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $morepicto ) {
2019-11-12 09:46:08 +01:00
$morepicto = preg_replace ( '/__FILENAMEURLENCODED__/' , urlencode ( $relativepath ), $morepicto );
$out .= $morepicto ;
2017-10-16 08:47:05 +02:00
}
2019-11-12 09:46:08 +01:00
$out .= '</td>' ;
2017-10-16 08:47:05 +02:00
}
2021-02-23 22:03:23 +01:00
if ( is_object ( $hookmanager )) {
2023-02-10 15:02:11 +01:00
$addcolumforpicto = ( $delallowed || $printer || $morepicto );
$colspan = ( 4 + ( $addcolumforpicto ? 1 : 0 ));
$colspanmore = 0 ;
2024-03-13 00:29:31 +01:00
$parameters = array ( 'colspan' => ( $colspan + $colspanmore ), 'socid' => ( isset ( $GLOBALS [ 'socid' ]) ? $GLOBALS [ 'socid' ] : '' ), 'id' => ( isset ( $GLOBALS [ 'id' ]) ? $GLOBALS [ 'id' ] : '' ), 'modulepart' => $modulepart , 'relativepath' => $relativepath );
2019-01-27 11:55:16 +01:00
$res = $hookmanager -> executeHooks ( 'formBuilddocLineOptions' , $parameters , $file );
2021-02-23 22:03:23 +01:00
if ( empty ( $res )) {
2019-11-12 09:46:08 +01:00
$out .= $hookmanager -> resPrint ; // Complete line
$out .= '</tr>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-12 09:46:08 +01:00
$out = $hookmanager -> resPrint ; // Replace all $out
2019-05-27 13:28:10 +02:00
}
2021-02-23 22:03:23 +01:00
}
2012-09-18 18:00:05 +02:00
}
2011-08-16 11:36:00 +02:00
2017-10-16 08:47:05 +02:00
$this -> numoffiles ++ ;
}
2018-08-19 03:00:11 +02:00
// Loop on each link found
2021-02-23 22:03:23 +01:00
if ( is_array ( $link_list )) {
2019-11-12 09:46:08 +01:00
$colspan = 2 ;
2017-06-10 13:44:20 +02:00
2021-02-23 22:03:23 +01:00
foreach ( $link_list as $file ) {
2019-11-12 09:46:08 +01:00
$out .= '<tr class="oddeven">' ;
$out .= '<td colspan="' . $colspan . '" class="maxwidhtonsmartphone">' ;
2021-11-22 02:35:55 +01:00
$out .= '<a data-ajax="false" href="' . $file -> url . '" target="_blank" rel="noopener noreferrer">' ;
2019-11-12 09:46:08 +01:00
$out .= $file -> label ;
$out .= '</a>' ;
$out .= '</td>' ;
$out .= '<td class="right">' ;
$out .= dol_print_date ( $file -> datea , 'dayhour' );
$out .= '</td>' ;
2022-05-03 20:37:04 +02:00
// for share link of files
$out .= '<td></td>' ;
2021-02-23 22:03:23 +01:00
if ( $delallowed || $printer || $morepicto ) {
$out .= '<td></td>' ;
}
2019-11-12 09:46:08 +01:00
$out .= '</tr>' . " \n " ;
2017-10-16 08:47:05 +02:00
}
$this -> numoffiles ++ ;
}
2017-06-10 13:44:20 +02:00
2021-02-23 22:03:23 +01:00
if ( count ( $file_list ) == 0 && count ( $link_list ) == 0 && $headershown ) {
2021-10-05 10:24:31 +02:00
$out .= '<tr><td colspan="' . ( 3 + ( $addcolumforpicto ? 1 : 0 )) . '"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td></tr>' . " \n " ;
2017-10-16 08:47:05 +02:00
}
}
2011-08-16 11:36:00 +02:00
2021-02-23 22:03:23 +01:00
if ( $headershown ) {
2017-10-16 08:47:05 +02:00
// Affiche pied du tableau
2019-11-12 09:46:08 +01:00
$out .= " </table> \n " ;
$out .= " </div> \n " ;
2021-02-23 22:03:23 +01:00
if ( $genallowed ) {
if ( empty ( $noform )) {
$out .= '</form>' . " \n " ;
}
2017-10-16 08:47:05 +02:00
}
}
2019-11-12 09:46:08 +01:00
$out .= '<!-- End show_document -->' . " \n " ;
2023-06-13 02:13:09 +02:00
$out .= ' < script >
jQuery ( document ) . ready ( function () {
var selectedValue = $ ( " .selectformat " ) . val ();
2023-08-30 23:23:45 +02:00
2023-06-13 02:13:09 +02:00
if ( selectedValue === " excel2007 " || selectedValue === " tsv " ) {
$ ( " .forhide " ) . prop ( " disabled " , true ) . hide ();
} else {
$ ( " .forhide " ) . prop ( " disabled " , false ) . show ();
}
});
</ script > ' ;
2017-10-16 08:47:05 +02:00
//return ($i?$i:$headershown);
return $out ;
}
/**
* Show a Document icon with link ( s )
* You may want to call this into a div like this :
* print '<div class="inline-block valignmiddle">' . $formfile -> getDocumentsLink ( $element_doc , $filename , $filedir ) . '</div>' ;
*
2025-02-10 11:15:08 +01:00
* @ param string $modulepart 'propal' , 'facture' , 'facture_fourn' , ...
* @ param string $modulesubdir Sub - directory to scan ( Example : '0/1/10' , 'FA/DD/MM/YY/9999' ) . Use '' if file is not into subdir of module .
* @ param string $filedir Full path to directory to scan
* @ param string $filter Filter filenames on this regex string ( Example : '\.pdf$' )
* @ param string $morecss Add more css to the download picto
* @ param int < 0 , 1 > $allfiles 0 = Only generated docs , 1 = All files
* @ return string Output string with HTML link of documents ( might be empty string ) . This also fill the array -> infofiles
2017-10-16 08:47:05 +02:00
*/
2021-08-06 13:24:40 +02:00
public function getDocumentsLink ( $modulepart , $modulesubdir , $filedir , $filter = '' , $morecss = 'valignmiddle' , $allfiles = 0 )
2017-10-16 08:47:05 +02:00
{
global $conf , $langs ;
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2019-11-12 09:46:08 +01:00
$out = '' ;
2024-03-13 00:29:31 +01:00
$this -> infofiles = array ( 'nboffiles' => 0 , 'extensions' => array (), 'files' => array ());
2017-10-16 08:47:05 +02:00
2018-10-29 12:30:36 +01:00
$entity = 1 ; // Without multicompany
2018-02-26 11:00:49 +01:00
// Get object entity
2022-08-28 13:55:48 +02:00
if ( isModEnabled ( 'multicompany' )) {
2020-04-23 13:35:40 +02:00
$regs = array ();
2019-01-27 11:55:16 +01:00
preg_match ( '/\/([0-9]+)\/[^\/]+\/' . preg_quote ( $modulesubdir , '/' ) . '$/' , $filedir , $regs );
2019-11-12 09:46:08 +01:00
$entity = (( ! empty ( $regs [ 1 ]) && $regs [ 1 ] > 1 ) ? $regs [ 1 ] : 1 ); // If entity id not found in $filedir this is entity 1 by default
2018-03-02 17:48:58 +01:00
}
2018-03-14 17:12:32 +01:00
2021-08-06 13:24:40 +02:00
// Get list of files starting with name of ref (Note: files with '^ref\.extension' are generated files, files with '^ref-...' are uploaded files)
2023-11-27 11:24:19 +01:00
if ( $allfiles || getDolGlobalString ( 'MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP' )) {
2021-08-06 13:24:40 +02:00
$filterforfilesearch = '^' . preg_quote ( basename ( $modulesubdir ), '/' );
2020-05-21 15:05:19 +02:00
} else {
2021-08-06 13:24:40 +02:00
$filterforfilesearch = '^' . preg_quote ( basename ( $modulesubdir ), '/' ) . '\.' ;
2018-04-07 13:23:26 +02:00
}
2019-11-12 09:46:08 +01:00
$file_list = dol_dir_list ( $filedir , 'files' , 0 , $filterforfilesearch , '\.meta$|\.png$' ); // We also discard .meta and .png preview
2017-10-16 08:47:05 +02:00
2017-11-10 20:20:59 +01:00
//var_dump($file_list);
2017-10-16 08:47:05 +02:00
// For ajax treatment
2019-11-12 09:46:08 +01:00
$out .= '<!-- html.formfile::getDocumentsLink -->' . " \n " ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $file_list )) {
2019-11-12 09:46:08 +01:00
$out = ' < dl class = " dropdown inline-block " >
2024-05-05 02:51:05 +02:00
< dt >< a data - ajax = " false " href = " # " onClick = " return false; " > '.img_picto(' ', ' listlight ', ' ', 0, 0, 0, ' ', $morecss).' </ a ></ dt >
< dd >< div class = " multichoicedoc " style = " position:absolute;left:100px; " >< ul class = " ulselectedfields " > ' ;
2019-11-12 09:46:08 +01:00
$tmpout = '' ;
2017-10-16 08:47:05 +02:00
// Loop on each file found
2019-11-12 09:46:08 +01:00
$found = 0 ;
2021-03-14 20:31:13 +01:00
$i = 0 ;
2021-02-23 22:03:23 +01:00
foreach ( $file_list as $file ) {
2017-10-16 08:47:05 +02:00
$i ++ ;
2021-02-23 22:03:23 +01:00
if ( $filter && ! preg_match ( '/' . $filter . '/i' , $file [ " name " ])) {
continue ; // Discard this. It does not match provided filter.
}
2017-10-16 08:47:05 +02:00
2017-11-10 20:20:59 +01:00
$found ++ ;
2017-10-16 08:47:05 +02:00
// Define relative path for download link (depends on module)
2019-11-12 09:46:08 +01:00
$relativepath = $file [ " name " ]; // Cas general
2021-02-23 22:03:23 +01:00
if ( $modulesubdir ) {
2024-10-26 18:24:40 +02:00
$relativepath = ( string ) $modulesubdir . " / " . $file [ " name " ]; // Cas propal, facture...
2021-02-23 22:03:23 +01:00
}
2017-10-16 08:47:05 +02:00
// Autre cas
2019-11-12 09:46:08 +01:00
if ( $modulepart == 'donation' ) {
2024-10-26 18:24:40 +02:00
$relativepath = ( string ) get_exdir ( $modulesubdir , 2 , 0 , 0 , null , 'donation' ) . $file [ " name " ];
2017-10-16 08:47:05 +02:00
}
2019-11-12 09:46:08 +01:00
if ( $modulepart == 'export' ) {
2024-10-26 18:24:40 +02:00
$relativepath = ( string ) $file [ " name " ];
2017-10-16 08:47:05 +02:00
}
$this -> infofiles [ 'nboffiles' ] ++ ;
2019-11-12 09:46:08 +01:00
$this -> infofiles [ 'files' ][] = $file [ 'fullname' ];
2024-10-26 18:24:40 +02:00
$ext = ( string ) pathinfo ( $file [ 'name' ], PATHINFO_EXTENSION ); // pathinfo returns a string here (cast for static analysis)
if ( ! array_key_exists ( $ext , $this -> infofiles [ 'extensions' ])) {
2021-02-23 22:03:23 +01:00
$this -> infofiles [ 'extensions' ][ $ext ] = 1 ;
} else {
$this -> infofiles [ 'extensions' ][ $ext ] ++ ;
}
2017-10-16 08:47:05 +02:00
// Preview
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && ( $conf -> browser -> layout != 'phone' )) {
2017-10-16 08:47:05 +02:00
$tmparray = getAdvancedPreviewUrl ( $modulepart , $relativepath , 1 , '&entity=' . $entity );
2021-02-23 22:03:23 +01:00
if ( $tmparray && $tmparray [ 'url' ]) {
2019-11-12 09:46:08 +01:00
$tmpout .= '<li><a href="' . $tmparray [ 'url' ] . '"' . ( $tmparray [ 'css' ] ? ' class="' . $tmparray [ 'css' ] . '"' : '' ) . ( $tmparray [ 'mime' ] ? ' mime="' . $tmparray [ 'mime' ] . '"' : '' ) . ( $tmparray [ 'target' ] ? ' target="' . $tmparray [ 'target' ] . '"' : '' ) . '>' ;
2017-11-10 20:20:59 +01:00
//$tmpout.= img_picto('','detail');
2019-11-12 09:46:08 +01:00
$tmpout .= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>' ;
$tmpout .= $langs -> trans ( " Preview " ) . ' ' . $ext . '</a></li>' ;
2017-11-10 20:20:59 +01:00
}
2017-10-16 08:47:05 +02:00
}
// Download
2024-05-05 02:51:05 +02:00
$tmpout .= '<li class="nowrap"><a class="pictopreview nowrap" ' ;
if ( getDolGlobalInt ( 'MAIN_DISABLE_FORCE_SAVEAS' ) == 2 ) {
2024-08-07 03:05:02 +02:00
$tmpout .= 'target="_blank" ' ;
2024-05-05 02:51:05 +02:00
}
$tmpout .= 'href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode ( $relativepath ) . '"' ;
2019-11-12 09:46:08 +01:00
$mime = dol_mimetype ( $relativepath , '' , 0 );
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/text/' , $mime )) {
2021-11-22 02:35:55 +01:00
$tmpout .= ' target="_blank" rel="noopener noreferrer"' ;
2021-02-23 22:03:23 +01:00
}
2019-11-12 09:46:08 +01:00
$tmpout .= '>' ;
$tmpout .= img_mime ( $relativepath , $file [ " name " ]);
$tmpout .= $langs -> trans ( " Download " ) . ' ' . $ext ;
$tmpout .= '</a></li>' . " \n " ;
}
$out .= $tmpout ;
$out .= ' </ ul ></ div ></ dd >
2024-05-05 02:51:05 +02:00
</ dl > ' ;
2017-11-10 20:20:59 +01:00
2021-02-23 22:03:23 +01:00
if ( ! $found ) {
$out = '' ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
// TODO Add link to regenerate doc ?
//$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
}
return $out ;
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-16 08:47:05 +02:00
/**
* Show list of documents in $filearray ( may be they are all in same directory but may not )
* This also sync database if $upload_dir is defined .
*
2024-10-26 18:24:40 +02:00
* @ param array < array { name : string , path : string , level1name : string , relativename : string , fullname : string , date : string , size : int , perm : int , type : string } > $filearray Array of files loaded by dol_dir_list ( 'files' ) function before calling this .
* @ param ? CommonObject $object Object on which document is linked to .
2023-04-30 03:57:10 +02:00
* @ param string $modulepart Value for modulepart used by download or viewimage wrapper .
* @ param string $param Parameters on sort links ( param must start with & , example & aaa = bbb & ccc = ddd )
2024-10-26 18:24:40 +02:00
* @ param int < 0 , 1 > $forcedownload Force to open dialog box " Save As " when clicking on file .
2023-04-30 03:57:10 +02:00
* @ param string $relativepath Relative path of docs ( autodefined if not provided ), relative to module dir , not to MAIN_DATA_ROOT .
2024-10-26 18:24:40 +02:00
* @ param int < 0 , 1 > $permonobject Permission on object ( so permission to delete or crop document )
* @ param int < 0 , 6 > $useinecm Change output to add more information :
2024-07-03 15:40:22 +02:00
* 0 , 4 , 5 , 6 : Add a preview column . Show also a rename button . Show also a crop button for some values of $modulepart ( must be supported into hard coded list in this function + photos_resize . php + restrictedArea + checkUserAccessToObject )
2023-04-30 03:57:10 +02:00
* 1 : Add link to edit ECM entry
* 2 : Add rename and crop link
2024-07-03 15:40:22 +02:00
* 5 : Add link to edit ECM entry and add a preview column
2023-04-30 03:57:10 +02:00
* @ param string $textifempty Text to show if filearray is empty ( 'NoFileFound' if not defined )
* @ param int $maxlength Maximum length of file name shown .
* @ param string $title Title before list . Use 'none' to disable title .
* @ param string $url Full url to use for click links ( '' = autodetect )
2024-10-26 18:24:40 +02:00
* @ param int < 0 , 1 > $showrelpart 0 = Show only filename ( default ), 1 = Show first level 1 dir
* @ param int <- 1 , 1 > $permtoeditline Permission to edit document line ( You must provide a value , - 1 is deprecated and must not be used any more )
2023-04-30 03:57:10 +02:00
* @ param string $upload_dir Full path directory so we can know dir relative to MAIN_DATA_ROOT . Fill this to complete file data with database indexes .
* @ param string $sortfield Sort field ( 'name' , 'size' , 'position' , ... )
* @ param string $sortorder Sort order ( 'ASC' or 'DESC' )
2024-10-26 18:24:40 +02:00
* @ param int < 0 , 1 > $disablemove 1 = Disable move button , 0 = Position move is possible .
* @ param int < 0 , 1 > $addfilterfields Add the line with filters
* @ param int <- 1 , 1 > $disablecrop Disable crop feature on images ( - 1 = auto , prefer to set it explicitly to 0 or 1 )
2023-04-30 03:57:10 +02:00
* @ param string $moreattrondiv More attributes on the div for responsive . Example 'style="height:280px; overflow: auto;"'
2024-10-26 18:24:40 +02:00
* @ param array < string , mixed > $moreoptions Add more options like array ( 'afteruploadtitle' , ... )
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if KO , nb of files shown if OK
2019-03-24 12:15:19 +01:00
* @ see list_of_autoecmfiles ()
2017-10-16 08:47:05 +02:00
*/
2024-10-24 18:05:46 +02:00
public function list_of_documents ( $filearray , $object , $modulepart , $param = '' , $forcedownload = 0 , $relativepath = '' , $permonobject = 1 , $useinecm = 0 , $textifempty = '' , $maxlength = 0 , $title = '' , $url = '' , $showrelpart = 0 , $permtoeditline = - 1 , $upload_dir = '' , $sortfield = '' , $sortorder = 'ASC' , $disablemove = 1 , $addfilterfields = 0 , $disablecrop = - 1 , $moreattrondiv = '' , $moreoptions = array ())
2012-09-11 17:01:54 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2020-11-11 22:47:06 +01:00
global $user , $conf , $langs , $hookmanager , $form ;
2024-10-24 18:05:46 +02:00
global $sortfield , $sortorder ;
2018-02-13 13:55:36 +01:00
global $dolibarr_main_url_root ;
2012-09-11 17:01:54 +02:00
2021-02-23 22:03:23 +01:00
if ( $disablecrop == - 1 ) {
2019-11-12 09:46:08 +01:00
$disablecrop = 1 ;
2022-11-14 01:19:15 +01:00
// Values here must be supported by the photos_resize.php page.
2021-02-23 22:03:23 +01:00
if ( in_array ( $modulepart , array ( 'bank' , 'bom' , 'expensereport' , 'facture' , 'facture_fournisseur' , 'holiday' , 'medias' , 'member' , 'mrp' , 'project' , 'product' , 'produit' , 'propal' , 'service' , 'societe' , 'tax' , 'tax-vat' , 'ticket' , 'user' ))) {
$disablecrop = 0 ;
}
2019-10-23 16:07:09 +02:00
}
2012-09-11 17:01:54 +02:00
2016-12-13 00:15:21 +01:00
// Define relative path used to store the file
2021-02-23 22:03:23 +01:00
if ( empty ( $relativepath )) {
2023-12-04 12:04:36 +01:00
$relativepath = ( ! empty ( $object -> ref ) ? dol_sanitizeFileName ( $object -> ref ) : '' ) . '/' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $object -> element ) && $object -> element == 'invoice_supplier' ) {
$relativepath = get_exdir ( $object -> id , 2 , 0 , 0 , $object , 'invoice_supplier' ) . $relativepath ; // TODO Call using a defined value for $relativepath
}
if ( ! empty ( $object -> element ) && $object -> element == 'project_task' ) {
$relativepath = 'Call_not_supported_._Call_function_using_a_defined_relative_path_.' ;
}
2016-12-13 00:15:21 +01:00
}
2024-01-13 19:48:20 +01:00
// For backward compatibility, we detect file stored into an old path
2024-01-03 14:53:31 +01:00
if ( getDolGlobalInt ( 'PRODUCT_USE_OLD_PATH_FOR_PHOTO' ) && isset ( $filearray [ 0 ]) && $filearray [ 0 ][ 'level1name' ] == 'photos' ) {
2020-09-07 10:18:17 +02:00
$relativepath = preg_replace ( '/^.*\/produit\//' , '' , $filearray [ 0 ][ 'path' ]) . '/' ;
2016-12-13 00:15:21 +01:00
}
2021-04-15 17:56:55 +02:00
2016-12-13 00:15:21 +01:00
// Defined relative dir to DOL_DATA_ROOT
2016-12-13 00:40:12 +01:00
$relativedir = '' ;
2021-02-23 22:03:23 +01:00
if ( $upload_dir ) {
2019-01-27 11:55:16 +01:00
$relativedir = preg_replace ( '/^' . preg_quote ( DOL_DATA_ROOT , '/' ) . '/' , '' , $upload_dir );
$relativedir = preg_replace ( '/^[\\/]/' , '' , $relativedir );
2016-12-13 00:40:12 +01:00
}
2020-02-26 20:25:26 +01:00
// For example here $upload_dir = '/pathtodocuments/commande/SO2001-123/'
// For example here $upload_dir = '/pathtodocuments/tax/vat/1'
2024-05-14 00:49:32 +02:00
// For example here $upload_dir = '/home/ldestailleur/git/dolibarr_dev/documents/fournisseur/facture/6/1/SI2210-0013' and relativedir='fournisseur/facture/6/1/SI2210-0013'
2016-12-13 00:40:12 +01:00
2012-09-11 17:01:54 +02:00
$hookmanager -> initHooks ( array ( 'formfile' ));
2019-11-12 09:46:08 +01:00
$parameters = array (
2012-09-11 17:01:54 +02:00
'filearray' => $filearray ,
2024-03-13 00:29:31 +01:00
'modulepart' => $modulepart ,
2012-09-11 17:01:54 +02:00
'param' => $param ,
'forcedownload' => $forcedownload ,
2019-11-12 09:46:08 +01:00
'relativepath' => $relativepath , // relative filename to module dir
'relativedir' => $relativedir , // relative dirname to DOL_DATA_ROOT
2016-09-07 01:54:16 +02:00
'permtodelete' => $permonobject ,
2012-09-11 17:01:54 +02:00
'useinecm' => $useinecm ,
'textifempty' => $textifempty ,
'maxlength' => $maxlength ,
'title' => $title ,
'url' => $url
);
2025-01-13 20:04:35 +01:00
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable
2019-11-12 09:46:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'showFilesList' , $parameters , $object );
2012-09-11 17:01:54 +02:00
2021-07-28 15:57:12 +02:00
if ( ! empty ( $reshook )) { // null or '' for bypass
2012-09-11 17:01:54 +02:00
return $reshook ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( ! is_object ( $form )) {
2024-01-13 19:48:20 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ; // The component may be included into ajax page that does not include the Form class
2019-11-12 09:46:08 +01:00
$form = new Form ( $this -> db );
2018-04-21 11:24:45 +02:00
}
2018-04-15 17:58:13 +02:00
2021-02-23 22:03:23 +01:00
if ( ! preg_match ( '/&id=/' , $param ) && isset ( $object -> id )) {
$param .= '&id=' . $object -> id ;
}
2019-11-12 09:46:08 +01:00
$relativepathwihtoutslashend = preg_replace ( '/\/$/' , '' , $relativepath );
2021-02-23 22:03:23 +01:00
if ( $relativepathwihtoutslashend ) {
$param .= '&file=' . urlencode ( $relativepathwihtoutslashend );
}
2012-09-12 10:46:35 +02:00
2021-02-23 22:03:23 +01:00
if ( $permtoeditline < 0 ) { // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
2019-11-12 09:46:08 +01:00
$permtoeditline = 0 ;
2021-02-23 22:03:23 +01:00
if ( in_array ( $modulepart , array ( 'product' , 'produit' , 'service' ))) {
2025-02-10 11:15:08 +01:00
'@phan-var-force Product $object' ;
2023-06-19 23:05:59 +02:00
if ( $user -> hasRight ( 'produit' , 'creer' ) && $object -> type == Product :: TYPE_PRODUCT ) {
2021-02-23 22:03:23 +01:00
$permtoeditline = 1 ;
}
2023-10-15 15:32:35 +02:00
if ( $user -> hasRight ( 'service' , 'creer' ) && $object -> type == Product :: TYPE_SERVICE ) {
2021-02-23 22:03:23 +01:00
$permtoeditline = 1 ;
}
2017-10-16 08:47:05 +02:00
}
2016-09-07 01:54:16 +02:00
}
2023-11-27 11:24:19 +01:00
if ( ! getDolGlobalString ( 'MAIN_UPLOAD_DOC' )) {
2019-11-12 09:46:08 +01:00
$permtoeditline = 0 ;
$permonobject = 0 ;
2016-09-07 01:54:16 +02:00
}
2024-10-24 18:05:46 +02:00
if ( empty ( $url )) {
$url = $_SERVER [ " PHP_SELF " ];
}
2016-09-07 01:54:16 +02:00
2024-10-24 18:05:46 +02:00
// Show title of list of existing files
2024-10-24 18:56:43 +02:00
$morehtmlright = '' ;
if ( ! empty ( $moreoptions [ 'showhideaddbutton' ]) && $conf -> use_javascript_ajax ) {
2024-12-13 09:55:50 +01:00
$tmpurlforbutton = 'javascript:console.log("open add file form");jQuery(".divattachnewfile").toggle(); if (!jQuery(".divattachnewfile").is(":hidden")) { jQuery("input[type=\'file\']").click();}void(0);' ;
2024-11-09 12:28:36 +01:00
$morehtmlright .= dolGetButtonTitle ( $langs -> trans ( 'New' ), '' , 'fa fa-plus-circle' , $tmpurlforbutton , '' , $permtoeditline );
2024-10-24 18:56:43 +02:00
}
2024-07-03 15:59:59 +02:00
if (( empty ( $useinecm ) || $useinecm == 3 || $useinecm == 6 ) && $title != 'none' ) {
2024-10-24 18:56:43 +02:00
print load_fiche_titre ( $title ? $title : $langs -> trans ( " AttachedFiles " ), $morehtmlright , 'file-upload' , 0 , '' , 'table-list-of-attached-files' );
2021-02-23 22:03:23 +01:00
}
2024-10-24 18:05:46 +02:00
if ( ! empty ( $moreoptions ) && $moreoptions [ 'afteruploadtitle' ]) {
2024-10-24 18:56:43 +02:00
print '<div class="divattachnewfile' . (( ! empty ( $moreoptions [ 'showhideaddbutton' ]) && $conf -> use_javascript_ajax ) ? ' hidden' : '' ) . '">' . $moreoptions [ 'afteruploadtitle' ] . '</div>' ;
2021-02-23 22:03:23 +01:00
}
2017-06-10 13:44:20 +02:00
2024-10-24 18:05:46 +02:00
// Show the table
2016-03-04 11:25:54 +01:00
print '<!-- html.formfile::list_of_documents -->' . " \n " ;
2021-02-23 22:03:23 +01:00
if ( GETPOST ( 'action' , 'aZ09' ) == 'editfile' && $permtoeditline ) {
2017-10-16 08:47:05 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?' . $param . '" method="POST">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-16 08:47:05 +02:00
print '<input type="hidden" name="action" value="renamefile">' ;
2024-05-14 01:34:25 +02:00
print '<input type="hidden" name="id" value="' . ( is_object ( $object ) ? $object -> id : '' ) . '">' ;
2017-10-16 08:47:05 +02:00
print '<input type="hidden" name="modulepart" value="' . $modulepart . '">' ;
2016-09-07 01:54:16 +02:00
}
2017-06-20 12:31:08 +02:00
2022-05-24 12:11:51 +02:00
print '<div class="div-table-responsive-no-min"' . ( $moreattrondiv ? ' ' . $moreattrondiv : '' ) . '>' ;
2021-12-11 18:13:03 +01:00
print '<table id="tablelines" class="centpercent liste noborder nobottom">' . " \n " ;
2017-06-10 13:44:20 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $addfilterfields )) {
2017-08-04 13:07:15 +02:00
print '<tr class="liste_titre nodrag nodrop">' ;
2019-01-27 11:55:16 +01:00
print '<td><input type="search_doc_ref" value="' . dol_escape_htmltag ( GETPOST ( 'search_doc_ref' , 'alpha' )) . '"></td>' ;
2017-08-04 13:07:15 +02:00
print '<td></td>' ;
print '<td></td>' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $useinecm ) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6 ) {
print '<td></td>' ;
}
2017-08-04 13:07:15 +02:00
print '<td></td>' ;
2018-02-13 13:55:36 +01:00
print '<td></td>' ;
2022-03-07 16:04:55 +01:00
if ( empty ( $disablemove ) && count ( $filearray ) > 1 ) {
2021-02-23 22:03:23 +01:00
print '<td></td>' ;
}
2017-08-04 13:07:15 +02:00
print " </tr> \n " ;
}
2022-03-07 16:04:55 +01:00
// Get list of files stored into database for same relative directory
if ( $relativedir ) {
completeFileArrayWithDatabaseInfo ( $filearray , $relativedir );
2024-11-11 14:48:18 +01:00
'@phan-var-force array<array{name:string,path:string,level1name:string,relativename:string,fullname:string,date:string,size:int,perm:int,type:string,position_name:string,cover:string,keywords:string,acl:string,rowid:int,label:string,share:string}> $filearray' ;
2022-03-07 16:04:55 +01:00
//var_dump($sortfield.' - '.$sortorder);
if ( $sortfield && $sortorder ) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
2025-01-23 23:41:51 +01:00
$filearray = dol_sort_array ( $filearray , $sortfield , $sortorder , 1 );
2022-03-07 16:04:55 +01:00
}
}
2016-12-20 19:42:25 +01:00
print '<tr class="liste_titre nodrag nodrop">' ;
2017-11-10 13:45:38 +01:00
//print $url.' sortfield='.$sortfield.' sortorder='.$sortorder;
2019-04-10 11:39:54 +02:00
print_liste_field_titre ( 'Documents2' , $url , " name " , " " , $param , '' , $sortfield , $sortorder , 'left ' );
print_liste_field_titre ( 'Size' , $url , " size " , " " , $param , '' , $sortfield , $sortorder , 'right ' );
print_liste_field_titre ( 'Date' , $url , " date " , " " , $param , '' , $sortfield , $sortorder , 'center ' );
2021-02-23 22:03:23 +01:00
if ( empty ( $useinecm ) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6 ) {
print_liste_field_titre ( '' , $url , " " , " " , $param , '' , $sortfield , $sortorder , 'center ' ); // Preview
}
2021-01-23 13:56:51 +01:00
// Shared or not - Hash of file
2018-02-13 13:55:36 +01:00
print_liste_field_titre ( '' );
2021-01-23 13:56:51 +01:00
// Action button
2015-06-26 06:23:29 +02:00
print_liste_field_titre ( '' );
2022-03-07 16:04:55 +01:00
if ( empty ( $disablemove ) && count ( $filearray ) > 1 ) {
2021-02-23 22:03:23 +01:00
print_liste_field_titre ( '' );
}
2015-06-26 06:23:29 +02:00
print " </tr> \n " ;
2012-09-11 17:01:54 +02:00
2019-11-12 09:46:08 +01:00
$nboffiles = count ( $filearray );
2021-02-23 22:03:23 +01:00
if ( $nboffiles > 0 ) {
include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php' ;
}
2017-06-10 13:44:20 +02:00
2021-03-01 20:37:16 +01:00
$i = 0 ;
$nboflines = 0 ;
$lastrowid = 0 ;
2024-08-07 00:50:08 +02:00
$parametersByDefault = array (
2024-09-18 03:27:25 +02:00
'modulepart' => $modulepart ,
'relativepath' => $relativepath ,
2024-08-07 00:50:08 +02:00
'permtoedit' => $permtoeditline ,
'permonobject' => $permonobject ,
);
2021-02-23 22:03:23 +01:00
foreach ( $filearray as $key => $file ) { // filearray must be only files here
2024-05-14 00:49:32 +02:00
if ( $file [ 'name' ] != '.' && $file [ 'name' ] != '..' && ! preg_match ( '/\.meta$/i' , $file [ 'name' ])) {
2022-05-21 18:26:20 +02:00
if ( array_key_exists ( 'rowid' , $filearray [ $key ]) && $filearray [ $key ][ 'rowid' ] > 0 ) {
2021-02-23 22:03:23 +01:00
$lastrowid = $filearray [ $key ][ 'rowid' ];
}
2024-05-14 00:49:32 +02:00
//var_dump($filearray[$key]);
2024-08-07 00:50:08 +02:00
// get specific parameters from file attributes if set or get default ones
$modulepart = ( $file [ 'modulepart' ] ? ? $parametersByDefault [ 'modulepart' ]);
$relativepath = ( $file [ 'relativepath' ] ? ? $parametersByDefault [ 'relativepath' ]);
$permtoeditline = ( $file [ 'permtoedit' ] ? ? $parametersByDefault [ 'permtoedit' ]);
$permonobject = ( $file [ 'permonobject' ] ? ? $parametersByDefault [ 'permonobject' ]);
2024-05-14 00:49:32 +02:00
2024-08-07 00:50:08 +02:00
// Note: for supplier invoice, $modulepart may be already 'facture_fournisseur' and $relativepath may be already '6/1/SI2210-0013/'
2024-05-14 00:49:32 +02:00
if ( empty ( $relativepath ) || empty ( $modulepart )) {
$filepath = $file [ 'level1name' ] . '/' . $file [ 'name' ];
} else {
$filepath = $relativepath . $file [ 'name' ];
}
if ( empty ( $modulepart )) {
$modulepart = basename ( dirname ( $file [ 'path' ]));
}
if ( empty ( $relativepath )) {
$relativepath = preg_replace ( '/\/(.+)/' , '' , $filepath ) . '/' ;
}
2017-06-10 13:44:20 +02:00
2019-11-12 09:46:08 +01:00
$editline = 0 ;
2016-12-20 19:42:25 +01:00
$nboflines ++ ;
2017-10-16 08:47:05 +02:00
print '<!-- Line list_of_documents ' . $key . ' relativepath = ' . $relativepath . ' -->' . " \n " ;
// Do we have entry into database ?
2022-06-22 12:12:12 +02:00
2022-05-21 18:26:20 +02:00
print '<!-- In database: position=' . ( array_key_exists ( 'position' , $filearray [ $key ]) ? $filearray [ $key ][ 'position' ] : 0 ) . ' -->' . " \n " ;
2022-05-23 01:10:37 +02:00
print '<tr class="oddeven" id="row-' . (( array_key_exists ( 'rowid' , $filearray [ $key ]) && $filearray [ $key ][ 'rowid' ] > 0 ) ? $filearray [ $key ][ 'rowid' ] : 'AFTER' . $lastrowid . 'POS' . ( $i + 1 )) . '">' ;
2017-06-10 13:44:20 +02:00
2017-11-18 15:41:30 +01:00
// File name
2024-10-03 19:36:59 +02:00
print '<td class="minwidth200 tdoverflowmax500" title="' . dolPrintHTMLForAttribute ( $file [ 'name' ]) . '">' ;
2017-06-10 13:44:20 +02:00
2017-11-10 20:20:59 +01:00
// Show file name with link to download
2012-09-11 17:01:54 +02:00
//print "XX".$file['name']; //$file['name'] must be utf8
2024-05-05 02:51:05 +02:00
print '<a class="paddingright valignmiddle" ' ;
if ( getDolGlobalInt ( 'MAIN_DISABLE_FORCE_SAVEAS' ) == 2 ) {
print 'target="_blank" ' ;
}
print 'href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart ;
2021-02-23 22:03:23 +01:00
if ( $forcedownload ) {
print '&attachment=1' ;
}
if ( ! empty ( $object -> entity )) {
print '&entity=' . $object -> entity ;
}
2013-11-17 02:59:01 +01:00
print '&file=' . urlencode ( $filepath );
2013-11-13 20:36:07 +01:00
print '">' ;
2021-10-10 21:11:48 +02:00
print img_mime ( $file [ 'name' ], $file [ 'name' ] . ' (' . dol_print_size ( $file [ 'size' ], 0 , 0 ) . ')' , 'inline-block valignmiddle paddingright' );
2021-02-23 22:03:23 +01:00
if ( $showrelpart == 1 ) {
print $relativepath ;
}
2016-03-04 11:25:54 +01:00
//print dol_trunc($file['name'],$maxlength,'middle');
2024-05-14 02:01:39 +02:00
//var_dump(dirname($filepath).' - '.dirname(GETPOST('urlfile', 'alpha')));
if ( GETPOST ( 'action' , 'aZ09' ) == 'editfile' && $file [ 'name' ] == basename ( GETPOST ( 'urlfile' , 'alpha' )) && dirname ( $filepath ) == dirname ( GETPOST ( 'urlfile' , 'alpha' ))) {
2017-10-16 08:47:05 +02:00
print '</a>' ;
2019-11-12 09:46:08 +01:00
$section_dir = dirname ( GETPOST ( 'urlfile' , 'alpha' ));
2021-02-23 22:03:23 +01:00
if ( ! preg_match ( '/\/$/' , $section_dir )) {
$section_dir .= '/' ;
}
2017-11-18 15:41:30 +01:00
print '<input type="hidden" name="section_dir" value="' . $section_dir . '">' ;
2017-10-16 08:47:05 +02:00
print '<input type="hidden" name="renamefilefrom" value="' . dol_escape_htmltag ( $file [ 'name' ]) . '">' ;
print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="' . dol_escape_htmltag ( $file [ 'name' ]) . '">' ;
2019-11-12 09:46:08 +01:00
$editline = 1 ;
2020-05-28 20:02:07 +02:00
} else {
2020-05-27 13:12:18 +02:00
$filenametoshow = preg_replace ( '/\.noexe$/' , '' , $file [ 'name' ]);
2020-09-16 14:51:46 +02:00
print dol_escape_htmltag ( dol_trunc ( $filenametoshow , 200 ));
2017-10-16 08:47:05 +02:00
print '</a>' ;
2016-09-07 01:54:16 +02:00
}
2022-09-15 05:00:13 +02:00
// Preview link
if ( ! $editline ) {
2023-12-28 12:37:34 +01:00
print $this -> showPreview ( $file , $modulepart , $filepath , 0 , '&entity=' . ( empty ( $object -> entity ) ? $conf -> entity : $object -> entity ));
2022-09-15 05:00:13 +02:00
}
2017-06-10 13:44:20 +02:00
2012-09-11 17:01:54 +02:00
print " </td> \n " ;
2017-06-10 13:44:20 +02:00
2017-11-18 15:41:30 +01:00
// Size
2019-01-27 11:55:16 +01:00
$sizetoshow = dol_print_size ( $file [ 'size' ], 1 , 1 );
$sizetoshowbytes = dol_print_size ( $file [ 'size' ], 0 , 1 );
2020-04-11 16:34:59 +02:00
print '<td class="right nowraponall">' ;
2021-02-23 22:03:23 +01:00
if ( $sizetoshow == $sizetoshowbytes ) {
print $sizetoshow ;
} else {
2018-04-15 17:58:13 +02:00
print $form -> textwithpicto ( $sizetoshow , $sizetoshowbytes , - 1 );
}
print '</td>' ;
2017-06-10 13:44:20 +02:00
2017-11-18 15:41:30 +01:00
// Date
2022-02-07 15:07:03 +01:00
print '<td class="center nowraponall">' . dol_print_date ( $file [ 'date' ], " dayhour " , " tzuser " ) . '</td>' ;
2017-06-10 13:44:20 +02:00
2012-09-11 17:01:54 +02:00
// Preview
2021-02-23 22:03:23 +01:00
if ( empty ( $useinecm ) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6 ) {
2014-07-13 19:51:44 +02:00
$fileinfo = pathinfo ( $file [ 'name' ]);
2019-01-20 23:36:39 +01:00
print '<td class="center">' ;
2021-02-23 22:03:23 +01:00
if ( image_format_supported ( $file [ 'name' ]) >= 0 ) {
if ( $useinecm == 5 || $useinecm == 6 ) {
2024-07-14 19:56:55 +02:00
$smallfile = getImageFileNameForSize ( $file [ 'name' ], '' ); // There is no thumb for ECM module and Media filemanager, so we use true image. TODO Change this for better performance.
2020-09-07 10:18:17 +02:00
} else {
$smallfile = getImageFileNameForSize ( $file [ 'name' ], '_small' ); // For new thumbs using same ext (in lower case however) than original
}
2021-02-23 22:03:23 +01:00
if ( ! dol_is_file ( $file [ 'path' ] . '/' . $smallfile )) {
$smallfile = getImageFileNameForSize ( $file [ 'name' ], '_small' , '.png' ); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
}
2024-04-24 15:18:45 +02:00
if ( ! dol_is_file ( $file [ 'path' ] . '/' . $smallfile )) {
$smallfile = getImageFileNameForSize ( $file [ 'name' ], '' ); // This is in case no _small image exist
}
2019-10-05 11:17:09 +02:00
//print $file['path'].'/'.$smallfile.'<br>';
2017-01-16 00:48:37 +01:00
2024-04-24 15:18:45 +02:00
2023-12-28 12:37:34 +01:00
$urlforhref = getAdvancedPreviewUrl ( $modulepart , $relativepath . $fileinfo [ 'filename' ] . '.' . strtolower ( $fileinfo [ 'extension' ]), 1 , '&entity=' . ( empty ( $object -> entity ) ? $conf -> entity : $object -> entity ));
2018-11-07 21:51:05 +01:00
if ( empty ( $urlforhref )) {
2024-07-14 19:56:55 +02:00
$urlforhref = DOL_URL_ROOT . '/viewimage.php?modulepart=' . urlencode ( $modulepart ) . '&entity=' . ( empty ( $object -> entity ) ? $conf -> entity : $object -> entity ) . '&file=' . urlencode ( $relativepath . $fileinfo [ 'filename' ] . '.' . strtolower ( $fileinfo [ 'extension' ]));
2021-11-22 02:35:55 +01:00
print '<a href="' . $urlforhref . '" class="aphoto" target="_blank" rel="noopener noreferrer">' ;
2018-11-07 21:51:05 +01:00
} else {
print '<a href="' . $urlforhref [ 'url' ] . '" class="' . $urlforhref [ 'css' ] . '" target="' . $urlforhref [ 'target' ] . '" mime="' . $urlforhref [ 'mime' ] . '">' ;
}
2024-02-13 10:56:47 +01:00
print '<img class="photo maxwidth200 shadow valignmiddle"' ;
if ( $useinecm == 4 || $useinecm == 5 || $useinecm == 6 ) {
print ' height="20"' ;
} else {
//print ' style="max-height: '.$maxheightmini.'px"';
print ' style="max-height: 24px"' ;
}
2024-07-14 19:56:55 +02:00
print ' src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . urlencode ( $modulepart ) . '&entity=' . ( empty ( $object -> entity ) ? $conf -> entity : $object -> entity ) . '&file=' . urlencode ( $relativepath . $smallfile );
if ( ! empty ( $filearray [ $key ][ 'date' ])) { // We know the date of file, we can use it as cache key so URL will be in browser cache as long as file date is not modified.
print '&cache=' . urlencode (( string ) $filearray [ $key ][ 'date' ]);
}
print '" title="">' ;
2015-06-19 00:52:58 +02:00
print '</a>' ;
2021-02-23 22:03:23 +01:00
}
2012-09-11 17:01:54 +02:00
print '</td>' ;
}
2018-02-13 13:55:36 +01:00
2021-01-23 13:56:51 +01:00
// Shared or not - Hash of file
2019-01-20 23:36:39 +01:00
print '<td class="center">' ;
2021-01-23 13:56:51 +01:00
if ( $relativedir && $filearray [ $key ][ 'rowid' ] > 0 ) { // only if we are in a mode where a scan of dir were done and we have id of file in ECM table
if ( $editline ) {
2021-04-15 17:09:15 +02:00
print '<label for="idshareenabled' . $key . '">' . $langs -> trans ( " FileSharedViaALink " ) . '</label> ' ;
print '<input class="inline-block" type="checkbox" id="idshareenabled' . $key . '" name="shareenabled"' . ( $file [ 'share' ] ? ' checked="checked"' : '' ) . ' /> ' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( $file [ 'share' ]) {
2018-02-13 13:55:36 +01:00
// Define $urlwithroot
2019-11-12 09:46:08 +01:00
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
2018-02-13 13:55:36 +01:00
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
//print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
2019-11-12 09:46:08 +01:00
$forcedownload = 0 ;
$paramlink = '' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $file [ 'share' ])) {
$paramlink .= ( $paramlink ? '&' : '' ) . 'hashp=' . $file [ 'share' ]; // Hash for public share
}
if ( $forcedownload ) {
$paramlink .= ( $paramlink ? '&' : '' ) . 'attachment=1' ;
}
2018-02-13 13:55:36 +01:00
2019-11-12 09:46:08 +01:00
$fulllink = $urlwithroot . '/document.php' . ( $paramlink ? '?' . $paramlink : '' );
2018-02-13 13:55:36 +01:00
2022-10-08 03:05:19 +02:00
print '<a href="' . $fulllink . '" target="_blank" rel="noopener">' . img_picto ( $langs -> trans ( " FileSharedViaALink " ), 'globe' ) . '</a> ' ;
2022-04-11 19:21:04 +02:00
print '<input type="text" class="quatrevingtpercent minwidth200imp nopadding small" id="downloadlink' . $filearray [ $key ][ 'rowid' ] . '" name="downloadexternallink" title="' . dol_escape_htmltag ( $langs -> trans ( " FileSharedViaALink " )) . '" value="' . dol_escape_htmltag ( $fulllink ) . '">' ;
2020-05-21 15:05:19 +02:00
} else {
2018-02-13 13:55:36 +01:00
//print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
}
}
}
print '</td>' ;
2021-01-23 13:56:51 +01:00
// Actions buttons (1 column or 2 if !disablemove)
2021-02-23 22:03:23 +01:00
if ( ! $editline ) {
2017-10-16 08:47:05 +02:00
// Delete or view link
// ($param must start with &)
2019-05-10 19:38:08 +02:00
print '<td class="valignmiddle right actionbuttons nowraponall"><!-- action on files -->' ;
2021-02-23 22:03:23 +01:00
if ( $useinecm == 1 || $useinecm == 5 ) { // ECM manual tree only
2020-06-05 13:41:33 +02:00
// $section is inside $param
2022-06-08 20:07:16 +02:00
$newparam = preg_replace ( '/&file=.*$/' , '' , $param ); // We don't need param file=
2020-06-05 13:41:33 +02:00
$backtopage = DOL_URL_ROOT . '/ecm/index.php?§ion_dir=' . urlencode ( $relativepath ) . $newparam ;
2021-03-05 08:41:04 +01:00
print '<a class="editfielda editfilelink" href="' . DOL_URL_ROOT . '/ecm/file_card.php?urlfile=' . urlencode ( $file [ 'name' ]) . $param . '&backtopage=' . urlencode ( $backtopage ) . '" rel="' . urlencode ( $file [ 'name' ]) . '">' . img_edit ( 'default' , 0 , 'class="paddingrightonly"' ) . '</a>' ;
2017-10-16 08:47:05 +02:00
}
2020-06-05 13:41:33 +02:00
2024-07-03 15:59:59 +02:00
if ( empty ( $useinecm ) || $useinecm == 2 || $useinecm == 3 || $useinecm == 6 ) { // 6=Media file manager
2019-11-12 09:46:08 +01:00
$newmodulepart = $modulepart ;
2021-02-23 22:03:23 +01:00
if ( in_array ( $modulepart , array ( 'product' , 'produit' , 'service' ))) {
$newmodulepart = 'produit|service' ;
}
2023-03-14 15:27:55 +01:00
if ( image_format_supported ( $file [ 'name' ]) > 0 ) {
if ( $permtoeditline ) {
$moreparaminurl = '' ;
if ( ! empty ( $object -> id ) && $object -> id > 0 ) {
$moreparaminurl .= '&id=' . $object -> id ;
} elseif ( GETPOST ( 'website' , 'alpha' )) {
$moreparaminurl .= '&website=' . GETPOST ( 'website' , 'alpha' );
}
// Set the backtourl
if ( $modulepart == 'medias' && ! GETPOST ( 'website' )) {
$moreparaminurl .= '&backtourl=' . urlencode ( DOL_URL_ROOT . '/ecm/index_medias.php?file_manager=1&modulepart=' . $modulepart . '§ion_dir=' . $relativepath );
}
2023-03-27 08:49:26 +02:00
// Link to convert into webp
if ( ! preg_match ( '/\.webp$/i' , $file [ 'name' ])) {
if ( $modulepart == 'medias' && ! GETPOST ( 'website' )) {
print '<a href="' . DOL_URL_ROOT . '/ecm/index_medias.php?action=confirmconvertimgwebp&token=' . newToken () . '§ion_dir=' . urlencode ( $relativepath ) . '&filetoregenerate=' . urlencode ( $fileinfo [ 'basename' ]) . '&module=' . $modulepart . $param . $moreparaminurl . '" title="' . dol_escape_htmltag ( $langs -> trans ( " GenerateChosenImgWebp " )) . '">' . img_picto ( '' , 'images' , 'class="flip marginrightonly"' ) . '</a>' ;
} elseif ( $modulepart == 'medias' && GETPOST ( 'website' )) {
print '<a href="' . DOL_URL_ROOT . '/website/index.php?action=confirmconvertimgwebp&token=' . newToken () . '§ion_dir=' . urlencode ( $relativepath ) . '&filetoregenerate=' . urlencode ( $fileinfo [ 'basename' ]) . '&module=' . $modulepart . $param . $moreparaminurl . '" title="' . dol_escape_htmltag ( $langs -> trans ( " GenerateChosenImgWebp " )) . '">' . img_picto ( '' , 'images' , 'class="flip marginrightonly"' ) . '</a>' ;
}
2023-03-14 15:27:55 +01:00
}
}
}
2021-02-23 22:03:23 +01:00
if ( ! $disablecrop && image_format_supported ( $file [ 'name' ]) > 0 ) {
if ( $permtoeditline ) {
// Link to resize
$moreparaminurl = '' ;
2022-03-22 11:42:15 +01:00
if ( ! empty ( $object -> id ) && $object -> id > 0 ) {
2022-11-14 01:19:15 +01:00
$moreparaminurl .= '&id=' . $object -> id ;
2020-06-03 11:20:59 +02:00
} elseif ( GETPOST ( 'website' , 'alpha' )) {
2022-11-14 01:19:15 +01:00
$moreparaminurl .= '&website=' . GETPOST ( 'website' , 'alpha' );
2020-06-03 11:20:59 +02:00
}
2022-11-14 01:19:15 +01:00
// Set the backtourl
if ( $modulepart == 'medias' && ! GETPOST ( 'website' )) {
$moreparaminurl .= '&backtourl=' . urlencode ( DOL_URL_ROOT . '/ecm/index_medias.php?file_manager=1&modulepart=' . $modulepart . '§ion_dir=' . $relativepath );
}
//var_dump($moreparaminurl);
2020-06-03 11:20:59 +02:00
print '<a class="editfielda" href="' . DOL_URL_ROOT . '/core/photos_resize.php?modulepart=' . urlencode ( $newmodulepart ) . $moreparaminurl . '&file=' . urlencode ( $relativepath . $fileinfo [ 'filename' ] . '.' . strtolower ( $fileinfo [ 'extension' ])) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " ResizeOrCrop " )) . '">' . img_picto ( $langs -> trans ( " ResizeOrCrop " ), 'resize' , 'class="paddingrightonly"' ) . '</a>' ;
2017-10-16 08:47:05 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( $permtoeditline ) {
2019-11-12 09:46:08 +01:00
$paramsectiondir = ( in_array ( $modulepart , array ( 'medias' , 'ecm' )) ? '§ion_dir=' . urlencode ( $relativepath ) : '' );
2024-11-09 12:39:44 +01:00
print '<a class="editfielda reposition editfilelink paddingright marginleftonly" href="' . (( $useinecm == 1 || $useinecm == 5 ) ? '#' : ( $url . '?action=editfile&token=' . newToken () . '&urlfile=' . urlencode ( $filepath ) . $paramsectiondir . $param )) . '" rel="' . $filepath . '">' . img_edit ( 'default' , 0 , 'class="paddingrightonly"' ) . '</a>' ;
2017-10-16 08:47:05 +02:00
}
}
2022-11-14 01:19:15 +01:00
// Output link to delete file
2021-02-23 22:03:23 +01:00
if ( $permonobject ) {
2019-11-12 09:46:08 +01:00
$useajax = 1 ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> dol_use_jmobile )) {
$useajax = 0 ;
}
if ( empty ( $conf -> use_javascript_ajax )) {
$useajax = 0 ;
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_ECM_DISABLE_JS' )) {
2021-02-23 22:03:23 +01:00
$useajax = 0 ;
}
2024-11-09 12:28:36 +01:00
2024-11-09 12:39:44 +01:00
print '<a href="' . ((( $useinecm && $useinecm != 3 && $useinecm != 6 ) && $useajax ) ? '#' : ( $url . '?action=deletefile&token=' . newToken () . '&urlfile=' . urlencode ( $filepath ) . $param )) . '" class="reposition deletefilelink paddingright marginleftonly" rel="' . $filepath . '">' . img_delete () . '</a>' ;
2017-10-16 08:47:05 +02:00
}
print " </td> " ;
2022-03-07 16:04:55 +01:00
if ( empty ( $disablemove ) && count ( $filearray ) > 1 ) {
2018-09-02 16:45:03 +02:00
if ( $nboffiles > 1 && $conf -> browser -> layout != 'phone' ) {
2019-01-20 23:36:39 +01:00
print '<td class="linecolmove tdlineupdown center">' ;
2017-10-16 08:47:05 +02:00
if ( $i > 0 ) {
2022-09-06 08:31:05 +02:00
print '<a class="lineupdown" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=up&rowid=' . $object -> id . '">' . img_up ( 'default' , 0 , 'imgupforline' ) . '</a>' ;
2017-10-16 08:47:05 +02:00
}
2022-03-07 16:04:55 +01:00
if ( $i < ( $nboffiles - 1 )) {
2022-09-06 08:31:05 +02:00
print '<a class="lineupdown" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=down&rowid=' . $object -> id . '">' . img_down ( 'default' , 0 , 'imgdownforline' ) . '</a>' ;
2017-10-16 08:47:05 +02:00
}
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2022-03-07 16:04:55 +01:00
print '<td' . (( $conf -> browser -> layout != 'phone' ) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"' ) . '>' ;
2021-02-23 22:03:23 +01:00
print '</td>' ;
2017-10-16 08:47:05 +02:00
}
2020-09-07 10:18:17 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
print '<td class="right">' ;
2024-05-14 02:01:39 +02:00
print '<input type="hidden" name="ecmfileid" value="' . ( empty ( $filearray [ $key ][ 'rowid' ]) ? '' : $filearray [ $key ][ 'rowid' ]) . '">' ;
2022-11-14 01:19:15 +01:00
print '<input type="submit" class="button button-save smallpaddingimp" name="renamefilesave" value="' . dol_escape_htmltag ( $langs -> trans ( " Save " )) . '">' ;
print '<input type="submit" class="button button-cancel smallpaddingimp" name="cancel" value="' . dol_escape_htmltag ( $langs -> trans ( " Cancel " )) . '">' ;
2017-10-16 08:47:05 +02:00
print '</td>' ;
2022-03-07 16:04:55 +01:00
if ( empty ( $disablemove ) && count ( $filearray ) > 1 ) {
2021-02-23 22:03:23 +01:00
print '<td class="right"></td>' ;
}
2013-10-20 20:58:38 +02:00
}
2012-09-11 17:01:54 +02:00
print " </tr> \n " ;
2017-06-10 13:44:20 +02:00
2016-12-20 19:42:25 +01:00
$i ++ ;
2012-09-11 17:01:54 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( $nboffiles == 0 ) {
2019-11-12 09:46:08 +01:00
$colspan = '6' ;
2022-03-07 16:04:55 +01:00
if ( empty ( $disablemove ) && count ( $filearray ) > 1 ) {
2021-02-23 22:03:23 +01:00
$colspan ++ ; // 6 columns or 7
}
2021-10-10 21:25:46 +02:00
print '<tr class="oddeven"><td colspan="' . $colspan . '">' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $textifempty )) {
2021-10-10 21:25:46 +02:00
print '<span class="opacitymedium">' . $langs -> trans ( " NoFileFound " ) . '</span>' ;
2021-02-23 22:03:23 +01:00
} else {
2021-10-10 21:25:46 +02:00
print '<span class="opacitymedium">' . $textifempty . '</span>' ;
2021-02-23 22:03:23 +01:00
}
2012-09-11 17:01:54 +02:00
print '</td></tr>' ;
}
2021-01-23 13:56:51 +01:00
2012-09-11 17:01:54 +02:00
print " </table> " ;
2017-04-14 13:21:02 +02:00
print '</div>' ;
2017-06-10 13:44:20 +02:00
2018-01-12 15:33:21 +01:00
if ( $nboflines > 1 && is_object ( $object )) {
2019-11-12 09:46:08 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && $permtoeditline ) {
2024-10-24 18:05:46 +02:00
$table_element_line = 'ecm_files' ; // used by ajaxrow.tpl.php
2019-11-12 09:46:08 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php' ;
2016-12-20 19:42:25 +01:00
}
2017-06-10 13:44:20 +02:00
}
2018-02-13 15:47:17 +01:00
print ajax_autoselect ( 'downloadlink' );
2021-02-23 22:03:23 +01:00
if ( GETPOST ( 'action' , 'aZ09' ) == 'editfile' && $permtoeditline ) {
2017-10-16 08:47:05 +02:00
print '</form>' ;
2016-09-07 01:54:16 +02:00
}
2017-06-10 13:44:20 +02:00
2012-09-11 17:01:54 +02:00
return $nboffiles ;
}
}
2010-05-03 10:43:32 +02:00
2011-04-17 20:41:26 +02:00
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-16 08:47:05 +02:00
/**
2020-11-11 22:47:06 +01:00
* Show list of documents in a directory of ECM module .
2017-10-16 08:47:05 +02:00
*
2020-11-11 22:47:06 +01:00
* @ param string $upload_dir Directory that was scanned . This directory will contains files into subdirs REF / files
2024-10-26 18:24:40 +02:00
* @ param array < array { name : string , path : string , level1name : string , relativename : string , fullname : string , date : string , size : int , perm : int , type : string } > $filearray Array of files loaded by dol_dir_list ( 'files' ) function before calling this .
2021-10-06 14:01:48 +02:00
* @ param string $modulepart Value for modulepart used by download wrapper . Value can be $object -> table_name ( that is 'myobject' or 'mymodule_myobject' ) or $object -> element . '-' . $module ( for compatibility purpose )
2017-10-16 08:47:05 +02:00
* @ param string $param Parameters on sort links
* @ param int $forcedownload Force to open dialog box " Save As " when clicking on file
* @ param string $relativepath Relative path of docs ( autodefined if not provided )
2019-11-04 15:33:49 +01:00
* @ param int $permissiontodelete Permission to delete
2017-10-16 08:47:05 +02:00
* @ param int $useinecm Change output for use in ecm module
2023-11-21 23:09:09 +01:00
* @ param string $textifempty Text to show if filearray is empty
2017-10-16 08:47:05 +02:00
* @ param int $maxlength Maximum length of file name shown
* @ param string $url Full url to use for click links ( '' = autodetect )
* @ param int $addfilterfields Add line with filters
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if KO , nb of files shown if OK
2019-04-04 18:33:12 +02:00
* @ see list_of_documents ()
2017-10-16 08:47:05 +02:00
*/
2019-11-04 15:33:49 +01:00
public function list_of_autoecmfiles ( $upload_dir , $filearray , $modulepart , $param , $forcedownload = 0 , $relativepath = '' , $permissiontodelete = 1 , $useinecm = 0 , $textifempty = '' , $maxlength = 0 , $url = '' , $addfilterfields = 0 )
2017-10-16 08:47:05 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2023-08-27 14:47:48 +02:00
global $conf , $langs , $hookmanager , $form ;
2017-10-16 08:47:05 +02:00
global $sortfield , $sortorder ;
2017-08-04 13:07:15 +02:00
global $search_doc_ref ;
2020-11-11 22:47:06 +01:00
global $dolibarr_main_url_root ;
2011-04-17 20:41:26 +02:00
2017-10-16 08:47:05 +02:00
dol_syslog ( get_class ( $this ) . '::list_of_autoecmfiles upload_dir=' . $upload_dir . ' modulepart=' . $modulepart );
2012-06-24 17:49:52 +02:00
2017-10-16 08:47:05 +02:00
// Show list of documents
2021-02-23 22:03:23 +01:00
if ( empty ( $useinecm ) || $useinecm == 6 ) {
print load_fiche_titre ( $langs -> trans ( " AttachedFiles " ));
}
if ( empty ( $url )) {
$url = $_SERVER [ " PHP_SELF " ];
}
2017-08-04 13:07:15 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $addfilterfields )) {
2017-10-16 08:47:05 +02:00
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . '">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-16 08:47:05 +02:00
print '<input type="hidden" name="module" value="' . $modulepart . '">' ;
}
2017-08-04 13:07:15 +02:00
print '<div class="div-table-responsive-no-min">' ;
2025-02-04 18:46:20 +01:00
print '<table class="noborder centpercent">' . " \n " ;
2017-10-16 08:47:05 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $addfilterfields )) {
2017-10-16 08:47:05 +02:00
print '<tr class="liste_titre nodrag nodrop">' ;
2020-04-05 02:39:40 +02:00
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="' . dol_escape_htmltag ( $search_doc_ref ) . '"></td>' ;
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
2017-08-04 13:07:15 +02:00
// Action column
2021-01-23 13:56:51 +01:00
print '<td class="liste_titre right">' ;
2019-11-12 09:46:08 +01:00
$searchpicto = $form -> showFilterButtons ();
2017-08-04 13:07:15 +02:00
print $searchpicto ;
print '</td>' ;
2017-10-16 08:47:05 +02:00
print " </tr> \n " ;
}
print '<tr class="liste_titre">' ;
2019-11-12 09:46:08 +01:00
$sortref = " fullname " ;
2021-02-23 22:03:23 +01:00
if ( $modulepart == 'invoice_supplier' ) {
$sortref = 'level1name' ;
}
2019-04-21 19:54:30 +02:00
print_liste_field_titre ( " Ref " , $url , $sortref , " " , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " Documents2 " , $url , " name " , " " , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " Size " , $url , " size " , " " , $param , '' , $sortfield , $sortorder , 'right ' );
print_liste_field_titre ( " Date " , $url , " date " , " " , $param , '' , $sortfield , $sortorder , 'center ' );
2021-01-23 13:56:51 +01:00
print_liste_field_titre ( " Shared " , $url , 'share' , '' , $param , '' , $sortfield , $sortorder , 'right ' );
2017-10-16 08:47:05 +02:00
print '</tr>' . " \n " ;
// To show ref or specific information according to view to show (defined by $module)
2021-12-21 15:33:11 +01:00
$object_instance = null ;
2021-02-23 22:03:23 +01:00
if ( $modulepart == 'company' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new Societe ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'invoice' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new Facture ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'invoice_supplier' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new FactureFournisseur ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'propal' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new Propal ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'supplier_proposal' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/supplier_proposal/class/supplier_proposal.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new SupplierProposal ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'order' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new Commande ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'order_supplier' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new CommandeFournisseur ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'contract' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new Contrat ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'product' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new Product ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'tax' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new ChargeSociales ( $this -> db );
2021-12-07 02:00:34 +01:00
} elseif ( $modulepart == 'tax-vat' ) {
include_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php' ;
$object_instance = new Tva ( $this -> db );
} elseif ( $modulepart == 'salaries' ) {
include_once DOL_DOCUMENT_ROOT . '/salaries/class/salary.class.php' ;
$object_instance = new Salary ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'project' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new Project ( $this -> db );
2021-10-24 11:38:45 +02:00
} elseif ( $modulepart == 'project_task' ) {
include_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php' ;
$object_instance = new Task ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'fichinter' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new Fichinter ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'user' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new User ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'expensereport' ) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new ExpenseReport ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'holiday' ) {
2018-12-01 19:39:00 +01:00
include_once DOL_DOCUMENT_ROOT . '/holiday/class/holiday.class.php' ;
2019-11-12 09:46:08 +01:00
$object_instance = new Holiday ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'recruitment-recruitmentcandidature' ) {
2020-08-23 15:19:03 +02:00
include_once DOL_DOCUMENT_ROOT . '/recruitment/class/recruitmentcandidature.class.php' ;
$object_instance = new RecruitmentCandidature ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'banque' ) {
2020-09-07 10:18:17 +02:00
include_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
$object_instance = new Account ( $this -> db );
2025-02-04 18:46:20 +01:00
} elseif ( $modulepart == 'bank-statement' ) {
//include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$object_instance = null ;
2021-10-24 11:38:45 +02:00
} elseif ( $modulepart == 'chequereceipt' ) {
include_once DOL_DOCUMENT_ROOT . '/compta/paiement/cheque/class/remisecheque.class.php' ;
$object_instance = new RemiseCheque ( $this -> db );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'mrp-mo' ) {
2020-08-23 15:19:03 +02:00
include_once DOL_DOCUMENT_ROOT . '/mrp/class/mo.class.php' ;
$object_instance = new Mo ( $this -> db );
2021-02-06 13:21:16 +01:00
} else {
2024-03-13 00:29:31 +01:00
$parameters = array ( 'modulepart' => $modulepart );
2021-02-06 13:21:16 +01:00
$reshook = $hookmanager -> executeHooks ( 'addSectionECMAuto' , $parameters );
2021-10-25 22:07:31 +02:00
if ( $reshook > 0 && is_array ( $hookmanager -> resArray ) && count ( $hookmanager -> resArray ) > 0 ) {
2021-02-06 13:21:16 +01:00
if ( array_key_exists ( 'classpath' , $hookmanager -> resArray ) && ! empty ( $hookmanager -> resArray [ 'classpath' ])) {
dol_include_once ( $hookmanager -> resArray [ 'classpath' ]);
if ( array_key_exists ( 'classname' , $hookmanager -> resArray ) && ! empty ( $hookmanager -> resArray [ 'classname' ])) {
2024-11-06 23:57:45 +01:00
$tmpclassname = $hookmanager -> resArray [ 'classname' ];
if ( is_string ( $tmpclassname ) && class_exists ( $tmpclassname )) {
2021-09-30 13:38:38 +02:00
$object_instance = new $tmpclassname ( $this -> db );
2021-02-06 13:21:16 +01:00
}
}
}
}
2019-04-21 19:54:30 +02:00
}
2017-10-16 08:47:05 +02:00
2020-11-11 22:47:06 +01:00
//var_dump($filearray);
2021-12-07 02:00:34 +01:00
//var_dump($object_instance);
2020-11-11 22:47:06 +01:00
// Get list of files stored into database for same relative directory
$relativepathfromroot = preg_replace ( '/' . preg_quote ( DOL_DATA_ROOT . '/' , '/' ) . '/' , '' , $upload_dir );
2021-02-23 22:03:23 +01:00
if ( $relativepathfromroot ) {
2020-11-11 22:47:06 +01:00
completeFileArrayWithDatabaseInfo ( $filearray , $relativepathfromroot . '/%' );
2024-11-11 14:48:18 +01:00
'@phan-var-force array<array{name:string,path:string,level1name:string,relativename:string,fullname:string,date:string,size:int,perm:int,type:string,position_name:string,cover:string,keywords:string,acl:string,rowid:int,label:string,share:string}> $filearray' ;
2020-11-11 22:47:06 +01:00
//var_dump($sortfield.' - '.$sortorder);
2021-02-23 22:03:23 +01:00
if ( $sortfield && $sortorder ) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
2021-01-23 13:56:51 +01:00
$filearray = dol_sort_array ( $filearray , $sortfield , $sortorder , 1 );
2020-11-11 22:47:06 +01:00
}
}
//var_dump($filearray);
2021-02-23 22:03:23 +01:00
foreach ( $filearray as $key => $file ) {
2017-10-16 08:47:05 +02:00
if ( ! is_dir ( $file [ 'name' ])
&& $file [ 'name' ] != '.'
&& $file [ 'name' ] != '..'
&& $file [ 'name' ] != 'CVS'
2021-02-23 22:03:23 +01:00
&& ! preg_match ( '/\.meta$/i' , $file [ 'name' ])) {
2017-10-16 08:47:05 +02:00
// Define relative path used to store the file
2019-11-12 09:46:08 +01:00
$relativefile = preg_replace ( '/' . preg_quote ( $upload_dir . '/' , '/' ) . '/' , '' , $file [ 'fullname' ]);
2012-02-06 14:34:58 +01:00
2021-03-01 20:37:16 +01:00
$id = 0 ;
$ref = '' ;
2012-02-06 14:34:58 +01:00
2021-10-06 14:01:48 +02:00
// To show ref or specific information according to view to show (defined by $modulepart)
// $modulepart can be $object->table_name (that is 'mymodule_myobject') or $object->element.'-'.$module (for compatibility purpose)
2020-08-23 15:19:03 +02:00
$reg = array ();
2021-12-07 02:00:34 +01:00
if ( $modulepart == 'company' || $modulepart == 'tax' || $modulepart == 'tax-vat' || $modulepart == 'salaries' ) {
2021-03-01 20:37:16 +01:00
preg_match ( '/(\d+)\/[^\/]+$/' , $relativefile , $reg );
$id = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' );
2021-02-23 22:03:23 +01:00
} elseif ( $modulepart == 'invoice_supplier' ) {
2021-03-01 20:37:16 +01:00
preg_match ( '/([^\/]+)\/[^\/]+$/' , $relativefile , $reg );
2021-10-24 11:38:45 +02:00
$ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' );
if ( is_numeric ( $ref )) {
2021-03-01 20:37:16 +01:00
$id = $ref ;
$ref = '' ;
2021-02-23 22:03:23 +01:00
}
2021-10-24 11:38:45 +02:00
} elseif ( $modulepart == 'user' ) {
2021-03-01 20:37:16 +01:00
// $ref may be also id with old supplier invoices
preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg );
$id = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' );
2021-10-24 11:38:45 +02:00
} elseif ( $modulepart == 'project_task' ) {
// $ref of task is the sub-directory of the project
$reg = explode ( " / " , $relativefile );
$ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' );
2021-02-23 22:03:23 +01:00
} elseif ( in_array ( $modulepart , array (
2020-08-23 15:19:03 +02:00
'invoice' ,
'propal' ,
'supplier_proposal' ,
'order' ,
'order_supplier' ,
'contract' ,
'product' ,
'project' ,
2021-10-24 11:38:45 +02:00
'project_task' ,
2020-08-23 15:19:03 +02:00
'fichinter' ,
'expensereport' ,
'recruitment-recruitmentcandidature' ,
'mrp-mo' ,
2021-10-24 11:38:45 +02:00
'banque' ,
'chequereceipt' ,
'holiday' ))) {
2021-03-01 20:37:16 +01:00
preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg );
$ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' );
2020-05-21 15:05:19 +02:00
} else {
2024-03-13 00:29:31 +01:00
$parameters = array ( 'modulepart' => $modulepart , 'fileinfo' => $file );
2021-02-06 13:21:16 +01:00
$reshook = $hookmanager -> executeHooks ( 'addSectionECMAuto' , $parameters );
2021-10-25 22:07:31 +02:00
if ( $reshook > 0 && is_array ( $hookmanager -> resArray ) && count ( $hookmanager -> resArray ) > 0 ) {
2021-02-06 13:21:16 +01:00
if ( array_key_exists ( 'ref' , $hookmanager -> resArray ) && ! empty ( $hookmanager -> resArray [ 'ref' ])) {
$ref = $hookmanager -> resArray [ 'ref' ];
}
if ( array_key_exists ( 'id' , $hookmanager -> resArray ) && ! empty ( $hookmanager -> resArray [ 'id' ])) {
$id = $hookmanager -> resArray [ 'id' ];
}
}
2020-09-07 10:18:17 +02:00
//print 'Error: Value for modulepart = '.$modulepart.' is not yet implemented in function list_of_autoecmfiles'."\n";
2019-04-21 19:54:30 +02:00
}
2019-02-28 23:19:58 +01:00
2021-02-23 22:03:23 +01:00
if ( ! $id && ! $ref ) {
continue ;
}
2021-12-21 15:33:11 +01:00
2019-11-12 09:46:08 +01:00
$found = 0 ;
2023-08-27 14:47:48 +02:00
if ( ! empty ( $conf -> cache [ 'modulepartobject' ][ $modulepart . '_' . $id . '_' . $ref ])) {
2019-11-12 09:46:08 +01:00
$found = 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-11-11 22:47:06 +01:00
//print 'Fetch '.$id." - ".$ref.' class='.get_class($object_instance).'<br>';
2017-10-16 08:47:05 +02:00
2021-12-21 15:33:11 +01:00
$result = 0 ;
if ( is_object ( $object_instance )) {
2022-09-25 22:08:06 +02:00
$object_instance -> id = 0 ;
$object_instance -> ref = '' ;
2021-12-21 15:33:11 +01:00
if ( $id ) {
$result = $object_instance -> fetch ( $id );
} else {
2024-07-31 18:54:52 +02:00
if ( ! ( $result = $object_instance -> fetch ( 0 , $ref ))) {
2025-02-04 18:46:20 +01:00
// fetchOneLike looks for objects with wildcards in its reference.
// It is useful for those masks who get underscores instead of their actual symbols (because the _ had replaced all forbidden chars into filename)
2023-11-23 18:07:05 +01:00
// TODO Example when this is needed ?
// This may find when ref is 'A_B' and date was stored as 'A~B' into database, but in which case do we have this ?
// May be we can add hidden option to enable this.
2021-12-21 15:33:11 +01:00
$result = $object_instance -> fetchOneLike ( $ref );
}
2017-10-16 08:47:05 +02:00
}
}
2014-12-25 21:47:39 +01:00
2019-04-21 19:54:30 +02:00
if ( $result > 0 ) { // Save object loaded into a cache
2021-03-01 20:37:16 +01:00
$found = 1 ;
2023-08-27 14:47:48 +02:00
$conf -> cache [ 'modulepartobject' ][ $modulepart . '_' . $id . '_' . $ref ] = clone $object_instance ;
2015-09-24 16:32:48 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $result == 0 ) {
2021-03-01 20:37:16 +01:00
$found = 1 ;
2023-08-27 14:47:48 +02:00
$conf -> cache [ 'modulepartobject' ][ $modulepart . '_' . $id . '_' . $ref ] = 'notfound' ;
2021-03-01 20:37:16 +01:00
unset ( $filearray [ $key ]);
2021-02-23 22:03:23 +01:00
}
2017-10-16 08:47:05 +02:00
}
2023-08-27 14:47:48 +02:00
if ( $found <= 0 || ! is_object ( $conf -> cache [ 'modulepartobject' ][ $modulepart . '_' . $id . '_' . $ref ])) {
2021-02-23 22:03:23 +01:00
continue ; // We do not show orphelins files
}
2017-10-16 08:47:05 +02:00
2021-05-21 18:53:09 +02:00
print '<!-- Line list_of_autoecmfiles key=' . $key . ' -->' . " \n " ;
2017-10-16 08:47:05 +02:00
print '<tr class="oddeven">' ;
print '<td>' ;
2023-08-27 14:47:48 +02:00
if ( $found > 0 && is_object ( $conf -> cache [ 'modulepartobject' ][ $modulepart . '_' . $id . '_' . $ref ])) {
$tmpobject = $conf -> cache [ 'modulepartobject' ][ $modulepart . '_' . $id . '_' . $ref ];
2021-05-21 18:53:09 +02:00
//if (! in_array($tmpobject->element, array('expensereport'))) {
print $tmpobject -> getNomUrl ( 1 , 'document' );
//} else {
// print $tmpobject->getNomUrl(1);
//}
2021-02-23 22:03:23 +01:00
} else {
print $langs -> trans ( " ObjectDeleted " , ( $id ? $id : $ref ));
}
2017-10-16 08:47:05 +02:00
//$modulesubdir=dol_sanitizeFileName($ref);
2020-11-11 22:47:06 +01:00
//$modulesubdir = dirname($relativefile);
2017-10-16 08:47:05 +02:00
//$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref);
2020-11-11 22:47:06 +01:00
//$filedir = $file['path'];
2017-10-16 08:47:05 +02:00
//$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
//print $formfile->getDocumentsLink($modulepart, $filename, $filedir);
print '</td>' ;
// File
2021-09-28 16:22:28 +02:00
// Check if document source has external module part, if it the case use it for module part on document.php
2017-10-16 08:47:05 +02:00
print '<td>' ;
//print "XX".$file['name']; //$file['name'] must be utf8
2024-05-05 02:51:05 +02:00
print '<a ' ;
if ( getDolGlobalInt ( 'MAIN_DISABLE_FORCE_SAVEAS' ) == 2 ) {
print 'target="_blank" ' ;
}
print 'href="' . DOL_URL_ROOT . '/document.php?modulepart=' . urlencode ( $modulepart );
2021-02-23 22:03:23 +01:00
if ( $forcedownload ) {
print '&attachment=1' ;
}
2017-10-16 08:47:05 +02:00
print '&file=' . urlencode ( $relativefile ) . '">' ;
2019-01-27 11:55:16 +01:00
print img_mime ( $file [ 'name' ], $file [ 'name' ] . ' (' . dol_print_size ( $file [ 'size' ], 0 , 0 ) . ')' );
2024-02-17 18:05:31 +01:00
print dol_escape_htmltag ( dol_trunc ( $file [ 'name' ], $maxlength , 'middle' ));
2017-10-16 08:47:05 +02:00
print '</a>' ;
2018-01-12 16:28:10 +01:00
//print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$');
2020-11-11 22:47:06 +01:00
2021-10-06 14:01:48 +02:00
print $this -> showPreview ( $file , $modulepart , $file [ 'relativename' ]);
2017-10-16 08:47:05 +02:00
print " </td> \n " ;
2020-11-12 13:44:57 +01:00
// Size
$sizetoshow = dol_print_size ( $file [ 'size' ], 1 , 1 );
$sizetoshowbytes = dol_print_size ( $file [ 'size' ], 0 , 1 );
print '<td class="right nowraponall">' ;
2021-02-23 22:03:23 +01:00
if ( $sizetoshow == $sizetoshowbytes ) {
print $sizetoshow ;
} else {
2020-11-12 13:44:57 +01:00
print $form -> textwithpicto ( $sizetoshow , $sizetoshowbytes , - 1 );
}
print '</td>' ;
// Date
2019-01-27 11:55:16 +01:00
print '<td class="center">' . dol_print_date ( $file [ 'date' ], " dayhour " ) . '</td>' ;
2020-11-12 13:44:57 +01:00
// Share link
2019-01-20 23:36:39 +01:00
print '<td class="right">' ;
2021-03-19 17:01:14 +01:00
if ( ! empty ( $file [ 'share' ])) {
2020-11-11 22:47:06 +01:00
// Define $urlwithroot
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
//print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
$forcedownload = 0 ;
$paramlink = '' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $file [ 'share' ])) {
$paramlink .= ( $paramlink ? '&' : '' ) . 'hashp=' . $file [ 'share' ]; // Hash for public share
}
if ( $forcedownload ) {
$paramlink .= ( $paramlink ? '&' : '' ) . 'attachment=1' ;
}
2020-11-11 22:47:06 +01:00
$fulllink = $urlwithroot . '/document.php' . ( $paramlink ? '?' . $paramlink : '' );
print img_picto ( $langs -> trans ( " FileSharedViaALink " ), 'globe' ) . ' ' ;
2022-04-11 19:21:04 +02:00
print '<input type="text" class="quatrevingtpercent width100 nopadding nopadding small" id="downloadlink" name="downloadexternallink" value="' . dol_escape_htmltag ( $fulllink ) . '">' ;
2020-11-11 22:47:06 +01:00
}
2022-08-31 22:14:20 +02:00
//if (!empty($useinecm) && $useinecm != 6) print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
2017-10-16 08:47:05 +02:00
//if ($forcedownload) print '&attachment=1';
//print '&file='.urlencode($relativefile).'">';
//print img_view().'</a> ';
2020-10-01 10:50:54 +02:00
//if ($permissiontodelete) print '<a href="'.$url.'?id='.$object->id.'§ion='.$_REQUEST["section"].'&action=delete&token='.newToken().'&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
2017-10-16 08:47:05 +02:00
//else print ' ';
2021-01-23 13:56:51 +01:00
print " </td> " ;
print " </tr> \n " ;
2017-10-16 08:47:05 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( count ( $filearray ) == 0 ) {
2018-02-21 11:02:45 +01:00
print '<tr class="oddeven"><td colspan="5">' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $textifempty )) {
print '<span class="opacitymedium">' . $langs -> trans ( " NoFileFound " ) . '</span>' ;
} else {
print '<span class="opacitymedium">' . $textifempty . '</span>' ;
}
2017-10-16 08:47:05 +02:00
print '</td></tr>' ;
}
print " </table> " ;
print '</div>' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $addfilterfields )) {
print '</form>' ;
}
2023-07-12 16:32:50 +02:00
return count ( $filearray );
2017-10-16 08:47:05 +02:00
// Fin de zone
}
/**
* Show array with linked files
*
2024-10-26 18:24:40 +02:00
* @ param CommonObject $object Object
* @ param int < 0 , 1 > $permissiontodelete Deletion is allowed
* @ param ? string $action Action
* @ param ? string $selected ? ? ?
* @ param string $param More param to add into URL
* @ param string $htmlname Html name of component
* @ param array < string , mixed > $moreoptions Add more options like array ( 'afterlinktitle' , ... )
2017-10-16 08:47:05 +02:00
* @ return int Number of links
*/
2024-10-24 18:56:43 +02:00
public function listOfLinks ( $object , $permissiontodelete = 1 , $action = null , $selected = null , $param = '' , $htmlname = 'formaddlink' , $moreoptions = array ())
2017-10-16 08:47:05 +02:00
{
2024-10-24 18:56:43 +02:00
global $conf , $langs ;
2017-10-16 08:47:05 +02:00
global $sortfield , $sortorder ;
$langs -> load ( " link " );
2019-11-12 09:46:08 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php' ;
2017-10-16 08:47:05 +02:00
$link = new Link ( $this -> db );
$links = array ();
if ( $sortfield == " name " ) {
$sortfield = " label " ;
} elseif ( $sortfield == " date " ) {
$sortfield = " datea " ;
} else {
2023-06-13 16:01:52 +02:00
$sortfield = '' ;
2017-10-16 08:47:05 +02:00
}
$res = $link -> fetchAll ( $links , $object -> element , $object -> id , $sortfield , $sortorder );
2019-11-12 09:46:08 +01:00
$param .= ( isset ( $object -> id ) ? '&id=' . $object -> id : '' );
2017-10-16 08:47:05 +02:00
2024-10-24 18:56:43 +02:00
$permissiontoedit = $permissiontodelete ;
2019-10-21 15:49:08 +02:00
print '<!-- listOfLinks -->' . " \n " ;
2024-10-24 18:56:43 +02:00
$morehtmlright = '' ;
if ( ! empty ( $moreoptions [ 'showhideaddbutton' ]) && $conf -> use_javascript_ajax ) {
2024-12-13 09:50:29 +01:00
$morehtmlright .= dolGetButtonTitle ( $langs -> trans ( 'New' ), '' , 'fa fa-plus-circle' , 'javascript:console.log("open addlink form"); jQuery(".divlinkfile").toggle(); void(0);' , '' , $permissiontoedit );
2024-10-24 18:56:43 +02:00
}
2017-10-16 08:47:05 +02:00
// Show list of associated links
2024-10-24 18:56:43 +02:00
print load_fiche_titre ( $langs -> trans ( " LinkedFiles " ), $morehtmlright , 'link' , 0 , '' , 'table-list-of-links' );
2017-10-16 08:47:05 +02:00
2024-10-24 18:56:43 +02:00
if ( ! empty ( $moreoptions ) && $moreoptions [ 'afterlinktitle' ]) {
print '<div class="divlinkfile' . (( ! empty ( $moreoptions [ 'showhideaddbutton' ]) && $conf -> use_javascript_ajax ) ? ' hidden' : '' ) . '">' . $moreoptions [ 'afterlinktitle' ] . '</div>' ;
2024-10-24 18:05:46 +02:00
}
2024-10-24 18:56:43 +02:00
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . ( $param ? '?' . $param : '' ) . '" id="' . $htmlname . '" method="POST">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-10-16 08:47:05 +02:00
2022-03-07 16:04:55 +01:00
print '<table class="liste noborder nobottom centpercent">' ;
2017-10-16 08:47:05 +02:00
print '<tr class="liste_titre">' ;
2020-09-07 10:18:17 +02:00
print_liste_field_titre (
2017-10-16 08:47:05 +02:00
$langs -> trans ( " Links " ),
$_SERVER [ 'PHP_SELF' ],
" name " ,
" " ,
$param ,
2019-04-10 11:39:54 +02:00
'' ,
2017-10-16 08:47:05 +02:00
$sortfield ,
2019-04-10 11:39:54 +02:00
$sortorder ,
2020-09-07 10:18:17 +02:00
''
2017-10-16 08:47:05 +02:00
);
2020-09-07 10:18:17 +02:00
print_liste_field_titre (
2017-10-16 08:47:05 +02:00
" " ,
" " ,
" " ,
" " ,
" " ,
2019-04-10 11:39:54 +02:00
'' ,
2020-09-07 10:18:17 +02:00
'' ,
'' ,
'right '
2017-10-16 08:47:05 +02:00
);
2020-09-07 10:18:17 +02:00
print_liste_field_titre (
2017-10-16 08:47:05 +02:00
$langs -> trans ( " Date " ),
$_SERVER [ 'PHP_SELF' ],
" date " ,
" " ,
$param ,
2019-04-10 11:39:54 +02:00
'' ,
2017-10-16 08:47:05 +02:00
$sortfield ,
2019-04-10 11:39:54 +02:00
$sortorder ,
2020-09-07 10:18:17 +02:00
'center '
2017-10-16 08:47:05 +02:00
);
2020-09-07 10:18:17 +02:00
print_liste_field_titre (
2017-10-16 08:47:05 +02:00
'' ,
$_SERVER [ 'PHP_SELF' ],
" " ,
" " ,
$param ,
2019-04-10 11:39:54 +02:00
'' ,
2020-09-07 10:18:17 +02:00
'' ,
'' ,
'center '
2017-10-16 08:47:05 +02:00
);
2019-01-27 11:55:16 +01:00
print_liste_field_titre ( '' , '' , '' );
2017-10-16 08:47:05 +02:00
print '</tr>' ;
$nboflinks = count ( $links );
2021-02-23 22:03:23 +01:00
if ( $nboflinks > 0 ) {
include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php' ;
}
foreach ( $links as $link ) {
2017-11-19 20:44:57 +01:00
print '<tr class="oddeven">' ;
2017-10-16 08:47:05 +02:00
//edit mode
2024-10-24 20:13:12 +02:00
if ( $action == 'update' && $selected === ( int ) $link -> id && $permissiontoedit ) {
2017-10-16 08:47:05 +02:00
print '<td>' ;
2019-11-12 09:46:08 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
print '<input type="hidden" name="linkid" value="' . $link -> id . '">' ;
2017-10-16 08:47:05 +02:00
print '<input type="hidden" name="action" value="confirm_updateline">' ;
2019-11-12 09:46:08 +01:00
print $langs -> trans ( 'Link' ) . ': <input type="text" name="link" value="' . $link -> url . '">' ;
2017-10-16 08:47:05 +02:00
print '</td>' ;
print '<td>' ;
2019-11-12 09:46:08 +01:00
print $langs -> trans ( 'Label' ) . ': <input type="text" name="label" value="' . dol_escape_htmltag ( $link -> label ) . '">' ;
2017-10-16 08:47:05 +02:00
print '</td>' ;
2019-11-12 09:46:08 +01:00
print '<td class="center">' . dol_print_date ( dol_now (), " dayhour " , " tzuser " ) . '</td>' ;
2019-01-20 23:36:39 +01:00
print '<td class="right"></td>' ;
print '<td class="right">' ;
2021-09-22 08:43:30 +02:00
print '<input type="submit" class="button button-save" name="save" value="' . dol_escape_htmltag ( $langs -> trans ( " Save " )) . '">' ;
print '<input type="submit" class="button button-cancel" name="cancel" value="' . dol_escape_htmltag ( $langs -> trans ( " Cancel " )) . '">' ;
2017-10-16 08:47:05 +02:00
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-16 08:47:05 +02:00
print '<td>' ;
2019-10-03 21:32:55 +02:00
print img_picto ( '' , 'globe' ) . ' ' ;
2021-11-22 02:35:55 +01:00
print '<a data-ajax="false" href="' . $link -> url . '" target="_blank" rel="noopener noreferrer">' ;
2019-08-16 16:41:53 +02:00
print dol_escape_htmltag ( $link -> label );
2017-10-16 08:47:05 +02:00
print '</a>' ;
print '</td>' . " \n " ;
2019-01-20 23:36:39 +01:00
print '<td class="right"></td>' ;
2019-11-12 09:46:08 +01:00
print '<td class="center">' . dol_print_date ( $link -> datea , " dayhour " , " tzuser " ) . '</td>' ;
2019-01-20 23:36:39 +01:00
print '<td class="center"></td>' ;
print '<td class="right">' ;
2021-05-05 17:05:51 +02:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=update&linkid=' . $link -> id . $param . '&token=' . newToken () . '" class="editfilelink editfielda reposition" >' . img_edit () . '</a>' ; // id= is included into $param
2019-11-04 15:33:49 +01:00
if ( $permissiontodelete ) {
2022-03-07 16:04:55 +01:00
print ' <a class="deletefilelink reposition" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=deletelink&token=' . newToken () . '&linkid=' . (( int ) $link -> id ) . $param . '">' . img_delete () . '</a>' ; // id= is included into $param
2017-10-16 08:47:05 +02:00
} else {
print ' ' ;
}
print '</td>' ;
}
print " </tr> \n " ;
}
2021-02-23 22:03:23 +01:00
if ( $nboflinks == 0 ) {
2021-10-10 21:25:46 +02:00
print '<tr class="oddeven"><td colspan="5">' ;
print '<span class="opacitymedium">' . $langs -> trans ( " NoLinkFound " ) . '</span>' ;
2017-10-16 08:47:05 +02:00
print '</td></tr>' ;
}
print " </table> " ;
2016-08-02 03:35:22 +02:00
2017-10-16 08:47:05 +02:00
print '</form>' ;
return $nboflinks ;
}
/**
* Show detail icon with link for preview
*
2024-10-26 18:24:40 +02:00
* @ param array { name : string , path : string , level1name : string , relativename : string , fullname : string , date : string , size : int , perm : int , type : string } $file Array with data of file . Example : array ( 'name' =>... )
2025-02-10 11:15:08 +01:00
* @ param string $modulepart propal , facture , facture_fourn , ...
* @ param string $relativepath Relative path of docs
* @ param int < min , 1 > $ruleforpicto Rule for picto : 0 = Use the generic preview picto , 1 = Use the picto of mime type of file ) . Use a negative value to show a generic picto even if preview not available .
2017-10-16 08:47:05 +02:00
* @ param string $param More param on http links
* @ return string $out Output string with HTML
*/
2022-09-15 05:00:13 +02:00
public function showPreview ( $file , $modulepart , $relativepath , $ruleforpicto = 0 , $param = '' )
2017-10-16 08:47:05 +02:00
{
global $langs , $conf ;
2010-05-03 10:43:32 +02:00
2019-11-12 09:46:08 +01:00
$out = '' ;
2021-02-23 22:03:23 +01:00
if ( $conf -> browser -> layout != 'phone' && ! empty ( $conf -> use_javascript_ajax )) {
2019-11-12 09:46:08 +01:00
$urladvancedpreview = getAdvancedPreviewUrl ( $modulepart , $relativepath , 1 , $param ); // Return if a file is qualified for preview.
2021-02-23 22:03:23 +01:00
if ( count ( $urladvancedpreview )) {
2022-09-15 05:00:13 +02:00
$out .= '<a class="pictopreview ' . $urladvancedpreview [ 'css' ] . '" href="' . $urladvancedpreview [ 'url' ] . '"' . ( empty ( $urladvancedpreview [ 'mime' ]) ? '' : ' mime="' . $urladvancedpreview [ 'mime' ] . '"' ) . ' ' . ( empty ( $urladvancedpreview [ 'target' ]) ? '' : ' target="' . $urladvancedpreview [ 'target' ] . '"' ) . '>' ;
2017-10-16 08:47:05 +02:00
//$out.= '<a class="pictopreview">';
2020-12-17 11:57:12 +01:00
if ( empty ( $ruleforpicto )) {
2017-11-10 20:20:59 +01:00
//$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail');
2022-04-01 11:24:45 +02:00
$out .= '<span class="fa fa-search-plus pictofixedwidth" style="color: gray"></span>' ;
2020-12-17 11:57:12 +01:00
} else {
2022-04-01 11:24:45 +02:00
$out .= img_mime ( $relativepath , $langs -> trans ( 'Preview' ) . ' ' . $file [ 'name' ], 'pictofixedwidth' );
2020-12-17 11:57:12 +01:00
}
2019-11-12 09:46:08 +01:00
$out .= '</a>' ;
2022-04-01 11:24:45 +02:00
} else {
if ( $ruleforpicto < 0 ) {
2024-09-25 22:21:31 +02:00
$out .= img_picto ( '' , 'generic' , '' , 0 , 0 , 0 , '' , 'paddingright pictofixedwidth' );
2022-04-01 11:24:45 +02:00
}
2017-10-16 08:47:05 +02:00
}
}
return $out ;
}
2010-05-03 10:43:32 +02:00
}