From 194c4a0dadf7665c4118d5b50cd58ac903f4e943 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 6 Aug 2015 12:56:44 -0400 Subject: [PATCH] #275 Utilize the separated folders option --- admin/manage_knowledgebase.php | 5 +++-- download_attachment.php | 4 ++++ inc/attachments.inc.php | 21 +++++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/admin/manage_knowledgebase.php b/admin/manage_knowledgebase.php index 3b2f50b2..efe6e526 100644 --- a/admin/manage_knowledgebase.php +++ b/admin/manage_knowledgebase.php @@ -37,6 +37,7 @@ define('HESK_PATH','../'); /* Get all the required files and functions */ require(HESK_PATH . 'hesk_settings.inc.php'); +require(HESK_PATH . 'modsForHesk_settings.inc.php'); require(HESK_PATH . 'inc/common.inc.php'); require(HESK_PATH . 'inc/admin_functions.inc.php'); hesk_load_database_functions(); @@ -1113,7 +1114,7 @@ function save_article() $attachments = array(); for ($i=1;$i<=3;$i++) { - $att = hesk_uploadFile($i); + $att = hesk_uploadFile($i, false); if ( ! empty($att)) { $attachments[$i] = $att; @@ -1922,7 +1923,7 @@ function new_article() $attachments = array(); for ($i=1;$i<=3;$i++) { - $att = hesk_uploadFile($i); + $att = hesk_uploadFile($i, false); if ( ! empty($att)) { $attachments[$i] = $att; diff --git a/download_attachment.php b/download_attachment.php index e5907d34..dab63c42 100755 --- a/download_attachment.php +++ b/download_attachment.php @@ -37,6 +37,7 @@ define('HESK_PATH','./'); // Get all the required files and functions require(HESK_PATH . 'hesk_settings.inc.php'); +require(HESK_PATH . 'modsForHesk_settings.inc.php'); require(HESK_PATH . 'inc/common.inc.php'); hesk_load_database_functions(); @@ -139,6 +140,9 @@ else // Path of the file on the server $realpath = $hesk_settings['attach_dir'] . '/' . $file['saved_name']; +if (isset($_GET['kb_att'])) { + $realpath = $modsForHesk_settings['kb_attach_dir'] . '/' . $file['saved_name']; +} // Perhaps the file has been deleted? if ( ! file_exists($realpath)) diff --git a/inc/attachments.inc.php b/inc/attachments.inc.php index 71521905..8a56797a 100644 --- a/inc/attachments.inc.php +++ b/inc/attachments.inc.php @@ -38,9 +38,9 @@ if (!defined('IN_SCRIPT')) {die('Invalid attempt');} /*************************** Function hesk_uploadFiles() ***************************/ -function hesk_uploadFile($i) +function hesk_uploadFile($i, $isTicket = true) { - global $hesk_settings, $hesklang, $trackingID, $hesk_error_buffer; + global $hesk_settings, $hesklang, $trackingID, $hesk_error_buffer, $modsForHesk_settings; /* Return if name is empty */ if (empty($_FILES['attachment']['name'][$i])) {return '';} @@ -92,7 +92,11 @@ function hesk_uploadFile($i) */ /* 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)) + $directory = $hesk_settings['attach_dir']; + if (!$isTicket) { + $directory = $modsForHesk_settings['kb_attach_dir']; + } + if ( ! move_uploaded_file($_FILES['attachment']['tmp_name'][$i], dirname(dirname(__FILE__)).'/'.$directory.'/'.$file_name)) { return hesk_fileError($hesklang['cannot_move_tmp']); } @@ -118,11 +122,16 @@ function hesk_fileError($error) } // End hesk_fileError() -function hesk_removeAttachments($attachments) +function hesk_removeAttachments($attachments, $isTicket) { - global $hesk_settings, $hesklang; + global $hesk_settings, $hesklang, $modsForHesk_settings; + + $directory = $hesk_settings['attach_dir']; + if (!$isTicket) { + $directory = $modsForHesk_settings['kb_attach_dir']; + } - $hesk_settings['server_path'] = dirname(dirname(__FILE__)).'/'.$hesk_settings['attach_dir'].'/'; + $hesk_settings['server_path'] = dirname(dirname(__FILE__)).'/'.$directory.'/'; foreach ($attachments as $myatt) {