19declare(strict_types=1);
35 use FileDataRCHandling;
54 $this->tpl =
$DIC->ui()->mainTemplate();
55 $this->
lng = $DIC->language();
56 $this->
user = $DIC->user();
57 $this->
tabs = $DIC->tabs();
59 $this->ui_factory =
$DIC->ui()->factory();
60 $this->ui_renderer =
$DIC->ui()->renderer();
61 $this->storage =
$DIC->resourceStorage();
63 $this->
ctrl->saveParameter($this,
'mobj_id');
83 $this->mode = AttachmentManagement::MANAGE;
95 $cmd = $this->
ctrl->getCmd();
97 case AbstractCtrlAwareUploadHandler::CMD_UPLOAD:
98 case AbstractCtrlAwareUploadHandler::CMD_INFO:
99 case AbstractCtrlAwareUploadHandler::CMD_REMOVE:
100 parent::executeCommand();
104 if ($cmd ===
null || $cmd ===
'' || !method_exists($this, $cmd .
'Command')) {
107 $verified_command = $cmd .
'Command';
108 $this->$verified_command();
120 $size_of_affected_files = 0;
121 $files_of_request = $this->
http->wrapper()->query()->retrieve(
122 'mail_attachments_filename',
124 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
125 $this->refinery->always([])
129 if ($files_of_request !== [] && $files_of_request[0] ===
'ALL_OBJECTS') {
130 $files_of_request = array_map(
static fn(array $file):
string => $file[
'name'], $this->fdm->getUserFilesData());
133 foreach ($files_of_request as $file) {
134 if (is_file($this->fdm->getMailPath() .
'/' . basename($this->
user->getId() .
'_' . urldecode((
string) $file)))) {
135 $files[] = urldecode((
string) $file);
136 $size_of_affected_files += filesize(
137 $this->fdm->getMailPath() .
'/' .
138 basename($this->
user->getId() .
'_' . urldecode((
string) $file))
144 $this->fdm->getAttachmentsTotalSizeLimit() !==
null &&
145 $size_of_affected_files > $this->fdm->getAttachmentsTotalSizeLimit()) {
146 $this->tpl->setOnScreenMessage(
147 $this->tpl::MESSAGE_TYPE_FAILURE,
148 $this->
lng->txt(
'mail_max_size_attachments_total_error') .
' ' .
155 $rcid_for_files = $this->getIdforCollection($files);
156 $this->umail->saveAttachments($rcid_for_files);
158 $this->
ctrl->returnToParent($this);
164 $this->
ctrl->returnToParent($this);
169 $files = $this->
http->wrapper()->query()->retrieve(
170 'mail_attachments_filename',
172 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
173 $this->refinery->always([])
177 if ($files !== [] && $files[0] ===
'ALL_OBJECTS') {
178 $files = array_map(
static fn(array $file):
string => $file[
'name'], $this->fdm->getUserFilesData());
182 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->
lng->txt(
'select_one'),
true);
183 $this->
ctrl->redirect($this);
186 $this->tpl->setTitle($this->
lng->txt(
'mail_attachments'));
189 $confirmation->setFormAction($this->
ctrl->getFormAction($this, self::CMD_DELETE_ATTACHMENTS));
190 $confirmation->setConfirm($this->
lng->txt(
'confirm'), self::CMD_DELETE_ATTACHMENTS);
191 $confirmation->setCancel($this->
lng->txt(
'cancel'), self::CMD_SHOW_ATTACHMENTS);
192 $confirmation->setHeaderText($this->
lng->txt(
'mail_sure_delete_file'));
195 $confirmation->addItem(
202 $this->tpl->setContent($confirmation->getHTML());
203 $this->tpl->printToStdout();
208 $files = $this->
http->wrapper()->post()->retrieve(
211 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
212 $this->refinery->always([])
217 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->
lng->txt(
'mail_select_one_mail'));
223 foreach ($files as $value) {
224 $decoded_files[] = urldecode((
string) $value);
227 $error = $this->fdm->unlinkFiles($decoded_files);
229 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'mail_error_delete_file') .
' ' . $error,
true);
231 $mail_data = $this->umail->retrieveFromStage();
232 if (!is_null($mail_data[
'attachments'])) {
233 $files_to_legacy = $this->FilesFromIRSSToLegacy($mail_data[
'attachments']);
234 $files = $this->handleAttachments($files_to_legacy);
236 if (is_array($files)) {
237 foreach ($files as $attachment) {
239 if (!in_array($attachment, $decoded_files,
true)) {
240 $tmp[] = $attachment;
242 $rcid = $this->getIdforCollection($tmp);
244 $this->umail->saveAttachments($rcid);
248 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'mail_files_deleted'),
true);
251 $this->
ctrl->redirect($this);
256 $this->tpl->setTitle($this->
lng->txt(
'mail_attachments'));
259 $this->
tabs->clearTargets();
260 $this->
tabs->setBackTarget(
261 $this->
lng->txt(
'mail_manage_attachments_back_to_compose'),
262 $this->ctrl->getLinkTarget($this, self::CMD_CANCEL_SAVE_ATTACHMENTS)
267 if ($this->mode === AttachmentManagement::MANAGE) {
268 $dropzone = $this->ui_factory
272 $this->
lng->txt(
'mail_manage_attachments'),
273 $this->lng->txt(
'mail_manage_attachments_drop_files_msg'),
275 $this->ui_factory->input()->field()->file(
277 $this->lng->txt(
'file')
282 $this->ui_factory->button()->shy(
283 $this->lng->txt(
'upload'),
290 $mail_data = $this->umail->retrieveFromStage();
291 $files = $this->fdm->getUserFilesData();
294 foreach ($files as $file) {
295 if (is_array($mail_data[
'attachments']) && in_array($file[
'name'], $mail_data[
'attachments'],
true)) {
296 $checked_items[] = urlencode($file[
'name']);
300 'filename' => $file[
'name'],
301 'filesize' => (
int) $file[
'size'],
302 'filecreatedate' => (
int) $file[
'ctime'],
314 $this->
http->request(),
315 new ILIAS\Data\Factory(),
316 self::CMD_HANDLE_TABLE_ACTIONS,
321 $this->tpl->setContent($this->ui_renderer->render(
$components));
325 $this->tpl->addOnLoadCode(
'
326 const checked_items = ' . json_encode($checked_items, JSON_THROW_ON_ERROR) .
';
327 for (const item of checked_items) {
328 const checkbox = document.querySelector("input[type=\'checkbox\'][value=\'" + item + "\']");
330 checkbox.checked = true;
336 $this->tpl->printToStdout();
341 $query = $this->
http->wrapper()->query();
342 if (!$query->has(
'mail_attachments_table_action')) {
346 $action = $query->retrieve(
'mail_attachments_table_action', $this->
refinery->to()->string());
350 default => $this->
ctrl->redirect($this),
357 $array = $this->
upload->getResults();
358 $result = end($array);
361 $identifier = $this->fdm->storeUploadedFile($result);
362 $status = HandlerResult::STATUS_OK;
363 $message = $this->
lng->txt(
'saved_successfully');
364 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'saved_successfully'),
true);
366 $status = HandlerResult::STATUS_FAILED;
368 $message = $result->getStatus()->getMessage();
376 throw new DomainException(
'Not necessary for this handler');
381 throw new DomainException(
'Not necessary for this handler');
386 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 ILIAS ResourceStorage Services $storage
executeCommand()
Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented.
readonly ilFileDataMail $fdm
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.