$v) {
$agents[$keys_prefix.$k] = $v;
unset($agents[$k]);
}
}
echo json_encode($agents);
return;
}
return;
}
function process_manage_add($id_alert_template, $id_agents, $module_names)
{
if (empty($id_agents) || $id_agents[0] == 0) {
ui_print_error_message(__('No agents selected'));
return false;
}
if (empty($id_alert_template)) {
ui_print_error_message(__('No alert selected'));
return false;
}
$modules_id = [];
foreach ($module_names as $module) {
foreach ($id_agents as $id_agent) {
if ($module == '0') {
// Get all modules of agent.
$agent_modules = db_get_all_rows_filter(
'tagente_modulo',
['id_agente' => $id_agent],
'id_agente_modulo'
);
$agent_modules_id = array_map(
function ($field) {
return $field['id_agente_modulo'];
},
$agent_modules
);
$modules_id = array_merge($modules_id, $agent_modules_id);
} else {
$module_id = modules_get_agentmodule_id($module, $id_agent);
$modules_id[] = $module_id['id_agente_modulo'];
}
}
}
$conttotal = 0;
$contsuccess = 0;
foreach ($modules_id as $module) {
$success = alerts_create_alert_agent_module($module, $id_alert_template);
if ($success) {
$contsuccess ++;
}
$conttotal ++;
}
if ($contsuccess > 0) {
db_pandora_audit('Massive management', 'Add alert', false, false, 'Alert template: '.$id_alert_template.' Modules: '.json_encode($modules_id));
} else {
db_pandora_audit('Massive management', 'Fail try to add alert', false, false, 'Alert template: '.$id_alert_template.' Modules: '.json_encode($modules_id));
}
ui_print_result_message(
$contsuccess > 0,
__('Successfully added').'('.$contsuccess.'/'.$conttotal.')',
__('Could not be added')
);
}
$id_group = (int) get_parameter('id_group', -1);
$id_agents = get_parameter('id_agents');
$module_names = get_parameter('module');
$id_alert_template = (int) get_parameter('id_alert_template');
$recursion = get_parameter('recursion');
$add = (bool) get_parameter_post('add');
if ($add) {
process_manage_add($id_alert_template, $id_agents, $module_names);
}
$groups = users_get_groups();
$own_info = get_user_info($config['id_user']);
if (!$own_info['is_admin'] && !check_acl($config['id_user'], 0, 'AW')) {
$return_all_group = false;
} else {
$return_all_group = true;
}
$table = new stdClass();
$table->id = 'add_table';
$table->class = 'databox filters';
$table->width = '100%';
$table->data = [];
$table->style = [];
$table->style[0] = 'font-weight: bold; vertical-align:top';
$table->style[2] = 'font-weight: bold; vertical-align:top';
$table->size = [];
$table->size[0] = '15%';
$table->size[1] = '25%';
$table->size[2] = '15%';
$table->size[3] = '30%';
$table->data = [];
$table->data[0][0] = __('Group');
$table->data[0][1] = html_print_select_groups(
false,
'AW',
$return_all_group,
'id_group',
0,
'',
'Select',
-1,
true,
false,
true,
'',
false,
'width:180px;'
);
$table->data[0][2] = __('Group recursion');
$table->data[0][3] = html_print_checkbox('recursion', 1, $recursion, true, false, '', true);
$table->data[1][0] = __('Agents');
$table->data[1][0] .= '';
$table->data[1][0] .= html_print_image('images/spinner.png', true);
$table->data[1][0] .= '';
$agents_alerts = alerts_get_agents_with_alert_template(
$id_alert_template,
$id_group,
false,
[
'tagente.nombre',
'tagente.id_agente',
]
);
$agents = agents_get_group_agents(array_keys(users_get_groups($config['id_user'], 'AW', false)));
$table->data[1][1] = html_print_select(
$agents,
'id_agents[]',
'',
'',
'',
'',
true,
true,
true,
'',
false,
'width:180px;'
);
$table->data[1][2] = __('When select agents');
$table->data[1][2] .= '
';
$table->data[1][2] .= html_print_select(
[
'common' => __('Show common modules'),
'all' => __('Show all modules'),
],
'modules_selection_mode',
'common',
false,
'',
'',
true
);
$table->data[1][3] = html_print_select([], 'module[]', '', false, '', '', true, true, false, '', false, 'width:180px;');
$usr_groups = users_get_groups($config['id_user'], 'LW', true);
$filter_groups = '';
$filter_groups = implode(',', array_keys($usr_groups));
$templates = alerts_get_alert_templates(['id_group IN ('.$filter_groups.')'], ['id', 'name']);
$table->data[2][0] = __('Alert template');
$table->data[2][1] = html_print_select(
index_array($templates, 'id', 'name'),
'id_alert_template',
$id_alert_template,
false,
__('Select'),
0,
true
);
$table->data[2][2] = '';
$table->data[2][3] = '';
echo '