/** * Constructor. * * @param Horde_Variables &$vars The variables object of this form. * @param string $app The name of the application that this * configuration form is for. * @param boolean $fillvars Whether to fill the $vars object with * values from the existing configuration. */ public function __construct(&$vars, $app, $fillvars = false) { parent::__construct($vars); $this->_xmlConfig = new Horde_Config($app); $this->_vars =& $vars; $this->_fillvars = $fillvars; if ($fillvars) { $vars->app = $app; } $config = $this->_xmlConfig->readXMLConfig(); $this->addHidden('', 'app', 'text', true); $this->_buildVariables($config); }
/** * Perform all functions for this task. */ public function execute() { global $notification, $registry; $hconfig = new Horde_Config(); try { $versions = $hconfig->checkVersions(); foreach ($versions as &$app) { $app['version'] = preg_replace('/H\\d \\((.*)\\)/', '$1', $app['version']); } } catch (Horde_Exception $e) { return; } $pearConfig = PEAR_Config::singleton(); $packageFile = new PEAR_PackageFile($pearConfig); $packages = array(); foreach ($pearConfig->getRegistry()->packageInfo(null, null, 'pear.horde.org') as $package) { $packages[$package['name']] = $package['version']['release']; } $configLink = Horde::link(Horde::url('admin/config/index.php', false, array('app' => 'horde'))); if (class_exists('Horde_Bundle') && isset($versions[Horde_Bundle::NAME]) && version_compare($versions[Horde_Bundle::NAME]['version'], Horde_Bundle::VERSION, '>')) { $notification->push($configLink . sprintf(_("A newer version of %s exists."), Horde_Bundle::FULLNAME) . '</a>', 'horde.warning', array('content.raw', 'sticky')); return; } foreach ($registry->listAllApps() as $app) { if (($version = $registry->getVersion($app, true)) && isset($versions[$app]) && version_compare($versions[$app]['version'], $version, '>')) { $notification->push($configLink . _("A newer version of an application exists.") . '</a>', 'horde.warning', array('content.raw', 'sticky')); return; } } foreach ($packages as $app => $version) { if (isset($versions[$app]) && version_compare($versions[$app]['version'], $version, '>')) { $notification->push($configLink . _("A newer version of a library exists.") . '</a>', 'horde.warning', array('content.raw', 'sticky')); return; } } }
} $php = ''; $path = $registry->get('fileroot', $app) . '/config'; $configFile = $path . '/conf.php'; if (is_link($configFile)) { $configFile = readlink($configFile); } if ($vars->submitbutton == _("Revert Configuration")) { if (@copy($path . '/conf.bak.php', $configFile)) { $notification->push(_("Successfully reverted configuration. Reload to see changes."), 'horde.success'); @unlink($path . '/conf.bak.php'); } else { $notification->push(_("Could not revert configuration."), 'horde.error'); } } elseif ($form->validate($vars)) { $config = new Horde_Config($app); if ($config->writePHPConfig($vars, $php)) { Horde::url('admin/config/index.php', true)->redirect(); } else { $notification->push(sprintf(_("Could not save the configuration file %s. You can either use one of the options to save the code back on %s or copy manually the code below to %s."), Horde_Util::realPath($configFile), Horde::link(Horde::url('admin/config/index.php') . '#update', _("Configuration")) . _("Configuration") . '</a>', Horde_Util::realPath($configFile)), 'horde.warning', array('content.raw', 'sticky')); } } elseif ($form->isSubmitted()) { $notification->push(_("There was an error in the configuration form. Perhaps you left out a required field."), 'horde.error'); } $view = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/admin/config')); $view->addHelper('Text'); $view->php = $php; /* Create the link for the diff popup only if stored in session. */ if ($session->exists('horde', 'config/' . $app)) { $url = Horde::url('admin/config/diff.php', true)->add('app', $app); $view->diff_popup = Horde::link('#', '', '', '', Horde::popupJs($url, array('height' => 480, 'width' => 640, 'urlencode' => true)) . 'return false;') . _("show differences") . '</a>';
/** * Creates default configuration files for all installed applications. * * @throws Horde_Exception */ public function writeAllConfigs() { foreach ($GLOBALS['registry']->listAllApps() as $app) { if ($app == 'horde' || !file_exists($GLOBALS['registry']->get('fileroot', $app) . '/config/conf.xml')) { continue; } $config = new Horde_Config($app); $configFile = $config->configFile(); if (!$config->writePHPConfig(new Horde_Variables())) { throw new Horde_Exception('Cannot write configuration file ' . Horde_Util::realPath($configFile)); } } }
} catch (Horde_Exception $e) { $notification->push(_("Could not contact server. Try again later."), 'horde.error'); } } /* Update configurations if requested. */ if ($vars->action == 'config') { foreach ($a as $app) { $path = $registry->get('fileroot', $app) . '/config'; if (!file_exists($path . '/conf.xml') || file_exists($path . '/conf.php') && ($xml_ver = $hconfig->getVersion(@file_get_contents($path . '/conf.xml'))) !== false && ($php_ver = $hconfig->getVersion(@file_get_contents($path . '/conf.php'))) !== false && $xml_ver == $php_ver) { continue; } $vars = new Horde_Variables(); $form = new Horde_Config_Form($vars, $app, true); $form->setSubmitted(true); if ($form->validate($vars)) { $config = new Horde_Config($app); if (!$config->writePHPConfig($vars)) { $notification->push(sprintf(_("Could not save the configuration file %s. Use one of the options below to save the code."), Horde_Util::realPath($config->configFile())), 'horde.warning', array('content.raw', 'sticky')); } } else { $notification->push(sprintf(_("The configuration for %s cannot be updated automatically. Please update the configuration manually."), $app), 'horde.error'); } } } /* Update schema if requested. */ if ($vars->action == 'schema') { $apps = isset($vars->app) ? array($vars->app) : $migration->apps; foreach ($apps as $app) { $migrator = $migration->getMigrator($app); if ($migrator->getTargetVersion() <= $migrator->getCurrentVersion()) { continue;