2003-12-10 02:12:40 +03:00
|
|
|
#!/usr/bin/perl -wT
|
2000-01-07 00:16:15 +03:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
|
|
|
#
|
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Terry Weissman.
|
|
|
|
# Portions created by Terry Weissman are
|
|
|
|
# Copyright (C) 2000 Terry Weissman. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
|
|
|
|
|
|
|
use strict;
|
2002-04-29 23:32:29 +04:00
|
|
|
use lib ".";
|
2000-01-07 00:16:15 +03:00
|
|
|
|
|
|
|
require "CGI.pl";
|
|
|
|
|
2004-03-27 06:51:44 +03:00
|
|
|
use Bugzilla::Constants;
|
2003-11-22 06:50:42 +03:00
|
|
|
use Bugzilla::Config qw(:DEFAULT $datadir);
|
2005-03-16 01:10:14 +03:00
|
|
|
use Bugzilla::User;
|
2003-11-22 06:50:42 +03:00
|
|
|
|
2004-03-06 12:04:33 +03:00
|
|
|
my $cgi = Bugzilla->cgi;
|
2005-03-16 03:27:15 +03:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2004-03-06 12:04:33 +03:00
|
|
|
|
2003-11-21 13:00:54 +03:00
|
|
|
use vars qw($template $vars);
|
|
|
|
|
2000-01-07 00:16:15 +03:00
|
|
|
|
|
|
|
sub Validate ($$) {
|
|
|
|
my ($name, $description) = @_;
|
|
|
|
if ($name eq "") {
|
2003-12-10 02:12:40 +03:00
|
|
|
ThrowUserError("keyword_blank_name");
|
2000-01-07 00:16:15 +03:00
|
|
|
}
|
2000-01-19 22:26:37 +03:00
|
|
|
if ($name =~ /[\s,]/) {
|
2003-12-10 02:12:40 +03:00
|
|
|
ThrowUserError("keyword_invalid_name");
|
2000-01-07 00:16:15 +03:00
|
|
|
}
|
|
|
|
if ($description eq "") {
|
2003-12-10 02:12:40 +03:00
|
|
|
ThrowUserError("keyword_blank_description");
|
2000-01-07 00:16:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Preliminary checks:
|
|
|
|
#
|
|
|
|
|
2004-03-27 06:51:44 +03:00
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
2000-01-07 00:16:15 +03:00
|
|
|
|
2003-05-05 05:15:38 +04:00
|
|
|
print Bugzilla->cgi->header();
|
2000-01-07 00:16:15 +03:00
|
|
|
|
2005-01-16 17:07:31 +03:00
|
|
|
UserInGroup("editkeywords")
|
|
|
|
|| ThrowUserError("auth_failure", {group => "editkeywords",
|
|
|
|
action => "edit",
|
|
|
|
object => "keywords"});
|
2000-01-07 00:16:15 +03:00
|
|
|
|
2004-03-06 12:04:33 +03:00
|
|
|
my $action = trim($cgi->param('action') || '');
|
2003-11-21 13:00:54 +03:00
|
|
|
$vars->{'action'} = $action;
|
|
|
|
|
2000-01-07 00:16:15 +03:00
|
|
|
|
|
|
|
if ($action eq "") {
|
2003-12-10 02:12:40 +03:00
|
|
|
my @keywords;
|
2000-01-22 19:51:49 +03:00
|
|
|
|
2000-01-07 00:16:15 +03:00
|
|
|
SendSQL("SELECT keyworddefs.id, keyworddefs.name, keyworddefs.description,
|
2002-07-22 01:47:43 +04:00
|
|
|
COUNT(keywords.bug_id)
|
2005-03-16 03:27:15 +03:00
|
|
|
FROM keyworddefs LEFT JOIN keywords
|
|
|
|
ON keyworddefs.id = keywords.keywordid " .
|
|
|
|
$dbh->sql_group_by('keyworddefs.id',
|
|
|
|
'keyworddefs.name, keyworddefs.description') . "
|
2000-01-07 00:16:15 +03:00
|
|
|
ORDER BY keyworddefs.name");
|
2003-12-10 02:12:40 +03:00
|
|
|
|
2000-01-07 00:16:15 +03:00
|
|
|
while (MoreSQLData()) {
|
2002-07-22 01:47:43 +04:00
|
|
|
my ($id, $name, $description, $bugs) = FetchSQLData();
|
2003-12-10 02:12:40 +03:00
|
|
|
my $keyword = {};
|
|
|
|
$keyword->{'id'} = $id;
|
|
|
|
$keyword->{'name'} = $name;
|
|
|
|
$keyword->{'description'} = $description;
|
|
|
|
$keyword->{'bug_count'} = $bugs;
|
|
|
|
push(@keywords, $keyword);
|
2000-01-07 00:16:15 +03:00
|
|
|
}
|
2003-12-10 02:12:40 +03:00
|
|
|
|
|
|
|
print Bugzilla->cgi->header();
|
|
|
|
|
|
|
|
$vars->{'keywords'} = \@keywords;
|
|
|
|
$template->process("admin/keywords/list.html.tmpl",
|
|
|
|
$vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
2000-01-07 00:16:15 +03:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($action eq 'add') {
|
2003-11-21 13:00:54 +03:00
|
|
|
print Bugzilla->cgi->header();
|
2000-01-07 00:16:15 +03:00
|
|
|
|
2003-11-21 13:00:54 +03:00
|
|
|
$template->process("admin/keywords/create.html.tmpl",
|
|
|
|
$vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-01-07 00:16:15 +03:00
|
|
|
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='new' -> add keyword entered in the 'action=add' screen
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'new') {
|
|
|
|
# Cleanups and valididy checks
|
|
|
|
|
2004-03-06 12:04:33 +03:00
|
|
|
my $name = trim($cgi->param('name') || '');
|
|
|
|
my $description = trim($cgi->param('description') || '');
|
2000-01-07 00:16:15 +03:00
|
|
|
|
|
|
|
Validate($name, $description);
|
|
|
|
|
|
|
|
SendSQL("SELECT id FROM keyworddefs WHERE name = " . SqlQuote($name));
|
|
|
|
|
|
|
|
if (FetchOneColumn()) {
|
2003-12-10 02:12:40 +03:00
|
|
|
$vars->{'name'} = $name;
|
|
|
|
ThrowUserError("keyword_already_exists");
|
2000-01-07 00:16:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Pick an unused number. Be sure to recycle numbers that may have been
|
|
|
|
# deleted in the past. This code is potentially slow, but it happens
|
|
|
|
# rarely enough, and there really aren't ever going to be that many
|
|
|
|
# keywords anyway.
|
|
|
|
|
|
|
|
SendSQL("SELECT id FROM keyworddefs ORDER BY id");
|
|
|
|
|
|
|
|
my $newid = 1;
|
|
|
|
|
|
|
|
while (MoreSQLData()) {
|
|
|
|
my $oldid = FetchOneColumn();
|
|
|
|
if ($oldid > $newid) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
$newid = $oldid + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add the new keyword.
|
|
|
|
SendSQL("INSERT INTO keyworddefs (id, name, description) VALUES ($newid, " .
|
|
|
|
SqlQuote($name) . "," .
|
|
|
|
SqlQuote($description) . ")");
|
|
|
|
|
|
|
|
# Make versioncache flush
|
2003-11-22 06:50:42 +03:00
|
|
|
unlink "$datadir/versioncache";
|
2000-01-07 00:16:15 +03:00
|
|
|
|
2003-12-10 02:12:40 +03:00
|
|
|
print Bugzilla->cgi->header();
|
|
|
|
|
|
|
|
$vars->{'name'} = $name;
|
|
|
|
$template->process("admin/keywords/created.html.tmpl",
|
|
|
|
$vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
2000-01-07 00:16:15 +03:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='edit' -> present the edit keywords from
|
|
|
|
#
|
|
|
|
# (next action would be 'update')
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'edit') {
|
2004-04-05 05:32:43 +04:00
|
|
|
my $id = trim($cgi->param('id'));
|
2004-03-06 12:04:33 +03:00
|
|
|
detaint_natural($id);
|
|
|
|
|
2000-01-07 00:16:15 +03:00
|
|
|
# get data of keyword
|
|
|
|
SendSQL("SELECT name,description
|
|
|
|
FROM keyworddefs
|
|
|
|
WHERE id=$id");
|
|
|
|
my ($name, $description) = FetchSQLData();
|
|
|
|
if (!$name) {
|
2003-12-10 02:12:40 +03:00
|
|
|
$vars->{'id'} = $id;
|
|
|
|
ThrowCodeError("invalid_keyword_id", $vars);
|
2000-01-07 00:16:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SendSQL("SELECT count(*)
|
|
|
|
FROM keywords
|
|
|
|
WHERE keywordid = $id");
|
|
|
|
my $bugs = '';
|
|
|
|
$bugs = FetchOneColumn() if MoreSQLData();
|
|
|
|
|
2003-12-10 02:12:40 +03:00
|
|
|
$vars->{'keyword_id'} = $id;
|
|
|
|
$vars->{'name'} = $name;
|
|
|
|
$vars->{'description'} = $description;
|
|
|
|
$vars->{'bug_count'} = $bugs;
|
2000-01-07 00:16:15 +03:00
|
|
|
|
2003-12-10 02:12:40 +03:00
|
|
|
print Bugzilla->cgi->header();
|
2000-01-07 00:16:15 +03:00
|
|
|
|
2003-12-10 02:12:40 +03:00
|
|
|
$template->process("admin/keywords/edit.html.tmpl",
|
|
|
|
$vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-01-07 00:16:15 +03:00
|
|
|
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='update' -> update the keyword
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'update') {
|
2004-03-06 12:04:33 +03:00
|
|
|
my $id = $cgi->param('id');
|
|
|
|
detaint_natural($id);
|
|
|
|
|
|
|
|
my $name = trim($cgi->param('name') || '');
|
|
|
|
my $description = trim($cgi->param('description') || '');
|
2000-01-07 00:16:15 +03:00
|
|
|
|
|
|
|
Validate($name, $description);
|
|
|
|
|
|
|
|
SendSQL("SELECT id FROM keyworddefs WHERE name = " . SqlQuote($name));
|
|
|
|
|
|
|
|
my $tmp = FetchOneColumn();
|
|
|
|
|
|
|
|
if ($tmp && $tmp != $id) {
|
2003-12-10 02:12:40 +03:00
|
|
|
$vars->{'name'} = $name;
|
|
|
|
ThrowUserError("keyword_already_exists", $vars);
|
2000-01-07 00:16:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SendSQL("UPDATE keyworddefs SET name = " . SqlQuote($name) .
|
|
|
|
", description = " . SqlQuote($description) .
|
|
|
|
" WHERE id = $id");
|
|
|
|
|
|
|
|
# Make versioncache flush
|
2003-11-22 06:50:42 +03:00
|
|
|
unlink "$datadir/versioncache";
|
2000-01-07 00:16:15 +03:00
|
|
|
|
2003-11-21 13:00:54 +03:00
|
|
|
print Bugzilla->cgi->header();
|
|
|
|
|
|
|
|
$vars->{'name'} = $name;
|
|
|
|
$template->process("admin/keywords/rebuild-cache.html.tmpl",
|
|
|
|
$vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
2000-01-07 00:16:15 +03:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($action eq 'delete') {
|
2004-03-06 12:04:33 +03:00
|
|
|
my $id = $cgi->param('id');
|
|
|
|
detaint_natural($id);
|
2000-01-07 00:16:15 +03:00
|
|
|
|
|
|
|
SendSQL("SELECT name FROM keyworddefs WHERE id=$id");
|
|
|
|
my $name = FetchOneColumn();
|
|
|
|
|
2004-03-06 12:04:33 +03:00
|
|
|
if (!$cgi->param('reallydelete')) {
|
2000-01-07 00:16:15 +03:00
|
|
|
SendSQL("SELECT count(*)
|
|
|
|
FROM keywords
|
|
|
|
WHERE keywordid = $id");
|
|
|
|
|
|
|
|
my $bugs = FetchOneColumn();
|
|
|
|
|
|
|
|
if ($bugs) {
|
2003-11-21 13:00:54 +03:00
|
|
|
$vars->{'bug_count'} = $bugs;
|
|
|
|
$vars->{'keyword_id'} = $id;
|
|
|
|
$vars->{'name'} = $name;
|
|
|
|
|
|
|
|
print Bugzilla->cgi->header();
|
|
|
|
|
|
|
|
$template->process("admin/keywords/confirm-delete.html.tmpl",
|
|
|
|
$vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-01-07 00:16:15 +03:00
|
|
|
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SendSQL("DELETE FROM keywords WHERE keywordid = $id");
|
|
|
|
SendSQL("DELETE FROM keyworddefs WHERE id = $id");
|
|
|
|
|
|
|
|
# Make versioncache flush
|
2003-11-22 06:50:42 +03:00
|
|
|
unlink "$datadir/versioncache";
|
2000-01-07 00:16:15 +03:00
|
|
|
|
2003-11-21 13:00:54 +03:00
|
|
|
print Bugzilla->cgi->header();
|
2000-01-07 00:16:15 +03:00
|
|
|
|
2003-11-21 13:00:54 +03:00
|
|
|
$vars->{'name'} = $name;
|
|
|
|
$template->process("admin/keywords/rebuild-cache.html.tmpl",
|
|
|
|
$vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2001-02-27 02:25:22 +03:00
|
|
|
|
2003-11-21 13:00:54 +03:00
|
|
|
exit;
|
2001-02-27 02:25:22 +03:00
|
|
|
}
|
|
|
|
|
2003-11-21 13:00:54 +03:00
|
|
|
ThrowCodeError("action_unrecognized", $vars);
|