2023-09-21 17:58:18 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* General tactical view
|
|
|
|
*
|
|
|
|
* @category General
|
|
|
|
* @package Pandora FMS
|
|
|
|
* @subpackage TacticalView
|
|
|
|
* @version 1.0.0
|
|
|
|
* @license See below
|
|
|
|
*
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
* Copyright (c) 2007-2023 Artica Soluciones Tecnologicas, http://www.artica.es
|
|
|
|
* This code is NOT free software. This code is NOT licenced under GPL2 licence
|
|
|
|
* You cannnot redistribute it without written permission of copyright holder.
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace PandoraFMS\TacticalView;
|
|
|
|
|
2023-11-20 13:58:29 +01:00
|
|
|
use DateTimeZone;
|
2023-09-21 17:58:18 +02:00
|
|
|
use Exception;
|
|
|
|
use PandoraFMS\View;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* General tactical view
|
|
|
|
*/
|
|
|
|
class GeneralTacticalView
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List elements instanced for show in view.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $elements;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
ui_require_css_file('general_tactical_view');
|
2023-10-02 16:44:53 +02:00
|
|
|
ui_require_javascript_file('general_tactical_view');
|
2023-09-21 17:58:18 +02:00
|
|
|
$this->elements = $this->instanceElements();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-07 13:18:44 +01:00
|
|
|
/**
|
|
|
|
* Returns whether general statistics are disabled.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function disableGeneralStatistics():bool
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
if (users_is_admin($config['id_user']) === true) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return (bool) $config['disable_general_statistics'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-21 17:58:18 +02:00
|
|
|
/**
|
|
|
|
* Instantiate all the elements that will build the dashboard
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function instanceElements():array
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$dir = $config['homedir'].'/include/lib/TacticalView/elements/';
|
|
|
|
|
|
|
|
$handle = opendir($dir);
|
|
|
|
if ($handle === false) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$ignores = [
|
|
|
|
'.',
|
|
|
|
'..',
|
|
|
|
];
|
|
|
|
|
|
|
|
$elements = [];
|
2023-09-25 13:52:28 +02:00
|
|
|
$elements['welcome'] = $this->getWelcomeMessage();
|
2023-09-21 17:58:18 +02:00
|
|
|
while (false !== ($file = readdir($handle))) {
|
|
|
|
try {
|
|
|
|
if (in_array($file, $ignores) === true) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$filepath = realpath($dir.'/'.$file);
|
|
|
|
if (is_readable($filepath) === false
|
|
|
|
|| is_dir($filepath) === true
|
|
|
|
|| preg_match('/.*\.php$/', $filepath) === false
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$className = preg_replace('/.php/', '', $file);
|
|
|
|
include_once $filepath;
|
|
|
|
if (class_exists($className) === true) {
|
|
|
|
$instance = new $className();
|
|
|
|
$elements[$className] = $instance;
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render funcion for print the html.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function render():void
|
|
|
|
{
|
2023-10-02 16:44:53 +02:00
|
|
|
$data = [];
|
|
|
|
$data['javascript'] = $this->javascript();
|
2023-11-07 13:18:44 +01:00
|
|
|
$data['disableGeneralStatistics'] = $this->disableGeneralStatistics();
|
2023-10-02 16:44:53 +02:00
|
|
|
$data = array_merge($data, $this->elements);
|
2023-09-21 17:58:18 +02:00
|
|
|
View::render(
|
|
|
|
'tacticalView/view',
|
2023-10-02 16:44:53 +02:00
|
|
|
$data
|
2023-09-21 17:58:18 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-02 16:44:53 +02:00
|
|
|
/**
|
|
|
|
* Function for print js embedded in html.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function javascript():string
|
|
|
|
{
|
|
|
|
$js = '<script>';
|
|
|
|
foreach ($this->elements as $key => $element) {
|
|
|
|
if ($element->interval > 0) {
|
|
|
|
foreach ($element->refreshConfig as $key => $conf) {
|
|
|
|
$js .= 'autoRefresh('.$element->interval.',"'.$conf['id'].'", "'.$conf['method'].'", "'.$element->nameClass().'");';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$js .= '</script>';
|
|
|
|
return $js;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-25 13:52:28 +02:00
|
|
|
/**
|
|
|
|
* Return the welcome message.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getWelcomeMessage():string
|
2023-11-20 13:58:29 +01:00
|
|
|
{
|
|
|
|
$message = $this->randomWelcomeMessage();
|
|
|
|
|
|
|
|
return html_print_div(
|
|
|
|
[
|
|
|
|
'content' => $message,
|
|
|
|
'class' => 'message-welcome',
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return random welcome message.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function randomWelcomeMessage() : string
|
2023-09-25 13:52:28 +02:00
|
|
|
{
|
|
|
|
global $config;
|
2023-11-20 13:58:29 +01:00
|
|
|
$welcome = [];
|
|
|
|
|
2023-09-27 13:30:56 +02:00
|
|
|
$user = users_get_user_by_id($config['id_user']);
|
|
|
|
if (is_array($user) === true && count($user) > 0) {
|
|
|
|
$name = $user['fullname'];
|
2023-09-25 13:52:28 +02:00
|
|
|
} else {
|
2023-11-20 13:58:29 +01:00
|
|
|
$name = $user['firstname'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config user time zone.
|
|
|
|
date_default_timezone_set($user['timezone']);
|
|
|
|
$date_zone = new DateTimeZone($user['timezone']);
|
|
|
|
$zone_location = $date_zone->getLocation();
|
|
|
|
$latitude = $zone_location['latitude'];
|
|
|
|
|
|
|
|
$emojiOptions = [
|
|
|
|
'have_good_day' => __('Have a good day %s ✌', $name),
|
|
|
|
'welcome_back' => __('Welcome back! %s 👋', $name),
|
|
|
|
'good_morning' => __('Good morning, %s! ☕', $name),
|
|
|
|
'good_evening' => __('Good evening, %s 🌇', $name),
|
|
|
|
'good_night' => __('Good night, %s 🌕', $name),
|
|
|
|
'happy_summer' => __('Happy summer, %s 🌞', $name),
|
|
|
|
'happy_winter' => __('Happy winter, %s ⛄', $name),
|
|
|
|
'happy_autumn' => __('Happy autumn, %s 🍂', $name),
|
|
|
|
'happy_spring' => __('Happy spring, %s 🌻', $name),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
// Welcome back.
|
|
|
|
$user_last_connect = $user['last_connect'];
|
|
|
|
$user_last_day = date('d', strtotime($user_last_connect));
|
|
|
|
$day = date('d', strtotime('now'));
|
|
|
|
if ($user_last_day === $day) {
|
|
|
|
if (empty($name) === true) {
|
|
|
|
$welcome[] = $emojiOptions['welcome_back'];
|
|
|
|
} else {
|
|
|
|
$welcome[] = $emojiOptions['welcome_back'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Morning, evening, night.
|
|
|
|
$date = date('H');
|
|
|
|
if ($date < 13) {
|
|
|
|
if (empty($name) === true) {
|
|
|
|
$welcome[] = $emojiOptions['good_morning'];
|
|
|
|
} else {
|
|
|
|
$welcome[] = $emojiOptions['good_morning'];
|
|
|
|
}
|
|
|
|
} else if ($date < 18) {
|
|
|
|
if (empty($name) === true) {
|
|
|
|
$welcome[] = $emojiOptions['good_evening'];
|
|
|
|
} else {
|
|
|
|
$welcome[] = $emojiOptions['good_evening'];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (empty($name) === true) {
|
|
|
|
$welcome[] = $emojiOptions['good_night'];
|
|
|
|
} else {
|
|
|
|
$welcome[] = $emojiOptions['good_night'];
|
|
|
|
}
|
2023-09-25 13:52:28 +02:00
|
|
|
}
|
|
|
|
|
2023-11-20 13:58:29 +01:00
|
|
|
// Seasons.
|
|
|
|
$mes = date('m');
|
|
|
|
if (($latitude > 0 && ($mes >= 3 && $mes <= 5)) || ($latitude < 0 && ($mes >= 9 && $mes <= 11))) {
|
|
|
|
$welcome[] = $emojiOptions['happy_spring'];
|
|
|
|
} else if (($latitude > 0 && ($mes >= 6 && $mes <= 8)) || ($latitude < 0 && ($mes >= 12 || $mes <= 2))) {
|
|
|
|
$welcome[] = $emojiOptions['happy_summer'];
|
|
|
|
} else if (($latitude > 0 && ($mes >= 9 && $mes <= 11)) || ($latitude < 0 && ($mes >= 3 && $mes <= 5))) {
|
|
|
|
$welcome[] = $emojiOptions['happy_autumn'];
|
2023-09-25 13:52:28 +02:00
|
|
|
} else {
|
2023-11-20 13:58:29 +01:00
|
|
|
$welcome[] = $emojiOptions['happy_winter'];
|
2023-09-25 13:52:28 +02:00
|
|
|
}
|
|
|
|
|
2023-11-20 13:58:29 +01:00
|
|
|
$length = count($welcome);
|
|
|
|
$possition = rand(0, ($length - 1));
|
|
|
|
|
|
|
|
return $welcome[$possition];
|
2023-09-25 13:52:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-21 17:58:18 +02:00
|
|
|
}
|