document_quota.php 5.1 KB

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