ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDiskQuotaReminderMail.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
14{
16
20 private $data;
21
22 private $tmp_lng;
23
28 public function __construct()
29 {
30 }
31
32 public function useLangVariablesAsFallback($a_status)
33 {
34 $this->lang_variables_as_fallback = $a_status;
35 }
36
38 {
40 }
41
61 public function setData($a_data)
62 {
63 $this->data = $a_data;
64 }
65
69 public function reset()
70 {
71 unset($this->data);
72 }
73
77 public function readMailTemplate($a_lang)
78 {
79 if (!is_array($this->amail[$a_lang])) {
80 $this->amail[$a_lang] = ilObjDiskQuotaSettings::_lookupReminderMailTemplate($a_lang);
81 $this->amail["body"] = trim($this->amail["body"]);
82 $this->amail["subject"] = trim($this->amail["subject"]);
83 }
84
85 return $this->amail[$a_lang];
86 }
87
96 public function send()
97 {
98 global $DIC;
99
100 // determine language and get account mail data
101 // fall back to default language if acccount mail data is not given for user language.
102 $amail = $this->readMailTemplate($this->data['language']);
103 if ($amail['body'] == '' || $amail['subject'] == '') {
104 $amail = $this->readMailTemplate($DIC->settings()->get('language'));
105 $lang = $DIC->settings()->get('language');
106 } else {
107 $lang = $this->data['language'];
108 }
109
110 // fallback if mail data is still not given
111 if ($this->areLangVariablesUsedAsFallback() &&
112 ($amail['body'] == '' || $amail['subject'] == '')) {
113 $lang = $this->data['language'];
114 $tmp_lang = $this->getLng($lang);
115
116 // mail subject
117 $mail_subject = $tmp_lang->txt('disk_quota_mail_subject');
118
119 // mail body
120 $mail_body = $tmp_lang->txt('disk_quota_mail_body_salutation') . ' ' . $data['firstname'] . ' ' . $data['lastname'] . ",\n\n" .
121 $tmp_lang->txt('disk_quota_body_text1') . "\n\n" .
122 $tmp_lang->txt('disk_quota_body_text2') . "\n" .
123 ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID . "\n";
124 $mail_body .= $tmp_lang->txt('login') . ': ' . $data['firstname'] . "\n";
125 $mail_body .= "\n";
126 $mail_body .= $tmp_lang->txt('disk_quota_mail_body_text3') . "\n\r";
127 //$mail_body .= $user->getProfileAsString($tmp_lang);
128 } else {
129 // replace placeholders
130 $mail_subject = $this->replacePlaceholders($amail['subject'], $amail, $lang);
131 $mail_body = $this->replacePlaceholders($amail['body'], $amail, $lang);
132 }
133
135 $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
136
137 // send the mail
138 include_once 'Services/Mail/classes/class.ilMimeMail.php';
139 $mmail = new ilMimeMail();
140 $mmail->From($senderFactory->system());
141 $mmail->Subject($mail_subject);
142 $mmail->To($this->data['email']);
143 $mmail->Body($mail_body);
144 $mmail->Send();
145
146 include_once 'Services/Mail/classes/class.ilMail.php';
147 $mail = new ilMail($GLOBALS['DIC']['ilUser']->getId());
148 $mail->enqueue($this->data['login'], "", "", $mail_subject, $mail_body, array());
149
150
151
152 return true;
153 }
154
155 private function getLng($a_lang)
156 {
157 if ($this->tmp_lng == null || $this->tmp_lng->lang_key != $a_lang) {
158 $this->tmp_lng = new ilLanguage($lang);
159 }
160 return $this->tmp_lng;
161 }
162
163 public function replacePlaceholders($a_string, $a_amail, $a_lang)
164 {
165 global $DIC;
166
167 $tmp_lang = $this->getLng($a_lang);
168
169 // determine salutation
170 switch ($this->data['gender']) {
171 case "f": $gender_salut = $a_amail["sal_f"];
172 break;
173 case "m": $gender_salut = $a_amail["sal_m"];
174 break;
175 default: $gender_salut = $a_amail["sal_g"];
176 }
177 $gender_salut = trim($gender_salut);
178
179 $a_string = str_replace("[MAIL_SALUTATION]", $gender_salut, $a_string);
180 $a_string = str_replace("[LOGIN]", $this->data['login'], $a_string);
181 $a_string = str_replace("[FIRST_NAME]", $this->data['firstname'], $a_string);
182 $a_string = str_replace("[LAST_NAME]", $this->data['lastname'], $a_string);
183 // BEGIN Mail Include E-Mail Address in account mail
184 $a_string = str_replace("[EMAIL]", $this->data['email'], $a_string);
185 $a_string = str_replace(
186 "[ILIAS_URL]",
187 ILIAS_HTTP_PATH . "/login.php?client_id=" . CLIENT_ID,
188 $a_string
189 );
190 $a_string = str_replace("[CLIENT_NAME]", CLIENT_NAME, $a_string);
191 $a_string = str_replace(
192 "[ADMIN_MAIL]",
193 $DIC->settings()->get("admin_email"),
194 $a_string
195 );
196
197 $a_string = str_replace("[DISK_QUOTA]", ilUtil::formatSize($this->data['disk_quota'], 'short', $tmp_lang), $a_string);
198 $a_string = str_replace("[DISK_USAGE]", ilUtil::formatSize($this->data['disk_usage'], 'short', $tmp_lang), $a_string);
199
200 $disk_usage_details = '';
201 foreach ($this->data['disk_usage_details'] as $details) {
202 $disk_usage_details .= number_format($details['count'], 0) . ' ' .
203 $tmp_lang->txt($details['type']) . ' ' .
204 ilUtil::formatSize($details['size'], 'short', $tmp_lang) . "\n";
205 }
206 $a_string = str_replace("[DISK_USAGE_DETAILS]", $disk_usage_details, $a_string);
207
208 return $a_string;
209 }
210}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
Class ilDiskQuotaReminderMail.
setData($a_data)
Sets used to fill in the placeholders in the mail.
replacePlaceholders($a_string, $a_amail, $a_lang)
__construct()
constructor @access public
$data
Data used to fill in the placeholders in the mail.
readMailTemplate($a_lang)
get new mail template array (including subject and message body)
language handling
Class ilMimeMail.
static _lookupReminderMailTemplate($a_lang)
Looks up the mail template for the specified language.
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
$lang
Definition: xapiexit.php:8
$DIC
Definition: xapitoken.php:46
catch(ilCmiXapiException $e) send($response)
Definition: xapitoken.php:92