pandorafms/pandora_console/include/lib/Dashboard/Widgets/clock.php

326 lines
7.1 KiB
PHP
Raw Normal View History

2020-03-26 12:29:38 +01:00
<?php
/**
* Widget Clock Pandora FMS Console
*
* @category Console Class
* @package Pandora FMS
* @subpackage Widget Clock
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
2020-11-27 13:52:35 +01:00
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
2020-03-26 12:29:38 +01:00
* 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.
* ============================================================================
*/
namespace PandoraFMS\Dashboard;
/**
* Clock Widgets
*/
class ClockWidget extends Widget
{
/**
* Name widget.
*
* @var string
*/
protected $name;
/**
* Title widget.
*
* @var string
*/
protected $title;
/**
* Page widget;
*
* @var string
*/
protected $page;
/**
* Class name widget.
*
* @var [type]
*/
protected $className;
/**
* Values options for each widget.
*
* @var [type]
*/
protected $values;
/**
* Configuration required.
*
* @var boolean
*/
protected $configurationRequired;
/**
* Error load widget.
*
* @var boolean
*/
protected $loadError;
/**
* Width.
*
* @var integer
*/
protected $width;
/**
* Heigth.
*
* @var integer
*/
protected $height;
/**
* Grid Width.
*
* @var integer
*/
protected $gridWidth;
/**
* Construct.
*
* @param integer $cellId Cell ID.
* @param integer $dashboardId Dashboard ID.
* @param integer $widgetId Widget ID.
* @param integer|null $width New width.
* @param integer|null $height New height.
* @param integer|null $gridWidth Grid width.
*/
public function __construct(
int $cellId,
int $dashboardId=0,
int $widgetId=0,
?int $width=0,
?int $height=0,
?int $gridWidth=0
) {
global $config;
// WARNING: Do not edit. This chunk must be in the constructor.
parent::__construct(
$cellId,
$dashboardId,
$widgetId
);
// Width.
$this->width = $width;
// Height.
$this->height = $height;
// Grid Width.
$this->gridWidth = $gridWidth;
// Options.
2020-04-30 14:08:56 +02:00
$this->values = $this->decoders($this->getOptionsWidget());
2020-03-26 12:29:38 +01:00
// Positions.
$this->position = $this->getPositionWidget();
// Page.
$this->page = basename(__FILE__);
// ClassName.
$class = new \ReflectionClass($this);
$this->className = $class->getShortName();
// Title.
$this->title = __('Clock');
// Name.
if (empty($this->name) === true) {
$this->name = 'clock';
}
// This forces at least a first configuration.
$this->configurationRequired = false;
if (empty($this->values['clockType']) === true) {
$this->configurationRequired = true;
}
$this->overflow_scrollbars = false;
}
2020-04-30 14:08:56 +02:00
/**
* Decoders hack for retrocompability.
*
* @param array $decoder Values.
*
* @return array Returns the values with the correct key.
*/
public function decoders(array $decoder): array
{
$values = [];
// Retrieve global - common inputs.
$values = parent::decoders($decoder);
if (isset($decoder['clock_type']) === true) {
$values['clockType'] = $decoder['clock_type'];
}
if (isset($decoder['clockType']) === true) {
$values['clockType'] = $decoder['clockType'];
}
return $values;
}
2020-03-26 12:29:38 +01:00
/**
* Generates inputs for form (specific).
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public function getFormInputs(): array
{
$values = $this->values;
// Retrieve global - common inputs.
$inputs = parent::getFormInputs();
// Type clock.
$fields = [
'analogic' => __('Analogic'),
'digital' => __('Digital'),
];
$inputs[] = [
'label' => __('Type'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'clockType',
'selected' => $values['clockType'],
'return' => true,
],
];
return $inputs;
}
/**
* Get Post for widget.
*
* @return array
*/
public function getPost():array
{
// Retrieve global - common inputs.
$values = parent::getPost();
$values['clockType'] = \get_parameter('clockType', 0);
return $values;
}
/**
* Draw widget.
*
* @return string;
*/
public function load()
{
global $config;
$size = parent::getSize();
include_once $config['homedir'].'/include/graphs/functions_d3.php';
$id = \uniqid();
$output = '<div class="container-center">';
if ($this->values['clockType'] === 'analogic') {
$posAnolgic = (int) $size['height'];
if ((int) $size['width'] < (int) $size['height']) {
$posAnolgic = (int) $size['width'];
}
$output .= "<div id='clock_".$id."' style=''>";
$output .= print_clock_analogic_1(
'time',
$config['timezone'],
'analogic_1',
$posAnolgic,
$posAnolgic,
$id,
'#000000',
false
);
$output .= '</div>';
} else {
$output .= "<div id='clock_".$id."' style=''>";
$output .= print_clock_digital_1(
'time',
$config['timezone'],
'digital_1',
$size['width'],
$size['height'],
$id,
'#000000'
);
$output .= '</div>';
}
$output .= '</div>';
return $output;
}
/**
* Get description.
*
* @return string.
*/
public static function getDescription()
{
return __('Clock');
}
/**
* Get Name.
*
* @return string.
*/
public static function getName()
{
return 'clock';
}
}