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

« back to all changes in this revision

Viewing changes to admin/setup/diff.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
 * Script to show the differences between the currently saved and the newly
 
4
 * generated configuration.
 
5
 *
 
6
 * $Horde: horde/admin/setup/diff.php,v 1.4.10.1 2005/01/03 12:25:29 jan Exp $
 
7
 *
 
8
 * Copyright 2004-2005 The Horde Project (http://www.horde.org/)
 
9
 *
 
10
 * See the enclosed file COPYING for license information (LGPL).  If you
 
11
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 
12
 */
 
13
 
 
14
define('HORDE_BASE', dirname(__FILE__) . '/../..');
 
15
require_once HORDE_BASE . '/lib/base.php';
 
16
require_once 'Horde/Form.php';
 
17
require_once 'Horde/Config.php';
 
18
require_once 'Horde/Template.php';
 
19
include_once 'Text/Diff.php';
 
20
include_once 'Text/Diff/Renderer.php';
 
21
 
 
22
if (!Auth::isAdmin()) {
 
23
    Horde::fatal('Forbidden.', __FILE__, __LINE__);
 
24
}
 
25
 
 
26
/* Set up the diff renderer. */
 
27
$render_type = Util::getFormData('render', 'inline');
 
28
include_once 'Text/Diff/Renderer/' . $render_type . '.php';
 
29
$class = 'Text_Diff_Renderer_' . $render_type;
 
30
$renderer = &new $class();
 
31
 
 
32
/**
 
33
 * Private function to render the differences for a specific app.
 
34
 */
 
35
function _getDiff($app)
 
36
{
 
37
    global $renderer, $registry;
 
38
 
 
39
    /* Read the existing configuration. */
 
40
    $current_config = '';
 
41
    $path = $registry->get('fileroot', $app) . '/config';
 
42
    $size = @filesize($path . '/conf.php');
 
43
    if ($size && is_resource($fp = @fopen($path . '/conf.php', 'r'))) {
 
44
        $current_config = @fread($fp, $size);
 
45
    }
 
46
 
 
47
    /* Calculate the differences. */
 
48
    $diff = &new Text_Diff(explode("\n", htmlentities($current_config)),
 
49
                           explode("\n", htmlentities($_SESSION['_config'][$app])));
 
50
    //return nl2br($renderer->render($diff)); 
 
51
    $diff = $renderer->render($diff);
 
52
    if (!empty($diff)) {
 
53
        return $diff;
 
54
    } else {
 
55
        return _("No change.");
 
56
    } 
 
57
}
 
58
 
 
59
$diffs = array();
 
60
/* Only bother to do anything if there is any config. */
 
61
if (!empty($_SESSION['_config'])) {
 
62
    /* Set up the toggle button for inline/unified. */
 
63
    $url = Horde::applicationUrl('admin/setup/diff.php');
 
64
    $url = Util::addParameter($url, 'render', ($render_type == 'inline') ? 'unified' : 'inline');
 
65
 
 
66
    if ($app = Util::getFormData('app')) {
 
67
        /* Handle a single app request. */
 
68
        $toggle_renderer = Horde::link($url . '#' . $app) . (($render_type == 'inline') ? _("unified") : _("inline")) . '</a>';
 
69
        $diffs[] = array('app'  => $app,
 
70
                         'diff' => _getDiff($app),
 
71
                         'toggle_renderer' => $toggle_renderer);
 
72
    } else {
 
73
        /* List all the apps with generated configuration. */
 
74
        ksort($_SESSION['_config']);
 
75
        foreach ($_SESSION['_config'] as $app => $config) {
 
76
            $toggle_renderer = Horde::link($url . '#' . $app) . (($render_type == 'inline') ? _("unified") : _("inline")) . '</a>';
 
77
            $diffs[] = array('app'  => $app,
 
78
                             'diff' => _getDiff($app),
 
79
                             'toggle_renderer' => $toggle_renderer);
 
80
        }
 
81
    }
 
82
}
 
83
 
 
84
/* Set up the template. */
 
85
$template = &new Horde_Template();
 
86
$template->setOption('gettext', true);
 
87
$template->set('diffs', $diffs, true);
 
88
 
 
89
$title = _("Configuration Differences");
 
90
require HORDE_TEMPLATES . '/common-header.inc';
 
91
echo $template->fetch(HORDE_TEMPLATES . '/admin/setup/diff.html');
 
92
require HORDE_TEMPLATES . '/common-footer.inc';