ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMailGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 class ilMailGUI
13 {
15  const VIEWMODE_SESSION_KEY = 'mail_viewmode';
16 
18  private $tpl;
19 
21  private $ctrl;
22 
24  private $lng;
25 
27  private $forwardClass = '';
28 
30  private $httpRequest;
31 
33  private $currentFolderId = 0;
34 
36  private $user;
37 
39  public $umail;
40 
42  public $mbox;
43 
47  public function __construct()
48  {
49  global $DIC;
50 
51  $this->tpl = $DIC->ui()->mainTemplate();
52  $this->ctrl = $DIC->ctrl();
53  $this->lng = $DIC->language();
54  $this->user = $DIC->user();
55  $this->httpRequest = $DIC->http()->request();
56 
57  $this->lng->loadLanguageModule('mail');
58 
59  $this->mbox = new ilMailbox($this->user->getId());
60  $this->umail = new \ilMail($this->user->getId());
61  if (!$DIC->rbac()->system()->checkAccess('internal_mail', $this->umail->getMailObjectReferenceId())) {
62  $DIC['ilErr']->raiseError($this->lng->txt("permission_denied"), $DIC['ilErr']->WARNING);
63  }
64 
65  $this->initFolder();
66  }
67 
71  protected function initFolder()
72  {
73  $folderId = $this->httpRequest->getParsedBody()['mobj_id'] ?? 0;
74  if (!is_numeric($folderId) || 0 == $folderId) {
75  $folderId = $this->httpRequest->getQueryParams()['mobj_id'] ?? 0;
76  }
77  if (!is_numeric($folderId) || 0 == $folderId || !$this->mbox->isOwnedFolder($folderId)) {
78  $folderId = $this->mbox->getInboxFolder();
79  }
80  $this->currentFolderId = (int) $folderId;
81  }
82 
86  public function executeCommand()
87  {
88  $type = $this->httpRequest->getQueryParams()['type'] ?? '';
89  $mailId = (int) ($this->httpRequest->getQueryParams()['mail_id'] ?? 0);
90 
91  $this->ctrl->setParameterByClass('ilmailformgui', 'mobj_id', $this->currentFolderId);
92  $this->ctrl->setParameterByClass('ilmailfoldergui', 'mobj_id', $this->currentFolderId);
93 
94  if ('search_res' === $type) {
95  \ilMailFormCall::storeReferer($this->httpRequest->getQueryParams());
96  $this->ctrl->redirectByClass('ilmailformgui', 'searchResults');
97  } elseif ('attach' === $type) {
98  ilMailFormCall::storeReferer($this->httpRequest->getQueryParams());
99  $this->ctrl->redirectByClass('ilmailformgui', 'mailAttachment');
100  } elseif ('new' === $type) {
101  $to = $this->httpRequest->getQueryParams()['rcp_to'] ?? '';
102  \ilSession::set('rcp_to', \ilUtil::stripSlashes($to));
103  if (!strlen(\ilSession::get('rcp_to')) && ($recipients = \ilMailFormCall::getRecipients())) {
104  \ilSession::set('rcp_to', implode(',', $recipients));
106  }
107 
108  $cc = $this->httpRequest->getQueryParams()['rcp_cc'] ?? '';
109  $bcc = $this->httpRequest->getQueryParams()['rcp_bcc'] ?? '';
110  \ilSession::set('rcp_cc', \ilUtil::stripSlashes($cc));
111  \ilSession::set('rcp_bcc', \ilUtil::stripSlashes($bcc));
112 
113  ilMailFormCall::storeReferer($this->httpRequest->getQueryParams());
114  $this->ctrl->redirectByClass('ilmailformgui', 'mailUser');
115  } elseif ('reply' === $type) {
116  \ilSession::set('mail_id', $mailId);
117  $this->ctrl->redirectByClass('ilmailformgui', 'replyMail');
118  } elseif ('read' === $type) {
119  \ilSession::set('mail_id', $mailId);
120  $this->ctrl->redirectByClass('ilmailfoldergui', 'showMail');
121  } elseif ('deliverFile' === $type) {
122  \ilSession::set('mail_id', $mailId);
123 
124  $fileName = '';
125  if (isset($this->httpRequest->getParsedBody()['filename'])) {
126  $fileName = $this->httpRequest->getParsedBody()['filename'];
127  } elseif (isset($this->httpRequest->getQueryParams()['filename'])) {
128  $fileName = $this->httpRequest->getQueryParams()['filename'];
129  }
130  \ilSession::set('filename', \ilUtil::stripSlashes($fileName));
131  ;
132  $this->ctrl->redirectByClass('ilmailfoldergui', 'deliverFile');
133  } elseif ('message_sent' === $type) {
134  \ilUtil::sendSuccess($this->lng->txt('mail_message_send'), true);
135  $this->ctrl->redirectByClass('ilmailfoldergui');
136  } elseif ('role' === $type) {
137  $roles = $this->httpRequest->getParsedBody()['roles'] ?? [];
138  if (is_array($roles) && count($roles) > 0) {
139  \ilSession::set('mail_roles', $roles);
140  } elseif (isset($this->httpRequest->getQueryParams()['role'])) {
141  \ilSession::set('mail_roles', [$this->httpRequest->getQueryParams()['role']]);
142  }
143 
144  \ilMailFormCall::storeReferer($this->httpRequest->getQueryParams());
145  $this->ctrl->redirectByClass('ilmailformgui', 'mailRole');
146  }
147 
148  if ('my_courses' === $this->httpRequest->getQueryParams()['view']) {
149  \ilSession::set('search_crs', \ilUtil::stripSlashes($this->httpRequest->getQueryParams()['search_crs']));
150  $this->ctrl->redirectByClass('ilmailformgui', 'searchCoursesTo');
151  }
152 
153  if (isset($this->httpRequest->getQueryParams()['viewmode'])) {
154  \ilSession::set(self::VIEWMODE_SESSION_KEY, $this->httpRequest->getQueryParams()['viewmode']);
155  $this->ctrl->setCmd('setViewMode');
156  }
157 
158  $this->forwardClass = $this->ctrl->getNextClass($this);
159  $this->showHeader();
160 
161  if ('tree' === ilSession::get(self::VIEWMODE_SESSION_KEY) && $this->ctrl->getCmd() !== 'showExplorer') {
162  $this->showExplorer();
163  }
164 
165  switch ($this->forwardClass) {
166  case 'ilmailformgui':
167  $this->ctrl->forwardCommand(new \ilMailFormGUI());
168  break;
169 
170  case 'ilcontactgui':
171  $this->tpl->setTitle($this->lng->txt('mail_addressbook'));
172  $this->ctrl->forwardCommand(new \ilContactGUI());
173  break;
174 
175  case 'ilmailoptionsgui':
176  $this->tpl->setTitle($this->lng->txt('mail'));
177  $this->ctrl->forwardCommand(new \ilMailOptionsGUI());
178  break;
179 
180  case 'ilmailfoldergui':
181  $this->ctrl->forwardCommand(new \ilMailFolderGUI());
182  break;
183 
184  default:
185  if (!($cmd = $this->ctrl->getCmd()) || !method_exists($this, $cmd)) {
186  $cmd = 'setViewMode';
187  }
188 
189  $this->{$cmd}();
190  break;
191  }
192  }
193 
197  private function setViewMode()
198  {
199  $targetClass = $this->httpRequest->getQueryParams()['target'] ?? 'ilmailfoldergui';
200  $type = $this->httpRequest->getQueryParams()['type'] ?? '';
201  $mailId = (int) ($this->httpRequest->getQueryParams()['mail_id'] ?? 0);
202 
203  $this->ctrl->setParameterByClass($targetClass, 'mobj_id', $this->currentFolderId);
204 
205  if ('redirect_to_read' === $type) {
206  $this->ctrl->setParameterByClass(
207  'ilMailFolderGUI',
208  'mail_id',
209  $mailId
210  );
211  $this->ctrl->setParameterByClass('ilmailfoldergui', 'mobj_id', $this->currentFolderId);
212  $this->ctrl->redirectByClass('ilMailFolderGUI', 'showMail');
213  } elseif ('add_subfolder' === $type) {
214  $this->ctrl->redirectByClass($targetClass, 'addSubFolder');
215  } elseif ('enter_folderdata' === $type) {
216  $this->ctrl->redirectByClass($targetClass, 'enterFolderData');
217  } elseif ('confirmdelete_folderdata' === $type) {
218  $this->ctrl->redirectByClass($targetClass, 'confirmDeleteFolder');
219  } else {
220  $this->ctrl->redirectByClass($targetClass);
221  }
222  }
223 
227  private function showHeader()
228  {
229  global $DIC;
230 
231  $DIC['ilHelp']->setScreenIdComponent("mail");
232  $DIC['ilMainMenu']->setActive("mail");
233 
234  $this->tpl->getStandardTemplate();
235  $this->tpl->setTitleIcon(\ilUtil::getImagePath("icon_mail.svg"));
236 
238 
239  $this->ctrl->setParameterByClass('ilmailfoldergui', 'mobj_id', $this->currentFolderId);
240  $DIC->tabs()->addTarget('fold', $this->ctrl->getLinkTargetByClass('ilmailfoldergui'));
241  $this->ctrl->clearParametersByClass('ilmailformgui');
242 
243  $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'new');
244  $this->ctrl->setParameterByClass('ilmailformgui', 'mobj_id', $this->currentFolderId);
245  $DIC->tabs()->addTarget('compose', $this->ctrl->getLinkTargetByClass('ilmailformgui'));
246  $this->ctrl->clearParametersByClass('ilmailformgui');
247 
248  $this->ctrl->setParameterByClass('ilcontactgui', 'mobj_id', $this->currentFolderId);
249  $DIC->tabs()->addTarget('mail_addressbook', $this->ctrl->getLinkTargetByClass('ilcontactgui'));
250  $this->ctrl->clearParametersByClass('ilcontactgui');
251 
252  if ($DIC->settings()->get('show_mail_settings')) {
253  $this->ctrl->setParameterByClass('ilmailoptionsgui', 'mobj_id', $this->currentFolderId);
254  $DIC->tabs()->addTarget('options', $this->ctrl->getLinkTargetByClass('ilmailoptionsgui'));
255  $this->ctrl->clearParametersByClass('ilmailoptionsgui');
256  }
257 
258  switch ($this->forwardClass) {
259  case 'ilmailformgui':
260  $DIC->tabs()->setTabActive('compose');
261  break;
262 
263  case 'ilcontactgui':
264  $DIC->tabs()->setTabActive('mail_addressbook');
265  break;
266 
267  case 'ilmailoptionsgui':
268  $DIC->tabs()->setTabActive('options');
269  break;
270 
271  case 'ilmailfoldergui':
272  default:
273  $DIC->tabs()->setTabActive('fold');
274  break;
275  }
276 
277  if (isset($this->httpRequest->getQueryParams()['message_sent'])) {
278  $DIC->tabs()->setTabActive('fold');
279  }
280 
281  $folderTreeState = 'flat';
282  if ('tree' !== ilSession::get(self::VIEWMODE_SESSION_KEY)) {
283  $folderTreeState = 'tree';
284  }
285 
286  if ($this->isMailDetailCommand($this->ctrl->getCmd())) {
287  $this->ctrl->setParameter($this, 'mail_id', (int) $this->httpRequest->getQueryParams()['mail_id']);
288  $this->ctrl->setParameter($this, 'type', 'redirect_to_read');
289  }
290  $this->ctrl->setParameter($this, 'mobj_id', $this->currentFolderId);
291  $this->ctrl->setParameter($this, 'viewmode', $folderTreeState);
292  $this->tpl->setTreeFlatIcon($this->ctrl->getLinkTarget($this), $folderTreeState);
293  $this->ctrl->clearParameters($this);
294 
295  $this->tpl->setCurrentBlock('tree_icons');
296  $this->tpl->parseCurrentBlock();
297  }
298 
303  private function isMailDetailCommand(string $cmd) : bool
304  {
305  $mailId = $this->httpRequest->getQueryParams()['mail_id'] ?? 0;
306  if (!is_numeric($mailId) || 0 == $mailId) {
307  return false;
308  }
309 
310  return in_array(strtolower($cmd), ['showmail']);
311  }
312 
316  private function showExplorer()
317  {
318  $exp = new \ilMailExplorer($this, 'showExplorer', $this->user->getId());
319  if (!$exp->handleCommand()) {
320  $this->tpl->setLeftNavContent($exp->getHTML());
321  }
322  }
323 }
$type
global $DIC
Definition: saml.php:7
static get($a_var)
Get a value.
static set($a_var, $a_val)
Set a value.
user()
Definition: user.php:4
const VIEWMODE_SESSION_KEY
static storeReferer($request_params)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
Mail Box class Base class for creating and handling mail boxes.
static infoPanel($a_keep=true)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
__construct()
ilMailGUI constructor.
static setRecipients(array $recipients)
isMailDetailCommand(string $cmd)