Bootswatch, Summernote, and Captcheck mods for Mods for HESK (mods-for-hesk.com). In use at support.netsyms.com.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

view_attachment_functions.inc.php 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <?php
  2. function mfh_listAttachments($attachments = '', $reply = 0, $is_staff)
  3. {
  4. global $hesk_settings, $hesklang, $trackingID, $can_edit, $can_delete;
  5. $email = '';
  6. if (!$is_staff) {
  7. $email = $hesk_settings['e_query'];
  8. }
  9. /* Attachments disabled or not available */
  10. if (!$hesk_settings['attachments']['use'] || !strlen($attachments)) {
  11. return false;
  12. }
  13. /* List attachments */
  14. $att = explode(',', substr($attachments, 0, -1));
  15. echo '<div class="table-responsive">';
  16. echo '<table class="table table-striped attachment-table">';
  17. echo '<thead>
  18. <tr>
  19. <th>&nbsp;</th>
  20. <th>' . $hesklang['file_name'] . '</th>';
  21. if ($is_staff) {
  22. echo '<th>' . $hesklang['download_count'] . '</th>';
  23. }
  24. echo '<th>' . $hesklang['action'] . '</th>
  25. </tr>
  26. </thead>';
  27. echo '<tbody>';
  28. foreach ($att as $myatt) {
  29. list($att_id, $att_name) = explode('#', $myatt);
  30. $fileparts = pathinfo($att_name);
  31. $fontAwesomeIcon = mfh_getFontAwesomeIconForFileExtension($fileparts['extension']);
  32. echo '
  33. <tr>
  34. <td>';
  35. //-- File is an image
  36. if ($fontAwesomeIcon == 'fa fa-file-image-o') {
  37. //-- Get the actual image location and display a thumbnail. It will be linked to a modal to view a larger size.
  38. $path = mfh_getSavedNameUrlForAttachment($att_id, $is_staff);
  39. if ($path == '') {
  40. echo '<i class="fa fa-ban fa-4x" data-toggle="tooltip" title="' . $hesklang['attachment_removed'] . '"></i>';
  41. } else {
  42. echo '<span data-toggle="tooltip" title="' . $hesklang['click_to_preview'] . '">
  43. <img src="' . $path . '" alt="' . $hesklang['image'] . '" data-toggle="modal" data-target="#modal-attachment-' . $att_id . '">
  44. </span>';
  45. $download_path = '';
  46. if ($is_staff) {
  47. $download_path = '../';
  48. }
  49. echo '<div class="modal fade" id="modal-attachment-' . $att_id . '" tabindex="-1" role="dialog" aria-hidden="true">
  50. <div class="modal-dialog">
  51. <div class="modal-content">
  52. <div class="modal-header">
  53. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  54. <h4 class="modal-title" id="myModalLabel">' . $att_name . '</h4>
  55. </div>
  56. <div class="modal-body">
  57. <img class="img-responsive" src="' . $path . '" alt="' . $hesklang['image'] . '">
  58. </div>
  59. <div class="modal-footer">
  60. <button type="button" class="btn btn-default" data-dismiss="modal">' . $hesklang['close_modal'] . '</button>
  61. <a href="' . $download_path . 'download_attachment.php?att_id=' . $att_id . '&amp;track=' . $trackingID . $email . '" class="btn btn-success">' . $hesklang['dnl'] . '</a>
  62. </div>
  63. </div>
  64. </div>
  65. </div>';
  66. }
  67. } else {
  68. //-- Display the FontAwesome icon in the panel's body
  69. echo '<i class="' . $fontAwesomeIcon . ' fa-4x"></i>';
  70. }
  71. echo '
  72. </td>
  73. <td>
  74. <p>' . $att_name . '</p>
  75. </td>';
  76. if ($is_staff) {
  77. echo '<td>' . mfh_getNumberOfDownloadsForAttachment($att_id) . '</td>';
  78. }
  79. echo '<td>
  80. <div class="btn-group">';
  81. /* Can edit and delete tickets? */
  82. $download_path = '';
  83. if ($is_staff) {
  84. $download_path = '../';
  85. if ($can_edit && $can_delete) {
  86. echo '<a class="btn btn-danger" href="admin_ticket.php?delatt=' . $att_id . '&amp;reply=' . $reply . '&amp;track=' . $trackingID . '&amp;Refresh=' . mt_rand(10000, 99999) . '&amp;token=' . hesk_token_echo(0) . '" onclick="return hesk_confirmExecute(\'' . hesk_makeJsString($hesklang['pda']) . '\');" data-toggle="tooltip" data-placement="top" data-original-title="' . $hesklang['delete'] . '"><i class="fa fa-times"></i></a> ';
  87. }
  88. }
  89. echo '<a class="btn btn-success" href="' . $download_path . 'download_attachment.php?att_id=' . $att_id . '&amp;track=' . $trackingID . $email . '"
  90. data-toggle="tooltip" data-placement="top" data-original-title="' . $hesklang['dnl'] . '">
  91. <i class="fa fa-arrow-down"></i>
  92. </a>';
  93. echo '</div>
  94. </td>
  95. </tr>
  96. ';
  97. }
  98. echo '</tbody></table></div>';
  99. return true;
  100. } // End hesk_listAttachments()
  101. function mfh_getSavedNameUrlForAttachment($att_id, $is_staff)
  102. {
  103. global $hesk_settings;
  104. //-- Call the DB for the attachment
  105. $nameRS = hesk_dbQuery("SELECT `saved_name` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "attachments` WHERE `att_id` = " . hesk_dbEscape($att_id));
  106. $name = hesk_dbFetchAssoc($nameRS);
  107. if ($is_staff) {
  108. $realpath = '../' . $hesk_settings['attach_dir'] . '/' . $name['saved_name'];
  109. } else {
  110. $realpath = $hesk_settings['attach_dir'] . '/' . $name['saved_name'];
  111. }
  112. return !file_exists($realpath) ? '' : $realpath;
  113. }
  114. function mfh_getFontAwesomeIconForFileExtension($fileExtension)
  115. {
  116. $imageExtensions = array('jpg', 'jpeg', 'png', 'bmp', 'gif');
  117. //-- Word, Excel, and PPT file extensions: http://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions
  118. $wordFileExtensions = array('doc', 'docx', 'dotm', 'dot', 'docm', 'docb');
  119. $excelFileExtensions = array('xls', 'xlt', 'xlm', 'xlsx', 'xlsm', 'xltx', 'xltm');
  120. $pptFileExtensions = array('ppt', 'pot', 'pps', 'pptx', 'pptm', 'potx', 'potm', 'ppsx', 'ppsm', 'sldx', 'sldm');
  121. //-- File archive extensions: http://en.wikipedia.org/wiki/List_of_archive_formats
  122. $archiveFileExtensions = array('tar', 'gz', 'zip', 'rar', '7z', 'bz2', 'lz', 'lzma', 'tgz', 'tbz2', 'zipx');
  123. //-- Audio file extensions: http://en.wikipedia.org/wiki/Audio_file_format#List_of_formats
  124. $audioFileExtensions = array('3gp', 'act', 'aiff', 'aac', 'amr', 'au', 'awb', 'dct', 'dss', 'dvf', 'flac', 'gsm', 'iklax', 'ivs', 'm4a', 'm4p', 'mmf', 'mp3', 'mpc', 'msv', 'ogg', 'oga', 'opus', 'ra', 'rm', 'raw', 'tta', 'vox', 'wav', 'wma', 'wv');
  125. //-- Video file extensions: http://en.wikipedia.org/wiki/Video_file_format#List_of_video_file_formats
  126. $videoFileExtensions = array('webm', 'mkv', 'flv', 'drc', 'mng', 'avi', 'mov', 'qt', 'wmv', 'yuv', 'rm', 'rmvb', 'asf', 'mp4', 'm4p', 'm4v', 'mpg', 'mp2', 'mpeg', 'mpe', 'mpv', 'm2v', 'svi', '3gp', '3g2', 'mxf', 'roq', 'nsv');
  127. //-- The only one I know of :D
  128. $pdfFileExtensions = array('pdf');
  129. $textFileExtensions = array('txt');
  130. $icon = 'fa fa-file-';
  131. $fileExtension = strtolower($fileExtension);
  132. if (in_array($fileExtension, $imageExtensions)) {
  133. $icon .= 'image-o';
  134. } elseif (in_array($fileExtension, $wordFileExtensions)) {
  135. $icon .= 'word-o';
  136. } elseif (in_array($fileExtension, $excelFileExtensions)) {
  137. $icon .= 'excel-o';
  138. } elseif (in_array($fileExtension, $pptFileExtensions)) {
  139. $icon .= 'powerpoint-o';
  140. } elseif (in_array($fileExtension, $archiveFileExtensions)) {
  141. $icon .= 'archive-o';
  142. } elseif (in_array($fileExtension, $audioFileExtensions)) {
  143. $icon .= 'audio-o';
  144. } elseif (in_array($fileExtension, $videoFileExtensions)) {
  145. $icon .= 'video-o';
  146. } elseif (in_array($fileExtension, $pdfFileExtensions)) {
  147. $icon .= 'pdf-o';
  148. } elseif (in_array($fileExtension, $textFileExtensions)) {
  149. $icon .= 'text-o';
  150. } else {
  151. $icon .= 'o';
  152. }
  153. return $icon;
  154. }
  155. function output_dropzone_window() {
  156. echo '
  157. <div class="table table-striped" class="files" id="previews" style="display:none">
  158. <div id="template" class="file-row">
  159. <!-- This is used as the file preview template -->
  160. <div class="row">
  161. <div class="col-md-4">
  162. <span class="preview"><img class="img-responsive" data-dz-thumbnail></span>
  163. </div>
  164. <div class="col-md-8">
  165. <div class="row">
  166. <p class="name" data-dz-name></p>
  167. <i class="fa fa-trash fa-2x" style="color: gray; cursor: pointer" title="Remove file" data-dz-remove></i>
  168. <span class="size" data-dz-size></span>
  169. </div>
  170. <div class="row">
  171. <div class="progress progress-striped active" role="progressbar" id="total-progress">
  172. <div class="progress-bar progress-bar-success" style="width:0%;" data-dz-uploadprogress>
  173. <span id="percentage"></span>
  174. </div>
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. <div class="row">
  180. <div class="col-xs-12">
  181. <strong class="error text-danger" data-dz-errormessage></strong>
  182. </div>
  183. </div>
  184. </div>
  185. </div>';
  186. }
  187. function output_attachment_id_holder_container($id) {
  188. echo '<div id="attachment-holder-' . $id . '" class="hide"></div>';
  189. }
  190. function build_dropzone_markup($admin = false, $id = 'filedrop', $startingId = 1) {
  191. global $hesklang, $hesk_settings;
  192. $directory_separator = $admin ? '../' : '';
  193. echo '<div class="dropzone" id="' . $id . '">
  194. <div class="fallback">
  195. <input type="hidden" name="use-legacy-attachments" value="1">';
  196. for ($i = $startingId; $i <= $hesk_settings['attachments']['max_number']; $i++) {
  197. $cls = ($i == 1 && isset($_SESSION['iserror']) && in_array('attachments', $_SESSION['iserror'])) ? ' class="isError" ' : '';
  198. echo '<input type="file" name="attachment[' . $i . ']" size="50" ' . $cls . ' /><br />';
  199. }
  200. echo '</div>
  201. </div>
  202. <div class="btn btn-default btn-xs fileinput-button filedropbutton-' . $id . '">' . $hesklang['add_files'] . '</div><br>
  203. <a href="' . $directory_separator . 'file_limits.php" target="_blank"
  204. onclick="Javascript:hesk_window(\'' . $directory_separator . 'file_limits.php\',250,500);return false;">'. $hesklang['ful'] . '</a>';
  205. }
  206. function display_dropzone_field($url, $id = 'filedrop', $max_files_override = -1) {
  207. global $hesk_settings, $hesklang;
  208. output_dropzone_window();
  209. output_attachment_id_holder_container($id);
  210. $acceptedFiles = implode(',', $hesk_settings['attachments']['allowed_types']);
  211. $size = mfh_bytesToUnits($hesk_settings['attachments']['max_size']);
  212. $max_files = $max_files_override > -1 ? $max_files_override : $hesk_settings['attachments']['max_number'];
  213. echo "
  214. <script type=\"text/javascript\">
  215. Dropzone.options.".$id." = {
  216. init: function() {
  217. this.on('success', function(file, response) {
  218. // The response will only be the ID of the attachment in the database
  219. outputAttachmentIdHolder(response, '".$id."');
  220. // Add the database id to the file
  221. file['databaseId'] = response;
  222. });
  223. this.on('addedfile', function() {
  224. var numberOfFiles = $('#" . $id . " .file-row').length;
  225. var disabled = false;
  226. if (numberOfFiles >= " . $max_files . ") {
  227. disabled = true;
  228. }
  229. $('." . $id . "button-" . $id . "').attr('disabled', disabled);
  230. });
  231. this.on('removedfile', function(file) {
  232. // Remove the attachment from the database and the filesystem.
  233. removeAttachment(file['databaseId']);
  234. var numberOfFiles = $('#" . $id . " .file-row').length;
  235. var disabled = false;
  236. if (numberOfFiles >= " . $max_files . ") {
  237. disabled = true;
  238. }
  239. $('." . $id . "button-" . $id . "').attr('disabled', disabled);
  240. });
  241. this.on('complete', function(file) {
  242. // Stop animating if complete.
  243. $(file.previewTemplate).find('#total-progress').removeClass('active');
  244. });
  245. this.on('queuecomplete', function() {
  246. $('input[type=\"submit\"]').attr('disabled', false);
  247. });
  248. this.on('processing', function() {
  249. $('input[type=\"submit\"]').attr('disabled', true);
  250. });
  251. this.on('uploadprogress', function(file, percentage) {
  252. $(file.previewTemplate).find('#percentage').text(percentage + '%');
  253. });
  254. this.on('error', function(file, errorMessage, xhr) {
  255. $(file.previewTemplate).addClass('alert-danger');
  256. });
  257. },
  258. paramName: 'attachment',
  259. url: '" . $url . "',
  260. parallelUploads: ".$max_files.",
  261. uploadMultiple: true,
  262. maxFiles: ".$max_files.",
  263. acceptedFiles: ".json_encode($acceptedFiles).",
  264. maxFilesize: ".$size.", // MB
  265. dictDefaultMessage: ".json_encode($hesklang['attachment_viewer_message']).",
  266. dictFallbackMessage: '',
  267. dictInvalidFileType: ".json_encode($hesklang['attachment_invalid_type_message']).",
  268. dictResponseError: ".json_encode($hesklang['attachment_upload_error']).",
  269. dictFileTooBig: ".json_encode($hesklang['attachment_too_large']).",
  270. dictCancelUpload: ".json_encode($hesklang['attachment_cancel']).",
  271. dictCancelUploadConfirmation: ".json_encode($hesklang['attachment_confirm_cancel']).",
  272. dictRemoveFile: ".json_encode($hesklang['attachment_remove']).",
  273. dictMaxFilesExceeded: ".json_encode($hesklang['attachment_max_exceeded']).",
  274. previewTemplate: $('#previews').html(),
  275. clickable: '.filedropbutton-".$id."',
  276. uploadMultiple: false
  277. };
  278. </script>
  279. ";
  280. }