2014-08-29 06:25:25 -04:00
|
|
|
<?php
|
2015-02-04 04:46:36 -05:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-08-29 06:25:25 -04:00
|
|
|
|
2014-11-14 04:57:14 -05:00
|
|
|
namespace Icinga\Forms;
|
2014-08-29 06:25:25 -04:00
|
|
|
|
|
|
|
|
use Exception;
|
2014-11-04 08:48:24 -05:00
|
|
|
use Zend_Form_Decorator_Abstract;
|
2014-08-29 06:25:25 -04: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
|
|
|
|
|
*
|
2015-04-07 08:23:26 -04:00
|
|
|
* @return $this
|
2014-08-29 06:25:25 -04:00
|
|
|
*/
|
2014-09-08 07:31:25 -04:00
|
|
|
public function setIniConfig(Config $config)
|
2014-08-29 06:25:25 -04: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 03:32:08 -05:00
|
|
|
$this->config->saveIni();
|
2014-08-29 06:25:25 -04:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$this->addDecorator('ViewScript', array(
|
2014-09-09 07:22:51 -04:00
|
|
|
'viewModule' => 'default',
|
2014-08-29 06:25:25 -04:00
|
|
|
'viewScript' => 'showConfiguration.phtml',
|
|
|
|
|
'errorMessage' => $e->getMessage(),
|
2015-01-30 03:32:08 -05:00
|
|
|
'configString' => $this->config,
|
2014-11-04 08:48:24 -05:00
|
|
|
'filePath' => $this->config->getConfigFile(),
|
|
|
|
|
'placement' => Zend_Form_Decorator_Abstract::PREPEND
|
2014-08-29 06:25:25 -04:00
|
|
|
));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|