html.formfile.class.php 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873
  1. <?php
  2. /* Copyright (C) 2008-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010-2014 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2013 Charles-Fr BENKE <charles.fr@benke.fr>
  6. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  7. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  8. * Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
  9. * Copyright (C) 2016-2017 Ferran Marcet <fmarcet@2byte.es>
  10. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/core/class/html.formfile.class.php
  27. * \ingroup core
  28. * \brief File of class to offer components to list and upload files
  29. */
  30. /**
  31. * Class to offer components to list and upload files
  32. */
  33. class FormFile
  34. {
  35. private $db;
  36. /**
  37. * @var string Error code (or message)
  38. */
  39. public $error;
  40. public $numoffiles;
  41. public $infofiles; // Used to return informations by function getDocumentsLink
  42. /**
  43. * Constructor
  44. *
  45. * @param DoliDB $db Database handler
  46. */
  47. public function __construct($db)
  48. {
  49. $this->db = $db;
  50. $this->numoffiles = 0;
  51. }
  52. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  53. /**
  54. * Show form to upload a new file.
  55. *
  56. * @param string $url Url
  57. * @param string $title Title zone (Title or '' or 'none')
  58. * @param int $addcancel 1=Add 'Cancel' button
  59. * @param int $sectionid If upload must be done inside a particular ECM section (is sectionid defined, sectiondir must not be)
  60. * @param int $perm Value of permission to allow upload
  61. * @param int $size Length of input file area. Deprecated.
  62. * @param Object $object Object to use (when attachment is done on an element)
  63. * @param string $options Add an option column
  64. * @param integer $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option).
  65. * Deprecated 2 should never be used and if 1 is used, option should no be enabled.
  66. * @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__'
  67. * @param integer $linkfiles 1=Also add form to link files, 0=Do not show form to link files
  68. * @param string $htmlname Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM)
  69. * @param string $accept Specifies the types of files accepted (This is not a security check but an user interface facility. eg '.pdf,image/*' or '.png,.jpg' or 'video/*')
  70. * @param string $sectiondir If upload must be done inside a particular directory (if sectiondir defined, sectionid must not be)
  71. * @param int $usewithoutform 0=Default, 1=Disable <form> and style to use in existing area
  72. * @param int $capture 1=Add tag capture="capture" to force use of micro or video recording to generate file. When setting this to 1, you must also provide a value for $accept.
  73. * @return int <0 if KO, >0 if OK
  74. */
  75. public function form_attach_new_file($url, $title = '', $addcancel = 0, $sectionid = 0, $perm = 1, $size = 50, $object = '', $options = '', $useajax = 1, $savingdocmask = '', $linkfiles = 1, $htmlname = 'formuserfile', $accept = '', $sectiondir = '', $usewithoutform = 0, $capture = 0)
  76. {
  77. // phpcs:enable
  78. global $conf, $langs, $hookmanager;
  79. $hookmanager->initHooks(array('formfile'));
  80. // Deprecation warning
  81. if ($useajax == 2) {
  82. dol_syslog(__METHOD__.": using 2 for useajax is deprecated and should be not used", LOG_WARNING);
  83. }
  84. if (!empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax = 0;
  85. if ((!empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax == 2))
  86. {
  87. // TODO: Check this works with 2 forms on same page
  88. // TODO: Check this works with GED module, otherwise, force useajax to 0
  89. // TODO: This does not support option savingdocmask
  90. // TODO: This break feature to upload links too
  91. return $this->_formAjaxFileUpload($object);
  92. } else {
  93. //If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed
  94. if (!$perm && !empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
  95. return 1;
  96. }
  97. $out = "\n\n".'<!-- Start form attach new file --><div class="formattachnewfile">'."\n";
  98. if (empty($title)) $title = $langs->trans("AttachANewFile");
  99. if ($title != 'none') $out .= load_fiche_titre($title, null, null);
  100. if (empty($usewithoutform)) // Try to avoid this and set instead the form by the caller.
  101. {
  102. $out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">';
  103. $out .= '<input type="hidden" name="token" value="'.newToken().'">';
  104. $out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">';
  105. $out .= '<input type="hidden" id="'.$htmlname.'_section_id" name="section_id" value="'.$sectionid.'">';
  106. $out .= '<input type="hidden" name="sortfield" value="'.GETPOST('sortfield', 'alpha').'">';
  107. $out .= '<input type="hidden" name="sortorder" value="'.GETPOST('sortorder', 'aZ09').'">';
  108. }
  109. $out .= '<table class="nobordernopadding centpercent">';
  110. $out .= '<tr>';
  111. if (!empty($options)) $out .= '<td>'.$options.'</td>';
  112. $out .= '<td class="valignmiddle nowrap">';
  113. $max = $conf->global->MAIN_UPLOAD_DOC; // In Kb
  114. $maxphp = @ini_get('upload_max_filesize'); // In unknown
  115. if (preg_match('/k$/i', $maxphp)) $maxphp = $maxphp * 1;
  116. if (preg_match('/m$/i', $maxphp)) $maxphp = $maxphp * 1024;
  117. if (preg_match('/g$/i', $maxphp)) $maxphp = $maxphp * 1024 * 1024;
  118. if (preg_match('/t$/i', $maxphp)) $maxphp = $maxphp * 1024 * 1024 * 1024;
  119. $maxphp2 = @ini_get('post_max_size'); // In unknown
  120. if (preg_match('/k$/i', $maxphp2)) $maxphp2 = $maxphp2 * 1;
  121. if (preg_match('/m$/i', $maxphp2)) $maxphp2 = $maxphp2 * 1024;
  122. if (preg_match('/g$/i', $maxphp2)) $maxphp2 = $maxphp2 * 1024 * 1024;
  123. if (preg_match('/t$/i', $maxphp2)) $maxphp2 = $maxphp2 * 1024 * 1024 * 1024;
  124. // Now $max and $maxphp and $maxphp2 are in Kb
  125. $maxmin = $max;
  126. $maxphptoshow = $maxphptoshowparam = '';
  127. if ($maxphp > 0)
  128. {
  129. $maxmin = min($max, $maxphp);
  130. $maxphptoshow = $maxphp;
  131. $maxphptoshowparam = 'upload_max_filesize';
  132. }
  133. if ($maxphp2 > 0)
  134. {
  135. $maxmin = min($max, $maxphp2);
  136. if ($maxphp2 < $maxphp)
  137. {
  138. $maxphptoshow = $maxphp2;
  139. $maxphptoshowparam = 'post_max_size';
  140. }
  141. }
  142. if ($maxmin > 0)
  143. {
  144. // MAX_FILE_SIZE doit précéder le champ input de type file
  145. $out .= '<input type="hidden" name="max_file_size" value="'.($maxmin * 1024).'">';
  146. }
  147. $out .= '<input class="flat minwidth400 maxwidth200onsmartphone" type="file"';
  148. //$out .= ((!empty($conf->global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic') ? ' name="userfile"' : ' name="userfile[]" multiple');
  149. $out .= ((!empty($conf->global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD)) ? ' name="userfile"' : ' name="userfile[]" multiple');
  150. $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm) ? ' disabled' : '');
  151. $out .= (!empty($accept) ? ' accept="'.$accept.'"' : ' accept=""');
  152. $out .= (!empty($capture) ? ' capture="capture"' : '');
  153. $out .= '>';
  154. $out .= ' ';
  155. if ($sectionid) { // Show overwrite if exists for ECM module only
  156. $langs->load('link');
  157. $out .= '<input style="margin-right: 2px;" type="checkbox" id="overwritefile" name="overwritefile" value="1"><label for="overwritefile">'.$langs->trans("OverwriteIfExists").'</label>';
  158. }
  159. $out .= '<input type="submit" class="button reposition" name="sendit" value="'.$langs->trans("Upload").'"';
  160. $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm) ? ' disabled' : '');
  161. $out .= '>';
  162. if ($addcancel)
  163. {
  164. $out .= ' &nbsp; ';
  165. $out .= '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  166. }
  167. if (!empty($conf->global->MAIN_UPLOAD_DOC))
  168. {
  169. if ($perm)
  170. {
  171. $langs->load('other');
  172. $out .= ' ';
  173. $out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
  174. }
  175. } else {
  176. $out .= ' ('.$langs->trans("UploadDisabled").')';
  177. }
  178. $out .= "</td></tr>";
  179. if ($savingdocmask)
  180. {
  181. //add a global variable for disable the auto renaming on upload
  182. $rename = (empty($conf->global->MAIN_DOC_UPLOAD_NOT_RENAME_BY_DEFAULT) ? 'checked' : '');
  183. $out .= '<tr>';
  184. if (!empty($options)) $out .= '<td>'.$options.'</td>';
  185. $out .= '<td valign="middle" class="nowrap">';
  186. $out .= '<input type="checkbox" '.$rename.' class="savingdocmask" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/', $langs->transnoentitiesnoconv("OriginFileName"), $savingdocmask), $langs->transnoentitiesnoconv("OriginFileName"));
  187. $out .= '</td>';
  188. $out .= '</tr>';
  189. }
  190. $out .= "</table>";
  191. if (empty($usewithoutform))
  192. {
  193. $out .= '</form>';
  194. if (empty($sectionid)) $out .= '<br>';
  195. }
  196. $out .= "\n</div><!-- End form attach new file -->\n";
  197. if ($linkfiles)
  198. {
  199. $out .= "\n".'<!-- Start form link new url --><div class="formlinknewurl">'."\n";
  200. $langs->load('link');
  201. $title = $langs->trans("LinkANewFile");
  202. $out .= load_fiche_titre($title, null, null);
  203. if (empty($usewithoutform))
  204. {
  205. $out .= '<form name="'.$htmlname.'_link" id="'.$htmlname.'_link" action="'.$url.'" method="POST">'."\n";
  206. $out .= '<input type="hidden" name="token" value="'.newToken().'">'."\n";
  207. $out .= '<input type="hidden" id="'.$htmlname.'_link_section_dir" name="link_section_dir" value="">'."\n";
  208. $out .= '<input type="hidden" id="'.$htmlname.'_link_section_id" name="link_section_id" value="'.$sectionid.'">'."\n";
  209. }
  210. $out .= '<div class="valignmiddle">';
  211. $out .= '<div class="inline-block" style="padding-right: 10px;">';
  212. if (!empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink").':</label> ';
  213. $out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">';
  214. $out .= '</div>';
  215. $out .= '<div class="inline-block" style="padding-right: 10px;">';
  216. if (!empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="label">'.$langs->trans("Label").':</label> ';
  217. $out .= '<input type="text" class="flat" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">';
  218. $out .= '<input type="hidden" name="objecttype" value="'.$object->element.'">';
  219. $out .= '<input type="hidden" name="objectid" value="'.$object->id.'">';
  220. $out .= '</div>';
  221. $out .= '<div class="inline-block" style="padding-right: 10px;">';
  222. $out .= '<input type="submit" class="button" name="linkit" value="'.$langs->trans("ToLink").'"';
  223. $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm) ? ' disabled' : '');
  224. $out .= '>';
  225. $out .= '</div>';
  226. $out .= '</div>';
  227. if (empty($usewithoutform))
  228. {
  229. $out .= '<div class="clearboth"></div>';
  230. $out .= '</form><br>';
  231. }
  232. $out .= "\n</div><!-- End form link new url -->\n";
  233. }
  234. $parameters = array('socid'=>(isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id'=>(isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'url'=>$url, 'perm'=>$perm);
  235. $res = $hookmanager->executeHooks('formattachOptions', $parameters, $object);
  236. if (empty($res))
  237. {
  238. print '<div class="'.($usewithoutform ? 'inline-block valignmiddle' : 'attacharea attacharea'.$htmlname).'">';
  239. print $out;
  240. print '</div>';
  241. }
  242. print $hookmanager->resPrint;
  243. return 1;
  244. }
  245. }
  246. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  247. /**
  248. * Show the box with list of available documents for object
  249. *
  250. * @param string $modulepart propal, facture, facture_fourn, ...
  251. * @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.
  252. * @param string $filedir Directory to scan
  253. * @param string $urlsource Url of origin page (for return)
  254. * @param int $genallowed Generation is allowed (1/0 or array of formats)
  255. * @param int $delallowed Remove is allowed (1/0)
  256. * @param string $modelselected Model to preselect by default
  257. * @param integer $allowgenifempty Show warning if no model activated
  258. * @param integer $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined)
  259. * @param int $iconPDF Show only PDF icon with link (1/0)
  260. * @param int $notused Not used
  261. * @param integer $noform Do not output html form tags
  262. * @param string $param More param on http links
  263. * @param string $title Title to show on top of form
  264. * @param string $buttonlabel Label on submit button
  265. * @param string $codelang Default language code to use on lang combo box if multilang is enabled
  266. * @return int <0 if KO, number of shown files if OK
  267. * @deprecated Use print xxx->showdocuments() instead.
  268. */
  269. public function show_documents($modulepart, $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed = 0, $modelselected = '', $allowgenifempty = 1, $forcenomultilang = 0, $iconPDF = 0, $notused = 0, $noform = 0, $param = '', $title = '', $buttonlabel = '', $codelang = '')
  270. {
  271. // phpcs:enable
  272. $this->numoffiles = 0;
  273. print $this->showdocuments($modulepart, $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed, $modelselected, $allowgenifempty, $forcenomultilang, $iconPDF, $notused, $noform, $param, $title, $buttonlabel, $codelang);
  274. return $this->numoffiles;
  275. }
  276. /**
  277. * Return a string to show the box with list of available documents for object.
  278. * This also set the property $this->numoffiles
  279. *
  280. * @param string $modulepart Module the files are related to ('propal', 'facture', 'facture_fourn', 'mymodule', 'mymodule:nameofsubmodule', 'mymodule_temp', ...)
  281. * @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.
  282. * @param string $filedir Directory to scan
  283. * @param string $urlsource Url of origin page (for return)
  284. * @param int|string[] $genallowed Generation is allowed (1/0 or array list of templates)
  285. * @param int $delallowed Remove is allowed (1/0)
  286. * @param string $modelselected Model to preselect by default
  287. * @param integer $allowgenifempty Allow generation even if list of template ($genallowed) is empty (show however a warning)
  288. * @param integer $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined)
  289. * @param int $iconPDF Deprecated, see getDocumentsLink
  290. * @param int $notused Not used
  291. * @param integer $noform Do not output html form tags
  292. * @param string $param More param on http links
  293. * @param string $title Title to show on top of form. Example: '' (Default to "Documents") or 'none'
  294. * @param string $buttonlabel Label on submit button
  295. * @param string $codelang Default language code to use on lang combo box if multilang is enabled
  296. * @param string $morepicto Add more HTML content into cell with picto
  297. * @param Object $object Object when method is called from an object card.
  298. * @param int $hideifempty Hide section of generated files if there is no file
  299. * @param string $removeaction (optional) The action to remove a file
  300. * @return string Output string with HTML array of documents (might be empty string)
  301. */
  302. public function showdocuments($modulepart, $modulesubdir, $filedir, $urlsource, $genallowed, $delallowed = 0, $modelselected = '', $allowgenifempty = 1, $forcenomultilang = 0, $iconPDF = 0, $notused = 0, $noform = 0, $param = '', $title = '', $buttonlabel = '', $codelang = '', $morepicto = '', $object = null, $hideifempty = 0, $removeaction = 'remove_file')
  303. {
  304. // Deprecation warning
  305. if (!empty($iconPDF)) {
  306. dol_syslog(__METHOD__.": passing iconPDF parameter is deprecated", LOG_WARNING);
  307. }
  308. global $langs, $conf, $user, $hookmanager;
  309. global $form;
  310. if (!is_object($form)) $form = new Form($this->db);
  311. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  312. // For backward compatibility
  313. if (!empty($iconPDF)) {
  314. return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir);
  315. }
  316. // Add entity in $param if not already exists
  317. if (!preg_match('/entity\=[0-9]+/', $param)) {
  318. $param .= ($param ? '&' : '').'entity='.(!empty($object->entity) ? $object->entity : $conf->entity);
  319. }
  320. $printer = 0;
  321. if (in_array($modulepart, array('facture', 'supplier_proposal', 'propal', 'proposal', 'order', 'commande', 'expedition', 'commande_fournisseur', 'expensereport', 'livraison', 'ticket'))) // The direct print feature is implemented only for such elements
  322. {
  323. $printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled)) ?true:false;
  324. }
  325. $hookmanager->initHooks(array('formfile'));
  326. // Get list of files
  327. $file_list = null;
  328. if (!empty($filedir))
  329. {
  330. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  331. }
  332. if ($hideifempty && empty($file_list)) return '';
  333. $out = '';
  334. $forname = 'builddoc';
  335. $headershown = 0;
  336. $showempty = 0;
  337. $i = 0;
  338. $out .= "\n".'<!-- Start show_document -->'."\n";
  339. //print 'filedir='.$filedir;
  340. if (preg_match('/massfilesarea_/', $modulepart))
  341. {
  342. $out .= '<div id="show_files"><br></div>'."\n";
  343. $title = $langs->trans("MassFilesArea").' <a href="" id="togglemassfilesarea" ref="shown">('.$langs->trans("Hide").')</a>';
  344. $title .= '<script>
  345. jQuery(document).ready(function() {
  346. jQuery(\'#togglemassfilesarea\').click(function() {
  347. if (jQuery(\'#togglemassfilesarea\').attr(\'ref\') == "shown")
  348. {
  349. jQuery(\'#'.$modulepart.'_table\').hide();
  350. jQuery(\'#togglemassfilesarea\').attr("ref", "hidden");
  351. jQuery(\'#togglemassfilesarea\').text("('.dol_escape_js($langs->trans("Show")).')");
  352. }
  353. else
  354. {
  355. jQuery(\'#'.$modulepart.'_table\').show();
  356. jQuery(\'#togglemassfilesarea\').attr("ref","shown");
  357. jQuery(\'#togglemassfilesarea\').text("('.dol_escape_js($langs->trans("Hide")).')");
  358. }
  359. return false;
  360. });
  361. });
  362. </script>';
  363. }
  364. $titletoshow = $langs->trans("Documents");
  365. if (!empty($title)) $titletoshow = ($title == 'none' ? '' : $title);
  366. // Show table
  367. if ($genallowed)
  368. {
  369. $modellist = array();
  370. if ($modulepart == 'company')
  371. {
  372. $showempty = 1;
  373. if (is_array($genallowed)) $modellist = $genallowed;
  374. else {
  375. include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
  376. $modellist = ModeleThirdPartyDoc::liste_modeles($this->db);
  377. }
  378. } elseif ($modulepart == 'propal')
  379. {
  380. if (is_array($genallowed)) $modellist = $genallowed;
  381. else {
  382. include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
  383. $modellist = ModelePDFPropales::liste_modeles($this->db);
  384. }
  385. } elseif ($modulepart == 'supplier_proposal')
  386. {
  387. if (is_array($genallowed)) $modellist = $genallowed;
  388. else {
  389. include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
  390. $modellist = ModelePDFSupplierProposal::liste_modeles($this->db);
  391. }
  392. } elseif ($modulepart == 'commande')
  393. {
  394. if (is_array($genallowed)) $modellist = $genallowed;
  395. else {
  396. include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
  397. $modellist = ModelePDFCommandes::liste_modeles($this->db);
  398. }
  399. } elseif ($modulepart == 'expedition')
  400. {
  401. if (is_array($genallowed)) $modellist = $genallowed;
  402. else {
  403. include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  404. $modellist = ModelePDFExpedition::liste_modeles($this->db);
  405. }
  406. } elseif ($modulepart == 'reception')
  407. {
  408. if (is_array($genallowed)) $modellist = $genallowed;
  409. else {
  410. include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
  411. $modellist = ModelePdfReception::liste_modeles($this->db);
  412. }
  413. } elseif ($modulepart == 'livraison')
  414. {
  415. if (is_array($genallowed)) $modellist = $genallowed;
  416. else {
  417. include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php';
  418. $modellist = ModelePDFDeliveryOrder::liste_modeles($this->db);
  419. }
  420. } elseif ($modulepart == 'ficheinter')
  421. {
  422. if (is_array($genallowed)) $modellist = $genallowed;
  423. else {
  424. include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
  425. $modellist = ModelePDFFicheinter::liste_modeles($this->db);
  426. }
  427. } elseif ($modulepart == 'facture')
  428. {
  429. if (is_array($genallowed)) $modellist = $genallowed;
  430. else {
  431. include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  432. $modellist = ModelePDFFactures::liste_modeles($this->db);
  433. }
  434. } elseif ($modulepart == 'contract')
  435. {
  436. if (is_array($genallowed)) $modellist = $genallowed;
  437. else {
  438. include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
  439. $modellist = ModelePDFContract::liste_modeles($this->db);
  440. }
  441. } elseif ($modulepart == 'project')
  442. {
  443. if (is_array($genallowed)) $modellist = $genallowed;
  444. else {
  445. include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
  446. $modellist = ModelePDFProjects::liste_modeles($this->db);
  447. }
  448. } elseif ($modulepart == 'project_task')
  449. {
  450. if (is_array($genallowed)) $modellist = $genallowed;
  451. else {
  452. include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
  453. $modellist = ModelePDFTask::liste_modeles($this->db);
  454. }
  455. } elseif ($modulepart == 'product')
  456. {
  457. if (is_array($genallowed)) $modellist = $genallowed;
  458. else {
  459. include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
  460. $modellist = ModelePDFProduct::liste_modeles($this->db);
  461. }
  462. } elseif ($modulepart == 'product_batch')
  463. {
  464. if (is_array($genallowed)) $modellist = $genallowed;
  465. else {
  466. include_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php';
  467. $modellist = ModelePDFProductBatch::liste_modeles($this->db);
  468. }
  469. } elseif ($modulepart == 'stock')
  470. {
  471. if (is_array($genallowed)) $modellist = $genallowed;
  472. else {
  473. include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_stock.php';
  474. $modellist = ModelePDFStock::liste_modeles($this->db);
  475. }
  476. } elseif ($modulepart == 'movement')
  477. {
  478. if (is_array($genallowed)) $modellist = $genallowed;
  479. else {
  480. include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_movement.php';
  481. $modellist = ModelePDFMovement::liste_modeles($this->db);
  482. }
  483. } elseif ($modulepart == 'export')
  484. {
  485. if (is_array($genallowed)) $modellist = $genallowed;
  486. else {
  487. include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
  488. $modellist = ModeleExports::liste_modeles($this->db);
  489. }
  490. } elseif ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order')
  491. {
  492. if (is_array($genallowed)) $modellist = $genallowed;
  493. else {
  494. include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
  495. $modellist = ModelePDFSuppliersOrders::liste_modeles($this->db);
  496. }
  497. } elseif ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice')
  498. {
  499. if (is_array($genallowed)) $modellist = $genallowed;
  500. else {
  501. include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
  502. $modellist = ModelePDFSuppliersInvoices::liste_modeles($this->db);
  503. }
  504. } elseif ($modulepart == 'supplier_payment')
  505. {
  506. if (is_array($genallowed)) $modellist = $genallowed;
  507. else {
  508. include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
  509. $modellist = ModelePDFSuppliersPayments::liste_modeles($this->db);
  510. }
  511. } elseif ($modulepart == 'remisecheque')
  512. {
  513. if (is_array($genallowed)) $modellist = $genallowed;
  514. else {
  515. include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
  516. $modellist = ModeleChequeReceipts::liste_modeles($this->db);
  517. }
  518. } elseif ($modulepart == 'donation')
  519. {
  520. if (is_array($genallowed)) $modellist = $genallowed;
  521. else {
  522. include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
  523. $modellist = ModeleDon::liste_modeles($this->db);
  524. }
  525. } elseif ($modulepart == 'member')
  526. {
  527. if (is_array($genallowed)) $modellist = $genallowed;
  528. else {
  529. include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php';
  530. $modellist = ModelePDFCards::liste_modeles($this->db);
  531. }
  532. } elseif ($modulepart == 'agenda' || $modulepart == 'actions')
  533. {
  534. if (is_array($genallowed)) $modellist = $genallowed;
  535. else {
  536. include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php';
  537. $modellist = ModeleAction::liste_modeles($this->db);
  538. }
  539. } elseif ($modulepart == 'expensereport')
  540. {
  541. if (is_array($genallowed)) $modellist = $genallowed;
  542. else {
  543. include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
  544. $modellist = ModeleExpenseReport::liste_modeles($this->db);
  545. }
  546. } elseif ($modulepart == 'unpaid')
  547. {
  548. $modellist = '';
  549. } elseif ($modulepart == 'user')
  550. {
  551. if (is_array($genallowed)) $modellist = $genallowed;
  552. else {
  553. include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php';
  554. $modellist = ModelePDFUser::liste_modeles($this->db);
  555. }
  556. } elseif ($modulepart == 'usergroup')
  557. {
  558. if (is_array($genallowed)) $modellist = $genallowed;
  559. else {
  560. include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php';
  561. $modellist = ModelePDFUserGroup::liste_modeles($this->db);
  562. }
  563. } else {
  564. $submodulepart = $modulepart;
  565. // modulepart = 'nameofmodule' or 'nameofmodule:NameOfObject'
  566. $tmp = explode(':', $modulepart);
  567. if (!empty($tmp[1])) {
  568. $modulepart = $tmp[0];
  569. $submodulepart = $tmp[1];
  570. }
  571. // For normalized standard modules
  572. $file = dol_buildpath('/core/modules/'.$modulepart.'/modules_'.strtolower($submodulepart).'.php', 0);
  573. if (file_exists($file))
  574. {
  575. $res = include_once $file;
  576. }
  577. // For normalized external modules.
  578. else {
  579. $file = dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.strtolower($submodulepart).'.php', 0);
  580. $res = include_once $file;
  581. }
  582. $class = 'ModelePDF'.$submodulepart;
  583. if (class_exists($class))
  584. {
  585. $modellist = call_user_func($class.'::liste_modeles', $this->db);
  586. } else {
  587. dol_print_error($this->db, "Bad value for modulepart '".$modulepart."' in showdocuments");
  588. return -1;
  589. }
  590. }
  591. // Set headershown to avoid to have table opened a second time later
  592. $headershown = 1;
  593. if (empty($buttonlabel)) $buttonlabel = $langs->trans('Generate');
  594. if ($conf->browser->layout == 'phone') $urlsource .= '#'.$forname.'_form'; // So we switch to form after a generation
  595. if (empty($noform)) $out .= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc').'" id="'.$forname.'_form" method="post">';
  596. $out .= '<input type="hidden" name="action" value="builddoc">';
  597. $out .= '<input type="hidden" name="token" value="'.newToken().'">';
  598. $out .= load_fiche_titre($titletoshow, '', '');
  599. $out .= '<div class="div-table-responsive-no-min">';
  600. $out .= '<table class="liste formdoc noborder centpercent">';
  601. $out .= '<tr class="liste_titre">';
  602. $addcolumforpicto = ($delallowed || $printer || $morepicto);
  603. $colspan = (3 + ($addcolumforpicto ? 1 : 0)); $colspanmore = 0;
  604. $out .= '<th colspan="'.$colspan.'" class="formdoc liste_titre maxwidthonsmartphone center">';
  605. // Model
  606. if (!empty($modellist))
  607. {
  608. asort($modellist);
  609. $out .= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>';
  610. if (is_array($modellist) && count($modellist) == 1) // If there is only one element
  611. {
  612. $arraykeys = array_keys($modellist);
  613. $modelselected = $arraykeys[0];
  614. }
  615. $morecss = 'maxwidth200';
  616. if ($conf->browser->layout == 'phone') $morecss = 'maxwidth100';
  617. $out .= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss);
  618. if ($conf->use_javascript_ajax)
  619. {
  620. $out .= ajax_combobox('model');
  621. }
  622. } else {
  623. $out .= '<div class="float">'.$langs->trans("Files").'</div>';
  624. }
  625. // Language code (if multilang)
  626. if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && !$forcenomultilang && (!empty($modellist) || $showempty))
  627. {
  628. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  629. $formadmin = new FormAdmin($this->db);
  630. $defaultlang = $codelang ? $codelang : $langs->getDefaultLang();
  631. $morecss = 'maxwidth150';
  632. if ($conf->browser->layout == 'phone') $morecss = 'maxwidth100';
  633. $out .= $formadmin->select_language($defaultlang, 'lang_id', 0, null, 0, 0, 0, $morecss);
  634. } else {
  635. $out .= '&nbsp;';
  636. }
  637. // Button
  638. $genbutton = '<input class="button buttongen" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
  639. $genbutton .= ' type="submit" value="'.$buttonlabel.'"';
  640. if (!$allowgenifempty && !is_array($modellist) && empty($modellist)) $genbutton .= ' disabled';
  641. $genbutton .= '>';
  642. if ($allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid')
  643. {
  644. $langs->load("errors");
  645. $genbutton .= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
  646. }
  647. if (!$allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton = '';
  648. if (empty($modellist) && !$showempty && $modulepart != 'unpaid') $genbutton = '';
  649. $out .= $genbutton;
  650. $out .= '</th>';
  651. if (!empty($hookmanager->hooks['formfile']))
  652. {
  653. foreach ($hookmanager->hooks['formfile'] as $module)
  654. {
  655. if (method_exists($module, 'formBuilddocLineOptions'))
  656. {
  657. $colspanmore++;
  658. $out .= '<th></th>';
  659. }
  660. }
  661. }
  662. $out .= '</tr>';
  663. // Execute hooks
  664. $parameters = array('colspan'=>($colspan + $colspanmore), 'socid'=>(isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id'=>(isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'modulepart'=>$modulepart);
  665. if (is_object($hookmanager))
  666. {
  667. $reshook = $hookmanager->executeHooks('formBuilddocOptions', $parameters, $GLOBALS['object']);
  668. $out .= $hookmanager->resPrint;
  669. }
  670. }
  671. // Get list of files
  672. if (!empty($filedir))
  673. {
  674. $link_list = array();
  675. if (is_object($object))
  676. {
  677. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  678. $link = new Link($this->db);
  679. $sortfield = $sortorder = null;
  680. $res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder);
  681. }
  682. $out .= '<!-- html.formfile::showdocuments -->'."\n";
  683. // Show title of array if not already shown
  684. if ((!empty($file_list) || !empty($link_list) || preg_match('/^massfilesarea/', $modulepart))
  685. && !$headershown)
  686. {
  687. $headershown = 1;
  688. $out .= '<div class="titre">'.$titletoshow.'</div>'."\n";
  689. $out .= '<div class="div-table-responsive-no-min">';
  690. $out .= '<table class="noborder centpercent" id="'.$modulepart.'_table">'."\n";
  691. }
  692. // Loop on each file found
  693. if (is_array($file_list))
  694. {
  695. foreach ($file_list as $file)
  696. {
  697. // Define relative path for download link (depends on module)
  698. $relativepath = $file["name"]; // Cas general
  699. if ($modulesubdir) $relativepath = $modulesubdir."/".$file["name"]; // Cas propal, facture...
  700. if ($modulepart == 'export') $relativepath = $file["name"]; // Other case
  701. $out .= '<tr class="oddeven">';
  702. $documenturl = DOL_URL_ROOT.'/document.php';
  703. if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) $documenturl = $conf->global->DOL_URL_ROOT_DOCUMENT_PHP; // To use another wrapper
  704. // Show file name with link to download
  705. $out .= '<td class="minwidth200">';
  706. $out .= '<a class="documentdownload paddingright" href="'.$documenturl.'?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).($param ? '&'.$param : '').'"';
  707. $mime = dol_mimetype($relativepath, '', 0);
  708. if (preg_match('/text/', $mime)) $out .= ' target="_blank"';
  709. $out .= '>';
  710. $out .= img_mime($file["name"], $langs->trans("File").': '.$file["name"]);
  711. $out .= dol_trunc($file["name"], 150);
  712. $out .= '</a>'."\n";
  713. $out .= $this->showPreview($file, $modulepart, $relativepath, 0, $param);
  714. $out .= '</td>';
  715. // Show file size
  716. $size = (!empty($file['size']) ? $file['size'] : dol_filesize($filedir."/".$file["name"]));
  717. $out .= '<td class="nowrap right">'.dol_print_size($size, 1, 1).'</td>';
  718. // Show file date
  719. $date = (!empty($file['date']) ? $file['date'] : dol_filemtime($filedir."/".$file["name"]));
  720. $out .= '<td class="nowrap right">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>';
  721. if ($delallowed || $printer || $morepicto)
  722. {
  723. $out .= '<td class="right nowraponall">';
  724. if ($delallowed)
  725. {
  726. $tmpurlsource = preg_replace('/#[a-zA-Z0-9_]*$/', '', $urlsource);
  727. $out .= '<a href="'.$tmpurlsource.((strpos($tmpurlsource, '?') === false) ? '?' : '&amp;').'action='.$removeaction.'&amp;file='.urlencode($relativepath);
  728. $out .= ($param ? '&amp;'.$param : '');
  729. //$out.= '&modulepart='.$modulepart; // TODO obsolete ?
  730. //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
  731. $out .= '">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  732. }
  733. if ($printer)
  734. {
  735. //$out.= '<td class="right">';
  736. $out .= '<a class="marginleftonly" href="'.$urlsource.(strpos($urlsource, '?') ? '&amp;' : '?').'action=print_file&amp;printer='.$modulepart.'&amp;file='.urlencode($relativepath);
  737. $out .= ($param ? '&amp;'.$param : '');
  738. $out .= '">'.img_picto($langs->trans("PrintFile", $relativepath), 'printer.png').'</a>';
  739. }
  740. if ($morepicto)
  741. {
  742. $morepicto = preg_replace('/__FILENAMEURLENCODED__/', urlencode($relativepath), $morepicto);
  743. $out .= $morepicto;
  744. }
  745. $out .= '</td>';
  746. }
  747. if (is_object($hookmanager))
  748. {
  749. $parameters = array('colspan'=>($colspan + $colspanmore), 'socid'=>(isset($GLOBALS['socid']) ? $GLOBALS['socid'] : ''), 'id'=>(isset($GLOBALS['id']) ? $GLOBALS['id'] : ''), 'modulepart'=>$modulepart, 'relativepath'=>$relativepath);
  750. $res = $hookmanager->executeHooks('formBuilddocLineOptions', $parameters, $file);
  751. if (empty($res))
  752. {
  753. $out .= $hookmanager->resPrint; // Complete line
  754. $out .= '</tr>';
  755. } else {
  756. $out = $hookmanager->resPrint; // Replace all $out
  757. }
  758. }
  759. }
  760. $this->numoffiles++;
  761. }
  762. // Loop on each link found
  763. if (is_array($link_list))
  764. {
  765. $colspan = 2;
  766. foreach ($link_list as $file)
  767. {
  768. $out .= '<tr class="oddeven">';
  769. $out .= '<td colspan="'.$colspan.'" class="maxwidhtonsmartphone">';
  770. $out .= '<a data-ajax="false" href="'.$file->url.'" target="_blank">';
  771. $out .= $file->label;
  772. $out .= '</a>';
  773. $out .= '</td>';
  774. $out .= '<td class="right">';
  775. $out .= dol_print_date($file->datea, 'dayhour');
  776. $out .= '</td>';
  777. if ($delallowed || $printer || $morepicto) $out .= '<td></td>';
  778. $out .= '</tr>'."\n";
  779. }
  780. $this->numoffiles++;
  781. }
  782. if (count($file_list) == 0 && count($link_list) == 0 && $headershown)
  783. {
  784. $out .= '<tr><td colspan="'.(3 + ($addcolumforpicto ? 1 : 0)).'" class="opacitymedium">'.$langs->trans("None").'</td></tr>'."\n";
  785. }
  786. }
  787. if ($headershown)
  788. {
  789. // Affiche pied du tableau
  790. $out .= "</table>\n";
  791. $out .= "</div>\n";
  792. if ($genallowed)
  793. {
  794. if (empty($noform)) $out .= '</form>'."\n";
  795. }
  796. }
  797. $out .= '<!-- End show_document -->'."\n";
  798. //return ($i?$i:$headershown);
  799. return $out;
  800. }
  801. /**
  802. * Show a Document icon with link(s)
  803. * You may want to call this into a div like this:
  804. * print '<div class="inline-block valignmiddle">'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'</div>';
  805. *
  806. * @param string $modulepart propal, facture, facture_fourn, ...
  807. * @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.
  808. * @param string $filedir Full path to directory to scan
  809. * @param string $filter Filter filenames on this regex string (Example: '\.pdf$')
  810. * @return string Output string with HTML link of documents (might be empty string). This also fill the array ->infofiles
  811. */
  812. public function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter = '')
  813. {
  814. global $conf, $langs;
  815. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  816. $out = '';
  817. $this->infofiles = array('nboffiles'=>0, 'extensions'=>array(), 'files'=>array());
  818. $entity = 1; // Without multicompany
  819. // Get object entity
  820. if (!empty($conf->multicompany->enabled))
  821. {
  822. $regs = array();
  823. preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir, '/').'$/', $filedir, $regs);
  824. $entity = ((!empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default
  825. }
  826. // Get list of files starting with name of ref (but not followed by "-" to discard uploaded files and get only generated files)
  827. // @todo Why not showing by default all files by just removing the '[^\-]+' at end of regex ?
  828. if (!empty($conf->global->MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP))
  829. {
  830. $filterforfilesearch = preg_quote(basename($modulesubdir), '/');
  831. } else {
  832. $filterforfilesearch = preg_quote(basename($modulesubdir), '/').'[^\-]+';
  833. }
  834. $file_list = dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // We also discard .meta and .png preview
  835. //var_dump($file_list);
  836. // For ajax treatment
  837. $out .= '<!-- html.formfile::getDocumentsLink -->'."\n";
  838. if (!empty($file_list))
  839. {
  840. $out = '<dl class="dropdown inline-block">
  841. <dt><a data-ajax="false" href="#" onClick="return false;">'.img_picto('', 'listlight', '', 0, 0, 0, '', 'valignmiddle').'</a></dt>
  842. <dd><div class="multichoicedoc" style="position:absolute;left:100px;" ><ul class="ulselectedfields">';
  843. $tmpout = '';
  844. // Loop on each file found
  845. $found = 0;
  846. foreach ($file_list as $file)
  847. {
  848. $i++;
  849. if ($filter && !preg_match('/'.$filter.'/i', $file["name"])) continue; // Discard this. It does not match provided filter.
  850. $found++;
  851. // Define relative path for download link (depends on module)
  852. $relativepath = $file["name"]; // Cas general
  853. if ($modulesubdir) $relativepath = $modulesubdir."/".$file["name"]; // Cas propal, facture...
  854. // Autre cas
  855. if ($modulepart == 'donation') {
  856. $relativepath = get_exdir($modulesubdir, 2, 0, 0, null, 'donation').$file["name"];
  857. }
  858. if ($modulepart == 'export') {
  859. $relativepath = $file["name"];
  860. }
  861. $this->infofiles['nboffiles']++;
  862. $this->infofiles['files'][] = $file['fullname'];
  863. $ext = pathinfo($file["name"], PATHINFO_EXTENSION);
  864. if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext] = 1;
  865. else $this->infofiles['extensions'][$ext]++;
  866. // Preview
  867. if (!empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone'))
  868. {
  869. $tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity='.$entity);
  870. if ($tmparray && $tmparray['url'])
  871. {
  872. $tmpout .= '<li><a href="'.$tmparray['url'].'"'.($tmparray['css'] ? ' class="'.$tmparray['css'].'"' : '').($tmparray['mime'] ? ' mime="'.$tmparray['mime'].'"' : '').($tmparray['target'] ? ' target="'.$tmparray['target'].'"' : '').'>';
  873. //$tmpout.= img_picto('','detail');
  874. $tmpout .= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>';
  875. $tmpout .= $langs->trans("Preview").' '.$ext.'</a></li>';
  876. }
  877. }
  878. // Download
  879. $tmpout .= '<li class="nowrap"><a class="pictopreview nowrap" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&amp;entity='.$entity.'&amp;file='.urlencode($relativepath).'"';
  880. $mime = dol_mimetype($relativepath, '', 0);
  881. if (preg_match('/text/', $mime)) $tmpout .= ' target="_blank"';
  882. $tmpout .= '>';
  883. $tmpout .= img_mime($relativepath, $file["name"]);
  884. $tmpout .= $langs->trans("Download").' '.$ext;
  885. $tmpout .= '</a></li>'."\n";
  886. }
  887. $out .= $tmpout;
  888. $out .= '</ul></div></dd>
  889. </dl>';
  890. if (!$found) $out = '';
  891. } else {
  892. // TODO Add link to regenerate doc ?
  893. //$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n";
  894. }
  895. return $out;
  896. }
  897. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  898. /**
  899. * Show list of documents in $filearray (may be they are all in same directory but may not)
  900. * This also sync database if $upload_dir is defined.
  901. *
  902. * @param array $filearray Array of files loaded by dol_dir_list('files') function before calling this.
  903. * @param Object $object Object on which document is linked to.
  904. * @param string $modulepart Value for modulepart used by download or viewimage wrapper.
  905. * @param string $param Parameters on sort links (param must start with &, example &aaa=bbb&ccc=ddd)
  906. * @param int $forcedownload Force to open dialog box "Save As" when clicking on file.
  907. * @param string $relativepath Relative path of docs (autodefined if not provided), relative to module dir, not to MAIN_DATA_ROOT.
  908. * @param int $permonobject Permission on object (so permission to delete or crop document)
  909. * @param int $useinecm Change output for use in ecm module:
  910. * 0 or 6: Add a preview column. Show also a rename button. Show also a crop button for some values of $modulepart (must be supported into hard coded list in this function + photos_resize.php + restrictedArea + checkUserAccessToObject)
  911. * 1: Add link to edit ECM entry
  912. * 2: Add rename and crop link
  913. * 4: Add a preview column
  914. * 5: Add link to edit ECM entry and Add a preview column
  915. * @param string $textifempty Text to show if filearray is empty ('NoFileFound' if not defined)
  916. * @param int $maxlength Maximum length of file name shown.
  917. * @param string $title Title before list. Use 'none' to disable title.
  918. * @param string $url Full url to use for click links ('' = autodetect)
  919. * @param int $showrelpart 0=Show only filename (default), 1=Show first level 1 dir
  920. * @param int $permtoeditline Permission to edit document line (You must provide a value, -1 is deprecated and must not be used any more)
  921. * @param string $upload_dir Full path directory so we can know dir relative to MAIN_DATA_ROOT. Fill this to complete file data with database indexes.
  922. * @param string $sortfield Sort field ('name', 'size', 'position', ...)
  923. * @param string $sortorder Sort order ('ASC' or 'DESC')
  924. * @param int $disablemove 1=Disable move button, 0=Position move is possible.
  925. * @param int $addfilterfields Add line with filters
  926. * @param int $disablecrop Disable crop feature on images (-1 = auto, prefer to set it explicitely to 0 or 1)
  927. * @return int <0 if KO, nb of files shown if OK
  928. * @see list_of_autoecmfiles()
  929. */
  930. public function list_of_documents($filearray, $object, $modulepart, $param = '', $forcedownload = 0, $relativepath = '', $permonobject = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $title = '', $url = '', $showrelpart = 0, $permtoeditline = -1, $upload_dir = '', $sortfield = '', $sortorder = 'ASC', $disablemove = 1, $addfilterfields = 0, $disablecrop = -1)
  931. {
  932. // phpcs:enable
  933. global $user, $conf, $langs, $hookmanager;
  934. global $sortfield, $sortorder, $maxheightmini;
  935. global $dolibarr_main_url_root;
  936. global $form;
  937. if ($disablecrop == -1)
  938. {
  939. $disablecrop = 1;
  940. if (in_array($modulepart, array('bank', 'bom', 'expensereport', 'holiday', 'medias', 'member', 'mrp', 'project', 'product', 'produit', 'propal', 'service', 'societe', 'tax', 'tax-vat', 'ticket', 'user'))) $disablecrop = 0;
  941. }
  942. // Define relative path used to store the file
  943. if (empty($relativepath))
  944. {
  945. $relativepath = (!empty($object->ref) ?dol_sanitizeFileName($object->ref) : '').'/';
  946. 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
  947. if ($object->element == 'project_task') $relativepath = 'Call_not_supported_._Call_function_using_a_defined_relative_path_.';
  948. }
  949. // For backward compatiblity, we detect file stored into an old path
  950. if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos')
  951. {
  952. $relativepath = preg_replace('/^.*\/produit\//', '', $filearray[0]['path']).'/';
  953. }
  954. // Defined relative dir to DOL_DATA_ROOT
  955. $relativedir = '';
  956. if ($upload_dir)
  957. {
  958. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir);
  959. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  960. }
  961. // For example here $upload_dir = '/pathtodocuments/commande/SO2001-123/'
  962. // For example here $upload_dir = '/pathtodocuments/tax/vat/1'
  963. $hookmanager->initHooks(array('formfile'));
  964. $parameters = array(
  965. 'filearray' => $filearray,
  966. 'modulepart'=> $modulepart,
  967. 'param' => $param,
  968. 'forcedownload' => $forcedownload,
  969. 'relativepath' => $relativepath, // relative filename to module dir
  970. 'relativedir' => $relativedir, // relative dirname to DOL_DATA_ROOT
  971. 'permtodelete' => $permonobject,
  972. 'useinecm' => $useinecm,
  973. 'textifempty' => $textifempty,
  974. 'maxlength' => $maxlength,
  975. 'title' => $title,
  976. 'url' => $url
  977. );
  978. $reshook = $hookmanager->executeHooks('showFilesList', $parameters, $object);
  979. if (isset($reshook) && $reshook != '') // null or '' for bypass
  980. {
  981. return $reshook;
  982. } else {
  983. if (!is_object($form))
  984. {
  985. include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; // The compoent may be included into ajax page that does not include the Form class
  986. $form = new Form($this->db);
  987. }
  988. if (!preg_match('/&id=/', $param) && isset($object->id)) $param .= '&id='.$object->id;
  989. $relativepathwihtoutslashend = preg_replace('/\/$/', '', $relativepath);
  990. if ($relativepathwihtoutslashend) $param .= '&file='.urlencode($relativepathwihtoutslashend);
  991. if ($permtoeditline < 0) // Old behaviour for backward compatibility. New feature should call method with value 0 or 1
  992. {
  993. $permtoeditline = 0;
  994. if (in_array($modulepart, array('product', 'produit', 'service')))
  995. {
  996. if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoeditline = 1;
  997. if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoeditline = 1;
  998. }
  999. }
  1000. if (empty($conf->global->MAIN_UPLOAD_DOC))
  1001. {
  1002. $permtoeditline = 0;
  1003. $permonobject = 0;
  1004. }
  1005. // Show list of existing files
  1006. if ((empty($useinecm) || $useinecm == 6) && $title != 'none') print load_fiche_titre($title ? $title : $langs->trans("AttachedFiles"), '', 'file-upload', 0, '', 'table-list-of-attached-files');
  1007. if (empty($url)) $url = $_SERVER["PHP_SELF"];
  1008. print '<!-- html.formfile::list_of_documents -->'."\n";
  1009. if (GETPOST('action', 'aZ09') == 'editfile' && $permtoeditline)
  1010. {
  1011. print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" method="POST">';
  1012. print '<input type="hidden" name="token" value="'.newToken().'">';
  1013. print '<input type="hidden" name="action" value="renamefile">';
  1014. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1015. print '<input type="hidden" name="modulepart" value="'.$modulepart.'">';
  1016. }
  1017. print '<div class="div-table-responsive-no-min">';
  1018. print '<table width="100%" id="tablelines" class="liste noborder nobottom">'."\n";
  1019. if (!empty($addfilterfields))
  1020. {
  1021. print '<tr class="liste_titre nodrag nodrop">';
  1022. print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref', 'alpha')).'"></td>';
  1023. print '<td></td>';
  1024. print '<td></td>';
  1025. if (empty($useinecm) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6) print '<td></td>';
  1026. print '<td></td>';
  1027. print '<td></td>';
  1028. if (!$disablemove) print '<td></td>';
  1029. print "</tr>\n";
  1030. }
  1031. print '<tr class="liste_titre nodrag nodrop">';
  1032. //print $url.' sortfield='.$sortfield.' sortorder='.$sortorder;
  1033. print_liste_field_titre('Documents2', $url, "name", "", $param, '', $sortfield, $sortorder, 'left ');
  1034. print_liste_field_titre('Size', $url, "size", "", $param, '', $sortfield, $sortorder, 'right ');
  1035. print_liste_field_titre('Date', $url, "date", "", $param, '', $sortfield, $sortorder, 'center ');
  1036. if (empty($useinecm) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6) print_liste_field_titre('', $url, "", "", $param, '', $sortfield, $sortorder, 'center '); // Preview
  1037. print_liste_field_titre('');
  1038. print_liste_field_titre('');
  1039. if (!$disablemove) print_liste_field_titre('');
  1040. print "</tr>\n";
  1041. // Get list of files stored into database for same relative directory
  1042. if ($relativedir)
  1043. {
  1044. completeFileArrayWithDatabaseInfo($filearray, $relativedir);
  1045. //var_dump($sortfield.' - '.$sortorder);
  1046. if ($sortfield && $sortorder) // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
  1047. {
  1048. $filearray = dol_sort_array($filearray, $sortfield, $sortorder);
  1049. }
  1050. }
  1051. $nboffiles = count($filearray);
  1052. if ($nboffiles > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  1053. $i = 0; $nboflines = 0; $lastrowid = 0;
  1054. foreach ($filearray as $key => $file) // filearray must be only files here
  1055. {
  1056. if ($file['name'] != '.'
  1057. && $file['name'] != '..'
  1058. && !preg_match('/\.meta$/i', $file['name']))
  1059. {
  1060. if ($filearray[$key]['rowid'] > 0) $lastrowid = $filearray[$key]['rowid'];
  1061. $filepath = $relativepath.$file['name'];
  1062. $editline = 0;
  1063. $nboflines++;
  1064. print '<!-- Line list_of_documents '.$key.' relativepath = '.$relativepath.' -->'."\n";
  1065. // Do we have entry into database ?
  1066. print '<!-- In database: position='.$filearray[$key]['position'].' -->'."\n";
  1067. print '<tr class="oddeven" id="row-'.($filearray[$key]['rowid'] > 0 ? $filearray[$key]['rowid'] : 'AFTER'.$lastrowid.'POS'.($i + 1)).'">';
  1068. // File name
  1069. print '<td class="minwith200">';
  1070. // Show file name with link to download
  1071. //print "XX".$file['name']; //$file['name'] must be utf8
  1072. print '<a class="paddingright" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
  1073. if ($forcedownload) print '&attachment=1';
  1074. if (!empty($object->entity)) print '&entity='.$object->entity;
  1075. print '&file='.urlencode($filepath);
  1076. print '">';
  1077. print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'], 0, 0).')', 'inline-block valignbottom paddingright');
  1078. if ($showrelpart == 1) print $relativepath;
  1079. //print dol_trunc($file['name'],$maxlength,'middle');
  1080. if (GETPOST('action', 'aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile', 'alpha')))
  1081. {
  1082. print '</a>';
  1083. $section_dir = dirname(GETPOST('urlfile', 'alpha'));
  1084. if (! preg_match('/\/$/', $section_dir)) $section_dir.='/';
  1085. print '<input type="hidden" name="section_dir" value="'.$section_dir.'">';
  1086. print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">';
  1087. print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">';
  1088. $editline = 1;
  1089. } else {
  1090. $filenametoshow = preg_replace('/\.noexe$/', '', $file['name']);
  1091. print dol_trunc($filenametoshow, 200);
  1092. print '</a>';
  1093. }
  1094. // Preview link
  1095. if (!$editline) print $this->showPreview($file, $modulepart, $filepath, 0, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity));
  1096. print "</td>\n";
  1097. // Size
  1098. $sizetoshow = dol_print_size($file['size'], 1, 1);
  1099. $sizetoshowbytes = dol_print_size($file['size'], 0, 1);
  1100. print '<td class="right nowraponall">';
  1101. if ($sizetoshow == $sizetoshowbytes) print $sizetoshow;
  1102. else {
  1103. print $form->textwithpicto($sizetoshow, $sizetoshowbytes, -1);
  1104. }
  1105. print '</td>';
  1106. // Date
  1107. print '<td class="center" style="width: 140px">'.dol_print_date($file['date'], "dayhour", "tzuser").'</td>'; // 140px = width for date with PM format
  1108. // Preview
  1109. if (empty($useinecm) || $useinecm == 4 || $useinecm == 5 || $useinecm == 6)
  1110. {
  1111. $fileinfo = pathinfo($file['name']);
  1112. print '<td class="center">';
  1113. if (image_format_supported($file['name']) >= 0)
  1114. {
  1115. if ($useinecm == 5 || $useinecm == 6)
  1116. {
  1117. $smallfile = getImageFileNameForSize($file['name'], ''); // There is no thumb for ECM module and Media filemanager, so we use true image. TODO Change this it is slow on image dir.
  1118. } else {
  1119. $smallfile = getImageFileNameForSize($file['name'], '_small'); // For new thumbs using same ext (in lower case however) than original
  1120. }
  1121. if (!dol_is_file($file['path'].'/'.$smallfile)) $smallfile = getImageFileNameForSize($file['name'], '_small', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
  1122. //print $file['path'].'/'.$smallfile.'<br>';
  1123. $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity));
  1124. if (empty($urlforhref)) {
  1125. $urlforhref = DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity) ? $object->entity : $conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
  1126. print '<a href="'.$urlforhref.'" class="aphoto" target="_blank">';
  1127. } else {
  1128. print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
  1129. }
  1130. print '<img class="photo maxwidth200" height="'.(($useinecm == 4 || $useinecm == 5 || $useinecm == 6) ? '12' : $maxheightmini).'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity) ? $object->entity : $conf->entity).'&file='.urlencode($relativepath.$smallfile).'" title="">';
  1131. print '</a>';
  1132. } else print '&nbsp;';
  1133. print '</td>';
  1134. }
  1135. // Hash of file (only if we are in a mode where a scan of dir were done and we have id of file in ECM table)
  1136. print '<td class="center">';
  1137. if ($relativedir && $filearray[$key]['rowid'] > 0)
  1138. {
  1139. if ($editline)
  1140. {
  1141. print $langs->trans("FileSharedViaALink").' ';
  1142. print '<input class="inline-block" type="checkbox" name="shareenabled"'.($file['share'] ? ' checked="checked"' : '').' /> ';
  1143. } else {
  1144. if ($file['share'])
  1145. {
  1146. // Define $urlwithroot
  1147. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  1148. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  1149. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  1150. //print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>';
  1151. $forcedownload = 0;
  1152. $paramlink = '';
  1153. if (!empty($file['share'])) $paramlink .= ($paramlink ? '&' : '').'hashp='.$file['share']; // Hash for public share
  1154. if ($forcedownload) $paramlink .= ($paramlink ? '&' : '').'attachment=1';
  1155. $fulllink = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : '');
  1156. print img_picto($langs->trans("FileSharedViaALink"), 'globe').' ';
  1157. print '<input type="text" class="quatrevingtpercent minwidth200imp" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).'">';
  1158. } else {
  1159. //print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>';
  1160. }
  1161. }
  1162. }
  1163. print '</td>';
  1164. // Actions buttons
  1165. if (!$editline)
  1166. {
  1167. // Delete or view link
  1168. // ($param must start with &)
  1169. print '<td class="valignmiddle right actionbuttons nowraponall"><!-- action on files -->';
  1170. if ($useinecm == 1 || $useinecm == 5) // ECM manual tree only
  1171. {
  1172. // $section is inside $param
  1173. $newparam.=preg_replace('/&file=.*$/', '', $param); // We don't need param file=
  1174. $backtopage = DOL_URL_ROOT.'/ecm/index.php?&section_dir='.urlencode($relativepath).$newparam;
  1175. print '<a class="editfielda" href="'.DOL_URL_ROOT.'/ecm/file_card.php?urlfile='.urlencode($file['name']).$param.'&backtopage='.urlencode($backtopage).'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>';
  1176. }
  1177. if (empty($useinecm) || $useinecm == 2 || $useinecm == 6) // 6=Media file manager
  1178. {
  1179. $newmodulepart = $modulepart;
  1180. if (in_array($modulepart, array('product', 'produit', 'service'))) $newmodulepart = 'produit|service';
  1181. if (!$disablecrop && image_format_supported($file['name']) > 0)
  1182. {
  1183. if ($permtoeditline)
  1184. {
  1185. // Link to resize
  1186. $moreparaminurl = '';
  1187. if ($object->id > 0) {
  1188. $moreparaminurl = '&id='.$object->id;
  1189. } elseif (GETPOST('website', 'alpha')) {
  1190. $moreparaminurl = '&website='.GETPOST('website', 'alpha');
  1191. }
  1192. print '<a class="editfielda" href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).$moreparaminurl.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("ResizeOrCrop")).'">'.img_picto($langs->trans("ResizeOrCrop"), 'resize', 'class="paddingrightonly"').'</a>';
  1193. }
  1194. }
  1195. if ($permtoeditline)
  1196. {
  1197. $paramsectiondir = (in_array($modulepart, array('medias', 'ecm')) ? '&section_dir='.urlencode($relativepath) : '');
  1198. print '<a class="editfielda reposition" href="'.(($useinecm == 1 || $useinecm == 5) ? '#' : ($url.'?action=editfile&urlfile='.urlencode($filepath).$paramsectiondir.$param)).'" class="editfilelink" rel="'.$filepath.'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>';
  1199. }
  1200. }
  1201. if ($permonobject)
  1202. {
  1203. $useajax = 1;
  1204. if (!empty($conf->dol_use_jmobile)) $useajax = 0;
  1205. if (empty($conf->use_javascript_ajax)) $useajax = 0;
  1206. if (!empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax = 0;
  1207. print '<a href="'.((($useinecm && $useinecm != 6) && $useajax) ? '#' : ($url.'?action=delete&urlfile='.urlencode($filepath).$param)).'" class="reposition deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>';
  1208. }
  1209. print "</td>";
  1210. if (empty($disablemove))
  1211. {
  1212. if ($nboffiles > 1 && $conf->browser->layout != 'phone') {
  1213. print '<td class="linecolmove tdlineupdown center">';
  1214. if ($i > 0) {
  1215. print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=up&amp;rowid='.$line->id.'">'.img_up('default', 0, 'imgupforline').'</a>';
  1216. }
  1217. if ($i < $nboffiles - 1) {
  1218. print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id.'">'.img_down('default', 0, 'imgdownforline').'</a>';
  1219. }
  1220. print '</td>';
  1221. } else {
  1222. print '<td'.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'>';
  1223. print '</td>';
  1224. }
  1225. }
  1226. } else {
  1227. print '<td class="right">';
  1228. print '<input type="hidden" name="ecmfileid" value="'.$filearray[$key]['rowid'].'">';
  1229. print '<input type="submit" class="button" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  1230. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  1231. print '</td>';
  1232. if (empty($disablemove)) print '<td class="right"></td>';
  1233. }
  1234. print "</tr>\n";
  1235. $i++;
  1236. }
  1237. }
  1238. if ($nboffiles == 0)
  1239. {
  1240. $colspan = '6';
  1241. if (empty($disablemove)) $colspan++; // 6 columns or 7
  1242. print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">';
  1243. if (empty($textifempty)) print $langs->trans("NoFileFound");
  1244. else print $textifempty;
  1245. print '</td></tr>';
  1246. }
  1247. print "</table>";
  1248. print '</div>';
  1249. if ($nboflines > 1 && is_object($object)) {
  1250. if (!empty($conf->use_javascript_ajax) && $permtoeditline) {
  1251. $table_element_line = 'ecm_files';
  1252. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  1253. }
  1254. }
  1255. print ajax_autoselect('downloadlink');
  1256. if (GETPOST('action', 'aZ09') == 'editfile' && $permtoeditline)
  1257. {
  1258. print '</form>';
  1259. }
  1260. return $nboffiles;
  1261. }
  1262. }
  1263. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1264. /**
  1265. * Show list of documents in a directory
  1266. *
  1267. * @param string $upload_dir Directory that was scanned
  1268. * @param array $filearray Array of files loaded by dol_dir_list function before calling this function
  1269. * @param string $modulepart Value for modulepart used by download wrapper
  1270. * @param string $param Parameters on sort links
  1271. * @param int $forcedownload Force to open dialog box "Save As" when clicking on file
  1272. * @param string $relativepath Relative path of docs (autodefined if not provided)
  1273. * @param int $permissiontodelete Permission to delete
  1274. * @param int $useinecm Change output for use in ecm module
  1275. * @param int $textifempty Text to show if filearray is empty
  1276. * @param int $maxlength Maximum length of file name shown
  1277. * @param string $url Full url to use for click links ('' = autodetect)
  1278. * @param int $addfilterfields Add line with filters
  1279. * @return int <0 if KO, nb of files shown if OK
  1280. * @see list_of_documents()
  1281. */
  1282. public function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload = 0, $relativepath = '', $permissiontodelete = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $url = '', $addfilterfields = 0)
  1283. {
  1284. // phpcs:enable
  1285. global $user, $conf, $langs, $form;
  1286. global $sortfield, $sortorder;
  1287. global $search_doc_ref;
  1288. dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart);
  1289. // Show list of documents
  1290. if (empty($useinecm) || $useinecm == 6) print load_fiche_titre($langs->trans("AttachedFiles"));
  1291. if (empty($url)) $url = $_SERVER["PHP_SELF"];
  1292. if (!empty($addfilterfields))
  1293. {
  1294. print '<form action="'.$_SERVER['PHP_SELF'].'">';
  1295. print '<input type="hidden" name="token" value="'.newToken().'">';
  1296. print '<input type="hidden" name="module" value="'.$modulepart.'">';
  1297. }
  1298. print '<div class="div-table-responsive-no-min">';
  1299. print '<table width="100%" class="noborder">'."\n";
  1300. if (!empty($addfilterfields))
  1301. {
  1302. print '<tr class="liste_titre nodrag nodrop">';
  1303. print '<td class="liste_titre"></td>';
  1304. print '<td class="liste_titre"><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"></td>';
  1305. print '<td class="liste_titre"></td>';
  1306. print '<td class="liste_titre"></td>';
  1307. // Action column
  1308. print '<td class="liste_titre center">';
  1309. $searchpicto = $form->showFilterButtons();
  1310. print $searchpicto;
  1311. print '</td>';
  1312. print "</tr>\n";
  1313. }
  1314. print '<tr class="liste_titre">';
  1315. $sortref = "fullname";
  1316. if ($modulepart == 'invoice_supplier') $sortref = 'level1name';
  1317. print_liste_field_titre("Ref", $url, $sortref, "", $param, '', $sortfield, $sortorder);
  1318. print_liste_field_titre("Documents2", $url, "name", "", $param, '', $sortfield, $sortorder);
  1319. print_liste_field_titre("Size", $url, "size", "", $param, '', $sortfield, $sortorder, 'right ');
  1320. print_liste_field_titre("Date", $url, "date", "", $param, '', $sortfield, $sortorder, 'center ');
  1321. print_liste_field_titre('', '', '');
  1322. print '</tr>'."\n";
  1323. // To show ref or specific information according to view to show (defined by $module)
  1324. if ($modulepart == 'company')
  1325. {
  1326. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  1327. $object_instance = new Societe($this->db);
  1328. } elseif ($modulepart == 'invoice')
  1329. {
  1330. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  1331. $object_instance = new Facture($this->db);
  1332. } elseif ($modulepart == 'invoice_supplier')
  1333. {
  1334. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  1335. $object_instance = new FactureFournisseur($this->db);
  1336. } elseif ($modulepart == 'propal')
  1337. {
  1338. include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  1339. $object_instance = new Propal($this->db);
  1340. } elseif ($modulepart == 'supplier_proposal')
  1341. {
  1342. include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  1343. $object_instance = new SupplierProposal($this->db);
  1344. } elseif ($modulepart == 'order')
  1345. {
  1346. include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  1347. $object_instance = new Commande($this->db);
  1348. } elseif ($modulepart == 'order_supplier')
  1349. {
  1350. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  1351. $object_instance = new CommandeFournisseur($this->db);
  1352. } elseif ($modulepart == 'contract')
  1353. {
  1354. include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  1355. $object_instance = new Contrat($this->db);
  1356. } elseif ($modulepart == 'product')
  1357. {
  1358. include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  1359. $object_instance = new Product($this->db);
  1360. } elseif ($modulepart == 'tax')
  1361. {
  1362. include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  1363. $object_instance = new ChargeSociales($this->db);
  1364. } elseif ($modulepart == 'project')
  1365. {
  1366. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  1367. $object_instance = new Project($this->db);
  1368. } elseif ($modulepart == 'fichinter')
  1369. {
  1370. include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  1371. $object_instance = new Fichinter($this->db);
  1372. } elseif ($modulepart == 'user')
  1373. {
  1374. include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  1375. $object_instance = new User($this->db);
  1376. } elseif ($modulepart == 'expensereport')
  1377. {
  1378. include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  1379. $object_instance = new ExpenseReport($this->db);
  1380. } elseif ($modulepart == 'holiday')
  1381. {
  1382. include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  1383. $object_instance = new Holiday($this->db);
  1384. } elseif ($modulepart == 'recruitment-recruitmentcandidature')
  1385. {
  1386. include_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentcandidature.class.php';
  1387. $object_instance = new RecruitmentCandidature($this->db);
  1388. } elseif ($modulepart == 'banque')
  1389. {
  1390. include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  1391. $object_instance = new Account($this->db);
  1392. } elseif ($modulepart == 'mrp-mo')
  1393. {
  1394. include_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
  1395. $object_instance = new Mo($this->db);
  1396. }
  1397. foreach ($filearray as $key => $file)
  1398. {
  1399. if (!is_dir($file['name'])
  1400. && $file['name'] != '.'
  1401. && $file['name'] != '..'
  1402. && $file['name'] != 'CVS'
  1403. && !preg_match('/\.meta$/i', $file['name']))
  1404. {
  1405. // Define relative path used to store the file
  1406. $relativefile = preg_replace('/'.preg_quote($upload_dir.'/', '/').'/', '', $file['fullname']);
  1407. $id = 0; $ref = ''; $label = '';
  1408. // To show ref or specific information according to view to show (defined by $module)
  1409. $reg = array();
  1410. if ($modulepart == 'company' || $modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/', $relativefile, $reg); $id = (isset($reg[1]) ? $reg[1] : ''); }
  1411. elseif ($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. elseif ($modulepart == 'user' || $modulepart == 'holiday') { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $id = (isset($reg[1]) ? $reg[1] : ''); }
  1413. elseif (in_array($modulepart, array(
  1414. 'invoice',
  1415. 'propal',
  1416. 'supplier_proposal',
  1417. 'order',
  1418. 'order_supplier',
  1419. 'contract',
  1420. 'product',
  1421. 'project',
  1422. 'fichinter',
  1423. 'expensereport',
  1424. 'recruitment-recruitmentcandidature',
  1425. 'mrp-mo',
  1426. 'banque'))) {
  1427. preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = (isset($reg[1]) ? $reg[1] : '');
  1428. } else {
  1429. //print 'Error: Value for modulepart = '.$modulepart.' is not yet implemented in function list_of_autoecmfiles'."\n";
  1430. }
  1431. if (!$id && !$ref) continue;
  1432. $found = 0;
  1433. if (!empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref]))
  1434. {
  1435. $found = 1;
  1436. } else {
  1437. //print 'Fetch '.$id." - ".$ref.'<br>';
  1438. if ($id) {
  1439. $result = $object_instance->fetch($id);
  1440. } else {
  1441. //fetchOneLike looks for objects with wildcards in its reference.
  1442. //It is useful for those masks who get underscores instead of their actual symbols
  1443. //fetchOneLike requires some info in the object. If it doesn't have it, then 0 is returned
  1444. //that's why we look only into fetchOneLike when fetch returns 0
  1445. if (!$result = $object_instance->fetch('', $ref)) {
  1446. $result = $object_instance->fetchOneLike($ref);
  1447. }
  1448. }
  1449. if ($result > 0) { // Save object loaded into a cache
  1450. $found = 1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref] = clone $object_instance;
  1451. }
  1452. if ($result == 0) { $found = 1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref] = 'notfound'; unset($filearray[$key]); }
  1453. }
  1454. if (!$found > 0 || !is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue; // We do not show orphelins files
  1455. print '<!-- Line list_of_autoecmfiles '.$key.' -->'."\n";
  1456. print '<tr class="oddeven">';
  1457. print '<td>';
  1458. if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1, 'document');
  1459. else print $langs->trans("ObjectDeleted", ($id ? $id : $ref));
  1460. //$modulesubdir=dol_sanitizeFileName($ref);
  1461. $modulesubdir = dirname($relativefile);
  1462. //$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  1463. $filedir = $file['path'];
  1464. //$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  1465. //print $formfile->getDocumentsLink($modulepart, $filename, $filedir);
  1466. print '</td>';
  1467. // File
  1468. print '<td>';
  1469. //print "XX".$file['name']; //$file['name'] must be utf8
  1470. print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
  1471. if ($forcedownload) print '&attachment=1';
  1472. print '&file='.urlencode($relativefile).'">';
  1473. print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'], 0, 0).')');
  1474. print dol_trunc($file['name'], $maxlength, 'middle');
  1475. print '</a>';
  1476. //print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$');
  1477. print $this->showPreview($file, $modulepart, $file['relativename']);
  1478. print "</td>\n";
  1479. print '<td class="right">'.dol_print_size($file['size'], 1, 1).'</td>';
  1480. print '<td class="center">'.dol_print_date($file['date'], "dayhour").'</td>';
  1481. print '<td class="right">';
  1482. //if (! empty($useinecm) && $useinecm != 6) print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
  1483. //if ($forcedownload) print '&attachment=1';
  1484. //print '&file='.urlencode($relativefile).'">';
  1485. //print img_view().'</a> &nbsp; ';
  1486. //if ($permissiontodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
  1487. //else print '&nbsp;';
  1488. print "</td></tr>\n";
  1489. }
  1490. }
  1491. if (count($filearray) == 0)
  1492. {
  1493. print '<tr class="oddeven"><td colspan="5">';
  1494. if (empty($textifempty)) print '<span class="opacitymedium">'.$langs->trans("NoFileFound").'</span>';
  1495. else print '<span class="opacitymedium">'.$textifempty.'</span>';
  1496. print '</td></tr>';
  1497. }
  1498. print "</table>";
  1499. print '</div>';
  1500. if (!empty($addfilterfields)) print '</form>';
  1501. // Fin de zone
  1502. }
  1503. /**
  1504. * Show form to upload a new file with jquery fileupload.
  1505. * This form use the fileupload.php file.
  1506. *
  1507. * @param Object $object Object to use
  1508. * @return void
  1509. */
  1510. private function _formAjaxFileUpload($object)
  1511. {
  1512. global $langs, $conf;
  1513. // PHP post_max_size
  1514. $post_max_size = ini_get('post_max_size');
  1515. $mul_post_max_size = substr($post_max_size, -1);
  1516. $mul_post_max_size = ($mul_post_max_size == 'M' ? 1048576 : ($mul_post_max_size == 'K' ? 1024 : ($mul_post_max_size == 'G' ? 1073741824 : 1)));
  1517. $post_max_size = $mul_post_max_size * (int) $post_max_size;
  1518. // PHP upload_max_filesize
  1519. $upload_max_filesize = ini_get('upload_max_filesize');
  1520. $mul_upload_max_filesize = substr($upload_max_filesize, -1);
  1521. $mul_upload_max_filesize = ($mul_upload_max_filesize == 'M' ? 1048576 : ($mul_upload_max_filesize == 'K' ? 1024 : ($mul_upload_max_filesize == 'G' ? 1073741824 : 1)));
  1522. $upload_max_filesize = $mul_upload_max_filesize * (int) $upload_max_filesize;
  1523. // Max file size
  1524. $max_file_size = (($post_max_size < $upload_max_filesize) ? $post_max_size : $upload_max_filesize);
  1525. // Include main
  1526. include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_main.tpl.php';
  1527. // Include template
  1528. include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php';
  1529. }
  1530. /**
  1531. * Show array with linked files
  1532. *
  1533. * @param Object $object Object
  1534. * @param int $permissiontodelete Deletion is allowed
  1535. * @param string $action Action
  1536. * @param string $selected ???
  1537. * @param string $param More param to add into URL
  1538. * @return int Number of links
  1539. */
  1540. public function listOfLinks($object, $permissiontodelete = 1, $action = null, $selected = null, $param = '')
  1541. {
  1542. global $user, $conf, $langs, $user;
  1543. global $sortfield, $sortorder;
  1544. $langs->load("link");
  1545. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  1546. $link = new Link($this->db);
  1547. $links = array();
  1548. if ($sortfield == "name") {
  1549. $sortfield = "label";
  1550. } elseif ($sortfield == "date") {
  1551. $sortfield = "datea";
  1552. } else {
  1553. $sortfield = null;
  1554. }
  1555. $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder);
  1556. $param .= (isset($object->id) ? '&id='.$object->id : '');
  1557. print '<!-- listOfLinks -->'."\n";
  1558. // Show list of associated links
  1559. print load_fiche_titre($langs->trans("LinkedFiles"), '', 'external-link-square-alt', 0, '', 'table-list-of-links');
  1560. print '<form action="'.$_SERVER['PHP_SELF'].($param ? '?'.$param : '').'" method="POST">';
  1561. print '<input type="hidden" name="token" value="'.newToken().'">';
  1562. print '<table width="100%" class="liste noborder nobottom">';
  1563. print '<tr class="liste_titre">';
  1564. print_liste_field_titre(
  1565. $langs->trans("Links"),
  1566. $_SERVER['PHP_SELF'],
  1567. "name",
  1568. "",
  1569. $param,
  1570. '',
  1571. $sortfield,
  1572. $sortorder,
  1573. ''
  1574. );
  1575. print_liste_field_titre(
  1576. "",
  1577. "",
  1578. "",
  1579. "",
  1580. "",
  1581. '',
  1582. '',
  1583. '',
  1584. 'right '
  1585. );
  1586. print_liste_field_titre(
  1587. $langs->trans("Date"),
  1588. $_SERVER['PHP_SELF'],
  1589. "date",
  1590. "",
  1591. $param,
  1592. '',
  1593. $sortfield,
  1594. $sortorder,
  1595. 'center '
  1596. );
  1597. print_liste_field_titre(
  1598. '',
  1599. $_SERVER['PHP_SELF'],
  1600. "",
  1601. "",
  1602. $param,
  1603. '',
  1604. '',
  1605. '',
  1606. 'center '
  1607. );
  1608. print_liste_field_titre('', '', '');
  1609. print '</tr>';
  1610. $nboflinks = count($links);
  1611. if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  1612. foreach ($links as $link)
  1613. {
  1614. print '<tr class="oddeven">';
  1615. //edit mode
  1616. if ($action == 'update' && $selected === $link->id)
  1617. {
  1618. print '<td>';
  1619. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1620. print '<input type="hidden" name="linkid" value="'.$link->id.'">';
  1621. print '<input type="hidden" name="action" value="confirm_updateline">';
  1622. print $langs->trans('Link').': <input type="text" name="link" value="'.$link->url.'">';
  1623. print '</td>';
  1624. print '<td>';
  1625. print $langs->trans('Label').': <input type="text" name="label" value="'.dol_escape_htmltag($link->label).'">';
  1626. print '</td>';
  1627. print '<td class="center">'.dol_print_date(dol_now(), "dayhour", "tzuser").'</td>';
  1628. print '<td class="right"></td>';
  1629. print '<td class="right">';
  1630. print '<input type="submit" name="save" class="button" value="'.dol_escape_htmltag($langs->trans('Save')).'">';
  1631. print '<input type="submit" name="cancel" class="button" value="'.dol_escape_htmltag($langs->trans('Cancel')).'">';
  1632. print '</td>';
  1633. } else {
  1634. print '<td>';
  1635. print img_picto('', 'globe').' ';
  1636. print '<a data-ajax="false" href="'.$link->url.'" target="_blank">';
  1637. print dol_escape_htmltag($link->label);
  1638. print '</a>';
  1639. print '</td>'."\n";
  1640. print '<td class="right"></td>';
  1641. print '<td class="center">'.dol_print_date($link->datea, "dayhour", "tzuser").'</td>';
  1642. print '<td class="center"></td>';
  1643. print '<td class="right">';
  1644. print '<a href="'.$_SERVER['PHP_SELF'].'?action=update&linkid='.$link->id.$param.'" class="editfilelink editfielda reposition" >'.img_edit().'</a>'; // id= is included into $param
  1645. if ($permissiontodelete) {
  1646. print ' &nbsp; <a class="deletefilelink" href="'.$_SERVER['PHP_SELF'].'?action=delete&linkid='.$link->id.$param.'">'.img_delete().'</a>'; // id= is included into $param
  1647. } else {
  1648. print '&nbsp;';
  1649. }
  1650. print '</td>';
  1651. }
  1652. print "</tr>\n";
  1653. }
  1654. if ($nboflinks == 0)
  1655. {
  1656. print '<tr class="oddeven"><td colspan="5" class="opacitymedium">';
  1657. print $langs->trans("NoLinkFound");
  1658. print '</td></tr>';
  1659. }
  1660. print "</table>";
  1661. print '</form>';
  1662. return $nboflinks;
  1663. }
  1664. /**
  1665. * Show detail icon with link for preview
  1666. *
  1667. * @param array $file Array with data of file. Example: array('name'=>...)
  1668. * @param string $modulepart propal, facture, facture_fourn, ...
  1669. * @param string $relativepath Relative path of docs
  1670. * @param integer $ruleforpicto Rule for picto: 0=Use the generic preview picto, 1=Use the picto of mime type of file)
  1671. * @param string $param More param on http links
  1672. * @return string $out Output string with HTML
  1673. */
  1674. public function showPreview($file, $modulepart, $relativepath, $ruleforpicto = 0, $param = '')
  1675. {
  1676. global $langs, $conf;
  1677. $out = '';
  1678. if ($conf->browser->layout != 'phone' && !empty($conf->use_javascript_ajax))
  1679. {
  1680. $urladvancedpreview = getAdvancedPreviewUrl($modulepart, $relativepath, 1, $param); // Return if a file is qualified for preview.
  1681. if (count($urladvancedpreview))
  1682. {
  1683. $out .= '<a class="pictopreview '.$urladvancedpreview['css'].'" href="'.$urladvancedpreview['url'].'"'.(empty($urladvancedpreview['mime']) ? '' : ' mime="'.$urladvancedpreview['mime'].'"').' '.(empty($urladvancedpreview['target']) ? '' : ' target="'.$urladvancedpreview['target'].'"').'>';
  1684. //$out.= '<a class="pictopreview">';
  1685. if (empty($ruleforpicto))
  1686. {
  1687. //$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail');
  1688. $out .= '<span class="fa fa-search-plus" style="color: gray"></span>';
  1689. } else $out .= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']);
  1690. $out .= '</a>';
  1691. }
  1692. }
  1693. return $out;
  1694. }
  1695. }