19declare(strict_types=1);
51 $this->tpl =
$DIC->ui()->mainTemplate();
52 $this->
lng = $DIC->language();
53 $this->
user = $DIC->user();
54 $this->
tabs = $DIC->tabs();
56 $this->ui_factory =
$DIC->ui()->factory();
57 $this->ui_renderer =
$DIC->ui()->renderer();
59 $this->
ctrl->saveParameter($this,
'mobj_id');
79 $this->mode = AttachmentManagement::MANAGE;
91 $cmd = $this->
ctrl->getCmd();
93 case AbstractCtrlAwareUploadHandler::CMD_UPLOAD:
94 case AbstractCtrlAwareUploadHandler::CMD_INFO:
95 case AbstractCtrlAwareUploadHandler::CMD_REMOVE:
96 parent::executeCommand();
100 if ($cmd ===
null || $cmd ===
'' || !method_exists($this, $cmd .
'Command')) {
103 $verified_command = $cmd .
'Command';
104 $this->$verified_command();
116 $size_of_affected_files = 0;
117 $files_of_request = $this->
http->wrapper()->query()->retrieve(
118 'mail_attachments_filename',
120 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
121 $this->refinery->always([])
125 if ($files_of_request !== [] && $files_of_request[0] ===
'ALL_OBJECTS') {
126 $files_of_request = array_map(
static fn(array $file):
string => $file[
'name'], $this->mfile->getUserFilesData());
129 foreach ($files_of_request as $file) {
130 if (is_file($this->mfile->getMailPath() .
'/' . basename($this->
user->getId() .
'_' . urldecode((
string) $file)))) {
131 $files[] = urldecode((
string) $file);
132 $size_of_affected_files += filesize(
133 $this->mfile->getMailPath() .
'/' .
134 basename($this->
user->getId() .
'_' . urldecode((
string) $file))
140 $this->mfile->getAttachmentsTotalSizeLimit() !==
null &&
141 $size_of_affected_files > $this->mfile->getAttachmentsTotalSizeLimit()) {
142 $this->tpl->setOnScreenMessage(
143 $this->tpl::MESSAGE_TYPE_FAILURE,
144 $this->
lng->txt(
'mail_max_size_attachments_total_error') .
' ' .
151 $this->umail->saveAttachments($files);
153 $this->
ctrl->returnToParent($this);
159 $this->
ctrl->returnToParent($this);
164 $files = $this->
http->wrapper()->query()->retrieve(
165 'mail_attachments_filename',
167 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
168 $this->refinery->always([])
172 if ($files !== [] && $files[0] ===
'ALL_OBJECTS') {
173 $files = array_map(
static fn(array $file):
string => $file[
'name'], $this->mfile->getUserFilesData());
177 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->
lng->txt(
'select_one'),
true);
178 $this->
ctrl->redirect($this);
181 $this->tpl->setTitle($this->
lng->txt(
'mail'));
184 $confirmation->setFormAction($this->
ctrl->getFormAction($this, self::CMD_DELETE_ATTACHMENTS));
185 $confirmation->setConfirm($this->
lng->txt(
'confirm'), self::CMD_DELETE_ATTACHMENTS);
186 $confirmation->setCancel($this->
lng->txt(
'cancel'), self::CMD_SHOW_ATTACHMENTS);
187 $confirmation->setHeaderText($this->
lng->txt(
'mail_sure_delete_file'));
190 $confirmation->addItem(
197 $this->tpl->setContent($confirmation->getHTML());
198 $this->tpl->printToStdout();
203 $files = $this->
http->wrapper()->post()->retrieve(
206 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
207 $this->refinery->always([])
212 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->
lng->txt(
'mail_select_one_mail'));
218 foreach ($files as $value) {
219 $decoded_files[] = urldecode((
string) $value);
222 $error = $this->mfile->unlinkFiles($decoded_files);
224 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'mail_error_delete_file') .
' ' . $error,
true);
226 $mail_data = $this->umail->retrieveFromStage();
227 if (is_array($mail_data[
'attachments'])) {
229 foreach ($mail_data[
'attachments'] as $attachment) {
230 if (!in_array($attachment, $decoded_files,
true)) {
231 $tmp[] = $attachment;
234 $this->umail->saveAttachments($tmp);
237 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'mail_files_deleted'),
true);
240 $this->
ctrl->redirect($this);
245 $this->tpl->setTitle($this->
lng->txt(
'mail'));
248 $this->
tabs->clearTargets();
249 $this->
tabs->setBackTarget(
250 $this->
lng->txt(
'mail_manage_attachments_back_to_compose'),
251 $this->ctrl->getLinkTarget($this, self::CMD_CANCEL_SAVE_ATTACHMENTS)
256 if ($this->mode === AttachmentManagement::MANAGE) {
257 $dropzone = $this->ui_factory
261 $this->
lng->txt(
'mail_manage_attachments'),
262 $this->lng->txt(
'mail_manage_attachments_drop_files_msg'),
264 $this->ui_factory->input()->field()->file(
266 $this->lng->txt(
'file')
271 $this->ui_factory->button()->shy(
272 $this->lng->txt(
'upload'),
279 $mail_data = $this->umail->retrieveFromStage();
280 $files = $this->mfile->getUserFilesData();
283 foreach ($files as $file) {
284 if (is_array($mail_data[
'attachments']) && in_array($file[
'name'], $mail_data[
'attachments'],
true)) {
285 $checked_items[] = urlencode($file[
'name']);
289 'filename' => $file[
'name'],
290 'filesize' => (
int) $file[
'size'],
291 'filecreatedate' => (
int) $file[
'ctime'],
303 $this->
http->request(),
304 new ILIAS\Data\Factory(),
305 self::CMD_HANDLE_TABLE_ACTIONS,
310 $this->tpl->setContent($this->ui_renderer->render(
$components));
314 $this->tpl->addOnLoadCode(
'
315 const checked_items = ' . json_encode($checked_items, JSON_THROW_ON_ERROR) .
';
316 for (const item of checked_items) {
317 const checkbox = document.querySelector("input[type=\'checkbox\'][value=\'" + item + "\']");
319 checkbox.checked = true;
325 $this->tpl->printToStdout();
330 $query = $this->
http->wrapper()->query();
331 if (!$query->has(
'mail_attachments_table_action')) {
335 $action = $query->retrieve(
'mail_attachments_table_action', $this->
refinery->to()->string());
339 default => $this->
ctrl->redirect($this),
346 $array = $this->
upload->getResults();
347 $result = end($array);
350 $identifier = $this->mfile->storeUploadedFile($result);
351 $status = HandlerResult::STATUS_OK;
353 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'saved_successfully'),
true);
355 $status = HandlerResult::STATUS_FAILED;
357 $message = $result->getStatus()->getMessage();
365 throw new DomainException(
'Not necessary for this handler');
370 throw new DomainException(
'Not necessary for this handler');
375 throw new DomainException(
'Not necessary for this handler');
Class ilCtrlAwareUploadHandler.
Class BasicHandlerResult.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
deleteAttachmentsCommand()
handleTableActionsCommand()
getInfoForExistingFiles(array $file_ids)
readonly ilFormatMail $umail
readonly Refinery $refinery
readonly ilFileDataMail $mfile
executeCommand()
Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented.
readonly ILIAS UI Factory $ui_factory
getInfoResult(string $identifier)
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
readonly ilGlobalTemplateInterface $tpl
getRemoveResult(string $identifier)
getSafePostCommands()
This method must return a list of safe POST commands.
cancelSaveAttachmentsCommand()
getFileIdentifierParameterName()
@inheritDoc
__construct()
ilUIDemoFileUploadHandlerGUI constructor.
confirmDeleteAttachments()
readonly ILIAS UI Renderer $ui_renderer
AttachmentManagement $mode
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.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Interface FileInfoResult.
const string CMD_HANDLE_TABLE_ACTIONS
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.