ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDiskQuotaReminderMail.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 {
16 
20  private $data;
21 
22  private $tmp_lng;
23 
28  public function __construct()
29  {
30  }
31 
32  public function useLangVariablesAsFallback($a_status)
33  {
34  $this->lang_variables_as_fallback = $a_status;
35  }
36 
38  {
40  }
41 
61  function setData($a_data)
62  {
63  $this->data = $a_data;
64  }
65 
69  function reset()
70  {
71  unset($this->data);
72  }
73 
77  function readMailTemplate($a_lang)
78  {
79  if (!is_array($this->amail[$a_lang]))
80  {
81  require_once('./Services/WebDAV/classes/class.ilObjDiskQuotaSettings.php');
82  $this->amail[$a_lang] = ilObjDiskQuotaSettings::_lookupReminderMailTemplate($a_lang);
83  $this->amail["body"] = trim($this->amail["body"]);
84  $this->amail["subject"] = trim($this->amail["subject"]);
85  }
86 
87  return $this->amail[$a_lang];
88  }
89 
98  function send()
99  {
100  global $ilSetting;
101 
102  // determine language and get account mail data
103  // fall back to default language if acccount mail data is not given for user language.
104  $amail = $this->readMailTemplate($this->data['language']);
105  if ($amail['body'] == '' || $amail['subject'] == '')
106  {
107  $amail = $this->readMailTemplate($ilSetting->get('language'));
108  $lang = $ilSetting->get('language');
109  }
110  else
111  {
112  $lang = $this->data['language'];
113  }
114 
115  // fallback if mail data is still not given
116  if($this->areLangVariablesUsedAsFallback() &&
117  ($amail['body'] == '' || $amail['subject'] == ''))
118  {
119  $lang = $this->data['language'];
120  $tmp_lang = $this->getLng($lang);
121 
122  // mail subject
123  $mail_subject = $tmp_lang->txt('disk_quota_mail_subject');
124 
125  // mail body
126  $mail_body = $tmp_lang->txt('disk_quota_mail_body_salutation').' '.$data['firstname'].' '.$data['lastname'].",\n\n".
127  $tmp_lang->txt('disk_quota_body_text1')."\n\n".
128  $tmp_lang->txt('disk_quota_body_text2')."\n".
129  ILIAS_HTTP_PATH.'/login.php?client_id='.CLIENT_ID."\n";
130  $mail_body .= $tmp_lang->txt('login').': '.$data['firstname']."\n";
131  $mail_body.= "\n";
132  $mail_body .= $tmp_lang->txt('disk_quota_mail_body_text3')."\n\r";
133  //$mail_body .= $user->getProfileAsString($tmp_lang);
134  }
135  else
136  {
137  // replace placeholders
138  $mail_subject = $this->replacePlaceholders($amail['subject'], $amail, $lang);
139  $mail_body = $this->replacePlaceholders($amail['body'], $amail, $lang);
140  }
141 
142  // send the mail
143  include_once 'Services/Mail/classes/class.ilMimeMail.php';
144  $mmail = new ilMimeMail();
145  $mmail->autoCheck(false);
146  $mmail->From($ilSetting->get('admin_email'));
147  $mmail->Subject($mail_subject);
148  $mmail->To($this->data['email']);
149  $mmail->Body($mail_body);
150  $mmail->Send();
151 
152  include_once 'Services/Mail/classes/class.ilMail.php';
153  $mail = new ilMail($_SESSION["AccountId"]);
154  $mail->sendMail($this->data['login'],"","",$mail_subject,$mail_body,array(),array("normal"));
155 
156 
157 
158  return true;
159  }
160 
161  private function getLng($a_lang) {
162  if ($this->tmp_lng == null || $this->tmp_lng->lang_key != $a_lang)
163  {
164  $this->tmp_lng = new ilLanguage($lang);
165  }
166  return $this->tmp_lng;
167  }
168 
169  function replacePlaceholders($a_string, $a_amail, $a_lang)
170  {
171  global $ilSetting, $tree;
172 
173  $tmp_lang = $this->getLng($a_lang);
174 
175  // determine salutation
176  switch ($this->data['gender'])
177  {
178  case "f" : $gender_salut = $a_amail["sal_f"];
179  break;
180  case "m" : $gender_salut = $a_amail["sal_m"];
181  break;
182  default : $gender_salut = $a_amail["sal_g"];
183  }
184  $gender_salut = trim($gender_salut);
185 
186  $a_string = str_replace("[MAIL_SALUTATION]", $gender_salut, $a_string);
187  $a_string = str_replace("[LOGIN]", $this->data['login'], $a_string);
188  $a_string = str_replace("[FIRST_NAME]", $this->data['firstname'], $a_string);
189  $a_string = str_replace("[LAST_NAME]", $this->data['lastname'], $a_string);
190  // BEGIN Mail Include E-Mail Address in account mail
191  $a_string = str_replace("[EMAIL]", $this->data['email'], $a_string);
192  $a_string = str_replace("[ILIAS_URL]",
193  ILIAS_HTTP_PATH."/login.php?client_id=".CLIENT_ID, $a_string);
194  $a_string = str_replace("[CLIENT_NAME]", CLIENT_NAME, $a_string);
195  $a_string = str_replace("[ADMIN_MAIL]", $ilSetting->get("admin_email"),
196  $a_string);
197 
198  require_once './Services/Utilities/classes/class.ilFormat.php';
199  $a_string = str_replace("[DISK_QUOTA]", ilFormat::formatSize($this->data['disk_quota'],'short',$tmp_lang), $a_string);
200  $a_string = str_replace("[DISK_USAGE]", ilFormat::formatSize($this->data['disk_usage'],'short',$tmp_lang), $a_string);
201 
202  $disk_usage_details = '';
203  foreach ($this->data['disk_usage_details'] as $details)
204  {
205  $disk_usage_details .= ilFormat::formatFloat($details['count'],0,true,$tmp_lang).' '.$tmp_lang->txt($details['type']).' '.ilFormat::formatSize($details['size'],'short',$tmp_lang)."\n";
206  }
207  $a_string = str_replace("[DISK_USAGE_DETAILS]", $disk_usage_details, $a_string);
208 
209  return $a_string;
210  }
211 
212 }
213 ?>