From 50decdd941cb1e81788dd4c91b713f49492360fa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 16 Feb 2013 21:06:15 +0100 Subject: [PATCH] Fix: When creating user on other entity, no way to read user after creation. --- htdocs/core/class/html.form.class.php | 26 +++++------ htdocs/user/class/user.class.php | 6 +-- htdocs/user/fiche.php | 65 +++++++++++++++------------ 3 files changed, 52 insertions(+), 45 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index dcf70443fd8..2d46eec81dc 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -689,7 +689,7 @@ class Form { //$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); $out.= ajax_combobox($htmlname, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); - /* + /* if ($selected && empty($selected_input_value)) { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; @@ -876,7 +876,7 @@ class Form if ($resql) { $num=$this->db->num_rows($resql); - + if ($conf->use_javascript_ajax && $conf->global->CONTACT_USE_SEARCH_TO_SELECT && ! $forcecombo) { $out.= ajax_combobox($htmlname, $event); @@ -968,10 +968,10 @@ class Form * @param int $disabled If select list must be disabled * @param array $include Array list of users id to include * @param int $enableonly Array list of users id to be enabled. All other must be disabled - * @param int $force_entity Possibility to force entity + * @param int $force_entity 0 or Id of environment to force * @return void */ - function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=false) + function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0) { print $this->select_dolusers($selected,$htmlname,$show_empty,$exclude,$disabled,$include,$enableonly,$force_entity); } @@ -986,10 +986,10 @@ class Form * @param int $disabled If select list must be disabled * @param array $include Array list of users id to include * @param int $enableonly Array list of users id to be enabled. All other must be disabled - * @param int $force_entity Possibility to force entity + * @param int $force_entity 0 or Id of environment to force * @return string HTML select string */ - function select_dolusers($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=false) + function select_dolusers($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0) { global $conf,$user,$langs; @@ -3946,17 +3946,17 @@ class Form /** * Return select list of groups * - * @param string $selected Id group preselected - * @param string $htmlname Field name in form - * @param int $show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue - * @param string $exclude Array list of groups id to exclude + * @param string $selected Id group preselected + * @param string $htmlname Field name in form + * @param int $show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue + * @param string $exclude Array list of groups id to exclude * @param int $disabled If select list must be disabled - * @param string $include Array list of groups id to include + * @param string $include Array list of groups id to include * @param int $enableonly Array list of groups id to be enabled. All other must be disabled - * @param int $force_entity Possibility to force entity + * @param int $force_entity 0 or Id of environment to force * @return void */ - function select_dolgroups($selected='', $htmlname='groupid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity='') + function select_dolgroups($selected='', $htmlname='groupid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0) { global $conf,$user,$langs; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 6b144c79a08..59641c1bbc1 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -154,13 +154,13 @@ class User extends CommonObject $sql.= " u.ref_int, u.ref_ext"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; - if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) + if ((empty($conf->multicompany->enabled) || empty($conf->multicompany->transverse_mode)) && (! empty($user->entity))) { - $sql.= " WHERE u.entity IS NOT NULL"; + $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; } else { - $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; + $sql.= " WHERE u.entity IS NOT NULL"; } if ($sid) // permet une recherche du user par son SID ActiveDirectory ou Samba diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index 7988b68dfd2..4da27c64a55 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -819,21 +819,6 @@ if (($action == 'create') || ($action == 'adduserldap')) print "\n"; } - //Multicompany - if (! empty($conf->multicompany->enabled)) - { - if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) - { - print "".''.$langs->trans("Entity").''; - print "".$mc->select_entities($conf->entity); - print "\n"; - } - else - { - print ''; - } - } - // Type print ''.$langs->trans("Type").''; print ''; @@ -902,6 +887,28 @@ if (($action == 'create') || ($action == 'adduserldap')) print ''; print ''; + // Multicompany + if (! empty($conf->multicompany->enabled)) + { + if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) + { + print "".''.$langs->trans("Entity").''; + print "".$mc->select_entities($conf->entity); + print "\n"; + } + else + { + print ''; + } + } + + // Hierarchy + print ''.$langs->trans("HierarchicalResponsible").''; + print ''; + print $form->select_dolusers($object->fk_user,'fk_user',1,array($object->id),0,'',0,$conf->entity); + print ''; + print "\n"; + // Note print ''; print $langs->trans("Note"); @@ -941,7 +948,7 @@ else /* */ /* ************************************************************************** */ - if ($id) + if ($id > 0) { $object->fetch($id); if ($res < 0) { dol_print_error($db,$object->error); exit; } @@ -1051,7 +1058,7 @@ else if ($action != 'edit') { $rowspan=16; - + print ''; // Ref @@ -1188,7 +1195,7 @@ else print '\n"; - + // Hierarchy print ''; print ''; print "\n"; - - // Statut + + // Status print ''; print ''; print "\n"; } - + // Company / Contact if (! empty($conf->societe->enabled)) { @@ -1287,7 +1294,7 @@ else } print "\n"; } - + // Other attributes $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook @@ -1315,7 +1322,7 @@ else print '
'; - if ($caneditfield && ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1))) + if ($caneditfield && (empty($conf->multicompany->enabled) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1))) { if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) { @@ -1327,7 +1334,7 @@ else } } elseif ($caneditpassword && ! $object->ldap_sid && - ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1))) + (empty($conf->multicompany->enabled) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1))) { print ''.$langs->trans("EditPassword").''; } @@ -1787,7 +1794,7 @@ else print '
'; - + // openid if (isset($conf->authmode) && preg_match('/myopenid/',$conf->authmode)) { @@ -1808,16 +1815,16 @@ else // Hierarchy print ''; print ''; print "\n"; - // Statut + // Status print ''; print ''; - + // Multicompany if (! empty($conf->multicompany->enabled)) { @@ -1832,7 +1839,7 @@ else print ''; } } - + // Company / Contact if (! empty($conf->societe->enabled)) {
'.$langs->trans('Signature').''; print dol_textishtml($object->signature)?$object->signature:dol_nl2br($object->signature,1,false); print "
'.$langs->trans("HierarchicalResponsible").''; @@ -1200,8 +1207,8 @@ else } print '
'.$langs->trans("Status").''; print $object->getLibStatut(4); @@ -1223,7 +1230,7 @@ else print ''.$object->openid.'
'; print ''; print '
'.$langs->trans("HierarchicalResponsible").''; - print $form->select_dolusers($object->fk_user,'fk_user',1,array($object->id)); + print $form->select_dolusers($object->fk_user,'fk_user',1,array($object->id),0,'',0,$object->entity); print '
'.$langs->trans("Status").''; print $object->getLibStatut(4); print '