document_quota.php 5.1 KB

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