ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $to = $this->httpRequest->getQueryParams()['rcp_to'] ?? '';
111 ilSession::set('rcp_to', ilUtil::stripSlashes($to));
112 if (!strlen(ilSession::get('rcp_to')) && ($recipients = ilMailFormCall::getRecipients())) {
113 ilSession::set('rcp_to', implode(',', $recipients));
115 }
116
117 $cc = $this->httpRequest->getQueryParams()['rcp_cc'] ?? '';
118 $bcc = $this->httpRequest->getQueryParams()['rcp_bcc'] ?? '';
119 ilSession::set('rcp_cc', ilUtil::stripSlashes($cc));
120 ilSession::set('rcp_bcc', ilUtil::stripSlashes($bcc));
121
122 ilMailFormCall::storeReferer($this->httpRequest->getQueryParams());
123 $this->ctrl->redirectByClass('ilmailformgui', 'mailUser');
124 } elseif ('reply' === $type) {
125 ilSession::set('mail_id', $mailId);
126 $this->ctrl->redirectByClass('ilmailformgui', 'replyMail');
127 } elseif ('read' === $type) {
128 ilSession::set('mail_id', $mailId);
129 $this->ctrl->redirectByClass('ilmailfoldergui', 'showMail');
130 } elseif ('deliverFile' === $type) {
131 ilSession::set('mail_id', $mailId);
132
133 $fileName = '';
134 if (isset($this->httpRequest->getParsedBody()['filename'])) {
135 $fileName = $this->httpRequest->getParsedBody()['filename'];
136 } elseif (isset($this->httpRequest->getQueryParams()['filename'])) {
137 $fileName = $this->httpRequest->getQueryParams()['filename'];
138 }
139 ilSession::set('filename', ilUtil::stripSlashes($fileName));
140 $this->ctrl->redirectByClass('ilmailfoldergui', 'deliverFile');
141 } elseif ('message_sent' === $type) {
142 ilUtil::sendSuccess($this->lng->txt('mail_message_send'), true);
143 $this->ctrl->redirectByClass('ilmailfoldergui');
144 } elseif ('role' === $type) {
145 $roles = $this->httpRequest->getParsedBody()['roles'] ?? [];
146 if (is_array($roles) && count($roles) > 0) {
147 ilSession::set('mail_roles', $roles);
148 } elseif (isset($this->httpRequest->getQueryParams()['role'])) {
149 ilSession::set('mail_roles', [$this->httpRequest->getQueryParams()['role']]);
150 }
151
152 ilMailFormCall::storeReferer($this->httpRequest->getQueryParams());
153 $this->ctrl->redirectByClass('ilmailformgui', 'mailRole');
154 }
155
156 if ('my_courses' === $this->httpRequest->getQueryParams()['view']) {
157 ilSession::set('search_crs', ilUtil::stripSlashes($this->httpRequest->getQueryParams()['search_crs']));
158 $this->ctrl->redirectByClass('ilmailformgui', 'searchCoursesTo');
159 }
160
161 if (isset($this->httpRequest->getQueryParams()['viewmode'])) {
162 $this->ctrl->setCmd('setViewMode');
163 }
164
165 $this->forwardClass = (string) $this->ctrl->getNextClass($this);
166 $this->showHeader();
167
168 switch (strtolower($this->forwardClass)) {
169 case 'ilmailformgui':
170 $this->ctrl->forwardCommand(new ilMailFormGUI());
171 break;
172
173 case 'ilcontactgui':
174 $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
175 $this->ctrl->forwardCommand(new ilContactGUI());
176 break;
177
178 case 'ilmailoptionsgui':
179 $this->tpl->setTitle($this->lng->txt('mail'));
180 $this->ctrl->forwardCommand(new ilMailOptionsGUI());
181 break;
182
183 case 'ilmailfoldergui':
184 $this->ctrl->forwardCommand(new ilMailFolderGUI());
185 break;
186
187 default:
188 if (!($cmd = $this->ctrl->getCmd()) || !method_exists($this, $cmd)) {
189 $cmd = 'setViewMode';
190 }
191
192 $this->{$cmd}();
193 break;
194 }
195 }
196
200 private function setViewMode() : void
201 {
202 $targetClass = $this->httpRequest->getQueryParams()['target'] ?? 'ilmailfoldergui';
203 $type = $this->httpRequest->getQueryParams()['type'] ?? '';
204 $mailId = (int) ($this->httpRequest->getQueryParams()['mail_id'] ?? 0);
205
206 $this->ctrl->setParameterByClass($targetClass, 'mobj_id', $this->currentFolderId);
207
208 if ('redirect_to_read' === $type) {
209 $this->ctrl->setParameterByClass(
210 'ilMailFolderGUI',
211 'mail_id',
212 $mailId
213 );
214 $this->ctrl->setParameterByClass('ilmailfoldergui', 'mobj_id', $this->currentFolderId);
215 $this->ctrl->redirectByClass('ilMailFolderGUI', 'showMail');
216 } elseif ('add_subfolder' === $type) {
217 $this->ctrl->redirectByClass($targetClass, 'addSubFolder');
218 } elseif ('enter_folderdata' === $type) {
219 $this->ctrl->redirectByClass($targetClass, 'enterFolderData');
220 } elseif ('confirmdelete_folderdata' === $type) {
221 $this->ctrl->redirectByClass($targetClass, 'confirmDeleteFolder');
222 } else {
223 $this->ctrl->redirectByClass($targetClass);
224 }
225 }
226
230 private function showHeader() : void
231 {
232 global $DIC;
233
234 $DIC['ilHelp']->setScreenIdComponent("mail");
235 $DIC['ilMainMenu']->setActive("mail");
236
237 $this->tpl->loadStandardTemplate();
238 $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_mail.svg"));
239
241
242 $this->ctrl->setParameterByClass('ilmailfoldergui', 'mobj_id', $this->currentFolderId);
243 $DIC->tabs()->addTarget('fold', $this->ctrl->getLinkTargetByClass('ilmailfoldergui'));
244 $this->ctrl->clearParametersByClass('ilmailformgui');
245
246 $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'new');
247 $this->ctrl->setParameterByClass('ilmailformgui', 'mobj_id', $this->currentFolderId);
248 $DIC->tabs()->addTarget('compose', $this->ctrl->getLinkTargetByClass('ilmailformgui'));
249 $this->ctrl->clearParametersByClass('ilmailformgui');
250
251 $this->ctrl->setParameterByClass('ilcontactgui', 'mobj_id', $this->currentFolderId);
252 $DIC->tabs()->addTarget('mail_addressbook', $this->ctrl->getLinkTargetByClass('ilcontactgui'));
253 $this->ctrl->clearParametersByClass('ilcontactgui');
254
255 if ($DIC->settings()->get('show_mail_settings')) {
256 $this->ctrl->setParameterByClass('ilmailoptionsgui', 'mobj_id', $this->currentFolderId);
257 $DIC->tabs()->addTarget('options', $this->ctrl->getLinkTargetByClass('ilmailoptionsgui'));
258 $this->ctrl->clearParametersByClass('ilmailoptionsgui');
259 }
260
261 switch ($this->forwardClass) {
262 case 'ilmailformgui':
263 $DIC->tabs()->setTabActive('compose');
264 break;
265
266 case 'ilcontactgui':
267 $DIC->tabs()->setTabActive('mail_addressbook');
268 break;
269
270 case 'ilmailoptionsgui':
271 $DIC->tabs()->setTabActive('options');
272 break;
273
274 case 'ilmailfoldergui':
275 default:
276 $DIC->tabs()->setTabActive('fold');
277 break;
278 }
279
280 if (isset($this->httpRequest->getQueryParams()['message_sent'])) {
281 $DIC->tabs()->setTabActive('fold');
282 }
283 }
284
288 protected function toggleExplorerNodeState() : void
289 {
290 $exp = new ilMailExplorer($this, $this->user->getId());
291 $exp->toggleExplorerNodeState();
292 }
293}
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($request_params)
static setRecipients(array $recipients)
__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)
$type
$DIC
Definition: xapitoken.php:46