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