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

Services/Mail/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                 unset($this->u_password);
00138                 unset($this->user);
00139                 unset($this->target);
00140         }
00141         
00145         function readAccountMail($a_lang)
00146         {
00147                 if (!is_array($this->amail[$a_lang]))
00148                 {
00149                         include_once('./Services/User/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 "Services/Mail/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                 switch ($a_user->getGender())
00219                 {
00220                         case "f" :      $gender_salut = $a_amail["sal_f"];
00221                                                 break;
00222                         case "m" :      $gender_salut = $a_amail["sal_m"];
00223                                                 break;
00224                         default :       $gender_salut = $a_amail["sal_g"];
00225         }
00226         $gender_salut = trim($gender_salut);
00227 
00228                 $a_string = str_replace("[MAIL_SALUTATION]", $gender_salut, $a_string);
00229                 $a_string = str_replace("[LOGIN]", $a_user->getLogin(), $a_string);
00230                 $a_string = str_replace("[FIRST_NAME]", $a_user->getFirstname(), $a_string);
00231                 $a_string = str_replace("[LAST_NAME]", $a_user->getLastname(), $a_string);
00232                 $a_string  = str_replace("[PASSWORD]", $this->getUserPassword(), $a_string);
00233                 $a_string  = str_replace("[ILIAS_URL]",
00234                         ILIAS_HTTP_PATH."/login.php?client_id=".CLIENT_ID, $a_string);
00235                 $a_string  = str_replace("[CLIENT_NAME]", CLIENT_NAME, $a_string);
00236                 $a_string  = str_replace("[ADMIN_MAIL]", $ilSetting->get("admin_email"),
00237                         $a_string);
00238                         
00239                 // (no) password sections
00240                 if ($this->getUserPassword() == "")
00241                 {
00242                         $a_string = eregi_replace("\[".$ws."IF_PASSWORD".$ws."\].*\[\/".$ws."IF_PASSWORD".$ws."\]",
00243                                 "", $a_string);
00244                         $a_string = eregi_replace("\[".$ws."IF_NO_PASSWORD".$ws."\](.*)\[\/".$ws."IF_NO_PASSWORD".$ws."\]",
00245                                 "\\1", $a_string);
00246                 }
00247                 else
00248                 {
00249                         $a_string = eregi_replace("\[".$ws."IF_NO_PASSWORD".$ws."\].*\[\/".$ws."IF_NO_PASSWORD".$ws."\]",
00250                                 "", $a_string);
00251                         $a_string = eregi_replace("\[".$ws."IF_PASSWORD".$ws."\](.*)\[\/".$ws."IF_PASSWORD".$ws."\]",
00252                                 "\\1", $a_string);
00253                 }
00254                 
00255                 // target
00256                 $tar = false;
00257                 if ($_GET["target"] != "")
00258                 {
00259                         $tarr = explode("_", $_GET["target"]);
00260                         if ($tree->isInTree($tarr[1]))
00261                         {
00262                                 $obj_id = ilObject::_lookupObjId($tarr[1]);
00263                                 $type = ilObject::_lookupType($obj_id);
00264                                 if ($type == $tarr[0])
00265                                 {
00266                                         $a_string  = str_replace("[TARGET_TITLE]", ilObject::_lookupTitle($obj_id),
00267                                                 $a_string);
00268                                         $a_string  = str_replace("[TARGET]",
00269                                                 ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID."&target=".$_GET["target"],
00270                                                 $a_string);
00271                                                 
00272                                         // this looks complicated, but we may have no initilised $lng object here
00273                                         // if mail is send during user creation in authentication
00274                                         include_once("./Services/Language/classes/class.ilLanguage.php");
00275                                         $a_string  = str_replace("[TARGET_TYPE]",
00276                                                 ilLanguage::_lookupEntry($a_lang, "common", "obj_".$tarr[0]),
00277                                                 $a_string);
00278                                                 
00279                                         $tar = true;
00280                                 }
00281                         }
00282                 }
00283 
00284                 // (no) target section
00285                 if (!$tar)
00286                 {
00287                         $a_string = eregi_replace("\[".$ws."IF_TARGET".$ws."\].*\[\/".$ws."IF_TARGET".$ws."\]",
00288                                 "", $a_string);
00289                 }
00290                 else
00291                 {
00292                         $a_string = eregi_replace("\[".$ws."IF_TARGET".$ws."\](.*)\[\/".$ws."IF_TARGET".$ws."\]",
00293                                 "\\1", $a_string);
00294                 }
00295 
00296                 return $a_string;
00297         }
00298                 
00299 }
00300 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1