2012-12-10 Sergio Martin <sergio.martin@artica.es>

* include/javascript/pandora_modules.js
	godmode/agentes/module_manager_editor_common.php
	godmode/modules/manage_network_components_form.php
	godmode/modules/manage_network_components_form_common.php
	godmode/modules/manage_network_components.php: Added tags support
	to the network components



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7248 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2012-12-10 18:04:27 +00:00
parent b60a8143d6
commit c94f05b2e4
6 changed files with 188 additions and 14 deletions

View File

@ -1,3 +1,12 @@
2012-12-10 Sergio Martin <sergio.martin@artica.es>
* include/javascript/pandora_modules.js
godmode/agentes/module_manager_editor_common.php
godmode/modules/manage_network_components_form.php
godmode/modules/manage_network_components_form_common.php
godmode/modules/manage_network_components.php: Added tags support
to the network components
2012-12-10 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* pandoradb_data.sql

View File

@ -401,6 +401,10 @@ $(document).ready (function () {
id_tag = $(value).attr('value');
$("select[name='id_tag_selected[]']").append($("<option></option>").val(id_tag).html('<i>' + tag_name + '</i>'));
$("#id_tag_available").find("option[value='" + id_tag + "']").remove();
$("#id_tag_selected").find("option[value='']").remove();
if($("#id_tag_available option").length == 0) {
$("select[name='id_tag_available[]']").append($("<option></option>").val('').html('<i><?php echo __('None'); ?></i>'));
}
}
});
});
@ -411,6 +415,10 @@ $(document).ready (function () {
id_tag = $(value).attr('value');
$("select[name='id_tag_available[]']").append($("<option>").val(id_tag).html('<i>' + tag_name + '</i>'));
$("#id_tag_selected").find("option[value='" + id_tag + "']").remove();
$("#id_tag_available").find("option[value='']").remove();
if($("#id_tag_selected option").length == 0) {
$("select[name='id_tag_selected[]']").append($("<option></option>").val('').html('<i><?php echo __('None'); ?></i>'));
}
}
});
});

View File

@ -76,13 +76,21 @@ $post_process = (float) get_parameter('post_process');
$unit = (string) get_parameter('unit');
$id = (int) get_parameter ('id');
$wizard_level = get_parameter ('wizard_level');
$only_metaconsole = get_parameter ('only_metaconsole');
$only_metaconsole = (int) get_parameter ('only_metaconsole');
$critical_instructions = (string) get_parameter('critical_instructions');
$warning_instructions = (string) get_parameter('warning_instructions');
$unknown_instructions = (string) get_parameter('unknown_instructions');
$critical_inverse = (int) get_parameter('critical_inverse');
$warning_inverse = (int) get_parameter('warning_inverse');
$id_category = (int) get_parameter('id_category');
$id_tag_selected = (array) get_parameter('id_tag_selected');
if(count($id_tag_selected) == 1 && empty($id_tag_selected[0])) {
$tags = '';
}
else {
$tags = implode(',',$id_tag_selected);
}
$snmp_version = (string) get_parameter('snmp_version');
$snmp3_auth_user = (string) get_parameter('snmp3_auth_user');
@ -134,6 +142,8 @@ if ($create_component) {
$custom_string_3 = $snmp3_security_level;
$name_check = db_get_value ('name', 'tnetwork_component', 'name', $name);
}
if ($name && !$name_check) {
$id = network_components_create_network_component ($name, $type, $id_group,
@ -176,18 +186,20 @@ if ($create_component) {
'unknown_instructions' => $unknown_instructions,
'critical_inverse' => $critical_inverse,
'warning_inverse' => $warning_inverse,
'id_category' => $id_category));
'id_category' => $id_category,
'tags' => $tags));
}
else {
$id = '';
}
if ($id === false || !$id) {
db_pandora_audit("Module management", "Fail try to create network component");
ui_print_error_message (__('Could not be created'));
include_once ('godmode/modules/manage_network_components_form.php');
return;
}
db_pandora_audit("Module management", "Create network component group #$id");
db_pandora_audit("Module management", "Create network component #$id");
ui_print_success_message (__('Created successfully'));
$id = 0;
}
@ -255,7 +267,8 @@ if ($update_component) {
'unknown_instructions' => $unknown_instructions,
'critical_inverse' => $critical_inverse,
'warning_inverse' => $warning_inverse,
'id_category' => $id_category));
'id_category' => $id_category,
'tags' => $tags));
}
else {
$result = '';
@ -372,7 +385,8 @@ $url = ui_get_url_refresh (array ('offset' => false,
'unknown_instructions' => false,
'critical_inverse' => false,
'warning_inverse' => false,
'id_category' => false));
'id_category' => false,
'tags' => false));
$search_id_group = (int) get_parameter ('search_id_group');

View File

@ -116,6 +116,7 @@ if (isset ($id)) {
$critical_inverse = $component["critical_inverse"];
$warning_inverse = $component["warning_inverse"];
$id_category = $component["id_category"];
$tags = $component["tags"];
if ($type >= 15 && $type <= 18) {
// New support for snmp v3
@ -163,6 +164,7 @@ if (isset ($id)) {
$critical_inverse = 0;
$warning_inverse = 0;
$id_category = 0;
$tags = '';
$snmp_version = 1;
$snmp3_auth_user = '';
@ -382,6 +384,44 @@ function type_change () {
}
$(document).ready (function () {
$("#right").click (function () {
jQuery.each($("select[name='id_tag_available[]'] option:selected"), function (key, value) {
tag_name = $(value).html();
if (tag_name != <?php echo "'".__('None')."'"; ?>) {
id_tag = $(value).attr('value');
$("select[name='id_tag_selected[]']").append($("<option></option>").val(id_tag).html('<i>' + tag_name + '</i>'));
$("#id_tag_available").find("option[value='" + id_tag + "']").remove();
$("#id_tag_selected").find("option[value='']").remove();
if($("#id_tag_available option").length == 0) {
$("select[name='id_tag_available[]']").append($("<option></option>").val('').html('<i><?php echo __('None'); ?></i>'));
}
}
});
});
$("#left").click (function () {
jQuery.each($("select[name='id_tag_selected[]'] option:selected"), function (key, value) {
tag_name = $(value).html();
if (tag_name != <?php echo "'".__('None')."'"; ?>) {
id_tag = $(value).attr('value');
$("select[name='id_tag_available[]']").append($("<option>").val(id_tag).html('<i>' + tag_name + '</i>'));
$("#id_tag_selected").find("option[value='" + id_tag + "']").remove();
$("#id_tag_available").find("option[value='']").remove();
if($("#id_tag_selected option").length == 0) {
$("select[name='id_tag_selected[]']").append($("<option></option>").val('').html('<i><?php echo __('None'); ?></i>'));
}
}
});
});
$("#submit-crt").click(function () {
$('#id_tag_selected option').map(function(){
$(this).attr('selected','selected');
});
});
$("#submit-upd").click(function () {
$('#id_tag_selected option').map(function(){
$(this).attr('selected','selected');
});
});
if ($("#snmp_version").value == "3"){
$("input[name=snmp3_auth_user]").css({backgroundColor: '#fff'});
$("input[name=snmp3_auth_user]").removeAttr('disabled');

View File

@ -125,24 +125,59 @@ $table->data[6][2] = $table->data[6][3] = '';
$table->data[7][0] = __('Critical instructions'). ui_print_help_tip(__("Instructions when the status is critical"), true);
$table->data[7][1] = html_print_textarea ('critical_instructions', 2, 65, $critical_instructions, '', true);
$table->data[7][2] = $table->data[7][3] = '';
$table->colspan[7][1] = 3;
$table->data[8][0] = __('Warning instructions'). ui_print_help_tip(__("Instructions when the status is warning"), true);
$table->data[8][1] = html_print_textarea ('warning_instructions', 2, 65, $warning_instructions, '', true);
$table->data[8][2] = $table->data[8][3] = '';
$table->colspan[8][1] = 3;
$table->data[9][0] = __('Unknown instructions'). ui_print_help_tip(__("Instructions when the status is unknown"), true);
$table->data[9][1] = html_print_textarea ('unknown_instructions', 2, 65, $unknown_instructions, '', true);
$table->data[9][2] = $table->data[9][3] = '';
$table->colspan[9][1] = 3;
$next_row = 10;
if (check_acl ($config['id_user'], 0, "PM")) {
$table->data[10][0] = __('Category');
$table->data[10][1] = html_print_select(categories_get_all_categories('forselect'), 'id_category', $id_category, '', __('None'), 0, true);
$table->data[10][2] = $table->data[9][3] = '';
$table->data[$next_row][0] = __('Category');
$table->data[$next_row][1] = html_print_select(categories_get_all_categories('forselect'), 'id_category', $id_category, '', __('None'), 0, true);
$table->data[$next_row][2] = $table->data[$next_row][3] = $table->data[$next_row][4] = '';
$next_row++;
}
else {
// Store in a hidden field if is not visible to avoid delete the value
$table->data[9][2] .= html_print_input_hidden ('id_category', $id_category, true);
$table->data[9][1] .= html_print_input_hidden ('id_category', $id_category, true);
}
$table->data[$next_row][0] = __('Tags');
if($tags == '') {
$tags_condition_not = '1 = 1';
$tags_condition_in = '1 = 0';
}
else {
$tags = str_replace(",", "','", $tags);
$tags_condition_not = "name NOT IN ('".$tags."')";
$tags_condition_in = "name IN ('".$tags."')";
}
$table->data[$next_row][1] = '<b>' . __('Tags available') . '</b><br>';
$table->data[$next_row][1] .= html_print_select_from_sql (
"SELECT name, name
FROM ttag
WHERE $tags_condition_not
ORDER BY name", 'id_tag_available[]', '', '','','',
true, true, false, false, 'width: 200px', '5');
$table->data[$next_row][2] = html_print_image('images/darrowright.png', true, array('id' => 'right', 'title' => __('Add tags to module'))); //html_print_input_image ('add', 'images/darrowright.png', 1, '', true, array ('title' => __('Add tags to module')));
$table->data[$next_row][2] .= '<br><br><br><br>' . html_print_image('images/darrowleft.png', true, array('id' => 'left', 'title' => __('Delete tags to module'))); //html_print_input_image ('add', 'images/darrowleft.png', 1, '', true, array ('title' => __('Delete tags to module')));
$table->data[$next_row][3] = '<b>' . __('Tags selected') . '</b><br>';
$table->data[$next_row][3] .= html_print_select_from_sql (
"SELECT name, name
FROM ttag
WHERE $tags_condition_in
ORDER BY name",
'id_tag_selected[]', '', '','','', true, true, false,
false, 'width: 200px', '5');
$next_row++;
?>

View File

@ -139,13 +139,46 @@ function configure_modules_form () {
$("#id_module_type").change ();
if($("#id_category").is("select")) {
$("#id_category option[value="+data["id_category"]+"]").select (1);
console.log('select');
}
else {
$("#hidden-id_category").val(data["id_category"]);
console.log('hidden');
}
var tags = data["tags"];
// Reset the selection of tags (put all of them into available box)
$("#id_tag_selected option").each(function(){
if($(this).attr('value') != '') {
$("#id_tag_selected").find("option[value='" + $(this).attr('value') + "']").remove();
$("select[name='id_tag_available[]']").append($("<option></option>").val($(this).attr('value')).html($(this).text()));
}
});
if($("#id_tag_available option").length > 1) {
$("#id_tag_available").find("option[value='']").remove();
}
if($("#id_tag_selected option").length == 0) {
$("select[name='id_tag_selected[]']").append($("<option></option>").val('').html('<i>None</i>'));
}
if(tags != '') {
tags = tags.split(',');
// Fill the selected tags box with select ones
for(i=0; i<tags.length; i++){
$("#id_tag_available option").each(function(){
if(tags[i] == $(this).text()) {
$("#id_tag_available").find("option[value='" + $(this).attr('value') + "']").remove();
$("select[name='id_tag_selected[]']").append($("<option></option>").val($(this).attr('value')).html($(this).text()));
$("#id_tag_selected").find("option[value='']").remove();
}
});
if($("#id_tag_available option").length == 0) {
$("select[name='id_tag_available[]']").append($("<option></option>").val('').html('<i>None</i>'));
}
}
}
// Delete macro fields
$('.macro_field').remove();
@ -273,6 +306,41 @@ function configure_modules_form () {
else {
$("#hidden-id_category").val(data["id_category"]);
}
var tags = data["tags"];
// Reset the selection of tags (put all of them into available box)
$("#id_tag_selected option").each(function(){
if($(this).attr('value') != '') {
$("#id_tag_selected").find("option[value='" + $(this).attr('value') + "']").remove();
$("select[name='id_tag_available[]']").append($("<option></option>").val($(this).attr('value')).html($(this).text()));
}
});
if($("#id_tag_available option").length > 1) {
$("#id_tag_available").find("option[value='']").remove();
}
if($("#id_tag_selected option").length == 0) {
$("select[name='id_tag_selected[]']").append($("<option></option>").val('').html('<i>None</i>'));
}
if(tags != '') {
tags = tags.split(',');
// Fill the selected tags box with select ones
for(i=0; i<tags.length; i++){
$("#id_tag_available option").each(function(){
if(tags[i] == $(this).text()) {
$("#id_tag_available").find("option[value='" + $(this).attr('value') + "']").remove();
$("select[name='id_tag_selected[]']").append($("<option></option>").val($(this).attr('value')).html($(this).text()));
$("#id_tag_selected").find("option[value='']").remove();
}
});
if($("#id_tag_available option").length == 0) {
$("select[name='id_tag_available[]']").append($("<option></option>").val('').html('<i>None</i>'));
}
}
}
// Delete macro fields
$('.macro_field').remove();