2014-08-29 12:25:25 +02:00
|
|
|
<?php
|
2015-02-03 16:27:59 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | http://www.gnu.org/licenses/gpl-2.0.txt */
|
2014-08-29 12:25:25 +02:00
|
|
|
|
2014-11-14 10:57:14 +01:00
|
|
|
namespace Icinga\Forms;
|
2014-08-29 12:25:25 +02:00
|
|
|
|
|
|
|
use Exception;
|
2014-11-04 14:48:24 +01:00
|
|
|
use Zend_Form_Decorator_Abstract;
|
2014-08-29 12:25:25 +02:00
|
|
|
use Icinga\Web\Form;
|
|
|
|
use Icinga\Application\Config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Form base-class providing standard functionality for configuration forms
|
|
|
|
*/
|
|
|
|
class ConfigForm extends Form
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The configuration to work with
|
|
|
|
*
|
|
|
|
* @var Config
|
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the configuration to use when populating the form or when saving the user's input
|
|
|
|
*
|
|
|
|
* @param Config $config The configuration to use
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
2014-09-08 13:31:25 +02:00
|
|
|
public function setIniConfig(Config $config)
|
2014-08-29 12:25:25 +02:00
|
|
|
{
|
|
|
|
$this->config = $config;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Persist the current configuration to disk
|
|
|
|
*
|
|
|
|
* If an error occurs the user is shown a view describing the issue and displaying the raw INI configuration.
|
|
|
|
*
|
|
|
|
* @return bool Whether the configuration could be persisted
|
|
|
|
*/
|
|
|
|
public function save()
|
|
|
|
{
|
|
|
|
try {
|
2015-01-30 09:32:08 +01:00
|
|
|
$this->config->saveIni();
|
2014-08-29 12:25:25 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->addDecorator('ViewScript', array(
|
2014-09-09 13:22:51 +02:00
|
|
|
'viewModule' => 'default',
|
2014-08-29 12:25:25 +02:00
|
|
|
'viewScript' => 'showConfiguration.phtml',
|
|
|
|
'errorMessage' => $e->getMessage(),
|
2015-01-30 09:32:08 +01:00
|
|
|
'configString' => $this->config,
|
2014-11-04 14:48:24 +01:00
|
|
|
'filePath' => $this->config->getConfigFile(),
|
|
|
|
'placement' => Zend_Form_Decorator_Abstract::PREPEND
|
2014-08-29 12:25:25 +02:00
|
|
|
));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|