describecomponents.cgi 3.38 KB
Newer Older
1
#!/usr/bin/perl -wT
2 3
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
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.
#
14
# The Original Code is the Bugzilla Bug Tracking System.
15
#
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.
#
21
# Contributor(s): Terry Weissman <terry@mozilla.org>
22
#                 Bradley Baetz <bbaetz@student.usyd.edu.au>
23 24

use strict;
25 26
use lib qw(.);

27
use Bugzilla;
28
use Bugzilla::Constants;
29 30
require "CGI.pl";

31 32
use vars qw($vars @legal_product);

33
Bugzilla->login();
34

35 36
GetVersionTable();

37
my $cgi = Bugzilla->cgi;
38 39 40
my $template = Bugzilla->template;
my $product = trim($cgi->param('product') || '');
my $product_id = get_product_id($product);
41

42
if (!$product_id || !CanEnterProduct($product)) {
43 44 45
    # Reference to a subset of %::proddesc, which the user is allowed to see
    my %products;

46
    if (AnyEntryGroups()) {
47
        # OK, now only add products the user can see
48
        Bugzilla->login(LOGIN_REQUIRED);
49
        foreach my $p (@::legal_product) {
50
            if (CanEnterProduct($p)) {
51 52 53 54 55
                $products{$p} = $::proddesc{$p};
            }
        }
    }
    else {
56
        %products = %::proddesc;
57
    }
58

59 60
    my $prodsize = scalar(keys %products);
    if ($prodsize == 0) {
61
        ThrowUserError("no_products");
62 63
    }
    elsif ($prodsize > 1) {
64 65 66 67 68 69 70 71 72
        $vars->{'proddesc'} = \%products;
        $vars->{'target'} = "describecomponents.cgi";
        # If an invalid product name is given, or the user is not
        # allowed to access that product, a message is displayed
        # with a list of the products the user can choose from.
        if ($product) {
            $vars->{'message'} = "product_invalid";
            $vars->{'product'} = $product;
        }
73

74
        print $cgi->header();
75 76
        $template->process("global/choose-product.html.tmpl", $vars)
          || ThrowTemplateError($template->error());
77 78
        exit;
    }
79

80
    $product = (keys %products)[0];
81 82 83 84 85 86
}

######################################################################
# End Data/Security Validation
######################################################################

87
my @components;
88
SendSQL("SELECT name, initialowner, initialqacontact, description FROM " .
89
        "components WHERE product_id = $product_id ORDER BY name");
90 91 92
while (MoreSQLData()) {
    my ($name, $initialowner, $initialqacontact, $description) =
      FetchSQLData();
93

94
    my %component;
95

96 97 98 99 100 101
    $component{'name'} = $name;
    $component{'initialowner'} = $initialowner ?
      DBID_to_name($initialowner) : '';
    $component{'initialqacontact'} = $initialqacontact ?
      DBID_to_name($initialqacontact) : '';
    $component{'description'} = $description;
102

103
    push @components, \%component;
104 105
}

106 107
$vars->{'product'} = $product;
$vars->{'components'} = \@components;
108

109
print $cgi->header();
110 111
$template->process("reports/components.html.tmpl", $vars)
  || ThrowTemplateError($template->error());