31if (!defined(
'NOTOKENRENEWAL')) {
32 define(
'NOTOKENRENEWAL', 1);
34if (!defined(
'NOREQUIREMENU')) {
35 define(
'NOREQUIREMENU',
'1');
37if (!defined(
'NOREQUIREHTML')) {
38 define(
'NOREQUIREHTML',
'1');
40if (!defined(
'NOREQUIREAJAX')) {
41 define(
'NOREQUIREAJAX',
'1');
44if (!isset($mode) || $mode !=
'noajax') {
45 require_once
'../../main.inc.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
50 $action =
GETPOST(
'action',
'aZ09');
51 $file = urldecode(
GETPOST(
'file',
'alpha'));
52 $section =
GETPOST(
"section",
'alpha');
53 $module =
GETPOST(
"module",
'alpha');
54 $urlsource =
GETPOST(
"urlsource",
'alpha');
55 $search_doc_ref =
GETPOST(
'search_doc_ref',
'alpha');
58 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
59 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
61 if (empty($page) || $page == -1) {
64 $offset = $limit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
74 $rootdirfordoc = $conf->ecm->dir_output;
76 $upload_dir = dirname(str_replace(
"../",
"/", $rootdirfordoc.
'/'.$file));
80 $result = $ecmdir->fetch($section);
89 @phan-var-force int $section
90 @phan-var-force string $module
91 @phan-var-force string $showonrightsize
93 $rootdirfordoc = $conf->ecm->dir_output;
98 $result = $ecmdir->fetch($section);
104 $relativepath = $ecmdir->getRelativePath();
105 } elseif (
GETPOST(
'section_dir')) {
106 $relativepath =
GETPOST(
'section_dir');
110 $upload_dir = $rootdirfordoc.
'/'.$relativepath;
114 if (!empty($module) && $module ==
'medias' && !
GETPOST(
'website')) {
115 $url = DOL_URL_ROOT.
'/ecm/index_medias.php';
116 } elseif (GETPOSTISSET(
'website')) {
117 $url = DOL_URL_ROOT.
'/website/index.php';
119 $url = DOL_URL_ROOT.
'/ecm/index.php';
124$langs->loadLangs(array(
"ecm",
"companies",
"other"));
126if (empty($modulepart)) {
127 $modulepart = $module;
131if ($user->socid > 0) {
132 $socid = $user->socid;
135if (preg_match(
'/\.\./', $upload_dir) || preg_match(
'/[<>|]/', $upload_dir)) {
136 dol_syslog(
"Refused to deliver file ".$upload_dir);
138 dol_print_error(
null, $langs->trans(
"ErrorFileNameInvalid", $upload_dir));
142if ($modulepart ==
'ecm') {
143 if (!$user->hasRight(
'ecm',
'read')) {
146} elseif ($modulepart ==
'medias' || $modulepart ==
'website') {
165if (!isset($mode) || $mode !=
'noajax') {
167 header(
'Cache-Control: Public, must-revalidate');
168 header(
'Pragma: public');
183print
'<!-- ajaxdirpreview type='.$type.
' module='.$module.
' modulepart='.$modulepart.
'-->'.
"\n";
186$param = ($sortfield ?
'&sortfield='.urlencode($sortfield) :
'').($sortorder ?
'&sortorder='.urlencode($sortorder) :
'');
187if (!empty($websitekey)) {
188 $param .=
'&website='.urlencode($websitekey);
190if (!empty($pageid)) {
191 $param .=
'&pageid='.((int) $pageid);
196if ($type ==
'directory') {
200 $excludefiles = array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$');
201 $sorting = (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC);
204 $automodules = array(
223 'recruitment-recruitmentcandidature',
229 $parameters = array(
'modulepart' => $module);
230 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
231 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
232 $automodules[] = $hookmanager->resArray[
'module'];
236 if ($module ==
'company') {
237 $upload_dir = $conf->societe->dir_output;
238 $excludefiles[] =
'^contact$';
239 } elseif ($module ==
'invoice') {
240 $upload_dir = $conf->facture->dir_output;
241 } elseif ($module ==
'invoice_supplier') {
242 $upload_dir = $conf->fournisseur->facture->dir_output;
243 } elseif ($module ==
'propal') {
244 $upload_dir = $conf->propal->dir_output;
245 } elseif ($module ==
'supplier_proposal') {
246 $upload_dir = $conf->supplier_proposal->dir_output;
247 } elseif ($module ==
'order') {
248 $upload_dir = $conf->commande->dir_output;
249 } elseif ($module ==
'order_supplier') {
250 $upload_dir = $conf->fournisseur->commande->dir_output;
251 } elseif ($module ==
'contract') {
252 $upload_dir = $conf->contrat->dir_output;
253 } elseif ($module ==
'product') {
254 $upload_dir = $conf->product->dir_output;
255 } elseif ($module ==
'tax') {
256 $upload_dir = $conf->tax->dir_output;
257 $excludefiles[] =
'^vat$';
258 } elseif ($module ==
'tax-vat') {
259 $upload_dir = $conf->tax->dir_output.
'/vat';
260 } elseif ($module ==
'salaries') {
261 $upload_dir = $conf->salaries->dir_output;
262 } elseif ($module ==
'project') {
263 $upload_dir = $conf->project->dir_output;
264 } elseif ($module ==
'project_task') {
265 $upload_dir = $conf->project->dir_output;
266 } elseif ($module ==
'fichinter') {
267 $upload_dir = $conf->ficheinter->dir_output;
268 } elseif ($module ==
'user') {
269 $upload_dir = $conf->user->dir_output;
270 } elseif ($module ==
'expensereport') {
271 $upload_dir = $conf->expensereport->dir_output;
272 } elseif ($module ==
'holiday') {
273 $upload_dir = $conf->holiday->dir_output;
274 } elseif ($module ==
'recruitment-recruitmentcandidature') {
275 $upload_dir = $conf->recruitment->dir_output.
'/recruitmentcandidature';
276 } elseif ($module ==
'banque') {
277 $upload_dir = $conf->bank->dir_output;
278 } elseif ($module ==
'chequereceipt') {
279 $upload_dir = $conf->bank->dir_output.
'/checkdeposits';
280 } elseif ($module ==
'mrp-mo') {
281 $upload_dir = $conf->mrp->dir_output;
283 $parameters = array(
'modulepart' => $module);
284 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
285 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
286 $upload_dir = $hookmanager->resArray[
'directory'];
291 if (in_array($module, $automodules)) {
292 $param .=
'&module='.$module;
293 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
294 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
297 $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
299 $filter = preg_quote((
string) $search_doc_ref,
'/');
300 $filearray =
dol_dir_list($upload_dir,
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
304 if ($user->socid > 0) {
305 $filearrayallowedtoexternal = array();
311 foreach ($filearray as $key => $val) {
312 if (!in_array($upload_dir.
'/'.$val[
'relativename'], $filearrayallowedtoexternal)) {
313 unset($filearray[$key]);
318 $perm = $user->hasRight(
'ecm',
'upload');
320 $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1,
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
323 if ($module ==
'medias') {
335 $relativepath =
GETPOST(
'file',
'alpha') ?
GETPOST(
'file',
'alpha') :
GETPOST(
'section_dir',
'alpha');
336 if ($relativepath && $relativepath !=
'/') {
337 $relativepath .=
'/';
339 $upload_dir = $dolibarr_main_data_root.
'/'.$module.
'/'.$relativepath;
340 if (GETPOSTISSET(
'website') || GETPOSTISSET(
'file_manager')) {
341 $param .=
'&file_manager=1';
342 if (!preg_match(
'/website=/', $param) &&
GETPOST(
'website',
'alpha')) {
343 $param .=
'&website='.urlencode(
GETPOST(
'website',
'alpha'));
345 if (!preg_match(
'/pageid=/', $param)) {
346 $param .=
'&pageid='.GETPOSTINT(
'pageid');
351 $relativepath = $ecmdir->getRelativePath();
352 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
356 if (($section ===
'0' || empty($section)) && ($module !=
'medias')) {
357 $filearray = array();
359 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'', array(
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^CVS$'), $sortfield, $sorting, 1);
363 $param .=
'§ion='.$section;
364 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
365 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
368 $textifempty = $langs->trans(
'NoFileFound');
369 } elseif ($section ===
'0') {
370 if ($module ==
'ecm') {
371 $textifempty =
'<br><div class="center"><span class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</span></div><br>';
373 $textifempty = $langs->trans(
'NoFileFound');
376 $textifempty = ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
380 if ($module ==
'medias') {
382 $modulepart =
'medias';
383 $perm = ($user->hasRight(
"website",
"write") || $user->hasRight(
"emailing",
"creer"));
385 } elseif ($module ==
'ecm') {
386 if ($user->hasRight(
"ecm",
"read")) {
391 if ($user->hasRight(
"ecm",
"upload")) {
396 if ($user->hasRight(
"ecm",
"setup")) {
401 $perm = $user->hasRight(
"ecm",
"upload");
407 $perm = $user->hasRight(
"ecm",
"upload");
414 $formfile->list_of_documents($filearray,
null, $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm,
'', $sortfield, $sortorder);
422if (!empty($conf->dol_use_jmobile)) {
425if (empty($conf->use_javascript_ajax)) {
434if ($useajax || $action ==
'deletefile') {
436 if ($action ==
'deletefile') {
437 $urlfile =
GETPOST(
'urlfile',
'alpha');
440 if (empty($section_dir)) {
441 $section_dir =
GETPOST(
"file",
"alpha");
443 $section_id = $section;
445 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
447 $form =
new Form($db);
448 $formquestion = array();
449 $formquestion[
'urlfile'] = array(
'type' =>
'hidden',
'value' => $urlfile,
'name' =>
'urlfile');
450 $formquestion[
'section'] = array(
'type' =>
'hidden',
'value' => $section,
'name' =>
'section');
451 $formquestion[
'section_id'] = array(
'type' =>
'hidden',
'value' => $section_id,
'name' =>
'section_id');
452 $formquestion[
'section_dir'] = array(
'type' =>
'hidden',
'value' => $section_dir,
'name' =>
'section_dir');
453 $formquestion[
'sortfield'] = array(
'type' =>
'hidden',
'value' => $sortfield,
'name' =>
'sortfield');
454 $formquestion[
'sortorder'] = array(
'type' =>
'hidden',
'value' => $sortorder,
'name' =>
'sortorder');
455 if (!empty($action) && $action ==
'file_manager') {
456 $formquestion[
'file_manager'] = array(
'type' =>
'hidden',
'value' => 1,
'name' =>
'file_manager');
458 if (!empty($websitekey)) {
459 $formquestion[
'website'] = array(
'type' =>
'hidden',
'value' => $websitekey,
'name' =>
'website');
461 if (!empty($pageid) && $pageid > 0) {
462 $formquestion[
'pageid'] = array(
'type' =>
'hidden',
'value' => $pageid,
'name' =>
'pageid');
465 print $form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"),
'confirm_deletefile', $formquestion,
"no", ($useajax ?
'deletefile' : 0));
469 print
'<!-- ajaxdirpreview.php: js to manage preview of doc -->'.
"\n";
470 print
'<script nonce="'.getNonce().
'" type="text/javascript">';
475 if ($conf->browser->layout !=
'phone') {
476 print
"\n/* JS CODE TO ENABLE document_preview */\n";
478 jQuery(document).ready(function () {
479 jQuery(".documentpreview").click(function () {
480 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
481 document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\');
488 // Enable jquery handlers button to delete files
489 print 'jQuery(document).ready(
function() {
'."\n";
490 print ' jQuery(
".deletefilelink").click(
function(e) {
'."\n";
491 print ' console.log(
"We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(
this).attr(
"rel"));
'."\n";
492 print ' jQuery(
"#urlfile").val(jQuery(
this).attr(
"rel"));
'."\n";
493 //print ' jQuery(
"#section_dir").val(\
'aaa\');'.
"\n";
494 print
' jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
495 print
' return false;'.
"\n";
498 print
'</script>'.
"\n";
502if ((!isset($mode) || $mode !=
'noajax') && is_object($db)) {
Class to manage ECM directories.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.