Hpdownload.php 5.1 KB

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