From a4b2e38ffcb13dbb9aa1e144ceeb21f182d6cdf4 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 8 Oct 2020 16:41:26 +0200 Subject: [PATCH] Fix unhandled extra-options in group selector inclusions --- .../godmode/massive/massive_edit_agents.php | 19 +++++++- pandora_console/include/functions_html.php | 5 +++ pandora_console/include/lib/Group.php | 44 +++++++++++++++---- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index 6a4ca61fcb..7f04eb2b29 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -548,7 +548,24 @@ $table->data[0][1] .= ''.__('Cascade protection').''.html_print_select( $table->data[0][1] .= '  '.__('Module').' '.html_print_select($modules, 'cascade_protection_module', $cascade_protection_module, '', '', 0, true); $table->data[1][0] = __('Group'); -$table->data[1][1] = html_print_select_groups(false, 'AR', false, 'group', $group, '', __('No change'), -1, true, false, true, '', false, 'width: 150px;'); +$table->data[1][1] = '
'; +$table->data[1][1] .= html_print_select_groups( + false, + 'AR', + false, + 'group', + $group, + '', + __('No change'), + -1, + true, + false, + true, + '', + false, + 'width: 150px;' +); +$table->data[1][1] .= '
'; $table->data[2][0] = __('Interval'); diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 6dedb85927..092044765c 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -514,6 +514,11 @@ function html_print_select_groups( } } + if (empty($nothing) === false) { + $fields[$nothing_value] = $nothing; + $include_groups[$nothing_value] = $nothing; + } + if (is_array($delete_groups) === true) { $json_exclusions = json_encode($delete_groups); } diff --git a/pandora_console/include/lib/Group.php b/pandora_console/include/lib/Group.php index d054f67abe..cf4ffa9ab0 100644 --- a/pandora_console/include/lib/Group.php +++ b/pandora_console/include/lib/Group.php @@ -170,8 +170,8 @@ class Group extends Entity private static function prepareGroups(array $groups):array { $return = []; - $groups = \groups_get_groups_tree_recursive($groups); - foreach ($groups as $k => $v) { + $tree_groups = \groups_get_groups_tree_recursive($groups); + foreach ($tree_groups as $k => $v) { $return[] = [ 'id' => $k, 'text' => \io_safe_output( @@ -187,8 +187,29 @@ class Group extends Entity ]; } - return $return; + $unassigned = []; + $processed = array_keys($tree_groups); + foreach ($groups as $k => $v) { + if (in_array($k, $processed) === true) { + continue; + } + $unassigned[] = [ + 'id' => $k, + 'text' => \io_safe_output( + \ui_print_truncate_text( + $v, + GENERIC_SIZE_TEXT, + false, + true, + false + ) + ), + 'level' => 0, + ]; + } + + return array_merge($unassigned, $return); } @@ -291,18 +312,25 @@ class Group extends Entity ] ); - $exclusions = json_decode(\io_safe_output($exclusions)); + $exclusions = json_decode(\io_safe_output($exclusions), true); if (empty($exclusions) === false) { foreach ($exclusions as $ex) { unset($groups[$ex]); } } - $inclusions = json_decode(\io_safe_output($inclusions)); + $inclusions = json_decode(\io_safe_output($inclusions), true); if (empty($inclusions) === false) { - foreach ($inclusions as $g) { - if (empty($groups[$g]) === true) { - $groups[$g] = \groups_get_name($g); + foreach ($inclusions as $k => $g) { + if (empty($groups[$k]) === true) { + if (is_numeric($g) === true) { + $groups[$k] = \groups_get_name($k); + } + + if (empty($groups[$k]) === true) { + // Group does not exist, direct value assigned. + $groups[$k] = $g; + } } } }