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');
54if (!isset($mode) || $mode !=
'noajax') {
55 require_once
'../../main.inc.php';
56 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
57 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
60 $action =
GETPOST(
'action',
'aZ09');
61 $file = urldecode(
GETPOST(
'file',
'alpha'));
62 $section =
GETPOST(
"section",
'alpha');
63 $module =
GETPOST(
"module",
'alpha');
64 $urlsource =
GETPOST(
"urlsource",
'alpha');
65 $search_doc_ref =
GETPOST(
'search_doc_ref',
'alpha');
68 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
69 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
71 $showonrightsize =
'';
73 if (empty($page) || $page == -1) {
76 $offset = $limit * $page;
77 $pageprev = $page - 1;
78 $pagenext = $page + 1;
86 $rootdirfordoc =
$conf->ecm->dir_output;
88 $upload_dir = dirname(str_replace(
"../",
"/", $rootdirfordoc.
'/'.$file));
92 $result = $ecmdir->fetch($section);
101 @phan-var-force int $section
102 @phan-var-force string $module
103 @phan-var-force string $showonrightsize
105 $rootdirfordoc =
$conf->ecm->dir_output;
110 $result = $ecmdir->fetch($section);
111 if (!($result > 0)) {
116 $relativepath = $ecmdir->getRelativePath();
117 } elseif (
GETPOST(
'section_dir')) {
118 $relativepath =
GETPOST(
'section_dir');
122 $upload_dir = $rootdirfordoc.
'/'.$relativepath;
126 if (!empty($module) && $module ==
'medias' && !
GETPOST(
'website')) {
127 $url = DOL_URL_ROOT.
'/ecm/index_medias.php';
128 } elseif (GETPOSTISSET(
'website')) {
129 $url = DOL_URL_ROOT.
'/website/index.php';
131 $url = DOL_URL_ROOT.
'/ecm/index.php';
136$langs->loadLangs(array(
"ecm",
"companies",
"other"));
138if (empty($modulepart)) {
139 $modulepart = $module;
143if ($user->socid > 0) {
144 $socid = $user->socid;
147if (preg_match(
'/\.\./', $upload_dir) || preg_match(
'/[<>|]/', $upload_dir)) {
148 dol_syslog(
"Refused to deliver file ".$upload_dir);
150 dol_print_error(
null, $langs->trans(
"ErrorFileNameInvalid", $upload_dir));
154if ($modulepart ==
'ecm') {
155 if (!$user->hasRight(
'ecm',
'read')) {
158} elseif ($modulepart ==
'medias' || $modulepart ==
'website') {
177if (!isset($mode) || $mode !=
'noajax') {
179 header(
'Cache-Control: Public, must-revalidate');
180 header(
'Pragma: public');
195print
'<!-- ajaxdirpreview type='.$type.
' module='.$module.
' modulepart='.$modulepart.
'-->'.
"\n";
198$param = ($sortfield ?
'&sortfield='.urlencode($sortfield) :
'').($sortorder ?
'&sortorder='.urlencode($sortorder) :
'');
199if (!empty($websitekey)) {
200 $param .=
'&website='.urlencode($websitekey);
202if (!empty($pageid)) {
203 $param .=
'&pageid='.((int) $pageid);
208if ($type ==
'directory') {
212 $excludefiles = array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$');
213 $sorting = (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC);
216 $automodules = array(
235 'recruitment-recruitmentcandidature',
241 $parameters = array(
'modulepart' => $module);
242 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
243 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
244 if (is_array($hookmanager->resArray[
'module'])) {
245 $automodules = array_merge($automodules, $hookmanager->resArray[
'module']);
247 $automodules[] = $hookmanager->resArray[
'module'];
252 if ($module ==
'company') {
253 $upload_dir =
$conf->societe->dir_output;
254 $excludefiles[] =
'^contact$';
255 } elseif ($module ==
'invoice') {
256 $upload_dir =
$conf->facture->dir_output;
257 } elseif ($module ==
'invoice_supplier') {
258 $upload_dir =
$conf->fournisseur->facture->dir_output;
259 } elseif ($module ==
'propal') {
260 $upload_dir =
$conf->propal->dir_output;
261 } elseif ($module ==
'supplier_proposal') {
262 $upload_dir =
$conf->supplier_proposal->dir_output;
263 } elseif ($module ==
'order') {
264 $upload_dir =
$conf->commande->dir_output;
265 } elseif ($module ==
'order_supplier') {
266 $upload_dir =
$conf->fournisseur->commande->dir_output;
267 } elseif ($module ==
'contract') {
268 $upload_dir =
$conf->contrat->dir_output;
269 } elseif ($module ==
'product') {
270 $upload_dir =
$conf->product->dir_output;
271 } elseif ($module ==
'tax') {
272 $upload_dir =
$conf->tax->dir_output;
273 $excludefiles[] =
'^vat$';
274 } elseif ($module ==
'tax-vat') {
275 $upload_dir =
$conf->tax->dir_output.
'/vat';
276 } elseif ($module ==
'salaries') {
277 $upload_dir =
$conf->salaries->dir_output;
278 } elseif ($module ==
'project') {
279 $upload_dir =
$conf->project->dir_output;
280 } elseif ($module ==
'project_task') {
281 $upload_dir =
$conf->project->dir_output;
282 } elseif ($module ==
'fichinter') {
283 $upload_dir =
$conf->ficheinter->dir_output;
284 } elseif ($module ==
'user') {
285 $upload_dir =
$conf->user->dir_output;
286 } elseif ($module ==
'expensereport') {
287 $upload_dir =
$conf->expensereport->dir_output;
288 } elseif ($module ==
'holiday') {
289 $upload_dir =
$conf->holiday->dir_output;
290 } elseif ($module ==
'recruitment-recruitmentcandidature') {
291 $upload_dir =
$conf->recruitment->dir_output.
'/recruitmentcandidature';
292 } elseif ($module ==
'banque') {
293 $upload_dir =
$conf->bank->dir_output;
294 } elseif ($module ==
'chequereceipt') {
295 $upload_dir =
$conf->bank->dir_output.
'/checkdeposits';
296 } elseif ($module ==
'mrp-mo') {
297 $upload_dir =
$conf->mrp->dir_output;
299 $parameters = array(
'modulepart' => $module);
300 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
301 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
302 $upload_dir = $hookmanager->resArray[
'directory'];
307 if (in_array($module, $automodules)) {
308 $param .=
'&module='.urlencode($module);
309 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
310 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
313 $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
315 $filter = preg_quote((
string) $search_doc_ref,
'/');
316 $filearray =
dol_dir_list($upload_dir,
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
320 if ($user->socid > 0) {
321 $filearrayallowedtoexternal = array();
327 foreach ($filearray as $key => $val) {
328 if (!in_array($upload_dir.
'/'.$val[
'relativename'], $filearrayallowedtoexternal)) {
329 unset($filearray[$key]);
334 $perm = $user->hasRight(
'ecm',
'upload');
336 $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1,
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
339 if ($module ==
'medias') {
351 $relativepath =
GETPOST(
'file',
'alpha') ?
GETPOST(
'file',
'alpha') :
GETPOST(
'section_dir',
'alpha');
352 if ($relativepath && $relativepath !=
'/') {
353 $relativepath .=
'/';
355 $upload_dir = $dolibarr_main_data_root.
'/'.$module.
'/'.$relativepath;
356 if (GETPOSTISSET(
'website') || GETPOSTISSET(
'file_manager')) {
357 $param .=
'&file_manager=1';
358 if (!preg_match(
'/website=/', $param) &&
GETPOST(
'website',
'alpha')) {
359 $param .=
'&website='.urlencode(
GETPOST(
'website',
'alpha'));
361 if (!preg_match(
'/pageid=/', $param)) {
362 $param .=
'&pageid='.GETPOSTINT(
'pageid');
367 $relativepath = $ecmdir->getRelativePath();
368 $upload_dir =
$conf->ecm->dir_output.
'/'.$relativepath;
372 if (($section ===
'0' || empty($section)) && ($module !=
'medias')) {
373 $filearray = array();
375 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'', array(
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^CVS$'), $sortfield, $sorting, 1);
379 $param .=
'§ion='.$section;
380 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
381 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
384 $textifempty = $langs->trans(
'NoFileFound');
385 } elseif ($section ===
'0') {
386 if ($module ==
'ecm') {
387 $textifempty =
'<br><div class="center"><span class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</span></div><br>';
389 $textifempty = $langs->trans(
'NoFileFound');
392 $textifempty = ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
396 if ($module ==
'medias') {
398 $modulepart =
'medias';
399 $perm = ($user->hasRight(
"website",
"write") || $user->hasRight(
"emailing",
"creer"));
401 } elseif ($module ==
'ecm') {
402 if ($user->hasRight(
"ecm",
"read")) {
407 if ($user->hasRight(
"ecm",
"upload")) {
412 if ($user->hasRight(
"ecm",
"setup")) {
417 $perm = $user->hasRight(
"ecm",
"upload");
423 $perm = $user->hasRight(
"ecm",
"upload");
430 $formfile->list_of_documents($filearray,
null, $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm,
'', $sortfield, $sortorder);
438if (!empty(
$conf->dol_use_jmobile)) {
441if (empty(
$conf->use_javascript_ajax)) {
450if ($useajax || $action ==
'deletefile') {
452 if ($action ==
'deletefile') {
453 $urlfile =
GETPOST(
'urlfile',
'alpha');
456 if (empty($section_dir)) {
457 $section_dir =
GETPOST(
"file",
"alpha");
459 $section_id = $section;
461 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
463 $form =
new Form($db);
464 $formquestion = array();
465 $formquestion[
'urlfile'] = array(
'type' =>
'hidden',
'value' => $urlfile,
'name' =>
'urlfile');
466 $formquestion[
'section'] = array(
'type' =>
'hidden',
'value' => $section,
'name' =>
'section');
467 $formquestion[
'section_id'] = array(
'type' =>
'hidden',
'value' => $section_id,
'name' =>
'section_id');
468 $formquestion[
'section_dir'] = array(
'type' =>
'hidden',
'value' => $section_dir,
'name' =>
'section_dir');
469 $formquestion[
'sortfield'] = array(
'type' =>
'hidden',
'value' => $sortfield,
'name' =>
'sortfield');
470 $formquestion[
'sortorder'] = array(
'type' =>
'hidden',
'value' => $sortorder,
'name' =>
'sortorder');
471 if (!empty($action) && $action ==
'file_manager') {
472 $formquestion[
'file_manager'] = array(
'type' =>
'hidden',
'value' => 1,
'name' =>
'file_manager');
474 if (!empty($websitekey)) {
475 $formquestion[
'website'] = array(
'type' =>
'hidden',
'value' => $websitekey,
'name' =>
'website');
477 if (!empty($pageid) && $pageid > 0) {
478 $formquestion[
'pageid'] = array(
'type' =>
'hidden',
'value' => $pageid,
'name' =>
'pageid');
481 print $form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"),
'confirm_deletefile', $formquestion,
"no", ($useajax ?
'deletefile' : 0));
485 print
'<!-- ajaxdirpreview.php: js to manage preview of doc -->'.
"\n";
486 print
'<script nonce="'.getNonce().
'" type="text/javascript">';
491 if (
$conf->browser->layout !=
'phone') {
492 print
"\n/* JS CODE TO ENABLE document_preview */\n";
494 jQuery(document).ready(function () {
495 jQuery(".documentpreview").click(function () {
496 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
497 document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\');
504 // Enable jquery handlers button to delete files
505 print 'jQuery(document).ready(
function() {
'."\n";
506 print ' jQuery(
".deletefilelink").click(
function(e) {
'."\n";
507 print ' console.log(
"We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(
this).attr(
"rel"));
'."\n";
508 print ' jQuery(
"#urlfile").val(jQuery(
this).attr(
"rel"));
'."\n";
509 //print ' jQuery(
"#section_dir").val(\
'aaa\');'.
"\n";
510 print
' jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
511 print
' return false;'.
"\n";
514 print
'</script>'.
"\n";
518if ((!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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.