quota.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php // $Id: quota.php 21106 2009-05-30 16:25:16Z iflorespaz $
  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. // name of the language file that needs to be included
  28. $language_file = 'document';
  29. // including the global dokeos file
  30. require_once "../inc/global.inc.php";
  31. // including additional libraries
  32. require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
  33. require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
  34. // some constants and variables
  35. $courseDir = $_course['path']."/document";
  36. $maxFilledSpace = DEFAULT_DOCUMENT_QUOTA;
  37. // breadcrumbs
  38. $interbreadcrumb[]=array("url" => "document.php","name" => get_lang('Document'));
  39. // title of the page
  40. $nameTools = get_lang("DocumentQuota");
  41. // display the header
  42. Display::display_header($nameTools,"Doc");
  43. /*
  44. ==============================================================================
  45. FUNCTIONS
  46. ==============================================================================
  47. */
  48. /**
  49. * Here we count 1 kilobyte = 1000 byte, 12 megabyte = 1000 kilobyte.
  50. */
  51. function display_quota($course_quota, $already_consumed_space)
  52. {
  53. $course_quota_m = round($course_quota / 1000000);
  54. $already_consumed_space_m = round($already_consumed_space / 1000000);
  55. $message = get_lang("CourseCurrentlyUses") . " <strong>" . $already_consumed_space_m . " megabyte</strong>.<br/>". get_lang("MaximumAllowedQuota") . " <strong>$course_quota_m megabyte</strong>.<br/>";
  56. $percentage = $already_consumed_space / $course_quota * 100;
  57. $percentage = round($percentage);
  58. if ($percentage < 100) $other_percentage = 100 - $percentage;
  59. else $other_percentage = 0;
  60. //decide where to place percentage in graph
  61. if ($percentage >= 50)
  62. {
  63. $text_in_filled = "&nbsp;$other_percentage%".
  64. $text_in_unfilled = "";
  65. }
  66. else
  67. {
  68. $text_in_unfilled = "&nbsp;$other_percentage%".
  69. $text_in_filled = "";
  70. }
  71. //decide the background colour of the graph
  72. if ($percentage < 65) $colour = "#00BB00"; //safe - green
  73. else if ($percentage < 90) $colour = "#ffd400"; //filling up - yelloworange
  74. else $colour = "#DD0000"; //full - red
  75. //this is used for the table width: a table of only 100 pixels looks too small
  76. $visual_percentage = 4 * $percentage;
  77. $visual_other_percentage = 4 * $other_percentage;
  78. $message .= get_lang("PercentageQuotaInUse") . ": <strong>$percentage%</strong>.<br/>" .
  79. get_lang("PercentageQuotaFree") . ": <strong>$other_percentage%</strong>.<br>";
  80. $message .= "<br/><table cellpadding=\"\" cellspacing=\"0\" height=\"40\"><tr>
  81. <td bgcolor=\"$colour\" width=\"$visual_percentage\"></td>
  82. <td bgcolor=\"Silver\" width=\"$visual_other_percentage\">&nbsp;$other_percentage%</td>
  83. </tr></table>";
  84. echo $message;
  85. }
  86. // actions
  87. echo '<div class="actions">';
  88. // link back to the documents overview
  89. echo '<a href="document.php">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('DocumentsOverview')).get_lang('Back').' '.get_lang('To').' '.get_lang('DocumentsOverview').'</a>';
  90. echo '</div>';
  91. // getting the course quota
  92. $course_quota = DocumentManager::get_course_quota();
  93. // setting the full path
  94. $full_path = $baseWorkDir . $courseDir;
  95. // calculating the total space
  96. $already_consumed_space = documents_total_space($_course);
  97. // displaying the quota
  98. display_quota($course_quota, $already_consumed_space);
  99. // display the footer
  100. Display::display_footer();
  101. ?>