dokeos-exercise
[ class tree: dokeos-exercise ] [ index: dokeos-exercise ] [ all elements ]

Source for file Hpdownload.php

Documentation is available at Hpdownload.php

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

Documentation generated on Thu, 12 Jun 2008 13:39:48 -0500 by phpDocumentor 1.4.1