ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilMailAttachmentGUI Class Reference
+ Inheritance diagram for ilMailAttachmentGUI:
+ Collaboration diagram for ilMailAttachmentGUI:

Public Member Functions

 __construct ()
 
 getUnsafeGetCommands ()
 This method must return a list of unsafe GET commands. More...
 
 getSafePostCommands ()
 This method must return a list of safe POST commands. More...
 
 manage ()
 
 consume ()
 
 executeCommand ()
 Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented. More...
 
 saveAttachments ()
 
 cancelSaveAttachments ()
 
 deleteAttachments ()
 
 confirmDeleteAttachments ()
 
 showAttachments ()
 
 getInfoResult (string $identifier)
 
 getInfoForExistingFiles (array $file_ids)
 
 getFileIdentifierParameterName ()
 
- Public Member Functions inherited from ILIAS\MetaData\OERExposer\OAIPMH\Handler\AbstractCtrlAwareUploadHandler
 __construct ()
 ilUIDemoFileUploadHandlerGUI constructor. More...
 
 getFileIdentifierParameterName ()
 
 getUploadURL ()
 
 getExistingFileInfoURL ()
 
 getFileRemovalURL ()
 
 executeCommand ()
 Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented. More...
 
 getInfoResult (string $identifier)
 
 getInfoForExistingFiles (array $file_ids)
 
 supportsChunkedUploads ()
 

Protected Member Functions

 getUploadResult ()
 
 getRemoveResult (string $identifier)
 
- Protected Member Functions inherited from ILIAS\MetaData\OERExposer\OAIPMH\Handler\AbstractCtrlAwareUploadHandler
 readChunkedInformation ()
 
 getUploadResult ()
 
 getRemoveResult (string $identifier)
 

Private Member Functions

 handleTableActions ()
 

Private Attributes

readonly ilGlobalTemplateInterface $tpl
 
readonly ilLanguage $lng
 
readonly ilObjUser $user
 
readonly ilFormatMail $umail
 
readonly ilFileDataMail $mfile
 
readonly Refinery $refinery
 
readonly ILIAS UI Factory $ui_factory
 
readonly ILIAS UI Renderer $ui_renderer
 
readonly ilTabsGUI $tabs
 
AttachmentManagement $mode = AttachmentManagement::MANAGE
 

Additional Inherited Members

- Data Fields inherited from ILIAS\UI\Component\Input\Field\UploadHandler
const DEFAULT_FILE_ID_PARAMETER = 'file_id'
 
- Protected Attributes inherited from ILIAS\MetaData\OERExposer\OAIPMH\Handler\AbstractCtrlAwareUploadHandler
const CMD_UPLOAD = 'upload'
 
const CMD_REMOVE = 'remove'
 
const CMD_INFO = 'info'
 
HttpServices $http
 
ilCtrl $ctrl
 
FileUpload $upload
 
bool $is_chunked = false
 
int $chunk_index = 0
 
int $amount_of_chunks = 0
 
string $chunk_id = null
 
int $chunk_total_size = 0
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilMailAttachmentGUI::__construct ( )

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

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), ILIAS\Repository\tabs(), and ILIAS\Repository\user().

44  {
45  global $DIC;
46 
48  $this->tpl = $DIC->ui()->mainTemplate();
49  $this->lng = $DIC->language();
50  $this->user = $DIC->user();
51  $this->tabs = $DIC->tabs();
52  $this->refinery = $DIC->refinery();
53  $this->ui_factory = $DIC->ui()->factory();
54  $this->ui_renderer = $DIC->ui()->renderer();
55 
56  $this->ctrl->saveParameter($this, 'mobj_id');
57 
58  $this->umail = new ilFormatMail($DIC->user()->getId());
59  $this->mfile = new ilFileDataMail($DIC->user()->getId());
60  }
This class handles all operations on files (attachments) in directory ilias_data/mail.
global $DIC
Definition: shib_login.php:25
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ cancelSaveAttachments()

ilMailAttachmentGUI::cancelSaveAttachments ( )

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

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

149  : void
150  {
151  $this->ctrl->setParameter($this, 'type', ilMailFormGUI::MAIL_FORM_TYPE_ATTACH);
152  $this->ctrl->returnToParent($this);
153  }
final const MAIL_FORM_TYPE_ATTACH
+ Here is the call graph for this function:

◆ confirmDeleteAttachments()

ilMailAttachmentGUI::confirmDeleteAttachments ( )

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

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

196  : void
197  {
198  $files = $this->http->wrapper()->post()->retrieve(
199  'filename',
200  $this->refinery->byTrying([
201  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
202  $this->refinery->always([])
203  ])
204  );
205 
206  if ($files === []) {
207  $this->tpl->setOnScreenMessage('info', $this->lng->txt('mail_select_one_mail'));
208  $this->showAttachments();
209  return;
210  }
211 
212  $decodedFiles = [];
213  foreach ($files as $value) {
214  $decodedFiles[] = urldecode($value);
215  }
216 
217  $error = $this->mfile->unlinkFiles($decodedFiles);
218  if ($error !== '') {
219  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_error_delete_file') . ' ' . $error, true);
220  } else {
221  $mail_data = $this->umail->retrieveFromStage();
222  if (is_array($mail_data['attachments'])) {
223  $tmp = [];
224  foreach ($mail_data['attachments'] as $attachment) {
225  if (!in_array($attachment, $decodedFiles, true)) {
226  $tmp[] = $attachment;
227  }
228  }
229  $this->umail->saveAttachments($tmp);
230  }
231 
232  $this->tpl->setOnScreenMessage('success', $this->lng->txt('mail_files_deleted'), true);
233  }
234 
235  $this->ctrl->redirect($this);
236  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ consume()

ilMailAttachmentGUI::consume ( )

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

References ILIAS\Mail\Attachments\CONSUME.

80  : self
81  {
82  $this->mode = AttachmentManagement::CONSUME;
83  return $this;
84  }

◆ deleteAttachments()

ilMailAttachmentGUI::deleteAttachments ( )

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

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

Referenced by handleTableActions().

155  : void
156  {
157  $files = $this->http->wrapper()->query()->retrieve(
158  'mail_attachments_filename',
159  $this->refinery->byTrying([
160  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
161  $this->refinery->always([])
162  ])
163  );
164 
165  if ($files !== [] && $files[0] === 'ALL_OBJECTS') {
166  $files = array_map(static function (array $file): string {
167  return $file['name'];
168  }, $this->mfile->getUserFilesData());
169  }
170 
171  if ($files === []) {
172  $this->tpl->setOnScreenMessage('info', $this->lng->txt('select_one'), true);
173  $this->ctrl->redirect($this);
174  }
175 
176  $this->tpl->setTitle($this->lng->txt('mail'));
177 
178  $confirmation = new ilConfirmationGUI();
179  $confirmation->setFormAction($this->ctrl->getFormAction($this, 'confirmDeleteAttachments'));
180  $confirmation->setConfirm($this->lng->txt('confirm'), 'confirmDeleteAttachments');
181  $confirmation->setCancel($this->lng->txt('cancel'), 'showAttachments');
182  $confirmation->setHeaderText($this->lng->txt('mail_sure_delete_file'));
183 
184  foreach ($files as $filename) {
185  $confirmation->addItem(
186  'filename[]',
187  ilUtil::stripSlashes($filename),
188  ilUtil::stripSlashes(urldecode($filename))
189  );
190  }
191 
192  $this->tpl->setContent($confirmation->getHTML());
193  $this->tpl->printToStdout();
194  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static http()
Fetches the global http state from ILIAS.
$filename
Definition: buildRTE.php:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilMailAttachmentGUI::executeCommand ( )

Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented.

The Implementation MUST make sure, the Upload and the Removal Command are handled correctly

Implements ILIAS\MetaData\OERExposer\OAIPMH\Handler\ilCtrlAwareUploadHandler.

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

References ILIAS\Repository\ctrl().

86  : void
87  {
88  if (!($cmd = $this->ctrl->getCmd())) {
89  $cmd = 'showAttachments';
90  }
91 
92  match ($cmd) {
93  AbstractCtrlAwareUploadHandler::CMD_UPLOAD,
94  AbstractCtrlAwareUploadHandler::CMD_INFO,
95  AbstractCtrlAwareUploadHandler::CMD_REMOVE => parent::executeCommand(),
96  default => $this->$cmd()
97  };
98  }
+ Here is the call graph for this function:

◆ getFileIdentifierParameterName()

ilMailAttachmentGUI::getFileIdentifierParameterName ( )
Returns
string defaults to self::DEFAULT_FILE_ID_PARAMETER

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

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

Referenced by getUploadResult().

373  : string
374  {
375  return 'userfile';
376  }
+ Here is the caller graph for this function:

◆ getInfoForExistingFiles()

ilMailAttachmentGUI::getInfoForExistingFiles ( array  $file_ids)
Parameters
array$file_ids
Returns
BasicFileInfoResult[]

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

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

368  : array
369  {
370  throw new DomainException('Not necessary for this handler');
371  }

◆ getInfoResult()

ilMailAttachmentGUI::getInfoResult ( string  $identifier)
Returns
null|FileInfoResult for the file with the given identifier or null if the file does not exist.

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

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

363  : ?FileInfoResult
364  {
365  throw new DomainException('Not necessary for this handler');
366  }

◆ getRemoveResult()

ilMailAttachmentGUI::getRemoveResult ( string  $identifier)
protected

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

358  : HandlerResult
359  {
360  throw new DomainException('Not necessary for this handler');
361  }

◆ getSafePostCommands()

ilMailAttachmentGUI::getSafePostCommands ( )

This method must return a list of safe POST commands.

Safe post commands returned by this method will no longer be CSRF protected and will NOT be appended by an ilCtrlToken.

Returns
string[]

Implements ilCtrlSecurityInterface.

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

69  : array
70  {
71  return [];
72  }

◆ getUnsafeGetCommands()

ilMailAttachmentGUI::getUnsafeGetCommands ( )

This method must return a list of unsafe GET commands.

Unsafe get commands returned by this method will now be CSRF protected, which means an ilCtrlToken is appended each time a link-target is generated to the class implementing this interface with a command from that list.

Tokens will be validated in

See also
ilCtrlInterface::getCmd(), whereas the fallback command will be used if the CSRF validation fails.
Returns
string[]

Implements ilCtrlSecurityInterface.

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

62  : array
63  {
64  return [
65  'handleTableActions',
66  ];
67  }

◆ getUploadResult()

ilMailAttachmentGUI::getUploadResult ( )
protected

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

References getFileIdentifierParameterName(), ILIAS\FileUpload\DTO\UploadResult\isOK(), ILIAS\Repository\lng(), and ILIAS\Repository\upload().

338  : HandlerResult
339  {
340  $this->upload->process();
341  $array = $this->upload->getResults();
342  $result = end($array);
343 
344  if ($result instanceof UploadResult && $result->isOK()) {
345  $identifier = $this->mfile->storeUploadedFile($result);
346  $status = HandlerResult::STATUS_OK;
347  $message = $this->lng->txt('saved_successfully');
348  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
349  } else {
350  $status = HandlerResult::STATUS_FAILED;
351  $identifier = '';
352  $message = $result->getStatus()->getMessage();
353  }
354 
355  return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
356  }
+ Here is the call graph for this function:

◆ handleTableActions()

ilMailAttachmentGUI::handleTableActions ( )
private

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

References ILIAS\Repository\ctrl(), deleteAttachments(), ILIAS\FileDelivery\http(), ILIAS\Repository\refinery(), and saveAttachments().

323  : void
324  {
325  $query = $this->http->wrapper()->query();
326  if (!$query->has('mail_attachments_table_action')) {
327  return;
328  }
329 
330  $action = $query->retrieve('mail_attachments_table_action', $this->refinery->to()->string());
331  match ($action) {
332  'saveAttachments' => $this->saveAttachments(),
333  'deleteAttachments' => $this->deleteAttachments(),
334  default => $this->ctrl->redirect($this),
335  };
336  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ manage()

ilMailAttachmentGUI::manage ( )

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

74  : self
75  {
76  $this->mode = AttachmentManagement::MANAGE;
77  return $this;
78  }

◆ saveAttachments()

ilMailAttachmentGUI::saveAttachments ( )

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

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

Referenced by handleTableActions().

100  : void
101  {
102  $files = [];
103 
104  // Important: Do not check for uploaded files here,
105  // otherwise it is no more possible to remove files (please ignore bug reports like 10137)
106 
107  $sizeOfSelectedFiles = 0;
108  $filesOfRequest = $this->http->wrapper()->query()->retrieve(
109  'mail_attachments_filename',
110  $this->refinery->byTrying([
111  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
112  $this->refinery->always([])
113  ])
114  );
115 
116  if ($filesOfRequest !== [] && $filesOfRequest[0] === 'ALL_OBJECTS') {
117  $filesOfRequest = array_map(static function (array $file): string {
118  return $file['name'];
119  }, $this->mfile->getUserFilesData());
120  }
121 
122  foreach ($filesOfRequest as $file) {
123  if (is_file($this->mfile->getMailPath() . '/' . basename($this->user->getId() . '_' . urldecode($file)))) {
124  $files[] = urldecode($file);
125  $sizeOfSelectedFiles += filesize(
126  $this->mfile->getMailPath() . '/' .
127  basename($this->user->getId() . '_' . urldecode($file))
128  );
129  }
130  }
131 
132  if ($files !== [] &&
133  null !== $this->mfile->getAttachmentsTotalSizeLimit() &&
134  $sizeOfSelectedFiles > $this->mfile->getAttachmentsTotalSizeLimit()) {
135  $this->tpl->setOnScreenMessage(
136  'failure',
137  $this->lng->txt('mail_max_size_attachments_total_error') . ' ' .
138  ilUtil::formatSize((int) $this->mfile->getAttachmentsTotalSizeLimit())
139  );
140  $this->showAttachments();
141  return;
142  }
143 
144  $this->umail->saveAttachments($files);
145 
146  $this->ctrl->returnToParent($this);
147  }
static http()
Fetches the global http state from ILIAS.
static formatSize(int $size, string $a_mode='short', ?ilLanguage $a_lng=null)
Returns the specified file size value in a human friendly form.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showAttachments()

ilMailAttachmentGUI::showAttachments ( )

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

References $components, $mode, ILIAS\Mail\Attachments\CONSUME, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\int(), ILIAS\Repository\lng(), ILIAS\Repository\tabs(), and ILIAS\Repository\user().

Referenced by confirmDeleteAttachments(), and saveAttachments().

238  : void
239  {
240  $this->tpl->setTitle($this->lng->txt('mail'));
241 
242  if ($this->mode === AttachmentManagement::CONSUME) {
243  $this->tabs->clearTargets();
244  $this->tabs->setBackTarget(
245  $this->lng->txt('mail_manage_attachments_back_to_compose'),
246  $this->ctrl->getLinkTarget($this, 'cancelSaveAttachments')
247  );
248  }
249 
250  $components = [];
251  if ($this->mode === AttachmentManagement::MANAGE) {
252  $dropzone = $this->ui_factory
253  ->dropzone()
254  ->file()
255  ->standard(
256  $this->lng->txt('mail_manage_attachments'),
257  $this->lng->txt('mail_manage_attachments_drop_files_msg'),
258  '#',
259  $this->ui_factory->input()->field()->file(
260  $this,
261  $this->lng->txt('file')
262  )->withMaxFiles(42) // The answer to life, universe and the rest
263  )
264  ->withBulky(true)
265  ->withUploadButton(
266  $this->ui_factory->button()->shy(
267  $this->lng->txt('upload'),
268  '#'
269  )
270  );
271  $components[] = $dropzone;
272  }
273 
274  $mail_data = $this->umail->retrieveFromStage();
275  $files = $this->mfile->getUserFilesData();
276  $records = [];
277  $checked_items = [];
278  foreach ($files as $file) {
279  if (is_array($mail_data['attachments']) && in_array($file['name'], $mail_data['attachments'], true)) {
280  $checked_items[] = urlencode($file['name']);
281  }
282 
283  $records[] = [
284  'filename' => $file['name'],
285  'filesize' => (int) $file['size'],
286  'filecreatedate' => (int) $file['ctime'],
287  ];
288  }
289 
290  $table = new MailAttachmentTableGUI(
291  $this,
292  $this->user,
293  $records,
294  $this->ui_factory,
295  $this->ui_renderer,
296  $this->lng,
297  $this->ctrl,
298  $this->http->request(),
299  new ILIAS\Data\Factory(),
300  'handleTableActions',
302  );
303  $components[] = $table->get();
304 
305  $this->tpl->setContent($this->ui_renderer->render($components));
306 
307  if ($this->mode === AttachmentManagement::CONSUME) {
308  // The table above has to be rendered first, because it deselects all checkboxes
309  $this->tpl->addOnLoadCode('
310  const checked_items = ' . json_encode($checked_items, JSON_THROW_ON_ERROR) . ';
311  for (const item of checked_items) {
312  const checkbox = document.querySelector("input[type=\'checkbox\'][value=\'" + item + "\']");
313  if (checkbox) {
314  checkbox.checked = true;
315  }
316  }
317  ');
318  }
319 
320  $this->tpl->printToStdout();
321  }
AttachmentManagement $mode
$components
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $lng

readonly ilLanguage ilMailAttachmentGUI::$lng
private

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

◆ $mfile

readonly ilFileDataMail ilMailAttachmentGUI::$mfile
private

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

◆ $mode

AttachmentManagement ilMailAttachmentGUI::$mode = AttachmentManagement::MANAGE
private

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

Referenced by showAttachments().

◆ $refinery

readonly Refinery ilMailAttachmentGUI::$refinery
private

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

◆ $tabs

readonly ilTabsGUI ilMailAttachmentGUI::$tabs
private

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

◆ $tpl

readonly ilGlobalTemplateInterface ilMailAttachmentGUI::$tpl
private

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

◆ $ui_factory

readonly ILIAS UI Factory ilMailAttachmentGUI::$ui_factory
private

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

◆ $ui_renderer

readonly ILIAS UI Renderer ilMailAttachmentGUI::$ui_renderer
private

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

◆ $umail

readonly ilFormatMail ilMailAttachmentGUI::$umail
private

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

◆ $user

readonly ilObjUser ilMailAttachmentGUI::$user
private

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


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