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