]> git.ipfire.org Git - thirdparty/bugzilla.git/blame - editsettings.cgi
add a new hook: template_after_create (#60)
[thirdparty/bugzilla.git] / editsettings.cgi
CommitLineData
9f3d18d4 1#!/usr/bin/perl -T
fe2a998b
FB
2# This Source Code Form is subject to the terms of the Mozilla Public
3# License, v. 2.0. If a copy of the MPL was not distributed with this
4# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6674f619 5#
fe2a998b
FB
6# This Source Code Form is "Incompatible With Secondary Licenses", as
7# defined by the Mozilla Public License, v. 2.0.
6674f619 8
1001cbba 9use 5.10.1;
6674f619 10use strict;
9f3d18d4
FB
11use warnings;
12
415e32d4 13use lib qw(. lib);
6674f619 14
15use Bugzilla;
16use Bugzilla::Constants;
c4111734 17use Bugzilla::Util;
18use Bugzilla::Error;
6674f619 19use Bugzilla::User::Setting;
93815fc7 20use Bugzilla::Token;
6674f619 21
44de29d0 22my $template = Bugzilla->template;
c87cca60 23my $user = Bugzilla->login(LOGIN_REQUIRED);
24my $cgi = Bugzilla->cgi;
25my $vars = {};
6674f619 26
c87cca60 27print $cgi->header;
6674f619 28
c87cca60 29$user->in_group('tweakparams')
30 || ThrowUserError("auth_failure", {group => "tweakparams",
31 action => "modify",
32 object => "settings"});
6674f619 33
c87cca60 34my $action = trim($cgi->param('action') || '');
35my $token = $cgi->param('token');
6674f619 36
c87cca60 37if ($action eq 'update') {
38 check_token_data($token, 'edit_settings');
39 my $settings = Bugzilla::User::Setting::get_defaults();
40 my $changed = 0;
6674f619 41
c87cca60 42 foreach my $name (keys %$settings) {
43 my $old_enabled = $settings->{$name}->{'is_enabled'};
44 my $old_value = $settings->{$name}->{'default_value'};
6674f619 45 my $enabled = defined $cgi->param("${name}-enabled") || 0;
46 my $value = $cgi->param("${name}");
5f9f484f 47 my $setting = new Bugzilla::User::Setting($name);
6674f619 48
5f9f484f 49 $setting->validate_value($value);
6674f619 50
c87cca60 51 if ($old_enabled != $enabled || $old_value ne $value) {
6674f619 52 Bugzilla::User::Setting::set_default($name, $value, $enabled);
c87cca60 53 $changed = 1;
6674f619 54 }
55 }
c87cca60 56 $vars->{'message'} = 'default_settings_updated';
57 $vars->{'changes_saved'} = $changed;
c19dc4ff 58 Bugzilla->memcached->clear_config();
93815fc7 59 delete_token($token);
6674f619 60}
61
c87cca60 62# Don't use $settings as defaults may have changed.
63$vars->{'settings'} = Bugzilla::User::Setting::get_defaults();
64$vars->{'token'} = issue_session_token('edit_settings');
6674f619 65
c87cca60 66$template->process("admin/settings/edit.html.tmpl", $vars)
67 || ThrowTemplateError($template->error());