pandorafms/pandora_console/mobile/operation/visualmaps.php

237 lines
5.9 KiB
PHP
Raw Normal View History

<?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.
ob_start();
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.
*/
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
*/
private $acl = 'VR';
2020-12-18 13:23:35 +01:00
/**
* Default filters.
*
* @var array
*/
private $defaultFilters = [];
/**
* Group.
*
* @var integer
*/
private $group = 0;
2020-12-18 13:23:35 +01:00
/**
* Type. Something about filtering.
*
* @var boolean
*/
private $type = 0;
2020-12-18 13:23:35 +01:00
/**
* Builder.
*/
public function __construct()
{
$system = System::getInstance();
if ($system->checkACL($this->acl)) {
2020-12-18 13:23:35 +01:00
$this->allowed = true;
} else {
2020-12-18 13:23:35 +01:00
$this->allowed = false;
}
}
2020-12-18 13:23:35 +01:00
/**
* Prepare filters for current view.
*
* @return void
*/
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;
$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;
}
$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;
}
}
2020-12-18 13:23:35 +01:00
/**
* Run view.
*
* @return void
*/
public function show()
{
2020-12-18 13:23:35 +01:00
if (!$this->allowed) {
$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
*/
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) {
$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
*/
private function show_visualmaps()
{
$ui = Ui::getInstance();
$ui->createPage();
$ui->createDefaultHeader(
__('Visual consoles'),
$ui->createHeaderButton(
[
'icon' => 'back',
'pos' => 'left',
'text' => __('Back'),
'href' => 'index.php?page=home',
]
)
);
$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
*/
private function listVisualmapsHtml()
{
$system = System::getInstance();
$ui = Ui::getInstance();
2020-12-18 13:23:35 +01:00
$visualmaps = visual_map_get_user_layouts();
2020-12-18 13:23:35 +01:00
if (empty($visualmaps) === true) {
$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(['']);
$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]);
}
$ui->contentAddHtml($table->getHTML());
2020-12-18 13:23:35 +01:00
$ui->contentAddLinkListener('list_visualmaps');
}
}
}