colchange.cgi 6.45 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>
terry%netscape.com's avatar
terry%netscape.com committed
24

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

27
use lib qw(. lib);
28

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

37
Bugzilla->login();
38

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

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

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

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

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

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

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

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

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

89
my @collist;
90
if (defined $cgi->param('rememberedquery')) {
91
    my $splitheader = 0;
92
    if (defined $cgi->param('resetit')) {
93
        @collist = DEFAULT_COLUMN_LIST;
terry%netscape.com's avatar
terry%netscape.com committed
94
    } else {
95
        foreach my $i (@masterlist) {
96
            if (defined $cgi->param("column_$i")) {
97
                push @collist, $i;
terry%netscape.com's avatar
terry%netscape.com committed
98 99
            }
        }
100
        if (defined $cgi->param('splitheader')) {
101
            $splitheader = $cgi->param('splitheader')? 1: 0;
102
        }
terry%netscape.com's avatar
terry%netscape.com committed
103
    }
104
    my $list = join(" ", @collist);
105
    my $urlbase = Bugzilla->params->{"urlbase"};
106

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

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

    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();
    }

150 151 152 153

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

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

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

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

180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
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);

    # Only allow users to edit their own queries.
    if ($search && $search->user->id == Bugzilla->user->id) {
        $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());