ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAccountMail.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{
20 public $u_password = "";
21
27 public $user = "";
28
34 public $target = "";
35
37
38 private $attachments = array();
39
44 public function __construct()
45 {
46 }
47
48 public function useLangVariablesAsFallback($a_status)
49 {
50 $this->lang_variables_as_fallback = $a_status;
51 }
52
54 {
56 }
57
64 public function setUserPassword($a_pwd)
65 {
66 $this->u_password = $a_pwd;
67 }
68
75 public function getUserPassword()
76 {
77 return $this->u_password;
78 }
79
87 public function setUser(&$a_user)
88 {
89 $this->user =&$a_user;
90 }
91
98 public function &getUser()
99 {
100 return $this->user;
101 }
102
109 public function setTarget($a_target)
110 {
111 $this->u_target = $a_target;
112 }
113
120 public function getTarget()
121 {
122 return $this->target;
123 }
124
128 public function reset()
129 {
130 unset($this->u_password);
131 unset($this->user);
132 unset($this->target);
133 }
134
138 public function readAccountMail($a_lang)
139 {
140 if (!is_array($this->amail[$a_lang])) {
141 include_once('./Services/User/classes/class.ilObjUserFolder.php');
142 $this->amail[$a_lang] = ilObjUserFolder::_lookupNewAccountMail($a_lang);
143 $amail["body"] = trim($amail["body"]);
144 $amail["subject"] = trim($amail["subject"]);
145 }
146
147 return $this->amail[$a_lang];
148 }
149
158 public function send()
159 {
160 global $ilSetting;
161
162 $user =&$this->getUser();
163
164 if (!$user->getEmail()) {
165 return false;
166 }
167
168 // determine language and get account mail data
169 // fall back to default language if acccount mail data is not given for user language.
170 $amail = $this->readAccountMail($user->getLanguage());
171 if ($amail['body'] == '' || $amail['subject'] == '') {
172 $amail = $this->readAccountMail($ilSetting->get('language'));
173 $lang = $ilSetting->get('language');
174 } else {
175 $lang = $user->getLanguage();
176 }
177
178 // fallback if mail data is still not given
179 if ($this->areLangVariablesUsedAsFallback() &&
180 ($amail['body'] == '' || $amail['subject'] == '')) {
181 $lang = $user->getLanguage();
182 $tmp_lang = new ilLanguage($lang);
183
184 // mail subject
185 $mail_subject = $tmp_lang->txt('reg_mail_subject');
186
187 $timelimit = "";
188 if (!$user->checkTimeLimit()) {
189 $tmp_lang->loadLanguageModule("registration");
190
191 // #6098
192 $timelimit_from = new ilDateTime($user->getTimeLimitFrom(), IL_CAL_UNIX);
193 $timelimit_until = new ilDateTime($user->getTimeLimitUntil(), IL_CAL_UNIX);
194 $timelimit = ilDatePresentation::formatPeriod($timelimit_from, $timelimit_until);
195 $timelimit = "\n" . sprintf($tmp_lang->txt('reg_mail_body_timelimit'), $timelimit) . "\n\n";
196 }
197
198 // mail body
199 $mail_body = $tmp_lang->txt('reg_mail_body_salutation') . ' ' . $user->getFullname() . ",\n\n" .
200 $tmp_lang->txt('reg_mail_body_text1') . "\n\n" .
201 $tmp_lang->txt('reg_mail_body_text2') . "\n" .
202 ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID . "\n";
203 $mail_body .= $tmp_lang->txt('login') . ': ' . $user->getLogin() . "\n";
204 $mail_body.= $tmp_lang->txt('passwd') . ': ' . $this->u_password . "\n";
205 $mail_body.= "\n" . $timelimit;
206 $mail_body .= $tmp_lang->txt('reg_mail_body_text3') . "\n\r";
207 $mail_body .= $user->getProfileAsString($tmp_lang);
208 } else {
209 // replace placeholders
210 $mail_subject = $this->replacePlaceholders($amail['subject'], $user, $amail, $lang);
211 $mail_body = $this->replacePlaceholders($amail['body'], $user, $amail, $lang);
212 }
213
215 $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
216
217 // send the mail
218 include_once 'Services/Mail/classes/class.ilMimeMail.php';
219 $mmail = new ilMimeMail();
220 $mmail->From($senderFactory->system());
221 $mmail->Subject($mail_subject);
222 $mmail->To($user->getEmail());
223 $mmail->Body($mail_body);
224
225 foreach ($this->attachments as $filename => $display_name) {
226 $mmail->Attach($filename, "", "attachment", $display_name);
227 }
228 /*
229 echo "<br><br><b>From</b>:".$ilSetting->get("admin_email");
230 echo "<br><br><b>To</b>:".$user->getEmail();
231 echo "<br><br><b>Subject</b>:".$mail_subject;
232 echo "<br><br><b>Body</b>:".$mail_body;
233 return true;*/
234 $mmail->Send();
235
236 return true;
237 }
238
239 public function replacePlaceholders($a_string, &$a_user, $a_amail, $a_lang)
240 {
241 global $ilSetting, $tree;
242
243 // determine salutation
244 switch ($a_user->getGender()) {
245 case "f": $gender_salut = $a_amail["sal_f"];
246 break;
247 case "m": $gender_salut = $a_amail["sal_m"];
248 break;
249 default: $gender_salut = $a_amail["sal_g"];
250 }
251 $gender_salut = trim($gender_salut);
252
253 $a_string = str_replace("[MAIL_SALUTATION]", $gender_salut, $a_string);
254 $a_string = str_replace("[LOGIN]", $a_user->getLogin(), $a_string);
255 $a_string = str_replace("[FIRST_NAME]", $a_user->getFirstname(), $a_string);
256 $a_string = str_replace("[LAST_NAME]", $a_user->getLastname(), $a_string);
257 // BEGIN Mail Include E-Mail Address in account mail
258 $a_string = str_replace("[EMAIL]", $a_user->getEmail(), $a_string);
259 // END Mail Include E-Mail Address in account mail
260 $a_string = str_replace("[PASSWORD]", $this->getUserPassword(), $a_string);
261 $a_string = str_replace(
262 "[ILIAS_URL]",
263 ILIAS_HTTP_PATH . "/login.php?client_id=" . CLIENT_ID,
264 $a_string
265 );
266 $a_string = str_replace("[CLIENT_NAME]", CLIENT_NAME, $a_string);
267 $a_string = str_replace(
268 "[ADMIN_MAIL]",
269 $ilSetting->get("admin_email"),
270 $a_string
271 );
272
273 // (no) password sections
274 if ($this->getUserPassword() == "") {
275 // #12232
276 $a_string = preg_replace("/\[IF_PASSWORD\].*\[\/IF_PASSWORD\]/imsU", "", $a_string);
277 $a_string = preg_replace("/\[IF_NO_PASSWORD\](.*)\[\/IF_NO_PASSWORD\]/imsU", "$1", $a_string);
278 } else {
279 $a_string = preg_replace("/\[IF_NO_PASSWORD\].*\[\/IF_NO_PASSWORD\]/imsU", "", $a_string);
280 $a_string = preg_replace("/\[IF_PASSWORD\](.*)\[\/IF_PASSWORD\]/imsU", "$1", $a_string);
281 }
282
283 // #13346
284 if (!$a_user->getTimeLimitUnlimited()) {
285 // #6098
286 $a_string = preg_replace("/\[IF_TIMELIMIT\](.*)\[\/IF_TIMELIMIT\]/imsU", "$1", $a_string);
287 $timelimit_from = new ilDateTime($a_user->getTimeLimitFrom(), IL_CAL_UNIX);
288 $timelimit_until = new ilDateTime($a_user->getTimeLimitUntil(), IL_CAL_UNIX);
289 $timelimit = ilDatePresentation::formatPeriod($timelimit_from, $timelimit_until);
290 $a_string = str_replace("[TIMELIMIT]", $timelimit, $a_string);
291 } else {
292 $a_string = preg_replace("/\[IF_TIMELIMIT\](.*)\[\/IF_TIMELIMIT\]/imsU", "", $a_string);
293 }
294
295 // target
296 $tar = false;
297 if ($_GET["target"] != "") {
298 $tarr = explode("_", $_GET["target"]);
299 if ($tree->isInTree($tarr[1])) {
300 $obj_id = ilObject::_lookupObjId($tarr[1]);
301 $type = ilObject::_lookupType($obj_id);
302 if ($type == $tarr[0]) {
303 $a_string = str_replace(
304 "[TARGET_TITLE]",
305 ilObject::_lookupTitle($obj_id),
306 $a_string
307 );
308 $a_string = str_replace(
309 "[TARGET]",
310 ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . "&target=" . $_GET["target"],
311 $a_string
312 );
313
314 // this looks complicated, but we may have no initilised $lng object here
315 // if mail is send during user creation in authentication
316 include_once("./Services/Language/classes/class.ilLanguage.php");
317 $a_string = str_replace(
318 "[TARGET_TYPE]",
319 ilLanguage::_lookupEntry($a_lang, "common", "obj_" . $tarr[0]),
320 $a_string
321 );
322
323 $tar = true;
324 }
325 }
326 }
327
328 // (no) target section
329 if (!$tar) {
330 $a_string = preg_replace("/\[IF_TARGET\].*\[\/IF_TARGET\]/imsU", "", $a_string);
331 } else {
332 $a_string = preg_replace("/\[IF_TARGET\](.*)\[\/IF_TARGET\]/imsU", "$1", $a_string);
333 }
334
335 return $a_string;
336 }
337
338 public function addAttachment($a_filename, $a_display_name)
339 {
340 $this->attachments[$a_filename] = $a_display_name;
341 }
342}
sprintf('%.4f', $callTime)
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Class ilAccountMail.
replacePlaceholders($a_string, &$a_user, $a_amail, $a_lang)
setUser(&$a_user)
Set user.
addAttachment($a_filename, $a_display_name)
& getUser()
get user object
useLangVariablesAsFallback($a_status)
getUserPassword()
get user password
readAccountMail($a_lang)
get new account mail array (including subject and message body)
reset()
reset all values
setUserPassword($a_pwd)
set user password
__construct()
constructor @access public
setTarget($a_target)
set repository item target
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
language handling
static _lookupEntry($a_lang_key, $a_mod, $a_id)
Class ilMimeMail.
static _lookupNewAccountMail($a_lang)
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
$lang
Definition: consent.php:3
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilSetting
Definition: privfeed.php:17
$type