download_comment_file.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. require_once __DIR__.'/../inc/global.inc.php';
  12. require_once 'work.lib.php';
  13. // Course protection
  14. api_protect_course_script(true);
  15. $commentId = isset($_GET['comment_id']) ? intval($_GET['comment_id']) : null;
  16. if (empty($commentId)) {
  17. api_not_allowed(true);
  18. }
  19. $workData = getWorkComment($commentId);
  20. $courseInfo = api_get_course_info();
  21. if (!empty($workData)) {
  22. if (empty($workData['file_path']) ||
  23. (isset($workData['file_path']) && !file_exists($workData['file_path']))
  24. ) {
  25. api_not_allowed(true);
  26. }
  27. $work = get_work_data_by_id($workData['work_id']);
  28. protectWork($courseInfo, $work['parent_id']);
  29. if (user_is_author($workData['work_id']) ||
  30. $courseInfo['show_score'] == 0 &&
  31. $work['active'] == 1 &&
  32. $work['accepted'] == 1
  33. ) {
  34. if (Security::check_abs_path(
  35. $workData['file_path'],
  36. api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'
  37. )
  38. ) {
  39. DocumentManager::file_send_for_download(
  40. $workData['file_path'],
  41. true,
  42. $workData['file_name_to_show']
  43. );
  44. }
  45. } else {
  46. api_not_allowed(true);
  47. }
  48. } else {
  49. api_not_allowed(true);
  50. }