From 0ba7af0f6826dd7426a017c51e0d3e7ab34bfa19 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 19 Nov 2021 16:36:14 +0100 Subject: [PATCH 1/5] only one user assign per tickets --- htdocs/ticket/card.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 76d16aa53b6..a150c88dee4 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -418,20 +418,25 @@ 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) { - } - { + if ($contact['id'] !== $usertoassign) { //print "user à effacer : ".$useroriginassign; - $object->delete_contact($contact['rowid']); + $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'); + } } } @@ -439,11 +444,10 @@ if (empty($reshook)) { // Log action in ticket logs table $object->fetch_user($usertoassign); $log_action = $langs->trans('TicketLogAssignedTo', $object->user->getFullName($langs)); - + //var_dump($error); setEventMessages($langs->trans('TicketAssigned'), null, 'mesgs'); - header("Location: card.php?track_id=".$object->track_id."&action=view"); - exit; + //exit; } else { array_push($object->errors, $object->error); } From ce651ff4f964d01a13b0c06a370a511fb565f248 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 19 Nov 2021 16:46:05 +0100 Subject: [PATCH 2/5] 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) { From fcf223bf578e30a9f31280f7807c42c9a6b55c71 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 19 Nov 2021 16:46:53 +0100 Subject: [PATCH 3/5] remove debug --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d9ac5a7fb22..7d8d7c5bc7b 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); From 1b0e89635e10f4a20541d742714ff15a5c22f7c0 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 19 Nov 2021 16:47:23 +0100 Subject: [PATCH 4/5] remove debug --- htdocs/ticket/card.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index a150c88dee4..5284fcf01ea 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -421,7 +421,6 @@ if (empty($reshook)) { $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC'); foreach ($internal_contacts as $key => $contact) { if ($contact['id'] !== $usertoassign) { - //print "user à effacer : ".$useroriginassign; $result = $object->delete_contact($contact['rowid']); if ($result<0) { $error++; From 07c9ce4e597596e144426b67194b86e16ae47334 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 19 Nov 2021 16:47:39 +0100 Subject: [PATCH 5/5] remove debug --- htdocs/ticket/card.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 5284fcf01ea..27b4bfc1010 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -443,10 +443,9 @@ if (empty($reshook)) { // Log action in ticket logs table $object->fetch_user($usertoassign); $log_action = $langs->trans('TicketLogAssignedTo', $object->user->getFullName($langs)); - //var_dump($error); setEventMessages($langs->trans('TicketAssigned'), null, 'mesgs'); header("Location: card.php?track_id=".$object->track_id."&action=view"); - //exit; + exit; } else { array_push($object->errors, $object->error); }