FIX Setup of thirdparty or contact for external users

This commit is contained in:
Laurent Destailleur 2020-04-29 20:21:17 +02:00
parent f8dfe886ac
commit 6ec6a4465a
2 changed files with 28 additions and 10 deletions

View File

@ -1298,11 +1298,11 @@ class Form
// Construct $out and $outarray
$out .= '<select id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').'>'."\n";
$textifempty = '';
// Do not use textifempty = ' ' or '&nbsp;' here, or search on key will search on ' key'.
//if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
$textifempty = (($showempty && !is_numeric($showempty)) ? $langs->trans($showempty) : '');
if (!empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT))
{
// Do not use textifempty = ' ' or '&nbsp;' here, or search on key will search on ' key'.
//if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
else $textifempty .= $langs->trans("All");
}
@ -1554,7 +1554,7 @@ class Form
if ($htmlname != 'none' && !$options_only) $out .= '<select class="flat'.($moreclass ? ' '.$moreclass : '').'" id="'.$htmlid.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.(!empty($moreparam) ? $moreparam : '').'>';
if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) $out .= '<option value="0"'.(in_array(0, $selected) ? ' selected' : '').'>&nbsp;</option>';
if ($showempty == 2) $out .= '<option value="0"'.(in_array(0, $selected) ? ' selected' : '').'>'.$langs->trans("Internal").'</option>';
if ($showempty == 2) $out .= '<option value="0"'.(in_array(0, $selected) ? ' selected' : '').'>-- '.$langs->trans("Internal").' --</option>';
$num = $this->db->num_rows($resql);
$i = 0;

View File

@ -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 '<br>';
print '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$object->contactid.'">'.img_object($langs->trans("ShowContact"), 'contact').' '.dol_trunc($contact->getFullName($langs), 32).'</a>';
print $contact->getNomUrl(1, '');
}
print '</td>';
print '</tr>'."\n";
@ -2287,6 +2292,7 @@ else
print '<td>';
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', '', '&nbsp;');
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', '', '&nbsp;'); // 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', '', '&nbsp;'); // We keep thirdparty empty, contact is already set
print img_picto('', 'contact').$form->selectcontacts(0, 0, 'contactid', 1, '', '', 1, '', false, 1);
}
}
print '</td></tr>';