#10335 fixed plugin select in edit modules in bulk

This commit is contained in:
Daniel Cebrian 2023-02-08 15:23:13 +01:00
parent f845cc9478
commit bcfa977f56
2 changed files with 36 additions and 41 deletions

View File

@ -89,8 +89,7 @@ $password_fields = [];
// If there are $macros, we create the form fields // If there are $macros, we create the form fields
if (!empty($macros)) { if (!empty($macros)) {
$macros = json_decode($macros, true); $macros = json_decode(io_safe_output($macros), true);
foreach ($macros as $k => $m) { foreach ($macros as $k => $m) {
$data = []; $data = [];
$data[0] = $m['desc']; $data[0] = $m['desc'];

View File

@ -2094,46 +2094,21 @@ function process_manage_edit($module_name, $agents_select=null, $module_status='
switch ($field) { switch ($field) {
case 'id_plugin': case 'id_plugin':
if ($value != 0) { if ($value != 0) {
$value_field_1 = get_parameter('_field1_', ''); for ($i = 0; $i <= 15; $i++) {
$value_field_1_desc = get_parameter('desc_field1_', ''); $value_field = get_parameter('_field'.$i.'_', '');
$value_field_desc = get_parameter('desc_field'.$i.'_', '');
$value_field_2 = get_parameter('_field2_', ''); if ($value_field_desc != '') {
$value_field_2_desc = get_parameter('desc_field2_', ''); $values['macros'][$i] = [
'macro' => '_field'.$i.'_',
$value_field_3 = get_parameter('_field3_', ''); 'desc' => io_safe_input($value_field_desc),
$value_field_3_desc = get_parameter('desc_field3_', ''); 'help' => io_safe_input($value_field_desc),
'value' => $value_field,
$value_field_4 = get_parameter('_field4_', ''); ];
$value_field_4_desc = get_parameter('desc_field4_', '');
$value_field_5 = get_parameter('_field5_', '');
$value_field_5_desc = get_parameter('desc_field5_', '');
$values['macros'] = '{"1":{"macro":"_field1_","desc":"'.io_safe_input($value_field_1_desc).'","help":"'.io_safe_input($value_field_1_desc).'","value":"'.$value_field_1.'"}';
if ($value_field_2_desc != '') {
$values['macros'] .= ',"2":{"macro":"_field2_","desc":"'.io_safe_input($value_field_2_desc).'","help":"'.io_safe_input($value_field_2_desc).'","value":"'.$value_field_2.'"}';
if ($value_field_3_desc != '') {
$values['macros'] .= ',"3":{"macro":"_field3_","desc":"'.io_safe_input($value_field_3_desc).'","help":"'.io_safe_input($value_field_3_desc).'","value":"'.$value_field_3.'"}';
if ($value_field_4_desc != '') {
$values['macros'] .= ',"4":{"macro":"_field4_","desc":"'.io_safe_input($value_field_4_desc).'","help":"'.io_safe_input($value_field_4_desc).'","value":"'.$value_field_4.'"}';
if ($value_field_5_desc != '') {
$values['macros'] .= ',"5":{"macro":"_field5_","desc":"'.io_safe_input($value_field_5_desc).'","help":"'.io_safe_input($value_field_5_desc).'","value":"'.$value_field_5.'"}';
} else {
$values['macros'] .= '}';
}
} else {
$values['macros'] .= '}';
}
} else {
$values['macros'] .= '}';
} }
} else {
$values['macros'] .= '}';
} }
$values['macros'] = json_encode($values['macros']);
$values[$field] = $value;
} }
break; break;
@ -2260,7 +2235,7 @@ function process_manage_edit($module_name, $agents_select=null, $module_status='
// Apply at All agents (within valid groups). // Apply at All agents (within valid groups).
$modules = db_get_all_rows_sql( $modules = db_get_all_rows_sql(
sprintf( sprintf(
'SELECT tam.id_agente_modulo, tam.id_tipo_modulo 'SELECT tam.id_agente_modulo, tam.id_tipo_modulo,tam.macros, tam.id_plugin
FROM tagente_modulo tam INNER JOIN tagente ta FROM tagente_modulo tam INNER JOIN tagente ta
ON ta.id_agente = tam.id_agente ON ta.id_agente = tam.id_agente
WHERE ta.id_grupo IN (%s) %s;', WHERE ta.id_grupo IN (%s) %s;',
@ -2277,6 +2252,8 @@ function process_manage_edit($module_name, $agents_select=null, $module_status='
[ [
'id_agente_modulo', 'id_agente_modulo',
'id_tipo_modulo', 'id_tipo_modulo',
'macros',
'id_plugin',
] ]
); );
} else { } else {
@ -2289,6 +2266,8 @@ function process_manage_edit($module_name, $agents_select=null, $module_status='
[ [
'id_agente_modulo', 'id_agente_modulo',
'id_tipo_modulo', 'id_tipo_modulo',
'macros',
'id_plugin',
] ]
); );
} }
@ -2346,6 +2325,23 @@ function process_manage_edit($module_name, $agents_select=null, $module_status='
} }
} }
if ($module['macros'] && $module['id_plugin'] == $values['id_plugin']) {
$module_macros = json_decode($module['macros'], true);
$values_macros = json_decode($values['macros'], true);
foreach ($values_macros as $k => $value_macro) {
foreach ($module_macros as $s => $module_macro) {
if ($value_macro['macro'] == $module_macro['macro'] && $value_macro['value'] !== '') {
$module_macros[$s]['value'] = $value_macro['value'];
$module_macros[$s]['desc'] = $value_macro['desc'];
$module_macros[$s]['help'] = $value_macro['help'];
}
}
}
$values['macros'] = json_encode($module_macros);
}
$result = modules_update_agent_module( $result = modules_update_agent_module(
$module['id_agente_modulo'], $module['id_agente_modulo'],
$values, $values,