• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilAccountMail.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00033 class ilAccountMail
00034 {
00040         var $u_password = "";
00041 
00047         var $user = "";
00048 
00054         var $target = "";
00055 
00056         
00061         function ilAccountMail()
00062         {               
00063         }
00064         
00071         function setUserPassword($a_pwd)
00072         {               
00073                 $this->u_password = $a_pwd;
00074         }
00075 
00082         function getUserPassword()
00083         {               
00084                 return $this->u_password;
00085         }
00086 
00094         function setUser(&$a_user)
00095         {               
00096                 $this->user =& $a_user;
00097         }
00098 
00105         function &getUser()
00106         {               
00107                 return $this->user;
00108         }
00109 
00116         function setTarget($a_target)
00117         {               
00118                 $this->u_target = $a_target;
00119         }
00120 
00127         function getTarget()
00128         {               
00129                 return $this->target;
00130         }
00131 
00135         function reset()
00136         {
00137                 $this->u_password = "";
00138                 $this->user = "";
00139                 $this->target = "";
00140         }
00141         
00145         function readAccountMail($a_lang)
00146         {
00147                 if (!is_array($this->amail[$a_lang]))
00148                 {
00149                         include_once("classes/class.ilObjUserFolder.php");
00150                         $this->amail[$a_lang] = ilObjUserFolder::_lookupNewAccountMail($a_lang);
00151                         $amail["body"] = trim($amail["body"]);
00152                         $amail["subject"] = trim($amail["subject"]);
00153                 }
00154 
00155                 return $this->amail[$a_lang];
00156         }
00157         
00166         function send()
00167         {
00168                 global $ilSetting;
00169                 
00170                 $user =& $this->getUser();
00171                 
00172                 if (!$user->getEmail())
00173                 {
00174                         return false;
00175                 }
00176                 
00177                 // determine language and get account mail data
00178                 // fall back to default language if acccount mail data is not given for user language.
00179                 $amail = $this->readAccountMail($user->getLanguage());
00180                 if ($amail["body"] == "" || $amail["subject"] == "")
00181                 {
00182                         $amail = $this->readAccountMail($ilSetting->get("language"));
00183                         $lang = $ilSetting->get("language");
00184                 }
00185                 else
00186                 {
00187                         $lang = $user->getLanguage();
00188                 }
00189 
00190                 // replace placeholders
00191                 $mail_subject = $this->replacePlaceholders($amail["subject"], $user, $amail, $lang);
00192                 $mail_body = $this->replacePlaceholders($amail["body"], $user, $amail, $lang);
00193                 
00194                 // send the mail
00195                 include_once "classes/class.ilMimeMail.php";
00196                 $mmail = new ilMimeMail();
00197                 $mmail->autoCheck(false);
00198                 $mmail->From($ilSetting->get("admin_email"));                                                                                                                                           
00199                 $mmail->Subject($mail_subject);
00200                 $mmail->To($user->getEmail());
00201                 $mmail->Body($mail_body);
00202 /*
00203 echo "<br><br><b>From</b>:".$ilSetting->get("admin_email");
00204 echo "<br><br><b>To</b>:".$user->getEmail();
00205 echo "<br><br><b>Subject</b>:".$mail_subject;
00206 echo "<br><br><b>Body</b>:".$mail_body;
00207 return true;*/
00208                 $mmail->Send();
00209                 
00210                 return true;
00211         }
00212         
00213         function replacePlaceholders($a_string, &$a_user, $a_amail, $a_lang)
00214         {
00215                 global $ilSetting, $tree;
00216                 
00217                 // determine salutation
00218                 $gender_salut = ($a_user->getGender() == "f")
00219                         ? $a_amail["sal_f"]
00220                         : ($a_user->getGender() == "m")
00221                                 ? $a_amail["sal_m"]
00222                                 : $a_amail["sal_g"];
00223                                 
00224                 if (trim($gender_salut) == "")
00225                 {
00226                         $gender_salut = $a_amail["sal_g"];
00227                 }
00228 
00229                 $a_string = str_replace("[MAIL_SALUTATION]", $gender_salut, $a_string);
00230                 $a_string = str_replace("[LOGIN]", $a_user->getLogin(), $a_string);
00231                 $a_string = str_replace("[FIRST_NAME]", $a_user->getFirstname(), $a_string);
00232                 $a_string = str_replace("[LAST_NAME]", $a_user->getLastname(), $a_string);
00233                 $a_string  = str_replace("[PASSWORD]", $this->getUserPassword(), $a_string);
00234                 $a_string  = str_replace("[ILIAS_URL]",
00235                         ILIAS_HTTP_PATH."/login.php?client_id=".CLIENT_ID, $a_string);
00236                 $a_string  = str_replace("[CLIENT_NAME]", CLIENT_NAME, $a_string);
00237                 $a_string  = str_replace("[ADMIN_MAIL]", $ilSetting->get("admin_email"),
00238                         $a_string);
00239                         
00240                 // (no) password sections
00241                 if ($this->getUserPassword() == "")
00242                 {
00243                         $a_string = eregi_replace("\[".$ws."IF_PASSWORD".$ws."\].*\[\/".$ws."IF_PASSWORD".$ws."\]",
00244                                 "", $a_string);
00245                         $a_string = eregi_replace("\[".$ws."IF_NO_PASSWORD".$ws."\](.*)\[\/".$ws."IF_NO_PASSWORD".$ws."\]",
00246                                 "\\1", $a_string);
00247                 }
00248                 else
00249                 {
00250                         $a_string = eregi_replace("\[".$ws."IF_NO_PASSWORD".$ws."\].*\[\/".$ws."IF_NO_PASSWORD".$ws."\]",
00251                                 "", $a_string);
00252                         $a_string = eregi_replace("\[".$ws."IF_PASSWORD".$ws."\](.*)\[\/".$ws."IF_PASSWORD".$ws."\]",
00253                                 "\\1", $a_string);
00254                 }
00255                 
00256                 // target
00257                 $tar = false;
00258                 if ($_GET["target"] != "")
00259                 {
00260                         $tarr = explode("_", $_GET["target"]);
00261                         if ($tree->isInTree($tarr[1]))
00262                         {
00263                                 $obj_id = ilObject::_lookupObjId($tarr[1]);
00264                                 $type = ilObject::_lookupType($obj_id);
00265                                 if ($type == $tarr[0])
00266                                 {
00267                                         $a_string  = str_replace("[TARGET_TITLE]", ilObject::_lookupTitle($obj_id),
00268                                                 $a_string);
00269                                         $a_string  = str_replace("[TARGET]",
00270                                                 ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID."&target=".$_GET["target"],
00271                                                 $a_string);
00272                                                 
00273                                         // this looks complicated, but we may have no initilised $lng object here
00274                                         // if mail is send during user creation in authentication
00275                                         include_once("./classes/class.ilLanguage.php");
00276                                         $a_string  = str_replace("[TARGET_TYPE]",
00277                                                 ilLanguage::_lookupEntry($a_lang, "common", "obj_".$tarr[0]),
00278                                                 $a_string);
00279                                                 
00280                                         $tar = true;
00281                                 }
00282                         }
00283                 }
00284 
00285                 // (no) target section
00286                 if (!$tar)
00287                 {
00288                         $a_string = eregi_replace("\[".$ws."IF_TARGET".$ws."\].*\[\/".$ws."IF_TARGET".$ws."\]",
00289                                 "", $a_string);
00290                 }
00291                 else
00292                 {
00293                         $a_string = eregi_replace("\[".$ws."IF_TARGET".$ws."\](.*)\[\/".$ws."IF_TARGET".$ws."\]",
00294                                 "\\1", $a_string);
00295                 }
00296 
00297                 return $a_string;
00298         }
00299                 
00300 }
00301 ?>

Generated on Fri Dec 13 2013 13:52:06 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1