From 589df5e63dea803868b3a159c75be4cca8b77cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Cendrier?= Date: Thu, 27 Oct 2022 16:13:11 +0200 Subject: [PATCH 1/5] check if contact is active before creating associated ticket --- htdocs/public/ticket/create_ticket.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/htdocs/public/ticket/create_ticket.php b/htdocs/public/ticket/create_ticket.php index f2b72693a13..e81d9802aac 100644 --- a/htdocs/public/ticket/create_ticket.php +++ b/htdocs/public/ticket/create_ticket.php @@ -145,8 +145,19 @@ if (empty($reshook) && $action == 'create_ticket' && GETPOST('save', 'alpha')) { // Le premier contact trouvé est utilisé pour déterminer le contact suivi $contacts = $object->searchContactByEmail($origin_email); + // Ensure that contact is active and select first active contact + $cid = 0; + foreach ($contacts as $key => $contact) { + if ($contact->statut !== "1") { + $cid = $key + 1; + } else { + break; + } + } + + // Option to require email exists to create ticket - if (!empty($conf->global->TICKET_EMAIL_MUST_EXISTS) && !$contacts[0]->socid) { + if (!empty($conf->global->TICKET_EMAIL_MUST_EXISTS) && !$contacts[$cid]->socid) { $error++; array_push($object->errors, $langs->trans("ErrorEmailMustExistToCreateTicket")); $action = ''; @@ -198,8 +209,8 @@ if (empty($reshook) && $action == 'create_ticket' && GETPOST('save', 'alpha')) { } if (is_array($contacts) and count($contacts) > 0) { - $object->fk_soc = $contacts[0]->socid; - $usertoassign = $contacts[0]->id; + $object->fk_soc = $contacts[$cid]->socid; + $usertoassign = $contacts[$cid]->id; } $ret = $extrafields->setOptionalsFromPost(null, $object); From 634348d0483158489107fa9da2aff7f82e136658 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 2 Nov 2022 01:02:52 +0100 Subject: [PATCH 2/5] Update create_ticket.php --- htdocs/public/ticket/create_ticket.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/public/ticket/create_ticket.php b/htdocs/public/ticket/create_ticket.php index e81d9802aac..0e6515bedd2 100644 --- a/htdocs/public/ticket/create_ticket.php +++ b/htdocs/public/ticket/create_ticket.php @@ -148,9 +148,8 @@ if (empty($reshook) && $action == 'create_ticket' && GETPOST('save', 'alpha')) { // Ensure that contact is active and select first active contact $cid = 0; foreach ($contacts as $key => $contact) { - if ($contact->statut !== "1") { - $cid = $key + 1; - } else { + if ((int) $contact->statut == 1) { + $cid = $key; break; } } From 414b183eadf547df2c5db76afe85b253fc7eac3a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 2 Nov 2022 01:07:31 +0100 Subject: [PATCH 3/5] Update create_ticket.php --- htdocs/public/ticket/create_ticket.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/public/ticket/create_ticket.php b/htdocs/public/ticket/create_ticket.php index 0e6515bedd2..ec47aaf4b18 100644 --- a/htdocs/public/ticket/create_ticket.php +++ b/htdocs/public/ticket/create_ticket.php @@ -146,7 +146,7 @@ if (empty($reshook) && $action == 'create_ticket' && GETPOST('save', 'alpha')) { $contacts = $object->searchContactByEmail($origin_email); // Ensure that contact is active and select first active contact - $cid = 0; + $cid = -1; foreach ($contacts as $key => $contact) { if ((int) $contact->statut == 1) { $cid = $key; @@ -156,7 +156,7 @@ if (empty($reshook) && $action == 'create_ticket' && GETPOST('save', 'alpha')) { // Option to require email exists to create ticket - if (!empty($conf->global->TICKET_EMAIL_MUST_EXISTS) && !$contacts[$cid]->socid) { + if (!empty($conf->global->TICKET_EMAIL_MUST_EXISTS) && ($cid <= 0 || empty($contacts[$cid]->socid))) { $error++; array_push($object->errors, $langs->trans("ErrorEmailMustExistToCreateTicket")); $action = ''; From 870ffb6ddaf627aa513714a440d16c604cfc04b5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 2 Nov 2022 01:10:17 +0100 Subject: [PATCH 4/5] Update create_ticket.php --- htdocs/public/ticket/create_ticket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/ticket/create_ticket.php b/htdocs/public/ticket/create_ticket.php index ec47aaf4b18..60d10f012fc 100644 --- a/htdocs/public/ticket/create_ticket.php +++ b/htdocs/public/ticket/create_ticket.php @@ -207,7 +207,7 @@ if (empty($reshook) && $action == 'create_ticket' && GETPOST('save', 'alpha')) { $object->fk_soc = $searched_companies[0]->id; } - if (is_array($contacts) and count($contacts) > 0) { + if (is_array($contacts) && count($contacts) > 0) { $object->fk_soc = $contacts[$cid]->socid; $usertoassign = $contacts[$cid]->id; } From bcfcbf19ec8c6a1750e66ef6137f9bdfbb250164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Cendrier?= Date: Wed, 2 Nov 2022 14:11:37 +0100 Subject: [PATCH 5/5] strictly inferior, please --- htdocs/public/ticket/create_ticket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/ticket/create_ticket.php b/htdocs/public/ticket/create_ticket.php index 60d10f012fc..1b96cc5ebd6 100644 --- a/htdocs/public/ticket/create_ticket.php +++ b/htdocs/public/ticket/create_ticket.php @@ -156,7 +156,7 @@ if (empty($reshook) && $action == 'create_ticket' && GETPOST('save', 'alpha')) { // Option to require email exists to create ticket - if (!empty($conf->global->TICKET_EMAIL_MUST_EXISTS) && ($cid <= 0 || empty($contacts[$cid]->socid))) { + if (!empty($conf->global->TICKET_EMAIL_MUST_EXISTS) && ($cid < 0 || empty($contacts[$cid]->socid))) { $error++; array_push($object->errors, $langs->trans("ErrorEmailMustExistToCreateTicket")); $action = '';