19 declare(strict_types=1);
48 $this->tpl = $DIC->ui()->mainTemplate();
49 $this->
lng = $DIC->language();
50 $this->
user = $DIC->user();
51 $this->
tabs = $DIC->tabs();
53 $this->ui_factory = $DIC->ui()->factory();
54 $this->ui_renderer = $DIC->ui()->renderer();
56 $this->
ctrl->saveParameter($this,
'mobj_id');
76 $this->mode = AttachmentManagement::MANAGE;
88 if (!($cmd = $this->
ctrl->getCmd())) {
89 $cmd =
'showAttachments';
93 AbstractCtrlAwareUploadHandler::CMD_UPLOAD,
94 AbstractCtrlAwareUploadHandler::CMD_INFO,
95 AbstractCtrlAwareUploadHandler::CMD_REMOVE => parent::executeCommand(),
96 default => $this->$cmd()
107 $size_of_affected_files = 0;
108 $files_of_request = $this->
http->wrapper()->query()->retrieve(
109 'mail_attachments_filename',
111 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->string()),
116 if ($files_of_request !== [] && $files_of_request[0] ===
'ALL_OBJECTS') {
117 $files_of_request =
array_map(
static fn(array $file):
string => $file[
'name'], $this->mfile->getUserFilesData());
120 foreach ($files_of_request as $file) {
121 if (is_file($this->mfile->getMailPath() .
'/' . basename($this->
user->getId() .
'_' . urldecode((
string) $file)))) {
122 $files[] = urldecode((
string) $file);
123 $size_of_affected_files += filesize(
124 $this->mfile->getMailPath() .
'/' .
125 basename($this->
user->getId() .
'_' . urldecode((
string) $file))
131 $this->mfile->getAttachmentsTotalSizeLimit() !==
null &&
132 $size_of_affected_files > $this->mfile->getAttachmentsTotalSizeLimit()) {
133 $this->tpl->setOnScreenMessage(
135 $this->
lng->txt(
'mail_max_size_attachments_total_error') .
' ' .
142 $this->umail->saveAttachments($files);
144 $this->
ctrl->returnToParent($this);
150 $this->
ctrl->returnToParent($this);
155 $files = $this->
http->wrapper()->query()->retrieve(
156 'mail_attachments_filename',
158 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->string()),
163 if ($files !== [] && $files[0] ===
'ALL_OBJECTS') {
164 $files =
array_map(
static fn(array $file):
string => $file[
'name'], $this->mfile->getUserFilesData());
168 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'select_one'),
true);
169 $this->
ctrl->redirect($this);
172 $this->tpl->setTitle($this->
lng->txt(
'mail'));
175 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'confirmDeleteAttachments'));
176 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'confirmDeleteAttachments');
177 $confirmation->setCancel($this->
lng->txt(
'cancel'),
'showAttachments');
178 $confirmation->setHeaderText($this->
lng->txt(
'mail_sure_delete_file'));
181 $confirmation->addItem(
188 $this->tpl->setContent($confirmation->getHTML());
189 $this->tpl->printToStdout();
194 $files = $this->
http->wrapper()->post()->retrieve(
197 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->string()),
203 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_mail'));
209 foreach ($files as $value) {
210 $decoded_files[] = urldecode((
string) $value);
213 $error = $this->mfile->unlinkFiles($decoded_files);
215 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_error_delete_file') .
' ' . $error,
true);
217 $mail_data = $this->umail->retrieveFromStage();
218 if (is_array($mail_data[
'attachments'])) {
220 foreach ($mail_data[
'attachments'] as $attachment) {
221 if (!in_array($attachment, $decoded_files,
true)) {
222 $tmp[] = $attachment;
225 $this->umail->saveAttachments($tmp);
228 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_files_deleted'),
true);
231 $this->
ctrl->redirect($this);
236 $this->tpl->setTitle($this->
lng->txt(
'mail'));
239 $this->
tabs->clearTargets();
240 $this->
tabs->setBackTarget(
241 $this->
lng->txt(
'mail_manage_attachments_back_to_compose'),
242 $this->
ctrl->getLinkTarget($this,
'cancelSaveAttachments')
247 if ($this->mode === AttachmentManagement::MANAGE) {
248 $dropzone = $this->ui_factory
252 $this->
lng->txt(
'mail_manage_attachments'),
253 $this->
lng->txt(
'mail_manage_attachments_drop_files_msg'),
255 $this->ui_factory->input()->field()->file(
257 $this->
lng->txt(
'file')
262 $this->ui_factory->button()->shy(
263 $this->
lng->txt(
'upload'),
270 $mail_data = $this->umail->retrieveFromStage();
271 $files = $this->mfile->getUserFilesData();
274 foreach ($files as $file) {
275 if (is_array($mail_data[
'attachments']) && in_array($file[
'name'], $mail_data[
'attachments'],
true)) {
276 $checked_items[] = urlencode($file[
'name']);
280 'filename' => $file[
'name'],
281 'filesize' => (
int) $file[
'size'],
282 'filecreatedate' => (
int) $file[
'ctime'],
294 $this->
http->request(),
296 'handleTableActions',
301 $this->tpl->setContent($this->ui_renderer->render($components));
305 $this->tpl->addOnLoadCode(
' 306 const checked_items = ' . json_encode($checked_items, JSON_THROW_ON_ERROR) .
'; 307 for (const item of checked_items) { 308 const checkbox = document.querySelector("input[type=\'checkbox\'][value=\'" + item + "\']"); 310 checkbox.checked = true; 316 $this->tpl->printToStdout();
321 $query = $this->
http->wrapper()->query();
322 if (!$query->has(
'mail_attachments_table_action')) {
326 $action = $query->retrieve(
'mail_attachments_table_action', $this->
refinery->to()->string());
330 default => $this->
ctrl->redirect($this),
337 $array = $this->
upload->getResults();
338 $result = end($array);
341 $identifier = $this->mfile->storeUploadedFile($result);
342 $status = HandlerResult::STATUS_OK;
344 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
346 $status = HandlerResult::STATUS_FAILED;
348 $message = $result->getStatus()->getMessage();
356 throw new DomainException(
'Not necessary for this handler');
361 throw new DomainException(
'Not necessary for this handler');
366 throw new DomainException(
'Not necessary for this handler');
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
AttachmentManagement $mode
readonly ilFileDataMail $mfile
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getSafePostCommands()
This method must return a list of safe POST commands.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
readonly ILIAS UI Renderer $ui_renderer
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
readonly ilFormatMail $umail
getFileIdentifierParameterName()
executeCommand()
Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented.
getInfoResult(string $identifier)
static http()
Fetches the global http state from ILIAS.
confirmDeleteAttachments()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatSize(int $size, string $a_mode='short', ?ilLanguage $a_lng=null)
Returns the specified file size value in a human friendly form.
Class BasicHandlerResult.
Interface FileInfoResult.
readonly Refinery $refinery
Class ilCtrlAwareUploadHandler.
getInfoForExistingFiles(array $file_ids)
__construct(Container $dic, ilPlugin $plugin)
readonly ILIAS UI Factory $ui_factory
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getRemoveResult(string $identifier)
readonly ilGlobalTemplateInterface $tpl