GC.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Code library for HotPotatoes integration.
  5. * @package chamilo.exercise
  6. * @author Istvan Mandak
  7. * @version $Id: GC.php 20451 2009-05-10 12:02:22Z ivantcholakov $
  8. */
  9. /**
  10. * Code
  11. */
  12. // usage: HotPotGC($_configuration['root_sys'],$flag);
  13. // working recursively, flag[0,1] print or delete the HotPotatoes temp files (.t.html)
  14. echo "Garbage Collector<BR>";
  15. HotPotGC($_configuration['root_sys'],1,1);
  16. /**
  17. * Garbage collector caller function
  18. */
  19. function HotPotGC($root_sys,$flag,$userID) {
  20. // flag[0,1] - print or delete the HotPotatoes temp files (.t.html)
  21. $documentPath = $root_sys."courses";
  22. require_once(api_get_path(LIBRARY_PATH)."fileManage.lib.php");
  23. HotPotGCt($documentPath,$flag,$userID);
  24. }
  25. /**
  26. * Garbage collector
  27. */
  28. function HotPotGCt($folder,$flag,$userID) { // Garbage Collector
  29. $filelist = array();
  30. if ($dir = @opendir($folder)) {
  31. while (($file = readdir($dir)) !== false) {
  32. if ( $file != ".") {
  33. if ($file != "..")
  34. {
  35. $full_name = $folder."/".$file;
  36. if (is_dir($full_name))
  37. {
  38. HotPotGCt($folder."/".$file,$flag);
  39. }
  40. else
  41. {
  42. $filelist[] = $file;
  43. }
  44. }
  45. }
  46. }
  47. closedir($dir);
  48. }
  49. while (list ($key, $val) = each ($filelist))
  50. {
  51. if (stristr($val,$userID.".t.html"))
  52. { if ($flag == 1)
  53. {
  54. my_delete($folder."/".$val);
  55. }
  56. else
  57. {
  58. echo $folder."/".$val."<br />";
  59. }
  60. }
  61. }
  62. }