Hpdownload.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 22201 2009-07-17 19:57:03Z cfasanando $
  21. */
  22. session_cache_limiter('public');
  23. include('../inc/global.inc.php');
  24. $this_section=SECTION_COURSES;
  25. $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
  26. $doc_url=str_replace(array('../','\\..','\\0','..\\'),array('','','',''),urldecode($_GET['doc_url']));
  27. $filename=basename($doc_url);
  28. // launch event
  29. //event_download($doc_url);
  30. if (isset($_course['path'])) {
  31. $full_file_name = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.Security::remove_XSS($doc_url);
  32. } else {
  33. $full_file_name = api_get_path(SYS_COURSE_PATH).$cid.'/document'.Security::remove_XSS($doc_url);
  34. }
  35. if(!is_file($full_file_name)) {
  36. exit();
  37. }
  38. $extension=explode('.',$filename);
  39. $extension=strtolower($extension[sizeof($extension)-1]);
  40. switch($extension) {
  41. case 'gz': $content_type='application/x-gzip'; break;
  42. case 'zip': $content_type='application/zip'; break;
  43. case 'pdf': $content_type='application/pdf'; break;
  44. case 'png': $content_type='image/png'; break;
  45. case 'gif': $content_type='image/gif'; break;
  46. case 'jpg': $content_type='image/jpeg'; break;
  47. case 'txt': $content_type='text/plain'; break;
  48. case 'htm': $content_type='text/html'; break;
  49. case 'html': $content_type='text/html'; break;
  50. default: $content_type='application/octet-stream'; break;
  51. }
  52. header('Content-disposition: filename='.$filename);
  53. header('Content-Type: '.$content_type);
  54. header('Expires: '.gmdate('D, d M Y H:i:s',time()+10).' GMT');
  55. header('Last-Modified: '.gmdate('D, d M Y H:i:s',time()+10).' GMT');
  56. /*
  57. ------------------------------------------------------------------------------
  58. Dynamic parsing section
  59. is activated whenever a user views an html file
  60. work in progress
  61. - question: we could also parse per line,
  62. perhaps this would be faster.
  63. ($file_content = file($full_file_name) returns file in array)
  64. ------------------------------------------------------------------------------
  65. */
  66. if($content_type == 'text/html') {
  67. include (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  68. $directory_name = dirname($full_file_name);
  69. $dir=str_replace(array('\\',$_configuration['root_sys']."courses/".$_course['path'].'/document'),array('/',''),$directory_name);
  70. if($dir[strlen($dir)-1] != '/')
  71. {
  72. $dir.='/';
  73. }
  74. //Parse whole file at one
  75. $fp = fopen($full_file_name, "r");
  76. $file_content = fread ($fp, filesize ($full_file_name));
  77. fclose($fp);
  78. //$file_content = api_replace_parameter($dir, $file_content, "src");
  79. //$file_content = api_replace_parameter($dir, $file_content, "href");
  80. /*
  81. //parse line per line
  82. $file_content_array = file($full_file_name);
  83. foreach($file_content_array as $line)
  84. {
  85. $line = api_replace_parameter($dir, $line, "src");
  86. $line = api_replace_parameter($dir, $line, "href");
  87. $file_content .= $line;
  88. }
  89. */
  90. $exercicePath = api_get_self();
  91. $exfile = explode('/',$exercicePath);
  92. $exfile = $exfile[sizeof($exfile)-1];
  93. $exercicePath = substr($exercicePath,0,strpos($exercicePath,$exfile));
  94. $exercicePath = $exercicePath;
  95. $content = $file_content;
  96. $mit = "function Finish(){";
  97. $js_content = "var SaveScoreVariable = 0; // This variable included by Dokeos System\n".
  98. "function mySaveScore() // This function included by Dokeos System\n".
  99. "{\n".
  100. " if (SaveScoreVariable==0)\n".
  101. " {\n".
  102. " SaveScoreVariable = 1;\n".
  103. " if (C.ie)\n".
  104. " {\n".
  105. " document.location.href = \"".$exercicePath."savescores.php?origin=$origin&time=$time&test=".$doc_url."&uid=".$_user['user_id']."&cid=".$cid."&score=\"+Score;\n".
  106. " //window.alert(Score);\n".
  107. " }\n".
  108. " else\n".
  109. " {\n".
  110. " }\n".
  111. " }\n".
  112. "}\n".
  113. "// Must be included \n".
  114. "function Finish(){\n".
  115. " mySaveScore();";
  116. $newcontent = str_replace($mit,$js_content,$content);
  117. $prehref="javascript:void(0);";
  118. $posthref=$_configuration['root_web']."main/exercice/Hpdownload.php?doc_url=".$doc_url."&cid=".$cid."&uid=".$uid;
  119. $newcontent = str_replace($prehref,$posthref,$newcontent);
  120. $prehref="class=\"GridNum\" onclick=";
  121. $posthref="class=\"GridNum\" onMouseover=";
  122. $newcontent = str_replace($prehref,$posthref,$newcontent);
  123. header('Content-length: '.strlen($newcontent));
  124. // Dipsp.
  125. echo $newcontent;
  126. exit();
  127. }
  128. //normal case, all non-html files
  129. //header('Content-length: '.filesize($full_file_name));
  130. $fp=fopen($full_file_name,'rb');
  131. fpassthru($fp);
  132. fclose($fp);
  133. ?>