~ubuntu-branches/ubuntu/saucy/horde3/saucy

« back to all changes in this revision

Viewing changes to admin/setup/config.php

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-05-04 23:08:08 UTC
  • Revision ID: james.westby@ubuntu.com-20050504230808-p4hf3hk28o3v7wir
Tags: upstream-3.0.4
ImportĀ upstreamĀ versionĀ 3.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * $Horde: horde/admin/setup/config.php,v 1.24.4.3 2005/01/31 09:28:27 jan Exp $
 
4
 *
 
5
 * Copyright 1999-2005 Charles J. Hagenbuch <chuck@horde.org>
 
6
 * Copyright 1999-2005 Jon Parise <jon@horde.org>
 
7
 *
 
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.
 
10
 */
 
11
 
 
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';
 
19
 
 
20
if (!Auth::isAdmin()) {
 
21
    Horde::fatal('Forbidden.', __FILE__, __LINE__);
 
22
}
 
23
 
 
24
if (!Util::extensionExists('domxml') && !Util::extensionExists('dom')) {
 
25
    Horde::fatal('You need the domxml PHP extension to use the configuration tool.', __FILE__, __LINE__);
 
26
}
 
27
 
 
28
$app = Util::getFormData('app');
 
29
$appname = $registry->get('name', $app);
 
30
$title = sprintf(_("%s Setup"), $appname);
 
31
 
 
32
if ($app === null &&
 
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);
 
37
    exit;
 
38
}
 
39
 
 
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"));
 
45
}
 
46
 
 
47
$php = '';
 
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');
 
53
    } else {
 
54
        $notification->push(_("Could not revert configuration."), 'horde.error');
 
55
    }
 
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');
 
63
        } else {
 
64
            $notification->push(sprintf(_("Could not save the backup configuration file %s."), $path .'/conf.php.bak'), 'horde.warning');
 
65
        }
 
66
    }
 
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'));
 
70
        fclose($fp);
 
71
        $notification->push(sprintf(_("Successfully wrote %s"), $path . '/conf.php'), 'horde.success');
 
72
    } else {
 
73
        /* Can not write. */
 
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;
 
77
    }
 
78
} elseif ($form->isSubmitted()) {
 
79
    $notification->push(_("There was an error in the configuration form. Perhaps you left out a required field."), 'horde.error');
 
80
}
 
81
 
 
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');
 
87
 
 
88
 
 
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);
 
100
}
 
101
$template->set('form', $form);
 
102
$template->set('notify', Util::bufferOutput(array($notification, 'notify')));
 
103
$template->setOption('gettext', true);
 
104
 
 
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';