colchange.cgi 6.6 KB

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