diff --git a/hook.php b/hook.php index 2c3fa649b..c8a720a99 100644 --- a/hook.php +++ b/hook.php @@ -387,33 +387,35 @@ function plugin_formcreator_hook_update_ticket(CommonDBTM $item) { function plugin_formcreator_hook_delete_ticket(CommonDBTM $item) { global $DB; - if ($item instanceof Ticket) { - $id = $item->getID(); + if (!($item instanceof Ticket)) { + return; + } - // mark formanswers as deleted - $iterator = $DB->request([ - 'SELECT' => ['id'], - 'FROM' => Item_Ticket::getTable(), - 'WHERE' => [ - 'itemtype' => 'PluginFormcreatorFormAnswer', - 'tickets_id' => $id, - ] - ]); - foreach ($iterator as $row) { - $form_answer = new PluginFormcreatorFormAnswer(); - $form_answer->update([ - 'id' => $row['id'], - 'is_deleted' => 1, - ]); - } + $id = $item->getID(); - // delete issue - $issue = new PluginFormcreatorIssue(); - $issue->deleteByCriteria([ - 'display_id' => "t_$id", - 'sub_itemtype' => 'Ticket' - ], 1); + // mark formanswers as deleted + $iterator = $DB->request([ + 'SELECT' => ['id'], + 'FROM' => Item_Ticket::getTable(), + 'WHERE' => [ + 'itemtype' => 'PluginFormcreatorFormAnswer', + 'tickets_id' => $id, + ] + ]); + foreach ($iterator as $row) { + $form_answer = new PluginFormcreatorFormAnswer(); + $form_answer->update([ + 'id' => $row['id'], + 'is_deleted' => 1, + ]); } + + // delete issue + $issue = new PluginFormcreatorIssue(); + $issue->deleteByCriteria([ + 'display_id' => "t_$id", + 'sub_itemtype' => 'Ticket' + ], 1); } function plugin_formcreator_hook_restore_ticket(CommonDBTM $item) { diff --git a/js/scripts.js.php b/js/scripts.js.php index c40407834..7693d0b35 100644 --- a/js/scripts.js.php +++ b/js/scripts.js.php @@ -1335,8 +1335,10 @@ function plugin_formcreator_cancelMyTicket(id) { url: rootDoc + '/plugins/formcreator/ajax/cancelticket.php', data: {id: id}, type: "POST", - dataType: "json" + dataType: "text" }).done(function(response) { - reloadTab; + window.location.replace(rootDoc + '/plugins/formcreator/front/issue.php?reset=reset'); + }).error(function(response) { + alert(""); }); } \ No newline at end of file