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