From 6ec6a4465ad95fb16a660f87653a8e397596d1a0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 29 Apr 2020 20:21:17 +0200 Subject: [PATCH] FIX Setup of thirdparty or contact for external users --- htdocs/core/class/html.form.class.php | 8 +++---- htdocs/user/card.php | 30 +++++++++++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 25ed9f86625..b2c677ed29d 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1298,11 +1298,11 @@ class Form // Construct $out and $outarray $out .= ''; if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) $out .= ''; - if ($showempty == 2) $out .= ''; + if ($showempty == 2) $out .= ''; $num = $this->db->num_rows($resql); $i = 0; diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 22b591dd53f..cd115dbe292 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -481,17 +481,22 @@ if (empty($reshook)) { if (!$error && GETPOSTISSET('contactid')) { $contactid = GETPOST('contactid', 'int'); + $socid = GETPOST('socid', 'int'); - if ($contactid > 0) { + if ($contactid > 0) { // The 'contactid' is used inpriority over the 'socid' $contact = new Contact($db); $contact->fetch($contactid); $sql = "UPDATE ".MAIN_DB_PREFIX."user"; - $sql .= " SET fk_socpeople=".$db->escape($contactid); + $sql .= " SET fk_socpeople=".((int) $contactid); if (!empty($contact->socid)) { - $sql .= ", fk_soc=".$db->escape($contact->socid); + $sql .= ", fk_soc=".((int) $contact->socid); } $sql .= " WHERE rowid=".$object->id; + } elseif ($socid > 0) { + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; + $sql .= " SET fk_socpeople=NULL, fk_soc=".((int) $socid); + $sql .= " WHERE rowid=".$object->id; } else { $sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql .= " SET fk_socpeople=NULL, fk_soc=NULL"; @@ -1831,7 +1836,7 @@ else $contact->fetch($object->contactid); if ($object->socid > 0) print ' / '; else print '
'; - print ''.img_object($langs->trans("ShowContact"), 'contact').' '.dol_trunc($contact->getFullName($langs), 32).''; + print $contact->getNomUrl(1, ''); } print ''; print ''."\n"; @@ -2287,6 +2292,7 @@ else print ''; if ($user->id == $object->id || !$user->admin) { + // Read mode $type = $langs->trans("Internal"); if ($object->socid) $type = $langs->trans("External"); print $form->textwithpicto($type, $langs->trans("InternalExternalDesc")); @@ -2294,10 +2300,22 @@ else } else { + // Select mode $type = 0; if ($object->contactid) $type = $object->contactid; - print $form->selectcontacts(0, $type, 'contactid', 2, '', '', 1, '', false, 1); - if ($object->ldap_sid) print ' ('.$langs->trans("DomainUser").')'; + + if ($object->socid > 0 && ! ($object->contactid > 0)) { // external user but no link to a contact + print img_picto('', 'company').$form->select_company($object->socid, 'socid', '', ' '); + print img_picto('', 'contact').$form->selectcontacts(0, 0, 'contactid', 1, '', '', 1, '', false, 1); + if ($object->ldap_sid) print ' ('.$langs->trans("DomainUser").')'; + } elseif ($object->socid > 0 && $object->contactid > 0) { // external user with a link to a contact + print img_picto('', 'company').$form->select_company(0, 'socid', '', ' '); // We keep thirdparty empty, contact is already set + print img_picto('', 'contact').$form->selectcontacts(0, $object->contactid, 'contactid', 1, '', '', 1, '', false, 1); + if ($object->ldap_sid) print ' ('.$langs->trans("DomainUser").')'; + } else { // $object->socid is not > 0 here + print img_picto('', 'company').$form->select_company(0, 'socid', '', ' '); // We keep thirdparty empty, contact is already set + print img_picto('', 'contact').$form->selectcontacts(0, 0, 'contactid', 1, '', '', 1, '', false, 1); + } } print '';