76 $res = $ilDB->queryf(
"SELECT keyword, value ".
79 "AND keyword IN ('disk_quota', 'disk_quota_last_reminder')",
84 switch (
$row->keyword)
87 $info[
'user_disk_quota'] =
$row->value;
89 case 'disk_quota_last_reminder' :
90 $info[
'last_reminder'] =
$row->value;
101 $res = $ilDB->queryf(
"SELECT rd.role_id, rd.disk_quota, od.title ".
103 "JOIN rbac_fa fa ON fa.rol_id=ua.rol_id AND fa.parent = %s ".
104 "JOIN role_data rd ON ua.rol_id=rd.role_id ".
105 "JOIN object_data od ON od.obj_id=rd.role_id ".
106 "WHERE ua.usr_id = %s ".
107 "ORDER BY disk_quota DESC, role_id ASC",
108 array(
'integer',
'integer'),
109 array(ROLE_FOLDER_ID, $a_user_id));
112 $info[
'role_id'] =
$row->role_id;
113 $info[
'role_title'] =
$row->title;
117 $info[
'role_disk_quota'] = (
$row->role_id == SYSTEM_ROLE_ID) ? -log(0) :
$row->disk_quota;
118 $info[
'disk_quota'] = max($info[
'user_disk_quota'], $info[
'role_disk_quota']);
147 $res = $ilDB->query(
"SELECT keyword, value ".
149 "WHERE usr_id = ".$ilDB->quote($a_user_id,
'integer').
" ".
150 "AND ".$ilDB->like(
"keyword",
"text",
'disk\\_usage%')
154 switch (
$row->keyword)
156 case 'disk_usage.last_update' :
157 $info[
'last_update'] =
$row->value;
161 $info[
'disk_usage'] =
$row->value;
170 preg_match(
'/^disk_usage\\.([^.]+)\\.([^.]+)/',
$row->keyword, $matches);
175 $detail_data = $details[
$type];
176 if ($detail_data == null)
178 $detail_data = array(
'type'=>
$type);
180 $detail_data[$key] =
$row->value;
182 $details[
$type] = $detail_data;
186 $info[
'details'] = $details;
219 public static function _fetchDiskQuotaReport($a_usage_filter = 3, $a_access_filter = 1, $a_order_column=
'disk_usage',$a_order_by=
'desc')
224 if (! $a_order_column) {
225 $a_order_column =
'disk_usage';
228 switch ($a_usage_filter) {
233 $where_clause =
'WHERE (p2.value IS NULL) ';
237 $where_clause =
'WHERE (p2.value > 0) ';
240 $where_clause =
'WHERE (p2.value > p1.value AND p2.value > rq.role_disk_quota) ';
243 switch ($a_access_filter) {
249 $where_clause .= ($where_clause ==
'' ?
'WHERE ' :
' AND ' ).
250 '(u.active=1 AND (u.time_limit_unlimited = 1 OR '.$ilDB->unixTimestamp().
' BETWEEN u.time_limit_from AND u.time_limit_until)) ';
253 $where_clause .= ($where_clause ==
'' ?
'WHERE ' :
' AND ' ).
254 '(u.active=0 OR (u.time_limit_unlimited IS NULL AND '.$ilDB->unixTimestamp().
' NOT BETWEEN u.time_limit_from AND u.time_limit_until)) ';
258 $res = $ilDB->queryf(
259 "SELECT u.usr_id,u.firstname,u.lastname,u.login,u.email,u.last_login,u.active,".
260 "u.time_limit_unlimited, ".$ilDB->fromUnixtime(
"u.time_limit_from").
", ".$ilDB->fromUnixtime(
"u.time_limit_until").
",".
266 "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,".
268 "CASE WHEN ".$ilDB->unixTimestamp().
" BETWEEN u.time_limit_from AND u.time_limit_until THEN 0 ELSE 1 END expired,".
269 "rq.role_disk_quota, system_role.rol_id role_id, ".
270 "p1.value+0 user_disk_quota,".
271 "p2.value+0 disk_usage, ".
272 "p3.value last_update, ".
273 "p4.value last_reminder, ".
277 "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 ".
281 "JOIN (SELECT u.usr_id usr_id,MAX(rd.disk_quota) role_disk_quota ".
283 "JOIN rbac_ua ua ON ua.usr_id=u.usr_id ".
284 "JOIN rbac_fa fa ON fa.rol_id=ua.rol_id AND fa.parent=%s ".
285 "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 ".
288 "LEFT JOIN rbac_ua system_role ON system_role.usr_id=u.usr_id AND system_role.rol_id = %s ".
291 "LEFT JOIN usr_pref p1 ON p1.usr_id=u.usr_id AND p1.keyword = 'disk_quota' ".
294 "LEFT JOIN usr_pref p2 ON p2.usr_id=u.usr_id AND p2.keyword = 'disk_usage' ".
297 "LEFT JOIN usr_pref p3 ON p3.usr_id=u.usr_id AND p3.keyword = 'disk_usage.last_update' ".
300 "LEFT JOIN usr_pref p4 ON p4.usr_id=u.usr_id AND p4.keyword = 'disk_quota_last_reminder' ".
303 "ORDER BY ".$a_order_column.
" ".($a_order_by==
'asc'?
' ASC':
' DESC').
", ".
304 "lastname, firstname, login"
306 array(
'integer',
'integer'),
307 array(ROLE_FOLDER_ID, SYSTEM_ROLE_ID)
309 $previous_usr_id = null;
311 if ($previous_usr_id !=
$row[
'usr_id'])
314 $previous_usr_id =
$row[
'usr_id'];
335 $ilDB->manipulate(
"DELETE FROM usr_pref ".
336 "WHERE ".$ilDB->like(
"keyword",
"text",
'disk_usage%'));
339 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
342 require_once
'Modules/HTMLLearningModule/classes/class.ilObjFileBasedLMAccess.php';
345 require_once
'Modules/MediaCast/classes/class.ilObjMediaCastAccess.php';
348 require_once
'Modules/ScormAicc/classes/class.ilObjSAHSLearningModuleAccess.php';
351 require_once
'Services/Mail/classes/class.ilObjMailAccess.php';
356 $ilDB->manipulate(
"INSERT INTO usr_pref ".
357 "(usr_id, keyword, value) ".
358 "SELECT usr_id, 'disk_usage', SUM(value) ".
360 "WHERE ".$ilDB->like(
"keyword",
"text",
'disk_usage.%.size%').
365 $ilDB->manipulate(
"INSERT INTO usr_pref ".
366 "(usr_id, keyword, value) ".
367 "SELECT usr_id, 'disk_usage.last_update', ".$ilDB->now().
" ".
390 $res = $ilDB->query(
"SELECT DISTINCT d.obj_id, d.owner ".
391 "FROM object_data d ".
392 "JOIN object_reference r ON d.obj_id=r.obj_id ".
393 "JOIN tree t ON t.child=r.ref_id ".
394 "WHERE d.type = ".$ilDB->quote($a_type,
"text").
" ".
405 if (
$row->owner != $owner) {
406 if ($owner != null) {
407 $ilDB->manipulate(
"INSERT INTO usr_pref ".
408 "(usr_id, keyword, value) ".
410 "(".$ilDB->quote($owner,
'integer').
", ".
411 $ilDB->quote(
'disk_usage.'.$a_type.
'.size').
", ".
412 $ilDB->quote($size,
'integer').
")");
414 $ilDB->manipulate(
"INSERT INTO usr_pref ".
415 "(usr_id, keyword, value) ".
417 "(".$ilDB->quote($owner,
'integer').
", ".
418 $ilDB->quote(
'disk_usage.'.$a_type.
'.count').
", ".
419 $ilDB->quote($count,
'integer').
")"
423 $owner =
$row->owner;
427 $size += $a_access_obj->_lookupDiskUsage(
$row->obj_id);
430 if ($owner != null) {
431 $ilDB->manipulate(
"INSERT INTO usr_pref ".
432 "(usr_id, keyword, value) ".
434 "(".$ilDB->quote($owner,
'integer').
", ".
435 $ilDB->quote(
'disk_usage.'.$a_type.
'.size').
", ".
436 $ilDB->quote($size,
'integer').
")");
438 $ilDB->manipulate(
"INSERT INTO usr_pref ".
439 "(usr_id, keyword, value) ".
441 "(".$ilDB->quote($owner,
'integer').
", ".
442 $ilDB->quote(
'disk_usage.'.$a_type.
'.count').
", ".
443 $ilDB->quote($count,
'integer').
")");
466 $res = $ilDB->query(
"SELECT usr_id FROM usr_data");
470 $data = $a_access_obj->_lookupDiskUsageOfUser(
$row->usr_id);
472 if (
$data[
'size'] != null &&
$data[
'count'] != null)
474 $ilDB->manipulate(
"INSERT INTO usr_pref ".
475 "(usr_id, keyword, value) ".
477 "(".$ilDB->quote(
$row->usr_id,
'integer').
", ".
478 $ilDB->quote(
'disk_usage.'.$a_type.
'.size').
", ".
479 $ilDB->quote(
$data[
'size'],
'integer').
")");
480 $ilDB->manipulate(
"INSERT INTO usr_pref ".
481 "(usr_id, keyword, value) ".
483 "(".$ilDB->quote(
$row->usr_id,
'integer').
", ".
484 $ilDB->quote(
'disk_usage.'.$a_type.
'.count').
", ".
485 $ilDB->quote(
$data[
'count'],
'integer').
")");
494 $lastStart = $ilSetting->get(
'last_cronjob_disk_quota_sum_start_ts', 0);
495 if( !$lastStart || date(
'dmY', $lastStart) != date(
'dmY') )
497 $ilSetting->set(
'last_cronjob_disk_quota_sum_start_ts', time());
499 include_once
'Services/Mail/classes/class.ilDiskQuotaSummaryNotification.php';
514 require_once
'Services/Mail/classes/class.ilDiskQuotaReminderMail.php';
517 $res = $ilDB->queryf(
518 "SELECT u.usr_id,u.gender,u.firstname,u.lastname,u.login,u.email,u.last_login,u.active,".
519 "u.time_limit_unlimited, ".$ilDB->fromUnixtime(
"u.time_limit_from").
", ".$ilDB->fromUnixtime(
"u.time_limit_until").
",".
525 "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,".
527 " CASE WHEN ".$ilDB->unixTimestamp().
" BETWEEN u.time_limit_from AND u.time_limit_until THEN 0 ELSE 1 END expired,".
528 "rq.role_disk_quota, system_role.rol_id role_id, ".
529 "p1.value+0 user_disk_quota,".
530 "p2.value+0 disk_usage, ".
531 "p3.value last_update, ".
532 "p4.value last_reminder, ".
533 "p5.value language, ".
537 "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 ".
541 "JOIN (SELECT u.usr_id usr_id,MAX(rd.disk_quota) role_disk_quota ".
543 "JOIN rbac_ua ua ON ua.usr_id=u.usr_id ".
544 "JOIN rbac_fa fa ON fa.rol_id=ua.rol_id AND fa.parent=%s ".
545 "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 ".
548 "LEFT JOIN rbac_ua system_role ON system_role.usr_id=u.usr_id AND system_role.rol_id = %s ".
551 "LEFT JOIN usr_pref p1 ON p1.usr_id=u.usr_id AND p1.keyword = 'disk_quota' ".
554 "LEFT JOIN usr_pref p2 ON p2.usr_id=u.usr_id AND p2.keyword = 'disk_usage' ".
557 "LEFT JOIN usr_pref p3 ON p3.usr_id=u.usr_id AND p3.keyword = 'disk_usage.last_update' ".
560 "LEFT JOIN usr_pref p4 ON p4.usr_id=u.usr_id AND p4.keyword = 'disk_quota_last_reminder' ".
563 "LEFT JOIN usr_pref p5 ON p5.usr_id=u.usr_id AND p5.keyword = 'language' ".
567 'WHERE (p2.value > p1.value AND p2.value > rq.role_disk_quota) '.
568 'AND (u.active=1 AND (u.time_limit_unlimited = 1 OR '.$ilDB->unixTimestamp().
' BETWEEN u.time_limit_from AND u.time_limit_until)) '.
569 'AND (p4.value IS NULL OR p4.value < DATE_SUB(NOW(), INTERVAL 7 DAY)) '
572 array(
'integer',
'integer'),
573 array(ROLE_FOLDER_ID, SYSTEM_ROLE_ID)
578 $row[
'disk_usage_details'] = $details[
'details'];
581 $mail->setData(
$row);
585 if (
$row[
'last_reminder'] != null)
587 $ilDB->manipulatef(
"UPDATE usr_pref SET value= ".$ilDB->now().
" ".
588 "WHERE usr_id=%s AND keyword = 'disk_quota_last_reminder'"
591 array(
$row[
'usr_id'])
596 $ilDB->manipulatef(
"INSERT INTO usr_pref (usr_id, keyword, value) ".
597 "VALUES (%s, 'disk_quota_last_reminder', ".$ilDB->now().
")"
600 array(
$row[
'usr_id'])
614 require_once
'Services/Mail/classes/class.ilDiskQuotaReminderMail.php';
617 $res = $ilDB->query(
"SELECT MAX(value) last_update ".
618 "FROM usr_pref WHERE keyword='disk_usage.last_update'");
620 return (
$row != null) ?
$row[
'last_update'] : null;