2
# -*- Mode: perl; indent-tabs-mode: nil -*-
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/
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.
14
# The Original Code is the Bugzilla Bug Tracking System.
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
21
# Contributor(s): Terry Weissman <terry@mozilla.org>
22
# J. Paul Reed <preed@sigkill.com>
23
# Frédéric Buclin <LpSolit@gmail.com>
29
use Bugzilla::Constants;
30
use Bugzilla::Config qw(:admin);
31
use Bugzilla::Config::Common;
36
use Bugzilla::User::Setting;
38
my $user = Bugzilla->login(LOGIN_REQUIRED);
39
my $cgi = Bugzilla->cgi;
40
my $template = Bugzilla->template;
45
$user->in_group('tweakparams')
46
|| ThrowUserError("auth_failure", {group => "tweakparams",
48
object => "parameters"});
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_-]+)$/;
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;"
67
$current_module = $panel if ($current_panel eq lc($panel));
70
$vars->{panels} = \@panels;
72
if ($action eq 'save' && $current_module) {
73
check_token_data($token, 'edit_parameters');
75
my @module_param_list = "Bugzilla::Config::${current_module}"->get_param_list(1);
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);
82
if (defined $cgi->param("reset-$name")) {
83
$value = $i->{'default'};
85
if ($i->{'type'} eq 'm') {
86
# This simplifies the code below
87
$value = [ $cgi->param($name) ];
89
# Get rid of windows/mac-style line endings.
90
$value =~ s/\r\n?/\n/g;
91
# assume single linefeed is an empty string
97
if ($i->{'type'} eq 'm') {
98
my @old = sort @{Bugzilla->params->{$name}};
99
my @new = sort @$value;
100
if (scalar(@old) != scalar(@new)) {
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
113
$changed = ($value eq Bugzilla->params->{$name})? 0 : 1;
117
if (exists $i->{'checker'}) {
118
my $ok = $i->{'checker'}->($value, $i);
120
ThrowUserError('invalid_parameter', { name => $name, err => $ok });
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)) {
128
{ name => $name, err => "no such user $watcher" }
129
) unless login_to_id($watcher);
132
push(@changes, $name);
133
SetParam($name, $value);
134
if (($name eq "shutdownhtml") && ($value ne "")) {
135
$vars->{'shutdown_is_active'} = 1;
137
if ($name eq 'languages') {
138
$update_lang_user_pref = 1;
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'};
150
add_setting('lang', \@languages, $lang, undef, 1);
153
$vars->{'message'} = 'parameters_updated';
154
$vars->{'param_changed'} = \@changes;
157
delete_token($token);
160
$vars->{'token'} = issue_session_token('edit_parameters');
162
$template->process("admin/params/editparams.html.tmpl", $vars)
163
|| ThrowTemplateError($template->error());