dolibarr  9.0.0
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 
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
35 class FormFile
36 {
37  private $db;
38 
42  public $error;
43 
44  public $numoffiles;
45  public $infofiles; // Used to return informations by function getDocumentsLink
46 
47 
53  function __construct($db)
54  {
55  $this->db = $db;
56  $this->numoffiles=0;
57  }
58 
59 
60  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
80  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='')
81  {
82  // phpcs:enable
83  global $conf,$langs, $hookmanager;
84  $hookmanager->initHooks(array('formfile'));
85 
86 
87  if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax=0;
88 
89  if ((! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax==2))
90  {
91  // TODO: Check this works with 2 forms on same page
92  // TODO: Check this works with GED module, otherwise, force useajax to 0
93  // TODO: This does not support option savingdocmask
94  // TODO: This break feature to upload links too
95  return $this->_formAjaxFileUpload($object);
96  }
97  else
98  {
99  //If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed
100  if (!$perm && !empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
101  return 1;
102  }
103 
104  $maxlength=$size;
105 
106  $out = "\n\n<!-- Start form attach new file -->\n";
107 
108  if (empty($title)) $title=$langs->trans("AttachANewFile");
109  if ($title != 'none') $out.=load_fiche_titre($title, null, null);
110 
111  $out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">';
112  $out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">';
113  $out .= '<input type="hidden" id="'.$htmlname.'_section_id" name="section_id" value="'.$sectionid.'">';
114  $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
115 
116  $out .= '<table width="100%" class="nobordernopadding">';
117  $out .= '<tr>';
118 
119  if (! empty($options)) $out .= '<td>'.$options.'</td>';
120 
121  $out .= '<td class="valignmiddle nowrap">';
122 
123  $max=$conf->global->MAIN_UPLOAD_DOC; // En Kb
124  $maxphp=@ini_get('upload_max_filesize'); // En inconnu
125  if (preg_match('/k$/i',$maxphp)) $maxphp=$maxphp*1;
126  if (preg_match('/m$/i',$maxphp)) $maxphp=$maxphp*1024;
127  if (preg_match('/g$/i',$maxphp)) $maxphp=$maxphp*1024*1024;
128  if (preg_match('/t$/i',$maxphp)) $maxphp=$maxphp*1024*1024*1024;
129  // Now $max and $maxphp are in Kb
130  $maxmin = $max;
131  if ($maxphp > 0) $maxmin=min($max,$maxphp);
132 
133  if ($maxmin > 0)
134  {
135  // MAX_FILE_SIZE doit précéder le champ input de type file
136  $out .= '<input type="hidden" name="max_file_size" value="'.($maxmin*1024).'">';
137  }
138 
139  $out .= '<input class="flat minwidth400" type="file"';
140  $out .= ((! empty($conf->global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic')?' name="userfile"':' name="userfile[]" multiple');
141  $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
142  $out .= (!empty($accept)?' accept="'.$accept.'"':' accept=""');
143  $out .= '>';
144  $out .= ' ';
145  $out .= '<input type="submit" class="button" name="sendit" value="'.$langs->trans("Upload").'"';
146  $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
147  $out .= '>';
148 
149  if ($addcancel)
150  {
151  $out .= ' &nbsp; ';
152  $out .= '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
153  }
154 
155  if (! empty($conf->global->MAIN_UPLOAD_DOC))
156  {
157  if ($perm)
158  {
159  $langs->load('other');
160  $out .= ' ';
161  $out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1);
162  }
163  }
164  else
165  {
166  $out .= ' ('.$langs->trans("UploadDisabled").')';
167  }
168  $out .= "</td></tr>";
169 
170  if ($savingdocmask)
171  {
172  $out .= '<tr>';
173  if (! empty($options)) $out .= '<td>'.$options.'</td>';
174  $out .= '<td valign="middle" class="nowrap">';
175  $out .= '<input type="checkbox" checked class="savingdocmask" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName"));
176  $out .= '</td>';
177  $out .= '</tr>';
178  }
179 
180  $out .= "</table>";
181 
182  $out .= '</form>';
183  if (empty($sectionid)) $out .= '<br>';
184 
185  $out .= "\n<!-- End form attach new file -->\n";
186 
187  if ($linkfiles)
188  {
189  $out .= "\n<!-- Start form link new url -->\n";
190  $langs->load('link');
191  $title = $langs->trans("LinkANewFile");
192  $out .= load_fiche_titre($title, null, null);
193  $out .= '<form name="'.$htmlname.'_link" id="'.$htmlname.'_link" action="'.$url.'" method="POST">';
194  $out .= '<input type="hidden" id="'.$htmlname.'_link_section_dir" name="link_section_dir" value="">';
195  $out .= '<input type="hidden" id="'.$htmlname.'_link_section_id" name="link_section_id" value="'.$sectionid.'">';
196  $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
197 
198  $out .= '<div class="valignmiddle" >';
199  $out .= '<div class="inline-block" style="padding-right: 10px;">';
200  if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink") . ':</label> ';
201  $out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">';
202  $out .= '</div>';
203  $out .= '<div class="inline-block" style="padding-right: 10px;">';
204  if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="label">'.$langs->trans("Label") . ':</label> ';
205  $out .= '<input type="text" class="flat" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">';
206  $out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">';
207  $out .= '<input type="hidden" name="objectid" value="' . $object->id . '">';
208  $out .= '</div>';
209  $out .= '<div class="inline-block" style="padding-right: 10px;">';
210  $out .= '<input type="submit" class="button" name="linkit" value="'.$langs->trans("ToLink").'"';
211  $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
212  $out .= '>';
213  $out .= '</div>';
214  $out .= '</div>';
215  $out .= '<div class="clearboth"></div>';
216  $out .= '</form><br>';
217 
218  $out .= "\n<!-- End form link new url -->\n";
219  }
220 
221  $parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''), 'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm);
222  $res = $hookmanager->executeHooks('formattachOptions',$parameters,$object);
223  if (empty($res))
224  {
225  print '<div class="attacharea attacharea'.$htmlname.'">';
226  print $out;
227  print '</div>';
228  }
229  print $hookmanager->resPrint;
230 
231  return 1;
232  }
233  }
234 
235  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
258  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='')
259  {
260  // phpcs:enable
261  $this->numoffiles=0;
262  print $this->showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$notused,$noform,$param,$title,$buttonlabel,$codelang);
263  return $this->numoffiles;
264  }
265 
291  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)
292  {
293  // Deprecation warning
294  if (! empty($iconPDF)) {
295  dol_syslog(__METHOD__ . ": passing iconPDF parameter is deprecated", LOG_WARNING);
296  }
297 
298  global $langs, $conf, $user, $hookmanager;
299  global $form;
300 
301  if (! is_object($form)) $form=new Form($this->db);
302 
303  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
304 
305  // For backward compatibility
306  if (! empty($iconPDF)) {
307  return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir);
308  }
309 
310  // Add entity in $param if not already exists
311  if (!preg_match('/entity\=[0-9]+/', $param)) {
312  $param.= 'entity='.(!empty($object->entity)?$object->entity:$conf->entity);
313  }
314 
315  $printer=0;
316  if (in_array($modulepart,array('facture','supplier_proposal','propal','proposal','order','commande','expedition', 'commande_fournisseur', 'expensereport','livraison'))) // The direct print feature is implemented only for such elements
317  {
318  $printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false;
319  }
320 
321  $hookmanager->initHooks(array('formfile'));
322 
323  // Get list of files
324  $file_list=null;
325  if (! empty($filedir))
326  {
327  $file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview.*.*\.png)$','date',SORT_DESC);
328  }
329  if ($hideifempty && empty($file_list)) return '';
330 
331  $out='';
332  $forname='builddoc';
333  $headershown=0;
334  $showempty=0;
335  $i=0;
336 
337  $out.= "\n".'<!-- Start show_document -->'."\n";
338  //print 'filedir='.$filedir;
339 
340  if (preg_match('/massfilesarea_/', $modulepart))
341  {
342  $out.='<div id="show_files"><br></div>'."\n";
343  $title=$langs->trans("MassFilesArea").' <a href="" id="togglemassfilesarea" ref="shown">('.$langs->trans("Hide").')</a>';
344  $title.='<script type="text/javascript" language="javascript">
345  jQuery(document).ready(function() {
346  jQuery(\'#togglemassfilesarea\').click(function() {
347  if (jQuery(\'#togglemassfilesarea\').attr(\'ref\') == "shown")
348  {
349  jQuery(\'#'.$modulepart.'_table\').hide();
350  jQuery(\'#togglemassfilesarea\').attr("ref", "hidden");
351  jQuery(\'#togglemassfilesarea\').text("('.dol_escape_js($langs->trans("Show")).')");
352  }
353  else
354  {
355  jQuery(\'#'.$modulepart.'_table\').show();
356  jQuery(\'#togglemassfilesarea\').attr("ref","shown");
357  jQuery(\'#togglemassfilesarea\').text("('.dol_escape_js($langs->trans("Hide")).')");
358  }
359  return false;
360  });
361  });
362  </script>';
363  }
364 
365  $titletoshow=$langs->trans("Documents");
366  if (! empty($title)) $titletoshow=$title;
367 
368  // Show table
369  if ($genallowed)
370  {
371  $modellist=array();
372 
373  if ($modulepart == 'company')
374  {
375  $showempty=1;
376  if (is_array($genallowed)) $modellist=$genallowed;
377  else
378  {
379  include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
380  $modellist=ModeleThirdPartyDoc::liste_modeles($this->db);
381  }
382  }
383  else if ($modulepart == 'propal')
384  {
385  if (is_array($genallowed)) $modellist=$genallowed;
386  else
387  {
388  include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
389  $modellist=ModelePDFPropales::liste_modeles($this->db);
390  }
391  }
392  else if ($modulepart == 'supplier_proposal')
393  {
394  if (is_array($genallowed)) $modellist=$genallowed;
395  else
396  {
397  include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
398  $modellist=ModelePDFSupplierProposal::liste_modeles($this->db);
399  }
400  }
401  else if ($modulepart == 'commande')
402  {
403  if (is_array($genallowed)) $modellist=$genallowed;
404  else
405  {
406  include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
407  $modellist=ModelePDFCommandes::liste_modeles($this->db);
408  }
409  }
410  elseif ($modulepart == 'expedition')
411  {
412  if (is_array($genallowed)) $modellist=$genallowed;
413  else
414  {
415  include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
416  $modellist=ModelePDFExpedition::liste_modeles($this->db);
417  }
418  }
419  elseif ($modulepart == 'livraison')
420  {
421  if (is_array($genallowed)) $modellist=$genallowed;
422  else
423  {
424  include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php';
425  $modellist=ModelePDFDeliveryOrder::liste_modeles($this->db);
426  }
427  }
428  else if ($modulepart == 'ficheinter')
429  {
430  if (is_array($genallowed)) $modellist=$genallowed;
431  else
432  {
433  include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
434  $modellist=ModelePDFFicheinter::liste_modeles($this->db);
435  }
436  }
437  elseif ($modulepart == 'facture')
438  {
439  if (is_array($genallowed)) $modellist=$genallowed;
440  else
441  {
442  include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
443  $modellist=ModelePDFFactures::liste_modeles($this->db);
444  }
445  }
446  elseif ($modulepart == 'contract')
447  {
448  if (is_array($genallowed)) $modellist=$genallowed;
449  else
450  {
451  include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
452  $modellist=ModelePDFContract::liste_modeles($this->db);
453  }
454  }
455  elseif ($modulepart == 'project')
456  {
457  if (is_array($genallowed)) $modellist=$genallowed;
458  else
459  {
460  include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
461  $modellist=ModelePDFProjects::liste_modeles($this->db);
462  }
463  }
464  elseif ($modulepart == 'project_task')
465  {
466  if (is_array($genallowed)) $modellist=$genallowed;
467  else
468  {
469  include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
470  $modellist=ModelePDFTask::liste_modeles($this->db);
471  }
472  }
473  elseif ($modulepart == 'product')
474  {
475  if (is_array($genallowed)) $modellist=$genallowed;
476  else
477  {
478  include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
479  $modellist=ModelePDFProduct::liste_modeles($this->db);
480  }
481  }
482  elseif ($modulepart == 'product_batch')
483  {
484  if (is_array($genallowed)) $modellist=$genallowed;
485  else
486  {
487  include_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php';
488  $modellist=ModelePDFProductBatch::liste_modeles($this->db);
489  }
490  }
491  elseif ($modulepart == 'stock')
492  {
493  if (is_array($genallowed)) $modellist=$genallowed;
494  else
495  {
496  include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_stock.php';
497  $modellist=ModelePDFStock::liste_modeles($this->db);
498  }
499  }
500  elseif ($modulepart == 'movement')
501  {
502  if (is_array($genallowed)) $modellist=$genallowed;
503  else
504  {
505  include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_movement.php';
506  $modellist=ModelePDFMovement::liste_modeles($this->db);
507  }
508  }
509  elseif ($modulepart == 'export')
510  {
511  if (is_array($genallowed)) $modellist=$genallowed;
512  else
513  {
514  include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
515  $modellist=ModeleExports::liste_modeles($this->db);
516  }
517  }
518  else if ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order')
519  {
520  if (is_array($genallowed)) $modellist=$genallowed;
521  else
522  {
523  include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
524  $modellist=ModelePDFSuppliersOrders::liste_modeles($this->db);
525  }
526  }
527  else if ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice')
528  {
529  if (is_array($genallowed)) $modellist=$genallowed;
530  else
531  {
532  include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
533  $modellist=ModelePDFSuppliersInvoices::liste_modeles($this->db);
534  }
535  }
536  else if ($modulepart == 'supplier_payment')
537  {
538  if (is_array($genallowed)) $modellist=$genallowed;
539  else
540  {
541  include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
542  $modellist=ModelePDFSuppliersPayments::liste_modeles($this->db);
543  }
544  }
545  else if ($modulepart == 'remisecheque')
546  {
547  if (is_array($genallowed)) $modellist=$genallowed;
548  else
549  {
550  include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
551  $modellist=ModeleChequeReceipts::liste_modeles($this->db);
552  }
553  }
554  elseif ($modulepart == 'donation')
555  {
556  if (is_array($genallowed)) $modellist=$genallowed;
557  else
558  {
559  include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
560  $modellist=ModeleDon::liste_modeles($this->db);
561  }
562  }
563  elseif ($modulepart == 'member')
564  {
565  if (is_array($genallowed)) $modellist=$genallowed;
566  else
567  {
568  include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
569  $modellist=ModelePDFCards::liste_modeles($this->db);
570  }
571  }
572  elseif ($modulepart == 'agenda' || $modulepart == 'actions')
573  {
574  if (is_array($genallowed)) $modellist=$genallowed;
575  else
576  {
577  include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php';
578  $modellist=ModeleAction::liste_modeles($this->db);
579  }
580  }
581  else if ($modulepart == 'expensereport')
582  {
583  if (is_array($genallowed)) $modellist=$genallowed;
584  else
585  {
586  include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
587  $modellist=ModeleExpenseReport::liste_modeles($this->db);
588  }
589  }
590  else if ($modulepart == 'unpaid')
591  {
592  $modellist='';
593  }
594  elseif ($modulepart == 'user')
595  {
596  if (is_array($genallowed)) $modellist=$genallowed;
597  else
598  {
599  include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php';
600  $modellist=ModelePDFUser::liste_modeles($this->db);
601  }
602  }
603  elseif ($modulepart == 'usergroup')
604  {
605  if (is_array($genallowed)) $modellist=$genallowed;
606  else
607  {
608  include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php';
609  $modellist=ModelePDFUserGroup::liste_modeles($this->db);
610  }
611  }
612  else
613  {
614  // For normalized standard modules
615  $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
616  if (file_exists($file))
617  {
618  $res=include_once $file;
619  }
620  // For normalized external modules
621  else
622  {
623  $file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
624  $res=include_once $file;
625  }
626  $class='ModelePDF'.ucfirst($modulepart);
627  if (class_exists($class))
628  {
629  $modellist=call_user_func($class.'::liste_modeles',$this->db);
630  }
631  else
632  {
633  dol_print_error($this->db,'Bad value for modulepart');
634  return -1;
635  }
636  }
637 
638  // Set headershown to avoid to have table opened a second time later
639  $headershown=1;
640 
641  $buttonlabeltoshow=$buttonlabel;
642  if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate');
643 
644  if ($conf->browser->layout == 'phone') $urlsource.='#'.$forname.'_form'; // So we switch to form after a generation
645  if (empty($noform)) $out.= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc').'" id="'.$forname.'_form" method="post">';
646  $out.= '<input type="hidden" name="action" value="builddoc">';
647  $out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
648 
649  $out.= load_fiche_titre($titletoshow, '', '');
650  $out.= '<div class="div-table-responsive-no-min">';
651  $out.= '<table class="liste formdoc noborder" summary="listofdocumentstable" width="100%">';
652 
653  $out.= '<tr class="liste_titre">';
654 
655  $addcolumforpicto=($delallowed || $printer || $morepicto);
656  $out.= '<th align="center" colspan="'.(3+($addcolumforpicto?1:0)).'" class="formdoc liste_titre maxwidthonsmartphone">';
657 
658  // Model
659  if (! empty($modellist))
660  {
661  $out.= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>';
662  if (is_array($modellist) && count($modellist) == 1) // If there is only one element
663  {
664  $arraykeys=array_keys($modellist);
665  $modelselected=$arraykeys[0];
666  }
667  $out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100');
668  if ($conf->use_javascript_ajax)
669  {
670  $out.= ajax_combobox('model');
671  }
672  }
673  else
674  {
675  $out.= '<div class="float">'.$langs->trans("Files").'</div>';
676  }
677 
678  // Language code (if multilang)
679  if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && ! $forcenomultilang && (! empty($modellist) || $showempty))
680  {
681  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
682  $formadmin=new FormAdmin($this->db);
683  $defaultlang=$codelang?$codelang:$langs->getDefaultLang();
684  $morecss='maxwidth150';
685  if ($conf->browser->layout == 'phone') $morecss='maxwidth100';
686  $out.= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss);
687  }
688  else
689  {
690  $out.= '&nbsp;';
691  }
692 
693  // Button
694  $genbutton = '<input class="button buttongen" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
695  $genbutton.= ' type="submit" value="'.$buttonlabel.'"';
696  if (! $allowgenifempty && ! is_array($modellist) && empty($modellist)) $genbutton.= ' disabled';
697  $genbutton.= '>';
698  if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid')
699  {
700  $langs->load("errors");
701  $genbutton.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
702  }
703  if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton='';
704  if (empty($modellist) && ! $showempty && $modulepart != 'unpaid') $genbutton='';
705  $out.= $genbutton;
706  $out.= '</th>';
707 
708  if (!empty($hookmanager->hooks['formfile']))
709  {
710  foreach($hookmanager->hooks['formfile'] as $module)
711  {
712  if (method_exists($module, 'formBuilddocLineOptions')) $out .= '<th></th>';
713  }
714  }
715  $out.= '</tr>';
716 
717  // Execute hooks
718  $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart);
719  if (is_object($hookmanager))
720  {
721  $reshook = $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']);
722  $out.= $hookmanager->resPrint;
723  }
724  }
725 
726  // Get list of files
727  if (! empty($filedir))
728  {
729  $link_list = array();
730  if (is_object($object))
731  {
732  require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
733  $link = new Link($this->db);
734  $sortfield = $sortorder = null;
735  $res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder);
736  }
737 
738  $out.= '<!-- html.formfile::showdocuments -->'."\n";
739 
740  // Show title of array if not already shown
741  if ((! empty($file_list) || ! empty($link_list) || preg_match('/^massfilesarea/', $modulepart))
742  && ! $headershown)
743  {
744  $headershown=1;
745  $out.= '<div class="titre">'.$titletoshow.'</div>'."\n";
746  $out.= '<div class="div-table-responsive-no-min">';
747  $out.= '<table class="noborder" summary="listofdocumentstable" id="'.$modulepart.'_table" width="100%">'."\n";
748  }
749 
750  // Loop on each file found
751  if (is_array($file_list))
752  {
753  foreach($file_list as $file)
754  {
755  // Define relative path for download link (depends on module)
756  $relativepath=$file["name"]; // Cas general
757  if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture...
758  if ($modulepart == 'export') $relativepath = $file["name"]; // Other case
759 
760  $out.= '<tr class="oddeven">';
761 
762  $documenturl = DOL_URL_ROOT.'/document.php';
763  if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) $documenturl=$conf->global->DOL_URL_ROOT_DOCUMENT_PHP; // To use another wrapper
764 
765  // Show file name with link to download
766  $out.= '<td class="minwidth200">';
767  $out.= '<a class="documentdownload paddingright" href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).($param?'&'.$param:'').'"';
768  $mime=dol_mimetype($relativepath,'',0);
769  if (preg_match('/text/',$mime)) $out.= ' target="_blank"';
770  $out.= ' target="_blank">';
771  $out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]);
772  $out.= dol_trunc($file["name"], 150);
773  $out.= '</a>'."\n";
774  $out.= $this->showPreview($file,$modulepart,$relativepath,0,$param);
775  $out.= '</td>';
776 
777  // Show file size
778  $size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"]));
779  $out.= '<td align="right" class="nowrap">'.dol_print_size($size,1,1).'</td>';
780 
781  // Show file date
782  $date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"]));
783  $out.= '<td align="right" class="nowrap">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>';
784 
785  if ($delallowed || $printer || $morepicto)
786  {
787  $out.= '<td class="right nowraponall">';
788  if ($delallowed)
789  {
790  $tmpurlsource = preg_replace('/#[a-zA-Z0-9_]*$/', '', $urlsource);
791  $out.= '<a href="'.$tmpurlsource.(strpos($tmpurlsource,'?')?'&amp;':'?').'action=remove_file&amp;file='.urlencode($relativepath);
792  $out.= ($param?'&amp;'.$param:'');
793  //$out.= '&modulepart='.$modulepart; // TODO obsolete ?
794  //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
795  $out.= '">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
796  }
797  if ($printer)
798  {
799  //$out.= '<td align="right">';
800  $out.= '<a class="paddingleft" href="'.$urlsource.(strpos($urlsource,'?')?'&amp;':'?').'action=print_file&amp;printer='.$modulepart.'&amp;file='.urlencode($relativepath);
801  $out.= ($param?'&amp;'.$param:'');
802  $out.= '">'.img_picto($langs->trans("PrintFile", $relativepath),'printer.png').'</a>';
803  }
804  if ($morepicto)
805  {
806  $morepicto=preg_replace('/__FILENAMEURLENCODED__/',urlencode($relativepath),$morepicto);
807  $out.=$morepicto;
808  }
809  $out.='</td>';
810  }
811 
812  if (is_object($hookmanager))
813  {
814  $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart,'relativepath'=>$relativepath);
815  $res = $hookmanager->executeHooks('formBuilddocLineOptions',$parameters,$file);
816  if (empty($res))
817  {
818  $out.= $hookmanager->resPrint; // Complete line
819  $out.= '</tr>';
820  }
821  else $out = $hookmanager->resPrint; // Replace line
822  }
823  }
824 
825  $this->numoffiles++;
826  }
827  // Loop on each link found
828  if (is_array($link_list))
829  {
830  $colspan=2;
831 
832  foreach($link_list as $file)
833  {
834  $out.='<tr class="oddeven">';
835  $out.='<td colspan="'.$colspan.'" class="maxwidhtonsmartphone">';
836  $out.='<a data-ajax="false" href="' . $link->url . '" target="_blank">';
837  $out.=$file->label;
838  $out.='</a>';
839  $out.='</td>';
840  $out.='<td align="right">';
841  $out.=dol_print_date($file->datea,'dayhour');
842  $out.='</td>';
843  if ($delallowed || $printer || $morepicto) $out.='<td></td>';
844  $out.='</tr>'."\n";
845  }
846  $this->numoffiles++;
847  }
848 
849  if (count($file_list) == 0 && count($link_list) == 0 && $headershown)
850  {
851  $out.='<tr><td colspan="'.(3+($addcolumforpicto?1:0)).'" class="opacitymedium">'.$langs->trans("None").'</td></tr>'."\n";
852  }
853  }
854 
855  if ($headershown)
856  {
857  // Affiche pied du tableau
858  $out.= "</table>\n";
859  $out.= "</div>\n";
860  if ($genallowed)
861  {
862  if (empty($noform)) $out.= '</form>'."\n";
863  }
864  }
865  $out.= '<!-- End show_document -->'."\n";
866  //return ($i?$i:$headershown);
867  return $out;
868  }
869 
881  function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='')
882  {
883  global $conf, $langs;
884 
885  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
886 
887  $out='';
888  $this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array());
889 
890  $entity = 1; // Without multicompany
891 
892  // Get object entity
893  if (! empty($conf->multicompany->enabled))
894  {
895  preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir,'/').'$/', $filedir, $regs);
896  $entity = ((! empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default
897  }
898 
899  // Get list of files starting with name of ref (but not followed by "-" to discard uploaded files and get only generated files)
900  // @TODO Why not showing by default all files by just removing the '[^\-]+' at end of regex ?
901  if (! empty($conf->global->MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP))
902  {
903  $filterforfilesearch = preg_quote(basename($modulesubdir),'/');
904  }
905  else
906  {
907  $filterforfilesearch = preg_quote(basename($modulesubdir),'/').'[^\-]+';
908  }
909  $file_list=dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // We also discard .meta and .png preview
910 
911  //var_dump($file_list);
912  // For ajax treatment
913  $out.= '<!-- html.formfile::getDocumentsLink -->'."\n";
914  if (! empty($file_list))
915  {
916  $out='<dl class="dropdown inline-block">
917  <dt><a data-ajax="false" href="#" onClick="return false;">'.img_picto('', 'listlight', '', 0, 0, 0, '', 'valignmiddle').'</a></dt>
918  <dd><div class="multichoicedoc" style="position:absolute;left:100px;" ><ul class="ulselectedfields" style="display: none;">';
919  $tmpout='';
920 
921  // Loop on each file found
922  $found=0;
923  foreach($file_list as $file)
924  {
925  $i++;
926  if ($filter && ! preg_match('/'.$filter.'/i', $file["name"])) continue; // Discard this. It does not match provided filter.
927 
928  $found++;
929  // Define relative path for download link (depends on module)
930  $relativepath=$file["name"]; // Cas general
931  if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture...
932  // Autre cas
933  if ($modulepart == 'donation') {
934  $relativepath = get_exdir($modulesubdir,2,0,0,null,'donation').$file["name"];
935  }
936  if ($modulepart == 'export') {
937  $relativepath = $file["name"];
938  }
939 
940  $this->infofiles['nboffiles']++;
941  $this->infofiles['files'][]=$file['fullname'];
942  $ext=pathinfo($file["name"], PATHINFO_EXTENSION);
943  if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext]=1;
944  else $this->infofiles['extensions'][$ext]++;
945 
946  // Preview
947  if (! empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone'))
948  {
949  $tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity='.$entity);
950  if ($tmparray && $tmparray['url'])
951  {
952  $tmpout.= '<li><a href="'.$tmparray['url'].'"'.($tmparray['css']?' class="'.$tmparray['css'].'"':'').($tmparray['mime']?' mime="'.$tmparray['mime'].'"':'').($tmparray['target']?' target="'.$tmparray['target'].'"':'').'>';
953  //$tmpout.= img_picto('','detail');
954  $tmpout.= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>';
955  $tmpout.= $langs->trans("Preview").' '.$ext.'</a></li>';
956  }
957  }
958 
959  // Download
960  $tmpout.= '<li class="nowrap"><a class="pictopreview nowrap" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;entity='.$entity.'&amp;file='.urlencode($relativepath).'"';
961  $mime=dol_mimetype($relativepath,'',0);
962  if (preg_match('/text/',$mime)) $tmpout.= ' target="_blank"';
963  $tmpout.= '>';
964  $tmpout.= img_mime($relativepath, $file["name"]);
965  $tmpout.= $langs->trans("Download").' '.$ext;
966  $tmpout.= '</a></li>'."\n";
967  }
968  $out.=$tmpout;
969  $out.='</ul></div></dd>
970  </dl>';
971 
972  if (! $found) $out='';
973  }
974  else
975  {
976  // TODO Add link to regenerate doc ?
977  //$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
978  }
979 
980  return $out;
981  }
982 
983 
984  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1014  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)
1015  {
1016  // phpcs:enable
1017  global $user, $conf, $langs, $hookmanager;
1018  global $sortfield, $sortorder, $maxheightmini;
1019  global $dolibarr_main_url_root;
1020  global $form;
1021 
1022  $disablecrop=1;
1023  if (in_array($modulepart, array('expensereport','holiday','member','project','product','produit','service','societe','tax','ticket','user'))) $disablecrop=0;
1024 
1025  // Define relative path used to store the file
1026  if (empty($relativepath))
1027  {
1028  $relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/';
1029  if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath; // TODO Call using a defined value for $relativepath
1030  if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
1031  }
1032  // For backward compatiblity, we detect file stored into an old path
1033  if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos')
1034  {
1035  $relativepath=preg_replace('/^.*\/produit\//','',$filearray[0]['path']).'/';
1036  }
1037  // Defined relative dir to DOL_DATA_ROOT
1038  $relativedir = '';
1039  if ($upload_dir)
1040  {
1041  $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
1042  $relativedir = preg_replace('/^[\\/]/','',$relativedir);
1043  }
1044 
1045  $hookmanager->initHooks(array('formfile'));
1046  $parameters=array(
1047  'filearray' => $filearray,
1048  'modulepart'=> $modulepart,
1049  'param' => $param,
1050  'forcedownload' => $forcedownload,
1051  'relativepath' => $relativepath, // relative filename to module dir
1052  'relativedir' => $relativedir, // relative dirname to DOL_DATA_ROOT
1053  'permtodelete' => $permonobject,
1054  'useinecm' => $useinecm,
1055  'textifempty' => $textifempty,
1056  'maxlength' => $maxlength,
1057  'title' => $title,
1058  'url' => $url
1059  );
1060  $reshook=$hookmanager->executeHooks('showFilesList', $parameters, $object);
1061 
1062  if (isset($reshook) && $reshook != '') // null or '' for bypass
1063  {
1064  return $reshook;
1065  }
1066  else
1067  {
1068  if (! is_object($form))
1069  {
1070  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
1071  $form=new Form($this->db);
1072  }
1073 
1074  if (! preg_match('/&id=/', $param) && isset($object->id)) $param.='&id='.$object->id;
1075  $relativepathwihtoutslashend=preg_replace('/\/$/', '', $relativepath);
1076  if ($relativepathwihtoutslashend) $param.= '&file='.urlencode($relativepathwihtoutslashend);
1077 
1078  if ($permtoeditline < 0) // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
1079  {
1080  $permtoeditline=0;
1081  if (in_array($modulepart, array('product','produit','service')))
1082  {
1083  if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoeditline=1;
1084  if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoeditline=1;
1085  }
1086  }
1087  if (empty($conf->global->MAIN_UPLOAD_DOC))
1088  {
1089  $permtoeditline=0;
1090  $permonobject=0;
1091  }
1092 
1093  // Show list of existing files
1094  if (empty($useinecm) && $title != 'none') print load_fiche_titre($title?$title:$langs->trans("AttachedFiles"));
1095  if (empty($url)) $url=$_SERVER["PHP_SELF"];
1096 
1097  print '<!-- html.formfile::list_of_documents -->'."\n";
1098  if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline)
1099  {
1100  print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" method="POST">';
1101  print '<input type="hidden" name="action" value="renamefile">';
1102  print '<input type="hidden" name="id" value="'.$object->id.'">';
1103  print '<input type="hidden" name="modulepart" value="'.$modulepart.'">';
1104  }
1105 
1106  print '<div class="div-table-responsive-no-min">';
1107  print '<table width="100%" id="tablelines" class="'.($useinecm?'liste noborder':'liste').'">'."\n";
1108 
1109  if (! empty($addfilterfields))
1110  {
1111  print '<tr class="liste_titre nodrag nodrop">';
1112  print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref','alpha')).'"></td>';
1113  print '<td></td>';
1114  print '<td></td>';
1115  if (empty($useinecm)) print '<td></td>';
1116  print '<td></td>';
1117  print '<td></td>';
1118  if (! $disablemove) print '<td></td>';
1119  print "</tr>\n";
1120  }
1121 
1122  print '<tr class="liste_titre nodrag nodrop">';
1123  //print $url.' sortfield='.$sortfield.' sortorder='.$sortorder;
1124  print_liste_field_titre('Documents2',$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1125  print_liste_field_titre('Size',$url,"size","",$param,'align="right"',$sortfield,$sortorder);
1126  print_liste_field_titre('Date',$url,"date","",$param,'align="center"',$sortfield,$sortorder);
1127  if (empty($useinecm)) print_liste_field_titre('',$url,"","",$param,'align="center"'); // Preview
1130  if (! $disablemove) print_liste_field_titre('');
1131  print "</tr>\n";
1132 
1133  // Get list of files stored into database for same relative directory
1134  if ($relativedir)
1135  {
1136  completeFileArrayWithDatabaseInfo($filearray, $relativedir);
1137 
1138  //var_dump($sortfield.' - '.$sortorder);
1139  if ($sortfield && $sortorder) // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
1140  {
1141  $filearray=dol_sort_array($filearray, $sortfield, $sortorder);
1142  }
1143  }
1144 
1145  $nboffiles=count($filearray);
1146  if ($nboffiles > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1147 
1148  $i=0; $nboflines = 0; $lastrowid=0;
1149  foreach($filearray as $key => $file) // filearray must be only files here
1150  {
1151  if ($file['name'] != '.'
1152  && $file['name'] != '..'
1153  && ! preg_match('/\.meta$/i',$file['name']))
1154  {
1155  if ($filearray[$key]['rowid'] > 0) $lastrowid = $filearray[$key]['rowid'];
1156  $filepath=$relativepath.$file['name'];
1157 
1158  $editline=0;
1159  $nboflines++;
1160  print '<!-- Line list_of_documents '.$key.' relativepath = '.$relativepath.' -->'."\n";
1161  // Do we have entry into database ?
1162  print '<!-- In database: position='.$filearray[$key]['position'].' -->'."\n";
1163  print '<tr class="oddeven" id="row-'.($filearray[$key]['rowid']>0?$filearray[$key]['rowid']:'AFTER'.$lastrowid.'POS'.($i+1)).'">';
1164 
1165  // File name
1166  print '<td class="minwith200">';
1167 
1168  // Show file name with link to download
1169  //print "XX".$file['name']; //$file['name'] must be utf8
1170  print '<a class="paddingright" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1171  if ($forcedownload) print '&attachment=1';
1172  if (! empty($object->entity)) print '&entity='.$object->entity;
1173  print '&file='.urlencode($filepath);
1174  print '">';
1175  print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'],0,0).')', 'inline-block valignbottom paddingright');
1176  if ($showrelpart == 1) print $relativepath;
1177  //print dol_trunc($file['name'],$maxlength,'middle');
1178  if (GETPOST('action','aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile','alpha')))
1179  {
1180  print '</a>';
1181  $section_dir=dirname(GETPOST('urlfile','alpha'));
1182  print '<input type="hidden" name="section_dir" value="'.$section_dir.'">';
1183  print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">';
1184  print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">';
1185  $editline=1;
1186  }
1187  else
1188  {
1189  print dol_trunc($file['name'], 200);
1190  print '</a>';
1191  }
1192  // Preview link
1193  if (! $editline) print $this->showPreview($file, $modulepart, $filepath);
1194  // Public share link
1195  //if (! $editline && ! empty($filearray[$key]['hashp'])) print pictowithlinktodirectdownload;
1196 
1197  print "</td>\n";
1198 
1199  // Size
1200  $sizetoshow = dol_print_size($file['size'],1,1);
1201  $sizetoshowbytes = dol_print_size($file['size'],0,1);
1202 
1203  print '<td align="right" width="80px">';
1204  if ($sizetoshow == $sizetoshowbytes) print $sizetoshow;
1205  else {
1206  print $form->textwithpicto($sizetoshow, $sizetoshowbytes, -1);
1207  }
1208  print '</td>';
1209 
1210  // Date
1211  print '<td align="center" width="140px">'.dol_print_date($file['date'],"dayhour","tzuser").'</td>'; // 140px = width for date with PM format
1212 
1213  // Preview
1214  if (empty($useinecm))
1215  {
1216  $fileinfo = pathinfo($file['name']);
1217  print '<td align="center">';
1218  if (image_format_supported($file['name']) > 0)
1219  {
1220  $minifile=getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original
1221  if (! dol_is_file($file['path'].'/'.$minifile)) $minifile=getImageFileNameForSize($file['name'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
1222  //print $file['path'].'/'.$minifile.'<br>';
1223 
1224  $urlforhref=getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity)?$object->entity:$conf->entity));
1225  if (empty($urlforhref)) {
1226  $urlforhref=DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
1227  print '<a href="'.$urlforhref.'" class="aphoto" target="_blank">';
1228  } else {
1229  print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
1230  }
1231  print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$minifile).'" title="">';
1232  print '</a>';
1233  }
1234  else print '&nbsp;';
1235  print '</td>';
1236  }
1237 
1238  // Hash of file (only if we are in a mode where a scan of dir were done and we have id of file in ECM table)
1239  print '<td align="center">';
1240  if ($relativedir && $filearray[$key]['rowid'] > 0)
1241  {
1242  if ($editline)
1243  {
1244  print $langs->trans("FileSharedViaALink").' ';
1245  print '<input class="inline-block" type="checkbox" name="shareenabled"'.($file['share']?' checked="checked"':'').' /> ';
1246  }
1247  else
1248  {
1249  if ($file['share'])
1250  {
1251  // Define $urlwithroot
1252  $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
1253  $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
1254  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
1255 
1256  //print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
1257  $forcedownload=0;
1258  $paramlink='';
1259  if (! empty($file['share'])) $paramlink.=($paramlink?'&':'').'hashp='.$file['share']; // Hash for public share
1260  if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1';
1261 
1262  $fulllink=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:'');
1263 
1264  print img_picto($langs->trans("FileSharedViaALink"),'object_globe.png').' ';
1265  print '<input type="text" class="quatrevingtpercent" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).'">';
1266  }
1267  else
1268  {
1269  //print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
1270  }
1271  }
1272  }
1273  print '</td>';
1274 
1275  // Actions buttons
1276  if (! $editline)
1277  {
1278  // Delete or view link
1279  // ($param must start with &)
1280  print '<td class="valignmiddle right actionbuttons"><!-- action on files -->';
1281  if ($useinecm == 1)
1282  {
1283  print '<a href="'.DOL_URL_ROOT.'/ecm/file_card.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>';
1284  }
1285  if (! $useinecm || $useinecm == 2)
1286  {
1287  $newmodulepart=$modulepart;
1288  if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service';
1289 
1290  if (! $disablecrop && image_format_supported($file['name']) > 0)
1291  {
1292  if ($permtoeditline)
1293  {
1294  // Link to resize
1295  print '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("ResizeOrCrop")).'">'.img_picto($langs->trans("ResizeOrCrop"),'resize','class="paddingrightonly"').'</a>';
1296  }
1297  }
1298 
1299  if ($permtoeditline)
1300  {
1301  $paramsectiondir=(in_array($modulepart, array('medias','ecm'))?'&section_dir='.urlencode($relativepath):'');
1302  print '<a href="'.(($useinecm == 1)?'#':($url.'?action=editfile&urlfile='.urlencode($filepath).$paramsectiondir.$param)).'" class="editfilelink" rel="'.$filepath.'">'.img_edit('default',0,'class="paddingrightonly"').'</a>';
1303  }
1304  }
1305  if ($permonobject)
1306  {
1307  $useajax=1;
1308  if (! empty($conf->dol_use_jmobile)) $useajax=0;
1309  if (empty($conf->use_javascript_ajax)) $useajax=0;
1310  if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0;
1311  print '<a href="'.(($useinecm && $useajax)?'#':($url.'?action=delete&urlfile='.urlencode($filepath).$param)).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
1312  }
1313  print "</td>";
1314 
1315  if (empty($disablemove))
1316  {
1317  if ($nboffiles > 1 && $conf->browser->layout != 'phone') {
1318  print '<td align="center" class="linecolmove tdlineupdown">';
1319  if ($i > 0) {
1320  print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=up&amp;rowid='.$line->id.'">'.img_up('default',0,'imgupforline').'</a>';
1321  }
1322  if ($i < $nboffiles-1) {
1323  print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id.'">'.img_down('default',0,'imgdownforline').'</a>';
1324  }
1325  print '</td>';
1326  }
1327  else {
1328  print '<td align="center"'.(($conf->browser->layout != 'phone' && empty($disablemove)) ?' class="linecolmove tdlineupdown"':' class="linecolmove"').'>';
1329  print '</td>';
1330  }
1331  }
1332  }
1333  else
1334  {
1335  print '<td class="right">';
1336  print '<input type="hidden" name="ecmfileid" value="'.$filearray[$key]['rowid'].'">';
1337  print '<input type="submit" class="button" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
1338  print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
1339  print '</td>';
1340  if (empty($disablemove)) print '<td class="right"></td>';
1341  }
1342  print "</tr>\n";
1343 
1344  $i++;
1345  }
1346  }
1347  if ($nboffiles == 0)
1348  {
1349  $colspan=(empty($useinecm)?'6':'6');
1350  if (empty($disablemove)) $colspan++; // 6 columns or 7
1351  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">';
1352  if (empty($textifempty)) print $langs->trans("NoFileFound");
1353  else print $textifempty;
1354  print '</td></tr>';
1355  }
1356  print "</table>";
1357  print '</div>';
1358 
1359  if ($nboflines > 1 && is_object($object)) {
1360  if (! empty($conf->use_javascript_ajax) && $permtoeditline) {
1361  $table_element_line = 'ecm_files';
1362  include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
1363  }
1364  }
1365 
1366  print ajax_autoselect('downloadlink');
1367 
1368  if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline)
1369  {
1370  print '</form>';
1371  }
1372 
1373  return $nboffiles;
1374  }
1375  }
1376 
1377 
1378  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1397  function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload=0, $relativepath='', $permtodelete=1, $useinecm=0, $textifempty='', $maxlength=0, $url='', $addfilterfields=0)
1398  {
1399  // phpcs:enable
1400  global $user, $conf, $langs, $form;
1401  global $sortfield, $sortorder;
1402  global $search_doc_ref;
1403 
1404  dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart);
1405 
1406  // Show list of documents
1407  if (empty($useinecm)) print load_fiche_titre($langs->trans("AttachedFiles"));
1408  if (empty($url)) $url=$_SERVER["PHP_SELF"];
1409 
1410  if (! empty($addfilterfields))
1411  {
1412  print '<form action="'.$_SERVER['PHP_SELF'].'">';
1413  print '<input type="hidden" name="module" value="'.$modulepart.'">';
1414  }
1415 
1416  print '<div class="div-table-responsive-no-min">';
1417  print '<table width="100%" class="noborder">'."\n";
1418 
1419  if (! empty($addfilterfields))
1420  {
1421  print '<tr class="liste_titre nodrag nodrop">';
1422  print '<td></td>';
1423  print '<td><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"></td>';
1424  print '<td></td>';
1425  print '<td></td>';
1426  // Action column
1427  print '<td class="liste_titre" align="middle">';
1428  $searchpicto=$form->showFilterButtons();
1429  print $searchpicto;
1430  print '</td>';
1431  print "</tr>\n";
1432  }
1433 
1434  print '<tr class="liste_titre">';
1435  $sortref="fullname";
1436  if ($modulepart == 'invoice_supplier') $sortref='level1name';
1437  print_liste_field_titre("Ref",$url,$sortref,"",$param,'align="left"',$sortfield,$sortorder);
1438  print_liste_field_titre("Documents2",$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1439  print_liste_field_titre("Size",$url,"size","",$param,'align="right"',$sortfield,$sortorder);
1440  print_liste_field_titre("Date",$url,"date","",$param,'align="center"',$sortfield,$sortorder);
1441  print_liste_field_titre('','','');
1442  print '</tr>'."\n";
1443 
1444  // To show ref or specific information according to view to show (defined by $module)
1445  if ($modulepart == 'company')
1446  {
1447  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1448  $object_instance=new Societe($this->db);
1449  }
1450  else if ($modulepart == 'invoice')
1451  {
1452  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1453  $object_instance=new Facture($this->db);
1454  }
1455  else if ($modulepart == 'invoice_supplier')
1456  {
1457  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1458  $object_instance=new FactureFournisseur($this->db);
1459  }
1460  else if ($modulepart == 'propal')
1461  {
1462  include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
1463  $object_instance=new Propal($this->db);
1464  }
1465  else if ($modulepart == 'supplier_proposal')
1466  {
1467  include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
1468  $object_instance=new SupplierProposal($this->db);
1469  }
1470  else if ($modulepart == 'order')
1471  {
1472  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
1473  $object_instance=new Commande($this->db);
1474  }
1475  else if ($modulepart == 'order_supplier')
1476  {
1477  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
1478  $object_instance=new CommandeFournisseur($this->db);
1479  }
1480  else if ($modulepart == 'contract')
1481  {
1482  include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
1483  $object_instance=new Contrat($this->db);
1484  }
1485  else if ($modulepart == 'product')
1486  {
1487  include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1488  $object_instance=new Product($this->db);
1489  }
1490  else if ($modulepart == 'tax')
1491  {
1492  include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
1493  $object_instance=new ChargeSociales($this->db);
1494  }
1495  else if ($modulepart == 'project')
1496  {
1497  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1498  $object_instance=new Project($this->db);
1499  }
1500  else if ($modulepart == 'fichinter')
1501  {
1502  include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
1503  $object_instance=new Fichinter($this->db);
1504  }
1505  else if ($modulepart == 'user')
1506  {
1507  include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1508  $object_instance=new User($this->db);
1509  }
1510  else if ($modulepart == 'expensereport')
1511  {
1512  include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1513  $object_instance=new ExpenseReport($this->db);
1514  }
1515  else if ($modulepart == 'holiday')
1516  {
1517  include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
1518  $object_instance=new Holiday($this->db);
1519  }
1520 
1521  foreach($filearray as $key => $file)
1522  {
1523  if (!is_dir($file['name'])
1524  && $file['name'] != '.'
1525  && $file['name'] != '..'
1526  && $file['name'] != 'CVS'
1527  && ! preg_match('/\.meta$/i',$file['name']))
1528  {
1529  // Define relative path used to store the file
1530  $relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']);
1531 
1532  //var_dump($file);
1533  $id=0; $ref=''; $label='';
1534 
1535  // To show ref or specific information according to view to show (defined by $module)
1536  if ($modulepart == 'company') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
1537  if ($modulepart == 'invoice') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1538  if ($modulepart == 'invoice_supplier') { preg_match('/([^\/]+)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); if (is_numeric($ref)) { $id=$ref; $ref=''; } } // $ref may be also id with old supplier invoices
1539  if ($modulepart == 'propal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1540  if ($modulepart == 'supplier_proposal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1541  if ($modulepart == 'order') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1542  if ($modulepart == 'order_supplier') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1543  if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1544  if ($modulepart == 'product') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1545  if ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
1546  if ($modulepart == 'project') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');}
1547  if ($modulepart == 'fichinter') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');}
1548  if ($modulepart == 'user') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:'');}
1549  if ($modulepart == 'expensereport') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');}
1550  if ($modulepart == 'holiday') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:'');}
1551 
1552  if (! $id && ! $ref) continue;
1553  $found=0;
1554  if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref]))
1555  {
1556  $found=1;
1557  }
1558  else
1559  {
1560  //print 'Fetch '.$id." - ".$ref.'<br>';
1561 
1562  if ($id) {
1563  $result = $object_instance->fetch($id);
1564  } else {
1565  //fetchOneLike looks for objects with wildcards in its reference.
1566  //It is useful for those masks who get underscores instead of their actual symbols
1567  //fetchOneLike requires some info in the object. If it doesn't have it, then 0 is returned
1568  //that's why we look only look fetchOneLike when fetch returns 0
1569  if (!$result = $object_instance->fetch('', $ref)) {
1570  $result = $object_instance->fetchOneLike($ref);
1571  }
1572  }
1573 
1574  if ($result > 0) { // Save object into a cache
1575  $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref] = clone $object_instance;
1576  }
1577  if ($result == 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]='notfound'; unset($filearray[$key]); }
1578  }
1579 
1580  if (! $found > 0 || ! is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue; // We do not show orphelins files
1581 
1582  print '<!-- Line list_of_autoecmfiles '.$key.' -->'."\n";
1583  print '<tr class="oddeven">';
1584  print '<td>';
1585  if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1,'document');
1586  else print $langs->trans("ObjectDeleted",($id?$id:$ref));
1587 
1588  //$modulesubdir=dol_sanitizeFileName($ref);
1589  $modulesubdir=dirname($relativefile);
1590 
1591  //$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref);
1592  $filedir=$file['path'];
1593  //$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1594  //print $formfile->getDocumentsLink($modulepart, $filename, $filedir);
1595 
1596  print '</td>';
1597 
1598  // File
1599  print '<td>';
1600  //print "XX".$file['name']; //$file['name'] must be utf8
1601  print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1602  if ($forcedownload) print '&attachment=1';
1603  print '&file='.urlencode($relativefile).'">';
1604  print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')');
1605  print dol_trunc($file['name'],$maxlength,'middle');
1606  print '</a>';
1607 
1608  //print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$');
1609  print $this->showPreview($file, $modulepart, $file['relativename']);
1610 
1611  print "</td>\n";
1612  print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>';
1613  print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>';
1614  print '<td align="right">';
1615  //if (! empty($useinecm)) print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1616  //if ($forcedownload) print '&attachment=1';
1617  //print '&file='.urlencode($relativefile).'">';
1618  //print img_view().'</a> &nbsp; ';
1619  //if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
1620  //else print '&nbsp;';
1621  print "</td></tr>\n";
1622  }
1623  }
1624 
1625  if (count($filearray) == 0)
1626  {
1627  print '<tr class="oddeven"><td colspan="5">';
1628  if (empty($textifempty)) print $langs->trans("NoFileFound");
1629  else print $textifempty;
1630  print '</td></tr>';
1631  }
1632  print "</table>";
1633  print '</div>';
1634 
1635  if (! empty($addfilterfields)) print '</form>';
1636  // Fin de zone
1637  }
1638 
1646  private function _formAjaxFileUpload($object)
1647  {
1648  global $langs, $conf;
1649 
1650  // PHP post_max_size
1651  $post_max_size = ini_get('post_max_size');
1652  $mul_post_max_size = substr($post_max_size, -1);
1653  $mul_post_max_size = ($mul_post_max_size == 'M' ? 1048576 : ($mul_post_max_size == 'K' ? 1024 : ($mul_post_max_size == 'G' ? 1073741824 : 1)));
1654  $post_max_size = $mul_post_max_size * (int) $post_max_size;
1655  // PHP upload_max_filesize
1656  $upload_max_filesize = ini_get('upload_max_filesize');
1657  $mul_upload_max_filesize = substr($upload_max_filesize, -1);
1658  $mul_upload_max_filesize = ($mul_upload_max_filesize == 'M' ? 1048576 : ($mul_upload_max_filesize == 'K' ? 1024 : ($mul_upload_max_filesize == 'G' ? 1073741824 : 1)));
1659  $upload_max_filesize = $mul_upload_max_filesize * (int) $upload_max_filesize;
1660  // Max file size
1661  $max_file_size = (($post_max_size < $upload_max_filesize) ? $post_max_size : $upload_max_filesize);
1662 
1663  // Include main
1664  include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_main.tpl.php';
1665 
1666  // Include template
1667  include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php';
1668  }
1669 
1680  public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null, $param='')
1681  {
1682  global $user, $conf, $langs, $user;
1683  global $sortfield, $sortorder;
1684 
1685  $langs->load("link");
1686 
1687  require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
1688  $link = new Link($this->db);
1689  $links = array();
1690  if ($sortfield == "name") {
1691  $sortfield = "label";
1692  } elseif ($sortfield == "date") {
1693  $sortfield = "datea";
1694  } else {
1695  $sortfield = null;
1696  }
1697  $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder);
1698  $param .= (isset($object->id)?'&id=' . $object->id : '');
1699 
1700  // Show list of associated links
1701  print load_fiche_titre($langs->trans("LinkedFiles"));
1702 
1703  print '<form action="' . $_SERVER['PHP_SELF'] . ($param?'?'.$param:'') . '" method="POST">';
1704 
1705  print '<table width="100%" class="liste">';
1706  print '<tr class="liste_titre">';
1708  $langs->trans("Links"),
1709  $_SERVER['PHP_SELF'],
1710  "name",
1711  "",
1712  $param,
1713  'align="left"',
1714  $sortfield,
1715  $sortorder
1716  );
1718  "",
1719  "",
1720  "",
1721  "",
1722  "",
1723  'align="right"'
1724  );
1726  $langs->trans("Date"),
1727  $_SERVER['PHP_SELF'],
1728  "date",
1729  "",
1730  $param,
1731  'align="center"',
1732  $sortfield,
1733  $sortorder
1734  );
1736  '',
1737  $_SERVER['PHP_SELF'],
1738  "",
1739  "",
1740  $param,
1741  'align="center"'
1742  );
1743  print_liste_field_titre('','','');
1744  print '</tr>';
1745  $nboflinks = count($links);
1746  if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1747 
1748  foreach ($links as $link)
1749  {
1750  print '<tr class="oddeven">';
1751  //edit mode
1752  if ($action == 'update' && $selected === $link->id)
1753  {
1754  print '<td>';
1755  print '<input type="hidden" name="id" value="' . $object->id . '">';
1756  print '<input type="hidden" name="linkid" value="' . $link->id . '">';
1757  print '<input type="hidden" name="action" value="confirm_updateline">';
1758  print $langs->trans('Link') . ': <input type="text" name="link" value="' . $link->url . '">';
1759  print '</td>';
1760  print '<td>';
1761  print $langs->trans('Label') . ': <input type="text" name="label" value="' . $link->label . '">';
1762  print '</td>';
1763  print '<td align="center">' . dol_print_date(dol_now(), "dayhour", "tzuser") . '</td>';
1764  print '<td align="right"></td>';
1765  print '<td align="right">';
1766  print '<input type="submit" name="save" class="button" value="' . dol_escape_htmltag($langs->trans('Save')) . '">';
1767  print '<input type="submit" name="cancel" class="button" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '">';
1768  print '</td>';
1769  }
1770  else
1771  {
1772  print '<td>';
1773  print img_picto('', 'object_globe').' ';
1774  print '<a data-ajax="false" href="' . $link->url . '" target="_blank">';
1775  print $link->label;
1776  print '</a>';
1777  print '</td>'."\n";
1778  print '<td align="right"></td>';
1779  print '<td align="center">' . dol_print_date($link->datea, "dayhour", "tzuser") . '</td>';
1780  print '<td align="center"></td>';
1781  print '<td align="right">';
1782  print '<a href="' . $_SERVER['PHP_SELF'] . '?action=update&linkid=' . $link->id . $param . '" class="editfilelink" >' . img_edit() . '</a>'; // id= is included into $param
1783  if ($permtodelete) {
1784  print ' &nbsp; <a href="'. $_SERVER['PHP_SELF'] .'?action=delete&linkid=' . $link->id . $param . '" class="deletefilelink">' . img_delete() . '</a>'; // id= is included into $param
1785  } else {
1786  print '&nbsp;';
1787  }
1788  print '</td>';
1789  }
1790  print "</tr>\n";
1791  }
1792  if ($nboflinks == 0)
1793  {
1794  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">';
1795  print $langs->trans("NoLinkFound");
1796  print '</td></tr>';
1797  }
1798  print "</table>";
1799 
1800  print '</form>';
1801 
1802  return $nboflinks;
1803  }
1804 
1805 
1816  public function showPreview($file, $modulepart, $relativepath, $ruleforpicto=0, $param='')
1817  {
1818  global $langs, $conf;
1819 
1820  $out='';
1821  if ($conf->browser->layout != 'phone' && ! empty($conf->use_javascript_ajax))
1822  {
1823  $urladvancedpreview=getAdvancedPreviewUrl($modulepart, $relativepath, 1, $param); // Return if a file is qualified for preview.
1824  if (count($urladvancedpreview))
1825  {
1826  $out.= '<a class="pictopreview '.$urladvancedpreview['css'].'" href="'.$urladvancedpreview['url'].'"'.(empty($urladvancedpreview['mime'])?'':' mime="'.$urladvancedpreview['mime'].'"').' '.(empty($urladvancedpreview['target'])?'':' target="'.$urladvancedpreview['target'].'"').'>';
1827  //$out.= '<a class="pictopreview">';
1828  if (empty($ruleforpicto))
1829  {
1830  //$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail');
1831  $out.='<span class="fa fa-search-plus" style="color: gray"></span>';
1832  }
1833  else $out.= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']);
1834  $out.= '</a>';
1835  }
1836  }
1837  return $out;
1838  }
1839 }
image_format_supported($file)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:38
Class of the module paid holiday.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:374
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
_formAjaxFileUpload($object)
Show form to upload a new file with jquery fileupload.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
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...
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart)
Return a path to have a the directory according to object where files are stored. ...
completeFileArrayWithDatabaseInfo(&$filearray, $relativedir)
Complete $filearray with data from database.
Definition: files.lib.php:304
Class to manage products or services.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage interventions.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return mime type of a file.
Class to manage Dolibarr users.
Definition: user.class.php:41
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage contracts.
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:552
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
const TYPE_SERVICE
Service.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage suppliers invoices.
const TYPE_PRODUCT
Regular product.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
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)
Show list of documents in $filearray (may be they are all in same directory but may not) This also sy...
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)
Return a string to show the box with list of available documents for object.
img_delete($titlealt='default', $other='class="pictodelete"')
Show delete logo.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Definition: modules_don.php:50
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to generate html code for admin pages.
listOfLinks($object, $permtodelete=1, $action=null, $selected=null, $param='')
Show array with linked files.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
Class to manage third parties objects (customers, suppliers, prospects...)
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
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.
Class to manage projects.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='')
Show information for admin users or standard users.
__construct($db)
Constructor.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage customers orders.
liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
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:59
dol_now($mode='gmt')
Return date for now.
Class to manage Trips and Expenses.
Class to manage predefined suppliers products.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to offer components to list and upload files.
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:451
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
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='')
Show form to upload a new file.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
ajax_autoselect($htmlname, $addlink='')
Make content of an input box selected when we click into input field.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:564
Class to manage price ask supplier.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
Class to manage invoices.
liste_modeles($db, $maxfilenamelength=0)
Load into memory list of available export format.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
Classe permettant la gestion des paiements des charges La tva collectee n&#39;est calculee que sur les fa...
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
showPreview($file, $modulepart, $relativepath, $ruleforpicto=0, $param='')
Show detail icon with link for preview.
getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='')
Show a Document icon with link(s) You may want to call this into a div like this: print &#39;&#39;...
list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload=0, $relativepath='', $permtodelete=1, $useinecm=0, $textifempty='', $maxlength=0, $url='', $addfilterfields=0)
Show list of documents in a directory.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage proposals.