Hpdownload.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Istvan Mandak
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * EXERCISE LIST
  22. *
  23. * This script shows the list of exercises for administrators and students.
  24. *
  25. * @author Istvan Mandak
  26. * @package dokeos.exercise
  27. ==============================================================================
  28. */
  29. session_cache_limiter('public');
  30. include('../inc/global.inc.php');
  31. $this_section=SECTION_COURSES;
  32. include(api_get_path(LIBRARY_PATH)."events.lib.inc.php");
  33. $tbl_document=$_course['dbNameGlu']."document";
  34. $doc_url=urldecode($_GET['doc_url']);
  35. $filename=basename($doc_url);
  36. // launch event
  37. //event_download($doc_url);
  38. if (isset($_course['path']))
  39. {
  40. // $full_file_name=$rootSys."courses/".$_course['path'].'/document'.$doc_url;
  41. $full_file_name = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$doc_url;
  42. }
  43. else
  44. {
  45. //$full_file_name=$rootSys."courses/".$cid.'/document'.$doc_url;
  46. $full_file_name = api_get_path(SYS_COURSE_PATH).$cid.'/document'.$doc_url;
  47. }
  48. if(!is_file($full_file_name))
  49. {
  50. exit();
  51. }
  52. $extension=explode('.',$filename);
  53. $extension=strtolower($extension[sizeof($extension)-1]);
  54. switch($extension)
  55. {
  56. case 'gz': $content_type='application/x-gzip'; break;
  57. case 'zip': $content_type='application/zip'; break;
  58. case 'pdf': $content_type='application/pdf'; break;
  59. case 'png': $content_type='image/png'; break;
  60. case 'gif': $content_type='image/gif'; break;
  61. case 'jpg': $content_type='image/jpeg'; break;
  62. case 'txt': $content_type='text/plain'; break;
  63. case 'htm': $content_type='text/html'; break;
  64. case 'html': $content_type='text/html'; break;
  65. default: $content_type='application/octet-stream'; break;
  66. }
  67. header('Content-disposition: filename='.$filename);
  68. header('Content-Type: '.$content_type);
  69. header('Expires: '.gmdate('D, d M Y H:i:s',time()+10).' GMT');
  70. header('Last-Modified: '.gmdate('D, d M Y H:i:s',time()+10).' GMT');
  71. /*
  72. ------------------------------------------------------------------------------
  73. Dynamic parsing section
  74. is activated whenever a user views an html file
  75. work in progress
  76. - question: we could also parse per line,
  77. perhaps this would be faster.
  78. ($file_content = file($full_file_name) returns file in array)
  79. ------------------------------------------------------------------------------
  80. */
  81. if($content_type == 'text/html')
  82. {
  83. include (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  84. $directory_name = dirname($full_file_name);
  85. $dir=str_replace(array('\\',$rootSys."courses/".$_course['path'].'/document'),array('/',''),$directory_name);
  86. if($dir[strlen($dir)-1] != '/')
  87. {
  88. $dir.='/';
  89. }
  90. //Parse whole file at one
  91. $fp = fopen($full_file_name, "r");
  92. $file_content = fread ($fp, filesize ($full_file_name));
  93. fclose($fp);
  94. //$file_content = api_replace_parameter($dir, $file_content, "src");
  95. //$file_content = api_replace_parameter($dir, $file_content, "href");
  96. /*
  97. //parse line per line
  98. $file_content_array = file($full_file_name);
  99. foreach($file_content_array as $line)
  100. {
  101. $line = api_replace_parameter($dir, $line, "src");
  102. $line = api_replace_parameter($dir, $line, "href");
  103. $file_content .= $line;
  104. }
  105. */
  106. $exercicePath = $_SERVER['PHP_SELF'];
  107. $exfile = explode('/',$exercicePath);
  108. $exfile = $exfile[sizeof($exfile)-1];
  109. $exercicePath = substr($exercicePath,0,strpos($exercicePath,$exfile));
  110. $exercicePath = $exercicePath;
  111. $content = $file_content;
  112. $mit = "function Finish(){";
  113. $js_content = "var SaveScoreVariable = 0; // This variable included by Dokeos System\n".
  114. "function mySaveScore() // This function included by Dokeos System\n".
  115. "{\n".
  116. " if (SaveScoreVariable==0)\n".
  117. " {\n".
  118. " SaveScoreVariable = 1;\n".
  119. " if (C.ie)\n".
  120. " {\n".
  121. " document.location.href = \"".$exercicePath."savescores.php?origin=$origin&time=$time&test=".$doc_url."&uid=".$_uid."&cid=".$cid."&score=\"+Score;\n".
  122. " //window.alert(Score);\n".
  123. " }\n".
  124. " else\n".
  125. " {\n".
  126. " }\n".
  127. " }\n".
  128. "}\n".
  129. "// Must be included \n".
  130. "function Finish(){\n".
  131. " mySaveScore();";
  132. $newcontent = str_replace($mit,$js_content,$content);
  133. $prehref="javascript:void(0);";
  134. $posthref=$rootWeb."main/exercice/Hpdownload.php?doc_url=".$doc_url."&cid=".$cid."&uid=".$uid;
  135. $newcontent = str_replace($prehref,$posthref,$newcontent);
  136. $prehref="class=\"GridNum\" onclick=";
  137. $posthref="class=\"GridNum\" onMouseover=";
  138. $newcontent = str_replace($prehref,$posthref,$newcontent);
  139. header('Content-length: '.strlen($newcontent));
  140. // Dipsp.
  141. echo $newcontent;
  142. exit();
  143. }
  144. //normal case, all non-html files
  145. //header('Content-length: '.filesize($full_file_name));
  146. $fp=fopen($full_file_name,'rb');
  147. fpassthru($fp);
  148. fclose($fp);
  149. ?>