31if (!defined(
'NOTOKENRENEWAL')) {
32 define(
'NOTOKENRENEWAL', 1);
34if (!defined(
'NOREQUIREMENU')) {
35 define(
'NOREQUIREMENU',
'1');
37if (!defined(
'NOREQUIREHTML')) {
38 define(
'NOREQUIREHTML',
'1');
40if (!defined(
'NOREQUIREAJAX')) {
41 define(
'NOREQUIREAJAX',
'1');
44if (!isset($mode) || $mode !=
'noajax') {
45 require_once
'../../main.inc.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
50 $action =
GETPOST(
'action',
'aZ09');
51 $file = urldecode(
GETPOST(
'file',
'alpha'));
52 $section =
GETPOST(
"section",
'alpha');
53 $module =
GETPOST(
"module",
'alpha');
54 $urlsource =
GETPOST(
"urlsource",
'alpha');
55 $search_doc_ref =
GETPOST(
'search_doc_ref',
'alpha');
58 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
59 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
61 if (empty($page) || $page == -1) {
64 $offset = $limit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
74 $rootdirfordoc = $conf->ecm->dir_output;
76 $upload_dir = dirname(str_replace(
"../",
"/", $rootdirfordoc.
'/'.$file));
80 $result = $ecmdir->fetch($section);
88 $rootdirfordoc = $conf->ecm->dir_output;
93 $result = $ecmdir->fetch($section);
99 $relativepath = $ecmdir->getRelativePath();
100 } elseif (
GETPOST(
'section_dir')) {
101 $relativepath =
GETPOST(
'section_dir');
105 $upload_dir = $rootdirfordoc.
'/'.$relativepath;
109 if (!empty($module) && $module ==
'medias' && !
GETPOST(
'website')) {
110 $url = DOL_URL_ROOT.
'/ecm/index_medias.php';
111 } elseif (GETPOSTISSET(
'website')) {
112 $url = DOL_URL_ROOT.
'/website/index.php';
114 $url = DOL_URL_ROOT.
'/ecm/index.php';
119$langs->loadLangs(array(
"ecm",
"companies",
"other"));
121if (empty($modulepart)) {
122 $modulepart = $module;
126if ($user->socid > 0) {
127 $socid = $user->socid;
130if (preg_match(
'/\.\./', $upload_dir) || preg_match(
'/[<>|]/', $upload_dir)) {
131 dol_syslog(
"Refused to deliver file ".$upload_dir);
133 dol_print_error(
null, $langs->trans(
"ErrorFileNameInvalid", $upload_dir));
137if ($modulepart ==
'ecm') {
138 if (!$user->hasRight(
'ecm',
'read')) {
141} elseif ($modulepart ==
'medias' || $modulepart ==
'website') {
160if (!isset($mode) || $mode !=
'noajax') {
162 header(
'Cache-Control: Public, must-revalidate');
163 header(
'Pragma: public');
178print
'<!-- ajaxdirpreview type='.$type.
' module='.$module.
' modulepart='.$modulepart.
'-->'.
"\n";
181$param = ($sortfield ?
'&sortfield='.urlencode($sortfield) :
'').($sortorder ?
'&sortorder='.urlencode($sortorder) :
'');
182if (!empty($websitekey)) {
183 $param .=
'&website='.urlencode($websitekey);
185if (!empty($pageid)) {
186 $param .=
'&pageid='.((int) $pageid);
191if ($type ==
'directory') {
195 $excludefiles = array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$');
196 $sorting = (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC);
199 $automodules = array(
218 'recruitment-recruitmentcandidature',
224 $parameters = array(
'modulepart' => $module);
225 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
226 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
227 $automodules[] = $hookmanager->resArray[
'module'];
231 if ($module ==
'company') {
232 $upload_dir = $conf->societe->dir_output;
233 $excludefiles[] =
'^contact$';
234 } elseif ($module ==
'invoice') {
235 $upload_dir = $conf->facture->dir_output;
236 } elseif ($module ==
'invoice_supplier') {
237 $upload_dir = $conf->fournisseur->facture->dir_output;
238 } elseif ($module ==
'propal') {
239 $upload_dir = $conf->propal->dir_output;
240 } elseif ($module ==
'supplier_proposal') {
241 $upload_dir = $conf->supplier_proposal->dir_output;
242 } elseif ($module ==
'order') {
243 $upload_dir = $conf->commande->dir_output;
244 } elseif ($module ==
'order_supplier') {
245 $upload_dir = $conf->fournisseur->commande->dir_output;
246 } elseif ($module ==
'contract') {
247 $upload_dir = $conf->contrat->dir_output;
248 } elseif ($module ==
'product') {
249 $upload_dir = $conf->product->dir_output;
250 } elseif ($module ==
'tax') {
251 $upload_dir = $conf->tax->dir_output;
252 $excludefiles[] =
'^vat$';
253 } elseif ($module ==
'tax-vat') {
254 $upload_dir = $conf->tax->dir_output.
'/vat';
255 } elseif ($module ==
'salaries') {
256 $upload_dir = $conf->salaries->dir_output;
257 } elseif ($module ==
'project') {
258 $upload_dir = $conf->project->dir_output;
259 } elseif ($module ==
'project_task') {
260 $upload_dir = $conf->project->dir_output;
261 } elseif ($module ==
'fichinter') {
262 $upload_dir = $conf->ficheinter->dir_output;
263 } elseif ($module ==
'user') {
264 $upload_dir = $conf->user->dir_output;
265 } elseif ($module ==
'expensereport') {
266 $upload_dir = $conf->expensereport->dir_output;
267 } elseif ($module ==
'holiday') {
268 $upload_dir = $conf->holiday->dir_output;
269 } elseif ($module ==
'recruitment-recruitmentcandidature') {
270 $upload_dir = $conf->recruitment->dir_output.
'/recruitmentcandidature';
271 } elseif ($module ==
'banque') {
272 $upload_dir = $conf->bank->dir_output;
273 } elseif ($module ==
'chequereceipt') {
274 $upload_dir = $conf->bank->dir_output.
'/checkdeposits';
275 } elseif ($module ==
'mrp-mo') {
276 $upload_dir = $conf->mrp->dir_output;
278 $parameters = array(
'modulepart' => $module);
279 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
280 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
281 $upload_dir = $hookmanager->resArray[
'directory'];
286 if (in_array($module, $automodules)) {
287 $param .=
'&module='.$module;
288 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
289 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
292 $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
294 $filter = preg_quote($search_doc_ref,
'/');
295 $filearray =
dol_dir_list($upload_dir,
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
297 $perm = $user->hasRight(
'ecm',
'upload');
299 $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1,
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
302 if ($module ==
'medias') {
314 $relativepath =
GETPOST(
'file',
'alpha') ?
GETPOST(
'file',
'alpha') :
GETPOST(
'section_dir',
'alpha');
315 if ($relativepath && $relativepath !=
'/') {
316 $relativepath .=
'/';
318 $upload_dir = $dolibarr_main_data_root.
'/'.$module.
'/'.$relativepath;
319 if (GETPOSTISSET(
'website') || GETPOSTISSET(
'file_manager')) {
320 $param .=
'&file_manager=1';
321 if (!preg_match(
'/website=/', $param) &&
GETPOST(
'website',
'alpha')) {
322 $param .=
'&website='.urlencode(
GETPOST(
'website',
'alpha'));
324 if (!preg_match(
'/pageid=/', $param)) {
325 $param .=
'&pageid='.GETPOSTINT(
'pageid');
330 $relativepath = $ecmdir->getRelativePath();
331 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
335 if (($section ===
'0' || empty($section)) && ($module !=
'medias')) {
336 $filearray = array();
338 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'', array(
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^CVS$'), $sortfield, $sorting, 1);
342 $param .=
'§ion='.$section;
343 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
344 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
347 $textifempty = $langs->trans(
'NoFileFound');
348 } elseif ($section ===
'0') {
349 if ($module ==
'ecm') {
350 $textifempty =
'<br><div class="center"><span class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</span></div><br>';
352 $textifempty = $langs->trans(
'NoFileFound');
355 $textifempty = ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
358 if ($module ==
'medias') {
360 $modulepart =
'medias';
361 $perm = ($user->hasRight(
"website",
"write") || $user->hasRight(
"emailing",
"creer"));
363 } elseif ($module ==
'ecm') {
364 if ($user->hasRight(
"ecm",
"read")) {
369 if ($user->hasRight(
"ecm",
"upload")) {
374 if ($user->hasRight(
"ecm",
"setup")) {
379 $perm = $user->hasRight(
"ecm",
"upload");
385 $perm = $user->hasRight(
"ecm",
"upload");
392 $formfile->list_of_documents($filearray,
'', $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm,
'', $sortfield, $sortorder);
400if (!empty($conf->dol_use_jmobile)) {
403if (empty($conf->use_javascript_ajax)) {
412if ($useajax || $action ==
'deletefile') {
414 if ($action ==
'deletefile') {
415 $urlfile =
GETPOST(
'urlfile',
'alpha');
418 if (empty($section_dir)) {
419 $section_dir =
GETPOST(
"file",
"alpha");
421 $section_id = $section;
423 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
425 $form =
new Form($db);
426 $formquestion = array();
427 $formquestion[
'urlfile'] = array(
'type' =>
'hidden',
'value' => $urlfile,
'name' =>
'urlfile');
428 $formquestion[
'section'] = array(
'type' =>
'hidden',
'value' => $section,
'name' =>
'section');
429 $formquestion[
'section_id'] = array(
'type' =>
'hidden',
'value' => $section_id,
'name' =>
'section_id');
430 $formquestion[
'section_dir'] = array(
'type' =>
'hidden',
'value' => $section_dir,
'name' =>
'section_dir');
431 $formquestion[
'sortfield'] = array(
'type' =>
'hidden',
'value' => $sortfield,
'name' =>
'sortfield');
432 $formquestion[
'sortorder'] = array(
'type' =>
'hidden',
'value' => $sortorder,
'name' =>
'sortorder');
433 if (!empty($action) && $action ==
'file_manager') {
434 $formquestion[
'file_manager'] = array(
'type' =>
'hidden',
'value' => 1,
'name' =>
'file_manager');
436 if (!empty($websitekey)) {
437 $formquestion[
'website'] = array(
'type' =>
'hidden',
'value' => $websitekey,
'name' =>
'website');
439 if (!empty($pageid) && $pageid > 0) {
440 $formquestion[
'pageid'] = array(
'type' =>
'hidden',
'value' => $pageid,
'name' =>
'pageid');
443 print $form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"),
'confirm_deletefile', $formquestion,
"no", ($useajax ?
'deletefile' : 0));
447 print
'<!-- ajaxdirpreview.php: js to manage preview of doc -->'.
"\n";
448 print
'<script nonce="'.getNonce().
'" type="text/javascript">';
453 if ($conf->browser->layout !=
'phone') {
454 print
"\n/* JS CODE TO ENABLE document_preview */\n";
456 jQuery(document).ready(function () {
457 jQuery(".documentpreview").click(function () {
458 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
459 document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\');
466 // Enable jquery handlers button to delete files
467 print 'jQuery(document).ready(
function() {
'."\n";
468 print ' jQuery(
".deletefilelink").click(
function(e) {
'."\n";
469 print ' console.log(
"We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(
this).attr(
"rel"));
'."\n";
470 print ' jQuery(
"#urlfile").val(jQuery(
this).attr(
"rel"));
'."\n";
471 //print ' jQuery(
"#section_dir").val(\
'aaa\');'.
"\n";
472 print
' jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
473 print
' return false;'.
"\n";
476 print
'</script>'.
"\n";
480if ((!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 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.