From 3e68693daa416ceff5744dfd6d9547eefa977f38 Mon Sep 17 00:00:00 2001 From: juancpbinario Date: Thu, 11 Jul 2024 20:51:07 +0200 Subject: [PATCH] Hide documents from other sessions --- main/inc/lib/elfinder/filemanager.php | 2 ++ .../javascript/editor/elfinder_standalone.tpl | 34 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/main/inc/lib/elfinder/filemanager.php b/main/inc/lib/elfinder/filemanager.php index 00143e3ed7..d93756e339 100644 --- a/main/inc/lib/elfinder/filemanager.php +++ b/main/inc/lib/elfinder/filemanager.php @@ -18,8 +18,10 @@ if (file_exists($file)) { $language = $iso; } $questionId = isset($_REQUEST['question_id']) ? (int) $_REQUEST['question_id'] : 0; +$sessionId = api_get_session_id(); $template->assign('question_id', $questionId); +$template->assign('session_id', $sessionId); $template->assign('elfinder_lang', $language); $template->assign('elfinder_translation_file', $includeFile); $template->display('default/javascript/editor/ckeditor/elfinder.tpl'); diff --git a/main/template/default/javascript/editor/elfinder_standalone.tpl b/main/template/default/javascript/editor/elfinder_standalone.tpl index 17fcfd90e1..ece2449b71 100644 --- a/main/template/default/javascript/editor/elfinder_standalone.tpl +++ b/main/template/default/javascript/editor/elfinder_standalone.tpl @@ -19,24 +19,40 @@ $().ready(function() { var funcNum = getUrlParam('CKEditorFuncNum'); + var sessionId = {{session_id}}; var elf = $('#elfinder').elfinder({ url : '{{ _p.web_lib ~ 'elfinder/connectorAction.php?' }}{{ course_condition }}', // connector URL (REQUIRED) getFileCallback : function(file) { - if (window.opener) { - if (window.opener.CKEDITOR) { - window.opener.CKEDITOR.tools.callFunction(funcNum, file.url); - } + if (!file.name.includes("__0") || file.name.includes("__" + sessionId + "__")) { + if (window.opener) { + if (window.opener.CKEDITOR) { + window.opener.CKEDITOR.tools.callFunction(funcNum, file.url); + } - if (window.opener.addImageToQuestion) { - window.opener.addImageToQuestion(file.url, {{ question_id }}); + if (window.opener.addImageToQuestion) { + window.opener.addImageToQuestion(file.url, {{ question_id }}); + } } + window.close(); } - - window.close(); }, startPathHash: 'l2_Lw', // Sets the course driver as default resizable: false, - lang: '{{ elfinder_lang }}' + lang: '{{ elfinder_lang }}', + handlers : { + sync : function (event, elfinderInstance) { + let files = elfinderInstance.files(); + for (const key in files) { + for (const subkey in files[key]) { + if (subkey === "name") { + if (files[key][subkey].includes("__0") && !files[key][subkey].includes("__" + sessionId + "__")) { + $('#' + files[key].hash).hide(); + } + } + } + } + } + } }).elfinder('instance'); });