Rubber-stamped by Brady Eidson.
[webbrowser.git] / BugsSite / colchange.cgi
blob476ce997d8ec88bedda6694b4d4924b7ce39ce57
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 # Gervase Markham <gerv@gerv.net>
23 # Max Kanat-Alexander <mkanat@bugzilla.org>
25 use strict;
27 use lib qw(. lib);
29 use Bugzilla;
30 use Bugzilla::Constants;
31 use Bugzilla::Util;
32 use Bugzilla::CGI;
33 use Bugzilla::Search::Saved;
34 use Bugzilla::Error;
35 use Bugzilla::User;
36 use Bugzilla::Keyword;
38 Bugzilla->login();
40 my $cgi = Bugzilla->cgi;
41 my $template = Bugzilla->template;
42 my $vars = {};
44 # The master list not only says what fields are possible, but what order
45 # they get displayed in.
46 my @masterlist = ("opendate", "changeddate", "bug_severity", "priority",
47 "rep_platform", "assigned_to", "assigned_to_realname",
48 "reporter", "reporter_realname", "bug_status",
49 "resolution");
51 if (Bugzilla->params->{"useclassification"}) {
52 push(@masterlist, "classification");
55 push(@masterlist, ("product", "component", "version", "op_sys"));
57 if (Bugzilla->params->{"usevotes"}) {
58 push (@masterlist, "votes");
60 if (Bugzilla->params->{"usebugaliases"}) {
61 unshift(@masterlist, "alias");
63 if (Bugzilla->params->{"usetargetmilestone"}) {
64 push(@masterlist, "target_milestone");
66 if (Bugzilla->params->{"useqacontact"}) {
67 push(@masterlist, "qa_contact");
68 push(@masterlist, "qa_contact_realname");
70 if (Bugzilla->params->{"usestatuswhiteboard"}) {
71 push(@masterlist, "status_whiteboard");
73 if (Bugzilla::Keyword::keyword_count()) {
74 push(@masterlist, "keywords");
77 if (Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) {
78 push(@masterlist, ("estimated_time", "remaining_time", "actual_time",
79 "percentage_complete", "deadline"));
82 push(@masterlist, ("short_desc", "short_short_desc"));
84 my @custom_fields = grep { $_->type != FIELD_TYPE_MULTI_SELECT }
85 Bugzilla->active_custom_fields;
86 push(@masterlist, map { $_->name } @custom_fields);
88 Bugzilla::Hook::process("colchange-columns", {'columns' => \@masterlist} );
90 $vars->{'masterlist'} = \@masterlist;
92 my @collist;
93 if (defined $cgi->param('rememberedquery')) {
94 my $splitheader = 0;
95 if (defined $cgi->param('resetit')) {
96 @collist = DEFAULT_COLUMN_LIST;
97 } else {
98 foreach my $i (@masterlist) {
99 if (defined $cgi->param("column_$i")) {
100 push @collist, $i;
103 if (defined $cgi->param('splitheader')) {
104 $splitheader = $cgi->param('splitheader')? 1: 0;
107 my $list = join(" ", @collist);
108 my $urlbase = Bugzilla->params->{"urlbase"};
110 if ($list) {
111 # Only set the cookie if this is not a saved search.
112 # Saved searches have their own column list
113 if (!$cgi->param('save_columns_for_search')) {
114 $cgi->send_cookie(-name => 'COLUMNLIST',
115 -value => $list,
116 -expires => 'Fri, 01-Jan-2038 00:00:00 GMT');
119 else {
120 $cgi->remove_cookie('COLUMNLIST');
122 if ($splitheader) {
123 $cgi->send_cookie(-name => 'SPLITHEADER',
124 -value => $splitheader,
125 -expires => 'Fri, 01-Jan-2038 00:00:00 GMT');
127 else {
128 $cgi->remove_cookie('SPLITHEADER');
131 $vars->{'message'} = "change_columns";
133 my $search;
134 if (defined $cgi->param('saved_search')) {
135 $search = new Bugzilla::Search::Saved($cgi->param('saved_search'));
138 if ($cgi->param('save_columns_for_search')
139 && defined $search && $search->user->id == Bugzilla->user->id)
141 my $params = new Bugzilla::CGI($search->url);
142 $params->param('columnlist', join(",", @collist));
143 $search->set_url($params->query_string());
144 $search->update();
145 $vars->{'redirect_url'} = "buglist.cgi?".$cgi->param('rememberedquery');
147 else {
148 my $params = new Bugzilla::CGI($cgi->param('rememberedquery'));
149 $params->param('columnlist', join(",", @collist));
150 $vars->{'redirect_url'} = "buglist.cgi?".$params->query_string();
154 # If we're running on Microsoft IIS, using cgi->redirect discards
155 # the Set-Cookie lines -- workaround is to use the old-fashioned
156 # redirection mechanism. See bug 214466 for details.
157 if ($ENV{'SERVER_SOFTWARE'} =~ /Microsoft-IIS/
158 || $ENV{'SERVER_SOFTWARE'} =~ /Sun ONE Web/)
160 print $cgi->header(-type => "text/html",
161 -refresh => "0; URL=$vars->{'redirect_url'}");
163 else {
164 print $cgi->redirect($vars->{'redirect_url'});
167 $template->process("global/message.html.tmpl", $vars)
168 || ThrowTemplateError($template->error());
169 exit;
172 if (defined $cgi->cookie('COLUMNLIST')) {
173 @collist = split(/ /, $cgi->cookie('COLUMNLIST'));
174 } else {
175 @collist = DEFAULT_COLUMN_LIST;
178 $vars->{'collist'} = \@collist;
179 $vars->{'splitheader'} = $cgi->cookie('SPLITHEADER') ? 1 : 0;
181 $vars->{'buffer'} = $cgi->query_string();
183 my $search;
184 if (defined $cgi->param('query_based_on')) {
185 my $searches = Bugzilla->user->queries;
186 my ($search) = grep($_->name eq $cgi->param('query_based_on'), @$searches);
188 # Only allow users to edit their own queries.
189 if ($search && $search->user->id == Bugzilla->user->id) {
190 $vars->{'saved_search'} = $search;
191 $vars->{'buffer'} = "cmdtype=runnamed&namedcmd=". url_quote($search->name);
193 my $params = new Bugzilla::CGI($search->url);
194 if ($params->param('columnlist')) {
195 my @collist = split(',', $params->param('columnlist'));
196 $vars->{'collist'} = \@collist if scalar (@collist);
201 # Generate and return the UI (HTML page) from the appropriate template.
202 print $cgi->header();
203 $template->process("list/change-columns.html.tmpl", $vars)
204 || ThrowTemplateError($template->error());