ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMailFolderGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
15  private $confirmTrashDeletion = false;
16 
18  private $errorDelete = false;
19 
21  private $tpl;
22 
24  private $ctrl;
25 
27  private $lng;
28 
30  private $toolbar;
31 
33  private $tabs;
34 
36  private $user;
37 
39  public $umail;
40 
42  public $mbox;
43 
45  private $httpRequest;
46 
48  private $currentFolderId = 0;
49 
53  public function __construct()
54  {
55  global $DIC;
56 
57  $this->tpl = $DIC->ui()->mainTemplate();
58  $this->ctrl = $DIC->ctrl();
59  $this->lng = $DIC->language();
60  $this->toolbar = $DIC->toolbar();
61  $this->user = $DIC->user();
62  $this->tabs = $DIC->tabs();
63  $this->httpRequest = $DIC->http()->request();
64 
65  $this->umail = new ilMail($this->user->getId());
66  $this->mbox = new ilMailbox($this->user->getId());
67 
68  $this->initFolder();
69  }
70 
74  protected function initFolder()
75  {
76  $folderId = $this->httpRequest->getParsedBody()['mobj_id'] ?? 0;
77  if (!is_numeric($folderId) || 0 == $folderId) {
78  $folderId = $this->httpRequest->getQueryParams()['mobj_id'] ?? 0;
79  }
80 
81  if (!is_numeric($folderId) || 0 == $folderId || !$this->mbox->isOwnedFolder($folderId)) {
82  $folderId = $this->mbox->getInboxFolder();
83  }
84 
85  $this->currentFolderId = (int) $folderId;
86  }
87 
92  protected function parseCommand(string $originalCommand) : string
93  {
94  $matches = [];
95  if (preg_match('/^([a-zA-Z0-9]+?)_(\d+?)$/', $originalCommand, $matches) && 3 === count($matches)) {
96  $originalCommand = $matches[1];
97  }
98 
99  return $originalCommand;
100  }
101 
107  protected function parseFolderIdFromCommand(string $command) : int
108  {
109  $matches = [];
110  if (
111  preg_match('/^([a-zA-Z0-9]+?)_(\d+?)$/', $command, $matches) &&
112  3 === count($matches) && is_numeric($matches[2])
113  ) {
114  return (int) $matches[2];
115  }
116 
117  throw new \InvalidArgumentException("Cannot parse a numeric folder id from command string!");
118  }
119 
123  public function executeCommand()
124  {
125  $cmd = $this->parseCommand(
126  $this->ctrl->getCmd()
127  );
128 
129  $nextClass = $this->ctrl->getNextClass($this);
130  switch ($nextClass) {
131  case 'ilcontactgui':
132  $this->ctrl->forwardCommand(new \ilContactGUI());
133  break;
134 
135  case 'ilmailoptionsgui':
136  $this->tpl->setTitle($this->lng->txt('mail'));
137  $this->ctrl->forwardCommand(new \ilMailOptionsGUI());
138  break;
139 
140  case 'ilpublicuserprofilegui':
141  $this->tpl->setTitle($this->lng->txt('mail'));
142  $profileGui = new \ilPublicUserProfileGUI((int) ($this->httpRequest->getQueryParams()['user'] ?? 0));
143 
144  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
145  $profileGui->setBackUrl($this->ctrl->getLinkTarget($this, 'showMail'));
146  $this->ctrl->clearParameters($this);
147 
148  $ret = $this->ctrl->forwardCommand($profileGui);
149  if ($ret != '') {
150  $this->tpl->setContent($ret);
151  }
152  $this->tpl->show();
153  break;
154 
155  default:
156  if (!method_exists($this, $cmd)) {
157  $cmd = 'showFolder';
158  }
159  $this->{$cmd}();
160  break;
161  }
162  }
163 
167  protected function performEmptyTrash()
168  {
169  $this->umail->deleteMailsOfFolder($this->currentFolderId);
170 
171  \ilUtil::sendSuccess($this->lng->txt('mail_deleted'), true);
172  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
173  $this->ctrl->redirect($this, 'showFolder');
174  }
175 
179  protected function confirmEmptyTrash()
180  {
181  if ($this->umail->countMailsOfFolder($this->currentFolderId)) {
182  $this->confirmTrashDeletion = true;
183  }
184 
185  $this->showFolder();
186  }
187 
191  protected function showUser()
192  {
193  $this->tpl->setVariable('TBL_TITLE', implode(' ', [
194  $this->lng->txt('profile_of'),
195  \ilObjUser::_lookupLogin((int) ($this->httpRequest->getQueryParams()['user'] ?? 0))
196  ]));
197  $this->tpl->setVariable('TBL_TITLE_IMG', ilUtil::getImagePath('icon_usr.svg'));
198  $this->tpl->setVariable('TBL_TITLE_IMG_ALT', $this->lng->txt('public_profile'));
199 
200  $profile_gui = new \ilPublicUserProfileGUI((int) ($this->httpRequest->getQueryParams()['user'] ?? 0));
201 
202  $this->ctrl->setParameter($this, 'mail_id', (int) $this->httpRequest->getQueryParams()['mail_id']);
203  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
204  $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, 'showMail'));
205  $this->ctrl->clearParameters($this);
206 
207  $this->tpl->setTitle($this->lng->txt('mail'));
208  $this->tpl->setContent($this->ctrl->getHTML($profile_gui));
209  $this->tpl->show();
210  }
211 
215  protected function addSubFolderCommands(bool $isUserSubFolder = false)
216  {
218  $this->toolbar->addSeparator();
219  }
220 
221  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
222  $this->toolbar->addButton($this->lng->txt('mail_add_subfolder'), $this->ctrl->getLinkTarget($this, 'addSubFolder'));
223 
224  if ($isUserSubFolder) {
225  $this->toolbar->addButton($this->lng->txt('rename'), $this->ctrl->getLinkTarget($this, 'renameSubFolder'));
226  $this->toolbar->addButton($this->lng->txt('delete'), $this->ctrl->getLinkTarget($this, 'deleteSubFolder'));
227  }
228  $this->ctrl->clearParameters($this);
229  }
230 
235  protected function showFolder(bool $oneConfirmationDialogueRendered = false)
236  {
237  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail.html', 'Services/Mail');
238  $this->tpl->setTitle($this->lng->txt('mail'));
239 
240  $sentFolderId = $this->mbox->getSentFolder();
241  $draftsFolderId = $this->mbox->getDraftsFolder();
242 
243  $isTrashFolder = $this->currentFolderId == $this->mbox->getTrashFolder();
244  $isSentFolder = $this->currentFolderId == $sentFolderId;
245  $isDraftFolder = $this->currentFolderId == $draftsFolderId;
246 
247  if ($isTrashFolder && 'deleteMails' === $this->parseCommand($this->ctrl->getCmd()) && !$this->errorDelete) {
248  $confirmationGui = new \ilConfirmationGUI();
249  $confirmationGui->setHeaderText($this->lng->txt('mail_sure_delete'));
250  foreach ($this->getMailIdsFromRequest() as $mailId) {
251  $confirmationGui->addHiddenItem('mail_id[]', $mailId);
252  }
253  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
254  $confirmationGui->setFormAction($this->ctrl->getFormAction($this, 'showFolder'));
255  $this->ctrl->clearParameters($this);
256  $confirmationGui->setConfirm($this->lng->txt('confirm'), 'confirmDeleteMails');
257  $confirmationGui->setCancel($this->lng->txt('cancel'), 'showFolder');
258  $this->tpl->setVariable('CONFIRMATION', $confirmationGui->getHTML());
259  $oneConfirmationDialogueRendered = true;
260  }
261 
262  $folders = $this->mbox->getSubFolders();
263  $mtree = new \ilTree($this->user->getId());
264  $mtree->setTableNames('mail_tree', 'mail_obj_data');
265 
266  $isUserSubFolder = false;
267  $isUserRootFolder = false;
268 
270  $folder_d = $mtree->getNodeData($this->currentFolderId);
271  if ($folder_d['m_type'] === 'user_folder') {
272  $isUserSubFolder = true;
273  } elseif ($folder_d['m_type'] === 'local') {
274  $isUserRootFolder = true;
275  }
276  }
277 
278  $mailtable = new ilMailFolderTableGUI($this, $this->currentFolderId, 'showFolder');
279  $mailtable->isSentFolder($isSentFolder)
280  ->isDraftFolder($isDraftFolder)
281  ->isTrashFolder($isTrashFolder)
282  ->setSelectedItems($this->getMailIdsFromRequest(true))
283  ->initFilter();
284 
285  try {
286  $mailtable->prepareHTML();
287  } catch (\Exception $e) {
289  $this->lng->txt($e->getMessage()) != '-' . $e->getMessage() . '-' ?
290  $this->lng->txt($e->getMessage()) :
291  $e->getMessage()
292  );
293  }
294 
295  $table_html = $mailtable->getHtml();
296 
297  $folder_options = array();
299  foreach ($folders as $folder) {
300  $folder_d = $mtree->getNodeData($folder['obj_id']);
301 
302  if ($folder['obj_id'] == $this->currentFolderId) {
303  if ($folder['type'] === 'user_folder') {
304  $isUserSubFolder = true;
305  } else {
306  if ($folder['type'] === 'local') {
307  $isUserRootFolder = true;
308  $isUserSubFolder = false;
309  }
310  }
311  }
312 
313  $folder_options[$folder['obj_id']] = sprintf(
314  $this->lng->txt('mail_change_to_folder'),
315  $this->lng->txt('mail_' . $folder['title'])
316  );
317  if ($folder['type'] === 'user_folder') {
318  $pre = '';
319  for ($i = 2; $i < $folder_d['depth'] - 1; $i++) {
320  $pre .= '&nbsp;';
321  }
322 
323  if ($folder_d['depth'] > 1) {
324  $pre .= '+';
325  }
326 
327  $folder_options[$folder['obj_id']] = sprintf(
328  $this->lng->txt('mail_change_to_folder'),
329  $pre . ' ' . $folder['title']
330  );
331  }
332  }
333  }
334 
335  if ($oneConfirmationDialogueRendered === false && $this->confirmTrashDeletion === false) {
337  $si = new \ilSelectInputGUI('', 'mobj_id');
338  $si->setOptions($folder_options);
339  $si->setValue($this->currentFolderId);
340  $this->toolbar->addStickyItem($si);
341 
343  $btn->setCaption('change');
344  $btn->setCommand('showFolder');
345  $this->toolbar->addStickyItem($btn);
346  $this->toolbar->setFormAction($this->ctrl->getFormAction($this, 'showFolder'));
347  }
348  if ($isUserRootFolder == true || $isUserSubFolder == true) {
349  $this->addSubFolderCommands($isUserSubFolder);
350  }
351  }
352 
353  if ($mailtable->isTrashFolder() && $mailtable->getNumberOfMails() > 0 && $this->confirmTrashDeletion === true) {
354  $confirmationGui = new \ilConfirmationGUI();
355  $confirmationGui->setHeaderText($this->lng->txt('mail_empty_trash_confirmation'));
356  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
357  $confirmationGui->setFormAction($this->ctrl->getFormAction($this, 'performEmptyTrash'));
358  $this->ctrl->clearParameters($this);
359  $confirmationGui->setConfirm($this->lng->txt('confirm'), 'performEmptyTrash');
360  $confirmationGui->setCancel($this->lng->txt('cancel'), 'showFolder');
361  $this->tpl->setVariable('CONFIRMATION', $confirmationGui->getHTML());
362  }
363 
364  $this->tpl->setVariable('MAIL_TABLE', $table_html);
365  $this->tpl->show();
366  }
367 
371  protected function deleteSubFolder($a_show_confirm = true)
372  {
373  if ($a_show_confirm) {
374  $confirmationGui = new \ilConfirmationGUI();
375  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
376  $confirmationGui->setFormAction($this->ctrl->getFormAction($this, 'showFolder'));
377  $this->ctrl->clearParameters($this);
378  $confirmationGui->setHeaderText($this->lng->txt('mail_sure_delete_folder'));
379  $confirmationGui->setCancel($this->lng->txt('cancel'), 'showFolder');
380  $confirmationGui->setConfirm($this->lng->txt('confirm'), 'performDeleteSubFolder');
381  $this->tpl->setVariable('CONFIRMATION', $confirmationGui->getHTML());
382 
383  $this->showFolder(true);
384  } else {
385  $this->showFolder(false);
386  }
387  }
388 
392  protected function performDeleteSubFolder()
393  {
394  $parentFolderId = $this->mbox->getParentFolderId($this->currentFolderId);
395  if ($parentFolderId > 0 && $this->mbox->deleteFolder($this->currentFolderId)) {
396  ilUtil::sendInfo($this->lng->txt('mail_folder_deleted'), true);
397  $this->ctrl->setParameterByClass('ilMailGUI', 'mobj_id', (int) $parentFolderId);
398  $this->ctrl->redirectByClass('ilMailGUI');
399  } else {
400  \ilUtil::sendFailure($this->lng->txt('mail_error_delete'));
401  $this->showFolder();
402  }
403  }
404 
409  protected function getSubFolderForm(string $mode = 'create') : \ilPropertyFormGUI
410  {
411  $form = new \ilPropertyFormGUI();
412  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
413  $form->setFormAction($this->ctrl->getFormAction($this, 'performAddSubFolder'));
414  $this->ctrl->clearParameters($this);
415  if ('edit' === $mode) {
416  $form->addCommandButton('performRenameSubFolder', $this->lng->txt('save'));
417  $form->setTitle($this->lng->txt('mail_rename_folder'));
418  } else {
419  $form->addCommandButton('performAddSubFolder', $this->lng->txt('save'));
420  $form->setTitle($this->lng->txt('mail_add_folder'));
421  }
422  $form->addCommandButton('showFolder', $this->lng->txt('cancel'));
423 
424  $title = new \ilTextInputGUI($this->lng->txt('title'), 'subfolder_title');
425  $title->setRequired(true);
426  $form->addItem($title);
427 
428  return $form;
429  }
430 
434  protected function performAddSubFolder()
435  {
436  $form = $this->getSubFolderForm();
437  $isFormValid = $form->checkInput();
438  $form->setValuesByPost();
439  if (!$isFormValid) {
440  $this->addSubFolder($form);
441  return;
442  }
443 
444  if ($newFolderId = $this->mbox->addFolder($this->currentFolderId, $form->getInput('subfolder_title'))) {
445  \ilUtil::sendSuccess($this->lng->txt('mail_folder_created'), true);
446  $this->ctrl->setParameterByClass('ilMailGUI', 'mobj_id', $newFolderId);
447  $this->ctrl->redirectByClass('ilMailGUI');
448  }
449 
450  \ilUtil::sendFailure($this->lng->txt('mail_folder_exists'));
451  $this->addSubFolder($form);
452  }
453 
458  protected function addSubFolder(\ilPropertyFormGUI $form = null)
459  {
460  if (null === $form) {
461  $form = $this->getSubFolderForm();
462  }
463 
464  $this->tpl->setTitle($this->lng->txt('mail'));
465  $this->tpl->setContent($form->getHTML());
466  $this->tpl->show();
467  }
468 
472  protected function performRenameSubFolder()
473  {
474  $form = $this->getSubFolderForm('edit');
475  $isFormValid = $form->checkInput();
476  $form->setValuesByPost();
477  if (!$isFormValid) {
478  $this->renameSubFolder($form);
479  return;
480  }
481 
482  $folderData = $this->mbox->getFolderData($this->currentFolderId);
483  if ($folderData['title'] === $form->getInput('subfolder_title')) {
484  $this->showFolder();
485  return;
486  }
487 
488  if ($this->mbox->renameFolder($this->currentFolderId, $form->getInput('subfolder_title'))) {
489  \ilUtil::sendSuccess($this->lng->txt('mail_folder_name_changed'), true);
490  $this->ctrl->setParameterByClass('ilMailGUI', 'mobj_id', $this->currentFolderId);
491  $this->ctrl->redirectByClass('ilMailGUI');
492  }
493 
494  \ilUtil::sendFailure($this->lng->txt('mail_folder_exists'));
495  $this->renameSubFolder($form);
496  }
497 
502  protected function renameSubFolder(\ilPropertyFormGUI $form = null)
503  {
504  if (null === $form) {
505  $form = $this->getSubFolderForm('edit');
506  $form->setValuesByArray(['subfolder_title' => $this->mbox->getFolderData($this->currentFolderId)['title']]);
507  }
508 
509  $this->tpl->setTitle($this->lng->txt('mail'));
510  $this->tpl->setContent($form->getHTML());
511  $this->tpl->show();
512  }
513 
518  protected function getMailIdsFromRequest(bool $ignoreHttpGet = false) : array
519  {
520  $mailIds = $this->httpRequest->getParsedBody()['mail_id'] ?? [];
521  if (!is_array($mailIds)) {
522  return [];
523  }
524 
525  if (0 === count($mailIds) && !$ignoreHttpGet) {
526  $mailId = $this->httpRequest->getQueryParams()['mail_id'] ?? 0;
527  if (is_numeric($mailId)) {
528  $mailIds = [$mailId];
529  }
530  }
531 
532  return array_filter(array_map('intval', $mailIds));
533  }
534 
538  protected function markMailsRead()
539  {
540  $mailIds = $this->getMailIdsFromRequest();
541  if (count($mailIds) > 0) {
542  $this->umail->markRead($mailIds);
543  \ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
544  } else {
545  \ilUtil::sendInfo($this->lng->txt('mail_select_one'));
546  }
547 
548  $this->showFolder();
549  }
550 
554  protected function markMailsUnread()
555  {
556  $mailIds = $this->getMailIdsFromRequest();
557  if (count($mailIds) > 0) {
558  $this->umail->markUnread($mailIds);
559  \ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
560  } else {
561  \ilUtil::sendInfo($this->lng->txt('mail_select_one'));
562  }
563 
564  $this->showFolder();
565  }
566 
570  protected function moveSingleMail()
571  {
572  $mailIds = $this->getMailIdsFromRequest();
573  if (1 !== count($mailIds)) {
574  $this->showMail();
575  \ilUtil::sendInfo($this->lng->txt('mail_select_one'));
576  return;
577  }
578 
579  $newFolderId = (int) ($this->httpRequest->getParsedBody()['folder_id'] ?? 0);
580  $redirectFolderId = $newFolderId;
581  foreach ($mailIds as $mailId) {
582  $mailData = $this->umail->getMail($mailId);
583  if (isset($mailData['folder_id']) && is_numeric($mailData['folder_id']) && (int) $mailData['folder_id'] > 0) {
584  $redirectFolderId = $mailData['folder_id'];
585  break;
586  }
587  }
588 
589  if ($this->umail->moveMailsToFolder($mailIds, $newFolderId)) {
590  \ilUtil::sendSuccess($this->lng->txt('mail_moved'), true);
591  $this->ctrl->setParameter($this, 'mobj_id', $redirectFolderId);
592  $this->ctrl->redirect($this, 'showFolder');
593  } else {
594  \ilUtil::sendFailure($this->lng->txt('mail_move_error'));
595  $this->showMail();
596  }
597  }
598 
602  protected function moveMails()
603  {
604  $mailIds = $this->getMailIdsFromRequest();
605  if (0 === count($mailIds)) {
606  $this->showFolder();
607  \ilUtil::sendInfo($this->lng->txt('mail_select_one'));
608  return;
609  }
610 
611  $folderId = $this->parseFolderIdFromCommand($this->ctrl->getCmd());
612  if ($this->umail->moveMailsToFolder($mailIds, $folderId)) {
613  \ilUtil::sendSuccess($this->lng->txt('mail_moved'), true);
614  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
615  $this->ctrl->redirect($this, 'showFolder');
616  } else {
617  \ilUtil::sendFailure($this->lng->txt('mail_move_error'));
618  $this->showFolder();
619  }
620  }
621 
625  protected function deleteMails()
626  {
627  $trashFolderId = (int) $this->mbox->getTrashFolder();
628  $mailIds = $this->getMailIdsFromRequest();
629 
630  if ($trashFolderId == $this->currentFolderId) {
631  if (0 === count($mailIds)) {
632  \ilUtil::sendInfo($this->lng->txt('mail_select_one'));
633  $this->errorDelete = true;
634  }
635  } else {
636  if (0 === count($mailIds)) {
637  \ilUtil::sendInfo($this->lng->txt('mail_select_one'));
638  } elseif ($this->umail->moveMailsToFolder($mailIds, $trashFolderId)) {
639  \ilUtil::sendSuccess($this->lng->txt('mail_moved_to_trash'), true);
640  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
641  $this->ctrl->redirect($this, 'showFolder');
642  } else {
643  \ilUtil::sendFailure($this->lng->txt('mail_move_error'));
644  }
645  }
646 
647  $this->showFolder();
648  }
649 
653  protected function confirmDeleteMails()
654  {
655  $mailIds = $this->getMailIdsFromRequest();
656  if (0 === count($mailIds)) {
657  $this->showFolder();
658  \ilUtil::sendInfo($this->lng->txt('mail_select_one'));
659  return;
660  }
661 
662  if ((int) $this->mbox->getTrashFolder() === (int) $this->currentFolderId) {
663  if ($this->umail->deleteMails($mailIds)) {
664  \ilUtil::sendSuccess($this->lng->txt('mail_deleted'), true);
665  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
666  $this->ctrl->redirect($this, 'showFolder');
667  } else {
668  \ilUtil::sendFailure($this->lng->txt('mail_delete_error'));
669  }
670  }
671 
672  $this->showFolder();
673  }
674 
678  protected function showMail()
679  {
680  if ((int) \ilSession::get('mail_id') > 0) {
681  $mailId = (int) \ilSession::get('mail_id');
682  \ilSession::set('mail_id', null);
683  } else {
684  $mailId = $this->httpRequest->getQueryParams()['mail_id'] ?? 0;
685  }
686 
687  $mailData = $this->umail->getMail($mailId);
688  $this->umail->markRead(array($mailId));
689 
690  $this->tpl->setTitle($this->lng->txt('mail_mails_of'));
691 
692  $this->tabs->clearTargets();
693  $this->ctrl->setParameter($this, 'mobj_id', $mailData['folder_id']);
694  $this->tabs->setBackTarget($this->lng->txt('back_to_folder'), $this->ctrl->getFormAction($this, 'showFolder'));
695  $this->ctrl->clearParameters($this);
696 
697  $this->ctrl->setParameter($this, 'mail_id', $mailId);
698  $this->ctrl->setParameter($this, 'mobj_id', $mailData['folder_id']);
699  $this->toolbar->setFormAction($this->ctrl->getFormAction($this, 'showMail'));
700  $this->ctrl->clearParameters($this);
701 
702  $form = new \ilPropertyFormGUI();
703  $form->setPreventDoubleSubmission(false);
704  $form->setTableWidth('100%');
705  $this->ctrl->setParameter($this, 'mobj_id', $mailData['folder_id']);
706  $this->ctrl->setParameter($this, 'mail_id', $mailId);
707  $form->setFormAction($this->ctrl->getFormAction($this, 'showMail'));
708  $this->ctrl->clearParameters($this);
709  $form->setTitle($this->lng->txt('mail_mails_of'));
710 
714  $sender = ilObjectFactory::getInstanceByObjId($mailData['sender_id'], false);
715  $replyBtn = null;
716  if ($sender && $sender->getId() && !$sender->isAnonymous()) {
717  $replyBtn = \ilLinkButton::getInstance();
718  $replyBtn->setCaption('reply');
719  $this->ctrl->setParameterByClass('ilmailformgui', 'mobj_id', $mailData['folder_id']);
720  $this->ctrl->setParameterByClass('ilmailformgui', 'mail_id', $mailId);
721  $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'reply');
722  $replyBtn->setUrl($this->ctrl->getLinkTargetByClass('ilmailformgui'));
723  $this->ctrl->clearParametersByClass('ilmailformgui');
724  $replyBtn->setAccessKey(\ilAccessKey::REPLY);
725  $replyBtn->setPrimary(true);
726  $this->toolbar->addStickyItem($replyBtn);
727  }
728 
729  $fwdBtn = \ilLinkButton::getInstance();
730  $fwdBtn->setCaption('forward');
731  $this->ctrl->setParameterByClass('ilmailformgui', 'mobj_id', $mailData['folder_id']);
732  $this->ctrl->setParameterByClass('ilmailformgui', 'mail_id', $mailId);
733  $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'forward');
734  $fwdBtn->setUrl($this->ctrl->getLinkTargetByClass('ilmailformgui'));
735  $this->ctrl->clearParametersByClass('ilmailformgui');
736  $fwdBtn->setAccessKey(\ilAccessKey::FORWARD_MAIL);
737  if (!$replyBtn) {
738  $fwdBtn->setPrimary(true);
739  $this->toolbar->addStickyItem($fwdBtn);
740  } else {
741  $this->toolbar->addButtonInstance($fwdBtn);
742  }
743 
744  $printBtn = \ilLinkButton::getInstance();
745  $printBtn->setCaption('print');
746  $this->ctrl->setParameter($this, 'mail_id', $mailId);
747  $this->ctrl->setParameter($this, 'mobj_id', $mailData['folder_id']);
748  $printBtn->setUrl($this->ctrl->getLinkTarget($this, 'printMail'));
749  $this->ctrl->clearParameters($this);
750  $printBtn->setTarget('_blank');
751  $this->toolbar->addButtonInstance($printBtn);
752 
753  $deleteBtn = \ilSubmitButton::getInstance();
754  $deleteBtn->setCaption('delete');
755  $deleteBtn->setCommand('deleteMails');
756  $deleteBtn->setAccessKey(\ilAccessKey::DELETE);
757  $this->toolbar->addButtonInstance($deleteBtn);
758 
759  if ($sender && $sender->getId() && !$sender->isAnonymous()) {
760  $linked_fullname = $sender->getPublicName();
761  $picture = ilUtil::img(
762  $sender->getPersonalPicturePath('xsmall'),
763  $sender->getPublicName(),
764  '',
765  '',
766  0,
767  '',
768  'ilMailAvatar'
769  );
770 
771  if (in_array(ilObjUser::_lookupPref($sender->getId(), 'public_profile'), array('y', 'g'))) {
772  $this->ctrl->setParameter($this, 'mail_id', $mailId);
773  $this->ctrl->setParameter($this, 'mobj_id', $mailData['folder_id']);
774  $this->ctrl->setParameter($this, 'user', $sender->getId());
775  $linked_fullname = '<br /><a href="' . $this->ctrl->getLinkTarget($this, 'showUser') . '" title="' . $linked_fullname . '">' . $linked_fullname . '</a>';
776  $this->ctrl->clearParameters($this);
777  }
778 
779  $from = new ilCustomInputGUI($this->lng->txt('from') . ':');
780  $from->setHtml($picture . ' ' . $linked_fullname);
781  $form->addItem($from);
782  } elseif (!$sender || !$sender->getId()) {
783  $from = new ilCustomInputGUI($this->lng->txt('from') . ':');
784  $from->setHtml($mailData['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')');
785  $form->addItem($from);
786  } else {
787  $from = new ilCustomInputGUI($this->lng->txt('from') . ':');
788  $from->setHtml(
789  ilUtil::img(ilUtil::getImagePath('HeaderIconAvatar.svg'), ilMail::_getIliasMailerName(), '', '', 0, '', 'ilMailAvatar') .
790  '<br />' . ilMail::_getIliasMailerName()
791  );
792  $form->addItem($from);
793  }
794 
795  $to = new ilCustomInputGUI($this->lng->txt('mail_to') . ':');
796  $to->setHtml(ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_to']), false));
797  $form->addItem($to);
798 
799  if ($mailData['rcp_cc']) {
800  $cc = new ilCustomInputGUI($this->lng->txt('cc') . ':');
801  $cc->setHtml(ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_cc']), false));
802  $form->addItem($cc);
803  }
804 
805  if ($mailData['rcp_bcc']) {
806  $bcc = new ilCustomInputGUI($this->lng->txt('bc') . ':');
807  $bcc->setHtml(ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_bcc']), false));
808  $form->addItem($bcc);
809  }
810 
811  $subject = new ilCustomInputGUI($this->lng->txt('subject') . ':');
812  $subject->setHtml(ilUtil::htmlencodePlainString($mailData['m_subject'], true));
813  $form->addItem($subject);
814 
815  $date = new ilCustomInputGUI($this->lng->txt('date') . ':');
816  $date->setHtml(ilDatePresentation::formatDate(new ilDateTime($mailData['send_time'], IL_CAL_DATETIME)));
817  $form->addItem($date);
818 
819  $message = new ilCustomInputGUI($this->lng->txt('message') . ':');
820  $message->setHtml(ilUtil::htmlencodePlainString($mailData['m_message'], true));
821  $form->addItem($message);
822 
823  if ($mailData['attachments']) {
824  $att = new ilCustomInputGUI($this->lng->txt('attachments') . ':');
825 
826  $radiog = new ilRadioGroupInputGUI('', 'filename');
827  foreach ($mailData['attachments'] as $file) {
828  $radiog->addOption(new ilRadioOption($file, md5($file)));
829  }
830 
831  $att->setHtml($radiog->render());
832  $form->addCommandButton('deliverFile', $this->lng->txt('download'));
833  $form->addItem($att);
834  }
835 
836  $isTrashFolder = false;
837  if ($this->mbox->getTrashFolder() == $mailData['folder_id']) {
838  $isTrashFolder = true;
839  }
840 
841  $currentFolderData = $this->mbox->getFolderData($mailData['folder_id']);
842  $actions = $this->mbox->getActions($mailData['folder_id']);
843 
844  $selectOptions = array();
845  foreach ($actions as $key => $action) {
846  if ($key === 'moveMails') {
847  $folders = $this->mbox->getSubFolders();
848  foreach ($folders as $folder) {
849  if (
850  ($folder['type'] !== 'trash' || !$isTrashFolder) &&
851  $folder['obj_id'] != $mailData['folder_id']
852  ) {
853  $optionText = $action . ' ' . $folder['title'];
854  if ($folder['type'] !== 'user_folder') {
855  $optionText = $action . ' ' . $this->lng->txt('mail_' . $folder['title']) . ($folder['type'] == 'trash' ? ' (' . $this->lng->txt('delete') . ')' : '');
856  }
857 
858  $selectOptions[$folder['obj_id']] = $optionText;
859  }
860  }
861  }
862  }
863 
864  $folderLabel = $this->lng->txt('mail_' . $currentFolderData['title']);
865  if ($currentFolderData['type'] === 'user_folder') {
866  $folderLabel = $currentFolderData['title'];
867  }
868 
869  $this->toolbar->addSeparator();
870  $this->toolbar->addText(sprintf($this->lng->txt('current_folder'), $folderLabel));
871 
872  if (is_array($selectOptions) && count($selectOptions) > 0) {
873  $actions = new \ilSelectInputGUI('', 'folder_id');
874  $actions->setOptions($selectOptions);
875  $this->toolbar->addInputItem($actions);
876 
877  $moveBtn = \ilSubmitButton::getInstance();
878  $moveBtn->setCaption('execute');
879  $moveBtn->setCommand('moveSingleMail');
880  $this->toolbar->addButtonInstance($moveBtn);
881  }
882 
883  $prevMail = $this->umail->getPreviousMail($mailId);
884  $nextMail = $this->umail->getNextMail($mailId);
885  if (is_array($prevMail) || is_array($nextMail)) {
886  $this->toolbar->addSeparator();
887 
888  if ($prevMail['mail_id']) {
889  $prevBtn = \ilLinkButton::getInstance();
890  $prevBtn->setCaption('previous');
891  $this->ctrl->setParameter($this, 'mail_id', $prevMail['mail_id']);
892  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
893  $prevBtn->setUrl($this->ctrl->getLinkTarget($this, 'showMail'));
894  $this->ctrl->clearParameters($this);
895  $this->toolbar->addButtonInstance($prevBtn);
896  }
897 
898  if ($nextMail['mail_id']) {
899  $nextBtn = \ilLinkButton::getInstance();
900  $nextBtn->setCaption('next');
901  $this->ctrl->setParameter($this, 'mail_id', $nextMail['mail_id']);
902  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
903  $nextBtn->setUrl($this->ctrl->getLinkTarget($this, 'showMail'));
904  $this->ctrl->clearParameters($this);
905  $this->toolbar->addButtonInstance($nextBtn);
906  }
907  }
908 
909  $this->tpl->setContent($form->getHTML());
910  $this->tpl->show();
911  }
912 
916  public function printMail()
917  {
918  $tplprint = new ilTemplate('tpl.mail_print.html', true, true, 'Services/Mail');
919  $tplprint->setVariable('JSPATH', $this->tpl->tplPath);
920 
921  $mailData = $this->umail->getMail((int) ($this->httpRequest->getQueryParams()['mail_id'] ?? 0));
922 
926  $sender = ilObjectFactory::getInstanceByObjId($mailData['sender_id'], false);
927 
928  $tplprint->setVariable('TXT_FROM', $this->lng->txt('from'));
929  if ($sender && $sender->getId() && !$sender->isAnonymous()) {
930  $tplprint->setVariable('FROM', $sender->getPublicName());
931  } elseif (!$sender || !$sender->getId()) {
932  $tplprint->setVariable('FROM', $mailData['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')');
933  } else {
934  $tplprint->setVariable('FROM', ilMail::_getIliasMailerName());
935  }
936 
937  $tplprint->setVariable('TXT_TO', $this->lng->txt('mail_to'));
938  $tplprint->setVariable('TO', $mailData['rcp_to']);
939 
940  if ($mailData['rcp_cc']) {
941  $tplprint->setCurrentBlock('cc');
942  $tplprint->setVariable('TXT_CC', $this->lng->txt('cc'));
943  $tplprint->setVariable('CC', $mailData['rcp_cc']);
944  $tplprint->parseCurrentBlock();
945  }
946 
947  if ($mailData['rcp_bcc']) {
948  $tplprint->setCurrentBlock('bcc');
949  $tplprint->setVariable('TXT_BCC', $this->lng->txt('bc'));
950  $tplprint->setVariable('BCC', $mailData['rcp_bcc']);
951  $tplprint->parseCurrentBlock();
952  }
953 
954  $tplprint->setVariable('TXT_SUBJECT', $this->lng->txt('subject'));
955  $tplprint->setVariable('SUBJECT', htmlspecialchars($mailData['m_subject']));
956 
957  $tplprint->setVariable('TXT_DATE', $this->lng->txt('date'));
958  $tplprint->setVariable('DATE', ilDatePresentation::formatDate(new ilDateTime($mailData['send_time'], IL_CAL_DATETIME)));
959 
960  $tplprint->setVariable('TXT_MESSAGE', $this->lng->txt('message'));
961  $tplprint->setVariable('MAIL_MESSAGE', nl2br(htmlspecialchars($mailData['m_message'])));
962 
963  $tplprint->show();
964  }
965 
966  protected function deliverFile()
967  {
968  $mailId = $this->httpRequest->getQueryParams()['mail_id'] ?? 0;
969  if ((int) \ilSession::get('mail_id') > 0) {
970  $mailId = \ilSession::get('mail_id');
971  \ilSession::set('mail_id', null);
972  }
973 
974  $filename = $this->httpRequest->getParsedBody()['filename'] ?? '';
975  if (is_string(ilSession::get('filename')) && strlen(\ilSession::get('filename')) > 0) {
976  $filename = \ilSession::get('filename');
977  \ilSession::set('filename', null);
978  }
979 
980  try {
981  if ($mailId > 0 && $filename !== '') {
982  while (strpos($filename, '..') !== false) {
983  $filename = str_replace('..', '', $filename);
984  }
985 
986  $mailFileData = new \ilFileDataMail($this->user->getId());
987  try {
988  $file = $mailFileData->getAttachmentPathAndFilenameByMd5Hash($filename, (int) $mailId);
989  \ilUtil::deliverFile($file['path'], $file['filename']);
990  } catch (\OutOfBoundsException $e) {
991  throw new \ilException('mail_error_reading_attachment');
992  }
993  } else {
994  \ilUtil::sendInfo($this->lng->txt('mail_select_attachment'));
995  $this->showMail();
996  }
997  } catch (\Exception $e) {
998  \ilUtil::sendFailure($this->lng->txt($e->getMessage()), true);
999  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
1000  $this->ctrl->redirect($this);
1001  }
1002  }
1003 
1004  protected function deliverAttachments()
1005  {
1006  try {
1007  $mailId = $this->httpRequest->getQueryParams()['mail_id'] ?? 0;
1008 
1009  $mailData = $this->umail->getMail((int) $mailId);
1010  if (null === $mailData || 0 === count((array) $mailData['attachments'])) {
1011  throw new \ilException('mail_error_reading_attachment');
1012  }
1013 
1014  $type = $this->httpRequest->getQueryParams()['type'] ?? '';
1015 
1016  $mailFileData = new \ilFileDataMail($this->user->getId());
1017  if (count($mailData['attachments']) === 1) {
1018  $attachment = current($mailData['attachments']);
1019 
1020  try {
1021  if ('draft' === $type) {
1022  if (!$mailFileData->checkFilesExist([$attachment])) {
1023  throw new \OutOfBoundsException('');
1024  }
1025  $pathToFile = $mailFileData->getAbsoluteAttachmentPoolPathByFilename($attachment);
1026  $fileName = $attachment;
1027  } else {
1028  $file = $mailFileData->getAttachmentPathAndFilenameByMd5Hash(md5($attachment), (int) $mailId);
1029  $pathToFile = $file['path'];
1030  $fileName = $file['filename'];
1031  }
1032  \ilUtil::deliverFile($pathToFile, $fileName);
1033  } catch (\OutOfBoundsException $e) {
1034  throw new \ilException('mail_error_reading_attachment');
1035  }
1036  } else {
1037  $mailFileData->deliverAttachmentsAsZip(
1038  $mailData['m_subject'],
1039  (int) $mailId,
1040  $mailData['attachments'],
1041  'draft' === $type
1042  );
1043  }
1044  } catch (\Exception $e) {
1045  \ilUtil::sendFailure($this->lng->txt($e->getMessage()), true);
1046  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
1047  $this->ctrl->redirect($this);
1048  }
1049  }
1050 
1054  protected function applyFilter()
1055  {
1056  $sentFolderId = $this->mbox->getSentFolder();
1057  $draftsFolderId = $this->mbox->getDraftsFolder();
1058 
1059  $isTrashFolder = $this->currentFolderId == $this->mbox->getTrashFolder();
1060  $isSentFolder = $this->currentFolderId == $sentFolderId;
1061  $isDraftFolder = $this->currentFolderId == $draftsFolderId;
1062 
1063  $table = new ilMailFolderTableGUI($this, $this->currentFolderId, 'showFolder');
1064  $table->isSentFolder($isSentFolder)
1065  ->isDraftFolder($isDraftFolder)
1066  ->isTrashFolder($isTrashFolder)
1067  ->initFilter();
1068  $table->resetOffset();
1069  $table->writeFilterToSession();
1070 
1071  $this->showFolder();
1072  }
1073 
1077  protected function resetFilter()
1078  {
1079  $sentFolderId = $this->mbox->getSentFolder();
1080  $draftsFolderId = $this->mbox->getDraftsFolder();
1081 
1082  $isTrashFolder = $this->currentFolderId == $this->mbox->getTrashFolder();
1083  $isSentFolder = $this->currentFolderId == $sentFolderId;
1084  $isDraftFolder = $this->currentFolderId == $draftsFolderId;
1085 
1086  $table = new ilMailFolderTableGUI($this, $this->currentFolderId, 'showFolder');
1087  $table->isSentFolder($isSentFolder)
1088  ->isDraftFolder($isDraftFolder)
1089  ->isTrashFolder($isTrashFolder)
1090  ->initFilter();
1091  $table->resetOffset();
1092  $table->resetFilter();
1093 
1094  $this->showFolder();
1095  }
1096 }
static _lookupLogin($a_user_id)
lookup login
getMailIdsFromRequest(bool $ignoreHttpGet=false)
This class represents an option in a radio group.
addSubFolder(\ilPropertyFormGUI $form=null)
Called if the acting user wants to create a folder.
setHtml($a_html)
Set Html.
__construct()
ilMailFolderGUI constructor.
markMailsRead()
Called if multiple messages should be marked as read in the list view.
const IL_CAL_DATETIME
This class represents a property form user interface.
$action
$type
global $DIC
Definition: saml.php:7
deleteSubFolder($a_show_confirm=true)
static get($a_var)
Get a value.
static set($a_var, $a_val)
Set a value.
renameSubFolder(\ilPropertyFormGUI $form=null)
Called if the acting user wants to rename a folder.
$from
confirmDeleteMails()
Called if the final deletion of selected messages was confirmed by the acting user.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
performAddSubFolder()
Called if a folder is created by the action user.
user()
Definition: user.php:4
const VIEWMODE_SESSION_KEY
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
parseFolderIdFromCommand(string $command)
catch(Exception $e) $message
This class represents a property in a property form.
if(isset($_POST['submit'])) $form
getSubFolderForm(string $mode='create')
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
Mail Box class Base class for creating and handling mail boxes.
addSubFolderCommands(bool $isUserSubFolder=false)
special template class to simplify handling of ITX/PEAR
markMailsUnread()
Called if multiple messages should be marked as un-read in the list view.
Date and time handling
moveMails()
Called if a single message or multiple messages should be be moved in the list view.
showFolder(bool $oneConfirmationDialogueRendered=false)
Shows current folder.
parseCommand(string $originalCommand)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$filename
Definition: buildRTE.php:89
This class represents a custom property in a property form.
deleteMails()
Called if a single message or multiple messages should be deleted.
moveSingleMail()
Called if a single message should be be moved in the detail view.
static _lookupPref($a_usr_id, $a_keyword)
performRenameSubFolder()
Called if the folder title is renamed by the acting user.
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
confirmEmptyTrash()
Called if the deletion of messages in trash should be confirmed by the acting user.
performEmptyTrash()
Called if the deletion of all messages in trash was confirmed by the acting user. ...
if(empty($password)) $table
Definition: pwgen.php:24
static htmlencodePlainString($a_str, $a_make_links_clickable, $a_detect_goto_links=false)
Encodes a plain text string into HTML for display in a browser.
$key
Definition: croninfo.php:18
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.