dolibarr 20.0.0
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 $.pleaseBePatient("<?php echo $langs->trans('PleaseBePatient'); ?>");
85 $.get("<?php echo DOL_URL_ROOT.'/ecm/ajax/ecmdatabase.php'; ?>", {
86 action: 'build',
87 token: '<?php echo newToken(); ?>',
88 element: 'ecm'
89 },
90 function(response) {
91 $.unblockUI();
92 location.href='<?php echo $_SERVER['PHP_SELF']; ?>';
93 });
94 });
95});
96
97function loadandshowpreview(filedirname,section)
98{
99 //alert('filedirname='+filedirname);
100 //console.log(filedirname);
101 //console.log('loadandshowpreview for section='+section);
102
103 $('#ecmfileview').empty();
104
105 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."'"); ?>;
106 $.get(url, function(data) {
107 //alert('Load of url '+url+' was performed : '+data);
108 pos=data.indexOf("TYPE=directory",0);
109 //alert(pos);
110 if ((pos > 0) && (pos < 20))
111 {
112 filediractive=filedirname; // Save current dirname
113 filetypeactive='directory';
114 }
115 else
116 {
117 filediractive=filedirname; // Save current dirname
118 filetypeactive='file';
119 }
120 $('#ecmfileview').append(data);
121 });
122}
123
124</script>
125<!-- END PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137