2015-06-01 17:00:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|
|
|
|
|
|
|
class IcingaUserForm extends DirectorObjectForm
|
|
|
|
{
|
|
|
|
public function setup()
|
|
|
|
{
|
2016-03-10 19:28:31 +01:00
|
|
|
$this->addObjectTypeElement();
|
|
|
|
if (! $this->hasObjectType()) {
|
2016-03-10 20:44:12 +01:00
|
|
|
return $this->groupMainProperties();
|
2016-03-10 19:28:31 +01:00
|
|
|
}
|
2015-06-01 17:00:02 +02:00
|
|
|
|
2016-03-10 19:28:31 +01:00
|
|
|
if ($this->isTemplate()) {
|
2015-06-01 17:00:02 +02:00
|
|
|
$this->addElement('text', 'object_name', array(
|
|
|
|
'label' => $this->translate('User template name'),
|
|
|
|
'required' => true,
|
|
|
|
'description' => $this->translate('User for the Icinga host template you are going to create')
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
$this->addElement('text', 'object_name', array(
|
|
|
|
'label' => $this->translate('Username'),
|
|
|
|
'required' => true,
|
|
|
|
'description' => $this->translate('Username for the Icinga host you are going to create')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->addElement('text', 'email', array(
|
|
|
|
'label' => $this->translate('Email'),
|
|
|
|
'description' => $this->translate('The Email address of the user.')
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->addElement('text', 'pager', array(
|
|
|
|
'label' => $this->translate('Pager'),
|
|
|
|
'description' => $this->translate('The pager address of the user.')
|
|
|
|
));
|
|
|
|
|
2016-03-10 20:44:12 +01:00
|
|
|
$this->addGroupsElement()
|
|
|
|
->addImportsElement()
|
2016-03-16 12:31:23 +01:00
|
|
|
->addDisplayNameElement()
|
2016-03-10 20:44:12 +01:00
|
|
|
->addEnableNotificationsElement()
|
|
|
|
->addDisabledElement()
|
|
|
|
->addEventFilterElements()
|
|
|
|
->groupMainProperties()
|
|
|
|
->setButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function addEnableNotificationsElement()
|
|
|
|
{
|
2016-03-10 19:28:31 +01:00
|
|
|
$this->optionalBoolean(
|
|
|
|
'enable_notifications',
|
|
|
|
$this->translate('Send notifications'),
|
|
|
|
$this->translate('Whether to send notifications for this user')
|
|
|
|
);
|
|
|
|
|
2016-03-10 20:44:12 +01:00
|
|
|
return $this;
|
2016-03-10 19:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function addGroupsElement()
|
|
|
|
{
|
|
|
|
$groups = $this->enumUsergroups();
|
|
|
|
|
|
|
|
if (empty($groups)) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-03-05 16:21:35 +01:00
|
|
|
$this->addElement('extensibleSet', 'groups', array(
|
|
|
|
'label' => $this->translate('Groups'),
|
2016-03-10 19:28:31 +01:00
|
|
|
'multiOptions' => $this->optionallyAddFromEnum($groups),
|
2016-03-05 16:21:35 +01:00
|
|
|
'positional' => false,
|
|
|
|
'description' => $this->translate(
|
|
|
|
'User groups that should be directly assigned to this user. Groups can be useful'
|
|
|
|
. ' for various reasons. You might prefer to send notifications to groups instead of'
|
|
|
|
. ' single users'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
2016-03-10 19:28:31 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2016-02-28 17:02:57 +01:00
|
|
|
|
2016-03-16 12:31:23 +01:00
|
|
|
protected function addDisplayNameElement()
|
|
|
|
{
|
|
|
|
if ($this->isTemplate()) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->addElement('text', 'display_name', array(
|
|
|
|
'label' => $this->translate('Display name'),
|
|
|
|
'description' => $this->translate(
|
|
|
|
'Alternative name for this user. In case your object name is a'
|
|
|
|
. ' username, this could be the full name of the corresponding person'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-03-10 19:28:31 +01:00
|
|
|
protected function groupObjectDefinition()
|
|
|
|
{
|
|
|
|
$elements = array(
|
|
|
|
'object_type',
|
|
|
|
'object_name',
|
|
|
|
'display_name',
|
|
|
|
'imports',
|
|
|
|
'groups',
|
|
|
|
'email',
|
|
|
|
'pager',
|
|
|
|
'enable_notifications',
|
|
|
|
'disabled',
|
|
|
|
);
|
|
|
|
$this->addDisplayGroup($elements, 'object_definition', array(
|
|
|
|
'decorators' => array(
|
|
|
|
'FormElements',
|
|
|
|
array('HtmlTag', array('tag' => 'dl')),
|
|
|
|
'Fieldset',
|
|
|
|
),
|
|
|
|
'order' => 20,
|
|
|
|
'legend' => $this->translate('User properties')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2016-03-05 16:21:35 +01:00
|
|
|
protected function enumUsergroups()
|
|
|
|
{
|
|
|
|
$db = $this->db->getDbAdapter();
|
|
|
|
$select = $db->select()->from(
|
|
|
|
'icinga_usergroup',
|
|
|
|
array(
|
|
|
|
'name' => 'object_name',
|
|
|
|
'display' => 'COALESCE(display_name, object_name)'
|
|
|
|
)
|
|
|
|
)->where('object_type = ?', 'object')->order('display');
|
|
|
|
|
|
|
|
return $db->fetchPairs($select);
|
|
|
|
}
|
2015-06-01 17:00:02 +02:00
|
|
|
}
|