Merge branch '1630-Lentitud_en_vista_de_eventos_con_muchos_grupos' into 'develop'

optimization view events

See merge request artica/pandorafms!1139
This commit is contained in:
nramon 2017-11-30 16:12:14 +01:00
commit 9809efd6f3
5 changed files with 64 additions and 69 deletions

View File

@ -1687,7 +1687,7 @@ function events_page_responses ($event, $childrens_ids = array()) {
$users[0]['id_user'] = $config['id_user'];
$users[0]['fullname'] = $user_name;
} else {
$users = groups_get_users($_user_groups, array('id_perfil' => $profiles_view_events), true, true);
$users = groups_get_users($_user_groups, array('id_perfil' => $profiles_view_events), true);
}
foreach($users as $u) {

View File

@ -538,7 +538,7 @@ function groups_get_groups_tree_recursive($groups, $trash = 0, $trash2 = 0) {
// If the user has ACLs on a gruop but not in his father,
// we consider it as a son of group "all"
if(!in_array($group['parent'], array_keys($groups))) {
if(!isset($groups[$group['parent']])) {
$group['parent'] = 0;
}
@ -633,61 +633,55 @@ function groups_get_id ($group_name, $returnAllGroup = false) {
* @param int $id_group The group id to look for
* @param mixed filter array
* @param bool True if users with all permissions in the group are retrieved
* @param bool Is id_group an array or not #Fix
*
* @return array An array with all the users or an empty array
*/
function groups_get_users ($id_group, $filter = false, $return_user_all = false, $_is_array = false) {
function groups_get_users ($id_group, $filter = false, $return_user_all = false) {
global $config;
if (! is_array ($filter))
$filter = array ();
$filter['id_grupo'] = $id_group;
$result_a = array();
// Juanma (05/05/2014) Fix: Check for number/array id_group variable
if ($_is_array && is_array($id_group) && !empty($id_group)) {
$result_a = db_get_all_rows_filter ("tusuario_perfil", $filter);
} else {
if (!is_array($id_group) && !empty($id_group)) {
$result_a = db_get_all_rows_filter ("tusuario_perfil", $filter);
if($return_user_all){
if (is_array($id_group)){
$filter['id_grupo'] = $id_group;
}
else{
$filter['id_grupo'][0] = $id_group;
}
array_push($filter['id_grupo'], 0);
}
$result_b = array();
if ($return_user_all) {
// The users of the group All (0) will be also returned
$filter['id_grupo'] = 0;
$result_b = db_get_all_rows_filter ("tusuario_perfil", $filter);
else{
$filter['id_grupo'] = $id_group;
}
if ($result_a == false && $result_b == false)
$result = false;
elseif ($result_a == false)
$result = $result_b;
elseif ($result_b == false)
$result = $result_a;
else
$result = array_merge($result_a, $result_b);
if ($result === false)
$query = "SELECT tu.*
FROM tusuario tu, tusuario_perfil tup
WHERE tup.id_usuario = tu.id_user" ;
if(is_array($filter)){
foreach ($filter as $key => $value) {
if($key != 'limit' && $key != 'order' &&
$key != 'offset' &&$key != 'group'){
$filter_array["tup.".$key] = $value;
}
else{
$filter_array[$key] = $value;
}
}
$clause_sql = mysql_db_format_array_where_clause_sql($filter_array,'AND',false);
if($clause_sql){
$query .= " AND " . $clause_sql;
}
}
$result = db_get_all_rows_sql($query);
if ($result === false){
return array ();
//This removes stale users from the list. This can happen if switched to another auth scheme
//(internal users still exist) or external auth has users removed/inactivated from the list (eg. LDAP)
$retval = array ();
foreach ($result as $key => $user) {
if (!is_user ($user)) {
unset ($result[$key]);
}
else {
array_push ($retval, get_user_info ($user));
}
}
return $retval;
return $result;
}
/**

View File

@ -235,12 +235,6 @@ function io_safe_output($value, $utf8 = true)
//Replace the html entitie of > for the char
$value = str_replace(">", '>', $value);
//Revert html entities to chars
for ($i = 0; $i < 33; $i++) {
$value = str_ireplace("&#x" . dechex($i) . ";",
io_html_to_ascii(dechex($i)), $value);
}
if ($utf8) {
$value = html_entity_decode ($value, ENT_QUOTES, "UTF-8");
}

View File

@ -888,21 +888,24 @@ function users_get_user_users($id_user = false, $privilege = "AR",
global $config;
$user_groups = users_get_groups($id_user, $privilege, $returnAllGroup);
$user_users = array();
$array_user_group = array();
foreach ($user_groups as $id_user_group => $name_user_group) {
$group_users = groups_get_users($id_user_group, false, $returnAllGroup);
$array_user_group[] = $id_user_group;
}
$group_users = groups_get_users($array_user_group, false, $returnAllGroup);
foreach ($group_users as $gu) {
if (empty($fields)) {
$user_users[$gu['id_user']] = $gu['id_user'];
}
else {
$fields = (array)$fields;
foreach ($fields as $field) {
$user_users[$gu['id_user']][$field] = $gu[$field];
}
foreach ($group_users as $gu) {
if (empty($fields)) {
$user_users[$gu['id_user']] = $gu['id_user'];
}
else {
$fields = (array)$fields;
foreach ($fields as $field) {
$user_users[$gu['id_user']][$field] = $gu[$field];
}
}
}

View File

@ -249,6 +249,7 @@ if ($update_pressed || $open_filter) {
unset($table);
$filters = events_get_event_filter_select();
$user_groups_array = users_get_groups_for_select($config["id_user"], $access, users_can_manage_group_all(), true, false);
// Some translated words to be used from javascript
html_print_div(array('hidden' => true,
@ -292,9 +293,11 @@ if (check_acl ($config["id_user"], 0, "EW") || check_acl ($config["id_user"], 0,
$data[1] = __('Save in Group') . $jump;
else
$data[1] = __('Filter group') . $jump;
# Fix : Only admin users can see group ALL
$data[1] .= html_print_select_groups($config['id_user'], $access, users_can_manage_group_all(), "id_group_filter",
$id_group_filter, '', '', 0, true, false, false, 'w130', false, '', false, false, 'id_grupo', $strict_user);
$data[1] .= html_print_select ($user_groups_array, 'id_group_filter', $id_group_filter,
'', '', 0, true, false, false, 'w130'
);
$table->data[] = $data;
$table->rowclass[] = '';
@ -608,9 +611,9 @@ $table->data = array();
$data = array();
$data[0] = __('Group') . $jump;
$data[0] .= html_print_select_groups($config["id_user"], $access, true,
'id_group', $id_group, '', '', 0, true, false, false, '', false, false, false, false, 'id_grupo', $strict_user). $jump;
$data[0] .= html_print_select ($user_groups_array, 'id_group', $id_group,
'', '', 0, true, false, false
) . $jump;
//**********************************************************************
// TODO
// This code is disabled for to enabled in Pandora 5.1
@ -794,7 +797,8 @@ enterprise_hook('print_event_tags_active_filters',
'severity' => $severities,
'duplicate' => $repeated_sel,
'alerts' => $alert_events_titles,
'groups' => users_get_groups_for_select($config["id_user"], $access, true, true, false))
'groups' => $user_groups_array
)
)
);