From 121df747f540609dd69b3847df739b77001c421e Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Mon, 3 Aug 2015 22:08:55 -0400 Subject: [PATCH 01/10] #275 Add download_attachment to source control --- .gitignore | 1 - download_attachment.php | 175 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 1 deletion(-) create mode 100755 download_attachment.php diff --git a/.gitignore b/.gitignore index 7b12609a..02bb49b7 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,6 @@ docs/docs_style.css docs/index.html docs/quick-guide.html docs/step-by-step-guide.html -download_attachment.php file_limits.php footer.txt header.txt diff --git a/download_attachment.php b/download_attachment.php new file mode 100755 index 00000000..a6ad6a22 --- /dev/null +++ b/download_attachment.php @@ -0,0 +1,175 @@ + $chunksize) +{ + $handle = fopen($realpath, 'rb'); + $buffer = ''; + while ( ! feof($handle)) + { + set_time_limit(300); + $buffer = fread($handle, $chunksize); + echo $buffer; + flush(); + } + fclose($handle); +} +else +{ + readfile($realpath); +} + +exit(); +?> From f5cc9da7926f4bbcbd427addb36e8a1df1e8b3ae Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Mon, 3 Aug 2015 22:10:57 -0400 Subject: [PATCH 02/10] #275 Add download count column to attachments table --- install/mods-for-hesk/sql/installSql.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/install/mods-for-hesk/sql/installSql.php b/install/mods-for-hesk/sql/installSql.php index 53405010..aa52a037 100644 --- a/install/mods-for-hesk/sql/installSql.php +++ b/install/mods-for-hesk/sql/installSql.php @@ -2,7 +2,6 @@ define('IN_SCRIPT', 1); require(HESK_PATH . 'hesk_settings.inc.php'); require(HESK_PATH . 'inc/common.inc.php'); -echo $hesklang['yes']; function executeQuery($sql) { global $hesk_last_query; @@ -557,6 +556,8 @@ function execute240Scripts() { global $hesk_settings; hesk_dbConnect(); + + // Setup quick help sections executeQuery("CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."quick_help_sections` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `location` VARCHAR(100) NOT NULL, @@ -572,6 +573,7 @@ function execute240Scripts() { executeQuery("INSERT INTO `hesk_quick_help_sections` (`location`, `show`) VALUES ('knowledgebase', '1')"); + // Setup status improvement tables executeQuery("CREATE TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."text_to_status_xref` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `language` VARCHAR(200) NOT NULL, @@ -586,6 +588,11 @@ function execute240Scripts() { WHERE `id`='".intval($myStatus['ID'])."' LIMIT 1"); $i += 10; } + + // Process attachment improvement tables + executeQuery("ALTER TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` ADD COLUMN `download_count` INT NOT NULL DEFAULT 0"); + + executeQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."settings` SET `Value` = '2.4.0' WHERE `Key` = 'modsForHeskVersion'"); } function initializeXrefTable() { From e7a90e66e44325ea1da95024c2e8d22f17d65056 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Mon, 3 Aug 2015 22:20:38 -0400 Subject: [PATCH 03/10] #275 Add kb attachment download count --- install/mods-for-hesk/sql/installSql.php | 1 + 1 file changed, 1 insertion(+) diff --git a/install/mods-for-hesk/sql/installSql.php b/install/mods-for-hesk/sql/installSql.php index aa52a037..ccf64750 100644 --- a/install/mods-for-hesk/sql/installSql.php +++ b/install/mods-for-hesk/sql/installSql.php @@ -591,6 +591,7 @@ function execute240Scripts() { // Process attachment improvement tables executeQuery("ALTER TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` ADD COLUMN `download_count` INT NOT NULL DEFAULT 0"); + executeQuery("ALTER TABLE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_attachments` ADD COLUMN `download_count` INT NOT NULL DEFAULT 0"); executeQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."settings` SET `Value` = '2.4.0' WHERE `Key` = 'modsForHeskVersion'"); } From 22d6d3569cbdaacebbe2521c171047b91fb8f608 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Mon, 3 Aug 2015 22:20:49 -0400 Subject: [PATCH 04/10] #275 Update download count for each attachment --- download_attachment.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/download_attachment.php b/download_attachment.php index a6ad6a22..387eb5c8 100755 --- a/download_attachment.php +++ b/download_attachment.php @@ -95,6 +95,9 @@ if ( isset($_GET['kb_att']) ) hesk_checkPermission('can_man_kb'); } } + + // Update the download count + hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_attachments` SET `download_count` = `download_count` + 1 WHERE `att_id` = '{$att_id}'"); } // Ticket attachments @@ -132,6 +135,9 @@ else hesk_error($hesklang['perm_deny']); } } + + // Update the download count + hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` SET `download_count` = `download_count` + 1 WHERE `att_id` = '{$att_id}'"); } // Path of the file on the server From f375859de3ebaea3ec4650b72174d6852bbaa804 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Tue, 4 Aug 2015 12:37:18 -0400 Subject: [PATCH 05/10] #275 Only update dl count if the attachment exists --- download_attachment.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/download_attachment.php b/download_attachment.php index 387eb5c8..e5907d34 100755 --- a/download_attachment.php +++ b/download_attachment.php @@ -95,9 +95,6 @@ if ( isset($_GET['kb_att']) ) hesk_checkPermission('can_man_kb'); } } - - // Update the download count - hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_attachments` SET `download_count` = `download_count` + 1 WHERE `att_id` = '{$att_id}'"); } // Ticket attachments @@ -137,7 +134,7 @@ else } // Update the download count - hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` SET `download_count` = `download_count` + 1 WHERE `att_id` = '{$att_id}'"); + } // Path of the file on the server @@ -149,6 +146,13 @@ if ( ! file_exists($realpath)) hesk_error($hesklang['attdel']); } +// Update the download count +if ( isset($_GET['kb_att']) ) { + hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."kb_attachments` SET `download_count` = `download_count` + 1 WHERE `att_id` = '{$att_id}'"); +} else { + hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` SET `download_count` = `download_count` + 1 WHERE `att_id` = '{$att_id}'"); +} + // Send the file as an attachment to prevent malicious code from executing header("Pragma: "); # To fix a bug in IE when running https header("Cache-Control: "); # To fix a bug in IE when running https From 246d2e626188e52c7cdf48d964f00b1c47ed9665 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Tue, 4 Aug 2015 12:37:36 -0400 Subject: [PATCH 06/10] #275 Show download count next to attachment name --- admin/admin_ticket.php | 5 ++++- inc/common.inc.php | 9 +++++++++ language/en/text.php | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/admin/admin_ticket.php b/admin/admin_ticket.php index 6b4cf175..27b48c4c 100644 --- a/admin/admin_ticket.php +++ b/admin/admin_ticket.php @@ -1520,7 +1520,7 @@ function hesk_listAttachments($attachments='', $reply=0, $white=1) $att=explode(',',substr($attachments, 0, -1)); echo '
'; echo ''; - echo ''; + echo ''; echo ''; foreach ($att as $myatt) { @@ -1569,6 +1569,9 @@ function hesk_listAttachments($attachments='', $reply=0, $white=1) +
 '.$hesklang['file_name'].''.$hesklang['action'].'
 '.$hesklang['file_name'].''.$hesklang['download_count'].''.$hesklang['action'].'

'.$att_name.'

+ '.mfh_getNumberOfDownloadsForAttachment($att_id).' +
'; /* Can edit and delete tickets? */ diff --git a/inc/common.inc.php b/inc/common.inc.php index 5a6a7074..1c43e76f 100644 --- a/inc/common.inc.php +++ b/inc/common.inc.php @@ -1972,4 +1972,13 @@ function mfh_getDisplayTextForStatusId($statusId) { // Fallback to the language key return $hesklang[$statusRec['Key']]; } +} + +function mfh_getNumberOfDownloadsForAttachment($att_id, $table='attachments') +{ + global $hesk_settings; + + $res = hesk_dbQuery('SELECT `download_count` FROM `'.hesk_dbEscape($hesk_settings['db_pfix'].$table)."` WHERE `att_id` = ".intval($att_id)); + $rec = hesk_dbFetchAssoc($res); + return $rec['download_count']; } \ No newline at end of file diff --git a/language/en/text.php b/language/en/text.php index f193e14c..f3f07ba1 100644 --- a/language/en/text.php +++ b/language/en/text.php @@ -53,6 +53,7 @@ $hesklang['status_sort'] = 'Status Sorting'; $hesklang['status_sort_help'] = 'Determines if statuses shown on the manage statuses page and all dropdowns are sorted by the user-defined order (default), or sorted alphabetically.'; $hesklang['cannot_delete_status_tickets'] = 'This status cannot be deleted because there are tickets set to this status.'; $hesklang['default_statuses_updated'] = 'Default statuses have been updated!'; +$hesklang['download_count'] = 'Download Count'; // ADDED OR MODIFIED IN Mods for HESK 2.3.0 $hesklang['sm_icon'] = 'Icon'; From 8cba950253bc897151a60e6542179860a4ee6a1b Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 6 Aug 2015 12:21:43 -0400 Subject: [PATCH 07/10] #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) { From 598e19130bc39b0c61a0d677b98150c5a131f1a8 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 6 Aug 2015 12:27:30 -0400 Subject: [PATCH 08/10] #275 Add attachments.inc.php to source control --- .gitignore | 1 - inc/attachments.inc.php | 133 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 inc/attachments.inc.php diff --git a/.gitignore b/.gitignore index 02bb49b7..e4ef0e68 100644 --- a/.gitignore +++ b/.gitignore @@ -146,7 +146,6 @@ img/unlock.png img/vertical.jpg img/view.png inc/assignment_search.inc.php -inc/attachments.inc.php inc/calendar/img/cal.gif inc/calendar/img/next_mon.gif inc/calendar/img/next_year.gif diff --git a/inc/attachments.inc.php b/inc/attachments.inc.php new file mode 100644 index 00000000..71521905 --- /dev/null +++ b/inc/attachments.inc.php @@ -0,0 +1,133 @@ + $hesk_settings['attachments']['max_size']) + { + return hesk_fileError(sprintf($hesklang['file_too_large'], $file_realname)); + } + else + { + $file_size = $_FILES['attachment']['size'][$i]; + } + + /* Generate a random file name */ + $useChars='AEUYBDGHJLMNPQRSTVWXZ123456789'; + $tmp = uniqid(); + for($j=1;$j<10;$j++) + { + $tmp .= $useChars{mt_rand(0,29)}; + } + + if (defined('KB')) + { + $file_name = substr(md5($tmp . $file_realname), 0, 200) . $ext; + } + else + { + $file_name = substr($trackingID . '_' . md5($tmp . $file_realname), 0, 200) . $ext; + } + + // Does the temporary file exist? If not, probably server-side configuration limits have been reached + // Uncomment this for debugging purposes + /* + if ( ! file_exists($_FILES['attachment']['tmp_name'][$i]) ) + { + return hesk_fileError($hesklang['fnuscphp']); + } + */ + + /* If upload was successful let's create the headers */ + if ( ! move_uploaded_file($_FILES['attachment']['tmp_name'][$i], dirname(dirname(__FILE__)).'/'.$hesk_settings['attach_dir'].'/'.$file_name)) + { + return hesk_fileError($hesklang['cannot_move_tmp']); + } + + $info = array( + 'saved_name'=> $file_name, + 'real_name' => $file_realname, + 'size' => $file_size + ); + + return $info; +} // End hesk_uploadFile() + + +function hesk_fileError($error) +{ + global $hesk_settings, $hesklang, $trackingID; + global $hesk_error_buffer; + + $hesk_error_buffer['attachments'] = $error; + + return false; +} // End hesk_fileError() + + +function hesk_removeAttachments($attachments) +{ + global $hesk_settings, $hesklang; + + $hesk_settings['server_path'] = dirname(dirname(__FILE__)).'/'.$hesk_settings['attach_dir'].'/'; + + foreach ($attachments as $myatt) + { + hesk_unlink($hesk_settings['server_path'].$myatt['saved_name']); + } + + return true; +} // End hesk_removeAttachments() From 698e0b678ac88c2289801581177b09250a716ac1 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 6 Aug 2015 12:46:14 -0400 Subject: [PATCH 09/10] #275 Add setting for knowledgebase attachments folder --- admin/admin_settings.php | 19 +++++++++++++++++-- admin/admin_settings_save.php | 6 +++++- install/mods-for-hesk/sql/installSql.php | 9 +++++++++ language/en/text.php | 4 ++++ modsForHesk_settings.inc.php | 5 ++++- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/admin/admin_settings.php b/admin/admin_settings.php index 5e578079..a9d235b6 100644 --- a/admin/admin_settings.php +++ b/admin/admin_settings.php @@ -697,9 +697,9 @@ if ( defined('HESK_DEMO') )
- +
- +
@@ -1287,6 +1287,21 @@ if ( defined('HESK_DEMO') ) ?>
+ +
+ +
+ +
+