30if (!defined(
'NOTOKENRENEWAL')) {
31 define(
'NOTOKENRENEWAL', 1);
33if (!defined(
'NOREQUIREMENU')) {
34 define(
'NOREQUIREMENU',
'1');
36if (!defined(
'NOREQUIREHTML')) {
37 define(
'NOREQUIREHTML',
'1');
39if (!defined(
'NOREQUIREAJAX')) {
40 define(
'NOREQUIREAJAX',
'1');
43if (!isset($mode) || $mode !=
'noajax') {
44 require_once
'../../main.inc.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
49 $action =
GETPOST(
'action',
'aZ09');
50 $file = urldecode(
GETPOST(
'file',
'alpha'));
51 $section =
GETPOST(
"section",
'alpha');
52 $module =
GETPOST(
"module",
'alpha');
53 $urlsource =
GETPOST(
"urlsource",
'alpha');
54 $search_doc_ref =
GETPOST(
'search_doc_ref',
'alpha');
56 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
57 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
58 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
59 $page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
60 if (empty($page) || $page == -1) {
63 $offset = $limit * $page;
64 $pageprev = $page - 1;
65 $pagenext = $page + 1;
73 $rootdirfordoc = $conf->ecm->dir_output;
75 $upload_dir = dirname(str_replace(
"../",
"/", $rootdirfordoc.
'/'.$file));
79 $result = $ecmdir->fetch($section);
87 $rootdirfordoc = $conf->ecm->dir_output;
92 $result = $ecmdir->fetch($section);
98 $relativepath = $ecmdir->getRelativePath();
99 } elseif (
GETPOST(
'section_dir')) {
100 $relativepath =
GETPOST(
'section_dir');
104 $upload_dir = $rootdirfordoc.
'/'.$relativepath;
108 if (!empty($module) && $module ==
'medias' && !
GETPOST(
'website')) {
109 $url = DOL_URL_ROOT.
'/ecm/index_medias.php';
110 } elseif (GETPOSTISSET(
'website')) {
111 $url = DOL_URL_ROOT.
'/website/index.php';
113 $url = DOL_URL_ROOT.
'/ecm/index.php';
118$langs->loadLangs(array(
"ecm",
"companies",
"other"));
120if (empty($modulepart)) {
121 $modulepart = $module;
125if ($user->socid > 0) {
126 $socid = $user->socid;
129if (preg_match(
'/\.\./', $upload_dir) || preg_match(
'/[<>|]/', $upload_dir)) {
130 dol_syslog(
"Refused to deliver file ".$upload_dir);
132 dol_print_error(0, $langs->trans(
"ErrorFileNameInvalid", $upload_dir));
136if ($modulepart ==
'ecm') {
137 if (!$user->hasRight(
'ecm',
'read')) {
140} elseif ($modulepart ==
'medias' || $modulepart ==
'website') {
159if (!isset($mode) || $mode !=
'noajax') {
161 header(
'Cache-Control: Public, must-revalidate');
162 header(
'Pragma: public');
177print
'<!-- ajaxdirpreview type='.$type.
' module='.$module.
' modulepart='.$modulepart.
'-->'.
"\n";
180$param = ($sortfield ?
'&sortfield='.urlencode($sortfield) :
'').($sortorder ?
'&sortorder='.urlencode($sortorder) :
'');
181if (!empty($websitekey)) {
182 $param .=
'&website='.urlencode($websitekey);
184if (!empty($pageid)) {
185 $param .=
'&pageid='.urlencode($pageid);
190if ($type ==
'directory') {
194 $excludefiles = array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$');
195 $sorting = (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC);
198 $automodules = array(
217 'recruitment-recruitmentcandidature',
223 $parameters = array(
'modulepart'=>$module);
224 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
225 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
226 $automodules[] = $hookmanager->resArray[
'module'];
230 if ($module ==
'company') {
231 $upload_dir = $conf->societe->dir_output;
232 $excludefiles[] =
'^contact$';
233 } elseif ($module ==
'invoice') {
234 $upload_dir = $conf->facture->dir_output;
235 } elseif ($module ==
'invoice_supplier') {
236 $upload_dir = $conf->fournisseur->facture->dir_output;
237 } elseif ($module ==
'propal') {
238 $upload_dir = $conf->propal->dir_output;
239 } elseif ($module ==
'supplier_proposal') {
240 $upload_dir = $conf->supplier_proposal->dir_output;
241 } elseif ($module ==
'order') {
242 $upload_dir = $conf->commande->dir_output;
243 } elseif ($module ==
'order_supplier') {
244 $upload_dir = $conf->fournisseur->commande->dir_output;
245 } elseif ($module ==
'contract') {
246 $upload_dir = $conf->contrat->dir_output;
247 } elseif ($module ==
'product') {
248 $upload_dir = $conf->product->dir_output;
249 } elseif ($module ==
'tax') {
250 $upload_dir = $conf->tax->dir_output;
251 $excludefiles[] =
'^vat$';
252 } elseif ($module ==
'tax-vat') {
253 $upload_dir = $conf->tax->dir_output.
'/vat';
254 } elseif ($module ==
'salaries') {
255 $upload_dir = $conf->salaries->dir_output;
256 } elseif ($module ==
'project') {
257 $upload_dir = $conf->project->dir_output;
258 } elseif ($module ==
'project_task') {
259 $upload_dir = $conf->project->dir_output;
260 } elseif ($module ==
'fichinter') {
261 $upload_dir = $conf->ficheinter->dir_output;
262 } elseif ($module ==
'user') {
263 $upload_dir = $conf->user->dir_output;
264 } elseif ($module ==
'expensereport') {
265 $upload_dir = $conf->expensereport->dir_output;
266 } elseif ($module ==
'holiday') {
267 $upload_dir = $conf->holiday->dir_output;
268 } elseif ($module ==
'recruitment-recruitmentcandidature') {
269 $upload_dir = $conf->recruitment->dir_output.
'/recruitmentcandidature';
270 } elseif ($module ==
'banque') {
271 $upload_dir = $conf->bank->dir_output;
272 } elseif ($module ==
'chequereceipt') {
273 $upload_dir = $conf->bank->dir_output.
'/checkdeposits';
274 } elseif ($module ==
'mrp-mo') {
275 $upload_dir = $conf->mrp->dir_output;
277 $parameters = array(
'modulepart'=>$module);
278 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
279 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
280 $upload_dir = $hookmanager->resArray[
'directory'];
285 if (in_array($module, $automodules)) {
286 $param .=
'&module='.$module;
287 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
288 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
291 $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
293 $filter = preg_quote($search_doc_ref,
'/');
294 $filearray =
dol_dir_list($upload_dir,
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
296 $perm = $user->rights->ecm->upload;
298 $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1,
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
301 if ($module ==
'medias') {
313 $relativepath =
GETPOST(
'file',
'alpha') ?
GETPOST(
'file',
'alpha') :
GETPOST(
'section_dir',
'alpha');
314 if ($relativepath && $relativepath !=
'/') {
315 $relativepath .=
'/';
317 $upload_dir = $dolibarr_main_data_root.
'/'.$module.
'/'.$relativepath;
318 if (GETPOSTISSET(
'website') || GETPOSTISSET(
'file_manager')) {
319 $param .=
'&file_manager=1';
320 if (!preg_match(
'/website=/', $param) &&
GETPOST(
'website',
'alpha')) {
321 $param .=
'&website='.urlencode(
GETPOST(
'website',
'alpha'));
323 if (!preg_match(
'/pageid=/', $param)) {
324 $param .=
'&pageid='.urlencode(
GETPOST(
'pageid',
'int'));
329 $relativepath = $ecmdir->getRelativePath();
330 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
334 if (($section ===
'0' || empty($section)) && ($module !=
'medias')) {
335 $filearray = array();
337 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'', array(
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^CVS$'), $sortfield, $sorting, 1);
341 $param .=
'§ion='.$section;
342 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
343 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
346 $textifempty = $langs->trans(
'NoFileFound');
347 } elseif ($section ===
'0') {
348 if ($module ==
'ecm') {
349 $textifempty =
'<br><div class="center"><span class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</span></div><br>';
351 $textifempty = $langs->trans(
'NoFileFound');
354 $textifempty = ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
357 if ($module ==
'medias') {
359 $modulepart =
'medias';
360 $perm = ($user->hasRight(
"website",
"write") || $user->hasRight(
"emailing",
"creer"));
362 } elseif ($module ==
'ecm') {
363 if ($user->hasRight(
"ecm",
"read")) {
368 if ($user->hasRight(
"ecm",
"upload")) {
373 if ($user->hasRight(
"ecm",
"setup")) {
378 $perm = $user->hasRight(
"ecm",
"upload");
384 $perm = $user->hasRight(
"ecm",
"upload");
391 $formfile->list_of_documents($filearray,
'', $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm,
'', $sortfield, $sortorder);
399if (!empty($conf->dol_use_jmobile)) {
402if (empty($conf->use_javascript_ajax)) {
411if ($useajax || $action ==
'deletefile') {
413 if ($action ==
'deletefile') {
414 $urlfile =
GETPOST(
'urlfile',
'alpha');
417 if (empty($section_dir)) {
418 $section_dir =
GETPOST(
"file",
"alpha");
420 $section_id = $section;
422 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
424 $form =
new Form($db);
425 $formquestion[
'urlfile'] = array(
'type'=>
'hidden',
'value'=>$urlfile,
'name'=>
'urlfile');
426 $formquestion[
'section'] = array(
'type'=>
'hidden',
'value'=>$section,
'name'=>
'section');
427 $formquestion[
'section_id'] = array(
'type'=>
'hidden',
'value'=>$section_id,
'name'=>
'section_id');
428 $formquestion[
'section_dir'] = array(
'type'=>
'hidden',
'value'=>$section_dir,
'name'=>
'section_dir');
429 $formquestion[
'sortfield'] = array(
'type'=>
'hidden',
'value'=>$sortfield,
'name'=>
'sortfield');
430 $formquestion[
'sortorder'] = array(
'type'=>
'hidden',
'value'=>$sortorder,
'name'=>
'sortorder');
431 if (!empty($action) && $action ==
'file_manager') {
432 $formquestion[
'file_manager'] = array(
'type'=>
'hidden',
'value'=>1,
'name'=>
'file_manager');
434 if (!empty($websitekey)) {
435 $formquestion[
'website'] = array(
'type'=>
'hidden',
'value'=>$websitekey,
'name'=>
'website');
437 if (!empty($pageid) && $pageid > 0) {
438 $formquestion[
'pageid'] = array(
'type'=>
'hidden',
'value'=>$pageid,
'name'=>
'pageid');
441 print $form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"),
'confirm_deletefile', $formquestion,
"no", ($useajax ?
'deletefile' : 0));
445 print
'<!-- ajaxdirpreview.php: js to manage preview of doc -->'.
"\n";
446 print
'<script nonce="'.getNonce().
'" type="text/javascript">';
451 if ($conf->browser->layout !=
'phone') {
452 print
"\n/* JS CODE TO ENABLE document_preview */\n";
454 jQuery(document).ready(function () {
455 jQuery(".documentpreview").click(function () {
456 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
457 document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\');
464 // Enable jquery handlers button to delete files
465 print 'jQuery(document).ready(
function() {
'."\n";
466 print ' jQuery(
".deletefilelink").click(
function(e) {
'."\n";
467 print ' console.log(
"We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(
this).attr(
"rel"));
'."\n";
468 print ' jQuery(
"#urlfile").val(jQuery(
this).attr(
"rel"));
'."\n";
469 //print ' jQuery(
"#section_dir").val(\
'aaa\');'.
"\n";
470 print
' jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
471 print
' return false;'.
"\n";
474 print
'</script>'.
"\n";
478if ((!isset($mode) || $mode !=
'noajax') && is_object($db)) {
Class to manage ECM directories.
dol_dir_list($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.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.