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 $sizeOfSelectedFiles = 0;
108 $filesOfRequest = $this->
http->wrapper()->query()->retrieve(
109 'mail_attachments_filename',
111 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->string()),
116 if ($filesOfRequest !== [] && $filesOfRequest[0] ===
'ALL_OBJECTS') {
117 $filesOfRequest =
array_map(
static function (array $file):
string {
118 return $file[
'name'];
119 }, $this->mfile->getUserFilesData());
122 foreach ($filesOfRequest as $file) {
123 if (is_file($this->mfile->getMailPath() .
'/' . basename($this->
user->getId() .
'_' . urldecode($file)))) {
124 $files[] = urldecode($file);
125 $sizeOfSelectedFiles += filesize(
126 $this->mfile->getMailPath() .
'/' .
127 basename($this->
user->getId() .
'_' . urldecode($file))
133 null !== $this->mfile->getAttachmentsTotalSizeLimit() &&
134 $sizeOfSelectedFiles > $this->mfile->getAttachmentsTotalSizeLimit()) {
135 $this->tpl->setOnScreenMessage(
137 $this->
lng->txt(
'mail_max_size_attachments_total_error') .
' ' .
144 $this->umail->saveAttachments($files);
146 $this->
ctrl->returnToParent($this);
152 $this->
ctrl->returnToParent($this);
157 $files = $this->
http->wrapper()->query()->retrieve(
158 'mail_attachments_filename',
160 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->string()),
165 if ($files !== [] && $files[0] ===
'ALL_OBJECTS') {
166 $files =
array_map(
static function (array $file):
string {
167 return $file[
'name'];
168 }, $this->mfile->getUserFilesData());
172 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'select_one'),
true);
173 $this->
ctrl->redirect($this);
176 $this->tpl->setTitle($this->
lng->txt(
'mail'));
179 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'confirmDeleteAttachments'));
180 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'confirmDeleteAttachments');
181 $confirmation->setCancel($this->
lng->txt(
'cancel'),
'showAttachments');
182 $confirmation->setHeaderText($this->
lng->txt(
'mail_sure_delete_file'));
185 $confirmation->addItem(
192 $this->tpl->setContent($confirmation->getHTML());
193 $this->tpl->printToStdout();
198 $files = $this->
http->wrapper()->post()->retrieve(
201 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->string()),
207 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_mail'));
213 foreach ($files as $value) {
214 $decodedFiles[] = urldecode($value);
217 $error = $this->mfile->unlinkFiles($decodedFiles);
219 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_error_delete_file') .
' ' . $error,
true);
221 $mail_data = $this->umail->retrieveFromStage();
222 if (is_array($mail_data[
'attachments'])) {
224 foreach ($mail_data[
'attachments'] as $attachment) {
225 if (!in_array($attachment, $decodedFiles,
true)) {
226 $tmp[] = $attachment;
229 $this->umail->saveAttachments($tmp);
232 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_files_deleted'),
true);
235 $this->
ctrl->redirect($this);
240 $this->tpl->setTitle($this->
lng->txt(
'mail'));
243 $this->
tabs->clearTargets();
244 $this->
tabs->setBackTarget(
245 $this->
lng->txt(
'mail_manage_attachments_back_to_compose'),
246 $this->
ctrl->getLinkTarget($this,
'cancelSaveAttachments')
251 if ($this->mode === AttachmentManagement::MANAGE) {
252 $dropzone = $this->ui_factory
256 $this->
lng->txt(
'mail_manage_attachments'),
257 $this->
lng->txt(
'mail_manage_attachments_drop_files_msg'),
259 $this->ui_factory->input()->field()->file(
261 $this->
lng->txt(
'file')
266 $this->ui_factory->button()->shy(
267 $this->
lng->txt(
'upload'),
274 $mail_data = $this->umail->retrieveFromStage();
275 $files = $this->mfile->getUserFilesData();
278 foreach ($files as $file) {
279 if (is_array($mail_data[
'attachments']) && in_array($file[
'name'], $mail_data[
'attachments'],
true)) {
280 $checked_items[] = urlencode($file[
'name']);
284 'filename' => $file[
'name'],
285 'filesize' => (
int) $file[
'size'],
286 'filecreatedate' => (
int) $file[
'ctime'],
298 $this->
http->request(),
300 'handleTableActions',
305 $this->tpl->setContent($this->ui_renderer->render($components));
309 $this->tpl->addOnLoadCode(
' 310 const checked_items = ' . json_encode($checked_items, JSON_THROW_ON_ERROR) .
'; 311 for (const item of checked_items) { 312 const checkbox = document.querySelector("input[type=\'checkbox\'][value=\'" + item + "\']"); 314 checkbox.checked = true; 320 $this->tpl->printToStdout();
325 $query = $this->
http->wrapper()->query();
326 if (!$query->has(
'mail_attachments_table_action')) {
330 $action = $query->retrieve(
'mail_attachments_table_action', $this->
refinery->to()->string());
334 default => $this->
ctrl->redirect($this),
341 $array = $this->
upload->getResults();
342 $result = end($array);
345 $identifier = $this->mfile->storeUploadedFile($result);
346 $status = HandlerResult::STATUS_OK;
347 $message = $this->
lng->txt(
'saved_successfully');
348 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
350 $status = HandlerResult::STATUS_FAILED;
352 $message = $result->getStatus()->getMessage();
360 throw new DomainException(
'Not necessary for this handler');
365 throw new DomainException(
'Not necessary for this handler');
370 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.
This class handles all operations on files (attachments) in directory ilias_data/mail.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
readonly ILIAS UI Renderer $ui_renderer
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
Interface ilCtrlSecurityInterface provides ilCtrl security information.
getRemoveResult(string $identifier)
readonly ilGlobalTemplateInterface $tpl