2017-06-19 01:07:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Web\Tabs;
|
|
|
|
|
|
|
|
use Icinga\Authentication\Auth;
|
|
|
|
use Icinga\Module\Director\Objects\IcingaObject;
|
2017-10-09 15:23:27 +02:00
|
|
|
use dipl\Translation\TranslationHelper;
|
|
|
|
use dipl\Web\Widget\Tabs;
|
2017-06-19 01:07:57 +02:00
|
|
|
|
|
|
|
class ObjectsTabs extends Tabs
|
|
|
|
{
|
|
|
|
use TranslationHelper;
|
|
|
|
|
|
|
|
public function __construct($type, Auth $auth)
|
|
|
|
{
|
|
|
|
$object = IcingaObject::createByType($type);
|
|
|
|
if ($object->isGroup()) {
|
|
|
|
$object = IcingaObject::createByType(substr($type, 0, -5));
|
|
|
|
}
|
|
|
|
|
2017-08-25 22:42:38 +02:00
|
|
|
$plType = strtolower(preg_replace('/cys$/', 'cies', $type . 's'));
|
|
|
|
if ($auth->hasPermission("director/${plType}")) {
|
2017-08-07 11:00:59 +02:00
|
|
|
$this->add('index', array(
|
2017-08-25 22:42:38 +02:00
|
|
|
'url' => sprintf('director/%s', $plType),
|
|
|
|
'label' => $this->translate(ucfirst($plType)),
|
2017-08-07 11:00:59 +02:00
|
|
|
));
|
|
|
|
}
|
2017-06-19 01:07:57 +02:00
|
|
|
|
2017-07-31 10:37:08 +02:00
|
|
|
if ($object->getShortTableName() === 'command') {
|
|
|
|
$this->add('external', array(
|
2017-08-25 22:42:38 +02:00
|
|
|
'url' => sprintf('director/%s', strtolower($plType)),
|
2017-07-31 10:37:08 +02:00
|
|
|
'urlParams' => ['type' => 'external_object'],
|
|
|
|
'label' => $this->translate('External'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2017-07-28 22:42:16 +02:00
|
|
|
if ($auth->hasPermission('director/admin') || (
|
2017-08-25 22:42:38 +02:00
|
|
|
$object->getShortTableName() === 'notification'
|
|
|
|
&& $auth->hasPermission('director/notifications')
|
|
|
|
)) {
|
2017-07-28 22:42:16 +02:00
|
|
|
if ($object->supportsApplyRules()) {
|
|
|
|
$this->add('applyrules', array(
|
2017-08-25 22:42:38 +02:00
|
|
|
'url' => sprintf('director/%s/applyrules', $plType),
|
2017-07-28 22:42:16 +02:00
|
|
|
'label' => $this->translate('Apply')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 09:06:21 +02:00
|
|
|
if ($auth->hasPermission('director/admin') && $type !== 'zone') {
|
2017-06-19 01:07:57 +02:00
|
|
|
if ($object->supportsImports()) {
|
|
|
|
$this->add('templates', array(
|
2017-08-25 22:42:38 +02:00
|
|
|
'url' => sprintf('director/%s/templates', $plType),
|
2017-06-19 01:07:57 +02:00
|
|
|
'label' => $this->translate('Templates'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($object->supportsGroups()) {
|
|
|
|
$this->add('groups', array(
|
2017-07-14 11:26:59 +02:00
|
|
|
'url' => sprintf('director/%sgroups', $type),
|
2017-06-19 01:07:57 +02:00
|
|
|
'label' => $this->translate('Groups')
|
|
|
|
));
|
|
|
|
}
|
2017-07-14 11:26:59 +02:00
|
|
|
}
|
2017-06-19 01:07:57 +02:00
|
|
|
|
2017-07-14 11:26:59 +02:00
|
|
|
if ($auth->hasPermission('director/admin')) {
|
2017-06-29 14:06:32 +02:00
|
|
|
if ($object->supportsChoices()) {
|
|
|
|
$this->add('choices', array(
|
2017-08-07 11:00:59 +02:00
|
|
|
'url' => sprintf('director/templatechoices/%s', $type),
|
2017-06-29 14:06:32 +02:00
|
|
|
'label' => $this->translate('Choices')
|
|
|
|
));
|
|
|
|
}
|
2017-08-07 11:00:59 +02:00
|
|
|
}
|
2017-10-12 16:26:50 +02:00
|
|
|
if ($object->supportsSets() && $auth->hasPermission("director/${type}sets")) {
|
2017-08-07 11:00:59 +02:00
|
|
|
$this->add('sets', array(
|
2017-08-25 22:42:38 +02:00
|
|
|
'url' => sprintf('director/%s/sets', $plType),
|
2017-08-07 11:00:59 +02:00
|
|
|
'label' => $this->translate('Sets')
|
|
|
|
));
|
2017-06-19 01:07:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|