dolibarr  16.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
23 if (empty($conf) || !is_object($conf)) {
24  print "Error, template enablefiletreeajax.tpl.php can't be called as URL";
25  exit;
26 }
27 
28 ?>
29 
30 <!-- BEGIN PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->
31 <!-- Doc of fileTree plugin at https://www.abeautifulsite.net/jquery-file-tree -->
32 
33 <script type="text/javascript">
34 
35 <?php
36 if (empty($module)) {
37  $module = 'ecm';
38 }
39 if (empty($nameforformuserfile)) {
40  $nameforformuserfile = '';
41 }
42 $paramwithoutsection = preg_replace('/&?section=(\d+)/', '', $param);
43 
44 $openeddir = '/'; // The root directory shown
45 // $preopened // The dir to have preopened
46 
47 ?>
48 
49 $(document).ready(function() {
50 
51  $('#filetree').fileTree({
52  root: '<?php print dol_escape_js($openeddir); ?>',
53  // 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.
54  // 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
55  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); ?>',
56  folderEvent: 'click', // 'dblclick'
57  multiFolder: false },
58  // Called if we click on a file (not a dir)
59  function(file) {
60  console.log("We click on a file");
61  $("#mesg").hide();
62  loadandshowpreview(file,0);
63  },
64  // Called if we click on a dir (not a file)
65  function(elem) {
66  id=elem.attr('id').substr(12); // We get id that is 'fmdirlia_id_xxx' (id we want is xxx)
67  rel=elem.attr('rel')
68  console.log("We click on a dir, we call the ajaxdirtree.php with modulepart=<?php echo $module; ?>, param=<?php echo $paramwithoutsection; ?>");
69  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);
70  jQuery("#<?php echo $nameforformuserfile ?>_section_dir").val(rel);
71  jQuery("#<?php echo $nameforformuserfile ?>_section_id").val(id);
72  jQuery("#section_dir").val(rel);
73  jQuery("#section_id").val(id);
74  jQuery("#section").val(id);
75  jQuery('#<?php echo $nameforformuserfile ?>').show();
76  console.log("We also execute the loadandshowpreview() that is on the onclick of each li defined by ajaxdirtree");
77  }
78  // The loadanshowpreview is also call by the 'onclick' set on each li return by ajaxdirtree
79  );
80 
81  $('#refreshbutton').click( function() {
82  console.log("Click on refreshbutton");
83  $.pleaseBePatient("<?php echo $langs->trans('PleaseBePatient'); ?>");
84  $.get("<?php echo DOL_URL_ROOT.'/ecm/ajax/ecmdatabase.php'; ?>", {
85  action: 'build',
86  token: '<?php echo newToken(); ?>',
87  element: 'ecm'
88  },
89  function(response) {
90  $.unblockUI();
91  location.href='<?php echo $_SERVER['PHP_SELF']; ?>';
92  });
93  });
94 });
95 
96 function loadandshowpreview(filedirname,section)
97 {
98  //alert('filedirname='+filedirname);
99  //console.log(filedirname);
100  //console.log('loadandshowpreview for section='+section);
101 
102  $('#ecmfileview').empty();
103 
104  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."'"); ?>;
105  $.get(url, function(data) {
106  //alert('Load of url '+url+' was performed : '+data);
107  pos=data.indexOf("TYPE=directory",0);
108  //alert(pos);
109  if ((pos > 0) && (pos < 20))
110  {
111  filediractive=filedirname; // Save current dirname
112  filetypeactive='directory';
113  }
114  else
115  {
116  filediractive=filedirname; // Save current dirname
117  filetypeactive='file';
118  }
119  $('#ecmfileview').append(data);
120  });
121 }
122 
123 </script>
124 <!-- END PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119