ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPDMailBlockGUI.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 include_once("Services/Block/classes/class.ilBlockGUI.php");
25 
35 {
36  static $block_type = "pdmail";
37 
41  function ilPDMailBlockGUI()
42  {
43  global $ilCtrl, $lng, $ilUser;
44 
45  #include_once "./include/inc.mail.php";
46  include_once './Services/User/classes/class.ilObjUser.php';
47  include_once "Services/Mail/classes/class.ilMailbox.php";
48  include_once "Services/Mail/classes/class.ilMail.php";
49 
50 
52 
53  $this->setLimit(5);
54  $this->setImage(ilUtil::getImagePath("icon_mail_s.gif"));
55  $this->setTitle($lng->txt("mail"));
56  $this->setAvailableDetailLevels(3);
57  }
58 
64  static function getBlockType()
65  {
66  return self::$block_type;
67  }
68 
74  static function isRepositoryObject()
75  {
76  return false;
77  }
78 
82  static function getScreenMode()
83  {
84  switch($_GET["cmd"])
85  {
86  case "showMail":
87  return IL_SCREEN_CENTER;
88  break;
89 
90  default:
91  return IL_SCREEN_SIDE;
92  break;
93  }
94  }
95 
99  function &executeCommand()
100  {
101  global $ilCtrl;
102 
103  $next_class = $ilCtrl->getNextClass();
104  $cmd = $ilCtrl->getCmd("getHTML");
105 
106  return $this->$cmd();
107  }
108 
109  function getHTML()
110  {
111  global $ilUser, $rbacsystem;
112 
113  $umail = new ilMail($ilUser->getId());
114  if(!$rbacsystem->checkAccess('mail_visible', $umail->getMailObjectReferenceId()))
115  {
116  return '';
117  }
118 
119  if ($this->getCurrentDetailLevel() == 0)
120  {
121  return '';
122  }
123  else
124  {
125  $html = parent::getHTML();
126  return $html;
127  }
128  }
129 
133  function getMails()
134  {
135  global $ilUser;
136 
137  // BEGIN MAILS
138  $umail = new ilMail($ilUser->getId());
139  $mbox = new ilMailBox($ilUser->getId());
140  $inbox = $mbox->getInboxFolder();
141 
142  //SHOW MAILS FOR EVERY USER
143  $this->mails = $umail->getMailsOfFolder($inbox, array('status' => 'unread', 'type' => 'normal'));
144  }
145 
149  function fillDataSection()
150  {
151  $this->getMails();
152  $this->setData($this->mails);
153 
154  if ($this->getCurrentDetailLevel() > 1 && count($this->mails) > 0)
155  {
156  $this->setRowTemplate("tpl.pd_mail_row.html", "Services/Mail");
157  if ($this->getCurrentDetailLevel() > 2)
158  {
159  $this->setColSpan(2);
160  }
162  }
163  else
164  {
165  $this->setEnableNumInfo(false);
166  if (count($this->mails) == 0)
167  {
168  $this->setEnableDetailRow(false);
169  }
170  $this->setDataSection($this->getOverview());
171  }
172  }
173 
183  protected function getUserInstance($a_usr_id)
184  {
185  static $userObjectCache = array();
186 
187  if(isset($userObjectCache[$a_usr_id])) return $userObjectCache[$a_usr_id];
188 
189  $userObjectCache[$a_usr_id] = new ilObjUser($a_usr_id);
190 
191  return $userObjectCache[$a_usr_id];
192  }
193 
197  function fillRow($mail)
198  {
199  global $ilUser, $ilCtrl, $lng;
200 
201  // GET SENDER NAME
202  $user = $this->getUserInstance($mail['sender_id']);
203  if ($this->getCurrentDetailLevel() > 2)
204  {
205  $this->tpl->setCurrentBlock('image');
206  $this->tpl->setVariable('IMG_SENDER', $user->getPersonalPicturePath('xxsmall'));
207  $this->tpl->setVariable('ALT_SENDER', $user->getLogin());
208  $this->tpl->parseCurrentBlock();
209  $this->tpl->setCurrentBlock('long');
210  if($mail['sender_id'] != ANONYMOUS_USER_ID)
211  {
212  if(in_array($user->getPref('public_profile'), array('y', 'g')))
213  {
214  if(!($fullname = $user->getFullname()))
215  {
216  $fullname = $lng->txt('unknown');
217  }
218  $this->tpl->setVariable('NEW_MAIL_FROM', $fullname);
219  }
220  $this->tpl->setVariable('NEW_MAIL_FROM_LOGIN', $user->getLogin());
221  }
222  else
223  {
224  $this->tpl->setVariable('NEW_MAIL_FROM_LOGIN', ilMail::_getIliasMailerName());
225  }
226  $this->tpl->setVariable('NEW_MAIL_DATE', ilDatePresentation::formatDate(new ilDate($mail['send_time'],IL_CAL_DATE)));
227  $this->tpl->setVariable('TXT_FROM', $lng->txt('from'));
228  $this->tpl->parseCurrentBlock();
229  }
230  else
231  {
232  if($mail['sender_id'] != ANONYMOUS_USER_ID)
233  {
234  $this->tpl->setCurrentBlock('short');
235  $this->tpl->setVariable('NEW_MAIL_FROM_LOGIN', $user->getLogin());
236  $this->tpl->parseCurrentBlock();
237  }
238  else
239  {
240  $this->tpl->setCurrentBlock('short');
241  $this->tpl->setVariable('NEW_MAIL_FROM_LOGIN', ilMail::_getIliasMailerName());
242  $this->tpl->parseCurrentBlock();
243  }
244  }
245 
246  $this->tpl->setVariable('NEW_MAIL_SUBJ', htmlentities($mail['m_subject'],ENT_NOQUOTES,'UTF-8'));
247  $ilCtrl->setParameter($this, 'mobj_id', $inbox);
248  $ilCtrl->setParameter($this, 'mail_id', $mail['mail_id']);
249  $ilCtrl->setParameter($this, 'mail_mode', $this->mail_mode);
250  $this->tpl->setVariable('NEW_MAIL_LINK_READ',
251  $ilCtrl->getLinkTarget($this, 'showMail'));
252  $ilCtrl->clearParameters($this);
253  }
254 
258  function getOverview()
259  {
260  global $ilUser, $lng, $ilCtrl;
261 
262  return '<div class="small">'.((int) count($this->mails))." ".$lng->txt("mails_pl")."</div>";
263  }
264 
268  function showMail()
269  {
270  global $lng, $ilCtrl;
271 
272  include_once("./Services/Mail/classes/class.ilPDMailGUI.php");
273  $mail_gui = new ilPDMailGUI();
274 
275  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
276  $content_block = new ilPDContentBlockGUI();
277  $content_block->setContent($mail_gui->getPDMailHTML($_GET["mail_id"],
278  $_GET["mobj_id"]));
279  $content_block->setTitle($lng->txt("message"));
280  $content_block->setColSpan(2);
281  $content_block->setImage(ilUtil::getImagePath("icon_mail.gif"));
282  $content_block->addHeaderCommand($ilCtrl->getLinkTargetByClass("ilpersonaldesktopgui", "show"),
283  $lng->txt("selected_items_back"));
284 
285  if ($_GET["mail_mode"] != "system")
286  {
287  $content_block->addBlockCommand("ilias.php?baseClass=ilMailGUI&mail_id=".
288  $_GET["mail_id"]."&mobj_id".$_GET["mobj_id"]."&type=reply",
289  $lng->txt("reply"));
290  $content_block->addBlockCommand("ilias.php?baseClass=ilMailGUI&mail_id=".
291  $_GET["mail_id"]."&mobj_id".$_GET["mobj_id"]."&type=read",
292  $lng->txt("inbox"));
293 
294  $ilCtrl->setParameter($this, 'mail_id', (int) $_GET['mail_id']);
295  $content_block->addBlockCommand($ilCtrl->getLinkTarget($this, 'deleteMail'), $lng->txt('delete'));
296 
297 
298  }
299  else
300  {
301  $ilCtrl->setParameter($this, "mail_id", $_GET["mail_id"]);
302  $ilCtrl->setParameter($this, "mobj_id", $_GET["mobj_id"]);
303  $content_block->addBlockCommand(
304  $ilCtrl->getLinkTarget($this, "deleteMail"),
305  $lng->txt("delete"));
306  $ilCtrl->clearParameters($this);
307  }
308 
309  return $content_block->getHTML();
310  }
311 
315  function deleteMail()
316  {
317  global $lng, $ilCtrl;
318 
319  $lng->loadLanguageModule('mail');
320 
321  $umail = new ilMail($_SESSION['AccountId']);
322  $mbox = new ilMailBox($_SESSION['AccountId']);
323 
324  // IF THERE IS NO OBJ_ID GIVEN GET THE ID OF MAIL ROOT NODE
325  if(!$_GET['mobj_id'])
326  {
327  $_GET['mobj_id'] = $mbox->getInboxFolder();
328  }
329 
330  if ($umail->moveMailsToFolder(array($_GET['mail_id']),
331  $mbox->getTrashFolder()))
332  {
333  ilUtil::sendInfo($lng->txt('mail_moved_to_trash'), true);
334  }
335  else
336  {
337  ilUtil::sendInfo($lng->txt('mail_move_error'), true);
338  }
339  $ilCtrl->redirectByClass('ilpersonaldesktopgui', 'show');
340  }
341 }
342 ?>