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