From a063aa364c6cafb341a1884691516fcc78a1187a Mon Sep 17 00:00:00 2001 From: "gerv%gerv.net" <> Date: Tue, 5 Feb 2002 05:17:10 +0000 Subject: show_bug.cgi templatisation. --- enter_bug.cgi | 545 ++++++++++------------------ template/default/entry/enter_bug.tmpl | 255 +++++++++++++ template/default/global/choose_product.tmpl | 41 +++ 3 files changed, 479 insertions(+), 362 deletions(-) create mode 100644 template/default/entry/enter_bug.tmpl create mode 100644 template/default/global/choose_product.tmpl diff --git a/enter_bug.cgi b/enter_bug.cgi index 4065fbbb9..eea2947bd 100755 --- a/enter_bug.cgi +++ b/enter_bug.cgi @@ -20,17 +20,17 @@ # Contributor(s): Terry Weissman # Dave Miller # Joe Robins +# Gervase Markham - -######################################################################## +############################################################################## # # enter_bug.cgi # ------------- # Displays bug entry form. Bug fields are specified through popup menus, -# drop-down lists, or text fields. Default for these values can be passed -# in as parameters to the cgi. +# drop-down lists, or text fields. Default for these values can be +# passed in as parameters to the cgi. # -######################################################################## +############################################################################## use diagnostics; use strict; @@ -39,105 +39,81 @@ use lib qw(.); require "CGI.pl"; -# Shut up misguided -w warnings about "used only once". "use vars" just -# doesn't work for me. - -sub sillyness { - my $zz; - $zz = $::unconfirmedstate; - $zz = @::legal_opsys; - $zz = @::legal_platform; - $zz = @::legal_priority; - $zz = @::legal_severity; -} - -# I've moved the call to confirm_login up to here, since if we're using bug -# groups to restrict bug entry, we need to know who the user is right from -# the start. If that parameter is turned off, there's still no harm done in -# doing it now instead of a bit later. -JMR, 2/18/00 -# Except that it will cause people without cookies enabled to have to log -# in an extra time. Only do it here if we really need to. -terry, 3/10/00 -if (Param("usebuggroupsentry")) { - confirm_login(); -} +use vars qw( + $unconfirmedstate + $template + $vars + %COOKIE + @legal_opsys + @legal_platform + @legal_priority + @legal_severity + %MFORM +); + +# Use template variables +my $template = $::template; +my $vars = $::vars; + +# If we're using bug groups to restrict bug entry, we need to know who the +# user is right from the start. +confirm_login() if (Param("usebuggroupsentry")); if (!defined $::FORM{'product'}) { GetVersionTable(); - my @prodlist; - foreach my $p (sort(keys %::versions)) { - if (defined $::proddesc{$p} && $::proddesc{$p} eq '0') { - # Special hack. If we stuffed a "0" into proddesc, that means - # that disallownew was set for this bug, and so we don't want - # to allow people to specify that product here. - next; - } - if(Param("usebuggroupsentry") - && GroupExists($p) - && !UserInGroup($p)) { - # If we're using bug groups to restrict entry on products, and - # this product has a bug group, and the user is not in that - # group, we don't want to include that product in this list. - next; + + foreach my $p (sort(keys(%::versions))) { + # Special hack: "0" in proddesc means disallownew was set. + # Also, if we're using bug groups to restrict entry on products, + # and this product has a bug group, and the user is not in that + # group, we don't want to include that product in this list. + if ((defined $::proddesc{$p} && $::proddesc{$p} eq '0') + || (Param("usebuggroupsentry") + && GroupExists($p) + && !UserInGroup($p))) + { + delete $::proddesc{$p}; } - push(@prodlist, $p); } - if (0 == @prodlist) { - print "Content-type: text/html\n\n"; - PutHeader("No Products Available"); - - print "Either no products have been defined to enter bugs against "; - print "or you have not been given access to any. Please email "; - print ""; - print Param("maintainer") . " if you feel this is in error.

\n"; - - PutFooter(); + + my $prodsize = scalar(keys %::proddesc); + if ($prodsize == 0) { + DisplayError("Either no products have been defined to enter bugs ". + "against or you have not been given access to any.\n"); exit; - } elsif (1 < @prodlist) { - print "Content-type: text/html\n\n"; - PutHeader("Enter Bug"); + } + elsif ($prodsize > 1) { + $vars->{'proddesc'} = \%::proddesc; + + $vars->{'target'} = "enter_bug.cgi"; + $vars->{'title'} = "Enter Bug"; + $vars->{'h2'} = + "First, you must pick a product on which to enter a bug."; - print "

First, you must pick a product on which to enter\n"; - print "a bug.

\n"; - print ""; - foreach my $p (@prodlist) { -# removed $::proddesc{$p} eq '0' check and UserInGroup($p) check from here -# because it's redundant. See the foreach loop above that created @prodlist. -# 1/13/01 - dave@intrec.com - print "\n"; - if (defined $::proddesc{$p}) { - print "\n"; - } - print ""; - } - print "
$p:$::proddesc{$p}
\n"; - PutFooter(); - exit; + print "Content-type: text/html\n\n"; + $template->process("global/choose_product.tmpl", $vars) + || DisplayError("Template process failed: " . $template->error()); + exit; } - $::FORM{'product'} = $prodlist[0]; -} -my $product = $::FORM{'product'}; + $::FORM{'product'} = (keys %::proddesc)[0]; + $::MFORM{'product'} = [$::FORM{'product'}]; -confirm_login(); +} -print "Content-type: text/html\n\n"; +my $product = $::FORM{'product'}; +############################################################################## +# Useful Subroutines +############################################################################## sub formvalue { my ($name, $default) = (@_); - if (exists $::FORM{$name}) { - return $::FORM{$name}; - } - if (defined $default) { - return $default; - } - return ""; + return $::FORM{$name} || $default || ""; } sub pickplatform { - my $value = formvalue("rep_platform"); - if ($value ne "") { - return $value; - } + return formvalue("rep_platform") if formvalue("rep_platform"); + if ( Param('usebrowserinfo') ) { for ($ENV{'HTTP_USER_AGENT'}) { #PowerPC @@ -181,42 +157,6 @@ sub pickplatform { return "Other"; } - - -sub pickversion { - my $version = formvalue('version'); - - if ( Param('usebrowserinfo') ) { - if ($version eq "") { - if ($ENV{'HTTP_USER_AGENT'} =~ m@Mozilla[ /]([^ ]*)@) { - $version = $1; - } - } - } - - if (lsearch($::versions{$product}, $version) >= 0) { - return $version; - } else { - if (defined $::COOKIE{"VERSION-$product"}) { - if (lsearch($::versions{$product}, - $::COOKIE{"VERSION-$product"}) >= 0) { - return $::COOKIE{"VERSION-$product"}; - } - } - } - return $::versions{$product}->[0]; -} - - -sub pickcomponent { - my $result =formvalue('component'); - if ($result ne "" && lsearch($::components{$product}, $result) < 0) { - $result = ""; - } - return $result; -} - - sub pickos { if (formvalue('op_sys') ne "") { return formvalue('op_sys'); @@ -253,18 +193,18 @@ sub pickos { /\(.*Mac OS 9.*\)/ && do {return "Mac System 9.x";}; /\(.*Mac OS 8\.6.*\)/ && do {return "Mac System 8.6";}; /\(.*Mac OS 8\.5.*\)/ && do {return "Mac System 8.5";}; -#we don't know 8.1 + # Bugzilla doesn't have an entry for 8.1 /\(.*Mac OS 8\.1.*\)/ && do {return "Mac System 8.0";}; /\(.*Mac OS 8\.0.*\)/ && do {return "Mac System 8.0";}; /\(.*Mac OS 8[^.].*\)/ && do {return "Mac System 8.0";}; /\(.*Mac OS 8.*\)/ && do {return "Mac System 8.6";}; /\(.*Mac OS X.*\)/ && do {return "MacOS X";}; /\(.*Darwin.*\)/ && do {return "MacOS X";}; -#silly + # Silly /\(.*Mac.*PowerPC.*\)/ && do {return "Mac System 9.x";}; /\(.*Mac.*PPC.*\)/ && do {return "Mac System 9.x";}; /\(.*Mac.*68k.*\)/ && do {return "Mac System 8.0";}; -#evil + # Evil /Amiga/i && do {return "other";}; /\(.*PowerPC.*\)/ && do {return "Mac System 9.x";}; /\(.*PPC.*\)/ && do {return "Mac System 9.x";}; @@ -274,271 +214,152 @@ sub pickos { # default return "other"; } +############################################################################## +# End of subroutines +############################################################################## +confirm_login() if (!(Param("usebuggroupsentry"))); -GetVersionTable(); - -my $assign_element = GeneratePersonInput('assigned_to', 1, - formvalue('assigned_to')); -my $cc_element = GeneratePeopleInput('cc', formvalue('cc')); - - -my $priority = Param('defaultpriority'); +# If the usebuggroupsentry parameter is set, we need to check and make sure +# that the user has permission to enter a bug against this product. +if(Param("usebuggroupsentry") + && GroupExists($product) + && !UserInGroup($product)) +{ + DisplayError("Sorry; you do not have the permissions necessary to " . + "enter a bug against this product.\n"); + exit; +} -my $priority_popup = make_popup('priority', \@::legal_priority, - formvalue('priority', $priority), 0); -my $sev_popup = make_popup('bug_severity', \@::legal_severity, - formvalue('bug_severity', 'normal'), 0); -my $platform_popup = make_popup('rep_platform', \@::legal_platform, - pickplatform(), 0); -my $opsys_popup = make_popup('op_sys', \@::legal_opsys, pickos(), 0); +GetVersionTable(); +if (!defined($::proddesc{$product}) || $::proddesc{$product} eq "0") { + DisplayError("'" . html_quote($product) . "' is not a valid product."); + exit; +} + if (0 == @{$::components{$product}}) { - print "

Permission Denied

\n"; - print "Sorry. You need to have at least one component for this product\n"; - print "in order to create a new bug. Go to the \"Components\" link to create\n"; - print "a new component\n"; - print "

\n"; - PutFooter(); - exit; -} elsif (1 == @{$::components{$product}}) { + my $error = "Sorry; there needs to be at least one component for this " . + "product in order to create a new bug. "; + if (UserInGroup('editcomponents')) { + $error .= "" . + "Create a new component\n"; + } + else { + $error .= "Please contact " . Param("maintainer") . ", detailing " . + "the product in which you tried to create a new bug.\n"; + } + + DisplayError($error); + exit; +} +elsif (1 == @{$::components{$product}}) { # Only one component; just pick it. $::FORM{'component'} = $::components{$product}->[0]; } -my $component_popup = make_popup('component', $::components{$product}, - formvalue('component'), 1); +my %default; -PutHeader ("Enter Bug","Enter Bug","This page lets you enter a new bug into Bugzilla."); +$vars->{'component_'} = $::components{$product}; +$default{'component_'} = formvalue('component'); -# Modified, -JMR, 2/24,00 -# If the usebuggroupsentry parameter is set, we need to check and make sure -# that the user has permission to enter a bug against this product. -# Modified, -DDM, 3/11/00 -# added GroupExists check so we don't choke on a groupless product -if(Param("usebuggroupsentry") - && GroupExists($product) - && !UserInGroup($product)) { - print "

Permission denied.

\n"; - print "Sorry; you do not have the permissions necessary to enter\n"; - print "a bug against this product.\n"; - print "

\n"; - PutFooter(); - exit; -} +$vars->{'assigned_to'} = formvalue('assigned_to'); +$vars->{'cc'} = formvalue('cc'); +$vars->{'reporter'} = $::COOKIE{'Bugzilla_login'}; +$vars->{'user_agent'} = $ENV{'HTTP_USER_AGENT'}; +$vars->{'product'} = $product; +$vars->{'bug_file_loc'} = formvalue('bug_file_loc', "http://"); +$vars->{'short_desc'} = formvalue('short_desc'); +$vars->{'comment'} = formvalue('comment'); -# Modified, -JMR, 2/18/00 -# I'm putting in a select box in order to select whether to restrict this bug to -# the product's bug group or not, if the usebuggroups parameter is set, and if -# this product has a bug group. This box will default to selected, but can be -# turned off if this bug should be world-viewable for some reason. -# -# To do this, I need to (1) get the bit and description for the bug group from -# the database, (2) insert the select box in the giant print statements below, -# and (3) update post_bug.cgi to process the additional input field. - -# Modified, -DDM, 3/11/00 -# Only need the bit here, and not the description. Description is gotten -# when the select boxes for all the groups this user has access to are read -# in later on. -# First we get the bit and description for the group. -my $group_bit=0; -if(Param("usebuggroups") && GroupExists($product)) { - SendSQL("select bit from groups ". - "where name = ".SqlQuote($product)." ". - "and isbuggroup != 0"); - ($group_bit) = FetchSQLData(); -} +$vars->{'priority'} = \@legal_priority; +$default{'priority'} = formvalue('priority', Param('defaultpriority')); -print " -

- - - "; - -if (Param("entryheaderhtml")){ - print " - - - - - "; -} +$vars->{'bug_severity'} = \@legal_severity; +$default{'bug_severity'} = formvalue('bug_severity', 'normal'); -print " - - - - - - - - - - - - - - - - - - - - - - - "; -if (Param('letsubmitterchoosepriority')) { - print " - - "; -} else { - print ''; -} -print " - - - - - - -"; +$vars->{'rep_platform'} = \@legal_platform; +$default{'rep_platform'} = pickplatform(); + +$vars->{'op_sys'} = \@legal_opsys; +$default{'op_sys'} = pickos(); + +# Default version is the last one in the list (hopefully the latest one). +# Eventually maybe each product should have a "current version" parameter. +$vars->{'version'} = $::versions{$product} || []; +$default{'version'} = $vars->{'version'}->[$#{$vars->{'version'}}]; + +# There must be at least one status in @status. +my @status = "NEW"; if (UserInGroup("editbugs") || UserInGroup("canconfirm")) { - SendSQL("SELECT votestoconfirm FROM products WHERE product = " . + SendSQL("SELECT votestoconfirm FROM products WHERE product = " . SqlQuote($product)); - if (FetchOneColumn()) { - print qq{ - - - "; - } + push(@status, $unconfirmedstate) if (FetchOneColumn()); } +$vars->{'bug_status'} = \@status; +$default{'bug_status'} = $status[0]; -print " - - - - - - - - - - - - - - - - - - - "; - -print " - - - - - - - "; - -if ( Param('usebrowserinfo') ) { - print " - - - - "; + $vars->{'group'} = \@groups; } -print " -
" . - Param("entryheaderhtml") . "\n" . - "

Reporter:$::COOKIE{'Bugzilla_login'}Product:$product
Version:" . Version_element(pickversion(), $product) . "Component:$component_popup
 
Platform:$platform_popupOS:$opsys_popup
Resolution
Priority
:
$priority_popupSeverity:$sev_popup
 
Initial state: -}; - print BuildPulldown("bug_status", - [[$::unconfirmedstate], ["NEW"]], - "NEW"); - print "
Assigned To:$assign_element - (Leave blank to assign to default component owner)
Cc:$cc_element
 
URL: - -
Summary: - -
Description:
-"; - +# Select whether to restrict this bug to the product's bug group or not, +# if the usebuggroups parameter is set, and if this product has a bug group. if ($::usergroupset ne '0') { + # First we get the bit and description for the group. + my $group_bit = '0'; + + if(Param("usebuggroups") && GroupExists($product)) { + SendSQL("SELECT bit FROM groups ". + "WHERE name = " . SqlQuote($product) . " " . + "AND isbuggroup != 0"); + ($group_bit) = FetchSQLData(); + } + SendSQL("SELECT bit, name, description FROM groups " . "WHERE bit & $::usergroupset != 0 " . - " AND isbuggroup != 0 AND isactive = 1 ORDER BY description"); - # We only print out a header bit for this section if there are any - # results. - my $groupFound = 0; + "AND isbuggroup != 0 AND isactive = 1 ORDER BY description"); + + my @groups; + while (MoreSQLData()) { - my ($bit, $prodname, $description) = (FetchSQLData()); + my ($bit, $prodname, $description) = FetchSQLData(); # Don't want to include product groups other than this product. - unless(($prodname eq $product) || (!defined($::proddesc{$prodname}))) { - next; - } - if(!$groupFound) { - print "
Only users in the selected groups can view this bug:
\n"; - print "(Leave all boxes unchecked to make this a public bug.)

\n"; - $groupFound = 1; - } - # Rather than waste time with another Param check and another database - # access, $group_bit will only have a non-zero value if we're using - # bug groups and have one for this product, so I'll check on that - # instead here. -JMR, 2/18/00 - # Moved this check to this location to fix conflict with existing - # select-box patch. Also, if $group_bit is 0, it won't match the - # current group, either, so I'll compare it to the current bit - # instead of checking for non-zero. -DDM, 3/11/00 - # Modifying this to use checkboxes instead of a select list. - # -JMR, 5/11/01 + next unless($prodname eq $product || + !defined($::proddesc{$prodname})); + + my $check; + # If this is the group for this product, make it checked. - my $check = ($group_bit == $bit); - # If this is a bookmarked template, then we only want to set the bit - # for those bits set in the template. - if(formvalue("maketemplate","") eq "Remember values as bookmarkable template") { - $check = formvalue("bit-$bit",0); + if(formvalue("maketemplate") eq + "Remember values as bookmarkable template") + { + # If this is a bookmarked template, then we only want to set the + # bit for those bits set in the template. + $check = formvalue("bit-$bit", 0); } - my $checked = $check ? " CHECKED" : ""; - # indent these a bit - print "    "; - print "\n"; - print "$description
\n"; + else { + # $group_bit will only have a non-zero value if we're using + # bug groups and have one for this product. + # If $group_bit is 0, it won't match the current group, so compare + # it to the current bit instead of checking for non-zero. + $check = ($group_bit == $bit); + } + + my $group = + { + 'bit' => $bit , + 'checked' => $check , + 'description' => $description + }; + + push @groups, $group; } -} -print " -
- -      - -      - -
-
- Some fields initialized from your user-agent, - $ENV{'HTTP_USER_AGENT'}. If you think it got it wrong, - please tell " . Param('maintainer') . " what it should have been. -
- -
\n"; -PutFooter(); - -print "\n"; +$vars->{'default'} = \%default; +print "Content-type: text/html\n\n"; +$template->process("entry/enter_bug.tmpl", $vars) + || DisplayError("Template process failed: " . $template->error()); +exit; diff --git a/template/default/entry/enter_bug.tmpl b/template/default/entry/enter_bug.tmpl new file mode 100644 index 000000000..3a86b55db --- /dev/null +++ b/template/default/entry/enter_bug.tmpl @@ -0,0 +1,255 @@ +[%# 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): Gervase Markham + #%] + +[% INCLUDE global/header + title = "Enter Bug" + h2 = "This page lets you enter a new bug into Bugzilla." +%] + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + [%# We can't use the select block in these two cases for various reasons. %] + + + + + + + + + + + + + + + [% sel = { description => 'Platform', name => 'rep_platform' } %] + [% INCLUDE select %] + + [% sel = { description => 'OS', name => 'op_sys' } %] + [% INCLUDE select %] + + + + [% IF Param('letsubmitterchoosepriority') %] + [% sel = { description => 'Priority', name => 'priority' } %] + [% INCLUDE select %] + [% ELSE %] + + [% END %] + + [% sel = { description => 'Severity', name => 'bug_severity' } %] + [% INCLUDE select %] + + + + + + + +[% IF bug_status.size > 1 %] + + [% sel = { description => 'Initial State', name => 'bug_status' } %] + [% INCLUDE select %] + + + +[% ELSE %] + +[% END %] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +[% IF Param('usebrowserinfo') %] + + + + +[% END %] + +

+ Before filling this in, please read the + bug-writing guidelines. +

Reporter:[% reporter FILTER html %]Product:[% product FILTER html %]
+ Version: + + + + + + Component: + + + +
 
 
+ + Assigned To: + + + + (Leave blank to assign to default component owner) +
Cc: + +
 
URL: + +
Summary: + +
Description: + +
+
+ [% IF group.size %] +
+ + Only users in the selected groups can view this bug: + +
+ + (Leave all boxes unchecked to make this a public bug.) + +
+
+ + + [% FOREACH g = group %] +      + [% g.description %]
+ [% END %] +
+ [% END %] +
+ +      + +
+
+ We've made a guess at your operating system and platform. + Please check them and, if we got it wrong, email + [% Param('maintainer') %]. +
+ +
+ +[% INCLUDE global/footer %] + +[%############################################################################%] +[%# Block for SELECT fields #%] +[%############################################################################%] + +[% BLOCK select %] + [% IF sel.description %] + + + [% sel.description %]: + + + [% END %] + + + + +[% END %] diff --git a/template/default/global/choose_product.tmpl b/template/default/global/choose_product.tmpl new file mode 100644 index 000000000..03d3fcd63 --- /dev/null +++ b/template/default/global/choose_product.tmpl @@ -0,0 +1,41 @@ +[%# 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): Gervase Markham + #%] + +[% DEFAULT title = "Choose a Product" %] +[% INCLUDE global/header %] + + + +[% FOREACH p = proddesc.keys.sort %] + + + + [% IF proddesc.$p %] + + [% END %] + +[% END %] + +
+ + [% p FILTER html %]: +  [% proddesc.$p %]
+ +[% INCLUDE global/footer %] -- cgit v1.2.3-24-g4f1b