download.php 1.9 KB

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