ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDiskQuotaReminderMail.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
36 
40  private $data;
41 
42  private $tmp_lng;
43 
49  {
50  }
51 
52  public function useLangVariablesAsFallback($a_status)
53  {
54  $this->lang_variables_as_fallback = $a_status;
55  }
56 
58  {
60  }
61 
81  function setData($a_data)
82  {
83  $this->data = $a_data;
84  }
85 
89  function reset()
90  {
91  unset($this->data);
92  }
93 
97  function readMailTemplate($a_lang)
98  {
99  if (!is_array($this->amail[$a_lang]))
100  {
101  require_once('./Services/WebDAV/classes/class.ilObjDiskQuotaSettings.php');
102  $this->amail[$a_lang] = ilObjDiskQuotaSettings::_lookupReminderMailTemplate($a_lang);
103  $this->amail["body"] = trim($this->amail["body"]);
104  $this->amail["subject"] = trim($this->amail["subject"]);
105  }
106 
107  return $this->amail[$a_lang];
108  }
109 
118  function send()
119  {
120  global $ilSetting;
121 
122  // determine language and get account mail data
123  // fall back to default language if acccount mail data is not given for user language.
124  $amail = $this->readMailTemplate($this->data['language']);
125  if ($amail['body'] == '' || $amail['subject'] == '')
126  {
127  $amail = $this->readMailTemplate($ilSetting->get('language'));
128  $lang = $ilSetting->get('language');
129  }
130  else
131  {
132  $lang = $this->data['language'];
133  }
134 
135  // fallback if mail data is still not given
136  if($this->areLangVariablesUsedAsFallback() &&
137  ($amail['body'] == '' || $amail['subject'] == ''))
138  {
139  $lang = $this->data['language'];
140  $tmp_lang = $this->getLng($lang);
141 
142  // mail subject
143  $mail_subject = $tmp_lang->txt('disk_quota_mail_subject');
144 
145  // mail body
146  $mail_body = $tmp_lang->txt('disk_quota_mail_body_salutation').' '.$data['firstname'].' '.$data['lastname'].",\n\n".
147  $tmp_lang->txt('disk_quota_body_text1')."\n\n".
148  $tmp_lang->txt('disk_quota_body_text2')."\n".
149  ILIAS_HTTP_PATH.'/login.php?client_id='.CLIENT_ID."\n";
150  $mail_body .= $tmp_lang->txt('login').': '.$data['firstname']."\n";
151  $mail_body.= "\n";
152  $mail_body .= $tmp_lang->txt('disk_quota_mail_body_text3')."\n\r";
153  //$mail_body .= $user->getProfileAsString($tmp_lang);
154  }
155  else
156  {
157  // replace placeholders
158  $mail_subject = $this->replacePlaceholders($amail['subject'], $amail, $lang);
159  $mail_body = $this->replacePlaceholders($amail['body'], $amail, $lang);
160  }
161 
162  // send the mail
163  include_once 'Services/Mail/classes/class.ilMimeMail.php';
164  $mmail = new ilMimeMail();
165  $mmail->autoCheck(false);
166  $mmail->From($ilSetting->get('admin_email'));
167  $mmail->Subject($mail_subject);
168  $mmail->To($this->data['email']);
169  $mmail->Body($mail_body);
170  $mmail->Send();
171 
172  include_once 'Services/Mail/classes/class.ilMail.php';
173  $mail = new ilMail($_SESSION["AccountId"]);
174  $mail->sendMail($this->data['login'],"","",$mail_subject,$mail_body,array(),array("normal"));
175 
176 
177 
178  return true;
179  }
180 
181  private function getLng($a_lang) {
182  if ($this->tmp_lng == null || $this->tmp_lng->lang_key != $a_lang)
183  {
184  $this->tmp_lng = new ilLanguage($lang);
185  }
186  return $this->tmp_lng;
187  }
188 
189  function replacePlaceholders($a_string, $a_amail, $a_lang)
190  {
191  global $ilSetting, $tree;
192 
193  $tmp_lang = $this->getLng($a_lang);
194 
195  // determine salutation
196  switch ($this->data['gender'])
197  {
198  case "f" : $gender_salut = $a_amail["sal_f"];
199  break;
200  case "m" : $gender_salut = $a_amail["sal_m"];
201  break;
202  default : $gender_salut = $a_amail["sal_g"];
203  }
204  $gender_salut = trim($gender_salut);
205 
206  $a_string = str_replace("[MAIL_SALUTATION]", $gender_salut, $a_string);
207  $a_string = str_replace("[LOGIN]", $this->data['login'], $a_string);
208  $a_string = str_replace("[FIRST_NAME]", $this->data['firstname'], $a_string);
209  $a_string = str_replace("[LAST_NAME]", $this->data['lastname'], $a_string);
210  // BEGIN Mail Include E-Mail Address in account mail
211  $a_string = str_replace("[EMAIL]", $this->data['email'], $a_string);
212  $a_string = str_replace("[ILIAS_URL]",
213  ILIAS_HTTP_PATH."/login.php?client_id=".CLIENT_ID, $a_string);
214  $a_string = str_replace("[CLIENT_NAME]", CLIENT_NAME, $a_string);
215  $a_string = str_replace("[ADMIN_MAIL]", $ilSetting->get("admin_email"),
216  $a_string);
217 
218  require_once 'classes/class.ilFormat.php';
219  $a_string = str_replace("[DISK_QUOTA]", ilFormat::formatSize($this->data['disk_quota'],'short',$tmp_lang), $a_string);
220  $a_string = str_replace("[DISK_USAGE]", ilFormat::formatSize($this->data['disk_usage'],'short',$tmp_lang), $a_string);
221 
222  $disk_usage_details = '';
223  foreach ($this->data['disk_usage_details'] as $details)
224  {
225  $disk_usage_details .= ilFormat::formatFloat($details['count'],0,true,$tmp_lang).' '.$tmp_lang->txt($details['type']).' '.ilFormat::formatSize($details['size'],'short',$tmp_lang)."\n";
226  }
227  $a_string = str_replace("[DISK_USAGE_DETAILS]", $disk_usage_details, $a_string);
228 
229  return $a_string;
230  }
231 
232 }
233 ?>