diff --git a/htdocs/public/ticket/create_ticket.php b/htdocs/public/ticket/create_ticket.php index f2b72693a13..1b96cc5ebd6 100644 --- a/htdocs/public/ticket/create_ticket.php +++ b/htdocs/public/ticket/create_ticket.php @@ -145,8 +145,18 @@ 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 = -1; + foreach ($contacts as $key => $contact) { + if ((int) $contact->statut == 1) { + $cid = $key; + 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) && ($cid < 0 || empty($contacts[$cid]->socid))) { $error++; array_push($object->errors, $langs->trans("ErrorEmailMustExistToCreateTicket")); $action = ''; @@ -197,9 +207,9 @@ if (empty($reshook) && $action == 'create_ticket' && GETPOST('save', 'alpha')) { $object->fk_soc = $searched_companies[0]->id; } - if (is_array($contacts) and count($contacts) > 0) { - $object->fk_soc = $contacts[0]->socid; - $usertoassign = $contacts[0]->id; + if (is_array($contacts) && count($contacts) > 0) { + $object->fk_soc = $contacts[$cid]->socid; + $usertoassign = $contacts[$cid]->id; } $ret = $extrafields->setOptionalsFromPost(null, $object);