ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
4include_once 'Services/Block/classes/class.ilBlockGUI.php';
5include_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
28 parent::__construct();
29
30 $this->setLimit(5);
31 $this->setImage(ilUtil::getImagePath('icon_mail.svg'));
32 $this->setTitle($lng->txt('mail'));
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, $ilSetting;
110
111 require_once 'Services/Mail/classes/class.ilObjMail.php';
112
113 $umail = new ilMail($ilUser->getId());
114 $mbox = new ilMailBox($ilUser->getId());
115 $this->inbox = $mbox->getInboxFolder();
116
117 $this->mails = $umail->getMailsOfFolder(
118 $this->inbox,
119 array(
120 'status' => 'unread',
121 'type' => ((int)$ilSetting->get('pd_sys_msg_mode')) != ilObjMail::PD_SYS_MSG_MAIL_BLOCK ? 'normal' : ''
122 )
123 );
124 }
125
129 public function fillDataSection()
130 {
131 $this->getMails();
132 $this->setData($this->mails);
133
134 if($this->getCurrentDetailLevel() > 1 && count($this->mails) > 0)
135 {
136 $this->setRowTemplate("tpl.pd_mail_row.html", "Services/Mail");
137 if($this->getCurrentDetailLevel() > 2)
138 {
139 $this->setColSpan(2);
140 }
141 parent::fillDataSection();
142 }
143 else
144 {
145 $this->setEnableNumInfo(false);
146 if(count($this->mails) == 0)
147 {
148 $this->setEnableDetailRow(false);
149 }
150 $this->setDataSection($this->getOverview());
151 }
152 }
153
157 public function fillRow($mail)
158 {
159 global $ilCtrl, $lng;
160
161 $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
162
163 if($this->getCurrentDetailLevel() > 2)
164 {
165 $this->tpl->touchBlock('usr_image_space');
166 if($user && $user->getId() != ANONYMOUS_USER_ID)
167 {
168 $this->tpl->setVariable('PUBLIC_NAME_LONG', $user->getPublicName());
169 $this->tpl->setVariable('IMG_SENDER', $user->getPersonalPicturePath('xxsmall'));
170 $this->tpl->setVariable('ALT_SENDER', htmlspecialchars($user->getPublicName()));
171 }
172 else if(!$user)
173 {
174 $this->tpl->setVariable('PUBLIC_NAME_LONG', $mail['import_name'] . ' (' . $lng->txt('user_deleted') . ')');
175
176 $this->tpl->setCurrentBlock('image_container');
177 $this->tpl->touchBlock('image_container');
178 $this->tpl->parseCurrentBlock();
179 }
180 else
181 {
182 $this->tpl->setVariable('PUBLIC_NAME_LONG', ilMail::_getIliasMailerName());
183 $this->tpl->setVariable('IMG_SENDER', ilUtil::getImagePath('HeaderIconAvatar.svg'));
184 $this->tpl->setVariable('ALT_SENDER', htmlspecialchars(ilMail::_getIliasMailerName()));
185 }
186
187 $this->tpl->setVariable('NEW_MAIL_DATE', ilDatePresentation::formatDate(new ilDate($mail['send_time'], IL_CAL_DATE)));
188 }
189 else
190 {
191 if($user && $user->getId() != ANONYMOUS_USER_ID)
192 {
193 $this->tpl->setVariable('PUBLIC_NAME_SHORT', $user->getPublicName());
194 }
195 else if(!$user)
196 {
197 $this->tpl->setVariable('PUBLIC_NAME_SHORT', $mail['import_name'] . ' (' . $lng->txt('user_deleted') . ')');
198 }
199 else
200 {
201 $this->tpl->setVariable('PUBLIC_NAME_SHORT', ilMail::_getIliasMailerName());
202 }
203 }
204
205 $this->tpl->setVariable('NEW_MAIL_SUBJ', htmlentities($mail['m_subject'], ENT_NOQUOTES, 'UTF-8'));
206 $ilCtrl->setParameter($this, 'mobj_id', $this->inbox);
207 $ilCtrl->setParameter($this, 'mail_id', $mail['mail_id']);
208 $ilCtrl->setParameter($this, 'mail_mode', $this->mail_mode);
209 $this->tpl->setVariable('NEW_MAIL_LINK_READ', $ilCtrl->getLinkTarget($this, 'showMail'));
210 $ilCtrl->clearParameters($this);
211 }
212
216 protected function getOverview()
217 {
218 global $lng;
219
220 return '<div class="small">' . ((int)count($this->mails)) . " " . $lng->txt("mails_pl") . "</div>";
221 }
222
226 protected function showMail()
227 {
228 global $lng, $ilCtrl;
229
230 include_once("./Services/Mail/classes/class.ilPDMailGUI.php");
231 $mail_gui = new ilPDMailGUI();
232
233 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
234 $content_block = new ilPDContentBlockGUI();
235 $content_block->setContent($mail_gui->getPDMailHTML($_GET["mail_id"],
236 $_GET["mobj_id"]));
237 $content_block->setTitle($lng->txt("message"));
238 $content_block->setColSpan(2);
239 $content_block->setImage(ilUtil::getImagePath("icon_mail.svg"));
240 $content_block->addHeaderCommand($ilCtrl->getLinkTargetByClass("ilpersonaldesktopgui", "show"),
241 $lng->txt("selected_items_back"));
242
243 if($_GET["mail_mode"] != "system")
244 {
245 $content_block->addBlockCommand("ilias.php?baseClass=ilMailGUI&mail_id=" .
246 $_GET["mail_id"] . "&mobj_id=" . $_GET["mobj_id"] . "&type=reply",
247 $lng->txt("reply"));
248 $content_block->addBlockCommand("ilias.php?baseClass=ilMailGUI&mail_id=" .
249 $_GET["mail_id"] . "&mobj_id=" . $_GET["mobj_id"] . "&type=read",
250 $lng->txt("inbox"));
251
252 $ilCtrl->setParameter($this, 'mail_id', (int)$_GET['mail_id']);
253 $content_block->addBlockCommand($ilCtrl->getLinkTarget($this, 'deleteMail'), $lng->txt('delete'));
254
255
256 }
257 else
258 {
259 $ilCtrl->setParameter($this, "mail_id", $_GET["mail_id"]);
260 $ilCtrl->setParameter($this, "mobj_id", $_GET["mobj_id"]);
261 $content_block->addBlockCommand(
262 $ilCtrl->getLinkTarget($this, "deleteMail"),
263 $lng->txt("delete"));
264 $ilCtrl->clearParameters($this);
265 }
266
267 return $content_block->getHTML();
268 }
269
273 public function deleteMail()
274 {
275 global $lng, $ilCtrl;
276
277 $lng->loadLanguageModule('mail');
278
279 $umail = new ilMail($GLOBALS['DIC']['ilUser']->getId());
280 $mbox = new ilMailBox($GLOBALS['DIC']['ilUser']->getId());
281
282 if(!$_GET['mobj_id'])
283 {
284 $_GET['mobj_id'] = $mbox->getInboxFolder();
285 }
286
287 if($umail->moveMailsToFolder(array($_GET['mail_id']),
288 $mbox->getTrashFolder())
289 )
290 {
291 ilUtil::sendInfo($lng->txt('mail_moved_to_trash'), true);
292 }
293 else
294 {
295 ilUtil::sendInfo($lng->txt('mail_move_error'), true);
296 }
297 $ilCtrl->redirectByClass('ilpersonaldesktopgui', 'show');
298 }
299
303 protected function preloadData(array $data)
304 {
305 $usr_ids = array();
306
307 foreach($data as $mail)
308 {
309 if($mail['sender_id'] && $mail['sender_id'] != ANONYMOUS_USER_ID)
310 {
311 $usr_ids[$mail['sender_id']] = $mail['sender_id'];
312 }
313 }
314
315 ilMailUserCache::preloadUserObjects($usr_ids);
316 }
317}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_SCREEN_SIDE
const IL_SCREEN_CENTER
const IL_CAL_DATE
This class represents a block method of a block.
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
setLimit($a_limit)
Set Limit.
setImage($a_image)
Set Image.
getCurrentDetailLevel()
Get Current Detail Level.
setAvailableDetailLevels($a_max, $a_min=0)
Set Available Detail Levels.
setEnableDetailRow($a_enabledetailrow)
Set EnableDetailRow.
setData($a_data)
Set Data.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
setColSpan($a_colspan)
Set Columns Span.
setTitle($a_title)
Set Title.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
static formatDate(ilDateTime $date)
Format a date @access public.
Class for single dates.
static getUserObjectById($usr_id)
This class handles base functions for mail handling.
const PD_SYS_MSG_MAIL_BLOCK
BlockGUI class for (centered) Content on Personal Desktop.
BlockGUI class for Personal Desktop Mail block.
static getBlockType()
Get block type.
fillDataSection()
Fill data section.
fillRow($mail)
get flat bookmark list for personal desktop
static getScreenMode()
Get Screen Mode for current command.
executeCommand()
execute command
getHTML()
Handle config status.
static isRepositoryObject()
Get block type.
Mail User Interface class.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$html
Definition: example_001.php:87
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
global $ilSetting
Definition: privfeed.php:17
$cmd
Definition: sahs_server.php:35
$ilUser
Definition: imgupload.php:18