ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMailGUI.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4use Psr\Http\Message\ServerRequestInterface;
5
14{
16 private $tpl;
17
19 private $ctrl;
20
22 private $lng;
23
25 private $forwardClass = '';
26
28 private $httpRequest;
29
31 private $currentFolderId = 0;
32
34 private $user;
35
37 public $umail;
38
40 public $mbox;
41
45 public function __construct()
46 {
47 global $DIC;
48
49 $this->tpl = $DIC->ui()->mainTemplate();
50 $this->ctrl = $DIC->ctrl();
51 $this->lng = $DIC->language();
52 $this->user = $DIC->user();
53 $this->httpRequest = $DIC->http()->request();
54
55 $this->lng->loadLanguageModule('mail');
56
57 $this->mbox = new ilMailbox($this->user->getId());
58 $this->umail = new ilMail($this->user->getId());
59 if (!$DIC->rbac()->system()->checkAccess('internal_mail', $this->umail->getMailObjectReferenceId())) {
60 $DIC['ilErr']->raiseError($this->lng->txt('permission_denied'), $DIC['ilErr']->WARNING);
61 }
62
63 $this->initFolder();
64
65
66 $toolContext = $DIC->globalScreen()
67 ->tool()
68 ->context()
69 ->current();
70
71 $additionalDataExists = $toolContext->getAdditionalData()->exists(MailGlobalScreenToolProvider::SHOW_MAIL_FOLDERS_TOOL);
72 if (false === $additionalDataExists) {
73 $toolContext->addAdditionalData(MailGlobalScreenToolProvider::SHOW_MAIL_FOLDERS_TOOL, true);
74 }
75 }
76
80 protected function initFolder() : void
81 {
82 $folderId = (int) ($this->httpRequest->getParsedBody()['mobj_id'] ?? 0);
83 if (0 === $folderId) {
84 $folderId = (int) ($this->httpRequest->getQueryParams()['mobj_id'] ?? 0);
85 }
86 if (0 === $folderId || !$this->mbox->isOwnedFolder($folderId)) {
87 $folderId = $this->mbox->getInboxFolder();
88 }
89 $this->currentFolderId = (int) $folderId;
90 }
91
95 public function executeCommand() : void
96 {
97 $type = $this->httpRequest->getQueryParams()['type'] ?? '';
98 $mailId = (int) ($this->httpRequest->getQueryParams()['mail_id'] ?? 0);
99
100 $this->ctrl->setParameterByClass('ilmailformgui', 'mobj_id', $this->currentFolderId);
101 $this->ctrl->setParameterByClass('ilmailfoldergui', 'mobj_id', $this->currentFolderId);
102
103 if ('search_res' === $type) {
104 ilMailFormCall::storeReferer($this->httpRequest->getQueryParams());
105 $this->ctrl->redirectByClass('ilmailformgui', 'searchResults');
106 } elseif ('attach' === $type) {
107 ilMailFormCall::storeReferer($this->httpRequest->getQueryParams());
108 $this->ctrl->redirectByClass('ilmailformgui', 'mailAttachment');
109 } elseif ('new' === $type) {
110 foreach (['to', 'cc', 'bcc'] as $reciepient_type) {
111 $key = 'rcp_' . $reciepient_type;
112
113 $recipients = $this->httpRequest->getQueryParams()[$key] ?? '';
114
115 ilSession::set($key, ilUtil::stripSlashes($recipients));
116
117 if (ilSession::get($key) === '' &&
118 ($recipients = ilMailFormCall::getRecipients($reciepient_type))) {
119 ilSession::set($key, implode(',', $recipients));
120 ilMailFormCall::setRecipients([], $reciepient_type);
121 }
122 }
123
124 ilMailFormCall::storeReferer($this->httpRequest->getQueryParams());
125 $this->ctrl->redirectByClass('ilmailformgui', 'mailUser');
126 } elseif ('reply' === $type) {
127 ilSession::set('mail_id', $mailId);
128 $this->ctrl->redirectByClass('ilmailformgui', 'replyMail');
129 } elseif ('read' === $type) {
130 ilSession::set('mail_id', $mailId);
131 $this->ctrl->redirectByClass('ilmailfoldergui', 'showMail');
132 } elseif ('deliverFile' === $type) {
133 ilSession::set('mail_id', $mailId);
134
135 $fileName = '';
136 if (isset($this->httpRequest->getParsedBody()['filename'])) {
137 $fileName = $this->httpRequest->getParsedBody()['filename'];
138 } elseif (isset($this->httpRequest->getQueryParams()['filename'])) {
139 $fileName = $this->httpRequest->getQueryParams()['filename'];
140 }
141 ilSession::set('filename', ilUtil::stripSlashes($fileName));
142 $this->ctrl->redirectByClass('ilmailfoldergui', 'deliverFile');
143 } elseif ('message_sent' === $type) {
144 ilUtil::sendSuccess($this->lng->txt('mail_message_send'), true);
145 $this->ctrl->redirectByClass('ilmailfoldergui');
146 } elseif ('role' === $type) {
147 $roles = $this->httpRequest->getParsedBody()['roles'] ?? [];
148 if (is_array($roles) && count($roles) > 0) {
149 ilSession::set('mail_roles', $roles);
150 } elseif (isset($this->httpRequest->getQueryParams()['role'])) {
151 ilSession::set('mail_roles', [$this->httpRequest->getQueryParams()['role']]);
152 }
153
154 ilMailFormCall::storeReferer($this->httpRequest->getQueryParams());
155 $this->ctrl->redirectByClass('ilmailformgui', 'mailRole');
156 }
157
158 $view = (string) ($this->httpRequest->getQueryParams()['view'] ?? '');
159 if ('my_courses' === $view) {
160 ilSession::set('search_crs', ilUtil::stripSlashes($this->httpRequest->getQueryParams()['search_crs']));
161 $this->ctrl->redirectByClass('ilmailformgui', 'searchCoursesTo');
162 }
163
164 if (isset($this->httpRequest->getQueryParams()['viewmode'])) {
165 $this->ctrl->setCmd('setViewMode');
166 }
167
168 $this->forwardClass = (string) $this->ctrl->getNextClass($this);
169 $this->showHeader();
170
171 switch (strtolower($this->forwardClass)) {
172 case 'ilmailformgui':
173 $this->ctrl->forwardCommand(new ilMailFormGUI());
174 break;
175
176 case 'ilcontactgui':
177 $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
178 $this->ctrl->forwardCommand(new ilContactGUI());
179 break;
180
181 case 'ilmailoptionsgui':
182 $this->tpl->setTitle($this->lng->txt('mail'));
183 $this->ctrl->forwardCommand(new ilMailOptionsGUI());
184 break;
185
186 case 'ilmailfoldergui':
187 $this->ctrl->forwardCommand(new ilMailFolderGUI());
188 break;
189
190 default:
191 if (!($cmd = $this->ctrl->getCmd()) || !method_exists($this, $cmd)) {
192 $cmd = 'setViewMode';
193 }
194
195 $this->{$cmd}();
196 break;
197 }
198 }
199
203 private function setViewMode() : void
204 {
205 $targetClass = $this->httpRequest->getQueryParams()['target'] ?? 'ilmailfoldergui';
206 $type = $this->httpRequest->getQueryParams()['type'] ?? '';
207 $mailId = (int) ($this->httpRequest->getQueryParams()['mail_id'] ?? 0);
208
209 $this->ctrl->setParameterByClass($targetClass, 'mobj_id', $this->currentFolderId);
210
211 if ('redirect_to_read' === $type) {
212 $this->ctrl->setParameterByClass(
213 'ilMailFolderGUI',
214 'mail_id',
215 $mailId
216 );
217 $this->ctrl->setParameterByClass('ilmailfoldergui', 'mobj_id', $this->currentFolderId);
218 $this->ctrl->redirectByClass('ilMailFolderGUI', 'showMail');
219 } elseif ('add_subfolder' === $type) {
220 $this->ctrl->redirectByClass($targetClass, 'addSubFolder');
221 } elseif ('enter_folderdata' === $type) {
222 $this->ctrl->redirectByClass($targetClass, 'enterFolderData');
223 } elseif ('confirmdelete_folderdata' === $type) {
224 $this->ctrl->redirectByClass($targetClass, 'confirmDeleteFolder');
225 } else {
226 $this->ctrl->redirectByClass($targetClass);
227 }
228 }
229
233 private function showHeader() : void
234 {
235 global $DIC;
236
237 $DIC['ilHelp']->setScreenIdComponent("mail");
238 $DIC['ilMainMenu']->setActive("mail");
239
240 $this->tpl->loadStandardTemplate();
241 $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_mail.svg"));
242
244
245 $this->ctrl->setParameterByClass('ilmailfoldergui', 'mobj_id', $this->currentFolderId);
246 $DIC->tabs()->addTarget('fold', $this->ctrl->getLinkTargetByClass('ilmailfoldergui'));
247 $this->ctrl->clearParametersByClass('ilmailformgui');
248
249 $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'new');
250 $this->ctrl->setParameterByClass('ilmailformgui', 'mobj_id', $this->currentFolderId);
251 $DIC->tabs()->addTarget('compose', $this->ctrl->getLinkTargetByClass('ilmailformgui'));
252 $this->ctrl->clearParametersByClass('ilmailformgui');
253
254 $this->ctrl->setParameterByClass('ilcontactgui', 'mobj_id', $this->currentFolderId);
255 $DIC->tabs()->addTarget('mail_addressbook', $this->ctrl->getLinkTargetByClass('ilcontactgui'));
256 $this->ctrl->clearParametersByClass('ilcontactgui');
257
258 if ($DIC->settings()->get('show_mail_settings')) {
259 $this->ctrl->setParameterByClass('ilmailoptionsgui', 'mobj_id', $this->currentFolderId);
260 $DIC->tabs()->addTarget('options', $this->ctrl->getLinkTargetByClass('ilmailoptionsgui'));
261 $this->ctrl->clearParametersByClass('ilmailoptionsgui');
262 }
263
264 switch ($this->forwardClass) {
265 case 'ilmailformgui':
266 $DIC->tabs()->setTabActive('compose');
267 break;
268
269 case 'ilcontactgui':
270 $DIC->tabs()->setTabActive('mail_addressbook');
271 break;
272
273 case 'ilmailoptionsgui':
274 $DIC->tabs()->setTabActive('options');
275 break;
276
277 case 'ilmailfoldergui':
278 default:
279 $DIC->tabs()->setTabActive('fold');
280 break;
281 }
282
283 if (isset($this->httpRequest->getQueryParams()['message_sent'])) {
284 $DIC->tabs()->setTabActive('fold');
285 }
286 }
287
291 protected function toggleExplorerNodeState() : void
292 {
293 $exp = new ilMailExplorer($this, $this->user->getId());
294 $exp->toggleExplorerNodeState();
295 }
296}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Class Mail Explorer class for explorer view for mailboxes.
static storeReferer(array $queryParameters)
static getRecipients(string $type='to')
static setRecipients(array $recipients, string $type='to')
__construct()
ilMailGUI constructor.
toggleExplorerNodeState()
Toggle explorer tree node.
Mail Box class Base class for creating and handling mail boxes.
static set($a_var, $a_val)
Set a value.
static get($a_var)
Get a value.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static infoPanel($a_keep=true)
global $DIC
Definition: goto.php:24
$type