Hpdownload.php 4.9 KB

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