diff --git a/ajax/cancelticket.php b/ajax/cancelticket.php index 278a5ee20..eabb1d003 100644 --- a/ajax/cancelticket.php +++ b/ajax/cancelticket.php @@ -35,4 +35,9 @@ exit; } $ticketId = (int) $_POST['id']; -PluginFormcreatorCommon::cancelMyTicket($ticketId); \ No newline at end of file +if (!PluginFormcreatorCommon::cancelMyTicket($ticketId)) { + http_response_code(403); + echo implode('
', $_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR]); + $_SESSION['MESSAGE_AFTER_REDIRECT'] = []; + exit; +} diff --git a/inc/common.class.php b/inc/common.class.php index 1cc328e5b..b86d603d5 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -202,14 +202,28 @@ public static function showFontAwesomeDropdown($name, $options = []) { echo $output; } + /** + * Cancel a new ticketn while it is still allowed + * + * In case of error, a message is added to the session + * + * @param integer $id + * @return boolean true on success, false otherwise + */ public static function cancelMyTicket($id) { $ticket = new Ticket(); $ticket->getFromDB($id); if (!$ticket->canRequesterUpdateItem()) { + Session::addMessageAfterRedirect(__('You cannot delete this issue. Maybe it is taken into account.', 'formcreator'), true, ERROR); + return false; + } + + if (!$ticket->delete($ticket->fields)) { + Session::addMessageAfterRedirect(__('Failed to delete this issue. An internal error occured.', 'formcreator'), true, ERROR); return false; } - return $ticket->delete($ticket->fields); + return true; } /** diff --git a/js/scripts.js.php b/js/scripts.js.php index 73156fcf0..ad9424552 100644 --- a/js/scripts.js.php +++ b/js/scripts.js.php @@ -1331,6 +1331,6 @@ function plugin_formcreator_cancelMyTicket(id) { }).done(function(response) { window.location.replace(formcreatorRootDoc + '/front/issue.php?reset=reset'); }).error(function(response) { - alert(""); + alert(response.responseText); }); -} \ No newline at end of file +}