reports.cgi 24.6 KB
Newer Older
1 2 3
#!/usr/bonsaitools/bin/perl -w
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
4 5 6 7
# 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/
8
#
9 10 11 12
# 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.
13 14 15 16
#
# The Original Code is the Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
17 18 19
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
20 21
#
# Contributor(s): Harrison Page <harrison@netscape.com>,
22
# Terry Weissman <terry@mozilla.org>,
23 24 25 26 27
# Dawn Endico <endico@mozilla.org>
# Bryce Nesbitt <bryce@nextbus.COM>,
#    Added -All- report, change "nobanner" to "banner" (it is strange to have a
#    list with 2 positive and 1 negative choice), default links on, add show
#    sql comment.
28 29 30
# Joe Robins <jmrobins@tgix.com>,
#    If using the usebuggroups parameter, users shouldn't be able to see
#    reports for products they don't have access to.
31 32 33 34 35 36 37
# Gervase Markham <gerv@gerv.net> and Adam Spiers <adam@spiers.net>
#    Added ability to chart any combination of resolutions/statuses.
#    Derive the choice of resolutions/statuses from the -All- data file
#    Removed hardcoded order of resolutions/statuses when reading from
#    daily stats file, so now works independently of collectstats.pl
#    version
#    Added image caching by date and datasets
38 39
# Myk Melez <myk@mozilla.org):
#    Implemented form field validation and reorganized code.
40 41 42

use diagnostics;
use strict;
43

44
eval "use GD";
45
my $use_gd = $@ ? 0 : 1;
46
eval "use Chart::Lines";
47
$use_gd = 0 if $@;
48 49

require "CGI.pl";
50
use vars qw(%FORM); # globals from CGI.pl
51

52 53
require "globals.pl";
use vars qw(@legal_product); # globals from er, globals.pl
54

55
my $dir = "data/mining";
56
my $graph_dir = "graphs";
57

58
my @status = qw (NEW ASSIGNED REOPENED);
59
my %bugsperperson;
60

61 62 63
# while this looks odd/redundant, it allows us to name
# functions differently than the value passed in
my %reports = 
64 65 66 67 68 69
    ( 
    "most_doomed" => \&most_doomed,
    "most_doomed_for_milestone" => \&most_doomed_for_milestone,
    "most_recently_doomed" => \&most_recently_doomed,
    "show_chart" => \&show_chart,
    );
70

71 72
# If we're using bug groups for products, we should apply those restrictions
# to viewing reports, as well.  Time to check the login in that case.
73
ConnectToDatabase(1);
74 75
quietly_check_login();

76
GetVersionTable();
77

78 79
# If the usebuggroups parameter is set, we don't want to list all products.
# We only want those products that the user has permissions for.
80
my @myproducts;
81
if(Param("usebuggroups")) {
82 83 84 85 86 87 88
    push( @myproducts, "-All-");
    foreach my $this_product (@legal_product) {
        if(GroupExists($this_product) && !UserInGroup($this_product)) {
            next;
        } else {
            push( @myproducts, $this_product )
        }
89 90
    }
} else {
91
    push( @myproducts, "-All-", @legal_product );
92
}
93

94
if (! defined $FORM{'product'}) {
95 96 97

    print "Content-type: text/html\n\n";
    PutHeader("Bug Reports");
98
    &choose_product;
99 100 101 102 103 104 105 106 107 108
    PutFooter();

} else {

    # For security and correctness, validate the value of the "product" form variable.
    # Valid values are those products for which the user has permissions which appear
    # in the "product" drop-down menu on the report generation form.
    grep($_ eq $FORM{'product'}, @myproducts)
      || DisplayError("You entered an invalid product name.") && exit;

109 110
    # If usebuggroups is on, we don't want people to be able to view
    # reports for products they don't have permissions for...
111 112 113 114 115
    Param("usebuggroups") 
      && GroupExists($FORM{'product'}) 
      && !UserInGroup($FORM{'product'})
      && DisplayError("You do not have the permissions necessary to view reports for this product.")
      && exit;
116
          
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    # For security and correctness, validate the value of the "output" form variable.
    # Valid values are the keys from the %reports hash defined above which appear in
    # the "output" drop-down menu on the report generation form.
    $FORM{'output'} ||= "most_doomed"; # a reasonable default
    grep($_ eq $FORM{'output'}, keys %reports)
      || DisplayError("You entered an invalid output type.") 
      && exit;

    # Output appropriate HTTP response headers
    print "Content-type: text/html\n";
    # Changing attachment to inline to resolve 46897 - zach@zachlipton.com
    print "Content-disposition: inline; filename=bugzilla_report.html\n\n";

    if ($FORM{'banner'}) {
      PutHeader("Bug Reports");
    } 
    else {
      print("<html><head><title>Bug Reports</title></head><body bgcolor=\"#FFFFFF\">");
135 136
    }

137 138 139
    # Execute the appropriate report generation function 
    # (the one whose name is the same as the value of the "output" form variable).
    &{$reports{$FORM{'output'}}};
140

141 142
    # ??? why is this necessary? formatting looks fine without it
    print "<p>";
143

144 145 146
    PutFooter() if $FORM{banner};

}
147

148

149

150 151 152 153
##################################
# user came in with no form data #
##################################

154 155
sub choose_product {
    my $product_popup = make_options (\@myproducts, $myproducts[0]);
156 157
  
    my $datafile = daily_stats_filename('-All-');
158

159 160 161 162 163 164
    # Can we do bug charts?  
         my $do_charts = ($use_gd && -d $dir && -d $graph_dir &&
                              open(DATA, "$dir/$datafile"));
 
     my $charts = $do_charts ? "<option value=\"show_chart\">Bug Charts" : "";
 
165
    print <<FIN;
166 167 168 169 170 171 172 173 174 175 176 177 178
<center>
<h1>Welcome to the Bugzilla Query Kitchen</h1>
<form method=get action=reports.cgi>
<table border=1 cellpadding=5>
<tr>
<td align=center><b>Product:</b></td>
<td align=center>
<select name="product">
$product_popup
</select>
</td>
</tr>
<tr>
179 180 181 182
<td align=center><b>Output:</b></td>
<td align=center>
<select name="output">
<option value="most_doomed">Bug Counts
183
FIN
184 185 186 187 188
    if (Param('usetargetmilestone')) {
        print "<option value=\"most_doomed_for_milestone\">Most Doomed";
    }
    print "<option value=\"most_recently_doomed\">Most Recently Doomed";
    print <<FIN;
189
$charts
190
</select>
191
</tr>
192 193
FIN

194 195 196 197 198 199 200
  if ($do_charts) {
      print <<FIN;
      <tr>
      <td align=center><b>Chart datasets:</b></td>
      <td align=center>
      <select name="datasets" multiple size=5>
FIN
201

202
      my @datasets = ();
203

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
      while (<DATA>) {
          if (/^# fields?: (.+)\s*$/) {
              @datasets = grep ! /date/i, (split /\|/, $1);
              last;
          }
      }

      close(DATA);

      my %default_sel = map { $_ => 1 }
                            qw/UNCONFIRMED NEW ASSIGNED REOPENED/;
      foreach my $dataset (@datasets) {
          my $sel = $default_sel{$dataset} ? ' selected' : '';
          print qq{<option value="$dataset:"$sel>$dataset</option>\n};
      }

      print <<FIN;
      </select>
      </td>
      </tr>
FIN
  }

print <<FIN;
228
<tr>
229 230
<td align=center><b>Switches:</b></td>
<td align=left>
231 232
<input type=checkbox name=links checked value=1>&nbsp;Links to Bugs<br>
<input type=checkbox name=banner checked value=1>&nbsp;Banner<br>
233
FIN
234 235 236 237 238 239 240
  
    if (Param('usequip')) {
        print "<input type=checkbox name=quip value=1>&nbsp;Quip<br>";
    } else {
        print "<input type=hidden name=quip value=0>";
    }
    print <<FIN;
241 242 243 244 245 246 247 248 249 250 251
</td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=submit value=Continue>
</td>
</tr>
</table>
</form>
<p>
FIN
252 253
#Add this above to get a control for showing the SQL query:
#<input type=checkbox name=showsql value=1>&nbsp;Show SQL<br>
254
}
255

256 257
sub most_doomed {
    my $when = localtime (time);
258

259
    print <<FIN;
260 261
<center>
<h1>
262
Bug Report for $FORM{'product'}
263 264 265 266
</h1>
$when<p>
FIN

267
# Build up $query string
268 269
    my $query;
    $query = <<FIN;
270
select 
271 272 273 274 275
    bugs.bug_id, bugs.assigned_to, bugs.bug_severity,
    bugs.bug_status, bugs.product, 
    assign.login_name,
    report.login_name,
    unix_timestamp(date_format(bugs.creation_ts, '%Y-%m-%d %h:%m:%s'))
276 277 278 279 280 281 282

from   bugs,
       profiles assign,
       profiles report,
       versions projector
where  bugs.assigned_to = assign.userid
and    bugs.reporter = report.userid
283 284
FIN

285 286 287 288 289 290 291 292 293 294 295
    if ($FORM{'product'} ne "-All-" ) {
        $query .= "and    bugs.product=".SqlQuote($FORM{'product'});
    }

    $query .= <<FIN;
and      
    ( 
    bugs.bug_status = 'NEW' or 
    bugs.bug_status = 'ASSIGNED' or 
    bugs.bug_status = 'REOPENED'
    )
296
FIN
297
# End build up $query string
298

299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 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 352 353
    print "<font color=purple><tt>$query</tt></font><p>\n" 
        unless (! exists $FORM{'showsql'});

    SendSQL ($query);
    
    my $c = 0;

    my $quip = "Summary";
    my $bugs_count = 0;
    my $bugs_new_this_week = 0;
    my $bugs_reopened = 0;
    my %bugs_owners;
    my %bugs_summary;
    my %bugs_status;
    my %bugs_totals;
    my %bugs_lookup;

    #############################
    # suck contents of database # 
    #############################

    my $week = 60 * 60 * 24 * 7;
    while (my ($bid, $a, $sev, $st, $prod, $who, $rep, $ts) = FetchSQLData()) {
        next if (exists $bugs_lookup{$bid});
        
        $bugs_lookup{$bid} ++;
        $bugs_owners{$who} ++;
        $bugs_new_this_week ++ if (time - $ts <= $week);
        $bugs_status{$st} ++;
        $bugs_count ++;
        
        push @{$bugs_summary{$who}{$st}}, $bid;
        
        $bugs_totals{$who}{$st} ++;
    }

    if ($FORM{'quip'}) {
        if (open (COMMENTS, "<data/comments")) {
            my @cdata;
            while (<COMMENTS>) {
                push @cdata, $_;
            }
            close COMMENTS;
            $quip = "<i>" . $cdata[int(rand($#cdata + 1))] . "</i>";
        }
    } 

    #########################
    # start painting report #
    #########################

    $bugs_status{'NEW'}      ||= '0';
    $bugs_status{'ASSIGNED'} ||= '0';
    $bugs_status{'REOPENED'} ||= '0';
    print <<FIN;
354
<h1>$quip</h1>
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
<table border=1 cellpadding=5>
<tr>
<td align=right><b>New Bugs This Week</b></td>
<td align=center>$bugs_new_this_week</td>
</tr>

<tr>
<td align=right><b>Bugs Marked New</b></td>
<td align=center>$bugs_status{'NEW'}</td>
</tr>

<tr>
<td align=right><b>Bugs Marked Assigned</b></td>
<td align=center>$bugs_status{'ASSIGNED'}</td>
</tr>

<tr>
<td align=right><b>Bugs Marked Reopened</b></td>
<td align=center>$bugs_status{'REOPENED'}</td>
</tr>

<tr>
<td align=right><b>Total Bugs</b></td>
<td align=center>$bugs_count</td>
</tr>

</table>
<p>
FIN

385 386 387 388 389 390 391
    if ($bugs_count == 0) {
        print "No bugs found!\n";
                PutFooter() if $FORM{banner};
        exit;
    }
    
    print <<FIN;
392 393 394 395 396 397 398 399 400 401 402
<h1>Bug Count by Engineer</h1>
<table border=3 cellpadding=5>
<tr>
<td align=center bgcolor="#DDDDDD"><b>Owner</b></td>
<td align=center bgcolor="#DDDDDD"><b>New</b></td>
<td align=center bgcolor="#DDDDDD"><b>Assigned</b></td>
<td align=center bgcolor="#DDDDDD"><b>Reopened</b></td>
<td align=center bgcolor="#DDDDDD"><b>Total</b></td>
</tr>
FIN

403 404 405
    foreach my $who (sort keys %bugs_summary) {
        my $bugz = 0;
        print <<FIN;
406 407 408
<tr>
<td align=left><tt>$who</tt></td>
FIN
409 410 411 412
        
        foreach my $st (@status) {
            $bugs_totals{$who}{$st} += 0;
            print <<FIN;
413 414
<td align=center>$bugs_totals{$who}{$st}
FIN
415 416 417 418
            $bugz += $#{$bugs_summary{$who}{$st}} + 1;
        }
        
        print <<FIN;
419 420 421
<td align=center>$bugz</td>
</tr>
FIN
422 423 424
    }
    
    print <<FIN;
425 426 427 428
</table>
<p>
FIN

429 430 431
    ###############################
    # individual bugs by engineer #
    ###############################
432

433
    print <<FIN;
434 435 436 437 438 439 440 441 442 443
<h1>Individual Bugs by Engineer</h1>
<table border=1 cellpadding=5>
<tr>
<td align=center bgcolor="#DDDDDD"><b>Owner</b></td>
<td align=center bgcolor="#DDDDDD"><b>New</b></td>
<td align=center bgcolor="#DDDDDD"><b>Assigned</b></td>
<td align=center bgcolor="#DDDDDD"><b>Reopened</b></td>
</tr>
FIN

444 445
    foreach my $who (sort keys %bugs_summary) {
        print <<FIN;
446 447 448 449
<tr>
<td align=left><tt>$who</tt></td>
FIN

450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
        foreach my $st (@status) {
            my @l;

            foreach (sort { $a <=> $b } @{$bugs_summary{$who}{$st}}) {
                if ($FORM{'links'}) {
                    push @l, "<a href=\"show_bug.cgi?id=$_\">$_</a>\n"; 
                }
                else {
                    push @l, $_;
                }
            }
                
            my $bugz = join ' ', @l;
            $bugz = "&nbsp;" unless ($bugz);
            
            print <<FIN
466 467
<td align=left>$bugz</td>
FIN
468
        }
469

470
        print <<FIN;
471 472
</tr>
FIN
473
    }
474

475
    print <<FIN;
476 477 478
</table>
<p>
FIN
479
}
480

481 482 483 484 485
sub daily_stats_filename {
    my ($prodname) = @_;
    $prodname =~ s/\//-/gs;
    return $prodname;
}
486

487
sub show_chart {
488 489 490 491
	# if we don't have the graphic mouldes don't even try to go
	# here. Should probably return some decent error message.
	return unless $use_gd;

492 493 494
    if (! $FORM{datasets}) {
        die_politely("You didn't select any datasets to plot");
    }
495

496 497 498 499
  print <<FIN;
<center>
FIN

500 501 502
    my $type = chart_image_type();
    my $data_file = daily_stats_filename($FORM{product});
    my $image_file = chart_image_name($data_file, $type);
503
    my $url_image = "$graph_dir/" . url_quote($image_file);
504

505 506
    if (! -e "$graph_dir/$image_file") {
        generate_chart("$dir/$data_file", "$graph_dir/$image_file", $type);
507 508 509
    }
    
    print <<FIN;
510
<img src="$url_image">
511 512 513
<br clear=left>
<br>
FIN
514
}
515

516 517 518 519
sub chart_image_type {
    # what chart type should we be generating?
    my $testimg = Chart::Lines->new(2,2);
    my $type = $testimg->can('gif') ? "gif" : "png";
520

521 522 523
    undef $testimg;
    return $type;
}
524

525 526 527
sub chart_image_name {
    my ($data_file, $type) = @_;

528 529 530
    # Cache charts by generating a unique filename based on what they
    # show. Charts should be deleted by collectstats.pl nightly.
    my $id = join ("_", split (":", $FORM{datasets}));
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558

    return "${data_file}_${id}.$type";
}

sub day_of_year {
    my ($mday, $month, $year) = (localtime())[3 .. 5];
    $month += 1;
    $year += 1900;
    my $date = sprintf "%02d%02d%04d", $mday, $month, $year;
}

sub generate_chart {
    my ($data_file, $image_file, $type) = @_;
    
    if (! open FILE, $data_file) {
        &die_politely ("The tool which gathers bug counts has not been run yet.");
    }

    my @fields;
    my @labels = qw(DATE);
    my %datasets = map { $_ => 1 } split /:/, $FORM{datasets};

    my %data = ();
    while (<FILE>) {
        chomp;
        next unless $_;
        if (/^#/) {
            if (/^# fields?: (.*)\s*$/) {
559
                @fields = split /\||\r/, $1;
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
                &die_politely("`# fields: ' line didn't start with DATE, but with $fields[0]")
                  unless $fields[0] =~ /date/i;
                push @labels, grep($datasets{$_}, @fields);
            }
            next;
        }

        &die_politely("`# fields: ' line was not found before start of data")
          unless @fields;
        
        my @line = split /\|/;
        my $date = $line[0];
        my ($yy, $mm, $dd) = $date =~ /^\d{2}(\d{2})(\d{2})(\d{2})$/;
        push @{$data{DATE}}, "$mm/$dd/$yy";
        
        for my $i (1 .. $#fields) {
            my $field = $fields[$i];
            if (! defined $line[$i] or $line[$i] eq '') {
                # no data point given, don't plot (this will probably
                # generate loads of Chart::Base warnings, but that's not
580
                # our fault.)
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
                push @{$data{$field}}, undef;
            }
            else {
                push @{$data{$field}}, $line[$i];
            }
        }
    }
    
    shift @labels;

    close FILE;

    if (! @{$data{DATE}}) {
        &die_politely ("We don't have enough data points to make a graph (yet)");
    }
    
    my $img = Chart::Lines->new (800, 600);
    my $i = 0;

    my $MAXTICKS = 20;      # Try not to show any more x ticks than this.
    my $skip = 1;
    if (@{$data{DATE}} > $MAXTICKS) {
        $skip = int((@{$data{DATE}} + $MAXTICKS - 1) / $MAXTICKS);
    }

    my %settings =
        (
         "title" => "Status Counts for $FORM{'product'}",
         "x_label" => "Dates",
         "y_label" => "Bug Counts",
         "legend_labels" => \@labels,
         "skip_x_ticks" => $skip,
         "y_grid_lines" => "true",
         "grey_background" => "false",
         "colors" => {
                      # default dataset colours are too alike
                      dataset4 => [0, 0, 0], # black
                     },
        );
    
    $img->set (%settings);
    $img->$type($image_file, [ @data{('DATE', @labels)} ]);
}

sub die_politely {
    my $msg = shift;

    print <<FIN;
629 630 631 632 633 634
<p>
<table border=1 cellpadding=10>
<tr>
<td align=center>
<font color=blue>Sorry, but ...</font>
<p>
635
There is no graph available for <b>$FORM{'product'}</b><p>
636 637 638 639 640 641 642 643

$msg
<p>
</td>
</tr>
</table>
<p>
FIN
644 645 646 647
    
    PutFooter() if $FORM{banner};
    exit;
}
648

649 650
sub bybugs {
   $bugsperperson{$a} <=> $bugsperperson{$b}
651
}
652

653 654 655 656
sub most_doomed_for_milestone {
    my $when = localtime (time);
    my $ms = "M" . Param("curmilestone");
    my $quip = "Summary";
657

658 659
    print "<center>\n<h1>";
    if( $FORM{'product'} ne "-All-" ) {
660 661 662
        SendSQL("SELECT defaultmilestone FROM products WHERE product = " .
                SqlQuote($FORM{'product'}));
        $ms = FetchOneColumn();
663 664 665 666 667
        print "Most Doomed for $ms ($FORM{'product'})";
    } else {
        print "Most Doomed for $ms";
    }
    print "</h1>\n$when<p>\n";
668

669 670 671
    #########################
    # start painting report #
    #########################
672

673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
    if ($FORM{'quip'}) {
        if (open (COMMENTS, "<data/comments")) {
            my @cdata;
            while (<COMMENTS>) {
                push @cdata, $_;
            }
            close COMMENTS;
            $quip = "<i>" . $cdata[int(rand($#cdata + 1))] . "</i>";
        }
    }
    
    # Build up $query string
    my $query;
    $query = "select distinct assigned_to from bugs where target_milestone=\"$ms\"";
    if ($FORM{'product'} ne "-All-" ) {
        $query .= "and    bugs.product=".SqlQuote($FORM{'product'});
    }
    $query .= <<FIN;
and      
    ( 
    bugs.bug_status = 'NEW' or 
    bugs.bug_status = 'ASSIGNED' or 
    bugs.bug_status = 'REOPENED'
    )
697 698 699
FIN
# End build up $query string

700 701 702 703 704
    SendSQL ($query);
    my @people = ();
    while (my ($person) = FetchSQLData()) {
        push @people, $person;
    }
705

706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
    #############################
    # suck contents of database # 
    #############################
    my $person = "";
    my $bugtotal = 0;
    foreach $person (@people) {
        my $query = "select count(bug_id) from bugs,profiles where target_milestone=\"$ms\" and userid=assigned_to and userid=\"$person\"";
        if( $FORM{'product'} ne "-All-" ) {
            $query .= "and    bugs.product=".SqlQuote($FORM{'product'});
        }
        $query .= <<FIN;
and      
    ( 
    bugs.bug_status = 'NEW' or 
    bugs.bug_status = 'ASSIGNED' or 
    bugs.bug_status = 'REOPENED'
    )
723
FIN
724 725 726 727 728
        SendSQL ($query);
        my $bugcount = FetchSQLData();
        $bugsperperson{$person} = $bugcount;
        $bugtotal += $bugcount;
    }
729

730 731 732
#   sort people by the number of bugs they have assigned to this milestone
    @people = sort bybugs @people;
    my $totalpeople = @people;
733
                
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768
    print "<TABLE>\n";
    print "<TR><TD COLSPAN=2>\n";
    print "$totalpeople engineers have $bugtotal $ms bugs and features.\n";
    print "</TD></TR>\n";

    while (@people) {
        $person = pop @people;
        print "<TR><TD>\n";
        SendSQL("select login_name from profiles where userid=$person");
        my $login_name= FetchSQLData();
        print("<A HREF=\"buglist.cgi?bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&target_milestone=$ms&assigned_to=$login_name");
        if ($FORM{'product'} ne "-All-" ) {
            print "&product=" . url_quote($FORM{'product'});
        }
        print("\">\n");
        print("$bugsperperson{$person}  bugs and features");
        print("</A>");
        print(" for \n");
        print("<A HREF=\"mailto:$login_name\">");
        print("$login_name");
        print("</A>\n");
        print("</TD><TD>\n");

        $person = pop @people;
        if ($person) {
            SendSQL("select login_name from profiles where userid=$person");
            my $login_name= FetchSQLData();
            print("<A HREF=\"buglist.cgi?bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&target_milestone=$ms&assigned_to=$login_name\">\n");
            print("$bugsperperson{$person}  bugs and features");
            print("</A>");
            print(" for \n");
            print("<A HREF=\"mailto:$login_name\">");
            print("$login_name");
            print("</A>\n");
            print("</TD></TR>\n\n");
769
        }
770 771 772
    }
    print "</TABLE>\n";
}
773 774


775 776 777 778 779 780 781
sub most_recently_doomed {
    my $when = localtime (time);
    my $ms = "M" . Param("curmilestone");
    my $quip = "Summary";
                                                     
    print "<center>\n<h1>";
    if( $FORM{'product'} ne "-All-" ) {
782 783 784
        SendSQL("SELECT defaultmilestone FROM products WHERE product = " .
                SqlQuote($FORM{'product'}));
        $ms = FetchOneColumn();
785 786 787 788 789
        print "Most Recently Doomed ($FORM{'product'})";
    } else {
        print "Most Recently Doomed";
    }
    print "</h1>\n$when<p>\n";
790

791 792 793
    #########################
    # start painting report #
    #########################
794

795 796 797 798 799
    if ($FORM{'quip'}) {
        if (open (COMMENTS, "<data/comments")) {
            my @cdata;
            while (<COMMENTS>) {
                push @cdata, $_;
800
            }
801 802 803 804
            close COMMENTS;
            $quip = "<i>" . $cdata[int(rand($#cdata + 1))] . "</i>";
        }
    }
805 806


807 808 809 810 811
    # Build up $query string
    my $query = "select distinct assigned_to from bugs where bugs.bug_status='NEW' and target_milestone='' and bug_severity!='enhancement' and status_whiteboard='' and (product='Browser' or product='MailNews')";
    if ($FORM{'product'} ne "-All-" ) {
        $query .= "and    bugs.product=".SqlQuote($FORM{'product'});
    }
812 813 814

# End build up $query string

815 816 817 818 819
    SendSQL ($query);
    my @people = ();
    while (my ($person) = FetchSQLData()) {
        push @people, $person;
    }
820

821 822 823 824 825 826 827 828 829 830 831 832 833 834 835
    #############################
    # suck contents of database # 
    #############################
    my $person = "";
    my $bugtotal = 0;
    foreach $person (@people) {
        my $query = "select count(bug_id) from bugs,profiles where bugs.bug_status='NEW' and userid=assigned_to and userid='$person' and target_milestone='' and bug_severity!='enhancement' and status_whiteboard='' and (product='Browser' or product='MailNews')";
        if( $FORM{'product'} ne "-All-" ) {
            $query .= "and    bugs.product='$FORM{'product'}'";
        }
        SendSQL ($query);
        my $bugcount = FetchSQLData();
        $bugsperperson{$person} = $bugcount;
        $bugtotal += $bugcount;
    }
836

837 838 839 840 841 842 843
#   sort people by the number of bugs they have assigned to this milestone
    @people = sort bybugs @people;
    my $totalpeople = @people;
    
    if ($totalpeople > 20) {
        splice @people, 0, $totalpeople-20;
    }
844
                
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
    print "<TABLE>\n";
    print "<TR><TD COLSPAN=2>\n";
    print "$totalpeople engineers have $bugtotal untouched new bugs.\n";
    if ($totalpeople > 20) {
        print "These are the 20 most doomed.";
    }
    print "</TD></TR>\n";

    while (@people) {
        $person = pop @people;
        print "<TR><TD>\n";
        SendSQL("select login_name from profiles where userid=$person");
        my $login_name= FetchSQLData();
        print("<A HREF=\"buglist.cgi?bug_status=NEW&email1=$login_name&emailtype1=substring&emailassigned_to1=1&product=Browser&product=MailNews&target_milestone=---&status_whiteboard=.&status_whiteboard_type=notregexp&bug_severity=blocker&bug_severity=critical&bug_severity=major&bug_severity=normal&bug_severity=minor&bug_severity=trivial\">\n"); 
        print("$bugsperperson{$person}  bugs");
        print("</A>");
        print(" for \n");
        print("<A HREF=\"mailto:$login_name\">");
        print("$login_name");
        print("</A>\n");
        print("</TD><TD>\n");

        $person = pop @people;
        if ($person) {
            SendSQL("select login_name from profiles where userid=$person");
            my $login_name= FetchSQLData();
            print("<A HREF=\"buglist.cgi?bug_status=NEW&email1=$login_name&emailtype1=substring&emailassigned_to1=1&product=Browser&product=MailNews&target_milestone=---&status_whiteboard=.&status_whiteboard_type=notregexp&bug_severity=blocker&bug_severity=critical&bug_severity=major&bug_severity=normal&bug_severity=minor&bug_severity=trivial\">\n"); 
            print("$bugsperperson{$person}  bugs");
            print("</A>");
            print(" for \n");
            print("<A HREF=\"mailto:$login_name\">");
            print("$login_name");
            print("</A>\n");
            print("</TD></TR>\n\n");
879
        }
880 881 882 883
    }
    print "</TABLE>\n";

}