From 7ce67eec4fb2c17ee3621b1aad2f99295ed4649f Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Fri, 2 Sep 2005 04:33:06 +0000 Subject: Bug 302370: Remove the EmitFormElements() routine from editproducts.cgi and templatize that code - Patch by Gabriel Sales de Oliveira r=LpSolit a=myk --- editproducts.cgi | 301 +++++++++++++------------------------------------------ 1 file changed, 72 insertions(+), 229 deletions(-) (limited to 'editproducts.cgi') diff --git a/editproducts.cgi b/editproducts.cgi index 5f6c32614..ba8337189 100755 --- a/editproducts.cgi +++ b/editproducts.cgi @@ -44,13 +44,6 @@ use Bugzilla::Config qw(:DEFAULT $datadir); # doesn't work for me. use vars qw(@legal_bug_status @legal_resolution); -my %ctl = ( - &::CONTROLMAPNA => 'NA', - &::CONTROLMAPSHOWN => 'Shown', - &::CONTROLMAPDEFAULT => 'Default', - &::CONTROLMAPMANDATORY => 'Mandatory' -); - # TestProduct: just returns if the specified product does exists # CheckProduct: same check, optionally emit an error text @@ -186,67 +179,6 @@ sub CheckClassificationProductNew } } -# -# Displays the form to edit a products parameters -# - -sub EmitFormElements -{ - my ($classification, $product, $description, $milestoneurl, $disallownew, - $votesperuser, $maxvotesperbug, $votestoconfirm, $defaultmilestone) - = @_; - - $product = value_quote($product); - $description = value_quote($description); - - if (Param('useclassification')) { - print " Classification:\n"; - print " ",html_quote($classification),"\n"; - print "\n"; - } - - print " Product:\n"; - print " \n"; - print "\n"; - - print " Description:\n"; - print " \n"; - - $defaultmilestone = value_quote($defaultmilestone); - if (Param('usetargetmilestone')) { - $milestoneurl = value_quote($milestoneurl); - print "\n"; - print " URL describing milestones for this product:\n"; - print " \n"; - - print "\n"; - print " Default milestone:\n"; - - print " \n"; - } else { - print qq{\n}; - } - - - print "\n"; - print " Closed for bug entry:\n"; - my $closed = $disallownew ? "CHECKED" : ""; - print " \n"; - - print "\n"; - print " Maximum votes per person:\n"; - print " \n"; - - print "\n"; - print " Maximum votes a person can put on a single bug:\n"; - print " \n"; - - print "\n"; - print " Number of votes a bug in this product needs to automatically get out of the UNCONFIRMED state:\n"; - print " \n"; -} - - # # Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d." # @@ -408,42 +340,18 @@ if (!$action && !$product) { # if ($action eq 'add') { - $template->put_header("Add product"); if (Param('useclassification')) { CheckClassification($classification); } - #print "This page lets you add a new product to bugzilla.\n"; - - print "
\n"; - print "\n"; - - EmitFormElements($classification,'', '', '', 0, 0, 10000, 0, "---"); - - print "\n"; - print " \n"; - print " \n"; - print "\n"; - print " \n"; - print " "; - print "\n"; - - print "
Version:
Create chart datasets for this product:
\n
\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "
"; - - my $other = $localtrailer; - $other =~ s/more/other/; - PutTrailer($other); + $vars->{'classification'} = $classification; + $template->process("admin/products/create.html.tmpl", $vars) + || ThrowTemplateError($template->error()); + exit; } - # # action='new' -> add product entered in the 'action=add' screen # @@ -781,8 +689,9 @@ if ($action eq 'delete') { # if ($action eq 'edit' || (!$action && $product)) { - $template->put_header("Edit product"); CheckProduct($product); + trick_taint($product); + my $product_id = get_product_id($product); my $classification_id=1; if (Param('useclassification')) { # If a product has been given with no classification associated @@ -790,7 +699,6 @@ if ($action eq 'edit' || (!$action && $product)) { if ($classification) { CheckClassificationProduct($classification, $product); } else { - trick_taint($product); $classification = $dbh->selectrow_array("SELECT classifications.name FROM products, classifications @@ -800,144 +708,79 @@ if ($action eq 'edit' || (!$action && $product)) { } $classification_id = get_classification_id($classification); } + + $vars->{'classification'} = $classification; # get data of product - SendSQL("SELECT classifications.description, - products.id,products.description,milestoneurl,disallownew, - votesperuser,maxvotesperbug,votestoconfirm,defaultmilestone - FROM products,classifications - WHERE products.name=" . SqlQuote($product) . - " AND classifications.id=" . SqlQuote($classification_id)); - my ($class_description, $product_id,$prod_description, $milestoneurl, $disallownew, - $votesperuser, $maxvotesperbug, $votestoconfirm, $defaultmilestone) = - FetchSQLData(); - - print "
\n"; - print "\n"; - - EmitFormElements($classification, $product, $prod_description, $milestoneurl, - $disallownew, $votesperuser, $maxvotesperbug, - $votestoconfirm, $defaultmilestone); + $vars->{'product'} = $dbh->selectrow_hashref(qq{ + SELECT id, name, classification_id, description, + milestoneurl, disallownew, votesperuser, + maxvotesperbug, votestoconfirm, defaultmilestone + FROM products + WHERE id = ?}, undef, $product_id); - print "\n"; - print " \n"; - print " \n\n"; - print " \n"; - print " \n\n"; - print " \n"; - print " \n\n"; - print " \n"; - print "\n\n"; - print " \n"; - print " \n
Edit components:"; - SendSQL("SELECT name,description - FROM components - WHERE product_id=$product_id"); - if (MoreSQLData()) { - print ""; - while ( MoreSQLData() ) { - my ($component, $description) = FetchSQLData(); - $description ||= "description missing"; - print ""; - print "\n"; - } - print "
$component:$description
\n"; - } else { - print "missing"; - } - - - print "
Edit versions:"; - SendSQL("SELECT value - FROM versions - WHERE product_id=$product_id - ORDER BY value"); - if (MoreSQLData()) { - my $br = 0; - while ( MoreSQLData() ) { - my ($version) = FetchSQLData(); - print "
" if $br; - print $version; - $br = 1; - } - } else { - print "missing"; - } + + $vars->{'components'} = $dbh->selectall_arrayref(qq{ + SELECT name, description + FROM components + WHERE product_id = ? + ORDER BY name}, {'Slice' => {}},$product_id); + + + $vars->{'versions'} = $dbh->selectcol_arrayref(q{ + SELECT value FROM versions + WHERE product_id = ? + ORDER BY value}, undef, $product_id); - # - # Adding listing for associated target milestones - matthew@zeroknowledge.com - # if (Param('usetargetmilestone')) { - print "
Edit milestones:"; - SendSQL("SELECT value - FROM milestones - WHERE product_id=$product_id - ORDER BY sortkey,value"); - if(MoreSQLData()) { - my $br = 0; - while ( MoreSQLData() ) { - my ($milestone) = FetchSQLData(); - print "
" if $br; - print $milestone; - $br = 1; - } - } else { - print "missing"; - } + $vars->{'milestones'} = $dbh->selectcol_arrayref(q{ + SELECT value + FROM milestones + WHERE product_id = ? + ORDER BY sortkey, value}, + undef, $product_id); } - - print "
Edit Group Access Controls\n"; - SendSQL("SELECT id, name, isactive, entry, membercontrol, othercontrol, canedit " . - "FROM groups, " . - "group_control_map " . - "WHERE group_control_map.group_id = id AND product_id = $product_id " . - "AND isbuggroup != 0 ORDER BY name"); - while (MoreSQLData()) { - my ($id, $name, $isactive, $entry, $membercontrol, $othercontrol, $canedit) - = FetchSQLData(); - print "" . html_quote($name) . ": "; - if ($isactive) { - print $ctl{$membercontrol} . "/" . $ctl{$othercontrol}; - print ", ENTRY" if $entry; - print ", CANEDIT" if $canedit; - } else { - print "DISABLED"; - } - print "
\n"; + + my $query = qq{SELECT + groups.id, groups.name, groups.isactive, + group_control_map.entry, + group_control_map.membercontrol, + group_control_map.othercontrol, + group_control_map.canedit + FROM groups + INNER JOIN group_control_map + ON groups.id = group_control_map.group_id + WHERE group_control_map.product_id = ? + AND groups.isbuggroup != 0 + ORDER BY groups.name}; + my $groups = $dbh->selectall_arrayref($query, {'Slice' => {}}, + $product_id); + + # Convert Group Controls(membercontrol and othercontrol) from + # integer to string to display Membercontrol/Othercontrol names + # at the template. + my $constants = { + (CONTROLMAPNA) => 'NA', + (CONTROLMAPSHOWN) => 'Shown', + (CONTROLMAPDEFAULT) => 'Default', + (CONTROLMAPMANDATORY) => 'Mandatory'}; + + foreach my $group (@$groups) { + $group->{'membercontrol'} = + $constants->{$group->{'membercontrol'}}; + $group->{'othercontrol'} = + $constants->{$group->{'othercontrol'}}; } - print "
Bugs:"; - SendSQL("SELECT count(bug_id), product_id - FROM bugs " . - $dbh->sql_group_by('product_id') . " - HAVING product_id = $product_id"); - my $bugs = ''; - $bugs = FetchOneColumn() if MoreSQLData(); - print $bugs || 'none'; - - print "
\n"; - - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - $defaultmilestone = value_quote($defaultmilestone); - print "\n"; - print "\n"; - print "\n"; - - print "
"; - - my $x = $localtrailer; - $x =~ s/more/other/; - PutTrailer($x); + + $vars->{'groups'} = $groups; + + $vars->{'bug_count'} = $dbh->selectrow_array(qq{ + SELECT COUNT(*) FROM bugs + WHERE product_id = ?}, undef, $product_id); + + $template->process("admin/products/edit.html.tmpl", $vars) + || ThrowTemplateError($template->error()); + exit; } -- cgit v1.2.3-24-g4f1b