download.php 3.6 KB

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