Merge pull request #22688 from altairis-noe/public_ticket_check

FIX: check if contact is active before creating associated ticket
This commit is contained in:
Laurent Destailleur 2022-11-02 16:54:20 +01:00 committed by GitHub
commit ecdc92e219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);