check if contact is active before creating associated ticket

This commit is contained in:
Noé Cendrier 2022-10-27 16:13:11 +02:00
parent a9c8c24e9b
commit 589df5e63d

View File

@ -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 // Le premier contact trouvé est utilisé pour déterminer le contact suivi
$contacts = $object->searchContactByEmail($origin_email); $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 // 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++; $error++;
array_push($object->errors, $langs->trans("ErrorEmailMustExistToCreateTicket")); array_push($object->errors, $langs->trans("ErrorEmailMustExistToCreateTicket"));
$action = ''; $action = '';
@ -198,8 +209,8 @@ if (empty($reshook) && $action == 'create_ticket' && GETPOST('save', 'alpha')) {
} }
if (is_array($contacts) and count($contacts) > 0) { if (is_array($contacts) and count($contacts) > 0) {
$object->fk_soc = $contacts[0]->socid; $object->fk_soc = $contacts[$cid]->socid;
$usertoassign = $contacts[0]->id; $usertoassign = $contacts[$cid]->id;
} }
$ret = $extrafields->setOptionalsFromPost(null, $object); $ret = $extrafields->setOptionalsFromPost(null, $object);