ILIAS  release_8 Revision v8.24
ilMailAttachmentGUI Class Reference
+ Collaboration diagram for ilMailAttachmentGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 
 saveAttachments ()
 
 cancelSaveAttachments ()
 
 deleteAttachments ()
 
 confirmDeleteAttachments ()
 
 uploadFile ()
 
 showAttachments ()
 

Protected Member Functions

 getToolbarForm ()
 

Private Attributes

ilGlobalTemplateInterface $tpl
 
ilCtrlInterface $ctrl
 
ilLanguage $lng
 
ilObjUser $user
 
ilToolbarGUI $toolbar
 
ilFormatMail $umail
 
ilFileDataMail $mfile
 
GlobalHttpState $http
 
Refinery $refinery
 

Detailed Description

Author
Jens Conze
Version
$Id$

Definition at line 29 of file class.ilMailAttachmentGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailAttachmentGUI::__construct ( )

Definition at line 41 of file class.ilMailAttachmentGUI.php.

42 {
43 global $DIC;
44
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();
51 $this->refinery = $DIC->refinery();
52
53 $this->ctrl->saveParameter($this, 'mobj_id');
54
55 $this->umail = new ilFormatMail($DIC->user()->getId());
56 $this->mfile = new ilFileDataMail($DIC->user()->getId());
57 }
This class handles all operations on files (attachments) in directory ilias_data/mail.
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.

References $DIC, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), ILIAS\Repository\toolbar(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ cancelSaveAttachments()

ilMailAttachmentGUI::cancelSaveAttachments ( )

Definition at line 117 of file class.ilMailAttachmentGUI.php.

117 : void
118 {
119 $this->ctrl->setParameter($this, 'type', ilMailFormGUI::MAIL_FORM_TYPE_ATTACH);
120 $this->ctrl->returnToParent($this);
121 }

References ILIAS\Repository\ctrl(), and ilMailFormGUI\MAIL_FORM_TYPE_ATTACH.

+ Here is the call graph for this function:

◆ confirmDeleteAttachments()

ilMailAttachmentGUI::confirmDeleteAttachments ( )

Definition at line 158 of file class.ilMailAttachmentGUI.php.

158 : void
159 {
160 $files = [];
161 if ($this->http->wrapper()->post()->has('filename')) {
162 $files = $this->http->wrapper()->post()->retrieve(
163 'filename',
164 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string())
165 );
166 }
167
168 if ($files === []) {
169 $this->tpl->setOnScreenMessage('info', $this->lng->txt('mail_select_one_mail'));
170 $this->showAttachments();
171 return;
172 }
173
174 $decodedFiles = [];
175 foreach ($files as $value) {
176 $decodedFiles[] = urldecode($value);
177 }
178
179 $error = $this->mfile->unlinkFiles($decodedFiles);
180 if ($error !== '') {
181 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_error_delete_file') . ' ' . $error);
182 } else {
183 $mail_data = $this->umail->retrieveFromStage();
184 if (is_array($mail_data['attachments'])) {
185 $tmp = [];
186 foreach ($mail_data['attachments'] as $attachment) {
187 if (!in_array($attachment, $decodedFiles, true)) {
188 $tmp[] = $attachment;
189 }
190 }
191 $this->umail->saveAttachments($tmp);
192 }
193
194 $this->tpl->setOnScreenMessage('success', $this->lng->txt('mail_files_deleted'));
195 }
196
197 $this->showAttachments();
198 }

References ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and showAttachments().

+ Here is the call graph for this function:

◆ deleteAttachments()

ilMailAttachmentGUI::deleteAttachments ( )

Definition at line 123 of file class.ilMailAttachmentGUI.php.

123 : void
124 {
125 $files = [];
126 if ($this->http->wrapper()->post()->has('filename')) {
127 $files = $this->http->wrapper()->post()->retrieve(
128 'filename',
129 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string())
130 );
131 }
132 if ($files === []) {
133 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_select_one_file'));
134 $this->showAttachments();
135 return;
136 }
137
138 $this->tpl->setTitle($this->lng->txt('mail'));
139
140 $confirmation = new ilConfirmationGUI();
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'));
145
146 foreach ($files as $filename) {
147 $confirmation->addItem(
148 'filename[]',
151 );
152 }
153
154 $this->tpl->setContent($confirmation->getHTML());
155 $this->tpl->printToStdout();
156 }
$filename
Definition: buildRTE.php:78
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")

References $filename, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), showAttachments(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ executeCommand()

ilMailAttachmentGUI::executeCommand ( )

Definition at line 59 of file class.ilMailAttachmentGUI.php.

59 : void
60 {
61 $forward_class = $this->ctrl->getNextClass($this);
62 switch ($forward_class) {
63 default:
64 if (!($cmd = $this->ctrl->getCmd())) {
65 $cmd = 'showAttachments';
66 }
67
68 $this->$cmd();
69 break;
70 }
71 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ getToolbarForm()

ilMailAttachmentGUI::getToolbarForm ( )
protected

Definition at line 200 of file class.ilMailAttachmentGUI.php.

201 {
202 $form = new ilPropertyFormGUI();
203
204 $attachment = new ilFileInputGUI($this->lng->txt('upload'), 'userfile');
205 $attachment->setRequired(true);
206 $attachment->setSize(20);
207 $form->addItem($attachment);
208
209 return $form;
210 }
This class represents a file property in a property form.
This class represents a property form user interface.

References ILIAS\Repository\lng().

Referenced by uploadFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveAttachments()

ilMailAttachmentGUI::saveAttachments ( )

Definition at line 73 of file class.ilMailAttachmentGUI.php.

73 : void
74 {
75 $files = [];
76
77 // Important: Do not check for uploaded files here,
78 // otherwise it is no more possible to remove files (please ignore bug reports like 10137)
79
80 $sizeOfSelectedFiles = 0;
81 $filesOfRequest = [];
82 if ($this->http->wrapper()->post()->has('filename')) {
83 $filesOfRequest = $this->http->wrapper()->post()->retrieve(
84 'filename',
85 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string())
86 );
87 }
88
89 foreach ($filesOfRequest as $file) {
90 if (is_file($this->mfile->getMailPath() . '/'
91 . basename($this->user->getId() . '_' . urldecode($file)))
92 ) {
93 $files[] = urldecode($file);
94 $sizeOfSelectedFiles += filesize(
95 $this->mfile->getMailPath() . '/' .
96 basename($this->user->getId() . '_' . urldecode($file))
97 );
98 }
99 }
100
101 if (
102 $files !== [] &&
103 null !== $this->mfile->getAttachmentsTotalSizeLimit() &&
104 $sizeOfSelectedFiles > $this->mfile->getAttachmentsTotalSizeLimit()
105 ) {
106 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_max_size_attachments_total_error') . ' ' .
107 ilUtil::formatSize((int) $this->mfile->getAttachmentsTotalSizeLimit()));
108 $this->showAttachments();
109 return;
110 }
111
112 $this->umail->saveAttachments($files);
113
114 $this->ctrl->returnToParent($this);
115 }
static formatSize(int $size, string $a_mode='short', ?ilLanguage $a_lng=null)
Returns the specified file size value in a human friendly form.

References ILIAS\Repository\ctrl(), ilUtil\formatSize(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), showAttachments(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ showAttachments()

ilMailAttachmentGUI::showAttachments ( )

Definition at line 234 of file class.ilMailAttachmentGUI.php.

234 : void
235 {
236 $this->tpl->setTitle($this->lng->txt('mail'));
237
238 $attachment = new ilFileInputGUI($this->lng->txt('upload'), 'userfile');
239 $attachment->setRequired(true);
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');
244
245 $table = new ilMailAttachmentTableGUI($this, 'showAttachments');
246
247 $mail_data = $this->umail->retrieveFromStage();
248 $files = $this->mfile->getUserFilesData();
249 $data = [];
250 $counter = 0;
251 foreach ($files as $file) {
252 $checked = false;
253 if (is_array($mail_data['attachments']) && in_array($file['name'], $mail_data['attachments'], true)) {
254 $checked = true;
255 }
256
257 $data[$counter] = [
258 'checked' => $checked,
259 'filename' => $file['name'],
260 'filesize' => (int) $file['size'],
261 'filecreatedate' => (int) $file['ctime'],
262 ];
263
264 ++$counter;
265 }
266 $table->setData($data);
267
268 $this->tpl->setContent($table->getHTML());
269 $this->tpl->printToStdout();
270 }

References $data, ILIAS\Repository\ctrl(), ILIAS\Repository\int(), ILIAS\Repository\lng(), and ILIAS\Repository\toolbar().

Referenced by confirmDeleteAttachments(), deleteAttachments(), saveAttachments(), and uploadFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ uploadFile()

ilMailAttachmentGUI::uploadFile ( )

Definition at line 212 of file class.ilMailAttachmentGUI.php.

212 : void
213 {
214 if (isset($_FILES['userfile']['name']) && trim($_FILES['userfile']['name']) !== '') {
215 $form = $this->getToolbarForm();
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")
221 ) {
222 $this->tpl->setOnScreenMessage('failure', $form->getItemByPostVar('userfile')->getAlert());
223 } else {
224 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_maxsize_attachment_error') . ' ' .
225 ilUtil::formatSize($this->mfile->getUploadLimit()));
226 }
227 } else {
228 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_select_one_file'));
229 }
230
231 $this->showAttachments();
232 }

References ilUtil\formatSize(), getToolbarForm(), ILIAS\Repository\lng(), and showAttachments().

+ Here is the call graph for this function:

Field Documentation

◆ $ctrl

ilCtrlInterface ilMailAttachmentGUI::$ctrl
private

Definition at line 32 of file class.ilMailAttachmentGUI.php.

◆ $http

GlobalHttpState ilMailAttachmentGUI::$http
private

Definition at line 38 of file class.ilMailAttachmentGUI.php.

◆ $lng

ilLanguage ilMailAttachmentGUI::$lng
private

Definition at line 33 of file class.ilMailAttachmentGUI.php.

◆ $mfile

ilFileDataMail ilMailAttachmentGUI::$mfile
private

Definition at line 37 of file class.ilMailAttachmentGUI.php.

◆ $refinery

Refinery ilMailAttachmentGUI::$refinery
private

Definition at line 39 of file class.ilMailAttachmentGUI.php.

◆ $toolbar

ilToolbarGUI ilMailAttachmentGUI::$toolbar
private

Definition at line 35 of file class.ilMailAttachmentGUI.php.

◆ $tpl

ilGlobalTemplateInterface ilMailAttachmentGUI::$tpl
private

Definition at line 31 of file class.ilMailAttachmentGUI.php.

◆ $umail

ilFormatMail ilMailAttachmentGUI::$umail
private

Definition at line 36 of file class.ilMailAttachmentGUI.php.

◆ $user

ilObjUser ilMailAttachmentGUI::$user
private

Definition at line 34 of file class.ilMailAttachmentGUI.php.


The documentation for this class was generated from the following file: