diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index ce791613bcb..f46a9ecc61d 100755 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -386,20 +386,24 @@ if (empty($reshook)) { if (!$error) { // Update list of contacts // Si déjà un user assigné on le supprime des contacts if ($useroriginassign > 0) { - $internal_contacts = $object->listeContact(-1, 'internal'); - + $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC'); foreach ($internal_contacts as $key => $contact) { - if ($contact['code'] == "SUPPORTTEC" && $contact['id'] == $useroriginassign) { - } - { - //print "user à effacer : ".$useroriginassign; - $object->delete_contact($contact['rowid']); + if ($contact['id'] !== $usertoassign) { + $result = $object->delete_contact($contact['rowid']); + if ($result<0) { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } } } } - if ($usertoassign > 0) { - $object->add_contact($usertoassign, "SUPPORTTEC", 'internal', $notrigger = 0); + if ($usertoassign > 0 && $usertoassign!==$useroriginassign) { + $result = $object->add_contact($usertoassign, "SUPPORTTEC", 'internal', $notrigger = 0); + if ($result<0) { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } } } @@ -408,8 +412,8 @@ if (empty($reshook)) { $object->fetch_user($usertoassign); //$log_action = $langs->trans('TicketLogAssignedTo', $object->user->getFullName($langs)); - setEventMessages($langs->trans('TicketAssigned'), null, 'mesgs'); + setEventMessages($langs->trans('TicketAssigned'), null, 'mesgs'); header("Location: card.php?track_id=".$object->track_id."&action=view"); exit; } else { diff --git a/htdocs/ticket/contact.php b/htdocs/ticket/contact.php index 093aaf5de1e..89822df2676 100644 --- a/htdocs/ticket/contact.php +++ b/htdocs/ticket/contact.php @@ -84,7 +84,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) {