$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;
}
foreach($module_names as $module) {
foreach($id_agents as $id_agent) {
$module_id = modules_get_agentmodule_id($module, $id_agent);
$modules_id[] = $module_id['id_agente_modulo'];
}
}
if(count($module_names) == 1 && $module_names[0] == '0') {
$modules_id = agents_common_modules ($id_agents, false, true);
}
$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->id = 'add_table';
$table->class = 'databox filters';
$table->width = '100%';
$table->data = array ();
$table->style = array ();
$table->style[0] = 'font-weight: bold; vertical-align:top';
$table->style[2] = 'font-weight: bold; vertical-align:top';
$table->size = array ();
$table->size[0] = '15%';
$table->size[1] = '25%';
$table->size[2] = '15%';
$table->size[3] = '30%';
$table->data = array ();
$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, array ('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 (array('common' => __('Show common modules'), 'all' => __('Show all modules')), 'modules_selection_mode',
'common', false, '', '', true);
$table->data[1][3] = html_print_select (array(), 'module[]', '', false, '', '', true, true, false, '', false, 'width:180px;');
$templates = alerts_get_alert_templates (false, array ('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 '