29 if (!defined(
'NOTOKENRENEWAL')) {
30 define(
'NOTOKENRENEWAL', 1);
32 if (!defined(
'NOREQUIREMENU')) {
33 define(
'NOREQUIREMENU',
'1');
35 if (!defined(
'NOREQUIREHTML')) {
36 define(
'NOREQUIREHTML',
'1');
38 if (!defined(
'NOREQUIREAJAX')) {
39 define(
'NOREQUIREAJAX',
'1');
42 if (!isset($mode) || $mode !=
'noajax') {
43 $res = @include
'../../main.inc.php';
44 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
45 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
46 include_once DOL_DOCUMENT_ROOT.
'/core/lib/treeview.lib.php';
47 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
48 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
50 $openeddir =
GETPOST(
'openeddir');
51 $modulepart =
GETPOST(
'modulepart');
54 $preopened =
GETPOST(
'preopened');
56 if ($selecteddir !=
'/') {
57 $selecteddir = preg_replace(
'/\/$/',
'', $selecteddir);
62 $openeddir =
GETPOST(
'openeddir');
63 $modulepart =
GETPOST(
'modulepart');
66 $preopened =
GETPOST(
'preopened');
68 if ($selecteddir !=
'/') {
69 $selecteddir = preg_replace(
'/\/$/',
'', $selecteddir);
72 $url = DOL_URL_ROOT.
'/ecm/index.php';
76 $websitekey =
GETPOST(
'websitekey',
'alpha');
77 $pageid =
GETPOST(
'pageid',
'int');
83 $fullpathselecteddir =
'<none>';
84 if ($modulepart ==
'ecm') {
85 $fullpathselecteddir = $conf->ecm->dir_output.
'/'.($selecteddir !=
'/' ? $selecteddir :
'');
86 $fullpathpreopened = $conf->ecm->dir_output.
'/'.($preopened !=
'/' ? $preopened :
'');
87 } elseif ($modulepart ==
'medias') {
88 $fullpathselecteddir = $dolibarr_main_data_root.
'/medias/'.($selecteddir !=
'/' ? $selecteddir :
'');
89 $fullpathpreopened = $dolibarr_main_data_root.
'/medias/'.($preopened !=
'/' ? $preopened :
'');
95 if (preg_match(
'/\.\./', $fullpathselecteddir) || preg_match(
'/[<>|]/', $fullpathselecteddir)) {
96 dol_syslog(
"Refused to deliver file ".$original_file);
103 if ($modulepart ==
'ecm') {
104 if (!$user->rights->ecm->read) {
107 } elseif ($modulepart ==
'medias') {
116 if (!isset($mode) || $mode !=
'noajax') {
121 $userstatic =
new User($db);
126 if (empty($sqltree)) {
127 $sqltree = $ecmdirstatic->get_full_arbo(0);
131 $current_ecmdir_id = -1;
132 foreach ($sqltree as $keycursor => $val) {
134 if ($val[
'fullrelativename'] == $selecteddir) {
135 $current_ecmdir_id = $keycursor;
139 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) {
140 treeOutputForAbsoluteDir($sqltree, $selecteddir, $fullpathselecteddir, $modulepart, $websitekey, $pageid, $preopened, $fullpathpreopened);
145 print
"\n<!-- JS CODE TO ENABLE Tooltips on all object with class classfortooltip (reload into ajaxdirtree) -->\n";
146 print
'<script type="text/javascript">
147 jQuery(document).ready(function () {
148 jQuery(".classfortooltip").tooltip({
149 show: { collision: "flipfit", effect:\'toggle\', delay:50 },
150 hide: { delay: 50 }, /* If I enable effect:\'toggle\' here, a bug appears: the tooltip is shown when collpasing a new dir if it was shown before */
151 tooltipClass: "mytooltip",
152 content: function () {
153 return $(this).prop(\'title\'); /* To force to get title as is */
166 if (empty($conf->use_javascript_ajax) || !empty($conf->global->MAIN_ECM_DISABLE_JS)) {
167 print
'<ul class="ecmjqft">';
170 if (empty($sqltree)) {
171 $sqltree = $ecmdirstatic->get_full_arbo(0);
179 $fullpathselected =
'';
180 foreach ($sqltree as $key => $val) {
182 if ($val[
'id'] == $section) {
183 $fullpathselected = $val[
'fullpath'];
190 $expandedsectionarray = array();
191 if (isset($_SESSION[
'dol_ecmexpandedsectionarray'])) {
192 $expandedsectionarray = explode(
',', $_SESSION[
'dol_ecmexpandedsectionarray']);
195 if ($section &&
GETPOST(
'sectionexpand') ==
'true') {
197 $pathtosection = explode(
'_', $fullpathselected);
198 foreach ($pathtosection as $idcursor) {
199 if ($idcursor && !in_array($idcursor, $expandedsectionarray)) {
200 $expandedsectionarray[] = $idcursor;
203 $_SESSION[
'dol_ecmexpandedsectionarray'] = join(
',', $expandedsectionarray);
205 if ($section &&
GETPOST(
'sectionexpand') ==
'false') {
207 $oldexpandedsectionarray = $expandedsectionarray;
208 $expandedsectionarray = array();
209 foreach ($oldexpandedsectionarray as $sectioncursor) {
213 $_SESSION[
'dol_ecmexpandedsectionarray'] = join(
',', $expandedsectionarray);
219 foreach ($sqltree as $key => $val) {
220 $ecmdirstatic->id = $val[
'id'];
221 $ecmdirstatic->ref = $val[
'label'];
224 if (preg_match(
'/refresh/i', $action)) {
225 $result = $ecmdirstatic->fetch($val[
'id']);
226 $ecmdirstatic->ref = $ecmdirstatic->label;
228 $result = $ecmdirstatic->refreshcachenboffile(0);
229 $val[
'cachenbofdoc'] = $result;
238 if (in_array($val[
'id_mere'], $expandedsectionarray)) {
240 } elseif ($val[
'id'] != $section && $val[
'id_mere'] == $ecmdirstatic->motherof[$section]) {
243 } elseif (preg_match(
'/'.$val[
'fullpath'].
'_/i', $fullpathselected.
'_')) {
246 } elseif ($val[
'level'] < 2) {
252 if (in_array($val[
'id'], $expandedsectionarray)) {
253 $option =
'indexexpanded';
255 $option =
'indexnotexpanded';
259 print
'<li class="directory collapsed">';
263 while ($cpt < $sqltree[$key][
'level']) {
264 print
' ';
269 $nbofsubdir = $resarray[1];
270 $nboffilesinsubdir = $resarray[2];
273 print $ecmdirstatic->getNomUrl(0, $option, 32,
'class="fmdirlia jqft ecmjqft"');
275 print
'<div class="ecmjqft">';
278 print
'<table class="nobordernopadding"><tr><td>';
279 print $val[
'cachenbofdoc'];
281 print
'<td class="left">';
282 if ($nbofsubdir && $nboffilesinsubdir) {
283 print
'<span style="color: #AAAAAA">+'.$nboffilesinsubdir.
'</span> ';
288 print
'<td class="center">';
289 $userstatic->id = $val[
'fk_user_c'];
290 $userstatic->lastname = $val[
'login_c'];
291 $userstatic->statut = $val[
'statut_c'];
292 $htmltooltip =
'<b>'.$langs->trans(
"ECMSection").
'</b>: '.$val[
'label'].
'<br>';
293 $htmltooltip =
'<b>'.$langs->trans(
"Type").
'</b>: '.$langs->trans(
"ECMSectionManual").
'<br>';
294 $htmltooltip .=
'<b>'.$langs->trans(
"ECMCreationUser").
'</b>: '.$userstatic->getNomUrl(1,
'',
false, 1).
'<br>';
295 $htmltooltip .=
'<b>'.$langs->trans(
"ECMCreationDate").
'</b>: '.
dol_print_date($val[
'date_c'],
"dayhour").
'<br>';
296 $htmltooltip .=
'<b>'.$langs->trans(
"Description").
'</b>: '.$val[
'description'].
'<br>';
297 $htmltooltip .=
'<b>'.$langs->trans(
"ECMNbOfFilesInDir").
'</b>: '.$val[
'cachenbofdoc'].
'<br>';
299 $htmltooltip .=
'<b>'.$langs->trans(
"ECMNbOfFilesInSubDir").
'</b>: '.$nboffilesinsubdir;
301 $htmltooltip .=
'<b>'.$langs->trans(
"ECMNbOfSubDir").
'</b>: '.$nbofsubdir.
'<br>';
303 print
$form->textwithpicto(
'', $htmltooltip, 1,
'info');
306 print
'</tr></table>';
313 $oldvallevel = $val[
'level'];
318 if ($nbofentries == 0) {
319 print
'<li class="directory collapsed">';
320 print
'<div class="ecmjqft">';
321 print $langs->trans(
"ECMNoDirectoryYet");
331 if ((!isset($mode) || $mode !=
'noajax') && is_object($db)) {
351 function treeOutputForAbsoluteDir($sqltree, $selecteddir, $fullpathselecteddir, $modulepart, $websitekey, $pageid, $preopened, $fullpathpreopened, $depth = 0)
353 global $conf, $db, $langs,
$form;
354 global $dolibarr_main_data_root;
357 $userstatic =
new User($db);
359 if (file_exists($fullpathselecteddir)) {
360 $files = @scandir($fullpathselecteddir);
362 if (!empty($files)) {
364 if (count($files) > 2) {
365 echo
'<ul class="ecmjqft" style="display: none;">'.
"\n";
368 foreach ($files as $file) {
369 if ($file ==
'temp') {
374 $nboffilesinsubdir = 0;
379 foreach ($sqltree as $key => $tmpval) {
381 if ($tmpval[
'fullrelativename'] == (($selecteddir !=
'/' ? $selecteddir.
'/' :
'').$file)) {
386 if (isset($val[
'cachenbofdoc']) && $val[
'cachenbofdoc'] < 0) {
387 $result = $ecmdirstatic->fetch($val[
'id']);
388 $ecmdirstatic->ref = $ecmdirstatic->label;
390 $result = $ecmdirstatic->refreshcachenboffile(0);
391 $val[
'cachenbofdoc'] = $result;
395 $nbofsubdir = $resarray[1];
396 $nboffilesinsubdir = $resarray[2];
402 if ($file !=
'.' && $file !=
'..' && ((!empty($val[
'fullrelativename']) && $val[
'id'] >= 0) ||
dol_is_dir($fullpathselecteddir.(preg_match(
'/\/$/', $fullpathselecteddir) ?
'' :
'/').$file))) {
403 if (empty($val[
'fullrelativename'])) {
404 $val[
'fullrelativename'] = (($selecteddir && $selecteddir !=
'/') ? $selecteddir.
'/' :
'').$file;
406 $val[
'label'] = $file;
407 $val[
'description'] =
'';
408 $nboffilesinsubdir = $langs->trans(
"Unknown");
411 $collapsedorexpanded =
'collapsed';
412 if (preg_match(
'/^'.preg_quote($val[
'fullrelativename'].
'/',
'/').
'/', $preopened)) {
413 $collapsedorexpanded =
'expanded';
415 print
'<li class="directory '.$collapsedorexpanded.
'">';
417 print
"<a class=\"fmdirlia jqft ecmjqft\" href=\"";
419 print
"\" rel=\"".dol_escape_htmltag($val[
'fullrelativename'].
'/').
"\" id=\"fmdirlia_id_".$val[
'id'].
"\"";
420 print
" onClick=\"loadandshowpreview('".dol_escape_js($val[
'fullrelativename']).
"',".$val[
'id'].
")";
425 print
'<div class="ecmjqft">';
427 print
'<table class="nobordernopadding"><tr>';
434 print
'<td class="right">';
435 print (isset($val[
'cachenbofdoc']) && $val[
'cachenbofdoc'] >= 0) ? $val[
'cachenbofdoc'] :
' ';
437 print
'<td class="left">';
438 if ($nbofsubdir > 0 && $nboffilesinsubdir > 0) {
439 print
'<span class="opacitymedium">+'.$nboffilesinsubdir.
'</span> ';
444 print
'<td class="right" width="18"><a class="editfielda" href="';
445 print DOL_URL_ROOT.
'/ecm/dir_card.php?module='.urlencode($modulepart).
'§ion='.$val[
'id'].
'&relativedir='.urlencode($val[
'fullrelativename']);
446 print
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?file_manager=1&website='.$websitekey.
'&pageid='.$pageid);
447 print
'">'.img_edit($langs->trans(
"Edit").
' - '.$langs->trans(
"View"), 0,
'class="valignmiddle opacitymedium"').
'</a></td>';
454 if ($modulepart ==
'ecm') {
455 print
'<td class="right" width="18">';
456 $userstatic->id = isset($val[
'fk_user_c']) ? $val[
'fk_user_c'] : 0;
457 $userstatic->lastname = isset($val[
'login_c']) ? $val[
'login_c'] : 0;
458 $userstatic->statut = isset($val[
'statut_c']) ? $val[
'statut_c'] : 0;
459 $htmltooltip =
'<b>'.$langs->trans(
"ECMSection").
'</b>: '.$val[
'label'].
'<br>';
460 $htmltooltip =
'<b>'.$langs->trans(
"Type").
'</b>: '.$langs->trans(
"ECMSectionManual").
'<br>';
461 $htmltooltip .=
'<b>'.$langs->trans(
"ECMCreationUser").
'</b>: '.$userstatic->getNomUrl(1,
'',
false, 1).
'<br>';
462 $htmltooltip .=
'<b>'.$langs->trans(
"ECMCreationDate").
'</b>: '.(isset($val[
'date_c']) ?
dol_print_date($val[
'date_c'],
"dayhour") : $langs->trans(
"NeedRefresh")).
'<br>';
463 $htmltooltip .=
'<b>'.$langs->trans(
"Description").
'</b>: '.$val[
'description'].
'<br>';
464 $htmltooltip .=
'<b>'.$langs->trans(
"ECMNbOfFilesInDir").
'</b>: '.((isset($val[
'cachenbofdoc']) && $val[
'cachenbofdoc'] >= 0) ? $val[
'cachenbofdoc'] : $langs->trans(
"NeedRefresh")).
'<br>';
465 if ($nboffilesinsubdir > 0) {
466 $htmltooltip .=
'<b>'.$langs->trans(
"ECMNbOfFilesInSubDir").
'</b>: '.$nboffilesinsubdir;
468 $htmltooltip .=
'<b>'.$langs->trans(
"ECMNbOfSubDir").
'</b>: '.($nbofsubdir >= 0 ? $nbofsubdir : $langs->trans(
"NeedRefresh")).
'<br>';
470 print
$form->textwithpicto(
'', $htmltooltip, 1,
"info");
474 print
"</tr></table>\n";
478 if (preg_match(
'/^'.preg_quote($val[
'fullrelativename'].
'/',
'/').
'/', $preopened)) {
480 $newselecteddir = $val[
'fullrelativename'];
481 $newfullpathselecteddir =
'';
482 if ($modulepart ==
'ecm') {
483 $newfullpathselecteddir = $conf->ecm->dir_output.
'/'.($val[
'fullrelativename'] !=
'/' ? $val[
'fullrelativename'] :
'');
484 } elseif ($modulepart ==
'medias') {
485 $newfullpathselecteddir = $dolibarr_main_data_root.
'/medias/'.($val[
'fullrelativename'] !=
'/' ? $val[
'fullrelativename'] :
'');
488 if ($newfullpathselecteddir) {
489 treeOutputForAbsoluteDir($sqltree, $newselecteddir, $newfullpathselecteddir, $modulepart, $websitekey, $pageid, $preopened, $fullpathpreopened, $depth + 1);
500 print
"PermissionDenied";