ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMailFolderGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once 'Services/User/classes/class.ilObjUser.php';
6 require_once 'Services/Mail/classes/class.ilMailbox.php';
7 require_once 'Services/Mail/classes/class.ilMail.php';
8 require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
9 include_once 'Services/Mail/classes/class.ilMailFolderTableGUI.php';
10 
20 {
23 
27  private $tpl;
28 
32  private $ctrl;
33 
37  private $lng;
38 
42  private $toolbar;
43 
47  private $tabs;
48 
52  private $user;
53 
57  public $umail;
58 
62  public $mbox;
63 
67  private $errorDelete = false;
68 
72  public function __construct()
73  {
74  global $DIC;
75 
76  $this->tpl = $DIC->ui()->mainTemplate();
77  $this->ctrl = $DIC->ctrl();
78  $this->lng = $DIC->language();
79  $this->toolbar = $DIC->toolbar();
80  $this->user = $DIC->user();
81  $this->tabs = $DIC->tabs();
82 
83  $this->umail = new ilMail($this->user->getId());
84  $this->mbox = new ilMailBox($this->user->getId());
85 
86  if (isset($_POST['mobj_id']) && (int) $_POST['mobj_id']) {
87  $_GET['mobj_id'] = $_POST['mobj_id'];
88  }
89 
90  if (!(int) $_GET['mobj_id']) {
91  $_GET['mobj_id'] = $this->mbox->getInboxFolder();
92  }
93  $_GET['mobj_id'] = (int) $_GET['mobj_id'];
94 
95  $this->ctrl->saveParameter($this, 'mobj_id');
96  $this->ctrl->setParameter($this, 'mobj_id', $_GET['mobj_id']);
97  }
98 
99  public function executeCommand()
100  {
101  if ($_POST["select_cmd"]) {
102  $_GET["cmd"] = 'editFolder';
103 
104  // lower menubar execute-button
105  $this->current_select_cmd = $_POST['select_cmd'];
106  $this->current_selected_cmd = $_POST['selected_cmd'];
107  } elseif ($_POST["select_cmd2"]) {
108  // upper menubar execute-button
109  $_GET["cmd"] = 'editFolder';
110  $this->current_select_cmd = $_POST['select_cmd2'];
111  $this->current_selected_cmd = $_POST['selected_cmd2'];
112  }
113 
114  /* Fix: User views mail and wants to delete it...
115  mjansen: The mail system needs a revision :-)
116  */
117  if ($_GET['selected_cmd'] == "deleteMails" && $_GET["mail_id"]) {
118  $_GET["cmd"] = "editFolder";
119  $this->current_selected_cmd = "deleteMails";
120  $_POST["mail_id"] = array($_GET["mail_id"]);
121  }
122 
123  /* Fix: User views mail and wants to move it...
124  mjansen: The mail system needs a revision :-)
125  */
126  $cmd = $this->ctrl->getCmd();
127  if ($cmd == 'changeFolder' &&
128  is_numeric($_POST['selected_cmd']) &&
129  $_GET["mail_id"]) {
130  $this->current_selected_cmd = (int) $_POST['selected_cmd'];
131  }
132 
133  $forward_class = $this->ctrl->getNextClass($this);
134  switch ($forward_class) {
135  case 'ilcontactgui':
136  require_once 'Services/Contact/classes/class.ilContactGUI.php';
137  $this->ctrl->forwardCommand(new ilContactGUI());
138  break;
139 
140  case 'ilmailoptionsgui':
141  $this->tpl->setTitle($this->lng->txt('mail'));
142  include_once 'Services/Mail/classes/class.ilMailOptionsGUI.php';
143 
144  $this->ctrl->forwardCommand(new ilMailOptionsGUI());
145  break;
146 
147  case 'ilpublicuserprofilegui':
148  include_once("Services/User/classes/class.ilPublicUserProfileGUI.php");
149  $this->tpl->setTitle($this->lng->txt("mail"));
150  $this->ctrl->saveParameter($this, "mail_id");
151  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
152  $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, "showMail"));
153  $ret = $this->ctrl->forwardCommand($profile_gui);
154  if ($ret != "") {
155  $this->tpl->setContent($ret);
156  }
157  $this->tpl->show();
158  break;
159 
160  default:
161  if (!($cmd = $this->ctrl->getCmd())) {
162  $cmd = "showFolder";
163  }
164  $this->$cmd();
165  break;
166  }
167  return true;
168  }
169 
173  public function cancelEmptyTrash()
174  {
175  $this->showFolder();
176  }
177 
181  public function performEmptyTrash()
182  {
183  $this->umail->deleteMailsOfFolder($_GET['mobj_id']);
184  ilUtil::sendInfo($this->lng->txt('mail_deleted'));
185  $this->showFolder();
186  }
187 
191  public function askForEmptyTrash()
192  {
193  if ($this->umail->countMailsOfFolder((int) $_GET['mobj_id'])) {
194  $this->askForConfirmation = true;
195  }
196 
197  $this->showFolder();
198 
199  return true;
200  }
201 
202  public function showUser()
203  {
204  $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
205 
206  $this->tpl->setTitle($this->lng->txt("mail"));
207 
208  $this->tpl->setVariable("TBL_TITLE", $this->lng->txt("profile_of") . " " .
209  ilObjUser::_lookupLogin($_GET["user"]));
210  $this->tpl->setVariable("TBL_TITLE_IMG", ilUtil::getImagePath("icon_usr.svg"));
211  $this->tpl->setVariable("TBL_TITLE_IMG_ALT", $this->lng->txt("public_profile"));
212 
213  include_once './Services/User/classes/class.ilPublicUserProfileGUI.php';
214  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
215  $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, "showMail"));
216  $this->tpl->setContent($this->ctrl->getHTML($profile_gui));
217  $this->tpl->show();
218 
219  return true;
220  }
221 
222  public function addSubfolderCommands($check_uf = false)
223  {
225  $this->toolbar->addSeparator();
226  }
227 
228  $this->toolbar->addButton($this->lng->txt('mail_add_subfolder'), $this->ctrl->getLinkTarget($this, 'addSubFolder'));
229 
230  if ($check_uf) {
231  $this->toolbar->addButton($this->lng->txt('rename'), $this->ctrl->getLinkTarget($this, 'renameSubFolder'));
232  $this->toolbar->addButton($this->lng->txt('delete'), $this->ctrl->getLinkTarget($this, 'deleteSubFolder'));
233  }
234 
235  return true;
236  }
240  public function showFolder($a_show_confirmation = false)
241  {
242  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail.html', 'Services/Mail');
243  $this->tpl->setTitle($this->lng->txt('mail'));
244 
245  $sentFolderId = $this->mbox->getSentFolder();
246  $draftsFolderId = $this->mbox->getDraftsFolder();
247 
248  $isTrashFolder = $_GET['mobj_id'] == $this->mbox->getTrashFolder();
249  $isSentFolder = $_GET['mobj_id'] == $sentFolderId;
250  $isDraftFolder = $_GET['mobj_id'] == $draftsFolderId;
251 
252  if ($this->current_selected_cmd == 'deleteMails' &&
253  !$this->errorDelete &&
254  $this->current_selected_cmd != 'confirm' &&
255  $isTrashFolder) {
256  if (isset($_REQUEST['mail_id']) && !is_array($_REQUEST['mail_id'])) {
257  $_REQUEST['mail_id'] = array($_REQUEST['mail_id']);
258  }
259  $confirmation = new ilConfirmationGUI();
260  $confirmation->setHeaderText($this->lng->txt('mail_sure_delete'));
261  $this->ctrl->setParameter($this, 'mail_id', implode(',', (array) $_REQUEST['mail_id']));
262  $confirmation->setFormAction($this->ctrl->getFormAction($this, 'confirmDeleteMails'));
263  $confirmation->setConfirm($this->lng->txt('confirm'), 'confirmDeleteMails');
264  $confirmation->setCancel($this->lng->txt('cancel'), 'cancelDeleteMails');
265  $this->tpl->setVariable('CONFIRMATION', $confirmation->getHTML());
266  $a_show_confirmation = true;
267  }
268 
269  $folders = $this->mbox->getSubFolders();
270  $mtree = new ilTree($this->user->getId());
271  $mtree->setTableNames('mail_tree', 'mail_obj_data');
272 
273  $check_uf = false;
274  $check_local = false;
275 
277  $folder_d = $mtree->getNodeData($_GET['mobj_id']);
278  if ($folder_d['m_type'] == 'user_folder') {
279  $check_uf = true;
280  } elseif ($folder_d['m_type'] == 'local') {
281  $check_local = true;
282  }
283  }
284 
285  $mailtable = new ilMailFolderTableGUI($this, (int) $_GET['mobj_id'], 'showFolder');
286  $mailtable->isSentFolder($isSentFolder)
287  ->isDraftFolder($isDraftFolder)
288  ->isTrashFolder($isTrashFolder)
289  ->initFilter();
290  $mailtable->setSelectedItems($_POST['mail_id']);
291 
292  try {
293  $mailtable->prepareHTML();
294  } catch (Exception $e) {
296  $this->lng->txt($e->getMessage()) != '-' . $e->getMessage() . '-' ?
297  $this->lng->txt($e->getMessage()) :
298  $e->getMessage()
299  );
300  }
301 
302  $table_html = $mailtable->getHtml();
303 
304  $folder_options = array();
306  foreach ($folders as $folder) {
307  $folder_d = $mtree->getNodeData($folder['obj_id']);
308 
309  if ($folder['obj_id'] == $_GET['mobj_id']) {
310  if ($folder['type'] == 'user_folder') {
311  $check_uf = true;
312  } elseif ($folder['type'] == 'local') {
313  $check_local = true;
314  $check_uf = false;
315  }
316  }
317 
318  if ($folder['type'] == 'user_folder') {
319  $pre = '';
320  for ($i = 2; $i < $folder_d['depth'] - 1; $i++) {
321  $pre .= '&nbsp;';
322  }
323 
324  if ($folder_d['depth'] > 1) {
325  $pre .= '+';
326  }
327 
328  $folder_options[$folder['obj_id']] = $pre . ' ' . $folder['title'];
329  } else {
330  $folder_options[$folder['obj_id']] = $this->lng->txt('mail_' . $folder['title']);
331  }
332  }
333  }
334 
335  if ($a_show_confirmation == false && $this->askForConfirmation == false) {
337  $this->toolbar->addText($this->lng->txt('mail_change_to_folder'));
338  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
339  $si = new ilSelectInputGUI("", "mobj_id");
340  $si->setOptions($folder_options);
341  $si->setValue($_GET['mobj_id']);
342  $this->toolbar->addInputItem($si);
343 
344  $this->toolbar->addFormButton($this->lng->txt('change'), 'showFolder');
345  $this->toolbar->setFormAction($this->ctrl->getFormAction($this, 'showFolder'));
346  }
347  if ($check_local == true || $check_uf == true) {
348  $this->addSubfolderCommands($check_uf);
349  }
350  }
351  // END SHOW_FOLDER
352 
353  if ($mailtable->isTrashFolder() &&
354  $mailtable->getNumerOfMails() > 0 &&
355  $this->askForConfirmation) {
356  $confirmation = new ilConfirmationGUI();
357  $confirmation->setHeaderText($this->lng->txt('mail_empty_trash_confirmation'));
358  $confirmation->setFormAction($this->ctrl->getFormAction($this, 'performEmptyTrash'));
359  $confirmation->setConfirm($this->lng->txt('confirm'), 'performEmptyTrash');
360  $confirmation->setCancel($this->lng->txt('cancel'), 'cancelEmptyTrash');
361  $this->tpl->setVariable('CONFIRMATION', $confirmation->getHTML());
362  }
363 
364  $this->tpl->setVariable('MAIL_TABLE', $table_html);
365  $this->tpl->show();
366  }
367 
368  public function deleteSubfolder($a_show_confirm = true)
369  {
370  if ($a_show_confirm) {
371  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
372  $oConfirmationGUI = new ilConfirmationGUI();
373 
374  // set confirm/cancel commands
375  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this, "showFolder"));
376  $oConfirmationGUI->setHeaderText($this->lng->txt("mail_sure_delete_folder"));
377  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "showFolder");
378  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDeleteSubfolder");
379  $this->tpl->setVariable('CONFIRMATION', $oConfirmationGUI->getHTML());
380 
381  return $this->showFolder(true);
382  } else {
383  return $this->showFolder(false);
384  }
385  }
386 
387  public function performDeleteSubFolder()
388  {
389  $new_parent = $this->mbox->getParentFolderId((int) $_GET['mobj_id']);
390  if ($this->mbox->deleteFolder((int) $_GET['mobj_id'])) {
391  ilUtil::sendInfo($this->lng->txt('mail_folder_deleted'), true);
392  $this->ctrl->setParameterByClass('ilMailGUI', 'mobj_id', (int) $new_parent);
393  $this->ctrl->redirectByClass('ilMailGUI');
394  } else {
395  ilUtil::sendFailure($this->lng->txt('mail_error_delete'));
396  $this->showFolder();
397  return;
398  }
399  }
400 
401  public function performAddSubFolder()
402  {
403  if (isset($_POST["subfolder_title"]) && 'tree' == ilSession::get(ilMailGUI::VIEWMODE_SESSION_KEY)) {
404  $_SESSION["subfolder_title"] = ilUtil::stripSlashes($_POST['subfolder_title']);
405  }
406 
407  if (empty($_POST['subfolder_title'])) {
408  ilUtil::sendInfo($this->lng->txt("mail_insert_folder_name"));
409  return $this->addSubFolder();
410  } elseif ($mobj_id = $this->mbox->addFolder($_GET["mobj_id"], ilUtil::stripSlashes($_POST["subfolder_title"]))) {
411  unset($_SESSION["subfolder_title"]);
412  ilUtil::sendInfo($this->lng->txt("mail_folder_created"), true);
413 
414  $this->ctrl->setParameterByClass("ilMailGUI", 'mobj_id', $mobj_id);
415  $this->ctrl->redirectByClass("ilMailGUI");
416  } else {
417  ilUtil::sendFailure($this->lng->txt("mail_folder_exists"));
418  $this->addSubFolder();
419  return;
420  }
421  }
422 
423  public function addSubFolder()
424  {
425  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
426 
427  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail.html', 'Services/Mail');
428  $this->tpl->setTitle($this->lng->txt('mail'));
429 
430  $oForm = new ilPropertyFormGUI();
431  $oForm->setFormAction($this->ctrl->getFormAction($this, 'performAddSubFolder'));
432  $oForm->setTitle($this->lng->txt('mail_add_folder'));
433 
434  //title
435  $oTitle = new ilTextInputGUI();
436  $oTitle->setTitle($this->lng->txt('title'));
437  $oTitle->setPostVar('subfolder_title');
438  $oForm->addItem($oTitle);
439 
440  $oForm->addCommandButton('performAddSubFolder', $this->lng->txt('save'));
441  $oForm->addCommandButton('showFolder', $this->lng->txt('cancel'));
442 
443  $this->tpl->setVariable('FORM', $oForm->getHTML());
444  $this->tpl->show();
445 
446  return true;
447  }
448 
449  public function renameSubFolder()
450  {
451  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
452 
453  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail.html', 'Services/Mail');
454  $this->tpl->setTitle($this->lng->txt('mail'));
455 
456  $oForm = new ilPropertyFormGUI();
457  $oForm->setFormAction($this->ctrl->getFormAction($this, 'performRenameSubFolder'));
458  $oForm->setTitle($this->lng->txt('mail_rename_folder'));
459 
460  //title
461  $oTitle = new ilTextInputGUI();
462  $oTitle->setTitle($this->lng->txt('title'));
463  $tmp_data = $this->mbox->getFolderData($_GET["mobj_id"]);
464  $oTitle->setValue($tmp_data["title"]);
465  $oTitle->setPostVar('subfolder_title');
466  $oForm->addItem($oTitle);
467 
468  $oForm->addCommandButton('performRenameSubFolder', $this->lng->txt('save'));
469  $oForm->addCommandButton('showFolder', $this->lng->txt('cancel'));
470  $this->tpl->setVariable('FORM', $oForm->getHTML());
471  $this->tpl->show();
472 
473  return true;
474  }
475 
476  public function performRenameSubFolder()
477  {
478  if (isset($_POST["subfolder_title"]) && 'tree' == ilSession::get(ilMailGUI::VIEWMODE_SESSION_KEY)) {
479  $_SESSION["subfolder_title"] = $_POST['subfolder_title'];
480  }
481 
482  $tmp_data = $this->mbox->getFolderData($_GET["mobj_id"]);
483  if ($tmp_data["title"] != $_POST["subfolder_title"]) {
484  if ($_POST["subfolder_title"] == "") {
485  ilUtil::sendInfo($this->lng->txt("mail_insert_folder_name"));
486  return $this->renameSubFolder();
487  } else {
488  if ($this->mbox->renameFolder($_GET["mobj_id"], ilUtil::stripSlashes($_POST["subfolder_title"]))) {
489  ilUtil::sendInfo($this->lng->txt("mail_folder_name_changed"), true);
490  unset($_SESSION["subfolder_title"]);
491  $this->ctrl->redirectByClass("ilMailGUI");
492  } else {
493  ilUtil::sendFailure($this->lng->txt("mail_folder_exists"));
494  return $this->renameSubFolder();
495  }
496  }
497  }
498  return $this->showFolder();
499  }
500 
501  public function changeFolder()
502  {
503  switch ($this->current_selected_cmd) {
504  default:
505  if (!(int) $_GET["mail_id"] || !(int) $this->current_selected_cmd) {
506  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
507  return $this->showMail();
508  }
509 
510  if ($this->umail->moveMailsToFolder(array($_GET["mail_id"]), $this->current_selected_cmd)) {
511  ilUtil::sendInfo($this->lng->txt("mail_moved"), true);
512  $this->ctrl->redirectByClass("ilMailGUI");
513  } else {
514  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
515  }
516  break;
517  }
518 
519  $this->showMail();
520 
521  return true;
522  }
523 
524  public function editFolder()
525  {
526  switch ($this->current_selected_cmd) {
527  case 'markMailsRead':
528  if (is_array($_POST["mail_id"])) {
529  $this->umail->markRead($_POST["mail_id"]);
530  } else {
531  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
532  }
533  break;
534  case 'markMailsUnread':
535  if (is_array($_POST["mail_id"])) {
536  $this->umail->markUnread($_POST["mail_id"]);
537  } else {
538  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
539  }
540  break;
541 
542  case 'deleteMails':
543  // IF MAILBOX IS TRASH ASK TO CONFIRM
544  if ($this->mbox->getTrashFolder() == $_GET["mobj_id"]) {
545  if (!is_array($_POST["mail_id"])) {
546  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
547  $this->errorDelete = true;
548  }
549  } // END IF MAILBOX IS TRASH FOLDER
550  else {
551  // MOVE MAILS TO TRASH
552  if (!is_array($_POST["mail_id"])) {
553  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
554  } elseif ($this->umail->moveMailsToFolder($_POST["mail_id"], $this->mbox->getTrashFolder())) {
555  $_GET["offset"] = 0;
556  ilUtil::sendInfo($this->lng->txt("mail_moved_to_trash"));
557  } else {
558  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
559  }
560  }
561  break;
562 
563  case 'add':
564  $this->ctrl->setParameterByClass("ilmailoptionsgui", "cmd", "add");
565  $this->ctrl->redirectByClass("ilmailoptionsgui");
566 
567  // no break
568  case 'moveMails':
569  default:
570  if (!is_array($_POST["mail_id"])) {
571  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
572  } elseif ($this->umail->moveMailsToFolder($_POST["mail_id"], $this->current_selected_cmd)) {
573  ilUtil::sendInfo($this->lng->txt("mail_moved"));
574  } else {
575  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
576  }
577  break;
578  }
579 
580  $this->showFolder();
581  }
582 
586  public function confirmDeleteMails()
587  {
588  if ($this->mbox->getTrashFolder() == $_GET['mobj_id']) {
589  $_POST['mail_id'] = $mail_ids = explode(',', $_GET['mail_id']);
590  if (!is_array($mail_ids)) {
591  ilUtil::sendInfo($this->lng->txt('mail_select_one'));
592  } elseif ($this->umail->deleteMails($mail_ids)) {
593  $_GET['offset'] = 0;
594  ilUtil::sendInfo($this->lng->txt('mail_deleted'));
595  } else {
596  ilUtil::sendInfo($this->lng->txt('mail_delete_error'));
597  }
598  }
599 
600  $this->showFolder();
601  }
602 
603  public function cancelDeleteMails()
604  {
605  $this->ctrl->redirect($this);
606  }
607 
611  public function showMail()
612  {
613  if ($_SESSION['mail_id']) {
614  $_GET['mail_id'] = $_SESSION['mail_id'];
615  $_SESSION['mail_id'] = '';
616  }
617 
618  $this->tabs->clearTargets();
619  $this->tabs->setBackTarget($this->lng->txt('back_to_folder'), $this->ctrl->getFormAction($this, 'showFolder'));
620 
621  $this->umail->markRead(array((int) $_GET['mail_id']));
622  $mailData = $this->umail->getMail((int) $_GET['mail_id']);
623 
624  $this->tpl->setTitle($this->lng->txt('mail_mails_of'));
625 
626  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
627 
628  $form = new ilPropertyFormGUI();
629  $form->setPreventDoubleSubmission(false);
630  $form->setTableWidth('100%');
631  $this->ctrl->setParameter($this, 'mail_id', (int) $_GET['mail_id']);
632  $form->setFormAction($this->ctrl->getFormAction($this, 'showMail'));
633  $this->ctrl->clearParameters($this);
634  $form->setTitle($this->lng->txt('mail_mails_of'));
635 
637  $this->tpl->setVariable('FORM_TARGET', ilFrameTargetInfo::_getFrame('MainContent'));
638  }
639 
640  include_once 'Services/Accessibility/classes/class.ilAccessKeyGUI.php';
641 
645  $sender = ilObjectFactory::getInstanceByObjId($mailData['sender_id'], false);
646 
647  if ($sender && $sender->getId() && $sender->getId() != ANONYMOUS_USER_ID) {
648  $this->ctrl->setParameterByClass('ilmailformgui', 'mail_id', (int) $_GET['mail_id']);
649  $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'reply');
650  $this->ctrl->clearParametersByClass('iliasmailformgui');
651  $this->toolbar->addButton($this->lng->txt('reply'), $this->ctrl->getLinkTargetByClass('ilmailformgui'), '', ilAccessKey::REPLY);
652  $this->ctrl->clearParameters($this);
653  }
654 
655  $this->ctrl->setParameterByClass('ilmailformgui', 'mail_id', (int) $_GET['mail_id']);
656  $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'forward');
657  $this->ctrl->clearParametersByClass('iliasmailformgui');
658  $this->toolbar->addButton($this->lng->txt('forward'), $this->ctrl->getLinkTargetByClass('ilmailformgui'), '', ilAccessKey::FORWARD_MAIL);
659  $this->ctrl->clearParameters($this);
660 
661  $this->ctrl->setParameter($this, 'mail_id', (int) $_GET['mail_id']);
662  $this->toolbar->addButton($this->lng->txt('print'), $this->ctrl->getLinkTarget($this, 'printMail'), '_blank');
663  $this->ctrl->clearParameters($this);
664 
665  $this->ctrl->setParameter($this, 'mail_id', (int) $_GET['mail_id']);
666  $this->ctrl->setParameter($this, 'selected_cmd', 'deleteMails');
667  $this->toolbar->addButton($this->lng->txt('delete'), $this->ctrl->getLinkTarget($this), '', ilAccessKey::DELETE);
668  $this->ctrl->clearParameters($this);
669 
670  if ($sender && $sender->getId() && $sender->getId() != ANONYMOUS_USER_ID) {
671  $linked_fullname = $sender->getPublicName();
672  $picture = ilUtil::img(
673  $sender->getPersonalPicturePath('xsmall'),
674  $sender->getPublicName(),
675  '',
676  '',
677  0,
678  '',
679  'ilMailAvatar'
680  );
681  $add_to_addb_button = '';
682 
683  if (in_array(ilObjUser::_lookupPref($sender->getId(), 'public_profile'), array('y', 'g'))) {
684  $this->ctrl->setParameter($this, 'mail_id', (int) $_GET['mail_id']);
685  $this->ctrl->setParameter($this, 'user', $sender->getId());
686  $linked_fullname = '<br /><a href="' . $this->ctrl->getLinkTarget($this, 'showUser') . '" title="' . $linked_fullname . '">' . $linked_fullname . '</a>';
687  $this->ctrl->clearParameters($this);
688  }
689 
690  $from = new ilCustomInputGUI($this->lng->txt('from'));
691  $from->setHtml($picture . ' ' . $linked_fullname . $add_to_addb_button);
692  $form->addItem($from);
693  } elseif (!$sender || !$sender->getId()) {
694  $from = new ilCustomInputGUI($this->lng->txt('from'));
695  $from->setHtml($mailData['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')');
696  $form->addItem($from);
697  } else {
698  $from = new ilCustomInputGUI($this->lng->txt('from') . ':');
699  $from->setHtml(
700  ilUtil::img(ilUtil::getImagePath('HeaderIconAvatar.svg'), ilMail::_getIliasMailerName(), '', '', 0, '', 'ilMailAvatar') .
701  '<br />' . ilMail::_getIliasMailerName()
702  );
703  $form->addItem($from);
704  }
705 
706  $to = new ilCustomInputGUI($this->lng->txt('mail_to'));
707  $to->setHtml(ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_to']), false));
708  $form->addItem($to);
709 
710  if ($mailData['rcp_cc']) {
711  $cc = new ilCustomInputGUI($this->lng->txt('cc'));
712  $cc->setHtml(ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_cc']), false));
713  $form->addItem($cc);
714  }
715 
716  if ($mailData['rcp_bcc']) {
717  $bcc = new ilCustomInputGUI($this->lng->txt('bc'));
718  $bcc->setHtml(ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_bcc']), false));
719  $form->addItem($bcc);
720  }
721 
722  $subject = new ilCustomInputGUI($this->lng->txt('subject'));
723  $subject->setHtml(ilUtil::htmlencodePlainString($mailData['m_subject'], true));
724  $form->addItem($subject);
725 
726  $date = new ilCustomInputGUI($this->lng->txt('date'));
727  $date->setHtml(ilDatePresentation::formatDate(new ilDateTime($mailData['send_time'], IL_CAL_DATETIME)));
728  $form->addItem($date);
729 
730  $message = new ilCustomInputGUI($this->lng->txt('message'));
731  $message->setHtml(ilUtil::htmlencodePlainString($mailData['m_message'], true));
732  $form->addItem($message);
733 
734  if ($mailData['attachments']) {
735  $att = new ilCustomInputGUI($this->lng->txt('attachments'));
736 
737  $radiog = new ilRadioGroupInputGUI('', 'filename');
738 
739  foreach ($mailData['attachments'] as $file) {
740  $radiog->addOption(new ilRadioOption($file, md5($file)));
741  }
742 
743  $att->setHtml($radiog->render());
744  $form->addCommandButton('deliverFile', $this->lng->txt('download'));
745  $form->addItem($att);
746  }
747 
748  $isTrashFolder = false;
749  if ($this->mbox->getTrashFolder() == $_GET['mobj_id']) {
750  $isTrashFolder = true;
751  }
752 
753  $current_folder_data = $this->mbox->getFolderData((int) $_GET['mobj_id']);
754 
755  $selectOptions = array();
756  $actions = $this->mbox->getActions((int) $_GET["mobj_id"]);
757  foreach ($actions as $key => $action) {
758  if ($key == 'moveMails') {
759  $folders = $this->mbox->getSubFolders();
760  foreach ($folders as $folder) {
761  if (
762  ($folder["type"] != 'trash' || !$isTrashFolder) &&
763  $folder['obj_id'] != $current_folder_data['obj_id']
764  ) {
765  $optionText = '';
766  if ($folder['type'] != 'user_folder') {
767  $optionText = $action . ' ' . $this->lng->txt('mail_' . $folder['title']) . ($folder['type'] == 'trash' ? ' (' . $this->lng->txt('delete') . ')' : '');
768  } else {
769  $optionText = $action . ' ' . $folder['title'];
770  }
771 
772  $selectOptions[$folder['obj_id']] = $optionText;
773  }
774  }
775  }
776  }
777 
778  if ($current_folder_data['type'] == 'user_folder') {
779  $txt_folder = $current_folder_data['title'];
780  } else {
781  $txt_folder = $this->lng->txt('mail_' . $current_folder_data['title']);
782  }
783  $this->toolbar->addSeparator();
784  $this->toolbar->addText(sprintf($this->lng->txt('current_folder'), $txt_folder));
785 
786  if (is_array($selectOptions) && count($selectOptions)) {
787  include_once 'Services/Form/classes/class.ilSelectInputGUI.php';
788  $actions = new ilSelectInputGUI('', 'selected_cmd');
789  $actions->setOptions($selectOptions);
790  $this->ctrl->setParameter($this, 'mail_id', (int) $_GET['mail_id']);
791  $this->toolbar->setFormAction($this->ctrl->getFormAction($this, 'showMail'));
792  $this->toolbar->addInputItem($actions);
793  $this->toolbar->addFormButton($this->lng->txt('submit'), 'changeFolder');
794  }
795 
796  // Navigation
797  $prevMail = $this->umail->getPreviousMail((int) $_GET['mail_id']);
798  $nextMail = $this->umail->getNextMail((int) $_GET['mail_id']);
799  if (is_array($prevMail) || is_array($nextMail)) {
800  $this->toolbar->addSeparator();
801 
802  if ($prevMail['mail_id']) {
803  $this->ctrl->setParameter($this, 'mail_id', $prevMail['mail_id']);
804  $this->toolbar->addButton($this->lng->txt('previous'), $this->ctrl->getLinkTarget($this, 'showMail'));
805  $this->ctrl->clearParameters($this);
806  }
807 
808  if ($nextMail['mail_id']) {
809  $this->ctrl->setParameter($this, 'mail_id', $nextMail['mail_id']);
810  $this->toolbar->addButton($this->lng->txt('next'), $this->ctrl->getLinkTarget($this, 'showMail'));
811  $this->ctrl->clearParameters($this);
812  }
813  }
814 
815  $this->tpl->setContent($form->getHTML());
816  $this->tpl->show();
817  }
818 
822  public function printMail()
823  {
824  $tplprint = new ilTemplate('tpl.mail_print.html', true, true, 'Services/Mail');
825  $tplprint->setVariable('JSPATH', $this->tpl->tplPath);
826 
827  $mailData = $this->umail->getMail((int) $_GET['mail_id']);
828 
832  $sender = ilObjectFactory::getInstanceByObjId($mailData['sender_id'], false);
833 
834  $tplprint->setVariable('TXT_FROM', $this->lng->txt('from'));
835  if ($sender && $sender->getId() && $sender->getId() != ANONYMOUS_USER_ID) {
836  $tplprint->setVariable('FROM', $sender->getPublicName());
837  } elseif (!$sender || !$sender->getId()) {
838  $tplprint->setVariable('FROM', $mailData['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')');
839  } else {
840  $tplprint->setVariable('FROM', ilMail::_getIliasMailerName());
841  }
842 
843  $tplprint->setVariable('TXT_TO', $this->lng->txt('mail_to'));
844  $tplprint->setVariable('TO', $mailData['rcp_to']);
845 
846  if ($mailData['rcp_cc']) {
847  $tplprint->setCurrentBlock('cc');
848  $tplprint->setVariable('TXT_CC', $this->lng->txt('cc'));
849  $tplprint->setVariable('CC', $mailData['rcp_cc']);
850  $tplprint->parseCurrentBlock();
851  }
852 
853  if ($mailData['rcp_bcc']) {
854  $tplprint->setCurrentBlock('bcc');
855  $tplprint->setVariable('TXT_BCC', $this->lng->txt('bc'));
856  $tplprint->setVariable('BCC', $mailData['rcp_bcc']);
857  $tplprint->parseCurrentBlock();
858  }
859 
860  $tplprint->setVariable('TXT_SUBJECT', $this->lng->txt('subject'));
861  $tplprint->setVariable('SUBJECT', htmlspecialchars($mailData['m_subject']));
862 
863  $tplprint->setVariable('TXT_DATE', $this->lng->txt('date'));
864  $tplprint->setVariable('DATE', ilDatePresentation::formatDate(new ilDateTime($mailData['send_time'], IL_CAL_DATETIME)));
865 
866  $tplprint->setVariable('TXT_MESSAGE', $this->lng->txt('message'));
867  $tplprint->setVariable('MAIL_MESSAGE', nl2br(htmlspecialchars($mailData['m_message'])));
868 
869  $tplprint->show();
870  }
871 
872  public function deliverFile()
873  {
874  if ($_SESSION["mail_id"]) {
875  $_GET["mail_id"] = $_SESSION["mail_id"];
876  }
877  $_SESSION["mail_id"] = "";
878 
879  $filename = ($_SESSION["filename"]
880  ? $_SESSION["filename"]
881  : ($_POST["filename"]
882  ? $_POST["filename"]
883  : $_GET["filename"]));
884  $_SESSION["filename"] = "";
885 
886  if ($filename != "") {
887  require_once "./Services/Mail/classes/class.ilFileDataMail.php";
888 
889  // secure filename
890  $filename = str_replace("..", "", $filename);
891 
892  $mfile = new ilFileDataMail($GLOBALS['DIC']['ilUser']->getId());
893  if (!is_array($file = $mfile->getAttachmentPathByMD5Filename($filename, $_GET['mail_id']))) {
894  ilUtil::sendInfo($this->lng->txt('mail_error_reading_attachment'));
895  $this->showMail();
896  } else {
897  ilUtil::deliverFile($file['path'], $file['filename']);
898  }
899  } else {
900  ilUtil::sendInfo($this->lng->txt('mail_select_attachment'));
901  $this->showMail();
902  }
903  }
904 
908  public function applyFilter()
909  {
910  $sentFolderId = $this->mbox->getSentFolder();
911  $draftsFolderId = $this->mbox->getDraftsFolder();
912 
913  $isTrashFolder = $_GET['mobj_id'] == $this->mbox->getTrashFolder();
914  $isSentFolder = $_GET['mobj_id'] == $sentFolderId;
915  $isDraftFolder = $_GET['mobj_id'] == $draftsFolderId;
916 
917  $table = new ilMailFolderTableGUI($this, (int) $_GET['mobj_id'], 'showFolder');
918  $table->isSentFolder($isSentFolder)
919  ->isDraftFolder($isDraftFolder)
920  ->isTrashFolder($isTrashFolder)
921  ->initFilter();
922  $table->resetOffset();
923  $table->writeFilterToSession();
924 
925  $this->showFolder();
926  }
927 
931  public function resetFilter()
932  {
933  $sentFolderId = $this->mbox->getSentFolder();
934  $draftsFolderId = $this->mbox->getDraftsFolder();
935 
936  $isTrashFolder = $_GET['mobj_id'] == $this->mbox->getTrashFolder();
937  $isSentFolder = $_GET['mobj_id'] == $sentFolderId;
938  $isDraftFolder = $_GET['mobj_id'] == $draftsFolderId;
939 
940  $table = new ilMailFolderTableGUI($this, (int) $_GET['mobj_id'], 'showFolder');
941  $table->isSentFolder($isSentFolder)
942  ->isDraftFolder($isDraftFolder)
943  ->isTrashFolder($isTrashFolder)
944  ->initFilter();
945  $table->resetOffset();
946  $table->resetFilter();
947 
948  $this->showFolder();
949  }
950 }
static _lookupLogin($a_user_id)
lookup login
This class represents an option in a radio group.
setHtml($a_html)
Set Html.
__construct()
ilMailFolderGUI constructor.
const IL_CAL_DATETIME
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
This class represents a property form user interface.
$action
global $DIC
Definition: saml.php:7
$_GET["client_id"]
This class handles all operations on files (attachments) in directory ilias_data/mail.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
showFolder($a_show_confirmation=false)
Shows current folder.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static get($a_var)
Get a value.
$from
user()
Definition: user.php:4
const VIEWMODE_SESSION_KEY
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
GUI class for public user profile presentation.
catch(Exception $e) $message
addSubfolderCommands($check_uf=false)
This class represents a property in a property form.
askForEmptyTrash()
confirmation message for empty trash action
if(isset($_POST['submit'])) $form
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
This class handles base functions for mail handling.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
Date and time handling
setTableNames($a_table_tree, $a_table_obj_data, $a_table_obj_reference="")
set table names The primary key of the table containing your object_data must be &#39;obj_id&#39; You may use...
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
cancelEmptyTrash()
cancel Empty Trash Action and return to folder
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
deleteSubfolder($a_show_confirm=true)
This class represents a custom property in a property form.
static img($a_src, $a_alt="", $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static _getFrame($a_class, $a_type='')
Get content frame name.
static _lookupPref($a_usr_id, $a_keyword)
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
performEmptyTrash()
empty Trash and return to folder
if(empty($password)) $table
Definition: pwgen.php:24
static htmlencodePlainString($a_str, $a_make_links_clickable, $a_detect_goto_links=false)
Encodes a plain text string into HTML for display in a browser.
$key
Definition: croninfo.php:18
$_POST["username"]
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
Confirmation screen class.