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