bulk operation edit agents add secundary groups pandora_enterprise#2152

This commit is contained in:
Daniel Barbero Martin 2022-02-03 13:52:40 +01:00
parent a359fd6828
commit 1146afe94c
3 changed files with 102 additions and 88 deletions

View File

@ -999,7 +999,6 @@ if ($update_agent) {
$fields = db_get_all_fields_in_table('tagent_custom_fields');
$secondary_groups = (string) get_parameter('secondary_hidden', '');
if ($fields === false) {
$fields = [];
}

View File

@ -140,8 +140,8 @@ if ($update_agents) {
$values['safe_mode_module'] = '0';
}
$secondary_groups_added = (string) get_parameter('secondary_hidden_added', '');
$secondary_groups_removed = (string) get_parameter('secondary_hidden_removed', '');
$secondary_groups_added = (array) get_parameter('secondary_groups_added', []);
$secondary_groups_removed = (array) get_parameter('secondary_groups_removed', []);
$fields = db_get_all_fields_in_table('tagent_custom_fields');
@ -389,8 +389,8 @@ if ($update_agents) {
'agents_update_secondary_groups',
[
$id_agent,
explode(',', $secondary_groups_added),
explode(',', $secondary_groups_removed),
$secondary_groups_added,
$secondary_groups_removed,
]
);
}
@ -743,9 +743,10 @@ if (enterprise_installed() === true) {
$agent,
$id_agente,
[
'container' => true,
'id_form' => 'form_agent',
'extra_id' => '_added',
'container' => true,
'id_form' => 'form_agent',
'extra_id' => '_added',
'only_select' => true,
]
);
@ -754,9 +755,10 @@ if (enterprise_installed() === true) {
$agent,
$id_agente,
[
'container' => true,
'id_form' => 'form_agent',
'extra_id' => '_removed',
'container' => true,
'id_form' => 'form_agent',
'extra_id' => '_removed',
'only_select' => true,
]
);
}

View File

@ -5639,15 +5639,24 @@ function html_print_select_agent_secondary($agent, $id_agente, $options=[])
$options['id_form'] = 'form_agent';
}
if (empty($options) === '' || isset($options['id_form']) === false) {
if (empty($options) === '' || isset($options['extra_id']) === false) {
$options['extra_id'] = '';
}
if (empty($options) === '' || isset($options['only_select']) === false) {
$options['only_select'] = false;
}
$secondary_groups_selected = enterprise_hook(
'agents_get_secondary_groups',
[$id_agente]
);
$name = 'secondary_groups'.$options['extra_id'];
if ($options['only_select'] === true) {
$name = 'secondary_groups'.$options['extra_id'].'[]';
}
$adv_secondary_groups_left = html_print_select_groups(
// Id_user.
// Use the current user to select the groups.
@ -5660,7 +5669,7 @@ function html_print_select_agent_secondary($agent, $id_agente, $options=[])
false,
// Name.
// HTML id.
'secondary_groups'.$options['extra_id'],
$name,
// Selected.
// No select any by default.
'',
@ -5714,89 +5723,93 @@ function html_print_select_agent_secondary($agent, $id_agente, $options=[])
// Simple_multiple_options.
);
$dictionary = base64_encode(
json_encode(
if ($options['only_select'] === false) {
$dictionary = base64_encode(
json_encode(
[
'primary_group' => __('Primary group cannot be secondary too.'),
'strNone' => __('None'),
]
)
);
$adv_secondary_groups_arrows = html_print_input_image(
'add_secondary',
'images/darrowright_green.png',
1,
'',
true,
[
'primary_group' => __('Primary group cannot be secondary too.'),
'strNone' => __('None'),
'id' => 'right_autorefreshlist'.$options['extra_id'],
'title' => __('Add secondary groups'),
'onclick' => 'agent_manager_add_secondary_groups(event, '.$id_agente.',\''.$options['extra_id'].'\', \''.$options['id_form'].'\', \''.$dictionary.'\');',
]
)
);
);
$adv_secondary_groups_arrows = html_print_input_image(
'add_secondary',
'images/darrowright_green.png',
1,
'',
true,
[
'id' => 'right_autorefreshlist'.$options['extra_id'],
'title' => __('Add secondary groups'),
'onclick' => 'agent_manager_add_secondary_groups(event, '.$id_agente.',\''.$options['extra_id'].'\', \''.$options['id_form'].'\', \''.$dictionary.'\');',
]
);
$adv_secondary_groups_arrows .= html_print_input_image(
'remove_secondary',
'images/darrowleft_green.png',
1,
'',
true,
[
'id' => 'left_autorefreshlist'.$options['extra_id'],
'title' => __('Remove secondary groups'),
'onclick' => 'agent_manager_remove_secondary_groups(event, '.$id_agente.',\''.$options['extra_id'].'\', \''.$options['id_form'].'\', \''.$dictionary.'\');',
]
);
$adv_secondary_groups_arrows .= html_print_input_image(
'remove_secondary',
'images/darrowleft_green.png',
1,
'',
true,
[
'id' => 'left_autorefreshlist'.$options['extra_id'],
'title' => __('Remove secondary groups'),
'onclick' => 'agent_manager_remove_secondary_groups(event, '.$id_agente.',\''.$options['extra_id'].'\', \''.$options['id_form'].'\', \''.$dictionary.'\');',
]
);
$adv_secondary_groups_right .= html_print_select(
$adv_secondary_groups_right .= html_print_select(
// Values.
$secondary_groups_selected['for_select'],
// HTML id.
'secondary_groups_selected'.$options['extra_id'],
// Selected.
'',
// Javascript onChange code.
'',
// Nothing selected.
false,
// Nothing selected.
0,
// Return HTML (not echo).
true,
// Multiple selection.
true,
// Sort.
true,
// Class.
'',
// Disabled.
false,
// Style.
'min-width:170px;'
);
$secondary_groups_selected['for_select'],
// HTML id.
'secondary_groups_selected'.$options['extra_id'],
// Selected.
'',
// Javascript onChange code.
'',
// Nothing selected.
false,
// Nothing selected.
0,
// Return HTML (not echo).
true,
// Multiple selection.
true,
// Sort.
true,
// Class.
'',
// Disabled.
false,
// Style.
'min-width:170px;'
);
$output = '';
if (isset($options['container']) === true
&& $options['container'] === true
) {
$output = '<div class="secondary_groups_list">';
}
$output = '';
if (isset($options['container']) === true
&& $options['container'] === true
) {
$output = '<div class="secondary_groups_list">';
}
$output .= '<div class="sg_source">';
$output .= $adv_secondary_groups_left;
$output .= '</div>';
$output .= '<div class="secondary_group_arrows">';
$output .= $adv_secondary_groups_arrows;
$output .= '</div>';
$output .= '<div class="sg_target">';
$output .= $adv_secondary_groups_right;
$output .= '</div>';
if (isset($options['container']) === true
&& $options['container'] === true
) {
$output .= '<div class="sg_source">';
$output .= $adv_secondary_groups_left;
$output .= '</div>';
$output .= '<div class="secondary_group_arrows">';
$output .= $adv_secondary_groups_arrows;
$output .= '</div>';
$output .= '<div class="sg_target">';
$output .= $adv_secondary_groups_right;
$output .= '</div>';
if (isset($options['container']) === true
&& $options['container'] === true
) {
$output .= '</div>';
}
} else {
$output .= $adv_secondary_groups_left;
}
return $output;