ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDiskQuotaSummaryNotification.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Mail/classes/class.ilMailNotification.php';
5 include_once 'Services/WebDAV/classes/class.ilDiskQuotaChecker.php';
6 
14 {
18  public function __construct($a_is_personal_workspace = false)
19  {
20  $dqs = new ilSetting('disk_quota');
21  $rcpt = $dqs->get('summary_rcpt');
22  $rcpt = explode(',', $rcpt);
23  $loginnames = array();
24  foreach($rcpt as $loginname)
25  {
26  $loginname = trim($loginname);
27  if(ilObjUser::_lookupId($loginname))
28  {
29  $loginnames[] = $loginname;
30  }
31  }
32  $this->setRecipients($loginnames);
33 
34  parent::__construct($a_is_personal_workspace);
35  }
36 
44  public function send()
45  {
46  global $ilDB;
47 
48  // parent::send();
49 
50  if( count($this->getRecipients()) )
51  {
52  $res = $ilDB->queryf(
53  "SELECT u.usr_id,u.gender,u.firstname,u.lastname,u.login,u.email,u.last_login,u.active,".
54  "u.time_limit_unlimited, ".$ilDB->fromUnixtime("u.time_limit_from").", ".$ilDB->fromUnixtime("u.time_limit_until").",".
55 
56  // Inactive users get the date 0001-01-01 so that they appear
57  // first when the list is sorted by this field. Users with
58  // unlimited access get the date 9999-12-31 so that they appear
59  // last.
60  "CASE WHEN u.active = 0 THEN '0001-01-01' ELSE CASE WHEN u.time_limit_unlimited=1 THEN '9999-12-31' ELSE ".$ilDB->fromUnixtime("u.time_limit_until")." END END access_until,".
61 
62  " CASE WHEN ".$ilDB->unixTimestamp()." BETWEEN u.time_limit_from AND u.time_limit_until THEN 0 ELSE 1 END expired,".
63  "rq.role_disk_quota, system_role.rol_id role_id, ".
64  "p1.value+0 user_disk_quota,".
65  "p2.value+0 disk_usage, ".
66  "p3.value last_update, ".
67  "p5.value language, ".
68 
69  // We add 0 to some of the values to convert them into a number.
70  // This is needed for correct sorting.
71  "CASE WHEN rq.role_disk_quota>p1.value+0 OR p1.value IS NULL THEN rq.role_disk_quota ELSE p1.value+0 END disk_quota ".
72  "FROM usr_data u ".
73 
74  // Fetch the role with the highest disk quota value.
75  "JOIN (SELECT u.usr_id usr_id,MAX(rd.disk_quota) role_disk_quota ".
76  "FROM usr_data u ".
77  "JOIN rbac_ua ua ON ua.usr_id=u.usr_id ".
78  "JOIN rbac_fa fa ON fa.rol_id=ua.rol_id AND fa.parent=%s ".
79  "JOIN role_data rd ON rd.role_id=ua.rol_id WHERE u.usr_id=ua.usr_id GROUP BY u.usr_id) rq ON rq.usr_id=u.usr_id ".
80 
81  // Fetch the system role in order to determine whether the user has unlimited disk quota
82  "LEFT JOIN rbac_ua system_role ON system_role.usr_id=u.usr_id AND system_role.rol_id = %s ".
83 
84  // Fetch the user disk quota from table usr_pref
85  "LEFT JOIN usr_pref p1 ON p1.usr_id=u.usr_id AND p1.keyword = 'disk_quota' ".
86 
87  // Fetch the disk usage from table usr_pref
88  "LEFT JOIN usr_pref p2 ON p2.usr_id=u.usr_id AND p2.keyword = 'disk_usage' ".
89 
90  // Fetch the last update from table usr_pref
91  "LEFT JOIN usr_pref p3 ON p3.usr_id=u.usr_id AND p3.keyword = 'disk_usage.last_update' ".
92 
93  // Fetch the language of the user
94  "LEFT JOIN usr_pref p5 ON p5.usr_id=u.usr_id AND p5.keyword = 'language' ".
95 
96  // Fetch only users who have exceeded their quota, and who have
97  // access, and who have not received a reminder in the past seven days
98  // #8554 / #10301
99  'WHERE (((p1.value+0 > rq.role_disk_quota OR rq.role_disk_quota IS NULL) AND p2.value+0 > p1.value+0) OR
100  ((rq.role_disk_quota > p1.value+0 OR p1.value IS NULL) AND p2.value+0 > rq.role_disk_quota)) '.
101  'AND (u.active=1 AND (u.time_limit_unlimited = 1 OR '.$ilDB->unixTimestamp().' BETWEEN u.time_limit_from AND u.time_limit_until)) '
102  ,
103  array('integer','integer'),
104  array(ROLE_FOLDER_ID, SYSTEM_ROLE_ID)
105  );
106 
107  $users = array();
108 
109  $counter = 0;
110  while( $row = $ilDB->fetchAssoc($res) )
111  {
112  $details = ilDiskQuotaChecker::_lookupDiskUsage($row['usr_id']);
113 
114  $users[$counter]['disk_quota'] = $row['disk_quota'];
115  $users[$counter]['disk_usage'] = $details['disk_usage'];
116  $users[$counter]['email'] = $row['email'];
117  $users[$counter]['firstname'] = $row['firstname'];
118  $users[$counter]['lastname'] = $row['lastname'];
119 
120  ++$counter;
121  }
122 
123  if( count($users) ) foreach($this->getRecipients() as $rcp)
124  {
125  $usrId = ilObjUser::_lookupId($rcp);
126 
127  $this->initLanguage($usrId);
128  $this->initMail();
129 
130  $this->setSubject($this->getLanguage()->txt('disk_quota_summary_subject'));
131 
132  $this->setBody(ilMail::getSalutation($usrId, $this->getLanguage()));
133 
134  $this->appendBody("\n\n");
135  $this->appendBody($this->getLanguage()->txt('disk_quota_exceeded_headline'));
136  $this->appendBody("\n\n");
137 
138  $first = true;
139  $counter = 0;
140  $numUsers = count($users);
141  foreach($users as $user)
142  {
143  if(!$first)
144  {
145  $this->appendBody("\n---------------------------------------------------\n\n");
146  }
147 
148  $this->appendBody(
149  $this->getLanguage()->txt('fullname').': '.
150  $user['lastname'].', '.$user['firstname']
151  ."\n");
152  $this->appendBody(
153  $this->getLanguage()->txt('email').': '.
154  $user['email']
155  ."\n");
156  $this->appendBody(
157  $this->getLanguage()->txt('disk_quota').': '.
158  ilUtil::formatSize($user['disk_quota'],'short', $this->getLanguage())
159  ."\n");
160  $this->appendBody(
161  $this->getLanguage()->txt('currently_used_disk_space').': '.
162  ilUtil::formatSize($user['disk_usage'],'short', $this->getLanguage())
163  ."\n");
164 
165  $this->appendBody(
166  $this->getLanguage()->txt('usrf_profile_link').': '.
167  ilUtil::_getHttpPath().'/goto.php?target=usrf&client_id='.CLIENT_ID
168  );
169 
170  if($counter < $numUsers - 1)
171  {
172  $this->appendBody("\n");
173  }
174 
175  ++$counter;
176  $first = false;
177  }
178 
179  $this->getMail()->appendInstallationSignature(true);
180 
181  $this->sendMail(array($rcp), array('system'), false);
182  }
183  }
184  }
185 }
ILIAS Setting Class.
initLanguage($a_usr_id)
Init language.
static _lookupId($a_user_str)
Lookup id by login.
__construct($a_is_personal_workspace=false)
{}
$counter
Base class for course/group mail notifications.
Create styles array
The data for the language used.
sendMail(array $a_rcp, $a_type, $a_parse_recipients=true)
getRecipients()
get array of recipients
static _lookupDiskUsage($a_user_id)
Gets the disk usage info for the specified user account.
static _getHttpPath()
global $ilDB
appendBody($a_body)
Append body text.
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.