diff options
-rw-r--r-- | defparams.pl | 6 | ||||
-rwxr-xr-x | editcomponents.cgi | 792 | ||||
-rwxr-xr-x | editproducts.cgi | 665 | ||||
-rwxr-xr-x | editusers.cgi | 583 | ||||
-rwxr-xr-x | editversions.cgi | 542 | ||||
-rwxr-xr-x | query.cgi | 2 |
6 files changed, 2510 insertions, 80 deletions
diff --git a/defparams.pl b/defparams.pl index 7efdc4053..56a63cf6d 100644 --- a/defparams.pl +++ b/defparams.pl @@ -353,6 +353,12 @@ Reason: %reason% %urlbase%show_bug.cgi?id=%bugid% "); +DefParam("allowbugdeletion", + q{The pages to edit products and components and versions can delete all associated bugs when you delete a product (or component or version). Since that is a pretty scary idea, you have to turn on this option before any such deletions will ever happen.}, + "b", + 0); + + 1; diff --git a/editcomponents.cgi b/editcomponents.cgi index e4b6a23de..371c27b72 100755 --- a/editcomponents.cgi +++ b/editcomponents.cgi @@ -10,114 +10,748 @@ # 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): Sam Ziegler <sam@ziegler.org> -# Terry Weissman <terry@mozilla.org> - -# Code derived from editparams.cgi, editowners.cgi +# +# +# Direct any questions on this source code to +# +# Holger Schurig <holgerschurig@nikocity.de> use diagnostics; use strict; require "CGI.pl"; +require "globals.pl"; + +my $dobugcounts = (defined $::FORM{'dobugcounts'}); + + + +# TestProduct: just returns if the specified product does exists +# CheckProduct: same check, optionally emit an error text +# TestComponent: just returns if the specified product/component combination exists +# CheckComponent: same check, optionally emit an error text + +sub TestProduct ($) +{ + my $prod = shift; + + # does the product exist? + SendSQL("SELECT product + FROM products + WHERE product=" . SqlQuote($prod)); + return FetchOneColumn(); +} + +sub CheckProduct ($) +{ + my $prod = shift; + + # do we have a product? + unless ($prod) { + print "Sorry, you haven't specified a product."; + PutTrailer(); + exit; + } + + unless (TestProduct $prod) { + print "Sorry, product '$prod' does not exist."; + PutTrailer(); + exit; + } +} + +sub TestComponent ($$) +{ + my ($prod,$comp) = @_; + + # does the product exist? + SendSQL("SELECT program,value + FROM components + WHERE program=" . SqlQuote($prod) . " and value=" . SqlQuote($comp)); + return FetchOneColumn(); +} + +sub CheckComponent ($$) +{ + my ($prod,$comp) = @_; + + # do we have the component? + unless ($comp) { + print "Sorry, you haven't specified a component."; + PutTrailer(); + exit; + } + + CheckProduct($prod); + + unless (TestComponent $prod,$comp) { + print "Sorry, component '$comp' for product '$prod' does not exist."; + PutTrailer(); + exit; + } +} + + +# +# Displays the form to edit component parameters +# + +sub EmitFormElements ($$$$$) +{ + my ($product, $component, $initialowner, $initialqacontact, $description) = @_; + + print " <TH ALIGN=\"right\">Component:</TH>\n"; + print " <TD><INPUT SIZE=64 MAXLENGTH=255 NAME=\"component\" VALUE=\"$component\">\n"; + print " <INPUT TYPE=HIDDEN NAME=\"product\" VALUE=\"$product\"></TD>\n"; + + print "</TR><TR>\n"; + print " <TH ALIGN=\"right\">Description:</TH>\n"; + print " <TD><TEXTAREA ROWS=4 COLS=64 WRAP=VIRTUAL NAME=\"description\">$description</TEXTAREA></TD>\n"; + + print "</TR><TR>\n"; + print " <TH ALIGN=\"right\">Initial owner:</TH>\n"; + print " <TD><INPUT TYPE=TEXT SIZE=64 MAXLENGTH=255 NAME=\"initialowner\" VALUE=\"$initialowner\"></TD>\n"; + + if (Param('useqacontact')) { + print "</TR><TR>\n"; + print " <TH ALIGN=\"right\">Initial QA contact:</TH>\n"; + print " <TD><INPUT TYPE=TEXT SIZE=64 MAXLENGTH=255 NAME=\"initialqacontact\" VALUE=\"$initialqacontact\"></TD>\n"; + } +} + + +# +# Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d." +# + +sub PutTrailer (@) +{ + my (@links) = ("Back to the <A HREF=\"query.cgi\">query page</A>", @_); + + my $count = $#links; + my $num = 0; + print "<P>\n"; + if (!$dobugcounts) { + print qq{<a href="editcomponents.cgi?dobugcounts=1&$::buffer">}; + print qq{Redisplay table with bug counts (slower)</a><p>\n}; + } + foreach (@links) { + print $_; + if ($num == $count) { + print ".\n"; + } + elsif ($num == $count-1) { + print " or "; + } + else { + print ", "; + } + $num++; + } + print "</BODY>\n</HTML>\n"; +} + + + + -# Shut up misguided -w warnings about "used only once": -use vars @::legal_product; + +# +# Preliminary checks: +# confirm_login(); print "Content-type: text/html\n\n"; -if (!UserInGroup("editcomponents")) { - print "<H1>Sorry, you aren't a member of the 'editcomponents' group.</H1>\n"; - print "And so, you aren't allowed to edit the owners.\n"; +unless (UserInGroup("editcomponents")) { + PutHeader("Not allowed"); + print "Sorry, you aren't a member of the 'editcomponents' group.\n"; + print "And so, you aren't allowed to add, modify or delete components.\n"; + PutTrailer(); exit; } -PutHeader("Edit Components"); +# +# often used variables +# +my $product = trim($::FORM{product} || ''); +my $component = trim($::FORM{component} || ''); +my $action = trim($::FORM{action} || ''); +my $localtrailer; +if ($product) { + $localtrailer = "<A HREF=\"editcomponents.cgi?product=" . url_quote($product) . "\">edit</A> more components"; +} else { + $localtrailer = "<A HREF=\"editcomponents.cgi\">edit</A> more components"; +} + + + +# +# product = '' -> Show nice list of products +# + +unless ($product) { + PutHeader("Select product"); + + if ($dobugcounts){ + SendSQL("SELECT products.product,products.description,COUNT(bug_id) + FROM products LEFT JOIN bugs + ON products.product=bugs.product + GROUP BY products.product + ORDER BY products.product"); + } else { + SendSQL("SELECT products.product,products.description + FROM products + ORDER BY products.product"); + } + print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0><TR BGCOLOR=\"#6666FF\">\n"; + print " <TH ALIGN=\"left\">Edit components of ...</TH>\n"; + print " <TH ALIGN=\"left\">Description</TH>\n"; + if ($dobugcounts) { + print " <TH ALIGN=\"left\">Bugs</TH>\n"; + } + #print " <TH ALIGN=\"left\">Edit</TH>\n"; + print "</TR>"; + while ( MoreSQLData() ) { + my ($product, $description, $bugs) = FetchSQLData(); + $description ||= "<FONT COLOR=\"red\">missing</FONT>"; + print "<TR>\n"; + print " <TD VALIGN=\"top\"><A HREF=\"editcomponents.cgi?product=", url_quote($product), "\"><B>$product</B></A></TD>\n"; + print " <TD VALIGN=\"top\">$description</TD>\n"; + if ($dobugcounts) { + $bugs ||= "none"; + print " <TD VALIGN=\"top\">$bugs</TD>\n"; + } + #print " <TD VALIGN=\"top\"><A HREF=\"editproducts.cgi?action=edit&product=", url_quote($product), "\">Edit</A></TD>\n"; + } + print "</TR></TABLE>\n"; -print "This lets you edit the program components of bugzilla.\n"; -print "<hr>"; -print "<a href=addcomponent.cgi>Add new component.</a><br>\n"; -print "<hr>"; + PutTrailer(); + exit; +} -print "<form method=post action=doeditcomponents.cgi>\n"; -my $rowbreak = "<tr><td colspan=2><hr></td></tr>"; -unlink "data/versioncache"; -GetVersionTable(); +# +# action='' -> Show nice list of components +# -my $prodcode = "P000"; +unless ($action) { + PutHeader("Select component"); + CheckProduct($product); -foreach my $product (@::legal_product) { - SendSQL("select description, milestoneurl, disallownew, votesperuser from products where product='$product'"); - my @row = FetchSQLData(); - if (!@row) { - next; + if ($dobugcounts) { + SendSQL("SELECT value,description,initialowner,initialqacontact,COUNT(bug_id) + FROM components LEFT JOIN bugs + ON components.program=bugs.product AND components.value=bugs.component + WHERE program=" . SqlQuote($product) . " + GROUP BY value"); + } else { + SendSQL("SELECT value,description,initialowner,initialqacontact + FROM components + WHERE program=" . SqlQuote($product) . " + GROUP BY value"); + } + print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0><TR BGCOLOR=\"#6666FF\">\n"; + print " <TH ALIGN=\"left\">Edit component ...</TH>\n"; + print " <TH ALIGN=\"left\">Description</TH>\n"; + print " <TH ALIGN=\"left\">Initial owner</TH>\n"; + print " <TH ALIGN=\"left\">Initial QA contact</TH>\n" + if Param('useqacontact'); + print " <TH ALIGN=\"left\">Bugs</TH>\n" + if $dobugcounts; + print " <TH ALIGN=\"left\">Delete</TH>\n"; + print "</TR>"; + while ( MoreSQLData() ) { + my ($component,$desc,$initialowner,$initialqacontact, $bugs) = FetchSQLData(); + $desc ||= "<FONT COLOR=\"red\">missing</FONT>"; + $initialowner ||= "<FONT COLOR=\"red\">missing</FONT>"; + $initialqacontact ||= "<FONT COLOR=\"red\">none</FONT>"; + print "<TR>\n"; + print " <TD VALIGN=\"top\"><A HREF=\"editcomponents.cgi?product=", url_quote($product), "&component=", url_quote($component), "&action=edit\"><B>$component</B></A></TD>\n"; + print " <TD VALIGN=\"top\">$desc</TD>\n"; + print " <TD VALIGN=\"top\">$initialowner</TD>\n"; + print " <TD VALIGN=\"top\">$initialqacontact</TD>\n" + if Param('useqacontact'); + if ($dobugcounts) { + $bugs ||= 'none'; + print " <TD VALIGN=\"top\">$bugs</TD>\n"; + } + print " <TD VALIGN=\"top\"><A HREF=\"editcomponents.cgi?product=", url_quote($product), "&component=", url_quote($component), "&action=del\"><B>Delete</B></A></TD>\n"; + print "</TR>"; } - my ($description, $milestoneurl, $disallownew, $votesperuser) = (@row); - $prodcode++; - print "<input type=hidden name=prodcode-$prodcode value=\"" . - value_quote($product) . "\">\n"; - print "<table><tr><th align=left valign=top>$product</th><td></td></tr>\n"; - print "<tr><th align=right>Description:</th>\n"; - print "<td><input size=80 name=$prodcode-description value=\"" . - value_quote($description) . "\"></td></tr>\n"; - if (Param('usetargetmilestone')) { - print "<tr><th align=right>MilestoneURL:</th>\n"; - print "<td><input size=80 name=$prodcode-milestoneurl value=\"" . - value_quote($milestoneurl) . "\"></td></tr>\n"; - } - print qq{<tr><th align=right>Maximum votes per user:</th><td>\n}; - print qq{<input size=10 name=$prodcode-votesperuser value=$votesperuser>}; - print qq{</td></tr>\n}; - my $check0 = !$disallownew ? " SELECTED" : ""; - my $check1 = $disallownew ? " SELECTED" : ""; - print "<tr><td colspan=2><select name=$prodcode-disallownew>\n"; - print "<option value=0$check0>Open; new bugs may be submitted against this project\n"; - print "<option value=1$check1>Closed; no new bugs may be submitted against this project\n"; - print "</select></td></tr>\n"; - - print "<tr><td colspan=2>Components:</td></tr></table>\n"; - print "<table>\n"; + print "<TR>\n"; + my $span = 3; + $span++ if Param('useqacontact'); + $span++ if $dobugcounts; + print " <TD VALIGN=\"top\" COLSPAN=$span>Add a new component</TD>\n"; + print " <TD VALIGN=\"top\" ALIGN=\"middle\"><A HREF=\"editcomponents.cgi?product=", url_quote($product) . "&action=add\">Add</A></TD>\n"; + print "</TR></TABLE>\n"; + + PutTrailer(); + exit; +} + + +$dobugcounts = 1; # Stupid hack to force further PutTrailer() + # calls to not offer a "bug count" option. + + +# +# action='add' -> present form for parameters for new component +# +# (next action will be 'new') +# + +if ($action eq 'add') { + PutHeader("Add component"); + CheckProduct($product); + + #print "This page lets you add a new product to bugzilla.\n"; + + print "<FORM METHOD=POST ACTION=editcomponents.cgi>\n"; + print "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=0><TR>\n"; + + EmitFormElements($product, '', '', '', ''); + + print "</TR></TABLE>\n<HR>\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Add\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"new\">\n"; + print "</FORM>"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='new' -> add component entered in the 'action=add' screen +# + +if ($action eq 'new') { + PutHeader("Adding new product"); + CheckProduct($product); + + # Cleanups and valididy checks + + unless ($component) { + print "You must enter a name for the new component. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + if (TestComponent($product,$component)) { + print "The component '$component' already exists. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + my $description = trim($::FORM{description} || ''); + + if ($description eq '') { + print "You must enter a description for the component '$component'. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + my $initialowner = trim($::FORM{initialowner} || ''); + + if ($initialowner eq '') { + print "You must enter an initial owner for the component '$component'. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + #+++ + #DBNameToIdAndCheck($initialowner, 0); + + my $initialqacontact = trim($::FORM{initialqacontact} || ''); + + if (Param('useqacontact')) { + if ($initialqacontact eq '') { + print "You must enter an initial QA contact for the component '$component'. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + #+++ + #DBNameToIdAndCheck($initialqacontact, 0); + } + + # Add the new component + SendSQL("INSERT INTO components ( " . + "program, value, description, initialowner, initialqacontact " . + " ) VALUES ( " . + SqlQuote($product) . "," . + SqlQuote($component) . "," . + SqlQuote($description) . "," . + SqlQuote($initialowner) . "," . + SqlQuote($initialqacontact) . ")"); + + # Make versioncache flush + unlink "data/versioncache"; + + print "OK, done.<p>\n"; + PutTrailer($localtrailer); + exit; +} + + + +# +# action='del' -> ask if user really wants to delete +# +# (next action would be 'delete') +# + +if ($action eq 'del') { + PutHeader("Delete component"); + CheckComponent($product, $component); + + # display some data about the component + SendSQL("SELECT products.product,products.description, + products.milestoneurl,products.disallownew, + components.program,components.value,components.initialowner, + components.initialqacontact,components.description + FROM products + LEFT JOIN components on product=program + WHERE product=" . SqlQuote($product) . " + AND value=" . SqlQuote($component) ); + + + my ($product,$pdesc,$milestoneurl,$disallownew, + $dummy,$component,$initialowner,$initialqacontact,$cdesc) = FetchSQLData(); + + $pdesc ||= "<FONT COLOR=\"red\">missing</FONT>"; + $milestoneurl ||= "<FONT COLOR=\"red\">missing</FONT>"; + $disallownew = $disallownew ? 'closed' : 'open'; + $initialowner ||= "<FONT COLOR=\"red\">missing</FONT>"; + $initialqacontact ||= "<FONT COLOR=\"red\">missing</FONT>"; + $cdesc ||= "<FONT COLOR=\"red\">missing</FONT>"; - SendSQL("select value, initialowner, initialqacontact, description from components where program=" . SqlQuote($product) . " order by value"); - my $c = 0; - while (my @row = FetchSQLData()) { - my ($component, $initialowner, $initialqacontact, $description) = - (@row); - $c++; - my $compcode = $prodcode . "-" . "C$c"; - print "<input type=hidden name=compcode-$compcode value=\"" . - value_quote($component) . "\">\n"; - print "<tr><th>$component</th><th align=right>Description:</th>\n"; - print "<td><input size=80 name=$compcode-description value=\"" . - value_quote($description) . "\"></td></tr>\n"; - print "<tr><td></td><th align=right>Initial owner:</th>\n"; - print "<td><input size=60 name=$compcode-initialowner value=\"" . - value_quote($initialowner) . "\"></td></tr>\n"; - if (Param('useqacontact')) { - print "<tr><td></td><th align=right>Initial QA contact:</th>\n"; - print "<td><input size=60 name=$compcode-initialqacontact value=\"" . - value_quote($initialqacontact) . "\"></td></tr>\n"; + print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0><TR BGCOLOR=\"#6666FF\">\n"; + print " <TH VALIGN=\"top\" ALIGN=\"left\">Part</TH>\n"; + print " <TH VALIGN=\"top\" ALIGN=\"left\">Value</TH>\n"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Component:</TD>\n"; + print " <TD VALIGN=\"top\">$component</TD>"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Component description:</TD>\n"; + print " <TD VALIGN=\"top\">$cdesc</TD>"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Initial owner:</TD>\n"; + print " <TD VALIGN=\"top\">$initialowner</TD>"; + + if (Param('useqacontact')) { + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Initial QA contact:</TD>\n"; + print " <TD VALIGN=\"top\">$initialqacontact</TD>"; + } + SendSQL("SELECT count(bug_id),product,component + FROM bugs + GROUP BY product + HAVING product=" . SqlQuote($product) . " + AND component=" . SqlQuote($component)); + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Component of product:</TD>\n"; + print " <TD VALIGN=\"top\">$product</TD>\n"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Description:</TD>\n"; + print " <TD VALIGN=\"top\">$pdesc</TD>\n"; + + if (Param('usetargetmilestone')) { + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Milestone URL:</TD>\n"; + print " <TD VALIGN=\"top\"><A HREF=\"$milestoneurl\">$milestoneurl</A></TD>\n"; + } + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Closed for bugs:</TD>\n"; + print " <TD VALIGN=\"top\">$disallownew</TD>\n"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Bugs</TD>\n"; + print " <TD VALIGN=\"top\">"; + my $bugs = FetchOneColumn(); + print $bugs || 'none'; + + + print "</TD>\n</TR></TABLE>"; + + print "<H2>Confirmation</H2>\n"; + + if ($bugs) { + if (!Param("allowbugdeletion")) { + print "Sorry, there are $bugs bugs outstanding for this component. +You must reassign those bugs to another component before you can delete this +one."; + PutTrailer($localtrailer); + exit; + } + print "<TABLE BORDER=0 CELLPADDING=20 WIDTH=\"70%\" BGCOLOR=\"red\"><TR><TD>\n", + "There are bugs entered for this component! When you delete this ", + "component, <B><BLINK>all</BLINK></B> stored bugs will be deleted, too. ", + "You could not even see the bug history for this component anymore!\n", + "</TD></TR></TABLE>\n"; + } + + print "<P>Do you really want to delete this component?<P>\n"; + + print "<FORM METHOD=POST ACTION=editcomponents.cgi>\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Yes, delete\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"delete\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"product\" VALUE=\"$product\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"component\" VALUE=\"$component\">\n"; + print "</FORM>"; + + PutTrailer($localtrailer); + exit; +} + + + +# +# action='delete' -> really delete the component +# + +if ($action eq 'delete') { + PutHeader("Deleting component"); + CheckComponent($product,$component); + + # lock the tables before we start to change everything: + + SendSQL("LOCK TABLES attachments WRITE, + bugs WRITE, + bugs_activity WRITE, + components WRITE, + dependencies WRITE"); + + # According to MySQL doc I cannot do a DELETE x.* FROM x JOIN Y, + # so I have to iterate over bugs and delete all the indivial entries + # in bugs_activies and attachments. + + SendSQL("SELECT bug_id + FROM bugs + WHERE product=" . SqlQuote($product) . " + AND component=" . SqlQuote($component)); + while (MoreSQLData()) { + my $bugid = FetchOneColumn(); + + my $query = $::db->query("DELETE FROM attachments WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM bugs_activity WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM dependencies WHERE blocked=$bugid") + or die "$::db_errstr"; + } + print "Attachments, bug activity and dependencies deleted.<BR>\n"; + + + # Deleting the rest is easier: + + SendSQL("DELETE FROM bugs + WHERE product=" . SqlQuote($product) . " + AND component=" . SqlQuote($component)); + print "Bugs deleted.<BR>\n"; + + SendSQL("DELETE FROM components + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($component)); + print "Components deleted.<P>\n"; + SendSQL("UNLOCK TABLES"); + + unlink "data/versioncache"; + PutTrailer($localtrailer); + exit; +} + + + +# +# action='edit' -> present the edit component form +# +# (next action would be 'update') +# + +if ($action eq 'edit') { + PutHeader("Edit component"); + CheckComponent($product,$component); + + # get data of component + SendSQL("SELECT products.product,products.description, + products.milestoneurl,products.disallownew, + components.program,components.value,components.initialowner, + components.initialqacontact,components.description + FROM products + LEFT JOIN components on product=program + WHERE product=" . SqlQuote($product) . " + AND value=" . SqlQuote($component) ); + + my ($product,$pdesc,$milestoneurl,$disallownew, + $dummy,$component,$initialowner,$initialqacontact,$cdesc) = FetchSQLData(); + + print "<FORM METHOD=POST ACTION=editcomponents.cgi>\n"; + print "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=0><TR>\n"; + + #+++ display product/product description + + EmitFormElements($product, $component, $initialowner, $initialqacontact, $cdesc); + + print "</TR><TR>\n"; + print " <TH ALIGN=\"right\">Bugs:</TH>\n"; + print " <TD>"; + SendSQL("SELECT count(*) + FROM bugs + WHERE product=" . SqlQuote($product) . + " and component=" . SqlQuote($component)); + my $bugs = ''; + $bugs = FetchOneColumn() if MoreSQLData(); + print $bugs || 'none'; + + print "</TD>\n</TR></TABLE>\n"; + + print "<INPUT TYPE=HIDDEN NAME=\"componentold\" VALUE=\"$component\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"descriptionold\" VALUE=\"$cdesc\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"initialownerold\" VALUE=\"$initialowner\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"initialqacontactold\" VALUE=\"$initialqacontact\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"update\">\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Update\">\n"; + + print "</FORM>"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='update' -> update the component +# + +if ($action eq 'update') { + PutHeader("Update component"); + + my $componentold = trim($::FORM{componentold} || ''); + my $description = trim($::FORM{description} || ''); + my $descriptionold = trim($::FORM{descriptionold} || ''); + my $initialowner = trim($::FORM{initialowner} || ''); + my $initialownerold = trim($::FORM{initialownerold} || ''); + my $initialqacontact = trim($::FORM{initialqacontact} || ''); + my $initialqacontactold = trim($::FORM{initialqacontactold} || ''); + + CheckComponent($product,$componentold); + + # Note that the order of this tests is important. If you change + # them, be sure to test for WHERE='$component' or WHERE='$componentold' + + SendSQL("LOCK TABLES bugs WRITE, + components WRITE"); + + if ($description ne $descriptionold) { + unless ($description) { + print "Sorry, I can't delete the description."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + SendSQL("UPDATE components + SET description=" . SqlQuote($description) . " + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($componentold)); + print "Updated description.<BR>\n"; + } + + + if ($initialowner ne $initialownerold) { + unless ($initialowner) { + print "Sorry, I can't delete the initial owner."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + #+++ + #DBNameToIdAndCheck($initialowner, 0); + SendSQL("UPDATE components + SET initialowner=" . SqlQuote($initialowner) . " + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($componentold)); + print "Updated initial owner.<BR>\n"; + } + + if (Param('useqacontact') && $initialqacontact ne $initialqacontactold) { + unless ($initialqacontact) { + print "Sorry, I can't delete the initial QA contact."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; } + #+++ + #DBNameToIdAndCheck($initialqacontact, 0); + SendSQL("UPDATE components + SET initialqacontact=" . SqlQuote($initialqacontact) . " + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($componentold)); + print "Updated initial QA contact.<BR>\n"; } - print "</table><hr>\n"; + if ($component ne $componentold) { + unless ($component) { + print "Sorry, I can't delete the product name."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + if (TestComponent($product,$component)) { + print "Sorry, component name '$component' is already in use."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + + SendSQL("UPDATE bugs + SET component=" . SqlQuote($component) . " + WHERE component=" . SqlQuote($componentold) . " + AND product=" . SqlQuote($product)); + SendSQL("UPDATE components + SET value=" . SqlQuote($component) . " + WHERE value=" . SqlQuote($componentold) . " + AND program=" . SqlQuote($product)); + + unlink "data/versioncache"; + print "Updated product name.<BR>\n"; + } + SendSQL("UNLOCK TABLES"); + + PutTrailer($localtrailer); + exit; } -print "<input type=submit value=\"Submit changes\">\n"; -print "</form>\n"; -print "<p><a href=query.cgi>Skip all this, and go back to the query page</a>\n"; +# +# No valid action found +# + +PutHeader("Error"); +print "I don't have a clue what you want.<BR>\n"; + +foreach ( sort keys %::FORM) { + print "$_: $::FORM{$_}<BR>\n"; +} diff --git a/editproducts.cgi b/editproducts.cgi new file mode 100755 index 000000000..be492ce01 --- /dev/null +++ b/editproducts.cgi @@ -0,0 +1,665 @@ +#!/usr/bonsaitools/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (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. +# +# +# Direct any questions on this source code to +# +# Holger Schurig <holgerschurig@nikocity.de> + +use diagnostics; +use strict; + +require "CGI.pl"; +require "globals.pl"; + + + + +# TestProduct: just returns if the specified product does exists +# CheckProduct: same check, optionally emit an error text + +sub TestProduct ($) +{ + my $prod = shift; + + # does the product exist? + SendSQL("SELECT product + FROM products + WHERE product=" . SqlQuote($prod)); + return FetchOneColumn(); +} + +sub CheckProduct ($) +{ + my $prod = shift; + + # do we have a product? + unless ($prod) { + print "Sorry, you haven't specified a product."; + PutTrailer(); + exit; + } + + unless (TestProduct $prod) { + print "Sorry, product '$prod' does not exist."; + PutTrailer(); + exit; + } +} + + +# +# Displays the form to edit a products parameters +# + +sub EmitFormElements ($$$$) +{ + my ($product, $description, $milestoneurl, $disallownew) = @_; + + print " <TH ALIGN=\"right\">Product:</TH>\n"; + print " <TD><INPUT SIZE=64 MAXLENGTH=64 NAME=\"product\" VALUE=\"$product\"></TD>\n"; + print "</TR><TR>\n"; + + print " <TH ALIGN=\"right\">Description:</TH>\n"; + print " <TD><TEXTAREA ROWS=4 COLS=64 WRAP=VIRTUAL NAME=\"description\">$description</TEXTAREA></TD>\n"; + + if (Param('usetargetmilestone')) { + print "</TR><TR>\n"; + print " <TH ALIGN=\"right\">Milestone URL:</TH>\n"; + print " <TD><INPUT TYPE=TEXT SIZE=64 MAXLENGTH=255 NAME=\"milestoneurl\" VALUE=\"$milestoneurl\"></TD>\n"; + } + + print "</TR><TR>\n"; + print " <TH ALIGN=\"right\">Closed for bug entry:</TH>\n"; + my $closed = $disallownew ? "CHECKED" : ""; + print " <TD><INPUT TYPE=CHECKBOX NAME=\"disallownew\" $closed VALUE=\"1\"></TD>\n"; +} + + +# +# Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d." +# + +sub PutTrailer (@) +{ + my (@links) = ("Back to the <A HREF=\"query.cgi\">query page</A>", @_); + + my $count = $#links; + my $num = 0; + print "<P>\n"; + foreach (@links) { + print $_; + if ($num == $count) { + print ".\n"; + } + elsif ($num == $count-1) { + print " or "; + } + else { + print ", "; + } + $num++; + } + print "</BODY>\n</HTML>\n"; +} + + + + + + + +# +# Preliminary checks: +# + +confirm_login(); + +print "Content-type: text/html\n\n"; + +unless (UserInGroup("editcomponents")) { + PutHeader("Not allowed"); + print "Sorry, you aren't a member of the 'editcomponents' group.\n"; + print "And so, you aren't allowed to add, modify or delete products.\n"; + PutTrailer(); + exit; +} + + + +# +# often used variables +# +my $product = trim($::FORM{product} || ''); +my $action = trim($::FORM{action} || ''); +my $localtrailer = "<A HREF=\"editproducts.cgi\">edit</A> more products"; + + + +# +# action='' -> Show nice list of products +# + +unless ($action) { + PutHeader("Select product"); + + SendSQL("SELECT products.product,description,disallownew,COUNT(bug_id) + FROM products LEFT JOIN bugs + ON products.product=bugs.product + GROUP BY products.product + ORDER BY products.product"); + print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0><TR BGCOLOR=\"#6666FF\">\n"; + print " <TH ALIGN=\"left\">Edit product ...</TH>\n"; + print " <TH ALIGN=\"left\">Description</TH>\n"; + print " <TH ALIGN=\"left\">Status</TH>\n"; + print " <TH ALIGN=\"left\">Bugs</TH>\n"; + print " <TH ALIGN=\"left\">Action</TH>\n"; + print "</TR>"; + while ( MoreSQLData() ) { + my ($product, $description, $disallownew, $bugs) = FetchSQLData(); + $description ||= "<FONT COLOR=\"red\">missing</FONT>"; + $disallownew = $disallownew ? 'closed' : 'open'; + $bugs ||= 'none'; + print "<TR>\n"; + print " <TD VALIGN=\"top\"><A HREF=\"editproducts.cgi?action=edit&product=", url_quote($product), "\"><B>$product</B></A></TD>\n"; + print " <TD VALIGN=\"top\">$description</TD>\n"; + print " <TD VALIGN=\"top\">$disallownew</TD>\n"; + print " <TD VALIGN=\"top\">$bugs</TD>\n"; + print " <TD VALIGN=\"top\"><A HREF=\"editproducts.cgi?action=del&product=", url_quote($product), "\">Delete</A></TD>\n"; + print "</TR>"; + } + print "<TR>\n"; + print " <TD VALIGN=\"top\" COLSPAN=4>Add a new product</TD>\n"; + print " <TD VALIGN=\"top\" ALIGN=\"middle\"><FONT SIZE =-1><A HREF=\"editproducts.cgi?action=add\">Add</A></FONT></TD>\n"; + print "</TR></TABLE>\n"; + + PutTrailer(); + exit; +} + + + + +# +# action='add' -> present form for parameters for new product +# +# (next action will be 'new') +# + +if ($action eq 'add') { + PutHeader("Add product"); + + #print "This page lets you add a new product to bugzilla.\n"; + + print "<FORM METHOD=POST ACTION=editproducts.cgi>\n"; + print "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=0><TR>\n"; + + EmitFormElements('', '', '', 0); + + print "</TR><TR>\n"; + print " <TH ALIGN=\"right\">Version:</TH>\n"; + print " <TD><INPUT SIZE=64 MAXLENGTH=255 NAME=\"version\" VALUE=\"unspecified\"></TD>\n"; + + print "</TABLE>\n<HR>\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Add\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"new\">\n"; + print "</FORM>"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='new' -> add product entered in the 'action=add' screen +# + +if ($action eq 'new') { + PutHeader("Adding new product"); + + # Cleanups and valididy checks + + unless ($product) { + print "You must enter a name for the new product. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + if (TestProduct($product)) { + print "The product '$product' already exists. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + my $version = trim($::FORM{version} || ''); + + if ($version eq '') { + print "You must enter a version for product '$product'. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + my $description = trim($::FORM{description} || ''); + my $milestoneurl = trim($::FORM{milestoneurl} || ''); + my $disallownew = 0; + $disallownew = 1 if $::FORM{disallownew}; + + # Add the new product. + SendSQL("INSERT INTO products ( " . + "product, description, milestoneurl, disallownew" . + " ) VALUES ( " . + SqlQuote($product) . "," . + SqlQuote($description) . "," . + SqlQuote($milestoneurl) . "," . + $disallownew . ")" ); + SendSQL("INSERT INTO versions ( " . + "value, program" . + " ) VALUES ( " . + SqlQuote($version) . "," . + SqlQuote($product) . ")" ); + + # Make versioncache flush + unlink "data/versioncache"; + + print "OK, done.<p>\n"; + PutTrailer($localtrailer, "<a href=\"editcomponents.cgi?action=add&product=" . url_quote($product) . "\">add</a> components to this new product."); + exit; +} + + + +# +# action='del' -> ask if user really wants to delete +# +# (next action would be 'delete') +# + +if ($action eq 'del') { + PutHeader("Delete product"); + CheckProduct($product); + + # display some data about the product + SendSQL("SELECT description, milestoneurl, disallownew + FROM products + WHERE product=" . SqlQuote($product)); + my ($description, $milestoneurl, $disallownew) = FetchSQLData(); + $description ||= "<FONT COLOR=\"red\">description missing</FONT>"; + $disallownew = $disallownew ? 'closed' : 'open'; + + print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0>\n"; + print "<TR BGCOLOR=\"#6666FF\">\n"; + print " <TH VALIGN=\"top\" ALIGN=\"left\">Part</TH>\n"; + print " <TH VALIGN=\"top\" ALIGN=\"left\">Value</TH>\n"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Product:</TD>\n"; + print " <TD VALIGN=\"top\">$product</TD>\n"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Description:</TD>\n"; + print " <TD VALIGN=\"top\">$description</TD>\n"; + + if (Param('usetargetmilestone')) { + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Milestone URL:</TD>\n"; + print " <TD VALIGN=\"top\"><A HREF=\"$milestoneurl\">$milestoneurl</A></TD>\n"; + } + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Closed for bugs:</TD>\n"; + print " <TD VALIGN=\"top\">$disallownew</TD>\n"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Components:</TD>\n"; + print " <TD VALIGN=\"top\">"; + SendSQL("SELECT value,description + FROM components + WHERE program=" . SqlQuote($product)); + if (MoreSQLData()) { + print "<table>"; + while ( MoreSQLData() ) { + my ($component, $description) = FetchSQLData(); + $description ||= "<FONT COLOR=\"red\">description missing</FONT>"; + print "<tr><th align=right valign=top>$component:</th>"; + print "<td valign=top>$description</td></tr>\n"; + } + print "</table>\n"; + } else { + print "<FONT COLOR=\"red\">missing</FONT>"; + } + + print "</TD>\n</TR><TR>\n"; + print " <TD VALIGN=\"top\">Versions:</TD>\n"; + print " <TD VALIGN=\"top\">"; + SendSQL("SELECT value + FROM versions + WHERE program=" . SqlQuote($product) . " + ORDER BY value"); + if (MoreSQLData()) { + my $br = 0; + while ( MoreSQLData() ) { + my ($version) = FetchSQLData(); + print "<BR>" if $br; + print $version; + $br = 1; + } + } else { + print "<FONT COLOR=\"red\">missing</FONT>"; + } + + + print "</TD>\n</TR><TR>\n"; + print " <TD VALIGN=\"top\">Bugs:</TD>\n"; + print " <TD VALIGN=\"top\">"; + SendSQL("SELECT count(bug_id),product + FROM bugs + GROUP BY product + HAVING product=" . SqlQuote($product)); + my $bugs = FetchOneColumn(); + print $bugs || 'none'; + + + print "</TD>\n</TR></TABLE>"; + + print "<H2>Confirmation</H2>\n"; + + if ($bugs) { + if (!Param("allowbugdeletion")) { + print "Sorry, there are $bugs bugs outstanding for this product. +You must reassign those bugs to another product before you can delete this +one."; + PutTrailer($localtrailer); + exit; + } + print "<TABLE BORDER=0 CELLPADDING=20 WIDTH=\"70%\" BGCOLOR=\"red\"><TR><TD>\n", + "There are bugs entered for this product! When you delete this ", + "product, <B><BLINK>all</BLINK><B> stored bugs will be deleted, too. ", + "You could not even see a bug history anymore!\n", + "</TD></TR></TABLE>\n"; + } + + print "<P>Do you really want to delete this product?<P>\n"; + print "<FORM METHOD=POST ACTION=editproducts.cgi>\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Yes, delete\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"delete\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"product\" VALUE=\"$product\">\n"; + print "</FORM>"; + + PutTrailer($localtrailer); + exit; +} + + + +# +# action='delete' -> really delete the product +# + +if ($action eq 'delete') { + PutHeader("Deleting product"); + CheckProduct($product); + + # lock the tables before we start to change everything: + + SendSQL("LOCK TABLES attachments WRITE, + bugs WRITE, + bugs_activity WRITE, + components WRITE, + dependencies WRITE, + versions WRITE, + products WRITE"); + + # According to MySQL doc I cannot do a DELETE x.* FROM x JOIN Y, + # so I have to iterate over bugs and delete all the indivial entries + # in bugs_activies and attachments. + + SendSQL("SELECT bug_id + FROM bugs + WHERE product=" . SqlQuote($product)); + while (MoreSQLData()) { + my $bugid = FetchOneColumn(); + + my $query = $::db->query("DELETE FROM attachments WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM bugs_activity WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM dependencies WHERE blocked=$bugid") + or die "$::db_errstr"; + } + print "Attachments, bug activity and dependencies deleted.<BR>\n"; + + + # Deleting the rest is easier: + + SendSQL("DELETE FROM bugs + WHERE product=" . SqlQuote($product)); + print "Bugs deleted.<BR>\n"; + + SendSQL("DELETE FROM components + WHERE program=" . SqlQuote($product)); + print "Components deleted.<BR>\n"; + + SendSQL("DELETE FROM versions + WHERE program=" . SqlQuote($product)); + print "Versions deleted.<P>\n"; + + SendSQL("DELETE FROM products + WHERE product=" . SqlQuote($product)); + print "Product '$product' deleted.<BR>\n"; + SendSQL("UNLOCK TABLES"); + + unlink "data/versioncache"; + PutTrailer($localtrailer); + exit; +} + + + +# +# action='edit' -> present the edit products from +# +# (next action would be 'update') +# + +if ($action eq 'edit') { + PutHeader("Edit product"); + CheckProduct($product); + + # get data of product + SendSQL("SELECT description,milestoneurl,disallownew + FROM products + WHERE product=" . SqlQuote($product)); + my ($description, $milestoneurl, $disallownew) = FetchSQLData(); + + print "<FORM METHOD=POST ACTION=editproducts.cgi>\n"; + print "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=0><TR>\n"; + + EmitFormElements($product, $description, $milestoneurl, $disallownew); + + print "</TR><TR>\n"; + print " <TH ALIGN=\"right\"><A HREF=\"editcomponents.cgi?product=", url_quote($product), "\">Edit components:</A></TH>\n"; + print " <TD>"; + SendSQL("SELECT value,description + FROM components + WHERE program=" . SqlQuote($product)); + if (MoreSQLData()) { + print "<table>"; + while ( MoreSQLData() ) { + my ($component, $description) = FetchSQLData(); + $description ||= "<FONT COLOR=\"red\">description missing</FONT>"; + print "<tr><th align=right valign=top>$component:</th>"; + print "<td valign=top>$description</td></tr>\n"; + } + print "</table>\n"; + } else { + print "<FONT COLOR=\"red\">missing</FONT>"; + } + + + print "</TD>\n</TR><TR>\n"; + print " <TH ALIGN=\"right\" VALIGN=\"top\"><A HREF=\"editversions.cgi?product=", url_quote($product), "\">Edit versions:</A></TH>\n"; + print " <TD>"; + SendSQL("SELECT value + FROM versions + WHERE program=" . SqlQuote($product) . " + ORDER BY value"); + if (MoreSQLData()) { + my $br = 0; + while ( MoreSQLData() ) { + my ($version) = FetchSQLData(); + print "<BR>" if $br; + print $version; + $br = 1; + } + } else { + print "<FONT COLOR=\"red\">missing</FONT>"; + } + + + print "</TD>\n</TR><TR>\n"; + print " <TH ALIGN=\"right\">Bugs:</TH>\n"; + print " <TD>"; + SendSQL("SELECT count(bug_id),product + FROM bugs + GROUP BY product + HAVING product=" . SqlQuote($product)); + my $bugs = ''; + $bugs = FetchOneColumn() if MoreSQLData(); + print $bugs || 'none'; + + print "</TD>\n</TR></TABLE>\n"; + + print "<INPUT TYPE=HIDDEN NAME=\"productold\" VALUE=\"$product\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"descriptionold\" VALUE=\"$description\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"milestoneurlold\" VALUE=\"$milestoneurl\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"disallownewold\" VALUE=\"$disallownew\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"update\">\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Update\">\n"; + + print "</FORM>"; + + my $x = $localtrailer; + $x =~ s/more/other/; + PutTrailer($x); + exit; +} + + + +# +# action='update' -> update the product +# + +if ($action eq 'update') { + PutHeader("Update product"); + + my $productold = trim($::FORM{productold} || ''); + my $description = trim($::FORM{description} || ''); + my $descriptionold = trim($::FORM{descriptionold} || ''); + my $disallownew = trim($::FORM{disallownew} || ''); + my $disallownewold = trim($::FORM{disallownewold} || ''); + my $milestoneurl = trim($::FORM{milestoneurl} || ''); + my $milestoneurlold = trim($::FORM{milestoneurlold} || ''); + + CheckProduct($productold); + + # Note that the order of this tests is important. If you change + # them, be sure to test for WHERE='$product' or WHERE='$productold' + + SendSQL("LOCK TABLES bugs WRITE, + components WRITE, + products WRITE, + versions WRITE"); + + if ($disallownew != $disallownewold) { + $disallownew ||= 0; + SendSQL("UPDATE products + SET disallownew=$disallownew + WHERE product=" . SqlQuote($productold)); + print "Updated bug submit status.<BR>\n"; + } + + if ($description ne $descriptionold) { + unless ($description) { + print "Sorry, I can't delete the description."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + SendSQL("UPDATE products + SET description=" . SqlQuote($description) . " + WHERE product=" . SqlQuote($productold)); + print "Updated description.<BR>\n"; + } + + if (Param('usetargetmilestone') && $milestoneurl ne $milestoneurlold) { + SendSQL("UPDATE products + SET milestoneurl=" . SqlQuote($milestoneurl) . " + WHERE product=" . SqlQuote($productold)); + print "Updated mile stone URL.<BR>\n"; + } + + + if ($product ne $productold) { + unless ($product) { + print "Sorry, I can't delete the product name."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + if (TestProduct($product)) { + print "Sorry, product name '$product' is already in use."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + + SendSQL("UPDATE bugs + SET product=" . SqlQuote($product) . " + WHERE product=" . SqlQuote($productold)); + SendSQL("UPDATE components + SET program=" . SqlQuote($product) . " + WHERE program=" . SqlQuote($productold)); + SendSQL("UPDATE products + SET product=" . SqlQuote($product) . " + WHERE product=" . SqlQuote($productold)); + SendSQL("UPDATE versions + SET program='$product' + WHERE program=" . SqlQuote($productold)); + + unlink "data/versioncache"; + print "Updated product name.<BR>\n"; + } + SendSQL("UNLOCK TABLES"); + + PutTrailer($localtrailer); + exit; +} + + + +# +# No valid action found +# + +PutHeader("Error"); +print "I don't have a clue what you want.<BR>\n"; + +foreach ( sort keys %::FORM) { + print "$_: $::FORM{$_}<BR>\n"; +} diff --git a/editusers.cgi b/editusers.cgi new file mode 100755 index 000000000..552474339 --- /dev/null +++ b/editusers.cgi @@ -0,0 +1,583 @@ +#!/usr/bonsaitools/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (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. +# +# +# Direct any questions on this source code to +# +# Holger Schurig <holgerschurig@nikocity.de> + +use diagnostics; +use strict; + +require "CGI.pl"; +require "globals.pl"; + + + + + +# TestUser: just returns if the specified user does exists +# CheckUser: same check, optionally emit an error text + +sub TestUser ($) +{ + my $user = shift; + + # does the product exist? + SendSQL("SELECT login_name + FROM profiles + WHERE login_name=" . SqlQuote($user)); + return FetchOneColumn(); +} + +sub CheckUser ($) +{ + my $user = shift; + + # do we have a product? + unless ($user) { + print "Sorry, you haven't specified a user."; + PutTrailer(); + exit; + } + + unless (TestUser $user) { + print "Sorry, user '$user' does not exist."; + PutTrailer(); + exit; + } +} + + + +# +# Displays the form to edit a user parameters +# + +sub EmitFormElements ($$$$) +{ + my ($user, $password, $realname, $groupset) = @_; + + print " <TH ALIGN=\"right\">Login name:</TH>\n"; + print " <TD><INPUT SIZE=64 MAXLENGTH=255 NAME=\"user\" VALUE=\"$user\"></TD>\n"; + + print "</TR><TR>\n"; + print " <TH ALIGN=\"right\">Real name:</TH>\n"; + print " <TD><INPUT SIZE=64 MAXLENGTH=255 NAME=\"realname\" VALUE=\"$realname\"></TD>\n"; + + print "</TR><TR>\n"; + print " <TH ALIGN=\"right\">Password:</TH>\n"; + print " <TD><INPUT SIZE=16 MAXLENGTH=16 NAME=\"password\" VALUE=\"$password\"></TD>\n"; + + + SendSQL("SELECT bit,name,description + FROM groups + ORDER BY name"); + while (MoreSQLData()) { + my($bit,$name,$description) = FetchSQLData(); + print "</TR><TR>\n"; + $bit = $bit+0; # this strange construct coverts a string to a number + print " <TH ALIGN=\"right\">", ucfirst($name), ":</TH>\n"; + my $checked = ($groupset & $bit) ? "CHECKED" : ""; + print " <TD><INPUT TYPE=CHECKBOX NAME=\"bit_$name\" $checked VALUE=\"$bit\"> $description</TD>\n"; + } + +} + + + +# +# Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d." +# + +sub PutTrailer (@) +{ + my (@links) = ("Back to the <A HREF=\"index.html\">index</A>", @_); + + my $count = $#links; + my $num = 0; + print "<P>\n"; + foreach (@links) { + print $_; + if ($num == $count) { + print ".\n"; + } + elsif ($num == $count-1) { + print " or "; + } + else { + print ", "; + } + $num++; + } + print "</BODY></HTML>\n"; +} + + + +# +# Preliminary checks: +# + +confirm_login(); + +print "Content-type: text/html\n\n"; + +unless (UserInGroup("tweakparams")) { + PutHeader("Not allowed"); + print "Sorry, you aren't a member of the 'tweakparams' group.\n"; + print "And so, you aren't allowed to add, modify or delete users.\n"; + PutTrailer(); + exit; +} + + + +# +# often used variables +# +my $user = trim($::FORM{user} || ''); +my $action = trim($::FORM{action} || ''); +my $localtrailer = "<A HREF=\"editusers.cgi\">edit</A> more users"; + + + +# +# action='' -> Show nice list of users +# + +unless ($action) { + PutHeader("Select user"); + + SendSQL("SELECT login_name,realname + FROM profiles + ORDER BY login_name"); + my $count = 0; + my $header = "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0><TR BGCOLOR=\"#6666FF\"> +<TH ALIGN=\"left\">Edit user ...</TH> +<TH ALIGN=\"left\">Real name</TH> +<TH ALIGN=\"left\">Action</TH>\n +</TR>"; + print $header; + while ( MoreSQLData() ) { + $count++; + if ($count % 100 == 0) { + print "</table>$header"; + } + my ($user, $realname) = FetchSQLData(); + $realname ||= "<FONT COLOR=\"red\">missing</FONT>"; + print "<TR>\n"; + print " <TD VALIGN=\"top\"><A HREF=\"editusers.cgi?action=edit&user=", url_quote($user), "\"><B>$user</B></A></TD>\n"; + print " <TD VALIGN=\"top\">$realname</TD>\n"; + print " <TD VALIGN=\"top\"><A HREF=\"editusers.cgi?action=del&user=", url_quote($user), "\">Delete</A></TD>\n"; + print "</TR>"; + } + print "<TR>\n"; + print " <TD VALIGN=\"top\" COLSPAN=2>Add a new user</TD>\n"; + print " <TD VALIGN=\"top\" ALIGN=\"middle\"><FONT SIZE =-1><A HREF=\"editusers.cgi?action=add\">Add</A></FONT></TD>\n"; + print "</TR></TABLE>\n"; + + PutTrailer(); + exit; +} + + + + +# +# action='add' -> present form for parameters for new user +# +# (next action will be 'new') +# + +if ($action eq 'add') { + PutHeader("Add user"); + + #print "This page lets you add a new product to bugzilla.\n"; + + print "<FORM METHOD=POST ACTION=editusers.cgi>\n"; + print "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=0><TR>\n"; + + EmitFormElements('', '', '', 0); + + print "</TR></TABLE>\n<HR>\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Add\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"new\">\n"; + print "</FORM>"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='new' -> add user entered in the 'action=add' screen +# + +if ($action eq 'new') { + PutHeader("Adding new user"); + + # Cleanups and valididy checks + my $realname = trim($::FORM{realname} || ''); + my $password = trim($::FORM{password} || ''); + + unless ($user) { + print "You must enter a name for the new user. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + unless ($user =~ /^[^\@]+\@[^\@]+$/) { + print "The user name entered must be a valid e-mail address. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + if (TestUser($user)) { + print "The user '$user' does already exist. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + if ($password !~ /^[a-zA-Z0-9-_]*$/ || length($password) < 3 || length($password) > 16) { + print "The new user must have a password. The password must be between ", + "3 and 16 characters long and must contain only numbers, letters, ", + "hyphens and underlines. Press <b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + my $bits = 0; + foreach (keys %::FORM) { + next unless /^bit_/; + #print "$_=$::FORM{$_}<br>\n"; + $bits |= $::FORM{$_}; + } + + + sub x { + my $sc="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./"; + return substr($sc, int (rand () * 100000) % (length ($sc) + 1), 1); + } + + my $salt = x() . x(); + my $cryptpassword = crypt($password, $salt); + + # Add the new user + SendSQL("INSERT INTO profiles ( " . + "login_name, password, cryptpassword, realname, groupset" . + " ) VALUES ( " . + SqlQuote($user) . "," . + SqlQuote($password) . "," . + SqlQuote($cryptpassword) . "," . + SqlQuote($realname) . "," . + $bits . ")" ); + + #+++ send e-mail away + + print "OK, done.<p>\n"; + PutTrailer($localtrailer, + "<a href=\"editusers.cgi?action=add\">add</a> another user."); + exit; + +} + + + +# +# action='del' -> ask if user really wants to delete +# +# (next action would be 'delete') +# + +if ($action eq 'del') { + PutHeader("Delete user"); + CheckUser($user); + + # display some data about the product + SendSQL("SELECT realname, groupset, emailnotification, login_name + FROM profiles + WHERE login_name=" . SqlQuote($user)); + my ($realname, $groupset, $emailnotification) = FetchSQLData(); + $realname ||= "<FONT COLOR=\"red\">missing</FONT>"; + + print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0>\n"; + print "<TR BGCOLOR=\"#6666FF\">\n"; + print " <TH VALIGN=\"top\" ALIGN=\"left\">Part</TH>\n"; + print " <TH VALIGN=\"top\" ALIGN=\"left\">Value</TH>\n"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Login name:</TD>\n"; + print " <TD VALIGN=\"top\">$user</TD>\n"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Real name:</TD>\n"; + print " <TD VALIGN=\"top\">$realname</TD>\n"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">E-Mail notification:</TD>\n"; + print " <TD VALIGN=\"top\">$emailnotification</TD>\n"; + + print "</TR><TR>\n"; + print " <TD VALIGN=\"top\">Group set:</TD>\n"; + print " <TD VALIGN=\"top\">"; + SendSQL("SELECT bit, name + FROM groups + ORDER BY name"); + my $found = 0; + while ( MoreSQLData() ) { + my ($bit,$name) = FetchSQLData(); + if ($bit & $groupset) { + print "<br>\n" if $found; + print ucfirst $name; + $found = 1; + } + } + print "none" unless $found; + print "</TD>\n</TR>"; + + + # Check if the user is an initialowner + my $nodelete = ''; + + SendSQL("SELECT program, value + FROM components + WHERE initialowner=" . SqlQuote($user)); + $found = 0; + while (MoreSQLData()) { + if ($found) { + print "<BR>\n"; + } else { + print "<TR>\n"; + print " <TD VALIGN=\"top\">Initial owner:</TD>\n"; + print " <TD VALIGN=\"top\">"; + } + my ($product, $component) = FetchSQLData(); + print "<a href=\"editcomponents.cgi?product=", url_quote($product), + "&component=", url_quote($component), + "&action=edit\">$product: $component</a>"; + $found = 1; + $nodelete = 'initial bug owner'; + } + print "</TD>\n</TR>" if $found; + + + # Check if the user is an initialqacontact + + SendSQL("SELECT program, value + FROM components + WHERE initialqacontact=" . SqlQuote($user)); + $found = 0; + while (MoreSQLData()) { + if ($found) { + print "<BR>\n"; + } else { + print "<TR>\n"; + print " <TD VALIGN=\"top\">Initial QA contact:</TD>\n"; + print " <TD VALIGN=\"top\">"; + } + my ($product, $component) = FetchSQLData(); + print "<a href=\"editcomponents.cgi?product=", url_quote($product), + "&component=", url_quote($component), + "&action=edit\">$product: $component</a>"; + $found = 1; + $nodelete = 'initial QA contact'; + } + print "</TD>\n</TR>" if $found; + + print "</TABLE>\n"; + + + if ($nodelete) { + print "<P>You can't delete this user because '$user' is an $nodelete ", + "for at least one product."; + PutTrailer($localtrailer); + exit; + } + + + print "<H2>Confirmation</H2>\n"; + print "<P>Do you really want to delete this user?<P>\n"; + + print "<FORM METHOD=POST ACTION=editusers.cgi>\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Yes, delete\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"delete\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"user\" VALUE=\"$user\">\n"; + print "</FORM>"; + + PutTrailer($localtrailer); + exit; +} + + + +# +# action='delete' -> really delete the user +# + +if ($action eq 'delete') { + PutHeader("Deleting user"); + CheckUser($user); + + SendSQL("SELECT userid + FROM profiles + WHERE login_name=" . SqlQuote($user)); + my $userid = FetchOneColumn(); + + SendSQL("DELETE FROM profiles + WHERE login_name=" . SqlQuote($user)); + SendSQL("DELETE FROM logincookies + WHERE userid=" . $userid); + print "User deleted.<BR>\n"; + + PutTrailer($localtrailer); + exit; +} + + + +# +# action='edit' -> present the user edit from +# +# (next action would be 'update') +# + +if ($action eq 'edit') { + PutHeader("Edit user"); + CheckUser($user); + + # get data of user + SendSQL("SELECT password, realname, groupset, emailnotification + FROM profiles + WHERE login_name=" . SqlQuote($user)); + my ($password, $realname, $groupset, $emailnotification) = FetchSQLData(); + + print "<FORM METHOD=POST ACTION=editusers.cgi>\n"; + print "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=0><TR>\n"; + + EmitFormElements($user, $password, $realname, $groupset); + + print "</TR></TABLE>\n"; + + print "<INPUT TYPE=HIDDEN NAME=\"userold\" VALUE=\"$user\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"passwordold\" VALUE=\"$password\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"realnameold\" VALUE=\"$realname\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"groupsetold\" VALUE=\"$groupset\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"emailnotificationold\" VALUE=\"$emailnotification\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"update\">\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Update\">\n"; + + print "</FORM>"; + + my $x = $localtrailer; + $x =~ s/more/other/; + PutTrailer($x); + exit; +} + +# +# action='update' -> update the user +# + +if ($action eq 'update') { + PutHeader("Update User"); + + my $userold = trim($::FORM{userold} || ''); + my $realname = trim($::FORM{realname} || ''); + my $realnameold = trim($::FORM{realnameold} || ''); + my $password = trim($::FORM{password} || ''); + my $passwordold = trim($::FORM{passwordold} || ''); + my $emailnotification = trim($::FORM{emailnotification} || ''); + my $emailnotificationold = trim($::FORM{emailnotificationold} || ''); + my $groupsetold = trim($::FORM{groupsetold} || ''); + + my $groupset = 0; + foreach (keys %::FORM) { + next unless /^bit_/; + #print "$_=$::FORM{$_}<br>\n"; + $groupset |= $::FORM{$_}; + } + + CheckUser($userold); + + # Note that the order of this tests is important. If you change + # them, be sure to test for WHERE='$product' or WHERE='$productold' + + if ($groupset != $groupsetold) { + SendSQL("UPDATE profiles + SET groupset=" . $groupset . " + WHERE login_name=" . SqlQuote($userold)); + print "Updated permissions.\n"; + } + +=for me + + if ($emailnotification ne $emailnotificationold) { + SendSQL("UPDATE profiles + SET emailnotification=" . $emailnotification . " + WHERE login_name=" . SqlQuote($userold)); + print "Updated email notification.<BR>\n"; + } + +=cut + + if ($password ne $passwordold) { + SendSQL("UPDATE profiles + SET password=" . SqlQuote($password) . " + WHERE login_name=" . SqlQuote($userold)); + print "Updated password.<BR>\n"; + } + if ($realname ne $realnameold) { + SendSQL("UPDATE profiles + SET realname=" . SqlQuote($realname) . " + WHERE login_name=" . SqlQuote($userold)); + print "Updated real name.<BR>\n"; + } + if ($user ne $userold) { + unless ($user) { + print "Sorry, I can't delete the user's name."; + PutTrailer($localtrailer); + exit; + } + if (TestUser($user)) { + print "Sorry, user name '$user' is already in use."; + PutTrailer($localtrailer); + exit; + } + + SendSQL("UPDATE profiles + SET login_name=" . SqlQuote($user) . " + WHERE login_name=" . SqlQuote($userold)); + + print "Updated user's name.<BR>\n"; + } + + PutTrailer($localtrailer); + exit; +} + + + +# +# No valid action found +# + +PutHeader("Error"); +print "I don't have a clue what you want.<BR>\n"; + +foreach ( sort keys %::FORM) { + print "$_: $::FORM{$_}<BR>\n"; +} diff --git a/editversions.cgi b/editversions.cgi new file mode 100755 index 000000000..7ac8032b2 --- /dev/null +++ b/editversions.cgi @@ -0,0 +1,542 @@ +#!/usr/bonsaitools/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (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. +# +# +# Direct any questions on this source code to +# +# Holger Schurig <holgerschurig@nikocity.de> + +use diagnostics; +use strict; + +require "CGI.pl"; +require "globals.pl"; + + + + +# TestProduct: just returns if the specified product does exists +# CheckProduct: same check, optionally emit an error text +# TestVersion: just returns if the specified product/version combination exists +# CheckVersion: same check, optionally emit an error text + +sub TestProduct ($) +{ + my $prod = shift; + + # does the product exist? + SendSQL("SELECT product + FROM products + WHERE product=" . SqlQuote($prod)); + return FetchOneColumn(); +} + +sub CheckProduct ($) +{ + my $prod = shift; + + # do we have a product? + unless ($prod) { + print "Sorry, you haven't specified a product."; + PutTrailer(); + exit; + } + + unless (TestProduct $prod) { + print "Sorry, product '$prod' does not exist."; + PutTrailer(); + exit; + } +} + +sub TestVersion ($$) +{ + my ($prod,$ver) = @_; + + # does the product exist? + SendSQL("SELECT program,value + FROM versions + WHERE program=" . SqlQuote($prod) . " and value=" . SqlQuote($ver)); + return FetchOneColumn(); +} + +sub CheckVersion ($$) +{ + my ($prod,$ver) = @_; + + # do we have the version? + unless ($ver) { + print "Sorry, you haven't specified a version."; + PutTrailer(); + exit; + } + + CheckProduct($prod); + + unless (TestVersion $prod,$ver) { + print "Sorry, version '$ver' for product '$prod' does not exist."; + PutTrailer(); + exit; + } +} + + +# +# Displays the form to edit a version +# + +sub EmitFormElements ($$) +{ + my ($product, $version) = @_; + + print " <TH ALIGN=\"right\">Version:</TH>\n"; + print " <TD><INPUT SIZE=64 MAXLENGTH=64 NAME=\"version\" VALUE=\"$version\">\n"; + print " <INPUT TYPE=HIDDEN NAME=\"product\" VALUE=\"$product\"></TD>\n"; +} + + +# +# Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d." +# + +sub PutTrailer (@) +{ + my (@links) = ("Back to the <A HREF=\"query.cgi\">query page</A>", @_); + + my $count = $#links; + my $num = 0; + print "<P>\n"; + foreach (@links) { + print $_; + if ($num == $count) { + print ".\n"; + } + elsif ($num == $count-1) { + print " or "; + } + else { + print ", "; + } + $num++; + } + print "</BODY>\n</HTML>\n"; +} + + + + + + + +# +# Preliminary checks: +# + +confirm_login(); + +print "Content-type: text/html\n\n"; + +unless (UserInGroup("editcomponents")) { + PutHeader("Not allowed"); + print "Sorry, you aren't a member of the 'editcomponents' group.\n"; + print "And so, you aren't allowed to add, modify or delete versions.\n"; + PutTrailer(); + exit; +} + + +# +# often used variables +# +my $product = trim($::FORM{product} || ''); +my $version = trim($::FORM{version} || ''); +my $action = trim($::FORM{action} || ''); +my $localtrailer; +if ($version) { + $localtrailer = "<A HREF=\"editversions.cgi?product=" . url_quote($product) . "\">edit</A> more versions"; +} else { + $localtrailer = "<A HREF=\"editversions.cgi\">edit</A> more versions"; +} + + + +# +# product = '' -> Show nice list of versions +# + +unless ($product) { + PutHeader("Select product"); + + SendSQL("SELECT products.product,products.description,'xyzzy' + FROM products + GROUP BY products.product + ORDER BY products.product"); + print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0><TR BGCOLOR=\"#6666FF\">\n"; + print " <TH ALIGN=\"left\">Edit versions of ...</TH>\n"; + print " <TH ALIGN=\"left\">Description</TH>\n"; + print " <TH ALIGN=\"left\">Bugs</TH>\n"; + #print " <TH ALIGN=\"left\">Edit</TH>\n"; + print "</TR>"; + while ( MoreSQLData() ) { + my ($product, $description, $bugs) = FetchSQLData(); + $description ||= "<FONT COLOR=\"red\">missing</FONT>"; + $bugs ||= "none"; + print "<TR>\n"; + print " <TD VALIGN=\"top\"><A HREF=\"editversions.cgi?product=", url_quote($product), "\"><B>$product</B></A></TD>\n"; + print " <TD VALIGN=\"top\">$description</TD>\n"; + print " <TD VALIGN=\"top\">$bugs</TD>\n"; + #print " <TD VALIGN=\"top\"><A HREF=\"editversions.cgi?action=edit&product=", url_quote($product), "\">Edit</A></TD>\n"; + } + print "</TR></TABLE>\n"; + + PutTrailer(); + exit; +} + + + +# +# action='' -> Show nice list of versions +# + +unless ($action) { + PutHeader("Select version"); + CheckProduct($product); + +=for me + + # Das geht nicht wie vermutet. Ich bekomme nicht alle Versionen + # angezeigt! Schade. Ich würde gerne sehen, wieviel Bugs pro + # Version angegeben sind ... + + SendSQL("SELECT value,program,COUNT(bug_id) + FROM versions LEFT JOIN bugs + ON program=product AND value=version + WHERE program=" . SqlQuote($product) . " + GROUP BY value"); + +=cut + + SendSQL("SELECT value,program + FROM versions + WHERE program=" . SqlQuote($product) . " + ORDER BY value"); + + print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0><TR BGCOLOR=\"#6666FF\">\n"; + print " <TH ALIGN=\"left\">Edit version ...</TH>\n"; + #print " <TH ALIGN=\"left\">Bugs</TH>\n"; + print " <TH ALIGN=\"left\">Action</TH>\n"; + print "</TR>"; + while ( MoreSQLData() ) { + my ($version,$dummy,$bugs) = FetchSQLData(); + $bugs ||= 'none'; + print "<TR>\n"; + print " <TD VALIGN=\"top\"><A HREF=\"editversions.cgi?product=", url_quote($product), "&version=", url_quote($version), "&action=edit\"><B>$version</B></A></TD>\n"; + #print " <TD VALIGN=\"top\">$bugs</TD>\n"; + print " <TD VALIGN=\"top\"><A HREF=\"editversions.cgi?product=", url_quote($product), "&version=", url_quote($version), "&action=del\"><B>Delete</B></A></TD>\n"; + print "</TR>"; + } + print "<TR>\n"; + print " <TD VALIGN=\"top\">Add a new version</TD>\n"; + print " <TD VALIGN=\"top\" ALIGN=\"middle\"><A HREF=\"editversions.cgi?product=", url_quote($product) . "&action=add\">Add</A></TD>\n"; + print "</TR></TABLE>\n"; + + PutTrailer(); + exit; +} + + + + +# +# action='add' -> present form for parameters for new version +# +# (next action will be 'new') +# + +if ($action eq 'add') { + PutHeader("Add version"); + CheckProduct($product); + + #print "This page lets you add a new version to a bugzilla-tracked product.\n"; + + print "<FORM METHOD=POST ACTION=editversions.cgi>\n"; + print "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=0><TR>\n"; + + EmitFormElements($product, $version); + + print "</TABLE>\n<HR>\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Add\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"new\">\n"; + print "</FORM>"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='new' -> add version entered in the 'action=add' screen +# + +if ($action eq 'new') { + PutHeader("Adding new version"); + CheckProduct($product); + + # Cleanups and valididy checks + + unless ($version) { + print "You must enter a text for the new version. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + if (TestVersion($product,$version)) { + print "The version '$version' already exists. Please press\n"; + print "<b>Back</b> and try again.\n"; + PutTrailer($localtrailer); + exit; + } + + # Add the new version + SendSQL("INSERT INTO versions ( " . + "value, program" . + " ) VALUES ( " . + SqlQuote($version) . "," . + SqlQuote($product) . ")"); + + # Make versioncache flush + unlink "data/versioncache"; + + print "OK, done.<p>\n"; + PutTrailer($localtrailer); + exit; +} + + + + +# +# action='del' -> ask if user really wants to delete +# +# (next action would be 'delete') +# + +if ($action eq 'del') { + PutHeader("Delete version"); + CheckVersion($product, $version); + + SendSQL("SELECT count(bug_id),product,version + FROM bugs + GROUP BY product,version + HAVING product=" . SqlQuote($product) . " + AND version=" . SqlQuote($version)); + my $bugs = FetchOneColumn(); + + print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0>\n"; + print "<TR BGCOLOR=\"#6666FF\">\n"; + print " <TH VALIGN=\"top\" ALIGN=\"left\">Part</TH>\n"; + print " <TH VALIGN=\"top\" ALIGN=\"left\">Value</TH>\n"; + + print "</TR><TR>\n"; + print " <TH ALIGN=\"left\" VALIGN=\"top\">Product:</TH>\n"; + print " <TD VALIGN=\"top\">$product</TD>\n"; + print "</TR><TR>\n"; + print " <TH ALIGN=\"left\" VALIGN=\"top\">Version:</TH>\n"; + print " <TD VALIGN=\"top\">$version</TD>\n"; + print "</TR><TR>\n"; + print " <TH ALIGN=\"left\" VALIGN=\"top\">Bugs:</TH>\n"; + print " <TD VALIGN=\"top\">", $bugs || 'none' , "</TD>\n"; + print "</TR></TABLE>\n"; + + print "<H2>Confirmation</H2>\n"; + + if ($bugs) { + if (!Param("allowbugdeletion")) { + print "Sorry, there are $bugs bugs outstanding for this version. +You must reassign those bugs to another version before you can delete this +one."; + PutTrailer($localtrailer); + exit; + } + print "<TABLE BORDER=0 CELLPADDING=20 WIDTH=\"70%\" BGCOLOR=\"red\"><TR><TD>\n", + "There are bugs entered for this version! When you delete this ", + "version, <B><BLINK>all</BLINK></B> stored bugs will be deleted, too. ", + "You could not even see the bug history for this version anymore!\n", + "</TD></TR></TABLE>\n"; + } + + print "<P>Do you really want to delete this version?<P>\n"; + print "<FORM METHOD=POST ACTION=editversions.cgi>\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Yes, delete\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"delete\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"product\" VALUE=\"$product\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"version\" VALUE=\"$version\">\n"; + print "</FORM>"; + + PutTrailer($localtrailer); + exit; +} + + + +# +# action='delete' -> really delete the version +# + +if ($action eq 'delete') { + PutHeader("Deleting version"); + CheckVersion($product,$version); + + # lock the tables before we start to change everything: + + SendSQL("LOCK TABLES attachments WRITE, + bugs WRITE, + bugs_activity WRITE, + versions WRITE, + dependencies WRITE"); + + # According to MySQL doc I cannot do a DELETE x.* FROM x JOIN Y, + # so I have to iterate over bugs and delete all the indivial entries + # in bugs_activies and attachments. + + SendSQL("SELECT bug_id + FROM bugs + WHERE product=" . SqlQuote($product) . " + AND version=" . SqlQuote($version)); + while (MoreSQLData()) { + my $bugid = FetchOneColumn(); + + my $query = $::db->query("DELETE FROM attachments WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM bugs_activity WHERE bug_id=$bugid") + or die "$::db_errstr"; + $query = $::db->query("DELETE FROM dependencies WHERE blocked=$bugid") + or die "$::db_errstr"; + } + print "Attachments, bug activity and dependencies deleted.<BR>\n"; + + + # Deleting the rest is easier: + + SendSQL("DELETE FROM bugs + WHERE product=" . SqlQuote($product) . " + AND version=" . SqlQuote($version)); + print "Bugs deleted.<BR>\n"; + + SendSQL("DELETE FROM versions + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($version)); + print "Version deleted.<P>\n"; + SendSQL("UNLOCK TABLES"); + + unlink "data/versioncache"; + PutTrailer($localtrailer); + exit; +} + + + +# +# action='edit' -> present the edit version form +# +# (next action would be 'update') +# + +if ($action eq 'edit') { + PutHeader("Edit version"); + CheckVersion($product,$version); + + print "<FORM METHOD=POST ACTION=editversions.cgi>\n"; + print "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=0><TR>\n"; + + EmitFormElements($product, $version); + + print "</TR></TABLE>\n"; + + print "<INPUT TYPE=HIDDEN NAME=\"versionold\" VALUE=\"$version\">\n"; + print "<INPUT TYPE=HIDDEN NAME=\"action\" VALUE=\"update\">\n"; + print "<INPUT TYPE=SUBMIT VALUE=\"Update\">\n"; + + print "</FORM>"; + + my $other = $localtrailer; + $other =~ s/more/other/; + PutTrailer($other); + exit; +} + + + +# +# action='update' -> update the version +# + +if ($action eq 'update') { + PutHeader("Update version"); + + my $versionold = trim($::FORM{versionold} || ''); + + CheckVersion($product,$versionold); + + # Note that the order of this tests is important. If you change + # them, be sure to test for WHERE='$version' or WHERE='$versionold' + + SendSQL("LOCK TABLES bugs WRITE, + versions WRITE"); + + if ($version ne $versionold) { + unless ($version) { + print "Sorry, I can't delete the version text."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + if (TestVersion($product,$version)) { + print "Sorry, version '$version' is already in use."; + PutTrailer($localtrailer); + SendSQL("UNLOCK TABLES"); + exit; + } + SendSQL("UPDATE bugs + SET version=" . SqlQuote($version) . " + WHERE version=" . SqlQuote($versionold) . " + AND product=" . SqlQuote($product)); + SendSQL("UPDATE versions + SET value=" . SqlQuote($version) . " + WHERE program=" . SqlQuote($product) . " + AND value=" . SqlQuote($versionold)); + unlink "data/versioncache"; + print "Updated version.<BR>\n"; + } + SendSQL("UNLOCK TABLES"); + + PutTrailer($localtrailer); + exit; +} + + + +# +# No valid action found +# + +PutHeader("Error"); +print "I don't have a clue what you want.<BR>\n"; + +foreach ( sort keys %::FORM) { + print "$_: $::FORM{$_}<BR>\n"; +} @@ -583,7 +583,7 @@ if (UserInGroup("tweakparams")) { print "<a href=editparams.cgi>Edit Bugzilla operating parameters</a><br>\n"; } if (UserInGroup("editcomponents")) { - print "<a href=editcomponents.cgi>Edit Bugzilla components</a><br>\n"; + print "<a href=editproducts.cgi>Edit Bugzilla products and components</a><br>\n"; } if (defined $::COOKIE{"Bugzilla_login"}) { print "<a href=relogin.cgi>Log in as someone besides <b>$::COOKIE{'Bugzilla_login'}</b></a><br>\n"; |