Fix: When creating user on other entity, no way to read user

after creation.
This commit is contained in:
Laurent Destailleur 2013-02-16 21:06:15 +01:00
parent b1ee14ce60
commit 50decdd941
3 changed files with 52 additions and 45 deletions

View File

@ -968,10 +968,10 @@ class Form
* @param int $disabled If select list must be disabled * @param int $disabled If select list must be disabled
* @param array $include Array list of users id to include * @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 $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 * @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); 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 int $disabled If select list must be disabled
* @param array $include Array list of users id to include * @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 $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 * @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; global $conf,$user,$langs;
@ -3953,10 +3953,10 @@ class Form
* @param int $disabled If select list must be disabled * @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 $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 * @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; global $conf,$user,$langs;

View File

@ -154,13 +154,13 @@ class User extends CommonObject
$sql.= " u.ref_int, u.ref_ext"; $sql.= " u.ref_int, u.ref_ext";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $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 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 if ($sid) // permet une recherche du user par son SID ActiveDirectory ou Samba

View File

@ -819,21 +819,6 @@ if (($action == 'create') || ($action == 'adduserldap'))
print "</td></tr>\n"; print "</td></tr>\n";
} }
//Multicompany
if (! empty($conf->multicompany->enabled))
{
if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
{
print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
print "<td>".$mc->select_entities($conf->entity);
print "</td></tr>\n";
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
}
}
// Type // Type
print '<tr><td valign="top">'.$langs->trans("Type").'</td>'; print '<tr><td valign="top">'.$langs->trans("Type").'</td>';
print '<td>'; print '<td>';
@ -902,6 +887,28 @@ if (($action == 'create') || ($action == 'adduserldap'))
print '<textarea rows="'.ROWS_5.'" cols="90" name="signature">'.GETPOST('signature').'</textarea>'; print '<textarea rows="'.ROWS_5.'" cols="90" name="signature">'.GETPOST('signature').'</textarea>';
print '</td></tr>'; print '</td></tr>';
// Multicompany
if (! empty($conf->multicompany->enabled))
{
if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
{
print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
print "<td>".$mc->select_entities($conf->entity);
print "</td></tr>\n";
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
}
}
// Hierarchy
print '<tr><td valign="top">'.$langs->trans("HierarchicalResponsible").'</td>';
print '<td>';
print $form->select_dolusers($object->fk_user,'fk_user',1,array($object->id),0,'',0,$conf->entity);
print '</td>';
print "</tr>\n";
// Note // Note
print '<tr><td valign="top">'; print '<tr><td valign="top">';
print $langs->trans("Note"); print $langs->trans("Note");
@ -941,7 +948,7 @@ else
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
if ($id) if ($id > 0)
{ {
$object->fetch($id); $object->fetch($id);
if ($res < 0) { dol_print_error($db,$object->error); exit; } if ($res < 0) { dol_print_error($db,$object->error); exit; }
@ -1201,7 +1208,7 @@ else
print '</td>'; print '</td>';
print "</tr>\n"; print "</tr>\n";
// Statut // Status
print '<tr><td valign="top">'.$langs->trans("Status").'</td>'; print '<tr><td valign="top">'.$langs->trans("Status").'</td>';
print '<td>'; print '<td>';
print $object->getLibStatut(4); print $object->getLibStatut(4);
@ -1315,7 +1322,7 @@ else
print '<div class="tabsAction">'; print '<div class="tabsAction">';
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)) if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
{ {
@ -1327,7 +1334,7 @@ else
} }
} }
elseif ($caneditpassword && ! $object->ldap_sid && 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 '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("EditPassword").'</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("EditPassword").'</a>';
} }
@ -1808,11 +1815,11 @@ else
// Hierarchy // Hierarchy
print '<tr><td valign="top">'.$langs->trans("HierarchicalResponsible").'</td>'; print '<tr><td valign="top">'.$langs->trans("HierarchicalResponsible").'</td>';
print '<td>'; print '<td>';
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 '</td>'; print '</td>';
print "</tr>\n"; print "</tr>\n";
// Statut // Status
print '<tr><td valign="top">'.$langs->trans("Status").'</td>'; print '<tr><td valign="top">'.$langs->trans("Status").'</td>';
print '<td>'; print '<td>';
print $object->getLibStatut(4); print $object->getLibStatut(4);