class FormFile (View source)

Class to offer components to list and upload files

Properties

string $error
int $numoffiles
array{nboffiles: int, extensions: array<string, int>, files: string[]} $infofiles

Methods

__construct($db)

Constructor

string
showImageToEdit(string $htmlname, string $modulepart, string $dirformainimage, string $subdirformainimage, string $fileformainimage)

Show an image with feature to edit it

form_attach_new_file($url, string $title = '', $addcancel = 0, int $sectionid = 0, $perm = 1, $size = 50, $object = null, $options = '', $useajax = 1, $savingdocmask = '', $linkfiles = 1, $htmlname = 'formuserfile', $accept = '', string $sectiondir = '', $usewithoutform = 0, $capture = 0, $disablemulti = 0, $nooutput = 0)

Show form to upload a new file.

show_documents($modulepart, string $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed = 0, $modelselected = '', $allowgenifempty = 1, $forcenomultilang = 0, $iconPDF = 0, $notused = 0, $noform = 0, $param = '', $title = '', $buttonlabel = '', $codelang = '')

Show the box with list of available documents for object

showdocuments(string $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 = '')

Return a string to show the box with list of available documents for object.

string
getDocumentsLink(string $modulepart, string $modulesubdir, string $filedir, $filter = '', $morecss = 'valignmiddle', $allfiles = 0)

Show a Document icon with link(s) You may want to call this into a div like this: print '

'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'
';

list_of_documents(array<array{name: string, path: string, level1name: string, relativename: string, fullname: string, date: string, size: int, perm: int, type: string}> $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())

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.

list_of_autoecmfiles($upload_dir, array<array{name: string, path: string, level1name: string, relativename: string, fullname: string, date: string, size: int, perm: int, type: string}> $filearray, $modulepart, $param, $forcedownload = 0, $relativepath = '', $permissiontodelete = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $url = '', $addfilterfields = 0)

Show list of documents in a directory of ECM module.

int
listOfLinks(CommonObject $object, int<0, 1> $permissiontodelete = 1, ?string $action = null, ?string $selected = null, string $param = '', string $htmlname = 'formaddlink', array<string, mixed> $moreoptions = array())

Show array with linked files

string
showPreview(array{name: string, path?: string, level1name?: string, relativename?: string, fullname: string, date?: string, size?: int, perm?: int, type?: string} $file, string $modulepart, string $relativepath, int<min, 1> $ruleforpicto = 0, string $param = '')

Show detail icon with link for preview

Details

__construct($db)

Constructor

@param DoliDB $db Database handler

Parameters

$db

string showImageToEdit(string $htmlname, string $modulepart, string $dirformainimage, string $subdirformainimage, string $fileformainimage)

Show an image with feature to edit it

Parameters

string $htmlname

HTML name

string $modulepart

Module part

string $dirformainimage

Main directory of module

string $subdirformainimage

Subdirectory into main directory. Often '', can be 'logos/'.

string $fileformainimage

File name of image to show

Return Value

string

HTML code to show and edit image

form_attach_new_file($url, string $title = '', $addcancel = 0, int $sectionid = 0, $perm = 1, $size = 50, $object = null, $options = '', $useajax = 1, $savingdocmask = '', $linkfiles = 1, $htmlname = 'formuserfile', $accept = '', string $sectiondir = '', $usewithoutform = 0, $capture = 0, $disablemulti = 0, $nooutput = 0)

Show form to upload a new file.

@param string $url Url

Parameters

$url
string $title

Title zone (Title or '' or 'none') @param int<0,1> $addcancel 1=Add 'Cancel' button

$addcancel
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. @param CommonObject|BlockedLog|null $object Object to use (when attachment is done on an element) @param string $options Add an option column @param int<0,1> $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 not be enabled. @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-YYYYMMDD-file' @param int<0,1> $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/')

$perm
$size
$object
$options
$useajax
$savingdocmask
$linkfiles
$htmlname
$accept
string $sectiondir

If upload must be done inside a particular directory (if sectiondir defined, sectionid must not be) @param int<0,2> $usewithoutform 0=Default, 1=Disable

and to use in existing form area, 2=Disable the tag 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 @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

$usewithoutform
$capture
$disablemulti
$nooutput

show_documents($modulepart, string $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed = 0, $modelselected = '', $allowgenifempty = 1, $forcenomultilang = 0, $iconPDF = 0, $notused = 0, $noform = 0, $param = '', $title = '', $buttonlabel = '', $codelang = '')

Show the box with list of available documents for object

@param string $modulepart propal, facture, facture_fourn, ...

Parameters

$modulepart
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<0,1> $genallowed Generation is allowed (1/0 or array of formats) @param int<0,1> $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 Return integer <0 if KO, number of shown files if OK @deprecated Use print xxx->showdocuments() instead.

$filedir
$urlsource
$genallowed
$delallowed
$modelselected
$allowgenifempty
$forcenomultilang
$iconPDF
$notused
$noform
$param
$title
$buttonlabel
$codelang

showdocuments(string $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 = '')

Return a string to show the box with list of available documents for object.

This also set the property $this->numoffiles

Parameters

string $modulepart

Module the files are related to ('propal', 'facture', 'facture_fourn', 'mymodule', 'mymodule:MyObject', '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 a subdir of module. @param string $filedir Directory to scan (must not end with a /). Example: '/mydolibarrdocuments/facture/FAYYMM-1234' @param string $urlsource Url of origin page (for return) @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) @param string $modelselected Model to preselect by default @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) @param int $iconPDF Deprecated, see getDocumentsLink @param int $notused Not used @param int<0,1> $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. Example: '' (Default to "Documents") or 'none' @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|null $object Object when method is called from an object card. @param int<0,1> $hideifempty Hide section of generated files if there is no file @param string $removeaction (optional) The action to remove a file @param string $tooltipontemplatecombo Text to show on a tooltip after the combo list of templates @return string|int<-1,-1> Output string with HTML array of documents (might be empty string)

$modulesubdir
$filedir
$urlsource
$genallowed
$delallowed
$modelselected
$allowgenifempty
$forcenomultilang
$iconPDF
$notused
$noform
$param
$title
$buttonlabel
$codelang
$morepicto
$object
$hideifempty
$removeaction
$tooltipontemplatecombo

Show a Document icon with link(s) You may want to call this into a div like this: print '

'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'
';

Parameters

string $modulepart

'propal', 'facture', 'facture_fourn', ...

string $modulesubdir

Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module.

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

$filter
$morecss
$allfiles

Return Value

string

Output string with HTML link of documents (might be empty string). This also fill the array ->infofiles

list_of_documents(array<array{name: string, path: string, level1name: string, relativename: string, fullname: string, date: string, size: int, perm: int, type: string}> $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())

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.

Parameters

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. @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<0,1> $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<0,1> $permonobject Permission on object (so permission to delete or crop document) @param int<0,6> $useinecm Change output to add more information: 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) 1: Add link to edit ECM entry 2: Add rename and crop link 5: Add link to edit ECM entry and add a preview column @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) @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) @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') @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) @param string $moreattrondiv More attributes on the div for responsive. Example 'style="height:280px; overflow: auto;"' @param array<string,mixed> $moreoptions Add more options like array('afteruploadtitle', ...) @return int Return integer <0 if KO, nb of files shown if OK list_of_autoecmfiles()

$object
$modulepart
$param
$forcedownload
$relativepath
$permonobject
$useinecm
$textifempty
$maxlength
$title
$url
$showrelpart
$permtoeditline
$upload_dir
$sortfield
$sortorder
$disablemove
$addfilterfields
$disablecrop
$moreattrondiv
$moreoptions

list_of_autoecmfiles($upload_dir, array<array{name: string, path: string, level1name: string, relativename: string, fullname: string, date: string, size: int, perm: int, type: string}> $filearray, $modulepart, $param, $forcedownload = 0, $relativepath = '', $permissiontodelete = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $url = '', $addfilterfields = 0)

Show list of documents in a directory of ECM module.

@param string $upload_dir Directory that was scanned. This directory will contains files into subdirs REF/files

Parameters

$upload_dir
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 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) @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 $permissiontodelete Permission to delete @param int $useinecm Change output for use in ecm module @param string $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 Return integer <0 if KO, nb of files shown if OK list_of_documents()

$modulepart
$param
$forcedownload
$relativepath
$permissiontodelete
$useinecm
$textifempty
$maxlength
$url
$addfilterfields

Show array with linked files

Parameters

CommonObject $object Object
int<0, 1> $permissiontodelete

Deletion is allowed

?string $action Action
?string $selected ???
string $param

More param to add into URL

string $htmlname

Html name of component

array<string, mixed> $moreoptions

Add more options like array('afterlinktitle', ...)

Return Value

int

Number of links

string showPreview(array{name: string, path?: string, level1name?: string, relativename?: string, fullname: string, date?: string, size?: int, perm?: int, type?: string} $file, string $modulepart, string $relativepath, int<min, 1> $ruleforpicto = 0, string $param = '')

Show detail icon with link for preview

Parameters

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'=>...)

string $modulepart

propal, facture, facture_fourn, ...

string $relativepath

Relative path of docs

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.

string $param

More param on http links

Return Value

string

$out Output string with HTML