diff --git a/pandora_console/extras/mr/68.sql b/pandora_console/extras/mr/68.sql index 59463c8e25..488b49fd33 100644 --- a/pandora_console/extras/mr/68.sql +++ b/pandora_console/extras/mr/68.sql @@ -117,4 +117,8 @@ CREATE TABLE IF NOT EXISTS `tmetaconsole_ha_databases` ( PRIMARY KEY (`node_id`, `host`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; +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..c0c574cd75 --- /dev/null +++ b/pandora_console/godmode/reporting/manage_schedule.php @@ -0,0 +1,326 @@ + '', + '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, 0, 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/schedule.php b/pandora_console/godmode/reporting/schedule.php new file mode 100644 index 0000000000..eca0ba93b5 --- /dev/null +++ b/pandora_console/godmode/reporting/schedule.php @@ -0,0 +1,263 @@ + '', + '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') { + 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(); + 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'] + ); + $report_name = db_get_value( + 'name', + 'treport', + 'id_report', + $row['id_report'] + ); + + $data = []; + $params = unserialize($row['args']); + $data[0] = $row['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/install.php b/pandora_console/install.php index a3bfe55962..295c32f95a 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -131,7 +131,7 @@