ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPDMailBlockGUI.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 include_once 'Services/Block/classes/class.ilBlockGUI.php';
5 include_once 'Services/Mail/classes/class.ilMailUserCache.php';
6 
14 {
15  static $block_type = 'pdmail';
16 
20  public function __construct()
21  {
22  global $lng;
23 
24  include_once 'Services/User/classes/class.ilObjUser.php';
25  include_once 'Services/Mail/classes/class.ilMailbox.php';
26  include_once 'Services/Mail/classes/class.ilMail.php';
27 
29 
30  $this->setLimit(5);
31  $this->setImage(ilUtil::getImagePath('icon_mail_s.png'));
32  $this->setTitle($lng->txt('mail'));
33  $this->setAvailableDetailLevels(3);
34  }
35 
40  static function getBlockType()
41  {
42  return self::$block_type;
43  }
44 
49  static function isRepositoryObject()
50  {
51  return false;
52  }
53 
57  static function getScreenMode()
58  {
59  switch($_GET['cmd'])
60  {
61  case 'showMail':
62  return IL_SCREEN_CENTER;
63  break;
64 
65  default:
66  return IL_SCREEN_SIDE;
67  break;
68  }
69  }
70 
74  public function executeCommand()
75  {
76  global $ilCtrl;
77 
78  $cmd = $ilCtrl->getCmd('getHTML');
79 
80  return $this->$cmd();
81  }
82 
83  public function getHTML()
84  {
85  global $ilUser, $rbacsystem;
86 
87  $umail = new ilMail($ilUser->getId());
88  if(!$rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId()))
89  {
90  return '';
91  }
92 
93  if($this->getCurrentDetailLevel() == 0)
94  {
95  return '';
96  }
97  else
98  {
99  $html = parent::getHTML();
100  return $html;
101  }
102  }
103 
107  protected function getMails()
108  {
109  global $ilUser;
110 
111  $umail = new ilMail($ilUser->getId());
112  $mbox = new ilMailBox($ilUser->getId());
113  $this->inbox = $mbox->getInboxFolder();
114 
115  $this->mails = $umail->getMailsOfFolder(
116  $this->inbox,
117  array(
118  'status' => 'unread',
119  'type' => 'normal'
120  )
121  );
122  }
123 
127  public function fillDataSection()
128  {
129  $this->getMails();
130  $this->setData($this->mails);
131 
132  if($this->getCurrentDetailLevel() > 1 && count($this->mails) > 0)
133  {
134  $this->setRowTemplate("tpl.pd_mail_row.html", "Services/Mail");
135  if($this->getCurrentDetailLevel() > 2)
136  {
137  $this->setColSpan(2);
138  }
140  }
141  else
142  {
143  $this->setEnableNumInfo(false);
144  if(count($this->mails) == 0)
145  {
146  $this->setEnableDetailRow(false);
147  }
148  $this->setDataSection($this->getOverview());
149  }
150  }
151 
155  public function fillRow($mail)
156  {
157  global $ilCtrl, $lng;
158 
159  $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
160 
161  if($this->getCurrentDetailLevel() > 2)
162  {
163  $this->tpl->touchBlock('usr_image_space');
164  if($user && $user->getId() != ANONYMOUS_USER_ID)
165  {
166  $this->tpl->setVariable('PUBLIC_NAME_LONG', $user->getPublicName());
167  $this->tpl->setVariable('IMG_SENDER', $user->getPersonalPicturePath('xxsmall'));
168  $this->tpl->setVariable('ALT_SENDER', $user->getPublicName());
169  }
170  else if(!$user)
171  {
172  $this->tpl->setVariable('PUBLIC_NAME_LONG', $mail['import_name'] . ' (' . $lng->txt('user_deleted') . ')');
173 
174  $this->tpl->setCurrentBlock('image_container');
175  $this->tpl->touchBlock('image_container');
176  $this->tpl->parseCurrentBlock();
177  }
178  else
179  {
180  $this->tpl->setVariable('PUBLIC_NAME_LONG', ilMail::_getIliasMailerName());
181  $this->tpl->setVariable('IMG_SENDER', ilUtil::getImagePath('HeaderIconAvatar.png'));
182  $this->tpl->setVariable('ALT_SENDER', ilMail::_getIliasMailerName());
183  }
184 
185  $this->tpl->setVariable('NEW_MAIL_DATE', ilDatePresentation::formatDate(new ilDate($mail['send_time'], IL_CAL_DATE)));
186  }
187  else
188  {
189  if($user && $user->getId() != ANONYMOUS_USER_ID)
190  {
191  $this->tpl->setVariable('PUBLIC_NAME_SHORT', $user->getPublicName());
192  }
193  else if(!$user)
194  {
195  $this->tpl->setVariable('PUBLIC_NAME_SHORT', $mail['import_name'] . ' (' . $lng->txt('user_deleted') . ')');
196  }
197  else
198  {
199  $this->tpl->setVariable('PUBLIC_NAME_SHORT', ilMail::_getIliasMailerName());
200  }
201  }
202 
203  $this->tpl->setVariable('NEW_MAIL_SUBJ', htmlentities($mail['m_subject'], ENT_NOQUOTES, 'UTF-8'));
204  $ilCtrl->setParameter($this, 'mobj_id', $this->inbox);
205  $ilCtrl->setParameter($this, 'mail_id', $mail['mail_id']);
206  $ilCtrl->setParameter($this, 'mail_mode', $this->mail_mode);
207  $this->tpl->setVariable('NEW_MAIL_LINK_READ', $ilCtrl->getLinkTarget($this, 'showMail'));
208  $ilCtrl->clearParameters($this);
209  }
210 
214  protected function getOverview()
215  {
216  global $lng;
217 
218  return '<div class="small">' . ((int)count($this->mails)) . " " . $lng->txt("mails_pl") . "</div>";
219  }
220 
224  protected function showMail()
225  {
226  global $lng, $ilCtrl;
227 
228  include_once("./Services/Mail/classes/class.ilPDMailGUI.php");
229  $mail_gui = new ilPDMailGUI();
230 
231  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
232  $content_block = new ilPDContentBlockGUI();
233  $content_block->setContent($mail_gui->getPDMailHTML($_GET["mail_id"],
234  $_GET["mobj_id"]));
235  $content_block->setTitle($lng->txt("message"));
236  $content_block->setColSpan(2);
237  $content_block->setImage(ilUtil::getImagePath("icon_mail.png"));
238  $content_block->addHeaderCommand($ilCtrl->getLinkTargetByClass("ilpersonaldesktopgui", "show"),
239  $lng->txt("selected_items_back"));
240 
241  if($_GET["mail_mode"] != "system")
242  {
243  $content_block->addBlockCommand("ilias.php?baseClass=ilMailGUI&mail_id=" .
244  $_GET["mail_id"] . "&mobj_id=" . $_GET["mobj_id"] . "&type=reply",
245  $lng->txt("reply"));
246  $content_block->addBlockCommand("ilias.php?baseClass=ilMailGUI&mail_id=" .
247  $_GET["mail_id"] . "&mobj_id=" . $_GET["mobj_id"] . "&type=read",
248  $lng->txt("inbox"));
249 
250  $ilCtrl->setParameter($this, 'mail_id', (int)$_GET['mail_id']);
251  $content_block->addBlockCommand($ilCtrl->getLinkTarget($this, 'deleteMail'), $lng->txt('delete'));
252 
253 
254  }
255  else
256  {
257  $ilCtrl->setParameter($this, "mail_id", $_GET["mail_id"]);
258  $ilCtrl->setParameter($this, "mobj_id", $_GET["mobj_id"]);
259  $content_block->addBlockCommand(
260  $ilCtrl->getLinkTarget($this, "deleteMail"),
261  $lng->txt("delete"));
262  $ilCtrl->clearParameters($this);
263  }
264 
265  return $content_block->getHTML();
266  }
267 
271  public function deleteMail()
272  {
273  global $lng, $ilCtrl;
274 
275  $lng->loadLanguageModule('mail');
276 
277  $umail = new ilMail($_SESSION['AccountId']);
278  $mbox = new ilMailBox($_SESSION['AccountId']);
279 
280  if(!$_GET['mobj_id'])
281  {
282  $_GET['mobj_id'] = $mbox->getInboxFolder();
283  }
284 
285  if($umail->moveMailsToFolder(array($_GET['mail_id']),
286  $mbox->getTrashFolder())
287  )
288  {
289  ilUtil::sendInfo($lng->txt('mail_moved_to_trash'), true);
290  }
291  else
292  {
293  ilUtil::sendInfo($lng->txt('mail_move_error'), true);
294  }
295  $ilCtrl->redirectByClass('ilpersonaldesktopgui', 'show');
296  }
297 
301  protected function preloadData(array $data)
302  {
303  $usr_ids = array();
304 
305  foreach($data as $mail)
306  {
307  if($mail['sender_id'] && $mail['sender_id'] != ANONYMOUS_USER_ID)
308  {
309  $usr_ids[$mail['sender_id']] = $mail['sender_id'];
310  }
311  }
312 
313  ilMailUserCache::preloadUserObjects($usr_ids);
314  }
315 }