ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
80 public function getBlockType() : string
81 {
82 return self::$block_type;
83 }
84
88 protected function isRepositoryObject() : bool
89 {
90 return false;
91 }
92
96 public static function getScreenMode()
97 {
98 switch ($_GET['cmd']) {
99 case 'showMail':
100 return IL_SCREEN_CENTER;
101 break;
102
103 default:
104 return IL_SCREEN_SIDE;
105 break;
106 }
107 }
108
112 public function executeCommand()
113 {
114 $cmd = $this->ctrl->getCmd('getHTML');
115
116 return $this->$cmd();
117 }
118
119 public function getHTML()
120 {
121 $umail = new ilMail($this->user->getId());
122 if (!$this->rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId())) {
123 return '';
124 }
125
126 if ($this->getCurrentDetailLevel() == 0) {
127 return '';
128 } else {
129 $html = parent::getHTML();
130 return $html;
131 }
132 }
133
137 protected function getMails()
138 {
139 require_once 'Services/Mail/classes/class.ilObjMail.php';
140
141 $umail = new ilMail($this->user->getId());
142 $mbox = new ilMailbox($this->user->getId());
143 $this->inbox = $mbox->getInboxFolder();
144
145 $this->mails = $umail->getMailsOfFolder(
146 $this->inbox,
147 array(
148 'status' => 'unread',
149 'type' => ((int) $this->setting->get('pd_sys_msg_mode')) != ilObjMail::PD_SYS_MSG_MAIL_BLOCK ? 'normal' : ''
150 )
151 );
152 }
153
157 public function fillDataSection()
158 {
159 $this->getMails();
160 $this->setData($this->mails);
161
162 if ($this->getCurrentDetailLevel() > 1 && count($this->mails) > 0) {
163 $this->setRowTemplate("tpl.pd_mail_row.html", "Services/Mail");
164 if ($this->getCurrentDetailLevel() > 2) {
165 $this->setColSpan(2);
166 }
167 parent::fillDataSection();
168 } else {
169 $this->setEnableNumInfo(false);
170 if (count($this->mails) == 0) {
171 $this->setEnableDetailRow(false);
172 }
173 $this->setDataSection($this->getOverview());
174 }
175 }
176
180 public function fillRow($mail)
181 {
182 $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
183
184 if ($this->getCurrentDetailLevel() > 2) {
185 $this->tpl->touchBlock('usr_image_space');
186 if ($user && $user->getId() != ANONYMOUS_USER_ID) {
187 $this->tpl->setVariable('PUBLIC_NAME_LONG', $user->getPublicName());
188 $this->tpl->setVariable('IMG_SENDER', $user->getPersonalPicturePath('xxsmall'));
189 $this->tpl->setVariable('ALT_SENDER', htmlspecialchars($user->getPublicName()));
190 } elseif (!$user) {
191 $this->tpl->setVariable('PUBLIC_NAME_LONG', $mail['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')');
192
193 $this->tpl->setCurrentBlock('image_container');
194 $this->tpl->touchBlock('image_container');
195 $this->tpl->parseCurrentBlock();
196 } else {
197 $this->tpl->setVariable('PUBLIC_NAME_LONG', ilMail::_getIliasMailerName());
198 $this->tpl->setVariable('IMG_SENDER', ilUtil::getImagePath('HeaderIconAvatar.svg'));
199 $this->tpl->setVariable('ALT_SENDER', htmlspecialchars(ilMail::_getIliasMailerName()));
200 }
201
202 $this->tpl->setVariable('NEW_MAIL_DATE', ilDatePresentation::formatDate(new ilDate($mail['send_time'], IL_CAL_DATE)));
203 } else {
204 if ($user && $user->getId() != ANONYMOUS_USER_ID) {
205 $this->tpl->setVariable('PUBLIC_NAME_SHORT', $user->getPublicName());
206 } elseif (!$user) {
207 $this->tpl->setVariable('PUBLIC_NAME_SHORT', $mail['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')');
208 } else {
209 $this->tpl->setVariable('PUBLIC_NAME_SHORT', ilMail::_getIliasMailerName());
210 }
211 }
212
213 $this->tpl->setVariable('NEW_MAIL_SUBJ', htmlentities($mail['m_subject'], ENT_NOQUOTES, 'UTF-8'));
214 $this->ctrl->setParameter($this, 'mobj_id', $this->inbox);
215 $this->ctrl->setParameter($this, 'mail_id', $mail['mail_id']);
216 $this->ctrl->setParameter($this, 'mail_mode', $this->mail_mode);
217 $this->tpl->setVariable('NEW_MAIL_LINK_READ', $this->ctrl->getLinkTarget($this, 'showMail'));
218 $this->ctrl->clearParameters($this);
219 }
220
224 protected function getOverview()
225 {
226 return '<div class="small">' . ((int) count($this->mails)) . " " . $this->lng->txt("mails_pl") . "</div>";
227 }
228
232 protected function showMail()
233 {
234 include_once("./Services/Mail/classes/class.ilPDMailGUI.php");
235 $mail_gui = new ilPDMailGUI();
236
237 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
238 $content_block = new ilPDContentBlockGUI();
239 $content_block->setContent($mail_gui->getPDMailHTML(
240 $_GET["mail_id"],
241 $_GET["mobj_id"]
242 ));
243 $content_block->setTitle($this->lng->txt("message"));
244 $content_block->setColSpan(2);
245 $content_block->setImage(ilUtil::getImagePath("icon_mail.svg"));
246 $content_block->addHeaderCommand(
247 $this->ctrl->getLinkTargetByClass("ilpersonaldesktopgui", "show"),
248 $this->lng->txt("selected_items_back")
249 );
250
251 if ($_GET["mail_mode"] != "system") {
252 $content_block->addBlockCommand(
253 "ilias.php?baseClass=ilMailGUI&mail_id=" .
254 $_GET["mail_id"] . "&mobj_id=" . $_GET["mobj_id"] . "&type=reply",
255 $this->lng->txt("reply")
256 );
257 $content_block->addBlockCommand(
258 "ilias.php?baseClass=ilMailGUI&mail_id=" .
259 $_GET["mail_id"] . "&mobj_id=" . $_GET["mobj_id"] . "&type=read",
260 $this->lng->txt("inbox")
261 );
262
263 $this->ctrl->setParameter($this, 'mail_id', (int) $_GET['mail_id']);
264 $content_block->addBlockCommand($this->ctrl->getLinkTarget($this, 'deleteMail'), $this->lng->txt('delete'));
265 } else {
266 $this->ctrl->setParameter($this, "mail_id", $_GET["mail_id"]);
267 $this->ctrl->setParameter($this, "mobj_id", $_GET["mobj_id"]);
268 $content_block->addBlockCommand(
269 $this->ctrl->getLinkTarget($this, "deleteMail"),
270 $this->lng->txt("delete")
271 );
272 $this->ctrl->clearParameters($this);
273 }
274
275 return $content_block->getHTML();
276 }
277
281 public function deleteMail()
282 {
283 $this->lng->loadLanguageModule('mail');
284
285 $umail = new ilMail($this->user->getId());
286 $mbox = new ilMailbox($this->user->getId());
287
288 if (!$_GET['mobj_id']) {
289 $_GET['mobj_id'] = $mbox->getInboxFolder();
290 }
291
292 if ($umail->moveMailsToFolder(array((int) $_GET['mail_id']), (int) $mbox->getTrashFolder())) {
293 \ilUtil::sendInfo($this->lng->txt('mail_moved_to_trash'), true);
294 } else {
295 \ilUtil::sendInfo($this->lng->txt('mail_move_error'), true);
296 }
297 $this->ctrl->redirectByClass('ilpersonaldesktopgui', 'show');
298 }
299
303 protected function preloadData(array $data)
304 {
305 $usr_ids = array();
306
307 foreach ($data as $mail) {
308 if ($mail['sender_id'] && $mail['sender_id'] != ANONYMOUS_USER_ID) {
309 $usr_ids[$mail['sender_id']] = $mail['sender_id'];
310 }
311 }
312
314 }
315}
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, $include_seconds=false)
Format a date @access public.
Class for single dates.
static getUserObjectById($usr_id)
static preloadUserObjects(array $usr_ids)
Mail Box class Base class for creating and handling mail boxes.
const PD_SYS_MSG_MAIL_BLOCK
BlockGUI class for (centered) Content on Personal Desktop.
BlockGUI class for Personal Desktop Mail block.
isRepositoryObject()
Returns whether block has a corresponding repository object.bool
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.
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