2012-04-03 Sergio Martin <sergio.martin@artica.es>

* include/javascript/pandora.js
	operation/agentes/ver_agente.php
	godmode/massive/massive_delete_modules.php
	godmode/massive/massive_edit_modules.php: Added the same
	extended form of the massive edit modules to massive
	delete modules section. Added to both a new combo to 
	select the behavior of the multi select of agents/modules
	selecting all or common for the result.
	Fixed some bugs



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5891 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2012-04-03 16:33:38 +00:00
parent b5425ae5aa
commit b4539066b3
5 changed files with 391 additions and 84 deletions

View File

@ -1,3 +1,15 @@
2012-04-03 Sergio Martin <sergio.martin@artica.es>
* include/javascript/pandora.js
operation/agentes/ver_agente.php
godmode/massive/massive_delete_modules.php
godmode/massive/massive_edit_modules.php: Added the same
extended form of the massive edit modules to massive
delete modules section. Added to both a new combo to
select the behavior of the multi select of agents/modules
selecting all or common for the result.
Fixed some bugs
2012-04-03 Dario Rodriguez <dario.rodriguez@artica.es>
* operation/agentes/estado_agente.php,

View File

@ -60,8 +60,10 @@ function process_manage_delete ($module_name, $id_agents) {
}
db_process_sql_begin ();
$modules = agents_get_modules ($id_agents, 'id_agente_modulo',
array ('nombre' => $module_name), true);
sprintf('nombre IN ("%s")', implode('","',$module_name)), true);
$success = modules_delete_agent_module ($modules);
if (! $success) {
echo '<h3 class="error">'.__('There was an error deleting the modules, the operation has been cancelled').'</h3>';
@ -78,15 +80,83 @@ function process_manage_delete ($module_name, $id_agents) {
}
}
$id_group = (int) get_parameter ('id_group');
$id_agents = (array) get_parameter ('id_agents');
$module_name = (string) get_parameter ('module_name');
$recursion = get_parameter ('recursion');
$module_type = (int) get_parameter ('module_type');
$idGroupMassive = (int) get_parameter('id_group_massive');
$idAgentMassive = (int) get_parameter('id_agent_massive');
$group_select = get_parameter('groups_select');
$delete = (bool) get_parameter_post ('delete');
$module_name = get_parameter ('module_name');
$agents_select = get_parameter('agents');
$agents_id = get_parameter('id_agents');
$modules_select = get_parameter('module');
$selection_mode = get_parameter('selection_mode', 'modules');
$recursion = get_parameter('recursion');
if ($delete) {
$result = process_manage_delete ($module_name, $id_agents);
if($selection_mode == 'modules') {
$force = get_parameter('force_type', false);
if($agents_select == false) {
$agents_select = array();
$agents_ = array();
}
foreach($agents_select as $agent_name) {
$agents_[] = agents_get_agent_id($agent_name);
}
$modules_ = $module_name;
}
else if($selection_mode == 'agents') {
$force = get_parameter('force_group', false);
$agents_ = $agents_id;
$modules_ = $modules_select;
}
// If the option to select all of one group or module type is checked
if($force) {
if($force == 'type') {
$condition = '';
if($module_type != 0)
$condition = ' AND t2.id_tipo_modulo = '.$module_type;
$agents_ = db_get_all_rows_sql('SELECT DISTINCT(t1.id_agente)
FROM tagente t1, tagente_modulo t2
WHERE t1.id_agente = t2.id_agente');
foreach($agents_ as $id_agent) {
$module_name = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent, 'id_tipo_modulo' => $module_type),'nombre');
if($module_name == false) {
$module_name = array();
}
foreach($module_name as $mod_name) {
$result = process_manage_edit ($mod_name['nombre'], $id_agent['id_agente']);
$count ++;
$success += (int)$result;
}
}
}
else if($force == 'group') {
$agents_ = array_keys (agents_get_group_agents ($group_select, false, "none"));
foreach($agents_ as $id_agent) {
$module_name = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent),'nombre');
if($module_name == false) {
$module_name = array();
}
foreach($module_name as $mod_name) {
$result = process_manage_edit ($mod_name['nombre'], $id_agent);
$count ++;
$success += (int)$result;
}
}
}
// We empty the agents array to skip the standard procedure
$agents_ = array();
}
$result = process_manage_delete ($modules_, $agents_);
if ($result) {
db_pandora_audit("Massive management", "Delete module ", false, false,
'Agent: ' . json_encode($id_agents) . ' Module: ' . $module_name);
@ -99,46 +169,93 @@ if ($delete) {
$groups = users_get_groups ();
$table->id = 'delete_table';
$table->width = '98%';
$table->data = array ();
$table->style = array ();
$table->style[0] = 'font-weight: bold; vertical-align:top';
$table->style[2] = 'font-weight: bold';
$table->size = array ();
$table->size[0] = '15%';
$table->size[1] = '35%';
$table->size[2] = '15%';
$table->size[3] = '35%';
$agents = agents_get_group_agents (array_keys (users_get_groups ()), false, "none");
$module_types = db_get_all_rows_filter ('tagente_modulo,ttipo_modulo',
array ('tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo',
'id_agente' => array_keys ($agents),
'disabled' => 0,
'order' => 'ttipo_modulo.nombre'),
array ('DISTINCT(id_tipo)',
'CONCAT(ttipo_modulo.descripcion," (",ttipo_modulo.nombre,")") AS description'));
$table->data = array ();
if ($module_types === false)
$module_types = array ();
$table->data[0][0] = __('Modules');
$modules = agents_get_modules();
$modulesSelect = array();
foreach ($modules as $module) {
$modulesSelect[$module] = io_safe_output($module);
$types = '';
foreach ($module_types as $type) {
$types[$type['id_tipo']] = $type['description'];
}
$table->data[0][1] = html_print_select($modulesSelect,
'module_name', $module_name, false, __('Select'), '', true);
$table->data[1][0] = __('Group');
$table->data[1][1] = html_print_select_groups(false, "AR", true, 'id_group', $id_group,
false, '', '', true, false, true, '', empty ($module_name));
$table->data[1][2] = __('Group recursion');
$table->data[1][3] = html_print_checkbox ("recursion", 1, $recursion, true, false);
$table->width = '99%';
$table->data = array ();
$table->data[0][0] = __('Selection mode');
$table->data[0][1] = __('Select modules first').' '.html_print_radio_button_extended ("selection_mode", 'modules', '', $selection_mode, false, '', 'style="margin-right: 40px;"', true);
$table->data[0][2] = '';
$table->data[0][3] = __('Select agents first').' '.html_print_radio_button_extended ("selection_mode", 'agents', '', $selection_mode, false, '', 'style="margin-right: 40px;"', true);
$table->data[2][0] = __('Agent');
$table->data[2][0] .= '<span id="agent_loading" class="invisible">';
$table->data[2][0] .= html_print_image('images/spinner.png', true);
$table->data[2][0] .= '</span>';
$agents = modules_get_agents_with_module_name ($module_name, $id_group,
array ('delete_pending' => 0,
'tagente_modulo.disabled' => 0),
array ('tagente.id_agente', 'tagente.nombre'));
$table->data[2][1] = html_print_select (index_array ($agents, 'id_agente', 'nombre'),
'id_agents[]', 0, false, __('None'), 0, true, true, true, '', empty ($module_name));
$table->rowclass[1] = 'select_modules_row';
$table->data[1][0] = __('Module type');
$table->data[1][0] .= '<span id="module_loading" class="invisible">';
$table->data[1][0] .= html_print_image('images/spinner.png', true);
$table->data[1][0] .= '</span>';
$types[0] = __('All');
$table->colspan[1][1] = 2;
$table->data[1][1] = html_print_select ($types,
'module_type', '', false, __('Select'), -1, true, false, true, '', false, 'width:100%');
$table->data[1][3] = __('Select all modules of this type').' '.html_print_checkbox_extended ("force_type", 'type', '', '', false, '', 'style="margin-right: 40px;"', true);
$modules = array ();
if ($module_type != '') {
$filter = array ('id_tipo_modulo' => $module_type);
}
else {
$filter = false;
}
$names = agents_get_modules (array_keys ($agents),
'DISTINCT(nombre)', $filter, false);
foreach ($names as $name) {
$modules[$name['nombre']] = $name['nombre'];
}
$table->rowclass[2] = 'select_agents_row';
$table->data[2][0] = __('Agent group');
$groups = groups_get_all(true);
$groups[0] = __('All');
$table->colspan[2][1] = 2;
$table->data[2][1] = html_print_select ($groups, 'groups_select',
'', true, __('Select'), -1, true, false, true, '', false, 'width:100%').
' '.__('Group recursion').' '.html_print_checkbox ("recursion", 1, false, true, false);
$table->data[2][3] = __('Select all modules of this group').' '.html_print_checkbox_extended ("force_group", 'group', '', '', false, '', 'style="margin-right: 40px;"', true);
$table->rowstyle[3] = 'vertical-align: top;';
$table->rowclass[3] = 'select_modules_row select_modules_row_2';
$table->data[3][0] = __('Modules');
$table->data[3][1] = html_print_select ($modules, 'module_name[]',
$module_name, false, __('Select'), -1, true, true, true, '', false, 'width:100%');
$table->data[3][2] = __('When select modules');
$table->data[3][2] .= '<br>';
$table->data[3][2] .= html_print_select (array('common' => __('Show common agents'), 'all' => __('Show all agents')), 'agents_selection_mode',
'common', false, '', '', true, false, true, '', false);
$table->data[3][3] = html_print_select (array(), 'agents[]',
$agents_select, false, __('None'), 0, true, true, false, '', false, 'width:100%');
$table->rowstyle[4] = 'vertical-align: top;';
$table->rowclass[4] = 'select_agents_row select_agents_row_2';
$table->data[4][0] = __('Agents');
$table->data[4][1] = html_print_select ($agents, 'id_agents[]',
$agents_id, false, '', '', true, true, false, '', false, 'width:100%');
$table->data[4][2] = __('When select agents');
$table->data[4][2] .= '<br>';
$table->data[4][2] .= html_print_select (array('common' => __('Show common modules'), 'all' => __('Show all modules')), 'modules_selection_mode',
'common', false, '', '', true);
$table->data[4][3] = html_print_select (array(), 'module[]',
$modules_select, false, '', '', true, true, false, '', false, 'width:100%');
echo '<form method="post" id="form_modules" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=delete_modules" >';
html_print_table ($table);
@ -153,51 +270,171 @@ echo '<h3 class="error invisible" id="message"> </h3>';
ui_require_jquery_file ('form');
ui_require_jquery_file ('pandora.controls');
if($selection_mode == 'modules'){
$modules_row = '';
$agents_row = 'none';
}
else {
$modules_row = 'none';
$agents_row = '';
}
?>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready (function () {
$("#module_name").change (function () {
if (this.value != "") {
$("#id_agents").enable ();
$("#id_group").enable ().change ();
} else {
$("#id_group, #id_agents").disable ();
}
});
$("#id_agents").change(agent_changed_by_multiple_agents);
$("#module_name").change(module_changed_by_multiple_modules);
clean_lists();
$("#checkbox-recursion").click(function () {
if ($("#module_name").attr ("value") != "") {
$("#id_group").trigger("change");
}
$(".select_modules_row").css('display', '<?php echo $modules_row?>');
$(".select_agents_row").css('display', '<?php echo $agents_row?>');
// Trigger change to refresh selection when change selection mode
$("#agents_selection_mode").change (function() {
$("#module_name").trigger('change');
});
$("#modules_selection_mode").change (function() {
$("#id_agents").trigger('change');
});
$("#id_group").change (function () {
var $select = $("#id_agents").disable ();
$("#agent_loading").show ();
$("option", $select).remove ();
$("#module_type").change (function () {
$('#checkbox-force_type').attr('checked', false);
if (this.value < 0) {
clean_lists();
$(".select_modules_row_2").css('display', 'none');
return;
}
else {
$("#module").html('<?php echo __('None'); ?>');
$("#module_name").html('');
$('input[type=checkbox]').removeAttr('disabled');
$(".select_modules_row_2").css('display', '');
}
$("tr#delete_table-edit1, tr#delete_table-edit2, tr#delete_table-edit3, tr#delete_table-edit35, tr#delete_table-edit4, tr#delete_table-edit5, tr#delete_table-edit6, tr#delete_table-edit7, tr#delete_table-edit8").hide ();
if (this.value == '0') {
filter = '';
}
else {
filter = "id_tipo_modulo="+this.value;
}
$("#module_loading").show ();
$("tr#delete_table-edit1, tr#delete_table-edit2").hide ();
$("#module_name").attr ("disabled", "disabled")
$("#module_name option[value!=0]").remove ();
jQuery.post ("ajax.php",
{"page" : "godmode/massive/massive_delete_modules",
"get_agents" : 1,
"id_group" : this.value,
"module_name" : $("#module_name").attr ("value"),
"recursion" : $("#checkbox-recursion").attr ("checked") ? 1 : 0
{"page" : "operation/agentes/ver_agente",
"get_agent_modules_json" : 1,
"filter" : filter,
"fields" : "DISTINCT(nombre)",
"indexed" : 0
},
function (data, status) {
options = "";
jQuery.each (data, function (id, value) {
options += "<option value=\""+id+"\">"+value+"</option>";
option = $("<option></option>").attr ("value", value["nombre"]).html (value["nombre"]);
$("#module_name").append (option);
});
$("#id_agents").append (options);
$("#agent_loading").hide ();
$select.enable ();
$("#module_loading").hide ();
$("#module_name").removeAttr ("disabled");
},
"json"
);
});
function clean_lists() {
$("#id_agents").html('<?php echo __('None'); ?>');
$("#module_name").html('<?php echo __('None'); ?>');
$("#agents").html('<?php echo __('None'); ?>');
$("#module").html('<?php echo __('None'); ?>');
$('input[type=checkbox]').attr('checked', false);
$('input[type=checkbox]').attr('disabled', true);
$('#module_type').val(-1);
$('#groups_select').val(-1);
}
$('input[type=checkbox]').change (
function () {
if(this.id == "checkbox-force_type"){
if(this.checked) {
$(".select_modules_row_2").css('display', 'none');
$("tr#delete_table-edit1, tr#delete_table-edit2, tr#delete_table-edit3, tr#delete_table-edit35, tr#delete_table-edit4, tr#delete_table-edit5, tr#delete_table-edit6, tr#delete_table-edit7, tr#delete_table-edit8").show ();
}
else {
$(".select_modules_row_2").css('display', '');
if($('#module_name option:selected').val() == undefined) {
$("tr#delete_table-edit1, tr#delete_table-edit2, tr#delete_table-edit3, tr#delete_table-edit35, tr#delete_table-edit4, tr#delete_table-edit5, tr#delete_table-edit6, tr#delete_table-edit7, tr#delete_table-edit8").hide ();
}
}
}
else if(this.id == "checkbox-recursion"){
$("#groups_select").trigger("change");
}
else {
if(this.checked) {
$(".select_agents_row_2").css('display', 'none');
}
else {
$(".select_agents_row_2").css('display', '');
}
}
}
);
$("#form_modules input[name=selection_mode]").change (function () {
console.log(this.value);
selector = this.value;
clean_lists();
if(selector == 'agents') {
$(".select_modules_row").css('display', 'none');
$(".select_agents_row").css('display', '');
}
else if(selector == 'modules') {
$(".select_agents_row").css('display', 'none');
$(".select_modules_row").css('display', '');
}
});
$("#groups_select").change (
function () {
$('#checkbox-force_group').attr('checked', false);
if (this.value < 0) {
clean_lists();
$(".select_agents_row_2").css('display', 'none');
return;
}
else {
$("#module").html('<?php echo __('None'); ?>');
$("#id_agents").html('');
$('input[type=checkbox]').removeAttr('disabled');
$(".select_agents_row_2").css('display', '');
}
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
"get_agents_group_json" : 1,
"recursion" : $("#checkbox-recursion").attr ("checked") ? 1 : 0,
"id_group" : this.value
},
function (data, status) {
$("#id_agents").html('');
jQuery.each (data, function (id, value) {
option = $("<option></option>").attr ("value", value["id_agente"]).html (value["nombre"]);
$("#id_agents").append (option);
});
},
"json"
);
}
);
});
/* ]]> */
</script>

View File

@ -239,6 +239,7 @@ $snmp_versions['2'] = 'v. 2';
$snmp_versions['2c'] = 'v. 2c';
$snmp_versions['3'] = 'v. 3';
$table->width = '99%';
$table->data = array ();
$table->data[0][0] = __('Selection mode');
@ -288,7 +289,10 @@ $table->data[3][0] = __('Modules');
$table->data[3][1] = html_print_select ($modules, 'module_name[]',
$module_name, false, __('Select'), -1, true, true, true);
$table->data[3][2] = __('Agents');
$table->data[3][2] = __('When select modules');
$table->data[3][2] .= '<br>';
$table->data[3][2] .= html_print_select (array('common' => __('Show common agents'), 'all' => __('Show all agents')), 'agents_selection_mode',
'common', false, '', '', true);
$table->data[3][3] = html_print_select (array(), 'agents[]',
$agents_select, false, __('None'), 0, true, true, false);
@ -298,7 +302,10 @@ $table->data[4][0] = __('Agents');
$table->data[4][1] = html_print_select ($agents, 'id_agents[]',
$agents_id, false, '', '', true, true, false);
$table->data[4][2] = __('Modules');
$table->data[4][2] = __('When select agents');
$table->data[4][2] .= '<br>';
$table->data[4][2] .= html_print_select (array('common' => __('Show common modules'), 'all' => __('Show all modules')), 'modules_selection_mode',
'common', false, '', '', true);
$table->data[4][3] = html_print_select (array(), 'module[]',
$modules_select, false, '', '', true, true, false);
@ -402,7 +409,16 @@ $(document).ready (function () {
$(".select_modules_row").css('display', '<?php echo $modules_row?>');
$(".select_agents_row").css('display', '<?php echo $agents_row?>');
// Trigger change to refresh selection when change selection mode
$("#agents_selection_mode").change (function() {
$("#module_name").trigger('change');
});
$("#modules_selection_mode").change (function() {
$("#id_agents").trigger('change');
});
$("#module_type").change (function () {
$('input[type=checkbox]').attr('checked', false);
if (this.value < 0) {
clean_lists();
$(".select_modules_row_2").css('display', 'none');
@ -447,7 +463,7 @@ $(document).ready (function () {
);
});
function show_form() {
$("td#delete_table-0-1, td#delete_table-edit1-1, td#delete_table-edit2-1").css ("width", "35%");
$("td#delete_table-0-1, td#delete_table-edit1-1, td#delete_table-edit2-1").css ("width", "100%");
$("#form_edit input[type=text]").attr ("value", "");
$("#form_edit input[type=checkbox]").not ("#checkbox-recursion").removeAttr ("checked");
$("tr#delete_table-edit1, tr#delete_table-edit2, tr#delete_table-edit3, tr#delete_table-edit35, tr#delete_table-edit4, tr#delete_table-edit5, tr#delete_table-edit6, tr#delete_table-edit7, tr#delete_table-edit8").show ();
@ -516,6 +532,7 @@ $(document).ready (function () {
$("#groups_select").change (
function () {
$('input[type=checkbox]').attr('checked', false);
if (this.value < 0) {
clean_lists();
$(".select_agents_row_2").css('display', 'none');

View File

@ -156,6 +156,11 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
}
}
var selection_mode = $('#modules_selection_mode').val();
if(selection_mode == undefined) {
selection_mode = 'common';
}
$('#module').attr ('disabled', 1);
$('#module').empty ();
$('#module').append ($('<option></option>').html ("Loading...").attr ("value", 0));
@ -164,7 +169,8 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
"get_agent_modules_json_for_multiple_agents": 1,
"id_agent[]": idAgents,
"all": find_modules,
"custom_condition": custom_condition
"custom_condition": custom_condition,
"selection_mode": selection_mode
},
function (data) {
$('#module').empty ();
@ -291,16 +297,35 @@ function module_changed_by_multiple_modules (event, id_module, selected) {
$('#agents').attr ('disabled', 1);
$('#agents').empty ();
$('#agents').append ($('<option></option>').html ("Loading...").attr ("value", 0));
var selection_mode = $('#agents_selection_mode').val();
if(selection_mode == undefined) {
selection_mode = 'common';
}
jQuery.post ('ajax.php',
{"page": "operation/agentes/ver_agente",
"get_agents_json_for_multiple_modules": 1,
"module_name[]": idModules
"module_name[]": idModules,
"selection_mode": selection_mode
},
function (data) {
$('#agents').append ($('<option></option>').html ("Loading...").attr ("value", 0));
$('#agents').empty ();
if (isEmptyObject(data)) {
var noneText = $("#none_text").html(); //Trick for catch the translate text.
if (noneText == null) {
noneText = 'None';
}
$('#agents').append ($('<option></option>').html (noneText).attr ("None", "").attr('selected', true));
return;
}
if (typeof($(document).data('text_for_module')) != 'undefined') {
$('#agents').append ($('<option></option>').html ($(document).data('text_for_module')).attr("value", 0).attr('selected', true));
}

View File

@ -87,16 +87,24 @@ if (is_ajax ()) {
if ($get_agents_json_for_multiple_modules) {
$nameModules = get_parameter('module_name');
$selection_mode = get_parameter('selection_mode','common');
$nameAgents = db_get_all_rows_sql('SELECT DISTINCT(t1.nombre) as name
$sql = 'SELECT DISTINCT(t1.nombre) as name
FROM tagente t1, tagente_modulo t2
WHERE t1.id_agente = t2.id_agente
AND t2.nombre IN (\'' . implode('\',\'', $nameModules) . '\')
AND (
AND t2.nombre IN (\'' . implode('\',\'', $nameModules) . '\')';
if($selection_mode == 'common') {
$sql .= 'AND (
SELECT count(t3.nombre)
FROM tagente t3, tagente_modulo t4
WHERE t3.id_agente = t4.id_agente AND t1.nombre = t3.nombre
AND t4.nombre IN (\'' . implode('\',\'', $nameModules) . '\')) = '.count($nameModules));
AND t4.nombre IN (\'' . implode('\',\'', $nameModules) . '\')) = '.count($nameModules);
}
$sql .= ' ORDER BY t1.nombre';
$nameAgents = db_get_all_rows_sql($sql);
foreach($nameAgents as $nameAgent) {
$names[] = $nameAgent['name'];
@ -139,6 +147,8 @@ if (is_ajax ()) {
if ($get_agent_modules_json_for_multiple_agents) {
$idAgents = get_parameter('id_agent');
$custom_condition = get_parameter('custom_condition', '');
$selection_mode = get_parameter('selection_mode', 'common');
$all = (string)get_parameter('all', 'all');
switch ($all) {
default:
@ -194,18 +204,24 @@ if (is_ajax ()) {
}
}
else {
$nameModules = db_get_all_rows_sql('SELECT DISTINCT(nombre)
$sql = 'SELECT DISTINCT(nombre)
FROM tagente_modulo t1
WHERE ' . $enabled .
io_safe_output($custom_condition) . '
AND delete_pending = 0
AND id_agente IN (' . implode(',', $idAgents) . ') AND (
SELECT count(nombre)
FROM tagente_modulo t2
WHERE delete_pending = 0 AND t1.nombre = t2.nombre
AND id_agente IN (' . implode(',', $idAgents) . ')) = (' . count($idAgents) . ')
ORDER BY nombre');
AND id_agente IN (' . implode(',', $idAgents) . ')';
if($selection_mode == 'common') {
$sql .= ' AND (
SELECT count(nombre)
FROM tagente_modulo t2
WHERE delete_pending = 0 AND t1.nombre = t2.nombre
AND id_agente IN (' . implode(',', $idAgents) . ')) = (' . count($idAgents) . ')';
}
$sql .= ' ORDER BY nombre';
$nameModules = db_get_all_rows_sql($sql);
if ($nameModules == false) {
$nameModules = array();