ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
22  public function __construct()
23  {
24  $dqs = new ilSetting('disk_quota');
25  $rcpt = $dqs->get('summary_rcpt');
26  $rcpt = explode(',', $rcpt);
27  $loginnames = array();
28  foreach($rcpt as $loginname)
29  {
30  $loginname = trim($loginname);
31  if(ilObjUser::_lookupId($loginname))
32  {
33  $loginnames[] = $loginname;
34  }
35  }
36  $this->setRecipients($loginnames);
37 
39  }
40 
48  public function send()
49  {
50  global $ilDB;
51 
52  parent::send();
53 
54  if( count($this->getRecipients()) )
55  {
56  $res = $ilDB->queryf(
57  "SELECT u.usr_id,u.gender,u.firstname,u.lastname,u.login,u.email,u.last_login,u.active,".
58  "u.time_limit_unlimited, ".$ilDB->fromUnixtime("u.time_limit_from").", ".$ilDB->fromUnixtime("u.time_limit_until").",".
59 
60  // Inactive users get the date 0001-01-01 so that they appear
61  // first when the list is sorted by this field. Users with
62  // unlimited access get the date 9999-12-31 so that they appear
63  // last.
64  "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,".
65 
66  " CASE WHEN ".$ilDB->unixTimestamp()." BETWEEN u.time_limit_from AND u.time_limit_until THEN 0 ELSE 1 END expired,".
67  "rq.role_disk_quota, system_role.rol_id role_id, ".
68  "p1.value+0 user_disk_quota,".
69  "p2.value+0 disk_usage, ".
70  "p3.value last_update, ".
71  "p5.value language, ".
72 
73  // We add 0 to some of the values to convert them into a number.
74  // This is needed for correct sorting.
75  "CASE WHEN rq.role_disk_quota+0>p1.value+0 OR p1.value IS NULL THEN rq.role_disk_quota+0 ELSE p1.value+0 END disk_quota ".
76  "FROM usr_data u ".
77 
78  // Fetch the role with the highest disk quota value.
79  "JOIN (SELECT u.usr_id usr_id,MAX(rd.disk_quota) role_disk_quota ".
80  "FROM usr_data u ".
81  "JOIN rbac_ua ua ON ua.usr_id=u.usr_id ".
82  "JOIN rbac_fa fa ON fa.rol_id=ua.rol_id AND fa.parent=%s ".
83  "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 ".
84 
85  // Fetch the system role in order to determine whether the user has unlimited disk quota
86  "LEFT JOIN rbac_ua system_role ON system_role.usr_id=u.usr_id AND system_role.rol_id = %s ".
87 
88  // Fetch the user disk quota from table usr_pref
89  "LEFT JOIN usr_pref p1 ON p1.usr_id=u.usr_id AND p1.keyword = 'disk_quota' ".
90 
91  // Fetch the disk usage from table usr_pref
92  "LEFT JOIN usr_pref p2 ON p2.usr_id=u.usr_id AND p2.keyword = 'disk_usage' ".
93 
94  // Fetch the last update from table usr_pref
95  "LEFT JOIN usr_pref p3 ON p3.usr_id=u.usr_id AND p3.keyword = 'disk_usage.last_update' ".
96 
97  // Fetch the language of the user
98  "LEFT JOIN usr_pref p5 ON p5.usr_id=u.usr_id AND p5.keyword = 'language' ".
99 
100  // Fetch only users who have exceeded their quota, and who have
101  // access, and who have not received a reminder in the past seven days
102  'WHERE (p2.value > p1.value AND p2.value > rq.role_disk_quota) '.
103  'AND (u.active=1 AND (u.time_limit_unlimited = 1 OR '.$ilDB->unixTimestamp().' BETWEEN u.time_limit_from AND u.time_limit_until)) '
104  ,
105  array('integer','integer'),
106  array(ROLE_FOLDER_ID, SYSTEM_ROLE_ID)
107  );
108 
109  $users = array();
110 
111  $counter = 0;
112  while( $row = $ilDB->fetchAssoc($res) )
113  {
114  $details = ilDiskQuotaChecker::_lookupDiskUsage($row['usr_id']);
115 
116  $users[$counter]['disk_quota'] = $row['disk_quota'];
117  $users[$counter]['disk_usage'] = $details['disk_usage'];
118  $users[$counter]['email'] = $row['email'];
119  $users[$counter]['firstname'] = $row['firstname'];
120  $users[$counter]['lastname'] = $row['lastname'];
121 
122  ++$counter;
123  }
124 
125  if( count($users) ) foreach($this->getRecipients() as $rcp)
126  {
127  $usrId = ilObjUser::_lookupId($rcp);
128 
129  $this->initLanguage($usrId);
130  $this->initMail();
131 
132  $this->setSubject($this->getLanguage()->txt('disk_quota_summary_subject'));
133 
134  $this->setBody(ilMail::getSalutation($usrId, $this->getLanguage()));
135 
136  $this->appendBody("\n\n");
137  $this->appendBody($this->getLanguage()->txt('disk_quota_exceeded_headline'));
138  $this->appendBody("\n\n");
139 
140  $first = true;
141  $counter = 0;
142  $numUsers = count($users);
143  foreach($users as $user)
144  {
145  if(!$first)
146  {
147  $this->appendBody("\n---------------------------------------------------\n\n");
148  }
149 
150  $this->appendBody(
151  $this->getLanguage()->txt('fullname').': '.
152  $user['lastname'].', '.$user['firstname']
153  ."\n");
154  $this->appendBody(
155  $this->getLanguage()->txt('email').': '.
156  $user['email']
157  ."\n");
158  $this->appendBody(
159  $this->getLanguage()->txt('disk_quota').': '.
160  ilFormat::formatSize($user['disk_quota'],'short', $this->getLanguage())
161  ."\n");
162  $this->appendBody(
163  $this->getLanguage()->txt('currently_used_disk_space').': '.
164  ilFormat::formatSize($user['disk_usage'],'short', $this->getLanguage())
165  ."\n");
166 
167  $this->appendBody(
168  $this->getLanguage()->txt('usrf_profile_link').': '.
169  ilUtil::_getHttpPath().'/goto.php?target=usrf&client_id='.CLIENT_ID
170  );
171 
172  if($counter < $numUsers - 1)
173  {
174  $this->appendBody("\n");
175  }
176 
177  ++$counter;
178  $first = false;
179  }
180 
181  $this->getMail()->appendInstallationSignature(true);
182 
183  $this->sendMail(array($rcp), array('system'), false);
184  }
185  }
186  }
187 }