#9073 added section welcome tips in menu

This commit is contained in:
Daniel Cebrian 2023-02-15 08:56:03 +01:00
parent 9f01a302c5
commit 1ab8767c34
4 changed files with 319 additions and 0 deletions

View File

@ -380,6 +380,9 @@ if ($access_console_node === true) {
$sub2['godmode/setup/setup&section=external_tools']['text'] = __('External Tools');
$sub2['godmode/setup/setup&section=external_tools']['refr'] = 0;
$sub2['godmode/setup/setup&section=welcome_tips']['text'] = __('Welcome Tips');
$sub2['godmode/setup/setup&section=welcome_tips']['refr'] = 0;
if ((bool) $config['activate_gis'] === true) {
$sub2['godmode/setup/setup&section=gis']['text'] = __('Map conections GIS');
}

View File

@ -224,6 +224,11 @@ $buttons['external_tools'] = [
'text' => '<a href="'.ui_get_full_url('index.php?sec=gsetup&sec2=godmode/setup/setup&section=external_tools').'">'.html_print_image('images/nettool.png', true, ['title' => __('External Tools'), 'class' => 'invert_filter']).'</a>',
];
$buttons['welcome_tips'] = [
'active' => false,
'text' => '<a href="'.ui_get_full_url('index.php?sec=gsetup&sec2=godmode/setup/setup&section=welcome_tips').'">'.html_print_image('images/', true, ['title' => __('Welcome tips'), 'class' => 'invert_filter']).'</a>',
];
if ($config['activate_gis']) {
$buttons['gis'] = [
'active' => false,
@ -312,6 +317,20 @@ switch ($section) {
$help_header = '';
break;
case 'welcome_tips':
$view = get_parameter('view', '');
$title = __('Welcome tips');
if ($view === 'create') {
$title = __('Create tip');
} else if ($view === 'edit') {
$title = __('Edit tip');
}
$buttons['welcome_tips']['active'] = true;
$subpage = ' &raquo '.$title;
$help_header = '';
break;
case 'enterprise':
$buttons['enterprise']['active'] = true;
$subpage = ' &raquo '.__('Enterprise');
@ -409,6 +428,10 @@ switch ($section) {
include_once $config['homedir'].'/godmode/setup/setup_external_tools.php';
break;
case 'welcome_tips':
include_once $config['homedir'].'/godmode/setup/welcome_tips.php';
break;
default:
enterprise_hook('setup_enterprise_select_tab', [$section]);
break;

View File

@ -0,0 +1,79 @@
<?php
/**
* Welcome Tips
*
* @category Welcome Tips
* @package Pandora FMS
* @subpackage Opensource
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
// Begin.
global $config;
// Require needed class.
require_once $config['homedir'].'/include/class/TipsWindow.class.php';
$view = get_parameter('view', '');
$action = get_parameter('action', '');
try {
$tipsWindow = new TipsWindow();
} catch (Exception $e) {
echo '[TipsWindow]'.$e->getMessage();
return;
}
if ($view === 'create') {
if ($action === 'create') {
$secure_input = get_parameter('secure_input', '');
$id_lang = get_parameter('id_lang', '');
$title = get_parameter('title', '');
$text = get_parameter('text', '');
$url = get_parameter('url', '');
$enable = get_parameter_switch('enable', '');
$errors = [];
if (empty($id_lang) === true) {
$errors[] = __('Language is empty');
}
if (empty($title) === true) {
$errors[] = __('Title is empty');
}
if (empty($text) === true) {
$errors[] = __('Text is empty');
}
if (count($errors) === 0) {
$response = $tipsWindow->createTip($id_lang, $title, $text, $url, $enable);
if ($response === false) {
$errors[] = __('Error in insert data');
}
}
$tipsWindow->viewCreate($errors);
} else {
$tipsWindow->viewCreate();
}
return;
}
$tipsWindow->draw();

View File

@ -45,6 +45,7 @@ class TipsWindow
'getRandomTip',
'renderView',
'setShowTipsAtStartup',
'getTips',
];
/**
@ -263,4 +264,217 @@ class TipsWindow
}
}
public function draw()
{
try {
$columns = [
'title',
'text',
];
$column_names = [
__('Title'),
__('Text'),
];
// Load datatables user interface.
ui_print_datatable(
[
'id' => 'list_tips_windows',
'class' => 'info_table',
'style' => 'width: 100%',
'columns' => $columns,
'column_names' => $column_names,
'ajax_url' => $this->ajaxController,
'ajax_data' => ['method' => 'getTips'],
'no_sortable_columns' => [-1],
'order' => [
'field' => 'title',
'direction' => 'asc',
],
'search_button_class' => 'sub filter float-right',
'form' => [
'inputs' => [
[
'label' => __('Search by title'),
'type' => 'text',
'name' => 'filter_title',
'size' => 12,
],
],
],
]
);
echo '<div class="action-buttons w100p">';
echo '<a href="index.php?sec=gsetup&sec2=godmode/setup/setup&section=welcome_tips&view=create">';
html_print_submit_button(
__('Create tip'),
'create',
false,
'class="sub next"'
);
echo '</a>';
echo '</div>';
} catch (Exception $e) {
echo $e->getMessage();
}
}
public function getTips()
{
global $config;
// Init data.
$data = [];
// Count of total records.
$count = 0;
// Catch post parameters.
$start = get_parameter('start', 0);
$length = get_parameter('length', $config['block_size']);
$order_datatable = get_datatable_order(true);
$filters = get_parameter('filter', []);
$pagination = '';
$filter = '';
$order = '';
try {
ob_start();
if (key_exists('filter_title', $filters) === true) {
if (empty($filters['filter_title']) === false) {
$filter = ' WHERE title like "%'.$filters['filter_title'].'%"';
}
}
if (isset($order_datatable)) {
$order = sprintf(
' ORDER BY %s %s',
$order_datatable['field'],
$order_datatable['direction']
);
}
if (isset($length) && $length > 0
&& isset($start) && $start >= 0
) {
$pagination = sprintf(
' LIMIT %d OFFSET %d ',
$length,
$start
);
}
$sql = sprintf(
'SELECT title, text, url
FROM twelcome_tip %s %s %s',
$filter,
$order,
$pagination
);
$data = db_get_all_rows_sql($sql);
if (empty($data) === true) {
$total = 0;
$data = [];
} else {
$total = $this->getTotalTips();
}
echo json_encode(
[
'data' => $data,
'recordsTotal' => $total,
'recordsFiltered' => $total,
]
);
// Capture output.
$response = ob_get_clean();
} catch (Exception $e) {
echo json_encode(['error' => $e->getMessage()]);
exit;
}
json_decode($response);
if (json_last_error() === JSON_ERROR_NONE) {
echo $response;
} else {
echo json_encode(
[
'success' => false,
'error' => $response,
]
);
}
exit;
}
public function viewCreate($errors=null)
{
if ($errors !== null) {
if (count($errors) > 0) {
foreach ($errors as $key => $value) {
ui_print_error_message($value);
}
} else {
ui_print_success_message(__('Tip created'));
}
}
$table = new stdClass();
$table->width = '100%';
$table->class = 'databox filters';
$table->style[0] = 'font-weight: bold';
$table->data = [];
$table->data[0][0] = __('Language');
$table->data[0][1] = html_print_select_from_sql(
'SELECT id_language, name FROM tlanguage',
'id_lang',
'',
'',
'',
'0',
true
);
$table->data[1][0] = __('Title');
$table->data[1][1] = html_print_input_text('title', '', '', 35, 100, true);
$table->data[2][0] = __('Text');
$table->data[2][1] = html_print_textarea('text', 5, 1, '', '', true);
$table->data[3][0] = __('Url');
$table->data[3][1] = html_print_input_text('url', '', '', 35, 100, true);
$table->data[4][0] = __('Enable');
$table->data[4][1] = html_print_checkbox_switch('enable', true, true, true);
echo '<form name="grupo" method="post" action="index.php?sec=gsetup&sec2=godmode/setup/setup&section=welcome_tips&view=create&action=create" >';
html_print_table($table);
echo '<div class="action-buttons" style="width: '.$table->width.'">';
html_print_submit_button(__('Send'), 'submit_button', false, ['class' => 'sub next']);
echo '</div>';
echo '</form>';
}
public function createTip($id_lang, $title, $text, $url, $enable)
{
return db_process_sql_insert(
'twelcome_tip',
[
'id_lang' => $id_lang,
'title' => $title,
'text' => $text,
'url' => $url,
'enable' => $enable,
]
);
}
}