ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilMailGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
29 {
30  private readonly ilGlobalTemplateInterface $tpl;
31  private readonly ilCtrlInterface $ctrl;
32  private readonly ilLanguage $lng;
33  private string $forward_class = '';
34  private readonly GlobalHttpState $http;
35  private readonly Refinery $refinery;
36  private int $current_folder_id = 0;
37  private readonly ilObjUser $user;
38  public ilMail $umail;
39  public ilMailbox $mbox;
40 
41  public function __construct()
42  {
43  global $DIC;
44  $this->tpl = $DIC->ui()->mainTemplate();
45  $this->ctrl = $DIC->ctrl();
46  $this->lng = $DIC->language();
47  $this->user = $DIC->user();
48  $this->http = $DIC->http();
49  $this->refinery = $DIC->refinery();
50 
51  $this->lng->loadLanguageModule('mail');
52 
53  $this->mbox = new ilMailbox($this->user->getId());
54  $this->umail = new ilMail($this->user->getId());
55  if (
56  !$DIC->rbac()->system()->checkAccess(
57  'internal_mail',
58  $this->umail->getMailObjectReferenceId()
59  )
60  ) {
61  $DIC['ilErr']->raiseError($this->lng->txt('permission_denied'), $DIC['ilErr']->WARNING);
62  }
63 
64  $this->initFolder();
65 
66  $tool_context = $DIC->globalScreen()
67  ->tool()
68  ->context()
69  ->current();
70 
71  $additional_data_exists = $tool_context->getAdditionalData()->exists(
72  MailGlobalScreenToolProvider::SHOW_MAIL_FOLDERS_TOOL
73  );
74  if ($additional_data_exists === false) {
75  $tool_context->addAdditionalData(MailGlobalScreenToolProvider::SHOW_MAIL_FOLDERS_TOOL, true);
76  }
77  }
78 
79  protected function initFolder(): void
80  {
81  if ($this->http->wrapper()->post()->has('mobj_id')) {
82  $folder_id = $this->http->wrapper()->post()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
83  } elseif ($this->http->wrapper()->query()->has('mobj_id')) {
84  $folder_id = $this->http->wrapper()->query()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
85  } else {
86  $folder_id = $this->refinery->byTrying([
87  $this->refinery->kindlyTo()->int(),
88  $this->refinery->always($this->current_folder_id),
89  ])->transform(ilSession::get('mobj_id'));
90  }
91  if ($folder_id === 0 || !$this->mbox->isOwnedFolder($folder_id)) {
92  $folder_id = $this->mbox->getInboxFolder();
93  }
94  $this->current_folder_id = $folder_id;
95  }
96 
97  public function executeCommand(): void
98  {
99  $type = '';
100  if ($this->http->wrapper()->query()->has('type')) {
101  $type = $this->http->wrapper()->query()->retrieve('type', $this->refinery->kindlyTo()->string());
102  }
103  $mail_id = 0;
104  if ($this->http->wrapper()->query()->has('mail_id')) {
105  $mail_id = $this->http->wrapper()->query()->retrieve('mail_id', $this->refinery->kindlyTo()->int());
106  }
107 
108  $this->ctrl->setParameterByClass(ilMailFormGUI::class, 'mobj_id', $this->current_folder_id);
109  $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mobj_id', $this->current_folder_id);
110 
112  ilMailFormCall::storeReferer($this->http->request()->getQueryParams());
113  $this->ctrl->redirectByClass(ilMailFormGUI::class, 'searchResults');
114  } elseif (ilMailFormGUI::MAIL_FORM_TYPE_ATTACH === $type) {
115  ilMailFormCall::storeReferer($this->http->request()->getQueryParams());
116  $this->ctrl->redirectByClass(ilMailFormGUI::class, 'mailAttachment');
117  } elseif (ilMailFormGUI::MAIL_FORM_TYPE_NEW === $type) {
118  foreach (['to', 'cc', 'bcc'] as $reciepient_type) {
119  $key = 'rcp_' . $reciepient_type;
120 
121  $recipients = '';
122  if ($this->http->wrapper()->query()->has($key)) {
123  $recipients = $this->http->wrapper()->query()->retrieve(
124  $key,
125  $this->refinery->kindlyTo()->string()
126  );
127  }
128 
129  ilSession::set($key, ilUtil::stripSlashes($recipients));
130 
131  if (ilSession::get($key) === '' &&
132  ($recipients = ilMailFormCall::getRecipients($reciepient_type))) {
133  ilSession::set($key, implode(',', $recipients));
134  ilMailFormCall::setRecipients([], $reciepient_type);
135  }
136  }
137  ilMailFormCall::storeReferer($this->http->request()->getQueryParams());
138  $this->ctrl->redirectByClass(ilMailFormGUI::class, 'mailUser');
139  } elseif (ilMailFormGUI::MAIL_FORM_TYPE_REPLY === $type) {
140  $this->ctrl->setParameterByClass(ilMailFormGUI::class, 'mail_id', $mail_id);
141  $this->ctrl->redirectByClass(ilMailFormGUI::class, 'replyMail');
142  } elseif ($type === 'read') {
143  $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mail_id', $mail_id);
144  $this->ctrl->redirectByClass(ilMailFolderGUI::class, 'showMail');
145  } elseif ($type === 'deliverFile') {
146  $filename = '';
147  if ($this->http->wrapper()->post()->has('filename')) {
148  $filename = $this->http->wrapper()->post()->retrieve(
149  'filename',
150  $this->refinery->kindlyTo()->string()
151  );
152  } elseif ($this->http->wrapper()->query()->has('filename')) {
153  $filename = $this->http->wrapper()->query()->retrieve(
154  'filename',
155  $this->refinery->kindlyTo()->string()
156  );
157  }
158 
160  $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mail_id', $mail_id);
161  $this->ctrl->redirectByClass(ilMailFolderGUI::class, 'deliverFile');
162  } elseif ($type === 'message_sent') {
163  $this->tpl->setOnScreenMessage('success', $this->lng->txt('mail_message_send'), true);
164  $this->ctrl->redirectByClass(ilMailFolderGUI::class);
165  } elseif (ilMailFormGUI::MAIL_FORM_TYPE_ROLE === $type) {
166  $roles = [];
167  if ($this->http->wrapper()->post()->has('roles')) {
168  $roles = $this->http->wrapper()->post()->retrieve(
169  'roles',
170  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string())
171  );
172  } elseif ($this->http->wrapper()->query()->has('role')) {
173  $roles = [$this->http->wrapper()->query()->retrieve('role', $this->refinery->kindlyTo()->string())];
174  }
175 
176  if ($roles !== []) {
177  ilSession::set('mail_roles', $roles);
178  }
179 
180  ilMailFormCall::storeReferer($this->http->request()->getQueryParams());
181  $this->ctrl->redirectByClass(ilMailFormGUI::class, 'mailRole');
182  }
183 
184  $view = '';
185  if ($this->http->wrapper()->query()->has('view')) {
186  $view = $this->http->wrapper()->query()->retrieve('view', $this->refinery->kindlyTo()->string());
187  }
188  if ($view === 'my_courses') {
189  $search_crs = '';
190  if ($this->http->wrapper()->query()->has('search_crs')) {
191  $search_crs = ilUtil::stripSlashes(
192  $this->http->wrapper()->query()->retrieve('search_crs', $this->refinery->kindlyTo()->string())
193  );
194  }
195  $this->ctrl->setParameter($this, 'search_crs', $search_crs);
196  $this->ctrl->redirectByClass(ilMailFormGUI::class, 'searchCoursesTo');
197  }
198 
199  $this->forward_class = (string) $this->ctrl->getNextClass($this);
200  $this->showHeader();
201 
202  switch (strtolower($this->forward_class)) {
203  case strtolower(ilMailFormGUI::class):
204  $this->ctrl->forwardCommand(new ilMailFormGUI());
205  break;
206 
207  case strtolower(ilContactGUI::class):
208  $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
209  $this->ctrl->forwardCommand(new ilContactGUI());
210  break;
211 
212  case strtolower(ilMailAttachmentGUI::class):
213  $this->tpl->setTitle($this->lng->txt('mail'));
214  $gui = new ilMailAttachmentGUI();
215  $gui->manage();
216  $this->ctrl->forwardCommand($gui);
217  break;
218 
219  case strtolower(ilMailOptionsGUI::class):
220  $this->tpl->setTitle($this->lng->txt('mail'));
221  $this->ctrl->forwardCommand(new ilMailOptionsGUI());
222  break;
223 
224  case strtolower(ilMailFolderGUI::class):
225  $this->ctrl->forwardCommand(new ilMailFolderGUI());
226  break;
227 
228  default:
229  if (!($cmd = $this->ctrl->getCmd()) || !method_exists($this, $cmd)) {
230  $cmd = 'setViewMode';
231  }
232 
233  $this->{$cmd}();
234  break;
235  }
236  }
237 
238  private function setViewMode(): void
239  {
240  $target_class = ilMailFolderGUI::class;
241  if ($this->http->wrapper()->query()->has('target')) {
242  $target_class = $this->http->wrapper()->query()->retrieve(
243  'target',
244  $this->refinery->kindlyTo()->string()
245  );
246  }
247  $type = '';
248  if ($this->http->wrapper()->query()->has('type')) {
249  $type = $this->http->wrapper()->query()->retrieve('type', $this->refinery->kindlyTo()->string());
250  }
251  $mail_id = 0;
252  if ($this->http->wrapper()->query()->has('mail_id')) {
253  $mail_id = $this->http->wrapper()->query()->retrieve('mail_id', $this->refinery->kindlyTo()->int());
254  }
255 
256  $this->ctrl->setParameterByClass($target_class, 'mobj_id', $this->current_folder_id);
257 
258  if ($type === 'redirect_to_read') {
259  $this->ctrl->setParameterByClass(
260  ilMailFolderGUI::class,
261  'mail_id',
262  $mail_id
263  );
264  $this->ctrl->setParameterByClass(
265  ilMailFolderGUI::class,
266  'mobj_id',
267  $this->current_folder_id
268  );
269  $this->ctrl->redirectByClass(ilMailFolderGUI::class, 'showMail');
270  } elseif ($type === 'add_subfolder') {
271  $this->ctrl->redirectByClass($target_class, 'addSubFolder');
272  } elseif ($type === 'enter_folderdata') {
273  $this->ctrl->redirectByClass($target_class, 'enterFolderData');
274  } elseif ($type === 'confirmdelete_folderdata') {
275  $this->ctrl->redirectByClass($target_class, 'confirmDeleteFolder');
276  } else {
277  $this->ctrl->redirectByClass($target_class);
278  }
279  }
280 
281  private function showHeader(): void
282  {
283  global $DIC;
284 
285  $DIC['ilHelp']->setScreenIdComponent('mail');
286 
287  $this->tpl->loadStandardTemplate();
288  $this->tpl->setTitleIcon(ilUtil::getImagePath('standard/icon_mail.svg'));
289 
290  $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mobj_id', $this->current_folder_id);
291  $DIC->tabs()->addTarget('fold', $this->ctrl->getLinkTargetByClass(ilMailFolderGUI::class));
292  $this->ctrl->clearParametersByClass(ilMailFormGUI::class);
293 
294  $this->ctrl->setParameterByClass(ilMailFormGUI::class, 'type', ilMailFormGUI::MAIL_FORM_TYPE_NEW);
295  $this->ctrl->setParameterByClass(ilMailFormGUI::class, 'mobj_id', $this->current_folder_id);
296  $DIC->tabs()->addTarget('compose', $this->ctrl->getLinkTargetByClass(ilMailFormGUI::class));
297  $this->ctrl->clearParametersByClass(ilMailFormGUI::class);
298 
299  $this->ctrl->setParameterByClass(ilContactGUI::class, 'mobj_id', $this->current_folder_id);
300  $DIC->tabs()->addTarget(
301  'mail_addressbook',
302  $this->ctrl->getLinkTargetByClass(ilContactGUI::class)
303  );
304  $this->ctrl->clearParametersByClass(ilContactGUI::class);
305 
306  $this->ctrl->setParameterByClass(
307  ilMailAttachmentGUI::class,
308  'mobj_id',
309  $this->current_folder_id
310  );
311  $DIC->tabs()->addTarget(
312  'mail_manage_attachments',
313  $this->ctrl->getLinkTargetByClass([self::class, ilMailAttachmentGUI::class])
314  );
315  $this->ctrl->clearParametersByClass(ilMailAttachmentGUI::class);
316 
317  if ($DIC->settings()->get('show_mail_settings', '0')) {
318  $this->ctrl->setParameterByClass(
319  ilMailOptionsGUI::class,
320  'mobj_id',
321  $this->current_folder_id
322  );
323  $DIC->tabs()->addTarget(
324  'options',
325  $this->ctrl->getLinkTargetByClass(ilMailOptionsGUI::class)
326  );
327  $this->ctrl->clearParametersByClass(ilMailOptionsGUI::class);
328  }
329 
330  match (strtolower($this->forward_class)) {
331  strtolower(ilMailFormGUI::class) => $DIC->tabs()->setTabActive('compose'),
332  strtolower(ilContactGUI::class) => $DIC->tabs()->setTabActive('mail_addressbook'),
333  strtolower(ilMailOptionsGUI::class) => $DIC->tabs()->setTabActive('options'),
334  strtolower(ilMailAttachmentGUI::class) => $DIC->tabs()->setTabActive('mail_manage_attachments'),
335  default => $DIC->tabs()->setTabActive('fold'),
336  };
337 
338  if ($this->http->wrapper()->query()->has('message_sent')) {
339  $DIC->tabs()->setTabActive('fold');
340  }
341  }
342 
343  protected function toggleExplorerNodeState(): void
344  {
345  $exp = new ilMailExplorer($this, $this->user->getId());
346  $exp->toggleExplorerNodeState();
347  }
348 }
static get(string $a_var)
readonly GlobalHttpState $http
final const string MAIL_FORM_TYPE_NEW
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
final const string MAIL_FORM_TYPE_REPLY
readonly ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilMailFormGUI: ilMailAttachmentGUI, ilMailSearchGUI, ilMailSearchCoursesGUI, ilMailSearchGroupsGUI, ilMailingListsGUI
ilMailFolderGUI:
static http()
Fetches the global http state from ILIAS.
final const string MAIL_FORM_TYPE_ROLE
global $DIC
Definition: shib_login.php:26
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static getRecipients(string $type='to')
$filename
Definition: buildRTE.php:78
readonly ilCtrlInterface $ctrl
readonly ilLanguage $lng
final const string MAIL_FORM_TYPE_SEARCH_RESULT
static setRecipients(array $recipients, string $type='to')
final const string MAIL_FORM_TYPE_ATTACH
static storeReferer(array $query_parameters)
int $current_folder_id
readonly ilObjUser $user
ilMailbox $mbox
string $forward_class
static set(string $a_var, $a_val)
Set a value.
readonly Refinery $refinery