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
# Contributor(s): Shane H. W. Travis <travis@sedsystems.ca>
23
use Bugzilla::Constants;
26
use Bugzilla::User::Setting;
29
my $template = Bugzilla->template;
32
###############################
33
### Subroutine Definitions ###
34
###############################
38
$vars->{'settings'} = Bugzilla::User::Setting::get_defaults();
40
my @setting_list = keys %{$vars->{'settings'}};
41
$vars->{'setting_names'} = \@setting_list;
46
my $cgi = Bugzilla->cgi;
48
$vars->{'settings'} = Bugzilla::User::Setting::get_defaults();
49
my @setting_list = keys %{$vars->{'settings'}};
51
foreach my $name (@setting_list) {
53
my $old_enabled = $vars->{'settings'}->{$name}->{'is_enabled'};
54
my $old_value = $vars->{'settings'}->{$name}->{'default_value'};
55
my $enabled = defined $cgi->param("${name}-enabled") || 0;
56
my $value = $cgi->param("${name}");
57
my $setting = new Bugzilla::User::Setting($name);
59
$setting->validate_value($value);
61
if ( ($old_enabled != $enabled) ||
62
($old_value ne $value) ) {
63
Bugzilla::User::Setting::set_default($name, $value, $enabled);
72
my $user = Bugzilla->login(LOGIN_REQUIRED);
74
my $cgi = Bugzilla->cgi;
77
$user->in_group('tweakparams')
78
|| ThrowUserError("auth_failure", {group => "tweakparams",
80
object => "settings"});
82
my $action = trim($cgi->param('action') || 'load');
83
my $token = $cgi->param('token');
85
if ($action eq 'update') {
86
check_token_data($token, 'edit_settings');
89
$vars->{'changes_saved'} = 1;
91
$template->process("admin/settings/updated.html.tmpl", $vars)
92
|| ThrowTemplateError($template->error());
97
if ($action eq 'load') {
99
$vars->{'token'} = issue_session_token('edit_settings');
101
$template->process("admin/settings/edit.html.tmpl", $vars)
102
|| ThrowTemplateError($template->error());
108
# No valid action found
110
ThrowUserError('no_valid_action', {'field' => "settings"});