dolibarr  7.0.0-beta
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@capnetworks.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 
39  public $error;
40  public $numoffiles;
41  public $infofiles; // Used to return informations by function getDocumentsLink
42 
43 
49  function __construct($db)
50  {
51  $this->db = $db;
52  $this->numoffiles=0;
53  return 1;
54  }
55 
56 
76  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='')
77  {
78  global $conf,$langs, $hookmanager;
79  $hookmanager->initHooks(array('formfile'));
80 
81 
82  if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax=0;
83 
84  if ((! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax==2))
85  {
86  // TODO: Check this works with 2 forms on same page
87  // TODO: Check this works with GED module, otherwise, force useajax to 0
88  // TODO: This does not support option savingdocmask
89  // TODO: This break feature to upload links too
90  return $this->_formAjaxFileUpload($object);
91  }
92  else
93  {
94  //If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed
95  if (!$perm && !empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
96  return 1;
97  }
98 
99  $maxlength=$size;
100 
101  $out = "\n\n<!-- Start form attach new file -->\n";
102 
103  if (empty($title)) $title=$langs->trans("AttachANewFile");
104  if ($title != 'none') $out.=load_fiche_titre($title, null, null);
105 
106  $out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">';
107  $out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">';
108  $out .= '<input type="hidden" id="'.$htmlname.'_section_id" name="section_id" value="'.$sectionid.'">';
109  $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
110 
111  $out .= '<table width="100%" class="nobordernopadding">';
112  $out .= '<tr>';
113 
114  if (! empty($options)) $out .= '<td>'.$options.'</td>';
115 
116  $out .= '<td class="valignmiddle nowrap">';
117 
118  $max=$conf->global->MAIN_UPLOAD_DOC; // En Kb
119  $maxphp=@ini_get('upload_max_filesize'); // En inconnu
120  if (preg_match('/k$/i',$maxphp)) $maxphp=$maxphp*1;
121  if (preg_match('/m$/i',$maxphp)) $maxphp=$maxphp*1024;
122  if (preg_match('/g$/i',$maxphp)) $maxphp=$maxphp*1024*1024;
123  if (preg_match('/t$/i',$maxphp)) $maxphp=$maxphp*1024*1024*1024;
124  // Now $max and $maxphp are in Kb
125  if ($maxphp > 0) $max=min($max,$maxphp);
126 
127  if ($max > 0)
128  {
129  $out .= '<input type="hidden" name="max_file_size" value="'.($max*1024).'">';
130  }
131 
132  $out .= '<input class="flat minwidth400" type="file"';
133  $out .= ((! empty($conf->global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic')?' name="userfile"':' name="userfile[]" multiple');
134  $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
135  $out .= (!empty($accept)?' accept="'.$accept.'"':' accept=""');
136  $out .= '>';
137  $out .= ' ';
138  $out .= '<input type="submit" class="button" name="sendit" value="'.$langs->trans("Upload").'"';
139  $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
140  $out .= '>';
141 
142  if ($addcancel)
143  {
144  $out .= ' &nbsp; ';
145  $out .= '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
146  }
147 
148  if (! empty($conf->global->MAIN_UPLOAD_DOC))
149  {
150  if ($perm)
151  {
152  $langs->load('other');
153  $out .= ' ';
154  $out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1);
155  }
156  }
157  else
158  {
159  $out .= ' ('.$langs->trans("UploadDisabled").')';
160  }
161  $out .= "</td></tr>";
162 
163  if ($savingdocmask)
164  {
165  $out .= '<tr>';
166  if (! empty($options)) $out .= '<td>'.$options.'</td>';
167  $out .= '<td valign="middle" class="nowrap">';
168  $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"));
169  $out .= '</td>';
170  $out .= '</tr>';
171  }
172 
173  $out .= "</table>";
174 
175  $out .= '</form>';
176  if (empty($sectionid)) $out .= '<br>';
177 
178  $out .= "\n<!-- End form attach new file -->\n";
179 
180  if ($linkfiles)
181  {
182  $out .= "\n<!-- Start form attach new link -->\n";
183  $langs->load('link');
184  $title = $langs->trans("LinkANewFile");
185  $out .= load_fiche_titre($title, null, null);
186  $out .= '<form name="'.$htmlname.'_link" id="'.$htmlname.'_link" action="'.$url.'" method="POST">';
187  $out .= '<input type="hidden" id="'.$htmlname.'_link_section_dir" name="link_section_dir" value="">';
188  $out .= '<input type="hidden" id="'.$htmlname.'_link_section_id" name="link_section_id" value="'.$sectionid.'">';
189  $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
190 
191  $out .= '<div class="valignmiddle" >';
192  $out .= '<div class="inline-block" style="padding-right: 10px;">';
193  if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink") . ':</label> ';
194  $out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">';
195  $out .= '</div>';
196  $out .= '<div class="inline-block" style="padding-right: 10px;">';
197  if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="label">'.$langs->trans("Label") . ':</label> ';
198  $out .= '<input type="text" class="flat" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">';
199  $out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">';
200  $out .= '<input type="hidden" name="objectid" value="' . $object->id . '">';
201  $out .= '</div>';
202  $out .= '<div class="inline-block" style="padding-right: 10px;">';
203  $out .= '<input type="submit" class="button" name="linkit" value="'.$langs->trans("ToLink").'"';
204  $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':'');
205  $out .= '>';
206  $out .= '</div>';
207  $out .= '</div>';
208  $out .= '<div class="clearboth"></div>';
209  $out .= '</form><br>';
210  $parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm);
211  $res = $hookmanager->executeHooks('formattachOptions',$parameters,$object);
212 
213  $out .= "\n<!-- End form attach new file -->\n";
214  }
215 
216  if (empty($res))
217  {
218  print '<div class="attacharea attacharea'.$htmlname.'">';
219  print $out;
220  print '</div>';
221  }
222 
223  print $hookmanager->resPrint;
224 
225  return 1;
226  }
227  }
228 
251  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='')
252  {
253  $this->numoffiles=0;
254  print $this->showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$notused,$noform,$param,$title,$buttonlabel,$codelang);
255  return $this->numoffiles;
256  }
257 
282  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)
283  {
284  // Deprecation warning
285  if (0 !== $iconPDF) {
286  dol_syslog(__METHOD__ . ": passing iconPDF parameter is deprecated", LOG_WARNING);
287  }
288 
289  global $langs, $conf, $user, $hookmanager;
290  global $form, $bc;
291 
292  if (! is_object($form)) $form=new Form($this->db);
293 
294  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
295 
296  // For backward compatibility
297  if (! empty($iconPDF)) {
298  return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir);
299  }
300 
301  $printer=0;
302  if (in_array($modulepart,array('facture','supplier_proposal','propal','proposal','order','commande','expedition', 'commande_fournisseur', 'expensereport'))) // The direct print feature is implemented only for such elements
303  {
304  $printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false;
305  }
306 
307  $hookmanager->initHooks(array('formfile'));
308  $forname='builddoc';
309  $out='';
310 
311  $headershown=0;
312  $showempty=0;
313  $i=0;
314 
315  $out.= "\n".'<!-- Start show_document -->'."\n";
316  //print 'filedir='.$filedir;
317 
318  if (preg_match('/massfilesarea_/', $modulepart))
319  {
320  $out.='<div id="show_files"><br></div>'."\n";
321  $title=$langs->trans("MassFilesArea").' <a href="" id="togglemassfilesarea" ref="shown">('.$langs->trans("Hide").')</a>';
322  $title.='<script type="text/javascript" language="javascript">
323  jQuery(document).ready(function() {
324  jQuery(\'#togglemassfilesarea\').click(function() {
325  if (jQuery(\'#togglemassfilesarea\').attr(\'ref\') == "shown")
326  {
327  jQuery(\'#'.$modulepart.'_table\').hide();
328  jQuery(\'#togglemassfilesarea\').attr("ref", "hidden");
329  jQuery(\'#togglemassfilesarea\').text("('.dol_escape_js($langs->trans("Show")).')");
330  }
331  else
332  {
333  jQuery(\'#'.$modulepart.'_table\').show();
334  jQuery(\'#togglemassfilesarea\').attr("ref","shown");
335  jQuery(\'#togglemassfilesarea\').text("('.dol_escape_js($langs->trans("Hide")).')");
336  }
337  return false;
338  });
339  });
340  </script>';
341  }
342 
343  $titletoshow=$langs->trans("Documents");
344  if (! empty($title)) $titletoshow=$title;
345 
346  // Show table
347  if ($genallowed)
348  {
349  $modellist=array();
350 
351  if ($modulepart == 'company')
352  {
353  $showempty=1;
354  if (is_array($genallowed)) $modellist=$genallowed;
355  else
356  {
357  include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
358  $modellist=ModeleThirdPartyDoc::liste_modeles($this->db);
359  }
360  }
361  else if ($modulepart == 'propal')
362  {
363  if (is_array($genallowed)) $modellist=$genallowed;
364  else
365  {
366  include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
367  $modellist=ModelePDFPropales::liste_modeles($this->db);
368  }
369  }
370  else if ($modulepart == 'supplier_proposal')
371  {
372  if (is_array($genallowed)) $modellist=$genallowed;
373  else
374  {
375  include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
376  $modellist=ModelePDFSupplierProposal::liste_modeles($this->db);
377  }
378  }
379  else if ($modulepart == 'commande')
380  {
381  if (is_array($genallowed)) $modellist=$genallowed;
382  else
383  {
384  include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
385  $modellist=ModelePDFCommandes::liste_modeles($this->db);
386  }
387  }
388  elseif ($modulepart == 'expedition')
389  {
390  if (is_array($genallowed)) $modellist=$genallowed;
391  else
392  {
393  include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
394  $modellist=ModelePDFExpedition::liste_modeles($this->db);
395  }
396  }
397  elseif ($modulepart == 'livraison')
398  {
399  if (is_array($genallowed)) $modellist=$genallowed;
400  else
401  {
402  include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php';
403  $modellist=ModelePDFDeliveryOrder::liste_modeles($this->db);
404  }
405  }
406  else if ($modulepart == 'ficheinter')
407  {
408  if (is_array($genallowed)) $modellist=$genallowed;
409  else
410  {
411  include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
412  $modellist=ModelePDFFicheinter::liste_modeles($this->db);
413  }
414  }
415  elseif ($modulepart == 'facture')
416  {
417  if (is_array($genallowed)) $modellist=$genallowed;
418  else
419  {
420  include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
421  $modellist=ModelePDFFactures::liste_modeles($this->db);
422  }
423  }
424  elseif ($modulepart == 'contract')
425  {
426  if (is_array($genallowed)) $modellist=$genallowed;
427  else
428  {
429  include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
430  $modellist=ModelePDFContract::liste_modeles($this->db);
431  }
432  }
433  elseif ($modulepart == 'project')
434  {
435  if (is_array($genallowed)) $modellist=$genallowed;
436  else
437  {
438  include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
439  $modellist=ModelePDFProjects::liste_modeles($this->db);
440  }
441  }
442  elseif ($modulepart == 'project_task')
443  {
444  if (is_array($genallowed)) $modellist=$genallowed;
445  else
446  {
447  include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
448  $modellist=ModelePDFTask::liste_modeles($this->db);
449  }
450  }
451  elseif ($modulepart == 'product')
452  {
453  if (is_array($genallowed)) $modellist=$genallowed;
454  else
455  {
456  include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
457  $modellist=ModelePDFProduct::liste_modeles($this->db);
458  }
459  }
460  elseif ($modulepart == 'export')
461  {
462  if (is_array($genallowed)) $modellist=$genallowed;
463  else
464  {
465  include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
466  $modellist=ModeleExports::liste_modeles($this->db);
467  }
468  }
469  else if ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order')
470  {
471  if (is_array($genallowed)) $modellist=$genallowed;
472  else
473  {
474  include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
475  $modellist=ModelePDFSuppliersOrders::liste_modeles($this->db);
476  }
477  }
478  else if ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice')
479  {
480  if (is_array($genallowed)) $modellist=$genallowed;
481  else
482  {
483  include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
484  $modellist=ModelePDFSuppliersInvoices::liste_modeles($this->db);
485  }
486  }
487  else if ($modulepart == 'supplier_payment')
488  {
489  if (is_array($genallowed)) $modellist=$genallowed;
490  else
491  {
492  include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
493  $modellist=ModelePDFSuppliersPayments::liste_modeles($this->db);
494  }
495  }
496  else if ($modulepart == 'remisecheque')
497  {
498  if (is_array($genallowed)) $modellist=$genallowed;
499  else
500  {
501  include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
502  $modellist=ModeleChequeReceipts::liste_modeles($this->db);
503  }
504  }
505  elseif ($modulepart == 'donation')
506  {
507  if (is_array($genallowed)) $modellist=$genallowed;
508  else
509  {
510  include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
511  $modellist=ModeleDon::liste_modeles($this->db);
512  }
513  }
514  elseif ($modulepart == 'member')
515  {
516  if (is_array($genallowed)) $modellist=$genallowed;
517  else
518  {
519  include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
520  $modellist=ModelePDFCards::liste_modeles($this->db);
521  }
522  }
523  elseif ($modulepart == 'agenda')
524  {
525  if (is_array($genallowed)) $modellist=$genallowed;
526  else
527  {
528  include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php';
529  $modellist=ModeleAction::liste_modeles($this->db);
530  }
531  }
532  else if ($modulepart == 'expensereport')
533  {
534  if (is_array($genallowed)) $modellist=$genallowed;
535  else
536  {
537  include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
538  $modellist=ModeleExpenseReport::liste_modeles($this->db);
539  }
540  }
541  else if ($modulepart == 'unpaid')
542  {
543  $modellist='';
544  }
545  elseif ($modulepart == 'user')
546  {
547  if (is_array($genallowed)) $modellist=$genallowed;
548  else
549  {
550  include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php';
551  $modellist=ModelePDFUser::liste_modeles($this->db);
552  }
553  }
554  elseif ($modulepart == 'usergroup')
555  {
556  if (is_array($genallowed)) $modellist=$genallowed;
557  else
558  {
559  include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php';
560  $modellist=ModelePDFUserGroup::liste_modeles($this->db);
561  }
562  }
563  else //if ($modulepart != 'agenda')
564  {
565  // For normalized standard modules
566  $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
567  if (file_exists($file))
568  {
569  $res=include_once $file;
570  }
571  // For normalized external modules
572  else
573  {
574  $file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
575  $res=include_once $file;
576  }
577  $class='Modele'.ucfirst($modulepart);
578  if (class_exists($class))
579  {
580  $modellist=call_user_func($class.'::liste_modeles',$this->db);
581  }
582  else
583  {
584  dol_print_error($this->db,'Bad value for modulepart');
585  return -1;
586  }
587  }
588 
589  // Set headershown to avoit to have table opened a second time later
590  $headershown=1;
591 
592  $buttonlabeltoshow=$buttonlabel;
593  if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate');
594 
595  if ($conf->browser->layout == 'phone') $urlsource.='#'.$forname.'_form'; // So we switch to form after a generation
596  if (empty($noform)) $out.= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc').'" id="'.$forname.'_form" method="post">';
597  $out.= '<input type="hidden" name="action" value="builddoc">';
598  $out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
599 
600  $out.= load_fiche_titre($titletoshow, '', '');
601  $out.= '<div class="div-table-responsive-no-min">';
602  $out.= '<table class="liste formdoc noborder" summary="listofdocumentstable" width="100%">';
603 
604  $out.= '<tr class="liste_titre">';
605 
606  $addcolumforpicto=($delallowed || $printer || $morepicto);
607  $out.= '<th align="center" colspan="'.(3+($addcolumforpicto?'2':'1')).'" class="formdoc liste_titre maxwidthonsmartphone">';
608 
609  // Model
610  if (! empty($modellist))
611  {
612  $out.= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>';
613  if (is_array($modellist) && count($modellist) == 1) // If there is only one element
614  {
615  $arraykeys=array_keys($modellist);
616  $modelselected=$arraykeys[0];
617  }
618  $out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100');
619  if ($conf->use_javascript_ajax)
620  {
621  $out.= ajax_combobox('model');
622  }
623  }
624  else
625  {
626  $out.= '<div class="float">'.$langs->trans("Files").'</div>';
627  }
628 
629  // Language code (if multilang)
630  if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && ! $forcenomultilang && (! empty($modellist) || $showempty))
631  {
632  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
633  $formadmin=new FormAdmin($this->db);
634  $defaultlang=$codelang?$codelang:$langs->getDefaultLang();
635  $morecss='maxwidth150';
636  if (! empty($conf->browser->phone)) $morecss='maxwidth100';
637  $out.= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss);
638  }
639  else
640  {
641  $out.= '&nbsp;';
642  }
643 
644  // Button
645  $genbutton = '<input class="button buttongen" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
646  $genbutton.= ' type="submit" value="'.$buttonlabel.'"';
647  if (! $allowgenifempty && ! is_array($modellist) && empty($modellist)) $genbutton.= ' disabled';
648  $genbutton.= '>';
649  if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid')
650  {
651  $langs->load("errors");
652  $genbutton.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
653  }
654  if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton='';
655  if (empty($modellist) && ! $showempty && $modulepart != 'unpaid') $genbutton='';
656  $out.= $genbutton;
657  $out.= '</th>';
658 
659  if (!empty($hookmanager->hooks['formfile']))
660  {
661  foreach($hookmanager->hooks['formfile'] as $module)
662  {
663  if (method_exists($module, 'formBuilddocLineOptions')) $out .= '<th></th>';
664  }
665  }
666  $out.= '</tr>';
667 
668  // Execute hooks
669  $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart);
670  if (is_object($hookmanager))
671  {
672  $reshook = $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']);
673  $out.= $hookmanager->resPrint;
674  }
675 
676  }
677 
678  // Get list of files
679  if (! empty($filedir))
680  {
681  $file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview.*.*\.png)$','date',SORT_DESC);
682 
683  $link_list = array();
684  if (is_object($object))
685  {
686  require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
687  $link = new Link($this->db);
688  $sortfield = $sortorder = null;
689  $res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder);
690  }
691 
692  $out.= '<!-- html.formfile::showdocuments -->'."\n";
693 
694  // Show title of array if not already shown
695  if ((! empty($file_list) || ! empty($link_list) || preg_match('/^massfilesarea/', $modulepart)) && ! $headershown)
696  {
697  $headershown=1;
698  $out.= '<div class="titre">'.$titletoshow.'</div>'."\n";
699  $out.= '<div class="div-table-responsive-no-min">';
700  $out.= '<table class="noborder" summary="listofdocumentstable" id="'.$modulepart.'_table" width="100%">'."\n";
701  }
702 
703  // Loop on each file found
704  if (is_array($file_list))
705  {
706  foreach($file_list as $file)
707  {
708  // Define relative path for download link (depends on module)
709  $relativepath=$file["name"]; // Cas general
710  if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture...
711  if ($modulepart == 'export') $relativepath = $file["name"]; // Other case
712 
713  $out.= '<tr class="oddeven">';
714 
715  $documenturl = DOL_URL_ROOT.'/document.php';
716  if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) $documenturl=$conf->global->DOL_URL_ROOT_DOCUMENT_PHP; // To use another wrapper
717 
718  // Show file name with link to download
719  $out.= '<td class="tdoverflowmax300">';
720  $out.= '<a class="documentdownload paddingright" href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).($param?'&'.$param:'').'"';
721  $mime=dol_mimetype($relativepath,'',0);
722  if (preg_match('/text/',$mime)) $out.= ' target="_blank"';
723  $out.= ' target="_blank">';
724  $out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]);
725  $out.= $file["name"];
726  $out.= '</a>'."\n";
727  $out.= $this->showPreview($file,$modulepart,$relativepath,0,$param);
728  $out.= '</td>';
729 
730  // Show file size
731  $size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"]));
732  $out.= '<td align="right" class="nowrap">'.dol_print_size($size).'</td>';
733 
734  // Show file date
735  $date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"]));
736  $out.= '<td align="right" class="nowrap">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>';
737 
738  if ($delallowed || $printer || $morepicto)
739  {
740  $out.= '<td align="right">';
741  if ($delallowed)
742  {
743  $out.= '<a href="'.$urlsource.(strpos($urlsource,'?')?'&amp;':'?').'action=remove_file&amp;file='.urlencode($relativepath);
744  $out.= ($param?'&amp;'.$param:'');
745  //$out.= '&modulepart='.$modulepart; // TODO obsolete ?
746  //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
747  $out.= '">'.img_picto($langs->trans("Delete"), 'delete.png').'</a>';
748  }
749  if ($printer)
750  {
751  //$out.= '<td align="right">';
752  $out.= '<a class="paddingleft" href="'.$urlsource.(strpos($urlsource,'?')?'&amp;':'?').'action=print_file&amp;printer='.$modulepart.'&amp;file='.urlencode($relativepath);
753  $out.= ($param?'&amp;'.$param:'');
754  $out.= '">'.img_picto($langs->trans("PrintFile", $relativepath),'printer.png').'</a>';
755  }
756  if ($morepicto)
757  {
758  $morepicto=preg_replace('/__FILENAMEURLENCODED__/',urlencode($relativepath),$morepicto);
759  $out.=$morepicto;
760  }
761  $out.='</td>';
762  }
763 
764  if (is_object($hookmanager))
765  {
766  $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart,'relativepath'=>$relativepath);
767  $res = $hookmanager->executeHooks('formBuilddocLineOptions',$parameters,$file);
768  if (empty($res))
769  {
770  $out .= $hookmanager->resPrint; // Complete line
771  $out.= '</tr>';
772  }
773  else $out = $hookmanager->resPrint; // Replace line
774  }
775  }
776 
777  $this->numoffiles++;
778  }
779  // Loop on each file found
780  if (is_array($link_list))
781  {
782  $colspan=2;
783 
784  foreach($link_list as $file)
785  {
786  $out.='<tr class="oddeven">';
787  $out.='<td colspan="'.$colspan.'" class="maxwidhtonsmartphone">';
788  $out.='<a data-ajax="false" href="' . $link->url . '" target="_blank">';
789  $out.=$file->label;
790  $out.='</a>';
791  $out.='</td>';
792  $out.='<td align="right">';
793  $out.=dol_print_date($file->datea,'dayhour');
794  $out.='</td>';
795  if ($delallowed || $printer || $morepicto) $out.='<td></td>';
796  $out.='</tr>'."\n";
797  }
798  $this->numoffiles++;
799  }
800 
801  if (count($file_list) == 0 && count($link_list) == 0 && $headershown)
802  {
803  $out.='<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>'."\n";
804  }
805 
806  }
807 
808  if ($headershown)
809  {
810  // Affiche pied du tableau
811  $out.= "</table>\n";
812  $out.= "</div>\n";
813  if ($genallowed)
814  {
815  if (empty($noform)) $out.= '</form>'."\n";
816  }
817  }
818  $out.= '<!-- End show_document -->'."\n";
819  //return ($i?$i:$headershown);
820  return $out;
821  }
822 
834  function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='')
835  {
836  global $conf, $langs;
837 
838  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
839 
840  $out='';
841  $this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array());
842 
843  $filterforfilesearch = preg_quote(basename($modulesubdir),'/').'[^\-]+';
844 
845  $file_list=dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // Get list of files starting with name of ref (but not followed by "-" to discard uploaded files)
846 
847  //var_dump($file_list);
848  // For ajax treatment
849  $out.= '<!-- html.formfile::getDocumentsLink -->'."\n";
850  if (! empty($file_list))
851  {
852  $out='<dl class="dropdown inline-block">
853  <dt><a data-ajax="false" href="#" onClick="return false;">'.img_picto('', 'listlight', '', 0, 0, 0, '', 'valignbottom').'</a></dt>
854  <dd><div class="multichoicedoc" style="position:absolute;left:100px;" ><ul class="ulselectedfields" style="display: none;">';
855  $tmpout='';
856 
857  // Loop on each file found
858  $found=0;
859  foreach($file_list as $file)
860  {
861  $i++;
862  if ($filter && ! preg_match('/'.$filter.'/i', $file["name"])) continue; // Discard this. It does not match provided filter.
863 
864  $found++;
865  // Define relative path for download link (depends on module)
866  $relativepath=$file["name"]; // Cas general
867  if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture...
868  // Autre cas
869  if ($modulepart == 'donation') {
870  $relativepath = get_exdir($modulesubdir,2,0,0,null,'donation').$file["name"];
871  }
872  if ($modulepart == 'export') {
873  $relativepath = $file["name"];
874  }
875 
876  $this->infofiles['nboffiles']++;
877  $this->infofiles['files'][]=$file['fullname'];
878  $ext=pathinfo($file["name"], PATHINFO_EXTENSION);
879  if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext]=1;
880  else $this->infofiles['extensions'][$ext]++;
881 
882  // Preview
883  if (! empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone'))
884  {
885  $tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity='.$entity);
886  if ($tmparray && $tmparray['url'])
887  {
888  $tmpout.= '<li><a href="'.$tmparray['url'].'"'.($tmparray['css']?' class="'.$tmparray['css'].'"':'').($tmparray['mime']?' mime="'.$tmparray['mime'].'"':'').($tmparray['target']?' target="'.$tmparray['target'].'"':'').'>';
889  //$tmpout.= img_picto('','detail');
890  $tmpout.= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>';
891  $tmpout.= $langs->trans("Preview").' '.$ext.'</a></li>';
892  }
893  }
894 
895  // Download
896  $tmpout.= '<li class="nowrap"><a class="pictopreview nowrap" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"';
897  $mime=dol_mimetype($relativepath,'',0);
898  if (preg_match('/text/',$mime)) $tmpout.= ' target="_blank"';
899  $tmpout.= '>';
900  $tmpout.= img_mime($relativepath, $file["name"]);
901  $tmpout.= $langs->trans("Download").' '.$ext;
902  $tmpout.= '</a></li>'."\n";
903  }
904  $out.=$tmpout;
905  $out.='</ul></div></dd>
906  </dl>';
907 
908  if (! $found) $out='';
909  }
910  else
911  {
912  // TODO Add link to regenerate doc ?
913  //$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
914  }
915 
916  return $out;
917  }
918 
919 
949  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)
950  {
951  global $user, $conf, $langs, $hookmanager;
952  global $bc,$bcdd;
953  global $sortfield, $sortorder, $maxheightmini;
954 
955  // Define relative path used to store the file
956  if (empty($relativepath))
957  {
958  $relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/';
959  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
960  if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
961  }
962  // For backward compatiblity, we detect file stored into an old path
963  if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos')
964  {
965  $relativepath=preg_replace('/^.*\/produit\//','',$filearray[0]['path']).'/';
966  }
967  // Defined relative dir to DOL_DATA_ROOT
968  $relativedir = '';
969  if ($upload_dir)
970  {
971  $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
972  $relativedir = preg_replace('/^[\\/]/','',$relativedir);
973  }
974 
975  $hookmanager->initHooks(array('formfile'));
976  $parameters=array(
977  'filearray' => $filearray,
978  'modulepart'=> $modulepart,
979  'param' => $param,
980  'forcedownload' => $forcedownload,
981  'relativepath' => $relativepath, // relative filename to module dir
982  'relativedir' => $relativedir, // relative dirname to DOL_DATA_ROOT
983  'permtodelete' => $permonobject,
984  'useinecm' => $useinecm,
985  'textifempty' => $textifempty,
986  'maxlength' => $maxlength,
987  'title' => $title,
988  'url' => $url
989  );
990  $reshook=$hookmanager->executeHooks('showFilesList', $parameters, $object);
991 
992  if (isset($reshook) && $reshook != '') // null or '' for bypass
993  {
994  return $reshook;
995  }
996  else
997  {
998  if (! preg_match('/&id=/', $param) && isset($object->id)) $param.='&id='.$object->id;
999  $relativepathwihtoutslashend=preg_replace('/\/$/', '', $relativepath);
1000  if ($relativepathwihtoutslashend) $param.= '&file='.urlencode($relativepathwihtoutslashend);
1001 
1002  if ($permtoeditline < 0) // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
1003  {
1004  $permtoeditline=0;
1005  if (in_array($modulepart, array('product','produit','service')))
1006  {
1007  if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoeditline=1;
1008  if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoeditline=1;
1009  }
1010  }
1011  if (empty($conf->global->MAIN_UPLOAD_DOC))
1012  {
1013  $permtoeditline=0;
1014  $permonobject=0;
1015  }
1016 
1017  // Show list of existing files
1018  if (empty($useinecm) && $title != 'none') print load_fiche_titre($title?$title:$langs->trans("AttachedFiles"));
1019  if (empty($url)) $url=$_SERVER["PHP_SELF"];
1020 
1021  print '<!-- html.formfile::list_of_documents -->'."\n";
1022  if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline)
1023  {
1024  print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" method="POST">';
1025  print '<input type="hidden" name="action" value="renamefile">';
1026  print '<input type="hidden" name="id" value="'.$object->id.'">';
1027  print '<input type="hidden" name="modulepart" value="'.$modulepart.'">';
1028  }
1029 
1030  print '<div class="div-table-responsive-no-min">';
1031  print '<table width="100%" id="tablelines" class="'.($useinecm?'liste noborder':'liste').'">'."\n";
1032 
1033  if (! empty($addfilterfields))
1034  {
1035  print '<tr class="liste_titre nodrag nodrop">';
1036  print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref','alpha')).'"></td>';
1037  print '<td></td>';
1038  print '<td></td>';
1039  if (empty($useinecm)) print '<td></td>';
1040  print '<td></td>';
1041  if (! $disablemove) print '<td></td>';
1042  print "</tr>\n";
1043  }
1044 
1045  print '<tr class="liste_titre nodrag nodrop">';
1046  //print $url.' sortfield='.$sortfield.' sortorder='.$sortorder;
1047  print_liste_field_titre('Documents2',$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1048  print_liste_field_titre('Size',$url,"size","",$param,'align="right"',$sortfield,$sortorder);
1049  print_liste_field_titre('Date',$url,"date","",$param,'align="center"',$sortfield,$sortorder);
1050  if (empty($useinecm)) print_liste_field_titre('',$url,"","",$param,'align="center"');
1052  if (! $disablemove) print_liste_field_titre('');
1053  print "</tr>\n";
1054 
1055  // Get list of files stored into database for same relative directory
1056  if ($relativedir)
1057  {
1058  completeFileArrayWithDatabaseInfo($filearray, $relativedir);
1059 
1060  //var_dump($sortfield.' - '.$sortorder);
1061  if ($sortfield && $sortorder) // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
1062  {
1063  //var_dump($sortfield);
1064  $filearray=dol_sort_array($filearray, $sortfield, $sortorder);
1065  }
1066  //var_dump($filearray);
1067  }
1068 
1069  $nboffiles=count($filearray);
1070  if ($nboffiles > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1071 
1072  $i=0; $nboflines = 0; $lastrowid=0;
1073  foreach($filearray as $key => $file) // filearray must be only files here
1074  {
1075  if ($file['name'] != '.'
1076  && $file['name'] != '..'
1077  && ! preg_match('/\.meta$/i',$file['name']))
1078  {
1079  if ($filearray[$key]['rowid'] > 0) $lastrowid = $filearray[$key]['rowid'];
1080  $filepath=$relativepath.$file['name'];
1081 
1082  $editline=0;
1083  $nboflines++;
1084  print '<!-- Line list_of_documents '.$key.' relativepath = '.$relativepath.' -->'."\n";
1085  // Do we have entry into database ?
1086  print '<!-- In database: position='.$filearray[$key]['position'].' -->'."\n";
1087  print '<tr id="row-'.($filearray[$key]['rowid']>0?$filearray[$key]['rowid']:'-AFTER'.$lastrowid.'POS'.($i+1)).'">';
1088 
1089  // File name
1090  print '<td class="tdoverflowmax300">';
1091 
1092  // Show file name with link to download
1093  //print "XX".$file['name']; //$file['name'] must be utf8
1094  print '<a class="paddingright" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1095  if ($forcedownload) print '&attachment=1';
1096  if (! empty($object->entity)) print '&entity='.$object->entity;
1097  print '&file='.urlencode($filepath);
1098  print '">';
1099  print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'],0,0).')', 'inline-block valignbottom paddingright');
1100  if ($showrelpart == 1) print $relativepath;
1101  //print dol_trunc($file['name'],$maxlength,'middle');
1102  if (GETPOST('action','aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile','alpha')))
1103  {
1104  print '</a>';
1105  $section_dir=dirname(GETPOST('urlfile','alpha'));
1106  print '<input type="hidden" name="section_dir" value="'.$section_dir.'">';
1107  print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">';
1108  print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">';
1109  $editline=1;
1110  }
1111  else
1112  {
1113  print $file['name'];
1114  print '</a>';
1115  }
1116  // Preview link
1117  if (! $editline) print $this->showPreview($file, $modulepart, $filepath);
1118  // Public share link
1119  //if (! $editline && ! empty($filearray[$key]['hashp'])) print pictowithlinktodirectdownload;
1120 
1121  print "</td>\n";
1122 
1123  // Size
1124  print '<td align="right" width="80px">'.dol_print_size($file['size'],1,1).'</td>';
1125 
1126  // Date
1127  print '<td align="center" width="130px">'.dol_print_date($file['date'],"dayhour","tzuser").'</td>';
1128 
1129  // Preview
1130  if (empty($useinecm))
1131  {
1132  $fileinfo = pathinfo($file['name']);
1133  print '<td align="center">';
1134  if (image_format_supported($file['name']) > 0)
1135  {
1136  $minifile=getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original
1137  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
1138  //print $file['path'].'/'.$minifile.'<br>';
1139 
1140  $urlforhref=getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 0, '&entity='.(!empty($object->entity)?$object->entity:$conf->entity));
1141  if (empty($urlforhref)) $urlforhref=DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
1142  print '<a href="'.$urlforhref.'" class="aphoto" target="_blank">';
1143  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="">';
1144  print '</a>';
1145  }
1146  else print '&nbsp;';
1147  print '</td>';
1148  }
1149  if (! $editline)
1150  {
1151  // Delete or view link
1152  // ($param must start with &)
1153  print '<td class="valignmiddle right actionbuttons"><!-- action on files -->';
1154  if ($useinecm == 1)
1155  {
1156  print '<a href="'.DOL_URL_ROOT.'/ecm/file_card.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_view('default', 0, 'class="paddingrightonly"').'</a>';
1157  }
1158  if (! $useinecm || $useinecm == 2)
1159  {
1160  $newmodulepart=$modulepart;
1161  if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service';
1162 
1163  $disablecrop=1;
1164  if (in_array($modulepart, array('societe','product','produit','service','expensereport','holiday','project','user'))) $disablecrop=0;
1165 
1166  if (! $disablecrop && image_format_supported($file['name']) > 0)
1167  {
1168  if ($permtoeditline)
1169  {
1170  // Link to resize
1171  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("Resize")).'">'.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','class="paddingrightonly"',1).'</a>';
1172  }
1173  }
1174 
1175  if ($permtoeditline)
1176  {
1177  print '<a href="'.(($useinecm == 1)?'#':($url.'?action=editfile&urlfile='.urlencode($filepath).$param)).'" class="editfilelink" rel="'.$filepath.'">'.img_edit('default',0,'class="paddingrightonly"').'</a>';
1178  }
1179  }
1180  if ($permonobject)
1181  {
1182  /*
1183  if ($file['level1name'] <> $object->id)
1184  $filepath=$file['level1name'].'/'.$file['name'];
1185  else
1186  $filepath=$file['name'];
1187  */
1188  $useajax=1;
1189  if (! empty($conf->dol_use_jmobile)) $useajax=0;
1190  if (empty($conf->use_javascript_ajax)) $useajax=0;
1191  if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0;
1192 
1193  print '<a href="'.(($useinecm && $useajax)?'#':$url.'?action=delete&urlfile='.urlencode($filepath).$param).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
1194  }
1195  print "</td>";
1196 
1197  if (empty($disablemove))
1198  {
1199  if ($nboffiles > 1 && empty($conf->browser->phone)) {
1200  print '<td align="center" class="linecolmove tdlineupdown">';
1201  if ($i > 0) {
1202  print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=up&amp;rowid='.$line->id.'">'.img_up('default',0,'imgupforline').'</a>';
1203  }
1204  if ($i < $nboffiles-1) {
1205  print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id.'">'.img_down('default',0,'imgdownforline').'</a>';
1206  }
1207  print '</td>';
1208  }
1209  else {
1210  print '<td align="center"'.((empty($conf->browser->phone) && empty($disablemove)) ?' class="linecolmove tdlineupdown"':' class="linecolmove"').'>';
1211  print '</td>';
1212  }
1213  }
1214  }
1215  else
1216  {
1217  print '<td class="right">';
1218  print '<input type="submit" class="button" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
1219  print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
1220  print '</td>';
1221  if (empty($disablemove)) print '<td class="right"></td>';
1222  }
1223  print "</tr>\n";
1224 
1225  $i++;
1226  }
1227  }
1228  if ($nboffiles == 0)
1229  {
1230  $colspan=(empty($useinecm)?'5':'5');
1231  if (empty($disablemove)) $colspan++;
1232  print '<tr '.$bc[false].'><td colspan="'.$colspan.'" class="opacitymedium">';
1233  if (empty($textifempty)) print $langs->trans("NoFileFound");
1234  else print $textifempty;
1235  print '</td></tr>';
1236  }
1237  print "</table>";
1238  print '</div>';
1239 
1240  if ($nboflines > 1 && is_object($object)) {
1241  if (! empty($conf->use_javascript_ajax) && $permtoeditline) {
1242  $table_element_line = 'ecm_files';
1243  include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
1244  }
1245  }
1246 
1247  if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline)
1248  {
1249  print '</form>';
1250  }
1251 
1252  return $nboffiles;
1253  }
1254  }
1255 
1256 
1275  function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload=0, $relativepath='', $permtodelete=1, $useinecm=0, $textifempty='', $maxlength=0, $url='', $addfilterfields=0)
1276  {
1277  global $user, $conf, $langs, $form;
1278  global $bc;
1279  global $sortfield, $sortorder;
1280  global $search_doc_ref;
1281 
1282  dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart);
1283 
1284  // Show list of documents
1285  if (empty($useinecm)) print load_fiche_titre($langs->trans("AttachedFiles"));
1286  if (empty($url)) $url=$_SERVER["PHP_SELF"];
1287 
1288  if (! empty($addfilterfields))
1289  {
1290  print '<form action="'.$_SERVER['PHP_SELF'].'">';
1291  print '<input type="hidden" name="module" value="'.$modulepart.'">';
1292  }
1293 
1294  print '<div class="div-table-responsive-no-min">';
1295  print '<table width="100%" class="noborder">'."\n";
1296 
1297  if (! empty($addfilterfields))
1298  {
1299  print '<tr class="liste_titre nodrag nodrop">';
1300  print '<td><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"></td>';
1301  print '<td></td>';
1302  print '<td></td>';
1303  print '<td></td>';
1304  // Action column
1305  print '<td class="liste_titre" align="middle">';
1306  $searchpicto=$form->showFilterButtons();
1307  print $searchpicto;
1308  print '</td>';
1309  print "</tr>\n";
1310  }
1311 
1312  print '<tr class="liste_titre">';
1313  $sortref="fullname";
1314  if ($modulepart == 'invoice_supplier') $sortref='level1name';
1315  print_liste_field_titre("Ref",$url,$sortref,"",$param,'align="left"',$sortfield,$sortorder);
1316  print_liste_field_titre("Documents2",$url,"name","",$param,'align="left"',$sortfield,$sortorder);
1317  print_liste_field_titre("Size",$url,"size","",$param,'align="right"',$sortfield,$sortorder);
1318  print_liste_field_titre("Date",$url,"date","",$param,'align="center"',$sortfield,$sortorder);
1319  print_liste_field_titre('','','');
1320  print '</tr>'."\n";
1321 
1322  // To show ref or specific information according to view to show (defined by $module)
1323  if ($modulepart == 'company')
1324  {
1325  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1326  $object_instance=new Societe($this->db);
1327  }
1328  else if ($modulepart == 'invoice')
1329  {
1330  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1331  $object_instance=new Facture($this->db);
1332  }
1333  else if ($modulepart == 'invoice_supplier')
1334  {
1335  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1336  $object_instance=new FactureFournisseur($this->db);
1337  }
1338  else if ($modulepart == 'propal')
1339  {
1340  include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
1341  $object_instance=new Propal($this->db);
1342  }
1343  else if ($modulepart == 'supplier_proposal')
1344  {
1345  include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
1346  $object_instance=new SupplierProposal($this->db);
1347  }
1348  else if ($modulepart == 'order')
1349  {
1350  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
1351  $object_instance=new Commande($this->db);
1352  }
1353  else if ($modulepart == 'order_supplier')
1354  {
1355  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
1356  $object_instance=new CommandeFournisseur($this->db);
1357  }
1358  else if ($modulepart == 'contract')
1359  {
1360  include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
1361  $object_instance=new Contrat($this->db);
1362  }
1363  else if ($modulepart == 'product')
1364  {
1365  include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1366  $object_instance=new Product($this->db);
1367  }
1368  else if ($modulepart == 'tax')
1369  {
1370  include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
1371  $object_instance=new ChargeSociales($this->db);
1372  }
1373  else if ($modulepart == 'project')
1374  {
1375  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1376  $object_instance=new Project($this->db);
1377  }
1378  else if ($modulepart == 'fichinter')
1379  {
1380  include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
1381  $object_instance=new Fichinter($this->db);
1382  }
1383  else if ($modulepart == 'user')
1384  {
1385  include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1386  $object_instance=new User($this->db);
1387  }
1388  else if ($modulepart == 'expensereport')
1389  {
1390  include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1391  $object_instance=new ExpenseReport($this->db);
1392  }
1393 
1394  foreach($filearray as $key => $file)
1395  {
1396  if (!is_dir($file['name'])
1397  && $file['name'] != '.'
1398  && $file['name'] != '..'
1399  && $file['name'] != 'CVS'
1400  && ! preg_match('/\.meta$/i',$file['name']))
1401  {
1402  // Define relative path used to store the file
1403  $relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']);
1404 
1405  //var_dump($file);
1406  $id=0; $ref=''; $label='';
1407 
1408  // To show ref or specific information according to view to show (defined by $module)
1409  if ($modulepart == 'company') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
1410  if ($modulepart == 'invoice') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1411  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
1412  if ($modulepart == 'propal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1413  if ($modulepart == 'supplier_proposal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1414  if ($modulepart == 'order') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1415  if ($modulepart == 'order_supplier') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1416  if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1417  if ($modulepart == 'product') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
1418  if ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
1419  if ($modulepart == 'project') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');}
1420  if ($modulepart == 'fichinter') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');}
1421  if ($modulepart == 'user') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:'');}
1422  if ($modulepart == 'expensereport') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:'');}
1423 
1424  if (! $id && ! $ref) continue;
1425  $found=0;
1426  if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref]))
1427  {
1428  $found=1;
1429  }
1430  else
1431  {
1432  //print 'Fetch '.$id." - ".$ref.'<br>';
1433 
1434  if ($id) {
1435  $result = $object_instance->fetch($id);
1436  } else {
1437  //fetchOneLike looks for objects with wildcards in its reference.
1438  //It is useful for those masks who get underscores instead of their actual symbols
1439  //fetchOneLike requires some info in the object. If it doesn't have it, then 0 is returned
1440  //that's why we look only look fetchOneLike when fetch returns 0
1441  if (!$result = $object_instance->fetch('', $ref)) {
1442  $result = $object_instance->fetchOneLike($ref);
1443  }
1444  }
1445 
1446  if ($result > 0) { // Save object into a cache
1447  $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref] = clone $object_instance;
1448  }
1449  if ($result == 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]='notfound'; unset($filearray[$key]); }
1450  }
1451 
1452  if (! $found > 0 || ! is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue; // We do not show orphelins files
1453 
1454  print '<!-- Line list_of_autoecmfiles '.$key.' -->'."\n";
1455  print '<tr class="oddeven">';
1456  print '<td>';
1457  if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1,'document');
1458  else print $langs->trans("ObjectDeleted",($id?$id:$ref));
1459 
1460  //$modulesubdir=dol_sanitizeFileName($ref);
1461  $modulesubdir=dirname($relativefile);
1462 
1463  //$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref);
1464  $filedir=$file['path'];
1465  //$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1466  //print $formfile->getDocumentsLink($modulepart, $filename, $filedir);
1467 
1468  print '</td>';
1469 
1470  // File
1471  print '<td>';
1472  //print "XX".$file['name']; //$file['name'] must be utf8
1473  print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1474  if ($forcedownload) print '&attachment=1';
1475  print '&file='.urlencode($relativefile).'">';
1476  print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')');
1477  print dol_trunc($file['name'],$maxlength,'middle');
1478  print '</a>';
1479 
1480  //print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$');
1481  print $this->showPreview($file, $modulepart, $file['relativename']);
1482 
1483  print "</td>\n";
1484  print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>';
1485  print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>';
1486  print '<td align="right">';
1487  //if (! empty($useinecm)) print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
1488  //if ($forcedownload) print '&attachment=1';
1489  //print '&file='.urlencode($relativefile).'">';
1490  //print img_view().'</a> &nbsp; ';
1491  //if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
1492  //else print '&nbsp;';
1493  print "</td></tr>\n";
1494  }
1495  }
1496 
1497  if (count($filearray) == 0)
1498  {
1499  print '<tr '.$bc[false].'><td colspan="5">';
1500  if (empty($textifempty)) print $langs->trans("NoFileFound");
1501  else print $textifempty;
1502  print '</td></tr>';
1503  }
1504  print "</table>";
1505  print '</div>';
1506 
1507  if (! empty($addfilterfields)) print '</form>';
1508  // Fin de zone
1509  }
1510 
1518  private function _formAjaxFileUpload($object)
1519  {
1520  global $langs;
1521 
1522  // PHP post_max_size
1523  $post_max_size = ini_get('post_max_size');
1524  $mul_post_max_size = substr($post_max_size, -1);
1525  $mul_post_max_size = ($mul_post_max_size == 'M' ? 1048576 : ($mul_post_max_size == 'K' ? 1024 : ($mul_post_max_size == 'G' ? 1073741824 : 1)));
1526  $post_max_size = $mul_post_max_size * (int) $post_max_size;
1527  // PHP upload_max_filesize
1528  $upload_max_filesize = ini_get('upload_max_filesize');
1529  $mul_upload_max_filesize = substr($upload_max_filesize, -1);
1530  $mul_upload_max_filesize = ($mul_upload_max_filesize == 'M' ? 1048576 : ($mul_upload_max_filesize == 'K' ? 1024 : ($mul_upload_max_filesize == 'G' ? 1073741824 : 1)));
1531  $upload_max_filesize = $mul_upload_max_filesize * (int) $upload_max_filesize;
1532  // Max file size
1533  $max_file_size = (($post_max_size < $upload_max_filesize) ? $post_max_size : $upload_max_filesize);
1534 
1535  // Include main
1536  include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_main.tpl.php';
1537 
1538  // Include template
1539  include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php';
1540 
1541  }
1542 
1553  public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null, $param='')
1554  {
1555  global $user, $conf, $langs, $user;
1556  global $bc;
1557  global $sortfield, $sortorder;
1558 
1559  $langs->load("link");
1560 
1561  require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
1562  $link = new Link($this->db);
1563  $links = array();
1564  if ($sortfield == "name") {
1565  $sortfield = "label";
1566  } elseif ($sortfield == "date") {
1567  $sortfield = "datea";
1568  } else {
1569  $sortfield = null;
1570  }
1571  $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder);
1572  $param .= (isset($object->id)?'&id=' . $object->id : '');
1573 
1574  // Show list of associated links
1575  print load_fiche_titre($langs->trans("LinkedFiles"));
1576 
1577  print '<form action="' . $_SERVER['PHP_SELF'] . ($param?'?'.$param:'') . '" method="POST">';
1578 
1579  print '<table width="100%" class="liste">';
1580  print '<tr class="liste_titre">';
1582  $langs->trans("Links"),
1583  $_SERVER['PHP_SELF'],
1584  "name",
1585  "",
1586  $param,
1587  'align="left"',
1588  $sortfield,
1589  $sortorder
1590  );
1592  "",
1593  "",
1594  "",
1595  "",
1596  "",
1597  'align="right"'
1598  );
1600  $langs->trans("Date"),
1601  $_SERVER['PHP_SELF'],
1602  "date",
1603  "",
1604  $param,
1605  'align="center"',
1606  $sortfield,
1607  $sortorder
1608  );
1610  '',
1611  $_SERVER['PHP_SELF'],
1612  "",
1613  "",
1614  $param,
1615  'align="center"'
1616  );
1617  print_liste_field_titre('','','');
1618  print '</tr>';
1619  $nboflinks = count($links);
1620  if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
1621 
1622  foreach ($links as $link)
1623  {
1624  print '<tr class="oddeven">';
1625  //edit mode
1626  if ($action == 'update' && $selected === $link->id)
1627  {
1628  print '<td>';
1629  print '<input type="hidden" name="id" value="' . $object->id . '">';
1630  print '<input type="hidden" name="linkid" value="' . $link->id . '">';
1631  print '<input type="hidden" name="action" value="confirm_updateline">';
1632  print $langs->trans('Link') . ': <input type="text" name="link" value="' . $link->url . '">';
1633  print '</td>';
1634  print '<td>';
1635  print $langs->trans('Label') . ': <input type="text" name="label" value="' . $link->label . '">';
1636  print '</td>';
1637  print '<td align="center">' . dol_print_date(dol_now(), "dayhour", "tzuser") . '</td>';
1638  print '<td align="right"></td>';
1639  print '<td align="right">';
1640  print '<input type="submit" name="save" class="button" value="' . dol_escape_htmltag($langs->trans('Save')) . '">';
1641  print '<input type="submit" name="cancel" class="button" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '">';
1642  print '</td>';
1643  }
1644  else
1645  {
1646  print '<td>';
1647  print img_picto('', 'object_globe').' ';
1648  print '<a data-ajax="false" href="' . $link->url . '" target="_blank">';
1649  print $link->label;
1650  print '</a>';
1651  print '</td>'."\n";
1652  print '<td align="right"></td>';
1653  print '<td align="center">' . dol_print_date($link->datea, "dayhour", "tzuser") . '</td>';
1654  print '<td align="center"></td>';
1655  print '<td align="right">';
1656  print '<a href="' . $_SERVER['PHP_SELF'] . '?action=update&linkid=' . $link->id . $param . '" class="editfilelink" >' . img_edit() . '</a>'; // id= is included into $param
1657  if ($permtodelete) {
1658  print ' &nbsp; <a href="'. $_SERVER['PHP_SELF'] .'?action=delete&linkid=' . $link->id . $param . '" class="deletefilelink">' . img_delete() . '</a>'; // id= is included into $param
1659  } else {
1660  print '&nbsp;';
1661  }
1662  print '</td>';
1663  }
1664  print "</tr>\n";
1665  }
1666  if ($nboflinks == 0)
1667  {
1668  print '<tr ' . $bc[false] . '><td colspan="5" class="opacitymedium">';
1669  print $langs->trans("NoLinkFound");
1670  print '</td></tr>';
1671  }
1672  print "</table>";
1673 
1674  print '</form>';
1675 
1676  return $nboflinks;
1677  }
1678 
1679 
1690  public function showPreview($file, $modulepart, $relativepath, $ruleforpicto=0, $param='')
1691  {
1692  global $langs, $conf;
1693 
1694  $out='';
1695  if ($conf->browser->layout != 'phone' && ! empty($conf->use_javascript_ajax))
1696  {
1697  $urladvancedpreview=getAdvancedPreviewUrl($modulepart, $relativepath, 1, $param); // Return if a file is qualified for preview.
1698  if (count($urladvancedpreview))
1699  {
1700  $out.= '<a class="pictopreview '.$urladvancedpreview['css'].'" href="'.$urladvancedpreview['url'].'"'.(empty($urladvancedpreview['mime'])?'':' mime="'.$urladvancedpreview['mime'].'"').' '.(empty($urladvancedpreview['target'])?'':' target="'.$urladvancedpreview['target'].'"').'>';
1701  //$out.= '<a class="pictopreview">';
1702  if (empty($ruleforpicto))
1703  {
1704  //$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail');
1705  $out.='<span class="fa fa-search-plus" style="color: gray"></span>';
1706  }
1707  else $out.= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']);
1708  $out.= '</a>';
1709  }
1710  }
1711  return $out;
1712  }
1713 
1714 }
1715 
image_format_supported($file)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:38
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:392
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
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 '...' 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.
img_mime($file, $titlealt= '', $morecss='')
Show MIME img of a file.
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...
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)
Return a string to show the box with list of available documents for object.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
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:297
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:39
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:516
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.
if(empty($reshook)) $form
View.
Definition: perms.php:103
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...
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="")
Scan a directory and return a list of files/directories.
Definition: files.lib.php:58
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Definition: modules_don.php:46
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.
img_down($titlealt= 'default', $selected=0, $moreclass='')
Show down arrow logo.
Class to manage generation of HTML components Only common components must be here.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1')
Show information for admin users or standard users.
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.
img_up($titlealt= 'default', $selected=0, $moreclass='')
Show top arrow logo.
__construct($db)
Constructor.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
Class to manage customers orders.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
dol_now($mode='gmt')
Return date for now.
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
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:427
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).
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
Draft customers invoices.
Definition: index.php:91
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:528
Class to manage price ask supplier.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
img_view($titlealt= 'default', $float=0, $other= '')
Show logo view card.
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.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.
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 ''...
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.