download.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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['id']) || !isset($_GET['ticket_id'])) {
  10. api_not_allowed(true);
  11. }
  12. $ticket_id = (int) $_GET['ticket_id'];
  13. $ticketInfo = TicketManager::get_ticket_detail_by_id($ticket_id);
  14. if (empty($ticketInfo)) {
  15. api_not_allowed(true);
  16. }
  17. $messageAttachment = TicketManager::getTicketMessageAttachment($_GET['id']);
  18. if (empty($messageAttachment)) {
  19. api_not_allowed(true);
  20. }
  21. if (!api_is_platform_admin()) {
  22. $table_support_messages = Database::get_main_table(TABLE_TICKET_MESSAGE);
  23. $table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
  24. $table_support_message_attachments = Database::get_main_table(TABLE_TICKET_MESSAGE_ATTACHMENTS);
  25. $sql = "SELECT DISTINCT ticket.request_user
  26. FROM $table_support_tickets ticket,
  27. $table_support_messages message,
  28. $table_support_message_attachments attch
  29. WHERE ticket.ticket_id = message.ticket_id
  30. AND attch.message_id = message.message_id
  31. AND ticket.ticket_id = $ticket_id";
  32. $rs = Database::query($sql);
  33. $row_users = Database::fetch_array($rs, 'ASSOC');
  34. $user_request_id = $row_users['request_user'];
  35. if (intval($user_request_id) != $user_id) {
  36. api_not_allowed(true);
  37. }
  38. }
  39. api_download_uploaded_file(
  40. 'ticket_attachment',
  41. $ticket_id,
  42. $messageAttachment->getPath(),
  43. $messageAttachment->getFilename()
  44. );
  45. exit;