1';
} else {
unset($filter['tagente_modulo.disabled']);
}
$agents_alerts = [];
foreach ($groups as $group) {
$agents_alerts_one_group = alerts_get_agents_with_alert_template(
$id_alert_template,
$group,
$filter,
[
'tagente.alias',
'tagente.id_agente',
]
);
if (is_array($agents_alerts_one_group)) {
$agents_alerts = array_merge($agents_alerts, $agents_alerts_one_group);
}
}
$agents = index_array($agents_alerts, 'id_agente', 'alias');
asort($agents);
// Add keys prefix
if ($keys_prefix !== '') {
foreach ($agents as $k => $v) {
$agents[$keys_prefix.$k] = $v;
unset($agents[$k]);
}
}
echo json_encode($agents);
return;
}
return;
}
function process_manage_delete($id_alert_template, $id_agents, $module_names)
{
if (empty($id_alert_template)) {
ui_print_error_message(__('No alert selected'));
return false;
}
if (empty($id_agents) || $id_agents[0] == 0) {
ui_print_error_message(__('No agents selected'));
return false;
}
$module_selection_mode = get_parameter('modules_selection_mode');
$alert_list = db_get_all_rows_filter('talert_template_modules', ['id_alert_template' => $id_alert_template], 'id_agent_module');
foreach ($module_names as $module) {
foreach ($id_agents as $id_agent) {
$module_id = modules_get_agentmodule_id($module, $id_agent);
// The module can exist in several of the selected agents, but we have to check if it has an alert.
foreach ($alert_list as $alert) {
if ($alert['id_agent_module'] == $module_id['id_agente_modulo']) {
$modules_id[] = $module_id['id_agente_modulo'];
}
}
}
}
// If is selected "ANY" option then we need the module selection
// mode: common or all modules
if (count($module_names) == 1 && $module_names[0] == '0') {
if ($module_selection_mode == 'common') {
$sql = 'SELECT t1.id_agente_modulo
FROM tagente_modulo t1
WHERE t1.id_agente_modulo IN (
SELECT t2.id_agent_module
FROM talert_template_modules t2
WHERE
t2.id_alert_template = '.$id_alert_template.')
AND t1.id_agente IN ('.implode(',', $id_agents).');';
$modules = db_get_all_rows_sql($sql);
if (empty($modules)) {
$modules = [];
}
$modules_id = [];
foreach ($modules as $module) {
$modules_id[$module['id_agente_modulo']] = $module['id_agente_modulo'];
}
} else {
// For agents selected
$modules_id = [];
foreach ($id_agents as $id_agent) {
$current_modules_agent = agents_get_modules($id_agent, 'id_agente_modulo', ['disabled' => 0]);
if ($current_modules_agent != false) {
// And their modules
foreach ($current_modules_agent as $current_module) {
$module_alerts = alerts_get_alerts_agent_module($current_module);
if ($module_alerts != false) {
// And for all alert in modules
foreach ($module_alerts as $module_alert) {
// Find the template in module
if ($module_alert['id_alert_template'] == $id_alert_template) {
$modules_id[] = $module_alert['id_agent_module'];
}
}
}
}
}
}
}
}
$conttotal = 0;
$contsuccess = 0;
foreach ($modules_id as $module) {
$success = alerts_delete_alert_agent_module(
false,
[
'id_agent_module' => $module,
'id_alert_template' => $id_alert_template,
]
);
if ($success) {
$contsuccess++;
}
$conttotal++;
}
ui_print_result_message(
$contsuccess > 0,
__('Successfully deleted').'('.$contsuccess.'/'.$conttotal.')',
__('Could not be deleted')
);
return (bool) ($contsuccess > 0);
}
$id_group = (int) get_parameter('id_group');
$id_agents = get_parameter('id_agents');
$module_names = get_parameter('module');
$id_alert_template = (int) get_parameter('id_alert_template');
$delete = (bool) get_parameter_post('delete');
if ($delete) {
$result = process_manage_delete($id_alert_template, $id_agents, $module_names);
$info = [
'Agent' => implode(',', $id_agents),
'Template' => $id_alert_template,
'Module' => implode(',', $module_names),
];
if ($result) {
db_pandora_audit(
AUDIT_LOG_MASSIVE_MANAGEMENT,
'Delete alert ',
false,
false,
json_encode($info)
);
} else {
db_pandora_audit(
AUDIT_LOG_MASSIVE_MANAGEMENT,
'Fail try to delete alert',
false,
false,
json_encode($info)
);
}
}
$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->id = 'delete_table';
$table->class = 'databox filters';
$table->width = '100%';
$table->data = [];
$table->style = [];
$table->style[0] = 'font-weight: bold;';
$table->style[2] = 'font-weight: bold;';
$table->size = [];
$table->size[0] = '15%';
$table->size[1] = '35%';
$table->size[2] = '15%';
$table->size[3] = '35%';
$table->data = [];
$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[0][0] = __('Alert template');
$table->data[0][1] = html_print_select(
index_array($templates, 'id', 'name'),
'id_alert_template',
$id_alert_template,
false,
__('Select'),
0,
true,
false,
true,
'',
false,
'width: 100%;'
);
$table->data[0][2] = '';
$table->data[0][3] = '';
$table->data[1][0] = __('Group');
$table->data[1][1] = html_print_select_groups(
false,
'AW',
$return_all_group,
'id_group',
$id_group,
'',
'',
'',
true,
false,
true,
'',
$id_alert_template == 0,
'width: 100%;'
);
$table->data[0][2] = __('Show alerts on disabled modules');
$table->data[0][3] = html_print_checkbox('disabled_modules', 1, false, true, false);
$table->data[1][2] = __('Group recursion');
$table->data[1][3] = html_print_checkbox('recursion', 1, false, true, false);
$table->data[2][0] = __('Agents');
$table->data[2][0] .= '';
$table->data[2][0] .= html_print_image('images/spinner.png', true);
$table->data[2][0] .= '';
$agents_alerts = alerts_get_agents_with_alert_template(
$id_alert_template,
$id_group,
false,
[
'tagente.alias',
'tagente.id_agente',
]
);
$table->data[2][1] = html_print_select(
index_array($agents_alerts, 'id_agente', 'alias'),
'id_agents[]',
'',
'',
'',
'',
true,
true,
true,
'',
$id_alert_template == 0
);
$table->data[2][2] = __('When select agents');
$table->data[2][2] .= '
';
$table->data[2][2] .= html_print_select(
[
'common' => __('Show common modules'),
'all' => __('Show all modules'),
],
'modules_selection_mode',
'common',
false,
'',
'',
true
);
$table->data[2][3] = html_print_select([], 'module[]', '', false, '', '', true, true, false);
echo '