~ubuntu-branches/ubuntu/oneiric/bugzilla/oneiric

« back to all changes in this revision

Viewing changes to editparams.cgi

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Bossek
  • Date: 2008-06-27 22:34:34 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080627223434-0ib57vstn43bb4a3
Tags: 3.0.4.1-1
* Update of French, Russian and German translations. (closes: #488251)
* Added Bulgarian and Belarusian translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl -wT
2
 
# -*- Mode: perl; indent-tabs-mode: nil -*-
3
 
#
4
 
# The contents of this file are subject to the Mozilla Public
5
 
# License Version 1.1 (the "License"); you may not use this file
6
 
# except in compliance with the License. You may obtain a copy of
7
 
# the License at http://www.mozilla.org/MPL/
8
 
#
9
 
# Software distributed under the License is distributed on an "AS
10
 
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11
 
# implied. See the License for the specific language governing
12
 
# rights and limitations under the License.
13
 
#
14
 
# The Original Code is the Bugzilla Bug Tracking System.
15
 
#
16
 
# The Initial Developer of the Original Code is Netscape Communications
17
 
# Corporation. Portions created by Netscape are
18
 
# Copyright (C) 1998 Netscape Communications Corporation. All
19
 
# Rights Reserved.
20
 
#
21
 
# Contributor(s): Terry Weissman <terry@mozilla.org>
22
 
#                 J. Paul Reed <preed@sigkill.com>
23
 
#                 Frédéric Buclin <LpSolit@gmail.com>
24
 
 
25
 
use strict;
26
 
use lib ".";
27
 
 
28
 
use Bugzilla;
29
 
use Bugzilla::Constants;
30
 
use Bugzilla::Config qw(:admin);
31
 
use Bugzilla::Config::Common;
32
 
use Bugzilla::Util;
33
 
use Bugzilla::Error;
34
 
use Bugzilla::Token;
35
 
use Bugzilla::User;
36
 
use Bugzilla::User::Setting;
37
 
 
38
 
my $user = Bugzilla->login(LOGIN_REQUIRED);
39
 
my $cgi = Bugzilla->cgi;
40
 
my $template = Bugzilla->template;
41
 
my $vars = {};
42
 
 
43
 
print $cgi->header();
44
 
 
45
 
$user->in_group('tweakparams')
46
 
  || ThrowUserError("auth_failure", {group  => "tweakparams",
47
 
                                     action => "access",
48
 
                                     object => "parameters"});
49
 
 
50
 
my $action = trim($cgi->param('action') || '');
51
 
my $token  = $cgi->param('token');
52
 
my $current_panel = $cgi->param('section') || 'core';
53
 
$current_panel =~ /^([A-Za-z0-9_-]+)$/;
54
 
$current_panel = $1;
55
 
 
56
 
my $current_module;
57
 
my @panels = ();
58
 
foreach my $panel (Bugzilla::Config::param_panels()) {
59
 
    eval("require Bugzilla::Config::$panel") || die $@;
60
 
    my @module_param_list = "Bugzilla::Config::${panel}"->get_param_list(1);
61
 
    my $item = { name => lc($panel),
62
 
                 current => ($current_panel eq lc($panel)) ? 1 : 0,
63
 
                 param_list => \@module_param_list,
64
 
                 sortkey => eval "\$Bugzilla::Config::${panel}::sortkey;"
65
 
               };
66
 
    push(@panels, $item);
67
 
    $current_module = $panel if ($current_panel eq lc($panel));
68
 
}
69
 
 
70
 
$vars->{panels} = \@panels;
71
 
 
72
 
if ($action eq 'save' && $current_module) {
73
 
    check_token_data($token, 'edit_parameters');
74
 
    my @changes = ();
75
 
    my @module_param_list = "Bugzilla::Config::${current_module}"->get_param_list(1);
76
 
 
77
 
    my $update_lang_user_pref = 0;
78
 
    foreach my $i (@module_param_list) {
79
 
        my $name = $i->{'name'};
80
 
        my $value = $cgi->param($name);
81
 
 
82
 
        if (defined $cgi->param("reset-$name")) {
83
 
            $value = $i->{'default'};
84
 
        } else {
85
 
            if ($i->{'type'} eq 'm') {
86
 
                # This simplifies the code below
87
 
                $value = [ $cgi->param($name) ];
88
 
            } else {
89
 
                # Get rid of windows/mac-style line endings.
90
 
                $value =~ s/\r\n?/\n/g;
91
 
                # assume single linefeed is an empty string
92
 
                $value =~ s/^\n$//;
93
 
            }
94
 
        }
95
 
 
96
 
        my $changed;
97
 
        if ($i->{'type'} eq 'm') {
98
 
            my @old = sort @{Bugzilla->params->{$name}};
99
 
            my @new = sort @$value;
100
 
            if (scalar(@old) != scalar(@new)) {
101
 
                $changed = 1;
102
 
            } else {
103
 
                $changed = 0; # Assume not changed...
104
 
                for (my $cnt = 0; $cnt < scalar(@old); ++$cnt) {
105
 
                    if ($old[$cnt] ne $new[$cnt]) {
106
 
                        # entry is different, therefore changed
107
 
                        $changed = 1;
108
 
                        last;
109
 
                    }
110
 
                }
111
 
            }
112
 
        } else {
113
 
            $changed = ($value eq Bugzilla->params->{$name})? 0 : 1;
114
 
        }
115
 
 
116
 
        if ($changed) {
117
 
            if (exists $i->{'checker'}) {
118
 
                my $ok = $i->{'checker'}->($value, $i);
119
 
                if ($ok ne "") {
120
 
                    ThrowUserError('invalid_parameter', { name => $name, err => $ok });
121
 
                }
122
 
            } elsif ($name eq 'globalwatchers') {
123
 
                # can't check this as others, as Bugzilla::Config::Common
124
 
                # can not use Bugzilla::User
125
 
                foreach my $watcher (split(/[,\s]+/, $value)) {
126
 
                    ThrowUserError(
127
 
                        'invalid_parameter',
128
 
                        { name => $name, err => "no such user $watcher" }
129
 
                    ) unless login_to_id($watcher);
130
 
                }
131
 
            }
132
 
            push(@changes, $name);
133
 
            SetParam($name, $value);
134
 
            if (($name eq "shutdownhtml") && ($value ne "")) {
135
 
                $vars->{'shutdown_is_active'} = 1;
136
 
            }
137
 
            if ($name eq 'languages') {
138
 
                $update_lang_user_pref = 1;
139
 
            }
140
 
        }
141
 
    }
142
 
    if ($update_lang_user_pref) {
143
 
        # We have to update the list of languages users can choose.
144
 
        # If some users have selected a language which is no longer available,
145
 
        # then we delete it (the user pref is reset to the default one).
146
 
        my @languages = split(/[\s,]+/, Bugzilla->params->{'languages'});
147
 
        map {trick_taint($_)} @languages;
148
 
        my $lang = Bugzilla->params->{'defaultlanguage'};
149
 
        trick_taint($lang);
150
 
        add_setting('lang', \@languages, $lang, undef, 1);
151
 
    }
152
 
 
153
 
    $vars->{'message'} = 'parameters_updated';
154
 
    $vars->{'param_changed'} = \@changes;
155
 
 
156
 
    write_params();
157
 
    delete_token($token);
158
 
}
159
 
 
160
 
$vars->{'token'} = issue_session_token('edit_parameters');
161
 
 
162
 
$template->process("admin/params/editparams.html.tmpl", $vars)
163
 
    || ThrowTemplateError($template->error());