ILIAS  release_8 Revision v8.24
class.ilMailGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Refinery\Factory as Refinery;
24
32{
36 private string $forwardClass = '';
38 private Refinery $refinery;
39 private int $currentFolderId = 0;
41 public ilMail $umail;
43
44 public function __construct()
45 {
46 global $DIC;
47 $this->tpl = $DIC->ui()->mainTemplate();
48 $this->ctrl = $DIC->ctrl();
49 $this->lng = $DIC->language();
50 $this->user = $DIC->user();
51 $this->http = $DIC->http();
52 $this->refinery = $DIC->refinery();
53
54 $this->lng->loadLanguageModule('mail');
55
56 $this->mbox = new ilMailbox($this->user->getId());
57 $this->umail = new ilMail($this->user->getId());
58 if (
59 !$DIC->rbac()->system()->checkAccess(
60 'internal_mail',
61 $this->umail->getMailObjectReferenceId()
62 )
63 ) {
64 $DIC['ilErr']->raiseError($this->lng->txt('permission_denied'), $DIC['ilErr']->WARNING);
65 }
66
67 $this->initFolder();
68
69 $toolContext = $DIC->globalScreen()
70 ->tool()
71 ->context()
72 ->current();
73
74 $additionalDataExists = $toolContext->getAdditionalData()->exists(
75 MailGlobalScreenToolProvider::SHOW_MAIL_FOLDERS_TOOL
76 );
77 if (false === $additionalDataExists) {
78 $toolContext->addAdditionalData(MailGlobalScreenToolProvider::SHOW_MAIL_FOLDERS_TOOL, true);
79 }
80 }
81
82 protected function initFolder(): void
83 {
84 if ($this->http->wrapper()->post()->has('mobj_id')) {
85 $folderId = $this->http->wrapper()->post()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
86 } elseif ($this->http->wrapper()->query()->has('mobj_id')) {
87 $folderId = $this->http->wrapper()->query()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
88 } else {
89 $folderId = $this->refinery->byTrying([
90 $this->refinery->kindlyTo()->int(),
91 $this->refinery->always($this->currentFolderId),
92 ])->transform(ilSession::get('mobj_id'));
93 }
94 if (0 === $folderId || !$this->mbox->isOwnedFolder($folderId)) {
95 $folderId = $this->mbox->getInboxFolder();
96 }
97 $this->currentFolderId = $folderId;
98 }
99
100 public function executeCommand(): void
101 {
102 $type = "";
103 if ($this->http->wrapper()->query()->has('type')) {
104 $type = $this->http->wrapper()->query()->retrieve('type', $this->refinery->kindlyTo()->string());
105 }
106 $mailId = 0;
107 if ($this->http->wrapper()->query()->has('mail_id')) {
108 $mailId = $this->http->wrapper()->query()->retrieve('mail_id', $this->refinery->kindlyTo()->int());
109 }
110
111 $this->ctrl->setParameterByClass(ilMailFormGUI::class, 'mobj_id', $this->currentFolderId);
112 $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mobj_id', $this->currentFolderId);
113
115 ilMailFormCall::storeReferer($this->http->request()->getQueryParams());
116 $this->ctrl->redirectByClass(ilMailFormGUI::class, 'searchResults');
118 ilMailFormCall::storeReferer($this->http->request()->getQueryParams());
119 $this->ctrl->redirectByClass(ilMailFormGUI::class, 'mailAttachment');
121 foreach (['to', 'cc', 'bcc'] as $reciepient_type) {
122 $key = 'rcp_' . $reciepient_type;
123
124 $recipients = '';
125 if ($this->http->wrapper()->query()->has($key)) {
126 $recipients = $this->http->wrapper()->query()->retrieve(
127 $key,
128 $this->refinery->kindlyTo()->string()
129 );
130 }
131
133
134 if (ilSession::get($key) === '' &&
135 ($recipients = ilMailFormCall::getRecipients($reciepient_type))) {
136 ilSession::set($key, implode(',', $recipients));
137 ilMailFormCall::setRecipients([], $reciepient_type);
138 }
139 }
140 ilMailFormCall::storeReferer($this->http->request()->getQueryParams());
141 $this->ctrl->redirectByClass(ilMailFormGUI::class, 'mailUser');
143 $this->ctrl->setParameterByClass(ilMailFormGUI::class, 'mail_id', $mailId);
144 $this->ctrl->redirectByClass(ilMailFormGUI::class, 'replyMail');
145 } elseif ('read' === $type) {
146 $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mail_id', $mailId);
147 $this->ctrl->redirectByClass(ilMailFolderGUI::class, 'showMail');
148 } elseif ('deliverFile' === $type) {
149 $fileName = "";
150 if ($this->http->wrapper()->post()->has('filename')) {
151 $fileName = $this->http->wrapper()->post()->retrieve(
152 'filename',
153 $this->refinery->kindlyTo()->string()
154 );
155 } elseif ($this->http->wrapper()->query()->has('filename')) {
156 $fileName = $this->http->wrapper()->query()->retrieve(
157 'filename',
158 $this->refinery->kindlyTo()->string()
159 );
160 }
161
162 ilSession::set('filename', ilUtil::stripSlashes($fileName));
163 $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mail_id', $mailId);
164 $this->ctrl->redirectByClass(ilMailFolderGUI::class, 'deliverFile');
165 } elseif ('message_sent' === $type) {
166 $this->tpl->setOnScreenMessage('success', $this->lng->txt('mail_message_send'), true);
167 $this->ctrl->redirectByClass(ilMailFolderGUI::class);
169 $roles = [];
170 if ($this->http->wrapper()->post()->has('roles')) {
171 $roles = $this->http->wrapper()->post()->retrieve(
172 'roles',
173 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string())
174 );
175 } elseif ($this->http->wrapper()->query()->has('role')) {
176 $roles = [$this->http->wrapper()->query()->retrieve('role', $this->refinery->kindlyTo()->string())];
177 }
178
179 if ($roles !== []) {
180 ilSession::set('mail_roles', $roles);
181 }
182
183 ilMailFormCall::storeReferer($this->http->request()->getQueryParams());
184 $this->ctrl->redirectByClass(ilMailFormGUI::class, 'mailRole');
185 }
186
187 $view = "";
188 if ($this->http->wrapper()->query()->has('view')) {
189 $view = $this->http->wrapper()->query()->retrieve('view', $this->refinery->kindlyTo()->string());
190 }
191 if ('my_courses' === $view) {
192 $search_crs = "";
193 if ($this->http->wrapper()->query()->has('search_crs')) {
194 $search_crs = ilUtil::stripSlashes(
195 $this->http->wrapper()->query()->retrieve('search_crs', $this->refinery->kindlyTo()->string())
196 );
197 }
198 $this->ctrl->setParameter($this, 'search_crs', $search_crs);
199 $this->ctrl->redirectByClass(ilMailFormGUI::class, 'searchCoursesTo');
200 }
201
202 if ($this->http->wrapper()->query()->has('viewmode')) {
203 $this->ctrl->setCmd('setViewMode');
204 }
205
206 $this->forwardClass = (string) $this->ctrl->getNextClass($this);
207 $this->showHeader();
208
209 switch (strtolower($this->forwardClass)) {
210 case strtolower(ilMailFormGUI::class):
211 $this->ctrl->forwardCommand(new ilMailFormGUI());
212 break;
213
214 case strtolower(ilContactGUI::class):
215 $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
216 $this->ctrl->forwardCommand(new ilContactGUI());
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 $targetClass = ilMailFolderGUI::class;
241 if ($this->http->wrapper()->query()->has('target')) {
242 $targetClass = $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 $mailId = 0;
252 if ($this->http->wrapper()->query()->has('mail_id')) {
253 $mailId = $this->http->wrapper()->query()->retrieve('mail_id', $this->refinery->kindlyTo()->int());
254 }
255
256 $this->ctrl->setParameterByClass($targetClass, 'mobj_id', $this->currentFolderId);
257
258 if ('redirect_to_read' === $type) {
259 $this->ctrl->setParameterByClass(
260 ilMailFolderGUI::class,
261 'mail_id',
262 $mailId
263 );
264 $this->ctrl->setParameterByClass(
265 ilMailFolderGUI::class,
266 'mobj_id',
267 $this->currentFolderId
268 );
269 $this->ctrl->redirectByClass(ilMailFolderGUI::class, 'showMail');
270 } elseif ('add_subfolder' === $type) {
271 $this->ctrl->redirectByClass($targetClass, 'addSubFolder');
272 } elseif ('enter_folderdata' === $type) {
273 $this->ctrl->redirectByClass($targetClass, 'enterFolderData');
274 } elseif ('confirmdelete_folderdata' === $type) {
275 $this->ctrl->redirectByClass($targetClass, 'confirmDeleteFolder');
276 } else {
277 $this->ctrl->redirectByClass($targetClass);
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("icon_mail.svg"));
289
290 $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mobj_id', $this->currentFolderId);
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->currentFolderId);
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->currentFolderId);
300 $DIC->tabs()->addTarget(
301 'mail_addressbook',
302 $this->ctrl->getLinkTargetByClass(ilContactGUI::class)
303 );
304 $this->ctrl->clearParametersByClass(ilContactGUI::class);
305
306 if ($DIC->settings()->get('show_mail_settings', '0')) {
307 $this->ctrl->setParameterByClass(
308 ilMailOptionsGUI::class,
309 'mobj_id',
310 $this->currentFolderId
311 );
312 $DIC->tabs()->addTarget(
313 'options',
314 $this->ctrl->getLinkTargetByClass(ilMailOptionsGUI::class)
315 );
316 $this->ctrl->clearParametersByClass(ilMailOptionsGUI::class);
317 }
318
319 switch (strtolower($this->forwardClass)) {
320 case strtolower(ilMailFormGUI::class):
321 $DIC->tabs()->setTabActive('compose');
322 break;
323
324 case strtolower(ilContactGUI::class):
325 $DIC->tabs()->setTabActive('mail_addressbook');
326 break;
327
328 case strtolower(ilMailOptionsGUI::class):
329 $DIC->tabs()->setTabActive('options');
330 break;
331
332 case strtolower(ilMailFolderGUI::class):
333 default:
334 $DIC->tabs()->setTabActive('fold');
335 break;
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}
Builds data types.
Definition: Factory.php:21
language handling
static storeReferer(array $queryParameters)
static getRecipients(string $type='to')
static setRecipients(array $recipients, string $type='to')
const MAIL_FORM_TYPE_SEARCH_RESULT
GlobalHttpState $http
string $forwardClass
ilGlobalTemplateInterface $tpl
Refinery $refinery
ilMailbox $mbox
int $currentFolderId
ilObjUser $user
ilCtrlInterface $ctrl
ilLanguage $lng
Mail Box class Base class for creating and handling mail boxes.
User class.
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
global $DIC
Definition: feed.php:28
Interface GlobalHttpState.
Interface ilCtrlBaseClassInterface describes ilCtrl base classes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
string $key
Consumer key/client ID value.
Definition: System.php:193
$type