download.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. exit;
  4. /**
  5. * This file is responsible for passing requested documents to the browser.
  6. * Html files are parsed to fix a few problems with URLs,
  7. * but this code will hopefully be replaced soon by an Apache URL
  8. * rewrite mechanism.
  9. *
  10. * @package chamilo.work
  11. */
  12. session_cache_limiter('public');
  13. require_once '../../inc/global.inc.php';
  14. $current_course_tool = TOOL_STUDENTPUBLICATION;
  15. $this_section = SECTION_COURSES;
  16. // IMPORTANT to avoid caching of documents
  17. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  18. header('Cache-Control: public');
  19. header('Pragma: no-cache');
  20. api_protect_course_script(true);
  21. $id = (int) $_GET['id'];
  22. $courseInfo = api_get_course_info();
  23. if (empty($courseInfo)) {
  24. api_not_allowed(true);
  25. }
  26. $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  27. if (!empty($courseInfo['real_id'])) {
  28. $courseId = $courseInfo['real_id'];
  29. $sql = "SELECT * FROM $tbl_student_publication
  30. WHERE c_id = $courseId AND id = $id";
  31. $result = Database::query($sql);
  32. if ($result && Database::num_rows($result)) {
  33. $row = Database::fetch_array($result, 'ASSOC');
  34. $full_file_name = $courseInfo['course_sys_path'].$row['url'];
  35. $item_info = api_get_item_property_info($courseId, 'work', $row['id']);
  36. if (empty($item_info)) {
  37. exit;
  38. }
  39. if ($courseInfo['show_score'] == 0 || $item_info['visibility'] == 1 && $row['accepted'] == 1 &&
  40. ($row['user_id'] == api_get_user_id() || api_is_allowed_to_edit())
  41. ) {
  42. $title = str_replace(' ', '_', $row['title']);
  43. Event::event_download($title);
  44. if (Security::check_abs_path($full_file_name, $courseInfo['course_sys_path'])) {
  45. DocumentManager::file_send_for_download($full_file_name, true, $title);
  46. }
  47. } else {
  48. api_not_allowed();
  49. }
  50. }
  51. }
  52. exit;