33if (!defined(
'NOTOKENRENEWAL')) {
34 define(
'NOTOKENRENEWAL', 1);
36if (!defined(
'NOREQUIREMENU')) {
37 define(
'NOREQUIREMENU',
'1');
39if (!defined(
'NOREQUIREHTML')) {
40 define(
'NOREQUIREHTML',
'1');
42if (!defined(
'NOREQUIREAJAX')) {
43 define(
'NOREQUIREAJAX',
'1');
61@phan-var-force ?string $mode
64if (!isset($mode) || $mode !=
'noajax') {
65 require_once
'../../main.inc.php';
66 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
67 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
68 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
70 $action =
GETPOST(
'action',
'aZ09');
71 $file = urldecode(
GETPOST(
'file',
'alpha'));
72 $section =
GETPOST(
"section",
'alpha');
74 $urlsource =
GETPOST(
"urlsource",
'alpha');
75 $search_doc_ref =
GETPOST(
'search_doc_ref',
'alpha');
76 $search_doc_date_start =
'';
77 $search_doc_date_end =
'';
79 $search_doc_date_start =
GETPOSTDATE(
'search_doc_date_start');
82 $search_doc_date_end =
GETPOSTDATE(
'search_doc_date_end',
'end');
86 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
87 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
89 $showonrightsize =
'';
91 if (empty($page) || $page == -1) {
94 $offset = $limit * $page;
95 $pageprev = $page - 1;
96 $pagenext = $page + 1;
104 $rootdirfordoc =
$conf->ecm->dir_output;
106 $upload_dir = dirname(str_replace(
"../",
"/", $rootdirfordoc.
'/'.$file));
110 $result = $ecmdir->fetch((
int) $section);
128 @phan-var-force int $section
129 @phan-var-force string $action
130 @phan-var-force string $module
131 @phan-var-force string $showonrightsize
132 @phan-var-force string $sortfield
133 @phan-var-force string $sortorder
136 $rootdirfordoc =
$conf->ecm->dir_output;
141 $result = $ecmdir->fetch($section);
142 if (!($result > 0)) {
143 dol_print_error($db, $ecmdir->error);
147 $relativepath = $ecmdir->getRelativePath();
148 } elseif (
GETPOST(
'section_dir')) {
149 $relativepath =
GETPOST(
'section_dir');
153 $upload_dir = $rootdirfordoc.
'/'.$relativepath;
158 $url = DOL_URL_ROOT.
'/ecm/index_medias.php';
160 $url = DOL_URL_ROOT.
'/website/index.php';
162 $url = DOL_URL_ROOT.
'/ecm/index.php';
167$langs->loadLangs(array(
"ecm",
"companies",
"other"));
169if (empty($modulepart)) {
174if ($user->socid > 0) {
175 $socid = $user->socid;
178if (preg_match(
'/\.\./', $upload_dir) || preg_match(
'/[<>|]/', $upload_dir)) {
179 dol_syslog(
"Refused to deliver file ".$upload_dir);
181 dol_print_error(
null, $langs->trans(
"ErrorFileNameInvalid", $upload_dir));
185if ($modulepart ==
'ecm') {
186 if (!$user->hasRight(
'ecm',
'read')) {
189} elseif ($modulepart ==
'medias' || $modulepart ==
'website') {
208if (!isset($mode) || $mode !=
'noajax') {
210 header(
'Cache-Control: Public, must-revalidate');
211 header(
'Pragma: public');
226print
'<!-- ajaxdirpreview mode='.$mode.
' type='.$type.
' module='.
$module.
' modulepart='.$modulepart.
'-->'.
"\n";
229$param = ($sortfield ?
'&sortfield='.urlencode($sortfield) :
'').($sortorder ?
'&sortorder='.urlencode($sortorder) :
'');
230if (!empty($websitekey)) {
231 $param .=
'&website='.urlencode($websitekey);
233if (!empty($pageid)) {
234 $param .=
'&pageid='.((int) $pageid);
238 $param .=
'&dol_hide_topmenu='.GETPOSTINT(
'dol_hide_topmenu');
241 $param .=
'&dol_hide_leftmenu='.GETPOSTINT(
'dol_hide_leftmenu');
243if (
GETPOST(
'dol_openinpopup',
'aZ09')) {
244 $param .=
'&dol_openinpopup='.urlencode(
GETPOST(
'dol_openinpopup',
'aZ09'));
249if ($type ==
'directory') {
253 $excludefiles = array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$');
254 $sorting = (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC);
257 $automodules = array(
276 'recruitment-recruitmentcandidature',
283 $parameters = array(
'modulepart' =>
$module);
284 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
285 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
286 if (is_array($hookmanager->resArray[
'module'])) {
287 $automodules = array_merge($automodules, $hookmanager->resArray[
'module']);
289 $automodules[] = $hookmanager->resArray[
'module'];
295 $upload_dir =
$conf->societe->dir_output;
296 $excludefiles[] =
'^contact$';
297 } elseif (
$module ==
'invoice') {
298 $upload_dir =
$conf->invoice->dir_output;
299 } elseif (
$module ==
'invoice_supplier') {
300 $upload_dir = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
301 } elseif (
$module ==
'propal') {
302 $upload_dir =
$conf->propal->dir_output;
303 } elseif (
$module ==
'supplier_proposal') {
304 $upload_dir =
$conf->supplier_proposal->dir_output;
305 } elseif (
$module ==
'order') {
306 $upload_dir =
$conf->order->dir_output;
307 } elseif (
$module ==
'order_supplier') {
308 $upload_dir =
$conf->fournisseur->commande->dir_output;
309 } elseif (
$module ==
'contract') {
310 $upload_dir =
$conf->contract->dir_output;
311 } elseif (
$module ==
'product') {
312 $upload_dir =
$conf->product->dir_output;
314 $upload_dir =
$conf->tax->dir_output;
315 $excludefiles[] =
'^vat$';
316 } elseif (
$module ==
'tax-vat') {
317 $upload_dir =
$conf->tax->dir_output.
'/vat';
318 } elseif (
$module ==
'salaries') {
319 $upload_dir =
$conf->salaries->dir_output;
320 } elseif (
$module ==
'project') {
321 $upload_dir =
$conf->project->dir_output;
322 } elseif (
$module ==
'project_task') {
323 $upload_dir =
$conf->project->dir_output;
324 } elseif (
$module ==
'fichinter') {
325 $upload_dir =
$conf->ficheinter->dir_output;
327 $upload_dir =
$conf->user->dir_output;
328 } elseif (
$module ==
'expensereport') {
329 $upload_dir =
$conf->expensereport->dir_output;
330 } elseif (
$module ==
'holiday') {
331 $upload_dir =
$conf->holiday->dir_output;
332 } elseif (
$module ==
'recruitment-recruitmentcandidature') {
333 $upload_dir =
$conf->recruitment->dir_output.
'/recruitmentcandidature';
334 } elseif (
$module ==
'banque') {
335 $upload_dir =
$conf->bank->dir_output;
336 } elseif (
$module ==
'bank-statement') {
337 $upload_dir =
$conf->bank->dir_output.
'/*/statement';
338 } elseif (
$module ==
'chequereceipt') {
339 $upload_dir =
$conf->bank->dir_output.
'/checkdeposits';
340 } elseif (
$module ==
'mrp-mo') {
341 $upload_dir =
$conf->mrp->dir_output;
343 $parameters = array(
'modulepart' =>
$module);
344 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
345 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
346 $upload_dir = $hookmanager->resArray[
'directory'];
351 if (in_array(
$module, $automodules)) {
352 $param .=
'&module='.urlencode(
$module);
353 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
354 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
356 if (!empty($search_doc_date_start)) {
357 $param .=
'&search_doc_date_startday='.dol_print_date($search_doc_date_start,
'%d');
358 $param .=
'&search_doc_date_startmonth='.dol_print_date($search_doc_date_start,
'%m');
359 $param .=
'&search_doc_date_startyear='.dol_print_date($search_doc_date_start,
'%Y');
361 if (!empty($search_doc_date_end)) {
362 $param .=
'&search_doc_date_endday='.dol_print_date($search_doc_date_end,
'%d');
363 $param .=
'&search_doc_date_endmonth='.dol_print_date($search_doc_date_end,
'%m');
364 $param .=
'&search_doc_date_endyear='.dol_print_date($search_doc_date_end,
'%Y');
367 $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
369 $filter = preg_quote((
string) $search_doc_ref,
'/');
370 $filearray =
dol_dir_list($upload_dir,
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
371 if (!empty($search_doc_date_start) || !empty($search_doc_date_end)) {
372 foreach ($filearray as $key => $file) {
373 $filedate = empty($file[
'date']) ? 0 : (int) $file[
'date'];
374 if ((!empty($search_doc_date_start) && $filedate < $search_doc_date_start)
375 || (!empty($search_doc_date_end) && $filedate > $search_doc_date_end)
377 unset($filearray[$key]);
385 if ($user->socid > 0) {
386 $filearrayallowedtoexternal = array();
392 foreach ($filearray as $key => $val) {
393 if (!in_array($upload_dir.
'/'.$val[
'relativename'], $filearrayallowedtoexternal)) {
394 unset($filearray[$key]);
399 $perm = $user->hasRight(
'ecm',
'upload');
402 $formfile->list_of_autoecmfiles($upload_dir, $filearray,
$module, $param, 1,
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
417 $relativepath =
GETPOST(
'file',
'alpha') ?
GETPOST(
'file',
'alpha') :
GETPOST(
'section_dir',
'alpha');
418 if ($relativepath && $relativepath !=
'/') {
419 $relativepath .=
'/';
421 $upload_dir = $dolibarr_main_data_root.
'/'.
$module.
'/'.$relativepath;
423 $param .=
'&file_manager=1';
424 if (!preg_match(
'/website=/', $param) &&
GETPOST(
'website',
'alpha')) {
425 $param .=
'&website='.urlencode(
GETPOST(
'website',
'alpha'));
427 if (!preg_match(
'/pageid=/', $param)) {
428 $param .=
'&pageid='.GETPOSTINT(
'pageid');
433 $relativepath = $ecmdir->getRelativePath();
434 $upload_dir =
$conf->ecm->dir_output.
'/'.$relativepath;
438 if (($section ===
'0' || empty($section)) && (
$module !=
'medias')) {
439 $filearray = array();
441 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'', array(
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^CVS$'), $sortfield, $sorting, 1);
445 $param .=
'§ion='.urlencode($section);
446 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
447 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
450 $textifempty = $langs->trans(
'NoFileFound');
451 } elseif ($section ===
'0') {
453 $textifempty =
'<br><div class="center"><span class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</span></div><br>';
455 $textifempty = $langs->trans(
'NoFileFound');
458 $textifempty = ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
464 $modulepart =
'medias';
465 $perm = $user->hasRight(
"website",
"write");
468 if ($user->hasRight(
"ecm",
"read")) {
473 if ($user->hasRight(
"ecm",
"upload")) {
478 if ($user->hasRight(
"ecm",
"setup")) {
483 $perm = $user->hasRight(
"ecm",
"upload");
489 $perm = $user->hasRight(
"ecm",
"upload");
497 $formfile->list_of_documents($filearray,
null, $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm, $upload_dir, $sortfield, $sortorder, 1, 1);
505if (!empty(
$conf->dol_use_jmobile)) {
508if (empty(
$conf->use_javascript_ajax)) {
517if ($useajax || $action ==
'deletefile') {
519 if ($action ==
'deletefile') {
520 $urlfile =
GETPOST(
'urlfile',
'alpha');
523 if (empty($section_dir)) {
524 $section_dir =
GETPOST(
"file",
"alpha");
526 $section_id = $section;
528 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
530 $form =
new Form($db);
531 $formquestion = array();
532 $formquestion[
'urlfile'] = array(
'type' =>
'hidden',
'value' => $urlfile,
'name' =>
'urlfile');
533 $formquestion[
'section'] = array(
'type' =>
'hidden',
'value' => $section,
'name' =>
'section');
534 $formquestion[
'section_id'] = array(
'type' =>
'hidden',
'value' => $section_id,
'name' =>
'section_id');
535 $formquestion[
'section_dir'] = array(
'type' =>
'hidden',
'value' => $section_dir,
'name' =>
'section_dir');
536 $formquestion[
'sortfield'] = array(
'type' =>
'hidden',
'value' => $sortfield,
'name' =>
'sortfield');
537 $formquestion[
'sortorder'] = array(
'type' =>
'hidden',
'value' => $sortorder,
'name' =>
'sortorder');
538 if (!empty($action) && $action ==
'file_manager') {
539 $formquestion[
'file_manager'] = array(
'type' =>
'hidden',
'value' => 1,
'name' =>
'file_manager');
541 if (!empty($websitekey)) {
542 $formquestion[
'website'] = array(
'type' =>
'hidden',
'value' => $websitekey,
'name' =>
'website');
544 if (!empty($pageid) && $pageid > 0) {
545 $formquestion[
'pageid'] = array(
'type' =>
'hidden',
'value' => $pageid,
'name' =>
'pageid');
547 foreach (array(
'dol_hide_topmenu',
'dol_hide_leftmenu') as $tmpparam) {
549 $formquestion[$tmpparam] = array(
'type' =>
'hidden',
'value' =>
GETPOSTINT($tmpparam),
'name' => $tmpparam);
552 if (
GETPOST(
'dol_openinpopup',
'aZ09')) {
553 $formquestion[
'dol_openinpopup'] = array(
'type' =>
'hidden',
'value' =>
GETPOST(
'dol_openinpopup',
'aZ09'),
'name' =>
'dol_openinpopup');
556 print $form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"),
'confirm_deletefile', $formquestion,
"no", ($useajax ?
'deletefile' : 0));
560 print
'<!-- ajaxdirpreview.php: js to manage preview of doc -->'.
"\n";
561 print
'<script nonce="'.getNonce().
'" type="text/javascript">';
567 if (
$conf->browser->layout !=
'phone') {
568 print
"\n/* JS CODE TO ENABLE document_preview */\n";
570 jQuery(document).ready(function () {
571 jQuery(".documentpreview").click(function () {
572 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
573 var titledocpreview = $(this).attr(\'data-title\');
574 if (titledocpreview == undefined || titledocpreview == "") {
575 titledocpreview = \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\'
577 document_preview($(
this).attr(\
'href\'), $(this).attr(\'mime\'), titledocpreview);
585 print
'jQuery(document).ready(function() {'.
"\n";
586 print
' jQuery(".deletefilelink").click(function(e) { '.
"\n";
587 print
' console.log("We click on button with class deletefilelink, param='.$param.
', we set urlfile to "+jQuery(this).attr("rel"));'.
"\n";
588 print
' jQuery("#urlfile").val(jQuery(this).attr("rel"));'.
"\n";
590 print
' jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
591 print
' return false;'.
"\n";
594 print
'</script>'.
"\n";
598if ((!isset($mode) || $mode !=
'noajax') && is_object($db)) {
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage ECM directories.
if(! $sortfield) if(! $sortorder) $module
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.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.