dolibarr 24.0.0-beta
enablefiletreeajax.tpl.php
1<?php
2/* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 *
20 * Output javascript for interactions code of ecm module
21 * $conf, $module, $param, $preopened, $nameforformuserfile may be defined
22 */
23
29'
30@phan-var-force string $param
31';
32// Protection to avoid direct call of template
33if (empty($conf) || !is_object($conf)) {
34 print "Error, template enablefiletreeajax.tpl.php can't be called as URL";
35 exit;
36}
37// Must have set $module, $nameforformuserfile, $preopened
38?>
39
40<!-- BEGIN PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->
41<!-- Doc of fileTree plugin at https://www.abeautifulsite.net/jquery-file-tree -->
42
43<script type="text/javascript">
44
45<?php
46if (empty($module)) {
47 $module = 'ecm';
48}
49if (empty($nameforformuserfile)) {
50 $nameforformuserfile = '';
51}
52$paramwithoutsection = preg_replace('/&?section=(\d+)/', '', $param);
53
54$openeddir = '/'; // The root directory shown
55// $preopened // The dir to have preopened
56
57?>
58
59$(document).ready(function() {
60
61 $('#filetree').fileTree({
62 root: '<?php print dol_escape_js($openeddir); ?>',
63 // Ajax called if we click to expand a dir (not a file). Parameter 'dir' is provided as a POST parameter by fileTree code to this following URL.
64 // We must use token=currentToken() and not newToken() here because ajaxdirtree has NOTOKENRENEWAL define so there is no rollup of token so we must compare with the one valid on main page
65 script: '<?php echo DOL_URL_ROOT.'/core/ajax/ajaxdirtree.php?token='.currentToken().'&modulepart='.urlencode($module).(empty($preopened) ? '' : '&preopened='.urlencode($preopened)).'&openeddir='.urlencode($openeddir).(empty($paramwithoutsection) ? '' : $paramwithoutsection); ?>',
66 folderEvent: 'click', // 'dblclick'
67 multiFolder: false },
68 // Called if we click on a file (not a dir)
69 function(file) {
70 console.log("We click on a file "+file);
71 $("#mesg").hide();
72 loadandshowpreview(file,0);
73 },
74 // Called if we click on a dir (not a file)
75 function(elem) {
76 id=elem.attr('id').substr(12); // We get id that is 'fmdirlia_id_xxx' (id we want is xxx)
77 rel=elem.attr('rel')
78 console.log("We click on a dir id="+id+", we call the ajaxdirtree.php with modulepart=<?php echo $module; ?>, param=<?php echo $paramwithoutsection; ?>");
79 console.log("We also save id and dir name into <?php echo $nameforformuserfile ?>_section_id|dir (vars into form to attach new file in filemanager.tpl.php) with id="+id+" and rel="+rel);
80 jQuery("#<?php echo $nameforformuserfile ?>_section_dir").val(rel);
81 jQuery("#<?php echo $nameforformuserfile ?>_section_id").val(id);
82 jQuery("#section_dir").val(rel);
83 jQuery("#section_id").val(id);
84 jQuery("#section").val(id);
85 jQuery('#<?php echo $nameforformuserfile ?>').show();
86 console.log("We also execute the loadandshowpreview() that is on the onclick of each li defined by ajaxdirtree");
87 }
88 // The loadanshowpreview is also call by the 'onclick' set on each li return by ajaxdirtree
89 );
90
91 $('#refreshbutton').click( function() {
92 console.log("Click on refreshbutton");
93
94 dolBlockUI("<?php echo $langs->transnoentities('PleaseBePatient'); ?>");
95
96 $.get("<?php echo DOL_URL_ROOT.'/ecm/ajax/ecmdatabase.php'; ?>", {
97 action: 'build',
98 token: '<?php echo newToken(); ?>',
99 element: 'ecm'
100 }, function(response) {
101 setTimeout(() => {
102 dolUnblockUI();
103
104 location.href='<?php echo $_SERVER['PHP_SELF']; ?>';
105 }, 1000); // delai 1s
106 });
107 });
108});
109
110function loadandshowpreview(filedirname,section)
111{
112 //alert('filedirname='+filedirname);
113 //console.log(filedirname);
114 //console.log('loadandshowpreview for section='+section);
115
116 $('#ecmfileview').empty();
117
118 var url = '<?php echo dol_buildpath('/core/ajax/ajaxdirpreview.php', 1); ?>?action=preview&module=<?php echo $module; ?>&section='+section+'&file='+urlencode(filedirname)<?php echo(empty($paramwithoutsection) ? '' : "+'".$paramwithoutsection."'"); ?>;
119 $.get(url, function(data) {
120 //alert('Load of url '+url+' was performed : '+data);
121 pos=data.indexOf("TYPE=directory",0);
122 //alert(pos);
123 if ((pos > 0) && (pos < 20))
124 {
125 filediractive=filedirname; // Save current dirname
126 filetypeactive='directory';
127 }
128 else
129 {
130 filediractive=filedirname; // Save current dirname
131 filetypeactive='file';
132 }
133 $('#ecmfileview').append(data);
134 });
135}
136
137</script>
138<!-- END PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130