Merge pull request #7768 from hregis/develop_bug

Fix: move transversal mode management in multicompany module
This commit is contained in:
Laurent Destailleur 2017-11-05 18:39:26 +01:00 committed by GitHub
commit 8a8842c8f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 306 additions and 368 deletions

View File

@ -68,7 +68,8 @@ if (($object->id != $user->id) && (! $user->rights->user->user->lire))
accessforbidden(); accessforbidden();
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('usercard','globalcard')); $contextpage=array('usercard','useragenda','globalcard');
$hookmanager->initHooks($contextpage);
/* /*
* Actions * Actions

View File

@ -48,19 +48,13 @@ if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherent
if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$id = GETPOST('id','int'); $id = GETPOST('id','int');
$action = GETPOST('action','alpha'); $action = GETPOST('action','aZ09');
$mode = GETPOST('mode','alpha'); $mode = GETPOST('mode','alpha');
$confirm = GETPOST('confirm','alpha'); $confirm = GETPOST('confirm','alpha');
$subaction = GETPOST('subaction','alpha'); $subaction = GETPOST('subaction','alpha');
$group = GETPOST("group","int",3); $group = GETPOST("group","int",3);
$cancel = GETPOST('cancel','alpha'); $cancel = GETPOST('cancel','alpha');
// Users/Groups management only in master entity if transverse mode
if (($action == 'create' || $action == 'adduserldap') && ! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)
{
accessforbidden();
}
// Define value to know what current user can do on users // Define value to know what current user can do on users
$canadduser=(! empty($user->admin) || $user->rights->user->user->creer); $canadduser=(! empty($user->admin) || $user->rights->user->user->creer);
$canreaduser=(! empty($user->admin) || $user->rights->user->user->lire); $canreaduser=(! empty($user->admin) || $user->rights->user->user->lire);
@ -106,7 +100,8 @@ $extrafields = new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
$hookmanager->initHooks(array('usercard','globalcard')); $contextpage=array('usercard','globalcard');
$hookmanager->initHooks($contextpage);
@ -114,7 +109,7 @@ $hookmanager->initHooks(array('usercard','globalcard'));
* Actions * Actions
*/ */
$parameters=array('id'=>$socid); $parameters=array('id' => $id, 'socid' => $socid, 'group' => $group, 'caneditgroup' => $caneditgroup);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
@ -279,7 +274,7 @@ if (empty($reshook)) {
} }
// Action add usergroup // Action add usergroup
if (($action == 'addgroup' || $action == 'removegroup') && $caneditfield) if (($action == 'addgroup' || $action == 'removegroup') && $caneditgroup)
{ {
if ($group) if ($group)
{ {
@ -289,10 +284,10 @@ if (empty($reshook)) {
$object->fetch($id); $object->fetch($id);
if ($action == 'addgroup') { if ($action == 'addgroup') {
$result = $object->SetInGroup($group, (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ? GETPOST('entity', 'int') : $editgroup->entity)); $result = $object->SetInGroup($group, $editgroup->entity);
} }
if ($action == 'removegroup') { if ($action == 'removegroup') {
$result = $object->RemoveFromGroup($group, (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ? GETPOST('entity', 'int') : $editgroup->entity)); $result = $object->RemoveFromGroup($group, $editgroup->entity);
} }
if ($result > 0) { if ($result > 0) {
@ -1706,7 +1701,7 @@ else
include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
if (GETPOST('action','aZ09') != 'presend' && GETPOST('action','aZ09') != 'send') if ($action != 'presend' && $action != 'send')
{ {
/* /*
* List of groups of user * List of groups of user
@ -1723,15 +1718,12 @@ else
$groupslist = $usergroup->listGroupsForUser($object->id); $groupslist = $usergroup->listGroupsForUser($object->id);
if (! empty($groupslist)) if (! empty($groupslist))
{
if (! (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)))
{ {
foreach($groupslist as $groupforuser) foreach($groupslist as $groupforuser)
{ {
$exclude[]=$groupforuser->id; $exclude[]=$groupforuser->id;
} }
} }
}
if ($caneditgroup) if ($caneditgroup)
{ {
@ -1741,43 +1733,23 @@ else
} }
print '<table class="noborder" width="100%">'."\n"; print '<table class="noborder" width="100%">'."\n";
print '<tr class="liste_titre"><th class="liste_titre">'.$langs->trans("Groups").'</th>'."\n";
if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && ! $user->entity) // Other form for add user to group
$parameters=array('caneditgroup' => $caneditgroup, 'groupslist' => $groupslist, 'exclude' => $exclude);
$reshook=$hookmanager->executeHooks('formAddUserToGroup',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (empty($reshook))
{ {
print '<th class="liste_titre">'.$langs->trans("Entity").'</td>'; print '<tr class="liste_titre"><th class="liste_titre">'.$langs->trans("Groups").'</th>'."\n";
}
print '<th class="liste_titre" align="right">'; print '<th class="liste_titre" align="right">';
if ($caneditgroup) if ($caneditgroup)
{
// Users/Groups management only in master entity if transverse mode
if (! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)
{
// nothing
}
else
{ {
print $form->select_dolgroups('', 'group', 1, $exclude, 0, '', '', $object->entity); print $form->select_dolgroups('', 'group', 1, $exclude, 0, '', '', $object->entity);
print ' &nbsp; '; print ' &nbsp; ';
// Multicompany
if (! empty($conf->multicompany->enabled))
{
if ($conf->entity == 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)
{
print '</td><td>'.$langs->trans("Entity").'</td>';
print "<td>".$mc->select_entities($conf->entity);
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />'; print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
}
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
}
print '<input type="submit" class="button" value="'.$langs->trans("Add").'" />'; print '<input type="submit" class="button" value="'.$langs->trans("Add").'" />';
} }
}
print '</th></tr>'."\n"; print '</th></tr>'."\n";
/* /*
@ -1787,8 +1759,6 @@ else
{ {
foreach($groupslist as $group) foreach($groupslist as $group)
{ {
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'; print '<td>';
if ($caneditgroup) if ($caneditgroup)
@ -1800,25 +1770,8 @@ else
print img_object($langs->trans("ShowGroup"),"group").' '.$group->name; print img_object($langs->trans("ShowGroup"),"group").' '.$group->name;
} }
print '</td>'; print '</td>';
if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && ! $user->entity)
{
print '<td class="valeur">';
if (! empty($group->usergroup_entity))
{
$nb=0;
foreach($group->usergroup_entity as $group_entity)
{
$mc->getInfo($group_entity);
print ($nb > 0 ? ', ' : '').$mc->label;
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removegroup&amp;group='.$group->id.'&amp;entity='.$group_entity.'">';
print img_delete($langs->trans("RemoveFromGroup"));
print '</a>';
$nb++;
}
}
}
print '<td align="right">'; print '<td align="right">';
if ($caneditgroup && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) if ($caneditgroup)
{ {
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removegroup&amp;group='.$group->id.'">'; print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removegroup&amp;group='.$group->id.'">';
print img_delete($langs->trans("RemoveFromGroup")); print img_delete($langs->trans("RemoveFromGroup"));
@ -1835,6 +1788,7 @@ else
{ {
print '<tr '.$bc[false].'><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; print '<tr '.$bc[false].'><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
} }
}
print "</table>"; print "</table>";

View File

@ -94,7 +94,8 @@ if ($id > 0 || ! empty($ref))
} }
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('usercard','globalcard')); $contextpage=array('usercard','userdoc','globalcard');
$hookmanager->initHooks($contextpage);
/* /*

View File

@ -65,11 +65,21 @@ $extrafields = new ExtraFields($db);
// fetch optionals attributes and labels // fetch optionals attributes and labels
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$hookmanager->initHooks(array('groupcard','globalcard')); // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
$contextpage=array('groupcard','globalcard');
$hookmanager->initHooks($contextpage);
/** /**
* Action remove group * Actions
*/ */
$parameters=array('id' => $id, 'userid' => $userid, 'caneditperms' => $caneditperms);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) {
// Action remove group
if ($action == 'confirm_delete' && $confirm == "yes") if ($action == 'confirm_delete' && $confirm == "yes")
{ {
if ($caneditperms) if ($caneditperms)
@ -86,9 +96,7 @@ if ($action == 'confirm_delete' && $confirm == "yes")
} }
} }
/** // Action add group
* Action add group
*/
if ($action == 'add') if ($action == 'add')
{ {
if ($caneditperms) if ($caneditperms)
@ -148,8 +156,8 @@ if ($action == 'adduser' || $action =='removeuser')
$edituser = new User($db); $edituser = new User($db);
$edituser->fetch($userid); $edituser->fetch($userid);
if ($action == 'adduser') $result=$edituser->SetInGroup($object->id,(! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)?GETPOST('entity','int'):$object->entity)); if ($action == 'adduser') $result=$edituser->SetInGroup($object->id,$object->entity);
if ($action == 'removeuser') $result=$edituser->RemoveFromGroup($object->id,(! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)?GETPOST('entity','int'):$object->entity)); if ($action == 'removeuser') $result=$edituser->RemoveFromGroup($object->id,$object->entity);
if ($result > 0) if ($result > 0)
{ {
@ -215,7 +223,7 @@ if ($action == 'update')
$upload_dir = $conf->usergroup->dir_output; $upload_dir = $conf->usergroup->dir_output;
$permissioncreate=$user->rights->user->user->creer; $permissioncreate=$user->rights->user->user->creer;
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
}
/* /*
@ -385,16 +393,20 @@ else
$exclude = array(); $exclude = array();
if (! empty($object->members)) if (! empty($object->members))
{
if (! (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)))
{ {
foreach($object->members as $useringroup) foreach($object->members as $useringroup)
{ {
$exclude[]=$useringroup->id; $exclude[]=$useringroup->id;
} }
} }
}
// Other form for add user to group
$parameters=array('caneditperms' => $caneditperms, 'exclude' => $exclude);
$reshook=$hookmanager->executeHooks('formAddUserToGroup',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (empty($reshook))
{
if ($caneditperms) if ($caneditperms)
{ {
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST">'."\n"; print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST">'."\n";
@ -405,23 +417,7 @@ else
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print $form->select_dolusers('', 'user', 1, $exclude, 0, '', '', $object->entity, 0, 0, '', 0, '', 'maxwidth300'); print $form->select_dolusers('', 'user', 1, $exclude, 0, '', '', $object->entity, 0, 0, '', 0, '', 'maxwidth300');
print ' &nbsp; '; print ' &nbsp; ';
// Multicompany
if (! empty($conf->multicompany->enabled) && is_object($mc))
{
if ($conf->entity == 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)
{
print '</td><td class="tdtop">'.$langs->trans("Entity").'</td>';
print "<td>".$mc->select_entities($conf->entity);
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
}
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'">'; print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
}
print '<input type="submit" class="button" value="'.$langs->trans("Add").'">'; print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
print '</td></tr>'."\n"; print '</td></tr>'."\n";
print '</table></form>'."\n"; print '</table></form>'."\n";
@ -436,10 +432,6 @@ else
print '<td class="liste_titre">'.$langs->trans("Login").'</td>'; print '<td class="liste_titre">'.$langs->trans("Login").'</td>';
print '<td class="liste_titre">'.$langs->trans("Lastname").'</td>'; print '<td class="liste_titre">'.$langs->trans("Lastname").'</td>';
print '<td class="liste_titre">'.$langs->trans("Firstname").'</td>'; print '<td class="liste_titre">'.$langs->trans("Firstname").'</td>';
if (! empty($conf->multicompany->enabled) && $conf->entity == 1)
{
print '<td class="liste_titre">'.$langs->trans("Entity").'</td>';
}
print '<td class="liste_titre" width="5" align="center">'.$langs->trans("Status").'</td>'; print '<td class="liste_titre" width="5" align="center">'.$langs->trans("Status").'</td>';
print '<td class="liste_titre" width="5" align="right">&nbsp;</td>'; print '<td class="liste_titre" width="5" align="right">&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
@ -456,27 +448,9 @@ else
print '</td>'; print '</td>';
print '<td>'.$useringroup->lastname.'</td>'; print '<td>'.$useringroup->lastname.'</td>';
print '<td>'.$useringroup->firstname.'</td>'; print '<td>'.$useringroup->firstname.'</td>';
if (! empty($conf->multicompany->enabled) && is_object($mc) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && ! $user->entity)
{
print '<td class="valeur">';
if (! empty($useringroup->usergroup_entity))
{
$nb=0;
foreach($useringroup->usergroup_entity as $group_entity)
{
$mc->getInfo($group_entity);
print ($nb > 0 ? ', ' : '').$mc->label;
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removeuser&amp;user='.$useringroup->id.'&amp;entity='.$group_entity.'">';
print img_delete($langs->trans("RemoveFromGroup"));
print '</a>';
$nb++;
}
}
print '</td>';
}
print '<td align="center">'.$useringroup->getLibStatut(3).'</td>'; print '<td align="center">'.$useringroup->getLibStatut(3).'</td>';
print '<td align="right">'; print '<td align="right">';
if (! empty($user->admin) && empty($conf->multicompany->enabled)) if (! empty($user->admin))
{ {
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removeuser&amp;user='.$useringroup->id.'">'; print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removeuser&amp;user='.$useringroup->id.'">';
print img_delete($langs->trans("RemoveFromGroup")); print img_delete($langs->trans("RemoveFromGroup"));
@ -494,8 +468,12 @@ else
print '<tr><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; print '<tr><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
} }
print "</table>"; print "</table>";
}
print "<br>"; print "<br>";
print '<div class="fichecenter"><div class="fichehalfleft">';
/* /*
* Documents generes * Documents generes
*/ */

View File

@ -46,7 +46,9 @@ $object->fetch($id, '', '', 1);
$object->getrights(); $object->getrights();
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('usercard','globalcard')); $contextpage=array('usercard','userldap','globalcard');
$hookmanager->initHooks($contextpage);
/* /*
* Actions * Actions

View File

@ -50,7 +50,8 @@ if ($user->id == $id) $feature2=''; // A user can always read its own card
$result = restrictedArea($user, 'user', $id, 'user&user', $feature2); $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('usercard','globalcard')); $contextpage=array('usercard','usernote','globalcard');
$hookmanager->initHooks($contextpage);
/* /*

View File

@ -79,7 +79,8 @@ $form = new Form($db);
$formadmin=new FormAdmin($db); $formadmin=new FormAdmin($db);
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('usercard','globalcard')); $contextpage=array('usercard','userihm','globalcard');
$hookmanager->initHooks($contextpage);
/* /*

View File

@ -73,7 +73,7 @@ $object->getrights();
$entity=$conf->entity; $entity=$conf->entity;
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$contextpage=array('usercard','globalcard'); $contextpage=array('usercard','userperms','globalcard');
$hookmanager->initHooks($contextpage); $hookmanager->initHooks($contextpage);