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 && empty($conf->dol_optimize_smallscreen)) {
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 if ($conf->use_javascript_ajax) {
844 $out .= ajax_combobox('model');
845 }
846 $out .= $form->textwithpicto('', $tooltipontemplatecombo, 1, 'help', 'marginrightonly', 0, 3, '', 0);
847 } else {
848 $out .= '<div class="float">'.$langs->trans("Files").'</div>';
849 }
850
851 // Language code (if multilang)
852 if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && getDolGlobalInt('MAIN_MULTILANGS') && !$forcenomultilang && (!empty($modellist) || $showempty)) {
853 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
854 $formadmin = new FormAdmin($this->db);
855 $defaultlang = ($codelang && $codelang != 'auto') ? $codelang : $langs->getDefaultLang();
856 $morecss = 'maxwidth150';
857 if ($conf->browser->layout == 'phone') {
858 $morecss = 'maxwidth100';
859 }
860 $out .= $formadmin->select_language($defaultlang, 'lang_id', 0, array(), 0, 0, 0, $morecss);
861 } else {
862 $out .= '&nbsp;';
863 }
864
865 // Button
866 $genbutton = '<input class="button buttongen reposition nomargintop nomarginbottom" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
867 $genbutton .= ' type="submit" value="'.$buttonlabel.'"';
868 if (!$allowgenifempty && !is_array($modellist) && empty($modellist)) {
869 $genbutton .= ' disabled';
870 }
871 $genbutton .= '>';
872 if ($allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') {
873 $langs->load("errors");
874 $genbutton .= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
875 }
876 if (!$allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') {
877 $genbutton = '';
878 }
879 if (empty($modellist) && !$showempty && $modulepart != 'unpaid') {
880 $genbutton = '';
881 }
882 $out .= $genbutton;
883 $out .= '</th>';
884
885 if (!empty($hookmanager->hooks['formfile'])) {
886 foreach ($hookmanager->hooks['formfile'] as $module) {
887 if (method_exists($module, 'formBuilddocLineOptions')) {
888 $colspanmore++;
889 $out .= '<th></th>';
890 }
891 }
892 }
893 $out .= '</tr>';
894
895 // Execute hooks
896 $parameters = array('colspan' => ($colspan + $colspanmore), 'socid' => (isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id' => (isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'modulepart' => $modulepart);
897 if (is_object($hookmanager)) {
898 $reshook = $hookmanager->executeHooks('formBuilddocOptions', $parameters, $GLOBALS['object']);
899 $out .= $hookmanager->resPrint;
900 }
901 }
902
903 // Get list of files
904 if (!empty($filedir)) {
905 $link_list = array();
906 if (is_object($object)) {
907 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
908 $link = new Link($this->db);
909 $sortfield = $sortorder = '';
910 $res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder);
911 }
912
913 $out .= '<!-- html.formfile::showdocuments -->'."\n";
914
915 // Show title of array if not already shown
916 if ((!empty($file_list) || !empty($link_list) || preg_match('/^massfilesarea/', $modulepart))
917 && !$headershown) {
918 $headershown = 1;
919 $out .= '<div class="titre">'.$titletoshow.'</div>'."\n";
920 $out .= '<div class="div-table-responsive-no-min">';
921 $out .= '<table class="noborder centpercent" id="'.$modulepart.'_table">'."\n";
922 }
923
924 // Loop on each file found
925 if (is_array($file_list)) {
926 '@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.
927 // Defined relative dir to DOL_DATA_ROOT
928 $relativedir = '';
929 if ($filedir) {
930 $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
931 $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
932 }
933
934 // Get list of files stored into database for same relative directory
935 if ($relativedir) {
936 completeFileArrayWithDatabaseInfo($file_list, $relativedir);
937 '@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';
938
939 //var_dump($sortfield.' - '.$sortorder);
940 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)
941 $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
942 }
943 }
944
945 require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmfiles.class.php';
946
947 $i = 0;
948 foreach ($file_list as $file) {
949 $i++;
950
951 if (!empty($file['rowid'])) {
952 $ecmfile = new EcmFiles($this->db);
953 $ecmfile->fetch($file['rowid']);
954 } else {
955 $ecmfile = null;
956 }
957
958 // Define relative path for download link (depends on module)
959 $relativepath = (string) $file["name"]; // Cas general
960 if ($modulesubdir) {
961 $relativepath = (string) $modulesubdir."/".$file["name"]; // Cas propal, facture...
962 }
963 if ($modulepart == 'export') {
964 $relativepath = (string) $file["name"]; // Other case
965 }
966
967 $out .= '<tr class="oddeven'.((!$genallowed && $i == 1) ? ' trfirstline' : '').'">';
968
969 $documenturl = DOL_URL_ROOT.'/document.php';
970 if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) {
971 $documenturl = getDolGlobalString('DOL_URL_ROOT_DOCUMENT_PHP'); // To use another wrapper
972 }
973
974 // Show file name with link to download
975 $imgpreview = $this->showPreview($file, $modulepart, $relativepath, 0, $param);
976
977 $out .= '<td class="minwidth200 tdoverflowmax300">';
978 if ($imgpreview) {
979 $out .= '<span class="spanoverflow widthcentpercentminusx valignmiddle">';
980 } else {
981 $out .= '<span class="spanoverflow">';
982 }
983 if (is_object($ecmfile)) {
984 $out .= $ecmfile->getNomUrl(1, $modulepart, 0, 0, ' documentdownload');
985 } else {
986 $out .= '<a class="documentdownload paddingright" ';
987 if (getDolGlobalInt('MAIN_DISABLE_FORCE_SAVEAS') == 2) {
988 $out .= 'target="_blank" ';
989 }
990 $out .= 'href="'.$documenturl.'?modulepart='.$modulepart.'&file='.urlencode($relativepath).($param ? '&'.$param : '').'"';
991
992 $mime = dol_mimetype($relativepath, '', 0);
993 if (preg_match('/text/', $mime)) {
994 $out .= ' target="_blank" rel="noopener noreferrer"';
995 }
996 $out .= ' title="'.dol_escape_htmltag($file["name"]).'"';
997 $out .= '>';
998 $out .= img_mime($file["name"], $langs->trans("File").': '.$file["name"]);
999 $out .= dol_trunc($file["name"], 150);
1000 $out .= '</a>';
1001 }
1002 $out .= '</span>'."\n";
1003 $out .= $imgpreview;
1004 $out .= '</td>';
1005
1006 // Show file size
1007 $size = (!empty($file['size']) ? $file['size'] : dol_filesize($filedir."/".$file["name"]));
1008 $out .= '<td class="nowraponall right" title="'.dolPrintHTML($size.' '.$langs->trans("Bytes")).'">'.dol_print_size($size, 1, 1).'</td>';
1009
1010 // Show file date
1011 $date = (!empty($file['date']) ? $file['date'] : dol_filemtime($filedir."/".$file["name"]));
1012 $out .= '<td class="nowrap right">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>';
1013
1014 // Show share link
1015 $out .= '<td class="nowraponall">';
1016 if (!empty($file['share'])) {
1017 // Define $urlwithroot
1018 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
1019 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
1020 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
1021
1022 //print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
1023 $forcedownload = 0;
1024 $paramlink = '';
1025 if (!empty($file['share'])) {
1026 $paramlink .= ($paramlink ? '&' : '').'hashp='.$file['share']; // Hash for public share
1027 }
1028 if ($forcedownload) {
1029 $paramlink .= ($paramlink ? '&' : '').'attachment=1';
1030 }
1031
1032 $fulllink = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : '');
1033
1034 $out .= '<a href="'.$fulllink.'" target="_blank" rel="noopener">'.img_picto($langs->trans("FileSharedViaALink"), 'globe').'</a> ';
1035 $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).'">';
1036 $out .= ajax_autoselect('downloadlink'.$file['rowid']);
1037 } else {
1038 //print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
1039 }
1040 $out .= '</td>';
1041
1042 // Show picto delete, print...
1043 if ($delallowed || $printer || $morepicto) {
1044 $out .= '<td class="right nowraponall">';
1045 if ($delallowed) {
1046 $tmpurlsource = preg_replace('/#[a-zA-Z0-9_]*$/', '', $urlsource);
1047 $out .= '<a class="reposition" href="'.$tmpurlsource.((strpos($tmpurlsource, '?') === false) ? '?' : '&').'action='.urlencode($removeaction).'&token='.newToken().'&file='.urlencode($relativepath);
1048 $out .= ($param ? '&'.$param : '');
1049 //$out.= '&modulepart='.$modulepart; // TODO obsolete ?
1050 //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
1051 $out .= '">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
1052 }
1053 if ($printer) {
1054 $out .= '<a class="marginleftonly reposition" href="'.$urlsource.(strpos($urlsource, '?') ? '&' : '?').'action=print_file&token='.newToken().'&printer='.urlencode($modulepart).'&file='.urlencode($relativepath);
1055 $out .= ($param ? '&'.$param : '');
1056 $out .= '">'.img_picto($langs->trans("PrintFile", $relativepath), 'printer.png').'</a>';
1057 }
1058 if ($morepicto) {
1059 $morepicto = preg_replace('/__FILENAMEURLENCODED__/', urlencode($relativepath), $morepicto);
1060 $out .= $morepicto;
1061 }
1062 $out .= '</td>';
1063 }
1064
1065 if (is_object($hookmanager)) {
1066 $addcolumforpicto = ($delallowed || $printer || $morepicto);
1067 $colspan = (4 + ($addcolumforpicto ? 1 : 0));
1068 $colspanmore = 0;
1069 $parameters = array('colspan' => ($colspan + $colspanmore), 'socid' => (isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id' => (isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'modulepart' => $modulepart, 'relativepath' => $relativepath);
1070 $res = $hookmanager->executeHooks('formBuilddocLineOptions', $parameters, $file);
1071 if (empty($res)) {
1072 $out .= $hookmanager->resPrint; // Complete line
1073 $out .= '</tr>';
1074 } else {
1075 $out = $hookmanager->resPrint; // Replace all $out
1076 }
1077 }
1078 }
1079
1080 $this->numoffiles++;
1081 }
1082 // Loop on each link found
1083 if (is_array($link_list)) {
1084 $colspan = 2;
1085
1086 foreach ($link_list as $file) {
1087 $out .= '<tr class="oddeven">';
1088 $out .= '<td colspan="'.$colspan.'" class="maxwidhtonsmartphone">';
1089 $out .= '<a data-ajax="false" href="'.$file->url.'" target="_blank" rel="noopener noreferrer">';
1090 $out .= $file->label;
1091 $out .= '</a>';
1092 $out .= '</td>';
1093 $out .= '<td class="right">';
1094 $out .= dol_print_date($file->datea, 'dayhour');
1095 $out .= '</td>';
1096 // for share link of files
1097 $out .= '<td></td>';
1098 if ($delallowed || $printer || $morepicto) {
1099 $out .= '<td></td>';
1100 }
1101 $out .= '</tr>'."\n";
1102 }
1103 $this->numoffiles++;
1104 }
1105
1106 if (count($file_list) == 0 && count($link_list) == 0 && $headershown) {
1107 $out .= '<tr><td colspan="'.(3 + ($addcolumforpicto ? 1 : 0)).'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>'."\n";
1108 }
1109 }
1110
1111 if ($headershown) {
1112 // Affiche pied du tableau
1113 $out .= "</table>\n";
1114 $out .= "</div>\n";
1115 if ($genallowed) {
1116 if (empty($noform)) {
1117 $out .= '</form>'."\n";
1118 }
1119 }
1120 }
1121 $out .= '<!-- End show_document -->'."\n";
1122
1123 $out .= '<script>
1124 jQuery(document).ready(function() {
1125 var selectedValue = $(".selectformat").val();
1126
1127 if (selectedValue === "excel2007" || selectedValue === "tsv") {
1128 $(".forhide").prop("disabled", true).hide();
1129 } else {
1130 $(".forhide").prop("disabled", false).show();
1131 }
1132 });
1133 </script>';
1134 //return ($i?$i:$headershown);
1135 return $out;
1136 }
1137
1151 public function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter = '', $morecss = 'valignmiddle', $allfiles = 0)
1152 {
1153 global $conf, $langs;
1154
1155 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1156
1157 $out = '';
1158 $this->infofiles = array('nboffiles' => 0, 'extensions' => array(), 'files' => array());
1159
1160 $entity = 1; // Without multicompany
1161
1162 // Get object entity
1163 if (isModEnabled('multicompany')) {
1164 $regs = array();
1165 preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir, '/').'$/', $filedir, $regs);
1166 $entity = ((!empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default
1167 }
1168
1169 // Get list of files starting with name of ref (Note: files with '^ref\.extension' are generated files, files with '^ref-...' are uploaded files)
1170 if ($allfiles || getDolGlobalString('MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP')) {
1171 $filterforfilesearch = '^'.preg_quote(basename($modulesubdir), '/');
1172 } else {
1173 $filterforfilesearch = '^'.preg_quote(basename($modulesubdir), '/').'\.';
1174 }
1175 $file_list = dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // We also discard .meta and .png preview
1176
1177 //var_dump($file_list);
1178 // For ajax treatment
1179 $out .= '<!-- html.formfile::getDocumentsLink -->'."\n";
1180 if (!empty($file_list)) {
1181 $out = '<dl class="dropdown inline-block">
1182 <dt><a data-ajax="false" href="#" onClick="return false;">'.img_picto('', 'listlight', '', 0, 0, 0, '', $morecss).'</a></dt>
1183 <dd><div class="multichoicedoc" style="position:absolute;left:100px;" ><ul class="ulselectedfields">';
1184 $tmpout = '';
1185
1186 // Loop on each file found
1187 $found = 0;
1188 $i = 0;
1189 foreach ($file_list as $file) {
1190 $i++;
1191 if ($filter && !preg_match('/'.$filter.'/i', $file["name"])) {
1192 continue; // Discard this. It does not match provided filter.
1193 }
1194
1195 $found++;
1196 // Define relative path for download link (depends on module)
1197 $relativepath = $file["name"]; // Cas general
1198 if ($modulesubdir) {
1199 $relativepath = (string) $modulesubdir."/".$file["name"]; // Cas propal, facture...
1200 }
1201 // Autre cas
1202 if ($modulepart == 'donation') {
1203 $relativepath = (string) get_exdir($modulesubdir, 2, 0, 0, null, 'donation').$file["name"];
1204 }
1205 if ($modulepart == 'export') {
1206 $relativepath = (string) $file["name"];
1207 }
1208
1209 $this->infofiles['nboffiles']++;
1210 $this->infofiles['files'][] = $file['fullname'];
1211 $ext = (string) pathinfo($file['name'], PATHINFO_EXTENSION); // pathinfo returns a string here (cast for static analysis)
1212 if (!array_key_exists($ext, $this->infofiles['extensions'])) {
1213 $this->infofiles['extensions'][$ext] = 1;
1214 } else {
1215 $this->infofiles['extensions'][$ext]++;
1216 }
1217
1218 // Preview
1219 if (!empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone')) {
1220 $tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity='.$entity);
1221 if ($tmparray && $tmparray['url']) {
1222 $tmpout .= '<li><a href="'.$tmparray['url'].'"'.($tmparray['css'] ? ' class="'.$tmparray['css'].'"' : '').($tmparray['mime'] ? ' mime="'.$tmparray['mime'].'"' : '').($tmparray['target'] ? ' target="'.$tmparray['target'].'"' : '').'>';
1223 //$tmpout.= img_picto('','detail');
1224 $tmpout .= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>';
1225 $tmpout .= $langs->trans("Preview").' '.$ext.'</a></li>';
1226 }
1227 }
1228
1229 // Download
1230 $tmpout .= '<li class="nowrap"><a class="pictopreview nowrap" ';
1231 if (getDolGlobalInt('MAIN_DISABLE_FORCE_SAVEAS') == 2) {
1232 $tmpout .= 'target="_blank" ';
1233 }
1234 $tmpout .= 'href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&amp;entity='.$entity.'&amp;file='.urlencode($relativepath).'"';
1235 $mime = dol_mimetype($relativepath, '', 0);
1236 if (preg_match('/text/', $mime)) {
1237 $tmpout .= ' target="_blank" rel="noopener noreferrer"';
1238 }
1239 $tmpout .= '>';
1240 $tmpout .= img_mime($relativepath, $file["name"]);
1241 $tmpout .= $langs->trans("Download").' '.$ext;
1242 $tmpout .= '</a></li>'."\n";
1243 }
1244 $out .= $tmpout;
1245 $out .= '</ul></div></dd>
1246 </dl>';
1247
1248 if (!$found) {
1249 $out = '';
1250 }
1251 } else {
1252 // TODO Add link to regenerate doc ?
1253 //$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
1254 }
1255
1256 return $out;
1257 }
1258
1259
1260 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1294 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())
1295 {
1296 // phpcs:enable
1297 global $user, $conf, $langs, $hookmanager, $form;
1298 global $sortfield, $sortorder;
1299 global $dolibarr_main_url_root;
1300
1301 if ($disablecrop == -1) {
1302 $disablecrop = 1;
1303 // Values here must be supported by the photos_resize.php page.
1304 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'))) {
1305 $disablecrop = 0;
1306 }
1307 }
1308
1309 // Define relative path used to store the file
1310 if (empty($relativepath)) {
1311 $relativepath = (!empty($object->ref) ? dol_sanitizeFileName($object->ref) : '').'/';
1312 if (!empty($object->element) && $object->element == 'invoice_supplier') {
1313 $relativepath = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$relativepath; // TODO Call using a defined value for $relativepath
1314 }
1315 if (!empty($object->element) && $object->element == 'project_task') {
1316 $relativepath = 'Call_not_supported_._Call_function_using_a_defined_relative_path_.';
1317 }
1318 }
1319 // For backward compatibility, we detect file stored into an old path
1320 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO') && isset($filearray[0]) && $filearray[0]['level1name'] == 'photos') {
1321 $relativepath = preg_replace('/^.*\/produit\//', '', $filearray[0]['path']).'/';
1322 }
1323
1324 // Defined relative dir to DOL_DATA_ROOT
1325 $relativedir = '';
1326 if ($upload_dir) {
1327 $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir);
1328 $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
1329 }
1330 // For example here $upload_dir = '/pathtodocuments/commande/SO2001-123/'
1331 // For example here $upload_dir = '/pathtodocuments/tax/vat/1'
1332 // 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'
1333
1334 $hookmanager->initHooks(array('formfile'));
1335 $parameters = array(
1336 'filearray' => $filearray,
1337 'modulepart' => $modulepart,
1338 'param' => $param,
1339 'forcedownload' => $forcedownload,
1340 'relativepath' => $relativepath, // relative filename to module dir
1341 'relativedir' => $relativedir, // relative dirname to DOL_DATA_ROOT
1342 'permtodelete' => $permonobject,
1343 'useinecm' => $useinecm,
1344 'textifempty' => $textifempty,
1345 'maxlength' => $maxlength,
1346 'title' => $title,
1347 'url' => $url
1348 );
1349 $reshook = $hookmanager->executeHooks('showFilesList', $parameters, $object);
1350
1351 if (!empty($reshook)) { // null or '' for bypass
1352 return $reshook;
1353 } else {
1354 if (!is_object($form)) {
1355 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
1356 $form = new Form($this->db);
1357 }
1358
1359 if (!preg_match('/&id=/', $param) && isset($object->id)) {
1360 $param .= '&id='.$object->id;
1361 }
1362 $relativepathwihtoutslashend = preg_replace('/\/$/', '', $relativepath);
1363 if ($relativepathwihtoutslashend) {
1364 $param .= '&file='.urlencode($relativepathwihtoutslashend);
1365 }
1366
1367 if ($permtoeditline < 0) { // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
1368 $permtoeditline = 0;
1369 if (in_array($modulepart, array('product', 'produit', 'service'))) {
1370 if ($user->hasRight('produit', 'creer') && $object->type == Product::TYPE_PRODUCT) {
1371 $permtoeditline = 1;
1372 }
1373 if ($user->hasRight('service', 'creer') && $object->type == Product::TYPE_SERVICE) {
1374 $permtoeditline = 1;
1375 }
1376 }
1377 }
1378 if (!getDolGlobalString('MAIN_UPLOAD_DOC')) {
1379 $permtoeditline = 0;
1380 $permonobject = 0;
1381 }
1382 if (empty($url)) {
1383 $url = $_SERVER["PHP_SELF"];
1384 }
1385
1386
1387 // Show title of list of existing files
1388 $morehtmlright = '';
1389 if (!empty($moreoptions['showhideaddbutton']) && $conf->use_javascript_ajax) {
1390 $tmpurlforbutton = 'javascript:console.log("open add file form");jQuery(".divattachnewfile").toggle(); if (!jQuery(".divattachnewfile").is(":hidden")) { jQuery("input[type=\'file\']").click();}void(0);';
1391 $morehtmlright .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', $tmpurlforbutton, '', $permtoeditline);
1392 }
1393
1394 if ((empty($useinecm) || $useinecm == 3 || $useinecm == 6) && $title != 'none') {
1395 print load_fiche_titre($title ? $title : $langs->trans("AttachedFiles"), $morehtmlright, 'file-upload', 0, '', 'table-list-of-attached-files');
1396 }
1397 if (!empty($moreoptions) && $moreoptions['afteruploadtitle']) {
1398 print '<div class="divattachnewfile'.((!empty($moreoptions['showhideaddbutton']) && $conf->use_javascript_ajax) ? ' hidden' : '').'">'.$moreoptions['afteruploadtitle'].'</div>';
1399 }
1400
1401 // Show the table
1402 print '<!-- html.formfile::list_of_documents -->'."\n";
1403 if (GETPOST('action', 'aZ09') == 'editfile' && $permtoeditline) {
1404 print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" method="POST">';
1405 print '<input type="hidden" name="token" value="'.newToken().'">';
1406 print '<input type="hidden" name="action" value="renamefile">';
1407 print '<input type="hidden" name="id" value="'.(is_object($object) ? $object->id : '').'">';
1408 print '<input type="hidden" name="modulepart" value="'.$modulepart.'">';
1409 }
1410
1411 print '<div class="div-table-responsive-no-min"'.($moreattrondiv ? ' '.$moreattrondiv : '').'>';
1412 print '<table id="tablelines" class="centpercent liste noborder nobottom">'."\n";
1413
1414 if (!empty($addfilterfields)) {
1415 print '<tr class="liste_titre nodrag nodrop">';
1416 print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref', 'alpha')).'"></td>';
1417 print '<td></td>';
1418 print '<td></td>';
1419 if (empty($useinecm) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6) {
1420 print '<td></td>';
1421 }
1422 print '<td></td>';
1423 print '<td></td>';
1424 if (empty($disablemove) && count($filearray) > 1) {
1425 print '<td></td>';
1426 }
1427 print "</tr>\n";
1428 }
1429
1430 // Get list of files stored into database for same relative directory
1431 if ($relativedir) {
1432 completeFileArrayWithDatabaseInfo($filearray, $relativedir);
1433 '@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';
1434
1435 //var_dump($sortfield.' - '.$sortorder);
1436 if ($sortfield && $sortorder) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
1437 $filearray = dol_sort_array($filearray, $sortfield, $sortorder);
1438 }
1439 }
1440
1441 print '<tr class="liste_titre nodrag nodrop">';
1442 //print $url.' sortfield='.$sortfield.' sortorder='.$sortorder;
1443 print_liste_field_titre('Documents2', $url, "name", "", $param, '', $sortfield, $sortorder, 'left ');
1444 print_liste_field_titre('Size', $url, "size", "", $param, '', $sortfield, $sortorder, 'right ');
1445 print_liste_field_titre('Date', $url, "date", "", $param, '', $sortfield, $sortorder, 'center ');
1446 if (empty($useinecm) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6) {
1447 print_liste_field_titre('', $url, "", "", $param, '', $sortfield, $sortorder, 'center '); // Preview
1448 }
1449 // Shared or not - Hash of file
1451 // Action button
1453 if (empty($disablemove) && count($filearray) > 1) {
1455 }
1456 print "</tr>\n";
1457
1458 $nboffiles = count($filearray);
1459 if ($nboffiles > 0) {
1460 include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1461 }
1462
1463 $i = 0;
1464 $nboflines = 0;
1465 $lastrowid = 0;
1466 $parametersByDefault = array(
1467 'modulepart' => $modulepart,
1468 'relativepath' => $relativepath,
1469 'permtoedit' => $permtoeditline,
1470 'permonobject' => $permonobject,
1471 );
1472 foreach ($filearray as $key => $file) { // filearray must be only files here
1473 if ($file['name'] != '.' && $file['name'] != '..' && !preg_match('/\.meta$/i', $file['name'])) {
1474 if (array_key_exists('rowid', $filearray[$key]) && $filearray[$key]['rowid'] > 0) {
1475 $lastrowid = $filearray[$key]['rowid'];
1476 }
1477 //var_dump($filearray[$key]);
1478
1479 // get specific parameters from file attributes if set or get default ones
1480 $modulepart = ($file['modulepart'] ?? $parametersByDefault['modulepart']);
1481 $relativepath = ($file['relativepath'] ?? $parametersByDefault['relativepath']);
1482 $permtoeditline = ($file['permtoedit'] ?? $parametersByDefault['permtoedit']);
1483 $permonobject = ($file['permonobject'] ?? $parametersByDefault['permonobject']);
1484
1485 // Note: for supplier invoice, $modulepart may be already 'facture_fournisseur' and $relativepath may be already '6/1/SI2210-0013/'
1486 if (empty($relativepath) || empty($modulepart)) {
1487 $filepath = $file['level1name'].'/'.$file['name'];
1488 } else {
1489 $filepath = $relativepath.$file['name'];
1490 }
1491 if (empty($modulepart)) {
1492 $modulepart = basename(dirname($file['path']));
1493 }
1494 if (empty($relativepath)) {
1495 $relativepath = preg_replace('/\/(.+)/', '', $filepath) . '/';
1496 }
1497
1498 $editline = 0;
1499 $nboflines++;
1500 print '<!-- Line list_of_documents '.$key.' relativepath = '.$relativepath.' -->'."\n";
1501 // Do we have entry into database ?
1502
1503 print '<!-- In database: position='.(array_key_exists('position', $filearray[$key]) ? $filearray[$key]['position'] : 0).' -->'."\n";
1504 print '<tr class="oddeven" id="row-'.((array_key_exists('rowid', $filearray[$key]) && $filearray[$key]['rowid'] > 0) ? $filearray[$key]['rowid'] : 'AFTER'.$lastrowid.'POS'.($i + 1)).'">';
1505
1506
1507 // File name
1508 print '<td class="minwidth200 tdoverflowmax500" title="'.dolPrintHTMLForAttribute($file['name']).'">';
1509
1510 // Show file name with link to download
1511 //print "XX".$file['name']; //$file['name'] must be utf8
1512 print '<a class="paddingright valignmiddle" ';
1513 if (getDolGlobalInt('MAIN_DISABLE_FORCE_SAVEAS') == 2) {
1514 print 'target="_blank" ';
1515 }
1516 print 'href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1517 if ($forcedownload) {
1518 print '&attachment=1';
1519 }
1520 if (!empty($object->entity)) {
1521 print '&entity='.$object->entity;
1522 }
1523 print '&file='.urlencode($filepath);
1524 print '">';
1525 print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'], 0, 0).')', 'inline-block valignmiddle paddingright');
1526 if ($showrelpart == 1) {
1527 print $relativepath;
1528 }
1529 //print dol_trunc($file['name'],$maxlength,'middle');
1530
1531 //var_dump(dirname($filepath).' - '.dirname(GETPOST('urlfile', 'alpha')));
1532
1533 if (GETPOST('action', 'aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile', 'alpha')) && dirname($filepath) == dirname(GETPOST('urlfile', 'alpha'))) {
1534 print '</a>';
1535 $section_dir = dirname(GETPOST('urlfile', 'alpha'));
1536 if (!preg_match('/\/$/', $section_dir)) {
1537 $section_dir .= '/';
1538 }
1539 print '<input type="hidden" name="section_dir" value="'.$section_dir.'">';
1540 print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">';
1541 print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">';
1542 $editline = 1;
1543 } else {
1544 $filenametoshow = preg_replace('/\.noexe$/', '', $file['name']);
1545 print dol_escape_htmltag(dol_trunc($filenametoshow, 200));
1546 print '</a>';
1547 }
1548 // Preview link
1549 if (!$editline) {
1550 print $this->showPreview($file, $modulepart, $filepath, 0, '&entity='.(empty($object->entity) ? $conf->entity : $object->entity));
1551 }
1552
1553 print "</td>\n";
1554
1555 // Size
1556 $sizetoshow = dol_print_size($file['size'], 1, 1);
1557 $sizetoshowbytes = dol_print_size($file['size'], 0, 1);
1558 print '<td class="right nowraponall">';
1559 if ($sizetoshow == $sizetoshowbytes) {
1560 print $sizetoshow;
1561 } else {
1562 print $form->textwithpicto($sizetoshow, $sizetoshowbytes, -1);
1563 }
1564 print '</td>';
1565
1566 // Date
1567 print '<td class="center nowraponall">'.dol_print_date($file['date'], "dayhour", "tzuser").'</td>';
1568
1569 // Preview
1570 if (empty($useinecm) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6) {
1571 $fileinfo = pathinfo($file['name']);
1572 print '<td class="center">';
1573 if (image_format_supported($file['name']) >= 0) {
1574 if ($useinecm == 5 || $useinecm == 6) {
1575 $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.
1576 } else {
1577 $smallfile = getImageFileNameForSize($file['name'], '_small'); // For new thumbs using same ext (in lower case however) than original
1578 }
1579 if (!dol_is_file($file['path'].'/'.$smallfile)) {
1580 $smallfile = getImageFileNameForSize($file['name'], '_small', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
1581 }
1582 if (!dol_is_file($file['path'].'/'.$smallfile)) {
1583 $smallfile = getImageFileNameForSize($file['name'], ''); // This is in case no _small image exist
1584 }
1585 //print $file['path'].'/'.$smallfile.'<br>';
1586
1587
1588 $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(empty($object->entity) ? $conf->entity : $object->entity));
1589 if (empty($urlforhref)) {
1590 $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']));
1591 print '<a href="'.$urlforhref.'" class="aphoto" target="_blank" rel="noopener noreferrer">';
1592 } else {
1593 print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
1594 }
1595 print '<img class="photo maxwidth200 shadow valignmiddle"';
1596 if ($useinecm == 4 || $useinecm == 5 || $useinecm == 6) {
1597 print ' height="20"';
1598 } else {
1599 //print ' style="max-height: '.$maxheightmini.'px"';
1600 print ' style="max-height: 24px"';
1601 }
1602 print ' src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.urlencode($modulepart).'&entity='.(empty($object->entity) ? $conf->entity : $object->entity).'&file='.urlencode($relativepath.$smallfile);
1603 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.
1604 print '&cache='.urlencode((string) $filearray[$key]['date']);
1605 }
1606 print '" title="">';
1607 print '</a>';
1608 }
1609 print '</td>';
1610 }
1611
1612 // Shared or not - Hash of file
1613 print '<td class="center">';
1614 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
1615 if ($editline) {
1616 print '<label for="idshareenabled'.$key.'">'.$langs->trans("FileSharedViaALink").'</label> ';
1617 print '<input class="inline-block" type="checkbox" id="idshareenabled'.$key.'" name="shareenabled"'.($file['share'] ? ' checked="checked"' : '').' /> ';
1618 } else {
1619 if ($file['share']) {
1620 // Define $urlwithroot
1621 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
1622 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
1623 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
1624
1625 //print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
1626 $forcedownload = 0;
1627 $paramlink = '';
1628 if (!empty($file['share'])) {
1629 $paramlink .= ($paramlink ? '&' : '').'hashp='.$file['share']; // Hash for public share
1630 }
1631 if ($forcedownload) {
1632 $paramlink .= ($paramlink ? '&' : '').'attachment=1';
1633 }
1634
1635 $fulllink = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : '');
1636
1637 print '<a href="'.$fulllink.'" target="_blank" rel="noopener">'.img_picto($langs->trans("FileSharedViaALink"), 'globe').'</a> ';
1638 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).'">';
1639 } else {
1640 //print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
1641 }
1642 }
1643 }
1644 print '</td>';
1645
1646 // Actions buttons (1 column or 2 if !disablemove)
1647 if (!$editline) {
1648 // Delete or view link
1649 // ($param must start with &)
1650 print '<td class="valignmiddle right actionbuttons nowraponall"><!-- action on files -->';
1651 if ($useinecm == 1 || $useinecm == 5) { // ECM manual tree only
1652 // $section is inside $param
1653 $newparam = preg_replace('/&file=.*$/', '', $param); // We don't need param file=
1654 $backtopage = DOL_URL_ROOT.'/ecm/index.php?&section_dir='.urlencode($relativepath).$newparam;
1655 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>';
1656 }
1657
1658 if (empty($useinecm) || $useinecm == 2 || $useinecm == 3 || $useinecm == 6) { // 6=Media file manager
1659 $newmodulepart = $modulepart;
1660 if (in_array($modulepart, array('product', 'produit', 'service'))) {
1661 $newmodulepart = 'produit|service';
1662 }
1663 if (image_format_supported($file['name']) > 0) {
1664 if ($permtoeditline) {
1665 $moreparaminurl = '';
1666 if (!empty($object->id) && $object->id > 0) {
1667 $moreparaminurl .= '&id='.$object->id;
1668 } elseif (GETPOST('website', 'alpha')) {
1669 $moreparaminurl .= '&website='.GETPOST('website', 'alpha');
1670 }
1671 // Set the backtourl
1672 if ($modulepart == 'medias' && !GETPOST('website')) {
1673 $moreparaminurl .= '&backtourl='.urlencode(DOL_URL_ROOT.'/ecm/index_medias.php?file_manager=1&modulepart='.$modulepart.'&section_dir='.$relativepath);
1674 }
1675 // Link to convert into webp
1676 if (!preg_match('/\.webp$/i', $file['name'])) {
1677 if ($modulepart == 'medias' && !GETPOST('website')) {
1678 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>';
1679 } elseif ($modulepart == 'medias' && GETPOST('website')) {
1680 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>';
1681 }
1682 }
1683 }
1684 }
1685 if (!$disablecrop && image_format_supported($file['name']) > 0) {
1686 if ($permtoeditline) {
1687 // Link to resize
1688 $moreparaminurl = '';
1689 if (!empty($object->id) && $object->id > 0) {
1690 $moreparaminurl .= '&id='.$object->id;
1691 } elseif (GETPOST('website', 'alpha')) {
1692 $moreparaminurl .= '&website='.GETPOST('website', 'alpha');
1693 }
1694 // Set the backtourl
1695 if ($modulepart == 'medias' && !GETPOST('website')) {
1696 $moreparaminurl .= '&backtourl='.urlencode(DOL_URL_ROOT.'/ecm/index_medias.php?file_manager=1&modulepart='.$modulepart.'&section_dir='.$relativepath);
1697 }
1698 //var_dump($moreparaminurl);
1699 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>';
1700 }
1701 }
1702
1703 if ($permtoeditline) {
1704 $paramsectiondir = (in_array($modulepart, array('medias', 'ecm')) ? '&section_dir='.urlencode($relativepath) : '');
1705 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>';
1706 }
1707 }
1708 // Output link to delete file
1709 if ($permonobject) {
1710 $useajax = 1;
1711 if (!empty($conf->dol_use_jmobile)) {
1712 $useajax = 0;
1713 }
1714 if (empty($conf->use_javascript_ajax)) {
1715 $useajax = 0;
1716 }
1717 if (getDolGlobalString('MAIN_ECM_DISABLE_JS')) {
1718 $useajax = 0;
1719 }
1720
1721 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>';
1722 }
1723 print "</td>";
1724
1725 if (empty($disablemove) && count($filearray) > 1) {
1726 if ($nboffiles > 1 && $conf->browser->layout != 'phone') {
1727 print '<td class="linecolmove tdlineupdown center">';
1728 if ($i > 0) {
1729 print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=up&rowid='.$object->id.'">'.img_up('default', 0, 'imgupforline').'</a>';
1730 }
1731 if ($i < ($nboffiles - 1)) {
1732 print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=down&rowid='.$object->id.'">'.img_down('default', 0, 'imgdownforline').'</a>';
1733 }
1734 print '</td>';
1735 } else {
1736 print '<td'.(($conf->browser->layout != 'phone') ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'>';
1737 print '</td>';
1738 }
1739 }
1740 } else {
1741 print '<td class="right">';
1742 print '<input type="hidden" name="ecmfileid" value="'.(empty($filearray[$key]['rowid']) ? '' : $filearray[$key]['rowid']).'">';
1743 print '<input type="submit" class="button button-save smallpaddingimp" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
1744 print '<input type="submit" class="button button-cancel smallpaddingimp" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
1745 print '</td>';
1746 if (empty($disablemove) && count($filearray) > 1) {
1747 print '<td class="right"></td>';
1748 }
1749 }
1750 print "</tr>\n";
1751
1752 $i++;
1753 }
1754 }
1755 if ($nboffiles == 0) {
1756 $colspan = '6';
1757 if (empty($disablemove) && count($filearray) > 1) {
1758 $colspan++; // 6 columns or 7
1759 }
1760 print '<tr class="oddeven"><td colspan="'.$colspan.'">';
1761 if (empty($textifempty)) {
1762 print '<span class="opacitymedium">'.$langs->trans("NoFileFound").'</span>';
1763 } else {
1764 print '<span class="opacitymedium">'.$textifempty.'</span>';
1765 }
1766 print '</td></tr>';
1767 }
1768
1769 print "</table>";
1770 print '</div>';
1771
1772 if ($nboflines > 1 && is_object($object)) {
1773 if (!empty($conf->use_javascript_ajax) && $permtoeditline) {
1774 $table_element_line = 'ecm_files'; // used by ajaxrow.tpl.php
1775 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
1776 }
1777 }
1778
1779 print ajax_autoselect('downloadlink');
1780
1781 if (GETPOST('action', 'aZ09') == 'editfile' && $permtoeditline) {
1782 print '</form>';
1783 }
1784
1785 return $nboffiles;
1786 }
1787 }
1788
1789
1790 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1809 public function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload = 0, $relativepath = '', $permissiontodelete = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $url = '', $addfilterfields = 0)
1810 {
1811 // phpcs:enable
1812 global $conf, $langs, $hookmanager, $form;
1813 global $sortfield, $sortorder;
1814 global $search_doc_ref;
1815 global $dolibarr_main_url_root;
1816
1817 dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart);
1818
1819 // Show list of documents
1820 if (empty($useinecm) || $useinecm == 6) {
1821 print load_fiche_titre($langs->trans("AttachedFiles"));
1822 }
1823 if (empty($url)) {
1824 $url = $_SERVER["PHP_SELF"];
1825 }
1826
1827 if (!empty($addfilterfields)) {
1828 print '<form action="'.$_SERVER['PHP_SELF'].'">';
1829 print '<input type="hidden" name="token" value="'.newToken().'">';
1830 print '<input type="hidden" name="module" value="'.$modulepart.'">';
1831 }
1832
1833 print '<div class="div-table-responsive-no-min">';
1834 print '<table width="100%" class="noborder">'."\n";
1835
1836 if (!empty($addfilterfields)) {
1837 print '<tr class="liste_titre nodrag nodrop">';
1838 print '<td class="liste_titre"></td>';
1839 print '<td class="liste_titre"><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"></td>';
1840 print '<td class="liste_titre"></td>';
1841 print '<td class="liste_titre"></td>';
1842 // Action column
1843 print '<td class="liste_titre right">';
1844 $searchpicto = $form->showFilterButtons();
1845 print $searchpicto;
1846 print '</td>';
1847 print "</tr>\n";
1848 }
1849
1850 print '<tr class="liste_titre">';
1851 $sortref = "fullname";
1852 if ($modulepart == 'invoice_supplier') {
1853 $sortref = 'level1name';
1854 }
1855 print_liste_field_titre("Ref", $url, $sortref, "", $param, '', $sortfield, $sortorder);
1856 print_liste_field_titre("Documents2", $url, "name", "", $param, '', $sortfield, $sortorder);
1857 print_liste_field_titre("Size", $url, "size", "", $param, '', $sortfield, $sortorder, 'right ');
1858 print_liste_field_titre("Date", $url, "date", "", $param, '', $sortfield, $sortorder, 'center ');
1859 print_liste_field_titre("Shared", $url, 'share', '', $param, '', $sortfield, $sortorder, 'right ');
1860 print '</tr>'."\n";
1861
1862 // To show ref or specific information according to view to show (defined by $module)
1863 $object_instance = null;
1864 if ($modulepart == 'company') {
1865 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1866 $object_instance = new Societe($this->db);
1867 } elseif ($modulepart == 'invoice') {
1868 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1869 $object_instance = new Facture($this->db);
1870 } elseif ($modulepart == 'invoice_supplier') {
1871 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1872 $object_instance = new FactureFournisseur($this->db);
1873 } elseif ($modulepart == 'propal') {
1874 include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
1875 $object_instance = new Propal($this->db);
1876 } elseif ($modulepart == 'supplier_proposal') {
1877 include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
1878 $object_instance = new SupplierProposal($this->db);
1879 } elseif ($modulepart == 'order') {
1880 include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
1881 $object_instance = new Commande($this->db);
1882 } elseif ($modulepart == 'order_supplier') {
1883 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
1884 $object_instance = new CommandeFournisseur($this->db);
1885 } elseif ($modulepart == 'contract') {
1886 include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
1887 $object_instance = new Contrat($this->db);
1888 } elseif ($modulepart == 'product') {
1889 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1890 $object_instance = new Product($this->db);
1891 } elseif ($modulepart == 'tax') {
1892 include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
1893 $object_instance = new ChargeSociales($this->db);
1894 } elseif ($modulepart == 'tax-vat') {
1895 include_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
1896 $object_instance = new Tva($this->db);
1897 } elseif ($modulepart == 'salaries') {
1898 include_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
1899 $object_instance = new Salary($this->db);
1900 } elseif ($modulepart == 'project') {
1901 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1902 $object_instance = new Project($this->db);
1903 } elseif ($modulepart == 'project_task') {
1904 include_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
1905 $object_instance = new Task($this->db);
1906 } elseif ($modulepart == 'fichinter') {
1907 include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
1908 $object_instance = new Fichinter($this->db);
1909 } elseif ($modulepart == 'user') {
1910 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1911 $object_instance = new User($this->db);
1912 } elseif ($modulepart == 'expensereport') {
1913 include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1914 $object_instance = new ExpenseReport($this->db);
1915 } elseif ($modulepart == 'holiday') {
1916 include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
1917 $object_instance = new Holiday($this->db);
1918 } elseif ($modulepart == 'recruitment-recruitmentcandidature') {
1919 include_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentcandidature.class.php';
1920 $object_instance = new RecruitmentCandidature($this->db);
1921 } elseif ($modulepart == 'banque') {
1922 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1923 $object_instance = new Account($this->db);
1924 } elseif ($modulepart == 'chequereceipt') {
1925 include_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
1926 $object_instance = new RemiseCheque($this->db);
1927 } elseif ($modulepart == 'mrp-mo') {
1928 include_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
1929 $object_instance = new Mo($this->db);
1930 } else {
1931 $parameters = array('modulepart' => $modulepart);
1932 $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters);
1933 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
1934 if (array_key_exists('classpath', $hookmanager->resArray) && !empty($hookmanager->resArray['classpath'])) {
1935 dol_include_once($hookmanager->resArray['classpath']);
1936 if (array_key_exists('classname', $hookmanager->resArray) && !empty($hookmanager->resArray['classname'])) {
1937 $tmpclassname = $hookmanager->resArray['classname'];
1938 if (is_string($tmpclassname) && class_exists($tmpclassname)) {
1939 $object_instance = new $tmpclassname($this->db);
1940 }
1941 }
1942 }
1943 }
1944 }
1945
1946 //var_dump($filearray);
1947 //var_dump($object_instance);
1948
1949 // Get list of files stored into database for same relative directory
1950 $relativepathfromroot = preg_replace('/'.preg_quote(DOL_DATA_ROOT.'/', '/').'/', '', $upload_dir);
1951 if ($relativepathfromroot) {
1952 completeFileArrayWithDatabaseInfo($filearray, $relativepathfromroot.'/%');
1953 '@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';
1954
1955 //var_dump($sortfield.' - '.$sortorder);
1956 if ($sortfield && $sortorder) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
1957 $filearray = dol_sort_array($filearray, $sortfield, $sortorder, 1);
1958 }
1959 }
1960
1961 //var_dump($filearray);
1962
1963 foreach ($filearray as $key => $file) {
1964 if (!is_dir($file['name'])
1965 && $file['name'] != '.'
1966 && $file['name'] != '..'
1967 && $file['name'] != 'CVS'
1968 && !preg_match('/\.meta$/i', $file['name'])) {
1969 // Define relative path used to store the file
1970 $relativefile = preg_replace('/'.preg_quote($upload_dir.'/', '/').'/', '', $file['fullname']);
1971
1972 $id = 0;
1973 $ref = '';
1974
1975 // To show ref or specific information according to view to show (defined by $modulepart)
1976 // $modulepart can be $object->table_name (that is 'mymodule_myobject') or $object->element.'-'.$module (for compatibility purpose)
1977 $reg = array();
1978 if ($modulepart == 'company' || $modulepart == 'tax' || $modulepart == 'tax-vat' || $modulepart == 'salaries') {
1979 preg_match('/(\d+)\/[^\/]+$/', $relativefile, $reg);
1980 $id = (isset($reg[1]) ? $reg[1] : '');
1981 } elseif ($modulepart == 'invoice_supplier') {
1982 preg_match('/([^\/]+)\/[^\/]+$/', $relativefile, $reg);
1983 $ref = (isset($reg[1]) ? $reg[1] : '');
1984 if (is_numeric($ref)) {
1985 $id = $ref;
1986 $ref = '';
1987 }
1988 } elseif ($modulepart == 'user') {
1989 // $ref may be also id with old supplier invoices
1990 preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg);
1991 $id = (isset($reg[1]) ? $reg[1] : '');
1992 } elseif ($modulepart == 'project_task') {
1993 // $ref of task is the sub-directory of the project
1994 $reg = explode("/", $relativefile);
1995 $ref = (isset($reg[1]) ? $reg[1] : '');
1996 } elseif (in_array($modulepart, array(
1997 'invoice',
1998 'propal',
1999 'supplier_proposal',
2000 'order',
2001 'order_supplier',
2002 'contract',
2003 'product',
2004 'project',
2005 'project_task',
2006 'fichinter',
2007 'expensereport',
2008 'recruitment-recruitmentcandidature',
2009 'mrp-mo',
2010 'banque',
2011 'chequereceipt',
2012 'holiday'))) {
2013 preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg);
2014 $ref = (isset($reg[1]) ? $reg[1] : '');
2015 } else {
2016 $parameters = array('modulepart' => $modulepart, 'fileinfo' => $file);
2017 $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters);
2018 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
2019 if (array_key_exists('ref', $hookmanager->resArray) && !empty($hookmanager->resArray['ref'])) {
2020 $ref = $hookmanager->resArray['ref'];
2021 }
2022 if (array_key_exists('id', $hookmanager->resArray) && !empty($hookmanager->resArray['id'])) {
2023 $id = $hookmanager->resArray['id'];
2024 }
2025 }
2026 //print 'Error: Value for modulepart = '.$modulepart.' is not yet implemented in function list_of_autoecmfiles'."\n";
2027 }
2028
2029 if (!$id && !$ref) {
2030 continue;
2031 }
2032
2033 $found = 0;
2034 if (!empty($conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref])) {
2035 $found = 1;
2036 } else {
2037 //print 'Fetch '.$id." - ".$ref.' class='.get_class($object_instance).'<br>';
2038
2039 $result = 0;
2040 if (is_object($object_instance)) {
2041 $object_instance->id = 0;
2042 $object_instance->ref = '';
2043 if ($id) {
2044 $result = $object_instance->fetch($id);
2045 } else {
2046 if (!($result = $object_instance->fetch(0, $ref))) {
2047 //fetchOneLike looks for objects with wildcards in its reference.
2048 //It is useful for those masks who get underscores instead of their actual symbols (because the _ had replaced all forbidden chars into filename)
2049 // TODO Example when this is needed ?
2050 // 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 ?
2051 // May be we can add hidden option to enable this.
2052 $result = $object_instance->fetchOneLike($ref);
2053 }
2054 }
2055 }
2056
2057 if ($result > 0) { // Save object loaded into a cache
2058 $found = 1;
2059 $conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref] = clone $object_instance;
2060 }
2061 if ($result == 0) {
2062 $found = 1;
2063 $conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref] = 'notfound';
2064 unset($filearray[$key]);
2065 }
2066 }
2067
2068 if ($found <= 0 || !is_object($conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref])) {
2069 continue; // We do not show orphelins files
2070 }
2071
2072 print '<!-- Line list_of_autoecmfiles key='.$key.' -->'."\n";
2073 print '<tr class="oddeven">';
2074 print '<td>';
2075 if ($found > 0 && is_object($conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref])) {
2076 $tmpobject = $conf->cache['modulepartobject'][$modulepart.'_'.$id.'_'.$ref];
2077 //if (! in_array($tmpobject->element, array('expensereport'))) {
2078 print $tmpobject->getNomUrl(1, 'document');
2079 //} else {
2080 // print $tmpobject->getNomUrl(1);
2081 //}
2082 } else {
2083 print $langs->trans("ObjectDeleted", ($id ? $id : $ref));
2084 }
2085
2086 //$modulesubdir=dol_sanitizeFileName($ref);
2087 //$modulesubdir = dirname($relativefile);
2088
2089 //$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref);
2090 //$filedir = $file['path'];
2091 //$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
2092 //print $formfile->getDocumentsLink($modulepart, $filename, $filedir);
2093 print '</td>';
2094
2095 // File
2096 // Check if document source has external module part, if it the case use it for module part on document.php
2097 print '<td>';
2098 //print "XX".$file['name']; //$file['name'] must be utf8
2099 print '<a ';
2100 if (getDolGlobalInt('MAIN_DISABLE_FORCE_SAVEAS') == 2) {
2101 print 'target="_blank" ';
2102 }
2103 print 'href="'.DOL_URL_ROOT.'/document.php?modulepart='.urlencode($modulepart);
2104 if ($forcedownload) {
2105 print '&attachment=1';
2106 }
2107 print '&file='.urlencode($relativefile).'">';
2108 print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'], 0, 0).')');
2109 print dol_escape_htmltag(dol_trunc($file['name'], $maxlength, 'middle'));
2110 print '</a>';
2111
2112 //print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$');
2113
2114 print $this->showPreview($file, $modulepart, $file['relativename']);
2115
2116 print "</td>\n";
2117
2118 // Size
2119 $sizetoshow = dol_print_size($file['size'], 1, 1);
2120 $sizetoshowbytes = dol_print_size($file['size'], 0, 1);
2121 print '<td class="right nowraponall">';
2122 if ($sizetoshow == $sizetoshowbytes) {
2123 print $sizetoshow;
2124 } else {
2125 print $form->textwithpicto($sizetoshow, $sizetoshowbytes, -1);
2126 }
2127 print '</td>';
2128
2129 // Date
2130 print '<td class="center">'.dol_print_date($file['date'], "dayhour").'</td>';
2131
2132 // Share link
2133 print '<td class="right">';
2134 if (!empty($file['share'])) {
2135 // Define $urlwithroot
2136 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
2137 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
2138 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2139
2140 //print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
2141 $forcedownload = 0;
2142 $paramlink = '';
2143 if (!empty($file['share'])) {
2144 $paramlink .= ($paramlink ? '&' : '').'hashp='.$file['share']; // Hash for public share
2145 }
2146 if ($forcedownload) {
2147 $paramlink .= ($paramlink ? '&' : '').'attachment=1';
2148 }
2149
2150 $fulllink = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : '');
2151
2152 print img_picto($langs->trans("FileSharedViaALink"), 'globe').' ';
2153 print '<input type="text" class="quatrevingtpercent width100 nopadding nopadding small" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).'">';
2154 }
2155 //if (!empty($useinecm) && $useinecm != 6) print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
2156 //if ($forcedownload) print '&attachment=1';
2157 //print '&file='.urlencode($relativefile).'">';
2158 //print img_view().'</a> &nbsp; ';
2159 //if ($permissiontodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&token='.newToken().'&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
2160 //else print '&nbsp;';
2161 print "</td>";
2162
2163 print "</tr>\n";
2164 }
2165 }
2166
2167 if (count($filearray) == 0) {
2168 print '<tr class="oddeven"><td colspan="5">';
2169 if (empty($textifempty)) {
2170 print '<span class="opacitymedium">'.$langs->trans("NoFileFound").'</span>';
2171 } else {
2172 print '<span class="opacitymedium">'.$textifempty.'</span>';
2173 }
2174 print '</td></tr>';
2175 }
2176 print "</table>";
2177 print '</div>';
2178
2179 if (!empty($addfilterfields)) {
2180 print '</form>';
2181 }
2182 return count($filearray);
2183 // Fin de zone
2184 }
2185
2198 public function listOfLinks($object, $permissiontodelete = 1, $action = null, $selected = null, $param = '', $htmlname = 'formaddlink', $moreoptions = array())
2199 {
2200 global $conf, $langs;
2201 global $sortfield, $sortorder;
2202
2203 $langs->load("link");
2204
2205 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
2206 $link = new Link($this->db);
2207 $links = array();
2208 if ($sortfield == "name") {
2209 $sortfield = "label";
2210 } elseif ($sortfield == "date") {
2211 $sortfield = "datea";
2212 } else {
2213 $sortfield = '';
2214 }
2215 $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder);
2216 $param .= (isset($object->id) ? '&id='.$object->id : '');
2217
2218 $permissiontoedit = $permissiontodelete;
2219
2220 print '<!-- listOfLinks -->'."\n";
2221
2222 $morehtmlright = '';
2223 if (!empty($moreoptions['showhideaddbutton']) && $conf->use_javascript_ajax) {
2224 $morehtmlright .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', 'javascript:console.log("open addlink form"); jQuery(".divlinkfile").toggle(); void(0);', '', $permissiontoedit);
2225 }
2226
2227 // Show list of associated links
2228 print load_fiche_titre($langs->trans("LinkedFiles"), $morehtmlright, 'link', 0, '', 'table-list-of-links');
2229
2230 if (!empty($moreoptions) && $moreoptions['afterlinktitle']) {
2231 print '<div class="divlinkfile'.((!empty($moreoptions['showhideaddbutton']) && $conf->use_javascript_ajax) ? ' hidden' : '').'">'.$moreoptions['afterlinktitle'].'</div>';
2232 }
2233
2234 print '<form action="'.$_SERVER['PHP_SELF'].($param ? '?'.$param : '').'" id="'.$htmlname.'" method="POST">';
2235 print '<input type="hidden" name="token" value="'.newToken().'">';
2236
2237 print '<table class="liste noborder nobottom centpercent">';
2238 print '<tr class="liste_titre">';
2240 $langs->trans("Links"),
2241 $_SERVER['PHP_SELF'],
2242 "name",
2243 "",
2244 $param,
2245 '',
2246 $sortfield,
2247 $sortorder,
2248 ''
2249 );
2251 "",
2252 "",
2253 "",
2254 "",
2255 "",
2256 '',
2257 '',
2258 '',
2259 'right '
2260 );
2262 $langs->trans("Date"),
2263 $_SERVER['PHP_SELF'],
2264 "date",
2265 "",
2266 $param,
2267 '',
2268 $sortfield,
2269 $sortorder,
2270 'center '
2271 );
2273 '',
2274 $_SERVER['PHP_SELF'],
2275 "",
2276 "",
2277 $param,
2278 '',
2279 '',
2280 '',
2281 'center '
2282 );
2283 print_liste_field_titre('', '', '');
2284 print '</tr>';
2285 $nboflinks = count($links);
2286 if ($nboflinks > 0) {
2287 include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
2288 }
2289 foreach ($links as $link) {
2290 print '<tr class="oddeven">';
2291 //edit mode
2292 if ($action == 'update' && $selected === (int) $link->id && $permissiontoedit) {
2293 print '<td>';
2294 print '<input type="hidden" name="id" value="'.$object->id.'">';
2295 print '<input type="hidden" name="linkid" value="'.$link->id.'">';
2296 print '<input type="hidden" name="action" value="confirm_updateline">';
2297 print $langs->trans('Link').': <input type="text" name="link" value="'.$link->url.'">';
2298 print '</td>';
2299 print '<td>';
2300 print $langs->trans('Label').': <input type="text" name="label" value="'.dol_escape_htmltag($link->label).'">';
2301 print '</td>';
2302 print '<td class="center">'.dol_print_date(dol_now(), "dayhour", "tzuser").'</td>';
2303 print '<td class="right"></td>';
2304 print '<td class="right">';
2305 print '<input type="submit" class="button button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
2306 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
2307 print '</td>';
2308 } else {
2309 print '<td>';
2310 print img_picto('', 'globe').' ';
2311 print '<a data-ajax="false" href="'.$link->url.'" target="_blank" rel="noopener noreferrer">';
2312 print dol_escape_htmltag($link->label);
2313 print '</a>';
2314 print '</td>'."\n";
2315 print '<td class="right"></td>';
2316 print '<td class="center">'.dol_print_date($link->datea, "dayhour", "tzuser").'</td>';
2317 print '<td class="center"></td>';
2318 print '<td class="right">';
2319 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
2320 if ($permissiontodelete) {
2321 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
2322 } else {
2323 print '&nbsp;';
2324 }
2325 print '</td>';
2326 }
2327 print "</tr>\n";
2328 }
2329 if ($nboflinks == 0) {
2330 print '<tr class="oddeven"><td colspan="5">';
2331 print '<span class="opacitymedium">'.$langs->trans("NoLinkFound").'</span>';
2332 print '</td></tr>';
2333 }
2334 print "</table>";
2335
2336 print '</form>';
2337
2338 return $nboflinks;
2339 }
2340
2341
2352 public function showPreview($file, $modulepart, $relativepath, $ruleforpicto = 0, $param = '')
2353 {
2354 global $langs, $conf;
2355
2356 $out = '';
2357 if ($conf->browser->layout != 'phone' && !empty($conf->use_javascript_ajax)) {
2358 $urladvancedpreview = getAdvancedPreviewUrl($modulepart, $relativepath, 1, $param); // Return if a file is qualified for preview.
2359 if (count($urladvancedpreview)) {
2360 $out .= '<a class="pictopreview '.$urladvancedpreview['css'].'" href="'.$urladvancedpreview['url'].'"'.(empty($urladvancedpreview['mime']) ? '' : ' mime="'.$urladvancedpreview['mime'].'"').' '.(empty($urladvancedpreview['target']) ? '' : ' target="'.$urladvancedpreview['target'].'"').'>';
2361 //$out.= '<a class="pictopreview">';
2362 if (empty($ruleforpicto)) {
2363 //$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail');
2364 $out .= '<span class="fa fa-search-plus pictofixedwidth" style="color: gray"></span>';
2365 } else {
2366 $out .= img_mime($relativepath, $langs->trans('Preview').' '.$file['name'], 'pictofixedwidth');
2367 }
2368 $out .= '</a>';
2369 } else {
2370 if ($ruleforpicto < 0) {
2371 $out .= img_picto('', 'generic', '', 0, 0, 0, '', 'paddingright pictofixedwidth');
2372 }
2373 }
2374 }
2375 return $out;
2376 }
2377}
$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.