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