32if (!defined(
'NOTOKENRENEWAL')) {
33 define(
'NOTOKENRENEWAL', 1);
35if (!defined(
'NOREQUIREMENU')) {
36 define(
'NOREQUIREMENU',
'1');
38if (!defined(
'NOREQUIREHTML')) {
39 define(
'NOREQUIREHTML',
'1');
41if (!defined(
'NOREQUIREAJAX')) {
42 define(
'NOREQUIREAJAX',
'1');
53if (!isset($mode) || $mode !=
'noajax') {
54 require_once
'../../main.inc.php';
55 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
56 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
57 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
59 $action =
GETPOST(
'action',
'aZ09');
60 $file = urldecode(
GETPOST(
'file',
'alpha'));
61 $section =
GETPOST(
"section",
'alpha');
62 $module =
GETPOST(
"module",
'alpha');
63 $urlsource =
GETPOST(
"urlsource",
'alpha');
64 $search_doc_ref =
GETPOST(
'search_doc_ref',
'alpha');
67 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
68 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
70 $showonrightsize =
'';
72 if (empty($page) || $page == -1) {
75 $offset = $limit * $page;
76 $pageprev = $page - 1;
77 $pagenext = $page + 1;
85 $rootdirfordoc =
$conf->ecm->dir_output;
87 $upload_dir = dirname(str_replace(
"../",
"/", $rootdirfordoc.
'/'.$file));
91 $result = $ecmdir->fetch($section);
100 @phan-var-force int $section
101 @phan-var-force string $module
102 @phan-var-force string $showonrightsize
104 $rootdirfordoc =
$conf->ecm->dir_output;
109 $result = $ecmdir->fetch($section);
110 if (!($result > 0)) {
115 $relativepath = $ecmdir->getRelativePath();
116 } elseif (
GETPOST(
'section_dir')) {
117 $relativepath =
GETPOST(
'section_dir');
121 $upload_dir = $rootdirfordoc.
'/'.$relativepath;
125 if (!empty($module) && $module ==
'medias' && !
GETPOST(
'website')) {
126 $url = DOL_URL_ROOT.
'/ecm/index_medias.php';
127 } elseif (GETPOSTISSET(
'website')) {
128 $url = DOL_URL_ROOT.
'/website/index.php';
130 $url = DOL_URL_ROOT.
'/ecm/index.php';
135$langs->loadLangs(array(
"ecm",
"companies",
"other"));
137if (empty($modulepart)) {
138 $modulepart = $module;
142if ($user->socid > 0) {
143 $socid = $user->socid;
146if (preg_match(
'/\.\./', $upload_dir) || preg_match(
'/[<>|]/', $upload_dir)) {
147 dol_syslog(
"Refused to deliver file ".$upload_dir);
149 dol_print_error(
null, $langs->trans(
"ErrorFileNameInvalid", $upload_dir));
153if ($modulepart ==
'ecm') {
154 if (!$user->hasRight(
'ecm',
'read')) {
157} elseif ($modulepart ==
'medias' || $modulepart ==
'website') {
176if (!isset($mode) || $mode !=
'noajax') {
178 header(
'Cache-Control: Public, must-revalidate');
179 header(
'Pragma: public');
194print
'<!-- ajaxdirpreview type='.$type.
' module='.$module.
' modulepart='.$modulepart.
'-->'.
"\n";
197$param = ($sortfield ?
'&sortfield='.urlencode($sortfield) :
'').($sortorder ?
'&sortorder='.urlencode($sortorder) :
'');
198if (!empty($websitekey)) {
199 $param .=
'&website='.urlencode($websitekey);
201if (!empty($pageid)) {
202 $param .=
'&pageid='.((int) $pageid);
207if ($type ==
'directory') {
211 $excludefiles = array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$');
212 $sorting = (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC);
215 $automodules = array(
234 'recruitment-recruitmentcandidature',
240 $parameters = array(
'modulepart' => $module);
241 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
242 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
243 $automodules[] = $hookmanager->resArray[
'module'];
247 if ($module ==
'company') {
248 $upload_dir =
$conf->societe->dir_output;
249 $excludefiles[] =
'^contact$';
250 } elseif ($module ==
'invoice') {
251 $upload_dir =
$conf->facture->dir_output;
252 } elseif ($module ==
'invoice_supplier') {
253 $upload_dir =
$conf->fournisseur->facture->dir_output;
254 } elseif ($module ==
'propal') {
255 $upload_dir =
$conf->propal->dir_output;
256 } elseif ($module ==
'supplier_proposal') {
257 $upload_dir =
$conf->supplier_proposal->dir_output;
258 } elseif ($module ==
'order') {
259 $upload_dir =
$conf->commande->dir_output;
260 } elseif ($module ==
'order_supplier') {
261 $upload_dir =
$conf->fournisseur->commande->dir_output;
262 } elseif ($module ==
'contract') {
263 $upload_dir =
$conf->contrat->dir_output;
264 } elseif ($module ==
'product') {
265 $upload_dir =
$conf->product->dir_output;
266 } elseif ($module ==
'tax') {
267 $upload_dir =
$conf->tax->dir_output;
268 $excludefiles[] =
'^vat$';
269 } elseif ($module ==
'tax-vat') {
270 $upload_dir =
$conf->tax->dir_output.
'/vat';
271 } elseif ($module ==
'salaries') {
272 $upload_dir =
$conf->salaries->dir_output;
273 } elseif ($module ==
'project') {
274 $upload_dir =
$conf->project->dir_output;
275 } elseif ($module ==
'project_task') {
276 $upload_dir =
$conf->project->dir_output;
277 } elseif ($module ==
'fichinter') {
278 $upload_dir =
$conf->ficheinter->dir_output;
279 } elseif ($module ==
'user') {
280 $upload_dir =
$conf->user->dir_output;
281 } elseif ($module ==
'expensereport') {
282 $upload_dir =
$conf->expensereport->dir_output;
283 } elseif ($module ==
'holiday') {
284 $upload_dir =
$conf->holiday->dir_output;
285 } elseif ($module ==
'recruitment-recruitmentcandidature') {
286 $upload_dir =
$conf->recruitment->dir_output.
'/recruitmentcandidature';
287 } elseif ($module ==
'banque') {
288 $upload_dir =
$conf->bank->dir_output;
289 } elseif ($module ==
'chequereceipt') {
290 $upload_dir =
$conf->bank->dir_output.
'/checkdeposits';
291 } elseif ($module ==
'mrp-mo') {
292 $upload_dir =
$conf->mrp->dir_output;
294 $parameters = array(
'modulepart' => $module);
295 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
296 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
297 $upload_dir = $hookmanager->resArray[
'directory'];
302 if (in_array($module, $automodules)) {
303 $param .=
'&module='.$module;
304 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
305 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
308 $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
310 $filter = preg_quote((
string) $search_doc_ref,
'/');
311 $filearray =
dol_dir_list($upload_dir,
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
315 if ($user->socid > 0) {
316 $filearrayallowedtoexternal = array();
322 foreach ($filearray as $key => $val) {
323 if (!in_array($upload_dir.
'/'.$val[
'relativename'], $filearrayallowedtoexternal)) {
324 unset($filearray[$key]);
329 $perm = $user->hasRight(
'ecm',
'upload');
331 $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1,
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
334 if ($module ==
'medias') {
346 $relativepath =
GETPOST(
'file',
'alpha') ?
GETPOST(
'file',
'alpha') :
GETPOST(
'section_dir',
'alpha');
347 if ($relativepath && $relativepath !=
'/') {
348 $relativepath .=
'/';
350 $upload_dir = $dolibarr_main_data_root.
'/'.$module.
'/'.$relativepath;
351 if (GETPOSTISSET(
'website') || GETPOSTISSET(
'file_manager')) {
352 $param .=
'&file_manager=1';
353 if (!preg_match(
'/website=/', $param) &&
GETPOST(
'website',
'alpha')) {
354 $param .=
'&website='.urlencode(
GETPOST(
'website',
'alpha'));
356 if (!preg_match(
'/pageid=/', $param)) {
357 $param .=
'&pageid='.GETPOSTINT(
'pageid');
362 $relativepath = $ecmdir->getRelativePath();
363 $upload_dir =
$conf->ecm->dir_output.
'/'.$relativepath;
367 if (($section ===
'0' || empty($section)) && ($module !=
'medias')) {
368 $filearray = array();
370 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'', array(
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^CVS$'), $sortfield, $sorting, 1);
374 $param .=
'§ion='.$section;
375 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
376 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
379 $textifempty = $langs->trans(
'NoFileFound');
380 } elseif ($section ===
'0') {
381 if ($module ==
'ecm') {
382 $textifempty =
'<br><div class="center"><span class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</span></div><br>';
384 $textifempty = $langs->trans(
'NoFileFound');
387 $textifempty = ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
391 if ($module ==
'medias') {
393 $modulepart =
'medias';
394 $perm = ($user->hasRight(
"website",
"write") || $user->hasRight(
"emailing",
"creer"));
396 } elseif ($module ==
'ecm') {
397 if ($user->hasRight(
"ecm",
"read")) {
402 if ($user->hasRight(
"ecm",
"upload")) {
407 if ($user->hasRight(
"ecm",
"setup")) {
412 $perm = $user->hasRight(
"ecm",
"upload");
418 $perm = $user->hasRight(
"ecm",
"upload");
425 $formfile->list_of_documents($filearray,
null, $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm,
'', $sortfield, $sortorder);
433if (!empty(
$conf->dol_use_jmobile)) {
436if (empty(
$conf->use_javascript_ajax)) {
445if ($useajax || $action ==
'deletefile') {
447 if ($action ==
'deletefile') {
448 $urlfile =
GETPOST(
'urlfile',
'alpha');
451 if (empty($section_dir)) {
452 $section_dir =
GETPOST(
"file",
"alpha");
454 $section_id = $section;
456 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
458 $form =
new Form($db);
459 $formquestion = array();
460 $formquestion[
'urlfile'] = array(
'type' =>
'hidden',
'value' => $urlfile,
'name' =>
'urlfile');
461 $formquestion[
'section'] = array(
'type' =>
'hidden',
'value' => $section,
'name' =>
'section');
462 $formquestion[
'section_id'] = array(
'type' =>
'hidden',
'value' => $section_id,
'name' =>
'section_id');
463 $formquestion[
'section_dir'] = array(
'type' =>
'hidden',
'value' => $section_dir,
'name' =>
'section_dir');
464 $formquestion[
'sortfield'] = array(
'type' =>
'hidden',
'value' => $sortfield,
'name' =>
'sortfield');
465 $formquestion[
'sortorder'] = array(
'type' =>
'hidden',
'value' => $sortorder,
'name' =>
'sortorder');
466 if (!empty($action) && $action ==
'file_manager') {
467 $formquestion[
'file_manager'] = array(
'type' =>
'hidden',
'value' => 1,
'name' =>
'file_manager');
469 if (!empty($websitekey)) {
470 $formquestion[
'website'] = array(
'type' =>
'hidden',
'value' => $websitekey,
'name' =>
'website');
472 if (!empty($pageid) && $pageid > 0) {
473 $formquestion[
'pageid'] = array(
'type' =>
'hidden',
'value' => $pageid,
'name' =>
'pageid');
476 print $form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"),
'confirm_deletefile', $formquestion,
"no", ($useajax ?
'deletefile' : 0));
480 print
'<!-- ajaxdirpreview.php: js to manage preview of doc -->'.
"\n";
481 print
'<script nonce="'.getNonce().
'" type="text/javascript">';
486 if (
$conf->browser->layout !=
'phone') {
487 print
"\n/* JS CODE TO ENABLE document_preview */\n";
489 jQuery(document).ready(function () {
490 jQuery(".documentpreview").click(function () {
491 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
492 document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\');
499 // Enable jquery handlers button to delete files
500 print 'jQuery(document).ready(
function() {
'."\n";
501 print ' jQuery(
".deletefilelink").click(
function(e) {
'."\n";
502 print ' console.log(
"We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(
this).attr(
"rel"));
'."\n";
503 print ' jQuery(
"#urlfile").val(jQuery(
this).attr(
"rel"));
'."\n";
504 //print ' jQuery(
"#section_dir").val(\
'aaa\');'.
"\n";
505 print
' jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
506 print
' return false;'.
"\n";
509 print
'</script>'.
"\n";
513if ((!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.