dolibarr 23.0.3
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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * Output javascript for interactions code of ecm module
20 * $conf, $module, $param, $preopened, $nameforformuserfile may be defined
21 */
22
27// Protection to avoid direct call of template
28if (empty($conf) || !is_object($conf)) {
29 print "Error, template enablefiletreeajax.tpl.php can't be called as URL";
30 exit;
31}
32// Must have set $module, $nameforformuserfile, $preopened
33?>
34
35<!-- BEGIN PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->
36<!-- Doc of fileTree plugin at https://www.abeautifulsite.net/jquery-file-tree -->
37
38<script type="text/javascript">
39
40<?php
41if (empty($module)) {
42 $module = 'ecm';
43}
44if (empty($nameforformuserfile)) {
45 $nameforformuserfile = '';
46}
47$paramwithoutsection = preg_replace('/&?section=(\d+)/', '', $param);
48
49$openeddir = '/'; // The root directory shown
50// $preopened // The dir to have preopened
51
52?>
53
54$(document).ready(function() {
55
56 $('#filetree').fileTree({
57 root: '<?php print dol_escape_js($openeddir); ?>',
58 // 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.
59 // 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
60 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); ?>',
61 folderEvent: 'click', // 'dblclick'
62 multiFolder: false },
63 // Called if we click on a file (not a dir)
64 function(file) {
65 console.log("We click on a file "+file);
66 $("#mesg").hide();
67 loadandshowpreview(file,0);
68 },
69 // Called if we click on a dir (not a file)
70 function(elem) {
71 id=elem.attr('id').substr(12); // We get id that is 'fmdirlia_id_xxx' (id we want is xxx)
72 rel=elem.attr('rel')
73 console.log("We click on a dir id="+id+", we call the ajaxdirtree.php with modulepart=<?php echo $module; ?>, param=<?php echo $paramwithoutsection; ?>");
74 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);
75 jQuery("#<?php echo $nameforformuserfile ?>_section_dir").val(rel);
76 jQuery("#<?php echo $nameforformuserfile ?>_section_id").val(id);
77 jQuery("#section_dir").val(rel);
78 jQuery("#section_id").val(id);
79 jQuery("#section").val(id);
80 jQuery('#<?php echo $nameforformuserfile ?>').show();
81 console.log("We also execute the loadandshowpreview() that is on the onclick of each li defined by ajaxdirtree");
82 }
83 // The loadanshowpreview is also call by the 'onclick' set on each li return by ajaxdirtree
84 );
85
86 $('#refreshbutton').click( function() {
87 console.log("Click on refreshbutton");
88
89 dolBlockUI("<?php echo $langs->transnoentities('PleaseBePatient'); ?>");
90
91 $.get("<?php echo DOL_URL_ROOT.'/ecm/ajax/ecmdatabase.php'; ?>", {
92 action: 'build',
93 token: '<?php echo newToken(); ?>',
94 element: 'ecm'
95 }, function(response) {
96 setTimeout(() => {
97 dolUnblockUI();
98
99 location.href='<?php echo $_SERVER['PHP_SELF']; ?>';
100 }, 1000); // delai 1s
101 });
102 });
103});
104
105function loadandshowpreview(filedirname,section)
106{
107 //alert('filedirname='+filedirname);
108 //console.log(filedirname);
109 //console.log('loadandshowpreview for section='+section);
110
111 $('#ecmfileview').empty();
112
113 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."'"); ?>;
114 $.get(url, function(data) {
115 //alert('Load of url '+url+' was performed : '+data);
116 pos=data.indexOf("TYPE=directory",0);
117 //alert(pos);
118 if ((pos > 0) && (pos < 20))
119 {
120 filediractive=filedirname; // Save current dirname
121 filetypeactive='directory';
122 }
123 else
124 {
125 filediractive=filedirname; // Save current dirname
126 filetypeactive='file';
127 }
128 $('#ecmfileview').append(data);
129 });
130}
131
132</script>
133<!-- END PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->
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:125