2014-02-06 18:39:39 +01:00
|
|
|
<?php
|
2020-12-18 13:23:35 +01:00
|
|
|
// phpcs:disable Squiz.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
|
|
|
/**
|
|
|
|
* List of visual consoles, for mobile view.
|
|
|
|
*
|
|
|
|
* @category Common Class
|
|
|
|
* @package Pandora FMS
|
|
|
|
* @subpackage OpenSource
|
|
|
|
* @version 1.0.0
|
|
|
|
* @license See below
|
|
|
|
*
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
* Copyright (c) 2005-2019 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.
|
2014-02-06 18:39:39 +01:00
|
|
|
ob_start();
|
2019-01-30 16:18:44 +01:00
|
|
|
require_once '../include/functions_visual_map.php';
|
|
|
|
ob_get_clean();
|
|
|
|
// Fixed unused javascript code.
|
2020-12-18 13:23:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to generate a list of current visual consoles defined.
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
class Visualmaps
|
|
|
|
{
|
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
/**
|
|
|
|
* ACL allowed.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
private $allowed = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perms needed to access this feature.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
private $acl = 'VR';
|
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
/**
|
|
|
|
* Default filters.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $defaultFilters = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Group.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
private $group = 0;
|
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
/**
|
|
|
|
* Type. Something about filtering.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
private $type = 0;
|
|
|
|
|
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
/**
|
|
|
|
* Builder.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
2019-01-30 16:18:44 +01:00
|
|
|
{
|
|
|
|
$system = System::getInstance();
|
|
|
|
|
|
|
|
if ($system->checkACL($this->acl)) {
|
2020-12-18 13:23:35 +01:00
|
|
|
$this->allowed = true;
|
2019-01-30 16:18:44 +01:00
|
|
|
} else {
|
2020-12-18 13:23:35 +01:00
|
|
|
$this->allowed = false;
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
/**
|
|
|
|
* Prepare filters for current view.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
private function getFilters()
|
|
|
|
{
|
|
|
|
$system = System::getInstance();
|
|
|
|
$user = User::getInstance();
|
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
$this->defaultFilters['group'] = true;
|
|
|
|
$this->defaultFilters['type'] = true;
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
$this->group = (int) $system->getRequest('group', __('Group'));
|
|
|
|
if (!$user->isInGroup($this->acl, $this->group)) {
|
|
|
|
$this->group = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($this->group === __('Group')) || ($this->group == 0)) {
|
|
|
|
$this->group = 0;
|
|
|
|
} else {
|
|
|
|
$this->default = false;
|
2020-12-18 13:23:35 +01:00
|
|
|
$this->defaultFilters['group'] = false;
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->type = $system->getRequest('type', __('Type'));
|
|
|
|
if (($this->type === __('Type')) || ($this->type === '0')) {
|
|
|
|
$this->type = '0';
|
|
|
|
} else {
|
|
|
|
$this->default = false;
|
2020-12-18 13:23:35 +01:00
|
|
|
$this->defaultFilters['type'] = false;
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
/**
|
|
|
|
* Run view.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
public function show()
|
|
|
|
{
|
2020-12-18 13:23:35 +01:00
|
|
|
if (!$this->allowed) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$this->show_fail_acl();
|
|
|
|
} else {
|
|
|
|
$this->getFilters();
|
|
|
|
$this->show_visualmaps();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
/**
|
|
|
|
* Show a message about failed ACL access.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
private function show_fail_acl()
|
|
|
|
{
|
|
|
|
$error['type'] = 'onStart';
|
|
|
|
$error['title_text'] = __('You don\'t have access to this page');
|
|
|
|
$error['content_text'] = System::getDefaultACLFailText();
|
2020-12-18 13:23:35 +01:00
|
|
|
|
|
|
|
// Redirect to main page.
|
|
|
|
if (class_exists('HomeEnterprise') === true) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$home = new HomeEnterprise();
|
|
|
|
} else {
|
|
|
|
$home = new Home();
|
|
|
|
}
|
|
|
|
|
|
|
|
$home->show($error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
/**
|
|
|
|
* Show visual console list header.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
private function show_visualmaps()
|
|
|
|
{
|
|
|
|
$ui = Ui::getInstance();
|
|
|
|
|
|
|
|
$ui->createPage();
|
|
|
|
$ui->createDefaultHeader(
|
|
|
|
__('Visual consoles'),
|
|
|
|
$ui->createHeaderButton(
|
|
|
|
[
|
2022-02-07 12:29:57 +01:00
|
|
|
'icon' => 'ui-icon-back',
|
|
|
|
'pos' => 'left',
|
|
|
|
'text' => __('Back'),
|
|
|
|
'href' => 'index.php?page=home',
|
|
|
|
'class' => 'header-button-left',
|
2019-01-30 16:18:44 +01:00
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$ui->showFooter(false);
|
|
|
|
$ui->beginContent();
|
|
|
|
$this->listVisualmapsHtml();
|
|
|
|
$ui->endContent();
|
|
|
|
$ui->showPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
/**
|
|
|
|
* Show list of visual consoles.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
private function listVisualmapsHtml()
|
|
|
|
{
|
|
|
|
$system = System::getInstance();
|
|
|
|
$ui = Ui::getInstance();
|
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
$visualmaps = visual_map_get_user_layouts();
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2020-12-18 13:23:35 +01:00
|
|
|
if (empty($visualmaps) === true) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$ui->contentAddHtml('<p style="color: #ff0000;">'.__('No maps defined').'</p>');
|
|
|
|
} else {
|
|
|
|
$table = new Table();
|
2020-12-18 13:23:35 +01:00
|
|
|
// Without header jquery.mobile crashes.
|
|
|
|
$table->addHeader(['']);
|
2019-01-30 16:18:44 +01:00
|
|
|
$table->id = 'list_visualmaps';
|
2020-12-18 13:23:35 +01:00
|
|
|
foreach ($visualmaps as $map) {
|
|
|
|
$link = '<a class="ui-link" data-ajax="false" ';
|
|
|
|
$link .= ' href="index.php?page=visualmap&id=';
|
|
|
|
$link .= $map['id'].'">'.io_safe_output($map['name']).'</a>';
|
|
|
|
|
|
|
|
$row = $link;
|
|
|
|
$row .= ui_print_group_icon(
|
|
|
|
$map['id_group'],
|
|
|
|
true,
|
|
|
|
'groups_small',
|
|
|
|
'',
|
|
|
|
false
|
|
|
|
);
|
|
|
|
$table->addRow([ $map['id'].' flex-center' => $row]);
|
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$ui->contentAddHtml($table->getHTML());
|
2020-12-18 13:23:35 +01:00
|
|
|
$ui->contentAddLinkListener('list_visualmaps');
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-06 18:39:39 +01:00
|
|
|
}
|