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