2010-05-03 10:43:32 +02:00
< ? php
2014-08-28 15:52:20 +02:00
/* Copyright ( C ) 2008 - 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2010 - 2014 Regis Houssin < regis . houssin @ capnetworks . 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 >
2015-05-18 21:47:44 +02: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
2011-08-01 01:45:11 +02:00
* along with this program . If not , see < http :// 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
{
2017-10-16 08:47:05 +02:00
private $db ;
2017-06-10 13:44:20 +02:00
2017-10-16 08:47:05 +02:00
public $error ;
public $numoffiles ;
public $infofiles ; // Used to return informations by function getDocumentsLink
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
*/
function __construct ( $db )
{
$this -> db = $db ;
$this -> numoffiles = 0 ;
return 1 ;
}
2011-08-16 11:36:00 +02:00
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' )
2017-11-18 15:41:30 +01:00
* @ param int $addcancel 1 = Add 'Cancel' button
* @ 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
* @ param int $size Length of input file area . Deprecated .
2017-10-16 08:47:05 +02:00
* @ param Object $object Object to use ( when attachment is done on an element )
* @ param string $options Add an option column
2017-11-18 15:41:30 +01:00
* @ param integer $useajax Use fileupload ajax ( 0 = never , 1 = if enabled , 2 = always whatever is option ) . @ deprecated 2 should never be used and if 1 is used , option should no be enabled .
2017-10-16 08:47:05 +02:00
* @ param string $savingdocmask Mask to use to define output filename . For example 'XXXXX-__YYYYMMDD__-__file__'
* @ param integer $linkfiles 1 = Also add form to link files , 0 = Do not show form to link files
* @ 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/*' )
2017-11-18 15:41:30 +01:00
* @ param string $sectiondir If upload must be done inside a particular directory ( is sectiondir defined , sectionid must not be )
* @ return int < 0 if KO , > 0 if OK
2017-10-16 08:47:05 +02:00
*/
2017-11-18 15:41:30 +01:00
function form_attach_new_file ( $url , $title = '' , $addcancel = 0 , $sectionid = 0 , $perm = 1 , $size = 50 , $object = '' , $options = '' , $useajax = 1 , $savingdocmask = '' , $linkfiles = 1 , $htmlname = 'formuserfile' , $accept = '' , $sectiondir = '' )
2017-10-16 08:47:05 +02:00
{
global $conf , $langs , $hookmanager ;
$hookmanager -> initHooks ( array ( 'formfile' ));
if ( ! empty ( $conf -> browser -> layout ) && $conf -> browser -> layout != 'classic' ) $useajax = 0 ;
2013-04-03 18:37:54 +02:00
2013-10-29 17:50:39 +01:00
if (( ! empty ( $conf -> global -> MAIN_USE_JQUERY_FILEUPLOAD ) && $useajax ) || ( $useajax == 2 ))
2017-10-16 08:47:05 +02:00
{
// TODO: Check this works with 2 forms on same page
// TODO: Check this works with GED module, otherwise, force useajax to 0
// TODO: This does not support option savingdocmask
// TODO: This break feature to upload links too
return $this -> _formAjaxFileUpload ( $object );
}
else
{
//If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed
if ( ! $perm && ! empty ( $conf -> global -> MAIN_BUTTON_HIDE_UNAUTHORIZED )) {
return 1 ;
}
$maxlength = $size ;
$out = " \n \n <!-- Start form attach new file --> \n " ;
if ( empty ( $title )) $title = $langs -> trans ( " AttachANewFile " );
if ( $title != 'none' ) $out .= load_fiche_titre ( $title , null , null );
$out .= '<form name="' . $htmlname . '" id="' . $htmlname . '" action="' . $url . '" enctype="multipart/form-data" method="POST">' ;
2017-11-18 15:41:30 +01:00
$out .= '<input type="hidden" id="' . $htmlname . '_section_dir" name="section_dir" value="' . $sectiondir . '">' ;
2017-10-16 08:47:05 +02:00
$out .= '<input type="hidden" id="' . $htmlname . '_section_id" name="section_id" value="' . $sectionid . '">' ;
$out .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
$out .= '<table width="100%" class="nobordernopadding">' ;
$out .= '<tr>' ;
if ( ! empty ( $options )) $out .= '<td>' . $options . '</td>' ;
2018-01-02 17:27:05 +01:00
$out .= '<td class="valignmiddle nowrap">' ;
2017-10-16 08:47:05 +02:00
$max = $conf -> global -> MAIN_UPLOAD_DOC ; // En Kb
$maxphp =@ ini_get ( 'upload_max_filesize' ); // En inconnu
if ( preg_match ( '/k$/i' , $maxphp )) $maxphp = $maxphp * 1 ;
if ( preg_match ( '/m$/i' , $maxphp )) $maxphp = $maxphp * 1024 ;
if ( preg_match ( '/g$/i' , $maxphp )) $maxphp = $maxphp * 1024 * 1024 ;
if ( preg_match ( '/t$/i' , $maxphp )) $maxphp = $maxphp * 1024 * 1024 * 1024 ;
// Now $max and $maxphp are in Kb
2018-09-20 16:21:08 +02:00
$maxmin = $max ;
if ( $maxphp > 0 ) $maxmin = min ( $max , $maxphp );
2017-10-16 08:47:05 +02:00
2018-09-20 16:21:08 +02:00
if ( $maxmin > 0 )
2017-10-16 08:47:05 +02:00
{
2018-11-06 17:40:59 +01:00
// MAX_FILE_SIZE doit précéder le champ input de type file
2018-09-20 16:21:08 +02:00
$out .= '<input type="hidden" name="max_file_size" value="' . ( $maxmin * 1024 ) . '">' ;
2017-10-16 08:47:05 +02:00
}
$out .= '<input class="flat minwidth400" type="file"' ;
$out .= (( ! empty ( $conf -> global -> MAIN_DISABLE_MULTIPLE_FILEUPLOAD ) || $conf -> browser -> layout != 'classic' ) ? ' name="userfile"' : ' name="userfile[]" multiple' );
$out .= ( empty ( $conf -> global -> MAIN_UPLOAD_DOC ) || empty ( $perm ) ? ' disabled' : '' );
$out .= ( ! empty ( $accept ) ? ' accept="' . $accept . '"' : ' accept=""' );
$out .= '>' ;
$out .= ' ' ;
$out .= '<input type="submit" class="button" name="sendit" value="' . $langs -> trans ( " Upload " ) . '"' ;
$out .= ( empty ( $conf -> global -> MAIN_UPLOAD_DOC ) || empty ( $perm ) ? ' disabled' : '' );
$out .= '>' ;
if ( $addcancel )
{
$out .= ' ' ;
$out .= '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
}
if ( ! empty ( $conf -> global -> MAIN_UPLOAD_DOC ))
{
if ( $perm )
{
$langs -> load ( 'other' );
$out .= ' ' ;
$out .= info_admin ( $langs -> trans ( " ThisLimitIsDefinedInSetup " , $max , $maxphp ), 1 );
}
}
else
{
$out .= ' (' . $langs -> trans ( " UploadDisabled " ) . ')' ;
}
$out .= " </td></tr> " ;
if ( $savingdocmask )
{
$out .= '<tr>' ;
if ( ! empty ( $options )) $out .= '<td>' . $options . '</td>' ;
$out .= '<td valign="middle" class="nowrap">' ;
2016-10-16 18:28:09 +02:00
$out .= '<input type="checkbox" checked class="savingdocmask" name="savingdocmask" value="' . dol_escape_js ( $savingdocmask ) . '"> ' . $langs -> trans ( " SaveUploadedFileWithMask " , preg_replace ( '/__file__/' , $langs -> transnoentitiesnoconv ( " OriginFileName " ), $savingdocmask ), $langs -> transnoentitiesnoconv ( " OriginFileName " ));
2017-10-16 08:47:05 +02:00
$out .= '</td>' ;
$out .= '</tr>' ;
}
$out .= " </table> " ;
$out .= '</form>' ;
if ( empty ( $sectionid )) $out .= '<br>' ;
$out .= " \n <!-- End form attach new file --> \n " ;
if ( $linkfiles )
{
2018-09-24 15:13:18 +02:00
$out .= " \n <!-- Start form link new url --> \n " ;
2017-10-16 08:47:05 +02:00
$langs -> load ( 'link' );
$title = $langs -> trans ( " LinkANewFile " );
$out .= load_fiche_titre ( $title , null , null );
$out .= '<form name="' . $htmlname . '_link" id="' . $htmlname . '_link" action="' . $url . '" method="POST">' ;
$out .= '<input type="hidden" id="' . $htmlname . '_link_section_dir" name="link_section_dir" value="">' ;
$out .= '<input type="hidden" id="' . $htmlname . '_link_section_id" name="link_section_id" value="' . $sectionid . '">' ;
$out .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
$out .= '<div class="valignmiddle" >' ;
$out .= '<div class="inline-block" style="padding-right: 10px;">' ;
if ( ! empty ( $conf -> global -> OPTIMIZEFORTEXTBROWSER )) $out .= '<label for="link">' . $langs -> trans ( " URLToLink " ) . ':</label> ' ;
$out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="' . dol_escape_htmltag ( $langs -> trans ( " URLToLink " )) . '">' ;
$out .= '</div>' ;
$out .= '<div class="inline-block" style="padding-right: 10px;">' ;
if ( ! empty ( $conf -> global -> OPTIMIZEFORTEXTBROWSER )) $out .= '<label for="label">' . $langs -> trans ( " Label " ) . ':</label> ' ;
$out .= '<input type="text" class="flat" name="label" id="label" placeholder="' . dol_escape_htmltag ( $langs -> trans ( " Label " )) . '">' ;
$out .= '<input type="hidden" name="objecttype" value="' . $object -> element . '">' ;
$out .= '<input type="hidden" name="objectid" value="' . $object -> id . '">' ;
$out .= '</div>' ;
$out .= '<div class="inline-block" style="padding-right: 10px;">' ;
$out .= '<input type="submit" class="button" name="linkit" value="' . $langs -> trans ( " ToLink " ) . '"' ;
$out .= ( empty ( $conf -> global -> MAIN_UPLOAD_DOC ) || empty ( $perm ) ? ' disabled' : '' );
$out .= '>' ;
$out .= '</div>' ;
$out .= '</div>' ;
$out .= '<div class="clearboth"></div>' ;
$out .= '</form><br>' ;
2018-09-24 15:13:18 +02:00
$out .= " \n <!-- End form link new url --> \n " ;
2017-10-16 08:47:05 +02:00
}
2018-09-24 15:13:18 +02:00
$parameters = array ( 'socid' => ( isset ( $GLOBALS [ 'socid' ]) ? $GLOBALS [ 'socid' ] : '' ), 'id' => ( isset ( $GLOBALS [ 'id' ]) ? $GLOBALS [ 'id' ] : '' ), 'url' => $url , 'perm' => $perm );
$res = $hookmanager -> executeHooks ( 'formattachOptions' , $parameters , $object );
2017-10-16 08:47:05 +02:00
if ( empty ( $res ))
{
print '<div class="attacharea attacharea' . $htmlname . '">' ;
print $out ;
print '</div>' ;
}
print $hookmanager -> resPrint ;
return 1 ;
}
}
/**
* 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 )
* @ param int $genallowed Generation is allowed ( 1 / 0 or array of formats )
* @ param int $delallowed Remove is allowed ( 1 / 0 )
* @ 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
* @ return int < 0 if KO , number of shown files if OK
* @ deprecated Use print xxx -> showdocuments () instead .
*/
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 = '' )
{
$this -> numoffiles = 0 ;
print $this -> showdocuments ( $modulepart , $modulesubdir , $filedir , $urlsource , $genallowed , $delallowed , $modelselected , $allowgenifempty , $forcenomultilang , $iconPDF , $notused , $noform , $param , $title , $buttonlabel , $codelang );
return $this -> numoffiles ;
}
/**
* Return a string to show the box with list of available documents for object .
* This also set the property $this -> numoffiles
*
* @ param string $modulepart Module the files are related to ( 'propal' , 'facture' , 'facture_fourn' , 'mymodule' , 'mymodule_temp' , ... )
* @ 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 subdir of module .
* @ param string $filedir Directory to scan
* @ param string $urlsource Url of origin page ( for return )
* @ param int $genallowed Generation is allowed ( 1 / 0 or array list of templates )
* @ param int $delallowed Remove is allowed ( 1 / 0 )
* @ param string $modelselected Model to preselect by default
* @ param integer $allowgenifempty Allow generation even if list of template ( $genallowed ) is empty ( show however a warning )
* @ param integer $forcenomultilang Do not show language option ( even if MAIN_MULTILANGS defined )
* @ param int $iconPDF Deprecated , see getDocumentsLink
* @ 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
* @ param string $morepicto Add more HTML content into cell with picto
* @ param Object $object Object when method is called from an object card .
2018-02-21 11:02:45 +01:00
* @ param int $hideifempty Hide section of generated files if there is no file
2017-10-16 08:47:05 +02:00
* @ return string Output string with HTML array of documents ( might be empty string )
*/
2018-02-21 11:02:45 +01:00
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 )
2017-10-16 08:47:05 +02:00
{
2015-04-23 23:21:06 +02:00
// Deprecation warning
2018-02-21 11:02:45 +01:00
if ( ! empty ( $iconPDF )) {
2015-04-23 23:21:06 +02:00
dol_syslog ( __METHOD__ . " : passing iconPDF parameter is deprecated " , LOG_WARNING );
}
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
2017-10-16 08:47:05 +02: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' ;
2013-06-16 20:08:45 +02:00
2017-10-16 08:47:05 +02:00
// For backward compatibility
if ( ! empty ( $iconPDF )) {
return $this -> getDocumentsLink ( $modulepart , $modulesubdir , $filedir );
}
2017-01-15 12:09:26 +01:00
2018-02-25 17:43:19 +01:00
// Add entity in $param
$param .= 'entity=' . ( ! empty ( $object -> entity ) ? $object -> entity : $conf -> entity );
2017-10-16 08:47:05 +02:00
$printer = 0 ;
if ( in_array ( $modulepart , array ( 'facture' , 'supplier_proposal' , 'propal' , 'proposal' , 'order' , 'commande' , 'expedition' , 'commande_fournisseur' , 'expensereport' ))) // The direct print feature is implemented only for such elements
{
$printer = ( ! empty ( $user -> rights -> printing -> read ) && ! empty ( $conf -> printing -> enabled )) ? true : false ;
}
2014-12-07 18:24:45 +01:00
2017-10-16 08:47:05 +02:00
$hookmanager -> initHooks ( array ( 'formfile' ));
2011-08-16 11:36:00 +02:00
2018-02-21 11:02:45 +01:00
// Get list of files
$file_list = null ;
if ( ! empty ( $filedir ))
{
$file_list = dol_dir_list ( $filedir , 'files' , 0 , '' , '(\.meta|_preview.*.*\.png)$' , 'date' , SORT_DESC );
}
if ( $hideifempty && empty ( $file_list )) return '' ;
$out = '' ;
$forname = 'builddoc' ;
2017-10-16 08:47:05 +02:00
$headershown = 0 ;
$showempty = 0 ;
$i = 0 ;
2010-05-03 10:43:32 +02:00
2017-10-16 08:47:05 +02:00
$out .= " \n " . '<!-- Start show_document -->' . " \n " ;
//print 'filedir='.$filedir;
2011-08-16 11:36:00 +02:00
2017-10-16 08:47:05 +02:00
if ( preg_match ( '/massfilesarea_/' , $modulepart ))
{
$out .= '<div id="show_files"><br></div>' . " \n " ;
2016-10-28 12:00:30 +02:00
$title = $langs -> trans ( " MassFilesArea " ) . ' <a href="" id="togglemassfilesarea" ref="shown">(' . $langs -> trans ( " Hide " ) . ')</a>' ;
$title .= ' < script type = " text/javascript " language = " javascript " >
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
}
$titletoshow = $langs -> trans ( " Documents " );
if ( ! empty ( $title )) $titletoshow = $title ;
// Show table
if ( $genallowed )
{
$modellist = array ();
if ( $modulepart == 'company' )
{
$showempty = 1 ;
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/societe/modules_societe.class.php' ;
$modellist = ModeleThirdPartyDoc :: liste_modeles ( $this -> db );
}
}
else if ( $modulepart == 'propal' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/propale/modules_propale.php' ;
$modellist = ModelePDFPropales :: liste_modeles ( $this -> db );
}
}
2015-11-15 18:23:42 +01:00
else if ( $modulepart == 'supplier_proposal' )
2017-10-16 08:47:05 +02:00
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_proposal/modules_supplier_proposal.php' ;
$modellist = ModelePDFSupplierProposal :: liste_modeles ( $this -> db );
}
}
else if ( $modulepart == 'commande' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/commande/modules_commande.php' ;
$modellist = ModelePDFCommandes :: liste_modeles ( $this -> db );
}
}
elseif ( $modulepart == 'expedition' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php' ;
$modellist = ModelePDFExpedition :: liste_modeles ( $this -> db );
}
}
elseif ( $modulepart == 'livraison' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/livraison/modules_livraison.php' ;
$modellist = ModelePDFDeliveryOrder :: liste_modeles ( $this -> db );
}
}
else if ( $modulepart == 'ficheinter' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/fichinter/modules_fichinter.php' ;
$modellist = ModelePDFFicheinter :: liste_modeles ( $this -> db );
}
}
elseif ( $modulepart == 'facture' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php' ;
$modellist = ModelePDFFactures :: liste_modeles ( $this -> db );
}
}
elseif ( $modulepart == 'contract' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/contract/modules_contract.php' ;
$modellist = ModelePDFContract :: liste_modeles ( $this -> db );
}
}
elseif ( $modulepart == 'project' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/project/modules_project.php' ;
$modellist = ModelePDFProjects :: liste_modeles ( $this -> db );
}
}
elseif ( $modulepart == 'project_task' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/project/task/modules_task.php' ;
$modellist = ModelePDFTask :: liste_modeles ( $this -> db );
}
}
elseif ( $modulepart == 'product' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/product/modules_product.class.php' ;
$modellist = ModelePDFProduct :: liste_modeles ( $this -> db );
}
}
2018-04-12 15:10:37 +02:00
elseif ( $modulepart == 'product_batch' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/product_batch/modules_product_batch.class.php' ;
$modellist = ModelePDFProductBatch :: liste_modeles ( $this -> db );
}
}
2018-05-22 02:09:52 +02: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' ;
2018-05-22 02:09:52 +02:00
$modellist = ModelePDFStock :: liste_modeles ( $this -> db );
}
}
2018-05-25 11:19:38 +02:00
elseif ( $modulepart == 'movement' )
2018-05-22 02:09:52 +02:00
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
2018-05-25 11:19:38 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/stock/modules_movement.php' ;
$modellist = ModelePDFMovement :: liste_modeles ( $this -> db );
2018-05-22 02:09:52 +02:00
}
}
2017-10-16 08:47:05 +02:00
elseif ( $modulepart == 'export' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/export/modules_export.php' ;
$modellist = ModeleExports :: liste_modeles ( $this -> db );
}
}
else if ( $modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_order/modules_commandefournisseur.php' ;
$modellist = ModelePDFSuppliersOrders :: liste_modeles ( $this -> db );
}
}
else if ( $modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php' ;
$modellist = ModelePDFSuppliersInvoices :: liste_modeles ( $this -> db );
}
}
2017-02-10 17:28:00 +01:00
else if ( $modulepart == 'supplier_payment' )
{
2017-10-16 08:47:05 +02:00
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_payment/modules_supplier_payment.php' ;
$modellist = ModelePDFSuppliersPayments :: liste_modeles ( $this -> db );
}
2017-02-10 17:28:00 +01:00
}
2017-10-16 08:47:05 +02:00
else if ( $modulepart == 'remisecheque' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/cheque/modules_chequereceipts.php' ;
$modellist = ModeleChequeReceipts :: liste_modeles ( $this -> db );
}
}
elseif ( $modulepart == 'donation' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
2015-02-21 12:57:17 +01:00
{
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/dons/modules_don.php' ;
$modellist = ModeleDon :: liste_modeles ( $this -> db );
}
}
elseif ( $modulepart == 'member' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/member/modules_cards.php' ;
$modellist = ModelePDFCards :: liste_modeles ( $this -> db );
}
}
2018-05-18 11:52:48 +02:00
elseif ( $modulepart == 'agenda' || $modulepart == 'actions' )
2017-10-16 08:47:05 +02:00
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/action/modules_action.php' ;
$modellist = ModeleAction :: liste_modeles ( $this -> db );
}
}
else if ( $modulepart == 'expensereport' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/expensereport/modules_expensereport.php' ;
$modellist = ModeleExpenseReport :: liste_modeles ( $this -> db );
}
}
else if ( $modulepart == 'unpaid' )
{
$modellist = '' ;
}
elseif ( $modulepart == 'user' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/user/modules_user.class.php' ;
$modellist = ModelePDFUser :: liste_modeles ( $this -> db );
}
}
elseif ( $modulepart == 'usergroup' )
{
if ( is_array ( $genallowed )) $modellist = $genallowed ;
else
{
include_once DOL_DOCUMENT_ROOT . '/core/modules/usergroup/modules_usergroup.class.php' ;
$modellist = ModelePDFUserGroup :: liste_modeles ( $this -> db );
}
}
2018-05-18 11:52:48 +02:00
else
2017-10-16 08:47:05 +02:00
{
// For normalized standard modules
$file = dol_buildpath ( '/core/modules/' . $modulepart . '/modules_' . $modulepart . '.php' , 0 );
if ( file_exists ( $file ))
{
$res = include_once $file ;
}
// For normalized external modules
else
{
$file = dol_buildpath ( '/' . $modulepart . '/core/modules/' . $modulepart . '/modules_' . $modulepart . '.php' , 0 );
$res = include_once $file ;
}
2018-04-20 16:47:49 +02:00
$class = 'ModelePDF' . ucfirst ( $modulepart );
2017-10-16 08:47:05 +02:00
if ( class_exists ( $class ))
{
$modellist = call_user_func ( $class . '::liste_modeles' , $this -> db );
}
else
2018-05-24 12:16:04 +02:00
{
2017-10-16 08:47:05 +02:00
dol_print_error ( $this -> db , 'Bad value for modulepart' );
return - 1 ;
}
}
2018-02-15 12:57:04 +01:00
// Set headershown to avoid to have table opened a second time later
2017-10-16 08:47:05 +02:00
$headershown = 1 ;
$buttonlabeltoshow = $buttonlabel ;
if ( empty ( $buttonlabel )) $buttonlabel = $langs -> trans ( 'Generate' );
if ( $conf -> browser -> layout == 'phone' ) $urlsource .= '#' . $forname . '_form' ; // So we switch to form after a generation
if ( empty ( $noform )) $out .= '<form action="' . $urlsource . ( empty ( $conf -> global -> MAIN_JUMP_TAG ) ? '' : '#builddoc' ) . '" id="' . $forname . '_form" method="post">' ;
$out .= '<input type="hidden" name="action" value="builddoc">' ;
$out .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
$out .= load_fiche_titre ( $titletoshow , '' , '' );
$out .= '<div class="div-table-responsive-no-min">' ;
$out .= '<table class="liste formdoc noborder" summary="listofdocumentstable" width="100%">' ;
$out .= '<tr class="liste_titre">' ;
$addcolumforpicto = ( $delallowed || $printer || $morepicto );
2018-03-14 17:12:32 +01:00
$out .= '<th align="center" colspan="' . ( 3 + ( $addcolumforpicto ? 1 : 0 )) . '" class="formdoc liste_titre maxwidthonsmartphone">' ;
2017-10-16 08:47:05 +02:00
// Model
if ( ! empty ( $modellist ))
{
$out .= '<span class="hideonsmartphone">' . $langs -> trans ( 'Model' ) . ' </span>' ;
if ( is_array ( $modellist ) && count ( $modellist ) == 1 ) // If there is only one element
{
$arraykeys = array_keys ( $modellist );
$modelselected = $arraykeys [ 0 ];
}
$out .= $form -> selectarray ( 'model' , $modellist , $modelselected , $showempty , 0 , 0 , '' , 0 , 0 , 0 , '' , 'minwidth100' );
2017-11-14 17:51:04 +01:00
if ( $conf -> use_javascript_ajax )
{
$out .= ajax_combobox ( 'model' );
}
2017-10-16 08:47:05 +02:00
}
else
{
$out .= '<div class="float">' . $langs -> trans ( " Files " ) . '</div>' ;
}
// Language code (if multilang)
if (( $allowgenifempty || ( is_array ( $modellist ) && count ( $modellist ) > 0 )) && $conf -> global -> MAIN_MULTILANGS && ! $forcenomultilang && ( ! empty ( $modellist ) || $showempty ))
{
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php' ;
$formadmin = new FormAdmin ( $this -> db );
$defaultlang = $codelang ? $codelang : $langs -> getDefaultLang ();
$morecss = 'maxwidth150' ;
if ( ! empty ( $conf -> browser -> phone )) $morecss = 'maxwidth100' ;
$out .= $formadmin -> select_language ( $defaultlang , 'lang_id' , 0 , 0 , 0 , 0 , 0 , $morecss );
}
else
{
$out .= ' ' ;
}
// Button
$genbutton = '<input class="button buttongen" id="' . $forname . '_generatebutton" name="' . $forname . '_generatebutton"' ;
$genbutton .= ' type="submit" value="' . $buttonlabel . '"' ;
if ( ! $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist )) $genbutton .= ' disabled' ;
$genbutton .= '>' ;
if ( $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist ) && empty ( $conf -> dol_no_mouse_hover ) && $modulepart != 'unpaid' )
{
$langs -> load ( " errors " );
$genbutton .= ' ' . img_warning ( $langs -> transnoentitiesnoconv ( " WarningNoDocumentModelActivated " ));
}
if ( ! $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist ) && empty ( $conf -> dol_no_mouse_hover ) && $modulepart != 'unpaid' ) $genbutton = '' ;
if ( empty ( $modellist ) && ! $showempty && $modulepart != 'unpaid' ) $genbutton = '' ;
$out .= $genbutton ;
$out .= '</th>' ;
if ( ! empty ( $hookmanager -> hooks [ 'formfile' ]))
{
foreach ( $hookmanager -> hooks [ 'formfile' ] as $module )
{
if ( method_exists ( $module , 'formBuilddocLineOptions' )) $out .= '<th></th>' ;
}
}
$out .= '</tr>' ;
// Execute hooks
$parameters = array ( 'socid' => ( isset ( $GLOBALS [ 'socid' ]) ? $GLOBALS [ 'socid' ] : '' ), 'id' => ( isset ( $GLOBALS [ 'id' ]) ? $GLOBALS [ 'id' ] : '' ), 'modulepart' => $modulepart );
if ( is_object ( $hookmanager ))
{
$reshook = $hookmanager -> executeHooks ( 'formBuilddocOptions' , $parameters , $GLOBALS [ 'object' ]);
$out .= $hookmanager -> resPrint ;
}
}
// Get list of files
if ( ! empty ( $filedir ))
{
$link_list = array ();
if ( is_object ( $object ))
{
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php' ;
$link = new Link ( $this -> db );
$sortfield = $sortorder = null ;
$res = $link -> fetchAll ( $link_list , $object -> element , $object -> id , $sortfield , $sortorder );
}
$out .= '<!-- html.formfile::showdocuments -->' . " \n " ;
// Show title of array if not already shown
2018-03-02 11:57:39 +01:00
if (( ! empty ( $file_list ) || ! empty ( $link_list ) || preg_match ( '/^massfilesarea/' , $modulepart ))
&& ! $headershown )
2017-10-16 08:47:05 +02:00
{
$headershown = 1 ;
$out .= '<div class="titre">' . $titletoshow . '</div>' . " \n " ;
$out .= '<div class="div-table-responsive-no-min">' ;
$out .= '<table class="noborder" summary="listofdocumentstable" id="' . $modulepart . '_table" width="100%">' . " \n " ;
}
// Loop on each file found
2012-09-18 18:00:05 +02:00
if ( is_array ( $file_list ))
{
foreach ( $file_list as $file )
{
// Define relative path for download link (depends on module)
2015-05-18 23:04:49 +02:00
$relativepath = $file [ " name " ]; // Cas general
2017-10-16 08:47:05 +02:00
if ( $modulesubdir ) $relativepath = $modulesubdir . " / " . $file [ " name " ]; // Cas propal, facture...
2015-05-18 23:04:49 +02:00
if ( $modulepart == 'export' ) $relativepath = $file [ " name " ]; // Other case
2013-07-10 15:45:16 +02:00
2017-04-03 16:59:22 +02:00
$out .= '<tr class="oddeven">' ;
2012-09-18 18:00:05 +02:00
2014-06-05 23:30:20 +02:00
$documenturl = DOL_URL_ROOT . '/document.php' ;
2017-06-10 13:44:20 +02:00
if ( isset ( $conf -> global -> DOL_URL_ROOT_DOCUMENT_PHP )) $documenturl = $conf -> global -> DOL_URL_ROOT_DOCUMENT_PHP ; // To use another wrapper
2012-09-18 18:00:05 +02:00
// Show file name with link to download
2018-02-16 12:11:39 +01:00
$out .= '<td class="minwidth200">' ;
2017-11-10 20:20:59 +01:00
$out .= '<a class="documentdownload paddingright" href="' . $documenturl . '?modulepart=' . $modulepart . '&file=' . urlencode ( $relativepath ) . ( $param ? '&' . $param : '' ) . '"' ;
2012-09-18 18:00:05 +02:00
$mime = dol_mimetype ( $relativepath , '' , 0 );
if ( preg_match ( '/text/' , $mime )) $out .= ' target="_blank"' ;
2013-04-20 20:30:18 +02:00
$out .= ' target="_blank">' ;
2017-11-10 20:20:59 +01:00
$out .= img_mime ( $file [ " name " ], $langs -> trans ( " File " ) . ': ' . $file [ " name " ]);
2018-02-16 12:11:39 +01:00
$out .= dol_trunc ( $file [ " name " ], 150 );
2012-09-18 18:00:05 +02:00
$out .= '</a>' . " \n " ;
2017-11-10 20:20:59 +01:00
$out .= $this -> showPreview ( $file , $modulepart , $relativepath , 0 , $param );
2012-09-18 18:00:05 +02:00
$out .= '</td>' ;
// Show file size
$size = ( ! empty ( $file [ 'size' ]) ? $file [ 'size' ] : dol_filesize ( $filedir . " / " . $file [ " name " ]));
2018-04-12 15:10:37 +02:00
$out .= '<td align="right" class="nowrap">' . dol_print_size ( $size , 1 , 1 ) . '</td>' ;
2012-09-18 18:00:05 +02:00
// Show file date
$date = ( ! empty ( $file [ 'date' ]) ? $file [ 'date' ] : dol_filemtime ( $filedir . " / " . $file [ " name " ]));
2013-07-26 14:49:46 +02:00
$out .= '<td align="right" class="nowrap">' . dol_print_date ( $date , 'dayhour' , 'tzuser' ) . '</td>' ;
2012-09-18 18:00:05 +02:00
2013-07-12 15:10:32 +02:00
if ( $delallowed || $printer || $morepicto )
2012-09-18 18:00:05 +02:00
{
2018-03-01 11:51:25 +01:00
$out .= '<td class="right nowraponall">' ;
2013-07-12 15:10:32 +02:00
if ( $delallowed )
{
2018-08-19 03:00:11 +02:00
$tmpurlsource = preg_replace ( '/#[a-zA-Z0-9_]*$/' , '' , $urlsource );
$out .= '<a href="' . $tmpurlsource . ( strpos ( $tmpurlsource , '?' ) ? '&' : '?' ) . 'action=remove_file&file=' . urlencode ( $relativepath );
2014-12-08 20:33:26 +01:00
$out .= ( $param ? '&' . $param : '' );
2013-07-12 15:10:32 +02:00
//$out.= '&modulepart='.$modulepart; // TODO obsolete ?
//$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
2018-03-14 20:08:44 +01:00
$out .= '">' . img_picto ( $langs -> trans ( " Delete " ), 'delete' ) . '</a>' ;
2013-07-12 15:10:32 +02:00
}
if ( $printer )
{
//$out.= '<td align="right">';
2017-11-10 20:20:59 +01:00
$out .= '<a class="paddingleft" href="' . $urlsource . ( strpos ( $urlsource , '?' ) ? '&' : '?' ) . 'action=print_file&printer=' . $modulepart . '&file=' . urlencode ( $relativepath );
2017-10-16 08:47:05 +02:00
$out .= ( $param ? '&' . $param : '' );
$out .= '">' . img_picto ( $langs -> trans ( " PrintFile " , $relativepath ), 'printer.png' ) . '</a>' ;
2013-07-12 15:10:32 +02:00
}
if ( $morepicto )
{
2013-07-16 17:50:12 +02:00
$morepicto = preg_replace ( '/__FILENAMEURLENCODED__/' , urlencode ( $relativepath ), $morepicto );
2017-10-16 08:47:05 +02:00
$out .= $morepicto ;
}
$out .= '</td>' ;
}
if ( is_object ( $hookmanager ))
{
$parameters = array ( 'socid' => ( isset ( $GLOBALS [ 'socid' ]) ? $GLOBALS [ 'socid' ] : '' ), 'id' => ( isset ( $GLOBALS [ 'id' ]) ? $GLOBALS [ 'id' ] : '' ), 'modulepart' => $modulepart , 'relativepath' => $relativepath );
$res = $hookmanager -> executeHooks ( 'formBuilddocLineOptions' , $parameters , $file );
if ( empty ( $res ))
{
2018-03-14 17:12:32 +01:00
$out .= $hookmanager -> resPrint ; // Complete line
2017-10-16 08:47:05 +02:00
$out .= '</tr>' ;
2013-07-12 15:10:32 +02:00
}
2017-10-16 08:47:05 +02:00
else $out = $hookmanager -> resPrint ; // Replace line
}
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
2017-10-16 08:47:05 +02:00
if ( is_array ( $link_list ))
{
$colspan = 2 ;
foreach ( $link_list as $file )
{
$out .= '<tr class="oddeven">' ;
$out .= '<td colspan="' . $colspan . '" class="maxwidhtonsmartphone">' ;
$out .= '<a data-ajax="false" href="' . $link -> url . '" target="_blank">' ;
$out .= $file -> label ;
$out .= '</a>' ;
$out .= '</td>' ;
$out .= '<td align="right">' ;
$out .= dol_print_date ( $file -> datea , 'dayhour' );
$out .= '</td>' ;
if ( $delallowed || $printer || $morepicto ) $out .= '<td></td>' ;
$out .= '</tr>' . " \n " ;
}
$this -> numoffiles ++ ;
}
2017-06-10 13:44:20 +02:00
2016-09-12 18:37:40 +02:00
if ( count ( $file_list ) == 0 && count ( $link_list ) == 0 && $headershown )
2017-10-16 08:47:05 +02:00
{
2018-03-14 17:12:32 +01:00
$out .= '<tr><td colspan="' . ( 3 + ( $addcolumforpicto ? 1 : 0 )) . '" class="opacitymedium">' . $langs -> trans ( " None " ) . '</td></tr>' . " \n " ;
2017-10-16 08:47:05 +02:00
}
}
if ( $headershown )
{
// Affiche pied du tableau
$out .= " </table> \n " ;
$out .= " </div> \n " ;
if ( $genallowed )
{
if ( empty ( $noform )) $out .= '</form>' . " \n " ;
}
}
$out .= '<!-- End show_document -->' . " \n " ;
//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>' ;
*
* @ 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$' )
* @ return string Output string with HTML link of documents ( might be empty string ) . This also fill the array -> infofiles
*/
function getDocumentsLink ( $modulepart , $modulesubdir , $filedir , $filter = '' )
{
global $conf , $langs ;
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
$out = '' ;
$this -> infofiles = array ( 'nboffiles' => 0 , 'extensions' => array (), 'files' => array ());
2018-02-26 11:00:49 +01:00
// Get object entity
2018-03-02 17:48:58 +01:00
if ( empty ( $conf -> multicompany -> enabled ))
{
$entity = $conf -> entity ;
}
else
{
2018-04-13 17:54:27 +02:00
preg_match ( '/\/([0-9]+)\/[^\/]+\/' . preg_quote ( $modulesubdir , '/' ) . '$/' , $filedir , $regs );
2018-03-02 17:48:58 +01:00
$entity = (( ! empty ( $regs [ 1 ]) && $regs [ 1 ] > 1 ) ? $regs [ 1 ] : $conf -> entity );
}
2018-03-14 17:12:32 +01:00
2018-04-07 13:04:52 +02:00
// Get list of files starting with name of ref (but not followed by "-" to discard uploaded files and get only generated files)
2018-04-07 13:23:26 +02:00
// @TODO Why not showing by default all files by just removing the '[^\-]+' at end of regex ?
if ( ! empty ( $conf -> global -> MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP ))
{
$filterforfilesearch = preg_quote ( basename ( $modulesubdir ), '/' );
}
else
{
$filterforfilesearch = preg_quote ( basename ( $modulesubdir ), '/' ) . '[^\-]+' ;
}
2018-04-07 13:04:52 +02: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
2016-08-05 12:18:51 +02:00
$out .= '<!-- html.formfile::getDocumentsLink -->' . " \n " ;
2017-10-16 08:47:05 +02:00
if ( ! empty ( $file_list ))
{
$out = ' < dl class = " dropdown inline-block " >
2017-11-10 20:20:59 +01:00
< dt >< a data - ajax = " false " href = " # " onClick = " return false; " > '.img_picto(' ', ' listlight ', ' ', 0, 0, 0, ' ', ' valignbottom ').' </ a ></ dt >
2017-02-17 12:05:24 +01:00
< dd >< div class = " multichoicedoc " style = " position:absolute;left:100px; " >< ul class = " ulselectedfields " style = " display: none; " > ' ;
2017-10-16 08:47:05 +02:00
$tmpout = '' ;
// Loop on each file found
2017-11-10 20:20:59 +01:00
$found = 0 ;
2017-10-16 08:47:05 +02:00
foreach ( $file_list as $file )
{
$i ++ ;
if ( $filter && ! preg_match ( '/' . $filter . '/i' , $file [ " name " ])) continue ; // Discard this. It does not match provided filter.
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)
$relativepath = $file [ " name " ]; // Cas general
if ( $modulesubdir ) $relativepath = $modulesubdir . " / " . $file [ " name " ]; // Cas propal, facture...
// Autre cas
if ( $modulepart == 'donation' ) {
$relativepath = get_exdir ( $modulesubdir , 2 , 0 , 0 , null , 'donation' ) . $file [ " name " ];
}
if ( $modulepart == 'export' ) {
$relativepath = $file [ " name " ];
}
$this -> infofiles [ 'nboffiles' ] ++ ;
$this -> infofiles [ 'files' ][] = $file [ 'fullname' ];
$ext = pathinfo ( $file [ " name " ], PATHINFO_EXTENSION );
if ( empty ( $this -> infofiles [ $ext ])) $this -> infofiles [ 'extensions' ][ $ext ] = 1 ;
else $this -> infofiles [ 'extensions' ][ $ext ] ++ ;
// Preview
if ( ! empty ( $conf -> use_javascript_ajax ) && ( $conf -> browser -> layout != 'phone' ))
{
$tmparray = getAdvancedPreviewUrl ( $modulepart , $relativepath , 1 , '&entity=' . $entity );
2017-11-10 20:20:59 +01:00
if ( $tmparray && $tmparray [ 'url' ])
{
$tmpout .= '<li><a href="' . $tmparray [ 'url' ] . '"' . ( $tmparray [ 'css' ] ? ' class="' . $tmparray [ 'css' ] . '"' : '' ) . ( $tmparray [ 'mime' ] ? ' mime="' . $tmparray [ 'mime' ] . '"' : '' ) . ( $tmparray [ 'target' ] ? ' target="' . $tmparray [ 'target' ] . '"' : '' ) . '>' ;
//$tmpout.= img_picto('','detail');
$tmpout .= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>' ;
$tmpout .= $langs -> trans ( " Preview " ) . ' ' . $ext . '</a></li>' ;
}
2017-10-16 08:47:05 +02:00
}
// Download
2018-02-26 11:00:49 +01:00
$tmpout .= '<li class="nowrap"><a class="pictopreview nowrap" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode ( $relativepath ) . '"' ;
2017-10-16 08:47:05 +02:00
$mime = dol_mimetype ( $relativepath , '' , 0 );
if ( preg_match ( '/text/' , $mime )) $tmpout .= ' target="_blank"' ;
$tmpout .= '>' ;
2017-11-10 20:20:59 +01:00
$tmpout .= img_mime ( $relativepath , $file [ " name " ]);
2017-10-16 08:47:05 +02:00
$tmpout .= $langs -> trans ( " Download " ) . ' ' . $ext ;
$tmpout .= '</a></li>' . " \n " ;
}
$out .= $tmpout ;
$out .= ' </ ul ></ div ></ dd >
2016-08-05 12:18:51 +02:00
</ dl > ' ;
2017-11-10 20:20:59 +01:00
if ( ! $found ) $out = '' ;
2017-10-16 08:47:05 +02:00
}
else
{
// TODO Add link to regenerate doc ?
//$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
}
return $out ;
}
/**
* 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 .
*
* @ param array $filearray Array of files loaded by dol_dir_list ( 'files' ) function before calling this .
* @ param Object $object Object on which document is linked to .
* @ 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 )
* @ 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 ), relative to module dir , not to MAIN_DATA_ROOT .
* @ param int $permonobject Permission on object ( so permission to delete or crop document )
2017-11-10 13:45:38 +01:00
* @ param int $useinecm Change output for use in ecm module :
* 0 : Add a previw link . Show also rename and crop file
* 1 : Add link to edit ECM entry
2017-11-10 15:29:12 +01:00
* 2 : Add rename and crop file
2017-10-16 08:47:05 +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 .
2017-11-10 13:45:38 +01:00
* @ param string $title Title before list . Use 'none' to disable title .
2017-10-16 08:47:05 +02:00
* @ param string $url Full url to use for click links ( '' = autodetect )
2013-11-01 17:36:22 +01:00
* @ param int $showrelpart 0 = Show only filename ( default ), 1 = Show first level 1 dir
2016-12-13 00:40:12 +01:00
* @ param int $permtoeditline Permission to edit document line ( You must provide a value , - 1 is deprecated and must not be used any more )
2018-02-13 13:55:36 +01: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 .
2017-10-16 08:47:05 +02:00
* @ param string $sortfield Sort field ( 'name' , 'size' , 'position' , ... )
* @ param string $sortorder Sort order ( 'ASC' or 'DESC' )
* @ param int $disablemove 1 = Disable move button , 0 = Position move is possible .
* @ param int $addfilterfields Add line with filters
* @ return int < 0 if KO , nb of files shown if OK
2018-01-12 16:28:10 +01:00
* @ see list_of_autoecmfiles
2017-10-16 08:47:05 +02:00
*/
2017-08-04 13:07:15 +02:00
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 )
2012-09-11 17:01:54 +02:00
{
2013-01-25 19:12:54 +01:00
global $user , $conf , $langs , $hookmanager ;
2012-09-11 17:01:54 +02:00
global $sortfield , $sortorder , $maxheightmini ;
2018-02-13 13:55:36 +01:00
global $dolibarr_main_url_root ;
2018-04-15 17:58:13 +02:00
global $form ;
2012-09-11 17:01:54 +02:00
2018-04-16 19:25:27 +02:00
$disablecrop = 1 ;
2018-06-04 21:49:29 +02:00
if ( in_array ( $modulepart , array ( 'societe' , 'product' , 'produit' , 'service' , 'expensereport' , 'holiday' , 'member' , 'project' , 'ticket' , 'user' ))) $disablecrop = 0 ;
2018-04-16 19:25:27 +02:00
2016-12-13 00:15:21 +01:00
// Define relative path used to store the file
if ( empty ( $relativepath ))
{
2017-10-16 08:47:05 +02:00
$relativepath = ( ! empty ( $object -> ref ) ? dol_sanitizeFileName ( $object -> ref ) : '' ) . '/' ;
if ( $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 ( $object -> element == 'project_task' ) $relativepath = 'Call_not_supported_._Call_function_using_a_defined_relative_path_.' ;
2016-12-13 00:15:21 +01:00
}
2017-12-08 13:13:53 +01:00
// For backward compatiblity, we detect file stored into an old path
2017-12-07 18:44:33 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_OLD_PATH_FOR_PHOTO ) && $filearray [ 0 ][ 'level1name' ] == 'photos' )
2016-12-13 00:15:21 +01:00
{
2017-12-07 18:44:33 +01:00
$relativepath = preg_replace ( '/^.*\/produit\//' , '' , $filearray [ 0 ][ 'path' ]) . '/' ;
2016-12-13 00:15:21 +01:00
}
// Defined relative dir to DOL_DATA_ROOT
2016-12-13 00:40:12 +01:00
$relativedir = '' ;
if ( $upload_dir )
{
2017-10-16 08:47:05 +02:00
$relativedir = preg_replace ( '/^' . preg_quote ( DOL_DATA_ROOT , '/' ) . '/' , '' , $upload_dir );
$relativedir = preg_replace ( '/^[\\/]/' , '' , $relativedir );
2016-12-13 00:40:12 +01:00
}
2012-09-11 17:01:54 +02:00
$hookmanager -> initHooks ( array ( 'formfile' ));
$parameters = array (
'filearray' => $filearray ,
'modulepart' => $modulepart ,
'param' => $param ,
'forcedownload' => $forcedownload ,
2016-12-13 00:15:21 +01:00
'relativepath' => $relativepath , // relative filename to module dir
2016-12-13 00:40:12 +01:00
'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
);
2012-09-11 17:05:12 +02:00
$reshook = $hookmanager -> executeHooks ( 'showFilesList' , $parameters , $object );
2012-09-11 17:01:54 +02:00
2012-09-11 17:09:43 +02:00
if ( isset ( $reshook ) && $reshook != '' ) // null or '' for bypass
2012-09-11 17:01:54 +02:00
{
return $reshook ;
}
else
{
2018-04-21 11:24:45 +02:00
if ( ! is_object ( $form ))
{
include_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ; // The compoent may be included into ajax page that does not include the Form class
$form = new Form ( $this -> db );
}
2018-04-15 17:58:13 +02:00
2017-11-10 13:45:38 +01:00
if ( ! preg_match ( '/&id=/' , $param ) && isset ( $object -> id )) $param .= '&id=' . $object -> id ;
$relativepathwihtoutslashend = preg_replace ( '/\/$/' , '' , $relativepath );
if ( $relativepathwihtoutslashend ) $param .= '&file=' . urlencode ( $relativepathwihtoutslashend );
2012-09-12 10:46:35 +02:00
2016-09-07 01:54:16 +02:00
if ( $permtoeditline < 0 ) // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
{
2017-10-16 08:47:05 +02:00
$permtoeditline = 0 ;
if ( in_array ( $modulepart , array ( 'product' , 'produit' , 'service' )))
{
if ( $user -> rights -> produit -> creer && $object -> type == Product :: TYPE_PRODUCT ) $permtoeditline = 1 ;
if ( $user -> rights -> service -> creer && $object -> type == Product :: TYPE_SERVICE ) $permtoeditline = 1 ;
}
2016-09-07 01:54:16 +02:00
}
2017-06-10 13:44:20 +02:00
if ( empty ( $conf -> global -> MAIN_UPLOAD_DOC ))
2016-09-07 01:54:16 +02:00
{
2017-10-16 08:47:05 +02:00
$permtoeditline = 0 ;
$permonobject = 0 ;
2016-09-07 01:54:16 +02:00
}
2012-09-11 17:01:54 +02:00
// Show list of existing files
2017-11-10 13:45:38 +01:00
if ( empty ( $useinecm ) && $title != 'none' ) print load_fiche_titre ( $title ? $title : $langs -> trans ( " AttachedFiles " ));
2012-09-11 17:01:54 +02:00
if ( empty ( $url )) $url = $_SERVER [ " PHP_SELF " ];
2017-06-10 13:44:20 +02:00
2016-03-04 11:25:54 +01:00
print '<!-- html.formfile::list_of_documents -->' . " \n " ;
2017-05-16 13:27:32 +02:00
if ( GETPOST ( 'action' , 'aZ09' ) == 'editfile' && $permtoeditline )
2016-09-07 01:54:16 +02:00
{
2017-10-16 08:47:05 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?' . $param . '" method="POST">' ;
print '<input type="hidden" name="action" value="renamefile">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
print '<input type="hidden" name="modulepart" value="' . $modulepart . '">' ;
2016-09-07 01:54:16 +02:00
}
2017-06-20 12:31:08 +02:00
2017-04-14 13:21:02 +02:00
print '<div class="div-table-responsive-no-min">' ;
2017-03-23 21:24:57 +01:00
print '<table width="100%" id="tablelines" class="' . ( $useinecm ? 'liste noborder' : 'liste' ) . '">' . " \n " ;
2017-06-10 13:44:20 +02:00
2017-08-04 13:07:15 +02:00
if ( ! empty ( $addfilterfields ))
{
print '<tr class="liste_titre nodrag nodrop">' ;
print '<td><input type="search_doc_ref" value="' . dol_escape_htmltag ( GETPOST ( 'search_doc_ref' , 'alpha' )) . '"></td>' ;
print '<td></td>' ;
print '<td></td>' ;
if ( empty ( $useinecm )) print '<td></td>' ;
print '<td></td>' ;
2018-02-13 13:55:36 +01:00
print '<td></td>' ;
2017-08-04 13:07:15 +02:00
if ( ! $disablemove ) print '<td></td>' ;
print " </tr> \n " ;
}
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;
2017-08-01 18:32:21 +02:00
print_liste_field_titre ( 'Documents2' , $url , " name " , " " , $param , 'align="left"' , $sortfield , $sortorder );
print_liste_field_titre ( 'Size' , $url , " size " , " " , $param , 'align="right"' , $sortfield , $sortorder );
print_liste_field_titre ( 'Date' , $url , " date " , " " , $param , 'align="center"' , $sortfield , $sortorder );
2018-02-13 13:55:36 +01:00
if ( empty ( $useinecm )) print_liste_field_titre ( '' , $url , " " , " " , $param , 'align="center"' ); // Preview
print_liste_field_titre ( '' );
2015-06-26 06:23:29 +02:00
print_liste_field_titre ( '' );
2016-12-20 19:42:25 +01:00
if ( ! $disablemove ) print_liste_field_titre ( '' );
2015-06-26 06:23:29 +02:00
print " </tr> \n " ;
2012-09-11 17:01:54 +02:00
2016-12-20 19:42:25 +01:00
// Get list of files stored into database for same relative directory
2016-12-13 00:40:12 +01:00
if ( $relativedir )
2016-12-13 00:15:21 +01:00
{
2017-08-18 16:10:21 +02:00
completeFileArrayWithDatabaseInfo ( $filearray , $relativedir );
2017-06-10 13:44:20 +02:00
2017-11-10 18:14:29 +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)
2017-10-16 08:47:05 +02:00
{
2017-11-10 18:14:29 +01:00
//var_dump($sortfield);
2017-10-16 08:47:05 +02:00
$filearray = dol_sort_array ( $filearray , $sortfield , $sortorder );
}
2016-12-13 00:15:21 +01:00
}
2017-06-10 13:44:20 +02:00
2016-12-13 00:15:21 +01:00
$nboffiles = count ( $filearray );
if ( $nboffiles > 0 ) include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php' ;
2017-06-10 13:44:20 +02:00
2017-11-19 20:44:57 +01:00
$i = 0 ; $nboflines = 0 ; $lastrowid = 0 ;
2012-09-11 17:01:54 +02:00
foreach ( $filearray as $key => $file ) // filearray must be only files here
{
if ( $file [ 'name' ] != '.'
&& $file [ 'name' ] != '..'
&& ! preg_match ( '/\.meta$/i' , $file [ 'name' ]))
{
2016-12-20 19:42:25 +01:00
if ( $filearray [ $key ][ 'rowid' ] > 0 ) $lastrowid = $filearray [ $key ][ 'rowid' ];
2017-11-10 20:20:59 +01:00
$filepath = $relativepath . $file [ 'name' ];
2017-06-10 13:44:20 +02:00
2016-12-20 19:42:25 +01:00
$editline = 0 ;
$nboflines ++ ;
2017-10-16 08:47:05 +02:00
print '<!-- Line list_of_documents ' . $key . ' relativepath = ' . $relativepath . ' -->' . " \n " ;
// Do we have entry into database ?
print '<!-- In database: position=' . $filearray [ $key ][ 'position' ] . ' -->' . " \n " ;
2017-11-19 20:44:57 +01:00
print '<tr id="row-' . ( $filearray [ $key ][ 'rowid' ] > 0 ? $filearray [ $key ][ 'rowid' ] : '-AFTER' . $lastrowid . 'POS' . ( $i + 1 )) . '">' ;
2017-11-18 15:41:30 +01:00
// File name
2018-02-16 12:11:39 +01:00
print '<td class="minwith200">' ;
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
2017-11-10 20:20:59 +01:00
print '<a class="paddingright" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart ;
2012-09-11 17:01:54 +02: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 '">' ;
2017-11-10 20:20:59 +01:00
print img_mime ( $file [ 'name' ], $file [ 'name' ] . ' (' . dol_print_size ( $file [ 'size' ], 0 , 0 ) . ')' , 'inline-block valignbottom paddingright' );
2013-11-13 20:36:07 +01:00
if ( $showrelpart == 1 ) print $relativepath ;
2016-03-04 11:25:54 +01:00
//print dol_trunc($file['name'],$maxlength,'middle');
2017-11-18 15:41:30 +01:00
if ( GETPOST ( 'action' , 'aZ09' ) == 'editfile' && $file [ 'name' ] == basename ( GETPOST ( 'urlfile' , 'alpha' )))
2016-09-07 01:54:16 +02:00
{
2017-10-16 08:47:05 +02:00
print '</a>' ;
2017-11-18 15:41:30 +01:00
$section_dir = dirname ( GETPOST ( 'urlfile' , 'alpha' ));
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' ]) . '">' ;
$editline = 1 ;
2016-09-07 01:54:16 +02:00
}
else
{
2018-02-16 12:11:39 +01:00
print dol_trunc ( $file [ 'name' ], 200 );
2017-10-16 08:47:05 +02:00
print '</a>' ;
2016-09-07 01:54:16 +02:00
}
2017-11-18 15:41:30 +01:00
// Preview link
2017-11-10 20:20:59 +01:00
if ( ! $editline ) print $this -> showPreview ( $file , $modulepart , $filepath );
2017-11-19 20:44:57 +01:00
// Public share link
2018-01-12 16:28:10 +01:00
//if (! $editline && ! empty($filearray[$key]['hashp'])) print pictowithlinktodirectdownload;
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
2018-04-15 17:58:13 +02:00
$sizetoshow = dol_print_size ( $file [ 'size' ], 1 , 1 );
$sizetoshowbytes = dol_print_size ( $file [ 'size' ], 0 , 1 );
print '<td align="right" width="80px">' ;
if ( $sizetoshow == $sizetoshowbytes ) print $sizetoshow ;
else {
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
2018-06-26 11:25:28 +02:00
print '<td align="center" width="140px">' . dol_print_date ( $file [ 'date' ], " dayhour " , " tzuser " ) . '</td>' ; // 140px = width for date with PM format
2017-06-10 13:44:20 +02:00
2012-09-11 17:01:54 +02:00
// Preview
if ( empty ( $useinecm ))
{
2014-07-13 19:51:44 +02:00
$fileinfo = pathinfo ( $file [ 'name' ]);
2012-09-11 17:01:54 +02:00
print '<td align="center">' ;
2015-06-19 00:52:58 +02:00
if ( image_format_supported ( $file [ 'name' ]) > 0 )
{
2017-10-16 08:47:05 +02:00
$minifile = getImageFileNameForSize ( $file [ 'name' ], '_mini' ); // For new thumbs using same ext (in lower case howerver) than original
if ( ! dol_is_file ( $file [ 'path' ] . '/' . $minifile )) $minifile = getImageFileNameForSize ( $file [ 'name' ], '_mini' , '.png' ); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
//print $file['path'].'/'.$minifile.'<br>';
2017-01-16 00:48:37 +01:00
2017-10-16 08:47:05 +02:00
$urlforhref = getAdvancedPreviewUrl ( $modulepart , $relativepath . $fileinfo [ 'filename' ] . '.' . strtolower ( $fileinfo [ 'extension' ]), 0 , '&entity=' . ( ! empty ( $object -> entity ) ? $object -> entity : $conf -> entity ));
if ( empty ( $urlforhref )) $urlforhref = DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . ( ! empty ( $object -> entity ) ? $object -> entity : $conf -> entity ) . '&file=' . urlencode ( $relativepath . $fileinfo [ 'filename' ] . '.' . strtolower ( $fileinfo [ 'extension' ]));
print '<a href="' . $urlforhref . '" class="aphoto" target="_blank">' ;
2017-01-15 12:09:26 +01:00
print '<img border="0" height="' . $maxheightmini . '" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . ( ! empty ( $object -> entity ) ? $object -> entity : $conf -> entity ) . '&file=' . urlencode ( $relativepath . $minifile ) . '" title="">' ;
2015-06-19 00:52:58 +02:00
print '</a>' ;
}
2012-09-11 17:01:54 +02:00
else print ' ' ;
print '</td>' ;
}
2018-02-13 13:55:36 +01:00
// Hash of file (only if we are in a mode where a scan of dir were done and we have id of file in ECM table)
print '<td align="center">' ;
if ( $relativedir && $filearray [ $key ][ 'rowid' ] > 0 )
{
if ( $editline )
{
print $langs -> trans ( " FileSharedViaALink " ) . ' ' ;
print '<input class="inline-block" type="checkbox" name="shareenabled"' . ( $file [ 'share' ] ? ' checked="checked"' : '' ) . ' /> ' ;
}
else
{
if ( $file [ 'share' ])
{
// 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 : '' );
//if (! empty($object->ref)) $fulllink.='&hashn='.$object->ref; // Hash of file path
//elseif (! empty($object->label)) $fulllink.='&hashc='.$object->label; // Hash of file content
print img_picto ( $langs -> trans ( " FileSharedViaALink " ), 'object_globe.png' ) . ' ' ;
print '<input type="text" class="quatrevingtpercent" id="downloadlink" name="downloadexternallink" value="' . dol_escape_htmltag ( $fulllink ) . '">' ;
//print ' <a href="'.$fulllink.'">'.$langs->trans("Download").'</a>'; // No target here
}
else
{
//print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
}
}
}
print '</td>' ;
// Actions buttons
2016-09-07 01:54:16 +02:00
if ( ! $editline )
2015-06-19 00:52:58 +02:00
{
2017-10-16 08:47:05 +02:00
// Delete or view link
// ($param must start with &)
2017-11-10 18:27:03 +01:00
print '<td class="valignmiddle right actionbuttons"><!-- action on files -->' ;
2017-11-10 15:29:12 +01:00
if ( $useinecm == 1 )
2017-10-16 08:47:05 +02:00
{
2018-06-26 11:25:28 +02:00
print '<a href="' . DOL_URL_ROOT . '/ecm/file_card.php?urlfile=' . urlencode ( $file [ 'name' ]) . $param . '" class="editfilelink" rel="' . urlencode ( $file [ 'name' ]) . '">' . img_edit ( 'default' , 0 , 'class="paddingrightonly"' ) . '</a>' ;
2017-10-16 08:47:05 +02:00
}
2017-11-10 15:29:12 +01:00
if ( ! $useinecm || $useinecm == 2 )
2017-10-16 08:47:05 +02:00
{
$newmodulepart = $modulepart ;
if ( in_array ( $modulepart , array ( 'product' , 'produit' , 'service' ))) $newmodulepart = 'produit|service' ;
if ( ! $disablecrop && image_format_supported ( $file [ 'name' ]) > 0 )
{
if ( $permtoeditline )
{
// Link to resize
2018-03-19 11:49:05 +01:00
print '<a href="' . DOL_URL_ROOT . '/core/photos_resize.php?modulepart=' . urlencode ( $newmodulepart ) . '&id=' . $object -> id . '&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
}
}
if ( $permtoeditline )
{
2017-11-10 15:29:12 +01:00
print '<a href="' . (( $useinecm == 1 ) ? '#' : ( $url . '?action=editfile&urlfile=' . urlencode ( $filepath ) . $param )) . '" class="editfilelink" rel="' . $filepath . '">' . img_edit ( 'default' , 0 , 'class="paddingrightonly"' ) . '</a>' ;
2017-10-16 08:47:05 +02:00
}
}
if ( $permonobject )
{
/*
2016-09-07 01:54:16 +02:00
if ( $file [ 'level1name' ] <> $object -> id )
$filepath = $file [ 'level1name' ] . '/' . $file [ 'name' ];
else
$filepath = $file [ 'name' ];
*/
2017-10-16 08:47:05 +02:00
$useajax = 1 ;
if ( ! empty ( $conf -> dol_use_jmobile )) $useajax = 0 ;
if ( empty ( $conf -> use_javascript_ajax )) $useajax = 0 ;
if ( ! empty ( $conf -> global -> MAIN_ECM_DISABLE_JS )) $useajax = 0 ;
2018-08-19 03:00:11 +02:00
print '<a href="' . (( $useinecm && $useajax ) ? '#' : ( $url . '?action=delete&urlfile=' . urlencode ( $filepath ) . $param )) . '" class="deletefilelink" rel="' . $filepath . '">' . img_delete () . '</a>' ;
2017-10-16 08:47:05 +02:00
}
print " </td> " ;
if ( empty ( $disablemove ))
{
if ( $nboffiles > 1 && empty ( $conf -> browser -> phone )) {
print '<td align="center" class="linecolmove tdlineupdown">' ;
if ( $i > 0 ) {
print '<a class="lineupdown" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $this -> id . '&action=up&rowid=' . $line -> id . '">' . img_up ( 'default' , 0 , 'imgupforline' ) . '</a>' ;
}
if ( $i < $nboffiles - 1 ) {
print '<a class="lineupdown" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $this -> id . '&action=down&rowid=' . $line -> id . '">' . img_down ( 'default' , 0 , 'imgdownforline' ) . '</a>' ;
}
print '</td>' ;
}
else {
print '<td align="center"' . (( empty ( $conf -> browser -> phone ) && empty ( $disablemove )) ? ' class="linecolmove tdlineupdown"' : ' class="linecolmove"' ) . '>' ;
print '</td>' ;
}
2016-12-20 19:42:25 +01:00
}
2015-06-19 00:52:58 +02:00
}
2016-09-07 01:54:16 +02:00
else
2013-10-20 20:58:38 +02:00
{
2017-10-16 08:47:05 +02:00
print '<td class="right">' ;
2018-02-13 13:55:36 +01:00
print '<input type="hidden" name="ecmfileid" value="' . $filearray [ $key ][ 'rowid' ] . '">' ;
2017-10-16 08:47:05 +02:00
print '<input type="submit" class="button" name="renamefilesave" value="' . dol_escape_htmltag ( $langs -> trans ( " Save " )) . '">' ;
print '<input type="submit" class="button" name="cancel" value="' . dol_escape_htmltag ( $langs -> trans ( " Cancel " )) . '">' ;
print '</td>' ;
if ( empty ( $disablemove )) 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
}
}
if ( $nboffiles == 0 )
{
2018-02-13 13:55:36 +01:00
$colspan = ( empty ( $useinecm ) ? '6' : '6' );
if ( empty ( $disablemove )) $colspan ++ ; // 6 columns or 7
print '<tr class="oddeven"><td colspan="' . $colspan . '" class="opacitymedium">' ;
2012-09-11 17:01:54 +02:00
if ( empty ( $textifempty )) print $langs -> trans ( " NoFileFound " );
else print $textifempty ;
print '</td></tr>' ;
}
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 )) {
2016-12-20 19:42:25 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && $permtoeditline ) {
2017-10-16 08:47:05 +02:00
$table_element_line = 'ecm_files' ;
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' );
2017-05-16 13:27:32 +02:00
if ( GETPOST ( 'action' , 'aZ09' ) == 'editfile' && $permtoeditline )
2016-09-07 01:54:16 +02:00
{
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
2017-10-16 08:47:05 +02:00
/**
* Show list of documents in a directory
*
* @ param string $upload_dir Directory that was scanned
* @ param array $filearray Array of files loaded by dol_dir_list function before calling this function
* @ param string $modulepart Value for modulepart used by download wrapper
* @ 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 )
* @ param int $permtodelete Permission to delete
* @ param int $useinecm Change output for use in ecm module
* @ param int $textifempty Text to show if filearray is empty
* @ 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
* @ return int < 0 if KO , nb of files shown if OK
2018-01-12 16:28:10 +01:00
* @ see list_of_documents
2017-10-16 08:47:05 +02:00
*/
2017-11-19 20:44:57 +01:00
function list_of_autoecmfiles ( $upload_dir , $filearray , $modulepart , $param , $forcedownload = 0 , $relativepath = '' , $permtodelete = 1 , $useinecm = 0 , $textifempty = '' , $maxlength = 0 , $url = '' , $addfilterfields = 0 )
2017-10-16 08:47:05 +02:00
{
global $user , $conf , $langs , $form ;
global $sortfield , $sortorder ;
2017-08-04 13:07:15 +02:00
global $search_doc_ref ;
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
if ( empty ( $useinecm )) print load_fiche_titre ( $langs -> trans ( " AttachedFiles " ));
if ( empty ( $url )) $url = $_SERVER [ " PHP_SELF " ];
2017-08-04 13:07:15 +02:00
2017-10-16 08:47:05 +02:00
if ( ! empty ( $addfilterfields ))
{
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . '">' ;
print '<input type="hidden" name="module" value="' . $modulepart . '">' ;
}
2017-08-04 13:07:15 +02:00
print '<div class="div-table-responsive-no-min">' ;
2017-10-16 08:47:05 +02:00
print '<table width="100%" class="noborder">' . " \n " ;
if ( ! empty ( $addfilterfields ))
{
print '<tr class="liste_titre nodrag nodrop">' ;
print '<td></td>' ;
2018-02-13 15:47:17 +01:00
print '<td><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="' . dol_escape_htmltag ( $search_doc_ref ) . '"></td>' ;
2017-10-16 08:47:05 +02:00
print '<td></td>' ;
print '<td></td>' ;
2017-08-04 13:07:15 +02:00
// Action column
print '<td class="liste_titre" align="middle">' ;
$searchpicto = $form -> showFilterButtons ();
print $searchpicto ;
print '</td>' ;
2017-10-16 08:47:05 +02:00
print " </tr> \n " ;
}
print '<tr class="liste_titre">' ;
$sortref = " fullname " ;
if ( $modulepart == 'invoice_supplier' ) $sortref = 'level1name' ;
print_liste_field_titre ( " Ref " , $url , $sortref , " " , $param , 'align="left"' , $sortfield , $sortorder );
print_liste_field_titre ( " Documents2 " , $url , " name " , " " , $param , 'align="left"' , $sortfield , $sortorder );
print_liste_field_titre ( " Size " , $url , " size " , " " , $param , 'align="right"' , $sortfield , $sortorder );
print_liste_field_titre ( " Date " , $url , " date " , " " , $param , 'align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( '' , '' , '' );
print '</tr>' . " \n " ;
// To show ref or specific information according to view to show (defined by $module)
if ( $modulepart == 'company' )
{
include_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
$object_instance = new Societe ( $this -> db );
}
else if ( $modulepart == 'invoice' )
{
include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
$object_instance = new Facture ( $this -> db );
}
else if ( $modulepart == 'invoice_supplier' )
{
include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php' ;
$object_instance = new FactureFournisseur ( $this -> db );
}
else if ( $modulepart == 'propal' )
{
include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php' ;
$object_instance = new Propal ( $this -> db );
}
else if ( $modulepart == 'supplier_proposal' )
{
include_once DOL_DOCUMENT_ROOT . '/supplier_proposal/class/supplier_proposal.class.php' ;
$object_instance = new SupplierProposal ( $this -> db );
}
else if ( $modulepart == 'order' )
{
include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
$object_instance = new Commande ( $this -> db );
}
else if ( $modulepart == 'order_supplier' )
{
include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php' ;
$object_instance = new CommandeFournisseur ( $this -> db );
}
else if ( $modulepart == 'contract' )
{
include_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php' ;
$object_instance = new Contrat ( $this -> db );
}
else if ( $modulepart == 'product' )
{
include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
$object_instance = new Product ( $this -> db );
}
else if ( $modulepart == 'tax' )
{
include_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php' ;
$object_instance = new ChargeSociales ( $this -> db );
}
else if ( $modulepart == 'project' )
{
include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
$object_instance = new Project ( $this -> db );
}
else if ( $modulepart == 'fichinter' )
{
include_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php' ;
$object_instance = new Fichinter ( $this -> db );
}
else if ( $modulepart == 'user' )
{
include_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
$object_instance = new User ( $this -> db );
}
else if ( $modulepart == 'expensereport' )
{
include_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php' ;
$object_instance = new ExpenseReport ( $this -> db );
}
2018-12-01 19:39:00 +01:00
else if ( $modulepart == 'holiday' )
{
include_once DOL_DOCUMENT_ROOT . '/holiday/class/holiday.class.php' ;
$object_instance = new Holiday ( $this -> db );
}
2017-10-16 08:47:05 +02:00
foreach ( $filearray as $key => $file )
{
if ( ! is_dir ( $file [ 'name' ])
&& $file [ 'name' ] != '.'
&& $file [ 'name' ] != '..'
&& $file [ 'name' ] != 'CVS'
&& ! preg_match ( '/\.meta$/i' , $file [ 'name' ]))
{
// Define relative path used to store the file
$relativefile = preg_replace ( '/' . preg_quote ( $upload_dir . '/' , '/' ) . '/' , '' , $file [ 'fullname' ]);
//var_dump($file);
$id = 0 ; $ref = '' ; $label = '' ;
// To show ref or specific information according to view to show (defined by $module)
if ( $modulepart == 'company' ) { preg_match ( '/(\d+)\/[^\/]+$/' , $relativefile , $reg ); $id = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' ); }
if ( $modulepart == 'invoice' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' ); }
if ( $modulepart == 'invoice_supplier' ) { preg_match ( '/([^\/]+)\/[^\/]+$/' , $relativefile , $reg ); $ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' ); if ( is_numeric ( $ref )) { $id = $ref ; $ref = '' ; } } // $ref may be also id with old supplier invoices
if ( $modulepart == 'propal' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' ); }
2015-11-15 18:23:42 +01:00
if ( $modulepart == 'supplier_proposal' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' ); }
2017-10-16 08:47:05 +02:00
if ( $modulepart == 'order' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' ); }
if ( $modulepart == 'order_supplier' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' ); }
if ( $modulepart == 'contract' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' ); }
if ( $modulepart == 'product' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' ); }
if ( $modulepart == 'tax' ) { preg_match ( '/(\d+)\/[^\/]+$/' , $relativefile , $reg ); $id = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' ); }
if ( $modulepart == 'project' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' );}
if ( $modulepart == 'fichinter' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' );}
if ( $modulepart == 'user' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $id = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' );}
2018-12-01 19:39:00 +01:00
if ( $modulepart == 'expensereport' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $ref = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' );}
if ( $modulepart == 'holiday' ) { preg_match ( '/(.*)\/[^\/]+$/' , $relativefile , $reg ); $id = ( isset ( $reg [ 1 ]) ? $reg [ 1 ] : '' );}
2017-10-16 08:47:05 +02:00
if ( ! $id && ! $ref ) continue ;
$found = 0 ;
if ( ! empty ( $this -> cache_objects [ $modulepart . '_' . $id . '_' . $ref ]))
{
$found = 1 ;
}
else
{
//print 'Fetch '.$id." - ".$ref.'<br>';
if ( $id ) {
$result = $object_instance -> fetch ( $id );
} else {
//fetchOneLike looks for objects with wildcards in its reference.
//It is useful for those masks who get underscores instead of their actual symbols
//fetchOneLike requires some info in the object. If it doesn't have it, then 0 is returned
//that's why we look only look fetchOneLike when fetch returns 0
if ( ! $result = $object_instance -> fetch ( '' , $ref )) {
$result = $object_instance -> fetchOneLike ( $ref );
}
}
2014-12-25 21:47:39 +01:00
2015-09-24 16:32:48 +02:00
if ( $result > 0 ) { // Save object into a cache
$found = 1 ; $this -> cache_objects [ $modulepart . '_' . $id . '_' . $ref ] = clone $object_instance ;
}
2017-10-16 08:47:05 +02:00
if ( $result == 0 ) { $found = 1 ; $this -> cache_objects [ $modulepart . '_' . $id . '_' . $ref ] = 'notfound' ; unset ( $filearray [ $key ]); }
}
if ( ! $found > 0 || ! is_object ( $this -> cache_objects [ $modulepart . '_' . $id . '_' . $ref ])) continue ; // We do not show orphelins files
print '<!-- Line list_of_autoecmfiles ' . $key . ' -->' . " \n " ;
print '<tr class="oddeven">' ;
print '<td>' ;
if ( $found > 0 && is_object ( $this -> cache_objects [ $modulepart . '_' . $id . '_' . $ref ])) print $this -> cache_objects [ $modulepart . '_' . $id . '_' . $ref ] -> getNomUrl ( 1 , 'document' );
else print $langs -> trans ( " ObjectDeleted " ,( $id ? $id : $ref ));
//$modulesubdir=dol_sanitizeFileName($ref);
$modulesubdir = dirname ( $relativefile );
//$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref);
$filedir = $file [ 'path' ];
//$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
//print $formfile->getDocumentsLink($modulepart, $filename, $filedir);
print '</td>' ;
// File
print '<td>' ;
//print "XX".$file['name']; //$file['name'] must be utf8
2017-11-10 20:20:59 +01:00
print '<a 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 ) . '">' ;
2017-11-10 20:20:59 +01:00
print img_mime ( $file [ 'name' ], $file [ 'name' ] . ' (' . dol_print_size ( $file [ 'size' ], 0 , 0 ) . ')' );
2017-10-16 08:47:05 +02:00
print dol_trunc ( $file [ 'name' ], $maxlength , 'middle' );
print '</a>' ;
2018-01-12 16:28:10 +01:00
//print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$');
print $this -> showPreview ( $file , $modulepart , $file [ 'relativename' ]);
2017-10-16 08:47:05 +02:00
print " </td> \n " ;
print '<td align="right">' . dol_print_size ( $file [ 'size' ], 1 , 1 ) . '</td>' ;
print '<td align="center">' . dol_print_date ( $file [ 'date' ], " dayhour " ) . '</td>' ;
print '<td align="right">' ;
//if (! empty($useinecm)) print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
//if ($forcedownload) print '&attachment=1';
//print '&file='.urlencode($relativefile).'">';
//print img_view().'</a> ';
//if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'§ion='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
//else print ' ';
print " </td></tr> \n " ;
}
}
if ( count ( $filearray ) == 0 )
{
2018-02-21 11:02:45 +01:00
print '<tr class="oddeven"><td colspan="5">' ;
2017-10-16 08:47:05 +02:00
if ( empty ( $textifempty )) print $langs -> trans ( " NoFileFound " );
else print $textifempty ;
print '</td></tr>' ;
}
print " </table> " ;
print '</div>' ;
if ( ! empty ( $addfilterfields )) print '</form>' ;
// Fin de zone
}
/**
* Show form to upload a new file with jquery fileupload .
* This form use the fileupload . php file .
*
* @ param Object $object Object to use
* @ return void
*/
private function _formAjaxFileUpload ( $object )
{
2018-11-13 14:44:10 +01:00
global $langs , $conf ;
2017-10-16 08:47:05 +02:00
// PHP post_max_size
$post_max_size = ini_get ( 'post_max_size' );
$mul_post_max_size = substr ( $post_max_size , - 1 );
$mul_post_max_size = ( $mul_post_max_size == 'M' ? 1048576 : ( $mul_post_max_size == 'K' ? 1024 : ( $mul_post_max_size == 'G' ? 1073741824 : 1 )));
$post_max_size = $mul_post_max_size * ( int ) $post_max_size ;
// PHP upload_max_filesize
$upload_max_filesize = ini_get ( 'upload_max_filesize' );
$mul_upload_max_filesize = substr ( $upload_max_filesize , - 1 );
$mul_upload_max_filesize = ( $mul_upload_max_filesize == 'M' ? 1048576 : ( $mul_upload_max_filesize == 'K' ? 1024 : ( $mul_upload_max_filesize == 'G' ? 1073741824 : 1 )));
$upload_max_filesize = $mul_upload_max_filesize * ( int ) $upload_max_filesize ;
// Max file size
$max_file_size = (( $post_max_size < $upload_max_filesize ) ? $post_max_size : $upload_max_filesize );
// Include main
include DOL_DOCUMENT_ROOT . '/core/tpl/ajax/fileupload_main.tpl.php' ;
// Include template
include DOL_DOCUMENT_ROOT . '/core/tpl/ajax/fileupload_view.tpl.php' ;
}
/**
* Show array with linked files
*
* @ param Object $object Object
* @ param int $permtodelete Deletion is allowed
* @ param string $action Action
* @ param string $selected ? ? ?
* @ param string $param More param to add into URL
* @ return int Number of links
*/
public function listOfLinks ( $object , $permtodelete = 1 , $action = null , $selected = null , $param = '' )
{
global $user , $conf , $langs , $user ;
global $sortfield , $sortorder ;
$langs -> load ( " link " );
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php' ;
$link = new Link ( $this -> db );
$links = array ();
if ( $sortfield == " name " ) {
$sortfield = " label " ;
} elseif ( $sortfield == " date " ) {
$sortfield = " datea " ;
} else {
$sortfield = null ;
}
$res = $link -> fetchAll ( $links , $object -> element , $object -> id , $sortfield , $sortorder );
$param .= ( isset ( $object -> id ) ? '&id=' . $object -> id : '' );
// Show list of associated links
print load_fiche_titre ( $langs -> trans ( " LinkedFiles " ));
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . ( $param ? '?' . $param : '' ) . '" method="POST">' ;
print '<table width="100%" class="liste">' ;
print '<tr class="liste_titre">' ;
print_liste_field_titre (
$langs -> trans ( " Links " ),
$_SERVER [ 'PHP_SELF' ],
" name " ,
" " ,
$param ,
'align="left"' ,
$sortfield ,
$sortorder
);
print_liste_field_titre (
" " ,
" " ,
" " ,
" " ,
" " ,
'align="right"'
);
print_liste_field_titre (
$langs -> trans ( " Date " ),
$_SERVER [ 'PHP_SELF' ],
" date " ,
" " ,
$param ,
'align="center"' ,
$sortfield ,
$sortorder
);
print_liste_field_titre (
'' ,
$_SERVER [ 'PHP_SELF' ],
" " ,
" " ,
$param ,
'align="center"'
);
print_liste_field_titre ( '' , '' , '' );
print '</tr>' ;
$nboflinks = count ( $links );
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
if ( $action == 'update' && $selected === $link -> id )
{
print '<td>' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
print '<input type="hidden" name="linkid" value="' . $link -> id . '">' ;
print '<input type="hidden" name="action" value="confirm_updateline">' ;
print $langs -> trans ( 'Link' ) . ': <input type="text" name="link" value="' . $link -> url . '">' ;
print '</td>' ;
print '<td>' ;
print $langs -> trans ( 'Label' ) . ': <input type="text" name="label" value="' . $link -> label . '">' ;
print '</td>' ;
print '<td align="center">' . dol_print_date ( dol_now (), " dayhour " , " tzuser " ) . '</td>' ;
print '<td align="right"></td>' ;
print '<td align="right">' ;
print '<input type="submit" name="save" class="button" value="' . dol_escape_htmltag ( $langs -> trans ( 'Save' )) . '">' ;
print '<input type="submit" name="cancel" class="button" value="' . dol_escape_htmltag ( $langs -> trans ( 'Cancel' )) . '">' ;
print '</td>' ;
}
else
{
print '<td>' ;
print img_picto ( '' , 'object_globe' ) . ' ' ;
print '<a data-ajax="false" href="' . $link -> url . '" target="_blank">' ;
print $link -> label ;
print '</a>' ;
print '</td>' . " \n " ;
print '<td align="right"></td>' ;
print '<td align="center">' . dol_print_date ( $link -> datea , " dayhour " , " tzuser " ) . '</td>' ;
print '<td align="center"></td>' ;
print '<td align="right">' ;
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=update&linkid=' . $link -> id . $param . '" class="editfilelink" >' . img_edit () . '</a>' ; // id= is included into $param
if ( $permtodelete ) {
print ' <a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=delete&linkid=' . $link -> id . $param . '" class="deletefilelink">' . img_delete () . '</a>' ; // id= is included into $param
} else {
print ' ' ;
}
print '</td>' ;
}
print " </tr> \n " ;
}
if ( $nboflinks == 0 )
{
2018-02-21 11:02:45 +01:00
print '<tr class="oddeven"><td colspan="5" class="opacitymedium">' ;
2017-10-16 08:47:05 +02:00
print $langs -> trans ( " NoLinkFound " );
print '</td></tr>' ;
}
print " </table> " ;
print '</form>' ;
return $nboflinks ;
}
/**
* Show detail icon with link for preview
*
2018-01-12 16:28:10 +01:00
* @ param array $file Array with data of file . Example : array ( 'name' =>... )
2017-10-16 08:47:05 +02:00
* @ param string $modulepart propal , facture , facture_fourn , ...
* @ param string $relativepath Relative path of docs
2017-11-18 15:41:30 +01:00
* @ param string $ruleforpicto Rule for picto : 0 = Use the generic preview picto , 1 = Use the picto of mime type of file )
2017-10-16 08:47:05 +02:00
* @ param string $param More param on http links
* @ return string $out Output string with HTML
*/
public function showPreview ( $file , $modulepart , $relativepath , $ruleforpicto = 0 , $param = '' )
{
global $langs , $conf ;
$out = '' ;
if ( $conf -> browser -> layout != 'phone' && ! empty ( $conf -> use_javascript_ajax ))
{
$urladvancedpreview = getAdvancedPreviewUrl ( $modulepart , $relativepath , 1 , $param ); // Return if a file is qualified for preview.
if ( count ( $urladvancedpreview ))
2014-03-14 02:07:54 +01:00
{
2017-10-16 08:47:05 +02:00
$out .= '<a class="pictopreview ' . $urladvancedpreview [ 'css' ] . '" href="' . $urladvancedpreview [ 'url' ] . '"' . ( empty ( $urladvancedpreview [ 'mime' ]) ? '' : ' mime="' . $urladvancedpreview [ 'mime' ] . '"' ) . ' ' . ( empty ( $urladvancedpreview [ 'target' ]) ? '' : ' target="' . $urladvancedpreview [ 'target' ] . '"' ) . '>' ;
//$out.= '<a class="pictopreview">';
2017-11-10 20:20:59 +01:00
if ( empty ( $ruleforpicto ))
{
//$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail');
$out .= '<span class="fa fa-search-plus" style="color: gray"></span>' ;
}
2017-10-16 08:47:05 +02:00
else $out .= img_mime ( $relativepath , $langs -> trans ( 'Preview' ) . ' ' . $file [ 'name' ]);
$out .= '</a>' ;
}
}
return $out ;
}
2016-08-02 03:35:22 +02:00
2010-05-03 10:43:32 +02:00
}