ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public function setData($a_data)
62  {
63  $this->data = $a_data;
64  }
65 
69  public function reset()
70  {
71  unset($this->data);
72  }
73 
77  public function readMailTemplate($a_lang)
78  {
79  if (!is_array($this->amail[$a_lang])) {
80  require_once('./Services/WebDAV/classes/class.ilObjDiskQuotaSettings.php');
81  $this->amail[$a_lang] = ilObjDiskQuotaSettings::_lookupReminderMailTemplate($a_lang);
82  $this->amail["body"] = trim($this->amail["body"]);
83  $this->amail["subject"] = trim($this->amail["subject"]);
84  }
85 
86  return $this->amail[$a_lang];
87  }
88 
97  public function send()
98  {
99  global $DIC;
100 
101  // determine language and get account mail data
102  // fall back to default language if acccount mail data is not given for user language.
103  $amail = $this->readMailTemplate($this->data['language']);
104  if ($amail['body'] == '' || $amail['subject'] == '') {
105  $amail = $this->readMailTemplate($DIC->settings()->get('language'));
106  $lang = $DIC->settings()->get('language');
107  } else {
108  $lang = $this->data['language'];
109  }
110 
111  // fallback if mail data is still not given
112  if ($this->areLangVariablesUsedAsFallback() &&
113  ($amail['body'] == '' || $amail['subject'] == '')) {
114  $lang = $this->data['language'];
115  $tmp_lang = $this->getLng($lang);
116 
117  // mail subject
118  $mail_subject = $tmp_lang->txt('disk_quota_mail_subject');
119 
120  // mail body
121  $mail_body = $tmp_lang->txt('disk_quota_mail_body_salutation') . ' ' . $data['firstname'] . ' ' . $data['lastname'] . ",\n\n" .
122  $tmp_lang->txt('disk_quota_body_text1') . "\n\n" .
123  $tmp_lang->txt('disk_quota_body_text2') . "\n" .
124  ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID . "\n";
125  $mail_body .= $tmp_lang->txt('login') . ': ' . $data['firstname'] . "\n";
126  $mail_body.= "\n";
127  $mail_body .= $tmp_lang->txt('disk_quota_mail_body_text3') . "\n\r";
128  //$mail_body .= $user->getProfileAsString($tmp_lang);
129  } else {
130  // replace placeholders
131  $mail_subject = $this->replacePlaceholders($amail['subject'], $amail, $lang);
132  $mail_body = $this->replacePlaceholders($amail['body'], $amail, $lang);
133  }
134 
136  $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
137 
138  // send the mail
139  include_once 'Services/Mail/classes/class.ilMimeMail.php';
140  $mmail = new ilMimeMail();
141  $mmail->From($senderFactory->system());
142  $mmail->Subject($mail_subject);
143  $mmail->To($this->data['email']);
144  $mmail->Body($mail_body);
145  $mmail->Send();
146 
147  include_once 'Services/Mail/classes/class.ilMail.php';
148  $mail = new ilMail($GLOBALS['DIC']['ilUser']->getId());
149  $mail->sendMail($this->data['login'], "", "", $mail_subject, $mail_body, array(), array("normal"));
150 
151 
152 
153  return true;
154  }
155 
156  private function getLng($a_lang)
157  {
158  if ($this->tmp_lng == null || $this->tmp_lng->lang_key != $a_lang) {
159  $this->tmp_lng = new ilLanguage($lang);
160  }
161  return $this->tmp_lng;
162  }
163 
164  public function replacePlaceholders($a_string, $a_amail, $a_lang)
165  {
166  global $DIC;
167 
168  $tmp_lang = $this->getLng($a_lang);
169 
170  // determine salutation
171  switch ($this->data['gender']) {
172  case "f": $gender_salut = $a_amail["sal_f"];
173  break;
174  case "m": $gender_salut = $a_amail["sal_m"];
175  break;
176  default: $gender_salut = $a_amail["sal_g"];
177  }
178  $gender_salut = trim($gender_salut);
179 
180  $a_string = str_replace("[MAIL_SALUTATION]", $gender_salut, $a_string);
181  $a_string = str_replace("[LOGIN]", $this->data['login'], $a_string);
182  $a_string = str_replace("[FIRST_NAME]", $this->data['firstname'], $a_string);
183  $a_string = str_replace("[LAST_NAME]", $this->data['lastname'], $a_string);
184  // BEGIN Mail Include E-Mail Address in account mail
185  $a_string = str_replace("[EMAIL]", $this->data['email'], $a_string);
186  $a_string = str_replace(
187  "[ILIAS_URL]",
188  ILIAS_HTTP_PATH . "/login.php?client_id=" . CLIENT_ID,
189  $a_string
190  );
191  $a_string = str_replace("[CLIENT_NAME]", CLIENT_NAME, $a_string);
192  $a_string = str_replace(
193  "[ADMIN_MAIL]",
194  $DIC->settings()->get("admin_email"),
195  $a_string
196  );
197 
198  $a_string = str_replace("[DISK_QUOTA]", ilUtil::formatSize($this->data['disk_quota'], 'short', $tmp_lang), $a_string);
199  $a_string = str_replace("[DISK_USAGE]", ilUtil::formatSize($this->data['disk_usage'], 'short', $tmp_lang), $a_string);
200 
201  $disk_usage_details = '';
202  foreach ($this->data['disk_usage_details'] as $details) {
203  $disk_usage_details .= number_format($details['count'], 0) . ' ' .
204  $tmp_lang->txt($details['type']) . ' ' .
205  ilUtil::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 }
Add some data
global $DIC
Definition: saml.php:7
static _lookupReminderMailTemplate($a_lang)
Looks up the mail template for the specified language.
readMailTemplate($a_lang)
get new mail template array (including subject and message body)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
setData($a_data)
Sets used to fill in the placeholders in the mail.
Class ilMimeMail.
This class handles base functions for mail handling.
Create styles array
The data for the language used.
Class ilDiskQuotaReminderMail.
replacePlaceholders($a_string, $a_amail, $a_lang)
language handling
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
$data
Data used to fill in the placeholders in the mail.