colchange.cgi 6.5 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 33
use Bugzilla::CGI;
use Bugzilla::Search::Saved;
34
use Bugzilla::Error;
35
use Bugzilla::User;
36
use Bugzilla::Keyword;
37

38
Bugzilla->login();
39

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

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

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

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

57
if (Bugzilla->params->{"usevotes"}) {
58 59
    push (@masterlist, "votes");
}
60
if (Bugzilla->params->{"usebugaliases"}) {
61 62
    unshift(@masterlist, "alias");
}
63
if (Bugzilla->params->{"usetargetmilestone"}) {
64 65
    push(@masterlist, "target_milestone");
}
66
if (Bugzilla->params->{"useqacontact"}) {
67
    push(@masterlist, "qa_contact");
68
    push(@masterlist, "qa_contact_realname");
69
}
70
if (Bugzilla->params->{"usestatuswhiteboard"}) {
71 72
    push(@masterlist, "status_whiteboard");
}
73
if (Bugzilla::Keyword::keyword_count()) {
74 75
    push(@masterlist, "keywords");
}
76

77
if (Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) {
78
    push(@masterlist, ("estimated_time", "remaining_time", "actual_time",
79
                       "percentage_complete", "deadline")); 
80 81
}

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

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

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

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

92
my @collist;
93
if (defined $cgi->param('rememberedquery')) {
94
    my $splitheader = 0;
95
    if (defined $cgi->param('resetit')) {
96
        @collist = DEFAULT_COLUMN_LIST;
terry%netscape.com's avatar
terry%netscape.com committed
97
    } else {
98 99 100
        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
101
        }
102
        if (defined $cgi->param('splitheader')) {
103
            $splitheader = $cgi->param('splitheader')? 1: 0;
104
        }
terry%netscape.com's avatar
terry%netscape.com committed
105
    }
106
    my $list = join(" ", @collist);
107

108
    if ($list) {
109 110 111 112 113 114 115
        # 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');
        }
116 117 118 119
    }
    else {
        $cgi->remove_cookie('COLUMNLIST');
    }
120 121 122 123 124 125 126 127
    if ($splitheader) {
        $cgi->send_cookie(-name => 'SPLITHEADER',
                          -value => $splitheader,
                          -expires => 'Fri, 01-Jan-2038 00:00:00 GMT');
    }
    else {
        $cgi->remove_cookie('SPLITHEADER');
    }
128

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

    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();
        $vars->{'redirect_url'} = "buglist.cgi?".$cgi->param('rememberedquery');
    }
    else {
        my $params = new Bugzilla::CGI($cgi->param('rememberedquery'));
        $params->param('columnlist', join(",", @collist));
        $vars->{'redirect_url'} = "buglist.cgi?".$params->query_string();
    }

151 152 153 154

    # 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.
155 156 157
    if ($ENV{'SERVER_SOFTWARE'} =~ /Microsoft-IIS/
        || $ENV{'SERVER_SOFTWARE'} =~ /Sun ONE Web/)
    {
158 159
      print $cgi->header(-type => "text/html",
                         -refresh => "0; URL=$vars->{'redirect_url'}");
160 161
    }
    else {
162 163 164
      print $cgi->redirect($vars->{'redirect_url'});
    }
    
165 166
    $template->process("global/message.html.tmpl", $vars)
      || ThrowTemplateError($template->error());
167
    exit;
terry%netscape.com's avatar
terry%netscape.com committed
168 169
}

170 171
if (defined $cgi->cookie('COLUMNLIST')) {
    @collist = split(/ /, $cgi->cookie('COLUMNLIST'));
terry%netscape.com's avatar
terry%netscape.com committed
172
} else {
173
    @collist = DEFAULT_COLUMN_LIST;
terry%netscape.com's avatar
terry%netscape.com committed
174 175
}

176
$vars->{'collist'} = \@collist;
177
$vars->{'splitheader'} = $cgi->cookie('SPLITHEADER') ? 1 : 0;
178

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

181 182 183 184 185
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);

186
    if ($search) {
187 188 189 190 191 192 193 194 195 196 197
        $vars->{'saved_search'} = $search;
        $vars->{'buffer'} = "cmdtype=runnamed&namedcmd=".$search->name;

        my $params = new Bugzilla::CGI($search->url);
        if ($params->param('columnlist')) {
            my @collist = split(',', $params->param('columnlist'));
            $vars->{'collist'} = \@collist if scalar (@collist);
        }
    }
}

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