11require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
13require_once __DIR__ .
'/abstractdocument.controller.class.php';
27 public $sanitized_subdir =
'';
36 $this->accessRight =
getDolGlobalInt(
'WEBPORTAL_SHARED_DOCUMENT_ACCESS');
37 return parent::checkAccess();
49 if (!
$context->controllerInstance->checkAccess()) {
53 $current_subdir = $_POST[
'subdir'] ?? $_GET[
'subdir'] ??
'';
54 if (!empty($current_subdir)) {
55 $parts = explode(
'/', $current_subdir);
56 $safe_parts = array();
57 foreach ($parts as $part) {
58 if ($part !==
'.' && $part !==
'..') {
62 $this->sanitized_subdir = implode(
'/', $safe_parts);
65 $context->title = html_entity_decode($langs->trans(
'SharedDocuments'));
66 $context->desc = $langs->trans(
'ListOfSharedDocuments');
67 $context->menu_active[] =
'shared_documents';
81 if (!
$context->controllerInstance->checkAccess()) {
90 print
'<main class="container">';
93 $sanitized_subdir = $this->sanitized_subdir;
96 $shared_dir_name =
getDolGlobalString(
'WEBPORTAL_SHARED_DOCS_DIR',
'Documentscomptes');
97 $base_dir_ged_partage = $conf->ecm->dir_output .
'/' . $shared_dir_name;
99 $current_dir_ged_partage = $base_dir_ged_partage .
'/' . $sanitized_subdir;
102 $itemList =
dol_dir_list($current_dir_ged_partage,
'all', 0,
'',
'',
'name', SORT_ASC);
103 if (is_array($itemList)) {
104 foreach ($itemList as $key => $item) {
106 if ($item[
'type'] ===
'file' && empty($item[
'size'])) {
107 $full_file_path = $current_dir_ged_partage .
'/' . $item[
'name'];
110 $itemList[$key][
'size'] = @filesize($full_file_path);
115 $baseUrl = $_SERVER[
'PHP_SELF'].
'?controller=shareddocuments';
116 $breadcrumbs =
'<nav aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="'.$baseUrl.
'">'.
dol_htmlentities($langs->trans(
"Home")).
'</a></li>';
118 if (!empty($sanitized_subdir)) {
119 foreach (explode(
'/', $sanitized_subdir) as $part) {
120 $path_so_far .= (empty($path_so_far) ?
'' :
'/') . $part;
121 $breadcrumbs .=
'<li class="breadcrumb-item"><a href="'.$baseUrl.
'&subdir='.$path_so_far.
'">'.
dol_htmlentities($part).
'</a></li>';
124 $breadcrumbs .=
'</ol></nav>';
130 $linkBuilder = array(
135 function (array $dir) use ($baseUrl, $sanitized_subdir) {
136 $new_subdir = (!empty($sanitized_subdir) ? $sanitized_subdir .
'/' :
'') . $dir[
'name'];
137 return $baseUrl .
'&subdir=' . urlencode($new_subdir);
143 function (array $file) use ($shared_dir_name, $sanitized_subdir) {
144 $file_path = $shared_dir_name .
'/' . (!empty($sanitized_subdir) ? $sanitized_subdir .
'/' :
'') . $file[
'name'];
145 return DOL_URL_ROOT .
'/document.php?modulepart=ecm&file=' . urlencode($file_path);
150 html_entity_decode($langs->trans(
'SharedDocuments')),
152 $langs->trans(
'ThisDirectoryIsEmpty'),
displayDocumentTable($title, $itemList, $emptyMessage, array $linkBuilder)
Renders an HTML file browser table for a given list of files and directories.
static getInstance()
Singleton method to create one instance of this object.
display404()
Display error template.
loadTemplate($templateName, $vars=false)
Load a template .tpl file.
Class for SharedDocumentsController.
display()
Build and display the page.
action()
Action method is called before html output.
checkAccess()
Check access rights for this page.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
$context
@method int call_trigger(string $triggerName, ?User $user)