quota.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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('CourseCurrentlyUses') . ' <strong>' . $already_consumed_space_m . ' megabyte</strong>.<br />'. get_lang('MaximumAllowedQuota') . ' <strong>'.$course_quota_m.' megabyte</strong>.<br />';
  35. $percentage = $already_consumed_space / $course_quota * 100;
  36. $percentage = round($percentage);
  37. $other_percentage = $percentage < 100 ? 100 - $percentage : 0;
  38. // Decide where to place percentage in graph
  39. if ($percentage >= 50) {
  40. $text_in_filled = '&nbsp;'.$other_percentage.'%';
  41. $text_in_unfilled = '';
  42. } else {
  43. $text_in_unfilled = '&nbsp;'.$other_percentage.'%';
  44. $text_in_filled = '';
  45. }
  46. // Decide the background colour of the graph
  47. if ($percentage < 65) {
  48. $colour = '#00BB00'; // Safe - green
  49. } elseif ($percentage < 90) {
  50. $colour = '#ffd400'; // Filling up - yelloworange
  51. } else {
  52. $colour = '#DD0000'; // Full - red
  53. }
  54. // This is used for the table width: a table of only 100 pixels looks too small
  55. $visual_percentage = 4 * $percentage;
  56. $visual_other_percentage = 4 * $other_percentage;
  57. $message .= get_lang('PercentageQuotaInUse') . ': <strong>'.$percentage.'%</strong>.<br />' .
  58. get_lang('PercentageQuotaFree') . ': <strong>'.$other_percentage.'%</strong>.<br />';
  59. $show_percentage = $percentage >= 10 ? '&nbsp;'.$percentage.'%' : '';
  60. $message .= '<br /><table cellpadding="" cellspacing="0" height="40"><tr>
  61. <td bgcolor="'.$colour.'" width="'.$visual_percentage.'">'.$show_percentage.'</td>
  62. <td bgcolor="Silver" width="'.$visual_other_percentage.'">&nbsp;'.$other_percentage.'%</td>
  63. </tr></table>';
  64. echo $message;
  65. }
  66. // Actions
  67. echo '<div class="actions">';
  68. // link back to the documents overview
  69. echo '<a href="document.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview')).get_lang('BackTo').' '.get_lang('DocumentsOverview').'</a>';
  70. echo '</div>';
  71. // Getting the course quota
  72. $course_quota = DocumentManager::get_course_quota();
  73. // Setting the full path
  74. $full_path = $baseWorkDir.$courseDir;
  75. // Calculating the total space
  76. $already_consumed_space = documents_total_space($_course);
  77. // Displaying the quota
  78. display_quota($course_quota, $already_consumed_space);
  79. // Display the footer
  80. Display::display_footer();