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');
59if (!isset($mode) || $mode !=
'noajax') {
60 require_once
'../../main.inc.php';
61 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
62 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
65 $action =
GETPOST(
'action',
'aZ09');
66 $file = urldecode(
GETPOST(
'file',
'alpha'));
67 $section =
GETPOST(
"section",
'alpha');
68 $module =
GETPOST(
"module",
'alpha');
69 $urlsource =
GETPOST(
"urlsource",
'alpha');
70 $search_doc_ref =
GETPOST(
'search_doc_ref',
'alpha');
73 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
74 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
76 $showonrightsize =
'';
78 if (empty($page) || $page == -1) {
81 $offset = $limit * $page;
82 $pageprev = $page - 1;
83 $pagenext = $page + 1;
91 $rootdirfordoc = $conf->ecm->dir_output;
93 $upload_dir = dirname(str_replace(
"../",
"/", $rootdirfordoc.
'/'.$file));
97 $result = $ecmdir->fetch((
int) $section);
109 @phan-var-force int $section
110 @phan-var-force string $module
111 @phan-var-force string $showonrightsize
114 $rootdirfordoc = $conf->ecm->dir_output;
119 $result = $ecmdir->fetch($section);
120 if (!($result > 0)) {
125 $relativepath = $ecmdir->getRelativePath();
126 } elseif (
GETPOST(
'section_dir')) {
127 $relativepath =
GETPOST(
'section_dir');
131 $upload_dir = $rootdirfordoc.
'/'.$relativepath;
135 if (!empty($module) && $module ==
'medias' && !
GETPOST(
'website')) {
136 $url = DOL_URL_ROOT.
'/ecm/index_medias.php';
137 } elseif (GETPOSTISSET(
'website')) {
138 $url = DOL_URL_ROOT.
'/website/index.php';
140 $url = DOL_URL_ROOT.
'/ecm/index.php';
145$langs->loadLangs(array(
"ecm",
"companies",
"other"));
147if (empty($modulepart)) {
148 $modulepart = $module;
152if ($user->socid > 0) {
153 $socid = $user->socid;
156if (preg_match(
'/\.\./', $upload_dir) || preg_match(
'/[<>|]/', $upload_dir)) {
157 dol_syslog(
"Refused to deliver file ".$upload_dir);
159 dol_print_error(
null, $langs->trans(
"ErrorFileNameInvalid", $upload_dir));
163if ($modulepart ==
'ecm') {
164 if (!$user->hasRight(
'ecm',
'read')) {
167} elseif ($modulepart ==
'medias' || $modulepart ==
'website') {
186if (!isset($mode) || $mode !=
'noajax') {
188 header(
'Cache-Control: Public, must-revalidate');
189 header(
'Pragma: public');
204print
'<!-- ajaxdirpreview mode='.$mode.
' type='.$type.
' module='.$module.
' modulepart='.$modulepart.
'-->'.
"\n";
207$param = ($sortfield ?
'&sortfield='.urlencode($sortfield) :
'').($sortorder ?
'&sortorder='.urlencode($sortorder) :
'');
208if (!empty($websitekey)) {
209 $param .=
'&website='.urlencode($websitekey);
211if (!empty($pageid)) {
212 $param .=
'&pageid='.((int) $pageid);
217if ($type ==
'directory') {
221 $excludefiles = array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$');
222 $sorting = (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC);
225 $automodules = array(
244 'recruitment-recruitmentcandidature',
251 $parameters = array(
'modulepart' => $module);
252 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
253 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
254 if (is_array($hookmanager->resArray[
'module'])) {
255 $automodules = array_merge($automodules, $hookmanager->resArray[
'module']);
257 $automodules[] = $hookmanager->resArray[
'module'];
262 if ($module ==
'company') {
263 $upload_dir = $conf->societe->dir_output;
264 $excludefiles[] =
'^contact$';
265 } elseif ($module ==
'invoice') {
266 $upload_dir = $conf->invoice->dir_output;
267 } elseif ($module ==
'invoice_supplier') {
268 $upload_dir = $conf->fournisseur->facture->dir_output;
269 } elseif ($module ==
'propal') {
270 $upload_dir = $conf->propal->dir_output;
271 } elseif ($module ==
'supplier_proposal') {
272 $upload_dir = $conf->supplier_proposal->dir_output;
273 } elseif ($module ==
'order') {
274 $upload_dir = $conf->order->dir_output;
275 } elseif ($module ==
'order_supplier') {
276 $upload_dir = $conf->fournisseur->commande->dir_output;
277 } elseif ($module ==
'contract') {
278 $upload_dir = $conf->contract->dir_output;
279 } elseif ($module ==
'product') {
280 $upload_dir = $conf->product->dir_output;
281 } elseif ($module ==
'tax') {
282 $upload_dir = $conf->tax->dir_output;
283 $excludefiles[] =
'^vat$';
284 } elseif ($module ==
'tax-vat') {
285 $upload_dir = $conf->tax->dir_output.
'/vat';
286 } elseif ($module ==
'salaries') {
287 $upload_dir = $conf->salaries->dir_output;
288 } elseif ($module ==
'project') {
289 $upload_dir = $conf->project->dir_output;
290 } elseif ($module ==
'project_task') {
291 $upload_dir = $conf->project->dir_output;
292 } elseif ($module ==
'fichinter') {
293 $upload_dir = $conf->ficheinter->dir_output;
294 } elseif ($module ==
'user') {
295 $upload_dir = $conf->user->dir_output;
296 } elseif ($module ==
'expensereport') {
297 $upload_dir = $conf->expensereport->dir_output;
298 } elseif ($module ==
'holiday') {
299 $upload_dir = $conf->holiday->dir_output;
300 } elseif ($module ==
'recruitment-recruitmentcandidature') {
301 $upload_dir = $conf->recruitment->dir_output.
'/recruitmentcandidature';
302 } elseif ($module ==
'banque') {
303 $upload_dir = $conf->bank->dir_output;
304 } elseif ($module ==
'bank-statement') {
305 $upload_dir = $conf->bank->dir_output.
'/*/statement';
306 } elseif ($module ==
'chequereceipt') {
307 $upload_dir = $conf->bank->dir_output.
'/checkdeposits';
308 } elseif ($module ==
'mrp-mo') {
309 $upload_dir = $conf->mrp->dir_output;
311 $parameters = array(
'modulepart' => $module);
312 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
313 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
314 $upload_dir = $hookmanager->resArray[
'directory'];
319 if (in_array($module, $automodules)) {
320 $param .=
'&module='.urlencode($module);
321 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
322 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
325 $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
327 $filter = preg_quote((
string) $search_doc_ref,
'/');
328 $filearray =
dol_dir_list($upload_dir,
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
333 if ($user->socid > 0) {
334 $filearrayallowedtoexternal = array();
340 foreach ($filearray as $key => $val) {
341 if (!in_array($upload_dir.
'/'.$val[
'relativename'], $filearrayallowedtoexternal)) {
342 unset($filearray[$key]);
347 $perm = $user->hasRight(
'ecm',
'upload');
350 $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1,
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
353 if ($module ==
'medias') {
365 $relativepath =
GETPOST(
'file',
'alpha') ?
GETPOST(
'file',
'alpha') :
GETPOST(
'section_dir',
'alpha');
366 if ($relativepath && $relativepath !=
'/') {
367 $relativepath .=
'/';
369 $upload_dir = $dolibarr_main_data_root.
'/'.$module.
'/'.$relativepath;
370 if (GETPOSTISSET(
'website') || GETPOSTISSET(
'file_manager')) {
371 $param .=
'&file_manager=1';
372 if (!preg_match(
'/website=/', $param) &&
GETPOST(
'website',
'alpha')) {
373 $param .=
'&website='.urlencode(
GETPOST(
'website',
'alpha'));
375 if (!preg_match(
'/pageid=/', $param)) {
376 $param .=
'&pageid='.GETPOSTINT(
'pageid');
381 $relativepath = $ecmdir->getRelativePath();
382 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
386 if (($section ===
'0' || empty($section)) && ($module !=
'medias')) {
387 $filearray = array();
389 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'', array(
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^CVS$'), $sortfield, $sorting, 1);
393 $param .=
'§ion='.$section;
394 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
395 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
398 $textifempty = $langs->trans(
'NoFileFound');
399 } elseif ($section ===
'0') {
400 if ($module ==
'ecm') {
401 $textifempty =
'<br><div class="center"><span class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</span></div><br>';
403 $textifempty = $langs->trans(
'NoFileFound');
406 $textifempty = ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
410 if ($module ==
'medias') {
412 $modulepart =
'medias';
413 $perm = ($user->hasRight(
"website",
"write") || $user->hasRight(
"emailing",
"creer"));
415 } elseif ($module ==
'ecm') {
416 if ($user->hasRight(
"ecm",
"read")) {
421 if ($user->hasRight(
"ecm",
"upload")) {
426 if ($user->hasRight(
"ecm",
"setup")) {
431 $perm = $user->hasRight(
"ecm",
"upload");
437 $perm = $user->hasRight(
"ecm",
"upload");
445 $formfile->list_of_documents($filearray,
null, $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm, $upload_dir, $sortfield, $sortorder);
453if (!empty($conf->dol_use_jmobile)) {
456if (empty($conf->use_javascript_ajax)) {
465if ($useajax || $action ==
'deletefile') {
467 if ($action ==
'deletefile') {
468 $urlfile =
GETPOST(
'urlfile',
'alpha');
471 if (empty($section_dir)) {
472 $section_dir =
GETPOST(
"file",
"alpha");
474 $section_id = $section;
476 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
478 $form =
new Form($db);
479 $formquestion = array();
480 $formquestion[
'urlfile'] = array(
'type' =>
'hidden',
'value' => $urlfile,
'name' =>
'urlfile');
481 $formquestion[
'section'] = array(
'type' =>
'hidden',
'value' => $section,
'name' =>
'section');
482 $formquestion[
'section_id'] = array(
'type' =>
'hidden',
'value' => $section_id,
'name' =>
'section_id');
483 $formquestion[
'section_dir'] = array(
'type' =>
'hidden',
'value' => $section_dir,
'name' =>
'section_dir');
484 $formquestion[
'sortfield'] = array(
'type' =>
'hidden',
'value' => $sortfield,
'name' =>
'sortfield');
485 $formquestion[
'sortorder'] = array(
'type' =>
'hidden',
'value' => $sortorder,
'name' =>
'sortorder');
486 if (!empty($action) && $action ==
'file_manager') {
487 $formquestion[
'file_manager'] = array(
'type' =>
'hidden',
'value' => 1,
'name' =>
'file_manager');
489 if (!empty($websitekey)) {
490 $formquestion[
'website'] = array(
'type' =>
'hidden',
'value' => $websitekey,
'name' =>
'website');
492 if (!empty($pageid) && $pageid > 0) {
493 $formquestion[
'pageid'] = array(
'type' =>
'hidden',
'value' => $pageid,
'name' =>
'pageid');
496 print $form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"),
'confirm_deletefile', $formquestion,
"no", ($useajax ?
'deletefile' : 0));
500 print
'<!-- ajaxdirpreview.php: js to manage preview of doc -->'.
"\n";
501 print
'<script nonce="'.getNonce().
'" type="text/javascript">';
507 if ($conf->browser->layout !=
'phone') {
508 print
"\n/* JS CODE TO ENABLE document_preview */\n";
510 jQuery(document).ready(function () {
511 jQuery(".documentpreview").click(function () {
512 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
513 var titledocpreview = $(this).attr(\'data-title\');
514 if (titledocpreview == undefined || titledocpreview == "") {
515 titledocpreview = \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\'
517 document_preview($(
this).attr(\
'href\'), $(this).attr(\'mime\'), titledocpreview);
525 print
'jQuery(document).ready(function() {'.
"\n";
526 print
' jQuery(".deletefilelink").click(function(e) { '.
"\n";
527 print
' console.log("We click on button with class deletefilelink, param='.$param.
', we set urlfile to "+jQuery(this).attr("rel"));'.
"\n";
528 print
' jQuery("#urlfile").val(jQuery(this).attr("rel"));'.
"\n";
530 print
' jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
531 print
' return false;'.
"\n";
534 print
'</script>'.
"\n";
538if ((!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.