pjs/webtools/bugzilla/buglist.cgi

612 строки
17 KiB
Plaintext
Исходник Обычный вид История

#!/usr/bonsaitools/bin/perl -w
# -*- Mode: perl; indent-tabs-mode: nil -*-
1998-08-26 10:14:20 +04:00
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 Netscape Communications
# Corporation. Portions created by Netscape are Copyright (C) 1998
# Netscape Communications Corporation. All Rights Reserved.
#
# Contributor(s): Terry Weissman <terry@mozilla.org>
use diagnostics;
use strict;
1998-08-26 10:14:20 +04:00
require "CGI.pl";
my $serverpush = 1;
1998-08-26 10:14:20 +04:00
if ($ENV{'HTTP_USER_AGENT'} =~ /MSIE/) {
# Internet explorer doesn't seem to understand server push. What fun.
$serverpush = 0;
}
if ($serverpush) {
print "Content-type: multipart/x-mixed-replace;boundary=thisrandomstring\n";
print "\n";
print "--thisrandomstring\n";
}
1998-08-26 10:14:20 +04:00
# Shut up misguided -w warnings about "used only once":
1998-08-26 10:14:20 +04:00
use vars @::legal_platform,
@::versions,
@::legal_product,
@::legal_component,
%::MFORM,
@::components,
@::legal_severity,
@::legal_priority,
@::default_column_list,
@::legal_resolution_no_dup;
1998-08-26 10:14:20 +04:00
ConnectToDatabase();
if (!defined $::FORM{'cmdtype'}) {
1998-08-26 10:14:20 +04:00
# This can happen if there's an old bookmark to a query...
$::FORM{'cmdtype'} = 'doit';
1998-08-26 10:14:20 +04:00
}
CMD: for ($::FORM{'cmdtype'}) {
/^runnamed$/ && do {
$::buffer = $::COOKIE{"QUERY_" . $::FORM{"namedcmd"}};
ProcessFormFields $::buffer;
last CMD;
};
/^editnamed$/ && do {
my $url = "query.cgi?" . $::COOKIE{"QUERY_" . $::FORM{"namedcmd"}};
print "Content-type: text/html
Refresh: 0; URL=$url
1998-08-26 10:14:20 +04:00
<TITLE>What a hack.</TITLE>
Loading your query named <B>$::FORM{'namedcmd'}</B>...";
exit;
};
/^forgetnamed$/ && do {
print "Set-Cookie: QUERY_" . $::FORM{'namedcmd'} . "= ; path=/ ; expires=Sun, 30-Jun-2029 00:00:00 GMT
Content-type: text/html
1998-08-26 10:14:20 +04:00
<HTML>
<TITLE>Forget what?</TITLE>
OK, the <B>$::FORM{'namedcmd'}</B> query is gone.
1998-08-26 10:14:20 +04:00
<P>
<A HREF=query.cgi>Go back to the query page.</A>";
exit;
};
/^asnamed$/ && do {
if ($::FORM{'newqueryname'} =~ /^[a-zA-Z0-9_ ]+$/) {
print "Set-Cookie: QUERY_" . $::FORM{'newqueryname'} . "=$::buffer ; path=/ ; expires=Sun, 30-Jun-2029 00:00:00 GMT
Content-type: text/html
1998-08-26 10:14:20 +04:00
<HTML>
<TITLE>OK, done.</TITLE>
OK, you now have a new query named <B>$::FORM{'newqueryname'}</B>.
1998-08-26 10:14:20 +04:00
<P>
<A HREF=query.cgi>Go back to the query page.</A>";
1998-08-26 10:14:20 +04:00
} else {
print "Content-type: text/html
1998-08-26 10:14:20 +04:00
<HTML>
<TITLE>Picky, picky.</TITLE>
1998-08-26 10:14:20 +04:00
Query names can only have letters, digits, spaces, or underbars. You entered
\"<B>$::FORM{'newqueryname'}</B>\", which doesn't cut it.
1998-08-26 10:14:20 +04:00
<P>
Click the <B>Back</B> button and type in a valid name for this query.";
1998-08-26 10:14:20 +04:00
}
exit;
};
/^asdefault$/ && do {
print "Set-Cookie: DEFAULTQUERY=$::buffer ; path=/ ; expires=Sun, 30-Jun-2029 00:00:00 GMT
Content-type: text/html
1998-08-26 10:14:20 +04:00
<HTML>
<TITLE>OK, default is set.</TITLE>
1998-08-26 10:14:20 +04:00
OK, you now have a new default query.
<P>
<A HREF=query.cgi>Go back to the query page, using the new default.</A>";
exit;
};
1998-08-26 10:14:20 +04:00
}
sub DefCol {
my ($name, $k, $t, $s, $q) = (@_);
$::key{$name} = $k;
$::title{$name} = $t;
if (defined $s && $s ne "") {
$::sortkey{$name} = $s;
1998-08-26 10:14:20 +04:00
}
if (!defined $q || $q eq "") {
$q = 0;
}
$::needquote{$name} = $q;
1998-08-26 10:14:20 +04:00
}
DefCol("opendate", "date_format(bugs.creation_ts,'Y-m-d')", "Opened",
"bugs.creation_ts");
DefCol("changeddate", "date_format(bugs.delta_ts,'Y-m-d')", "Changed",
"bugs.delta_ts");
DefCol("severity", "substring(bugs.bug_severity, 1, 3)", "Sev",
"bugs.bug_severity");
DefCol("priority", "substring(bugs.priority, 1, 3)", "Pri", "bugs.priority");
DefCol("platform", "substring(bugs.rep_platform, 1, 3)", "Plt",
"bugs.rep_platform");
DefCol("owner", "assign.login_name", "Owner", "assign.login_name");
DefCol("reporter", "report.login_name", "Reporter", "report.login_name");
DefCol("status", "substring(bugs.bug_status,1,4)", "State", "bugs.bug_status");
DefCol("resolution", "substring(bugs.resolution,1,4)", "Result",
"bugs.resolution");
DefCol("summary", "substring(bugs.short_desc, 1, 60)", "Summary", "", 1);
DefCol("summaryfull", "bugs.short_desc", "Summary", "", 1);
DefCol("component", "substring(bugs.component, 1, 8)", "Comp",
"bugs.component");
DefCol("product", "substring(bugs.product, 1, 8)", "Product", "bugs.product");
DefCol("version", "substring(bugs.version, 1, 5)", "Vers", "bugs.version");
DefCol("os", "substring(bugs.op_sys, 1, 4)", "OS", "bugs.op_sys");
my @collist;
if (defined $::COOKIE{'COLUMNLIST'}) {
@collist = split(/ /, $::COOKIE{'COLUMNLIST'});
1998-08-26 10:14:20 +04:00
} else {
@collist = @::default_column_list;
1998-08-26 10:14:20 +04:00
}
my $dotweak = defined $::FORM{'tweak'};
1998-08-26 10:14:20 +04:00
if ($dotweak) {
confirm_login();
1998-08-26 10:14:20 +04:00
}
print "Content-type: text/html\n\n";
1998-08-26 10:14:20 +04:00
my $query = "select bugs.bug_id";
1998-08-26 10:14:20 +04:00
foreach my $c (@collist) {
if (exists $::needquote{$c}) {
$query .= ",
\t$::key{$c}";
}
1998-08-26 10:14:20 +04:00
}
if ($dotweak) {
$query .= ",
1998-08-26 10:14:20 +04:00
bugs.product,
bugs.bug_status";
1998-08-26 10:14:20 +04:00
}
$query .= "
1998-08-26 10:14:20 +04:00
from bugs,
profiles assign,
profiles report,
versions projector
where bugs.assigned_to = assign.userid
and bugs.reporter = report.userid
and bugs.product = projector.program
and bugs.version = projector.value
";
1998-08-26 10:14:20 +04:00
if (defined $::FORM{'sql'}) {
$query .= "and (\n$::FORM('sql')\n)"
1998-08-26 10:14:20 +04:00
} else {
my @legal_fields = ("bug_id", "product", "version", "rep_platform", "op_sys",
"bug_status", "resolution", "priority", "bug_severity",
"assigned_to", "reporter", "bug_file_loc", "component");
foreach my $field (keys %::FORM) {
my $or = "";
if (lsearch(\@legal_fields, $field) != -1 && $::FORM{$field} ne "") {
$query .= "\tand (\n";
if ($field eq "assigned_to" || $field eq "reporter") {
foreach my $p (split(/,/, $::FORM{$field})) {
my $whoid = DBNameToIdAndCheck($p);
$query .= "\t\t${or}bugs.$field = $whoid\n";
$or = "or ";
}
1998-08-26 10:14:20 +04:00
} else {
my $ref = $::MFORM{$field};
foreach my $v (@$ref) {
if ($v eq "(empty)") {
$query .= "\t\t${or}bugs.$field is null\n";
} else {
if ($v eq "---") {
$query .= "\t\t${or}bugs.$field = ''\n";
} else {
$query .= "\t\t${or}bugs.$field = " . SqlQuote($v) .
"\n";
}
}
$or = "or ";
}
1998-08-26 10:14:20 +04:00
}
$query .= "\t)\n";
1998-08-26 10:14:20 +04:00
}
}
}
1998-08-26 10:14:20 +04:00
if (defined $::FORM{'changedin'}) {
my $c = trim($::FORM{'changedin'});
if ($c ne "") {
if ($c !~ /^[0-9]*$/) {
print "
The 'changed in last ___ days' field must be a simple number. You entered
\"$c\", which doesn't cut it.
<P>
Click the <B>Back</B> button and try again.";
exit;
}
$query .= "and to_days(now()) - to_days(bugs.delta_ts) <= $c ";
}
1998-08-26 10:14:20 +04:00
}
foreach my $f ("short_desc", "long_desc") {
if (defined $::FORM{$f}) {
my $s = SqlQuote(trim($::FORM{$f}));
if ($s ne "") {
if ($::FORM{$f . "_type"} eq "regexp") {
$query .= "and $f regexp $s ";
} else {
$query .= "and instr($f, $s) ";
}
1998-08-26 10:14:20 +04:00
}
}
}
if (defined $::FORM{'order'} && $::FORM{'order'} ne "") {
$query .= "order by ";
ORDER: for ($::FORM{'order'}) {
/\./ && do {
# This (hopefully) already has fieldnames in it, so we're done.
last ORDER;
};
/Number/ && do {
$::FORM{'order'} = "bugs.bug_id";
last ORDER;
};
/Import/ && do {
$::FORM{'order'} = "bugs.priority";
last ORDER;
};
/Assign/ && do {
$::FORM{'order'} = "assign.login_name, bugs.bug_status, priority, bugs.bug_id";
last ORDER;
};
# DEFAULT
$::FORM{'order'} = "bugs.bug_status, priorities.rank, assign.login_name, bugs.bug_id";
1998-08-26 10:14:20 +04:00
}
$query .= $::FORM{'order'};
1998-08-26 10:14:20 +04:00
}
if ($serverpush) {
print "Please stand by ... <p>\n";
if (defined $::FORM{'debug'}) {
print "<pre>$query</pre>\n";
}
1998-08-26 10:14:20 +04:00
}
SendSQL($query);
my $count = 0;
$::bugl = "";
sub pnl {
my ($str) = (@_);
$::bugl .= $str;
1998-08-26 10:14:20 +04:00
}
my $fields = $::buffer;
$fields =~ s/[&?]order=[^&]*//g;
$fields =~ s/[&?]cmdtype=[^&]*//g;
1998-08-26 10:14:20 +04:00
my $oldorder;
if (defined $::FORM{'order'}) {
$oldorder = url_quote(", $::FORM{'order'}");
1998-08-26 10:14:20 +04:00
} else {
$oldorder = "";
1998-08-26 10:14:20 +04:00
}
if ($dotweak) {
pnl "<FORM NAME=changeform METHOD=POST ACTION=\"process_bug.cgi\">";
1998-08-26 10:14:20 +04:00
}
my $tablestart = "<TABLE CELLSPACING=0 CELLPADDING=2>
<TR ALIGN=LEFT><TH>
<A HREF=\"buglist.cgi?$fields&order=bugs.bug_id\">ID</A>";
1998-08-26 10:14:20 +04:00
foreach my $c (@collist) {
if (exists $::needquote{$c}) {
if ($::needquote{$c}) {
$tablestart .= "<TH WIDTH=100% valigh=left>";
} else {
$tablestart .= "<TH valign=left>";
}
if (defined $::sortkey{$c}) {
$tablestart .= "<A HREF=\"buglist.cgi?$fields&order=$::sortkey{$c}$oldorder\">$::title{$c}</A>";
} else {
$tablestart .= $::title{$c};
}
1998-08-26 10:14:20 +04:00
}
}
$tablestart .= "\n";
1998-08-26 10:14:20 +04:00
my @row;
my %seen;
my @bugarray;
my %prodhash;
my %statushash;
1998-08-26 10:14:20 +04:00
while (@row = FetchSQLData()) {
my $bug_id = shift @row;
if (!defined $seen{$bug_id}) {
$seen{$bug_id} = 1;
$count++;
if ($count % 200 == 0) {
# Too big tables take too much browser memory...
pnl "</TABLE>$tablestart";
}
push @bugarray, $bug_id;
pnl "<TR VALIGN=TOP ALIGN=LEFT><TD>";
if ($dotweak) {
pnl "<input type=checkbox name=id_$bug_id>";
}
pnl "<A HREF=\"show_bug.cgi?id=$bug_id\">";
pnl "$bug_id</A> ";
foreach my $c (@collist) {
my $value = shift @row;
my $nowrap = "";
if (exists $::needquote{$c} && $::needquote{$c}) {
$value = html_quote($value);
1998-08-26 10:14:20 +04:00
} else {
$value = "<nobr>$value</nobr>";
1998-08-26 10:14:20 +04:00
}
pnl "<td $nowrap>$value";
1998-08-26 10:14:20 +04:00
}
if ($dotweak) {
my $value = shift @row;
$prodhash{$value} = 1;
$value = shift @row;
$statushash{$value} = 1;
}
pnl "\n";
1998-08-26 10:14:20 +04:00
}
}
my $buglist = join(":", @bugarray);
if ($serverpush) {
print "\n";
print "--thisrandomstring\n";
}
my $toolong = 0;
print "Content-type: text/html\n";
if (length($buglist) < 4000) {
print "Set-Cookie: BUGLIST=$buglist\n";
} else {
print "Set-Cookie: BUGLIST=\n";
$toolong = 1;
1998-08-26 10:14:20 +04:00
}
print "\n";
PutHeader("Bug List");
1998-08-26 10:14:20 +04:00
print "
<CENTER>
<B>" . time2str("%a %b %e %T %Z %Y", time()) . "</B>";
1998-08-26 10:14:20 +04:00
if (defined $::FORM{'debug'}) {
print "<PRE>$query</PRE>\n";
1998-08-26 10:14:20 +04:00
}
if ($toolong) {
print "<h2>This list is too long for bugzilla's little mind; the\n";
print "Next/Prev/First/Last buttons won't appear.</h2>\n";
}
# This is stupid. We really really need to move the quip list into the DB!
my $quip;
if (open (COMMENTS, "<data/comments")) {
my @cdata;
while (<COMMENTS>) {
push @cdata, $_;
1998-08-26 10:14:20 +04:00
}
close COMMENTS;
$quip = $cdata[int(rand($#cdata + 1))];
} else {
$quip = "Bugzilla would like to put a random quip here, but nobody has entered any.";
}
print "<HR><I><A HREF=newquip.html>$quip\n";
print "</I></A></CENTER>\n";
print "<HR SIZE=10>$tablestart\n";
print $::bugl;
print "</TABLE>\n";
if ($count == 0) {
print "Zarro Boogs found.\n";
} elsif ($count == 1) {
print "One bug found.\n";
} else {
print "$count bugs found.\n";
1998-08-26 10:14:20 +04:00
}
if ($dotweak) {
GetVersionTable();
print "
1998-08-26 10:14:20 +04:00
<SCRIPT>
numelements = document.changeform.elements.length;
function SetCheckboxes(value) {
for (var i=0 ; i<numelements ; i++) {
item = document.changeform.elements\[i\];
item.checked = value;
}
}
document.write(\" <input type=button value=\\\"Uncheck All\\\" onclick=\\\"SetCheckboxes(false);\\\"> <input type=button value=\\\"Check All\\\" onclick=\\\"SetCheckboxes(true);\\\">\");
</SCRIPT>";
my $resolution_popup = make_options(\@::legal_resolution_no_dup, "FIXED");
my @prod_list = keys %prodhash;
my @list = @prod_list;
my @legal_versions;
my @legal_component;
if ($#prod_list == 1) {
@legal_versions = @{$::versions{$prod_list[0]}};
@legal_component = @{$::components{$prod_list[0]}};
1998-08-26 10:14:20 +04:00
}
my $version_popup = make_options(\@legal_versions, $::dontchange);
my $platform_popup = make_options(\@::legal_platform, $::dontchange);
my $priority_popup = make_options(\@::legal_priority, $::dontchange);
my $sev_popup = make_options(\@::legal_severity, $::dontchange);
my $component_popup = make_options(\@::legal_component, $::dontchange);
my $product_popup = make_options(\@::legal_product, $::dontchange);
1998-08-26 10:14:20 +04:00
print "
1998-08-26 10:14:20 +04:00
<hr>
<TABLE>
<TR>
<TD ALIGN=RIGHT><B>Product:</B></TD>
<TD><SELECT NAME=product>$product_popup</SELECT></TD>
<TD ALIGN=RIGHT><B>Version:</B></TD>
<TD><SELECT NAME=version>$version_popup</SELECT></TD>
1998-08-26 10:14:20 +04:00
<TR>
<TD ALIGN=RIGHT><B><A HREF=\"bug_status.html#rep_platform\">Platform:</A></B></TD>
<TD><SELECT NAME=rep_platform>$platform_popup</SELECT></TD>
<TD ALIGN=RIGHT><B><A HREF=\"bug_status.html#priority\">Priority:</A></B></TD>
<TD><SELECT NAME=priority>$priority_popup</SELECT></TD>
1998-08-26 10:14:20 +04:00
</TR>
<TR>
<TD ALIGN=RIGHT><B>Component:</B></TD>
<TD><SELECT NAME=component>$component_popup</SELECT></TD>
<TD ALIGN=RIGHT><B><A HREF=\"bug_status.html#severity\">Severity:</A></B></TD>
<TD><SELECT NAME=bug_severity>$sev_popup</SELECT></TD>
1998-08-26 10:14:20 +04:00
</TR>
</TABLE>
<INPUT NAME=multiupdate value=Y TYPE=hidden>
1998-08-26 10:14:20 +04:00
<B>Additional Comments:</B>
<BR>
<TEXTAREA WRAP=HARD NAME=comment ROWS=5 COLS=80></TEXTAREA><BR>";
1998-08-26 10:14:20 +04:00
# knum is which knob number we're generating, in javascript terms.
my $knum = 0;
print "
<INPUT TYPE=radio NAME=knob VALUE=none CHECKED>
Do nothing else<br>";
$knum++;
print "
<INPUT TYPE=radio NAME=knob VALUE=accept>
Accept bugs (change status to <b>ASSIGNED</b>)<br>";
$knum++;
if (!defined $statushash{'CLOSED'} &&
!defined $statushash{'VERIFIED'} &&
!defined $statushash{'RESOLVED'}) {
print "
<INPUT TYPE=radio NAME=knob VALUE=clearresolution>
Clear the resolution<br>";
$knum++;
print "
<INPUT TYPE=radio NAME=knob VALUE=resolve>
1998-08-26 10:14:20 +04:00
Resolve bugs, changing <A HREF=\"bug_status.html\">resolution</A> to
<SELECT NAME=resolution
1998-08-26 10:14:20 +04:00
ONCHANGE=\"document.changeform.knob\[$knum\].checked=true\">
$resolution_popup</SELECT><br>";
$knum++;
1998-08-26 10:14:20 +04:00
}
if (!defined $statushash{'NEW'} &&
!defined $statushash{'ASSIGNED'} &&
!defined $statushash{'REOPENED'}) {
print "
<INPUT TYPE=radio NAME=knob VALUE=reopen> Reopen bugs<br>";
$knum++;
1998-08-26 10:14:20 +04:00
}
my @statuskeys = keys %statushash;
if ($#statuskeys == 1) {
if (defined $statushash{'RESOLVED'}) {
print "
<INPUT TYPE=radio NAME=knob VALUE=verify>
Mark bugs as <b>VERIFIED</b><br>";
$knum++;
1998-08-26 10:14:20 +04:00
}
if (defined $statushash{'VERIFIED'}) {
print "
<INPUT TYPE=radio NAME=knob VALUE=close>
Mark bugs as <b>CLOSED</b><br>";
$knum++;
1998-08-26 10:14:20 +04:00
}
}
print "
<INPUT TYPE=radio NAME=knob VALUE=reassign>
1998-08-26 10:14:20 +04:00
<A HREF=\"bug_status.html#assigned_to\">Reassign</A> bugs to
<INPUT NAME=assigned_to SIZE=32
1998-08-26 10:14:20 +04:00
ONCHANGE=\"document.changeform.knob\[$knum\].checked=true\"
VALUE=\"$::COOKIE{'Bugzilla_login'}\"><br>";
$knum++;
print "<INPUT TYPE=radio NAME=knob VALUE=reassignbycomponent>
Reassign bugs to owner of selected component<br>";
$knum++;
1998-08-26 10:14:20 +04:00
print "
1998-08-26 10:14:20 +04:00
<p>
<font size=-1>
1998-08-26 10:14:20 +04:00
To make changes to a bunch of bugs at once:
<ol>
<li> Put check boxes next to the bugs you want to change.
<li> Adjust above form elements. (It's <b>always</b> a good idea to add some
comment explaining what you're doing.)
<li> Click the below \"Commit\" button.
</ol></font>
<INPUT TYPE=SUBMIT VALUE=Commit>
</FORM><hr>\n";
1998-08-26 10:14:20 +04:00
}
if ($count > 0) {
print "<FORM METHOD=POST ACTION=\"long_list.cgi\">
<INPUT TYPE=HIDDEN NAME=buglist VALUE=$buglist>
<INPUT TYPE=SUBMIT VALUE=\"Long Format\">
1998-08-26 10:14:20 +04:00
<A HREF=\"query.cgi\">Query Page</A>
<A HREF=\"colchange.cgi?$::buffer\">Change columns</A>
</FORM>";
if (!$dotweak && $count > 1) {
print "<A HREF=\"buglist.cgi?$fields&tweak=1\">Make changes to several of these bugs at once.</A>\n";
1998-08-26 10:14:20 +04:00
}
}
if ($serverpush) {
print "\n--thisrandomstring--\n";
}