From 302fb6defa34c832dfb8203a32a00fe0f76d0d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 24 Oct 2020 13:17:23 +0200 Subject: [PATCH] add hook on public new ticket --- htdocs/public/ticket/create_ticket.php | 30 +++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/htdocs/public/ticket/create_ticket.php b/htdocs/public/ticket/create_ticket.php index ed26c881fd7..679941e91d5 100644 --- a/htdocs/public/ticket/create_ticket.php +++ b/htdocs/public/ticket/create_ticket.php @@ -49,6 +49,9 @@ $msg_id = GETPOST('msg_id', 'int'); $action = GETPOST('action', 'aZ09'); +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('publicnewticketcard', 'globalcard')); + $object = new Ticket($db); $extrafields = new ExtraFields($db); @@ -58,9 +61,16 @@ $extrafields->fetch_name_optionals_label($object->table_element); /* * Actions */ - +$parameters = array( + 'id' => $id, +); +// Note that $action and $object may have been modified by some hooks +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} // Add file in email form -if (GETPOST('addfile', 'alpha') && !GETPOST('add', 'alpha')) { +if (empty($reshook) && GETPOST('addfile', 'alpha') && !GETPOST('add', 'alpha')) { ////$res = $object->fetch('','',GETPOST('track_id')); ////if($res > 0) ////{ @@ -79,7 +89,7 @@ if (GETPOST('addfile', 'alpha') && !GETPOST('add', 'alpha')) { } // Remove file -if (GETPOST('removedfile', 'alpha') && !GETPOST('add', 'alpha')) { +if (empty($reshook) && GETPOST('removedfile', 'alpha') && !GETPOST('add', 'alpha')) { include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // Set tmp directory @@ -91,7 +101,7 @@ if (GETPOST('removedfile', 'alpha') && !GETPOST('add', 'alpha')) { $action = 'create_ticket'; } -if ($action == 'create_ticket' && GETPOST('add', 'alpha')) { +if (empty($reshook) && $action == 'create_ticket' && GETPOST('add', 'alpha')) { $error = 0; $origin_email = GETPOST('email', 'alpha'); if (empty($origin_email)) { @@ -176,8 +186,7 @@ if ($action == 'create_ticket' && GETPOST('add', 'alpha')) { } } - if (!$error) - { + if (!$error) { $object->db->commit(); $action = "infos_success"; } else { @@ -186,8 +195,7 @@ if ($action == 'create_ticket' && GETPOST('add', 'alpha')) { $action = 'create_ticket'; } - if (!$error) - { + if (!$error) { $res = $object->fetch($id); if ($res) { // Create form object @@ -242,8 +250,7 @@ if ($action == 'create_ticket' && GETPOST('add', 'alpha')) { // Send email to TICKET_NOTIFICATION_EMAIL_TO $sendto = $conf->global->TICKET_NOTIFICATION_EMAIL_TO; - if ($sendto) - { + if ($sendto) { $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin', $object->ref, $object->track_id); $message_admin = $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id).'

'; $message_admin .= '