contact_attachment.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2016-2018
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes
  22. require_once "root.php";
  23. require_once "resources/require.php";
  24. //add multi-lingual support
  25. $language = new text;
  26. $text = $language->get();
  27. //get attachment uuid
  28. $contact_attachment_uuid = $_GET['id'];
  29. $action = $_GET['action'];
  30. //get media
  31. if (is_uuid($contact_attachment_uuid)) {
  32. $sql = "select attachment_filename, attachment_content from v_contact_attachments ";
  33. $sql .= "where contact_attachment_uuid = :contact_attachment_uuid ";
  34. $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
  35. $parameters['contact_attachment_uuid'] = $contact_attachment_uuid;
  36. $parameters['domain_uuid'] = $domain_uuid;
  37. $database = new database;
  38. $attachment = $database->select($sql, $parameters, 'row');
  39. unset($sql, $parameters);
  40. $attachment_type = strtolower(pathinfo($attachment['attachment_filename'], PATHINFO_EXTENSION));
  41. //determine mime type
  42. $content_type = 'application/octet-stream'; //set default
  43. $allowed_attachment_types = json_decode($_SESSION['contacts']['allowed_attachment_types']['text'], true);
  44. if (is_array($allowed_attachment_types) && sizeof($allowed_attachment_types) != 0) {
  45. if ($allowed_attachment_types[$attachment_type] != '') {
  46. $content_type = $allowed_attachment_types[$attachment_type];
  47. }
  48. }
  49. switch ($action) {
  50. case 'download':
  51. header("Content-type: ".$content_type."; charset=utf-8");
  52. header("Content-Disposition: attachment; filename=\"".$attachment['attachment_filename']."\"");
  53. header("Content-Length: ".strlen(base64_decode($attachment['attachment_content'])));
  54. echo base64_decode($attachment['attachment_content']);
  55. break;
  56. case 'display':
  57. echo " <table cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'>\n";
  58. echo " <tr>\n";
  59. echo " <td align='center' valign='middle'>\n";
  60. echo " <img src=\"data:".$content_type.";base64,".$attachment['attachment_content']."\" style='width: auto; max-width: 95%; height: auto; max-height: 800px; box-shadow: 0px 1px 20px #888; background-color: #fff; cursor: pointer;' onclick=\"$('#contact_attachment_layer').fadeOut(200);\" oncontextmenu=\"window.open('contact_attachment.php?id=".$contact_attachment_uuid."&action=download'); return false;\" title=\"".$text['message-click_close_save']."\">\n";
  61. echo " </td>\n";
  62. echo " </tr>\n";
  63. echo " </table>\n";
  64. break;
  65. }
  66. }
  67. ?>