colchange.cgi 6.27 KB
Newer Older
1
#!/usr/bin/perl -wT
2
# -*- Mode: perl; indent-tabs-mode: nil -*-
terry%netscape.com's avatar
terry%netscape.com committed
3
#
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.
#
terry%netscape.com's avatar
terry%netscape.com committed
14
# The Original Code is the Bugzilla Bug Tracking System.
15
#
terry%netscape.com's avatar
terry%netscape.com committed
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.
#
terry%netscape.com's avatar
terry%netscape.com committed
21
# Contributor(s): Terry Weissman <terry@mozilla.org>
22
#                 Gervase Markham <gerv@gerv.net>
23
#                 Max Kanat-Alexander <mkanat@bugzilla.org>
24
#                 Pascal Held <paheld@gmail.com>
terry%netscape.com's avatar
terry%netscape.com committed
25

26
use strict;
terry%netscape.com's avatar
terry%netscape.com committed
27

28
use lib qw(. lib);
29

30
use Bugzilla;
31
use Bugzilla::Constants;
32
use Bugzilla::Util;
33 34
use Bugzilla::CGI;
use Bugzilla::Search::Saved;
35
use Bugzilla::Error;
36
use Bugzilla::User;
37
use Bugzilla::Keyword;
38

39
Bugzilla->login();
40

41
my $cgi = Bugzilla->cgi;
42 43
my $template = Bugzilla->template;
my $vars = {};
44

terry%netscape.com's avatar
terry%netscape.com committed
45 46
# The master list not only says what fields are possible, but what order
# they get displayed in.
47 48 49
my @masterlist = ("opendate", "changeddate", "bug_severity", "priority",
                  "rep_platform", "assigned_to", "assigned_to_realname",
                  "reporter", "reporter_realname", "bug_status",
50 51
                  "resolution");

52
if (Bugzilla->params->{"useclassification"}) {
53 54 55
    push(@masterlist, "classification");
}

56
push(@masterlist, ("product", "component", "version", "op_sys"));
57

58
if (Bugzilla->params->{"usevotes"}) {
59 60
    push (@masterlist, "votes");
}
61
if (Bugzilla->params->{"usebugaliases"}) {
62 63
    unshift(@masterlist, "alias");
}
64
if (Bugzilla->params->{"usetargetmilestone"}) {
65 66
    push(@masterlist, "target_milestone");
}
67
if (Bugzilla->params->{"useqacontact"}) {
68
    push(@masterlist, "qa_contact");
69
    push(@masterlist, "qa_contact_realname");
70
}
71
if (Bugzilla->params->{"usestatuswhiteboard"}) {
72 73
    push(@masterlist, "status_whiteboard");
}
74
if (Bugzilla::Keyword->any_exist) {
75 76
    push(@masterlist, "keywords");
}
77 78 79
if (Bugzilla->has_flags) {
    push(@masterlist, "flagtypes.name");
}
80
if (Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) {
81
    push(@masterlist, ("estimated_time", "remaining_time", "actual_time",
82
                       "percentage_complete", "deadline")); 
83 84
}

85
push(@masterlist, ("short_desc", "short_short_desc"));
terry%netscape.com's avatar
terry%netscape.com committed
86

87
my @custom_fields = grep { $_->type != FIELD_TYPE_MULTI_SELECT }
88
                         Bugzilla->active_custom_fields;
89
push(@masterlist, map { $_->name } @custom_fields);
90

91 92
Bugzilla::Hook::process("colchange-columns", {'columns' => \@masterlist} );

93
$vars->{'masterlist'} = \@masterlist;
terry%netscape.com's avatar
terry%netscape.com committed
94

95
my @collist;
96
if (defined $cgi->param('rememberedquery')) {
97
    my $splitheader = 0;
98
    if (defined $cgi->param('resetit')) {
99
        @collist = DEFAULT_COLUMN_LIST;
terry%netscape.com's avatar
terry%netscape.com committed
100
    } else {
101 102 103
        if (defined $cgi->param("selected_columns")) {
            my %legal_list = map { $_ => 1 } @masterlist;
            @collist = grep { exists $legal_list{$_} } $cgi->param("selected_columns");
terry%netscape.com's avatar
terry%netscape.com committed
104
        }
105
        if (defined $cgi->param('splitheader')) {
106
            $splitheader = $cgi->param('splitheader')? 1: 0;
107
        }
terry%netscape.com's avatar
terry%netscape.com committed
108
    }
109
    my $list = join(" ", @collist);
110

111
    if ($list) {
112 113 114 115 116 117 118
        # Only set the cookie if this is not a saved search.
        # Saved searches have their own column list
        if (!$cgi->param('save_columns_for_search')) {
            $cgi->send_cookie(-name => 'COLUMNLIST',
                              -value => $list,
                              -expires => 'Fri, 01-Jan-2038 00:00:00 GMT');
        }
119 120 121 122
    }
    else {
        $cgi->remove_cookie('COLUMNLIST');
    }
123 124 125 126 127 128 129 130
    if ($splitheader) {
        $cgi->send_cookie(-name => 'SPLITHEADER',
                          -value => $splitheader,
                          -expires => 'Fri, 01-Jan-2038 00:00:00 GMT');
    }
    else {
        $cgi->remove_cookie('SPLITHEADER');
    }
131

132
    $vars->{'message'} = "change_columns";
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

    my $search;
    if (defined $cgi->param('saved_search')) {
        $search = new Bugzilla::Search::Saved($cgi->param('saved_search'));
    }

    if ($cgi->param('save_columns_for_search')
        && defined $search && $search->user->id == Bugzilla->user->id) 
    {
        my $params = new Bugzilla::CGI($search->url);
        $params->param('columnlist', join(",", @collist));
        $search->set_url($params->query_string());
        $search->update();
    }

148 149 150 151
    my $params = new Bugzilla::CGI($cgi->param('rememberedquery'));
    $params->param('columnlist', join(",", @collist));
    $vars->{'redirect_url'} = "buglist.cgi?".$params->query_string();

152 153 154 155

    # If we're running on Microsoft IIS, using cgi->redirect discards
    # the Set-Cookie lines -- workaround is to use the old-fashioned 
    # redirection mechanism. See bug 214466 for details.
156 157 158
    if ($ENV{'SERVER_SOFTWARE'} =~ /Microsoft-IIS/
        || $ENV{'SERVER_SOFTWARE'} =~ /Sun ONE Web/)
    {
159 160
      print $cgi->header(-type => "text/html",
                         -refresh => "0; URL=$vars->{'redirect_url'}");
161 162
    }
    else {
163 164 165
      print $cgi->redirect($vars->{'redirect_url'});
    }
    
166 167
    $template->process("global/message.html.tmpl", $vars)
      || ThrowTemplateError($template->error());
168
    exit;
terry%netscape.com's avatar
terry%netscape.com committed
169 170
}

171 172 173
if (defined $cgi->param('columnlist')) {
    @collist = split(/[ ,]+/, $cgi->param('columnlist'));
} elsif (defined $cgi->cookie('COLUMNLIST')) {
174
    @collist = split(/ /, $cgi->cookie('COLUMNLIST'));
terry%netscape.com's avatar
terry%netscape.com committed
175
} else {
176
    @collist = DEFAULT_COLUMN_LIST;
terry%netscape.com's avatar
terry%netscape.com committed
177 178
}

179
$vars->{'collist'} = \@collist;
180
$vars->{'splitheader'} = $cgi->cookie('SPLITHEADER') ? 1 : 0;
181

182
$vars->{'buffer'} = $cgi->query_string();
terry%netscape.com's avatar
terry%netscape.com committed
183

184 185 186 187 188
my $search;
if (defined $cgi->param('query_based_on')) {
    my $searches = Bugzilla->user->queries;
    my ($search) = grep($_->name eq $cgi->param('query_based_on'), @$searches);

189
    if ($search) {
190 191 192 193
        $vars->{'saved_search'} = $search;
    }
}

194
# Generate and return the UI (HTML page) from the appropriate template.
195
print $cgi->header();
196 197
$template->process("list/change-columns.html.tmpl", $vars)
  || ThrowTemplateError($template->error());