contact_attachments.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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) 2008-2020
  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. require_once "resources/check_auth.php";
  25. //check permissions
  26. if (permission_exists('contact_attachment_view')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //get the contact attachment list
  34. $sql = "select *, length(decode(attachment_content,'base64')) as attachment_size from v_contact_attachments ";
  35. $sql .= "where domain_uuid = :domain_uuid ";
  36. $sql .= "and contact_uuid = :contact_uuid ";
  37. $sql .= "order by attachment_primary desc, attachment_filename asc ";
  38. $parameters['domain_uuid'] = $domain_uuid;
  39. $parameters['contact_uuid'] = $contact_uuid;
  40. $database = new database;
  41. $contact_attachments = $database->select($sql, $parameters, 'all');
  42. unset($sql, $parameters);
  43. //show if exists
  44. if (is_array($contact_attachments) && @sizeof($contact_attachments) != 0) {
  45. //styles and attachment layer
  46. echo "<style>\n";
  47. echo " #contact_attachment_layer {\n";
  48. echo " z-index: 999999;\n";
  49. echo " position: absolute;\n";
  50. echo " left: 0px;\n";
  51. echo " top: 0px;\n";
  52. echo " right: 0px;\n";
  53. echo " bottom: 0px;\n";
  54. echo " text-align: center;\n";
  55. echo " vertical-align: middle;\n";
  56. echo " }\n";
  57. echo "</style>\n";
  58. echo "<div id='contact_attachment_layer' style='display: none;'></div>\n";
  59. //script
  60. echo "<script>\n";
  61. echo " function display_attachment(id) {\n";
  62. echo " $('#contact_attachment_layer').load('contact_attachment.php?id=' + id + '&action=display', function(){\n";
  63. echo " $('#contact_attachment_layer').fadeIn(200);\n";
  64. echo " });\n";
  65. echo " }\n";
  66. echo "</script>\n";
  67. //show the content
  68. echo "<div class='action_bar sub shrink'>\n";
  69. echo " <div class='heading'><b>".$text['label-attachments']."</b></div>\n";
  70. echo " <div style='clear: both;'></div>\n";
  71. echo "</div>\n";
  72. echo "<table class='list'>\n";
  73. echo "<tr class='list-header'>\n";
  74. if (permission_exists('contact_attachment_delete')) {
  75. echo " <th class='checkbox'>\n";
  76. echo " <input type='checkbox' id='checkbox_all_attachments' name='checkbox_all' onclick=\"edit_all_toggle('attachments');\" ".($contact_attachments ?: "style='visibility: hidden;'").">\n";
  77. echo " </th>\n";
  78. }
  79. echo "<th class='pct-15'>".$text['label-type']."</th>\n";
  80. echo "<th>".$text['label-attachment_filename']."</th>\n";
  81. echo "<th>".$text['label-attachment_size']."</th>\n";
  82. echo "<th>".$text['label-tools']."</th>\n";
  83. echo "<th class='hide-md-dn'>".$text['label-attachment_description']."</th>\n";
  84. if (permission_exists('contact_attachment_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  85. echo " <td class='action-button'>&nbsp;</td>\n";
  86. }
  87. echo "</tr>\n";
  88. if (is_array($contact_attachments) && @sizeof($contact_attachments) != 0) {
  89. $x = 0;
  90. foreach ($contact_attachments as $row) {
  91. $attachment_type = strtolower(pathinfo($row['attachment_filename'], PATHINFO_EXTENSION));
  92. $attachment_type_label = $attachment_type == 'jpg' || $attachment_type == 'jpeg' || $attachment_type == 'gif' || $attachment_type == 'png' ? $text['label-image'] : $text['label-file'];
  93. if (permission_exists('contact_attachment_edit')) {
  94. $list_row_url = "contact_attachment_edit.php?contact_uuid=".urlencode($row['contact_uuid'])."&id=".urlencode($row['contact_attachment_uuid']);
  95. }
  96. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  97. if (permission_exists('contact_attachment_delete')) {
  98. echo " <td class='checkbox'>\n";
  99. echo " <input type='checkbox' name='contact_attachments[$x][checked]' id='checkbox_".$x."' class='chk_delete checkbox_attachments' value='true' onclick=\"edit_delete_action('attachments');\">\n";
  100. echo " <input type='hidden' name='contact_attachments[$x][uuid]' value='".escape($row['contact_attachment_uuid'])."' />\n";
  101. echo " </td>\n";
  102. }
  103. echo " <td>".$attachment_type_label." ".($row['attachment_primary'] ? "&nbsp;<i class='fas fa-star fa-xs' style='float: right; margin-top: 0.5em; margin-right: -0.5em;' title=\"".$text['label-primary']."\"></i>" : null)."</td>\n";
  104. echo " <td><a href='".$list_row_url."'>".escape($row['attachment_filename'])."</a></td>\n";
  105. echo " <td>".strtoupper(byte_convert($row['attachment_size']))."</td>\n";
  106. echo " <td class='no-link' style='cursor: pointer;'>";
  107. if ($attachment_type == 'jpg' || $attachment_type == 'jpeg' || $attachment_type == 'gif' || $attachment_type == 'png') {
  108. echo button::create(['type'=>'button','class'=>'link','label'=>$text['button-view'],'onclick'=>"display_attachment('".escape($row['contact_attachment_uuid'])."');"]);
  109. }
  110. else {
  111. echo button::create(['type'=>'button','class'=>'link','label'=>$text['label-download'],'onclick'=>"window.location='contact_attachment.php?id=".urlencode($row['contact_attachment_uuid'])."&action=download';"]);
  112. }
  113. echo " </td>\n";
  114. echo " <td class='description overflow hide-md-dn'>".escape($row['attachment_description'])."</td>\n";
  115. if (permission_exists('contact_attachment_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  116. echo " <td class='action-button'>\n";
  117. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  118. echo " </td>\n";
  119. }
  120. echo "</tr>\n";
  121. $x++;
  122. }
  123. }
  124. unset($contact_attachments);
  125. echo "</table>";
  126. echo "<br />\n";
  127. }
  128. ?>