ILIAS  Release_3_10_x_branch Revision 61812
 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($_SESSION["AccountId"]);
139  $mbox = new ilMailBox($_SESSION["AccountId"]);
140  $inbox = $mbox->getInboxFolder();
141 
142  //SHOW MAILS FOR EVERY USER
143  $mail_data = $umail->getMailsOfFolder($inbox);
144  $mail_counter = $umail->getMailCounterData();
145  $unreadmails = 0;
146 
147  $this->mails = array();
148  foreach ($mail_data as $mail)
149  {
150  //ONLY NEW MAILS WOULD BE ON THE PERSONAL DESKTOP
151  if($mail["m_status"] == 'unread' &&
152  in_array('normal',$mail['m_type']))
153  {
154  $this->mails[] = $mail;
155  }
156  }
157  }
158 
162  function fillDataSection()
163  {
164  $this->getMails();
165  $this->setData($this->mails);
166 
167  if ($this->getCurrentDetailLevel() > 1 && count($this->mails) > 0)
168  {
169  $this->setRowTemplate("tpl.pd_mail_row.html", "Services/Mail");
170  if ($this->getCurrentDetailLevel() > 2)
171  {
172  $this->setColSpan(2);
173  }
175  }
176  else
177  {
178  $this->setEnableNumInfo(false);
179  if (count($this->mails) == 0)
180  {
181  $this->setEnableDetailRow(false);
182  }
183  $this->setDataSection($this->getOverview());
184  }
185  }
186 
190  function fillRow($mail)
191  {
192  global $ilUser, $ilCtrl, $lng;
193 
194  // GET SENDER NAME
195  $user = new ilObjUser($mail["sender_id"]);
196  if ($this->getCurrentDetailLevel() > 2)
197  {
198  $this->tpl->setCurrentBlock("image");
199  $this->tpl->setVariable("IMG_SENDER", $user->getPersonalPicturePath("xxsmall"));
200  $this->tpl->setVariable("ALT_SENDER", $user->getLogin());
201  $this->tpl->parseCurrentBlock();
202  $this->tpl->setCurrentBlock("long");
203  if($mail['sender_id'] != ANONYMOUS_USER_ID)
204  {
205  if(ilObjUser::_lookupPref($mail['sender_id'], 'public_profile') == 'y')
206  {
207  if(!($fullname = $user->getFullname()))
208  {
209  $fullname = $lng->txt("unknown");
210  }
211  $this->tpl->setVariable("NEW_MAIL_FROM", $fullname);
212  }
213  $this->tpl->setVariable("NEW_MAIL_FROM_LOGIN", $user->getLogin());
214  }
215  else
216  {
217  $this->tpl->setVariable('NEW_MAIL_FROM_LOGIN', ilMail::_getAnonymousName());
218  }
219  $this->tpl->setVariable('NEW_MAIL_DATE', ilDatePresentation::formatDate(new ilDate($mail['send_time'],IL_CAL_DATE)));
220  $this->tpl->setVariable("TXT_FROM", $lng->txt("from"));
221  $this->tpl->parseCurrentBlock();
222  }
223  else
224  {
225  if($mail['sender_id'] != ANONYMOUS_USER_ID)
226  {
227  $this->tpl->setCurrentBlock('short');
228  $this->tpl->setVariable('NEW_MAIL_FROM_LOGIN', $user->getLogin());
229  $this->tpl->parseCurrentBlock();
230  }
231  else
232  {
233  $this->tpl->setCurrentBlock('short');
234  $this->tpl->setVariable('NEW_MAIL_FROM_LOGIN', ilMail::_getAnonymousName());
235  $this->tpl->parseCurrentBlock();
236  }
237  }
238 
239  $this->tpl->setVariable("NEW_MAIL_SUBJ", htmlentities($mail["m_subject"],ENT_NOQUOTES,'UTF-8'));
240  $ilCtrl->setParameter($this, "mobj_id", $inbox);
241  $ilCtrl->setParameter($this, "mail_id", $mail["mail_id"]);
242  $ilCtrl->setParameter($this, "mail_mode", $this->mail_mode);
243  $this->tpl->setVariable("NEW_MAIL_LINK_READ",
244  $ilCtrl->getLinkTarget($this, "showMail"));
245  $ilCtrl->clearParameters($this);
246  }
247 
251  function getOverview()
252  {
253  global $ilUser, $lng, $ilCtrl;
254 
255  return '<div class="small">'.((int) count($this->mails))." ".$lng->txt("mails_pl")."</div>";
256  }
257 
261  function showMail()
262  {
263  global $lng, $ilCtrl;
264 
265  include_once("./Services/Mail/classes/class.ilPDMailGUI.php");
266  $mail_gui = new ilPDMailGUI();
267 
268  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
269  $content_block = new ilPDContentBlockGUI();
270  $content_block->setContent($mail_gui->getPDMailHTML($_GET["mail_id"],
271  $_GET["mobj_id"]));
272  $content_block->setTitle($lng->txt("message"));
273  $content_block->setColSpan(2);
274  $content_block->setImage(ilUtil::getImagePath("icon_mail.gif"));
275  $content_block->addHeaderCommand($ilCtrl->getLinkTargetByClass("ilpersonaldesktopgui", "show"),
276  $lng->txt("selected_items_back"));
277 
278  if ($_GET["mail_mode"] != "system")
279  {
280  $content_block->addBlockCommand("ilias.php?baseClass=ilMailGUI&mail_id=".
281  $_GET["mail_id"]."&mobj_id".$_GET["mobj_id"]."&type=reply",
282  $lng->txt("reply"));
283  $content_block->addBlockCommand("ilias.php?baseClass=ilMailGUI&mail_id=".
284  $_GET["mail_id"]."&mobj_id".$_GET["mobj_id"]."&type=read",
285  $lng->txt("inbox"));
286 
287  $ilCtrl->setParameter($this, 'mail_id', (int) $_GET['mail_id']);
288  $content_block->addBlockCommand($ilCtrl->getLinkTarget($this, 'deleteMail'), $lng->txt('delete'));
289 
290 
291  }
292  else
293  {
294  $ilCtrl->setParameter($this, "mail_id", $_GET["mail_id"]);
295  $ilCtrl->setParameter($this, "mobj_id", $_GET["mobj_id"]);
296  $content_block->addBlockCommand(
297  $ilCtrl->getLinkTarget($this, "deleteMail"),
298  $lng->txt("delete"));
299  $ilCtrl->clearParameters($this);
300  }
301 
302  return $content_block->getHTML();
303  }
304 
308  function deleteMail()
309  {
310  global $lng, $ilCtrl;
311 
312  $lng->loadLanguageModule('mail');
313 
314  $umail = new ilMail($_SESSION['AccountId']);
315  $mbox = new ilMailBox($_SESSION['AccountId']);
316 
317  // IF THERE IS NO OBJ_ID GIVEN GET THE ID OF MAIL ROOT NODE
318  if(!$_GET['mobj_id'])
319  {
320  $_GET['mobj_id'] = $mbox->getInboxFolder();
321  }
322 
323  if ($umail->moveMailsToFolder(array($_GET['mail_id']),
324  $mbox->getTrashFolder()))
325  {
326  ilUtil::sendInfo($lng->txt('mail_moved_to_trash'), true);
327  }
328  else
329  {
330  ilUtil::sendInfo($lng->txt('mail_move_error'), true);
331  }
332  $ilCtrl->redirectByClass('ilpersonaldesktopgui', 'show');
333  }
334 }
335 ?>