Merge pull request #15134 from frederic34/public_ticket

add hook on public new ticket
This commit is contained in:
Laurent Destailleur 2020-10-25 14:33:46 +01:00 committed by GitHub
commit 167430137f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,6 +51,9 @@ $msg_id = GETPOST('msg_id', 'int');
$action = GETPOST('action', 'aZ09'); $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); $object = new Ticket($db);
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
@ -60,9 +63,16 @@ $extrafields->fetch_name_optionals_label($object->table_element);
/* /*
* Actions * 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 // 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')); ////$res = $object->fetch('','',GETPOST('track_id'));
////if($res > 0) ////if($res > 0)
////{ ////{
@ -81,7 +91,7 @@ if (GETPOST('addfile', 'alpha') && !GETPOST('add', 'alpha')) {
} }
// Remove file // 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'; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
// Set tmp directory // Set tmp directory
@ -93,7 +103,7 @@ if (GETPOST('removedfile', 'alpha') && !GETPOST('add', 'alpha')) {
$action = 'create_ticket'; $action = 'create_ticket';
} }
if ($action == 'create_ticket' && GETPOST('add', 'alpha')) { if (empty($reshook) && $action == 'create_ticket' && GETPOST('add', 'alpha')) {
$error = 0; $error = 0;
$origin_email = GETPOST('email', 'alpha'); $origin_email = GETPOST('email', 'alpha');
if (empty($origin_email)) { if (empty($origin_email)) {
@ -178,8 +188,7 @@ if ($action == 'create_ticket' && GETPOST('add', 'alpha')) {
} }
} }
if (!$error) if (!$error) {
{
$object->db->commit(); $object->db->commit();
$action = "infos_success"; $action = "infos_success";
} else { } else {
@ -188,8 +197,7 @@ if ($action == 'create_ticket' && GETPOST('add', 'alpha')) {
$action = 'create_ticket'; $action = 'create_ticket';
} }
if (!$error) if (!$error) {
{
$res = $object->fetch($id); $res = $object->fetch($id);
if ($res) { if ($res) {
// Create form object // Create form object
@ -244,8 +252,7 @@ if ($action == 'create_ticket' && GETPOST('add', 'alpha')) {
// Send email to TICKET_NOTIFICATION_EMAIL_TO // Send email to TICKET_NOTIFICATION_EMAIL_TO
$sendto = $conf->global->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); $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin', $object->ref, $object->track_id);
$message_admin = $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id).'<br><br>'; $message_admin = $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id).'<br><br>';
$message_admin .= '<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>'; $message_admin .= '<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>';
@ -319,8 +326,7 @@ if ($action == 'create_ticket' && GETPOST('add', 'alpha')) {
$form = new Form($db); $form = new Form($db);
$formticket = new FormTicket($db); $formticket = new FormTicket($db);
if (!$conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) if (!$conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) {
{
print '<div class="error">'.$langs->trans('TicketPublicInterfaceForbidden').'</div>'; print '<div class="error">'.$langs->trans('TicketPublicInterfaceForbidden').'</div>';
$db->close(); $db->close();
exit(); exit();