Merge remote-tracking branch 'origin/develop' into 1827-Graficas_TIP_eje_x_no_mantiene_ratio

This commit is contained in:
daniel 2018-02-16 13:14:45 +01:00
commit d7a8283994
1 changed files with 1 additions and 125 deletions

View File

@ -288,7 +288,7 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup
$forest_acl[$g["id_grupo"]] = $g;
}
else {
$forest_acl[$g["id_grupo"]]["tags"] .= "," . $g["tags"];
$forest_acl[$g["id_grupo"]] = groups_combine_acl($forest_acl[$g["id_grupo"]], $g);
}
}
@ -368,130 +368,6 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup
return $user_groups;
}
/**
* Get all the groups a user has reading privileges.
*
* @param string User id
* @param string The privilege to evaluate, and it is false then no check ACL.
* @param boolean $returnAllGroup Flag the return group, by default true.
* @param boolean $returnAllColumns Flag to return all columns of groups.
* @param array $id_groups The list of group to scan to bottom child. By default null.
* @param string $keys_field The field of the group used in the array keys. By default ID
*
* @return array A list of the groups the user has certain privileges.
*/
function old_users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup = true, $returnAllColumns = false,
$id_groups = null, $keys_field = 'id_grupo', $cache = true) {
static $group_cache = array();
if (empty ($id_user)) {
global $config;
$id_user = null;
if (isset($config['id_user'])) {
$id_user = $config['id_user'];
}
}
// Check the group cache first.
if (array_key_exists($id_user, $group_cache) && $cache) {
$groups = $group_cache[$id_user];
} else {
// Admin.
if (is_user_admin($id_user)) {
$groups = db_get_all_rows_sql ("SELECT * FROM tgrupo ORDER BY nombre");
}
// Per-group permissions.
else {
$query = sprintf("SELECT tgrupo.*, tperfil.*, tusuario_perfil.tags FROM tgrupo, tusuario_perfil, tperfil
WHERE (tgrupo.id_grupo = tusuario_perfil.id_grupo OR tusuario_perfil.id_grupo = 0)
AND tusuario_perfil.id_perfil = tperfil.id_perfil
AND tusuario_perfil.id_usuario = '%s' ORDER BY tgrupo.nombre", $id_user);
$groups = db_get_all_rows_sql ($query);
// Get children groups.
$parent_ids = array();
$parents = $groups;
$seen = array();
while (!empty($parents)) {
$children = array();
foreach ($parents as $parent) {
// Do not process the same parent twice.
if (array_key_exists($parent['id_grupo'], $seen)) {
continue;
}
$seen[$parent['id_grupo']] = 1;
// Does this group propagate ACLs?
if ($parent['propagate'] == '0') {
continue;
}
// Save a list of parents in the tree to search for user profiles, including the current parent!
$parent_ids[$parent['id_grupo']] = isset($parent_ids[$parent['parent']]) ? array_merge(array($parent['id_grupo']), $parent_ids[$parent['parent']]) : array($parent['id_grupo']);
// Get children groups from the DB.
$query = sprintf("SELECT tgrupo.*, tperfil.*, tusuario_perfil.tags FROM tgrupo, tusuario_perfil, tperfil
WHERE tgrupo.parent = %d
AND tusuario_perfil.id_grupo IN (%s)
AND tusuario_perfil.id_perfil = tperfil.id_perfil
AND tusuario_perfil.id_usuario = '%s'", $parent['id_grupo'], join(',', $parent_ids[$parent['id_grupo']]), $id_user);
$local_children = db_get_all_rows_sql ($query);
if (!empty($local_children)) {
$children = array_merge($children, $local_children);
}
}
if (!empty($children)) {
$groups = array_merge($groups, $children);
}
// Move down in the hierarchy.
$parents = $children;
}
}
// Update the group cache.
$group_cache[$id_user] = $groups;
}
$user_groups = array ();
if (!$groups) {
return $user_groups;
}
if ($returnAllGroup) { //All group
$groupall = array('id_grupo' => 0, 'nombre' => __('All'),
'icon' => 'world', 'parent' => 0, 'disabled' => 0,
'custom_id' => null, 'description' => '', 'propagate' => 0);
// Add the All group to the beginning to be always the first
array_unshift($groups, $groupall);
}
$acl_column = get_acl_column($privilege);
foreach ($groups as $group) {
# Check the specific permission column. acl_column is undefined for admins.
if (defined($group[$acl_column]) && $group[$acl_column] != '1') {
continue;
}
if ($returnAllColumns) {
$user_groups[$group[$keys_field]] = $group;
}
else {
$user_groups[$group[$keys_field]] = $group['nombre'];
}
}
if (!empty($id_groups)) {
$user_groups = array_intersect_key($user_groups,array_flip($id_groups));
}
return $user_groups;
}
/**
* Get all the groups a user has reading privileges. Version for tree groups.
*