22
22
# David Gardiner <david.gardiner@unisa.edu.au>
23
23
# Matthias Radestock <matthias@sorted.org>
24
24
# Gervase Markham <gerv@gerv.net>
25
# Byron Jones <bugzilla@glob.com.au>
28
use lib '/usr/share/bugzilla/lib';
32
use Bugzilla::Constants;
56
my $cgi = Bugzilla->cgi;
55
58
if (defined $::FORM{"GoAheadAndLogIn"}) {
56
59
# We got here from a login page, probably from relogin.cgi. We better
57
60
# make sure the password is legit.
61
Bugzilla->login(LOGIN_REQUIRED);
60
quietly_check_login();
66
my $user = Bugzilla->user;
67
my $userid = $user ? $user->id : 0;
63
69
# Backwards compatibility hack -- if there are any of the old QUERY_*
64
70
# cookies around, and we are logged in, then move them into the database
65
71
# and nuke the cookie. This is required for Bugzilla 2.8 and earlier.
67
73
my @oldquerycookies;
68
74
foreach my $i (keys %::COOKIE) {
69
75
if ($i =~ /^QUERY_(.*)$/) {
79
85
my ($name, $cookiename, $value) = (@$ref);
81
87
my $qname = SqlQuote($name);
88
SendSQL("LOCK TABLES namedqueries WRITE");
82
89
SendSQL("SELECT query FROM namedqueries " .
83
"WHERE userid = $::userid AND name = $qname");
90
"WHERE userid = $userid AND name = $qname");
84
91
my $query = FetchOneColumn();
86
SendSQL("REPLACE INTO namedqueries " .
93
SendSQL("INSERT INTO namedqueries " .
87
94
"(userid, name, query) VALUES " .
88
"($::userid, $qname, " . SqlQuote($value) . ")");
95
"($userid, $qname, " . SqlQuote($value) . ")");
97
SendSQL("UNLOCK TABLES");
91
print "Set-Cookie: $cookiename= ; path=" . Param("cookiepath") .
92
"; expires=Tue, 15-Sep-1998 21:49:00 GMT\n";
99
$cgi->remove_cookie($cookiename);
97
104
if ($::FORM{'nukedefaultquery'}) {
99
106
SendSQL("DELETE FROM namedqueries " .
100
"WHERE userid = $::userid AND name = '$::defaultqueryname'");
107
"WHERE userid = $userid AND name = '$::defaultqueryname'");
105
112
my $userdefaultquery;
107
114
SendSQL("SELECT query FROM namedqueries " .
108
"WHERE userid = $::userid AND name = '$::defaultqueryname'");
115
"WHERE userid = $userid AND name = '$::defaultqueryname'");
109
116
$userdefaultquery = FetchOneColumn();
126
133
"chfieldto", "chfieldvalue", "target_milestone",
127
134
"email", "emailtype", "emailreporter",
128
135
"emailassigned_to", "emailcc", "emailqa_contact",
136
"emaillongdesc", "content",
130
137
"changedin", "votes", "short_desc", "short_desc_type",
131
138
"long_desc", "long_desc_type", "bug_file_loc",
132
139
"bug_file_loc_type", "status_whiteboard",
133
140
"status_whiteboard_type", "bug_id",
134
"bugidtype", "keywords", "keywords_type") {
141
"bugidtype", "keywords", "keywords_type",
142
"x_axis_field", "y_axis_field", "z_axis_field",
143
"chart_format", "cumulate", "x_labels_vertical",
144
"category", "subcategory", "name", "newcategory",
145
"newsubcategory", "public", "frequency")
135
147
# This is a bit of a hack. The default, empty list has
136
148
# three entries to accommodate the needs of the email fields -
137
149
# we use each position to denote the relevant field. Array
167
# If the name begins with field, type, or value, then it is part of
168
# the boolean charts. Because these are built different than the rest
169
# of the form, we don't need to save a default value. We do, however,
170
# need to indicate that we found something so the default query isn't
171
# added in if all we have are boolean chart items.
172
if ($name =~ m/^(?:field|type|value)/) {
155
175
# If the name ends in a number (which it does for the fields which
156
176
# are part of the email searching), we use the array
157
177
# positions to show the defaults for that number field.
158
if ($name =~ m/^(.+)(\d)$/ && defined($default{$1})) {
178
elsif ($name =~ m/^(.+)(\d)$/ && defined($default{$1})) {
160
180
$default{$1}->[$2] = $value;
190
210
GetVersionTable();
192
# if using usebuggroups, then we don't want people to see products they don't
193
# have access to. Remove them from the list.
212
# if using groups for entry, then we don't want people to see products they
213
# don't have access to. Remove them from the list.
195
215
my @products = ();
196
216
my %component_set;
198
218
my %milestone_set;
199
foreach my $p (@::legal_product) {
200
# If we're using bug groups to restrict entry on products, and
201
# this product has a bug group, and the user is not in that
202
# group, we don't want to include that product in this list.
203
next if (Param("usebuggroups") && GroupExists($p) && !UserInGroup($p));
219
foreach my $p (GetSelectableProducts()) {
205
220
# We build up boolean hashes in the "-set" hashes for each of these things
206
221
# before making a list because there may be duplicates names across products.
207
222
push @products, $p;
245
# Sort the component list...
246
my $comps = \%::components;
247
foreach my $p (@products) {
248
my @tmp = sort { lc($a) cmp lc($b) } @{$comps->{$p}};
249
$comps->{$p} = \@tmp;
252
# and the version list...
253
my $vers = \%::versions;
254
foreach my $p (@products) {
255
my @tmp = sort { lc($a) cmp lc($b) } @{$vers->{$p}};
259
# and the milestone list.
261
if (Param('usetargetmilestone')) {
262
$mstones = \%::target_milestone;
263
foreach my $p (@products) {
264
my @tmp = sort { lc($a) cmp lc($b) } @{$mstones->{$p}};
265
$mstones->{$p} = \@tmp;
260
# Create data structures representing each product.
261
for (my $i = 0; $i < @products; ++$i) {
262
my $p = $products[$i];
264
# Bug 190611: band-aid to avoid crashing with no versions defined
265
if (!defined ($::components{$p})) {
266
$::components{$p} = [];
269
# Create hash to hold attributes for each product.
272
'components' => [ sort { lc($a) cmp lc($b) } @{$::components{$p}} ],
273
'versions' => [ sort { lc($a) cmp lc($b) } @{$::versions{$p}} ]
276
if (Param('usetargetmilestone')) {
277
# Sorting here is required for ordering multiple selections
278
# correctly; see bug 97736 for discussion on how to fix this
279
$product{'milestones'} =
280
[ sort { lc($a) cmp lc($b) } @{$::target_milestone{$p}} ];
283
# Assign hash back to product array.
284
$products[$i] = \%product;
269
# "foo" or "foos" is a list of all the possible (or legal) products,
270
# components, versions or target milestones.
271
# "foobyproduct" is a hash, keyed by product, of sorted lists
274
287
$vars->{'product'} = \@products;
276
289
# We use 'component_' because 'component' is a Template Toolkit reserved word.
277
$vars->{'componentsbyproduct'} = $comps;
278
290
$vars->{'component_'} = \@components;
280
$vars->{'versionsbyproduct'} = $vers;
281
292
$vars->{'version'} = \@versions;
283
294
if (Param('usetargetmilestone')) {
284
$vars->{'milestonesbyproduct'} = $mstones;
285
295
$vars->{'target_milestone'} = \@milestones;
292
302
# Another hack - this array contains "" for some reason. See bug 106589.
293
303
$vars->{'resolution'} = \@::legal_resolution;
295
$vars->{'chfield'} = ["[Bug creation]", @::log_columns];
307
push @chfields, "[Bug creation]";
309
# This is what happens when you have variables whose definition depends
310
# on the DB schema, and then the underlying schema changes...
311
foreach my $val (@::log_columns) {
312
if ($val eq 'product_id') {
314
} elsif ($val eq 'component_id') {
317
push @chfields, $val;
320
if (UserInGroup(Param('timetrackinggroup'))) {
321
push @chfields, "work_time";
323
@chfields = grep($_ ne "estimated_time", @chfields);
324
@chfields = grep($_ ne "remaining_time", @chfields);
326
@chfields = (sort(@chfields));
327
$vars->{'chfield'} = \@chfields;
296
328
$vars->{'bug_status'} = \@::legal_bug_status;
297
329
$vars->{'rep_platform'} = \@::legal_platform;
298
330
$vars->{'op_sys'} = \@::legal_opsys;
299
331
$vars->{'priority'} = \@::legal_priority;
300
332
$vars->{'bug_severity'} = \@::legal_severity;
301
$vars->{'userid'} = $::userid;
305
336
push(@fields, { name => "noop", description => "---" });
306
SendSQL("SELECT name, description FROM fielddefs ORDER BY sortkey");
307
while (MoreSQLData()) {
308
my ($name, $description) = FetchSQLData();
309
push(@fields, { name => $name, description => $description });
337
push(@fields, GetFieldDefs());
312
338
$vars->{'fields'} = \@fields;
314
340
# Creating new charts - if the cmd-add value is there, we define the field
345
371
$default{'charts'} = \@charts;
349
375
my @namedqueries;
350
376
SendSQL("SELECT name FROM namedqueries " .
351
"WHERE userid = $::userid AND name != '$::defaultqueryname' " .
377
"WHERE userid = $userid AND name != '$::defaultqueryname' " .
352
378
"ORDER BY name");
353
379
while (MoreSQLData()) {
354
380
push(@namedqueries, FetchOneColumn());
372
398
$vars->{'orders'} = \@orders;
373
399
$default{'querytype'} = $deforder || 'Importance';
401
if (($::FORM{'query_format'} || $::FORM{'format'} || "") eq "create-series") {
402
require Bugzilla::Chart;
403
$vars->{'category'} = Bugzilla::Chart::getVisibleSeries();
406
$vars->{'known_name'} = $cgi->param('known_name');
375
409
# Add in the defaults.
376
410
$vars->{'default'} = \%default;
412
$vars->{'format'} = $cgi->param('format');
413
$vars->{'query_format'} = $cgi->param('query_format');
415
# Set default page to "specific" if none proviced
416
if (!($cgi->param('query_format') || $cgi->param('format'))) {
417
if (defined $cgi->cookie('DEFAULTFORMAT')) {
418
$vars->{'format'} = $cgi->cookie('DEFAULTFORMAT');
420
$vars->{'format'} = 'specific';
424
# Set cookie to current format as default, but only if the format
425
# one that we should remember.
426
if (IsValidQueryType($vars->{'format'})) {
427
$cgi->send_cookie(-name => 'DEFAULTFORMAT',
428
-value => $vars->{'format'},
429
-expires => "Fri, 01-Jan-2038 00:00:00 GMT");
378
432
# Generate and return the UI (HTML page) from the appropriate template.
379
print "Content-type: text/html\n\n";
380
$template->process("search/search.html.tmpl", $vars)
433
# If we submit back to ourselves (for e.g. boolean charts), we need to
434
# preserve format information; hence query_format taking priority over
436
my $format = GetFormat("search/search",
437
$vars->{'query_format'} || $vars->{'format'},
438
$cgi->param('ctype'));
440
print $cgi->header($format->{'ctype'});
442
$template->process($format->{'template'}, $vars)
381
443
|| ThrowTemplateError($template->error());