ILIAS  Release_4_1_x_branch Revision 61804
 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 
166  $this->showMail();
167 
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 
185  ilUtil::sendInfo($this->lng->txt("mail_deleted"));
186  $this->showFolder();
187 
188  return true;
189  }
190 
194  public function askForEmptyTrash()
195  {
196  if($this->umail->countMailsOfFolder((int)$_GET['mobj_id']))
197  {
198  ilUtil::sendQuestion($this->lng->txt('mail_empty_trash_confirmation'));
199  $this->askForConfirmation = true;
200  }
201 
202  $this->showFolder();
203 
204  return true;
205  }
206 
207  public function showUser()
208  {
209  global $ilCtrl, $ilToolbar;
210 
211  $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
212 
213  $this->tpl->setTitle($this->lng->txt("mail"));
214  //$ilToolbar->addButton($this->lng->txt("back"), $this->ctrl->getLinkTarget($this, "showMail"));
215 
216  $this->tpl->setVariable("TBL_TITLE", $this->lng->txt("profile_of")." ".
217  ilObjUser::_lookupLogin($_GET["user"]));
218  $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath("icon_usr.gif"));
219  $this->tpl->setVariable("TBL_TITLE_IMG_ALT", $this->lng->txt("public_profile"));
220 
221  include_once './Services/User/classes/class.ilPublicUserProfileGUI.php';
222  $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
223  $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, "showMail"));
224  $this->tpl->setContent($ilCtrl->getHTML($profile_gui));
225  $this->tpl->show();
226 
227  return true;
228  }
229 
233  public function showFolder()
234  {
235  global $ilUser;
236 
237  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail.html', 'Services/Mail');
238  $this->tpl->setVariable('HEADER', $this->lng->txt('mail'));
239 
240  include_once 'Services/Mail/classes/class.ilMailFolderTableGUI.php';
241 
242  $sentFolderId = $this->mbox->getSentFolder();
243  $draftsFolderId = $this->mbox->getDraftsFolder();
244 
245  $isTrashFolder = $_GET['mobj_id'] == $this->mbox->getTrashFolder();
246  $isSentFolder = $_GET['mobj_id'] == $sentFolderId;
247  $isDraftFolder = $_GET['mobj_id'] == $draftsFolderId;
248 
249  // BEGIN CONFIRM_DELETE
250  if($this->current_selected_cmd == 'deleteMails' &&
251  !$this->errorDelete &&
252  $this->current_selected_cmd != 'confirm' &&
253  $isTrashFolder)
254  {
255  if(isset($_REQUEST['mail_id']) && !is_array($_REQUEST['mail_id'])) $_REQUEST['mail_id'] = array($_REQUEST['mail_id']);
256  foreach((array)$_REQUEST['mail_id'] as $id)
257  {
258  $this->tpl->setCurrentBlock('mail_ids');
259  $this->tpl->setVariable('MAIL_ID_VALUE', $id);
260  $this->tpl->parseCurrentBlock();
261  }
262 
263  $this->tpl->setCurrentBlock('confirm_delete');
264  $this->tpl->setVariable('ACTION', $this->ctrl->getFormAction($this, 'confirmDeleteMails'));
265  $this->tpl->setVariable('BUTTON_CONFIRM',$this->lng->txt('confirm'));
266  $this->tpl->setVariable('BUTTON_CANCEL',$this->lng->txt('cancel'));
267  $this->tpl->parseCurrentBlock();
268  }
269 
270  $mailtable = new ilMailFolderTableGUI($this, (int)$_GET['mobj_id'], 'showFolder');
271  $mailtable->isSentFolder($isSentFolder)
272  ->isDraftFolder($isDraftFolder)
273  ->isTrashFolder($isTrashFolder)
274  ->setSelectedItems($_POST['mail_id'])
275  ->prepareHTML();
276 
277  // SHOW_FOLDER ONLY IF viewmode is flatview
278  $folders = $this->mbox->getSubFolders();
279  $mtree = new ilTree($ilUser->getId());
280  $mtree->setTableNames('mail_tree', 'mail_obj_data');
281  if(!isset($_SESSION['viewmode']) || $_SESSION['viewmode'] == 'flat')
282  {
283  foreach($folders as $folder)
284  {
285  $this->tpl->setCurrentBLock('flat_select');
286  $folder_d = $mtree->getNodeData($folder['obj_id']);
287  if($folder['obj_id'] == $_GET['mobj_id'])
288  {
289  $this->tpl->setVariable('FLAT_SELECTED', ' selected="selected"');
290  }
291  $this->tpl->setVariable('FLAT_VALUE', $folder['obj_id']);
292  if($folder['type'] == 'user_folder')
293  {
294  $pre = '';
295  for ($i = 2; $i < $folder_d['depth'] - 1; $i++)
296  $pre .= '&nbsp';
297  if ($folder_d['depth'] > 1)
298  $pre .= '+';
299  $this->tpl->setVariable('FLAT_NAME', $pre.' '.$folder['title']);
300  }
301  else
302  {
303  $this->tpl->setVariable('FLAT_NAME', $this->lng->txt('mail_'.$folder['title']));
304  }
305  $this->tpl->parseCurrentBlock();
306  }
307 
308  $this->tpl->setCurrentBlock('show_folder');
309  $this->tpl->setVariable('TXT_FOLDERS', $this->lng->txt('mail_change_to_folder'));
310  //$this->tpl->setVariable('FOLDER_VALUE', $this->lng->txt('submit'));
311  $this->tpl->setVariable('FOLDER_VALUE', $this->lng->txt('change'));
312  $this->tpl->setVariable('ACTION_FLAT', $this->ctrl->getFormAction($this, 'showFolder'));
313  $this->tpl->parseCurrentBlock();
314  }
315  // END SHOW_FOLDER
316 
317  // BEGIN Trash delete confirmation
318  if($mailtable->isTrashFolder() &&
319  $mailtable->getNumerOfMails() > 0)
320  {
321  if($this->askForConfirmation == true)
322  {
323  $this->tpl->setCurrentBlock('CONFIRM_EMPTY_TRASH');
324  $this->tpl->setVariable('ACTION_EMPTY_TRASH_CONFIRMATION', $this->ctrl->getFormAction($this, 'performEmptyTrash'));
325  $this->tpl->setVariable('BUTTON_CONFIRM_EMPTY_TRASH', $this->lng->txt('confirm'));
326  $this->tpl->setVariable('BUTTON_CANCEL_EMPTY_TRASH', $this->lng->txt('cancel'));
327  $this->tpl->parseCurrentBlock();
328  }
329  }
330  // END Trash delete confirmation
331 
332  $this->tpl->setVariable('MAIL_TABLE', $mailtable->getHtml());
333  $this->tpl->show();
334  }
335 
336  public function deleteFolder()
337  {
338  if ($_SESSION["viewmode"] == "tree")
339  {
340  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$_GET["mobj_id"]."&type=confirmdelete_folderdata");
341  }
342  else
343  {
344  ilUtil::sendInfo($this->lng->txt("mail_sure_delete_folder"));
345  $this->enterFolderData("saveFolderSettings", true);
346 
347  return true;
348  }
349  }
350 
351  public function confirmDeleteFolder()
352  {
353  ilUtil::sendInfo($this->lng->txt("mail_sure_delete_folder"));
354  $this->enterFolderData("saveFolderSettings", true);
355 
356  return true;
357  }
358 
359  public function performDeleteFolder()
360  {
361  $new_parent = $this->mbox->getParentFolderId($_GET["mobj_id"]);
362 
363  if ($this->mbox->deleteFolder($_GET["mobj_id"]))
364  {
365  ilUtil::sendInfo($this->lng->txt("mail_folder_deleted"),true);
366  ilUtil::redirect("ilias.php?baseClass=ilMailGUI");
367  }
368  else
369  {
370  if ($_SESSION["viewmode"] == "tree")
371  {
372  ilUtil::sendInfo($this->lng->txt("mail_error_delete"), true);
373  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$_GET["mobj_id"]."&type=confirmdelete_folderdata");
374  }
375  else
376  {
377  ilUtil::sendInfo($this->lng->txt("mail_error_delete"));
378  $this->enterFolderData();
379 
380  return true;
381  }
382  }
383  }
384 
385  public function cancelDeleteFolder()
386  {
387  if ($_SESSION["viewmode"] == "tree")
388  {
389  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$_GET["mobj_id"]."&type=enter_folderdata");
390  }
391  else
392  {
393  $this->enterFolderData();
394  return true;
395  }
396  }
397 
398  public function cancelEnterFolderData()
399  {
400  if ($_SESSION["viewmode"] == "tree")
401  {
402  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$_GET["mobj_id"]."&target=ilmailfoldergui");
403  }
404  else
405  {
406  $this->showFolder();
407  return true;
408  }
409  }
410 
411  public function saveFolderSettings()
412  {
413  if (isset($_POST["folder_name_add"]) && $_SESSION["viewmode"] == "tree") $_SESSION["folder_name_add"] = $_POST['folder_name_add'];
414 
415  $tmp_data = $this->mbox->getFolderData($_GET["mobj_id"]);
416  if ($tmp_data["title"] != $_POST["folder_name_add"])
417  {
418  if ($_POST["folder_name_add"] == "")
419  {
420  if ($_SESSION["viewmode"] == "tree")
421  {
422  ilUtil::sendInfo($this->lng->txt("mail_insert_folder_name"), true);
423  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$_GET["mobj_id"]."&type=enter_folderdata");
424  }
425  else
426  {
427  ilUtil::sendInfo($this->lng->txt("mail_insert_folder_name"));
428  $this->enterFolderData();
429  return true;
430  }
431  }
432  else
433  {
434  if ($this->mbox->renameFolder($_GET["mobj_id"], ilUtil::stripSlashes($_POST["folder_name_add"])))
435  {
436  ilUtil::sendInfo($this->lng->txt("mail_folder_name_changed"), true);
437  unset($_SESSION["folder_name_add"]);
438  }
439  else
440  {
441  if ($_SESSION["viewmode"] == "tree")
442  {
443  ilUtil::sendInfo($this->lng->txt("mail_folder_exists"), true);
444  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$_GET["mobj_id"]."&type=enter_folderdata");
445  }
446  else
447  {
448  ilUtil::sendInfo($this->lng->txt("mail_folder_exists"));
449  $this->enterFolderData();
450  return true;
451  }
452  }
453  }
454  }
455 
456  if ($_SESSION["viewmode"] == "tree")
457  {
458  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$_GET["mobj_id"]."&type=enter_folderdata");
459  }
460  else
461  {
462  $this->enterFolderData();
463  return true;
464  }
465  }
466 
467  public function saveSubFolderSettings()
468  {
469  global $ilCtrl;
470 
471  if (isset($_POST["folder_name_add"]) && $_SESSION["viewmode"] == "tree") $_SESSION["folder_name_add"] = ilUtil::stripSlashes($_POST['folder_name_add']);
472 
473  if (empty($_POST['folder_name_add']))
474  {
475  if ($_SESSION["viewmode"] == "tree")
476  {
477  ilUtil::sendInfo($this->lng->txt("mail_insert_folder_name"), true);
478  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$_GET["mobj_id"]."&type=add_subfolder");
479  }
480  else
481  {
482  ilUtil::sendInfo($this->lng->txt("mail_insert_folder_name"));
483  $this->addSubFolder();
484  return true;
485  }
486  }
487  else if ($_GET["mobj_id"] = $this->mbox->addFolder($_GET["mobj_id"], ilUtil::stripSlashes($_POST["folder_name_add"])))
488  {
489  $ilCtrl->saveParameter($this, 'mobj_id');
490  $ilCtrl->setParameter($this, 'mobj_id', $_GET['mobj_id']);
491 
492  unset($_SESSION["folder_name_add"]);
493 
494  if ($_SESSION["viewmode"] == "tree")
495  {
496  ilUtil::sendInfo($this->lng->txt("mail_folder_created"), true);
497  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$_GET["mobj_id"]);
498  }
499  else
500  {
501  ilUtil::sendInfo($this->lng->txt("mail_folder_created"));
502  $this->enterFolderData();
503  return true;
504  }
505  }
506  else
507  {
508  if ($_SESSION["viewmode"] == "tree")
509  {
510  ilUtil::sendInfo($this->lng->txt("mail_folder_exists"), true);
511  ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$_GET["mobj_id"]."&type=add_subfolder");
512  }
513  else
514  {
515  ilUtil::sendInfo($this->lng->txt("mail_folder_exists"));
516  $this->addSubFolder();
517  return true;
518  }
519  }
520  }
521 
522  function addSubFolder()
523  {
524  $this->enterFolderData("saveSubFolderSettings");
525 
526  return true;
527  }
528 
529  public function enterFolderData($cmd = "saveFolderSettings", $confirmDelete = false)
530  {
531  global $ilUser;
532 
533  $mtree = new ilTree($ilUser->getId());
534  $mtree->setTableNames('mail_tree','mail_obj_data');
535  $folder_node = $mtree->getNodeData($_GET[mobj_id]);
536 
537  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_edit_user_folder.html",'Services/Mail');
538 
539  if ($confirmDelete)
540  {
541  $this->tpl->setCurrentBlock("confirm_delete");
542  $this->ctrl->setParameter($this, "cmd", "post");
543  $this->tpl->setVariable("ACTION_DELETE", $this->ctrl->getFormAction($this));
544  $this->tpl->setVariable("FRAME_DELETE", ilFrameTargetInfo::_getFrame("MainContent"));
545  $this->ctrl->clearParameters($this);
546  $this->tpl->setVariable("TXT_DELETE_CONFIRM",$this->lng->txt("confirm"));
547  $this->tpl->setVariable("TXT_DELETE_CANCEL",$this->lng->txt("cancel"));
548  $this->tpl->parseCurrentBlock();
549  }
550 
551  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
552 
553  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
554  $this->tpl->setVariable("FRAME_ADD", ilFrameTargetInfo::_getFrame("MainContent"));
555 
556  if ($cmd == "saveFolderSettings")
557  {
558  $this->tpl->setVariable("TXT_HEADLINE", $this->lng->txt('mail_folder_edit'));
559  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt('name'));
560  $this->tpl->setVariable("TXT_DELETE", $this->lng->txt('delete'));
561 
562  if (isset($_SESSION["folder_name_add"])) $title_value = ilUtil::prepareFormOutput($_SESSION["folder_name_add"], true);
563  else if (isset($_POST["folder_name_add"])) $title_value = ilUtil::prepareFormOutput($_POST["folder_name_add"], true);
564  else $title_value = ilUtil::stripSlashes($folder_node["title"]);
565  }
566  else
567  {
568  $this->tpl->setVariable("TXT_HEADLINE", $this->lng->txt('mail_add_subfolder'));
569  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt('name'));
570 
571  if (isset($_SESSION["folder_name_add"])) $title_value = ilUtil::prepareFormOutput($_SESSION["folder_name_add"], true);
572  else if (isset($_POST["folder_name_add"])) $title_value = ilUtil::prepareFormOutput($_POST["folder_name_add"], true);
573  }
574 
575  unset($_SESSION["folder_name_add"]);
576 
577  $this->tpl->setVariable("CMD_SUBMIT", $cmd);
578  $this->tpl->setVariable("TXT_SUBMIT", ($cmd == "saveSubFolderSettings" ? $this->lng->txt('save') : $this->lng->txt('rename')));
579  $this->tpl->setVariable("TITLE_VALUE", $title_value);
580  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt('cancel'));
581 
582  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
583  $this->tpl->show();
584 
585  return true;
586  }
587 
588  public function changeFolder()
589  {
590  switch ($this->current_selected_cmd)
591  {
592  default:
593  if(!(int)$_GET["mail_id"] || !(int)$this->current_selected_cmd)
594  {
595  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
596  return $this->showMail();
597  }
598  if ($this->umail->moveMailsToFolder(array($_GET["mail_id"]), $this->current_selected_cmd))
599  {
600  ilUtil::sendInfo($this->lng->txt("mail_moved"), true);
601  $this->ctrl->redirectByClass("ilMailGUI");
602  }
603  else
604  {
605  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
606  }
607  break;
608  }
609 
610  $this->showMail();
611 
612  return true;
613  }
614 
615  public function editFolder()
616  {
617  switch ($this->current_selected_cmd)
618  {
619  case 'markMailsRead':
620  if(is_array($_POST["mail_id"]))
621  {
622  $this->umail->markRead($_POST["mail_id"]);
623  }
624  else
625  {
626  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
627  }
628  break;
629  case 'markMailsUnread':
630  if(is_array($_POST["mail_id"]))
631  {
632  $this->umail->markUnread($_POST["mail_id"]);
633  }
634  else
635  {
636  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
637  }
638  break;
639 
640  case 'deleteMails':
641  // IF MAILBOX IS TRASH ASK TO CONFIRM
642  if($this->mbox->getTrashFolder() == $_GET["mobj_id"])
643  {
644  if(!is_array($_POST["mail_id"]))
645  {
646  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
647  $this->errorDelete = true;
648  }
649  else
650  {
651  ilUtil::sendQuestion($this->lng->txt("mail_sure_delete"));
652  }
653  } // END IF MAILBOX IS TRASH FOLDER
654  else
655  {
656  // MOVE MAILS TO TRASH
657  if(!is_array($_POST["mail_id"]))
658  {
659  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
660  }
661  else if($this->umail->moveMailsToFolder($_POST["mail_id"], $this->mbox->getTrashFolder()))
662  {
663  $_GET["offset"] = 0;
664  ilUtil::sendInfo($this->lng->txt("mail_moved_to_trash"));
665  }
666  else
667  {
668  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
669  }
670  }
671  break;
672 
673  case 'add':
674  $this->ctrl->setParameterByClass("ilmailoptionsgui", "cmd", "add");
675  $this->ctrl->redirectByClass("ilmailoptionsgui");
676 
677  case 'moveMails':
678  default:
679  if(!is_array($_POST["mail_id"]))
680  {
681  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
682  }
683  else if($this->umail->moveMailsToFolder($_POST["mail_id"],$this->current_selected_cmd))
684  {
685  ilUtil::sendInfo($this->lng->txt("mail_moved"));
686  }
687  else
688  {
689  ilUtil::sendInfo($this->lng->txt("mail_move_error"));
690  }
691  break;
692  }
693 
694  $this->showFolder();
695  }
696 
697  public function confirmDeleteMails()
698  {
699  // ONLY IF FOLDER IS TRASH, IT WAS ASKED FOR CONFIRMATION
700  if($this->mbox->getTrashFolder() == $_GET["mobj_id"])
701  {
702  if(!is_array($_POST["mail_id"]))
703  {
704  ilUtil::sendInfo($this->lng->txt("mail_select_one"));
705  }
706  else if($this->umail->deleteMails($_POST["mail_id"]))
707  {
708  $_GET["offset"] = 0;
709  ilUtil::sendInfo($this->lng->txt("mail_deleted"));
710  }
711  else
712  {
713  ilUtil::sendInfo($this->lng->txt("mail_delete_error"));
714  }
715  }
716 
717  $this->showFolder();
718  }
719 
720  public function cancelDeleteMails()
721  {
722  //$this->ctrl->setParameter($this, "offset", $_GET["offset"]);
723  $this->ctrl->redirect($this);
724  }
725 
726  public function showMail()
727  {
728  global $ilUser;
729 
730  if ($_SESSION["mail_id"])
731  {
732  $_GET["mail_id"] = $_SESSION["mail_id"];
733  $_SESSION["mail_id"] = "";
734  }
735 
736  $this->umail->markRead(array($_GET["mail_id"]));
737 
738  $mailData = $this->umail->getMail($_GET["mail_id"]);
739 
740  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_read.html", "Services/Mail");
741  $this->tpl->setVariable("HEADER",$this->lng->txt("mail_mails_of"));
742 
743  if ($_SESSION["viewmode"] == "tree") $this->tpl->setVariable("FORM_TARGET", ilFrameTargetInfo::_getFrame("MainContent"));
744 
745  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
746 
747  // buttons...
748  // reply
749  include_once("./Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php");
750  $toolbar = new ilToolbarGUI();
751  if($mailData["sender_id"] &&
752  $mailData["sender_id"] != ANONYMOUS_USER_ID)
753  {
754  $this->ctrl->setParameterByClass("ilmailformgui", "mail_id", $_GET["mail_id"]);
755  $this->ctrl->setParameterByClass("ilmailformgui", "type", "reply");
756  $this->ctrl->clearParametersByClass("iliasmailformgui");
757 
758  $toolbar->addButton($this->lng->txt("reply"), $this->ctrl->getLinkTargetByClass("ilmailformgui"),
759  "", ilAccessKey::REPLY);
760  }
761 
762  // forward
763  $this->ctrl->setParameterByClass("ilmailformgui", "mail_id", $_GET["mail_id"]);
764  $this->ctrl->setParameterByClass("ilmailformgui", "type", "forward");
765  $this->ctrl->clearParametersByClass("iliasmailformgui");
766  $toolbar->addButton($this->lng->txt("forward"), $this->ctrl->getLinkTargetByClass("ilmailformgui"),
768 
769  // print
770  $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
771  $this->ctrl->setParameter($this, "cmd", "printMail");
772  $toolbar->addButton($this->lng->txt("print"), $this->ctrl->getLinkTarget($this),
773  "_blank");
774  $this->ctrl->clearParameters($this);
775 
776  // delete
777  $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
778  $this->ctrl->setParameter($this, "selected_cmd", "deleteMails");
779  $toolbar->addButton($this->lng->txt("delete"), $this->ctrl->getLinkTarget($this),
780  "", ilAccessKey::DELETE);
781  $this->ctrl->clearParameters($this);
782 
783  $this->tpl->setVariable("BUTTONS2",$toolbar->getHTML());
784 
785  $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
786  $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this));
787  $this->ctrl->clearParameters($this);
788 
789  if ($mailData["sender_id"] &&
790  $mailData["sender_id"] != $ilUser->getId() &&
791  $mailData["sender_id"] != ANONYMOUS_USER_ID)
792  {
793  require_once "Services/Contact/classes/class.ilAddressbook.php";
794  $abook = new ilAddressbook($ilUser->getId());
795  $tmp_user = new ilObjUser($mailData["sender_id"]);
796  if ($abook->checkEntryByLogin($tmp_user->getLogin()) == 0)
797  {
798  $tplbtn = new ilTemplate("tpl.buttons.html", true, true);
799 
800  $tplbtn->setCurrentBlock("btn_cell");
801  $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
802  $this->ctrl->setParameter($this, "cmd", "add");
803  $tplbtn->setVariable("BTN_LINK", $this->ctrl->getLinkTarget($this));
804  $this->ctrl->clearParameters($this);
805  $tplbtn->setVariable("BTN_TXT", $this->lng->txt("mail_add_to_addressbook"));
806  $tplbtn->parseCurrentBlock();
807 
808  $this->tpl->setVariable("ADD_USER_BTN",$tplbtn->get());
809  }
810  }
811 
812  // SET MAIL DATA
813  $counter = 1;
814 
815  // FROM
816  if($mailData["sender_id"] != ANONYMOUS_USER_ID)
817  {
818  $tmp_user = new ilObjUser($mailData['sender_id']);
819  $this->ctrl->setParameter($this, 'mail_id', $_GET['mail_id']);
820  $this->ctrl->setParameter($this, 'user', $tmp_user->getId());
821  if (in_array(ilObjUser::_lookupPref($mailData['sender_id'], 'public_profile'), array("y", "g")))
822  {
823  $this->tpl->setVariable('PROFILE_LINK_FROM', $this->ctrl->getLinkTarget($this, 'showUser'));
824  $this->tpl->setVariable('FROM', $tmp_user->getFullname());
825  }
826  $this->tpl->setCurrentBlock("pers_image");
827  $this->tpl->setVariable("IMG_SENDER", $tmp_user->getPersonalPicturePath("xsmall"));
828  $this->tpl->setVariable("ALT_SENDER", $tmp_user->getFullname());
829  $this->tpl->parseCurrentBlock();
830  $this->tpl->setCurrentBlock("adm_content");
831  if(!($login = $tmp_user->getLogin()))
832  {
833  $login = $mailData["import_name"]." (".$this->lng->txt("user_deleted").")";
834  }
835  $this->tpl->setVariable("MAIL_LOGIN",$login);
836  $this->tpl->setVariable("CSSROW_FROM", (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
837  }
838  else
839  {
840  $tmp_user = new ilObjUser(ANONYMOUS_USER_ID);
841  $this->tpl->setVariable('MAIL_LOGIN', ilMail::_getIliasMailerName());
842  $this->tpl->setCurrentBlock('pers_image');
843  $this->tpl->setVariable('IMG_SENDER', ilUtil::getImagePath('HeaderIcon.png'));
844  $this->tpl->setVariable('ALT_SENDER', ilMail::_getIliasMailerName());
845  $this->tpl->parseCurrentBlock();
846  }
847 
848  $this->tpl->setVariable('TXT_FROM', $this->lng->txt('from'));
849 
850  // TO
851  $this->tpl->setVariable('TXT_TO', $this->lng->txt('mail_to'));
852  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
853  $this->tpl->setVariable('TO', ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_to']), false));
854  $this->tpl->setVariable('CSSROW_TO', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
855 
856  // CC
857  if($mailData['rcp_cc'])
858  {
859  $this->tpl->setCurrentBlock('cc');
860  $this->tpl->setVariable('TXT_CC',$this->lng->txt('cc'));
861  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
862  $this->tpl->setVariable('CC', ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_cc']), false));
863  $this->tpl->setVariable('CSSROW_CC', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
864  $this->tpl->parseCurrentBlock();
865  }
866 
867  // BCC
868  if($mailData['rcp_bcc'])
869  {
870  $this->tpl->setCurrentBlock('bcc');
871  $this->tpl->setVariable('TXT_BCC',$this->lng->txt('bc'));
872  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
873  $this->tpl->setVariable('BCC', ilUtil::htmlencodePlainString($this->umail->formatNamesForOutput($mailData['rcp_bcc']), false));
874  $this->tpl->setVariable('CSSROW_BCC', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
875  $this->tpl->parseCurrentBlock();
876  }
877 
878  // SUBJECT
879  $this->tpl->setVariable('TXT_SUBJECT', $this->lng->txt('subject'));
880  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
881  $this->tpl->setVariable('SUBJECT', ilUtil::htmlencodePlainString($mailData['m_subject'], true));
882  $this->tpl->setVariable('CSSROW_SUBJ', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
883 
884  // DATE
885  $this->tpl->setVariable('TXT_DATE', $this->lng->txt('date'));
886  $this->tpl->setVariable('DATE',ilDatePresentation::formatDate(new ilDateTime($mailData['send_time'],IL_CAL_DATETIME)));
887  $this->tpl->setVariable('CSSROW_DATE', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
888 
889  // ATTACHMENTS
890  if($mailData['attachments'])
891  {
892  $this->tpl->setCurrentBlock('attachment');
893  $this->tpl->setCurrentBlock('a_row');
894  $counter = 1;
895  foreach($mailData['attachments'] as $file)
896  {
897  $this->tpl->setVariable('A_CSSROW', (++$counter) % 2 ? 'tblrow1' : 'tblrow2');
898  $this->tpl->setVariable('FILE', md5($file));
899  $this->tpl->setVariable('FILE_NAME', $file);
900  $this->tpl->parseCurrentBlock();
901  }
902  $this->tpl->setVariable('TXT_ATTACHMENT', $this->lng->txt('attachments'));
903  $this->tpl->setVariable('TXT_DOWNLOAD', $this->lng->txt('download'));
904  $this->tpl->parseCurrentBlock();
905  }
906 
907  // MESSAGE
908  $this->tpl->setVariable('TXT_MESSAGE', $this->lng->txt('message'));
909 
910  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
911  $this->tpl->setVariable('MAIL_MESSAGE', ilUtil::htmlencodePlainString($mailData['m_message'], true));
912 
913  $isTrashFolder = false;
914  if ($this->mbox->getTrashFolder() == $_GET['mobj_id'])
915  {
916  $isTrashFolder = true;
917  }
918 
919  // Bottom toolbar
920  $oBottomToolbar = new ilToolbarGUI();
921 
922  $selectOptions = array();
923  $actions = $this->mbox->getActions($_GET["mobj_id"]);
924  foreach($actions as $key => $action)
925  {
926  if($key == 'moveMails')
927  {
928  $folders = $this->mbox->getSubFolders();
929  foreach($folders as $folder)
930  {
931  if ($folder["type"] != 'trash' ||
932  !$isTrashFolder)
933  {
934  $optionText = '';
935  if($folder['type'] != 'user_folder')
936  {
937  $optionText = $action.' '.$this->lng->txt('mail_'.$folder['title']).($folder['type'] == 'trash' ? ' ('.$this->lng->txt('delete').')' : '');
938  }
939  else
940  {
941  $optionText = $action.' '.$folder['title'];
942  }
943 
944  $selectOptions[$folder['obj_id']] = $optionText;
945  }
946  }
947  }
948  }
949  if(is_array($selectOptions) && count($selectOptions))
950  {
951  include_once 'Services/Form/classes/class.ilSelectInputGUI.php';
952  $oActionSelectBox = new ilSelectInputGUI('', 'selected_cmd');
953  $oActionSelectBox->setOptions($selectOptions);
954  $oBottomToolbar->addInputItem($oActionSelectBox);
955  $oBottomToolbar->addFormButton($this->lng->txt('submit'), 'changeFolder');
956  }
957 
958  // Navigation
959  $prevMail = $this->umail->getPreviousMail($_GET['mail_id']);
960  $nextMail = $this->umail->getNextMail($_GET['mail_id']);
961  if(is_array($prevMail) || is_array($nextMail))
962  {
963  $oBottomToolbar->addSeparator();
964 
965  if($prevMail['mail_id'])
966  {
967  $this->ctrl->setParameter($this, 'mail_id', $prevMail['mail_id']);
968  $this->ctrl->setParameter($this, 'cmd', 'showMail');
969  $oBottomToolbar->addButton($this->lng->txt('previous'), $this->ctrl->getLinkTarget($this));
970  $this->ctrl->clearParameters($this);
971  }
972 
973  if($nextMail['mail_id'])
974  {
975  $this->ctrl->setParameter($this, 'mail_id', $nextMail['mail_id']);
976  $this->ctrl->setParameter($this, 'cmd', 'showMail');
977  $oBottomToolbar->addButton($this->lng->txt('next'), $this->ctrl->getLinkTarget($this));
978  $this->ctrl->clearParameters($this);
979  }
980  }
981 
982  $this->tpl->setVariable('MAIL_NAVIGATION', $oBottomToolbar->getHTML());
983  $this->tpl->show();
984  }
985 
986  public function printMail()
987  {
988  $tplprint = new ilTemplate("Services/Mail/templates/default/tpl.mail_print.html",true,true,true);
989  $tplprint->setVariable("JSPATH",$tpl->tplPath);
990 
991  //get the mail from user
992  $mailData = $this->umail->getMail($_GET["mail_id"]);
993 
994  // SET MAIL DATA
995  // FROM
996  if($mailData["sender_id"] != ANONYMOUS_USER_ID)
997  {
998  $tmp_user = new ilObjUser($mailData["sender_id"]);
999  if(!($login = $tmp_user->getFullname()))
1000  {
1001  $login = $mailData["import_name"]." (".$this->lng->txt("user_deleted").")";
1002  }
1003  $tplprint->setVariable("FROM", $login);
1004  }
1005  else
1006  {
1007  $tplprint->setVariable('FROM', ilMail::_getIliasMailerName());
1008  }
1009 
1010  $tplprint->setVariable('TXT_FROM', $this->lng->txt('from'));
1011 
1012  // TO
1013  $tplprint->setVariable("TXT_TO", $this->lng->txt("mail_to"));
1014  $tplprint->setVariable("TO", $mailData["rcp_to"]);
1015 
1016  // CC
1017  if($mailData["rcp_cc"])
1018  {
1019  $tplprint->setCurrentBlock("cc");
1020  $tplprint->setVariable("TXT_CC",$this->lng->txt("cc"));
1021  $tplprint->setVariable("CC",$mailData["rcp_cc"]);
1022  $tplprint->parseCurrentBlock();
1023  }
1024  // SUBJECT
1025  $tplprint->setVariable("TXT_SUBJECT",$this->lng->txt("subject"));
1026  $tplprint->setVariable("SUBJECT",htmlspecialchars($mailData["m_subject"]));
1027 
1028  // DATE
1029  $tplprint->setVariable("TXT_DATE", $this->lng->txt("date"));
1030  $tplprint->setVariable("DATE", ilDatePresentation::formatDate(new ilDateTime($mailData["send_time"],IL_CAL_DATETIME)));
1031 
1032 
1033  // MESSAGE
1034  $tplprint->setVariable("TXT_MESSAGE", $this->lng->txt("message"));
1035  $tplprint->setVariable("MAIL_MESSAGE", nl2br(htmlspecialchars($mailData["m_message"])));
1036 
1037 
1038  $tplprint->show();
1039  }
1040 
1041  function deliverFile()
1042  {
1043  if ($_SESSION["mail_id"])
1044  {
1045  $_GET["mail_id"] = $_SESSION["mail_id"];
1046  }
1047  $_SESSION["mail_id"] = "";
1048 
1049  $filename = ($_SESSION["filename"]
1050  ? $_SESSION["filename"]
1051  : ($_POST["filename"]
1052  ? $_POST["filename"]
1053  : $_GET["filename"]));
1054  $_SESSION["filename"] = "";
1055 
1056  if ($filename != "")
1057  {
1058  require_once "classes/class.ilFileDataMail.php";
1059 
1060  // secure filename
1061  $filename = str_replace("..", "", $filename);
1062 
1063  $mfile = new ilFileDataMail($_SESSION["AccountId"]);
1064  if(!is_array($file = $mfile->getAttachmentPathByMD5Filename($filename, $_GET['mail_id'])))
1065  {
1066  ilUtil::sendInfo($this->lng->txt('mail_error_reading_attachment'));
1067  $this->showMail();
1068  }
1069  else
1070  {
1071  ilUtil::deliverFile($file['path'], $file['filename']);
1072  }
1073  }
1074  else
1075  {
1076  ilUtil::sendInfo($this->lng->txt('mail_select_attachment'));
1077  $this->showMail();
1078  }
1079  }
1080 
1081 }
1082 ?>