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');
73 $module =
GETPOST(
"module",
'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 =
'';
78 if (GETPOSTISSET(
'search_doc_date_start') || GETPOSTISSET(
'search_doc_date_startday') || GETPOSTISSET(
'search_doc_date_startmonth') || GETPOSTISSET(
'search_doc_date_startyear')) {
79 $search_doc_date_start =
GETPOSTDATE(
'search_doc_date_start');
81 if (GETPOSTISSET(
'search_doc_date_end') || GETPOSTISSET(
'search_doc_date_endday') || GETPOSTISSET(
'search_doc_date_endmonth') || GETPOSTISSET(
'search_doc_date_endyear')) {
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)) {
147 $relativepath = $ecmdir->getRelativePath();
148 } elseif (
GETPOST(
'section_dir')) {
149 $relativepath =
GETPOST(
'section_dir');
153 $upload_dir = $rootdirfordoc.
'/'.$relativepath;
157 if (!empty($module) && $module ==
'medias' && !
GETPOST(
'website')) {
158 $url = DOL_URL_ROOT.
'/ecm/index_medias.php';
159 } elseif (GETPOSTISSET(
'website')) {
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)) {
170 $modulepart = $module;
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);
239if ($type ==
'directory') {
243 $excludefiles = array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$');
244 $sorting = (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC);
247 $automodules = array(
266 'recruitment-recruitmentcandidature',
273 $parameters = array(
'modulepart' => $module);
274 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
275 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
276 if (is_array($hookmanager->resArray[
'module'])) {
277 $automodules = array_merge($automodules, $hookmanager->resArray[
'module']);
279 $automodules[] = $hookmanager->resArray[
'module'];
284 if ($module ==
'company') {
285 $upload_dir =
$conf->societe->dir_output;
286 $excludefiles[] =
'^contact$';
287 } elseif ($module ==
'invoice') {
288 $upload_dir =
$conf->invoice->dir_output;
289 } elseif ($module ==
'invoice_supplier') {
290 $upload_dir = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
291 } elseif ($module ==
'propal') {
292 $upload_dir =
$conf->propal->dir_output;
293 } elseif ($module ==
'supplier_proposal') {
294 $upload_dir =
$conf->supplier_proposal->dir_output;
295 } elseif ($module ==
'order') {
296 $upload_dir =
$conf->order->dir_output;
297 } elseif ($module ==
'order_supplier') {
298 $upload_dir =
$conf->fournisseur->commande->dir_output;
299 } elseif ($module ==
'contract') {
300 $upload_dir =
$conf->contract->dir_output;
301 } elseif ($module ==
'product') {
302 $upload_dir =
$conf->product->dir_output;
303 } elseif ($module ==
'tax') {
304 $upload_dir =
$conf->tax->dir_output;
305 $excludefiles[] =
'^vat$';
306 } elseif ($module ==
'tax-vat') {
307 $upload_dir =
$conf->tax->dir_output.
'/vat';
308 } elseif ($module ==
'salaries') {
309 $upload_dir =
$conf->salaries->dir_output;
310 } elseif ($module ==
'project') {
311 $upload_dir =
$conf->project->dir_output;
312 } elseif ($module ==
'project_task') {
313 $upload_dir =
$conf->project->dir_output;
314 } elseif ($module ==
'fichinter') {
315 $upload_dir =
$conf->ficheinter->dir_output;
316 } elseif ($module ==
'user') {
317 $upload_dir =
$conf->user->dir_output;
318 } elseif ($module ==
'expensereport') {
319 $upload_dir =
$conf->expensereport->dir_output;
320 } elseif ($module ==
'holiday') {
321 $upload_dir =
$conf->holiday->dir_output;
322 } elseif ($module ==
'recruitment-recruitmentcandidature') {
323 $upload_dir =
$conf->recruitment->dir_output.
'/recruitmentcandidature';
324 } elseif ($module ==
'banque') {
325 $upload_dir =
$conf->bank->dir_output;
326 } elseif ($module ==
'bank-statement') {
327 $upload_dir =
$conf->bank->dir_output.
'/*/statement';
328 } elseif ($module ==
'chequereceipt') {
329 $upload_dir =
$conf->bank->dir_output.
'/checkdeposits';
330 } elseif ($module ==
'mrp-mo') {
331 $upload_dir =
$conf->mrp->dir_output;
333 $parameters = array(
'modulepart' => $module);
334 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
335 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
336 $upload_dir = $hookmanager->resArray[
'directory'];
341 if (in_array($module, $automodules)) {
342 $param .=
'&module='.urlencode($module);
343 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
344 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
346 if (!empty($search_doc_date_start)) {
347 $param .=
'&search_doc_date_startday='.dol_print_date($search_doc_date_start,
'%d');
348 $param .=
'&search_doc_date_startmonth='.dol_print_date($search_doc_date_start,
'%m');
349 $param .=
'&search_doc_date_startyear='.dol_print_date($search_doc_date_start,
'%Y');
351 if (!empty($search_doc_date_end)) {
352 $param .=
'&search_doc_date_endday='.dol_print_date($search_doc_date_end,
'%d');
353 $param .=
'&search_doc_date_endmonth='.dol_print_date($search_doc_date_end,
'%m');
354 $param .=
'&search_doc_date_endyear='.dol_print_date($search_doc_date_end,
'%Y');
357 $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
359 $filter = preg_quote((
string) $search_doc_ref,
'/');
360 $filearray =
dol_dir_list($upload_dir,
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
361 if (!empty($search_doc_date_start) || !empty($search_doc_date_end)) {
362 foreach ($filearray as $key => $file) {
363 $filedate = empty($file[
'date']) ? 0 : (int) $file[
'date'];
364 if ((!empty($search_doc_date_start) && $filedate < $search_doc_date_start)
365 || (!empty($search_doc_date_end) && $filedate > $search_doc_date_end)
367 unset($filearray[$key]);
375 if ($user->socid > 0) {
376 $filearrayallowedtoexternal = array();
382 foreach ($filearray as $key => $val) {
383 if (!in_array($upload_dir.
'/'.$val[
'relativename'], $filearrayallowedtoexternal)) {
384 unset($filearray[$key]);
389 $perm = $user->hasRight(
'ecm',
'upload');
392 $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1,
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
395 if ($module ==
'medias') {
407 $relativepath =
GETPOST(
'file',
'alpha') ?
GETPOST(
'file',
'alpha') :
GETPOST(
'section_dir',
'alpha');
408 if ($relativepath && $relativepath !=
'/') {
409 $relativepath .=
'/';
411 $upload_dir = $dolibarr_main_data_root.
'/'.$module.
'/'.$relativepath;
412 if (GETPOSTISSET(
'website') || GETPOSTISSET(
'file_manager')) {
413 $param .=
'&file_manager=1';
414 if (!preg_match(
'/website=/', $param) &&
GETPOST(
'website',
'alpha')) {
415 $param .=
'&website='.urlencode(
GETPOST(
'website',
'alpha'));
417 if (!preg_match(
'/pageid=/', $param)) {
418 $param .=
'&pageid='.GETPOSTINT(
'pageid');
423 $relativepath = $ecmdir->getRelativePath();
424 $upload_dir =
$conf->ecm->dir_output.
'/'.$relativepath;
428 if (($section ===
'0' || empty($section)) && ($module !=
'medias')) {
429 $filearray = array();
431 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'', array(
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^CVS$'), $sortfield, $sorting, 1);
435 $param .=
'§ion='.urlencode($section);
436 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
437 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
440 $textifempty = $langs->trans(
'NoFileFound');
441 } elseif ($section ===
'0') {
442 if ($module ==
'ecm') {
443 $textifempty =
'<br><div class="center"><span class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</span></div><br>';
445 $textifempty = $langs->trans(
'NoFileFound');
448 $textifempty = ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
452 if ($module ==
'medias') {
454 $modulepart =
'medias';
455 $perm = $user->hasRight(
"website",
"write");
457 } elseif ($module ==
'ecm') {
458 if ($user->hasRight(
"ecm",
"read")) {
463 if ($user->hasRight(
"ecm",
"upload")) {
468 if ($user->hasRight(
"ecm",
"setup")) {
473 $perm = $user->hasRight(
"ecm",
"upload");
479 $perm = $user->hasRight(
"ecm",
"upload");
487 $formfile->list_of_documents($filearray,
null, $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm, $upload_dir, $sortfield, $sortorder);
495if (!empty(
$conf->dol_use_jmobile)) {
498if (empty(
$conf->use_javascript_ajax)) {
507if ($useajax || $action ==
'deletefile') {
509 if ($action ==
'deletefile') {
510 $urlfile =
GETPOST(
'urlfile',
'alpha');
513 if (empty($section_dir)) {
514 $section_dir =
GETPOST(
"file",
"alpha");
516 $section_id = $section;
518 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
521 $formquestion = array();
522 $formquestion[
'urlfile'] = array(
'type' =>
'hidden',
'value' => $urlfile,
'name' =>
'urlfile');
523 $formquestion[
'section'] = array(
'type' =>
'hidden',
'value' => $section,
'name' =>
'section');
524 $formquestion[
'section_id'] = array(
'type' =>
'hidden',
'value' => $section_id,
'name' =>
'section_id');
525 $formquestion[
'section_dir'] = array(
'type' =>
'hidden',
'value' => $section_dir,
'name' =>
'section_dir');
526 $formquestion[
'sortfield'] = array(
'type' =>
'hidden',
'value' => $sortfield,
'name' =>
'sortfield');
527 $formquestion[
'sortorder'] = array(
'type' =>
'hidden',
'value' => $sortorder,
'name' =>
'sortorder');
528 if (!empty($action) && $action ==
'file_manager') {
529 $formquestion[
'file_manager'] = array(
'type' =>
'hidden',
'value' => 1,
'name' =>
'file_manager');
531 if (!empty($websitekey)) {
532 $formquestion[
'website'] = array(
'type' =>
'hidden',
'value' => $websitekey,
'name' =>
'website');
534 if (!empty($pageid) && $pageid > 0) {
535 $formquestion[
'pageid'] = array(
'type' =>
'hidden',
'value' => $pageid,
'name' =>
'pageid');
538 print $form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"),
'confirm_deletefile', $formquestion,
"no", ($useajax ?
'deletefile' : 0));
542 print
'<!-- ajaxdirpreview.php: js to manage preview of doc -->'.
"\n";
543 print
'<script nonce="'.getNonce().
'" type="text/javascript">';
549 if (
$conf->browser->layout !=
'phone') {
550 print
"\n/* JS CODE TO ENABLE document_preview */\n";
552 jQuery(document).ready(function () {
553 jQuery(".documentpreview").click(function () {
554 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
555 var titledocpreview = $(this).attr(\'data-title\');
556 if (titledocpreview == undefined || titledocpreview == "") {
557 titledocpreview = \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\'
559 document_preview($(
this).attr(\
'href\'), $(this).attr(\'mime\'), titledocpreview);
567 print
'jQuery(document).ready(function() {'.
"\n";
568 print
' jQuery(".deletefilelink").click(function(e) { '.
"\n";
569 print
' console.log("We click on button with class deletefilelink, param='.$param.
', we set urlfile to "+jQuery(this).attr("rel"));'.
"\n";
570 print
' jQuery("#urlfile").val(jQuery(this).attr("rel"));'.
"\n";
572 print
' jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
573 print
' return false;'.
"\n";
576 print
'</script>'.
"\n";
580if ((!isset($mode) || $mode !=
'noajax') && is_object(
$db)) {
Class to manage ECM directories.
document_preview(file, type, title)
Function to show a document preview popup.
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.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.