mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 16:55:05 +02:00
#9073 refactoring
This commit is contained in:
parent
9a0dc247c0
commit
35a1a67006
@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Welcome Tips
|
* Controller View tips in setup
|
||||||
*
|
*
|
||||||
* @category Welcome Tips
|
* @category Console Class
|
||||||
* @package Pandora FMS
|
* @package Pandora FMS
|
||||||
* @subpackage Opensource
|
* @subpackage Dashboards
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @license See below
|
* @license See below
|
||||||
*
|
*
|
||||||
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
// Begin.
|
// Begin.
|
||||||
global $config;
|
global $config;
|
||||||
// Require needed class.
|
|
||||||
require_once $config['homedir'].'/include/class/TipsWindow.class.php';
|
require_once $config['homedir'].'/include/class/TipsWindow.class.php';
|
||||||
$view = get_parameter('view', '');
|
$view = get_parameter('view', '');
|
||||||
$action = get_parameter('action', '');
|
$action = get_parameter('action', '');
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Tips to Pandora FMS feature.
|
* Tips pandora
|
||||||
*
|
*
|
||||||
* @category Class
|
* @category Ajax library.
|
||||||
* @package Pandora FMS
|
* @package Pandora FMS
|
||||||
* @subpackage Tips Window
|
* @subpackage Modules.
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @license See below
|
* @license See below
|
||||||
*
|
*
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Begin.
|
// Begin.
|
||||||
use LDAP\Result;
|
|
||||||
use PandoraFMS\View;
|
use PandoraFMS\View;
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
@ -82,8 +81,6 @@ class TipsWindow
|
|||||||
*/
|
*/
|
||||||
public function ajaxMethod($method)
|
public function ajaxMethod($method)
|
||||||
{
|
{
|
||||||
global $config;
|
|
||||||
|
|
||||||
// Check access.
|
// Check access.
|
||||||
check_login();
|
check_login();
|
||||||
|
|
||||||
@ -94,7 +91,6 @@ class TipsWindow
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param boolean $must_run Must run or not.
|
|
||||||
* @param string $ajax_controller Controller.
|
* @param string $ajax_controller Controller.
|
||||||
*
|
*
|
||||||
* @return object
|
* @return object
|
||||||
@ -156,6 +152,11 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render view modal with random tip
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function renderView()
|
public function renderView()
|
||||||
{
|
{
|
||||||
$initialTip = $this->getRandomTip(true);
|
$initialTip = $this->getRandomTip(true);
|
||||||
@ -172,6 +173,11 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render preview view modal with parameter
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function renderPreview()
|
public function renderPreview()
|
||||||
{
|
{
|
||||||
$title = get_parameter('title', '');
|
$title = get_parameter('title', '');
|
||||||
@ -209,6 +215,13 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search a tip by id
|
||||||
|
*
|
||||||
|
* @param integer $idTip Id from tip.
|
||||||
|
*
|
||||||
|
* @return array $tip
|
||||||
|
*/
|
||||||
public function getTipById($idTip)
|
public function getTipById($idTip)
|
||||||
{
|
{
|
||||||
$tip = db_get_row(
|
$tip = db_get_row(
|
||||||
@ -226,6 +239,13 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a tip or print it in json
|
||||||
|
*
|
||||||
|
* @param boolean $return Param for return or print json.
|
||||||
|
*
|
||||||
|
* @return array $tip
|
||||||
|
*/
|
||||||
public function getRandomTip($return=false)
|
public function getRandomTip($return=false)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
@ -282,12 +302,22 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get number of tips in database
|
||||||
|
*
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
public function getTotalTips()
|
public function getTotalTips()
|
||||||
{
|
{
|
||||||
return db_get_sql('SELECT count(*) FROM twelcome_tip');
|
return db_get_sql('SELECT count(*) FROM twelcome_tip');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get totals tips that user can show
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getTotalTipsShowUser()
|
public function getTotalTipsShowUser()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
@ -309,6 +339,13 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return files from tip
|
||||||
|
*
|
||||||
|
* @param integer $idTip Id from tip.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getFilesFromTip($idTip)
|
public function getFilesFromTip($idTip)
|
||||||
{
|
{
|
||||||
if (empty($idTip) === true) {
|
if (empty($idTip) === true) {
|
||||||
@ -322,6 +359,14 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all images from tip in db and files
|
||||||
|
*
|
||||||
|
* @param integer $idTip Id from tip.
|
||||||
|
* @param array $imagesToRemove Array with id and images path.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function deleteImagesFromTip($idTip, $imagesToRemove)
|
public function deleteImagesFromTip($idTip, $imagesToRemove)
|
||||||
{
|
{
|
||||||
foreach ($imagesToRemove as $id => $image) {
|
foreach ($imagesToRemove as $id => $image) {
|
||||||
@ -337,6 +382,11 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update token user for show tips at startup
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function setShowTipsAtStartup()
|
public function setShowTipsAtStartup()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
@ -363,6 +413,13 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw table in list tips
|
||||||
|
*
|
||||||
|
* @param array $errors Array of errors if exists.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function draw($errors=null)
|
public function draw($errors=null)
|
||||||
{
|
{
|
||||||
ui_require_css_file('tips_window');
|
ui_require_css_file('tips_window');
|
||||||
@ -438,6 +495,13 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete tip and his files.
|
||||||
|
*
|
||||||
|
* @param integer $idTip Id from tip.
|
||||||
|
*
|
||||||
|
* @return integer Status from sql query.
|
||||||
|
*/
|
||||||
public function deleteTip($idTip)
|
public function deleteTip($idTip)
|
||||||
{
|
{
|
||||||
$files = $this->getFilesFromTip($idTip);
|
$files = $this->getFilesFromTip($idTip);
|
||||||
@ -456,6 +520,11 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return tips for datatable
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function getTips()
|
public function getTips()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
@ -579,6 +648,13 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render view create tips
|
||||||
|
*
|
||||||
|
* @param array $errors Array of errors if exists.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function viewCreate($errors=null)
|
public function viewCreate($errors=null)
|
||||||
{
|
{
|
||||||
ui_require_css_file('tips_window');
|
ui_require_css_file('tips_window');
|
||||||
@ -661,6 +737,14 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render view edit tips
|
||||||
|
*
|
||||||
|
* @param integer $idTip Id from tips.
|
||||||
|
* @param array $errors Array of errors if exists.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function viewEdit($idTip, $errors=null)
|
public function viewEdit($idTip, $errors=null)
|
||||||
{
|
{
|
||||||
$tip = $this->getTipById($idTip);
|
$tip = $this->getTipById($idTip);
|
||||||
@ -776,6 +860,20 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Udpdate tip
|
||||||
|
*
|
||||||
|
* @param integer $id Id from tip.
|
||||||
|
* @param integer $id_profile Id profile.
|
||||||
|
* @param string $id_lang Id langugage.
|
||||||
|
* @param string $title Title from tip.
|
||||||
|
* @param string $text Text from tip.
|
||||||
|
* @param string $url Url from tip.
|
||||||
|
* @param boolean $enable Indicates if the tip is activated.
|
||||||
|
* @param array $images Images from tip.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public function updateTip($id, $id_profile, $id_lang, $title, $text, $url, $enable, $images=null)
|
public function updateTip($id, $id_profile, $id_lang, $title, $text, $url, $enable, $images=null)
|
||||||
{
|
{
|
||||||
db_process_sql_begin();
|
db_process_sql_begin();
|
||||||
@ -820,6 +918,19 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create tip
|
||||||
|
*
|
||||||
|
* @param string $id_lang Id langugage.
|
||||||
|
* @param integer $id_profile Id profile.
|
||||||
|
* @param string $title Title from tip.
|
||||||
|
* @param string $text Text from tip.
|
||||||
|
* @param string $url Url from tip.
|
||||||
|
* @param boolean $enable Indicates if the tip is activated.
|
||||||
|
* @param array $images Images from tip.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public function createTip($id_lang, $id_profile, $title, $text, $url, $enable, $images=null)
|
public function createTip($id_lang, $id_profile, $title, $text, $url, $enable, $images=null)
|
||||||
{
|
{
|
||||||
db_process_sql_begin();
|
db_process_sql_begin();
|
||||||
@ -862,6 +973,13 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate images uploads for the user
|
||||||
|
*
|
||||||
|
* @param array $files List images for validate.
|
||||||
|
*
|
||||||
|
* @return boolean Return boolean or array errors.
|
||||||
|
*/
|
||||||
public function validateImages($files)
|
public function validateImages($files)
|
||||||
{
|
{
|
||||||
$formats = [
|
$formats = [
|
||||||
@ -895,6 +1013,13 @@ class TipsWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload images passed by user
|
||||||
|
*
|
||||||
|
* @param array $files List of files for upload.
|
||||||
|
*
|
||||||
|
* @return array List of names files.
|
||||||
|
*/
|
||||||
public function uploadImages($files)
|
public function uploadImages($files)
|
||||||
{
|
{
|
||||||
$dir = 'images/tips/';
|
$dir = 'images/tips/';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* globals $, idTips, totalTips, url, page */
|
/* globals $, idTips, totalTips, url, page, uniqId */
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$("#button-button_add_image").on("click", function() {
|
$("#button-button_add_image").on("click", function() {
|
||||||
var numberImages = $("#inputs_images").children().length;
|
var numberImages = $("#inputs_images").children().length;
|
||||||
@ -161,8 +161,6 @@ function next_tip() {
|
|||||||
if (success) {
|
if (success) {
|
||||||
idTips.push(parseInt(data.id));
|
idTips.push(parseInt(data.id));
|
||||||
render(data);
|
render(data);
|
||||||
} else {
|
|
||||||
//TODO control error
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Dashboards Modal for tips
|
* Dashboards View tips in modal
|
||||||
*
|
*
|
||||||
* @category Console Class
|
* @category Console Class
|
||||||
$output .= '* @packagePandora FMS';
|
* @package Pandora FMS
|
||||||
* @subpackage Dashboards
|
* @subpackage Dashboards
|
||||||
$output .= '* @version1.0.0';
|
* @version 1.0.0
|
||||||
$output .= '* @licenseSee below';
|
* @license See below
|
||||||
*
|
*
|
||||||
$output .= '*______ __________ _______ ________';
|
* ______ ___ _______ _______ ________
|
||||||
$output .= '* | __ \.-----.--.--.--| |.-----.----.-----. |___| | | __|';
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||||
$output .= '* |__/| _ | | _ || _ | _| _ | |___| |__ |';
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||||
*
|
*
|
||||||
* ============================================================================
|
* ============================================================================
|
||||||
@ -25,6 +25,7 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
* ============================================================================
|
* ============================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$output = '';
|
$output = '';
|
||||||
$output .= '<script>var idTips = ['.$id.'];</script>';
|
$output .= '<script>var idTips = ['.$id.'];</script>';
|
||||||
$output .= '<div class="window">';
|
$output .= '<div class="window">';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user