10898-Assign secondary groups in agent view

This commit is contained in:
Pablo Aragon 2023-04-12 08:21:26 +02:00
parent 01527dcc67
commit c21397476e
3 changed files with 27 additions and 8 deletions

View File

@ -636,7 +636,8 @@ $tableAdvancedAgent->data['secondary_groups'][] = html_print_label_input_block(
__('Secondary groups'),
html_print_select_agent_secondary(
$agent,
$id_agente
$id_agente,
['selected_post' => $secondary_groups]
)
);

View File

@ -228,7 +228,7 @@ if ($create_agent) {
$cps = (int) get_parameter_switch('cps', -1);
$fixed_ip = (int) get_parameter_switch('fixed_ip', 0);
$secondary_groups = (string) get_parameter('secondary_hidden', '');
$secondary_groups = (array) get_parameter('secondary_groups_selected', '');
$fields = db_get_all_fields_in_table('tagent_custom_fields');
if ($fields === false) {
@ -343,7 +343,7 @@ if ($create_agent) {
'agents_update_secondary_groups',
[
$id_agente,
explode(',', $secondary_groups),
$secondary_groups,
[],
]
);
@ -992,7 +992,7 @@ if ($update_agent) {
$cps = get_parameter_switch('cps', -1);
$old_values = db_get_row('tagente', 'id_agente', $id_agente);
$fields = db_get_all_fields_in_table('tagent_custom_fields');
$secondary_groups = (string) get_parameter('secondary_hidden', '');
$secondary_groups = (array) get_parameter('secondary_groups_selected', '');
$satellite_server = (int) get_parameter('satellite_server', 0);
$fixed_ip = (int) get_parameter_switch('fixed_ip', 0);
@ -1185,13 +1185,27 @@ if ($update_agent) {
"Quiet":"'.(int) $quiet.'",
"Cps":"'.(int) $cps.'"}';
$secondary_groups_selected = enterprise_hook(
'agents_get_secondary_groups',
[$id_agente]
);
$delete_secondary_groups = [];
foreach ($secondary_groups_selected['plain'] as $v_selected) {
if (in_array($v_selected, $secondary_groups) === false) {
array_push($delete_secondary_groups, $v_selected);
}
}
// Create the secondary groups.
enterprise_hook(
'agents_update_secondary_groups',
[
$id_agente,
explode(',', $secondary_groups),
[],
$secondary_groups,
$delete_secondary_groups,
true,
]
);

View File

@ -6435,7 +6435,11 @@ function html_print_select_agent_secondary($agent, $id_agente, $options=[])
[$id_agente]
);
$name = 'secondary_groups_selected'.$options['extra_id'];
if ($options['selected_post'] !== null) {
$secondary_groups_selected['plain'] = $options['selected_post'];
}
$name = 'secondary_groups_selected[]'.$options['extra_id'];
if ($options['only_select'] === true) {
$name = 'secondary_groups'.$options['extra_id'].'[]';
}
@ -6455,7 +6459,7 @@ function html_print_select_agent_secondary($agent, $id_agente, $options=[])
$name,
// Selected.
// No select any by default.
$secondary_groups_selected['for_select'],
$secondary_groups_selected['plain'],
// Script.
// Javascript onChange code.
'',