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