ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 public static $block_type = 'pdmail';
16
20 protected $lng;
21
25 protected $user;
26
30 protected $ctrl;
31
35 protected $rbacsystem;
36
40 protected $setting;
41
45 protected $mails = array();
46
50 protected $inbox;
51
55 public function __construct()
56 {
57 global $DIC;
58
59 $this->lng = $DIC->language();
60 $this->user = $DIC->user();
61 $this->ctrl = $DIC->ctrl();
62 $this->setting = $DIC->settings();
63 $this->rbacsystem = $DIC->rbac()->system();
64
65 include_once 'Services/User/classes/class.ilObjUser.php';
66 include_once 'Services/Mail/classes/class.ilMailbox.php';
67 include_once 'Services/Mail/classes/class.ilMail.php';
68
69 parent::__construct();
70
71 $this->setLimit(5);
72 $this->setImage(ilUtil::getImagePath('icon_mail.svg'));
73 $this->setTitle($this->lng->txt('mail'));
75 }
76
81 public static function getBlockType()
82 {
83 return self::$block_type;
84 }
85
90 public static function isRepositoryObject()
91 {
92 return false;
93 }
94
98 public static function getScreenMode()
99 {
100 switch ($_GET['cmd']) {
101 case 'showMail':
102 return IL_SCREEN_CENTER;
103 break;
104
105 default:
106 return IL_SCREEN_SIDE;
107 break;
108 }
109 }
110
114 public function executeCommand()
115 {
116 $cmd = $this->ctrl->getCmd('getHTML');
117
118 return $this->$cmd();
119 }
120
121 public function getHTML()
122 {
123 $umail = new ilMail($this->user->getId());
124 if (!$this->rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId())) {
125 return '';
126 }
127
128 if ($this->getCurrentDetailLevel() == 0) {
129 return '';
130 } else {
131 $html = parent::getHTML();
132 return $html;
133 }
134 }
135
139 protected function getMails()
140 {
141 require_once 'Services/Mail/classes/class.ilObjMail.php';
142
143 $umail = new ilMail($this->user->getId());
144 $mbox = new ilMailBox($this->user->getId());
145 $this->inbox = $mbox->getInboxFolder();
146
147 $this->mails = $umail->getMailsOfFolder(
148 $this->inbox,
149 array(
150 'status' => 'unread',
151 'type' => ((int) $this->setting->get('pd_sys_msg_mode')) != ilObjMail::PD_SYS_MSG_MAIL_BLOCK ? 'normal' : ''
152 )
153 );
154 }
155
159 public function fillDataSection()
160 {
161 $this->getMails();
162 $this->setData($this->mails);
163
164 if ($this->getCurrentDetailLevel() > 1 && count($this->mails) > 0) {
165 $this->setRowTemplate("tpl.pd_mail_row.html", "Services/Mail");
166 if ($this->getCurrentDetailLevel() > 2) {
167 $this->setColSpan(2);
168 }
169 parent::fillDataSection();
170 } else {
171 $this->setEnableNumInfo(false);
172 if (count($this->mails) == 0) {
173 $this->setEnableDetailRow(false);
174 }
175 $this->setDataSection($this->getOverview());
176 }
177 }
178
182 public function fillRow($mail)
183 {
184 $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
185
186 if ($this->getCurrentDetailLevel() > 2) {
187 $this->tpl->touchBlock('usr_image_space');
188 if ($user && $user->getId() != ANONYMOUS_USER_ID) {
189 $this->tpl->setVariable('PUBLIC_NAME_LONG', $user->getPublicName());
190 $this->tpl->setVariable('IMG_SENDER', $user->getPersonalPicturePath('xxsmall'));
191 $this->tpl->setVariable('ALT_SENDER', htmlspecialchars($user->getPublicName()));
192 } elseif (!$user) {
193 $this->tpl->setVariable('PUBLIC_NAME_LONG', $mail['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')');
194
195 $this->tpl->setCurrentBlock('image_container');
196 $this->tpl->touchBlock('image_container');
197 $this->tpl->parseCurrentBlock();
198 } else {
199 $this->tpl->setVariable('PUBLIC_NAME_LONG', ilMail::_getIliasMailerName());
200 $this->tpl->setVariable('IMG_SENDER', ilUtil::getImagePath('HeaderIconAvatar.svg'));
201 $this->tpl->setVariable('ALT_SENDER', htmlspecialchars(ilMail::_getIliasMailerName()));
202 }
203
204 $this->tpl->setVariable('NEW_MAIL_DATE', ilDatePresentation::formatDate(new ilDate($mail['send_time'], IL_CAL_DATE)));
205 } else {
206 if ($user && $user->getId() != ANONYMOUS_USER_ID) {
207 $this->tpl->setVariable('PUBLIC_NAME_SHORT', $user->getPublicName());
208 } elseif (!$user) {
209 $this->tpl->setVariable('PUBLIC_NAME_SHORT', $mail['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')');
210 } else {
211 $this->tpl->setVariable('PUBLIC_NAME_SHORT', ilMail::_getIliasMailerName());
212 }
213 }
214
215 $this->tpl->setVariable('NEW_MAIL_SUBJ', htmlentities($mail['m_subject'], ENT_NOQUOTES, 'UTF-8'));
216 $this->ctrl->setParameter($this, 'mobj_id', $this->inbox);
217 $this->ctrl->setParameter($this, 'mail_id', $mail['mail_id']);
218 $this->ctrl->setParameter($this, 'mail_mode', $this->mail_mode);
219 $this->tpl->setVariable('NEW_MAIL_LINK_READ', $this->ctrl->getLinkTarget($this, 'showMail'));
220 $this->ctrl->clearParameters($this);
221 }
222
226 protected function getOverview()
227 {
228 return '<div class="small">' . ((int) count($this->mails)) . " " . $this->lng->txt("mails_pl") . "</div>";
229 }
230
234 protected function showMail()
235 {
236 include_once("./Services/Mail/classes/class.ilPDMailGUI.php");
237 $mail_gui = new ilPDMailGUI();
238
239 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
240 $content_block = new ilPDContentBlockGUI();
241 $content_block->setContent($mail_gui->getPDMailHTML(
242 $_GET["mail_id"],
243 $_GET["mobj_id"]
244 ));
245 $content_block->setTitle($this->lng->txt("message"));
246 $content_block->setColSpan(2);
247 $content_block->setImage(ilUtil::getImagePath("icon_mail.svg"));
248 $content_block->addHeaderCommand(
249 $this->ctrl->getLinkTargetByClass("ilpersonaldesktopgui", "show"),
250 $this->lng->txt("selected_items_back")
251 );
252
253 if ($_GET["mail_mode"] != "system") {
254 $content_block->addBlockCommand(
255 "ilias.php?baseClass=ilMailGUI&mail_id=" .
256 $_GET["mail_id"] . "&mobj_id=" . $_GET["mobj_id"] . "&type=reply",
257 $this->lng->txt("reply")
258 );
259 $content_block->addBlockCommand(
260 "ilias.php?baseClass=ilMailGUI&mail_id=" .
261 $_GET["mail_id"] . "&mobj_id=" . $_GET["mobj_id"] . "&type=read",
262 $this->lng->txt("inbox")
263 );
264
265 $this->ctrl->setParameter($this, 'mail_id', (int) $_GET['mail_id']);
266 $content_block->addBlockCommand($this->ctrl->getLinkTarget($this, 'deleteMail'), $this->lng->txt('delete'));
267 } else {
268 $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
269 $this->ctrl->setParameter($this, "mobj_id", $_GET["mobj_id"]);
270 $content_block->addBlockCommand(
271 $this->ctrl->getLinkTarget($this, "deleteMail"),
272 $this->lng->txt("delete")
273 );
274 $this->ctrl->clearParameters($this);
275 }
276
277 return $content_block->getHTML();
278 }
279
283 public function deleteMail()
284 {
285 $this->lng->loadLanguageModule('mail');
286
287 $umail = new ilMail($this->user->getId());
288 $mbox = new ilMailBox($this->user->getId());
289
290 if (!$_GET['mobj_id']) {
291 $_GET['mobj_id'] = $mbox->getInboxFolder();
292 }
293
294 if ($umail->moveMailsToFolder(
295 array($_GET['mail_id']),
296 $mbox->getTrashFolder()
297 )
298 ) {
299 ilUtil::sendInfo($this->lng->txt('mail_moved_to_trash'), true);
300 } else {
301 ilUtil::sendInfo($this->lng->txt('mail_move_error'), true);
302 }
303 $this->ctrl->redirectByClass('ilpersonaldesktopgui', 'show');
304 }
305
309 protected function preloadData(array $data)
310 {
311 $usr_ids = array();
312
313 foreach ($data as $mail) {
314 if ($mail['sender_id'] && $mail['sender_id'] != ANONYMOUS_USER_ID) {
315 $usr_ids[$mail['sender_id']] = $mail['sender_id'];
316 }
317 }
318
320 }
321}
user()
Definition: user.php:4
$_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, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
Class for single dates.
static getUserObjectById($usr_id)
static preloadUserObjects(array $usr_ids)
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
global $DIC
Definition: saml.php:7