ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
18 // removed ilCtrl_Calls
19 // ilMailAddressbookGUI
20 
22 {
25 
26  private $tpl = null;
27  private $ctrl = null;
28  private $lng = null;
29 
30  public $umail = null;
31  public $mbox = null;
32 
33  private $errorDelete = false;
34 
35  public function __construct()
36  {
37  global $tpl, $ilCtrl, $lng, $ilUser;
38 
39  $this->tpl = $tpl;
40  $this->ctrl = $ilCtrl;
41  $this->lng = $lng;
42 
43  $this->umail = new ilMail($ilUser->getId());
44  $this->mbox = new ilMailBox($ilUser->getId());
45 
46  if(isset($_POST['mobj_id']) && (int)$_POST['mobj_id'])
47  {
48  $_GET['mobj_id'] = $_POST['mobj_id'];
49  }
50  // IF THERE IS NO OBJ_ID GIVEN GET THE ID OF MAIL ROOT NODE
51  if(!(int)$_GET['mobj_id'])
52  {
53  $_GET['mobj_id'] = $this->mbox->getInboxFolder();
54  }
55  $ilCtrl->saveParameter($this, 'mobj_id');
56  $ilCtrl->setParameter($this, 'mobj_id', $_GET['mobj_id']);
57 
58  }
59 
60  public function executeCommand()
61  {
62  if ($_POST["select_cmd"])
63  {
64  $_GET["cmd"] = 'editFolder';
65 
66  // lower menubar execute-button
67  $this->current_select_cmd = $_POST['select_cmd'];
68  $this->current_selected_cmd = $_POST['selected_cmd'];
69  }
70  else if ($_POST["select_cmd2"])
71  {
72  // upper menubar execute-button
73  $_GET["cmd"] = 'editFolder';
74  $this->current_select_cmd = $_POST['select_cmd2'];
75  $this->current_selected_cmd = $_POST['selected_cmd2'];
76  }
77 
78  /* Fix: User views mail and wants to delete it...
79  mjansen: The mail system needs a revision :-)
80  */
81  if ($_GET['selected_cmd'] == "deleteMails" && $_GET["mail_id"])
82  {
83  $_GET["cmd"] = "editFolder";
84  $this->current_selected_cmd = "deleteMails";
85  $_POST["mail_id"] = array($_GET["mail_id"]);
86  }
87 
88  /* Fix: User views mail and wants to move it...
89  mjansen: The mail system needs a revision :-)
90  */
91  $cmd = $this->ctrl->getCmd();
92  if($cmd == 'changeFolder' &&
93  is_numeric($_POST['selected_cmd']) &&
94  $_GET["mail_id"])
95  {
96  $this->current_selected_cmd = (int)$_POST['selected_cmd'];
97  }
98 
99  $forward_class = $this->ctrl->getNextClass($this);
100  switch($forward_class)
101  {
102  case 'ilmailaddressbookgui':
103  include_once 'Services/Contact/classes/class.ilMailAddressbookGUI.php';
104 
105  $this->ctrl->forwardCommand(new ilMailAddressbookGUI());
106  break;
107 
108  case 'ilmailoptionsgui':
109  include_once 'Services/Mail/classes/class.ilMailOptionsGUI.php';
110 
111  $this->ctrl->forwardCommand(new ilMailOptionsGUI());
112  break;
113 
114  case 'ilpublicuserprofilegui':
115  include_once("Services/User/classes/class.ilPublicUserProfileGUI.php");
116  $this->tpl->setTitle($this->lng->txt("mail"));
117  $this->ctrl->saveParameter($this, "mail_id");
118  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
119  $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, "showMail"));
120  $ret = $this->ctrl->forwardCommand($profile_gui);
121  if ($ret != "")
122  {
123  $this->tpl->setContent($ret);
124  $this->tpl->show();
125  }
126  break;
127 
128  default:
129  if (!($cmd = $this->ctrl->getCmd()))
130  {
131  $cmd = "showFolder";
132  }
133  $this->$cmd();
134  break;
135  }
136  return true;
137  }
138 
139  public function add()
140  {
141  global $lng, $ilUser;
142 
143  if($_GET["mail_id"] != "")
144  {
145  if (is_array($mail_data = $this->umail->getMail($_GET["mail_id"])))
146  {
147  require_once "Services/Contact/classes/class.ilAddressbook.php";
148  $abook = new ilAddressbook($ilUser->getId());
149 
150  $tmp_user = new ilObjUser($mail_data["sender_id"]);
151  if ($abook->checkEntryByLogin($tmp_user->getLogin()) > 0)
152  {
153  ilUtil::sendInfo($lng->txt("mail_entry_exists"));
154  }
155  else
156  {
157  $abook->addEntry($tmp_user->getLogin(),
158  $tmp_user->getFirstname(),
159  $tmp_user->getLastname(),
160  $tmp_user->getEmail());
161  ilUtil::sendInfo($lng->txt("mail_entry_added"));
162  }
163  }
164  }
165  $this->showMail();
166  }
167 
171  public function cancelEmptyTrash()
172  {
173  $this->showFolder();
174  }
175 
179  public function performEmptyTrash()
180  {
181  $this->umail->deleteMailsOfFolder($_GET["mobj_id"]);
182 
183  ilUtil::sendInfo($this->lng->txt("mail_deleted"));
184  $this->showFolder();
185 
186  return true;
187  }
188 
192  public function askForEmptyTrash()
193  {
194  if($this->umail->countMailsOfFolder((int)$_GET['mobj_id']))
195  {
196  ilUtil::sendQuestion($this->lng->txt('mail_empty_trash_confirmation'));
197  $this->askForConfirmation = true;
198  }
199 
200  $this->showFolder();
201 
202  return true;
203  }
204 
205  public function showUser()
206  {
207  global $ilCtrl, $ilToolbar;
208 
209  $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
210 
211  $this->tpl->setTitle($this->lng->txt("mail"));
212  //$ilToolbar->addButton($this->lng->txt("back"), $this->ctrl->getLinkTarget($this, "showMail"));
213 
214  $this->tpl->setVariable("TBL_TITLE", $this->lng->txt("profile_of")." ".
215  ilObjUser::_lookupLogin($_GET["user"]));
216  $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath("icon_usr.gif"));
217  $this->tpl->setVariable("TBL_TITLE_IMG_ALT", $this->lng->txt("public_profile"));
218 
219  include_once './Services/User/classes/class.ilPublicUserProfileGUI.php';
220  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
221  $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, "showMail"));
222  $this->tpl->setContent($ilCtrl->getHTML($profile_gui));
223  $this->tpl->show();
224 
225  return true;
226  }
227 
228  public function addSubfolderCommands($check_uf = false)
229  {
230  global $ilToolbar;
231 
233  {
234  $ilToolbar->addSeparator();
235  }
236 
237  $ilToolbar->addButton($this->lng->txt('mail_add_subfolder'), $this->ctrl->getLinkTarget($this, 'addSubFolder'));
238 
239  if($check_uf == true)
240  {
241  $ilToolbar->addButton($this->lng->txt('rename'), $this->ctrl->getLinkTarget($this, 'renameSubFolder'));
242  $ilToolbar->addButton($this->lng->txt('delete'), $this->ctrl->getLinkTarget($this, 'deleteSubFolder'));
243  }
244  return true;
245  }
249  public function showFolder($a_show_confirmation = false)
250  {
251  global $ilUser, $ilToolbar;
252 
253  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail.html', 'Services/Mail');
254  $this->tpl->setTitle($this->lng->txt('mail'));
255 
256  include_once 'Services/Mail/classes/class.ilMailFolderTableGUI.php';
257 
258  $sentFolderId = $this->mbox->getSentFolder();
259  $draftsFolderId = $this->mbox->getDraftsFolder();
260 
261  $isTrashFolder = $_GET['mobj_id'] == $this->mbox->getTrashFolder();
262  $isSentFolder = $_GET['mobj_id'] == $sentFolderId;
263  $isDraftFolder = $_GET['mobj_id'] == $draftsFolderId;
264 
265  // BEGIN CONFIRM_DELETE
266  if($this->current_selected_cmd == 'deleteMails' &&
267  !$this->errorDelete &&
268  $this->current_selected_cmd != 'confirm' &&
269  $isTrashFolder)
270  {
271  if(isset($_REQUEST['mail_id']) && !is_array($_REQUEST['mail_id'])) $_REQUEST['mail_id'] = array($_REQUEST['mail_id']);
272  foreach((array)$_REQUEST['mail_id'] as $id)
273  {
274  $this->tpl->setCurrentBlock('mail_ids');
275  $this->tpl->setVariable('MAIL_ID_VALUE', $id);
276  $this->tpl->parseCurrentBlock();
277  }
278 
279  $this->tpl->setCurrentBlock('confirm_delete');
280  $this->tpl->setVariable('ACTION', $this->ctrl->getFormAction($this, 'confirmDeleteMails'));
281  $this->tpl->setVariable('BUTTON_CONFIRM',$this->lng->txt('confirm'));
282  $this->tpl->setVariable('BUTTON_CANCEL',$this->lng->txt('cancel'));
283  $this->tpl->parseCurrentBlock();
284  }
285 
286  $folders = $this->mbox->getSubFolders();
287  $mtree = new ilTree($ilUser->getId());
288  $mtree->setTableNames('mail_tree', 'mail_obj_data');
289 
290  $check_uf = false;
291  $check_local = false;
292 
294  {
295  $folder_d = $mtree->getNodeData($_GET['mobj_id']);
296  if($folder_d['m_type'] == 'user_folder')
297  {
298  $check_uf = true;
299  }
300  else if($folder_d['m_type'] == 'local')
301  {
302  $check_local = true;
303  }
304  }
305 
306  $mailtable = new ilMailFolderTableGUI($this, (int)$_GET['mobj_id'], 'showFolder');
307  $mailtable->isSentFolder($isSentFolder)
308  ->isDraftFolder($isDraftFolder)
309  ->isTrashFolder($isTrashFolder)
310  ->setSelectedItems($_POST['mail_id'])
311  ->prepareHTML();
312 
313  if(!isset($_SESSION[ilMailGUI::VIEWMODE_SESSION_KEY]) || 'tree' != $_SESSION[ilMailGUI::VIEWMODE_SESSION_KEY])
314  {
315  $folder_options = array();
316  foreach($folders as $folder)
317  {
318  $folder_d = $mtree->getNodeData($folder['obj_id']);
319 
320  if($folder['obj_id'] == $_GET['mobj_id'])
321  {
322  if($folder['type'] == 'user_folder')
323  {
324  $check_uf = true;
325  }
326  else if($folder['type'] == 'local')
327  {
328  $check_local = true;
329  $check_uf = false;
330  }
331  }
332 
333  if($folder['type'] == 'user_folder')
334  {
335  $pre = '';
336  for ($i = 2; $i < $folder_d['depth'] - 1; $i++)
337  $pre .= '&nbsp';
338  if ($folder_d['depth'] > 1)
339  $pre .= '+';
340  $folder_options[$folder['obj_id']] = $pre.' '.$folder['title'];
341  }
342  else
343  {
344  $folder_options[$folder['obj_id']] = $this->lng->txt('mail_'.$folder['title']);
345  }
346  }
347  }
348  if($a_show_confirmation == false)
349  {
350  if('tree' != $_SESSION[ilMailGUI::VIEWMODE_SESSION_KEY])
351  {
352  $ilToolbar->addText($this->lng->txt('mail_change_to_folder'));
353  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
354  $si = new ilSelectInputGUI("", "mobj_id");
355  $si->setOptions($folder_options);
356  $si->setValue($_GET['mobj_id']);
357  $ilToolbar->addInputItem($si);
358 
359  $ilToolbar->addFormButton($this->lng->txt('change'),'showFolder');
360  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, 'showFolder'));
361  }
362  if($check_local == true || $check_uf == true)
363  {
364  $this->addSubfolderCommands($check_uf);
365  }
366  }
367  // END SHOW_FOLDER
368 
369  // BEGIN Trash delete confirmation
370  if($mailtable->isTrashFolder() &&
371  $mailtable->getNumerOfMails() > 0)
372  {
373  if($this->askForConfirmation == true)
374  {
375  $this->tpl->setCurrentBlock('CONFIRM_EMPTY_TRASH');
376  $this->tpl->setVariable('ACTION_EMPTY_TRASH_CONFIRMATION', $this->ctrl->getFormAction($this, 'performEmptyTrash'));
377  $this->tpl->setVariable('BUTTON_CONFIRM_EMPTY_TRASH', $this->lng->txt('confirm'));
378  $this->tpl->setVariable('BUTTON_CANCEL_EMPTY_TRASH', $this->lng->txt('cancel'));
379  $this->tpl->parseCurrentBlock();
380  }
381  }
382  // END Trash delete confirmation
383 
384  $this->tpl->setVariable('MAIL_TABLE', $mailtable->getHtml());
385  $this->tpl->show();
386  }
387 
388  public function deleteSubfolder($a_show_confirm = true)
389  {
390  if($a_show_confirm)
391  {
392  $sub_folder = $this->mbox->getFolderData($_GET['mobj_id']);
393  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
394  $oConfirmationGUI = new ilConfirmationGUI();
395 
396  // set confirm/cancel commands
397  $oConfirmationGUI->setFormAction($this->ctrl->getFormAction($this,"showFolder"));
398  $oConfirmationGUI->setHeaderText($this->lng->txt("mail_sure_delete_folder"));
399  $oConfirmationGUI->setCancel($this->lng->txt("cancel"), "showFolder");
400  $oConfirmationGUI->setConfirm($this->lng->txt("confirm"), "performDeleteSubfolder");
401  $oConfirmationGUI->addItem('', '', $sub_folder['title']);
402  $this->tpl->setVariable('CONFIRMATION',$oConfirmationGUI->getHTML());
403 
404  return $this->showFolder(true);
405  }
406  else
407  return $this->showFolder(false);
408  }
409 
410  public function performDeleteSubFolder()
411  {
412  $new_parent = $this->mbox->getParentFolderId($_GET["mobj_id"]);
413 
414  if ($this->mbox->deleteFolder($_GET["mobj_id"]))
415  {
416  ilUtil::sendInfo($this->lng->txt("mail_folder_deleted"),true);
417  ilUtil::redirect("ilias.php?baseClass=ilMailGUI");
418  }
419  else
420  {
421  ilUtil::sendFailure($this->lng->txt("mail_error_delete"));
422  return $this->showFolder();
423  }
424  }
425 
426  public function performAddSubFolder()
427  {
428  global $ilCtrl;
429 
430  if (isset($_POST["subfolder_title"]) && 'tree' == $_SESSION[ilMailGUI::VIEWMODE_SESSION_KEY]) $_SESSION["subfolder_title"] = ilUtil::stripSlashes($_POST['subfolder_title']);
431 
432  if (empty($_POST['subfolder_title']))
433  {
434  ilUtil::sendInfo($this->lng->txt("mail_insert_folder_name"));
435  return $this->addSubFolder();
436  }
437  else if ($mobj_id = $this->mbox->addFolder($_GET["mobj_id"], ilUtil::stripSlashes($_POST["subfolder_title"])))
438  {
439  $ilCtrl->saveParameter($this, 'mobj_id');
440  $ilCtrl->setParameter($this, 'mobj_id', $mobj_id);
441 
442  unset($_SESSION["subfolder_title"]);
443  ilUtil::sendInfo($this->lng->txt("mail_folder_created"));
444  }
445  else
446  {
447  ilUtil::sendFailure($this->lng->txt("mail_folder_exists"));
448  $this->addSubFolder();
449  }
450  return $this->showFolder();
451  }
452 
453  public function addSubFolder()
454  {
459  global $ilCtrl, $tpl;
460 
461  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
462 
463  $tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail.html', 'Services/Mail');
464  $tpl->setTitle($this->lng->txt('mail'));
465 
466  $oForm = new ilPropertyFormGUI();
467  $oForm->setFormAction($ilCtrl->getFormAction($this, 'performAddSubFolder'));
468  $oForm->setTitle($this->lng->txt('mail_add_folder'));
469 
470  //title
471  $oTitle = new ilTextInputGUI();
472  $oTitle->setTitle($this->lng->txt('title'));
473  $oTitle->setPostVar('subfolder_title');
474  $oForm->addItem($oTitle);
475 
476  $oForm->addCommandButton('performAddSubFolder', $this->lng->txt('save'));
477  $oForm->addCommandButton('showFolder', $this->lng->txt('cancel'));
478 
479  $tpl->setVariable('FORM', $oForm->getHTML());
480  $tpl->show();
481 
482  return true;
483  }
484 
485  public function renameSubFolder()
486  {
491  global $ilCtrl, $tpl;
492 
493  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
494 
495  $tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail.html', 'Services/Mail');
496  $tpl->setTitle($this->lng->txt('mail'));
497 
498  $oForm = new ilPropertyFormGUI();
499  $oForm->setFormAction($ilCtrl->getFormAction($this, 'performRenameSubFolder'));
500  $oForm->setTitle($this->lng->txt('mail_rename_folder'));
501 
502  //title
503  $oTitle = new ilTextInputGUI();
504  $oTitle->setTitle($this->lng->txt('title'));
505  $tmp_data = $this->mbox->getFolderData($_GET["mobj_id"]);
506  $oTitle->setValue($tmp_data["title"]);
507  $oTitle->setPostVar('subfolder_title');
508  $oForm->addItem($oTitle);
509 
510  $oForm->addCommandButton('performRenameSubFolder', $this->lng->txt('save'));
511  $oForm->addCommandButton('showFolder', $this->lng->txt('cancel'));
512  $tpl->setVariable('FORM', $oForm->getHTML());
513  $tpl->show();
514 
515  return true;
516  }
517 
518  public function performRenameSubFolder()
519  {
520  if (isset($_POST["subfolder_title"]) && 'tree' == $_SESSION[ilMailGUI::VIEWMODE_SESSION_KEY]) $_SESSION["subfolder_title"] = $_POST['subfolder_title'];
521 
522  $tmp_data = $this->mbox->getFolderData($_GET["mobj_id"]);
523  if ($tmp_data["title"] != $_POST["subfolder_title"])
524  {
525  if ($_POST["subfolder_title"] == "")
526  {
527  ilUtil::sendInfo($this->lng->txt("mail_insert_folder_name"));
528  return $this->renameSubFolder();
529  }
530  else
531  {
532  if ($this->mbox->renameFolder($_GET["mobj_id"], ilUtil::stripSlashes($_POST["subfolder_title"])))
533  {
534  ilUtil::sendInfo($this->lng->txt("mail_folder_name_changed"), true);
535  unset($_SESSION["subfolder_title"]);
536  }
537  else
538  {
539  ilUtil::sendFailure($this->lng->txt("mail_folder_exists"));
540  return $this->renameSubFolder();
541  }
542  }
543  }
544  return $this->showFolder();
545  }
546 
547  public function changeFolder()
548  {
549  switch ($this->current_selected_cmd)
550  {
551  default:
552  if(!(int)$_GET["mail_id"] || !(int)$this->current_selected_cmd)
553  {
554  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
555  return $this->showMail();
556  }
557 
558  if ($this->umail->moveMailsToFolder(array($_GET["mail_id"]), $this->current_selected_cmd))
559  {
560  ilUtil::sendInfo($this->lng->txt("mail_moved"), true);
561  $this->ctrl->redirectByClass("ilMailGUI");
562  }
563  else
564  {
565  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
566  }
567  break;
568  }
569 
570  $this->showMail();
571 
572  return true;
573  }
574 
575  public function editFolder()
576  {
577  switch ($this->current_selected_cmd)
578  {
579  case 'markMailsRead':
580  if(is_array($_POST["mail_id"]))
581  {
582  $this->umail->markRead($_POST["mail_id"]);
583  }
584  else
585  {
586  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
587  }
588  break;
589  case 'markMailsUnread':
590  if(is_array($_POST["mail_id"]))
591  {
592  $this->umail->markUnread($_POST["mail_id"]);
593  }
594  else
595  {
596  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
597  }
598  break;
599 
600  case 'deleteMails':
601  // IF MAILBOX IS TRASH ASK TO CONFIRM
602  if($this->mbox->getTrashFolder() == $_GET["mobj_id"])
603  {
604  if(!is_array($_POST["mail_id"]))
605  {
606  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
607  $this->errorDelete = true;
608  }
609  else
610  {
611  ilUtil::sendQuestion($this->lng->txt("mail_sure_delete"));
612  }
613  } // END IF MAILBOX IS TRASH FOLDER
614  else
615  {
616  // MOVE MAILS TO TRASH
617  if(!is_array($_POST["mail_id"]))
618  {
619  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
620  }
621  else if($this->umail->moveMailsToFolder($_POST["mail_id"], $this->mbox->getTrashFolder()))
622  {
623  $_GET["offset"] = 0;
624  ilUtil::sendInfo($this->lng->txt("mail_moved_to_trash"));
625  }
626  else
627  {
628  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
629  }
630  }
631  break;
632 
633  case 'add':
634  $this->ctrl->setParameterByClass("ilmailoptionsgui", "cmd", "add");
635  $this->ctrl->redirectByClass("ilmailoptionsgui");
636 
637  case 'moveMails':
638  default:
639  if(!is_array($_POST["mail_id"]))
640  {
641  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
642  }
643  else if($this->umail->moveMailsToFolder($_POST["mail_id"],$this->current_selected_cmd))
644  {
645  ilUtil::sendInfo($this->lng->txt("mail_moved"));
646  }
647  else
648  {
649  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
650  }
651  break;
652  }
653 
654  $this->showFolder();
655  }
656 
657  public function confirmDeleteMails()
658  {
659  // ONLY IF FOLDER IS TRASH, IT WAS ASKED FOR CONFIRMATION
660  if($this->mbox->getTrashFolder() == $_GET["mobj_id"])
661  {
662  if(!is_array($_POST["mail_id"]))
663  {
664  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
665  }
666  else if($this->umail->deleteMails($_POST["mail_id"]))
667  {
668  $_GET["offset"] = 0;
669  ilUtil::sendInfo($this->lng->txt("mail_deleted"));
670  }
671  else
672  {
673  ilUtil::sendInfo($this->lng->txt("mail_delete_error"));
674  }
675  }
676 
677  $this->showFolder();
678  }
679 
680  public function cancelDeleteMails()
681  {
682  //$this->ctrl->setParameter($this, "offset", $_GET["offset"]);
683  $this->ctrl->redirect($this);
684  }
685 
686  public function showMail()
687  {
688  global $ilUser;
689 
690  if ($_SESSION["mail_id"])
691  {
692  $_GET["mail_id"] = $_SESSION["mail_id"];
693  $_SESSION["mail_id"] = "";
694  }
695 
696  $this->umail->markRead(array($_GET["mail_id"]));
697 
698  $mailData = $this->umail->getMail($_GET["mail_id"]);
699 
700  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_read.html", "Services/Mail");
701  $this->tpl->setTitle($this->lng->txt("mail_mails_of"));
702 
703  if ($_SESSION[ilMailGUI::VIEWMODE_SESSION_KEY] == "tree") $this->tpl->setVariable("FORM_TARGET", ilFrameTargetInfo::_getFrame("MainContent"));
704 
705  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
706 
707  // buttons...
708  // reply
709  include_once("./Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php");
710  $toolbar = new ilToolbarGUI();
711  if($mailData["sender_id"] &&
712  $mailData["sender_id"] != ANONYMOUS_USER_ID)
713  {
714  $this->ctrl->setParameterByClass("ilmailformgui", "mail_id", $_GET["mail_id"]);
715  $this->ctrl->setParameterByClass("ilmailformgui", "type", "reply");
716  $this->ctrl->clearParametersByClass("iliasmailformgui");
717 
718  $toolbar->addButton($this->lng->txt("reply"), $this->ctrl->getLinkTargetByClass("ilmailformgui"),
719  "", ilAccessKey::REPLY);
720  }
721 
722  // forward
723  $this->ctrl->setParameterByClass("ilmailformgui", "mail_id", $_GET["mail_id"]);
724  $this->ctrl->setParameterByClass("ilmailformgui", "type", "forward");
725  $this->ctrl->clearParametersByClass("iliasmailformgui");
726  $toolbar->addButton($this->lng->txt("forward"), $this->ctrl->getLinkTargetByClass("ilmailformgui"),
728 
729  // print
730  $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
731  $this->ctrl->setParameter($this, "cmd", "printMail");
732  $toolbar->addButton($this->lng->txt("print"), $this->ctrl->getLinkTarget($this),
733  "_blank");
734  $this->ctrl->clearParameters($this);
735 
736  // delete
737  $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
738  $this->ctrl->setParameter($this, "selected_cmd", "deleteMails");
739  $toolbar->addButton($this->lng->txt("delete"), $this->ctrl->getLinkTarget($this),
740  "", ilAccessKey::DELETE);
741  $this->ctrl->clearParameters($this);
742 
743  $this->tpl->setVariable("BUTTONS2",$toolbar->getHTML());
744 
745  $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
746  $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this));
747  $this->ctrl->clearParameters($this);
748 
749  if ($mailData["sender_id"] &&
750  $mailData["sender_id"] != $ilUser->getId() &&
751  $mailData["sender_id"] != ANONYMOUS_USER_ID)
752  {
753  require_once "Services/Contact/classes/class.ilAddressbook.php";
754  $abook = new ilAddressbook($ilUser->getId());
755  $tmp_user = new ilObjUser($mailData["sender_id"]);
756  if ($abook->checkEntryByLogin($tmp_user->getLogin()) == 0)
757  {
758  $tplbtn = new ilTemplate("tpl.buttons.html", true, true);
759 
760  $tplbtn->setCurrentBlock("btn_cell");
761  $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
762  $this->ctrl->setParameter($this, "cmd", "add");
763  $tplbtn->setVariable("BTN_LINK", $this->ctrl->getLinkTarget($this));
764  $this->ctrl->clearParameters($this);
765  $tplbtn->setVariable("BTN_TXT", $this->lng->txt("mail_add_to_addressbook"));
766  $tplbtn->parseCurrentBlock();
767 
768  $this->tpl->setVariable("ADD_USER_BTN",$tplbtn->get());
769  }
770  }
771 
772  // SET MAIL DATA
773  $counter = 1;
774 
775  // FROM
776  if($mailData["sender_id"] != ANONYMOUS_USER_ID)
777  {
778  $tmp_user = new ilObjUser($mailData['sender_id']);
779  $this->ctrl->setParameter($this, 'mail_id', $_GET['mail_id']);
780  $this->ctrl->setParameter($this, 'user', $tmp_user->getId());
781  if (in_array(ilObjUser::_lookupPref($mailData['sender_id'], 'public_profile'), array("y", "g")))
782  {
783  $this->tpl->setVariable('PROFILE_LINK_FROM', $this->ctrl->getLinkTarget($this, 'showUser'));
784  $this->tpl->setVariable('FROM', $tmp_user->getFullname());
785  }
786  $this->tpl->setCurrentBlock("pers_image");
787  $this->tpl->setVariable("IMG_SENDER", $tmp_user->getPersonalPicturePath("xsmall"));
788  $this->tpl->setVariable("ALT_SENDER", $tmp_user->getFullname());
789  $this->tpl->parseCurrentBlock();
790  $this->tpl->setCurrentBlock("adm_content");
791  if(!($login = $tmp_user->getLogin()))
792  {
793  $login = $mailData["import_name"]." (".$this->lng->txt("user_deleted").")";
794  }
795  $this->tpl->setVariable("MAIL_LOGIN",$login);
796  $this->tpl->setVariable("CSSROW_FROM", (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
797  }
798  else
799  {
800  $tmp_user = new ilObjUser(ANONYMOUS_USER_ID);
801  $this->tpl->setVariable('MAIL_LOGIN', ilMail::_getIliasMailerName());
802  $this->tpl->setCurrentBlock('pers_image');
803  $this->tpl->setVariable('IMG_SENDER', ilUtil::getImagePath('HeaderIcon.png'));
804  $this->tpl->setVariable('ALT_SENDER', ilMail::_getIliasMailerName());
805  $this->tpl->parseCurrentBlock();
806  }
807 
808  $this->tpl->setVariable('TXT_FROM', $this->lng->txt('from'));
809 
810  // TO
811  $this->tpl->setVariable('TXT_TO', $this->lng->txt('mail_to'));
812  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
813  $this->tpl->setVariable('TO', ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_to']), false));
814  $this->tpl->setVariable('CSSROW_TO', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
815 
816  // CC
817  if($mailData['rcp_cc'])
818  {
819  $this->tpl->setCurrentBlock('cc');
820  $this->tpl->setVariable('TXT_CC',$this->lng->txt('cc'));
821  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
822  $this->tpl->setVariable('CC', ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_cc']), false));
823  $this->tpl->setVariable('CSSROW_CC', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
824  $this->tpl->parseCurrentBlock();
825  }
826 
827  // BCC
828  if($mailData['rcp_bcc'])
829  {
830  $this->tpl->setCurrentBlock('bcc');
831  $this->tpl->setVariable('TXT_BCC',$this->lng->txt('bc'));
832  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
833  $this->tpl->setVariable('BCC', ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_bcc']), false));
834  $this->tpl->setVariable('CSSROW_BCC', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
835  $this->tpl->parseCurrentBlock();
836  }
837 
838  // SUBJECT
839  $this->tpl->setVariable('TXT_SUBJECT', $this->lng->txt('subject'));
840  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
841  $this->tpl->setVariable('SUBJECT', ilUtil::htmlencodePlainString($mailData['m_subject'], true));
842  $this->tpl->setVariable('CSSROW_SUBJ', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
843 
844  // DATE
845  $this->tpl->setVariable('TXT_DATE', $this->lng->txt('date'));
846  $this->tpl->setVariable('DATE',ilDatePresentation::formatDate(new ilDateTime($mailData['send_time'],IL_CAL_DATETIME)));
847  $this->tpl->setVariable('CSSROW_DATE', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
848 
849  // ATTACHMENTS
850  if($mailData['attachments'])
851  {
852  $this->tpl->setCurrentBlock('attachment');
853  $this->tpl->setCurrentBlock('a_row');
854  $counter = 1;
855  foreach($mailData['attachments'] as $file)
856  {
857  $this->tpl->setVariable('A_CSSROW', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
858  $this->tpl->setVariable('FILE', md5($file));
859  $this->tpl->setVariable('FILE_NAME', $file);
860  $this->tpl->parseCurrentBlock();
861  }
862  $this->tpl->setVariable('TXT_ATTACHMENT', $this->lng->txt('attachments'));
863  $this->tpl->setVariable('TXT_DOWNLOAD', $this->lng->txt('download'));
864  $this->tpl->parseCurrentBlock();
865  }
866 
867  // MESSAGE
868  $this->tpl->setVariable('TXT_MESSAGE', $this->lng->txt('message'));
869 
870  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
871  $this->tpl->setVariable('MAIL_MESSAGE', ilUtil::htmlencodePlainString($mailData['m_message'], true));
872 
873  $isTrashFolder = false;
874  if ($this->mbox->getTrashFolder() == $_GET['mobj_id'])
875  {
876  $isTrashFolder = true;
877  }
878 
879  // Bottom toolbar
880  $oBottomToolbar = new ilToolbarGUI();
881 
882  $selectOptions = array();
883  $actions = $this->mbox->getActions($_GET["mobj_id"]);
884  foreach($actions as $key => $action)
885  {
886  if($key == 'moveMails')
887  {
888  $folders = $this->mbox->getSubFolders();
889  foreach($folders as $folder)
890  {
891  if ($folder["type"] != 'trash' ||
892  !$isTrashFolder)
893  {
894  $optionText = '';
895  if($folder['type'] != 'user_folder')
896  {
897  $optionText = $action.' '.$this->lng->txt('mail_'.$folder['title']).($folder['type'] == 'trash' ? ' ('.$this->lng->txt('delete').')' : '');
898  }
899  else
900  {
901  $optionText = $action.' '.$folder['title'];
902  }
903 
904  $selectOptions[$folder['obj_id']] = $optionText;
905  }
906  }
907  }
908  }
909  if(is_array($selectOptions) && count($selectOptions))
910  {
911  include_once 'Services/Form/classes/class.ilSelectInputGUI.php';
912  $oActionSelectBox = new ilSelectInputGUI('', 'selected_cmd');
913  $oActionSelectBox->setOptions($selectOptions);
914  $oBottomToolbar->addInputItem($oActionSelectBox);
915  $oBottomToolbar->addFormButton($this->lng->txt('submit'), 'changeFolder');
916  }
917 
918  // Navigation
919  $prevMail = $this->umail->getPreviousMail($_GET['mail_id']);
920  $nextMail = $this->umail->getNextMail($_GET['mail_id']);
921  if(is_array($prevMail) || is_array($nextMail))
922  {
923  $oBottomToolbar->addSeparator();
924 
925  if($prevMail['mail_id'])
926  {
927  $this->ctrl->setParameter($this, 'mail_id', $prevMail['mail_id']);
928  $this->ctrl->setParameter($this, 'cmd', 'showMail');
929  $oBottomToolbar->addButton($this->lng->txt('previous'), $this->ctrl->getLinkTarget($this));
930  $this->ctrl->clearParameters($this);
931  }
932 
933  if($nextMail['mail_id'])
934  {
935  $this->ctrl->setParameter($this, 'mail_id', $nextMail['mail_id']);
936  $this->ctrl->setParameter($this, 'cmd', 'showMail');
937  $oBottomToolbar->addButton($this->lng->txt('next'), $this->ctrl->getLinkTarget($this));
938  $this->ctrl->clearParameters($this);
939  }
940  }
941 
942  $this->tpl->setVariable('MAIL_NAVIGATION', $oBottomToolbar->getHTML());
943  $this->tpl->show();
944  }
945 
946  public function printMail()
947  {
948  $tplprint = new ilTemplate("Services/Mail/templates/default/tpl.mail_print.html",true,true,true);
949  $tplprint->setVariable("JSPATH",$tpl->tplPath);
950 
951  //get the mail from user
952  $mailData = $this->umail->getMail($_GET["mail_id"]);
953 
954  // SET MAIL DATA
955  // FROM
956  if($mailData["sender_id"] != ANONYMOUS_USER_ID)
957  {
958  $tmp_user = new ilObjUser($mailData["sender_id"]);
959  if(!($login = $tmp_user->getFullname()))
960  {
961  $login = $mailData["import_name"]." (".$this->lng->txt("user_deleted").")";
962  }
963  $tplprint->setVariable("FROM", $login);
964  }
965  else
966  {
967  $tplprint->setVariable('FROM', ilMail::_getIliasMailerName());
968  }
969 
970  $tplprint->setVariable('TXT_FROM', $this->lng->txt('from'));
971 
972  // TO
973  $tplprint->setVariable("TXT_TO", $this->lng->txt("mail_to"));
974  $tplprint->setVariable("TO", $mailData["rcp_to"]);
975 
976  // CC
977  if($mailData["rcp_cc"])
978  {
979  $tplprint->setCurrentBlock("cc");
980  $tplprint->setVariable("TXT_CC",$this->lng->txt("cc"));
981  $tplprint->setVariable("CC",$mailData["rcp_cc"]);
982  $tplprint->parseCurrentBlock();
983  }
984  // SUBJECT
985  $tplprint->setVariable("TXT_SUBJECT",$this->lng->txt("subject"));
986  $tplprint->setVariable("SUBJECT",htmlspecialchars($mailData["m_subject"]));
987 
988  // DATE
989  $tplprint->setVariable("TXT_DATE", $this->lng->txt("date"));
990  $tplprint->setVariable("DATE", ilDatePresentation::formatDate(new ilDateTime($mailData["send_time"],IL_CAL_DATETIME)));
991 
992 
993  // MESSAGE
994  $tplprint->setVariable("TXT_MESSAGE", $this->lng->txt("message"));
995  $tplprint->setVariable("MAIL_MESSAGE", nl2br(htmlspecialchars($mailData["m_message"])));
996 
997 
998  $tplprint->show();
999  }
1000 
1001  function deliverFile()
1002  {
1003  if ($_SESSION["mail_id"])
1004  {
1005  $_GET["mail_id"] = $_SESSION["mail_id"];
1006  }
1007  $_SESSION["mail_id"] = "";
1008 
1009  $filename = ($_SESSION["filename"]
1010  ? $_SESSION["filename"]
1011  : ($_POST["filename"]
1012  ? $_POST["filename"]
1013  : $_GET["filename"]));
1014  $_SESSION["filename"] = "";
1015 
1016  if ($filename != "")
1017  {
1018  require_once "classes/class.ilFileDataMail.php";
1019 
1020  // secure filename
1021  $filename = str_replace("..", "", $filename);
1022 
1023  $mfile = new ilFileDataMail($_SESSION["AccountId"]);
1024  if(!is_array($file = $mfile->getAttachmentPathByMD5Filename($filename, $_GET['mail_id'])))
1025  {
1026  ilUtil::sendInfo($this->lng->txt('mail_error_reading_attachment'));
1027  $this->showMail();
1028  }
1029  else
1030  {
1031  ilUtil::deliverFile($file['path'], $file['filename']);
1032  }
1033  }
1034  else
1035  {
1036  ilUtil::sendInfo($this->lng->txt('mail_select_attachment'));
1037  $this->showMail();
1038  }
1039  }
1040 
1041 }
1042 ?>