2013-07-16 15:39:47 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
/**
|
2013-10-23 15:10:33 +02:00
|
|
|
* This file is part of Icinga Web 2.
|
|
|
|
*
|
|
|
|
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
|
|
* Copyright (C) 2013 Icinga Development Team
|
|
|
|
*
|
|
|
|
* 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; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
|
|
|
*
|
|
|
|
*/
|
2013-07-16 15:39:47 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2013-08-20 15:32:25 +02:00
|
|
|
namespace Icinga\Module\Monitoring\Form\Command;
|
2013-07-16 15:39:47 +02:00
|
|
|
|
2013-10-08 14:19:14 +02:00
|
|
|
use Zend_Config;
|
2013-10-19 13:24:36 +02:00
|
|
|
use Zend_Controller_Request_Abstract;
|
2013-10-08 14:19:14 +02:00
|
|
|
use Zend_Form_Element_Hidden;
|
|
|
|
use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
|
|
|
|
use Icinga\Web\Form;
|
2013-07-16 15:39:47 +02:00
|
|
|
|
|
|
|
/**
|
2013-07-23 17:09:06 +02:00
|
|
|
* Simple confirmation command
|
2013-07-16 15:39:47 +02:00
|
|
|
*/
|
2013-10-08 14:19:14 +02:00
|
|
|
abstract class CommandForm extends Form
|
2013-07-16 15:39:47 +02:00
|
|
|
{
|
2013-10-19 13:24:36 +02:00
|
|
|
/**
|
|
|
|
* If the form is for a global command
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $globalCommand = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set command program wide
|
|
|
|
*
|
|
|
|
* @param bool $flag
|
|
|
|
*/
|
|
|
|
public function setProvideGlobalCommand($flag = true)
|
|
|
|
{
|
|
|
|
$this->globalCommand = (boolean) $flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for globalCommand
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function provideGlobalCommand()
|
|
|
|
{
|
|
|
|
return (boolean) $this->globalCommand;
|
|
|
|
}
|
|
|
|
|
2013-07-17 14:08:07 +02:00
|
|
|
/**
|
|
|
|
* Create an instance name containing hidden field
|
2013-08-28 14:42:31 +02:00
|
|
|
*
|
2013-07-17 14:08:07 +02:00
|
|
|
* @return Zend_Form_Element_Hidden
|
|
|
|
*/
|
|
|
|
private function createInstanceHiddenField()
|
|
|
|
{
|
|
|
|
$field = new Zend_Form_Element_Hidden('instance');
|
|
|
|
$value = $this->getRequest()->getParam($field->getName());
|
|
|
|
$field->setValue($value);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
2013-07-16 15:39:47 +02:00
|
|
|
/**
|
|
|
|
* Add elements to this form (used by extending classes)
|
2013-07-31 17:03:21 +02:00
|
|
|
*
|
2013-07-23 17:09:06 +02:00
|
|
|
* @see Form::create
|
2013-07-16 15:39:47 +02:00
|
|
|
*/
|
|
|
|
protected function create()
|
|
|
|
{
|
2013-07-17 14:08:07 +02:00
|
|
|
$this->addElement($this->createInstanceHiddenField());
|
2013-07-16 15:39:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the author name
|
2013-09-04 18:27:16 +02:00
|
|
|
*
|
2013-08-28 14:42:31 +02:00
|
|
|
* @return string
|
2013-07-16 15:39:47 +02:00
|
|
|
*/
|
|
|
|
protected function getAuthorName()
|
|
|
|
{
|
2013-08-01 17:49:17 +02:00
|
|
|
if (is_a($this->getRequest(), "Zend_Controller_Request_HttpTestCase")) {
|
|
|
|
return "Test user";
|
|
|
|
}
|
2013-07-31 17:03:21 +02:00
|
|
|
return $this->getRequest()->getUser()->getUsername();
|
2013-07-16 15:39:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creator for author field
|
2013-07-31 17:03:21 +02:00
|
|
|
*
|
2013-07-16 15:39:47 +02:00
|
|
|
* @return Zend_Form_Element_Hidden
|
|
|
|
*/
|
|
|
|
protected function createAuthorField()
|
|
|
|
{
|
|
|
|
$authorName = $this->getAuthorName();
|
|
|
|
|
|
|
|
$authorField = new Zend_Form_Element_Hidden(
|
|
|
|
array(
|
2013-07-18 18:00:44 +02:00
|
|
|
'name' => 'author',
|
2013-08-15 15:35:17 +02:00
|
|
|
'label' => t('Author (Your Name)'),
|
2013-07-18 18:00:44 +02:00
|
|
|
'value' => $authorName,
|
|
|
|
'required' => true
|
2013-07-16 15:39:47 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$authorField->addDecorator(
|
|
|
|
'Callback',
|
|
|
|
array(
|
|
|
|
'callback' => function () use ($authorName) {
|
|
|
|
return sprintf('<strong>%s</strong>', $authorName);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $authorField;
|
|
|
|
}
|
2013-08-30 10:37:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of valid datetime formats
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getValidDateTimeFormats()
|
|
|
|
{
|
|
|
|
$config = $this->getConfiguration();
|
|
|
|
$global = $config->global;
|
|
|
|
if ($global === null) {
|
|
|
|
$global = new Zend_Config(array());
|
|
|
|
}
|
|
|
|
$preferences = $this->getUserPreferences();
|
|
|
|
return array(
|
|
|
|
implode(
|
|
|
|
' ',
|
|
|
|
array(
|
|
|
|
$preferences->get('app.dateFormat', $global->get('dateFormat', 'd/m/Y')),
|
|
|
|
$preferences->get('app.timeFormat', $global->get('timeFormat', 'g:i A'))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2013-10-08 14:19:14 +02:00
|
|
|
|
2013-10-19 13:24:36 +02:00
|
|
|
/**
|
|
|
|
* Sets the form to global if we have data in the request
|
|
|
|
*
|
|
|
|
* @param Zend_Controller_Request_Abstract $request
|
|
|
|
*/
|
|
|
|
public function setRequest(Zend_Controller_Request_Abstract $request)
|
|
|
|
{
|
|
|
|
parent::setRequest($request);
|
|
|
|
|
|
|
|
if ($request->getParam('global')) {
|
|
|
|
$this->setProvideGlobalCommand(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-08 14:19:14 +02:00
|
|
|
/**
|
|
|
|
* Create command object for CommandPipe protocol
|
|
|
|
*
|
|
|
|
* @return AcknowledgeCommand
|
|
|
|
*/
|
|
|
|
abstract public function createCommand();
|
2013-07-17 14:08:07 +02:00
|
|
|
}
|