blob: 33539675c77194f6c979975d853d17782d5f1d46 [file] [log] [blame]
ddkilzer@apple.comf573e632009-07-03 02:14:39 +00001#!/usr/bin/env perl -wT
timothy@apple.comf42518d2008-02-06 20:19:16 +00002# -*- Mode: perl; indent-tabs-mode: nil -*-
3#
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/
8#
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.
13#
14# The Original Code is the Bugzilla Bug Tracking System.
15#
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.
20#
21# Contributor(s): Terry Weissman <terry@mozilla.org>
22# Myk Melez <myk@mozilla.org>
23
24################################################################################
25# Script Initialization
26################################################################################
27
28# Make it harder for us to do dangerous things in Perl.
29use strict;
30
ddkilzer@apple.com097da082009-07-03 02:14:25 +000031use lib qw(. lib);
ddkilzer@apple.comf3615fc2009-07-03 02:13:41 +000032
timothy@apple.comf42518d2008-02-06 20:19:16 +000033use Bugzilla;
34use Bugzilla::Constants;
ddkilzer@apple.comf3615fc2009-07-03 02:13:41 +000035use Bugzilla::Error;
36use Bugzilla::Keyword;
ddkilzer@apple.com097da082009-07-03 02:14:25 +000037use Bugzilla::Status;
ddkilzer@apple.comf3615fc2009-07-03 02:13:41 +000038use Bugzilla::Field;
timothy@apple.comf42518d2008-02-06 20:19:16 +000039
ddkilzer@apple.comf3615fc2009-07-03 02:13:41 +000040my $user = Bugzilla->login(LOGIN_OPTIONAL);
41my $cgi = Bugzilla->cgi;
timothy@apple.comf42518d2008-02-06 20:19:16 +000042
43# If the 'requirelogin' parameter is on and the user is not
44# authenticated, return empty fields.
ddkilzer@apple.comf3615fc2009-07-03 02:13:41 +000045if (Bugzilla->params->{'requirelogin'} && !$user->id) {
timothy@apple.comf42518d2008-02-06 20:19:16 +000046 display_data();
47}
48
timothy@apple.comf42518d2008-02-06 20:19:16 +000049# Pass a bunch of Bugzilla configuration to the templates.
ddkilzer@apple.comf3615fc2009-07-03 02:13:41 +000050my $vars = {};
51$vars->{'priority'} = get_legal_field_values('priority');
52$vars->{'severity'} = get_legal_field_values('bug_severity');
53$vars->{'platform'} = get_legal_field_values('rep_platform');
54$vars->{'op_sys'} = get_legal_field_values('op_sys');
55$vars->{'keyword'} = [map($_->name, Bugzilla::Keyword->get_all)];
56$vars->{'resolution'} = get_legal_field_values('resolution');
57$vars->{'status'} = get_legal_field_values('bug_status');
58$vars->{'custom_fields'} =
ddkilzer@apple.com097da082009-07-03 02:14:25 +000059 [ grep {$_->type == FIELD_TYPE_SINGLE_SELECT || $_->type == FIELD_TYPE_MULTI_SELECT}
60 Bugzilla->active_custom_fields ];
timothy@apple.comf42518d2008-02-06 20:19:16 +000061
ddkilzer@apple.comf3615fc2009-07-03 02:13:41 +000062# Include a list of product objects.
63if ($cgi->param('product')) {
64 my @products = $cgi->param('product');
65 foreach my $product_name (@products) {
66 # We don't use check_product because config.cgi outputs mostly
67 # in XML and JS and we don't want to display an HTML error
68 # instead of that.
69 my $product = new Bugzilla::Product({ name => $product_name });
70 if ($product && $user->can_see_product($product->name)) {
71 push (@{$vars->{'products'}}, $product);
72 }
73 }
74} else {
75 $vars->{'products'} = $user->get_selectable_products;
timothy@apple.comf42518d2008-02-06 20:19:16 +000076}
77
78# Create separate lists of open versus resolved statuses. This should really
79# be made part of the configuration.
80my @open_status;
81my @closed_status;
ddkilzer@apple.comf3615fc2009-07-03 02:13:41 +000082foreach my $status (@{$vars->{'status'}}) {
83 is_open_state($status) ? push(@open_status, $status)
timothy@apple.comf42518d2008-02-06 20:19:16 +000084 : push(@closed_status, $status);
85}
86$vars->{'open_status'} = \@open_status;
87$vars->{'closed_status'} = \@closed_status;
88
89# Generate a list of fields that can be queried.
ddkilzer@apple.com097da082009-07-03 02:14:25 +000090my @fields = @{Bugzilla::Field->match({obsolete => 0})};
91# Exclude fields the user cannot query.
92if (!Bugzilla->user->in_group(Bugzilla->params->{'timetrackinggroup'})) {
93 @fields = grep { $_->name !~ /^(estimated_time|remaining_time|work_time|percentage_complete|deadline)$/ } @fields;
94}
95$vars->{'field'} = \@fields;
timothy@apple.comf42518d2008-02-06 20:19:16 +000096
97display_data($vars);
98
99
100sub display_data {
101 my $vars = shift;
102
ddkilzer@apple.comf3615fc2009-07-03 02:13:41 +0000103 my $cgi = Bugzilla->cgi;
104 my $template = Bugzilla->template;
105
timothy@apple.comf42518d2008-02-06 20:19:16 +0000106 # Determine how the user would like to receive the output;
107 # default is JavaScript.
ddkilzer@apple.comf3615fc2009-07-03 02:13:41 +0000108 my $format = $template->get_format("config", scalar($cgi->param('format')),
109 scalar($cgi->param('ctype')) || "js");
timothy@apple.comf42518d2008-02-06 20:19:16 +0000110
111 # Return HTTP headers.
112 print "Content-Type: $format->{'ctype'}\n\n";
113
114 # Generate the configuration file and return it to the user.
115 $template->process($format->{'template'}, $vars)
116 || ThrowTemplateError($template->error());
117 exit;
118}