ILIAS  release_8 Revision v8.24
class.ilPDMailGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Refinery\Factory as Refinery;
23
30{
32 private Refinery $refinery;
33 protected ILIAS $ilias;
35 protected ilLanguage $lng;
36 protected ilObjUser $user;
37
38 public function __construct()
39 {
40 global $DIC;
41 $this->lng = $DIC->language();
42 $this->rbacsystem = $DIC->rbac()->system();
43 $this->ilias = $DIC['ilias'];
44 $this->user = $DIC->user();
45 $this->http = $DIC->http();
46 $this->refinery = $DIC->refinery();
47 }
48
49 public function getPDMailHTML(int $a_mail_id, int $a_mobj_id): string
50 {
51 $this->lng->loadLanguageModule('mail');
52
53 //get the mail from user
54 $umail = new ilMail($this->user->getId());
55
56 // catch hack attempts
57 if (!$this->rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId())) {
58 $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->WARNING);
59 }
60
61 $umail->markRead([$a_mail_id]);
62 $mail_data = $umail->getMail($a_mail_id);
63
64 $tpl = new ilTemplate('tpl.pd_mail.html', true, true, 'Services/Mail');
65
66 if ($mail_data['attachments']) {
67 $mailId = 0;
68 if ($this->http->wrapper()->query()->has('mail_id')) {
69 $mailId = $this->http->wrapper()->query()->retrieve('mail_id', $this->refinery->kindlyTo()->int());
70 }
71 foreach ($mail_data['attachments'] as $file) {
72 $tpl->setCurrentBlock('a_row');
73 $tpl->setVariable(
74 'HREF_DOWNLOAD',
75 'ilias.php?baseClass=ilMailGUI&amp;type=deliverFile&amp;mail_id='
76 . $mailId .
77 '&amp;filename=' . md5($file)
78 );
79 $tpl->setVariable('FILE_NAME', $file);
80 $tpl->setVariable('TXT_DOWNLOAD', $this->lng->txt('download'));
81 $tpl->parseCurrentBlock();
82 }
83 $tpl->setCurrentBlock('attachment');
84 $tpl->setVariable('TXT_ATTACHMENT', $this->lng->txt('attachments'));
85 $tpl->parseCurrentBlock();
86 }
87
88 $tpl->setVariable('TXT_FROM', $this->lng->txt('from'));
89
91 $sender = ilObjectFactory::getInstanceByObjId($mail_data['sender_id'], false);
92 if ($sender instanceof ilObjUser && $sender->getId() !== 0 && $sender->getId() !== ANONYMOUS_USER_ID) {
93 $tpl->setCurrentBlock('pers_image');
94 $tpl->setVariable('IMG_SENDER', $sender->getPersonalPicturePath('xsmall'));
95 $tpl->setVariable('ALT_SENDER', htmlspecialchars($sender->getPublicName()));
96 $tpl->parseCurrentBlock();
97
98 $tpl->setVariable('PUBLIC_NAME', $sender->getPublicName());
99 } elseif (null === $sender) {
100 $tpl->setVariable(
101 'PUBLIC_NAME',
102 trim(($mail_data['import_name'] ?? '') . ' (' . $this->lng->txt('user_deleted') . ')')
103 );
104 } else {
105 $tpl->setCurrentBlock('pers_image');
106 $tpl->setVariable('IMG_SENDER', ilUtil::getImagePath('HeaderIconAvatar.svg'));
107 $tpl->setVariable('ALT_SENDER', htmlspecialchars(ilMail::_getIliasMailerName()));
108 $tpl->parseCurrentBlock();
109 $tpl->setVariable('PUBLIC_NAME', ilMail::_getIliasMailerName());
110 }
111
112 $tpl->setVariable('TXT_TO', $this->lng->txt('mail_to'));
113 $tpl->setVariable('TO', $umail->formatNamesForOutput((string) $mail_data['rcp_to']));
114
115 if ($mail_data['rcp_cc']) {
116 $tpl->setCurrentBlock('cc');
117 $tpl->setVariable('TXT_CC', $this->lng->txt('mail_cc'));
118 $tpl->setVariable('CC', $umail->formatNamesForOutput((string) $mail_data['rcp_cc']));
119 $tpl->parseCurrentBlock();
120 }
121
122 $tpl->setVariable('TXT_SUBJECT', $this->lng->txt('subject'));
123 $tpl->setVariable('SUBJECT', htmlspecialchars($mail_data['m_subject']));
124
125 $tpl->setVariable('TXT_DATE', $this->lng->txt('date'));
126 $tpl->setVariable(
127 'DATE',
128 ilDatePresentation::formatDate(new ilDateTime($mail_data['send_time'], IL_CAL_DATETIME))
129 );
130
131 $tpl->setVariable('TXT_MESSAGE', $this->lng->txt('message'));
132 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
133 $tpl->setVariable(
134 'MAIL_MESSAGE',
135 nl2br(ilUtil::makeClickable(htmlspecialchars(ilUtil::securePlainString($mail_data['m_message']))))
136 );
137
138 return $tpl->get();
139 }
140}
Builds data types.
Definition: Factory.php:21
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
language handling
User class.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Mail User Interface class.
ilLanguage $lng
GlobalHttpState $http
Refinery $refinery
ilRbacSystem $rbacsystem
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
special template class to simplify handling of ITX/PEAR
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static makeClickable(string $a_text, bool $detectGotoLinks=false)
static securePlainString(string $a_str)
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: feed.php:28
Interface GlobalHttpState.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
static http()
Fetches the global http state from ILIAS.
Class ChatMainBarProvider \MainMenu\Provider.
header include for all ilias files.