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

Source for file download.php

Documentation is available at download.php

  1. <?php // $Id: download.php 12218 2007-05-01 18:27:14Z yannoo $
  2. /*
  3. ==============================================================================
  4.     Dokeos - elearning and course management software
  5.  
  6.     Copyright (c) 2008 Dokeos SPRL    
  7.  
  8.     For a full list of contributors, see "credits.txt".
  9.     The full license can be read in "license.txt".
  10.  
  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.  
  16.     See the GNU General Public License for more details.
  17.  
  18.     Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  19.     info@dokeos.com
  20. ==============================================================================
  21. */
  22. /**
  23. ==============================================================================
  24. *    This file is responsible for  passing requested documents to the browser.
  25. *    Html files are parsed to fix a few problems with URLs,
  26. *    but this code will hopefully be replaced soon by an Apache URL
  27. *    rewrite mechanism.
  28. *
  29. *    @package dokeos.document
  30. ==============================================================================
  31. */
  32.  
  33. /*
  34. ==============================================================================
  35.         MAIN CODE
  36. ==============================================================================
  37. */
  38.  
  39.  
  40. include('../inc/global.inc.php');
  41. $this_section=SECTION_COURSES;
  42.  
  43. include(api_get_path(LIBRARY_PATH).'document.lib.php');
  44. require_once('forumconfig.inc.php');
  45.  
  46. // IMPORTANT to avoid caching of documents
  47. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  48. header('Cache-Control: public');
  49. header('Pragma: no-cache');
  50.  
  51. //protection
  52.  
  53. $doc_url $_GET['file'];
  54. //change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  55. $doc_url str_replace('///''&'$doc_url);
  56. //still a space present? it must be a '+' (that got replaced by mod_rewrite)
  57. $doc_url str_replace(' ''+'$doc_url);
  58. $doc_url str_replace('/..'''$doc_url)//echo $doc_url;
  59.  
  60. include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  61.  
  62. if (isset($_course))
  63. {
  64.     api_not_allowed(true);    
  65. }
  66.  
  67. $full_file_name api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/forum/'.$doc_url;
  68.  
  69. //if the rewrite rule asks for a directory, we redirect to the document explorer
  70. if (is_dir($full_file_name)) 
  71. {
  72.     //remove last slash if present
  73.     //$doc_url = ($doc_url{strlen($doc_url)-1}=='/')?substr($doc_url,0,strlen($doc_url)-1):$doc_url; 
  74.     //mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (Ren�)
  75.     while ($doc_url{$dul strlen($doc_url)-1}=='/'$doc_url substr($doc_url,0,$dul);
  76.     //create the path
  77.     $document_explorer api_get_path(WEB_COURSE_PATH).api_get_course_path()// home course path
  78.     //redirect
  79.     header('Location: '.$document_explorer);
  80. }
  81.  
  82. $tbl_forum_attachment     Database::get_course_table(TABLE_FORUM_ATTACHMENT);
  83. $tbl_forum_post     Database::get_course_table(TABLE_FORUM_POST);
  84.  
  85. // launch event
  86. event_download($doc_url);
  87.  
  88. $sql='SELECT thread_id, forum_id,filename FROM '.$tbl_forum_post.'  f  INNER JOIN '.$tbl_forum_attachment.' a
  89.         ON a.post_id=f.post_id WHERE path LIKE BINARY "'.$doc_url.'"';
  90.  
  91. $resultapi_sql_query($sql__FILE____LINE__);
  92. $rowDatabase::fetch_array($result);
  93.  
  94. $forum_thread_visibility=api_get_item_visibility(api_get_course_info($course_code),TOOL_FORUM_THREAD,$row['thread_id']);
  95. $forum_forum_visibility=api_get_item_visibility(api_get_course_info($course_code),TOOL_FORUM,$row['forum_id']);
  96.  
  97. if ($forum_thread_visibility==&& $forum_forum_visibility==1)
  98. {
  99.     DocumentManager::file_send_for_download($full_file_name,TRUE$row['filename']);
  100. }
  101. exit;
  102. ?>

Documentation generated on Thu, 12 Jun 2008 13:20:32 -0500 by phpDocumentor 1.4.1