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