document_quota.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Document quota management script.
  5. *
  6. * @package chamilo.document
  7. */
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. api_protect_course_script(true);
  10. if (!api_is_allowed_to_edit(null, true)) {
  11. api_not_allowed(true);
  12. }
  13. $current_course_tool = TOOL_DOCUMENT;
  14. $this_section = SECTION_COURSES;
  15. $tool_name = get_lang('DocumentQuota');
  16. $interbreadcrumb[] = ['url' => 'document.php', 'name' => get_lang('Documents')];
  17. $htmlHeadXtra[] = api_get_js('jqplot/jquery.jqplot.js');
  18. $htmlHeadXtra[] = api_get_js('jqplot/plugins/jqplot.pieRenderer.js');
  19. $htmlHeadXtra[] = api_get_js('jqplot/plugins/jqplot.donutRenderer.js');
  20. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/jqplot/jquery.jqplot.css');
  21. $course_code = api_get_course_id();
  22. $course_id = api_get_course_int_id();
  23. $session_id = api_get_session_id();
  24. $group_id = api_get_group_id();
  25. $user_id = api_get_user_id();
  26. $user_info = api_get_user_info($user_id);
  27. $session = [];
  28. $user_name = $user_info['complete_name'];
  29. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  30. $session_list = SessionManager::get_session_by_course($course_id);
  31. $total_quota_bytes = DocumentManager::get_course_quota();
  32. $quota_bytes = DocumentManager::documents_total_space($course_id, 0, 0);
  33. $quota_percentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
  34. $session[] = [get_lang('Course').' ('.format_file_size($quota_bytes).')', $quota_percentage];
  35. $used_quota_bytes = $quota_bytes;
  36. if (!empty($session_list)) {
  37. foreach ($session_list as $session_data) {
  38. $quota_percentage = 0;
  39. $quota_bytes = DocumentManager::documents_total_space($course_id, null, $session_data['id']);
  40. if (!empty($quota_bytes)) {
  41. $quota_percentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
  42. }
  43. if ($session_id == $session_data['id']) {
  44. $session_data['name'] = $session_data['name'].' * ';
  45. }
  46. $used_quota_bytes += $quota_bytes;
  47. $session[] = [
  48. addslashes(get_lang('Session').': '.$session_data['name']).' ('.format_file_size($quota_bytes).')',
  49. $quota_percentage,
  50. ];
  51. }
  52. }
  53. $group_list = GroupManager::get_groups();
  54. if (!empty($group_list)) {
  55. foreach ($group_list as $group_data) {
  56. $quota_percentage = 0;
  57. $my_group_id = $group_data['id'];
  58. $quota_bytes = DocumentManager::documents_total_space($course_id, $my_group_id, 0);
  59. if (!empty($quota_bytes)) {
  60. $quota_percentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
  61. }
  62. if ($group_id == $my_group_id) {
  63. $group_data['name'] = $group_data['name'].' * ';
  64. }
  65. $used_quota_bytes += $quota_bytes;
  66. $session[] = [
  67. addslashes(get_lang('Group').': '.$group_data['name']).' ('.format_file_size($quota_bytes).')',
  68. $quota_percentage,
  69. ];
  70. }
  71. }
  72. // Showing weight of documents uploaded by user
  73. $document_list = DocumentManager::getAllDocumentData(api_get_course_info());
  74. if (!empty($document_list)) {
  75. foreach ($document_list as $document_data) {
  76. if ($document_data['insert_user_id'] == api_get_user_id() && $document_data['filetype'] === 'file') {
  77. $quota_bytes += $document_data['size'];
  78. }
  79. }
  80. if ($quota_bytes != 0) {
  81. $quota_percentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
  82. }
  83. $session[] = [
  84. addslashes(get_lang('Teacher').': '.$user_name).' ('.format_file_size($quota_bytes).')',
  85. $quota_percentage,
  86. ];
  87. //if a sesson is active
  88. if ($session_id != 0) {
  89. if (!empty($course_list)) {
  90. $total_courses_quota = 0;
  91. $total_quota_bytes = 0;
  92. if (is_array($course_list) && !empty($course_list)) {
  93. foreach ($course_list as $course_data) {
  94. $total_quota_bytes += DocumentManager::get_course_quota($course_data['id']);
  95. }
  96. }
  97. if ($quota_bytes != 0) {
  98. $quota_percentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
  99. }
  100. }
  101. $session[] = [addslashes(sprintf(get_lang('TeacherXInSession'), $user_name)), $quota_percentage];
  102. }
  103. }
  104. $quota_percentage = round(($total_quota_bytes - $used_quota_bytes) / $total_quota_bytes, 2) * 100;
  105. $session[] = [
  106. addslashes(get_lang('ShowCourseQuotaUse')).' ('.format_file_size(
  107. $total_quota_bytes - $used_quota_bytes
  108. ).') ',
  109. $quota_percentage,
  110. ];
  111. $quota_data = json_encode($session);
  112. $htmlHeadXtra[] = "<script>
  113. $(function() {
  114. var data = ".$quota_data.";
  115. var plot1 = jQuery.jqplot('chart1', [data], {
  116. seriesDefaults: {
  117. // Make this a pie chart
  118. renderer: jQuery.jqplot.PieRenderer,
  119. rendererOptions: {
  120. // Put data labels on the pie slices.
  121. // By default, labels show the percentage of the slice.
  122. showDataLabels: true
  123. }
  124. },
  125. legend: { show:true, location: 'e' }
  126. });
  127. });
  128. </script>";
  129. $tpl = new Template($tool_name);
  130. $content = Display::page_subheader(get_lang('ShowCourseQuotaUse')).'<div id="chart1"></div>';
  131. $tpl->assign('content', $content);
  132. $tpl->display_one_col_template();