diff --git a/ajax/cancelticket.php b/ajax/cancelticket.php new file mode 100644 index 000000000..278a5ee20 --- /dev/null +++ b/ajax/cancelticket.php @@ -0,0 +1,38 @@ +. + * --------------------------------------------------------------------- + * @copyright Copyright © 2011 - 2019 Teclib' + * @license http://www.gnu.org/licenses/gpl.txt GPLv3+ + * @link https://github.com/pluginsGLPI/formcreator/ + * @link https://pluginsglpi.github.io/formcreator/ + * @link http://plugins.glpi-project.org/#/plugin/formcreator + * --------------------------------------------------------------------- + */ + +include ('../../../inc/includes.php'); +if (!isset($_POST['id'])) { + http_response_code(400); + exit; +} +$ticketId = (int) $_POST['id']; +PluginFormcreatorCommon::cancelMyTicket($ticketId); \ No newline at end of file diff --git a/css/styles.css b/css/styles.css index 9e27ef0f2..d0fad8b12 100644 --- a/css/styles.css +++ b/css/styles.css @@ -1459,6 +1459,9 @@ span.fc_list_icon { color: #a0a0a0; } +.plugin_formcreator_cancel_my_ticket { + background: #fec95c; +} /* ################--------------- Responsive ---------------#################### */ @media screen and (max-width: 700px) { diff --git a/hook.php b/hook.php index 7c04e4b98..9c82c7afc 100644 --- a/hook.php +++ b/hook.php @@ -483,3 +483,24 @@ function plugin_formcreator_dynamicReport($params) { return false; } + +/** + * Hook for timeline_actions; display a new action for a CommonITILObject + * @see CommonITILObject + * + * @return void + */ +function plugin_formcreator_timelineActions($options) { + $item = $options['item']; + if (!$item->canDeleteItem()) { + return; + } + + if (!(isset($_SESSION['glpiactiveprofile']) && + $_SESSION['glpiactiveprofile']['interface'] == 'helpdesk')) { + return; + } + echo "
  • " + ."".__('Cancel my ticket', 'formcreator')."
  • "; +} diff --git a/inc/common.class.php b/inc/common.class.php index 044a57f56..fc9f5bebb 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -200,4 +200,14 @@ public static function showFontAwesomeDropdown($name, $options = []) { $output .= ''; echo $output; } + + public static function cancelMyTicket($id) { + $ticket = new Ticket(); + $ticket->getFromDB($id); + if (!$ticket->canRequesterUpdateItem()) { + return false; + } + + return $ticket->delete($ticket->fields); + } } diff --git a/js/scripts.js.php b/js/scripts.js.php index c0c5ebc6b..9c0e262b9 100644 --- a/js/scripts.js.php +++ b/js/scripts.js.php @@ -1651,3 +1651,14 @@ function plugin_formcreator_updateCompositePeerType(rand) { $('#plugin_formcreator_link_target').show(); } } + +function plugin_formcreator_cancelMyTicket(id) { + $.ajax({ + url: rootDoc + '/plugins/formcreator/ajax/cancelticket.php', + data: {id: id}, + type: "POST", + dataType: "json" + }).done(function(response) { + reloadTab; + }); +} \ No newline at end of file diff --git a/setup.php b/setup.php index aa5c60452..2f30f582e 100644 --- a/setup.php +++ b/setup.php @@ -154,6 +154,8 @@ function plugin_init_formcreator() { PluginFormcreatorTargetTicket::class => 'plugin_formcreator_hook_pre_purge_targetTicket', PluginFormcreatorTargetChange::class => 'plugin_formcreator_hook_pre_purge_targetChange' ]; + // hook to add custom actions on a ticket in service catalog + $PLUGIN_HOOKS['timeline_actions']['formcreator'] = 'plugin_formcreator_timelineActions'; $plugin = new Plugin(); if ($plugin->isInstalled('formcreator') && $plugin->isActivated('formcreator')) {