quota.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays info about the course disk use and quota:
  5. * how large (in megabytes) is the documents area of the course,
  6. * what is the maximum allowed for this course...
  7. *
  8. * @author Roan Embrechts
  9. * @package chamilo.document
  10. */
  11. // Name of the language file that needs to be included
  12. $language_file = 'document';
  13. // Including the global dokeos file
  14. require_once '../inc/global.inc.php';
  15. // Including additional libraries
  16. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  17. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  18. // Some constants and variables
  19. $courseDir = $_course['path'].'/document';
  20. $maxFilledSpace = DEFAULT_DOCUMENT_QUOTA;
  21. // Breadcrumbs
  22. $interbreadcrumb[] = array('url' => 'document.php','name' => get_lang('ToolDocument'));
  23. // Title of the page
  24. $nameTools = get_lang('DocumentQuota');
  25. // Display the header
  26. Display::display_header($nameTools,'Doc');
  27. /* FUNCTIONS */
  28. /**
  29. * Here we count 1 kilobyte = 1000 byte, 12 megabyte = 1000 kilobyte.
  30. */
  31. function display_quota($course_quota, $already_consumed_space) {
  32. $course_quota_m = round($course_quota / 1000000);
  33. $already_consumed_space_m = round($already_consumed_space / 1000000);
  34. $message = get_lang('MaximumAllowedQuota') . ' <strong>'.$course_quota_m.' megabyte</strong>.<br />';
  35. $message .= get_lang('CourseCurrentlyUses') . ' <strong>' . $already_consumed_space_m . ' megabyte</strong>.<br />';
  36. $percentage = $already_consumed_space / $course_quota * 100;
  37. $percentage = round($percentage, 1);
  38. $other_percentage = $percentage < 100 ? 100 - $percentage : 0;
  39. // Decide where to place percentage in graph
  40. if ($percentage >= 50) {
  41. $text_in_filled = '&nbsp;'.$other_percentage.'%';
  42. $text_in_unfilled = '';
  43. } else {
  44. $text_in_unfilled = '&nbsp;'.$other_percentage.'%';
  45. $text_in_filled = '';
  46. }
  47. // Decide the background colour of the graph
  48. if ($percentage < 65) {
  49. $colour = '#00BB00'; // Safe - green
  50. } elseif ($percentage < 90) {
  51. $colour = '#ffd400'; // Filling up - yelloworange
  52. } else {
  53. $colour = '#DD0000'; // Full - red
  54. }
  55. // This is used for the table width: a table of only 100 pixels looks too small
  56. $visual_percentage = 4 * $percentage;
  57. $visual_other_percentage = 4 * $other_percentage;
  58. $message .= get_lang('PercentageQuotaInUse') . ': <strong>'.$percentage.'%</strong>.<br />' .
  59. get_lang('PercentageQuotaFree') . ': <strong>'.$other_percentage.'%</strong>.<br />';
  60. $show_percentage = $percentage >= 10 ? '&nbsp;'.$percentage.'%' : '';
  61. $message .= '<br /><table cellpadding="" cellspacing="0" height="40"><tr>
  62. <td bgcolor="'.$colour.'" width="'.$visual_percentage.'">'.$show_percentage.'</td>
  63. <td bgcolor="Silver" width="'.$visual_other_percentage.'">&nbsp;'.$other_percentage.'%</td>
  64. </tr></table>';
  65. echo $message;
  66. }
  67. // Actions
  68. echo '<div class="actions">';
  69. // link back to the documents overview
  70. echo '<a href="document.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview')).get_lang('BackTo').' '.get_lang('DocumentsOverview').'</a>';
  71. echo '</div>';
  72. // Getting the course quota
  73. $course_quota = DocumentManager::get_course_quota();
  74. // Setting the full path
  75. $full_path = $baseWorkDir.$courseDir;
  76. // Calculating the total space
  77. $already_consumed_space = documents_total_space($_course);
  78. // Displaying the quota
  79. display_quota($course_quota, $already_consumed_space);
  80. // Display the footer
  81. Display::display_footer();