html.formfile.class.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. <?php
  2. /* Copyright (c) 2008-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (c) 2010 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. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/core/class/html.formfile.class.php
  23. * \ingroup core
  24. * \brief File of class to offer components to list and upload files
  25. */
  26. /**
  27. * Class to offer components to list and upload files
  28. */
  29. class FormFile
  30. {
  31. var $db;
  32. var $error;
  33. var $numoffiles;
  34. /**
  35. * Constructor
  36. *
  37. * @param DoliDB $db Database handler
  38. */
  39. function __construct($db)
  40. {
  41. $this->db = $db;
  42. $this->numoffiles=0;
  43. return 1;
  44. }
  45. /**
  46. * Show form to upload a new file
  47. *
  48. * @param string $url Url
  49. * @param string $title Title zone (Title or '' or 'none')
  50. * @param int $addcancel 1=Add 'Cancel' button
  51. * @param int $sectionid If upload must be done inside a particular ECM section
  52. * @param int $perm Value of permission to allow upload
  53. * @param int $size Length of input file area
  54. * @param Object $object Object to use (when attachment is done on an element)
  55. * @param string $options Add an option column
  56. * @param boolean $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). 2 should never be used.
  57. * @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__'
  58. * @param string $linkfiles 1=Also add form to link files, 0=Do not show form to link files
  59. * @param string $htmlname Name and id of HTML form
  60. * @return int <0 if KO, >0 if OK
  61. */
  62. function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile')
  63. {
  64. global $conf,$langs, $hookmanager;
  65. $hookmanager->initHooks(array('formfile'));
  66. if (! empty($conf->browser->phone)) return 0;
  67. if ((! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax==2))
  68. {
  69. // TODO: Cheeck this works with 2 forms on same page
  70. // TODO: Cheeck this works with GED module, otherwise, force useajax to 0
  71. // TODO: This does not support option savingdocmask
  72. // TODO: This break feature to upload links too
  73. return $this->_formAjaxFileUpload($object);
  74. }
  75. else
  76. {
  77. $maxlength=$size;
  78. $out = "\n\n<!-- Start form attach new file -->\n";
  79. if (empty($title)) $title=$langs->trans("AttachANewFile");
  80. if ($title != 'none') print_titre($title);
  81. $out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">';
  82. $out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="">';
  83. $out .= '<input type="hidden" id="'.$htmlname.'_section_id" name="section_id" value="'.$sectionid.'">';
  84. $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  85. $out .= '<table width="100%" class="nobordernopadding">';
  86. $out .= '<tr>';
  87. if (! empty($options)) $out .= '<td>'.$options.'</td>';
  88. $out .= '<td valign="middle" class="nowrap">';
  89. $max=$conf->global->MAIN_UPLOAD_DOC; // En Kb
  90. $maxphp=@ini_get('upload_max_filesize'); // En inconnu
  91. if (preg_match('/m$/i',$maxphp)) $maxphp=$maxphp*1024;
  92. // Now $max and $maxphp are in Kb
  93. if ($maxphp > 0) $max=min($max,$maxphp);
  94. if ($max > 0)
  95. {
  96. $out .= '<input type="hidden" name="max_file_size" value="'.($max*1024).'">';
  97. }
  98. $out .= '<input class="flat" type="file" name="userfile" size="'.$maxlength.'"';
  99. $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled="disabled"':'');
  100. $out .= '>';
  101. $out .= ' &nbsp; ';
  102. $out .= '<input type="submit" class="button" name="sendit" value="'.$langs->trans("Upload").'"';
  103. $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled="disabled"':'');
  104. $out .= '>';
  105. if ($addcancel)
  106. {
  107. $out .= ' &nbsp; ';
  108. $out .= '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  109. }
  110. if (! empty($conf->global->MAIN_UPLOAD_DOC))
  111. {
  112. if ($perm)
  113. {
  114. $langs->load('other');
  115. $out .= ' ('.$langs->trans("MaxSize").': '.$max.' '.$langs->trans("Kb");
  116. $out .= ' '.info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1);
  117. $out .= ')';
  118. }
  119. }
  120. else
  121. {
  122. $out .= ' ('.$langs->trans("UploadDisabled").')';
  123. }
  124. $out .= "</td></tr>";
  125. if ($savingdocmask)
  126. {
  127. $out .= '<tr>';
  128. if (! empty($options)) $out .= '<td>'.$options.'</td>';
  129. $out .= '<td valign="middle" class="nowrap">';
  130. $out .= '<input type="checkbox" checked="checked" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName"));
  131. $out .= '</td>';
  132. $out .= '</tr>';
  133. }
  134. $out .= "</table>";
  135. $out .= '</form>';
  136. if (empty($sectionid)) $out .= '<br>';
  137. $out .= "\n<!-- End form attach new file -->\n";
  138. if ($linkfiles)
  139. {
  140. $out .= "\n<!-- Start form attach new link -->\n";
  141. $langs->load('link');
  142. $title = $langs->trans("LinkANewFile");
  143. $out .= load_fiche_titre($title, null, null);
  144. $out .= '<form name="'.$htmlname.'_link" id="'.$htmlname.'_link" action="'.$url.'" method="POST">';
  145. $out .= '<input type="hidden" id="'.$htmlname.'_link_section_dir" name="link_section_dir" value="">';
  146. $out .= '<input type="hidden" id="'.$htmlname.'_link_section_id" name="link_section_id" value="'.$sectionid.'">';
  147. $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  148. $out .= '<table width="100%" class="nobordernopadding">';
  149. $out .= '<tr>';
  150. $out .= '<td valign="middle" class="nowrap">';
  151. $out .= $langs->trans("Link") . ': ';
  152. $out .= '<input type="text" name="link" size="'.$maxlength.'" id="link">';
  153. $out .= ' &nbsp; ' . $langs->trans("Label") . ': ';
  154. $out .= '<input type="text" name="label" id="label">';
  155. $out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">';
  156. $out .= '<input type="hidden" name="objectid" value="' . $object->id . '">';
  157. $out .= '<input type="submit" class="button" name="linkit" value="'.$langs->trans("ToLink").'"';
  158. $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled="disabled"':'');
  159. $out .= '>';
  160. $out .= '</td></tr>';
  161. $out .= '</table>';
  162. $out .= '</form><br>';
  163. $parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm);
  164. $res = $hookmanager->executeHooks('formattachOptions',$parameters,$object);
  165. $out .= "\n<!-- End form attach new file -->\n";
  166. }
  167. if (empty($res))
  168. {
  169. print $out;
  170. }
  171. print $hookmanager->resPrint;
  172. return 1;
  173. }
  174. }
  175. /**
  176. * Show the box with list of available documents for object
  177. *
  178. * @param string $modulepart propal, facture, facture_fourn, ...
  179. * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module.
  180. * @param string $filedir Directory to scan
  181. * @param string $urlsource Url of origin page (for return)
  182. * @param int $genallowed Generation is allowed (1/0 or array of formats)
  183. * @param int $delallowed Remove is allowed (1/0)
  184. * @param string $modelselected Model to preselect by default
  185. * @param string $allowgenifempty Show warning if no model activated
  186. * @param string $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined)
  187. * @param int $iconPDF Show only PDF icon with link (1/0)
  188. * @param int $maxfilenamelength Max length for filename shown
  189. * @param string $noform Do not output html form tags
  190. * @param string $param More param on http links
  191. * @param string $title Title to show on top of form
  192. * @param string $buttonlabel Label on submit button
  193. * @param string $codelang Default language code to use on lang combo box if multilang is enabled
  194. * @return int <0 if KO, number of shown files if OK
  195. */
  196. function show_documents($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='')
  197. {
  198. $this->numoffiles=0;
  199. print $this->showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$maxfilenamelength,$noform,$param,$title,$buttonlabel,$codelang);
  200. return $this->numoffiles;
  201. }
  202. /**
  203. * Return a string to show the box with list of available documents for object.
  204. * This also set the property $this->numoffiles
  205. *
  206. * @param string $modulepart Module the files are related to ('propal', 'facture', 'facture_fourn', 'mymodule', 'mymodule_temp', ...)
  207. * @param string $modulesubdir Existing (so sanitized) sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module.
  208. * @param string $filedir Directory to scan
  209. * @param string $urlsource Url of origin page (for return)
  210. * @param int $genallowed Generation is allowed (1/0 or array list of templates)
  211. * @param int $delallowed Remove is allowed (1/0)
  212. * @param string $modelselected Model to preselect by default
  213. * @param string $allowgenifempty Allow generation even if list of template ($genallowed) is empty (show however a warning)
  214. * @param string $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined)
  215. * @param int $iconPDF Obsolete, see getDocumentsLink
  216. * @param int $maxfilenamelength Max length for filename shown
  217. * @param string $noform Do not output html form tags
  218. * @param string $param More param on http links
  219. * @param string $title Title to show on top of form
  220. * @param string $buttonlabel Label on submit button
  221. * @param string $codelang Default language code to use on lang combo box if multilang is enabled
  222. * @param string $morepicto Add more HTML content into cell with picto
  223. * @return string Output string with HTML array of documents (might be empty string)
  224. */
  225. function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='')
  226. {
  227. global $langs,$conf,$hookmanager,$user,$form,$bc;
  228. if (! is_object($form)) $form=new Form($this->db);
  229. // filedir = $conf->...->dir_ouput."/".get_exdir(id)
  230. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  231. // For backward compatibility
  232. if (! empty($iconPDF)) {
  233. return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir);
  234. }
  235. $printer = ($user->rights->printipp->read && $conf->printipp->enabled)?true:false;
  236. $hookmanager->initHooks(array('formfile'));
  237. $forname='builddoc';
  238. $out='';
  239. $var=true;
  240. $headershown=0;
  241. $showempty=0;
  242. $i=0;
  243. $titletoshow=$langs->trans("Documents");
  244. if (! empty($title)) $titletoshow=$title;
  245. $out.= "\n".'<!-- Start show_document -->'."\n";
  246. //print 'filedir='.$filedir;
  247. // Show table
  248. if ($genallowed)
  249. {
  250. $modellist=array();
  251. if ($modulepart == 'company')
  252. {
  253. $showempty=1;
  254. if (is_array($genallowed)) $modellist=$genallowed;
  255. else
  256. {
  257. include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
  258. $modellist=ModeleThirdPartyDoc::liste_modeles($this->db);
  259. }
  260. }
  261. else if ($modulepart == 'propal')
  262. {
  263. if (is_array($genallowed)) $modellist=$genallowed;
  264. else
  265. {
  266. include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
  267. $modellist=ModelePDFPropales::liste_modeles($this->db);
  268. }
  269. }
  270. else if ($modulepart == 'commande')
  271. {
  272. if (is_array($genallowed)) $modellist=$genallowed;
  273. else
  274. {
  275. include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
  276. $modellist=ModelePDFCommandes::liste_modeles($this->db);
  277. }
  278. }
  279. elseif ($modulepart == 'expedition')
  280. {
  281. if (is_array($genallowed)) $modellist=$genallowed;
  282. else
  283. {
  284. include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  285. $modellist=ModelePDFExpedition::liste_modeles($this->db);
  286. }
  287. }
  288. elseif ($modulepart == 'livraison')
  289. {
  290. if (is_array($genallowed)) $modellist=$genallowed;
  291. else
  292. {
  293. include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php';
  294. $modellist=ModelePDFDeliveryOrder::liste_modeles($this->db);
  295. }
  296. }
  297. else if ($modulepart == 'ficheinter')
  298. {
  299. if (is_array($genallowed)) $modellist=$genallowed;
  300. else
  301. {
  302. include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
  303. $modellist=ModelePDFFicheinter::liste_modeles($this->db);
  304. }
  305. }
  306. elseif ($modulepart == 'facture')
  307. {
  308. if (is_array($genallowed)) $modellist=$genallowed;
  309. else
  310. {
  311. include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  312. $modellist=ModelePDFFactures::liste_modeles($this->db);
  313. }
  314. }
  315. elseif ($modulepart == 'project')
  316. {
  317. if (is_array($genallowed)) $modellist=$genallowed;
  318. else
  319. {
  320. include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
  321. $modellist=ModelePDFProjects::liste_modeles($this->db);
  322. }
  323. }
  324. elseif ($modulepart == 'project_task')
  325. {
  326. if (is_array($genallowed)) $modellist=$genallowed;
  327. else
  328. {
  329. include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
  330. $modellist=ModelePDFTask::liste_modeles($this->db);
  331. }
  332. }
  333. elseif ($modulepart == 'export')
  334. {
  335. if (is_array($genallowed)) $modellist=$genallowed;
  336. else
  337. {
  338. include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
  339. $modellist=ModeleExports::liste_modeles($this->db);
  340. }
  341. }
  342. else if ($modulepart == 'commande_fournisseur')
  343. {
  344. if (is_array($genallowed)) $modellist=$genallowed;
  345. else
  346. {
  347. include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
  348. $modellist=ModelePDFSuppliersOrders::liste_modeles($this->db);
  349. }
  350. }
  351. else if ($modulepart == 'facture_fournisseur')
  352. {
  353. if (is_array($genallowed)) $modellist=$genallowed;
  354. else
  355. {
  356. include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
  357. $modellist=ModelePDFSuppliersInvoices::liste_modeles($this->db);
  358. }
  359. }
  360. else if ($modulepart == 'remisecheque')
  361. {
  362. if (is_array($genallowed)) $modellist=$genallowed;
  363. else
  364. {
  365. include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/pdf/modules_chequereceipts.php';
  366. $modellist=ModeleChequeReceipts::liste_modeles($this->db);
  367. }
  368. }
  369. elseif ($modulepart == 'donation')
  370. {
  371. if (is_array($genallowed)) $modellist=$genallowed;
  372. else
  373. {
  374. include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
  375. $modellist=ModeleDon::liste_modeles($this->db);
  376. }
  377. }
  378. else if ($modulepart == 'unpaid')
  379. {
  380. $modellist='';
  381. }
  382. else
  383. {
  384. // For normalized standard modules
  385. $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
  386. if (file_exists($file))
  387. {
  388. $res=include_once $file;
  389. }
  390. // For normalized external modules
  391. else
  392. {
  393. $file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0);
  394. $res=include_once $file;
  395. }
  396. $class='Modele'.ucfirst($modulepart);
  397. if (class_exists($class))
  398. {
  399. $modellist=call_user_func($class.'::liste_modeles',$this->db);
  400. }
  401. else
  402. {
  403. dol_print_error($this->db,'Bad value for modulepart');
  404. return -1;
  405. }
  406. }
  407. $headershown=1;
  408. $buttonlabeltoshow=$buttonlabel;
  409. if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate');
  410. if (empty($noform)) $out.= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc').'" name="'.$forname.'" id="'.$forname.'_form" method="post">';
  411. $out.= '<input type="hidden" name="action" value="builddoc">';
  412. $out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  413. $out.= '<div class="titre">'.$titletoshow.'</div>';
  414. $out.= '<table class="liste formdoc noborder" summary="listofdocumentstable" width="100%">';
  415. $out.= '<tr class="liste_titre">';
  416. // Model
  417. if (! empty($modellist))
  418. {
  419. $out.= '<th align="center" class="formdoc liste_titre">';
  420. $out.= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>';
  421. if (is_array($modellist) && count($modellist) == 1) // If there is only one element
  422. {
  423. $arraykeys=array_keys($modellist);
  424. $modelselected=$arraykeys[0];
  425. }
  426. $out.= $form->selectarray('model',$modellist,$modelselected,$showempty,0,0);
  427. $out.= '</th>';
  428. }
  429. else
  430. {
  431. $out.= '<th align="left" class="formdoc liste_titre">';
  432. $out.= $langs->trans("Files");
  433. $out.= '</th>';
  434. }
  435. // Language code (if multilang)
  436. $out.= '<th align="center" class="formdoc liste_titre">';
  437. if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && ! $forcenomultilang)
  438. {
  439. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  440. $formadmin=new FormAdmin($this->db);
  441. $defaultlang=$codelang?$codelang:$langs->getDefaultLang();
  442. $out.= $formadmin->select_language($defaultlang);
  443. }
  444. else
  445. {
  446. $out.= '&nbsp;';
  447. }
  448. $out.= '</th>';
  449. // Button
  450. $addcolumforpicto=($delallowed || $printer || $morepicto);
  451. $out.= '<th align="center" colspan="'.($addcolumforpicto?'2':'1').'" class="formdocbutton liste_titre">';
  452. $genbutton = '<input class="button" id="'.$forname.'_generatebutton"';
  453. $genbutton.= ' type="submit" value="'.$buttonlabel.'"';
  454. if (! $allowgenifempty && ! is_array($modellist) && empty($modellist)) $genbutton.= ' disabled="disabled"';
  455. $genbutton.= '>';
  456. if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid')
  457. {
  458. $langs->load("errors");
  459. $genbutton.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
  460. }
  461. if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton='';
  462. $out.= $genbutton;
  463. $out.= '</th>';
  464. if($hookmanager->hooks['formfile'])
  465. {
  466. foreach($hookmanager->hooks['formfile'] as $module)
  467. {
  468. if(method_exists($module, 'formBuilddocLineOptions')) $out .= '<th></th>';
  469. }
  470. }
  471. $out.= '</tr>';
  472. // Execute hooks
  473. $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart);
  474. if (is_object($hookmanager)) $out.= $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']);
  475. }
  476. // Get list of files
  477. if (! empty($filedir))
  478. {
  479. $file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview\.png)$','date',SORT_DESC);
  480. // Affiche en-tete tableau si non deja affiche
  481. if (! empty($file_list) && ! $headershown)
  482. {
  483. $headershown=1;
  484. $out.= '<div class="titre">'.$titletoshow.'</div>';
  485. $out.= '<table class="border" summary="listofdocumentstable" width="100%">';
  486. }
  487. // Loop on each file found
  488. if (is_array($file_list))
  489. {
  490. foreach($file_list as $file)
  491. {
  492. $var=!$var;
  493. // Define relative path for download link (depends on module)
  494. $relativepath=$file["name"]; // Cas general
  495. if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture...
  496. // Autre cas
  497. if ($modulepart == 'donation') { $relativepath = get_exdir($modulesubdir,2).$file["name"]; }
  498. if ($modulepart == 'export') { $relativepath = $file["name"]; }
  499. $out.= "<tr ".$bc[$var].">";
  500. // Show file name with link to download
  501. $out.= '<td class="nowrap">';
  502. $out.= '<a data-ajax="false" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"';
  503. $mime=dol_mimetype($relativepath,'',0);
  504. if (preg_match('/text/',$mime)) $out.= ' target="_blank"';
  505. $out.= ' target="_blank">';
  506. $out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]).' '.dol_trunc($file["name"],$maxfilenamelength);
  507. $out.= '</a>'."\n";
  508. $out.= '</td>';
  509. // Show file size
  510. $size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"]));
  511. $out.= '<td align="right" class="nowrap">'.dol_print_size($size).'</td>';
  512. // Show file date
  513. $date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"]));
  514. $out.= '<td align="right" class="nowrap">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>';
  515. if ($delallowed || $printer || $morepicto)
  516. {
  517. $out.= '<td align="right">';
  518. if ($delallowed)
  519. {
  520. $out.= '<a href="'.$urlsource.(strpos($urlsource,'?')?'&':'?').'action=remove_file&file='.urlencode($relativepath);
  521. $out.= ($param?'&'.$param:'');
  522. //$out.= '&modulepart='.$modulepart; // TODO obsolete ?
  523. //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
  524. $out.= '">'.img_picto($langs->trans("Delete"), 'delete.png').'</a>';
  525. //$out.='</td>';
  526. }
  527. if ($printer)
  528. {
  529. //$out.= '<td align="right">';
  530. $out.= '&nbsp;<a href="'.$urlsource.(strpos($urlsource,'?')?'&':'?').'action=print_file&amp;printer='.$modulepart.'&amp;file='.urlencode($relativepath);
  531. $out.= ($param?'&'.$param:'');
  532. $out.= '">'.img_picto($langs->trans("Print"),'printer.png').'</a>';
  533. }
  534. if ($morepicto)
  535. {
  536. $morepicto=preg_replace('/__FILENAMEURLENCODED__/',urlencode($relativepath),$morepicto);
  537. $out.=$morepicto;
  538. }
  539. $out.='</td>';
  540. }
  541. if (is_object($hookmanager))
  542. {
  543. $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart,'relativepath'=>$relativepath);
  544. $res = $hookmanager->executeHooks('formBuilddocLineOptions',$parameters,$file);
  545. if (empty($res))
  546. {
  547. $out .= $hookmanager->resPrint; // Complete line
  548. $out.= '</tr>';
  549. }
  550. else $out = $hookmanager->resPrint; // Replace line
  551. }
  552. }
  553. if (count($file_list) == 0)
  554. {
  555. $out.='<tr><td colspan="3">'.$langs->trans("None").'</td></tr>';
  556. }
  557. $this->numoffiles++;
  558. }
  559. }
  560. if ($headershown)
  561. {
  562. // Affiche pied du tableau
  563. $out.= "</table>\n";
  564. if ($genallowed)
  565. {
  566. if (empty($noform)) $out.= '</form>'."\n";
  567. }
  568. }
  569. $out.= '<!-- End show_document -->'."\n";
  570. //return ($i?$i:$headershown);
  571. return $out;
  572. }
  573. /**
  574. * Show only Document icon with link
  575. *
  576. * @param string $modulepart propal, facture, facture_fourn, ...
  577. * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module.
  578. * @param string $filedir Directory to scan
  579. * @return string Output string with HTML link of documents (might be empty string)
  580. */
  581. function getDocumentsLink($modulepart, $modulesubdir, $filedir)
  582. {
  583. if (! function_exists('dol_dir_list')) include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  584. $out='';
  585. $this->numoffiles=0;
  586. $file_list=dol_dir_list($filedir, 'files', 0, preg_quote($modulesubdir.'.pdf','/'), '\.meta$|\.png$');
  587. // For ajax treatment
  588. $out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
  589. if (! empty($file_list))
  590. {
  591. // Loop on each file found
  592. foreach($file_list as $file)
  593. {
  594. // Define relative path for download link (depends on module)
  595. $relativepath=$file["name"]; // Cas general
  596. if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture...
  597. // Autre cas
  598. if ($modulepart == 'donation') {
  599. $relativepath = get_exdir($modulesubdir,2).$file["name"];
  600. }
  601. if ($modulepart == 'export') {
  602. $relativepath = $file["name"];
  603. }
  604. // Show file name with link to download
  605. $out.= '<a data-ajax="false" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"';
  606. $mime=dol_mimetype($relativepath,'',0);
  607. if (preg_match('/text/',$mime)) $out.= ' target="_blank"';
  608. $out.= '>';
  609. $out.= img_pdf($file["name"],2);
  610. $out.= '</a>'."\n";
  611. $this->numoffiles++;
  612. }
  613. }
  614. return $out;
  615. }
  616. /**
  617. * Show list of documents in a directory
  618. *
  619. * @param array $filearray Array of files loaded by dol_dir_list('files') function before calling this
  620. * @param Object $object Object on which document is linked to
  621. * @param string $modulepart Value for modulepart used by download or viewimage wrapper
  622. * @param string $param Parameters on sort links (param must start with &, example &aaa=bbb&ccc=ddd)
  623. * @param int $forcedownload Force to open dialog box "Save As" when clicking on file
  624. * @param string $relativepath Relative path of docs (autodefined if not provided)
  625. * @param int $permtodelete Permission to delete
  626. * @param int $useinecm Change output for use in ecm module
  627. * @param string $textifempty Text to show if filearray is empty ('NoFileFound' if not defined)
  628. * @param int $maxlength Maximum length of file name shown
  629. * @param string $title Title before list
  630. * @param string $url Full url to use for click links ('' = autodetect)
  631. * @param int $showrelpart 0=Show only filename (default), 1=Show first level 1 dir
  632. * @return int <0 if KO, nb of files shown if OK
  633. */
  634. function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permtodelete=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0)
  635. {
  636. global $user, $conf, $langs, $hookmanager;
  637. global $bc;
  638. global $sortfield, $sortorder, $maxheightmini;
  639. $hookmanager->initHooks(array('formfile'));
  640. $parameters=array(
  641. 'filearray' => $filearray,
  642. 'modulepart'=> $modulepart,
  643. 'param' => $param,
  644. 'forcedownload' => $forcedownload,
  645. 'relativepath' => $relativepath,
  646. 'permtodelete' => $permtodelete,
  647. 'useinecm' => $useinecm,
  648. 'textifempty' => $textifempty,
  649. 'maxlength' => $maxlength,
  650. 'title' => $title,
  651. 'url' => $url
  652. );
  653. $reshook=$hookmanager->executeHooks('showFilesList', $parameters, $object);
  654. if (isset($reshook) && $reshook != '') // null or '' for bypass
  655. {
  656. return $reshook;
  657. }
  658. else
  659. {
  660. $param = (isset($object->id)?'&id='.$object->id:'').$param;
  661. // Show list of existing files
  662. if (empty($useinecm)) print_titre($title?$title:$langs->trans("AttachedFiles"));
  663. if (empty($url)) $url=$_SERVER["PHP_SELF"];
  664. print '<table width="100%" class="'.($useinecm?'nobordernopadding':'liste').'">';
  665. print '<tr class="liste_titre">';
  666. print_liste_field_titre($langs->trans("Documents2"),$url,"name","",$param,'align="left"',$sortfield,$sortorder);
  667. print_liste_field_titre($langs->trans("Size"),$url,"size","",$param,'align="right"',$sortfield,$sortorder);
  668. print_liste_field_titre($langs->trans("Date"),$url,"date","",$param,'align="center"',$sortfield,$sortorder);
  669. if (empty($useinecm)) print_liste_field_titre('',$url,"","",$param,'align="center"');
  670. print_liste_field_titre('','','');
  671. print '</tr>';
  672. $nboffiles=count($filearray);
  673. if ($nboffiles > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  674. $var=true;
  675. foreach($filearray as $key => $file) // filearray must be only files here
  676. {
  677. if ($file['name'] != '.'
  678. && $file['name'] != '..'
  679. && ! preg_match('/\.meta$/i',$file['name']))
  680. {
  681. // Define relative path used to store the file
  682. if (empty($relativepath))
  683. {
  684. $relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/';
  685. if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2).$relativepath; // TODO Call using a defined value for $relativepath
  686. if ($object->element == 'member') $relativepath=get_exdir($object->id,2).$relativepath; // TODO Call using a defined value for $relativepath
  687. if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
  688. }
  689. $var=!$var;
  690. print '<tr '.$bc[$var].'>';
  691. print '<td>';
  692. //print "XX".$file['name']; //$file['name'] must be utf8
  693. print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
  694. if ($forcedownload) print '&attachment=1';
  695. if (! empty($object->entity)) print '&entity='.$object->entity;
  696. $filepath=$relativepath.$file['name'];
  697. /* Restore old code: When file is at level 2+, full relative path (and not only level1) must be into url
  698. if ($file['level1name'] <> $object->id)
  699. $filepath=$object->id.'/'.$file['level1name'].'/'.$file['name'];
  700. else
  701. $filepath=$object->id.'/'.$file['name'];
  702. */
  703. print '&file='.urlencode($filepath);
  704. print '">';
  705. print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')').' ';
  706. if ($showrelpart == 1) print $relativepath;
  707. print dol_trunc($file['name'],$maxlength,'middle');
  708. print '</a>';
  709. print "</td>\n";
  710. print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>';
  711. print '<td align="center">'.dol_print_date($file['date'],"dayhour","tzuser").'</td>';
  712. // Preview
  713. if (empty($useinecm))
  714. {
  715. print '<td align="center">';
  716. $tmp=explode('.',$file['name']);
  717. if (count($tmp) == 3) $minifile=$tmp[0].'_mini.'.$tmp[1].'.'.strtolower($tmp[2]); // Thumbs are created with filename in lower case
  718. else $minifile=$tmp[0].'_mini.'.strtolower($tmp[1]); // Thumbs are created with filename in lower case
  719. if (image_format_supported($file['name']) > 0) print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($relativepath.'thumbs/'.$minifile).'" title="">';
  720. else print '&nbsp;';
  721. print '</td>';
  722. }
  723. // Delete or view link
  724. // ($param must start with &)
  725. print '<td align="right">';
  726. if ($useinecm) print '<a href="'.DOL_URL_ROOT.'/ecm/docfile.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_view().'</a> &nbsp; ';
  727. if ($permtodelete)
  728. {
  729. /*
  730. if ($file['level1name'] <> $object->id)
  731. $filepath=$file['level1name'].'/'.$file['name'];
  732. else
  733. $filepath=$file['name'];
  734. */
  735. $useajax=1;
  736. if (! empty($conf->dol_use_jmobile)) $useajax=0;
  737. if (empty($conf->use_javascript_ajax)) $useajax=0;
  738. if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0;
  739. print '<a href="'.(($useinecm && $useajax)?'#':$url.'?action=delete&urlfile='.urlencode($filepath).$param).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
  740. }
  741. else print '&nbsp;';
  742. print "</td>";
  743. print "</tr>\n";
  744. }
  745. }
  746. if ($nboffiles == 0)
  747. {
  748. print '<tr '.$bc[$var].'><td colspan="'.(empty($useinecm)?'5':'4').'">';
  749. if (empty($textifempty)) print $langs->trans("NoFileFound");
  750. else print $textifempty;
  751. print '</td></tr>';
  752. }
  753. print "</table>";
  754. return $nboffiles;
  755. }
  756. }
  757. /**
  758. * Show list of documents in a directory
  759. *
  760. * @param string $upload_dir Directory that was scanned
  761. * @param array $filearray Array of files loaded by dol_dir_list function before calling this function
  762. * @param string $modulepart Value for modulepart used by download wrapper
  763. * @param string $param Parameters on sort links
  764. * @param int $forcedownload Force to open dialog box "Save As" when clicking on file
  765. * @param string $relativepath Relative path of docs (autodefined if not provided)
  766. * @param int $permtodelete Permission to delete
  767. * @param int $useinecm Change output for use in ecm module
  768. * @param int $textifempty Text to show if filearray is empty
  769. * @param int $maxlength Maximum length of file name shown
  770. * @param string $url Full url to use for click links ('' = autodetect)
  771. * @return int <0 if KO, nb of files shown if OK
  772. */
  773. function list_of_autoecmfiles($upload_dir,$filearray,$modulepart,$param,$forcedownload=0,$relativepath='',$permtodelete=1,$useinecm=0,$textifempty='',$maxlength=0,$url='')
  774. {
  775. global $user, $conf, $langs;
  776. global $bc;
  777. global $sortfield, $sortorder;
  778. dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart);
  779. // Show list of documents
  780. if (empty($useinecm)) print_titre($langs->trans("AttachedFiles"));
  781. if (empty($url)) $url=$_SERVER["PHP_SELF"];
  782. print '<table width="100%" class="nobordernopadding">';
  783. print '<tr class="liste_titre">';
  784. $sortref="fullname";
  785. if ($modulepart == 'invoice_supplier') $sortref='level1name';
  786. print_liste_field_titre($langs->trans("Ref"),$url,$sortref,"",$param,'align="left"',$sortfield,$sortorder);
  787. print_liste_field_titre($langs->trans("Documents2"),$url,"name","",$param,'align="left"',$sortfield,$sortorder);
  788. print_liste_field_titre($langs->trans("Size"),$url,"size","",$param,'align="right"',$sortfield,$sortorder);
  789. print_liste_field_titre($langs->trans("Date"),$url,"date","",$param,'align="center"',$sortfield,$sortorder);
  790. print_liste_field_titre('','','');
  791. print '</tr>';
  792. // To show ref or specific information according to view to show (defined by $module)
  793. if ($modulepart == 'company')
  794. {
  795. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  796. $object_instance=new Societe($this->db);
  797. }
  798. else if ($modulepart == 'invoice')
  799. {
  800. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  801. $object_instance=new Facture($this->db);
  802. }
  803. else if ($modulepart == 'invoice_supplier')
  804. {
  805. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  806. $object_instance=new FactureFournisseur($this->db);
  807. }
  808. else if ($modulepart == 'propal')
  809. {
  810. include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  811. $object_instance=new Propal($this->db);
  812. }
  813. else if ($modulepart == 'order')
  814. {
  815. include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  816. $object_instance=new Commande($this->db);
  817. }
  818. else if ($modulepart == 'order_supplier')
  819. {
  820. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  821. $object_instance=new CommandeFournisseur($this->db);
  822. }
  823. else if ($modulepart == 'contract')
  824. {
  825. include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  826. $object_instance=new Contrat($this->db);
  827. }
  828. else if ($modulepart == 'product')
  829. {
  830. include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  831. $object_instance=new Product($this->db);
  832. }
  833. else if ($modulepart == 'tax')
  834. {
  835. include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  836. $object_instance=new ChargeSociales($this->db);
  837. }
  838. else if ($modulepart == 'project')
  839. {
  840. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  841. $object_instance=new Project($this->db);
  842. }
  843. $var=true;
  844. foreach($filearray as $key => $file)
  845. {
  846. if (!is_dir($file['name'])
  847. && $file['name'] != '.'
  848. && $file['name'] != '..'
  849. && $file['name'] != 'CVS'
  850. && ! preg_match('/\.meta$/i',$file['name']))
  851. {
  852. // Define relative path used to store the file
  853. $relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']);
  854. //var_dump($file);
  855. $id=0; $ref=''; $label='';
  856. // To show ref or specific information according to view to show (defined by $module)
  857. if ($modulepart == 'company') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
  858. if ($modulepart == 'invoice') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
  859. 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
  860. if ($modulepart == 'propal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
  861. if ($modulepart == 'order') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
  862. if ($modulepart == 'order_supplier') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
  863. if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
  864. if ($modulepart == 'product') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); }
  865. if ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); }
  866. if ($modulepart == 'project') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');}
  867. if (! $id && ! $ref) continue;
  868. $found=0;
  869. if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref]))
  870. {
  871. $found=1;
  872. }
  873. else
  874. {
  875. //print 'Fetch '.$id." - ".$ref.'<br>';
  876. $result=$object_instance->fetch($id,$ref);
  877. if ($result > 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]=dol_clone($object_instance); } // Save object into a cache
  878. if ($result == 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]='notfound'; unset($filearray[$key]); }
  879. }
  880. if (! $found > 0 || ! is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue; // We do not show orphelins files
  881. $var=!$var;
  882. print '<tr '.$bc[$var].'>';
  883. print '<td>';
  884. if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1,'document');
  885. else print $langs->trans("ObjectDeleted",($id?$id:$ref));
  886. print '</td>';
  887. print '<td>';
  888. //print "XX".$file['name']; //$file['name'] must be utf8
  889. print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
  890. if ($forcedownload) print '&attachment=1';
  891. print '&file='.urlencode($relativefile).'">';
  892. print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')').' ';
  893. print dol_trunc($file['name'],$maxlength,'middle');
  894. print '</a>';
  895. print "</td>\n";
  896. print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>';
  897. print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>';
  898. print '<td align="right">';
  899. if (! empty($useinecm)) print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
  900. if ($forcedownload) print '&attachment=1';
  901. print '&file='.urlencode($relativefile).'">';
  902. print img_view().'</a> &nbsp; ';
  903. //if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
  904. //else print '&nbsp;';
  905. print "</td></tr>\n";
  906. }
  907. }
  908. if (count($filearray) == 0)
  909. {
  910. print '<tr '.$bc[$var].'><td colspan="4">';
  911. if (empty($textifempty)) print $langs->trans("NoFileFound");
  912. else print $textifempty;
  913. print '</td></tr>';
  914. }
  915. print "</table>";
  916. // Fin de zone
  917. }
  918. /**
  919. * Show form to upload a new file with jquery fileupload.
  920. * This form use the fileupload.php file.
  921. *
  922. * @param Object $object Object to use
  923. * @return void
  924. */
  925. private function _formAjaxFileUpload($object)
  926. {
  927. global $langs;
  928. // PHP post_max_size
  929. $post_max_size = ini_get('post_max_size');
  930. $mul_post_max_size = substr($post_max_size, -1);
  931. $mul_post_max_size = ($mul_post_max_size == 'M' ? 1048576 : ($mul_post_max_size == 'K' ? 1024 : ($mul_post_max_size == 'G' ? 1073741824 : 1)));
  932. $post_max_size = $mul_post_max_size * (int) $post_max_size;
  933. // PHP upload_max_filesize
  934. $upload_max_filesize = ini_get('upload_max_filesize');
  935. $mul_upload_max_filesize = substr($upload_max_filesize, -1);
  936. $mul_upload_max_filesize = ($mul_upload_max_filesize == 'M' ? 1048576 : ($mul_upload_max_filesize == 'K' ? 1024 : ($mul_upload_max_filesize == 'G' ? 1073741824 : 1)));
  937. $upload_max_filesize = $mul_upload_max_filesize * (int) $upload_max_filesize;
  938. // Max file size
  939. $max_file_size = (($post_max_size < $upload_max_filesize) ? $post_max_size : $upload_max_filesize);
  940. // Include main
  941. include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_main.tpl.php';
  942. // Include template
  943. include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php';
  944. }
  945. /**
  946. * Show array with linked files
  947. *
  948. * @param Object $object Object
  949. * @param int $permtodelete Deletion is allowed
  950. * @param string $action Action
  951. * @param string $selected ???
  952. * @param string $param More param to add into URL
  953. * @return int Number of links
  954. */
  955. public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null, $param='')
  956. {
  957. global $user, $conf, $langs, $user;
  958. global $bc;
  959. global $sortfield, $sortorder;
  960. require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
  961. $link = new Link($this->db);
  962. $links = array();
  963. if ($sortfield == "name") {
  964. $sortfield = "label";
  965. } elseif ($sortfield == "date") {
  966. $sortfield = "datea";
  967. } else {
  968. $sortfield = null;
  969. }
  970. $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder);
  971. $param .= (isset($object->id)?'&id=' . $object->id : '');
  972. // Show list of associated links
  973. print_titre($langs->trans("LinkedFiles"));
  974. print '<form action="' . $_SERVER['PHP_SELF'] . ($param?'?'.$param:'') . '" method="POST">';
  975. print '<table width="100%" class="liste">';
  976. print '<tr class="liste_titre">';
  977. print_liste_field_titre(
  978. $langs->trans("Links"),
  979. $_SERVER['PHP_SELF'],
  980. "name",
  981. "",
  982. $param,
  983. 'align="left"',
  984. $sortfield,
  985. $sortorder
  986. );
  987. print_liste_field_titre(
  988. "",
  989. "",
  990. "",
  991. "",
  992. "",
  993. 'align="right"'
  994. );
  995. print_liste_field_titre(
  996. $langs->trans("Date"),
  997. $_SERVER['PHP_SELF'],
  998. "date",
  999. "",
  1000. $param,
  1001. 'align="center"',
  1002. $sortfield,
  1003. $sortorder
  1004. );
  1005. print_liste_field_titre(
  1006. '',
  1007. $_SERVER['PHP_SELF'],
  1008. "",
  1009. "",
  1010. $param,
  1011. 'align="center"'
  1012. );
  1013. print_liste_field_titre('','','');
  1014. print '</tr>';
  1015. $nboflinks = count($links);
  1016. if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  1017. $var = true;
  1018. foreach ($links as $link)
  1019. {
  1020. $var =! $var;
  1021. print '<tr ' . $bc[$var] . '>';
  1022. //edit mode
  1023. if ($action == 'update' && $selected === $link->id)
  1024. {
  1025. print '<td>';
  1026. print '<input type="hidden" name="id" value="' . $object->id . '">';
  1027. print '<input type="hidden" name="linkid" value="' . $link->id . '">';
  1028. print '<input type="hidden" name="action" value="confirm_updateline">';
  1029. print $langs->trans('Link') . ': <input type="text" name="link" size="50" value="' . $link->url . '">';
  1030. print '</td>';
  1031. print '<td>';
  1032. print $langs->trans('Label') . ': <input type="text" name="label" value="' . $link->label . '">';
  1033. print '</td>';
  1034. print '<td align="center">' . dol_print_date(dol_now(), "dayhour", "tzuser") . '</td>';
  1035. print '<td align="right"></td>';
  1036. print '<td align="right" colspan="2">';
  1037. print '<input type="submit" name="save" class="button" value="' . dol_escape_htmltag($langs->trans('Save')) . '">';
  1038. print '<input type="submit" name="cancel" class="button" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '">';
  1039. print '</td>';
  1040. }
  1041. else
  1042. {
  1043. print '<td>';
  1044. print '<a data-ajax="false" href="' . $link->url . '" target="_blank">';
  1045. print $link->label;
  1046. print '</a>';
  1047. print '</td>'."\n";
  1048. print '<td align="right"></td>';
  1049. print '<td align="center">' . dol_print_date($link->datea, "dayhour", "tzuser") . '</td>';
  1050. print '<td align="center"></td>';
  1051. print '<td align="right" colspan="2">';
  1052. print '<a href="' . $_SERVER['PHP_SELF'] . '?action=update&linkid=' . $link->id . $param . '" class="editfilelink" >' . img_edit() . '</a>'; // id= is included into $param
  1053. if ($permtodelete) {
  1054. print ' &nbsp; <a href="'. $_SERVER['PHP_SELF'] .'?action=delete&linkid=' . $link->id . $param . '" class="deletefilelink">' . img_delete() . '</a>'; // id= is included into $param
  1055. } else {
  1056. print '&nbsp;';
  1057. }
  1058. print '</td>';
  1059. }
  1060. print "</tr>\n";
  1061. }
  1062. if ($nboflinks == 0)
  1063. {
  1064. print '<tr ' . $bc[$var] . '><td colspan="4">';
  1065. print $langs->trans("NoLinkFound");
  1066. print '</td></tr>';
  1067. }
  1068. print "</table>";
  1069. print '</form>';
  1070. return $nboflinks;
  1071. }
  1072. }