ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailGUI.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/Mail/classes/class.ilMail.php";
25 
34 class ilMailGUI
35 {
36  private $tpl = null;
37  private $ctrl = null;
38  private $lng = null;
39  private $tabs_gui = null;
40 
41  private $umail = null;
42  private $exp = null;
43  private $output = null;
44  private $mtree = null;
45  private $forwardClass = null;
46 
47  public function __construct()
48  {
49  global $tpl, $ilCtrl, $lng, $rbacsystem, $ilErr, $ilUser;
50 
51  $this->tpl = $tpl;
52  $this->ctrl = $ilCtrl;
53  $this->lng = $lng;
54 
55  if(isset($_POST['mobj_id']) && (int)$_POST['mobj_id'])
56  {
57  $_GET['mobj_id'] = $_POST['mobj_id'];
58  }
59 
60  $this->ctrl->saveParameter($this, "mobj_id");
61  $this->lng->loadLanguageModule("mail");
62 
63  $this->umail = new ilMail($ilUser->getId());
64 
65  // CHECK HACK
66  if (!$rbacsystem->checkAccess("mail_visible", $this->umail->getMailObjectReferenceId()))
67  {
68  $ilErr->raiseError($this->lng->txt("permission_denied"), $ilErr->WARNING);
69  }
70  }
71 
72  public function executeCommand()
73  {
74  global $ilUser;
75 
76  // Check for incomplete profile
77  if($ilUser->getProfileIncomplete())
78  {
79  ilUtil::redirect('ilias.php?baseClass=ilPersonalDesktopGUI');
80  }
81 
82  // check whether password of user have to be changed
83  // due to first login or password of user is expired
84  if( $ilUser->isPasswordChangeDemanded() || $ilUser->isPasswordExpired() )
85  {
86  ilUtil::redirect('ilias.php?baseClass=ilPersonalDesktopGUI');
87  }
88 
89  if ($_GET["type"] == "search_res")
90  {
91  $this->ctrl->setParameterByClass("ilmailformgui", "cmd", "searchResults");
92  $this->ctrl->redirectByClass("ilmailformgui");
93  }
94 
95  if ($_GET["type"] == "attach")
96  {
97  $this->ctrl->setParameterByClass("ilmailformgui", "cmd", "mailAttachment");
98  $this->ctrl->redirectByClass("ilmailformgui");
99  }
100 
101  if ($_GET["type"] == "new")
102  {
103  $_SESSION['rcp_to'] = $_GET['rcp_to'];
104 
105  $_SESSION['rcp_cc'] = $_GET['rcp_cc'];
106  $_SESSION['rcp_bcc'] = $_GET['rcp_bcc'];
107 
108  $this->ctrl->setParameterByClass("ilmailformgui", "cmd", "mailUser");
109  $this->ctrl->redirectByClass("ilmailformgui");
110  }
111 
112  if ($_GET["type"] == "reply")
113  {
114  $_SESSION['mail_id'] = $_GET['mail_id'];
115  $this->ctrl->setParameterByClass("ilmailformgui", "cmd", "replyMail");
116  $this->ctrl->redirectByClass("ilmailformgui");
117  }
118 
119  if ($_GET["type"] == "read")
120  {
121  $_SESSION['mail_id'] = $_GET['mail_id'];
122  $this->ctrl->setParameterByClass("ilmailfoldergui", "cmd", "showMail");
123  $this->ctrl->redirectByClass("ilmailfoldergui");
124  }
125 
126  if ($_GET["type"] == "deliverFile")
127  {
128  $_SESSION['mail_id'] = $_GET['mail_id'];
129  $_SESSION['filename'] = ($_POST["filename"] ? $_POST["filename"] : $_GET["filename"]);
130  $this->ctrl->setParameterByClass("ilmailfoldergui", "cmd", "deliverFile");
131  $this->ctrl->redirectByClass("ilmailfoldergui");
132  }
133 
134  if ($_GET["type"] == "message_sent")
135  {
136  ilUtil::sendInfo($this->lng->txt('mail_message_send'), true);
137  $this->ctrl->redirectByClass("ilmailfoldergui");
138  }
139 
140  if ($_GET["type"] == "role")
141  {
142  if (is_array($_POST['roles']))
143  {
144  $_SESSION['mail_roles'] = $_POST['roles'];
145  }
146  else if ($_GET["role"])
147  {
148  $_SESSION['mail_roles'] = array($_GET["role"]);
149  }
150  $this->ctrl->setParameterByClass("ilmailformgui", "cmd", "mailRole");
151  $this->ctrl->redirectByClass("ilmailformgui");
152  }
153 
154  if ($_GET["view"] == "my_courses")
155  {
156  $_SESSION['search_crs'] = $_GET['search_crs'];
157  $this->ctrl->setParameterByClass("ilmailformgui", "cmd", "searchCoursesTo");
158  $this->ctrl->redirectByClass("ilmailformgui");
159  }
160 
161  if (isset($_GET["viewmode"]))
162  {
163  $_SESSION["viewmode"] = $_GET["viewmode"];
164  $this->ctrl->setCmd("setViewMode");
165  }
166 
167  $this->forwardClass = $this->ctrl->getNextClass($this);
168  if ($this->ctrl->getCmd() != "showMenu" && $this->ctrl->getCmd() != "refresh")
169  {
170  $this->showHeader();
171  }
172 
173  switch($this->forwardClass)
174  {
175  case 'ilmailmenugui':
176  include_once 'Services/Mail/classes/class.ilMailMenuGUI.php';
177 
178  $this->ctrl->forwardCommand(new ilMailMenuGUI());
179  break;
180 
181  case 'ilmailformgui':
182  include_once 'Services/Mail/classes/class.ilMailFormGUI.php';
183 
184  $this->ctrl->forwardCommand(new ilMailFormGUI());
185  break;
186 
187  case 'ilmailaddressbookgui':
188  include_once 'Services/Contact/classes/class.ilMailAddressbookGUI.php';
189 
190  $this->ctrl->forwardCommand(new ilMailAddressbookGUI());
191  break;
192 
193  case 'ilmailoptionsgui':
194  include_once 'Services/Mail/classes/class.ilMailOptionsGUI.php';
195 
196  $this->ctrl->forwardCommand(new ilMailOptionsGUI());
197  break;
198 
199  case 'ilmailfoldergui':
200  include_once 'Services/Mail/classes/class.ilMailFolderGUI.php';
201  $this->ctrl->forwardCommand(new ilMailFolderGUI());
202  break;
203 
204  default:
205  if (!($cmd = $this->ctrl->getCmd()))
206  {
207  $cmd = "setViewMode";
208  }
209 
210  $this->$cmd();
211  break;
212 
213  }
214  return true;
215  }
216 
217  private function setViewMode()
218  {
219  if ($_GET["target"] == "")
220  {
221  $_GET["target"] = "ilmailfoldergui";
222  }
223  if ($_SESSION["viewmode"] == "tree")
224  {
225  include_once("Services/Frameset/classes/class.ilFramesetGUI.php");
226  $fs_gui = new ilFramesetGUI();
227  $fs_gui->setFramesetTitle($this->lng->txt("mail"));
228  $fs_gui->setMainFrameName("content");
229  $fs_gui->setSideFrameName("tree");
230 
231  $this->ctrl->setParameter($this, "cmd", "showMenu");
232  $this->ctrl->setParameter($this, "mexpand", 1);
233  $fs_gui->setSideFrameSource($this->ctrl->getLinkTarget($this));
234  $this->ctrl->clearParameters($this);
235 
236  if ($_GET["type"] == "add_subfolder")
237  {
238  $fs_gui->setMainFrameSource($this->ctrl->getLinkTargetByClass($_GET["target"], "addSubFolder"));
239  }
240  else if ($_GET["type"] == "enter_folderdata")
241  {
242  $fs_gui->setMainFrameSource($this->ctrl->getLinkTargetByClass($_GET["target"], "enterFolderData"));
243  }
244  else if ($_GET["type"] == "confirmdelete_folderdata")
245  {
246  $fs_gui->setMainFrameSource($this->ctrl->getLinkTargetByClass($_GET["target"], "confirmDeleteFolder"));
247  }
248  else
249  {
250  $fs_gui->setMainFrameSource($this->ctrl->getLinkTargetByClass($_GET["target"]));
251  }
252  $fs_gui->show();
253  }
254  else
255  {
256 //echo "-".$_GET["target"]."-";
257  $this->ctrl->redirectByClass($_GET["target"]);
258  }
259  }
260 
261  public function refresh()
262  {
263  $this->showMenu();
264  }
265 
266  private function showHeader()
267  {
268  global $ilMainMenu, $ilTabs;
269 
270  $ilMainMenu->setActive("mail");
271 
272  $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
273  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
274  $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_mail_b.gif"));
275 
276  // display infopanel if something happened
278 
279  $ilTabs->addTarget('fold', $this->ctrl->getLinkTargetByClass('ilmailfoldergui'));
280  $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'new');
281  $ilTabs->addTarget('compose', $this->ctrl->getLinkTargetByClass('ilmailformgui'));
282  $this->ctrl->clearParametersByClass('ilmailformgui');
283  $ilTabs->addTarget('mail_addressbook', $this->ctrl->getLinkTargetByClass('ilmailaddressbookgui'));
284  $ilTabs->addTarget('options', $this->ctrl->getLinkTargetByClass('ilmailoptionsgui'));
285 
286  switch($this->forwardClass)
287  {
288  case 'ilmailformgui':
289  $ilTabs->setTabActive('compose');
290  break;
291 
292  case 'ilmailaddressbookgui':
293  $ilTabs->setTabActive('mail_addressbook');
294  break;
295 
296  case 'ilmailoptionsgui':
297  $ilTabs->setTabActive('options');
298  break;
299 
300  case 'ilmailfoldergui':
301  default:
302  $ilTabs->setTabActive('fold');
303  break;
304 
305  }
306  if(isset($_GET['message_sent'])) $ilTabs->setTabActive('fold');
307 
308  // FLATVIEW <-> TREEVIEW
309  if (!isset($_SESSION["viewmode"]) or $_SESSION["viewmode"] == "flat")
310  {
311  $this->ctrl->setParameter($this, "viewmode", "tree");
312  $this->tpl->setTreeFlatIcon(
313  $this->ctrl->getLinkTarget($this),
314  "tree");
315  //$this->tpl->setVariable("IMG_TREE", ilUtil::getImagePath("ic_treeview.gif"));
316  //$this->tpl->parseCurrentBlock();
317  }
318  else
319  {
320  $this->ctrl->setParameter($this, "viewmode", "flat");
321  $this->tpl->setTreeFlatIcon(
322  $this->ctrl->getLinkTarget($this),
323  "flat");
324  //$this->tpl->parseCurrentBlock();
325  }
326  $this->ctrl->clearParameters($this);
327  $this->tpl->setCurrentBlock("tree_icons");
328  $this->tpl->parseCurrentBlock();
329  }
330 
331  private function showMenu()
332  {
333  global $ilUser;
334 
335  require_once "Services/Mail/classes/class.ilMailExplorer.php";
336 
337  $this->tpl->addBlockFile("CONTENT", "content", "tpl.explorer.html");
338  $this->tpl->setVariable("IMG_SPACE", ilUtil::getImagePath("spacer.gif", false));
339 
340  $this->exp = new ilMailExplorer($this->ctrl->getLinkTargetByClass("ilmailfoldergui"),$ilUser->getId());
341  $this->exp->setTargetGet("mobj_id");
342 
343  if ($_GET["mexpand"] == "")
344  {
345  $this->mtree = new ilTree($ilUser->getId());
346  $this->mtree->setTableNames('mail_tree','mail_obj_data');
347  $expanded = $this->mtree->readRootId();
348  }
349  else
350  $expanded = $_GET["mexpand"];
351 
352  $this->exp->setExpand($expanded);
353 
354  //build html-output
355  $this->exp->setOutput(0);
356  $this->output = $this->exp->getOutput();
357 
358  $this->tpl->setCurrentBlock("content");
359  $this->tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("mail_folders"));
360  $this->tpl->setVariable("EXP_REFRESH", $this->lng->txt("refresh"));
361  $this->tpl->setVariable("EXPLORER",$this->output);
362  $this->ctrl->setParameter($this, "mexpand", $_GET["mexpand"]);
363  $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this, 'showMenu'));
364  $this->tpl->parseCurrentBlock();
365 
366  $this->tpl->show(false);
367  }
368 }
369 
370 ?>