Rubber-stamped by Brady Eidson.
[webbrowser.git] / BugsSite / describecomponents.cgi
blobdf21a7187b7cdd2899c8061879f7b9ae94f345b1
1 #!/usr/bin/env perl -wT
2 # -*- Mode: perl; indent-tabs-mode: nil -*-
4 # The contents of this file are subject to the Mozilla Public
5 # License Version 1.1 (the "License"); you may not use this file
6 # except in compliance with the License. You may obtain a copy of
7 # the License at http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS
10 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 # implied. See the License for the specific language governing
12 # rights and limitations under the License.
14 # The Original Code is the Bugzilla Bug Tracking System.
16 # The Initial Developer of the Original Code is Netscape Communications
17 # Corporation. Portions created by Netscape are
18 # Copyright (C) 1998 Netscape Communications Corporation. All
19 # Rights Reserved.
21 # Contributor(s): Terry Weissman <terry@mozilla.org>
22 # Bradley Baetz <bbaetz@student.usyd.edu.au>
23 # Frédéric Buclin <LpSolit@gmail.com>
25 use strict;
26 use lib qw(. lib);
28 use Bugzilla;
29 use Bugzilla::Constants;
30 use Bugzilla::Util;
31 use Bugzilla::Error;
32 use Bugzilla::Product;
34 my $user = Bugzilla->login();
36 my $cgi = Bugzilla->cgi;
37 my $dbh = Bugzilla->dbh;
38 my $template = Bugzilla->template;
39 my $vars = {};
41 print $cgi->header();
43 my $product_name = trim($cgi->param('product') || '');
44 my $product = new Bugzilla::Product({'name' => $product_name});
46 unless ($product && $user->can_enter_product($product->name)) {
47 # Products which the user is allowed to see.
48 my @products = @{$user->get_enterable_products};
50 if (scalar(@products) == 0) {
51 ThrowUserError("no_products");
53 # If there is only one product available but the user entered
54 # another product name, we display a list with this single
55 # product only, to not confuse the user with components of a
56 # product he didn't request.
57 elsif (scalar(@products) > 1 || $product_name) {
58 $vars->{'classifications'} = [{object => undef, products => \@products}];
59 $vars->{'target'} = "describecomponents.cgi";
60 # If an invalid product name is given, or the user is not
61 # allowed to access that product, a message is displayed
62 # with a list of the products the user can choose from.
63 if ($product_name) {
64 $vars->{'message'} = "product_invalid";
65 # Do not use $product->name here, else you could use
66 # this way to determine whether the product exists or not.
67 $vars->{'product'} = $product_name;
70 $template->process("global/choose-product.html.tmpl", $vars)
71 || ThrowTemplateError($template->error());
72 exit;
75 # If there is only one product available and the user didn't specify
76 # any product name, we show this product.
77 $product = $products[0];
80 ######################################################################
81 # End Data/Security Validation
82 ######################################################################
84 $vars->{'product'} = $product;
86 $template->process("reports/components.html.tmpl", $vars)
87 || ThrowTemplateError($template->error());