dolibarr  13.0.2
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  */
20 
21 // Protection to avoid direct call of template
22 if (empty($conf) || !is_object($conf))
23 {
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)) $module = 'ecm';
37 $paramwithoutsection = preg_replace('/&?section=(\d+)/', '', $param);
38 
39 $openeddir = '/'; // The root directory shown
40 // $preopened // The dir to have preopened
41 
42 ?>
43 
44 $(document).ready(function() {
45 
46  $('#filetree').fileTree({
47  root: '<?php print dol_escape_js($openeddir); ?>',
48  // 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.
49  // We must use token=$_SESSION['token'] and not token=$_SESSION['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
50  script: '<?php echo DOL_URL_ROOT.'/core/ajax/ajaxdirtree.php?token='.urlencode($_SESSION['token']).'&modulepart='.urlencode($module).(empty($preopened) ? '' : '&preopened='.urlencode($preopened)).'&openeddir='.urlencode($openeddir).(empty($paramwithoutsection) ? '' : $paramwithoutsection); ?>',
51  folderEvent: 'click', // 'dblclick'
52  multiFolder: false },
53  // Called if we click on a file (not a dir)
54  function(file) {
55  console.log("We click on a file");
56  $("#mesg").hide();
57  loadandshowpreview(file,0);
58  },
59  // Called if we click on a dir (not a file)
60  function(elem) {
61  id=elem.attr('id').substr(12); // We get id that is 'fmdirlia_id_xxx' (id we want is xxx)
62  rel=elem.attr('rel')
63  console.log("We click on a dir, we call the ajaxdirtree.php with modulepart=<?php echo $module; ?>, param=<?php echo $paramwithoutsection; ?>");
64  console.log("We also save dir name or id into <?php echo $nameforformuserfile ?>_section_... with name section_... id="+id+" rel="+rel);
65  jQuery("#<?php echo $nameforformuserfile ?>_section_dir").val(rel);
66  jQuery("#<?php echo $nameforformuserfile ?>_section_id").val(id);
67  jQuery("#section_dir").val(rel);
68  jQuery("#section_id").val(id);
69  jQuery("#section").val(id);
70  jQuery('#<?php echo $nameforformuserfile ?>').show();
71  console.log("We also execute the loadandshowpreview() that is on the onclick of each li defined by ajaxdirtree");
72  }
73  // The loadanshowpreview is also call by the 'onclick' set on each li return by ajaxdirtree
74  );
75 
76  $('#refreshbutton').click( function() {
77  console.log("Click on refreshbutton");
78  $.pleaseBePatient("<?php echo $langs->trans('PleaseBePatient'); ?>");
79  $.get( "<?php echo DOL_URL_ROOT.'/ecm/ajax/ecmdatabase.php'; ?>", {
80  action: "build",
81  element: "ecm"
82  },
83  function(response) {
84  $.unblockUI();
85  location.href="<?php echo $_SERVER['PHP_SELF']; ?>";
86  });
87  });
88 });
89 
90 function loadandshowpreview(filedirname,section)
91 {
92  //alert('filedirname='+filedirname);
93  //console.log(filedirname);
94  //console.log('loadandshowpreview for section='+section);
95 
96  $('#ecmfileview').empty();
97 
98  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."'"); ?>;
99  $.get(url, function(data) {
100  //alert('Load of url '+url+' was performed : '+data);
101  pos=data.indexOf("TYPE=directory",0);
102  //alert(pos);
103  if ((pos > 0) && (pos < 20))
104  {
105  filediractive=filedirname; // Save current dirname
106  filetypeactive='directory';
107  }
108  else
109  {
110  filediractive=filedirname; // Save current dirname
111  filetypeactive='file';
112  }
113  $('#ecmfileview').append(data);
114  });
115 }
116 
117 </script>
118 <!-- END PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->
print
Draft customers invoices.
Definition: index.php:89
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105