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 $forward_class = $this->
ctrl->getNextClass($this);
62 switch ($forward_class) {
64 if (!($cmd = $this->
ctrl->getCmd())) {
65 $cmd =
'showAttachments';
80 $sizeOfSelectedFiles = 0;
82 if ($this->
http->wrapper()->post()->has(
'filename')) {
83 $filesOfRequest = $this->
http->wrapper()->post()->retrieve(
89 foreach ($filesOfRequest as $file) {
90 if (is_file($this->mfile->getMailPath() .
'/' 91 . basename($this->
user->getId() .
'_' . urldecode($file)))
93 $files[] = urldecode($file);
94 $sizeOfSelectedFiles += filesize(
95 $this->mfile->getMailPath() .
'/' .
96 basename($this->
user->getId() .
'_' . urldecode($file))
103 null !== $this->mfile->getAttachmentsTotalSizeLimit() &&
104 $sizeOfSelectedFiles > $this->mfile->getAttachmentsTotalSizeLimit()
106 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_max_size_attachments_total_error') .
' ' .
112 $this->umail->saveAttachments($files);
114 $this->
ctrl->returnToParent($this);
120 $this->
ctrl->returnToParent($this);
126 if ($this->
http->wrapper()->post()->has(
'filename')) {
127 $files = $this->
http->wrapper()->post()->retrieve(
133 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_select_one_file'));
138 $this->tpl->setTitle($this->
lng->txt(
'mail'));
141 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'confirmDeleteAttachments'));
142 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'confirmDeleteAttachments');
143 $confirmation->setCancel($this->
lng->txt(
'cancel'),
'showAttachments');
144 $confirmation->setHeaderText($this->
lng->txt(
'mail_sure_delete_file'));
147 $confirmation->addItem(
154 $this->tpl->setContent($confirmation->getHTML());
155 $this->tpl->printToStdout();
161 if ($this->
http->wrapper()->post()->has(
'filename')) {
162 $files = $this->
http->wrapper()->post()->retrieve(
169 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'mail_select_one_mail'));
175 foreach ($files as $value) {
176 $decodedFiles[] = urldecode($value);
179 $error = $this->mfile->unlinkFiles($decodedFiles);
181 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_error_delete_file') .
' ' . $error);
183 $mail_data = $this->umail->retrieveFromStage();
184 if (is_array($mail_data[
'attachments'])) {
186 foreach ($mail_data[
'attachments'] as $attachment) {
187 if (!in_array($attachment, $decodedFiles,
true)) {
188 $tmp[] = $attachment;
191 $this->umail->saveAttachments($tmp);
194 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_files_deleted'));
206 $attachment->setSize(20);
207 $form->addItem($attachment);
214 if (isset($_FILES[
'userfile'][
'name']) && trim($_FILES[
'userfile'][
'name']) !==
'') {
216 if ($form->checkInput()) {
217 $this->mfile->storeUploadedFile($_FILES[
'userfile']);
218 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
219 } elseif ($form->getItemByPostVar(
'userfile')->getAlert() !==
220 $this->
lng->txt(
"form_msg_file_size_exceeds")
222 $this->tpl->setOnScreenMessage(
'failure', $form->getItemByPostVar(
'userfile')->getAlert());
224 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_maxsize_attachment_error') .
' ' .
228 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_select_one_file'));
236 $this->tpl->setTitle($this->
lng->txt(
'mail'));
240 $attachment->setSize(20);
241 $this->
toolbar->setFormAction($this->
ctrl->getFormAction($this,
'uploadFile'),
true);
242 $this->
toolbar->addInputItem($attachment);
243 $this->
toolbar->addFormButton($this->
lng->txt(
'upload'),
'uploadFile');
247 $mail_data = $this->umail->retrieveFromStage();
248 $files = $this->mfile->getUserFilesData();
251 foreach ($files as $file) {
253 if (is_array($mail_data[
'attachments']) && in_array($file[
'name'], $mail_data[
'attachments'],
true)) {
258 'checked' => $checked,
259 'filename' => $file[
'name'],
260 'filesize' => (
int) $file[
'size'],
261 'filecreatedate' => (
int) $file[
'ctime'],
266 $table->setData(
$data);
268 $this->tpl->setContent($table->getHTML());
269 $this->tpl->printToStdout();
Interface GlobalHttpState.
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="")
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.
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...