From 88d26275229b5f52f435130496169766313c87b7 Mon Sep 17 00:00:00 2001 From: "bugreport%peshkin.net" <> Date: Sat, 21 Aug 2004 04:49:17 +0000 Subject: Bug 224208 Add a higher level of categorization (.ie departments, locations, etc.) patch by Albert Ting r=joel, glob a=myk --- editproducts.cgi | 225 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 193 insertions(+), 32 deletions(-) (limited to 'editproducts.cgi') diff --git a/editproducts.cgi b/editproducts.cgi index bd71bdd6d..74a62166e 100755 --- a/editproducts.cgi +++ b/editproducts.cgi @@ -86,20 +86,80 @@ sub CheckProduct ($) } } +# TestClassification: just returns if the specified classification does exists +# CheckClassification: same check, optionally emit an error text + +sub TestClassification ($) +{ + my $cl = shift; + + # does the classification exist? + SendSQL("SELECT name + FROM classifications + WHERE name=" . SqlQuote($cl)); + return FetchOneColumn(); +} + +sub CheckClassification ($) +{ + my $cl = shift; + + # do we have a classification? + unless ($cl) { + print "Sorry, you haven't specified a classification."; + PutTrailer(); + exit; + } + + unless (TestClassification $cl) { + print "Sorry, classification '$cl' does not exist."; + PutTrailer(); + exit; + } +} + +sub CheckClassificationProduct ($$) +{ + my $cl = shift; + my $prod = shift; + + CheckClassification($cl); + CheckProduct($prod); + + # does the classification exist? + SendSQL("SELECT products.name + FROM products,classifications + WHERE products.name=" . SqlQuote($prod) . + " AND classifications.name=" . SqlQuote($cl)); + my $res = FetchOneColumn(); + + unless ($res) { + print "Sorry, classification->product '$cl'->'$prod' does not exist."; + PutTrailer(); + exit; + } +} + # # Displays the form to edit a products parameters # -sub EmitFormElements ($$$$$$$$) +sub EmitFormElements ($$$$$$$$$) { - my ($product, $description, $milestoneurl, $disallownew, + 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"; @@ -197,23 +257,83 @@ unless (UserInGroup("editcomponents")) { # # often used variables # +my $classification = trim($::FORM{classification} || ''); my $product = trim($::FORM{product} || ''); my $action = trim($::FORM{action} || ''); my $headerdone = 0; my $localtrailer = "edit more products"; +my $classhtmlvarstart = ""; +my $classhtmlvar = ""; + +if (Param('useclassification') && (defined $classification)) { + $classhtmlvar = "&classification=" . url_quote($classification); + $classhtmlvarstart = "?classification=" . url_quote($classification); +} + +if (Param('useclassification') && (defined $classification)) { + $localtrailer .= ", edit in this classification"; +} + +# +# product = '' -> Show nice list of products +# + +if (Param('useclassification')) { + unless ($classification) { + PutHeader("Select classification"); + + SendSQL("SELECT classifications.name,classifications.description,COUNT(classification_id) as total + FROM classifications + LEFT JOIN products ON classifications.id=products.classification_id + GROUP BY classifications.id + ORDER BY name"); + print "\n"; + print " \n"; + print " \n"; + print " \n"; + print ""; + while ( MoreSQLData() ) { + my ($classification, $description, $count) = FetchSQLData(); + $description ||= "missing"; + print "\n"; + print " \n"; + print " \n"; + $count ||= "none"; + print " \n"; + } + print "
Edit products of ...DescriptionTotal
$classification$description$count
\n"; + + PutTrailer(); + exit; + } +} + # # action='' -> Show nice list of products # unless ($action) { - PutHeader("Select product"); + if (Param('useclassification')) { + PutHeader("Select product in " . $classification); + } else { + PutHeader("Select product"); + } - SendSQL("SELECT products.name,description,disallownew, + my $query="SELECT products.name,products.description,disallownew, votesperuser,maxvotesperbug,votestoconfirm,COUNT(bug_id) - FROM products LEFT JOIN bugs ON products.id = bugs.product_id - GROUP BY products.name - ORDER BY products.name"); + FROM products"; + if (Param('useclassification')) { + $query .= ",classifications"; + } + $query .= " LEFT JOIN bugs ON products.id = bugs.product_id"; + if (Param('useclassification')) { + $query .= " WHERE classifications.name=" . + SqlQuote($classification) . + " AND classifications.id=products.classification_id"; + } + $query .= " GROUP BY products.name ORDER BY products.name"; + SendSQL($query); print "\n"; print " \n"; print " \n"; @@ -231,19 +351,19 @@ unless ($action) { $disallownew = $disallownew ? 'closed' : 'open'; $bugs ||= 'none'; print "\n"; - print " \n"; + print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; - print " \n"; + print " \n"; print ""; } print "\n"; print " \n"; - print " \n"; + print " \n"; print "
Edit product ...Description
$product$product$description$disallownew$votesperuser$maxvotesperbug$votestoconfirm$bugsDeleteDelete
Add a new productAddAdd
\n"; PutTrailer(); @@ -262,12 +382,15 @@ unless ($action) { if ($action eq 'add') { PutHeader("Add product"); + if (Param('useclassification')) { + CheckClassification($classification); + } #print "This page lets you add a new product to bugzilla.\n"; print "
\n"; print "\n"; - EmitFormElements('', '', '', 0, 0, 10000, 0, "---"); + EmitFormElements($classification,'', '', '', 0, 0, 10000, 0, "---"); print "\n"; print " \n"; @@ -282,6 +405,7 @@ if ($action eq 'add') { print "\n"; print "\n"; print "\n"; + print "\n"; print ""; my $other = $localtrailer; @@ -349,10 +473,15 @@ if ($action eq 'new') { $votestoconfirm ||= 0; my $defaultmilestone = $::FORM{defaultmilestone} || "---"; + my $classification_id = 1; + if (Param('useclassification')) { + $classification_id = get_classification_id($classification); + } + # Add the new product. SendSQL("INSERT INTO products ( " . "name, description, milestoneurl, disallownew, votesperuser, " . - "maxvotesperbug, votestoconfirm, defaultmilestone" . + "maxvotesperbug, votestoconfirm, defaultmilestone, classification_id" . " ) VALUES ( " . SqlQuote($product) . "," . SqlQuote($description) . "," . @@ -366,9 +495,11 @@ if ($action eq 'new') { SqlQuote($votesperuser) . "," . SqlQuote($maxvotesperbug) . "," . SqlQuote($votestoconfirm) . "," . - SqlQuote($defaultmilestone) . ")"); + SqlQuote($defaultmilestone) . "," . + SqlQuote($classification_id) . ")"); SendSQL("SELECT LAST_INSERT_ID()"); my $product_id = FetchOneColumn(); + SendSQL("INSERT INTO versions ( " . "value, product_id" . " ) VALUES ( " . @@ -455,7 +586,8 @@ if ($action eq 'new') { PutTrailer($localtrailer, "add a new product", "add components to this new product"); + url_quote($product) . $classhtmlvar . + "\">add components to this new product"); exit; } @@ -470,15 +602,23 @@ if ($action eq 'new') { if ($action eq 'del') { PutHeader("Delete product"); CheckProduct($product); + my $classification_id=1; + if (Param('useclassification')) { + CheckClassificationProduct($classification,$product); + $classification_id = get_classification_id($classification); + } # display some data about the product - SendSQL("SELECT id, description, milestoneurl, disallownew - FROM products - WHERE name=" . SqlQuote($product)); - my ($product_id, $description, $milestoneurl, $disallownew) = FetchSQLData(); + SendSQL("SELECT classifications.description, + products.id, products.description, milestoneurl, disallownew + FROM products,classifications + WHERE products.name=" . SqlQuote($product) . + " AND classifications.id=" . SqlQuote($classification_id)); + my ($class_description, $product_id, $prod_description, $milestoneurl, $disallownew) = FetchSQLData(); my $milestonelink = $milestoneurl ? "$milestoneurl" : "missing"; - $description ||= "description missing"; + $prod_description ||= "description missing"; + $class_description ||= "description missing"; $disallownew = $disallownew ? 'closed' : 'open'; print "
Version:
\n"; @@ -486,13 +626,23 @@ if ($action eq 'del') { print " \n"; print " \n"; + if (Param('useclassification')) { + print "\n"; + print " \n"; + print " \n"; + + print "\n"; + print " \n"; + print " \n"; + } + print "\n"; print " \n"; print " \n"; print "\n"; print " \n"; - print " \n"; + print " \n"; if (Param('usetargetmilestone')) { print "\n"; @@ -548,7 +698,7 @@ if ($action eq 'del') { # if (Param('usetargetmilestone')) { print "\n\n"; - print " \n"; + print " \n"; print "
PartValue
Classification:$classification
Description:$class_description
Product:$product
Description:$description$prod_description
Edit milestones:Edit milestones:"; SendSQL("SELECT value FROM milestones @@ -603,6 +753,8 @@ one."; print "\n"; print "\n"; + print "\n"; print ""; PutTrailer($localtrailer); @@ -706,25 +858,32 @@ if ($action eq 'delete') { if ($action eq 'edit') { PutHeader("Edit product"); CheckProduct($product); + my $classification_id=1; + if (Param('useclassification')) { + CheckClassificationProduct($classification,$product); + $classification_id = get_classification_id($classification); + } # get data of product - SendSQL("SELECT id,description,milestoneurl,disallownew, + SendSQL("SELECT classifications.description, + products.id,products.description,milestoneurl,disallownew, votesperuser,maxvotesperbug,votestoconfirm,defaultmilestone - FROM products - WHERE name=" . SqlQuote($product)); - my ($product_id,$description, $milestoneurl, $disallownew, + 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($product, $description, $milestoneurl, + EmitFormElements($classification, $product, $prod_description, $milestoneurl, $disallownew, $votesperuser, $maxvotesperbug, $votestoconfirm, $defaultmilestone); print "\n"; - print " \n"; + print " \n"; print " \n\n"; - print " \n"; + print " \n"; print " \n\n"; - print " \n"; + print " \n"; print " \n\n"; - print " \n"; + print " \n"; print "\n
Edit components:Edit components:"; SendSQL("SELECT name,description FROM components @@ -744,7 +903,7 @@ if ($action eq 'edit') { print "
Edit versions:Edit versions:"; SendSQL("SELECT value FROM versions @@ -767,7 +926,7 @@ if ($action eq 'edit') { # if (Param('usetargetmilestone')) { print "
Edit milestones:Edit milestones:"; SendSQL("SELECT value FROM milestones @@ -787,7 +946,7 @@ if ($action eq 'edit') { } print "
Edit Group Access ControlsEdit Group Access Controls\n"; SendSQL("SELECT id, name, isactive, entry, membercontrol, othercontrol, canedit " . "FROM groups, " . @@ -820,10 +979,12 @@ if ($action eq 'edit') { print "
\n"; + print "\n"; print "\n"; print "\n"; + html_quote($prod_description) . "\">\n"; print "\n"; print "\n"; @@ -843,7 +1004,6 @@ if ($action eq 'edit') { exit; } - # # action='updategroupcontrols' -> update the product # @@ -1325,6 +1485,7 @@ if ($action eq 'editgroupcontrols') { } $vars->{'header_done'} = $headerdone; $vars->{'product'} = $product; + $vars->{'classification'} = $classification; $vars->{'groups'} = \@groups; $vars->{'const'} = { 'CONTROLMAPNA' => CONTROLMAPNA, -- cgit v1.2.3-24-g4f1b