1 #!/usr/bin/env perl -wT
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
;
37 use Bugzilla
::User
::Setting
;
40 my $user = Bugzilla
->login(LOGIN_REQUIRED
);
41 my $cgi = Bugzilla
->cgi;
42 my $template = Bugzilla
->template;
47 $user->in_group('tweakparams')
48 || ThrowUserError
("auth_failure", {group
=> "tweakparams",
50 object
=> "parameters"});
52 my $action = trim
($cgi->param('action') || '');
53 my $token = $cgi->param('token');
54 my $current_panel = $cgi->param('section') || 'core';
55 $current_panel =~ /^([A-Za-z0-9_-]+)$/;
60 my $param_panels = Bugzilla
::Config
::param_panels
();
61 foreach my $panel (keys %$param_panels) {
62 my $module = $param_panels->{$panel};
63 eval("require $module") || die $@
;
64 my @module_param_list = "$module"->get_param_list();
65 my $item = { name
=> lc($panel),
66 current
=> ($current_panel eq lc($panel)) ?
1 : 0,
67 param_list
=> \
@module_param_list,
68 sortkey
=> eval "\$${module}::sortkey;"
71 $current_module = $panel if ($current_panel eq lc($panel));
74 $vars->{panels
} = \
@panels;
76 if ($action eq 'save' && $current_module) {
77 check_token_data
($token, 'edit_parameters');
79 my @module_param_list = "$param_panels->{$current_module}"->get_param_list();
81 foreach my $i (@module_param_list) {
82 my $name = $i->{'name'};
83 my $value = $cgi->param($name);
85 if (defined $cgi->param("reset-$name")) {
86 $value = $i->{'default'};
88 if ($i->{'type'} eq 'm') {
89 # This simplifies the code below
90 $value = [ $cgi->param($name) ];
92 # Get rid of windows/mac-style line endings.
93 $value =~ s/\r\n?/\n/g;
94 # assume single linefeed is an empty string
100 if ($i->{'type'} eq 'm') {
101 my @old = sort @
{Bugzilla
->params->{$name}};
102 my @new = sort @
$value;
103 if (scalar(@old) != scalar(@new)) {
106 $changed = 0; # Assume not changed...
107 for (my $cnt = 0; $cnt < scalar(@old); ++$cnt) {
108 if ($old[$cnt] ne $new[$cnt]) {
109 # entry is different, therefore changed
116 $changed = ($value eq Bugzilla
->params->{$name})?
0 : 1;
120 if (exists $i->{'checker'}) {
121 my $ok = $i->{'checker'}->($value, $i);
123 ThrowUserError
('invalid_parameter', { name
=> $name, err
=> $ok });
125 } elsif ($name eq 'globalwatchers') {
126 # can't check this as others, as Bugzilla::Config::Common
127 # can not use Bugzilla::User
128 foreach my $watcher (split(/[,\s]+/, $value)) {
131 { name
=> $name, err
=> "no such user $watcher" }
132 ) unless login_to_id
($watcher);
135 push(@changes, $name);
136 SetParam
($name, $value);
137 if (($name eq "shutdownhtml") && ($value ne "")) {
138 $vars->{'shutdown_is_active'} = 1;
140 if ($name eq 'duplicate_or_move_bug_status') {
141 Bugzilla
::Status
::add_missing_bug_status_transitions
($value);
146 $vars->{'message'} = 'parameters_updated';
147 $vars->{'param_changed'} = \
@changes;
150 delete_token
($token);
153 $vars->{'token'} = issue_session_token
('edit_parameters');
155 $template->process("admin/params/editparams.html.tmpl", $vars)
156 || ThrowTemplateError
($template->error());