From 8cba950253bc897151a60e6542179860a4ee6a1b Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 6 Aug 2015 12:21:43 -0400 Subject: [PATCH] #275 Customers now have the new attachment viewer --- admin/admin_ticket.php | 156 +------------------------ inc/view_attachment_functions.inc.php | 162 ++++++++++++++++++++++++++ ticket.php | 36 +----- 3 files changed, 168 insertions(+), 186 deletions(-) create mode 100644 inc/view_attachment_functions.inc.php diff --git a/admin/admin_ticket.php b/admin/admin_ticket.php index 27b48c4c..02073ebd 100644 --- a/admin/admin_ticket.php +++ b/admin/admin_ticket.php @@ -42,6 +42,7 @@ require(HESK_PATH . 'modsForHesk_settings.inc.php'); require(HESK_PATH . 'inc/common.inc.php'); require(HESK_PATH . 'inc/admin_functions.inc.php'); require(HESK_PATH . 'inc/status_functions.inc.php'); +require(HESK_PATH . 'inc/view_attachment_functions.inc.php'); hesk_load_database_functions(); hesk_session_start(); @@ -1430,7 +1431,7 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); } } /* Attachments */ - hesk_listAttachments($ticket['attachments']); + mfh_listAttachments($ticket['attachments'], 0, true); // Show suggested KB articles if ($hesk_settings['kb_enable'] && $hesk_settings['kb_recommendanswers'] && strlen($ticket['articles']) ) @@ -1504,157 +1505,6 @@ require_once(HESK_PATH . 'inc/footer.inc.php'); /*** START FUNCTIONS ***/ - -function hesk_listAttachments($attachments='', $reply=0, $white=1) -{ - global $hesk_settings, $hesklang, $trackingID, $can_edit, $can_delete; - - /* Attachments disabled or not available */ - if ( ! $hesk_settings['attachments']['use'] || ! strlen($attachments) ) - { - return false; - } - - /* List attachments */ - echo '

'.$hesklang['attachments'].':


'; - $att=explode(',',substr($attachments, 0, -1)); - echo '
'; - echo ''; - echo ''; - echo ''; - foreach ($att as $myatt) - { - - list($att_id, $att_name) = explode('#', $myatt); - $fileparts = pathinfo($att_name); - $fontAwesomeIcon = hesk_getFontAwesomeIconForFileExtension($fileparts['extension']); - echo ' - - - - - - - '; - } - echo '
 '.$hesklang['file_name'].''.$hesklang['download_count'].''.$hesklang['action'].'
'; - //-- File is an image - if ($fontAwesomeIcon == 'fa fa-file-image-o') { - - //-- Get the actual image location and display a thumbnail. It will be linked to a modal to view a larger size. - $path = hesk_getSavedNameUrlForAttachment($att_id); - if ($path == '') { - echo ''; - } else { - echo ' - '.$hesklang['image'].' - '; - echo ''; - } - } else { - //-- Display the FontAwesome icon in the panel's body - echo ''; - } - echo' - -

'.$att_name.'

-
- '.mfh_getNumberOfDownloadsForAttachment($att_id).' - -
'; - /* Can edit and delete tickets? */ - if ($can_edit && $can_delete) - { - echo ' '; - } - echo ' - - '; - echo '
-
'; - - return true; -} // End hesk_listAttachments() - -function hesk_getSavedNameUrlForAttachment($att_id) -{ - global $hesk_settings; - - //-- Call the DB for the attachment - $nameRS = hesk_dbQuery("SELECT `saved_name` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` WHERE `att_id` = ".hesk_dbEscape($att_id)); - $name = hesk_dbFetchAssoc($nameRS); - $realpath = '../'.$hesk_settings['attach_dir'] . '/' . $name['saved_name']; - - return !file_exists($realpath) ? '' : $realpath; -} - -function hesk_getFontAwesomeIconForFileExtension($fileExtension) -{ - $imageExtensions = array('jpg','jpeg','png','bmp','gif'); - - //-- Word, Excel, and PPT file extensions: http://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions - $wordFileExtensions = array('doc','docx','dotm','dot','docm','docb'); - $excelFileExtensions = array('xls','xlt','xlm','xlsx','xlsm','xltx','xltm'); - $pptFileExtensions = array('ppt','pot','pps','pptx','pptm','potx','potm','ppsx','ppsm','sldx','sldm'); - - //-- File archive extensions: http://en.wikipedia.org/wiki/List_of_archive_formats - $archiveFileExtensions = array('tar','gz','zip','rar','7z','bz2','lz','lzma','tgz','tbz2','zipx'); - - //-- Audio file extensions: http://en.wikipedia.org/wiki/Audio_file_format#List_of_formats - $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'); - - //-- Video file extensions: http://en.wikipedia.org/wiki/Video_file_format#List_of_video_file_formats - $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'); - - //-- The only one I know of :D - $pdfFileExtensions = array('pdf'); - - $textFileExtensions = array('txt'); - - $icon = 'fa fa-file-'; - $fileExtension = strtolower($fileExtension); - if (in_array($fileExtension, $imageExtensions)) { - $icon.='image-o'; - } elseif (in_array($fileExtension, $wordFileExtensions)) { - $icon.='word-o'; - } elseif (in_array($fileExtension, $excelFileExtensions)) { - $icon.='excel-o'; - } elseif (in_array($fileExtension, $pptFileExtensions)) { - $icon.='powerpoint-o'; - } elseif (in_array($fileExtension, $archiveFileExtensions)) { - $icon.='archive-o'; - } elseif (in_array($fileExtension, $audioFileExtensions)) { - $icon.='audio-o'; - } elseif (in_array($fileExtension, $videoFileExtensions)) { - $icon.='video-o'; - } elseif (in_array($fileExtension, $pdfFileExtensions)) { - $icon.='pdf-o'; - } elseif (in_array($fileExtension, $textFileExtensions)) { - $icon.='text-o'; - } else { - $icon.='o'; - } - return $icon; -} - - function hesk_getAdminButtons($reply=0,$white=1) { global $hesk_settings, $hesklang, $ticket, $reply, $trackingID, $can_edit, $can_archive, $can_delete, $isManager; @@ -1854,7 +1704,7 @@ function hesk_printTicketReplies() { } ?>

- '.$hesklang['attachments'].':


'; + $att=explode(',',substr($attachments, 0, -1)); + echo '
'; + echo ''; + echo ' + + + '; + if ($is_staff) { + echo ''; + } + echo ' + + '; + echo ''; + foreach ($att as $myatt) + { + + list($att_id, $att_name) = explode('#', $myatt); + $fileparts = pathinfo($att_name); + $fontAwesomeIcon = mfh_getFontAwesomeIconForFileExtension($fileparts['extension']); + echo ' + + + '; + if ($is_staff) { + echo ''; + } + echo ' + + '; + } + echo '
 ' . $hesklang['file_name'] . ''.$hesklang['download_count'].''.$hesklang['action'].'
'; + //-- File is an image + if ($fontAwesomeIcon == 'fa fa-file-image-o') { + + //-- Get the actual image location and display a thumbnail. It will be linked to a modal to view a larger size. + $path = mfh_getSavedNameUrlForAttachment($att_id, $is_staff); + if ($path == '') { + echo ''; + } else { + echo ' + '.$hesklang['image'].' + '; + echo ''; + } + } else { + //-- Display the FontAwesome icon in the panel's body + echo ''; + } + echo' + +

'.$att_name.'

+
'.mfh_getNumberOfDownloadsForAttachment($att_id).' +
'; + /* Can edit and delete tickets? */ + if ($is_staff && $can_edit && $can_delete) + { + echo ' '; + } + echo ' + + '; + echo '
+
'; + + return true; +} // End hesk_listAttachments() + +function mfh_getSavedNameUrlForAttachment($att_id, $is_staff) +{ + global $hesk_settings; + + //-- Call the DB for the attachment + $nameRS = hesk_dbQuery("SELECT `saved_name` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` WHERE `att_id` = ".hesk_dbEscape($att_id)); + $name = hesk_dbFetchAssoc($nameRS); + if ($is_staff) { + $realpath = '../'.$hesk_settings['attach_dir'] . '/' . $name['saved_name']; + } else { + $realpath = $hesk_settings['attach_dir'] . '/' . $name['saved_name']; + } + + return !file_exists($realpath) ? '' : $realpath; +} + +function mfh_getFontAwesomeIconForFileExtension($fileExtension) +{ + $imageExtensions = array('jpg','jpeg','png','bmp','gif'); + + //-- Word, Excel, and PPT file extensions: http://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions + $wordFileExtensions = array('doc','docx','dotm','dot','docm','docb'); + $excelFileExtensions = array('xls','xlt','xlm','xlsx','xlsm','xltx','xltm'); + $pptFileExtensions = array('ppt','pot','pps','pptx','pptm','potx','potm','ppsx','ppsm','sldx','sldm'); + + //-- File archive extensions: http://en.wikipedia.org/wiki/List_of_archive_formats + $archiveFileExtensions = array('tar','gz','zip','rar','7z','bz2','lz','lzma','tgz','tbz2','zipx'); + + //-- Audio file extensions: http://en.wikipedia.org/wiki/Audio_file_format#List_of_formats + $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'); + + //-- Video file extensions: http://en.wikipedia.org/wiki/Video_file_format#List_of_video_file_formats + $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'); + + //-- The only one I know of :D + $pdfFileExtensions = array('pdf'); + + $textFileExtensions = array('txt'); + + $icon = 'fa fa-file-'; + $fileExtension = strtolower($fileExtension); + if (in_array($fileExtension, $imageExtensions)) { + $icon.='image-o'; + } elseif (in_array($fileExtension, $wordFileExtensions)) { + $icon.='word-o'; + } elseif (in_array($fileExtension, $excelFileExtensions)) { + $icon.='excel-o'; + } elseif (in_array($fileExtension, $pptFileExtensions)) { + $icon.='powerpoint-o'; + } elseif (in_array($fileExtension, $archiveFileExtensions)) { + $icon.='archive-o'; + } elseif (in_array($fileExtension, $audioFileExtensions)) { + $icon.='audio-o'; + } elseif (in_array($fileExtension, $videoFileExtensions)) { + $icon.='video-o'; + } elseif (in_array($fileExtension, $pdfFileExtensions)) { + $icon.='pdf-o'; + } elseif (in_array($fileExtension, $textFileExtensions)) { + $icon.='text-o'; + } else { + $icon.='o'; + } + return $icon; +} \ No newline at end of file diff --git a/ticket.php b/ticket.php index ff9412c4..bc1e34c2 100644 --- a/ticket.php +++ b/ticket.php @@ -40,6 +40,7 @@ define('WYSIWYG',1); /* Get all the required files and functions */ require(HESK_PATH . 'hesk_settings.inc.php'); require(HESK_PATH . 'inc/common.inc.php'); +require(HESK_PATH . 'inc/view_attachment_functions.inc.php'); // Are we in maintenance mode? hesk_check_maintenance(); @@ -407,7 +408,7 @@ if (!$show['show']) { } } /* Attachments */ - hesk_listAttachments($ticket['attachments'], $i); + mfh_listAttachments($ticket['attachments'], $i, false); ?>
@@ -726,7 +727,7 @@ function hesk_printCustomerTicketReplies()
- +
@@ -738,37 +739,6 @@ function hesk_printCustomerTicketReplies() } // End hesk_printCustomerTicketReplies() -function hesk_listAttachments($attachments='', $white=1) -{ - global $hesk_settings, $hesklang, $trackingID; - - /* Attachments disabled or not available */ - if ( ! $hesk_settings['attachments']['use'] || ! strlen($attachments) ) - { - return false; - } - - /* Style and mousover/mousout */ - $tmp = $white ? 'White' : 'Blue'; - $style = 'class="option'.$tmp.'OFF" onmouseover="this.className=\'option'.$tmp.'ON\'" onmouseout="this.className=\'option'.$tmp.'OFF\'"'; - - /* List attachments */ - echo '

'.$hesklang['attachments'].':
'; - $att=explode(',',substr($attachments, 0, -1)); - foreach ($att as $myatt) - { - list($att_id, $att_name) = explode('#', $myatt); - - echo ' - '.$hesklang['dnl'].' '.$att_name.' - '.$att_name.'
- '; - } - echo '

'; - - return true; -} // End hesk_listAttachments() - function hesk_getCustomerButtons($white=1) {