19 declare(strict_types=1);
45 $this->tpl = $DIC->ui()->mainTemplate();
46 $this->
ctrl = $DIC->ctrl();
47 $this->
lng = $DIC->language();
48 $this->
user = $DIC->user();
49 $this->
toolbar = $DIC->toolbar();
50 $this->
http = $DIC->http();
53 $this->
ctrl->saveParameter($this,
'mobj_id');
61 if (!($cmd = $this->
ctrl->getCmd())) {
62 $cmd =
'showAttachments';
74 $sizeOfSelectedFiles = 0;
76 if ($this->
http->wrapper()->post()->has(
'filename')) {
77 $filesOfRequest = $this->
http->wrapper()->post()->retrieve(
83 foreach ($filesOfRequest as $file) {
84 if (is_file($this->mfile->getMailPath() .
'/' 85 . basename($this->
user->getId() .
'_' . urldecode($file)))
87 $files[] = urldecode($file);
88 $sizeOfSelectedFiles += filesize(
89 $this->mfile->getMailPath() .
'/' .
90 basename($this->
user->getId() .
'_' . urldecode($file))
97 null !== $this->mfile->getAttachmentsTotalSizeLimit() &&
98 $sizeOfSelectedFiles > $this->mfile->getAttachmentsTotalSizeLimit()
100 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_max_size_attachments_total_error') .
' ' .
106 $this->umail->saveAttachments($files);
108 $this->
ctrl->returnToParent($this);
114 $this->
ctrl->returnToParent($this);
120 if ($this->
http->wrapper()->post()->has(
'filename')) {
121 $files = $this->
http->wrapper()->post()->retrieve(
127 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_select_one_file'));
132 $this->tpl->setTitle($this->
lng->txt(
'mail'));
135 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'confirmDeleteAttachments'));
136 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'confirmDeleteAttachments');
137 $confirmation->setCancel($this->
lng->txt(
'cancel'),
'showAttachments');
138 $confirmation->setHeaderText($this->
lng->txt(
'mail_sure_delete_file'));
141 $confirmation->addItem(
148 $this->tpl->setContent($confirmation->getHTML());
149 $this->tpl->printToStdout();
155 if ($this->
http->wrapper()->post()->has(
'filename')) {
156 $files = $this->
http->wrapper()->post()->retrieve(
163 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_mail'));
169 foreach ($files as $value) {
170 $decodedFiles[] = urldecode($value);
173 $error = $this->mfile->unlinkFiles($decodedFiles);
175 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_error_delete_file') .
' ' . $error);
177 $mail_data = $this->umail->retrieveFromStage();
178 if (is_array($mail_data[
'attachments'])) {
180 foreach ($mail_data[
'attachments'] as $attachment) {
181 if (!in_array($attachment, $decodedFiles,
true)) {
182 $tmp[] = $attachment;
185 $this->umail->saveAttachments($tmp);
188 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_files_deleted'));
200 $attachment->setSize(20);
201 $form->addItem($attachment);
208 if (isset($_FILES[
'userfile'][
'name']) && trim($_FILES[
'userfile'][
'name']) !==
'') {
210 if ($form->checkInput()) {
211 $this->mfile->storeUploadedFile($_FILES[
'userfile']);
212 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
213 } elseif ($form->getItemByPostVar(
'userfile')->getAlert() !==
214 $this->
lng->txt(
"form_msg_file_size_exceeds")
216 $this->tpl->setOnScreenMessage(
'failure', $form->getItemByPostVar(
'userfile')->getAlert());
218 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_maxsize_attachment_error') .
' ' .
222 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_select_one_file'));
230 $this->tpl->setTitle($this->
lng->txt(
'mail'));
234 $attachment->setSize(20);
235 $this->
toolbar->setFormAction($this->
ctrl->getFormAction($this,
'uploadFile'),
true);
236 $this->
toolbar->addInputItem($attachment);
237 $this->
toolbar->addFormButton($this->
lng->txt(
'upload'),
'uploadFile');
241 $mail_data = $this->umail->retrieveFromStage();
242 $files = $this->mfile->getUserFilesData();
245 foreach ($files as $file) {
247 if (is_array($mail_data[
'attachments']) && in_array($file[
'name'], $mail_data[
'attachments'],
true)) {
252 'checked' => $checked,
253 'filename' => $file[
'name'],
254 'filesize' => (
int) $file[
'size'],
255 'filecreatedate' => (
int) $file[
'ctime'],
260 $table->setData(
$data);
262 $this->tpl->setContent($table->getHTML());
263 $this->tpl->printToStdout();
Interface GlobalHttpState.
readonly ilFileDataMail $mfile
This class handles all operations on files (attachments) in directory ilias_data/mail.
readonly GlobalHttpState $http
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
readonly ilToolbarGUI $toolbar
readonly ilFormatMail $umail
static http()
Fetches the global http state from ILIAS.
confirmDeleteAttachments()
static formatSize(int $size, string $a_mode='short', ?ilLanguage $a_lng=null)
Returns the specified file size value in a human friendly form.
readonly Refinery $refinery
readonly ilCtrlInterface $ctrl
readonly ilGlobalTemplateInterface $tpl