dolibarr 22.0.5
html.formfile.class.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (C) 2008-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2010-2014 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2013 Charles-Fr BENKE <charles.fr@benke.fr>
7 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
8 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
10 * Copyright (C) 2016-2017 Ferran Marcet <fmarcet@2byte.es>
11 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
39{
43 private $db;
44
48 public $error;
49
53 public $numoffiles;
57 public $infofiles;
58
59
65 public function __construct($db)
66 {
67 $this->db = $db;
68 $this->numoffiles = 0;
69 }
70
81 public function showImageToEdit(string $htmlname, string $modulepart, string $dirformainimage, string $subdirformainimage, string $fileformainimage)
82 {
83 global $langs;
84
85 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
86 include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
87 include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
88
89 $tmparraysize = getDefaultImageSizes();
90 $maxwidthsmall = $tmparraysize['maxwidthsmall'];
91 $maxheightsmall = $tmparraysize['maxheightsmall'];
92 $maxwidthmini = $tmparraysize['maxwidthmini'];
93 $maxheightmini = $tmparraysize['maxheightmini'];
94 $quality = $tmparraysize['quality'];
95
96 $imgheight = 80;
97 $imgwidth = 200;
98 $max = 'max-';
99 if ($htmlname == 'logo_squarred') {
100 $imgheight = 80;
101 $imgwidth = 80;
102 $max = '';
103 }
104
105 $maxfilesizearray = getMaxFileSizeArray();
106 $maxmin = $maxfilesizearray['maxmin'];
107 $fileformainimagesmall = getImageFileNameForSize($fileformainimage, '_small'); // This include the "thumbs/..." in path
108 $fileformainimagemini = getImageFileNameForSize($fileformainimage, '_mini'); // This include the "thumbs/..." in path
109
110 $out = '';
111
112 $out .= '<div class="centpercent nobordernopadding valignmiddle"><div class="inline-block marginrightonly">';
113 if ($maxmin > 0) {
114 $out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
115 }
116 $out .= '<input type="file" class="flat minwidth100 maxwidthinputfileonsmartphone" name="'.$htmlname.'" id="'.$htmlname.'" accept="image/*">';
117 $out .= '</div>';
118 if (!empty($fileformainimagesmall)) {
119 $out .= '<div class="inline-block valignmiddle marginrightonly">';
120 $out .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=remove'.$htmlname.'&token='.newToken().'">'.img_delete($langs->trans("Delete"), '', 'marginleftonly').'</a>';
121 $out .= '</div>';
122 if (file_exists($dirformainimage.'/'.$subdirformainimage.$fileformainimagesmall)) {
123 $out .= '<div class="inline-block valignmiddle marginrightonly">';
124 $out .= '<img id="'.$htmlname.'" style="'.$max.'height: '.$imgheight.'px; '.$max.'width: '.$imgwidth.'px;" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($subdirformainimage.$fileformainimagesmall).'">';
125 $out .= '</div>';
126 } elseif (!empty($fileformainimage)) {
127 // Regenerate the thumbs
128 if (!file_exists($dirformainimage.'/'.$subdirformainimage.$fileformainimagemini)) {
129 $imgThumbMini = vignette($dirformainimage.'/'.$subdirformainimage.$fileformainimage, $maxwidthmini, $maxheightmini, '_mini', $quality);
130 }
131 $imgThumbSmall = vignette($dirformainimage.'/'.$subdirformainimage.$fileformainimage, $maxwidthsmall, $maxheightsmall, '_small', $quality);
132 $out .= '<div class="inline-block valignmiddle">';
133 $out .= '<img id="'.$htmlname.'" style="'.$max.'height: '.$imgheight.'px; '.$max.'width: '.$imgwidth.'px;" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($subdirformainimage.'thumbs/'.basename($imgThumbSmall)).'">';
134 $out .= '</div>';
135 }
136 } elseif (!empty($fileformainimage)) {
137 if (file_exists($dirformainimage.'/'.$subdirformainimage.$fileformainimage)) {
138 $out .= '<div class="inline-block valignmiddle">';
139 $out .= '<img id="'.$htmlname.'" style="'.$max.'height: '.$imgheight.'px; '.$max.'width: '.$imgwidth.'px;" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($subdirformainimage.$fileformainimage).'">';
140 $out .= '</div>';
141 $out .= '<div class="inline-block valignmiddle marginrightonly"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=remove'.$htmlname.'&token='.newToken().'">'.img_delete($langs->trans("Delete"), '', 'marginleftonly').'</a></div>';
142 } else {
143 $out .= '<div class="inline-block valignmiddle">';
144 $out .= '<img id="'.$htmlname.'" height="'.$imgheight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="File has been removed from disk">';
145 $out .= '</div>';
146 }
147 }
148 $out .= '</div>';
149
150 return $out;
151 }
152
153 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
178 public function form_attach_new_file($url, $title = '', $addcancel = 0, $sectionid = 0, $perm = 1, $size = 50, $object = null, $options = '', $useajax = 1, $savingdocmask = '', $linkfiles = 1, $htmlname = 'formuserfile', $accept = '', $sectiondir = '', $usewithoutform = 0, $capture = 0, $disablemulti = 0, $nooutput = 0)
179 {
180 // phpcs:enable
181 global $conf, $langs, $hookmanager;
182 $hookmanager->initHooks(array('formfile'));
183
184 // Deprecation warning
185 if ($useajax == 2) {
186 dol_syslog(__METHOD__.": using 2 for useajax is deprecated and should be not used", LOG_WARNING);
187 }
188
189 if (!empty($conf->browser->layout) && $conf->browser->layout != 'classic') {
190 $useajax = 0;
191 }
192
193 //If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed
194 if (!$perm && getDolGlobalString('MAIN_BUTTON_HIDE_UNAUTHORIZED')) {
195 if ($nooutput) {
196 return '';
197 } else {
198 return 1;
199 }
200 }
201
202 // Section to generate the form to upload a new file
203 $out = "\n".'<!-- Start form attach new file --><div class="formattachnewfile">'."\n";
204
205 if ($nooutput != 2) {
206 if (empty($title)) {
207 $title = $langs->trans("AttachANewFile");
208 }
209 if ($title != 'none') {
210 $out .= load_fiche_titre($title, '', '');
211 }
212 }
213
214 if (empty($usewithoutform)) { // Try to avoid this and set instead the form by the caller.
215 // Add a param as GET parameter to detect when POST were cleaned by PHP because a file larger than post_max_size
216 $url .= (strpos($url, '?') === false ? '?' : '&').'uploadform=1';
217
218 $out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">'."\n";
219 }
220 if (empty($usewithoutform) || $usewithoutform == 2) {
221 $out .= '<input type="hidden" name="token" value="'.newToken().'">'."\n";
222 $out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">'."\n";
223 $out .= '<input type="hidden" id="'.$htmlname.'_section_id" name="section_id" value="'.$sectionid.'">'."\n";
224 $out .= '<input type="hidden" name="sortfield" value="'.GETPOST('sortfield', 'aZ09comma').'">'."\n";
225 $out .= '<input type="hidden" name="sortorder" value="'.GETPOST('sortorder', 'aZ09comma').'">'."\n";
226 $out .= '<input type="hidden" name="page_y" value="">'."\n";
227 }
228
229 $out .= '<table class="nobordernopadding centpercent">';
230 $out .= '<tr>';
231
232 if (!empty($options)) {
233 $out .= '<td>'.$options.'</td>';
234 }
235
236 $out .= '<td class="valignmiddle nowrap">';
237
238 $maxfilesizearray = getMaxFileSizeArray();
239 $max = $maxfilesizearray['max'];
240 $maxmin = $maxfilesizearray['maxmin'];
241 $maxphptoshow = $maxfilesizearray['maxphptoshow'];
242 $maxphptoshowparam = $maxfilesizearray['maxphptoshowparam'];
243 if ($maxmin > 0) {
244 $out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
245 }
246 $out .= '<input class="flat minwidth400 maxwidth200onsmartphone" type="file"';
247 $out .= ((getDolGlobalString('MAIN_DISABLE_MULTIPLE_FILEUPLOAD') || $disablemulti) ? ' name="userfile"' : ' name="userfile[]" multiple');
248 $out .= (!getDolGlobalString('MAIN_UPLOAD_DOC') || empty($perm) ? ' disabled' : '');
249 $out .= (!empty($accept) ? ' accept="'.$accept.'"' : ' accept=""');
250 $out .= (!empty($capture) ? ' capture="capture"' : '');
251 $out .= '>';
252 $out .= ' ';
253 if ($sectionid) { // Show overwrite if exists for ECM module only
254 $langs->load('link');
255 $out .= '<span class="nowraponsmartphone"><input style="margin-right: 2px;" type="checkbox" id="overwritefile" name="overwritefile" value="1">';
256 $out .= '<label for="overwritefile" class="opacitylow paddingleft paddingright">'.$langs->trans("OverwriteIfExists").'</label>';
257 $out .= '</span>';
258 }
259 $out .= '<input type="submit" class="button smallpaddingimp reposition" name="sendit" value="'.$langs->trans("Upload").'"';
260 $out .= (!getDolGlobalString('MAIN_UPLOAD_DOC') || empty($perm) ? ' disabled' : '');
261 $out .= '>';
262
263 if ($addcancel) {
264 $out .= ' &nbsp; ';
265 $out .= '<input type="submit" class="button small button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
266 }
267
268 if (getDolGlobalString('MAIN_UPLOAD_DOC')) {
269 if ($perm && empty($conf->dol_optimize_smallscreen)) {
270 $langs->load('other');
271
272 $menudolibarrsetupmax = $langs->transnoentitiesnoconv("Home").' - '.$langs->transnoentitiesnoconv("Setup").' - '.$langs->transnoentitiesnoconv("Security");
273
274 $tooltiptext = $langs->trans("ThisLimitIsDefinedInSetupAt", $menudolibarrsetupmax, $max, $maxphptoshowparam, $maxphptoshow);
275 if (getDolGlobalString('MAIN_SAVE_FILE_CONTENT_AS_TEXT')) {
276 $tooltiptext .= '<br><br>Option to extract the file content in text to save it in database is ON <span class="opacitymedium">('.getDolGlobalString('MAIN_SAVE_FILE_CONTENT_AS_TEXT').')</span>';
277 }
278
279 $out .= ' ';
280 $out .= info_admin($tooltiptext, 1, 0, '1', 'classfortooltip');
281 }
282 } else {
283 $out .= ' ('.$langs->trans("UploadDisabled").')';
284 }
285 $out .= "</td></tr>";
286
287 if ($savingdocmask) {
288 //add a global variable for disable the auto renaming on upload
289 $rename = getDolGlobalString('MAIN_DOC_UPLOAD_NOT_RENAME_BY_DEFAULT') ? '' : 'checked';
290
291 $out .= '<tr>';
292 if (!empty($options)) {
293 $out .= '<td>'.$options.'</td>';
294 }
295 $out .= '<td valign="middle" class="nowrap">';
296 $out .= '<input type="checkbox" '.$rename.' class="savingdocmask" name="savingdocmask" id="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> ';
297 $out .= '<label class="opacitymedium small" for="savingdocmask">';
298 $out .= $langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/', $langs->transnoentitiesnoconv("OriginFileName"), $savingdocmask), $langs->transnoentitiesnoconv("OriginFileName"));
299 $out .= '</label>';
300 $out .= '</td>';
301 $out .= '</tr>';
302 }
303
304 $out .= "</table>";
305
306 if (empty($usewithoutform)) {
307 $out .= '</form>';
308 if (empty($sectionid)) {
309 $out .= '<br>';
310 }
311 }
312
313 $parameters = array('socid' => (isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id' => (isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'url' => $url, 'perm' => $perm, 'options' => $options);
314 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable
315 $res = $hookmanager->executeHooks('formattachOptionsUpload', $parameters, $object);
316 if (empty($res)) {
317 $out = '<div class="'.($usewithoutform ? 'inline-block valignmiddle' : (($nooutput == 2 ? '' : 'attacharea ').'attacharea'.$htmlname)).'">'.$out.'</div>';
318 }
319 $out .= $hookmanager->resPrint;
320
321 $out .= "\n</div><!-- End form class=formattachnewfile -->\n";
322
323
324 $out2 = "";
325
326 // Section to generate the form to upload a new file
327 if ($linkfiles) {
328 $out2 .= "\n".'<!-- Start form link new url --><div class="formlinknewurl">'."\n";
329 $langs->load('link');
330
331 if ($nooutput != 2) {
332 $title = $langs->trans("LinkANewFile");
333 $out2 .= load_fiche_titre($title, '', '');
334 }
335
336 if (empty($usewithoutform)) {
337 $out2 .= '<form name="'.$htmlname.'_link" id="'.$htmlname.'_link" action="'.$url.'" method="POST">'."\n";
338 $out2 .= '<input type="hidden" name="token" value="'.newToken().'">'."\n";
339 $out2 .= '<input type="hidden" id="'.$htmlname.'_link_section_dir" name="link_section_dir" value="">'."\n";
340 $out2 .= '<input type="hidden" id="'.$htmlname.'_link_section_id" name="link_section_id" value="'.$sectionid.'">'."\n";
341 $out2 .= '<input type="hidden" name="page_y" value="">'."\n";
342 }
343
344 $out2 .= '<div class="valignmiddle">';
345 $out2 .= '<div class="inline-block" style="padding-right: 10px;">';
346 if (getDolGlobalString('OPTIMIZEFORTEXTBROWSER')) {
347 $out2 .= '<label for="link">'.$langs->trans("URLToLink").':</label> ';
348 }
349 $out2 .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">';
350 $out2 .= '</div>';
351 $out2 .= '<div class="inline-block" style="padding-right: 10px;">';
352 if (getDolGlobalString('OPTIMIZEFORTEXTBROWSER')) {
353 $out2 .= '<label for="label">'.$langs->trans("Label").':</label> ';
354 }
355 $out2 .= '<input type="text" class="flat" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">';
356 $out2 .= '<input type="hidden" name="objecttype" value="'.$object->element.'">';
357 $out2 .= '<input type="hidden" name="objectid" value="'.$object->id.'">';
358 $out2 .= '</div>';
359 $out2 .= '<div class="inline-block" style="padding-right: 10px;">';
360 $out2 .= '<input type="submit" class="button smallpaddingimp reposition" name="linkit" value="'.$langs->trans("ToLink").'"';
361 $out2 .= (!getDolGlobalString('MAIN_UPLOAD_DOC') || empty($perm) ? ' disabled' : '');
362 $out2 .= '>';
363 $out2 .= '</div>';
364 $out2 .= '</div>';
365 if (empty($usewithoutform)) {
366 $out2 .= '<div class="clearboth"></div>';
367 $out2 .= '</form><br>';
368 }
369
370 $parameters = array('socid' => (isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id' => (isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'url' => $url, 'perm' => $perm, 'options' => $options);
371 $res = $hookmanager->executeHooks('formattachOptions', $parameters, $object);
372 if (empty($res)) {
373 $out2 = '<div class="'.($usewithoutform ? 'inline-block valignmiddle' : (($nooutput == 2 ? '' : 'attacharea ').$htmlname)).'">'.$out2.'</div>';
374 }
375 $out2 .= $hookmanager->resPrint;
376
377 $out2 .= "\n</div><!-- End form class=formlinknewurl -->\n";
378 }
379
380
381 if ($nooutput == 2) {
382 return array('formToUploadAFile' => $out, 'formToAddALink' => $out2);
383 } elseif ($nooutput) {
384 return $out.$out2;
385 } else {
386 print $out.$out2;
387 return 1;
388 }
389 }
390
391 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
414 public function show_documents($modulepart, $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed = 0, $modelselected = '', $allowgenifempty = 1, $forcenomultilang = 0, $iconPDF = 0, $notused = 0, $noform = 0, $param = '', $title = '', $buttonlabel = '', $codelang = '')
415 {
416 // phpcs:enable
417 $this->numoffiles = 0;
418 print $this->showdocuments($modulepart, $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed, $modelselected, $allowgenifempty, $forcenomultilang, $iconPDF, $notused, $noform, $param, $title, $buttonlabel, $codelang);
419 return $this->numoffiles;
420 }
421
449 public function showdocuments($modulepart, $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed = 0, $modelselected = '', $allowgenifempty = 1, $forcenomultilang = 0, $iconPDF = 0, $notused = 0, $noform = 0, $param = '', $title = '', $buttonlabel = '', $codelang = '', $morepicto = '', $object = null, $hideifempty = 0, $removeaction = 'remove_file', $tooltipontemplatecombo = '')
450 {
452
453 // Deprecation warning
454 if (!empty($iconPDF)) {
455 dol_syslog(__METHOD__.": passing iconPDF parameter is deprecated", LOG_WARNING);
456 }
457
458 global $langs, $conf, $user, $hookmanager;
459 global $form;
460
461 $reshook = 0;
462 if (is_object($hookmanager)) {
463 $parameters = array(
464 'modulepart' => &$modulepart,
465 'modulesubdir' => &$modulesubdir,
466 'filedir' => &$filedir,
467 'urlsource' => &$urlsource,
468 'genallowed' => &$genallowed,
469 'delallowed' => &$delallowed,
470 'modelselected' => &$modelselected,
471 'allowgenifempty' => &$allowgenifempty,
472 'forcenomultilang' => &$forcenomultilang,
473 'noform' => &$noform,
474 'param' => &$param,
475 'title' => &$title,
476 'buttonlabel' => &$buttonlabel,
477 'codelang' => &$codelang,
478 'morepicto' => &$morepicto,
479 'hideifempty' => &$hideifempty,
480 'removeaction' => &$removeaction
481 );
482 $reshook = $hookmanager->executeHooks('showDocuments', $parameters, $object); // Note that parameters may have been updated by hook
483 // May report error
484 if ($reshook < 0) {
485 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
486 }
487 }
488 // Remode default action if $reskook > 0
489 if ($reshook > 0) {
490 return $hookmanager->resPrint;
491 }
492
493 if (!is_object($form)) {
494 $form = new Form($this->db);
495 }
496
497 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
498
499 // For backward compatibility
500 if (!empty($iconPDF)) {
501 return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir);
502 }
503
504 // Add entity in $param if not already exists
505 if (!preg_match('/entity\=[0-9]+/', $param)) {
506 $param .= ($param ? '&' : '').'entity='.(empty($object->entity) ? $conf->entity : $object->entity);
507 }
508
509 $printer = 0;
510 // The direct print feature is implemented only for such elements
511 if (in_array($modulepart, array('contract', 'facture', 'supplier_proposal', 'propal', 'proposal', 'order', 'commande', 'expedition', 'commande_fournisseur', 'expensereport', 'delivery', 'ticket'))) {
512 $printer = ($user->hasRight('printing', 'read') && isModEnabled('printing'));
513 }
514
515 $hookmanager->initHooks(array('formfile'));
516
517 // Get list of files
518 $file_list = array();
519 if (!empty($filedir)) {
520 $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
521 }
522 if ($hideifempty && empty($file_list)) {
523 return '';
524 }
525
526 $out = '';
527 $forname = 'builddoc';
528 $headershown = 0;
529 $showempty = 0;
530 $i = 0;
531
532 $out .= "\n".'<!-- Start show_document -->'."\n";
533 //print 'filedir='.$filedir;
534
535 if (preg_match('/massfilesarea_/', $modulepart)) {
536 $out .= '<div id="show_files"><br></div>'."\n";
537 $title = $langs->trans("MassFilesArea").' <a href="" id="togglemassfilesarea" ref="shown">('.$langs->trans("Hide").')</a>';
538 $title .= '<script nonce="'.getNonce().'">
539 jQuery(document).ready(function() {
540 jQuery(\'#togglemassfilesarea\').click(function() {
541 if (jQuery(\'#togglemassfilesarea\').attr(\'ref\') == "shown")
542 {
543 jQuery(\'#'.$modulepart.'_table\').hide();
544 jQuery(\'#togglemassfilesarea\').attr("ref", "hidden");
545 jQuery(\'#togglemassfilesarea\').text("('.dol_escape_js($langs->trans("Show")).')");
546 }
547 else
548 {
549 jQuery(\'#'.$modulepart.'_table\').show();
550 jQuery(\'#togglemassfilesarea\').attr("ref","shown");
551 jQuery(\'#togglemassfilesarea\').text("('.dol_escape_js($langs->trans("Hide")).')");
552 }
553 return false;
554 });
555 });
556 </script>';
557 }
558
559 $titletoshow = $langs->trans("Documents");
560 if (!empty($title)) {
561 $titletoshow = ($title == 'none' ? '' : $title);
562 }
563
564 $submodulepart = $modulepart;
565
566 // modulepart = 'nameofmodule' or 'nameofmodule:NameOfObject'
567 $tmp = explode(':', $modulepart);
568 if (!empty($tmp[1])) {
569 $modulepart = $tmp[0];
570 $submodulepart = $tmp[1];
571 }
572
573 $addcolumforpicto = ($delallowed || $printer || $morepicto);
574 $colspan = (4 + ($addcolumforpicto ? 1 : 0));
575 $colspanmore = 0;
576
577 // Show table
578 if ($genallowed) {
579 $modellist = array();
580
581 if ($modulepart == 'company') {
582 $showempty = 1; // can have no template active
583 if (is_array($genallowed)) {
584 $modellist = $genallowed;
585 } else {
586 include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
587 $modellist = ModeleThirdPartyDoc::liste_modeles($this->db);
588 }
589 } elseif ($modulepart == 'propal') {
590 if (is_array($genallowed)) {
591 $modellist = $genallowed;
592 } else {
593 include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
594 $modellist = ModelePDFPropales::liste_modeles($this->db);
595 }
596 } elseif ($modulepart == 'supplier_proposal') {
597 if (is_array($genallowed)) {
598 $modellist = $genallowed;
599 } else {
600 include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
601 $modellist = ModelePDFSupplierProposal::liste_modeles($this->db);
602 }
603 } elseif ($modulepart == 'commande') {
604 if (is_array($genallowed)) {
605 $modellist = $genallowed;
606 } else {
607 include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
608 $modellist = ModelePDFCommandes::liste_modeles($this->db);
609 }
610 } elseif ($modulepart == 'expedition') {
611 if (is_array($genallowed)) {
612 $modellist = $genallowed;
613 } else {
614 include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
615 $modellist = ModelePdfExpedition::liste_modeles($this->db);
616 }
617 } elseif ($modulepart == 'reception') {
618 if (is_array($genallowed)) {
619 $modellist = $genallowed;
620 } else {
621 include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
622 $modellist = ModelePdfReception::liste_modeles($this->db);
623 }
624 } elseif ($modulepart == 'delivery') {
625 if (is_array($genallowed)) {
626 $modellist = $genallowed;
627 } else {
628 include_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php';
629 $modellist = ModelePDFDeliveryOrder::liste_modeles($this->db);
630 }
631 } elseif ($modulepart == 'ficheinter') {
632 if (is_array($genallowed)) {
633 $modellist = $genallowed;
634 } else {
635 include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
636 $modellist = ModelePDFFicheinter::liste_modeles($this->db);
637 }
638 } elseif ($modulepart == 'facture') {
639 if (is_array($genallowed)) {
640 $modellist = $genallowed;
641 } else {
642 include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
643 $modellist = ModelePDFFactures::liste_modeles($this->db);
644 }
645 } elseif ($modulepart == 'contract') {
646 $showempty = 1; // can have no template active
647 if (is_array($genallowed)) {
648 $modellist = $genallowed;
649 } else {
650 include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
651 $modellist = ModelePDFContract::liste_modeles($this->db);
652 }
653 } elseif ($modulepart == 'project') {
654 if (is_array($genallowed)) {
655 $modellist = $genallowed;
656 } else {
657 include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
658 $modellist = ModelePDFProjects::liste_modeles($this->db);
659 }
660 } elseif ($modulepart == 'project_task') {
661 if (is_array($genallowed)) {
662 $modellist = $genallowed;
663 } else {
664 include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
665 $modellist = ModelePDFTask::liste_modeles($this->db);
666 }
667 } elseif ($modulepart == 'product') {
668 if (is_array($genallowed)) {
669 $modellist = $genallowed;
670 } else {
671 include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
672 $modellist = ModelePDFProduct::liste_modeles($this->db);
673 }
674 } elseif ($modulepart == 'product_batch') {
675 if (is_array($genallowed)) {
676 $modellist = $genallowed;
677 } else {
678 include_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php';
679 $modellist = ModelePDFProductBatch::liste_modeles($this->db);
680 }
681 } elseif ($modulepart == 'stock') {
682 if (is_array($genallowed)) {
683 $modellist = $genallowed;
684 } else {
685 include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_stock.php';
686 $modellist = ModelePDFStock::liste_modeles($this->db);
687 }
688 } elseif ($modulepart == 'hrm') {
689 if (is_array($genallowed)) {
690 $modellist = $genallowed;
691 } else {
692 include_once DOL_DOCUMENT_ROOT.'/core/modules/hrm/modules_evaluation.php';
693 $modellist = ModelePDFEvaluation::liste_modeles($this->db);
694 }
695 } elseif ($modulepart == 'movement') {
696 if (is_array($genallowed)) {
697 $modellist = $genallowed;
698 } else {
699 include_once DOL_DOCUMENT_ROOT.'/core/modules/movement/modules_movement.php';
700 $modellist = ModelePDFMovement::liste_modeles($this->db);
701 }
702 } elseif ($modulepart == 'export') {
703 if (is_array($genallowed)) {
704 $modellist = $genallowed;
705 } else {
706 include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
707 //$modellist = ModeleExports::liste_modeles($this->db); // liste_modeles() does not exists. We are using listOfAvailableExportFormat() method instead that return a different array format.
708 $modellist = array();
709 }
710 } elseif ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order') {
711 if (is_array($genallowed)) {
712 $modellist = $genallowed;
713 } else {
714 include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
715 $modellist = ModelePDFSuppliersOrders::liste_modeles($this->db);
716 }
717 } elseif ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice') {
718 $showempty = 1; // can have no template active
719 if (is_array($genallowed)) {
720 $modellist = $genallowed;
721 } else {
722 include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
723 $modellist = ModelePDFSuppliersInvoices::liste_modeles($this->db);
724 }
725 } elseif ($modulepart == 'supplier_payment') {
726 if (is_array($genallowed)) {
727 $modellist = $genallowed;
728 } else {
729 include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
730 $modellist = ModelePDFSuppliersPayments::liste_modeles($this->db);
731 }
732 } elseif ($modulepart == 'remisecheque') {
733 if (is_array($genallowed)) {
734 $modellist = $genallowed;
735 } else {
736 include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
737 $modellist = ModeleChequeReceipts::liste_modeles($this->db);
738 }
739 } elseif ($modulepart == 'donation') {
740 if (is_array($genallowed)) {
741 $modellist = $genallowed;
742 } else {
743 include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
744 $modellist = ModeleDon::liste_modeles($this->db);
745 }
746 } elseif ($modulepart == 'member') {
747 if (is_array($genallowed)) {
748 $modellist = $genallowed;
749 } else {
750 include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
751 $modellist = ModelePDFCards::liste_modeles($this->db);
752 }
753 } elseif ($modulepart == 'agenda' || $modulepart == 'actions') {
754 if (is_array($genallowed)) {
755 $modellist = $genallowed;
756 } else {
757 include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php';
758 $modellist = ModeleAction::liste_modeles($this->db);
759 }
760 } elseif ($modulepart == 'expensereport') {
761 if (is_array($genallowed)) {
762 $modellist = $genallowed;
763 } else {
764 include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
765 $modellist = ModeleExpenseReport::liste_modeles($this->db);
766 }
767 } elseif ($modulepart == 'unpaid') {
768 $modellist = '';
769 } elseif ($modulepart == 'user') {
770 if (is_array($genallowed)) {
771 $modellist = $genallowed;
772 } else {
773 include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php';
774 $modellist = ModelePDFUser::liste_modeles($this->db);
775 }
776 } elseif ($modulepart == 'usergroup') {
777 if (is_array($genallowed)) {
778 $modellist = $genallowed;
779 } else {
780 include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php';
781 $modellist = ModelePDFUserGroup::liste_modeles($this->db);
782 }
783 } else {
784 // For normalized standard modules
785 $file = dol_buildpath('/core/modules/'.$modulepart.'/modules_'.strtolower($submodulepart).'.php', 0);
786 if (file_exists($file)) {
787 $res = include_once $file;
788 } else {
789 // For normalized external modules.
790 $file = dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.strtolower($submodulepart).'.php', 0);
791 $res = include_once $file;
792 }
793
794 $class = 'ModelePDF'.ucfirst($submodulepart);
795
796 if (class_exists($class)) {
797 $modellist = call_user_func($class.'::liste_modeles', $this->db);
798 } else {
799 dol_print_error($this->db, "Bad value for modulepart '".$modulepart."' in showdocuments (class ".$class." for Doc generation not found)");
800 return -1;
801 }
802 }
803
804 // Set headershown to avoid to have table opened a second time later
805 $headershown = 1;
806
807 if (empty($buttonlabel)) {
808 $buttonlabel = $langs->trans('Generate');
809 }
810
811 if ($conf->browser->layout == 'phone') {
812 $urlsource .= '#'.$forname.'_form'; // So we switch to form after a generation
813 }
814 if (empty($noform)) {
815 $out .= '<form action="'.$urlsource.'" id="'.$forname.'_form" method="post">';
816 }
817 $out .= '<input type="hidden" name="action" value="builddoc">';
818 $out .= '<input type="hidden" name="page_y" value="">';
819 $out .= '<input type="hidden" name="token" value="'.newToken().'">';
820
821 if ($titletoshow) {
822 $out .= load_fiche_titre($titletoshow, '', '');
823 }
824 $out .= '<div class="div-table-responsive-no-min">';
825 $out .= '<table class="liste formdoc noborder centpercent">';
826
827 $out .= '<tr class="liste_titre">';
828 $addcolumforpicto = ($delallowed || $printer || $morepicto);
829 $colspan = (4 + ($addcolumforpicto ? 1 : 0));
830 $colspanmore = 0;
831
832 $out .= '<th colspan="'.$colspan.'" class="formdoc liste_titre maxwidthonsmartphone center">';
833
834 // Model
835 if (!empty($modellist)) {
836 asort($modellist);
837 $out .= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>';
838 if (is_array($modellist) && count($modellist) == 1) { // If there is only one element
839 $arraykeys = array_keys($modellist);
840 $modelselected = $arraykeys[0];
841 }
842 $morecss = 'minwidth75 maxwidth200';
843 if ($conf->browser->layout == 'phone') {
844 $morecss = 'maxwidth100';
845 }
846 $out .= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1, '', 0, 0);
847 if ($conf->use_javascript_ajax) {
848 $out .= ajax_combobox('model');
849 }
850 $out .= $form->textwithpicto('', $tooltipontemplatecombo, 1, 'help', 'marginrightonly', 0, 3, '', 0);
851 } else {
852 $out .= '<div class="float">'.$langs->trans("Files").'</div>';
853 }
854
855 // Language code (if multilang)
856 if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && getDolGlobalInt('MAIN_MULTILANGS') && !$forcenomultilang && (!empty($modellist) || $showempty)) {
857 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
858 $formadmin = new FormAdmin($this->db);
859 $defaultlang = ($codelang && $codelang != 'auto') ? $codelang : $langs->getDefaultLang();
860 $morecss = 'maxwidth150';
861 if ($conf->browser->layout == 'phone') {
862 $morecss = 'maxwidth100';
863 }
864 $out .= $formadmin->select_language($defaultlang, 'lang_id', 0, array(), 0, 0, 0, $morecss);
865 } else {
866 $out .= '&nbsp;';
867 }
868
869 // Button to generate document
870 $genbutton = '<input class="button buttongen reposition nomargintop nomarginbottom" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
871 $genbutton .= ' type="submit" value="'.$buttonlabel.'"';
872 if (!$allowgenifempty && !is_array($modellist) && empty($modellist)) {
873 $genbutton .= ' disabled';
874 }
875 $genbutton .= '>';
876 if ($allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') {
877 $langs->load("errors");
878 $genbutton .= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
879 /*if (empty($modellist)) {
880 $genbutton .= '<input type="hidden" name="model" value="auto">';
881 }*/
882 }
883 if (!$allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') {
884 $genbutton = '';
885 }
886 if (empty($modellist) && !$showempty && $modulepart != 'unpaid') {
887 $genbutton = '';
888 }
889 $out .= $genbutton;
890 $out .= '</th>';
891
892 if (!empty($hookmanager->hooks['formfile'])) {
893 foreach ($hookmanager->hooks['formfile'] as $module) {
894 if (method_exists($module, 'formBuilddocLineOptions')) {
895 $colspanmore++;
896 $out .= '<th></th>';
897 }
898 }
899 }
900 $out .= '</tr>';
901
902 // Execute hooks
903 $parameters = array('colspan' => ($colspan + $colspanmore), 'socid' => (isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id' => (isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'modulepart' => $modulepart);
904 if (is_object($hookmanager)) {
905 $reshook = $hookmanager->executeHooks('formBuilddocOptions', $parameters, $GLOBALS['object']);
906 $out .= $hookmanager->resPrint;
907 }
908 }
909
910 // Get list of files
911 if (!empty($filedir)) {
912 $link_list = array();
913 if (is_object($object)) {
914 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
915 $link = new Link($this->db);
916 $sortfield = $sortorder = '';
917 $res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder);
918 }
919
920 $out .= '<!-- html.formfile::showdocuments -->'."\n";
921
922 // Show title of array if not already shown
923 if ((!empty($file_list) || !empty($link_list) || preg_match('/^massfilesarea/', $modulepart))
924 && !$headershown) {
925 $headershown = 1;
926 $out .= '<div class="titre">'.$titletoshow.'</div>'."\n";
927 $out .= '<div class="div-table-responsive-no-min">';
928 $out .= '<table class="noborder centpercent" id="'.$modulepart.'_table">'."\n";
929 }
930
931 // Loop on each file found
932 if (is_array($file_list)) {
933 '@phan-var-force array<array{name:string,path:string,level1name:string,relativename:string,fullname:string,date:string,size:int,perm:int,type:string}> $file_list'; // phan limitations loose typing information with empty() tests, etc. Force again.
934 // Defined relative dir to DOL_DATA_ROOT
935 $relativedir = '';
936 if ($filedir) {
937 $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
938 $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
939 }
940
941 // Get list of files stored into database for same relative directory
942 if ($relativedir) {
943 completeFileArrayWithDatabaseInfo($file_list, $relativedir, $object);
944 '@phan-var-force array<array{name:string,path:string,level1name:string,relativename:string,fullname:string,date:string,size:int,perm:int,type:string,position_name:string,cover:string,keywords:string,acl:string,rowid:int,label:string,share:string}> $file_list';
945
946 //var_dump($sortfield.' - '.$sortorder);
947 if (!empty($sortfield) && !empty($sortorder)) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
948 $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
949 }
950 }
951
952 '@phan-var-force array<array{name:string,path:string,level1name:string,relativename:string,fullname:string,date:string,size:int,perm:int,type:string,position_name:string,cover:string,keywords:string,acl:string,rowid:int,label:string,share:string}> $file_list';
953
954 require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmfiles.class.php';
955
956 $i = 0;
957 foreach ($file_list as $file) {
958 $i++;
959
960 if (!empty($file['rowid']) && $user->hasRight('ecm', 'read')) {
961 // If we have permission to read ECM files, we can use link for ECM file (not blocked by security test),
962 // so it will show the expended information found into ECM table
963 $ecmfile = new EcmFiles($this->db);
964 $ecmfile->fetch($file['rowid']);
965 } else {
966 // If no permission to read ECM files, popup for ECM extended information will not work so we show a simple link with no popup.
967 $ecmfile = null;
968 }
969
970 // Define relative path for download link (depends on module)
971 $relativepath = (string) $file["name"]; // Cas general
972 if ($modulesubdir) {
973 $relativepath = (string) $modulesubdir."/".$file["name"]; // Cas propal, facture...
974 }
975 if ($modulepart == 'export') {
976 $relativepath = (string) $file["name"]; // Other case
977 }
978
979 $out .= '<tr class="oddeven'.((!$genallowed && $i == 1) ? ' trfirstline' : '').'">';
980
981 $documenturl = getDolGlobalString('DOL_URL_ROOT_DOCUMENT_PHP', DOL_URL_ROOT.'/document.php'); // DOL_URL_ROOT_DOCUMENT_PHP can be used to set another wrapper
982
983 // Show file name with link to download
984 $imgpreview = $this->showPreview($file, $modulepart, $relativepath, 0, $param);
985 $out .= '<td class="minwidth200 tdoverflowmax300">';
986 if ($imgpreview) {
987 $out .= '<span class="spanoverflow widthcentpercentminusx valignmiddle">';
988 } else {
989 $out .= '<span class="spanoverflow">';
990 }
991 if (getDolGlobalInt('PREVIEW_PICTO_ON_LEFT_OF_NAME')) {
992 $out .= $imgpreview;
993 }
994
995 if (is_object($ecmfile)) {
996 $out .= $ecmfile->getNomUrl(1, $modulepart, 0, 0, ' documentdownload'); // We show property in ECM
997 //$out .= $ecmfile->getNomUrl(1, $modulepart, 0, 0, ' documentdownload', $object); // We show property on object
998 } else {
999 $out .= '<a class="documentdownload paddingright" ';
1000 if (getDolGlobalInt('MAIN_DISABLE_FORCE_SAVEAS') == 2) {
1001 $out .= 'target="_blank" ';
1002 }
1003 $out .= 'href="'.$documenturl.'?modulepart='.$modulepart.'&file='.urlencode($relativepath).($param ? '&'.$param : '').'"';
1004 $mime = dol_mimetype($relativepath, '', 0);
1005 if (preg_match('/text/', $mime)) {
1006 $out .= ' target="_blank" rel="noopener noreferrer"';
1007 }
1008 $out .= ' title="'.dol_escape_htmltag($file["name"]).'"';
1009 $out .= '>';
1010 $out .= img_mime($file["name"], $langs->trans("File").': '.$file["name"]);
1011 $out .= dol_trunc($file["name"], 150);
1012 $out .= '</a>';
1013 }
1014
1015 $out .= '</span>'."\n";
1016 if (!getDolGlobalInt('PREVIEW_PICTO_ON_LEFT_OF_NAME')) {
1017 $out .= $imgpreview;
1018 }
1019 $out .= '</td>';
1020
1021
1022 // Show file size
1023 $size = (!empty($file['size']) ? $file['size'] : dol_filesize($filedir."/".$file["name"]));
1024 $out .= '<td class="nowraponall right" title="'.dolPrintHTML($size.' '.$langs->trans("Bytes")).'">'.dol_print_size($size, 1, 1).'</td>';
1025
1026 // Show file date
1027 $date = (!empty($file['date']) ? $file['date'] : dol_filemtime($filedir."/".$file["name"]));
1028 $out .= '<td class="nowrap right">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>';
1029
1030 // Show share link
1031 $out .= '<td class="nowraponall">';
1032 if (!empty($file['share'])) {
1033 // Define $urlwithroot
1034 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
1035 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
1036 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
1037
1038 //print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
1039 $forcedownload = 0;
1040 $paramlink = '';
1041 if (!empty($file['share'])) {
1042 $paramlink .= ($paramlink ? '&' : '').'hashp='.$file['share']; // Hash for public share
1043 }
1044 if ($forcedownload) {
1045 $paramlink .= ($paramlink ? '&' : '').'attachment=1';
1046 }
1047
1048 $fulllink = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : '');
1049
1050 $out .= '<a href="'.$fulllink.'" target="_blank" rel="noopener">'.img_picto($langs->trans("FileSharedViaALink"), 'globe').'</a> ';
1051 $out .= '<input type="text" class="quatrevingtpercentminusx width75 nopadding small" id="downloadlink'.$file['rowid'].'" name="downloadexternallink" title="'.dol_escape_htmltag($langs->trans("FileSharedViaALink")).'" value="'.dol_escape_htmltag($fulllink).'">';
1052 $out .= ajax_autoselect('downloadlink'.$file['rowid']);
1053 } else {
1054 //print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
1055 }
1056 $out .= '</td>';
1057
1058 // Show picto delete, print...
1059 if ($delallowed || $printer || $morepicto) {
1060 $out .= '<td class="right nowraponall">';
1061 if ($delallowed) {
1062 $tmpurlsource = preg_replace('/#[a-zA-Z0-9_]*$/', '', $urlsource);
1063 $out .= '<a class="reposition" href="'.$tmpurlsource.((strpos($tmpurlsource, '?') === false) ? '?' : '&').'action='.urlencode($removeaction).'&token='.newToken().'&file='.urlencode($relativepath);
1064 $out .= ($param ? '&'.$param : '');
1065 //$out.= '&modulepart='.$modulepart; // TODO obsolete ?
1066 //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
1067 $out .= '">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
1068 }
1069 if ($printer) {
1070 $out .= '<a class="marginleftonly reposition" href="'.$urlsource.(strpos($urlsource, '?') ? '&' : '?').'action=print_file&token='.newToken().'&printer='.urlencode($modulepart).'&file='.urlencode($relativepath);
1071 $out .= ($param ? '&'.$param : '');
1072 $out .= '">'.img_picto($langs->trans("PrintFile", $relativepath), 'printer.png').'</a>';
1073 }
1074 if ($morepicto) {
1075 $morepicto = preg_replace('/__FILENAMEURLENCODED__/', urlencode($relativepath), $morepicto);
1076 $out .= $morepicto;
1077 }
1078 $out .= '</td>';
1079 }
1080
1081 if (is_object($hookmanager)) {
1082 $addcolumforpicto = ($delallowed || $printer || $morepicto);
1083 $colspan = (4 + ($addcolumforpicto ? 1 : 0));
1084 $colspanmore = 0;
1085 $parameters = array('colspan' => ($colspan + $colspanmore), 'socid' => (isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id' => (isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'modulepart' => $modulepart, 'relativepath' => $relativepath);
1086 $res = $hookmanager->executeHooks('formBuilddocLineOptions', $parameters, $file);
1087 if (empty($res)) {
1088 $out .= $hookmanager->resPrint; // Complete line
1089 $out .= '</tr>';
1090 } else {
1091 $out = $hookmanager->resPrint; // Replace all $out
1092 }
1093 }
1094 }
1095
1096 $this->numoffiles++;
1097 }
1098 // Loop on each link found
1099 if (is_array($link_list)) {
1100 $colspan = 2;
1101
1102 foreach ($link_list as $file) {
1103 $out .= '<tr class="oddeven">';
1104 $out .= '<td colspan="'.$colspan.'" class="maxwidhtonsmartphone">';
1105 $out .= '<a data-ajax="false" href="'.$file->url.'" target="_blank" rel="noopener noreferrer">';
1106 $out .= $file->label;
1107 $out .= '</a>';
1108 $out .= '</td>';
1109 $out .= '<td class="right">';
1110 $out .= dol_print_date($file->datea, 'dayhour');
1111 $out .= '</td>';
1112 // for share link of files
1113 $out .= '<td></td>';
1114 if ($delallowed || $printer || $morepicto) {
1115 $out .= '<td></td>';
1116 }
1117 $out .= '</tr>'."\n";
1118 }
1119 $this->numoffiles++;
1120 }
1121
1122 if (count($file_list) == 0 && count($link_list) == 0 && $headershown) {
1123 $out .= '<tr><td colspan="'.(3 + ($addcolumforpicto ? 1 : 0)).'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>'."\n";
1124 }
1125 }
1126
1127 if ($headershown) {
1128 // Affiche pied du tableau
1129 $out .= "</table>\n";
1130 $out .= "</div>\n";
1131 if ($genallowed) {
1132 if (empty($noform)) {
1133 $out .= '</form>'."\n";
1134 }
1135 }
1136 }
1137 $out .= '<!-- End show_document -->'."\n";
1138
1139 $out .= '<script>
1140 jQuery(document).ready(function() {
1141 var selectedValue = $(".selectformat").val();
1142
1143 if (selectedValue === "excel2007" || selectedValue === "tsv") {
1144 $(".forhide").prop("disabled", true).hide();
1145 } else {
1146 $(".forhide").prop("disabled", false).show();
1147 }
1148 });
1149 </script>';
1150 //return ($i?$i:$headershown);
1151 return $out;
1152 }
1153
1167 public function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter = '', $morecss = 'valignmiddle', $allfiles = 0)
1168 {
1169 global $conf, $langs;
1170
1171 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1172
1173 $out = '';
1174 $this->infofiles = array('nboffiles' => 0, 'extensions' => array(), 'files' => array());
1175
1176 $entity = 1; // Without multicompany
1177
1178 // Get object entity
1179 if (isModEnabled('multicompany')) {
1180 $regs = array();
1181 preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir, '/').'$/', $filedir, $regs);
1182 $entity = ((!empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default
1183 }
1184
1185 // Get list of files starting with name of ref (Note: files with '^ref\.extension' are generated files, files with '^ref-...' are uploaded files)
1186 if ($allfiles || getDolGlobalString('MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP')) {
1187 $filterforfilesearch = '^'.preg_quote(basename($modulesubdir), '/');
1188 } else {
1189 $filterforfilesearch = '^'.preg_quote(basename($modulesubdir), '/').'\.';
1190 }
1191 $file_list = dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // We also discard .meta and .png preview
1192
1193 //var_dump($file_list);
1194 // For ajax treatment
1195 $out .= '<!-- html.formfile::getDocumentsLink -->'."\n";
1196 if (!empty($file_list)) {
1197 $out = '<dl class="dropdown inline-block">
1198 <dt><a data-ajax="false" href="#" onClick="return false;">'.img_picto('', 'listlight', '', 0, 0, 0, '', $morecss).'</a></dt>
1199 <dd><div class="multichoicedoc" style="position:absolute;left:100px;" ><ul class="ulselectedfields">';
1200 $tmpout = '';
1201
1202 // Loop on each file found
1203 $found = 0;
1204 $i = 0;
1205 foreach ($file_list as $file) {
1206 $i++;
1207 if ($filter && !preg_match('/'.$filter.'/i', $file["name"])) {
1208 continue; // Discard this. It does not match provided filter.
1209 }
1210
1211 $found++;
1212 // Define relative path for download link (depends on module)
1213 $relativepath = $file["name"]; // Cas general
1214 if ($modulesubdir) {
1215 $relativepath = (string) $modulesubdir."/".$file["name"]; // Cas propal, facture...
1216 }
1217 // Autre cas
1218 if ($modulepart == 'donation') {
1219 $relativepath = (string) get_exdir($modulesubdir, 2, 0, 0, null, 'donation').$file["name"];
1220 }
1221 if ($modulepart == 'export') {
1222 $relativepath = (string) $file["name"];
1223 }
1224
1225 $this->infofiles['nboffiles']++;
1226 $this->infofiles['files'][] = $file['fullname'];
1227 $ext = (string) pathinfo($file['name'], PATHINFO_EXTENSION); // pathinfo returns a string here (cast for static analysis)
1228 if (!array_key_exists($ext, $this->infofiles['extensions'])) {
1229 $this->infofiles['extensions'][$ext] = 1;
1230 } else {
1231 $this->infofiles['extensions'][$ext]++;
1232 }
1233
1234 // Preview
1235 if (!empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone')) {
1236 $tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity='.$entity);
1237 if ($tmparray && $tmparray['url']) {
1238 $tmpout .= '<li><a href="'.$tmparray['url'].'"'.($tmparray['css'] ? ' class="'.$tmparray['css'].'"' : '').($tmparray['mime'] ? ' mime="'.$tmparray['mime'].'"' : '').($tmparray['target'] ? ' target="'.$tmparray['target'].'"' : '').'>';
1239 //$tmpout.= img_picto('','detail');
1240 $tmpout .= img_picto('', 'search-plus', 'class="paddingright"');
1241 $tmpout .= $langs->trans("Preview").' '.$ext.'</a></li>';
1242 }
1243 }
1244
1245 // Download
1246 $tmpout .= '<li class="nowrap"><a class="pictopreview nowrap" ';
1247 if (getDolGlobalInt('MAIN_DISABLE_FORCE_SAVEAS') == 2) {
1248 $tmpout .= 'target="_blank" ';
1249 }
1250 $tmpout .= 'href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&amp;entity='.$entity.'&amp;file='.urlencode($relativepath).'"';
1251 $mime = dol_mimetype($relativepath, '', 0);
1252 if (preg_match('/text/', $mime)) {
1253 $tmpout .= ' target="_blank" rel="noopener noreferrer"';
1254 }
1255 $tmpout .= '>';
1256 $tmpout .= img_mime($relativepath, $file["name"]);
1257 $tmpout .= $langs->trans("Download").' '.$ext;
1258 $tmpout .= '</a></li>'."\n";
1259 }
1260 $out .= $tmpout;
1261 $out .= '</ul></div></dd>
1262 </dl>';
1263
1264 if (!$found) {
1265 $out = '';
1266 }
1267 } else {
1268 // TODO Add link to regenerate doc ?
1269 //$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
1270 }
1271
1272 return $out;
1273 }
1274
1275
1276 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1310 public function list_of_documents($filearray, $object, $modulepart, $param = '', $forcedownload = 0, $relativepath = '', $permonobject = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $title = '', $url = '', $showrelpart = 0, $permtoeditline = -1, $upload_dir = '', $sortfield = '', $sortorder = 'ASC', $disablemove = 1, $addfilterfields = 0, $disablecrop = -1, $moreattrondiv = '', $moreoptions = array())
1311 {
1312 // phpcs:enable
1313 global $user, $conf, $langs, $hookmanager, $form;
1314 global $sortfield, $sortorder;
1316
1317 if ($disablecrop == -1) {
1318 $disablecrop = 1;
1319 // Values here must be supported by the photos_resize.php page.
1320 if (in_array($modulepart, array('bank', 'bom', 'expensereport', 'facture', 'facture_fournisseur', 'holiday', 'medias', 'member', 'mrp', 'project', 'product', 'produit', 'propal', 'service', 'societe', 'tax', 'tax-vat', 'ticket', 'user'))) {
1321 $disablecrop = 0;
1322 }
1323 }
1324
1325 // Define relative path used to store the file
1326 if (empty($relativepath)) {
1327 $relativepath = (!empty($object->ref) ? dol_sanitizeFileName($object->ref) : '').'/';
1328 if (!empty($object->element) && $object->element == "societe" && !empty($object->id)) {
1329 $relativepath = ($object->id).'/';
1330 } elseif (!empty($object->element) && $object->element == 'invoice_supplier') {
1331 $relativepath = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$relativepath; // TODO Call using a defined value for $relativepath
1332 } elseif (!empty($object->element) && $object->element == 'project_task') {
1333 $relativepath = 'Call_not_supported_._Call_function_using_a_defined_relative_path_.';
1334 }
1335 }
1336 // For backward compatibility, we detect file stored into an old path
1337 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO') && isset($filearray[0]) && $filearray[0]['level1name'] == 'photos') {
1338 $relativepath = preg_replace('/^.*\/produit\//', '', $filearray[0]['path']).'/';
1339 }
1340
1341 // Defined relative dir to DOL_DATA_ROOT
1342 $relativedir = '';
1343 if ($upload_dir) {
1344 $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir);
1345 $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
1346 }
1347
1348 // For example here $upload_dir = '/pathtodocuments/commande/SO2001-123/'
1349 // For example here $upload_dir = '/pathtodocuments/tax/vat/1'
1350 // For example here $upload_dir = '/home/ldestailleur/git/dolibarr_dev/documents/fournisseur/facture/6/1/SI2210-0013' and relativedir='fournisseur/facture/6/1/SI2210-0013'
1351
1352 $hookmanager->initHooks(array('formfile'));
1353 $parameters = array(
1354 'filearray' => $filearray,
1355 'modulepart' => $modulepart,
1356 'param' => $param,
1357 'forcedownload' => $forcedownload,
1358 'relativepath' => $relativepath, // relative filename to module dir
1359 'relativedir' => $relativedir, // relative dirname to DOL_DATA_ROOT
1360 'permtodelete' => $permonobject,
1361 'useinecm' => $useinecm,
1362 'textifempty' => $textifempty,
1363 'maxlength' => $maxlength,
1364 'title' => $title,
1365 'url' => $url
1366 );
1367 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable
1368 $reshook = $hookmanager->executeHooks('showFilesList', $parameters, $object);
1369
1370 if (!empty($reshook)) { // null or '' for bypass
1371 return $reshook;
1372 } else {
1373 if (!is_object($form)) {
1374 include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; // The component may be included into ajax page that does not include the Form class
1375 $form = new Form($this->db);
1376 }
1377
1378 if (!preg_match('/&id=/', $param) && isset($object->id)) {
1379 $param .= '&id='.$object->id;
1380 }
1381 $relativepathwihtoutslashend = preg_replace('/\/$/', '', $relativepath);
1382 if ($relativepathwihtoutslashend) {
1383 $param .= '&file='.urlencode($relativepathwihtoutslashend);
1384 }
1385
1386 if ($permtoeditline < 0) { // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
1387 $permtoeditline = 0;
1388 if (in_array($modulepart, array('product', 'produit', 'service'))) {
1389 '@phan-var-force Product $object';
1390 if ($user->hasRight('produit', 'creer') && $object->type == Product::TYPE_PRODUCT) {
1391 $permtoeditline = 1;
1392 }
1393 if ($user->hasRight('service', 'creer') && $object->type == Product::TYPE_SERVICE) {
1394 $permtoeditline = 1;
1395 }
1396 }
1397 }
1398 if (!getDolGlobalString('MAIN_UPLOAD_DOC')) {
1399 $permtoeditline = 0;
1400 $permonobject = 0;
1401 }
1402 if (empty($url)) {
1403 $url = $_SERVER["PHP_SELF"];
1404 }
1405
1406
1407 // Show title of list of existing files
1408 $morehtmlright = '';
1409 if (!empty($moreoptions['showhideaddbutton']) && $conf->use_javascript_ajax) {
1410 $tmpurlforbutton = 'javascript:console.log("open add file form");jQuery(".divattachnewfile").toggle(); if (!jQuery(".divattachnewfile").is(":hidden")) { jQuery(".divattachnewfile input[type=\'file\']").first().click();}void(0);'; // scope file picker click to the just-shown form to avoid triggering native file dialog twice when other input[type=file] exist on the page
1411 $morehtmlright .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', $tmpurlforbutton, '', $permtoeditline);
1412 }
1413
1414 if ((empty($useinecm) || $useinecm == 3 || $useinecm == 6) && $title != 'none') {
1415 print load_fiche_titre($title ? $title : $langs->trans("AttachedFiles"), $morehtmlright, 'file-upload', 0, '', 'table-list-of-attached-files');
1416 }
1417 if (!empty($moreoptions) && $moreoptions['afteruploadtitle']) {
1418 print '<div class="divattachnewfile'.((!empty($moreoptions['showhideaddbutton']) && $conf->use_javascript_ajax) ? ' hidden' : '').'">'.$moreoptions['afteruploadtitle'].'</div>';
1419 }
1420
1421 // Show the table
1422 print '<!-- html.formfile::list_of_documents -->'."\n";
1423 if (GETPOST('action', 'aZ09') == 'editfile' && $permtoeditline) {
1424 print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" method="POST">';
1425 print '<input type="hidden" name="token" value="'.newToken().'">';
1426 print '<input type="hidden" name="action" value="renamefile">';
1427 print '<input type="hidden" name="id" value="'.(is_object($object) ? $object->id : '').'">';
1428 print '<input type="hidden" name="modulepart" value="'.$modulepart.'">';
1429 }
1430
1431 print '<div class="div-table-responsive-no-min"'.($moreattrondiv ? ' '.$moreattrondiv : '').'>';
1432 print '<table id="tablelines" class="centpercent liste noborder nobottom">'."\n";
1433
1434 if (!empty($addfilterfields)) {
1435 print '<tr class="liste_titre nodrag nodrop">';
1436 print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref', 'alpha')).'"></td>';
1437 print '<td></td>';
1438 print '<td></td>';
1439 if (empty($useinecm) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6) {
1440 print '<td></td>';
1441 }
1442 print '<td></td>';
1443 print '<td></td>';
1444 if (empty($disablemove) && count($filearray) > 1) {
1445 print '<td></td>';
1446 }
1447 print "</tr>\n";
1448 }
1449
1450 // Get list of files stored into database for the same relative directory
1451 if ($relativedir) {
1452 completeFileArrayWithDatabaseInfo($filearray, $relativedir, $object);
1453 '@phan-var-force array<array{name:string,path:string,level1name:string,relativename:string,fullname:string,date:string,size:int,perm:int,type:string,position_name:string,cover:string,keywords:string,acl:string,rowid:int,label:string,share:string}> $filearray';
1454
1455 //var_dump($sortfield.' - '.$sortorder);
1456 if ($sortfield && $sortorder) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
1457 $filearray = dol_sort_array($filearray, $sortfield, $sortorder, 1);
1458 }
1459 }
1460
1461 print '<tr class="liste_titre nodrag nodrop">';
1462 // Name
1463 print_liste_field_titre('Documents2', $url, "name", "", $param, '', $sortfield, $sortorder, 'left ');
1464 // Size
1465 print_liste_field_titre('Size', $url, "size", "", $param, '', $sortfield, $sortorder, 'right ');
1466 // Date
1467 print_liste_field_titre('Date', $url, "date", "", $param, '', $sortfield, $sortorder, 'center ');
1468 // Preview
1469 if (empty($useinecm) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6) {
1470 print_liste_field_titre('', $url, "", "", $param, '', $sortfield, $sortorder, 'center '); // Preview
1471 }
1472 // Shared or not - Hash of file
1473 print_liste_field_titre('Shared');
1474 // Action button
1476 if (empty($disablemove) && count($filearray) > 1) {
1477 // Move
1479 }
1480 print "</tr>\n";
1481
1482 $nboffiles = count($filearray);
1483 if ($nboffiles > 0) {
1484 include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1485 }
1486
1487 $i = 0;
1488 $nboflines = 0;
1489 $lastrowid = 0;
1490 $parametersByDefault = array(
1491 'modulepart' => $modulepart,
1492 'relativepath' => $relativepath,
1493 'permtoedit' => $permtoeditline,
1494 'permonobject' => $permonobject,
1495 );
1496 foreach ($filearray as $key => $file) { // filearray must be only files here
1497 if ($file['name'] != '.' && $file['name'] != '..' && !preg_match('/\.meta$/i', $file['name'])) {
1498 if (array_key_exists('rowid', $filearray[$key]) && $filearray[$key]['rowid'] > 0) {
1499 $lastrowid = $filearray[$key]['rowid'];
1500 }
1501 //var_dump($filearray[$key]);
1502
1503 // get specific parameters from file attributes if set or get default ones
1504 $modulepart = ($file['modulepart'] ?? $parametersByDefault['modulepart']);
1505 $relativepath = ($file['relativepath'] ?? $parametersByDefault['relativepath']);
1506 $permtoeditline = ($file['permtoedit'] ?? $parametersByDefault['permtoedit']);
1507 $permonobject = ($file['permonobject'] ?? $parametersByDefault['permonobject']);
1508
1509 // Note: for supplier invoice, $modulepart may be already 'facture_fournisseur' and $relativepath may be already '6/1/SI2210-0013/'
1510 if (empty($relativepath) || empty($modulepart)) {
1511 $filepath = $file['level1name'].'/'.$file['name'];
1512 } else {
1513 $filepath = $relativepath.$file['name'];
1514 }
1515 if (empty($modulepart)) {
1516 $modulepart = basename(dirname($file['path']));
1517 }
1518 if (empty($relativepath)) {
1519 $relativepath = preg_replace('/\/(.+)/', '', $filepath) . '/';
1520 }
1521
1522 $editline = 0;
1523 $nboflines++;
1524 print '<!-- Line list_of_documents '.$key.' relativepath = '.$relativepath.' -->'."\n";
1525 // Do we have entry into database ?
1526
1527 print '<!-- In database: position='.(array_key_exists('position', $filearray[$key]) ? $filearray[$key]['position'] : 0).' -->'."\n";
1528 print '<tr class="oddeven" id="row-'.((array_key_exists('rowid', $filearray[$key]) && $filearray[$key]['rowid'] > 0) ? $filearray[$key]['rowid'] : 'AFTER'.$lastrowid.'POS'.($i + 1)).'">';
1529
1530
1531 // File name
1532 print '<td class="minwidth200imp tdoverflowmax500" title="'.dolPrintHTMLForAttribute($file['name']).'">';
1533
1534 // Show file name with link to download
1535 //print "XX".$file['name']; //$file['name'] must be utf8
1536 print '<a class="paddingright valignmiddle" ';
1537 if (getDolGlobalInt('MAIN_DISABLE_FORCE_SAVEAS') == 2) {
1538 print 'target="_blank" ';
1539 }
1540 print 'href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1541 if ($forcedownload) {
1542 print '&attachment=1';
1543 }
1544 if (!empty($object->entity)) {
1545 print '&entity='.$object->entity;
1546 }
1547 print '&file='.urlencode($filepath);
1548 print '">';
1549 print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'], 0, 0).')', 'inline-block valignmiddle paddingright');
1550 if ($showrelpart == 1) {
1551 print $relativepath;
1552 }
1553 //print dol_trunc($file['name'],$maxlength,'middle');
1554
1555 //var_dump(dirname($filepath).' - '.dirname(GETPOST('urlfile', 'alpha')));
1556
1557 if (GETPOST('action', 'aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile', 'alpha')) && dirname($filepath) == dirname(GETPOST('urlfile', 'alpha'))) {
1558 print '</a>';
1559 $section_dir = dirname(GETPOST('urlfile', 'alpha'));
1560 if (!preg_match('/\/$/', $section_dir)) {
1561 $section_dir .= '/';
1562 }
1563 print '<input type="hidden" name="section_dir" value="'.$section_dir.'">';
1564 print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">';
1565 print '<input type="text" name="renamefileto" class="centpercentminusx" value="'.dol_escape_htmltag($file['name']).'">';
1566 $editline = 1;
1567 } else {
1568 $filenametoshow = preg_replace('/\.noexe$/', '', $file['name']);
1569 print dol_escape_htmltag(dol_trunc($filenametoshow, 200));
1570 print '</a>';
1571 }
1572 // Preview link
1573 if (!$editline) {
1574 print $this->showPreview($file, $modulepart, $filepath, 0, '&entity='.(empty($object->entity) ? $conf->entity : $object->entity));
1575 }
1576
1577 print "</td>\n";
1578
1579 // Size
1580 $sizetoshow = dol_print_size($file['size'], 1, 1);
1581 $sizetoshowbytes = dol_print_size($file['size'], 0, 1);
1582 print '<td class="right nowraponall">';
1583 if ($sizetoshow == $sizetoshowbytes) {
1584 print $sizetoshow;
1585 } else {
1586 print $form->textwithpicto($sizetoshow, $sizetoshowbytes, -1);
1587 }
1588 print '</td>';
1589
1590 // Date
1591 print '<td class="center nowraponall">'.dol_print_date($file['date'], "dayhour", "tzuser").'</td>';
1592
1593 // Preview
1594 if (empty($useinecm) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6) {
1595 $fileinfo = pathinfo($file['name']);
1596 print '<td class="center">';
1597 if (image_format_supported($file['name']) >= 0) {
1598 if ($useinecm == 5 || $useinecm == 6) {
1599 $smallfile = getImageFileNameForSize($file['name'], ''); // There is no thumb for ECM module and Media filemanager, so we use true image. TODO Change this for better performance.
1600 } else {
1601 $smallfile = getImageFileNameForSize($file['name'], '_small'); // For new thumbs using same ext (in lower case however) than original
1602 }
1603 if (!dol_is_file($file['path'].'/'.$smallfile)) {
1604 $smallfile = getImageFileNameForSize($file['name'], '_small', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
1605 }
1606 if (!dol_is_file($file['path'].'/'.$smallfile)) {
1607 $smallfile = getImageFileNameForSize($file['name'], ''); // This is in case no _small image exist
1608 }
1609 //print $file['path'].'/'.$smallfile.'<br>';
1610
1611 $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(empty($object->entity) ? $conf->entity : $object->entity));
1612 if (empty($urlforhref)) {
1613 $urlforhref = DOL_URL_ROOT.'/viewimage.php?modulepart='.urlencode($modulepart).'&entity='.(empty($object->entity) ? $conf->entity : $object->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
1614 print '<a href="'.$urlforhref.'" class="aphoto" target="_blank" rel="noopener noreferrer">';
1615 } else {
1616 print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
1617 }
1618 print '<img class="photo maxwidth200 shadow valignmiddle"';
1619 if ($useinecm == 4 || $useinecm == 5 || $useinecm == 6) {
1620 print ' height="20"';
1621 } else {
1622 //print ' style="max-height: '.$maxheightmini.'px"';
1623 print ' style="max-height: 24px"';
1624 }
1625 print ' src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.urlencode($modulepart).'&entity='.(empty($object->entity) ? $conf->entity : $object->entity).'&file='.urlencode($relativepath.$smallfile);
1626 if (!empty($filearray[$key]['date'])) { // We know the date of file, we can use it as cache key so URL will be in browser cache as long as file date is not modified.
1627 print '&cache='.urlencode((string) $filearray[$key]['date']);
1628 }
1629 print '" title="">';
1630 print '</a>';
1631 }
1632 print '</td>';
1633 }
1634
1635 // Shared or not - Hash of file
1636 print '<td class="center minwidth100 nowraponsmartphone">';
1637 if ($relativedir && $filearray[$key]['rowid'] > 0) { // only if we are in a mode where a scan of dir were done and we have id of file in ECM table
1638 if ($editline) {
1639 print '<label for="idshareenabled'.$key.'">'.$langs->trans("FileSharedViaALink").'</label> ';
1640 print '<input class="inline-block" type="checkbox" id="idshareenabled'.$key.'" name="shareenabled"'.($file['share'] ? ' checked="checked"' : '').' /> ';
1641 } else {
1642 if ($file['share']) {
1643 // Define $urlwithroot
1644 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
1645 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
1646 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
1647
1648 //print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
1649 $forcedownload = 0;
1650 $paramlink = '';
1651 if (!empty($file['share'])) {
1652 $paramlink .= ($paramlink ? '&' : '').'hashp='.$file['share']; // Hash for public share
1653 }
1654 if ($forcedownload) {
1655 $paramlink .= ($paramlink ? '&' : '').'attachment=1';
1656 }
1657
1658 $fulllink = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : '');
1659
1660 print '<!-- shared link -->';
1661 print '<a href="'.$fulllink.'" target="_blank" rel="noopener">'.img_picto($langs->trans("FileSharedViaALink"), 'globe').'</a> ';
1662 print '<input type="text" class="centpercentminusx minwidth50imp nopadding small" id="downloadlink'.$filearray[$key]['rowid'].'" name="downloadexternallink" title="'.dol_escape_htmltag($langs->trans("FileSharedViaALink")).'" value="'.dol_escape_htmltag($fulllink).'">';
1663 } else {
1664 //print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
1665 }
1666 }
1667 }
1668 print '</td>';
1669
1670 // Actions buttons (1 column or 2 if !disablemove)
1671 if (!$editline) {
1672 // Delete or view link
1673 // ($param must start with &)
1674 print '<td class="valignmiddle right actionbuttons nowraponall"><!-- action on files -->';
1675 if ($useinecm == 1 || $useinecm == 5) { // ECM manual tree only
1676 // $section is inside $param
1677 $newparam = preg_replace('/&file=.*$/', '', $param); // We don't need param file=
1678 $backtopage = DOL_URL_ROOT.'/ecm/index.php?&section_dir='.urlencode($relativepath).$newparam;
1679 print '<a class="editfielda editfilelink" href="'.DOL_URL_ROOT.'/ecm/file_card.php?urlfile='.urlencode($file['name']).$param.'&backtopage='.urlencode($backtopage).'" rel="'.urlencode($file['name']).'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>';
1680 }
1681
1682 if (empty($useinecm) || $useinecm == 2 || $useinecm == 3 || $useinecm == 6) { // 6=Media file manager
1683 $newmodulepart = $modulepart;
1684 if (in_array($modulepart, array('product', 'produit', 'service'))) {
1685 $newmodulepart = 'produit|service';
1686 }
1687 if (image_format_supported($file['name']) > 0) {
1688 if ($permtoeditline) {
1689 $moreparaminurl = '';
1690 if (!empty($object->id) && $object->id > 0) {
1691 $moreparaminurl .= '&id='.$object->id;
1692 } elseif (GETPOST('website', 'alpha')) {
1693 $moreparaminurl .= '&website='.GETPOST('website', 'alpha');
1694 }
1695 // Set the backtourl
1696 if ($modulepart == 'medias' && !GETPOST('website')) {
1697 $moreparaminurl .= '&backtourl='.urlencode(DOL_URL_ROOT.'/ecm/index_medias.php?file_manager=1&modulepart='.$modulepart.'&section_dir='.$relativepath);
1698 }
1699 // Link to convert into webp
1700 if (!preg_match('/\.webp$/i', $file['name'])) {
1701 if ($modulepart == 'medias' && !GETPOST('website')) {
1702 print '<a href="'.DOL_URL_ROOT.'/ecm/index_medias.php?action=confirmconvertimgwebp&token='.newToken().'&section_dir='.urlencode($relativepath).'&filetoregenerate='.urlencode($fileinfo['basename']).'&module='.$modulepart.$param.$moreparaminurl.'" title="'.dol_escape_htmltag($langs->trans("GenerateChosenImgWebp")).'">'.img_picto('', 'images', 'class="flip marginrightonly"').'</a>';
1703 } elseif ($modulepart == 'medias' && GETPOST('website')) {
1704 print '<a href="'.DOL_URL_ROOT.'/website/index.php?action=confirmconvertimgwebp&token='.newToken().'&section_dir='.urlencode($relativepath).'&filetoregenerate='.urlencode($fileinfo['basename']).'&module='.$modulepart.$param.$moreparaminurl.'" title="'.dol_escape_htmltag($langs->trans("GenerateChosenImgWebp")).'">'.img_picto('', 'images', 'class="flip marginrightonly"').'</a>';
1705 }
1706 }
1707 }
1708 }
1709 if (!$disablecrop && image_format_supported($file['name']) > 0) {
1710 if ($permtoeditline) {
1711 // Link to resize
1712 $moreparaminurl = '';
1713 if (!empty($object->id) && $object->id > 0) {
1714 $moreparaminurl .= '&id='.$object->id;
1715 } elseif (GETPOST('website', 'alpha')) {
1716 $moreparaminurl .= '&website='.GETPOST('website', 'alpha');
1717 }
1718 // Set the backtourl
1719 if ($modulepart == 'medias' && !GETPOST('website')) {
1720 $moreparaminurl .= '&backtourl='.urlencode(DOL_URL_ROOT.'/ecm/index_medias.php?file_manager=1&modulepart='.$modulepart.'&section_dir='.$relativepath);
1721 }
1722 //var_dump($moreparaminurl);
1723 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).$moreparaminurl.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("ResizeOrCrop")).'">'.img_picto($langs->trans("ResizeOrCrop"), 'resize', 'class="paddingrightonly"').'</a>';
1724 }
1725 }
1726
1727 if ($permtoeditline) {
1728 $paramsectiondir = (in_array($modulepart, array('medias', 'ecm')) ? '&section_dir='.urlencode($relativepath) : '');
1729 print '<a class="editfielda reposition editfilelink paddingright marginleftonly" href="'.(($useinecm == 1 || $useinecm == 5) ? '#' : ($url.'?action=editfile&token='.newToken().'&urlfile='.urlencode($filepath).$paramsectiondir.$param)).'" rel="'.$filepath.'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>';
1730 }
1731 }
1732 // Output link to delete file
1733 if ($permonobject) {
1734 $useajax = 1;
1735 if (!empty($conf->dol_use_jmobile)) {
1736 $useajax = 0;
1737 }
1738 if (empty($conf->use_javascript_ajax)) {
1739 $useajax = 0;
1740 }
1741 if (getDolGlobalString('MAIN_ECM_DISABLE_JS')) {
1742 $useajax = 0;
1743 }
1744
1745 print '<a href="'.((($useinecm && $useinecm != 3 && $useinecm != 6) && $useajax) ? '#' : ($url.'?action=deletefile&token='.newToken().'&urlfile='.urlencode($filepath).$param)).'" class="reposition deletefilelink paddingright marginleftonly" rel="'.$filepath.'">'.img_delete().'</a>';
1746 }
1747 print "</td>";
1748
1749 if (empty($disablemove) && count($filearray) > 1) {
1750 if ($nboffiles > 1 && $conf->browser->layout != 'phone') {
1751 print '<td class="linecolmove tdlineupdown center">';
1752 if ($i > 0) {
1753 print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=up&rowid='.$object->id.'">'.img_up('default', 0, 'imgupforline').'</a>';
1754 }
1755 if ($i < ($nboffiles - 1)) {
1756 print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=down&rowid='.$object->id.'">'.img_down('default', 0, 'imgdownforline').'</a>';
1757 }
1758 print '</td>';
1759 } else {
1760 print '<td'.(($conf->browser->layout != 'phone') ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'>';
1761 print '</td>';
1762 }
1763 }
1764 } else {
1765 print '<td class="right">';
1766 print '<input type="hidden" name="ecmfileid" value="'.(empty($filearray[$key]['rowid']) ? '' : $filearray[$key]['rowid']).'">';
1767 print '<input type="submit" class="button button-save smallpaddingimp" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
1768 print '<input type="submit" class="button button-cancel smallpaddingimp" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
1769 print '</td>';
1770 if (empty($disablemove) && count($filearray) > 1) {
1771 print '<td class="right"></td>';
1772 }
1773 }
1774 print "</tr>\n";
1775
1776 $i++;
1777 }
1778 }
1779 if ($nboffiles == 0) {
1780 $colspan = '6';
1781 if (empty($disablemove) && count($filearray) > 1) {
1782 $colspan++; // 6 columns or 7
1783 }
1784 print '<tr class="oddeven"><td colspan="'.$colspan.'">';
1785 if (empty($textifempty)) {
1786 print '<span class="opacitymedium">'.$langs->trans("NoFileFound").'</span>';
1787 } else {
1788 print '<span class="opacitymedium">'.$textifempty.'</span>';
1789 }
1790 print '</td></tr>';
1791 }
1792
1793 print "</table>";
1794 print '</div>';
1795
1796 if ($nboflines > 1 && is_object($object)) {
1797 if (!empty($conf->use_javascript_ajax) && $permtoeditline) {
1798 $table_element_line = 'ecm_files'; // used by ajaxrow.tpl.php
1799 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
1800 }
1801 }
1802
1803 print ajax_autoselect('downloadlink');
1804
1805 if (GETPOST('action', 'aZ09') == 'editfile' && $permtoeditline) {
1806 print '</form>';
1807 }
1808
1809 return $nboffiles;
1810 }
1811 }
1812
1813
1814 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1833 public function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload = 0, $relativepath = '', $permissiontodelete = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $url = '', $addfilterfields = 0)
1834 {
1835 // phpcs:enable
1836 global $conf, $langs, $hookmanager, $form;
1837 global $sortfield, $sortorder;
1838 global $search_doc_ref;
1840
1841 dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart);
1842
1843 // Show list of documents
1844 if (empty($useinecm) || $useinecm == 6) {
1845 print load_fiche_titre($langs->trans("AttachedFiles"));
1846 }
1847 if (empty($url)) {
1848 $url = $_SERVER["PHP_SELF"];
1849 }
1850
1851 if (!empty($addfilterfields)) {
1852 print '<form action="'.$_SERVER['PHP_SELF'].'">';
1853 print '<input type="hidden" name="token" value="'.newToken().'">';
1854 print '<input type="hidden" name="module" value="'.$modulepart.'">';
1855 }
1856
1857 print '<div class="div-table-responsive-no-min">';
1858 print '<table class="noborder centpercent">'."\n";
1859
1860 if (!empty($addfilterfields)) {
1861 print '<tr class="liste_titre nodrag nodrop">';
1862 // Ref
1863 print '<td class="liste_titre"></td>';
1864 // Name
1865 print '<td class="liste_titre"><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"></td>';
1866 // Size
1867 print '<td class="liste_titre"></td>';
1868 // Date
1869 print '<td class="liste_titre"></td>';
1870 // Shared and action column
1871 print '<td class="liste_titre right">';
1872 $searchpicto = $form->showFilterButtons();
1873 print $searchpicto;
1874 print '</td>';
1875 print "</tr>\n";
1876 }
1877
1878 print '<tr class="liste_titre">';
1879 $sortref = "fullname";
1880 if ($modulepart == 'invoice_supplier') {
1881 $sortref = 'level1name';
1882 }
1883 print_liste_field_titre("Ref", $url, $sortref, "", $param, '', $sortfield, $sortorder);
1884 print_liste_field_titre("Documents2", $url, "name", "", $param, '', $sortfield, $sortorder);
1885 print_liste_field_titre("Size", $url, "size", "", $param, '', $sortfield, $sortorder, 'right ');
1886 print_liste_field_titre("Date", $url, "date", "", $param, '', $sortfield, $sortorder, 'center ');
1887 print_liste_field_titre("Shared", $url, 'share', '', $param, '', $sortfield, $sortorder, 'right ');
1888 print '</tr>'."\n";
1889
1890 // To show ref or specific information according to view to show (defined by $module)
1891 $object_instance = null;
1892 if ($modulepart == 'company') {
1893 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1894 $object_instance = new Societe($this->db);
1895 } elseif ($modulepart == 'invoice') {
1896 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1897 $object_instance = new Facture($this->db);
1898 } elseif ($modulepart == 'invoice_supplier') {
1899 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1900 $object_instance = new FactureFournisseur($this->db);
1901 } elseif ($modulepart == 'propal') {
1902 include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
1903 $object_instance = new Propal($this->db);
1904 } elseif ($modulepart == 'supplier_proposal') {
1905 include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
1906 $object_instance = new SupplierProposal($this->db);
1907 } elseif ($modulepart == 'order') {
1908 include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
1909 $object_instance = new Commande($this->db);
1910 } elseif ($modulepart == 'order_supplier') {
1911 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
1912 $object_instance = new CommandeFournisseur($this->db);
1913 } elseif ($modulepart == 'contract') {
1914 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
1915 $object_instance = new Contrat($this->db);
1916 } elseif ($modulepart == 'product') {
1917 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1918 $object_instance = new Product($this->db);
1919 } elseif ($modulepart == 'tax') {
1920 include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
1921 $object_instance = new ChargeSociales($this->db);
1922 } elseif ($modulepart == 'tax-vat') {
1923 include_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
1924 $object_instance = new Tva($this->db);
1925 } elseif ($modulepart == 'salaries') {
1926 include_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
1927 $object_instance = new Salary($this->db);
1928 } elseif ($modulepart == 'project') {
1929 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1930 $object_instance = new Project($this->db);
1931 } elseif ($modulepart == 'project_task') {
1932 include_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
1933 $object_instance = new Task($this->db);
1934 } elseif ($modulepart == 'fichinter') {
1935 include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
1936 $object_instance = new Fichinter($this->db);
1937 } elseif ($modulepart == 'user') {
1938 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1939 $object_instance = new User($this->db);
1940 } elseif ($modulepart == 'expensereport') {
1941 include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1942 $object_instance = new ExpenseReport($this->db);
1943 } elseif ($modulepart == 'holiday') {
1944 include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
1945 $object_instance = new Holiday($this->db);
1946 } elseif ($modulepart == 'recruitment-recruitmentcandidature') {
1947 include_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentcandidature.class.php';
1948 $object_instance = new RecruitmentCandidature($this->db);
1949 } elseif ($modulepart == 'banque') {
1950 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1951 $object_instance = new Account($this->db);
1952 } elseif ($modulepart == 'bank-statement') {
1953 //include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1954 $object_instance = null;
1955 } elseif ($modulepart == 'chequereceipt') {
1956 include_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
1957 $object_instance = new RemiseCheque($this->db);
1958 } elseif ($modulepart == 'mrp-mo') {
1959 include_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
1960 $object_instance = new Mo($this->db);
1961 } else {
1962 $parameters = array('modulepart' => $modulepart);
1963 $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters);
1964 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
1965 if (array_key_exists('classpath', $hookmanager->resArray) && !empty($hookmanager->resArray['classpath'])) {
1966 dol_include_once($hookmanager->resArray['classpath']);
1967 if (array_key_exists('classname', $hookmanager->resArray) && !empty($hookmanager->resArray['classname'])) {
1968 $tmpclassname = $hookmanager->resArray['classname'];
1969 if (is_string($tmpclassname) && class_exists($tmpclassname)) {
1970 $object_instance = new $tmpclassname($this->db);
1971 }
1972 }
1973 }
1974 }
1975 }
1976
1977 //var_dump($filearray);
1978 //var_dump($object_instance);
1979
1980 // Get list of files stored into database for same relative directory
1981 $relativepathfromroot = preg_replace('/'.preg_quote(DOL_DATA_ROOT.'/', '/').'/', '', $upload_dir);
1982 if ($relativepathfromroot) {
1983 completeFileArrayWithDatabaseInfo($filearray, $relativepathfromroot.'/%');
1984 '@phan-var-force array<array{name:string,path:string,level1name:string,relativename:string,fullname:string,date:string,size:int,perm:int,type:string,position_name:string,cover:string,keywords:string,acl:string,rowid:int,label:string,share:string}> $filearray';
1985
1986 //var_dump($sortfield.' - '.$sortorder);
1987 if ($sortfield && $sortorder) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
1988 $filearray = dol_sort_array($filearray, $sortfield, $sortorder, 1);
1989 }
1990 }
1991
1992 //var_dump($filearray);
1993
1994 foreach ($filearray as $key => $file) {
1995 if (!is_dir($file['name'])
1996 && $file['name'] != '.'
1997 && $file['name'] != '..'
1998 && $file['name'] != 'CVS'
1999 && !preg_match('/\.meta$/i', $file['name'])) {
2000 // Define relative path used to store the file
2001 $relativefile = preg_replace('/'.preg_quote($upload_dir.'/', '/').'/', '', $file['fullname']);
2002
2003 $id = 0;
2004 $ref = '';
2005
2006 // To show ref or specific information according to view to show (defined by $modulepart)
2007 // $modulepart can be $object->table_name (that is 'mymodule_myobject') or $object->element.'-'.$module (for compatibility purpose)
2008 $reg = array();
2009 if ($modulepart == 'company' || $modulepart == 'tax' || $modulepart == 'tax-vat' || $modulepart == 'salaries') {
2010 preg_match('/(\d+)\/[^\/]+$/', $relativefile, $reg);
2011 $id = (isset($reg[1]) ? $reg[1] : '');
2012 } elseif ($modulepart == 'invoice_supplier') {
2013 preg_match('/([^\/]+)\/[^\/]+$/', $relativefile, $reg);
2014 $ref = (isset($reg[1]) ? $reg[1] : '');
2015 if (is_numeric($ref)) {
2016 $id = $ref;
2017 $ref = '';
2018 }
2019 } elseif ($modulepart == 'user') {
2020 // $ref may be also id with old supplier invoices
2021 preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg);
2022 $id = (isset($reg[1]) ? $reg[1] : '');
2023 } elseif ($modulepart == 'project_task') {
2024 // $ref of task is the sub-directory of the project
2025 $reg = explode("/", $relativefile);
2026 $ref = (isset($reg[1]) ? $reg[1] : '');
2027 } elseif (in_array($modulepart, array(
2028 'invoice',
2029 'propal',
2030 'supplier_proposal',
2031 'order',
2032 'order_supplier',
2033 'contract',
2034 'product',
2035 'project',
2036 'project_task',
2037 'fichinter',
2038 'expensereport',
2039 'recruitment-recruitmentcandidature',
2040 'mrp-mo',
2041 'banque',
2042 'chequereceipt',
2043 'holiday'))) {
2044 preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg);
2045 $ref = (isset($reg[1]) ? $reg[1] : '');
2046 } else {
2047 $parameters = array('modulepart' => $modulepart, 'fileinfo' => $file);
2048 $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters);
2049 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
2050 if (array_key_exists('ref', $hookmanager->resArray) && !empty($hookmanager->resArray['ref'])) {
2051 $ref = $hookmanager->resArray['ref'];
2052 }
2053 if (array_key_exists('id', $hookmanager->resArray) && !empty($hookmanager->resArray['id'])) {
2054 $id = $hookmanager->resArray['id'];
2055 }
2056 }
2057 //print 'Error: Value for modulepart = '.$modulepart.' is not yet implemented in function list_of_autoecmfiles'."\n";
2058 }
2059
2060 if (!$id && !$ref) {
2061 continue;
2062 }
2063
2064 $found = 0;
2065 if (!empty($conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref])) {
2066 $found = 1;
2067 } else {
2068 //print 'Fetch '.$id." - ".$ref.' class='.get_class($object_instance).'<br>';
2069
2070 $result = 0;
2071 if (is_object($object_instance)) {
2072 $object_instance->id = 0;
2073 $object_instance->ref = '';
2074 if ($id) {
2075 $result = $object_instance->fetch($id);
2076 } else {
2077 if (!($result = $object_instance->fetch(0, $ref))) {
2078 // fetchOneLike looks for objects with wildcards in its reference.
2079 // It is useful for those masks who get underscores instead of their actual symbols (because the _ had replaced all forbidden chars into filename)
2080 // TODO Example when this is needed ?
2081 // This may find when ref is 'A_B' and date was stored as 'A~B' into database, but in which case do we have this ?
2082 // May be we can add hidden option to enable this.
2083 $result = $object_instance->fetchOneLike($ref);
2084 }
2085 }
2086 }
2087
2088 if ($result > 0) { // Save object loaded into a cache
2089 $found = 1;
2090 $conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref] = clone $object_instance;
2091 }
2092 if ($result == 0) {
2093 $found = 1;
2094 $conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref] = 'notfound';
2095 unset($filearray[$key]);
2096 }
2097 }
2098
2099 if ($found <= 0 || !is_object($conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref])) {
2100 continue; // We do not show orphelins files
2101 }
2102
2103 print '<!-- Line list_of_autoecmfiles key='.$key.' -->'."\n";
2104 print '<tr class="oddeven">';
2105 // Ref
2106 print '<td class="tdoverflowmax150">';
2107 if ($found > 0 && is_object($conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref])) {
2108 $tmpobject = $conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref];
2109 //if (! in_array($tmpobject->element, array('expensereport'))) {
2110 print $tmpobject->getNomUrl(1, 'document');
2111 //} else {
2112 // print $tmpobject->getNomUrl(1);
2113 //}
2114 } else {
2115 print $langs->trans("ObjectDeleted", ($id ? $id : $ref));
2116 }
2117
2118 //$modulesubdir=dol_sanitizeFileName($ref);
2119 //$modulesubdir = dirname($relativefile);
2120
2121 //$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref);
2122 //$filedir = $file['path'];
2123 //$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
2124 //print $formfile->getDocumentsLink($modulepart, $filename, $filedir);
2125 print '</td>';
2126
2127 // File
2128 // Check if document source has external module part, if it the case use it for module part on document.php
2129 print '<td>';
2130 //print "XX".$file['name']; //$file['name'] must be utf8
2131 print '<a ';
2132 if (getDolGlobalInt('MAIN_DISABLE_FORCE_SAVEAS') == 2) {
2133 print 'target="_blank" ';
2134 }
2135 print 'href="'.DOL_URL_ROOT.'/document.php?modulepart='.urlencode($modulepart);
2136 if ($forcedownload) {
2137 print '&attachment=1';
2138 }
2139 print '&file='.urlencode($relativefile).'">';
2140 print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'], 0, 0).')');
2141 print dol_escape_htmltag(dol_trunc($file['name'], $maxlength, 'middle'));
2142 print '</a>';
2143
2144 //print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$');
2145
2146 print $this->showPreview($file, $modulepart, $file['relativename']);
2147
2148 print "</td>\n";
2149
2150 // Size
2151 $sizetoshow = dol_print_size($file['size'], 1, 1);
2152 $sizetoshowbytes = dol_print_size($file['size'], 0, 1);
2153 print '<td class="right nowraponall">';
2154 if ($sizetoshow == $sizetoshowbytes) {
2155 print $sizetoshow;
2156 } else {
2157 print $form->textwithpicto($sizetoshow, $sizetoshowbytes, -1);
2158 }
2159 print '</td>';
2160
2161 // Date
2162 print '<td class="center">'.dol_print_date($file['date'], "dayhour").'</td>';
2163
2164 // Share link
2165 print '<td class="right">';
2166 if (!empty($file['share'])) {
2167 // Define $urlwithroot
2168 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
2169 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
2170 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2171
2172 //print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
2173 $forcedownload = 0;
2174 $paramlink = '';
2175 if (!empty($file['share'])) {
2176 $paramlink .= ($paramlink ? '&' : '').'hashp='.$file['share']; // Hash for public share
2177 }
2178 if ($forcedownload) {
2179 $paramlink .= ($paramlink ? '&' : '').'attachment=1';
2180 }
2181
2182 $fulllink = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : '');
2183
2184 print '<!-- shared link -->';
2185 print img_picto($langs->trans("FileSharedViaALink"), 'globe').' ';
2186 print '<input type="text" class="quatrevingtpercent width100 nopadding nopadding small" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).'">';
2187 }
2188 //if (!empty($useinecm) && $useinecm != 6) print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
2189 //if ($forcedownload) print '&attachment=1';
2190 //print '&file='.urlencode($relativefile).'">';
2191 //print img_view().'</a> &nbsp; ';
2192 //if ($permissiontodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&token='.newToken().'&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
2193 //else print '&nbsp;';
2194 print "</td>";
2195
2196 print "</tr>\n";
2197 }
2198 }
2199
2200 if (count($filearray) == 0) {
2201 print '<tr class="oddeven"><td colspan="5">';
2202 if (empty($textifempty)) {
2203 print '<span class="opacitymedium">'.$langs->trans("NoFileFound").'</span>';
2204 } else {
2205 print '<span class="opacitymedium">'.$textifempty.'</span>';
2206 }
2207 print '</td></tr>';
2208 }
2209 print "</table>";
2210 print '</div>';
2211
2212 if (!empty($addfilterfields)) {
2213 print '</form>';
2214 }
2215 return count($filearray);
2216 // Fin de zone
2217 }
2218
2231 public function listOfLinks($object, $permissiontodelete = 1, $action = null, $selected = null, $param = '', $htmlname = 'formaddlink', $moreoptions = array())
2232 {
2233 global $conf, $langs;
2234 global $sortfield, $sortorder;
2235
2236 $langs->load("link");
2237
2238 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
2239 $link = new Link($this->db);
2240 $links = array();
2241 if ($sortfield == "name") {
2242 $sortfield = "label";
2243 } elseif ($sortfield == "date") {
2244 $sortfield = "datea";
2245 } else {
2246 $sortfield = '';
2247 }
2248 $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder);
2249 $param .= (isset($object->id) && !preg_match('/&id='.$object->id.'/i', $param) ? '&id='.$object->id : '');
2250
2251 $permissiontoedit = $permissiontodelete;
2252
2253 print '<!-- listOfLinks -->'."\n";
2254
2255 $morehtmlright = '';
2256 if (!empty($moreoptions['showhideaddbutton']) && $conf->use_javascript_ajax) {
2257 $morehtmlright .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', 'javascript:console.log("open addlink form"); jQuery(".divlinkfile").toggle(); void(0);', '', $permissiontoedit);
2258 }
2259
2260 // Show list of associated links
2261 print load_fiche_titre($langs->trans("LinkedFiles"), $morehtmlright, 'link', 0, '', 'table-list-of-links');
2262
2263 if (!empty($moreoptions) && $moreoptions['afterlinktitle']) {
2264 print '<div class="divlinkfile'.((!empty($moreoptions['showhideaddbutton']) && $conf->use_javascript_ajax) ? ' hidden' : '').'">'.$moreoptions['afterlinktitle'].'</div>';
2265 }
2266
2267 print '<form action="'.$_SERVER['PHP_SELF'].($param ? '?'.$param : '').'" id="'.$htmlname.'" method="POST">';
2268 print '<input type="hidden" name="token" value="'.newToken().'">';
2269
2270 print '<table class="liste noborder nobottom centpercent">';
2271 print '<tr class="liste_titre">';
2273 $langs->trans("Links"),
2274 $_SERVER['PHP_SELF'],
2275 "name",
2276 "",
2277 $param,
2278 '',
2279 $sortfield,
2280 $sortorder,
2281 ''
2282 );
2284 "",
2285 "",
2286 "",
2287 "",
2288 "",
2289 '',
2290 '',
2291 '',
2292 'right '
2293 );
2295 $langs->trans("Date"),
2296 $_SERVER['PHP_SELF'],
2297 "date",
2298 "",
2299 $param,
2300 '',
2301 $sortfield,
2302 $sortorder,
2303 'center '
2304 );
2306 '',
2307 $_SERVER['PHP_SELF'],
2308 "",
2309 "",
2310 $param,
2311 '',
2312 '',
2313 '',
2314 'center '
2315 );
2316 // Shared or not - Hash of file
2317 print_liste_field_titre('', '', '');
2318 print '</tr>';
2319 $nboflinks = count($links);
2320 if ($nboflinks > 0) {
2321 include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
2322 }
2323 foreach ($links as $key => $link) {
2324 print '<tr class="oddeven">';
2325 //edit mode
2326 if ($action == 'update' && (int) $selected === (int) $link->id && $permissiontoedit) {
2327 print '<td>';
2328 print '<input type="hidden" name="id" value="'.$object->id.'">';
2329 print '<input type="hidden" name="linkid" value="'.$link->id.'">';
2330 print '<input type="hidden" name="action" value="confirm_updateline">';
2331 print $langs->trans('Link').': <input type="text" name="link" value="'.$link->url.'">';
2332 print '</td>';
2333 print '<td>';
2334 print $langs->trans('Label').': <input type="text" name="label" value="'.dol_escape_htmltag($link->label).'">';
2335 print '</td>';
2336 print '<td class="center">'.dol_print_date(dol_now(), "dayhour", "tzuser").'</td>';
2337 print '<td class="right">';
2338 print '<label for="idshareenabled'.$key.'">'.$langs->trans("LinkSharedViaALink").'</label> ';
2339 print '<input class="inline-block" type="checkbox" id="idshareenabled'.$key.'" name="shareenabled"'.($link->share ? ' checked="checked"' : '').' /> ';
2340 print '</td>';
2341 print '<td class="right">';
2342 print '<input type="submit" class="button button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
2343 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
2344 print '</td>';
2345 } else {
2346 print '<td>';
2347 print img_picto('', 'globe').' ';
2348 print '<a data-ajax="false" href="'.$link->url.'" target="_blank" rel="noopener noreferrer">';
2349 print dol_escape_htmltag($link->label);
2350 print '</a>';
2351 print '</td>'."\n";
2352 print '<td class="right"></td>';
2353 print '<td class="center">'.dol_print_date($link->datea, "dayhour", "tzuser").'</td>';
2354 print '<td class="center">';
2355 if ($link->share) {
2357 $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root));
2358 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT; // This is to use external domain name found into config file
2359 $fulllink = $urlwithroot.'/document.php?type=link&hashp=' . $link->share;
2360
2361 print '<a href="'.$fulllink.'" target="_blank" rel="noopener">'.img_picto($langs->trans("FileSharedViaALink"), 'globe').'</a> ';
2362 print '<input type="text" class="centpercentminusx minwidth200imp nopadding small" id="downloadlink'.$link->id.'" name="downloadexternallink" title="'.dol_escape_htmltag($langs->trans("LinkSharedViaALink")).'" value="'.dol_escape_htmltag($fulllink).'">';
2363 }
2364 print '</td>';
2365 print '<td class="right">';
2366 print '<a href="'.$_SERVER['PHP_SELF'].'?action=update&linkid='.$link->id.$param.'&token='.newToken().'" class="editfilelink editfielda reposition" >'.img_edit().'</a>'; // id= is included into $param
2367 if ($permissiontodelete) {
2368 print ' &nbsp; <a class="deletefilelink reposition" href="'.$_SERVER['PHP_SELF'].'?action=deletelink&token='.newToken().'&linkid='.((int) $link->id).$param.'">'.img_delete().'</a>'; // id= is included into $param
2369 } else {
2370 print '&nbsp;';
2371 }
2372 print '</td>';
2373 }
2374 print "</tr>\n";
2375 }
2376 if ($nboflinks == 0) {
2377 print '<tr class="oddeven"><td colspan="5">';
2378 print '<span class="opacitymedium">'.$langs->trans("NoLinkFound").'</span>';
2379 print '</td></tr>';
2380 }
2381 print "</table>";
2382
2383 print '</form>';
2384
2385 return $nboflinks;
2386 }
2387
2388
2399 public function showPreview($file, $modulepart, $relativepath, $ruleforpicto = 0, $param = '')
2400 {
2401 global $langs, $conf;
2402
2403 $out = '';
2404 if ($conf->browser->layout != 'phone' && !empty($conf->use_javascript_ajax)) {
2405 $urladvancedpreview = getAdvancedPreviewUrl($modulepart, $relativepath, 1, $param); // Return if a file is qualified for preview.
2406 if (count($urladvancedpreview)) {
2407 $out .= '<a class="pictopreview '.$urladvancedpreview['css'].'" href="'.$urladvancedpreview['url'].'"'.(empty($urladvancedpreview['mime']) ? '' : ' mime="'.$urladvancedpreview['mime'].'"').' '.(empty($urladvancedpreview['target']) ? '' : ' target="'.$urladvancedpreview['target'].'"').'>';
2408 //$out.= '<a class="pictopreview">';
2409 if (empty($ruleforpicto)) {
2410 $out .= img_picto('', 'search-plus', 'class="pictofixedwidth"');
2411 } else {
2412 $out .= img_mime($relativepath, $langs->trans('Preview').' '.$file['name'], 'pictofixedwidth');
2413 }
2414 $out .= '</a>';
2415 } else {
2416 if ($ruleforpicto < 0) {
2417 $out .= img_picto('', 'generic', '', 0, 0, 0, '', 'paddingright pictofixedwidth');
2418 }
2419 }
2420 }
2421 return $out;
2422 }
2423}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
global $dolibarr_main_url_root
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:475
Class to manage bank accounts.
Class for managing the social charges.
Class to manage predefined suppliers products.
Class to manage customers orders.
Class to manage ECM files.
Class to manage Trips and Expenses.
Class to manage suppliers invoices.
Class to manage invoices.
Class to generate html code for admin pages.
Class to offer components to list and upload files.
showImageToEdit(string $htmlname, string $modulepart, string $dirformainimage, string $subdirformainimage, string $fileformainimage)
Show an image with feature to edit it.
showPreview($file, $modulepart, $relativepath, $ruleforpicto=0, $param='')
Show detail icon with link for preview.
list_of_autoecmfiles($upload_dir, $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.
showdocuments($modulepart, $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed=0, $modelselected='', $allowgenifempty=1, $forcenomultilang=0, $iconPDF=0, $notused=0, $noform=0, $param='', $title='', $buttonlabel='', $codelang='', $morepicto='', $object=null, $hideifempty=0, $removeaction='remove_file', $tooltipontemplatecombo='')
Return a string to show the box with list of available documents for object.
list_of_documents($filearray, $object, $modulepart, $param='', $forcedownload=0, $relativepath='', $permonobject=1, $useinecm=0, $textifempty='', $maxlength=0, $title='', $url='', $showrelpart=0, $permtoeditline=-1, $upload_dir='', $sortfield='', $sortorder='ASC', $disablemove=1, $addfilterfields=0, $disablecrop=-1, $moreattrondiv='', $moreoptions=array())
Show list of documents in $filearray (may be they are all in same directory but may not) This also sy...
form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object=null, $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile', $accept='', $sectiondir='', $usewithoutform=0, $capture=0, $disablemulti=0, $nooutput=0)
Show form to upload a new file.
show_documents($modulepart, $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.
getDocumentsLink($modulepart, $modulesubdir, $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 '.
__construct($db)
Constructor.
listOfLinks($object, $permissiontodelete=1, $action=null, $selected=null, $param='', $htmlname='formaddlink', $moreoptions=array())
Show array with linked files.
Class to manage generation of HTML components Only common components must be here.
Class of the module paid holiday.
Class for Mo.
Definition mo.class.php:35
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage projects.
Class to manage proposals.
Class for RecruitmentCandidature.
Class to manage cheque delivery receipts.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage price ask supplier.
Class to manage tasks.
Class to manage VAT - Value-added tax (also known in French as TVA - Taxe sur la valeur ajoutée)
Definition tva.class.php:38
Class to manage Dolibarr users.
dol_filemtime($pathoffile)
Return time of a file.
dol_filesize($pathoffile)
Return size of a file.
completeFileArrayWithDatabaseInfo(&$filearray, $relativedir, $object=null)
Complete $filearray with data from database.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
dol_now($mode='auto')
Return date for now.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
vignette($file, $maxWidth=160, $maxHeight=120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
if(!defined( 'IMAGETYPE_WEBP')) getDefaultImageSizes()
Return default values for image sizes.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
getMaxFileSizeArray()
Return the max allowed for file upload.