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