GC.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. HotPotGCt($documentPath,$flag,$userID);
  23. }
  24. /**
  25. * Garbage collector
  26. */
  27. function HotPotGCt($folder,$flag,$userID) { // Garbage Collector
  28. $filelist = array();
  29. if ($dir = @opendir($folder)) {
  30. while (($file = readdir($dir)) !== false) {
  31. if ( $file != ".") {
  32. if ($file != "..")
  33. {
  34. $full_name = $folder."/".$file;
  35. if (is_dir($full_name))
  36. {
  37. HotPotGCt($folder."/".$file,$flag);
  38. }
  39. else
  40. {
  41. $filelist[] = $file;
  42. }
  43. }
  44. }
  45. }
  46. closedir($dir);
  47. }
  48. while (list ($key, $val) = each ($filelist))
  49. {
  50. if (stristr($val,$userID.".t.html"))
  51. { if ($flag == 1)
  52. {
  53. my_delete($folder."/".$val);
  54. }
  55. else
  56. {
  57. echo $folder."/".$val."<br />";
  58. }
  59. }
  60. }
  61. }