multiple fixes

This commit is contained in:
fbsanchez 2019-06-13 19:41:21 +02:00
parent 0df48675f3
commit b08e8b595d
6 changed files with 330 additions and 47 deletions

View File

@ -173,7 +173,13 @@ function events_get_column_names($fields)
$names = [];
foreach ($fields as $f) {
if (is_array($f)) {
$names[] = events_get_column_name($f['text']);
$name = [];
$name['text'] = events_get_column_name($f['text']);
$name['class'] = $f['class'];
$name['style'] = $f['style'];
$name['extra'] = $f['extra'];
$name['id'] = $f['id'];
$names[] = $name;
} else {
$names[] = events_get_column_name($f);
}
@ -251,7 +257,6 @@ function events_delete($id_evento, $filter=null, $history=false)
break;
}
error_log($delete_sql);
return db_process_sql($delete_sql);
}
@ -2511,6 +2516,7 @@ function events_page_responses($event, $childrens_ids=[])
//
// Responses.
//
$table_responses = new StdObject();
$table_responses->cellspacing = 2;
$table_responses->cellpadding = 2;
$table_responses->id = 'responses_table';
@ -3820,7 +3826,11 @@ function events_page_general($event)
$table_general->data[] = $data;
$table_data = $table_general->data;
$table_data_total = count($table_data);
if (is_array($table_data)) {
$table_data_total = count($table_data);
} else {
$table_data_total = -1;
}
for ($i = 0; $i <= $table_data_total; $i++) {
if (count($table_data[$i]) == 2) {

View File

@ -3061,6 +3061,7 @@ function ui_print_datatable(array $parameters)
if (is_array($column)) {
$table .= '<th id="'.$column['id'].'" class="'.$column['class'].'" ';
$table .= ' style="'.$column['style'].'">'.__($column['text']);
$table .= $column['extra'];
$table .= '</th>';
} else {
$table .= '<th>'.__($column).'</th>';

View File

@ -1,4 +1,4 @@
/*global jQuery,$,forced_title_callback,Base64*/
/*global jQuery,$,forced_title_callback,Base64, dt_event*/
// Show the modal window of an event
function show_event_dialog(event_id, group_rep, dialog_page, result) {
@ -725,3 +725,136 @@ function delete_event(table, id_evento, row) {
row.firstChild.src = "http://localhost/pandora_console/images/spinner.gif";
return update_event(table, id_evento, { delete_event: 1 }, row);
}
// Imported from old files.
function execute_event_response(event_list_btn) {
$("#max_custom_event_resp_msg").hide();
$("#max_custom_selected").hide();
var response_id = $("select[name=response_id]").val();
if (!isNaN(response_id)) {
// It is a custom response
var response = get_response(response_id);
// If cannot get response abort it
if (response == null) {
return;
}
var total_checked = $(".chk_val:checked").length;
// Check select an event.
if (total_checked == 0) {
$("#max_custom_selected").show();
return;
}
// Limit number of events to apply custom responses
// to for performance reasons.
if (total_checked > $("#max_execution_event_response").val()) {
$("#max_custom_event_resp_msg").show();
return;
}
var response_command = [];
$(".response_command_input").each(function() {
response_command[$(this).attr("name")] = $(this).val();
});
if (event_list_btn) {
$("#button-submit_event_response").hide(function() {
$("#response_loading_dialog").show(function() {
var check_params = get_response_params(response_id);
if (check_params[0] !== "") {
show_event_response_command_dialog(
response_id,
response,
total_checked
);
} else {
check_massive_response_event(
response_id,
response,
total_checked,
response_command
);
}
});
});
} else {
$("#button-btn_str").hide(function() {
$("#execute_again_loading").show(function() {
check_massive_response_event(
response_id,
response,
total_checked,
response_command
);
});
});
}
} else {
// It is not a custom response
switch (response_id) {
case "in_progress_selected":
$(".chk_val").each(function() {
if ($(this).is(":checked")) {
in_progress_event(dt_event, $(this).val(), this);
}
});
break;
case "validate_selected":
$(".chk_val").each(function() {
if ($(this).is(":checked")) {
validate_event(dt_event, $(this).val(), this);
}
});
break;
case "delete_selected":
$(".chk_val").each(function() {
if ($(this).is(":checked")) {
delete_event(dt_event, $(this).val(), this);
}
});
break;
}
}
}
function check_massive_response_event(
response_id,
response,
total_checked,
response_command
) {
var counter = 0;
var end = 0;
$(".chk_val").each(function() {
if ($(this).is(":checked")) {
var event_id = $(this).val();
var server_id = $("#hidden-server_id_" + event_id).val();
response["target"] = get_response_target(
event_id,
response_id,
server_id,
response_command
);
if (total_checked - 1 === counter) end = 1;
show_massive_response_dialog(
event_id,
response_id,
response,
counter,
end
);
counter++;
}
});
}

View File

@ -309,3 +309,45 @@ tr.group * {
text-indent: 3em;
background: #e2e2e2;
}
.dt-button.buttons-csv.buttons-html5 {
float: right;
font-weight: normal;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
font-size: 1.2em;
background-color: #fff;
background-repeat: no-repeat;
background-position: 92% 10px;
color: #000;
padding-bottom: 10px;
padding-top: 10px;
padding-left: 15px;
border: 1px solid #888;
font-family: "lato", "Open Sans", sans-serif;
cursor: pointer;
}
.dt-button.buttons-csv.buttons-html5:hover {
border: 1px solid #333;
}
.dt-button.buttons-csv.buttons-html5:active {
border: 1px solid #000;
color: #333;
background-color: #e1e1e1;
}
.dt-button.buttons-csv.buttons-html5[disabled] {
color: #b4b4b4;
background-color: #f3f3f3;
border-color: #b6b6b6;
cursor: default;
}
div.multi-response-buttons {
margin-top: 2em;
width: 100%;
text-align: right;
}

View File

@ -436,6 +436,12 @@ select:-internal-list-box {
* - GLOBAL STYLES -
* ---------------------------------------------------------------------
*/
.w120px {
width: 120px;
}
.w20px {
width: 20px;
}
.w10p {
width: 10%;
}
@ -487,7 +493,9 @@ select:-internal-list-box {
.h100p {
height: 100%;
}
.no-text-imp {
font-size: 0 !important;
}
.flex-column {
display: flex;
flex-direction: column;

View File

@ -67,6 +67,16 @@ $event_w = check_acl($config['id_user'], 0, 'EW');
$event_m = check_acl($config['id_user'], 0, 'EM');
$access = ($event_a == true) ? 'ER' : (($event_w == true) ? 'EW' : (($event_m == true) ? 'EM' : 'ER'));
$readonly = false;
if (!is_metaconsole()
&& isset($config['event_replication'])
&& $config['event_replication'] == 1
&& $config['show_events_in_local'] == 1
) {
$readonly = true;
}
// Load specific stylesheet.
ui_require_css_file('events');
@ -995,7 +1005,11 @@ try {
// 'module_name',
[
'text' => 'options',
'class' => 'action_buttons',
'class' => 'action_buttons w120px',
],[
'text' => 'm',
'extra' => "<input name='all_validate_box' type='checkbox' value='1' id='checkbox-all_validate_box' />",
'class' => 'w20px',
],
];
$fields = explode(',', $config['event_fields']);
@ -1008,10 +1022,15 @@ try {
// Always add options column.
$fields = array_merge(
$fields,
[[
'text' => 'options',
'class' => 'action_buttons',
],
[
[
'text' => 'options',
'class' => 'action_buttons w120px',
],[
'text' => 'm',
'extra' => "<input name='all_validate_box' type='checkbox' value='1' id='checkbox-all_validate_box' />",
'class' => 'w20px no-text-imp',
],
]
);
@ -1129,7 +1148,10 @@ try {
],
'column_names' => $column_names,
'columns' => $fields,
'no_sortable_columns' => [-1],
'no_sortable_columns' => [
-1,
-2,
],
'ajax_postprocess' => 'process_datatables_item(item)',
'drawCallback' => 'process_datatables_callback(this, settings)',
]
@ -1138,6 +1160,44 @@ try {
ui_print_error_message($e->getMessage());
}
// Event responses.
$sql_event_resp = "SELECT id, name FROM tevent_response WHERE type LIKE 'command'";
$event_responses = db_get_all_rows_sql($sql_event_resp);
if (check_acl($config['id_user'], 0, 'EW') == 1 && !$readonly) {
$array_events_actions['in_progress_selected'] = __('In progress selected');
$array_events_actions['validate_selected'] = __('Validate selected');
}
if (check_acl($config['id_user'], 0, 'EM') == 1 && !$readonly) {
$array_events_actions['delete_selected'] = __('Delete selected');
}
foreach ($event_responses as $val) {
$array_events_actions[$val['id']] = $val['name'];
}
if ($config['event_replication'] != 1) {
echo '<div class="multi-response-buttons">';
echo '<form method="post" id="form_event_response">';
echo '<input type="hidden" id="max_execution_event_response" value="'.$config['max_execution_event_response'].'" />';
html_print_select($array_events_actions, 'response_id', '', '', '', 0, false, false, false);
echo '&nbsp&nbsp';
html_print_button(__('Execute event response'), 'submit_event_response', false, 'execute_event_response(true);', 'class="sub next"');
echo "<span id='response_loading_dialog' style='display:none'>".html_print_image('images/spinner.gif', true).'</span>';
echo '</form>';
echo '<span id="max_custom_event_resp_msg" style="display:none; color:#e63c52; line-height: 200%;">';
echo __(
'A maximum of %s event custom responses can be selected',
$config['max_execution_event_response']
).'</span>';
echo '<span id="max_custom_selected" style="display:none; color:#e63c52; line-height: 200%;">';
echo __(
'Please, select an event'
).'</span>';
echo '</div>';
}
// Close viewer.
enterprise_hook('close_meta_frame');
@ -1401,6 +1461,59 @@ function process_datatables_item(item) {
item.id_grupo = item.group_name;
}
/* Options */
// Show more.
item.options = '<a href="javascript:" onclick="show_event_dialog(';
item.options += item.id_evento+','+$("#group_rep").val();
item.options += ')" ><?php echo html_print_image('images/eye.png', true, ['title' => __('Show more')]); ?></a>';
<?php
// XXX Here is not a global grant, use specific grants:
// Update query to include user_can_manage and user_can_write flags.
if (check_acl($config['id_user'], 0, 'EW') == 1 && !$readonly) {
?>
if (item.estado != '1') {
// Validate.
item.options += '<a href="javascript:" onclick="validate_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) {
item.options += item.max_id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/tick.png', true, ['title' => __('Validate events')]); ?></a>';
} else {
item.options += item.id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/tick.png', true, ['title' => __('Validate event')]); ?></a>';
}
}
if (item.estado != '2') {
// In process.
item.options += '<a href="javascript:" onclick="in_process_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) {
item.options += item.max_id_evento+', this)" >';
} else {
item.options += item.id_evento+', this)" >';
}
item.options += '<?php echo html_print_image('images/hourglass.png', true, ['title' => __('Change to in progress status')]); ?></a>';
}
// Delete.
item.options += '<a href="javascript:" onclick="delete_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) {
item.options += item.max_id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/cross.png', true, ['title' => __('Delete events')]); ?></a>';
} else {
item.options += item.id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/cross.png', true, ['title' => __('Delete event')]); ?></a>';
}
// Multi select.
item.m = '<input name="checkbox-multi[]" type="checkbox" value="';
item.m += item.id_evento+'" id="checkbox-multi-'+item.id_evento+'" ';
item.m += 'class="candeleted chk_val">';
<?php
}
?>
/* Status */
img = '<?php echo html_print_image('images/star.png', true, ['title' => __('Unknown'), 'class' => 'forced-title']); ?>';
switch (item.estado) {
@ -1421,42 +1534,6 @@ function process_datatables_item(item) {
item.estado += img;
item.estado += '</div>';
/* Options */
// Show more.
item.options = '<a href="javascript:" onclick="show_event_dialog(';
item.options += item.id_evento+','+$("#group_rep").val();
item.options += ')" ><?php echo html_print_image('images/eye.png', true, ['title' => __('Show more')]); ?></a>';
// Validate.
item.options += '<a href="javascript:" onclick="validate_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) {
item.options += item.max_id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/tick.png', true, ['title' => __('Validate events')]); ?></a>';
} else {
item.options += item.id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/tick.png', true, ['title' => __('Validate event')]); ?></a>';
}
// In process.
item.options += '<a href="javascript:" onclick="in_process_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) {
item.options += item.max_id_evento+', this)" >';
} else {
item.options += item.id_evento+', this)" >';
}
item.options += '<?php echo html_print_image('images/hourglass.png', true, ['title' => __('Change to in progress status')]); ?></a>';
// Delete.
item.options += '<a href="javascript:" onclick="delete_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) {
item.options += item.max_id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/cross.png', true, ['title' => __('Delete events')]); ?></a>';
} else {
item.options += item.id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/cross.png', true, ['title' => __('Delete event')]); ?></a>';
}
/* Event ID dash */
item.id_evento = "#"+item.id_evento;
@ -1709,6 +1786,18 @@ function reorder_tags_inputs() {
}
/* Tag management ends */
$(document).ready( function() {
/* Multi select handler */
$('#checkbox-all_validate_box').on('change', function() {
if($('#checkbox-all_validate_box').is(":checked")) {
$('.chk_val').check();
} else {
$('.chk_val').uncheck();
}
});
/* Update summary */
$("#status").on("change",function(){
$('#summary_status').html($("#status option:selected").text());