diff --git a/inc/view_attachment_functions.inc.php b/inc/view_attachment_functions.inc.php index 44b9ffee..431753a4 100644 --- a/inc/view_attachment_functions.inc.php +++ b/inc/view_attachment_functions.inc.php @@ -224,7 +224,7 @@ function display_dropzone_field($url) { file['databaseId'] = response; }); this.on('removedfile', function(file) { - console.log(file); + removeAttachment(file['databaseId']); }); this.on('queuecomplete', function(progress) { $('#total-progress').removeClass('active'); diff --git a/install/mods-for-hesk/sql/installSql.php b/install/mods-for-hesk/sql/installSql.php index f2b6b1cd..ba44f326 100644 --- a/install/mods-for-hesk/sql/installSql.php +++ b/install/mods-for-hesk/sql/installSql.php @@ -716,6 +716,7 @@ function execute260Scripts() executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "temp_attachment` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `file_name` VARCHAR(255) NOT NULL, + `saved_name` VARCHAR(255) NOT NULL, `size` INT(10) UNSIGNED NOT NULL, `type` ENUM('0','1') NOT NULL, `date_uploaded` TIMESTAMP NOT NULL) ENGINE = MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"); diff --git a/internal-api/dao/attachment_dao.php b/internal-api/dao/attachment_dao.php index 97703142..e8f4e229 100644 --- a/internal-api/dao/attachment_dao.php +++ b/internal-api/dao/attachment_dao.php @@ -8,4 +8,15 @@ function upload_temp_attachment($i, $isTicket) { VALUES ('" . hesk_dbEscape($info['saved_name']) . "','" . hesk_dbEscape($info['size']) . "','" . hesk_dbEscape($isTicket ? 1 : 0) . "', NOW())"); return hesk_dbInsertID(); +} + +function delete_temp_attachment($id, $isTicket) { + global $hesk_settings; + + $attachment_rs = hesk_dbQuery("SELECT `saved_name` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "temp_attachment` WHERE `id` = " . intval($id)); + $attachment = hesk_dbFetchAssoc($attachment_rs); + + if (hesk_removeAttachments(array($attachment), $isTicket)) { + hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "temp_attachment` WHERE `id` = " . intval($id)); + } } \ No newline at end of file diff --git a/internal-api/ticket/delete-attachment.php b/internal-api/ticket/delete-attachment.php new file mode 100644 index 00000000..68f063ff --- /dev/null +++ b/internal-api/ticket/delete-attachment.php @@ -0,0 +1,24 @@ +'); } +function removeAttachment(id) { + $('input[name="attachment-ids[]"][value="' + id + '"]').remove(); + $.ajax({ + url: getHelpdeskUrl() + '/internal-api/ticket/delete-attachment.php?id=' + id, + method: 'GET', + success: function() { + console.info('Removed attachment ' + id); + }, + error: function() { + console.error('Error removing attachment ' + id); + } + }); +} + jQuery(document).ready(loadJquery);