diff --git a/pandora_console/extras/mr/68.sql b/pandora_console/extras/mr/68.sql index c72067b5d8..238746e0a0 100644 --- a/pandora_console/extras/mr/68.sql +++ b/pandora_console/extras/mr/68.sql @@ -159,4 +159,8 @@ CREATE TABLE IF NOT EXISTS `tmetaconsole_ha_databases` ( ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; ALTER TABLE `tserver` ADD COLUMN `disabled` BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE `tuser_task_scheduled` ADD COLUMN `id_report` INT NULL AFTER `id_user_task`; +ALTER TABLE `tuser_task_scheduled` ADD COLUMN `name` VARCHAR(255) NULL AFTER `id_user_task`; + + COMMIT; \ No newline at end of file diff --git a/pandora_console/godmode/reporting/manage_schedule.php b/pandora_console/godmode/reporting/manage_schedule.php new file mode 100644 index 0000000000..d71bf47454 --- /dev/null +++ b/pandora_console/godmode/reporting/manage_schedule.php @@ -0,0 +1,343 @@ + '', + 'label' => __('Reporting'), + ], + [ + 'link' => '', + 'label' => __('Custom Reports'), + ], + ] +); + +$id_task = get_parameter('id_task', null); +$name = ''; +$id_report = ''; +$task = ''; +$group = 0; +$schedule = ''; +$console = ''; +$date = ''; +$time = ''; +$args = ''; + +if (isset($id_task) === true) { + $row = db_get_row('tuser_task_scheduled', 'id', $id_task); + $name = $row['name']; + $id_report = $row['id_report']; + $task = $row['id_user_task']; + $group = $row['id_grupo']; + $schedule = $row['scheduled']; + $console = $row['id_console']; + $args = unserialize($row['args']); + $date = date('Y/m/d', $args['first_execution']); + $time = date('H:i:s', $args['first_execution']); +} + +$table = new stdClass(); +$traps_generator = '
'; +$table->id = 'table_manage'; +$table->width = '100%'; +$table->class = 'filter-table-adv databox'; +$table->size = []; +$table->data = []; +$table->size[0] = '50%'; +$table->size[1] = '50%'; + +$table->data[0][0] = html_print_label_input_block( + __('Name'), + html_print_input_text( + 'name', + $name, + '', + 50, + 255, + true + ) +); + +$reports = db_get_all_rows_sql('SELECT id_report, name FROM treport'); +if ($reports !== false) { + $array_reports = []; + foreach ($reports as $row) { + $array_reports[$row['id_report']] = $row['name']; + } +} + +$table->data[0][1] = html_print_label_input_block( + __('Report'), + html_print_select( + $array_reports, + 'id_report', + $id_report, + '', + __('Select'), + -1, + true, + false, + true, + 'w100p' + ) +); + +// Remove Send csv log in list new console task. +$tasks = get_tasks(); +// Unset to take just Reports ones. +unset($tasks[4], $tasks[5], $tasks[6], $tasks[7]); +if (($key = array_search('Send csv log', $tasks)) !== false) { + unset($tasks[$key]); +} + +$table->data[1][0] = html_print_label_input_block( + __('Task'), + html_print_select( + $tasks, + 'id_user_task', + $task, + '', + __('Select'), + -1, + true, + false, + false, + '', + false, + 'width: 100%' + ) +); + +$table->data[1][1] = html_print_label_input_block( + __('Group'), + html_print_select_groups( + false, + 'AR', + true, + 'group', + $group, + '', + '', + '', + true, + false, + true, + '', + false, + 'width: 100%', + false, + false, + false, + false, + false, + false, + false, + false, + true + ) +); + +$table->data[2][0] = html_print_label_input_block( + __('Scheduled'), + html_print_select( + cron_get_scheduled_options(), + 'scheduled', + $schedule, + '', + '', + 0, + true, + false, + false, + '', + false, + 'width: 100%' + ) +); + +$table->data[2][1] = html_print_label_input_block( + __('Console'), + html_print_select( + $registered_consoles_opts, + 'console', + $console, + '', + __('Any'), + 0, + true, + false, + false, + '', + false, + 'width: 100%' + ) +); + +$table->data[3][0] = html_print_label_input_block( + __('Next execution'), + html_print_input_text( + 'date', + $date, + '', + 50, + 255, + true + ) +); + +$table->data[3][1] = html_print_label_input_block( + __('Hour'), + html_print_input_text( + 'time', + $time, + '', + 50, + 255, + true + ) +); +$table->colspan[4][0] = 2; +$table->data[4][0] = html_print_label_input_block(__('Parameters'), cron_render_parameters($task, $args, $id_report, true)); +$traps_generator .= html_print_table($table, true); +if (isset($id_task) === true) { + $buttons[] = html_print_submit_button( + __('Update schedule'), + 'btn_generate_trap', + false, + [ + 'class' => 'sub ok submitButton', + 'icon' => 'next', + ], + true + ).html_print_input_hidden('update_schedule', 1, true).html_print_input_hidden('id', $id_task, true); +} else { + $buttons[] = html_print_submit_button( + __('Create schedule'), + 'btn_generate_trap', + false, + [ + 'class' => 'sub ok submitButton', + 'icon' => 'next', + ], + true + ).html_print_input_hidden('new_schedule', 1, true); +} + +$buttons[] = html_print_button( + __('Go back'), + 'button_back', + false, + '', + [ + 'icon' => 'back', + 'mode' => 'secondary', + ], + true +); +$traps_generator .= '
'.html_print_action_buttons(implode('', $buttons), ['type' => 'form_action'], true).'
'; + +unset($table); +$traps_generator .= '
'; + +echo $traps_generator; + +ui_require_css_file('datepicker'); +ui_include_time_picker(); +ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript/i18n/'); + +?> + \ No newline at end of file diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 7b18365860..38206b060c 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1282,24 +1282,6 @@ switch ($action) { ); } - $discovery_tasklist = new DiscoveryTaskList(); - $report_task_data = $discovery_tasklist->showListConsoleTask(true); - if (is_array($report_task_data) === true || (strpos($report_task_data, 'class="nf"') === false && $report_task_data !== -1)) { - $task_table = '
'; - $task_table .= ''.__('Report tasks'); - $task_table .= ui_print_help_tip(__('To schedule a report, do it from the editing view of each report.'), true); - $task_table .= '
'; - $task_table .= $report_task_data; - $task_table .= '
'; - echo $task_table; - } else { - if ($report_task_data === -1) { - $report_task_data = ''; - } - - ui_print_info_message($report_task_data.__('To schedule a report, do it from the editing view of each report.')); - } - if (check_acl($config['id_user'], 0, 'RW') || check_acl($config['id_user'], 0, 'RM') ) { diff --git a/pandora_console/godmode/reporting/schedule.php b/pandora_console/godmode/reporting/schedule.php new file mode 100644 index 0000000000..8f01c85cfd --- /dev/null +++ b/pandora_console/godmode/reporting/schedule.php @@ -0,0 +1,271 @@ + '', + 'label' => __('Reporting'), + ], + [ + 'link' => '', + 'label' => __('Custom reports'), + ], + ] +); + +$delete_task = get_parameter('delete_task', false); +if ($delete_task !== false) { + db_process_sql(sprintf('DELETE FROM tuser_task_scheduled WHERE id = %s', $delete_task)); + ui_print_result_message( + true, + __('Successfully deleted') + ); +} + +$update_schedule = get_parameter('update_schedule', false); +if ($update_schedule === '1') { + enterprise_include_once('/godmode/wizards/ConsoleTasks.class.php'); + $task = new ConsoleTasks(0, 'Default message. Not set.', '/images/wizard/consoletasks.png', 'Report Tasks', true); + $task->updateTask(); + ui_print_result_message( + true, + __('Successfully updated') + ); +} + +$new_schedule = get_parameter('new_schedule', false); +if ($new_schedule === '1') { + $name = get_parameter('name', null); + $sql = sprintf('SELECT * FROM tuser_task_scheduled WHERE name = "%s"', $name); + if (db_get_all_rows_sql($sql) === false) { + enterprise_include_once('/godmode/wizards/ConsoleTasks.class.php'); + $task = new ConsoleTasks(0, 'Default message. Not set.', '/images/wizard/consoletasks.png', 'Report Tasks', true); + $result = $task->createTask(); + } else { + $result = false; + $_SESSION['report_task_msg'] = __('The schedule name is already in use.'); + } + + ui_print_result_message( + $result, + __('Successfully created'), + $_SESSION['report_task_msg'] + ); +} + +$id_group = get_parameter('id_group', 0); +$search = get_parameter('search', ''); + +$table_aux = new stdClass(); +$table_aux->width = '100%'; +$table_aux->class = 'filter-table-adv'; +$table_aux->size[0] = '50%'; +$table_aux->size[1] = '50%'; + +$table_aux->data[0][0] = html_print_label_input_block( + __('Group'), + html_print_select_groups( + false, + $access, + true, + 'id_group', + $id_group, + '', + '', + '', + true, + false, + true, + '', + false, + '', + false, + false, + 'id_grupo' + ) +); + +$table_aux->data[0][1] = html_print_label_input_block( + __('Free text for search: ').ui_print_help_tip( + __('Search by report name or description, list matches.'), + true + ), + html_print_input_text( + __('search'), + $search, + '', + 30, + '', + true + ) +); + +$where = ''; +if ((bool) users_is_admin() === false) { + $where = sprintf(' AND id_usuario = "%s"', $config['id_user']); +} + +$sql = 'SELECT * FROM tuser_task_scheduled WHERE id_user_task IN (1,2,3,4) '.$where; +$reports = db_get_all_rows_sql($sql); +if ($reports !== false) { + $table = new stdClass(); + $table->class = 'info_table'; + $table->width = '100%'; + $table->data = []; + + $table->head[0] = __('Name'); + $table->head[1] = __('Report'); + $table->head[2] = __('Type'); + $table->head[3] = __('Schedule / Day'); + $table->head[4] = __('Action'); + $table->head[5] = __('Operations'); + + foreach ($reports as $row) { + $table->cellclass[][5] = 'table_action_buttons'; + $function_name = db_get_value( + 'name', + 'tuser_task', + 'id', + $row['id_user_task'] + ); + $params = unserialize($row['args']); + $id_report = ($row['id_report'] ?? $params[0]); + $report_name = db_get_value( + 'name', + 'treport', + 'id_report', + $id_report + ); + $data = []; + $data[0] = ($row['name'] ?? __('No name')); + $data[1] = $report_name; + $data[2] = $function_name; + $data[3] = date('Y/m/d H:i:s', $params['first_execution']); + $data[4] = cron_get_scheduled_string($row['scheduled']); + $data[5] = ''; + if (check_acl($config['id_user'], 0, 'RW')) { + $data[5] .= html_print_anchor( + [ + 'href' => ui_get_full_url( + sprintf( + 'index.php?sec=reporting&sec2=godmode/reporting/manage_schedule&id_task=%s', + $row['id'] + ) + ), + 'content' => html_print_image( + 'images/edit.svg', + true, + [ + 'title' => __('Edit'), + 'class' => 'main_menu_icon invert_filter', + ] + ), + ], + true + ); + + $data[5] .= html_print_anchor( + [ + 'href' => sprintf( + 'index.php?sec=custom_report&sec2=godmode/reporting/schedule&delete_task=%s', + $row['id'] + ), + 'onClick' => 'if (!confirm(\''.__('Are you sure?').'\')) return false;', + 'content' => html_print_image( + 'images/delete.svg', + true, + [ + 'title' => __('Delete'), + 'class' => 'main_menu_icon invert_filter', + ] + ), + ], + true + ); + } + + array_push($table->data, $data); + } + + html_print_table($table); +} else { + ui_print_info_message( + __('No data to show') + ); +} + +if (check_acl($config['id_user'], 0, 'RW') || check_acl($config['id_user'], 0, 'RM') +) { + $buttonsOutput = []; + // Create form. + $buttonsOutput[] = '
'; + $buttonsOutput[] = html_print_submit_button( + __('Create report'), + 'create', + false, + [ 'icon' => 'next' ], + true + ); + $buttonsOutput[] = '
'; + + echo html_print_action_buttons( + implode('', $buttonsOutput), + [ + 'type' => 'form_action', + 'right_content' => $tablePagination, + ], + true + ); +} diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index 9e2824f9e4..93c5d8fe4e 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -153,6 +153,14 @@ function menu_print_menu(&$menu) if (empty($operation) === false) { $sec2 = $sec2.'&operation='.$operation; } + } else if ($sec2 === 'godmode/reporting/reporting_builder') { + $tab = (string) get_parameter('tab', ''); + $action = (string) get_parameter('action', ''); + if ($tab === 'template' && $action === 'list_template') { + $sec2 = $sec2.'&tab=template&action=list_template'; + } + } else if ($sec2 === 'godmode/reporting/manage_schedule') { + $sec2 = 'godmode/reporting/schedule'; } else if ($sec2 === 'godmode/users/configure_user') { $sec2 = 'godmode/users/user_list'; } else if ($sec2 === 'godmode/modules/manage_inventory_modules_form') { diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php index 89101f5b64..3e32e54b3c 100644 --- a/pandora_console/operation/menu.php +++ b/pandora_console/operation/menu.php @@ -460,13 +460,20 @@ if ($access_console_node === true) { $sub = []; - $sub['godmode/reporting/reporting_builder']['text'] = __('Custom reporting'); - $sub['godmode/reporting/reporting_builder']['id'] = 'Custom_reporting'; - // Set godomode path. - $sub['godmode/reporting/reporting_builder']['subsecs'] = [ - 'godmode/reporting/reporting_builder', - 'operation/reporting/reporting_viewer', - ]; + $sub['custom_report']['text'] = __('Custom Reports'); + $sub['custom_report']['id'] = 'Custom_reporting'; + $sub['custom_report']['type'] = 'direct'; + $sub['custom_report']['subtype'] = 'nolink'; + $sub['custom_report']['refr'] = 0; + + $sub2 = []; + $sub2['godmode/reporting/reporting_builder']['text'] = __('Reports'); + $sub2['godmode/reporting/reporting_builder&tab=template&action=list_template']['text'] = __('Templates'); + if (check_acl($config['id_user'], 0, 'RW') || check_acl($config['id_user'], 0, 'RM')) { + $sub2['godmode/reporting/schedule']['text'] = __('Schedule'); + } + + $sub['custom_report']['sub2'] = $sub2; $sub['godmode/reporting/graphs']['text'] = __('Custom graphs'); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index fe3eb7ebaa..0467099681 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -3885,6 +3885,8 @@ CREATE TABLE IF NOT EXISTS `tuser_task_scheduled` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `id_usuario` VARCHAR(255) NOT NULL DEFAULT '0', `id_user_task` INT UNSIGNED NOT NULL DEFAULT 0, + `id_report` INT NULL, + `name` VARCHAR(255) NULL, `args` TEXT, `scheduled` ENUM('no','hourly','daily','weekly','monthly','yearly','custom') DEFAULT 'no', `last_run` INT UNSIGNED DEFAULT 0,