#9073 create files structure
This commit is contained in:
parent
d89e29244b
commit
e62dee1c62
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* Tips to Pandora FMS feature.
|
||||
*
|
||||
* @category Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Tips Window
|
||||
* @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_once $config['homedir'].'/include/class/TipsWindow.class.php';
|
||||
if (is_ajax() === false) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Control call flow.
|
||||
try {
|
||||
// User access and validation is being processed on class constructor.
|
||||
$actions = new TipsWindow();
|
||||
} catch (Exception $e) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ajax controller.
|
||||
$method = get_parameter('method', '');
|
||||
|
||||
if (method_exists($actions, $method) === true) {
|
||||
if ($actions->ajaxMethod($method) === true) {
|
||||
$actions->{$method}();
|
||||
} else {
|
||||
$actions->error('Unavailable method.');
|
||||
}
|
||||
} else {
|
||||
$actions->error('Method not found. ['.$method.']');
|
||||
}
|
||||
|
||||
|
||||
// Stop any execution.
|
||||
exit;
|
|
@ -0,0 +1,228 @@
|
|||
<?php
|
||||
/**
|
||||
* Tips to Pandora FMS feature.
|
||||
*
|
||||
* @category Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage Tips Window
|
||||
* @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.
|
||||
use PandoraFMS\View;
|
||||
global $config;
|
||||
|
||||
/**
|
||||
* Class TipsWindow.
|
||||
*/
|
||||
class TipsWindow
|
||||
{
|
||||
|
||||
/**
|
||||
* Allowed methods to be called using AJAX request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $AJAXMethods = [
|
||||
'getRandomTip',
|
||||
'renderView',
|
||||
];
|
||||
|
||||
/**
|
||||
* Url of controller.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ajaxController;
|
||||
|
||||
/**
|
||||
* Total tips
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $totalTips;
|
||||
|
||||
/**
|
||||
* Array of tips
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $tips = [];
|
||||
|
||||
|
||||
/**
|
||||
* Generates a JSON error.
|
||||
*
|
||||
* @param string $msg Error message.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function error(string $msg)
|
||||
{
|
||||
echo json_encode(
|
||||
['error' => $msg]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if target method is available to be called using AJAX.
|
||||
*
|
||||
* @param string $method Target method.
|
||||
*
|
||||
* @return boolean True allowed, false not.
|
||||
*/
|
||||
public function ajaxMethod($method)
|
||||
{
|
||||
global $config;
|
||||
|
||||
// Check access.
|
||||
check_login();
|
||||
|
||||
return in_array($method, $this->AJAXMethods);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param boolean $must_run Must run or not.
|
||||
* @param string $ajax_controller Controller.
|
||||
*
|
||||
* @return object
|
||||
* @throws Exception On error.
|
||||
*/
|
||||
public function __construct(
|
||||
$ajax_controller='include/ajax/tips_window.ajax'
|
||||
) {
|
||||
$this->ajaxController = $ajax_controller;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Main method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
ui_require_css_file('tips_window');
|
||||
ui_require_javascript_file('tipsWindow');
|
||||
echo '<div id="tips_window_modal" class="invisible"></div>';
|
||||
?>
|
||||
|
||||
|
||||
<script>
|
||||
load_modal({
|
||||
target: $('#tips_window_modal'),
|
||||
url: '<?php echo ui_get_full_url('ajax.php'); ?>',
|
||||
modal: {
|
||||
title: '<?php echo __('Hola! estos son los tips del día'); ?>',
|
||||
ok: '<?php echo __('De acuerdo'); ?>'
|
||||
},
|
||||
onshow: {
|
||||
page: '<?php echo $this->ajaxController; ?>',
|
||||
method: 'renderView',
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
var totalTips = <?php echo $this->getTotalTips(); ?>;
|
||||
var idTips = [<?php echo $initialTip['id']; ?>];
|
||||
var url = '<?php echo ui_get_full_url('ajax.php'); ?>';
|
||||
var page = '<?php echo $this->ajaxController; ?>';
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
public function renderView()
|
||||
{
|
||||
$initialTip = $this->getRandomTip(true);
|
||||
View::render(
|
||||
'dashboard/tipsWindow',
|
||||
[
|
||||
'title' => $initialTip['title'],
|
||||
'text' => $initialTip['text'],
|
||||
'url' => $initialTip['url'],
|
||||
'files' => $initialTip['files'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function getRandomTip($return=false)
|
||||
{
|
||||
$exclude = get_parameter('exclude', '');
|
||||
|
||||
$sql = 'SELECT id, title, text, url
|
||||
FROM twelcome_tip';
|
||||
|
||||
if (empty($exclude) === false && $exclude !== null) {
|
||||
$exclude = implode(',', json_decode($exclude, true));
|
||||
if ($exclude !== '') {
|
||||
$sql .= sprintf(' WHERE id NOT IN (%s)', $exclude);
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY RAND()';
|
||||
|
||||
$tip = db_get_row_sql($sql);
|
||||
$tip['files'] = $this->getFilesFromTip($tip['id']);
|
||||
|
||||
if ($return) {
|
||||
if (empty($tip) === false) {
|
||||
return $tip;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (empty($tip) === false) {
|
||||
echo json_encode(['success' => true, 'data' => $tip]);
|
||||
return;
|
||||
} else {
|
||||
echo json_encode(['success' => false]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getTotalTips()
|
||||
{
|
||||
return db_get_sql('SELECT count(*) FROM twelcome_tip');
|
||||
}
|
||||
|
||||
|
||||
public function getFilesFromTip($idTip)
|
||||
{
|
||||
if (empty($idTip) === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sql = sprintf('SELECT filename, path FROM twelcome_tip_file WHERE twelcome_tip_file = %s', $idTip);
|
||||
|
||||
return db_get_all_rows_sql($sql);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/* globals $, idTips, totalTips, idTips, url, page */
|
||||
$(".carousel").ready(function() {
|
||||
function render({ title, text, url, files }) {
|
||||
$("#title_tip").html(title);
|
||||
$("#text_tip").html(text);
|
||||
$("#url_tip").attr("href", url);
|
||||
$(".carousel .images").empty();
|
||||
|
||||
if (files) {
|
||||
files.forEach(file => {
|
||||
$(".carousel .images").append(`<img src="${file.filename}" />`);
|
||||
});
|
||||
$(".carousel").removeClass("invisible");
|
||||
} else {
|
||||
$(".carousel").addClass("invisible");
|
||||
}
|
||||
}
|
||||
|
||||
$("#next_tip").on("click", function() {
|
||||
if (idTips.length >= totalTips) {
|
||||
idTips = [];
|
||||
}
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: url,
|
||||
dataType: "json",
|
||||
data: {
|
||||
page: page,
|
||||
method: "getRandomTip",
|
||||
exclude: JSON.stringify(idTips)
|
||||
},
|
||||
success: function({ success, data }) {
|
||||
if (success) {
|
||||
idTips.push(parseInt(data.id));
|
||||
render(data);
|
||||
} else {
|
||||
//TODO control error
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,71 @@
|
|||
#tips_window {
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.308);
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 2001;
|
||||
}
|
||||
.window {
|
||||
background-color: white;
|
||||
width: 100%;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.tips_header {
|
||||
display: flex;
|
||||
padding: 0px 20px;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.description {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.actions {
|
||||
border-top: 1px solid #0000001a;
|
||||
text-align: right;
|
||||
padding: 20px;
|
||||
}
|
||||
.carousel {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
max-width: 900px;
|
||||
height: 400px;
|
||||
}
|
||||
.carousel .prev_step {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
border: 0px;
|
||||
background: none;
|
||||
font-size: 50px;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
left: 0;
|
||||
}
|
||||
.carousel .next_step {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
right: 0;
|
||||
z-index: 1;
|
||||
border: 0px;
|
||||
background: none;
|
||||
font-size: 50px;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
}
|
||||
.carousel .images {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
font-size: 0px;
|
||||
}
|
||||
.carousel .images img {
|
||||
width: 100%;
|
||||
}
|
||||
.title {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
|
@ -4177,3 +4177,26 @@ CREATE TABLE IF NOT EXISTS `tmonitor_filter` (
|
|||
`ag_custom_fields` TEXT,
|
||||
PRIMARY KEY (`id_filter`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `twelcome_tip` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`id_lang` INT NULL,
|
||||
`title` VARCHAR(255) NOT NULL,
|
||||
`text` TEXT NOT NULL,
|
||||
`url` VARCHAR(255) NULL,
|
||||
`enable` TINYINT NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `twelcome_tip_file` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`twelcome_tip_file` INT NOT NULL,
|
||||
`filename` VARCHAR(255) NOT NULL,
|
||||
`path` VARCHAR(255) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `twelcome_tip_file`
|
||||
FOREIGN KEY (`twelcome_tip_file`)
|
||||
REFERENCES `twelcome_tip` (`id`)
|
||||
ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<div class="window">
|
||||
<div class="tips_header">
|
||||
<p><input type="checkbox" name="tips_in_start"/>Ver típs al iniciar</p>
|
||||
</div>
|
||||
<div class="carousel <?php echo ($files === false) ? 'invisible' : ''; ?>">
|
||||
<button class="next_step">></button>
|
||||
<div class="images">
|
||||
<?php if ($files !== false) : ?>
|
||||
<?php foreach ($files as $key => $file) : ?>
|
||||
<img src="<?php echo $file['filename']; ?>" />
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<button class="prev_step"><</button>
|
||||
</div>
|
||||
|
||||
<div class="description">
|
||||
<h2 id="title_tip"><?php echo $title; ?></h2>
|
||||
<p id="text_tip">
|
||||
<?php echo $text; ?>
|
||||
</p>
|
||||
<a href="<?php echo $url; ?>" id="url_tip"><?php echo __('Más información'); ?></a>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button id="next_tip"><?php echo __('Siguiente'); ?></button>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue