download.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.plugin.ticket
  5. */
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. api_block_anonymous_users();
  8. $user_id = api_get_user_id();
  9. if (!isset($_GET['file']) || !isset($_GET['title']) || !isset($_GET['ticket_id'])) {
  10. api_not_allowed();
  11. }
  12. if (!api_is_platform_admin()) {
  13. $ticket_id = intval($_GET['ticket_id']);
  14. $table_support_messages = Database::get_main_table(TABLE_TICKET_MESSAGE);
  15. $table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
  16. $table_support_message_attachments = Database::get_main_table(TABLE_TICKET_MESSAGE_ATTACHMENTS);
  17. $sql = "SELECT DISTINCT ticket.request_user
  18. FROM $table_support_tickets ticket,
  19. $table_support_messages message,
  20. $table_support_message_attachments attch
  21. WHERE ticket.ticket_id = message.ticket_id
  22. AND attch.message_id = message.message_id
  23. AND ticket.ticket_id = $ticket_id";
  24. $rs = Database::query($sql);
  25. $row_users = Database::fetch_array($rs, 'ASSOC');
  26. $user_request_id = $row_users['request_user'];
  27. if (intval($user_request_id) != $user_id) {
  28. api_not_allowed();
  29. }
  30. }
  31. // @todo replace by Security::check_abs_path()?
  32. $file_url = $_GET['file'];
  33. $file_url = str_replace('///', '&', $file_url);
  34. $file_url = str_replace(' ', '+', $file_url);
  35. $file_url = str_replace('/..', '', $file_url);
  36. $file_url = Database::escape_string($file_url);
  37. $title = $_GET['title'];
  38. $path_attachment = api_get_path(SYS_ARCHIVE_PATH);
  39. $path_message_attach = $path_attachment.'plugin_ticket_messageattch/';
  40. $full_file_name = $path_message_attach.$file_url;
  41. if (Security::check_abs_path($full_file_name, $path_message_attach)) {
  42. DocumentManager::file_send_for_download($full_file_name, true, $title);
  43. }
  44. exit;