From fc3aa3e7aa78106e8148b3ecbd92e65e5ad63985 Mon Sep 17 00:00:00 2001 From: "mkanat%kerio.com" <> Date: Thu, 17 Feb 2005 02:05:05 +0000 Subject: Bug 280412: Templatize the 'list products' bit of editproducts Patch By Gavin Shelly r=wurblzap, a=myk --- editproducts.cgi | 100 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 43 deletions(-) (limited to 'editproducts.cgi') diff --git a/editproducts.cgi b/editproducts.cgi index 3faa88563..0fa2ddbae 100755 --- a/editproducts.cgi +++ b/editproducts.cgi @@ -22,6 +22,7 @@ # Terry Weissman # Dawn Endico # Joe Robins +# Gavin Shelley # # Direct any questions on this source code to # @@ -117,6 +118,28 @@ sub CheckClassification ($) } } +# For the transition period, as this file is templatised bit by bit, +# we need this routine, which does things properly, and will +# eventually be the only version. (The older versions assume a +# PutHeader() call has been made) +sub CheckClassificationNew ($) +{ + my $cl = shift; + + # do we have a classification? + unless ($cl) { + ThrowUserError('classification_not_specified'); + exit; + } + + unless (TestClassification $cl) { + ThrowUserError('classification_doesnt_exist', + {'name' => $cl}); + exit; + } +} + + sub CheckClassificationProduct ($$) { my $cl = shift; @@ -308,59 +331,50 @@ if (Param('useclassification')) { # unless ($action) { + if (Param('useclassification')) { - PutHeader("Select product in " . $classification); - } else { - PutHeader("Select product"); + CheckClassificationNew($classification); } - my $query="SELECT products.name,products.description,disallownew, - votesperuser,maxvotesperbug,votestoconfirm,COUNT(bug_id) - FROM products"; + my $dbh = Bugzilla->dbh; + my @execute_params = (); + my @products = (); + + my $query = "SELECT products.name, + COALESCE(products.description,'') AS description, + NOT(disallownew) AS status, + votesperuser, maxvotesperbug, votestoconfirm, + COUNT(bug_id) AS bug_count + FROM products"; + if (Param('useclassification')) { - $query .= ",classifications"; + $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 .= " WHERE classifications.name = ? " . + " AND classifications.id = products.classification_id"; + + # trick_taint is OK because we use this in a placeholder in a SELECT + trick_taint($classification); + + push(@execute_params, + $classification); } + $query .= " GROUP BY products.name ORDER BY products.name"; - SendSQL($query); - print "\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print ""; - while ( MoreSQLData() ) { - my ($product, $description, $disallownew, $votesperuser, - $maxvotesperbug, $votestoconfirm, $bugs) = FetchSQLData(); - $description ||= "missing"; - $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 ""; - } - print "\n"; - print " \n"; - print " \n"; - print "
Edit product ...DescriptionStatusVotes
per
user
Max
Votes
per
bug
Votes
to
confirm
BugsAction
$product$description$disallownew$votesperuser$maxvotesperbug$votestoconfirm$bugsDelete
Add a new productAdd
\n"; - PutTrailer(); + $vars->{'products'} = $dbh->selectall_arrayref($query, + {'Slice' => {}}, + @execute_params); + + $vars->{'classification'} = $classification; + $template->process("admin/products/list.html.tmpl", + $vars) + || ThrowTemplateError($template->error()); + exit; } -- cgit v1.2.3-24-g4f1b