show_bug.cgi 3.46 KB
Newer Older
1
#!/usr/bin/perl -wT
2 3 4
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
terry%netscape.com's avatar
terry%netscape.com committed
5
#
6 7
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
terry%netscape.com's avatar
terry%netscape.com committed
8

9
use strict;
terry%netscape.com's avatar
terry%netscape.com committed
10

11
use lib qw(. lib);
12

13
use Bugzilla;
14
use Bugzilla::Constants;
15
use Bugzilla::Error;
16
use Bugzilla::User;
17
use Bugzilla::Keyword;
18
use Bugzilla::Bug;
19

20
my $cgi = Bugzilla->cgi;
21 22
my $template = Bugzilla->template;
my $vars = {};
23

24
my $user = Bugzilla->login();
25

26 27 28
# Editable, 'single' HTML bugs are treated slightly specially in a few places
my $single = !$cgi->param('format')
  && (!$cgi->param('ctype') || $cgi->param('ctype') eq 'html');
29

30
# If we don't have an ID, _AND_ we're only doing a single bug, then prompt
31
if (!$cgi->param('id') && $single) {
32
    print $cgi->header();
33
    $template->process("bug/choose.html.tmpl", $vars) ||
34 35 36 37
      ThrowTemplateError($template->error());
    exit;
}

38 39
my $format = $template->get_format("bug/show", scalar $cgi->param('format'), 
                                   scalar $cgi->param('ctype'));
40

41
my @bugs;
42
my %marks;
43

44 45 46 47 48
# If the user isn't logged in, we use data from the shadow DB. If he plans
# to edit the bug(s), he will have to log in first, meaning that the data
# will be reloaded anyway, from the main DB.
Bugzilla->switch_to_shadow_db unless $user->id;

49 50
if ($single) {
    my $id = $cgi->param('id');
51
    push @bugs, Bugzilla::Bug->check($id);
52 53 54 55 56 57 58 59 60 61 62
    if (defined $cgi->param('mark')) {
        foreach my $range (split ',', $cgi->param('mark')) {
            if ($range =~ /^(\d+)-(\d+)$/) {
               foreach my $i ($1..$2) {
                   $marks{$i} = 1;
               }
            } elsif ($range =~ /^(\d+)$/) {
               $marks{$1} = 1;
            }
        }
    }
63 64
} else {
    foreach my $id ($cgi->param('id')) {
65 66 67
        # Be kind enough and accept URLs of the form: id=1,2,3.
        my @ids = split(/,/, $id);
        foreach (@ids) {
68 69 70 71 72 73 74
            my $bug = new Bugzilla::Bug($_);
            # This is basically a backwards-compatibility hack from when
            # Bugzilla::Bug->new used to set 'NotPermitted' if you couldn't
            # see the bug.
            if (!$bug->{error} && !$user->can_see_bug($bug->bug_id)) {
                $bug->{error} = 'NotPermitted';
            }
75 76
            push(@bugs, $bug);
        }
77 78
    }
}
79

80 81
Bugzilla::Bug->preload(\@bugs);

82
$vars->{'bugs'} = \@bugs;
83
$vars->{'marks'} = \%marks;
84

85
my @bugids = map {$_->bug_id} grep {!$_->error} @bugs;
86 87
$vars->{'bugids'} = join(", ", @bugids);

88 89 90 91
# Work out which fields we are displaying (currently XML only.)
# If no explicit list is defined, we show all fields. We then exclude any
# on the exclusion list. This is so you can say e.g. "Everything except 
# attachments" without listing almost all the fields.
92
my @fieldlist = (Bugzilla::Bug->fields, 'flag', 'group', 'long_desc',
93
                 'attachment', 'attachmentdata', 'token');
94 95 96 97 98 99
my %displayfields;

if ($cgi->param("field")) {
    @fieldlist = $cgi->param("field");
}

100
unless ($user->is_timetracker) {
101
    @fieldlist = grep($_ !~ /(^deadline|_time)$/, @fieldlist);
102 103
}

104 105 106 107 108 109 110 111 112 113
foreach (@fieldlist) {
    $displayfields{$_} = 1;
}

foreach ($cgi->param("excludefield")) {
    $displayfields{$_} = undef;    
}

$vars->{'displayfields'} = \%displayfields;

114 115
print $cgi->header($format->{'ctype'});

116 117
$template->process("$format->{'template'}", $vars)
  || ThrowTemplateError($template->error());