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');
78 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
79 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
81 $showonrightsize =
'';
83 if (empty($page) || $page == -1) {
86 $offset = $limit * $page;
87 $pageprev = $page - 1;
88 $pagenext = $page + 1;
96 $rootdirfordoc =
$conf->ecm->dir_output;
98 $upload_dir = dirname(str_replace(
"../",
"/", $rootdirfordoc.
'/'.$file));
102 $result = $ecmdir->fetch((
int) $section);
120 @phan-var-force int $section
121 @phan-var-force string $action
122 @phan-var-force string $module
123 @phan-var-force string $showonrightsize
124 @phan-var-force string $sortfield
125 @phan-var-force string $sortorder
128 $rootdirfordoc =
$conf->ecm->dir_output;
133 $result = $ecmdir->fetch($section);
134 if (!($result > 0)) {
139 $relativepath = $ecmdir->getRelativePath();
140 } elseif (
GETPOST(
'section_dir')) {
141 $relativepath =
GETPOST(
'section_dir');
145 $upload_dir = $rootdirfordoc.
'/'.$relativepath;
149 if (!empty($module) && $module ==
'medias' && !
GETPOST(
'website')) {
150 $url = DOL_URL_ROOT.
'/ecm/index_medias.php';
151 } elseif (GETPOSTISSET(
'website')) {
152 $url = DOL_URL_ROOT.
'/website/index.php';
154 $url = DOL_URL_ROOT.
'/ecm/index.php';
159$langs->loadLangs(array(
"ecm",
"companies",
"other"));
161if (empty($modulepart)) {
162 $modulepart = $module;
166if ($user->socid > 0) {
167 $socid = $user->socid;
170if (preg_match(
'/\.\./', $upload_dir) || preg_match(
'/[<>|]/', $upload_dir)) {
171 dol_syslog(
"Refused to deliver file ".$upload_dir);
173 dol_print_error(
null, $langs->trans(
"ErrorFileNameInvalid", $upload_dir));
177if ($modulepart ==
'ecm') {
178 if (!$user->hasRight(
'ecm',
'read')) {
181} elseif ($modulepart ==
'medias' || $modulepart ==
'website') {
200if (!isset($mode) || $mode !=
'noajax') {
202 header(
'Cache-Control: Public, must-revalidate');
203 header(
'Pragma: public');
218print
'<!-- ajaxdirpreview mode='.$mode.
' type='.$type.
' module='.$module.
' modulepart='.$modulepart.
'-->'.
"\n";
221$param = ($sortfield ?
'&sortfield='.urlencode($sortfield) :
'').($sortorder ?
'&sortorder='.urlencode($sortorder) :
'');
222if (!empty($websitekey)) {
223 $param .=
'&website='.urlencode($websitekey);
225if (!empty($pageid)) {
226 $param .=
'&pageid='.((int) $pageid);
231if ($type ==
'directory') {
235 $excludefiles = array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$');
236 $sorting = (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC);
239 $automodules = array(
258 'recruitment-recruitmentcandidature',
265 $parameters = array(
'modulepart' => $module);
266 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
267 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
268 if (is_array($hookmanager->resArray[
'module'])) {
269 $automodules = array_merge($automodules, $hookmanager->resArray[
'module']);
271 $automodules[] = $hookmanager->resArray[
'module'];
276 if ($module ==
'company') {
277 $upload_dir =
$conf->societe->dir_output;
278 $excludefiles[] =
'^contact$';
279 } elseif ($module ==
'invoice') {
280 $upload_dir =
$conf->invoice->dir_output;
281 } elseif ($module ==
'invoice_supplier') {
282 $upload_dir =
$conf->fournisseur->facture->dir_output;
283 } elseif ($module ==
'propal') {
284 $upload_dir =
$conf->propal->dir_output;
285 } elseif ($module ==
'supplier_proposal') {
286 $upload_dir =
$conf->supplier_proposal->dir_output;
287 } elseif ($module ==
'order') {
288 $upload_dir =
$conf->order->dir_output;
289 } elseif ($module ==
'order_supplier') {
290 $upload_dir =
$conf->fournisseur->commande->dir_output;
291 } elseif ($module ==
'contract') {
292 $upload_dir =
$conf->contract->dir_output;
293 } elseif ($module ==
'product') {
294 $upload_dir =
$conf->product->dir_output;
295 } elseif ($module ==
'tax') {
296 $upload_dir =
$conf->tax->dir_output;
297 $excludefiles[] =
'^vat$';
298 } elseif ($module ==
'tax-vat') {
299 $upload_dir =
$conf->tax->dir_output.
'/vat';
300 } elseif ($module ==
'salaries') {
301 $upload_dir =
$conf->salaries->dir_output;
302 } elseif ($module ==
'project') {
303 $upload_dir =
$conf->project->dir_output;
304 } elseif ($module ==
'project_task') {
305 $upload_dir =
$conf->project->dir_output;
306 } elseif ($module ==
'fichinter') {
307 $upload_dir =
$conf->ficheinter->dir_output;
308 } elseif ($module ==
'user') {
309 $upload_dir =
$conf->user->dir_output;
310 } elseif ($module ==
'expensereport') {
311 $upload_dir =
$conf->expensereport->dir_output;
312 } elseif ($module ==
'holiday') {
313 $upload_dir =
$conf->holiday->dir_output;
314 } elseif ($module ==
'recruitment-recruitmentcandidature') {
315 $upload_dir =
$conf->recruitment->dir_output.
'/recruitmentcandidature';
316 } elseif ($module ==
'banque') {
317 $upload_dir =
$conf->bank->dir_output;
318 } elseif ($module ==
'bank-statement') {
319 $upload_dir =
$conf->bank->dir_output.
'/*/statement';
320 } elseif ($module ==
'chequereceipt') {
321 $upload_dir =
$conf->bank->dir_output.
'/checkdeposits';
322 } elseif ($module ==
'mrp-mo') {
323 $upload_dir =
$conf->mrp->dir_output;
325 $parameters = array(
'modulepart' => $module);
326 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
327 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
328 $upload_dir = $hookmanager->resArray[
'directory'];
333 if (in_array($module, $automodules)) {
334 $param .=
'&module='.urlencode($module);
335 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
336 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
339 $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
341 $filter = preg_quote((
string) $search_doc_ref,
'/');
342 $filearray =
dol_dir_list($upload_dir,
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
347 if ($user->socid > 0) {
348 $filearrayallowedtoexternal = array();
354 foreach ($filearray as $key => $val) {
355 if (!in_array($upload_dir.
'/'.$val[
'relativename'], $filearrayallowedtoexternal)) {
356 unset($filearray[$key]);
361 $perm = $user->hasRight(
'ecm',
'upload');
364 $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1,
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
367 if ($module ==
'medias') {
379 $relativepath =
GETPOST(
'file',
'alpha') ?
GETPOST(
'file',
'alpha') :
GETPOST(
'section_dir',
'alpha');
380 if ($relativepath && $relativepath !=
'/') {
381 $relativepath .=
'/';
383 $upload_dir = $dolibarr_main_data_root.
'/'.$module.
'/'.$relativepath;
384 if (GETPOSTISSET(
'website') || GETPOSTISSET(
'file_manager')) {
385 $param .=
'&file_manager=1';
386 if (!preg_match(
'/website=/', $param) &&
GETPOST(
'website',
'alpha')) {
387 $param .=
'&website='.urlencode(
GETPOST(
'website',
'alpha'));
389 if (!preg_match(
'/pageid=/', $param)) {
390 $param .=
'&pageid='.GETPOSTINT(
'pageid');
395 $relativepath = $ecmdir->getRelativePath();
396 $upload_dir =
$conf->ecm->dir_output.
'/'.$relativepath;
400 if (($section ===
'0' || empty($section)) && ($module !=
'medias')) {
401 $filearray = array();
403 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'', array(
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^CVS$'), $sortfield, $sorting, 1);
407 $param .=
'§ion='.$section;
408 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
409 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
412 $textifempty = $langs->trans(
'NoFileFound');
413 } elseif ($section ===
'0') {
414 if ($module ==
'ecm') {
415 $textifempty =
'<br><div class="center"><span class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</span></div><br>';
417 $textifempty = $langs->trans(
'NoFileFound');
420 $textifempty = ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
424 if ($module ==
'medias') {
426 $modulepart =
'medias';
427 $perm = $user->hasRight(
"website",
"write");
429 } elseif ($module ==
'ecm') {
430 if ($user->hasRight(
"ecm",
"read")) {
435 if ($user->hasRight(
"ecm",
"upload")) {
440 if ($user->hasRight(
"ecm",
"setup")) {
445 $perm = $user->hasRight(
"ecm",
"upload");
451 $perm = $user->hasRight(
"ecm",
"upload");
459 $formfile->list_of_documents($filearray,
null, $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm, $upload_dir, $sortfield, $sortorder);
467if (!empty(
$conf->dol_use_jmobile)) {
470if (empty(
$conf->use_javascript_ajax)) {
479if ($useajax || $action ==
'deletefile') {
481 if ($action ==
'deletefile') {
482 $urlfile =
GETPOST(
'urlfile',
'alpha');
485 if (empty($section_dir)) {
486 $section_dir =
GETPOST(
"file",
"alpha");
488 $section_id = $section;
490 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
493 $formquestion = array();
494 $formquestion[
'urlfile'] = array(
'type' =>
'hidden',
'value' => $urlfile,
'name' =>
'urlfile');
495 $formquestion[
'section'] = array(
'type' =>
'hidden',
'value' => $section,
'name' =>
'section');
496 $formquestion[
'section_id'] = array(
'type' =>
'hidden',
'value' => $section_id,
'name' =>
'section_id');
497 $formquestion[
'section_dir'] = array(
'type' =>
'hidden',
'value' => $section_dir,
'name' =>
'section_dir');
498 $formquestion[
'sortfield'] = array(
'type' =>
'hidden',
'value' => $sortfield,
'name' =>
'sortfield');
499 $formquestion[
'sortorder'] = array(
'type' =>
'hidden',
'value' => $sortorder,
'name' =>
'sortorder');
500 if (!empty($action) && $action ==
'file_manager') {
501 $formquestion[
'file_manager'] = array(
'type' =>
'hidden',
'value' => 1,
'name' =>
'file_manager');
503 if (!empty($websitekey)) {
504 $formquestion[
'website'] = array(
'type' =>
'hidden',
'value' => $websitekey,
'name' =>
'website');
506 if (!empty($pageid) && $pageid > 0) {
507 $formquestion[
'pageid'] = array(
'type' =>
'hidden',
'value' => $pageid,
'name' =>
'pageid');
510 print $form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"),
'confirm_deletefile', $formquestion,
"no", ($useajax ?
'deletefile' : 0));
514 print
'<!-- ajaxdirpreview.php: js to manage preview of doc -->'.
"\n";
515 print
'<script nonce="'.getNonce().
'" type="text/javascript">';
521 if (
$conf->browser->layout !=
'phone') {
522 print
"\n/* JS CODE TO ENABLE document_preview */\n";
524 jQuery(document).ready(function () {
525 jQuery(".documentpreview").click(function () {
526 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
527 var titledocpreview = $(this).attr(\'data-title\');
528 if (titledocpreview == undefined || titledocpreview == "") {
529 titledocpreview = \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\'
531 document_preview($(
this).attr(\
'href\'), $(this).attr(\'mime\'), titledocpreview);
539 print
'jQuery(document).ready(function() {'.
"\n";
540 print
' jQuery(".deletefilelink").click(function(e) { '.
"\n";
541 print
' console.log("We click on button with class deletefilelink, param='.$param.
', we set urlfile to "+jQuery(this).attr("rel"));'.
"\n";
542 print
' jQuery("#urlfile").val(jQuery(this).attr("rel"));'.
"\n";
544 print
' jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
545 print
' return false;'.
"\n";
548 print
'</script>'.
"\n";
552if ((!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.
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.