3
* $Horde: horde/admin/setup/config.php,v 1.24.4.3 2005/01/31 09:28:27 jan Exp $
5
* Copyright 1999-2005 Charles J. Hagenbuch <chuck@horde.org>
6
* Copyright 1999-2005 Jon Parise <jon@horde.org>
8
* See the enclosed file COPYING for license information (LGPL). If you
9
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
12
@define('HORDE_BASE', dirname(__FILE__) . '/../..');
13
require_once HORDE_BASE . '/lib/base.php';
14
require_once 'Horde/Form.php';
15
require_once 'Horde/Form/Action.php';
16
require_once 'Horde/Form/Renderer.php';
17
require_once 'Horde/Config.php';
18
require_once 'Horde/Variables.php';
20
if (!Auth::isAdmin()) {
21
Horde::fatal('Forbidden.', __FILE__, __LINE__);
24
if (!Util::extensionExists('domxml') && !Util::extensionExists('dom')) {
25
Horde::fatal('You need the domxml PHP extension to use the configuration tool.', __FILE__, __LINE__);
28
$app = Util::getFormData('app');
29
$appname = $registry->get('name', $app);
30
$title = sprintf(_("%s Setup"), $appname);
33
in_array($app, $registry->listApps(array('inactive', 'hidden', 'notoolbar', 'active', 'admin')))) {
34
$notification->push(_("Invalid application."), 'horde.error');
35
$url = Horde::applicationUrl('admin/setup/index.php', true);
36
header('Location: ' . $url);
40
$vars = Variables::getDefaultVariables();
41
$form = &new ConfigForm($vars, $app);
42
$form->setButtons(sprintf(_("Generate %s Configuration"), $appname));
43
if (file_exists($registry->get('fileroot', $app) . '/config/conf.php.bak')) {
44
$form->appendButtons(_("Revert Configuration"));
48
if (Util::getFormData('submitbutton') == _("Revert Configuration")) {
49
$path = $registry->get('fileroot', $app) . '/config';
50
if (@copy($path . '/conf.php.bak', $path . '/conf.php')) {
51
$notification->push(_("Successfully reverted configuration. Reload to see changes."), 'horde.success');
52
@unlink($path . '/conf.php.bak');
54
$notification->push(_("Could not revert configuration."), 'horde.error');
56
} elseif ($form->validate($vars)) {
57
$config = &new Horde_Config($app);
58
$php = $config->generatePHPConfig($vars);
59
$path = $registry->get('fileroot', $app) . '/config';
60
if (file_exists($path . '/conf.php')) {
61
if (@copy($path . '/conf.php', $path . '/conf.php.bak')) {
62
$notification->push(sprintf(_("Successfully saved the backup configuration file %s."), $path .'/conf.php.bak'), 'horde.success');
64
$notification->push(sprintf(_("Could not save the backup configuration file %s."), $path .'/conf.php.bak'), 'horde.warning');
67
if ($fp = @fopen($path . '/conf.php', 'w')) {
68
/* Can write, so output to file. */
69
fwrite($fp, String::convertCharset($php, NLS::getCharset(), 'iso-8859-1'));
71
$notification->push(sprintf(_("Successfully wrote %s"), $path . '/conf.php'), 'horde.success');
74
$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."), $path . '/conf.php', Horde::link(Horde::url('index.php') . '#update', _("Setup")) . _("Setup") . '</a>', $path . '/conf.php'), 'horde.warning', array('content.raw'));
75
/* Save to session. */
76
$_SESSION['_config'][$app] = $php;
78
} elseif ($form->isSubmitted()) {
79
$notification->push(_("There was an error in the configuration form. Perhaps you left out a required field."), 'horde.error');
82
/* Render the configuration form. */
83
require_once 'Horde/UI/VarRenderer.php';
84
$renderer = &new Horde_Form_Renderer();
85
$renderer->setAttrColumnWidth('50%');
86
$form = Util::bufferOutput(array($form, 'renderActive'), $renderer, $vars, 'config.php', 'post');
89
/* Set up the template. */
90
require_once 'Horde/Template.php';
91
$template = &new Horde_Template();
92
$template->set('php', htmlspecialchars($php), true);
93
/* Create the link for the diff popup only if stored in session. */
94
if (!empty($_SESSION['_config'][$app])) {
95
Horde::addScriptFile('popup.js', 'horde', true);
96
$url = Horde::applicationUrl('admin/setup/diff.php');
97
$url = Util::addParameter($url, 'app', $app);
98
$link = Horde::link('', _("show differences"), '', '', 'popup(\'' . $url . '\',640, 480); return false;') . _("show differences") . '</a>';
99
$template->set('diff_popup', $link);
101
$template->set('form', $form);
102
$template->set('notify', Util::bufferOutput(array($notification, 'notify')));
103
$template->setOption('gettext', true);
105
require HORDE_TEMPLATES . '/common-header.inc';
106
require HORDE_TEMPLATES . '/admin/common-header.inc';
107
echo $template->fetch(HORDE_TEMPLATES . '/admin/setup/config.html');
108
require HORDE_TEMPLATES . '/common-footer.inc';