bug_form.pl 15.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# 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;

24

25 26
my %knownattachments;

27 28 29 30 31 32 33 34 35
# This routine quoteUrls contains inspirations from the HTML::FromText CPAN
# module by Gareth Rees <garethr@cre.canon.co.uk>.  It has been heavily hacked,
# all that is really recognizable from the original is bits of the regular
# expressions.

sub quoteUrls {
    my $text = shift;		# Take a copy; don't modify in-place.
    return $text unless $text;

36 37
    my $base = Param('urlbase');

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    my $protocol = join '|',
    qw(afs cid ftp gopher http https mid news nntp prospero telnet wais);

    my %options = ( metachars => 1, @_ );

    my $count = 0;

    # Now, quote any "#" characters so they won't confuse stuff later
    $text =~ s/#/%#/g;

    # Next, find anything that looks like a URL or an email address and
    # pull them out the the text, replacing them with a "##<digits>##
    # marker, and writing them into an array.  All this confusion is
    # necessary so that we don't match on something we've already replaced,
    # which can happen if you do multiple s///g operations.

    my @things;
55
    while ($text =~ s%((mailto:)?([\w\.\-\+\=]+\@[\w\-]+(?:\.[\w\-]+)+)\b|
56
                       (\b((?:$protocol):\S+[\w/])))%"##$count##"%exo) {
57 58 59 60 61 62 63 64 65 66 67 68 69 70
        my $item = $&;

        $item = value_quote($item);

        if ($item !~ m/^$protocol:/o && $item !~ /^mailto:/) {
            # We must have grabbed this one because it looks like an email
            # address.
            $item = qq{<A HREF="mailto:$item">$item</A>};
        } else {
            $item = qq{<A HREF="$item">$item</A>};
        }

        $things[$count++] = $item;
    }
71 72 73 74 75 76 77 78
    while ($text =~ s/\bbug(\s|%\#)*(\d+)/"##$count##"/ei) {
        my $item = $&;
        my $num = $2;
        $item = value_quote($item); # Not really necessary, since we know
                                # there's no special chars in it.
        $item = qq{<A HREF="${base}show_bug.cgi?id=$num">$item</A>};
        $things[$count++] = $item;
    }
79 80 81 82 83 84
    while ($text =~ s/\*\*\* This bug has been marked as a duplicate of (\d+) \*\*\*/"##$count##"/ei) {
        my $item = $&;
        my $num = $1;
        $item =~ s@\d+@<A HREF="${base}show_bug.cgi?id=$num">$num</A>@;
        $things[$count++] = $item;
    }
85 86 87 88 89 90 91 92
    while ($text =~ s/Created an attachment \(id=(\d+)\)/"##$count##"/e) {
        my $item = $&;
        my $num = $1;
        if (exists $knownattachments{$num}) {
            $item = qq{<A HREF="showattachment.cgi?attach_id=$num">$item</A>};
        }
        $things[$count++] = $item;
    }
93 94 95 96 97 98 99 100 101 102 103 104 105

    $text = value_quote($text);

    # Stuff everything back from the array.
    for (my $i=0 ; $i<$count ; $i++) {
        $text =~ s/##$i##/$things[$i]/e;
    }

    # And undo the quoting of "#" characters.
    $text =~ s/%#/#/g;

    return $text;
}
106

107
my $loginok = quietly_check_login();
108

109 110
my $id = $::FORM{'id'};

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
my $query = "
select
        bug_id,
        product,
        version,
        rep_platform,
        op_sys,
        bug_status,
        resolution,
        priority,
        bug_severity,
        component,
        assigned_to,
        reporter,
        bug_file_loc,
        short_desc,
127 128 129
	target_milestone,
	qa_contact,
	status_whiteboard,
130
        date_format(creation_ts,'Y-m-d'),
131 132
        groupset,
	delta_ts
133
from bugs
134
where bug_id = $id
135
and bugs.groupset & $::usergroupset = bugs.groupset";
136 137 138 139 140 141 142 143 144

SendSQL($query);
my %bug;
my @row;
if (@row = FetchSQLData()) {
    my $count = 0;
    foreach my $field ("bug_id", "product", "version", "rep_platform",
		       "op_sys", "bug_status", "resolution", "priority",
		       "bug_severity", "component", "assigned_to", "reporter",
145
		       "bug_file_loc", "short_desc", "target_milestone",
146
                       "qa_contact", "status_whiteboard", "creation_ts",
147
                       "groupset", "delta_ts") {
148 149 150 151 152 153 154
	$bug{$field} = shift @row;
	if (!defined $bug{$field}) {
	    $bug{$field} = "";
	}
	$count++;
    }
} else {
155
    SendSQL("select groupset from bugs where bug_id = $id");
156 157 158 159
    if (@row = FetchSQLData()) {
        print "<H1>Permission denied.</H1>\n";
        if ($loginok) {
            print "Sorry; you do not have the permissions necessary to see\n";
160
            print "bug $id.\n";
161
        } else {
162
            print "Sorry; bug $id can only be viewed when logged\n";
163 164
            print "into an account with the appropriate permissions.  To\n";
            print "see this bug, you must first\n";
165
            print "<a href=\"show_bug.cgi?id=$id&GoAheadAndLogIn=1\">";
166 167 168 169
            print "log in</a>.";
        }
    } else {
        print "<H1>Bug not found</H1>\n";
170
        print "There does not seem to be a bug numbered $id.\n";
171 172
    }
    exit;
173 174 175 176
}

$bug{'assigned_to'} = DBID_to_name($bug{'assigned_to'});
$bug{'reporter'} = DBID_to_name($bug{'reporter'});
177
$bug{'long_desc'} = GetLongDescription($id);
178
my $longdesclength = length($bug{'long_desc'});
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197


GetVersionTable();

#
# These should be read from the database ...
#

my $resolution_popup = make_options(\@::legal_resolution_no_dup,
				    $bug{'resolution'});
my $platform_popup = make_options(\@::legal_platform, $bug{'rep_platform'});
my $priority_popup = make_options(\@::legal_priority, $bug{'priority'});
my $sev_popup = make_options(\@::legal_severity, $bug{'bug_severity'});


my $component_popup = make_options($::components{$bug{'product'}},
				   $bug{'component'});

my $cc_element = '<INPUT NAME=cc SIZE=30 VALUE="' .
198
    ShowCcList($id) . '">';
199 200 201 202 203 204 205 206 207 208 209 210


my $URL = $bug{'bug_file_loc'};

if (defined $URL && $URL ne "none" && $URL ne "NULL" && $URL ne "") {
    $URL = "<B><A HREF=\"$URL\">URL:</A></B>";
} else {
    $URL = "<B>URL:</B>";
}

print "
<FORM NAME=changeform METHOD=POST ACTION=\"process_bug.cgi\">
211 212
<INPUT TYPE=HIDDEN NAME=\"delta_ts\" VALUE=\"$bug{'delta_ts'}\">
<INPUT TYPE=HIDDEN NAME=\"longdesclength\" VALUE=\"$longdesclength\">
213
<INPUT TYPE=HIDDEN NAME=\"id\" VALUE=$id>
214 215
<INPUT TYPE=HIDDEN NAME=\"was_assigned_to\" VALUE=\"$bug{'assigned_to'}\">
  <TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0><TR>
216
    <TD ALIGN=RIGHT><B>Bug#:</B></TD><TD><A HREF=\"show_bug.cgi?id=$bug{'bug_id'}\">$bug{'bug_id'}</A></TD>
217 218 219 220 221 222 223 224 225 226 227
    <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>Version:</B></TD>
    <TD><SELECT NAME=version>" .
    make_options($::versions{$bug{'product'}}, $bug{'version'}) .
    "</SELECT></TD>
  </TR><TR>
    <TD ALIGN=RIGHT><B>Product:</B></TD>
    <TD><SELECT NAME=product>" .
    make_options(\@::legal_product, $bug{'product'}) .
    "</SELECT></TD>
228 229 230 231
    <TD ALIGN=RIGHT><B>OS:</B></TD>
    <TD><SELECT NAME=op_sys>" .
    make_options(\@::legal_opsys, $bug{'op_sys'}) .
    "</SELECT><TD ALIGN=RIGHT><B>Reporter:</B></TD><TD>$bug{'reporter'}</TD>
232 233 234 235 236 237 238 239 240 241 242 243
  </TR><TR>
    <TD ALIGN=RIGHT><B><A HREF=\"bug_status.html\">Status:</A></B></TD>
      <TD>$bug{'bug_status'}</TD>
    <TD ALIGN=RIGHT><B><A HREF=\"bug_status.html#priority\">Priority:</A></B></TD>
      <TD><SELECT NAME=priority>$priority_popup</SELECT></TD>
    <TD ALIGN=RIGHT><B>Cc:</B></TD>
      <TD> $cc_element </TD>
  </TR><TR>
    <TD ALIGN=RIGHT><B><A HREF=\"bug_status.html\">Resolution:</A></B></TD>
      <TD>$bug{'resolution'}</TD>
    <TD ALIGN=RIGHT><B><A HREF=\"bug_status.html#severity\">Severity:</A></B></TD>
      <TD><SELECT NAME=bug_severity>$sev_popup</SELECT></TD>
244 245
    <TD ALIGN=RIGHT><B><A HREF=\"describecomponents.cgi?product=" .
    url_quote($bug{'product'}) . "\">Component:</A></B></TD>
246 247 248 249
      <TD><SELECT NAME=component>$component_popup</SELECT></TD>
  </TR><TR>
    <TD ALIGN=RIGHT><B><A HREF=\"bug_status.html#assigned_to\">Assigned&nbsp;To:
        </A></B></TD>
250 251 252
      <TD>$bug{'assigned_to'}</TD>";

if (Param("usetargetmilestone")) {
253 254 255 256 257 258 259
    my $url = "";
    if (defined $::milestoneurl{$bug{'product'}}) {
        $url = $::milestoneurl{$bug{'product'}};
    }
    if ($url eq "") {
        $url = "notargetmilestone.html";
    }
260 261 262
    if ($bug{'target_milestone'} eq "") {
        $bug{'target_milestone'} = " ";
    }
263
    push(@::legal_target_milestone, " ");
264
    print "
265
<TD ALIGN=RIGHT><A href=\"$url\"><B>Target Milestone:</B></A></TD>
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
<TD><SELECT NAME=target_milestone>" .
    make_options(\@::legal_target_milestone,
                 $bug{'target_milestone'}) .
                     "</SELECT></TD>";
}

print "
</TR>";

if (Param("useqacontact")) {
    my $name = $bug{'qa_contact'} > 0 ? DBID_to_name($bug{'qa_contact'}) : "";
    print "
  <TR>
    <TD ALIGN=\"RIGHT\"><B>QA Contact:</B>
    <TD COLSPAN=6>
      <INPUT NAME=qa_contact VALUE=\"" .
    value_quote($name) .
    "\" SIZE=60></
  </TR>";
}


print "
  <TR>
290 291 292 293 294 295 296 297 298
    <TD ALIGN=\"RIGHT\">$URL
    <TD COLSPAN=6>
      <INPUT NAME=bug_file_loc VALUE=\"$bug{'bug_file_loc'}\" SIZE=60></TD>
  </TR><TR>
    <TD ALIGN=\"RIGHT\"><B>Summary:</B>
    <TD COLSPAN=6>
      <INPUT NAME=short_desc VALUE=\"" .
    value_quote($bug{'short_desc'}) .
    "\" SIZE=60></TD>
299 300 301 302 303 304 305 306 307 308 309 310 311
  </TR>";

if (Param("usestatuswhiteboard")) {
    print "
  <TR>
    <TD ALIGN=\"RIGHT\"><B>Status Whiteboard:</B>
    <TD COLSPAN=6>
      <INPUT NAME=status_whiteboard VALUE=\"" .
    value_quote($bug{'status_whiteboard'}) .
    "\" SIZE=60></
  </TR>";
}

312
print "<tr><td align=right><B>Attachments:</b></td>\n";
313
SendSQL("select attach_id, creation_ts, description from attachments where bug_id = $id");
314
while (MoreSQLData()) {
315
    my ($attachid, $date, $desc) = (FetchSQLData());
316 317 318
    if ($date =~ /^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
        $date = "$3/$4/$2 $5:$6";
    }
319
    my $link = "showattachment.cgi?attach_id=$attachid";
320 321
    $desc = value_quote($desc);
    print qq{<td><a href="$link">$date</a></td><td colspan=4>$desc</td></tr><tr><td></td>};
322 323
    $knownattachments{$attachid} = 1;
}
324
print "<td colspan=6><a href=\"createattachment.cgi?id=$id\">Create a new attachment</a> (proposed patch, testcase, etc.)</td></tr></table>\n";
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351


sub EmitDependList {
    my ($desc, $myfield, $targetfield) = (@_);
    print "<th align=right>$desc:</th><td>";
    my @list;
    SendSQL("select dependencies.$targetfield, bugs.bug_status
 from dependencies, bugs
 where dependencies.$myfield = $id
   and bugs.bug_id = dependencies.$targetfield
 order by dependencies.$targetfield");
    while (MoreSQLData()) {
        my ($i, $stat) = (FetchSQLData());
        push(@list, $i);
        my $opened = ($stat eq "NEW" || $stat eq "ASSIGNED" ||
                      $stat eq "REOPENED");
        if (!$opened) {
            print "<strike>";
        }
        print qq{<a href="show_bug.cgi?id=$i">$i</a>};
        if (!$opened) {
            print "</strike>";
        }
        print " ";
    }
    print "</td><td><input name=$targetfield value=\"" .
        join(',', @list) . "\"></td>\n";
352 353
}

354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
if (Param("usedependencies")) {
    print "<table><tr>\n";
    EmitDependList("Bugs that bug $id depends on", "blocked", "dependson");
    print qq{
<td rowspan=2><a href="showdependencytree.cgi?id=$id">Show dependency tree</a>
};
    if (Param("webdotbase") ne "") {
        print qq{
<br><a href="showdependencygraph.cgi?id=$id">Show dependency graph</a>
};
    }
    print "</td></tr><tr>";
    EmitDependList("Bugs depending on bug $id", "dependson", "blocked");
    print "</tr></table>\n";
}
369 370

print "
371 372 373
<br>
<B>Additional Comments:</B>
<BR>
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
<TEXTAREA WRAP=HARD NAME=comment ROWS=5 COLS=80></TEXTAREA><BR>";


if ($::usergroupset ne '0') {
    SendSQL("select bit, description, (bit & $bug{'groupset'} != 0) from groups where bit & $::usergroupset != 0 and isbuggroup != 0 order by bit");
    while (MoreSQLData()) {
        my ($bit, $description, $ison) = (FetchSQLData());
        my $check0 = !$ison ? " SELECTED" : "";
        my $check1 = $ison ? " SELECTED" : "";
        print "<select name=bit-$bit><option value=0$check0>\n";
        print "People not in the \"$description\" group can see this bug\n";
        print "<option value=1$check1>\n";
        print "Only people in the \"$description\" group can see this bug\n";
        print "</select><br>\n";
    }
}

print "<br>
392 393 394
<INPUT TYPE=radio NAME=knob VALUE=none CHECKED>
        Leave as <b>$bug{'bug_status'} $bug{'resolution'}</b><br>";

395

396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
# knum is which knob number we're generating, in javascript terms.

my $knum = 1;

my $status = $bug{'bug_status'};

if ($status eq "NEW" || $status eq "ASSIGNED" || $status eq "REOPENED") {
    if ($status ne "ASSIGNED") {
        print "<INPUT TYPE=radio NAME=knob VALUE=accept>";
	print "Accept bug (change status to <b>ASSIGNED</b>)<br>";
        $knum++;
    }
    if ($bug{'resolution'} ne "") {
        print "<INPUT TYPE=radio NAME=knob VALUE=clearresolution>\n";
        print "Clear the resolution (remove the current resolution of\n";
        print "<b>$bug{'resolution'}</b>)<br>\n";
        $knum++;
    }
    print "<INPUT TYPE=radio NAME=knob VALUE=resolve>
        Resolve bug, changing <A HREF=\"bug_status.html\">resolution</A> to
        <SELECT NAME=resolution
          ONCHANGE=\"document.changeform.knob\[$knum\].checked=true\">
          $resolution_popup</SELECT><br>\n";
    $knum++;
    print "<INPUT TYPE=radio NAME=knob VALUE=duplicate>
        Resolve bug, mark it as duplicate of bug # 
        <INPUT NAME=dup_id SIZE=6 ONCHANGE=\"document.changeform.knob\[$knum\].checked=true\"><br>\n";
    $knum++;
424
    my $assign_element = "<INPUT NAME=\"assigned_to\" SIZE=32 ONCHANGE=\"document.changeform.knob\[$knum\].checked=true\" VALUE=\"$bug{'assigned_to'}\">";
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454

    print "<INPUT TYPE=radio NAME=knob VALUE=reassign> 
          <A HREF=\"bug_status.html#assigned_to\">Reassign</A> bug to
          $assign_element
        <br>\n";
    $knum++;
    print "<INPUT TYPE=radio NAME=knob VALUE=reassignbycomponent>
          Reassign bug to owner of selected component<br>\n";
    $knum++;
} else {
    print "<INPUT TYPE=radio NAME=knob VALUE=reopen> Reopen bug<br>\n";
    $knum++;
    if ($status eq "RESOLVED") {
        print "<INPUT TYPE=radio NAME=knob VALUE=verify>
        Mark bug as <b>VERIFIED</b><br>\n";
        $knum++;
    }
    if ($status ne "CLOSED") {
        print "<INPUT TYPE=radio NAME=knob VALUE=close>
        Mark bug as <b>CLOSED</b><br>\n";
        $knum++;
    }
}
 
print "
<INPUT TYPE=\"submit\" VALUE=\"Commit\">
<INPUT TYPE=\"reset\" VALUE=\"Reset\">
<INPUT TYPE=hidden name=form_name VALUE=process_bug>
<BR>
<FONT size=\"+1\"><B>
455 456
 <A HREF=\"show_activity.cgi?id=$id\">View Bug Activity</A>
 <A HREF=\"long_list.cgi?buglist=$id\">Format For Printing</A>
457 458
</B></FONT><BR>
</FORM>
459
<table><tr><td align=left><B>Description:</B></td><td width=\"100%\">&nbsp;</td>
460 461 462
<td align=right>Opened:&nbsp;$bug{'creation_ts'}</td></tr></table>
<HR>
<PRE>
463
";
464
print quoteUrls($bug{'long_desc'}, email=>1, urls=>1);
465
print "
466 467 468 469 470
</PRE>
<HR>\n";

# To add back option of editing the long description, insert after the above
# long_list.cgi line:
471
#  <A HREF=\"edit_desc.cgi?id=$id\">Edit Long Description</A>
472 473 474

navigation_header();

475
1;