2018-07-09 09:33:20 -04:00
|
|
|
<?php
|
2026-03-26 12:46:27 -04:00
|
|
|
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2018-07-09 09:33:20 -04:00
|
|
|
|
|
|
|
|
namespace Icinga\Web\Widget;
|
|
|
|
|
|
2018-07-09 09:59:27 -04:00
|
|
|
use Icinga\Application\Config;
|
2018-07-09 09:33:20 -04:00
|
|
|
use Icinga\Application\Hook\ApplicationStateHook;
|
2018-07-09 09:59:27 -04:00
|
|
|
use Icinga\Authentication\Auth;
|
2018-07-09 09:33:20 -04:00
|
|
|
use Icinga\Forms\AcknowledgeApplicationStateMessageForm;
|
|
|
|
|
use Icinga\Web\ApplicationStateCookie;
|
2019-06-04 09:32:00 -04:00
|
|
|
use Icinga\Web\Helper\Markdown;
|
2018-07-09 09:33:20 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Render application state messages
|
|
|
|
|
*/
|
|
|
|
|
class ApplicationStateMessages extends AbstractWidget
|
|
|
|
|
{
|
|
|
|
|
protected function getMessages()
|
|
|
|
|
{
|
|
|
|
|
$cookie = new ApplicationStateCookie();
|
|
|
|
|
|
|
|
|
|
$acked = array_flip($cookie->getAcknowledgedMessages());
|
|
|
|
|
$messages = ApplicationStateHook::getAllMessages();
|
|
|
|
|
|
|
|
|
|
$active = array_diff_key($messages, $acked);
|
|
|
|
|
|
|
|
|
|
return $active;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
2018-07-09 09:59:27 -04:00
|
|
|
$enabled = Auth::getInstance()
|
|
|
|
|
->getUser()
|
|
|
|
|
->getPreferences()
|
|
|
|
|
->getValue('icingaweb', 'show_application_state_messages', 'system');
|
|
|
|
|
|
|
|
|
|
if ($enabled === 'system') {
|
|
|
|
|
$enabled = Config::app()->get('global', 'show_application_state_messages', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! (bool) $enabled) {
|
2023-07-18 04:24:39 -04:00
|
|
|
return '<div hidden></div>';
|
2018-07-09 09:59:27 -04:00
|
|
|
}
|
|
|
|
|
|
2018-07-09 09:33:20 -04:00
|
|
|
$active = $this->getMessages();
|
|
|
|
|
|
|
|
|
|
if (empty($active)) {
|
|
|
|
|
// Force container update on XHR
|
2023-07-18 04:24:39 -04:00
|
|
|
return '<div hidden></div>';
|
2018-07-09 09:33:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$html = '<div>';
|
|
|
|
|
|
|
|
|
|
reset($active);
|
|
|
|
|
|
|
|
|
|
$id = key($active);
|
|
|
|
|
$spec = current($active);
|
|
|
|
|
$message = array_pop($spec); // We don't use state and timestamp here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ackForm = new AcknowledgeApplicationStateMessageForm();
|
|
|
|
|
$ackForm->populate(['id' => $id]);
|
|
|
|
|
|
2019-07-26 09:23:41 -04:00
|
|
|
$html .= '<section class="markdown">';
|
|
|
|
|
$html .= Markdown::text($message);
|
|
|
|
|
$html .= '</section>';
|
|
|
|
|
|
|
|
|
|
$html .= $ackForm;
|
2018-07-09 09:33:20 -04:00
|
|
|
|
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
|
}
|
|
|
|
|
}
|