dolibarr 25.0.0-alpha
ajaxdirpreview.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Simon Tosser <simon@kornog-computing.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2010 Pierre Morin <pierre.morin@auguria.net>
7 * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2025 Joachim Kueter <git-jk@bloxera.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
33if (!defined('NOTOKENRENEWAL')) {
34 define('NOTOKENRENEWAL', 1); // Disables token renewal
35}
36if (!defined('NOREQUIREMENU')) {
37 define('NOREQUIREMENU', '1');
38}
39if (!defined('NOREQUIREHTML')) {
40 define('NOREQUIREHTML', '1');
41}
42if (!defined('NOREQUIREAJAX')) {
43 define('NOREQUIREAJAX', '1');
44}
45
60'
61@phan-var-force ?string $mode
62';
63
64if (!isset($mode) || $mode != 'noajax') { // For ajax call
65 require_once '../../main.inc.php';
66 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
67 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
68 require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
69
70 $action = GETPOST('action', 'aZ09');
71 $file = urldecode(GETPOST('file', 'alpha'));
72 $section = GETPOST("section", 'alpha');
73 $module = GETPOST("module", 'alpha');
74 $urlsource = GETPOST("urlsource", 'alpha');
75 $search_doc_ref = GETPOST('search_doc_ref', 'alpha');
76 $search_doc_date_start = '';
77 $search_doc_date_end = '';
78 if (GETPOSTISSET('search_doc_date_start') || GETPOSTISSET('search_doc_date_startday') || GETPOSTISSET('search_doc_date_startmonth') || GETPOSTISSET('search_doc_date_startyear')) {
79 $search_doc_date_start = GETPOSTDATE('search_doc_date_start');
80 }
81 if (GETPOSTISSET('search_doc_date_end') || GETPOSTISSET('search_doc_date_endday') || GETPOSTISSET('search_doc_date_endmonth') || GETPOSTISSET('search_doc_date_endyear')) {
82 $search_doc_date_end = GETPOSTDATE('search_doc_date_end', 'end');
83 }
84
85 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
86 $sortfield = GETPOST("sortfield", 'aZ09comma');
87 $sortorder = GETPOST("sortorder", 'aZ09comma');
88 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
89 $showonrightsize = '';
90
91 if (empty($page) || $page == -1) {
92 $page = 0;
93 } // If $page is not defined, or '' or -1
94 $offset = $limit * $page;
95 $pageprev = $page - 1;
96 $pagenext = $page + 1;
97 if (!$sortorder) {
98 $sortorder = "ASC";
99 }
100 if (!$sortfield) {
101 $sortfield = "name";
102 }
103
104 $rootdirfordoc = $conf->ecm->dir_output;
105
106 $upload_dir = dirname(str_replace("../", "/", $rootdirfordoc.'/'.$file));
107
108 $ecmdir = new EcmDirectory($db);
109 if ($section > 0) {
110 $result = $ecmdir->fetch((int) $section);
111 //if (!($result > 0)) {
112 //dol_print_error($db,$ecmdir->error);
113 //exit;
114 //}
115 }
116} else {
117 // When no an ajax call (include from other file)
127 '
128 @phan-var-force int $section
129 @phan-var-force string $action
130 @phan-var-force string $module
131 @phan-var-force string $showonrightsize
132 @phan-var-force string $sortfield
133 @phan-var-force string $sortorder
134 ';
135
136 $rootdirfordoc = $conf->ecm->dir_output;
137
138 $ecmdir = new EcmDirectory($db);
139 $relativepath = '';
140 if ($section > 0) {
141 $result = $ecmdir->fetch($section);
142 if (!($result > 0)) {
143 dol_print_error($db, $ecmdir->error);
144 exit;
145 }
146
147 $relativepath = $ecmdir->getRelativePath(); // Example 'mydir/'
148 } elseif (GETPOST('section_dir')) {
149 $relativepath = GETPOST('section_dir');
150 }
151 //var_dump($section.'-'.GETPOST('section_dir').'-'.$relativepath);
152
153 $upload_dir = $rootdirfordoc.'/'.$relativepath;
154}
155
156if (empty($url)) { // autoset $url but it is better to have it defined before into filemanager.tpl.php (not possible when in auto tree)
157 if (!empty($module) && $module == 'medias' && !GETPOST('website')) {
158 $url = DOL_URL_ROOT.'/ecm/index_medias.php';
159 } elseif (GETPOSTISSET('website')) {
160 $url = DOL_URL_ROOT.'/website/index.php';
161 } else {
162 $url = DOL_URL_ROOT.'/ecm/index.php';
163 }
164}
165
166// Load translation files required by the page
167$langs->loadLangs(array("ecm", "companies", "other"));
168
169if (empty($modulepart)) {
170 $modulepart = $module;
171}
172
173// Security check
174if ($user->socid > 0) {
175 $socid = $user->socid;
176}
177// We forbid directory traversal as well as pipes in file names.
178if (preg_match('/\.\./', $upload_dir) || preg_match('/[<>|]/', $upload_dir)) {
179 dol_syslog("Refused to deliver file ".$upload_dir);
180 // Do no show plain path in shown error message
181 dol_print_error(null, $langs->trans("ErrorFileNameInvalid", $upload_dir));
182 exit;
183}
184// Check permissions
185if ($modulepart == 'ecm') {
186 if (!$user->hasRight('ecm', 'read')) {
188 }
189} elseif ($modulepart == 'medias' || $modulepart == 'website') {
190 // Always allowed
191} else {
193}
194
195
196/*
197 * Action
198 */
199
200// None
201
202
203
204/*
205 * View
206 */
207
208if (!isset($mode) || $mode != 'noajax') {
209 // Add directives to fix IE bug
210 header('Cache-Control: Public, must-revalidate');
211 header('Pragma: public');
212
213 top_httphead();
214}
215
216$type = 'directory';
217
218// This test if file exists should be useless. We keep it to find bug more easily
219if (!dol_is_dir($upload_dir)) {
220 //dol_mkdir($upload_dir);
221 /*$langs->load("install");
222 dol_print_error(0,$langs->trans("ErrorDirDoesNotExists",$upload_dir));
223 exit;*/
224}
225
226print '<!-- ajaxdirpreview mode='.$mode.' type='.$type.' module='.$module.' modulepart='.$modulepart.'-->'."\n";
227//print '<!-- Page called with mode='.dol_escape_htmltag(isset($mode)?$mode:'').' type='.dol_escape_htmltag($type).' module='.dol_escape_htmltag($module).' url='.dol_escape_htmltag($url).' '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
228
229$param = ($sortfield ? '&sortfield='.urlencode($sortfield) : '').($sortorder ? '&sortorder='.urlencode($sortorder) : '');
230if (!empty($websitekey)) {
231 $param .= '&website='.urlencode($websitekey);
232}
233if (!empty($pageid)) {
234 $param .= '&pageid='.((int) $pageid);
235}
236// Keep the popup mode (no menus) when the file manager is open into a dialog popup
237if (GETPOSTINT('dol_hide_topmenu')) {
238 $param .= '&dol_hide_topmenu='.GETPOSTINT('dol_hide_topmenu');
239}
240if (GETPOSTINT('dol_hide_leftmenu')) {
241 $param .= '&dol_hide_leftmenu='.GETPOSTINT('dol_hide_leftmenu');
242}
243if (GETPOST('dol_openinpopup', 'aZ09')) {
244 $param .= '&dol_openinpopup='.urlencode(GETPOST('dol_openinpopup', 'aZ09'));
245}
246
247
248// Dir scan
249if ($type == 'directory') {
250 $formfile = new FormFile($db);
251
252 $maxlengthname = 40;
253 $excludefiles = array('^SPECIMEN\.pdf$', '^\.', '(\.meta|_preview.*\.png)$', '^temp$', '^payments$', '^CVS$', '^thumbs$');
254 $sorting = (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC);
255
256 // Right area. If module is defined here, we are in automatic ecm.
257 $automodules = array(
258 'company',
259 'invoice',
260 'invoice_supplier',
261 'propal',
262 'supplier_proposal',
263 'order',
264 'order_supplier',
265 'contract',
266 'product',
267 'tax',
268 'tax-vat',
269 'salaries',
270 'project',
271 'project_task',
272 'fichinter',
273 'user',
274 'expensereport',
275 'holiday',
276 'recruitment-recruitmentcandidature',
277 'banque',
278 'bank-statement',
279 'chequereceipt',
280 'mrp-mo'
281 );
282
283 $parameters = array('modulepart' => $module);
284 $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters);
285 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
286 if (is_array($hookmanager->resArray['module'])) {
287 $automodules = array_merge($automodules, $hookmanager->resArray['module']);
288 } else {
289 $automodules[] = $hookmanager->resArray['module'];
290 }
291 }
292
293 // TODO change for multicompany sharing
294 if ($module == 'company') {
295 $upload_dir = $conf->societe->dir_output;
296 $excludefiles[] = '^contact$'; // The subdir 'contact' contains files of contacts.
297 } elseif ($module == 'invoice') {
298 $upload_dir = $conf->invoice->dir_output;
299 } elseif ($module == 'invoice_supplier') {
300 $upload_dir = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
301 } elseif ($module == 'propal') {
302 $upload_dir = $conf->propal->dir_output;
303 } elseif ($module == 'supplier_proposal') {
304 $upload_dir = $conf->supplier_proposal->dir_output;
305 } elseif ($module == 'order') {
306 $upload_dir = $conf->order->dir_output;
307 } elseif ($module == 'order_supplier') {
308 $upload_dir = $conf->fournisseur->commande->dir_output;
309 } elseif ($module == 'contract') {
310 $upload_dir = $conf->contract->dir_output;
311 } elseif ($module == 'product') {
312 $upload_dir = $conf->product->dir_output;
313 } elseif ($module == 'tax') {
314 $upload_dir = $conf->tax->dir_output;
315 $excludefiles[] = '^vat$'; // The subdir 'vat' contains files of vats.
316 } elseif ($module == 'tax-vat') {
317 $upload_dir = $conf->tax->dir_output.'/vat';
318 } elseif ($module == 'salaries') {
319 $upload_dir = $conf->salaries->dir_output;
320 } elseif ($module == 'project') {
321 $upload_dir = $conf->project->dir_output;
322 } elseif ($module == 'project_task') {
323 $upload_dir = $conf->project->dir_output;
324 } elseif ($module == 'fichinter') {
325 $upload_dir = $conf->ficheinter->dir_output;
326 } elseif ($module == 'user') {
327 $upload_dir = $conf->user->dir_output;
328 } elseif ($module == 'expensereport') {
329 $upload_dir = $conf->expensereport->dir_output;
330 } elseif ($module == 'holiday') {
331 $upload_dir = $conf->holiday->dir_output;
332 } elseif ($module == 'recruitment-recruitmentcandidature') {
333 $upload_dir = $conf->recruitment->dir_output.'/recruitmentcandidature';
334 } elseif ($module == 'banque') {
335 $upload_dir = $conf->bank->dir_output;
336 } elseif ($module == 'bank-statement') {
337 $upload_dir = $conf->bank->dir_output.'/*/statement';
338 } elseif ($module == 'chequereceipt') {
339 $upload_dir = $conf->bank->dir_output.'/checkdeposits';
340 } elseif ($module == 'mrp-mo') {
341 $upload_dir = $conf->mrp->dir_output;
342 } else {
343 $parameters = array('modulepart' => $module);
344 $reshook = $hookmanager->executeHooks('addSectionECMAuto', $parameters);
345 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
346 $upload_dir = $hookmanager->resArray['directory'];
347 }
348 }
349
350 // Automatic list
351 if (in_array($module, $automodules)) {
352 $param .= '&module='.urlencode($module);
353 if (isset($search_doc_ref) && $search_doc_ref != '') {
354 $param .= '&search_doc_ref='.urlencode($search_doc_ref);
355 }
356 if (!empty($search_doc_date_start)) {
357 $param .= '&search_doc_date_startday='.dol_print_date($search_doc_date_start, '%d');
358 $param .= '&search_doc_date_startmonth='.dol_print_date($search_doc_date_start, '%m');
359 $param .= '&search_doc_date_startyear='.dol_print_date($search_doc_date_start, '%Y');
360 }
361 if (!empty($search_doc_date_end)) {
362 $param .= '&search_doc_date_endday='.dol_print_date($search_doc_date_end, '%d');
363 $param .= '&search_doc_date_endmonth='.dol_print_date($search_doc_date_end, '%m');
364 $param .= '&search_doc_date_endyear='.dol_print_date($search_doc_date_end, '%Y');
365 }
366
367 $textifempty = ($section ? $langs->trans("NoFileFound") : ($showonrightsize == 'featurenotyetavailable' ? $langs->trans("FeatureNotYetAvailable") : $langs->trans("NoFileFound")));
368
369 $filter = preg_quote((string) $search_doc_ref, '/');
370 $filearray = dol_dir_list($upload_dir, "files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
371 if (!empty($search_doc_date_start) || !empty($search_doc_date_end)) {
372 foreach ($filearray as $key => $file) {
373 $filedate = empty($file['date']) ? 0 : (int) $file['date'];
374 if ((!empty($search_doc_date_start) && $filedate < $search_doc_date_start)
375 || (!empty($search_doc_date_end) && $filedate > $search_doc_date_end)
376 ) {
377 unset($filearray[$key]);
378 }
379 }
380 }
381 //var_dump($filearray);
382
383 // To allow external users,we must restrict $filearray to entries the user is a thirdparty.
384 // This can be done by filtering on entries found into llx_ecm
385 if ($user->socid > 0) {
386 $filearrayallowedtoexternal = array(); // 'fullpath' => array(...)
387
388 // Search files in ECM with select filepath.filename where src_object_type = $module and src_object_type EXISTS in (select rowid from $objecttablename WERE fk_soc = '.$user->socid.' and entity in getEntity($objecttbalename)
389 // TODO
390
391 // Now clean $filearray to keep only record also found into $filearrayallowedtoexternal.
392 foreach ($filearray as $key => $val) {
393 if (!in_array($upload_dir.'/'.$val['relativename'], $filearrayallowedtoexternal)) {
394 unset($filearray[$key]);
395 }
396 }
397 }
398
399 $perm = $user->hasRight('ecm', 'upload');
400
401 // Print list of files
402 $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1, '', $perm, 1, $textifempty, $maxlengthname, $url, 1);
403 } else {
404 // Manual list
405 if ($module == 'medias') {
406 /*
407 $_POST is array like
408 'token' => string '062380e11b7dcd009d07318b57b71750' (length=32)
409 'action' => string 'file_manager' (length=12)
410 'website' => string 'template' (length=8)
411 'pageid' => string '124' (length=3)
412 'section_dir' => string 'mydir/' (length=3)
413 'section_id' => string '0' (length=1)
414 'max_file_size' => string '2097152' (length=7)
415 'sendit' => string 'Envoyer fichier' (length=15)
416 */
417 $relativepath = GETPOST('file', 'alpha') ? GETPOST('file', 'alpha') : GETPOST('section_dir', 'alpha');
418 if ($relativepath && $relativepath != '/') {
419 $relativepath .= '/';
420 }
421 $upload_dir = $dolibarr_main_data_root.'/'.$module.'/'.$relativepath;
422 if (GETPOSTISSET('website') || GETPOSTISSET('file_manager')) {
423 $param .= '&file_manager=1';
424 if (!preg_match('/website=/', $param) && GETPOST('website', 'alpha')) {
425 $param .= '&website='.urlencode(GETPOST('website', 'alpha'));
426 }
427 if (!preg_match('/pageid=/', $param)) {
428 $param .= '&pageid='.GETPOSTINT('pageid');
429 }
430 //if (!preg_match('/backtopage=/',$param)) $param.='&backtopage='.urlencode($_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid);
431 }
432 } else {
433 $relativepath = $ecmdir->getRelativePath();
434 $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
435 }
436
437 // If $section defined with value 0
438 if (($section === '0' || empty($section)) && ($module != 'medias')) {
439 $filearray = array();
440 } else {
441 $filearray = dol_dir_list($upload_dir, "files", 0, '', array('^\.', '(\.meta|_preview.*\.png)$', '^temp$', '^CVS$'), $sortfield, $sorting, 1);
442 }
443
444 if ($section) {
445 $param .= '&section='.urlencode($section);
446 if (isset($search_doc_ref) && $search_doc_ref != '') {
447 $param .= '&search_doc_ref='.urlencode($search_doc_ref);
448 }
449
450 $textifempty = $langs->trans('NoFileFound');
451 } elseif ($section === '0') {
452 if ($module == 'ecm') {
453 $textifempty = '<br><div class="center"><span class="warning">'.$langs->trans("DirNotSynchronizedSyncFirst").'</span></div><br>';
454 } else {
455 $textifempty = $langs->trans('NoFileFound');
456 }
457 } else {
458 $textifempty = ($showonrightsize == 'featurenotyetavailable' ? $langs->trans("FeatureNotYetAvailable") : $langs->trans("ECMSelectASection"));
459 }
460
461 $useinecm = 0;
462 if ($module == 'medias') {
463 $useinecm = 6;
464 $modulepart = 'medias';
465 $perm = $user->hasRight("website", "write");
466 $title = 'none';
467 } elseif ($module == 'ecm') { // DMS/ECM -> manual structure
468 if ($user->hasRight("ecm", "read")) {
469 // Buttons: Preview
470 $useinecm = 2;
471 }
472
473 if ($user->hasRight("ecm", "upload")) {
474 // Buttons: Preview + Delete
475 $useinecm = 4;
476 }
477
478 if ($user->hasRight("ecm", "setup")) {
479 // Buttons: Preview + Delete + Edit
480 $useinecm = 5;
481 }
482
483 $perm = $user->hasRight("ecm", "upload");
484 $modulepart = 'ecm';
485 $title = ''; // Use default
486 } else {
487 $useinecm = 5;
488 $modulepart = 'ecm';
489 $perm = $user->hasRight("ecm", "upload");
490 $title = ''; // Use default
491 }
492
493 // When we show list of files for ECM files, $filearray contains file list, and directory is defined with modulepart + section into $param
494 // When we show list of files for a directory, $filearray ciontains file list, and directory is defined with modulepart + $relativepath
495 //var_dump("section=".$section." title=".$title." modulepart=".$modulepart." useinecm=".$useinecm." perm(permtoeditline)=".$perm." relativepath=".$relativepath." upload_dir=".$upload_dir." param=".$param." url=".$url);
496
497 $formfile->list_of_documents($filearray, null, $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm, $upload_dir, $sortfield, $sortorder, 1, 1);
498 }
499}
500
501
502
503// Bottom of page
504$useajax = 1;
505if (!empty($conf->dol_use_jmobile)) {
506 $useajax = 0;
507}
508if (empty($conf->use_javascript_ajax)) {
509 $useajax = 0;
510}
511if (getDolGlobalString('MAIN_ECM_DISABLE_JS')) {
512 $useajax = 0;
513}
514
515//$param.=($param?'?':'').(preg_replace('/^&/','',$param));
516
517if ($useajax || $action == 'deletefile') {
518 $urlfile = '';
519 if ($action == 'deletefile') {
520 $urlfile = GETPOST('urlfile', 'alpha');
521 }
522
523 if (empty($section_dir)) {
524 $section_dir = GETPOST("file", "alpha");
525 }
526 $section_id = $section;
527
528 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
529
530 $form = new Form($db);
531 $formquestion = array();
532 $formquestion['urlfile'] = array('type' => 'hidden', 'value' => $urlfile, 'name' => 'urlfile'); // We must always put field, even if empty because it is filled by javascript later
533 $formquestion['section'] = array('type' => 'hidden', 'value' => $section, 'name' => 'section'); // We must always put field, even if empty because it is filled by javascript later
534 $formquestion['section_id'] = array('type' => 'hidden', 'value' => $section_id, 'name' => 'section_id'); // We must always put field, even if empty because it is filled by javascript later
535 $formquestion['section_dir'] = array('type' => 'hidden', 'value' => $section_dir, 'name' => 'section_dir'); // We must always put field, even if empty because it is filled by javascript later
536 $formquestion['sortfield'] = array('type' => 'hidden', 'value' => $sortfield, 'name' => 'sortfield'); // We must always put field, even if empty because it is filled by javascript later
537 $formquestion['sortorder'] = array('type' => 'hidden', 'value' => $sortorder, 'name' => 'sortorder'); // We must always put field, even if empty because it is filled by javascript later
538 if (!empty($action) && $action == 'file_manager') {
539 $formquestion['file_manager'] = array('type' => 'hidden', 'value' => 1, 'name' => 'file_manager');
540 }
541 if (!empty($websitekey)) {
542 $formquestion['website'] = array('type' => 'hidden', 'value' => $websitekey, 'name' => 'website');
543 }
544 if (!empty($pageid) && $pageid > 0) {
545 $formquestion['pageid'] = array('type' => 'hidden', 'value' => $pageid, 'name' => 'pageid');
546 }
547 foreach (array('dol_hide_topmenu', 'dol_hide_leftmenu') as $tmpparam) {
548 if (GETPOSTINT($tmpparam)) {
549 $formquestion[$tmpparam] = array('type' => 'hidden', 'value' => GETPOSTINT($tmpparam), 'name' => $tmpparam);
550 }
551 }
552 if (GETPOST('dol_openinpopup', 'aZ09')) {
553 $formquestion['dol_openinpopup'] = array('type' => 'hidden', 'value' => GETPOST('dol_openinpopup', 'aZ09'), 'name' => 'dol_openinpopup');
554 }
555
556 print $form->formconfirm($url, $langs->trans("DeleteFile"), $langs->trans("ConfirmDeleteFile"), 'confirm_deletefile', $formquestion, "no", ($useajax ? 'deletefile' : 0));
557}
558
559if ($useajax) {
560 print '<!-- ajaxdirpreview.php: js to manage preview of doc -->'."\n";
561 print '<script nonce="'.getNonce().'" type="text/javascript">';
562
563 // Enable jquery handlers on new generated HTML objects (same code than into lib_footer.js.php)
564 // Because the content is reloaded by ajax call, we must also redefine/reenable some jquery hooks.
565
566 // Handler to manage document_preview on click on a .documentpreview css class.
567 if ($conf->browser->layout != 'phone') {
568 print "\n/* JS CODE TO ENABLE document_preview */\n";
569 print '
570 jQuery(document).ready(function () {
571 jQuery(".documentpreview").click(function () {
572 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
573 var titledocpreview = $(this).attr(\'data-title\');
574 if (titledocpreview == undefined || titledocpreview == "") {
575 titledocpreview = \''.dol_escape_js($langs->transnoentities("Preview")).'\'
576 }
577 document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), titledocpreview);
578 return false;
579 });
580 });
581 ' . "\n";
582 }
583
584 // Enable jquery handlers button to delete files
585 print 'jQuery(document).ready(function() {'."\n";
586 print ' jQuery(".deletefilelink").click(function(e) { '."\n";
587 print ' console.log("We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(this).attr("rel"));'."\n";
588 print ' jQuery("#urlfile").val(jQuery(this).attr("rel"));'."\n";
589 //print ' jQuery("#section_dir").val(\'aaa\');'."\n";
590 print ' jQuery("#dialog-confirm-deletefile").dialog("open");'."\n";
591 print ' return false;'."\n";
592 print ' });'."\n";
593 print '});'."\n";
594 print '</script>'."\n";
595}
596
597// Close db if mode is not noajax
598if ((!isset($mode) || $mode != 'noajax') && is_object($db)) {
599 $db->close();
600}
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage ECM directories.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
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.
Definition files.lib.php:66
dol_is_dir($folder)
Test if filename is a directory.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.