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