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