buglist.cgi 44.6 KB
Newer Older
1
#!/usr/bin/perl -wT
2
# -*- Mode: perl; indent-tabs-mode: nil -*-
terry%netscape.com's avatar
terry%netscape.com committed
3
#
4 5 6 7 8 9 10 11 12 13
# 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.
#
terry%netscape.com's avatar
terry%netscape.com committed
14
# The Original Code is the Bugzilla Bug Tracking System.
15
#
terry%netscape.com's avatar
terry%netscape.com committed
16
# The Initial Developer of the Original Code is Netscape Communications
17 18 19 20
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
terry%netscape.com's avatar
terry%netscape.com committed
21
# Contributor(s): Terry Weissman <terry@mozilla.org>
22
#                 Dan Mosedale <dmose@mozilla.org>
23
#                 Stephan Niemz  <st.n@gmx.net>
24
#                 Andreas Franke <afranke@mathweb.org>
25
#                 Myk Melez <myk@mozilla.org>
26
#                 Max Kanat-Alexander <mkanat@bugzilla.org>
terry%netscape.com's avatar
terry%netscape.com committed
27

28 29 30 31 32
################################################################################
# Script Initialization
################################################################################

# Make it harder for us to do dangerous things in Perl.
33
use strict;
terry%netscape.com's avatar
terry%netscape.com committed
34

35 36
use lib qw(.);

37
use Bugzilla;
38
use Bugzilla::Search;
39
use Bugzilla::Search::Quicksearch;
40
use Bugzilla::Constants;
41
use Bugzilla::User;
42
use Bugzilla::Bug;
43 44

# Include the Bugzilla CGI and general utility library.
45
require "globals.pl";
46

47
use vars qw(@components
48 49 50 51 52 53 54 55
            @legal_keywords
            @legal_platform
            @legal_priority
            @legal_product
            @legal_severity
            @settable_resolution
            @target_milestone
            @versions);
terry%netscape.com's avatar
terry%netscape.com committed
56

57
my $cgi = Bugzilla->cgi;
58
my $dbh = Bugzilla->dbh;
59 60
my $template = Bugzilla->template;
my $vars = {};
61
my $buffer = $cgi->query_string();
62

63
if (length($buffer) == 0) {
64
    print $cgi->header(-refresh=> '10; URL=query.cgi');
65
    ThrowUserError("buglist_parameters_required");
66
}
67

68 69 70 71 72 73 74 75 76
# Determine whether this is a quicksearch query.
my $searchstring = $cgi->param('quicksearch');
if (defined($searchstring)) {
    $buffer = quicksearch($searchstring);
    # Quicksearch may do a redirect, in which case it does not return.
    # If it does return, it has modified $cgi->params so we can use them here
    # as if this had been a normal query from the beginning.
}

77 78 79
################################################################################
# Data and Security Validation
################################################################################
80

81
# Whether or not the user wants to change multiple bugs.
82
my $dotweak = $cgi->param('tweak') ? 1 : 0;
83 84 85

# Log the user in
if ($dotweak) {
86
    Bugzilla->login(LOGIN_REQUIRED);
87 88 89 90
    UserInGroup("editbugs")
      || ThrowUserError("auth_failure", {group  => "editbugs",
                                         action => "modify",
                                         object => "multiple_bugs"});
91 92 93
    GetVersionTable();
}
else {
94
    Bugzilla->login();
95 96
}

97
# Hack to support legacy applications that think the RDF ctype is at format=rdf.
98 99 100 101
if (defined $cgi->param('format') && $cgi->param('format') eq "rdf"
    && !defined $cgi->param('ctype')) {
    $cgi->param('ctype', "rdf");
    $cgi->delete('format');
102
}
103 104 105 106 107 108 109

# The js ctype presents a security risk; a malicious site could use it  
# to gather information about secure bugs. So, we only allow public bugs to be
# retrieved with this format.
#
# Note that if and when this call clears cookies or has other persistent 
# effects, we'll need to do this another way instead.
110
if ((defined $cgi->param('ctype')) && ($cgi->param('ctype') eq "js")) {
111
    Bugzilla->logout_request();
112
}
113

114 115 116
# Determine the format in which the user would like to receive the output.
# Uses the default format if the user did not specify an output format;
# otherwise validates the user's choice against the list of available formats.
117 118
my $format = $template->get_format("list/list", scalar $cgi->param('format'),
                                   scalar $cgi->param('ctype'));
119

120 121 122 123 124 125 126 127 128 129
# Use server push to display a "Please wait..." message for the user while
# executing their query if their browser supports it and they are viewing
# the bug list as HTML and they have not disabled it by adding &serverpush=0
# to the URL.
#
# Server push is a Netscape 3+ hack incompatible with MSIE, Lynx, and others. 
# Even Communicator 4.51 has bugs with it, especially during page reload.
# http://www.browsercaps.org used as source of compatible browsers.
#
my $serverpush =
130 131 132 133 134
  $format->{'extension'} eq "html"
    && exists $ENV{'HTTP_USER_AGENT'} 
      && $ENV{'HTTP_USER_AGENT'} =~ /Mozilla.[3-9]/ 
        && $ENV{'HTTP_USER_AGENT'} !~ /[Cc]ompatible/
          && $ENV{'HTTP_USER_AGENT'} !~ /WebKit/
135 136
            && !defined($cgi->param('serverpush'))
              || $cgi->param('serverpush');
137

138
my $order = $cgi->param('order') || "";
139
my $order_from_cookie = 0;  # True if $order set using the LASTORDER cookie
140

141 142 143
# The params object to use for the actual query itself
my $params;

144 145
# If the user is retrieving the last bug list they looked at, hack the buffer
# storing the query string so that it looks like a query retrieving those bugs.
146
if (defined $cgi->param('regetlastlist')) {
147
    $cgi->cookie('BUGLIST') || ThrowUserError("missing_cookie");
148

149
    $order = "reuse last sort" unless $order;
150 151
    my $bug_id = $cgi->cookie('BUGLIST');
    $bug_id =~ s/:/,/g;
152 153
    # set up the params for this new query
    $params = new Bugzilla::CGI({
154
                                 bug_id => $bug_id,
155 156
                                 order => $order,
                                });
157 158
}

159 160
if ($buffer =~ /&cmd-/) {
    my $url = "query.cgi?$buffer#chart";
161
    print $cgi->redirect(-location => $url);
162
    # Generate and return the UI (HTML page) from the appropriate template.
163
    $vars->{'message'} = "buglist_adding_field";
164 165
    $vars->{'url'} = $url;
    $template->process("global/message.html.tmpl", $vars)
166
      || ThrowTemplateError($template->error());
167 168
    exit;
}
169

170 171 172 173
# Figure out whether or not the user is doing a fulltext search.  If not,
# we'll remove the relevance column from the lists of columns to display
# and order by, since relevance only exists when doing a fulltext search.
my $fulltext = 0;
174
if ($cgi->param('content')) { $fulltext = 1 }
175
my @charts = map(/^field(\d-\d-\d)$/ ? $1 : (), $cgi->param());
176
foreach my $chart (@charts) {
177
    if ($cgi->param("field$chart") eq 'content' && $cgi->param("value$chart")) {
178 179 180 181 182
        $fulltext = 1;
        last;
    }
}

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
################################################################################
# Utilities
################################################################################

my @weekday= qw( Sun Mon Tue Wed Thu Fri Sat );
sub DiffDate {
    my ($datestr) = @_;
    my $date = str2time($datestr);
    my $age = time() - $date;
    my ($s,$m,$h,$d,$mo,$y,$wd)= localtime $date;
    if( $age < 18*60*60 ) {
        $date = sprintf "%02d:%02d:%02d", $h,$m,$s;
    } elsif( $age < 6*24*60*60 ) {
        $date = sprintf "%s %02d:%02d", $weekday[$wd],$h,$m;
    } else {
        $date = sprintf "%04d-%02d-%02d", 1900+$y,$mo+1,$d;
    }
    return $date;
}
202

203 204
sub LookupNamedQuery {
    my ($name) = @_;
205
    my $user = Bugzilla->login(LOGIN_REQUIRED);
206 207 208
    my $dbh = Bugzilla->dbh;
    # $name is safe -- we only use it below in a SELECT placeholder and then 
    # in error messages (which are always HTML-filtered).
209
    $name || ThrowUserError("query_name_missing");
210 211 212
    trick_taint($name);
    my $result = $dbh->selectrow_array("SELECT query FROM namedqueries" 
                          . " WHERE userid = ? AND name = ?"
213
                          , undef, ($user->id, $name));
214 215 216 217 218
    
    defined($result) || ThrowUserError("missing_query", {'queryname' => $name});
    $result
       || ThrowUserError("buglist_parameters_required", {'queryname' => $name});

219 220 221
    return $result;
}

222 223 224 225 226 227 228 229 230 231 232 233 234
# Inserts a Named Query (a "Saved Search") into the database, or
# updates a Named Query that already exists..
# Takes four arguments:
# userid - The userid who the Named Query will belong to.
# query_name - A string that names the new Named Query, or the name
#              of an old Named Query to update. If this is blank, we
#              will throw a UserError. Leading and trailing whitespace
#              will be stripped from this value before it is inserted
#              into the DB.
# query - The query part of the buglist.cgi URL, unencoded. Must not be 
#         empty, or we will throw a UserError.
# link_in_footer (optional) - 1 if the Named Query should be 
# displayed in the user's footer, 0 otherwise.
235 236
# query_type (optional) - 1 if the Named Query contains a list of
# bug IDs only, 0 otherwise (default).
237 238 239 240 241
#
# All parameters are validated before passing them into the database.
#
# Returns: A boolean true value if the query existed in the database 
# before, and we updated it. A boolean false value otherwise.
242
sub InsertNamedQuery {
243
    my ($userid, $query_name, $query, $link_in_footer, $query_type) = @_;
244
    $link_in_footer ||= 0;
245
    $query_type ||= QUERY_LIST;
246 247 248 249 250 251 252 253
    $query_name = trim($query_name);
    Bugzilla->login(LOGIN_REQUIRED);
    my $dbh = Bugzilla->dbh;
    my $query_existed_before;

    # Validate the query name.
    $query_name || ThrowUserError("query_name_missing");
    $query_name !~ /[<>&]/ || ThrowUserError("illegal_query_name");
254
    (length($query_name) <= 64) || ThrowUserError("query_name_too_long");
255 256 257 258 259 260 261 262 263 264 265
    trick_taint($query_name);

    detaint_natural($userid);
    detaint_natural($link_in_footer);

    $query || ThrowUserError("buglist_parameters_required",
                             {'queryname' => $query});
    # $query is safe, because we always urlencode or html_quote
    # it when we display it to the user.
    trick_taint($query);

266
    $dbh->bz_lock_tables('namedqueries WRITE');
267 268 269 270 271 272 273

    my $result = $dbh->selectrow_array("SELECT userid FROM namedqueries"
        . " WHERE userid = ? AND name = ?"
        , undef, ($userid, $query_name));
    if ($result) {
        $query_existed_before = 1;
        $dbh->do("UPDATE namedqueries"
274
            . " SET query = ?, linkinfooter = ?, query_type = ?"
275
            . " WHERE userid = ? AND name = ?"
276
            , undef, ($query, $link_in_footer, $query_type, $userid, $query_name));
277 278 279
    } else {
        $query_existed_before = 0;
        $dbh->do("INSERT INTO namedqueries"
280 281 282
            . " (userid, name, query, linkinfooter, query_type)"
            . " VALUES (?, ?, ?, ?, ?)"
            , undef, ($userid, $query_name, $query, $link_in_footer, $query_type));
283 284
    }

285
    $dbh->bz_unlock_tables();
286 287 288
    return $query_existed_before;
}

289 290 291 292 293 294
sub LookupSeries {
    my ($series_id) = @_;
    detaint_natural($series_id) || ThrowCodeError("invalid_series_id");
    
    my $dbh = Bugzilla->dbh;
    my $result = $dbh->selectrow_array("SELECT query FROM series " .
295 296
                                       "WHERE series_id = ?"
                                       , undef, ($series_id));
297 298 299 300 301
    $result
           || ThrowCodeError("invalid_series_id", {'series_id' => $series_id});
    return $result;
}

302
sub GetQuip {
303
    my $dbh = Bugzilla->dbh;
304 305
    # COUNT is quick because it is cached for MySQL. We may want to revisit
    # this when we support other databases.
306 307
    my $count = $dbh->selectrow_array("SELECT COUNT(quip)"
                                    . " FROM quips WHERE approved = 1");
308
    my $random = int(rand($count));
309
    my $quip = 
310 311
        $dbh->selectrow_array("SELECT quip FROM quips WHERE approved = 1 " . 
                              $dbh->sql_limit(1, $random));
312
    return $quip;
313
}
314

315
sub GetGroups {
316
    my $dbh = Bugzilla->dbh;
317
    my $user = Bugzilla->user;
318

319 320 321
    # Create an array where each item is a hash. The hash contains 
    # as keys the name of the columns, which point to the value of 
    # the columns for that row.
322
    my $grouplist = $user->groups_as_string;
323
    my $groups = $dbh->selectall_arrayref(
324
                "SELECT  id, name, description, isactive
325
                   FROM  groups
326
                  WHERE  id IN ($grouplist)
327
                    AND  isbuggroup = 1
328
               ORDER BY  description "
329
               , {Slice => {}});
330

331
    return $groups;
332
}
333

334

335 336 337
################################################################################
# Command Execution
################################################################################
338

339 340
$cgi->param('cmdtype', "") if !defined $cgi->param('cmdtype');
$cgi->param('remaction', "") if !defined $cgi->param('remaction');
341

342 343
# Backwards-compatibility - the old interface had cmdtype="runnamed" to run
# a named command, and we can't break this because it's in bookmarks.
344 345 346
if ($cgi->param('cmdtype') eq "runnamed") {  
    $cgi->param('cmdtype', "dorem");
    $cgi->param('remaction', "run");
347 348
}

349 350 351 352 353 354
# Now we're going to be running, so ensure that the params object is set up,
# using ||= so that we only do so if someone hasn't overridden this 
# earlier, for example by setting up a named query search.

# This will be modified, so make a copy.
$params ||= new Bugzilla::CGI($cgi);
355

356 357 358 359 360 361 362 363
# Generate a reasonable filename for the user agent to suggest to the user
# when the user saves the bug list.  Uses the name of the remembered query
# if available.  We have to do this now, even though we return HTTP headers 
# at the end, because the fact that there is a remembered query gets 
# forgotten in the process of retrieving it.
my @time = localtime(time());
my $date = sprintf "%04d-%02d-%02d", 1900+$time[5],$time[4]+1,$time[3];
my $filename = "bugs-$date.$format->{extension}";
364 365
if ($cgi->param('cmdtype') eq "dorem" && $cgi->param('remaction') =~ /^run/) {
    $filename = $cgi->param('namedcmd') . "-$date.$format->{extension}";
366 367 368 369 370
    # Remove white-space from the filename so the user cannot tamper
    # with the HTTP headers.
    $filename =~ s/\s/_/g;
}

371
# Take appropriate action based on user's request.
372 373
if ($cgi->param('cmdtype') eq "dorem") {  
    if ($cgi->param('remaction') eq "run") {
374
        $buffer = LookupNamedQuery(scalar $cgi->param("namedcmd"));
375
        $vars->{'searchname'} = $cgi->param('namedcmd');
376
        $vars->{'searchtype'} = "saved";
377
        $params = new Bugzilla::CGI($buffer);
378
        $order = $params->param('order') || $order;
379

380
    }
381
    elsif ($cgi->param('remaction') eq "runseries") {
382
        $buffer = LookupSeries(scalar $cgi->param("series_id"));
383
        $vars->{'searchname'} = $cgi->param('namedcmd');
384
        $vars->{'searchtype'} = "series";
385
        $params = new Bugzilla::CGI($buffer);
386 387
        $order = $params->param('order') || $order;
    }
388
    elsif ($cgi->param('remaction') eq "forget") {
389
        my $user = Bugzilla->login(LOGIN_REQUIRED);
390 391 392
        # Copy the name into a variable, so that we can trick_taint it for
        # the DB. We know it's safe, because we're using placeholders in 
        # the SQL, and the SQL is only a DELETE.
393
        my $qname = $cgi->param('namedcmd');
394
        trick_taint($qname);
395 396 397 398 399 400 401 402 403 404 405 406

        # Do not forget the saved search if it is being used in a whine
        my $whines_in_use = 
            $dbh->selectcol_arrayref('SELECT DISTINCT whine_events.subject
                                                 FROM whine_events
                                           INNER JOIN whine_queries
                                                   ON whine_queries.eventid
                                                      = whine_events.id
                                                WHERE whine_events.owner_userid
                                                      = ?
                                                  AND whine_queries.query_name
                                                      = ?
407
                                      ', undef, $user->id, $qname);
408 409 410 411 412 413 414 415
        if (scalar(@$whines_in_use)) {
            ThrowUserError('saved_search_used_by_whines', 
                           { subjects    => join(',', @$whines_in_use),
                             search_name => $qname                      }
            );
        }

        # If we are here, then we can safely remove the saved search
416 417
        $dbh->do("DELETE FROM namedqueries"
            . " WHERE userid = ? AND name = ?"
418
            , undef, ($user->id, $qname));
419 420

        # Now reset the cached queries
421
        $user->flush_queries_cache();
422

423
        print $cgi->header();
424
        # Generate and return the UI (HTML page) from the appropriate template.
425
        $vars->{'message'} = "buglist_query_gone";
426
        $vars->{'namedcmd'} = $cgi->param('namedcmd');
427 428
        $vars->{'url'} = "query.cgi";
        $template->process("global/message.html.tmpl", $vars)
429
          || ThrowTemplateError($template->error());
430
        exit;
431 432
    }
}
433 434
elsif (($cgi->param('cmdtype') eq "doit") && defined $cgi->param('remtype')) {
    if ($cgi->param('remtype') eq "asdefault") {
435 436
        my $user = Bugzilla->login(LOGIN_REQUIRED);
        InsertNamedQuery($user->id, DEFAULT_QUERY_NAME, $buffer);
437
        $vars->{'message'} = "buglist_new_default_query";
438
    }
439
    elsif ($cgi->param('remtype') eq "asnamed") {
440
        my $user = Bugzilla->login(LOGIN_REQUIRED);
441
        my $query_name = $cgi->param('newqueryname');
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
        my $new_query = $cgi->param('newquery');
        my $query_type = QUERY_LIST;
        # If add_bugids is true, we are adding individual bugs to a saved
        # search. We get the existing list of bug IDs (if any) and append
        # the new ones.
        if ($cgi->param('add_bugids')) {
            my %bug_ids;
            foreach my $bug_id (split(/[\s,]+/, $cgi->param('bug_ids'))) {
                next unless $bug_id;
                ValidateBugID($bug_id);
                $bug_ids{$bug_id} = 1;
            }
            ThrowUserError("no_bug_ids") unless scalar(keys %bug_ids);

            if (!trim($query_name)) {
                # No new query name has been given. We append new bug IDs
                # to the existing list.
                $query_name = $cgi->param('oldqueryname');
                my $old_query = LookupNamedQuery($query_name);
                foreach my $bug_id (split(/[\s,=]+/, $old_query)) {
                    $bug_ids{$bug_id} = 1 if detaint_natural($bug_id);
                }
            }
            $new_query = "bug_id=" . join(',', sort {$a <=> $b} keys %bug_ids);
            $query_type = LIST_OF_BUGS;
        }
468
        my $tofooter = 1;
469
        my $existed_before = InsertNamedQuery($user->id, $query_name, $new_query,
470
                                              $tofooter, $query_type);
471
        if ($existed_before) {
472 473
            $vars->{'message'} = "buglist_updated_named_query";
        }
474
        else {
475
            $vars->{'message'} = "buglist_new_named_query";
476
        }
477 478 479

        # Make sure to invalidate any cached query data, so that the footer is
        # correctly displayed
480
        $user->flush_queries_cache();
481

482
        $vars->{'queryname'} = $query_name;
483
        
484
        print $cgi->header();
485 486 487
        $template->process("global/message.html.tmpl", $vars)
          || ThrowTemplateError($template->error());
        exit;
488
    }
terry%netscape.com's avatar
terry%netscape.com committed
489 490
}

491 492 493 494 495
# backward compatibility hack: if the saved query doesn't say which
# form was used to create it, assume it was on the advanced query
# form - see bug 252295
if (!$params->param('query_format')) {
    $params->param('query_format', 'advanced');
496
    $buffer = $params->query_string;
497
}
terry%netscape.com's avatar
terry%netscape.com committed
498

499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
################################################################################
# Column Definition
################################################################################

# Define the columns that can be selected in a query and/or displayed in a bug
# list.  Column records include the following fields:
#
# 1. ID: a unique identifier by which the column is referred in code;
#
# 2. Name: The name of the column in the database (may also be an expression
#          that returns the value of the column);
#
# 3. Title: The title of the column as displayed to users.
# 
# Note: There are a few hacks in the code that deviate from these definitions.
#       In particular, when the list is sorted by the "votes" field the word 
#       "DESC" is added to the end of the field to sort in descending order, 
516
#       and the redundant short_desc column is removed when the client
517 518 519 520 521 522
#       requests "all" columns.

my $columns = {};
sub DefineColumn {
    my ($id, $name, $title) = @_;
    $columns->{$id} = { 'name' => $name , 'title' => $title };
523
}
524

525
# Column:     ID                    Name                           Title
526
DefineColumn("bug_id"            , "bugs.bug_id"                , "ID"               );
527
DefineColumn("alias"             , "bugs.alias"                 , "Alias"           );
528 529
DefineColumn("opendate"          , "bugs.creation_ts"           , "Opened"           );
DefineColumn("changeddate"       , "bugs.delta_ts"              , "Changed"          );
530
DefineColumn("bug_severity"      , "bugs.bug_severity"          , "Severity"         );
531
DefineColumn("priority"          , "bugs.priority"              , "Priority"         );
532 533
DefineColumn("rep_platform"      , "bugs.rep_platform"          , "Hardware"         );
DefineColumn("assigned_to"       , "map_assigned_to.login_name" , "Assignee"         );
534 535
DefineColumn("reporter"          , "map_reporter.login_name"    , "Reporter"         );
DefineColumn("qa_contact"        , "map_qa_contact.login_name"  , "QA Contact"       );
536
if ($format->{'extension'} eq 'html') {
537 538 539
    DefineColumn("assigned_to_realname", "CASE WHEN map_assigned_to.realname = '' THEN map_assigned_to.login_name ELSE map_assigned_to.realname END AS assigned_to_realname", "Assignee"  );
    DefineColumn("reporter_realname"   , "CASE WHEN map_reporter.realname    = '' THEN map_reporter.login_name    ELSE map_reporter.realname    END AS reporter_realname"   , "Reporter"  );
    DefineColumn("qa_contact_realname" , "CASE WHEN map_qa_contact.realname  = '' THEN map_qa_contact.login_name  ELSE map_qa_contact.realname  END AS qa_contact_realname" , "QA Contact");
540 541 542 543 544
} else {
    DefineColumn("assigned_to_realname", "map_assigned_to.realname" , "Assignee"         );
    DefineColumn("reporter_realname"   , "map_reporter.realname"    , "Reporter"         );
    DefineColumn("qa_contact_realname" , "map_qa_contact.realname"  , "QA Contact"       );
}
545
DefineColumn("bug_status"        , "bugs.bug_status"            , "Status"           );
546
DefineColumn("resolution"        , "bugs.resolution"            , "Resolution"       );
547 548
DefineColumn("short_short_desc"  , "bugs.short_desc"            , "Summary"          );
DefineColumn("short_desc"        , "bugs.short_desc"            , "Summary"          );
549
DefineColumn("status_whiteboard" , "bugs.status_whiteboard"     , "Whiteboard"       );
550 551
DefineColumn("component"         , "map_components.name"        , "Component"        );
DefineColumn("product"           , "map_products.name"          , "Product"          );
552
DefineColumn("classification"    , "map_classifications.name"   , "Classification"   );
553
DefineColumn("version"           , "bugs.version"               , "Version"          );
554
DefineColumn("op_sys"            , "bugs.op_sys"                , "OS"               );
555 556 557
DefineColumn("target_milestone"  , "bugs.target_milestone"      , "Target Milestone" );
DefineColumn("votes"             , "bugs.votes"                 , "Votes"            );
DefineColumn("keywords"          , "bugs.keywords"              , "Keywords"         );
558 559 560
DefineColumn("estimated_time"    , "bugs.estimated_time"        , "Estimated Hours"  );
DefineColumn("remaining_time"    , "bugs.remaining_time"        , "Remaining Hours"  );
DefineColumn("actual_time"       , "(SUM(ldtime.work_time)*COUNT(DISTINCT ldtime.bug_when)/COUNT(bugs.bug_id)) AS actual_time", "Actual Hours");
561
DefineColumn("percentage_complete","(100*((SUM(ldtime.work_time)*COUNT(DISTINCT ldtime.bug_when)/COUNT(bugs.bug_id))/((SUM(ldtime.work_time)*COUNT(DISTINCT ldtime.bug_when)/COUNT(bugs.bug_id))+bugs.remaining_time))) AS percentage_complete", "% Complete"); 
562
DefineColumn("relevance"         , "relevance"                  , "Relevance"        );
563
DefineColumn("deadline"          , $dbh->sql_date_format('bugs.deadline', '%Y-%m-%d') . " AS deadline", "Deadline");
564

565 566 567 568 569 570 571
################################################################################
# Display Column Determination
################################################################################

# Determine the columns that will be displayed in the bug list via the 
# columnlist CGI parameter, the user's preferences, or the default.
my @displaycolumns = ();
572 573
if (defined $params->param('columnlist')) {
    if ($params->param('columnlist') eq "all") {
574
        # If the value of the CGI parameter is "all", display all columns,
575 576
        # but remove the redundant "short_desc" column.
        @displaycolumns = grep($_ ne 'short_desc', keys(%$columns));
terry%netscape.com's avatar
terry%netscape.com committed
577
    }
578
    else {
579
        @displaycolumns = split(/[ ,]+/, $params->param('columnlist'));
580
    }
terry%netscape.com's avatar
terry%netscape.com committed
581
}
582
elsif (defined $cgi->cookie('COLUMNLIST')) {
583
    # 2002-10-31 Rename column names (see bug 176461)
584
    my $columnlist = $cgi->cookie('COLUMNLIST');
585 586 587 588 589 590 591
    $columnlist =~ s/\bowner\b/assigned_to/;
    $columnlist =~ s/\bowner_realname\b/assigned_to_realname/;
    $columnlist =~ s/\bplatform\b/rep_platform/;
    $columnlist =~ s/\bseverity\b/bug_severity/;
    $columnlist =~ s/\bstatus\b/bug_status/;
    $columnlist =~ s/\bsummaryfull\b/short_desc/;
    $columnlist =~ s/\bsummary\b/short_short_desc/;
592

593
    # Use the columns listed in the user's preferences.
594
    @displaycolumns = split(/ /, $columnlist);
terry%netscape.com's avatar
terry%netscape.com committed
595
}
596 597
else {
    # Use the default list of columns.
598
    @displaycolumns = DEFAULT_COLUMN_LIST;
599 600
}

601 602 603 604
# Weed out columns that don't actually exist to prevent the user 
# from hacking their column list cookie to grab data to which they 
# should not have access.  Detaint the data along the way.
@displaycolumns = grep($columns->{$_} && trick_taint($_), @displaycolumns);
605

606 607
# Remove the "ID" column from the list because bug IDs are always displayed
# and are hard-coded into the display templates.
608
@displaycolumns = grep($_ ne 'bug_id', @displaycolumns);
terry%netscape.com's avatar
terry%netscape.com committed
609

610 611 612
# Add the votes column to the list of columns to be displayed
# in the bug list if the user is searching for bugs with a certain
# number of votes and the votes column is not already on the list.
613 614

# Some versions of perl will taint 'votes' if this is done as a single
615 616 617 618
# statement, because the votes param is tainted at this point
my $votes = $params->param('votes');
$votes ||= "";
if (trim($votes) && !grep($_ eq 'votes', @displaycolumns)) {
619 620
    push(@displaycolumns, 'votes');
}
terry%netscape.com's avatar
terry%netscape.com committed
621

622 623 624 625 626 627 628
# Remove the timetracking columns if they are not a part of the group
# (happens if a user had access to time tracking and it was revoked/disabled)
if (!UserInGroup(Param("timetrackinggroup"))) {
   @displaycolumns = grep($_ ne 'estimated_time', @displaycolumns);
   @displaycolumns = grep($_ ne 'remaining_time', @displaycolumns);
   @displaycolumns = grep($_ ne 'actual_time', @displaycolumns);
   @displaycolumns = grep($_ ne 'percentage_complete', @displaycolumns);
629
   @displaycolumns = grep($_ ne 'deadline', @displaycolumns);
630
}
terry%netscape.com's avatar
terry%netscape.com committed
631

632 633 634 635 636 637
# Remove the relevance column if the user is not doing a fulltext search.
if (grep('relevance', @displaycolumns) && !$fulltext) {
    @displaycolumns = grep($_ ne 'relevance', @displaycolumns);
}


638 639 640
################################################################################
# Select Column Determination
################################################################################
terry%netscape.com's avatar
terry%netscape.com committed
641

642
# Generate the list of columns that will be selected in the SQL query.
terry%netscape.com's avatar
terry%netscape.com committed
643

644
# The bug ID is always selected because bug IDs are always displayed.
645 646 647 648
# Severity, priority, resolution and status are required for buglist
# CSS classes.
my @selectcolumns = ("bug_id", "bug_severity", "priority", "bug_status",
                     "resolution");
649

650 651 652 653 654
# if using classification, we also need to look in product.classification_id
if (Param("useclassification")) {
    push (@selectcolumns,"product");
}

655
# remaining and actual_time are required for precentage_complete calculation:
656
if (lsearch(\@displaycolumns, "percentage_complete") >= 0) {
657 658 659 660
    push (@selectcolumns, "remaining_time");
    push (@selectcolumns, "actual_time");
}

661 662
# Display columns are selected because otherwise we could not display them.
push (@selectcolumns, @displaycolumns);
terry%netscape.com's avatar
terry%netscape.com committed
663

664 665 666 667 668
# If the user is editing multiple bugs, we also make sure to select the product
# and status because the values of those fields determine what options the user
# has for modifying the bugs.
if ($dotweak) {
    push(@selectcolumns, "product") if !grep($_ eq 'product', @selectcolumns);
669
    push(@selectcolumns, "bug_status") if !grep($_ eq 'bug_status', @selectcolumns);
670 671
}

672 673 674
if ($format->{'extension'} eq 'ics') {
    push(@selectcolumns, "opendate") if !grep($_ eq 'opendate', @selectcolumns);
}
675

676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
if ($format->{'extension'} eq 'rss') {
    # This is the list of fields that are needed by the rss filter.
    my @required_rss_columns = (
      'short_desc',
      'opendate',
      'changeddate',
      'reporter_realname',
      'priority',
      'bug_severity',
      'assigned_to_realname',
      'bug_status'
    );

    foreach my $required (@required_rss_columns) {
        push(@selectcolumns, $required) if !grep($_ eq $required,@selectcolumns);
    }
}

694 695 696
################################################################################
# Query Generation
################################################################################
terry%netscape.com's avatar
terry%netscape.com committed
697

698 699
# Convert the list of columns being selected into a list of column names.
my @selectnames = map($columns->{$_}->{'name'}, @selectcolumns);
700

701 702 703 704
# Remove columns with no names, such as percentage_complete
#  (or a removed *_time column due to permissions)
@selectnames = grep($_ ne '', @selectnames);

705 706 707
################################################################################
# Sort Order Determination
################################################################################
708

709
# Add to the query some instructions for sorting the bug list.
710 711 712 713 714 715

# First check if we'll want to reuse the last sorting order; that happens if
# the order is not defined or its value is "reuse last sort"
if (!$order || $order =~ /^reuse/i) {
    if ($cgi->cookie('LASTORDER')) {
        $order = $cgi->cookie('LASTORDER');
716 717 718 719 720
       
        # Cookies from early versions of Specific Search included this text,
        # which is now invalid.
        $order =~ s/ LIMIT 200//;
        
721 722 723 724 725
        $order_from_cookie = 1;
    }
    else {
        $order = '';  # Remove possible "reuse" identifier as unnecessary
    }
726
}
727

728
my $db_order = "";  # Modified version of $order for use with SQL query
729 730 731 732
if ($order) {
    # Convert the value of the "order" form field into a list of columns
    # by which to sort the results.
    ORDER: for ($order) {
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
        /^Bug Number$/ && do {
            $order = "bugs.bug_id";
            last ORDER;
        };
        /^Importance$/ && do {
            $order = "bugs.priority, bugs.bug_severity";
            last ORDER;
        };
        /^Assignee$/ && do {
            $order = "map_assigned_to.login_name, bugs.bug_status, bugs.priority, bugs.bug_id";
            last ORDER;
        };
        /^Last Changed$/ && do {
            $order = "bugs.delta_ts, bugs.bug_status, bugs.priority, map_assigned_to.login_name, bugs.bug_id";
            last ORDER;
        };
        do {
            my @order;
751
            my @columnnames = map($columns->{lc($_)}->{'name'}, keys(%$columns));
752
            # A custom list of columns.  Make sure each column is valid.
753 754 755 756
            foreach my $fragment (split(/,/, $order)) {
                $fragment = trim($fragment);
                # Accept an order fragment matching a column name, with
                # asc|desc optionally following (to specify the direction)
757 758 759 760 761
                if (grep($fragment =~ /^\Q$_\E(\s+(asc|desc))?$/, @columnnames)) {
                    next if $fragment =~ /\brelevance\b/ && !$fulltext;
                    push(@order, $fragment);
                }
                else {
762
                    my $vars = { fragment => $fragment };
763
                    if ($order_from_cookie) {
764
                        $cgi->remove_cookie('LASTORDER');
765
                        ThrowCodeError("invalid_column_name_cookie", $vars);
766 767
                    }
                    else {
768
                        ThrowCodeError("invalid_column_name_form", $vars);
769
                    }
770 771
                }
            }
772
            $order = join(",", @order);
773 774 775
            # Now that we have checked that all columns in the order are valid,
            # detaint the order string.
            trick_taint($order);
776
        };
terry%netscape.com's avatar
terry%netscape.com committed
777
    }
778 779 780 781 782
}
else {
    # DEFAULT
    $order = "bugs.bug_status, bugs.priority, map_assigned_to.login_name, bugs.bug_id";
}
783

784 785 786 787 788 789
foreach my $fragment (split(/,/, $order)) {
    $fragment = trim($fragment);
    if (!grep($fragment =~ /^\Q$_\E(\s+(asc|desc))?$/, @selectnames)) {
        # Add order columns to selectnames
        # The fragment has already been validated
        $fragment =~ s/\s+(asc|desc)$//;
790 791 792 793 794 795 796 797 798
        # This fixes an issue where columns being used in the ORDER BY statement
        # can have the SQL that generates the value changed to become invalid -
        # mainly affects time tracking.
        if ($fragment =~ / AS (\w+)/) {
            $fragment = $columns->{$1}->{'name'};
        }
        else {
            $fragment =~ tr/a-zA-Z\.0-9\-_//cd;
        }
799 800 801
        push @selectnames, $fragment;
    }
}
802

803
$db_order = $order;  # Copy $order into $db_order for use with SQL query
804

805 806 807 808 809 810 811 812
# If we are sorting by votes, sort in descending order if no explicit
# sort order was given
$db_order =~ s/bugs.votes\s*(,|$)/bugs.votes desc$1/i;
                             
# the 'actual_time' field is defined as an aggregate function, but 
# for order we just need the column name 'actual_time'
my $aggregate_search = quotemeta($columns->{'actual_time'}->{'name'});
$db_order =~ s/$aggregate_search/actual_time/g;
813

814 815 816
# the 'percentage_complete' field is defined as an aggregate too
$aggregate_search = quotemeta($columns->{'percentage_complete'}->{'name'});
$db_order =~ s/$aggregate_search/percentage_complete/g;
817

818 819 820 821 822
# Now put $db_order into a format that Bugzilla::Search can use.
# (We create $db_order as a string first because that's the way
# we did it before Bugzilla::Search took an "order" argument.)
my @orderstrings = split(',', $db_order);

823 824
# Generate the basic SQL query that will be used to generate the bug list.
my $search = new Bugzilla::Search('fields' => \@selectnames, 
825 826
                                  'params' => $params,
                                  'order' => \@orderstrings);
827 828
my $query = $search->getSQL();

829 830 831 832 833
if (defined $cgi->param('limit')) {
    my $limit = $cgi->param('limit');
    if (detaint_natural($limit)) {
        $query .= " " . $dbh->sql_limit($limit);
    }
834 835
}
elsif ($fulltext) {
836
    $query .= " " . $dbh->sql_limit(FULLTEXT_BUGLIST_LIMIT);
837
    $vars->{'sorted_by_relevance'} = 1;
838 839
}

840

841 842 843
################################################################################
# Query Execution
################################################################################
844

845
if ($cgi->param('debug')) {
846 847
    $vars->{'debug'} = 1;
    $vars->{'query'} = $query;
848
    $vars->{'debugdata'} = $search->getDebugData();
849 850
}

851 852
# Time to use server push to display an interim message to the user until
# the query completes and we can display the bug list.
853
my $disposition = '';
854
if ($serverpush) {
855 856 857
    $filename =~ s/\\/\\\\/g; # escape backslashes
    $filename =~ s/"/\\"/g; # escape quotes
    $disposition = qq#inline; filename="$filename"#;
858

859
    print $cgi->multipart_init(-content_disposition => $disposition);
860
    print $cgi->multipart_start();
861

862
    # Generate and return the UI (HTML page) from the appropriate template.
863 864
    $template->process("list/server-push.html.tmpl", $vars)
      || ThrowTemplateError($template->error());
865

866 867 868
    # Don't do multipart_end() until we're ready to display the replacement
    # page, otherwise any errors that happen before then (like SQL errors)
    # will result in a blank page being shown to the user instead of the error.
terry%netscape.com's avatar
terry%netscape.com committed
869 870
}

871 872
# Connect to the shadow database if this installation is using one to improve
# query performance.
873
Bugzilla->switch_to_shadow_db();
terry%netscape.com's avatar
terry%netscape.com committed
874

875 876 877 878 879 880
# Normally, we ignore SIGTERM and SIGPIPE (see globals.pl) but we need to
# respond to them here to prevent someone DOSing us by reloading a query
# a large number of times.
$::SIG{TERM} = 'DEFAULT';
$::SIG{PIPE} = 'DEFAULT';

881
# Execute the query.
882 883
my $buglist_sth = $dbh->prepare($query);
$buglist_sth->execute();
884

terry%netscape.com's avatar
terry%netscape.com committed
885

886 887 888
################################################################################
# Results Retrieval
################################################################################
terry%netscape.com's avatar
terry%netscape.com committed
889

890 891
# Retrieve the query results one row at a time and write the data into a list
# of Perl records.
terry%netscape.com's avatar
terry%netscape.com committed
892

893 894 895
my $bugowners = {};
my $bugproducts = {};
my $bugstatuses = {};
896
my @bugidlist;
terry%netscape.com's avatar
terry%netscape.com committed
897

898
my @bugs; # the list of records
899

900
while (my @row = $buglist_sth->fetchrow_array()) {
901
    my $bug = {}; # a record
902

903
    # Slurp the row of data into the record.
904 905
    # The second from last column in the record is the number of groups
    # to which the bug is restricted.
906
    foreach my $column (@selectcolumns) {
907
        $bug->{$column} = shift @row;
908
    }
terry%netscape.com's avatar
terry%netscape.com committed
909

910 911 912
    # Process certain values further (i.e. date format conversion).
    if ($bug->{'changeddate'}) {
        $bug->{'changeddate'} =~ 
913
            s/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/$1-$2-$3 $4:$5:$6/;
914 915 916 917 918 919

        # Put in the change date as a time, so that the template date plugin
        # can format the date in any way needed by the template. ICS and RSS
        # have specific, and different, date and time formatting.
        $bug->{'changedtime'} = str2time($bug->{'changeddate'});
        $bug->{'changeddate'} = DiffDate($bug->{'changeddate'});        
920 921 922
    }

    if ($bug->{'opendate'}) {
923 924 925
        # Put in the open date as a time for the template date plugin.
        $bug->{'opentime'} = str2time($bug->{'opendate'});
        $bug->{'opendate'} = DiffDate($bug->{'opendate'});
926
    }
terry%netscape.com's avatar
terry%netscape.com committed
927

928
    # Record the assignee, product, and status in the big hashes of those things.
929
    $bugowners->{$bug->{'assigned_to'}} = 1 if $bug->{'assigned_to'};
930
    $bugproducts->{$bug->{'product'}} = 1 if $bug->{'product'};
931
    $bugstatuses->{$bug->{'bug_status'}} = 1 if $bug->{'bug_status'};
terry%netscape.com's avatar
terry%netscape.com committed
932

933
    $bug->{'secure_mode'} = undef;
934

935 936
    # Add the record to the list.
    push(@bugs, $bug);
937 938

    # Add id to list for checking for bug privacy later
939
    push(@bugidlist, $bug->{'bug_id'});
940 941
}

942 943 944 945
# Check for bug privacy and set $bug->{'secure_mode'} to 'implied' or 'manual'
# based on whether the privacy is simply product implied (by mandatory groups)
# or because of human choice
my %min_membercontrol;
946
if (@bugidlist) {
947
    my $sth = $dbh->prepare(
948 949 950 951 952 953 954 955
        "SELECT DISTINCT bugs.bug_id, MIN(group_control_map.membercontrol) " .
          "FROM bugs " .
    "INNER JOIN bug_group_map " .
            "ON bugs.bug_id = bug_group_map.bug_id " .
     "LEFT JOIN group_control_map " .
            "ON group_control_map.product_id = bugs.product_id " .
           "AND group_control_map.group_id = bug_group_map.group_id " .
         "WHERE bugs.bug_id IN (" . join(',',@bugidlist) . ") " .
956
            $dbh->sql_group_by('bugs.bug_id'));
957 958
    $sth->execute();
    while (my ($bug_id, $min_membercontrol) = $sth->fetchrow_array()) {
959
        $min_membercontrol{$bug_id} = $min_membercontrol || CONTROLMAPNA;
960 961
    }
    foreach my $bug (@bugs) {
962
        next unless defined($min_membercontrol{$bug->{'bug_id'}});
963
        if ($min_membercontrol{$bug->{'bug_id'}} == CONTROLMAPMANDATORY) {
964
            $bug->{'secure_mode'} = 'implied';
965
        }
966 967 968
        else {
            $bug->{'secure_mode'} = 'manual';
        }
969 970
    }
}
971

972 973 974
################################################################################
# Template Variable Definition
################################################################################
975

976
# Define the variables and functions that will be passed to the UI template.
977

978
$vars->{'bugs'} = \@bugs;
979
$vars->{'buglist'} = \@bugidlist;
980
$vars->{'buglist_joined'} = join(',', @bugidlist);
981 982
$vars->{'columns'} = $columns;
$vars->{'displaycolumns'} = \@displaycolumns;
983

984 985 986
my @openstates = OpenStates();
$vars->{'openstates'} = \@openstates;
$vars->{'closedstates'} = ['CLOSED', 'VERIFIED', 'RESOLVED'];
987

988 989 990
# The list of query fields in URL query string format, used when creating
# URLs to the same query results page with different parameters (such as
# a different sort order or when taking some action on the set of query
991 992 993 994 995
# results).  To get this string, we call the Bugzilla::CGI::canoncalise_query
# function with a list of elements to be removed from the URL.
$vars->{'urlquerypart'} = $params->canonicalise_query('order',
                                                      'cmdtype',
                                                      'query_based_on');
996 997
$vars->{'order'} = $order;
$vars->{'caneditbugs'} = UserInGroup('editbugs');
terry%netscape.com's avatar
terry%netscape.com committed
998

999 1000 1001 1002 1003 1004
my @bugowners = keys %$bugowners;
if (scalar(@bugowners) > 1 && UserInGroup('editbugs')) {
    my $suffix = Param('emailsuffix');
    map(s/$/$suffix/, @bugowners) if $suffix;
    my $bugowners = join(",", @bugowners);
    $vars->{'bugowners'} = $bugowners;
terry%netscape.com's avatar
terry%netscape.com committed
1005 1006
}

1007 1008
# Whether or not to split the column titles across two rows to make
# the list more compact.
1009
$vars->{'splitheader'} = $cgi->cookie('SPLITHEADER') ? 1 : 0;
terry%netscape.com's avatar
terry%netscape.com committed
1010

1011
$vars->{'quip'} = GetQuip();
1012
$vars->{'currenttime'} = time();
1013 1014

# The following variables are used when the user is making changes to multiple bugs.
1015
if ($dotweak) {
1016 1017 1018
    $vars->{'dotweak'} = 1;
    $vars->{'use_keywords'} = 1 if @::legal_keywords;

1019
    $vars->{'products'} = Bugzilla->user->get_enterable_products;
1020
    $vars->{'platforms'} = \@::legal_platform;
1021
    $vars->{'op_sys'} = \@::legal_opsys;
1022 1023 1024 1025
    $vars->{'priorities'} = \@::legal_priority;
    $vars->{'severities'} = \@::legal_severity;
    $vars->{'resolutions'} = \@::settable_resolution;

1026
    $vars->{'unconfirmedstate'} = 'UNCONFIRMED';
1027 1028 1029 1030

    $vars->{'bugstatuses'} = [ keys %$bugstatuses ];

    # The groups to which the user belongs.
1031
    $vars->{'groups'} = GetGroups();
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042

    # If all bugs being changed are in the same product, the user can change
    # their version and component, so generate a list of products, a list of
    # versions for the product (if there is only one product on the list of
    # products), and a list of components for the product.
    $vars->{'bugproducts'} = [ keys %$bugproducts ];
    if (scalar(@{$vars->{'bugproducts'}}) == 1) {
        my $product = $vars->{'bugproducts'}->[0];
        $vars->{'versions'} = $::versions{$product};
        $vars->{'components'} = $::components{$product};
        $vars->{'targetmilestones'} = $::target_milestone{$product} if Param('usetargetmilestone');
terry%netscape.com's avatar
terry%netscape.com committed
1043 1044
    }
}
1045

1046 1047 1048 1049
# If we're editing a stored query, use the existing query name as default for
# the "Remember search as" field.
$vars->{'defaultsavename'} = $cgi->param('query_based_on');

1050

1051 1052 1053
################################################################################
# HTTP Header Generation
################################################################################
1054

1055
# Generate HTTP headers
terry%netscape.com's avatar
terry%netscape.com committed
1056

1057
my $contenttype;
1058
my $disp = "inline";
terry%netscape.com's avatar
terry%netscape.com committed
1059

1060 1061
if ($format->{'extension'} eq "html") {
    if ($order) {
1062
        $cgi->send_cookie(-name => 'LASTORDER',
1063
                          -value => $order,
1064
                          -expires => 'Fri, 01-Jan-2038 00:00:00 GMT');
1065
    }
1066
    my $bugids = join(":", @bugidlist);
1067
    # See also Bug 111999
1068 1069 1070 1071
    if (length($bugids) == 0) {
        $cgi->remove_cookie('BUGLIST');
    }
    elsif (length($bugids) < 4000) {
1072 1073 1074
        $cgi->send_cookie(-name => 'BUGLIST',
                          -value => $bugids,
                          -expires => 'Fri, 01-Jan-2038 00:00:00 GMT');
1075
    }
1076
    else {
1077
        $cgi->remove_cookie('BUGLIST');
1078
        $vars->{'toolong'} = 1;
terry%netscape.com's avatar
terry%netscape.com committed
1079
    }
1080 1081

    $contenttype = "text/html";
1082 1083
}
else {
1084
    $contenttype = $format->{'ctype'};
terry%netscape.com's avatar
terry%netscape.com committed
1085 1086
}

1087 1088 1089 1090 1091 1092
if ($format->{'extension'} eq "csv") {
    # We set CSV files to be downloaded, as they are designed for importing
    # into other programs.
    $disp = "attachment";
}

1093
if ($serverpush) {
1094 1095
    # close the "please wait" page, then open the buglist page
    print $cgi->multipart_end();
1096 1097 1098 1099 1100
    my @extra;
    push @extra, (-charset => "utf8") if Param("utf8");
    print $cgi->multipart_start(-type => $contenttype, 
                                -content_disposition => $disposition, 
                                @extra);
1101 1102 1103 1104 1105
} else {
    # Suggest a name for the bug list if the user wants to save it as a file.
    # If we are doing server push, then we did this already in the HTTP headers
    # that started the server push, so we don't have to do it again here.
    print $cgi->header(-type => $contenttype,
1106
                       -content_disposition => "$disp; filename=$filename");
1107
}
terry%netscape.com's avatar
terry%netscape.com committed
1108

1109

1110 1111 1112
################################################################################
# Content Generation
################################################################################
1113

1114
# Generate and return the UI (HTML page) from the appropriate template.
1115
$template->process($format->{'template'}, $vars)
1116
  || ThrowTemplateError($template->error());
1117

1118

1119 1120 1121 1122
################################################################################
# Script Conclusion
################################################################################

1123
print $cgi->multipart_final() if $serverpush;