quota.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php // $Id: quota.php 10204 2006-11-26 20:46:53Z pcool $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2005 Roan Embrechts, Vrije Universiteit Brussel
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * This script displays info about the course disk use and quota:
  20. * how large (in megabytes) is the documents area of the course,
  21. * what is the maximum allowed for this course...
  22. *
  23. * @author Roan Embrechts
  24. * @package dokeos.document
  25. ==============================================================================
  26. */
  27. /*
  28. ==============================================================================
  29. INIT SECTION
  30. ==============================================================================
  31. */
  32. // name of the language file that needs to be included
  33. $language_file = 'document';
  34. // global settings initialisation
  35. // also provides access to main api (inc/lib/main_api.lib.php)
  36. include("../inc/global.inc.php");
  37. /*
  38. -----------------------------------------------------------
  39. Libraries
  40. -----------------------------------------------------------
  41. */
  42. //many useful functions in main_api.lib.php, by default included
  43. include_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  44. include_once(api_get_path(LIBRARY_PATH) . 'document.lib.php');
  45. /*
  46. -----------------------------------------------------------
  47. Constants and variables
  48. -----------------------------------------------------------
  49. */
  50. $courseDir = $_course['path']."/document";
  51. $maxFilledSpace = DEFAULT_DOCUMENT_QUOTA;
  52. /*
  53. -----------------------------------------------------------
  54. Header
  55. -----------------------------------------------------------
  56. */
  57. $interbreadcrumb[]=array("url" => "document.php","name" => get_lang("Doc"));
  58. $nameTools = get_lang("DocumentQuota"); // title of the page
  59. Display::display_header($nameTools,"Doc");
  60. /*
  61. ==============================================================================
  62. FUNCTIONS
  63. ==============================================================================
  64. */
  65. /**
  66. * Here we count 1 kilobyte = 1000 byte, 12 megabyte = 1000 kilobyte.
  67. */
  68. function display_quota($course_quota, $already_consumed_space)
  69. {
  70. $course_quota_m = round($course_quota / 1000000);
  71. $already_consumed_space_m = round($already_consumed_space / 1000000);
  72. $message = get_lang("CourseCurrentlyUses") . " <strong>" . $already_consumed_space_m . " megabyte</strong>.<br/>". get_lang("MaximumAllowedQuota") . " <strong>$course_quota_m megabyte</strong>.<br/>";
  73. $percentage = $already_consumed_space / $course_quota * 100;
  74. $percentage = round($percentage);
  75. if ($percentage < 100) $other_percentage = 100 - $percentage;
  76. else $other_percentage = 0;
  77. //decide where to place percentage in graph
  78. if ($percentage >= 50)
  79. {
  80. $text_in_filled = "&nbsp;$percentage%".
  81. $text_in_unfilled = "";
  82. }
  83. else
  84. {
  85. $text_in_unfilled = "&nbsp;$percentage%".
  86. $text_in_filled = "";
  87. }
  88. //decide the background colour of the graph
  89. if ($percentage < 65) $colour = "#00BB00"; //safe - green
  90. else if ($percentage < 90) $colour = "#ffd400"; //filling up - yelloworange
  91. else $colour = "#DD0000"; //full - red
  92. //this is used for the table width: a table of only 100 pixels looks too small
  93. $visual_percentage = 4 * $percentage;
  94. $visual_other_percentage = 4 * $other_percentage;
  95. $message .= get_lang("PercentageQuotaInUse") . ": <strong>$percentage%</strong>.<br/>" .
  96. get_lang("PercentageQuotaFree") . ": <strong>$other_percentage%</strong>.<br>";
  97. $message .= "<br/><table cellpadding=\"\" cellspacing=\"0\" height=\"40\"><tr>
  98. <td bgcolor=\"$colour\" width=\"$visual_percentage\">$text_in_filled</td>
  99. <td bgcolor=\"Silver\" width=\"$visual_other_percentage\">$text_in_unfilled</td>
  100. </tr></table>";
  101. echo $message;
  102. }
  103. /*
  104. ==============================================================================
  105. MAIN CODE
  106. ==============================================================================
  107. */
  108. api_display_tool_title($nameTools);
  109. $course_quota = DocumentManager::get_course_quota();
  110. $full_path = $baseWorkDir . $courseDir;
  111. $already_consumed_space = documents_total_space($_course);
  112. display_quota($course_quota, $already_consumed_space);
  113. /*
  114. ==============================================================================
  115. FOOTER
  116. ==============================================================================
  117. */
  118. Display::display_footer();
  119. ?>