From a0b17635fdf3816beaafaa7c3a1dcfa85ad076ea Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Oct 2020 14:02:07 +0200 Subject: [PATCH] NEW When creating a user from a member linked to a thirdparty, you can decide if it is an internal or external (default) user. --- htdocs/adherents/card.php | 19 ++++++++++++++----- htdocs/core/class/html.form.class.php | 5 +++-- htdocs/langs/en_US/users.lang | 1 + htdocs/main.inc.php | 2 +- htdocs/societe/class/societe.class.php | 11 ++++++----- htdocs/user/class/user.class.php | 3 ++- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index d0a67153209..cd432aa12d6 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -181,7 +181,12 @@ if (empty($reshook)) { if ($result > 0) { // Creation user $nuser = new User($db); - $result = $nuser->create_from_member($object, GETPOST('login', 'alphanohtml')); + $tmpuser = dol_clone($object); + if (GETPOST('internalorexternal', 'aZ09') == 'internal') { + $tmpuser->fk_soc = 0; + } + + $result = $nuser->create_from_member($tmpuser, GETPOST('login', 'alphanohtml')); if ($result < 0) { $langs->load("errors"); @@ -1279,11 +1284,15 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { $formquestion = array( array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login) ); - $text = $langs->trans("ConfirmCreateLogin").'
'; - if (!empty($conf->societe->enabled)) { - if ($object->socid > 0) $text .= $langs->trans("UserWillBeExternalUser"); - else $text .= $langs->trans("UserWillBeInternalUser"); + if (!empty($conf->societe->enabled) && $object->socid > 0) { + $object->fetch_thirdparty(); + $formquestion[] = array('label' => $langs->trans("UserWillBe"), 'type' => 'radio', 'name' => 'internalorexternal', 'default'=>'external', 'values' => array('external'=>$langs->trans("External").' - '.$langs->trans("LinkedToDolibarrThirdParty").' '.$object->thirdparty->getNomUrl(1, '', 0, 1), 'internal'=>$langs->trans("Internal"))); } + $text = ''; + if (!empty($conf->societe->enabled) && $object->socid <= 0) { + $text .= $langs->trans("UserWillBeInternalUser").'
'; + } + $text .= $langs->trans("ConfirmCreateLogin"); print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes'); } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 452454ced5b..e58ba5d5a8e 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4213,10 +4213,11 @@ class Form $more .= '
'; if ($i == 0) $more .= '
'.$input['label'].'
'; else $more .= '
 
'; - $more .= '
'.$selval.''; $more .= '
'."\n"; $i++; } diff --git a/htdocs/langs/en_US/users.lang b/htdocs/langs/en_US/users.lang index d6ffb849aa8..996ba20ab7d 100644 --- a/htdocs/langs/en_US/users.lang +++ b/htdocs/langs/en_US/users.lang @@ -75,6 +75,7 @@ CreateInternalUserDesc=This form allows you to create an internal user in your c InternalExternalDesc=An internal user is a user that is part of your company/organization.
An external user is a customer, vendor or other (Creating an external user for a third-party can be done from the contact record of the third-party).

In both cases, permissions defines rights on Dolibarr, also external user can have a different menu manager than internal user (See Home - Setup - Display) PermissionInheritedFromAGroup=Permission granted because inherited from one of a user's group. Inherited=Inherited +UserWillBe=Created user will be UserWillBeInternalUser=Created user will be an internal user (because not linked to a particular third party) UserWillBeExternalUser=Created user will be an external user (because linked to a particular third party) IdPhoneCaller=Id phone caller diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index e2c4b605dcc..9ecd00ca36f 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -375,7 +375,7 @@ if ((!defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && !empty($conf->gl // Check all cases that need a token (all POST actions, all actions and mass actions on pages with CSRFCHECK_WITH_TOKEN set, all sensitive GET actions) if ($_SERVER['REQUEST_METHOD'] == 'POST' || ((GETPOSTISSET('action') || GETPOSTISSET('massaction')) && defined('CSRFCHECK_WITH_TOKEN')) || - in_array(GETPOST('action', 'aZ09'), array('add', 'addtimespent', 'update', 'install', 'delete', 'deleteprof', 'deletepayment'))) + in_array(GETPOST('action', 'aZ09'), array('add', 'addtimespent', 'update', 'install', 'delete', 'deleteprof', 'deletepayment', 'confirm_create_user', 'confirm_create_thirdparty'))) { if (!GETPOSTISSET('token')) { if (GETPOST('uploadform', 'int')) { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index ac1aa5b8f98..fee36c3ff1b 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2358,11 +2358,12 @@ class Societe extends CommonObject $code .= $this->code_fournisseur.' - '; } - if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) - { - $name = $code.' '.$name; - } else { - $name = $code; + if ($code) { + if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) { + $name = $code.' '.$name; + } else { + $name = $code; + } } } diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index c82eafb353a..1649032fc8d 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1318,7 +1318,8 @@ class User extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Create a user into database from a member object + * Create a user into database from a member object. + * If $member->fk_soc is set, it will be an external user. * * @param Adherent $member Object member source * @param string $login Login to force