ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilAccountMail Class Reference

Class ilAccountMail. More...

+ Collaboration diagram for ilAccountMail:

Public Member Functions

 __construct ()
 constructor public More...
 
 useLangVariablesAsFallback ($a_status)
 
 areLangVariablesUsedAsFallback ()
 
 setUserPassword ($a_pwd)
 set user password More...
 
 getUserPassword ()
 get user password More...
 
 setUser (&$a_user)
 Set user. More...
 
getUser ()
 get user object More...
 
 setTarget ($a_target)
 set repository item target More...
 
 getTarget ()
 get target More...
 
 reset ()
 reset all values More...
 
 readAccountMail ($a_lang)
 get new account mail array (including subject and message body) More...
 
 send ()
 Sends the mail with its object properties as MimeMail It first tries to read the mail body, subject and sender address from posted named formular fields. More...
 
 replacePlaceholders ($a_string, &$a_user, $a_amail, $a_lang)
 
 addAttachment ($a_filename, $a_display_name)
 

Data Fields

 $u_password = ""
 
 $user = ""
 
 $target = ""
 

Private Attributes

 $lang_variables_as_fallback = false
 
 $attachments = array()
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAccountMail::__construct ( )

constructor public

Definition at line 44 of file class.ilAccountMail.php.

45  {
46  }

Member Function Documentation

◆ addAttachment()

ilAccountMail::addAttachment (   $a_filename,
  $a_display_name 
)

Definition at line 346 of file class.ilAccountMail.php.

347  {
348  $this->attachments[$a_filename] = $a_display_name;
349  }

◆ areLangVariablesUsedAsFallback()

ilAccountMail::areLangVariablesUsedAsFallback ( )

Definition at line 53 of file class.ilAccountMail.php.

References $lang_variables_as_fallback.

Referenced by send().

54  {
56  }
+ Here is the caller graph for this function:

◆ getTarget()

ilAccountMail::getTarget ( )

get target

public

Returns
string repository item target

Definition at line 120 of file class.ilAccountMail.php.

References $target.

121  {
122  return $this->target;
123  }

◆ getUser()

& ilAccountMail::getUser ( )

get user object

public

Returns
object user object

Definition at line 98 of file class.ilAccountMail.php.

References $user.

Referenced by send().

99  {
100  return $this->user;
101  }
+ Here is the caller graph for this function:

◆ getUserPassword()

ilAccountMail::getUserPassword ( )

get user password

public

Returns
string users password as plain text

Definition at line 75 of file class.ilAccountMail.php.

References $u_password.

Referenced by replacePlaceholders().

76  {
77  return $this->u_password;
78  }
+ Here is the caller graph for this function:

◆ readAccountMail()

ilAccountMail::readAccountMail (   $a_lang)

get new account mail array (including subject and message body)

Definition at line 138 of file class.ilAccountMail.php.

References ilObjUserFolder\_lookupNewAccountMail().

Referenced by send().

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  }
static _lookupNewAccountMail($a_lang)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replacePlaceholders()

ilAccountMail::replacePlaceholders (   $a_string,
$a_user,
  $a_amail,
  $a_lang 
)

Definition at line 247 of file class.ilAccountMail.php.

References $_GET, $ilSetting, ilLanguage\_lookupEntry(), ilObject\_lookupObjId(), ilObject\_lookupTitle(), ilObject\_lookupType(), ilDatePresentation\formatPeriod(), getUserPassword(), and IL_CAL_UNIX.

Referenced by send().

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  }
$_GET["client_id"]
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
static _lookupTitle($a_id)
lookup object title
static _lookupEntry($a_lang_key, $a_mod, $a_id)
const IL_CAL_UNIX
static _lookupObjId($a_id)
Date and time handling
static _lookupType($a_id, $a_reference=false)
lookup object type
getUserPassword()
get user password
global $ilSetting
Definition: privfeed.php:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

ilAccountMail::reset ( )

reset all values

Definition at line 128 of file class.ilAccountMail.php.

References user().

129  {
130  unset($this->u_password);
131  unset($this->user);
132  unset($this->target);
133  }
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ send()

ilAccountMail::send ( )

Sends the mail with its object properties as MimeMail It first tries to read the mail body, subject and sender address from posted named formular fields.

If no field values found the defaults are used. Placehoders will be replaced by the appropriate data. public

Parameters
objectilUser

Definition at line 159 of file class.ilAccountMail.php.

References $filename, $ilSetting, $lang, areLangVariablesUsedAsFallback(), ilDatePresentation\formatPeriod(), getUser(), IL_CAL_UNIX, readAccountMail(), and replacePlaceholders().

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 /*
237 echo "<br><br><b>From</b>:".$ilSetting->get("admin_email");
238 echo "<br><br><b>To</b>:".$user->getEmail();
239 echo "<br><br><b>Subject</b>:".$mail_subject;
240 echo "<br><br><b>Body</b>:".$mail_body;
241 return true;*/
242  $mmail->Send();
243 
244  return true;
245  }
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
const IL_CAL_UNIX
this class encapsulates the PHP mail() function.
& getUser()
get user object
Date and time handling
global $ilSetting
Definition: privfeed.php:17
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
readAccountMail($a_lang)
get new account mail array (including subject and message body)
language handling
replacePlaceholders($a_string, &$a_user, $a_amail, $a_lang)
+ Here is the call graph for this function:

◆ setTarget()

ilAccountMail::setTarget (   $a_target)

set repository item target

public

Parameters
string$a_targettarget as used in permanent links, e.g. crs_123

Definition at line 109 of file class.ilAccountMail.php.

110  {
111  $this->u_target = $a_target;
112  }

◆ setUser()

ilAccountMail::setUser ( $a_user)

Set user.

The user object should provide email, language login, gender, first and last name

public

Parameters
object$a_useruser object

Definition at line 87 of file class.ilAccountMail.php.

References user().

88  {
89  $this->user =& $a_user;
90  }
user()
Definition: user.php:4
+ Here is the call graph for this function:

◆ setUserPassword()

ilAccountMail::setUserPassword (   $a_pwd)

set user password

public

Parameters
string$a_pwdusers password as plain text

Definition at line 64 of file class.ilAccountMail.php.

65  {
66  $this->u_password = $a_pwd;
67  }

◆ useLangVariablesAsFallback()

ilAccountMail::useLangVariablesAsFallback (   $a_status)

Definition at line 48 of file class.ilAccountMail.php.

49  {
50  $this->lang_variables_as_fallback = $a_status;
51  }

Field Documentation

◆ $attachments

ilAccountMail::$attachments = array()
private

Definition at line 38 of file class.ilAccountMail.php.

◆ $lang_variables_as_fallback

ilAccountMail::$lang_variables_as_fallback = false
private

Definition at line 36 of file class.ilAccountMail.php.

Referenced by areLangVariablesUsedAsFallback().

◆ $target

ilAccountMail::$target = ""

Definition at line 34 of file class.ilAccountMail.php.

Referenced by getTarget().

◆ $u_password

ilAccountMail::$u_password = ""

Definition at line 20 of file class.ilAccountMail.php.

Referenced by getUserPassword().

◆ $user

ilAccountMail::$user = ""

Definition at line 27 of file class.ilAccountMail.php.

Referenced by getUser().


The documentation for this class was generated from the following file: