From ce651ff4f964d01a13b0c06a370a511fb565f248 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 19 Nov 2021 16:46:05 +0100 Subject: [PATCH] NEW: make unicity for user assigned(responsible) on ticket from anyways --- htdocs/core/lib/functions.lib.php | 2 +- htdocs/ticket/contact.php | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7d8d7c5bc7b..d9ac5a7fb22 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8113,7 +8113,7 @@ function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = if (!empty($entityfilter)) { $sql .= " AND entity IN (".getEntity($tablename).")"; } - + print $sql; $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); diff --git a/htdocs/ticket/contact.php b/htdocs/ticket/contact.php index 73efc14a038..a7058f184f3 100644 --- a/htdocs/ticket/contact.php +++ b/htdocs/ticket/contact.php @@ -85,7 +85,32 @@ if ($action == 'addcontact' && $user->rights->ticket->write) { if ($result > 0 && ($id > 0 || (!empty($track_id)))) { $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); + + $error = 0; + + $codecontact = dol_getIdFromCode($db, $typeid, 'c_type_contact', 'rowid', 'code'); + if ($codecontact=='SUPPORTTEC') { + $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC'); + foreach ($internal_contacts as $key => $contact) { + if ($contact['id'] !== $contactid) { + //print "user à effacer : ".$useroriginassign; + $result = $object->delete_contact($contact['rowid']); + if ($result<0) { + $error ++; + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } + $ret = $object->assignUser($user, $contactid); + if ($ret < 0) { + $error ++; + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + if (empty($error)) { + $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); + } } if ($result >= 0) {