~ubuntu-branches/ubuntu/intrepid/bugzilla/intrepid

« back to all changes in this revision

Viewing changes to editfields.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): Frédéric Buclin <LpSolit@gmail.com>
17
 
 
18
 
use strict;
19
 
use lib ".";
20
 
 
21
 
use Bugzilla;
22
 
use Bugzilla::Constants;
23
 
use Bugzilla::Error;
24
 
use Bugzilla::Util;
25
 
use Bugzilla::Field;
26
 
use Bugzilla::Token;
27
 
 
28
 
my $cgi = Bugzilla->cgi;
29
 
my $template = Bugzilla->template;
30
 
my $vars = {};
31
 
 
32
 
# Make sure the user is logged in and is an administrator.
33
 
my $user = Bugzilla->login(LOGIN_REQUIRED);
34
 
$user->in_group('admin')
35
 
  || ThrowUserError('auth_failure', {group  => 'admin',
36
 
                                     action => 'edit',
37
 
                                     object => 'custom_fields'});
38
 
 
39
 
my $action = trim($cgi->param('action') || '');
40
 
my $token  = $cgi->param('token');
41
 
 
42
 
print $cgi->header();
43
 
 
44
 
# List all existing custom fields if no action is given.
45
 
if (!$action) {
46
 
    $template->process('admin/custom_fields/list.html.tmpl', $vars)
47
 
        || ThrowTemplateError($template->error());
48
 
}
49
 
# Interface to add a new custom field.
50
 
elsif ($action eq 'add') {
51
 
    $vars->{'token'} = issue_session_token('add_field');
52
 
 
53
 
    $template->process('admin/custom_fields/create.html.tmpl', $vars)
54
 
        || ThrowTemplateError($template->error());
55
 
}
56
 
elsif ($action eq 'new') {
57
 
    check_token_data($token, 'add_field');
58
 
 
59
 
    $vars->{'field'} = Bugzilla::Field->create({
60
 
        name        => scalar $cgi->param('name'),
61
 
        description => scalar $cgi->param('desc'),
62
 
        type        => scalar $cgi->param('type'),
63
 
        sortkey     => scalar $cgi->param('sortkey'),
64
 
        mailhead    => scalar $cgi->param('new_bugmail'),
65
 
        enter_bug   => scalar $cgi->param('enter_bug'),
66
 
        obsolete    => scalar $cgi->param('obsolete'),
67
 
        custom      => 1,
68
 
    });
69
 
 
70
 
    delete_token($token);
71
 
 
72
 
    $vars->{'message'} = 'custom_field_created';
73
 
 
74
 
    $template->process('admin/custom_fields/list.html.tmpl', $vars)
75
 
        || ThrowTemplateError($template->error());
76
 
}
77
 
elsif ($action eq 'edit') {
78
 
    my $name = $cgi->param('name') || ThrowUserError('field_missing_name');
79
 
    # Custom field names must start with "cf_".
80
 
    if ($name !~ /^cf_/) {
81
 
        $name = 'cf_' . $name;
82
 
    }
83
 
    my $field = new Bugzilla::Field({'name' => $name});
84
 
    $field || ThrowUserError('customfield_nonexistent', {'name' => $name});
85
 
 
86
 
    $vars->{'field'} = $field;
87
 
    $vars->{'token'} = issue_session_token('edit_field');
88
 
 
89
 
    $template->process('admin/custom_fields/edit.html.tmpl', $vars)
90
 
        || ThrowTemplateError($template->error());
91
 
}
92
 
elsif ($action eq 'update') {
93
 
    check_token_data($token, 'edit_field');
94
 
    my $name = $cgi->param('name');
95
 
 
96
 
    # Validate fields.
97
 
    $name || ThrowUserError('field_missing_name');
98
 
    # Custom field names must start with "cf_".
99
 
    if ($name !~ /^cf_/) {
100
 
        $name = 'cf_' . $name;
101
 
    }
102
 
    my $field = new Bugzilla::Field({'name' => $name});
103
 
    $field || ThrowUserError('customfield_nonexistent', {'name' => $name});
104
 
 
105
 
    $field->set_description($cgi->param('desc'));
106
 
    $field->set_sortkey($cgi->param('sortkey'));
107
 
    $field->set_in_new_bugmail($cgi->param('new_bugmail'));
108
 
    $field->set_enter_bug($cgi->param('enter_bug'));
109
 
    $field->set_obsolete($cgi->param('obsolete'));
110
 
    $field->update();
111
 
 
112
 
    delete_token($token);
113
 
 
114
 
    $vars->{'field'}   = $field;
115
 
    $vars->{'message'} = 'custom_field_updated';
116
 
 
117
 
    $template->process('admin/custom_fields/list.html.tmpl', $vars)
118
 
        || ThrowTemplateError($template->error());
119
 
}
120
 
else {
121
 
    ThrowUserError('no_valid_action', {'field' => 'custom_field'});
122
 
}