diff --git a/inc/attachments.inc.php b/inc/attachments.inc.php index 761a5f16..bde3ba93 100644 --- a/inc/attachments.inc.php +++ b/inc/attachments.inc.php @@ -143,3 +143,29 @@ function hesk_removeAttachments($attachments, $isTicket) return true; } // End hesk_removeAttachments() + + +function mfh_getTemporaryAttachment($id) { + global $hesk_settings; + + $rs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "temp_attachment` WHERE `id` = " . intval($id)); + if (hesk_dbNumRows($rs) == 0) { + return NULL; + } + $row = hesk_dbFetchAssoc($rs); + + $info = array( + 'saved_name' => $row['saved_name'], + 'real_name' => $row['file_name'], + 'size' => $row['size'] + ); + + return $info; +} + + +function mfh_deleteTemporaryAttachment($id) { + global $hesk_settings; + + 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/dao/attachment_dao.php b/internal-api/dao/attachment_dao.php index ebd248af..c2e9c88c 100644 --- a/internal-api/dao/attachment_dao.php +++ b/internal-api/dao/attachment_dao.php @@ -4,8 +4,10 @@ function upload_temp_attachment($i, $isTicket) { global $hesk_settings; $info = hesk_uploadFile($i, $isTicket); + + // `type`: 0: ticket, 1: note hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "temp_attachment` (`file_name`,`size`, `type`, `date_uploaded`, `saved_name`) - VALUES ('" . hesk_dbEscape($info['real_name']) . "','" . hesk_dbEscape($info['size']) . "','" . hesk_dbEscape($isTicket ? 1 : 0) . "', + VALUES ('" . hesk_dbEscape($info['real_name']) . "','" . hesk_dbEscape($info['size']) . "','0', NOW(), '" . hesk_dbEscape($info['saved_name']) . "')"); return hesk_dbInsertID(); diff --git a/submit_ticket.php b/submit_ticket.php index 14c38b04..22363010 100644 --- a/submit_ticket.php +++ b/submit_ticket.php @@ -292,10 +292,24 @@ if ($below_limit) { $attachments = array(); $trackingID = $tmpvar['trackid']; - for ($i = 1; $i <= $hesk_settings['attachments']['max_number']; $i++) { - $att = hesk_uploadFile($i); - if ($att !== false && !empty($att)) { - $attachments[$i] = $att; + $use_legacy_attachments = hesk_POST('use-legacy-attachments', 0); + + if ($use_legacy_attachments) { + // The user went to the fallback file upload system. + for ($i = 1; $i <= $hesk_settings['attachments']['max_number']; $i++) { + $att = hesk_uploadFile($i); + if ($att !== false && !empty($att)) { + $attachments[$i] = $att; + } + } + } else { + // The user used the new drag-and-drop system. + $temp_attachment_ids = hesk_POST_array('attachment-ids'); + foreach ($temp_attachment_ids as $temp_attachment_id) { + // Simply get the temp info and move it to the attachments table + $temp_attachment = mfh_getTemporaryAttachment($temp_attachment_id); + $attachments[] = $temp_attachment; + mfh_deleteTemporaryAttachment($temp_attachment_id); } } }