2008-12-15 15:53:33 +03:00
|
|
|
#!/usr/bin/perl -wT
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
|
|
|
# David Gardiner <david.gardiner@unisa.edu.au>
|
|
|
|
# Matthias Radestock <matthias@sorted.org>
|
|
|
|
# Gervase Markham <gerv@gerv.net>
|
|
|
|
# Byron Jones <bugzilla@glob.com.au>
|
|
|
|
# Max Kanat-Alexander <mkanat@bugzilla.org>
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use lib qw(. lib);
|
|
|
|
|
|
|
|
use Bugzilla;
|
|
|
|
use Bugzilla::Bug;
|
|
|
|
use Bugzilla::Constants;
|
|
|
|
use Bugzilla::Search;
|
2010-06-30 19:05:02 +04:00
|
|
|
use Bugzilla::Search::Saved;
|
2008-12-15 15:53:33 +03:00
|
|
|
use Bugzilla::User;
|
|
|
|
use Bugzilla::Util;
|
|
|
|
use Bugzilla::Error;
|
|
|
|
use Bugzilla::Product;
|
|
|
|
use Bugzilla::Keyword;
|
|
|
|
use Bugzilla::Field;
|
|
|
|
use Bugzilla::Install::Util qw(vers_cmp);
|
|
|
|
|
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
my $template = Bugzilla->template;
|
|
|
|
my $vars = {};
|
|
|
|
my $buffer = $cgi->query_string();
|
|
|
|
|
|
|
|
my $user = Bugzilla->login();
|
|
|
|
my $userid = $user->id;
|
|
|
|
|
|
|
|
# Backwards compatibility hack -- if there are any of the old QUERY_*
|
|
|
|
# cookies around, and we are logged in, then move them into the database
|
|
|
|
# and nuke the cookie. This is required for Bugzilla 2.8 and earlier.
|
|
|
|
if ($userid) {
|
|
|
|
my @oldquerycookies;
|
|
|
|
foreach my $i ($cgi->cookie()) {
|
|
|
|
if ($i =~ /^QUERY_(.*)$/) {
|
|
|
|
push(@oldquerycookies, [$1, $i, $cgi->cookie($i)]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (defined $cgi->cookie('DEFAULTQUERY')) {
|
|
|
|
push(@oldquerycookies, [DEFAULT_QUERY_NAME, 'DEFAULTQUERY',
|
|
|
|
$cgi->cookie('DEFAULTQUERY')]);
|
|
|
|
}
|
|
|
|
if (@oldquerycookies) {
|
|
|
|
foreach my $ref (@oldquerycookies) {
|
|
|
|
my ($name, $cookiename, $value) = (@$ref);
|
|
|
|
if ($value) {
|
|
|
|
# If the query name contains invalid characters, don't import.
|
|
|
|
$name =~ /[<>&]/ && next;
|
|
|
|
trick_taint($name);
|
|
|
|
$dbh->bz_start_transaction();
|
|
|
|
my $query = $dbh->selectrow_array(
|
|
|
|
"SELECT query FROM namedqueries " .
|
|
|
|
"WHERE userid = ? AND name = ?",
|
|
|
|
undef, ($userid, $name));
|
|
|
|
if (!$query) {
|
|
|
|
$dbh->do("INSERT INTO namedqueries " .
|
|
|
|
"(userid, name, query) VALUES " .
|
|
|
|
"(?, ?, ?)", undef, ($userid, $name, $value));
|
|
|
|
}
|
|
|
|
$dbh->bz_commit_transaction();
|
|
|
|
}
|
|
|
|
$cgi->remove_cookie($cookiename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cgi->param('nukedefaultquery')) {
|
|
|
|
if ($userid) {
|
|
|
|
$dbh->do("DELETE FROM namedqueries" .
|
2010-05-15 00:02:34 +04:00
|
|
|
" WHERE userid = ? AND name = ?",
|
2008-12-15 15:53:33 +03:00
|
|
|
undef, ($userid, DEFAULT_QUERY_NAME));
|
|
|
|
}
|
|
|
|
$buffer = "";
|
|
|
|
}
|
|
|
|
|
2009-07-29 15:21:49 +04:00
|
|
|
# We are done with changes committed to the DB.
|
|
|
|
$dbh = Bugzilla->switch_to_shadow_db;
|
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
my $userdefaultquery;
|
|
|
|
if ($userid) {
|
|
|
|
$userdefaultquery = $dbh->selectrow_array(
|
|
|
|
"SELECT query FROM namedqueries " .
|
2010-05-15 00:02:34 +04:00
|
|
|
"WHERE userid = ? AND name = ?",
|
2008-12-15 15:53:33 +03:00
|
|
|
undef, ($userid, DEFAULT_QUERY_NAME));
|
|
|
|
}
|
|
|
|
|
|
|
|
local our %default;
|
|
|
|
|
|
|
|
# We pass the defaults as a hash of references to arrays. For those
|
|
|
|
# Items which are single-valued, the template should only reference [0]
|
|
|
|
# and ignore any multiple values.
|
|
|
|
sub PrefillForm {
|
|
|
|
my ($buf) = (@_);
|
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
$buf = new Bugzilla::CGI($buf);
|
|
|
|
my $foundone = 0;
|
|
|
|
|
|
|
|
# Nothing must be undef, otherwise the template complains.
|
2010-05-15 00:02:34 +04:00
|
|
|
my @list = ("bug_status", "resolution", "assigned_to",
|
|
|
|
"rep_platform", "priority", "bug_severity",
|
|
|
|
"classification", "product", "reporter", "op_sys",
|
|
|
|
"component", "version", "chfield", "chfieldfrom",
|
|
|
|
"chfieldto", "chfieldvalue", "target_milestone",
|
|
|
|
"email", "emailtype", "emailreporter",
|
|
|
|
"emailassigned_to", "emailcc", "emailqa_contact",
|
|
|
|
"emaillongdesc", "content",
|
|
|
|
"changedin", "votes", "short_desc", "short_desc_type",
|
|
|
|
"longdesc", "longdesc_type", "bug_file_loc",
|
|
|
|
"bug_file_loc_type", "status_whiteboard",
|
|
|
|
"status_whiteboard_type", "bug_id",
|
|
|
|
"bug_id_type", "keywords", "keywords_type",
|
|
|
|
"deadlinefrom", "deadlineto",
|
|
|
|
"x_axis_field", "y_axis_field", "z_axis_field",
|
|
|
|
"chart_format", "cumulate", "x_labels_vertical",
|
|
|
|
"category", "subcategory", "name", "newcategory",
|
|
|
|
"newsubcategory", "public", "frequency");
|
2010-03-24 21:08:21 +03:00
|
|
|
# These fields can also have default values (when used in reports).
|
2009-12-28 20:38:55 +03:00
|
|
|
# CustIS Bug 58300 - Add custom field to search filters
|
2010-03-24 21:08:21 +03:00
|
|
|
for my $field (Bugzilla->active_custom_fields)
|
|
|
|
{
|
|
|
|
push @list, $field->name;
|
2010-11-03 20:13:12 +03:00
|
|
|
push @list, $field->name . '_type';
|
2010-03-24 21:08:21 +03:00
|
|
|
}
|
2009-07-29 15:21:49 +04:00
|
|
|
|
|
|
|
foreach my $name (@list) {
|
2008-12-15 15:53:33 +03:00
|
|
|
$default{$name} = [];
|
|
|
|
}
|
2010-05-15 00:02:34 +04:00
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
# we won't prefill the boolean chart data from this query if
|
|
|
|
# there are any being submitted via params
|
|
|
|
my $prefillcharts = (grep(/^field-/, $cgi->param)) ? 0 : 1;
|
2010-05-15 00:02:34 +04:00
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
# Iterate over the URL parameters
|
|
|
|
foreach my $name ($buf->param()) {
|
|
|
|
my @values = $buf->param($name);
|
|
|
|
|
|
|
|
# If the name begins with the string 'field', 'type', 'value', or
|
|
|
|
# 'negate', then it is part of the boolean charts. Because
|
|
|
|
# these are built different than the rest of the form, we need
|
|
|
|
# to store these as parameters. We also need to indicate that
|
|
|
|
# we found something so the default query isn't added in if
|
|
|
|
# all we have are boolean chart items.
|
|
|
|
if ($name =~ m/^(?:field|type|value|negate)/) {
|
|
|
|
$cgi->param(-name => $name, -value => $values[0]) if ($prefillcharts);
|
|
|
|
$foundone = 1;
|
|
|
|
}
|
|
|
|
# If the name ends in a number (which it does for the fields which
|
|
|
|
# are part of the email searching), we use the array
|
|
|
|
# positions to show the defaults for that number field.
|
|
|
|
elsif ($name =~ m/^(.+)(\d)$/ && defined($default{$1})) {
|
|
|
|
$foundone = 1;
|
|
|
|
$default{$1}->[$2] = $values[0];
|
|
|
|
}
|
|
|
|
elsif (exists $default{$name}) {
|
|
|
|
$foundone = 1;
|
|
|
|
push (@{$default{$name}}, @values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $foundone;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PrefillForm($buffer)) {
|
|
|
|
# Ah-hah, there was no form stuff specified. Do it again with the
|
|
|
|
# default query.
|
|
|
|
if ($userdefaultquery) {
|
|
|
|
PrefillForm($userdefaultquery);
|
|
|
|
} else {
|
|
|
|
PrefillForm(Bugzilla->params->{"defaultquery"});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!scalar(@{$default{'chfieldto'}}) || $default{'chfieldto'}->[0] eq "") {
|
|
|
|
$default{'chfieldto'} = ["Now"];
|
|
|
|
}
|
|
|
|
|
2010-02-02 19:57:14 +03:00
|
|
|
# Fields for boolean charts
|
2010-11-02 19:07:59 +03:00
|
|
|
$vars->{fields} = &Bugzilla::Search::CHART_FIELDS;
|
2008-12-15 15:53:33 +03:00
|
|
|
|
2010-02-02 19:57:14 +03:00
|
|
|
# "where one or more of the following changed:"
|
2010-11-02 19:07:59 +03:00
|
|
|
$vars->{chfield} = [ map { $_->name } @{ &Bugzilla::Search::CHANGEDFROMTO_FIELDS } ];
|
2010-02-02 19:57:14 +03:00
|
|
|
|
|
|
|
# Another hack...
|
|
|
|
unshift @{$vars->{fields}}, { name => "noop", description => "---" };
|
|
|
|
|
2010-05-15 00:02:34 +04:00
|
|
|
# If we're not in the time-tracking group, exclude time-tracking fields.
|
|
|
|
if (!Bugzilla->user->is_timetracker) {
|
|
|
|
foreach my $tt_field (TIMETRACKING_FIELDS) {
|
2010-05-28 22:35:07 +04:00
|
|
|
@{$vars->{fields}} = grep($_->{name} ne $tt_field, @{$vars->{fields}});
|
2010-05-15 00:02:34 +04:00
|
|
|
}
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
|
2010-02-02 19:57:14 +03:00
|
|
|
# Boolean charts
|
2008-12-15 15:53:33 +03:00
|
|
|
|
|
|
|
# Creating new charts - if the cmd-add value is there, we define the field
|
|
|
|
# value so the code sees it and creates the chart. It will attempt to select
|
|
|
|
# "xyzzy" as the default, and fail. This is the correct behaviour.
|
|
|
|
foreach my $cmd (grep(/^cmd-/, $cgi->param)) {
|
|
|
|
if ($cmd =~ /^cmd-add(\d+)-(\d+)-(\d+)$/) {
|
|
|
|
$cgi->param(-name => "field$1-$2-$3", -value => "xyzzy");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$cgi->param('field0-0-0')) {
|
|
|
|
$cgi->param(-name => 'field0-0-0', -value => "xyzzy");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create data structure of boolean chart info. It's an array of arrays of
|
|
|
|
# arrays - with the inner arrays having three members - field, type and
|
|
|
|
# value.
|
|
|
|
my @charts;
|
|
|
|
for (my $chart = 0; $cgi->param("field$chart-0-0"); $chart++) {
|
|
|
|
my @rows;
|
|
|
|
for (my $row = 0; $cgi->param("field$chart-$row-0"); $row++) {
|
|
|
|
my @cols;
|
|
|
|
for (my $col = 0; $cgi->param("field$chart-$row-$col"); $col++) {
|
|
|
|
my $value = $cgi->param("value$chart-$row-$col");
|
|
|
|
if (!defined($value)) {
|
|
|
|
$value = '';
|
|
|
|
}
|
|
|
|
push(@cols, { field => $cgi->param("field$chart-$row-$col"),
|
|
|
|
type => $cgi->param("type$chart-$row-$col") || 'noop',
|
|
|
|
value => $value });
|
|
|
|
}
|
|
|
|
push(@rows, \@cols);
|
|
|
|
}
|
|
|
|
push(@charts, {'rows' => \@rows, 'negate' => scalar($cgi->param("negate$chart")) });
|
|
|
|
}
|
|
|
|
|
|
|
|
$default{'charts'} = \@charts;
|
|
|
|
|
|
|
|
# Named queries
|
|
|
|
if ($userid) {
|
|
|
|
$vars->{'namedqueries'} = $dbh->selectcol_arrayref(
|
|
|
|
"SELECT name FROM namedqueries " .
|
|
|
|
"WHERE userid = ? AND name != ? " .
|
|
|
|
"ORDER BY name",
|
|
|
|
undef, ($userid, DEFAULT_QUERY_NAME));
|
|
|
|
}
|
|
|
|
|
|
|
|
# Sort order
|
|
|
|
my $deforder;
|
2010-12-02 16:03:26 +03:00
|
|
|
my @orders = ('Bug Number', 'Importance', 'Assignee', 'Last Changed', 'relevance');
|
2008-12-15 15:53:33 +03:00
|
|
|
|
|
|
|
if ($cgi->cookie('LASTORDER')) {
|
|
|
|
$deforder = "Reuse same sort as last time";
|
|
|
|
unshift(@orders, $deforder);
|
|
|
|
}
|
|
|
|
|
2009-09-16 17:00:18 +04:00
|
|
|
if ($cgi->param('order'))
|
|
|
|
{
|
|
|
|
$deforder = $cgi->param('order');
|
|
|
|
if (lsearch(\@orders, $deforder) < 0)
|
|
|
|
{
|
|
|
|
unshift @orders, $deforder;
|
|
|
|
}
|
|
|
|
}
|
2008-12-15 15:53:33 +03:00
|
|
|
|
|
|
|
$vars->{'userdefaultquery'} = $userdefaultquery;
|
|
|
|
$vars->{'orders'} = \@orders;
|
|
|
|
$default{'order'} = [$deforder || 'Importance'];
|
|
|
|
|
|
|
|
if (($cgi->param('query_format') || $cgi->param('format') || "")
|
|
|
|
eq "create-series") {
|
|
|
|
require Bugzilla::Chart;
|
|
|
|
$vars->{'category'} = Bugzilla::Chart::getVisibleSeries();
|
|
|
|
}
|
|
|
|
|
2009-12-28 20:38:55 +03:00
|
|
|
# CustIS Bug 58300 - Add custom fields to search filters
|
|
|
|
# This logic is moved from search/form.html.tmpl
|
2010-05-11 18:34:12 +04:00
|
|
|
$vars->{freetext_fields} = [
|
2010-10-14 14:31:30 +04:00
|
|
|
Bugzilla->get_field('longdesc'),
|
|
|
|
Bugzilla->get_field('bug_file_loc')
|
2009-12-28 20:38:55 +03:00
|
|
|
];
|
|
|
|
if (Bugzilla->params->{usestatuswhiteboard})
|
|
|
|
{
|
2010-10-14 14:31:30 +04:00
|
|
|
push @{$vars->{freetext_fields}}, Bugzilla->get_field('status_whiteboard');
|
2009-12-28 20:38:55 +03:00
|
|
|
}
|
2010-05-11 18:34:12 +04:00
|
|
|
push @{$vars->{freetext_fields}},
|
2010-10-14 14:31:30 +04:00
|
|
|
Bugzilla->active_custom_fields({ type => [ FIELD_TYPE_TEXTAREA, FIELD_TYPE_FREETEXT ] });
|
2009-12-28 20:38:55 +03:00
|
|
|
|
2009-07-29 15:21:49 +04:00
|
|
|
if ($cgi->param('format') && $cgi->param('format') =~ /^report-(table|graph)$/) {
|
|
|
|
# Get legal custom fields for tabular and graphical reports.
|
2010-10-14 14:31:30 +04:00
|
|
|
my @custom_fields_for_reports = Bugzilla->active_custom_fields({ type => FIELD_TYPE_SINGLE_SELECT });
|
2009-07-29 15:21:49 +04:00
|
|
|
$vars->{'custom_fields'} = \@custom_fields_for_reports;
|
|
|
|
}
|
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
$vars->{'known_name'} = $cgi->param('known_name');
|
2009-07-29 15:21:49 +04:00
|
|
|
$vars->{'columnlist'} = $cgi->param('columnlist');
|
2008-12-15 15:53:33 +03:00
|
|
|
|
|
|
|
# Add in the defaults.
|
|
|
|
$vars->{'default'} = \%default;
|
|
|
|
|
|
|
|
$vars->{'format'} = $cgi->param('format');
|
|
|
|
$vars->{'query_format'} = $cgi->param('query_format');
|
|
|
|
|
|
|
|
# Set default page to "specific" if none provided
|
|
|
|
if (!($cgi->param('query_format') || $cgi->param('format'))) {
|
|
|
|
if (defined $cgi->cookie('DEFAULTFORMAT')) {
|
|
|
|
$vars->{'format'} = $cgi->cookie('DEFAULTFORMAT');
|
|
|
|
} else {
|
|
|
|
$vars->{'format'} = 'specific';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Set cookie to current format as default, but only if the format
|
|
|
|
# one that we should remember.
|
|
|
|
if (defined($vars->{'format'}) && IsValidQueryType($vars->{'format'})) {
|
|
|
|
$cgi->send_cookie(-name => 'DEFAULTFORMAT',
|
|
|
|
-value => $vars->{'format'},
|
|
|
|
-expires => "Fri, 01-Jan-2038 00:00:00 GMT");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate and return the UI (HTML page) from the appropriate template.
|
|
|
|
# If we submit back to ourselves (for e.g. boolean charts), we need to
|
|
|
|
# preserve format information; hence query_format taking priority over
|
|
|
|
# format.
|
2010-05-15 00:02:34 +04:00
|
|
|
my $format = $template->get_format("search/search",
|
|
|
|
$vars->{'query_format'} || $vars->{'format'},
|
2008-12-15 15:53:33 +03:00
|
|
|
scalar $cgi->param('ctype'));
|
|
|
|
|
2010-06-11 21:31:17 +04:00
|
|
|
$cgi->send_header($format->{'ctype'});
|
2008-12-15 15:53:33 +03:00
|
|
|
|
|
|
|
$template->process($format->{'template'}, $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|