download.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. api_block_anonymous_users();
  5. $user_id = api_get_user_id();
  6. if (!isset($_GET['id']) || !isset($_GET['ticket_id'])) {
  7. api_not_allowed(true);
  8. }
  9. $ticket_id = (int) $_GET['ticket_id'];
  10. $ticketInfo = TicketManager::get_ticket_detail_by_id($ticket_id);
  11. if (empty($ticketInfo)) {
  12. api_not_allowed(true);
  13. }
  14. $messageAttachment = TicketManager::getTicketMessageAttachment($_GET['id']);
  15. if (empty($messageAttachment)) {
  16. api_not_allowed(true);
  17. }
  18. if (!api_is_platform_admin()) {
  19. $table_support_messages = Database::get_main_table(TABLE_TICKET_MESSAGE);
  20. $table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
  21. $table_support_message_attachments = Database::get_main_table(TABLE_TICKET_MESSAGE_ATTACHMENTS);
  22. $sql = "SELECT DISTINCT ticket.request_user
  23. FROM $table_support_tickets ticket,
  24. $table_support_messages message,
  25. $table_support_message_attachments attch
  26. WHERE ticket.ticket_id = message.ticket_id
  27. AND attch.message_id = message.message_id
  28. AND ticket.ticket_id = $ticket_id";
  29. $rs = Database::query($sql);
  30. $row_users = Database::fetch_array($rs, 'ASSOC');
  31. $user_request_id = $row_users['request_user'];
  32. if (intval($user_request_id) != $user_id) {
  33. api_not_allowed(true);
  34. }
  35. }
  36. api_download_uploaded_file(
  37. 'ticket_attachment',
  38. $ticket_id,
  39. $messageAttachment->getPath(),
  40. $messageAttachment->getFilename()
  41. );
  42. exit;