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

« back to all changes in this revision

Viewing changes to editsettings.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
 
# Contributor(s): Shane H. W. Travis <travis@sedsystems.ca>
17
 
#
18
 
 
19
 
use strict;
20
 
use lib qw(.);
21
 
 
22
 
use Bugzilla;
23
 
use Bugzilla::Constants;
24
 
use Bugzilla::Util;
25
 
use Bugzilla::Error;
26
 
use Bugzilla::User::Setting;
27
 
use Bugzilla::Token;
28
 
 
29
 
my $template = Bugzilla->template;
30
 
local our $vars = {};
31
 
 
32
 
###############################
33
 
###  Subroutine Definitions ###
34
 
###############################
35
 
 
36
 
sub LoadSettings {
37
 
 
38
 
    $vars->{'settings'} = Bugzilla::User::Setting::get_defaults();
39
 
 
40
 
    my @setting_list = keys %{$vars->{'settings'}};
41
 
    $vars->{'setting_names'} = \@setting_list;
42
 
}
43
 
 
44
 
sub SaveSettings{
45
 
 
46
 
    my $cgi = Bugzilla->cgi;
47
 
 
48
 
    $vars->{'settings'} = Bugzilla::User::Setting::get_defaults();
49
 
    my @setting_list = keys %{$vars->{'settings'}};
50
 
 
51
 
    foreach my $name (@setting_list) {
52
 
        my $changed = 0;
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);
58
 
 
59
 
        $setting->validate_value($value);
60
 
 
61
 
        if ( ($old_enabled != $enabled) ||
62
 
             ($old_value ne $value) ) {
63
 
            Bugzilla::User::Setting::set_default($name, $value, $enabled);
64
 
        }
65
 
    }
66
 
}
67
 
 
68
 
###################
69
 
###  Live code  ###
70
 
###################
71
 
 
72
 
my $user = Bugzilla->login(LOGIN_REQUIRED);
73
 
 
74
 
my $cgi = Bugzilla->cgi;
75
 
print $cgi->header;
76
 
 
77
 
$user->in_group('tweakparams')
78
 
  || ThrowUserError("auth_failure", {group  => "tweakparams",
79
 
                                     action => "modify",
80
 
                                     object => "settings"});
81
 
 
82
 
my $action  = trim($cgi->param('action')  || 'load');
83
 
my $token   = $cgi->param('token');
84
 
 
85
 
if ($action eq 'update') {
86
 
    check_token_data($token, 'edit_settings');
87
 
    SaveSettings();
88
 
    delete_token($token);
89
 
    $vars->{'changes_saved'} = 1;
90
 
 
91
 
    $template->process("admin/settings/updated.html.tmpl", $vars)
92
 
      || ThrowTemplateError($template->error());
93
 
 
94
 
    exit;
95
 
}
96
 
 
97
 
if ($action eq 'load') {
98
 
    LoadSettings();
99
 
    $vars->{'token'} = issue_session_token('edit_settings');
100
 
 
101
 
    $template->process("admin/settings/edit.html.tmpl", $vars)
102
 
      || ThrowTemplateError($template->error());
103
 
 
104
 
    exit;
105
 
}
106
 
 
107
 
#
108
 
# No valid action found
109
 
#
110
 
ThrowUserError('no_valid_action', {'field' => "settings"});