Added copy button to alert commands
This commit is contained in:
parent
b50b1c9f34
commit
1f299cad52
|
@ -38,6 +38,7 @@ $pure = (int)get_parameter('pure', 0);
|
||||||
$update_command = (bool) get_parameter ('update_command');
|
$update_command = (bool) get_parameter ('update_command');
|
||||||
$create_command = (bool) get_parameter ('create_command');
|
$create_command = (bool) get_parameter ('create_command');
|
||||||
$delete_command = (bool) get_parameter ('delete_command');
|
$delete_command = (bool) get_parameter ('delete_command');
|
||||||
|
$copy_command = (bool) get_parameter ('copy_command');
|
||||||
|
|
||||||
if (is_ajax ()) {
|
if (is_ajax ()) {
|
||||||
$get_alert_command = (bool) get_parameter ('get_alert_command');
|
$get_alert_command = (bool) get_parameter ('get_alert_command');
|
||||||
|
@ -57,37 +58,13 @@ if (is_ajax ()) {
|
||||||
if (isset($command['description'])) {
|
if (isset($command['description'])) {
|
||||||
$command['description'] = io_safe_input(str_replace("\r\n","<br>", io_safe_output($command['description'])));
|
$command['description'] = io_safe_input(str_replace("\r\n","<br>", io_safe_output($command['description'])));
|
||||||
}
|
}
|
||||||
|
// Descriptions are stored in json
|
||||||
// Get the html rows of the fields form
|
$fields_descriptions = empty($command['fields_descriptions']) ?
|
||||||
switch ($config["dbtype"]) {
|
'' : json_decode(io_safe_output($command['fields_descriptions']), true);
|
||||||
case "mysql":
|
// Fields values are stored in json
|
||||||
case "postgresql":
|
$fields_values = empty($command['fields_values']) ?
|
||||||
// Descriptions are stored in json
|
'' : io_safe_output(json_decode($command['fields_values'], true));
|
||||||
$fields_descriptions = empty($command['fields_descriptions']) ?
|
|
||||||
'' : json_decode(io_safe_output($command['fields_descriptions']), true);
|
|
||||||
|
|
||||||
// Fields values are stored in json
|
|
||||||
$fields_values = empty($command['fields_values']) ?
|
|
||||||
'' : io_safe_output(json_decode($command['fields_values'], true));
|
|
||||||
break;
|
|
||||||
case "oracle":
|
|
||||||
// Descriptions are stored in json
|
|
||||||
$description_field = str_replace("\\\"","\"",$command['fields_descriptions']);
|
|
||||||
$description_field = str_replace("\\","",$description_field);
|
|
||||||
|
|
||||||
$fields_descriptions = empty($command['fields_descriptions']) ?
|
|
||||||
'' : json_decode(io_safe_output($description_field), true);
|
|
||||||
|
|
||||||
// Fields values are stored in json
|
|
||||||
$values_fields = str_replace("\\\"","\"",$command['fields_values']);
|
|
||||||
$values_fields = str_replace("\\","",$values_fields);
|
|
||||||
|
|
||||||
$fields_values = empty($command['fields_values']) ?
|
|
||||||
'' : io_safe_output(json_decode($values_fields, true));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fields_rows = array();
|
$fields_rows = array();
|
||||||
for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
|
for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
|
||||||
|
|
||||||
|
@ -266,9 +243,6 @@ if (defined('METACONSOLE'))
|
||||||
else
|
else
|
||||||
ui_print_page_header (__('Alerts').' » '.__('Alert commands'), "images/gm_alerts.png", false, "alerts_config", true);
|
ui_print_page_header (__('Alerts').' » '.__('Alert commands'), "images/gm_alerts.png", false, "alerts_config", true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($create_command) {
|
if ($create_command) {
|
||||||
$name = (string) get_parameter ('name');
|
$name = (string) get_parameter ('name');
|
||||||
$command = (string) get_parameter ('command');
|
$command = (string) get_parameter ('command');
|
||||||
|
@ -338,8 +312,29 @@ if ($delete_command) {
|
||||||
ui_print_result_message ($result,
|
ui_print_result_message ($result,
|
||||||
__('Successfully deleted'),
|
__('Successfully deleted'),
|
||||||
__('Could not be deleted'));
|
__('Could not be deleted'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($copy_command) {
|
||||||
|
$id = (int) get_parameter ('id');
|
||||||
|
|
||||||
|
// Get the info from the source command
|
||||||
|
$command_to_copy = db_get_row('talert_commands', 'id', $id);
|
||||||
|
if ($command_to_copy === false) {
|
||||||
|
ui_print_error_message(__("Command with id $id does not found."));
|
||||||
|
break 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare to insert the copy with same values
|
||||||
|
unset ($command_to_copy['id']);
|
||||||
|
$command_to_copy['name'].= __(' (copy)');
|
||||||
|
$result = db_process_sql_insert('talert_commands', $command_to_copy);
|
||||||
|
|
||||||
|
// Print the result
|
||||||
|
ui_print_result_message ($result,
|
||||||
|
__('Successfully copied'),
|
||||||
|
__('Could not be copied')
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$table->width = '100%';
|
$table->width = '100%';
|
||||||
|
@ -351,7 +346,7 @@ $table->head['name'] = __('Name');
|
||||||
$table->head['id'] = __('ID');
|
$table->head['id'] = __('ID');
|
||||||
$table->head['group'] = __('Group');
|
$table->head['group'] = __('Group');
|
||||||
$table->head['description'] = __('Description');
|
$table->head['description'] = __('Description');
|
||||||
$table->head['action'] = __('Delete');
|
$table->head['action'] = __('Actions');
|
||||||
$table->style = array ();
|
$table->style = array ();
|
||||||
$table->style['name'] = 'font-weight: bold';
|
$table->style['name'] = 'font-weight: bold';
|
||||||
$table->size = array ();
|
$table->size = array ();
|
||||||
|
@ -381,9 +376,14 @@ foreach ($commands as $command) {
|
||||||
io_safe_output($command['description']));
|
io_safe_output($command['description']));
|
||||||
$data['action'] = '';
|
$data['action'] = '';
|
||||||
if (! $command['internal']) {
|
if (! $command['internal']) {
|
||||||
$data['action'] = '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_commands&delete_command=1&id='.$command['id'].'&pure='.$pure.'"
|
$data['action'] = '<span style="display: inline-flex">';
|
||||||
|
$data['action'].= '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_commands&copy_command=1&id='.$command['id'].'&pure='.$pure.'"
|
||||||
|
onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.
|
||||||
|
html_print_image("images/copy.png", true) . '</a>';
|
||||||
|
$data['action'].= '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_commands&delete_command=1&id='.$command['id'].'&pure='.$pure.'"
|
||||||
onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.
|
onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.
|
||||||
html_print_image("images/cross.png", true) . '</a>';
|
html_print_image("images/cross.png", true) . '</a>';
|
||||||
|
$data['action'].= '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push ($table->data, $data);
|
array_push ($table->data, $data);
|
||||||
|
|
Loading…
Reference in New Issue