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 Terry Weissman.
17 # Portions created by Terry Weissman are
18 # Copyright (C) 2000 Terry Weissman. All
21 # Contributor(s): Terry Weissman <terry@mozilla.org>
27 use Bugzilla
::Constants
;
30 use Bugzilla
::Keyword
;
33 my $cgi = Bugzilla
->cgi;
34 my $dbh = Bugzilla
->dbh;
35 my $template = Bugzilla
->template;
42 my $user = Bugzilla
->login(LOGIN_REQUIRED
);
46 $user->in_group('editkeywords')
47 || ThrowUserError
("auth_failure", {group
=> "editkeywords",
49 object
=> "keywords"});
51 my $action = trim
($cgi->param('action') || '');
52 my $key_id = $cgi->param('id');
53 my $token = $cgi->param('token');
55 $vars->{'action'} = $action;
59 $vars->{'keywords'} = Bugzilla
::Keyword
->get_all_with_bug_count();
62 $template->process("admin/keywords/list.html.tmpl", $vars)
63 || ThrowTemplateError
($template->error());
69 if ($action eq 'add') {
70 $vars->{'token'} = issue_session_token
('add_keyword');
74 $template->process("admin/keywords/create.html.tmpl", $vars)
75 || ThrowTemplateError
($template->error());
81 # action='new' -> add keyword entered in the 'action=add' screen
83 if ($action eq 'new') {
84 check_token_data
($token, 'add_keyword');
85 my $name = $cgi->param('name') || '';
86 my $desc = $cgi->param('description') || '';
88 my $keyword = Bugzilla
::Keyword
->create(
89 { name
=> $name, description
=> $desc });
95 $vars->{'message'} = 'keyword_created';
96 $vars->{'name'} = $keyword->name;
97 $vars->{'keywords'} = Bugzilla
::Keyword
->get_all_with_bug_count();
99 $template->process("admin/keywords/list.html.tmpl", $vars)
100 || ThrowTemplateError
($template->error());
106 # action='edit' -> present the edit keywords from
108 # (next action would be 'update')
111 if ($action eq 'edit') {
112 my $keyword = new Bugzilla
::Keyword
($key_id)
113 || ThrowCodeError
('invalid_keyword_id', { id
=> $key_id });
115 $vars->{'keyword'} = $keyword;
116 $vars->{'token'} = issue_session_token
('edit_keyword');
118 print $cgi->header();
119 $template->process("admin/keywords/edit.html.tmpl", $vars)
120 || ThrowTemplateError
($template->error());
126 # action='update' -> update the keyword
129 if ($action eq 'update') {
130 check_token_data
($token, 'edit_keyword');
131 my $keyword = new Bugzilla
::Keyword
($key_id)
132 || ThrowCodeError
('invalid_keyword_id', { id
=> $key_id });
134 $keyword->set_name($cgi->param('name'));
135 $keyword->set_description($cgi->param('description'));
136 my $changes = $keyword->update();
138 delete_token
($token);
140 print $cgi->header();
142 $vars->{'message'} = 'keyword_updated';
143 $vars->{'keyword'} = $keyword;
144 $vars->{'changes'} = $changes;
145 $vars->{'keywords'} = Bugzilla
::Keyword
->get_all_with_bug_count();
147 $template->process("admin/keywords/list.html.tmpl", $vars)
148 || ThrowTemplateError
($template->error());
152 if ($action eq 'del') {
153 my $keyword = new Bugzilla
::Keyword
($key_id)
154 || ThrowCodeError
('invalid_keyword_id', { id
=> $key_id });
156 $vars->{'keyword'} = $keyword;
157 $vars->{'token'} = issue_session_token
('delete_keyword');
159 print $cgi->header();
160 $template->process("admin/keywords/confirm-delete.html.tmpl", $vars)
161 || ThrowTemplateError
($template->error());
165 if ($action eq 'delete') {
166 check_token_data
($token, 'delete_keyword');
167 my $keyword = new Bugzilla
::Keyword
($key_id)
168 || ThrowCodeError
('invalid_keyword_id', { id
=> $key_id });
170 $dbh->do('DELETE FROM keywords WHERE keywordid = ?', undef, $keyword->id);
171 $dbh->do('DELETE FROM keyworddefs WHERE id = ?', undef, $keyword->id);
173 delete_token
($token);
175 print $cgi->header();
177 $vars->{'message'} = 'keyword_deleted';
178 $vars->{'keywords'} = Bugzilla
::Keyword
->get_all_with_bug_count();
180 $template->process("admin/keywords/list.html.tmpl", $vars)
181 || ThrowTemplateError
($template->error());
185 ThrowCodeError
("action_unrecognized", $vars);