summaryrefslogtreecommitdiffstats
path: root/doeditparams.cgi
diff options
context:
space:
mode:
authorbbaetz%student.usyd.edu.au <>2002-08-29 18:25:41 +0200
committerbbaetz%student.usyd.edu.au <>2002-08-29 18:25:41 +0200
commit4c1922a6e893428bfbd43bc41ff4245384d8b543 (patch)
tree6c55aaa02be826e1352dd2d5be88b5ff61935029 /doeditparams.cgi
parent90c042db954fe86d555c2d3e413dd70f26d55cd4 (diff)
downloadbugzilla-4c1922a6e893428bfbd43bc41ff4245384d8b543.tar.gz
bugzilla-4c1922a6e893428bfbd43bc41ff4245384d8b543.tar.xz
Bug 163829 - move pref code into a separate package
r=joel, preed
Diffstat (limited to 'doeditparams.cgi')
-rwxr-xr-xdoeditparams.cgi91
1 files changed, 42 insertions, 49 deletions
diff --git a/doeditparams.cgi b/doeditparams.cgi
index b7c834979..3bdab3eb4 100755
--- a/doeditparams.cgi
+++ b/doeditparams.cgi
@@ -25,13 +25,11 @@ use strict;
use lib qw(.);
+use Bugzilla::Config qw(:DEFAULT :admin);
+
require "CGI.pl";
-require "defparams.pl";
-# Shut up misguided -w warnings about "used only once":
-use vars %::param,
- %::param_default,
- @::param_list;
+use vars %::MFORM;
ConnectToDatabase();
confirm_login();
@@ -45,62 +43,57 @@ if (!UserInGroup("tweakparams")) {
exit;
}
-
PutHeader("Saving new parameters");
-foreach my $i (@::param_list) {
-# print "Processing $i...<BR>\n";
- if (exists $::FORM{"reset-$i"}) {
- if ($::param_type{$i} eq "s") {
- my $index = get_select_param_index($i, $::param_default{$i}->[1]);
- die "Param not found for '$i'" if ($index eq undef);
- $::FORM{$i} = $index;
+foreach my $i (GetParamList()) {
+ my $name = $i->{'name'};
+ my $value = $::FORM{$name};
+ if (exists $::FORM{"reset-$name"}) {
+ $value = $i->{'default'};
+ } else {
+ if ($i->{'type'} eq 'm') {
+ # This simplifies the code below
+ $value = \@{$::MFORM{$name}};
+ } else {
+ # Get rid of windows/mac-style line endings.
+ $value =~ s/\r\n?/\n/g;
+
+ # assume single linefeed is an empty string
+ $value =~ s/^\n$//;
}
- elsif ($::param_type{$i} eq "m") {
- # For 'multi' selects, default is the 2nd anon array of the default
- @{$::MFORM{$i}} = ();
- foreach my $defaultPrm (@{$::param_default{$i}->[1]}) {
- my $index = get_select_param_index($i, $defaultPrm);
- die "Param not found for '$i'" if ($index eq undef);
- push(@{$::MFORM{$i}}, $index);
+ }
+ my $changed;
+ if ($i->{'type'} eq 'm') {
+ my @old = sort @{Param($name)};
+ my @new = sort @$value;
+ if (scalar(@old) != scalar(@new)) {
+ $changed = 1;
+ } else {
+ $changed = 0; # Assume not changed...
+ for (my $cnt = 0; $cnt < scalar(@old); ++$cnt) {
+ if ($old[$cnt] ne $new[$cnt]) {
+ # entry is different, therefore changed
+ $changed = 1;
+ last;
+ }
}
}
- else {
- $::FORM{$i} = $::param_default{$i};
- }
+ } else {
+ $changed = ($value eq Param($name) ? 0 : 1);
}
- $::FORM{$i} =~ s/\r\n?/\n/g; # Get rid of windows/mac-style line endings.
- $::FORM{$i} =~ s/^\n$//; # assume single linefeed is an empty string
- if ($::FORM{$i} ne Param($i)) {
- if (defined $::param_checker{$i}) {
- my $ref = $::param_checker{$i};
- my $ok = &$ref($::FORM{$i}, $i);
+ if ($changed) {
+ if (exists $i->{'checker'}) {
+ my $ok = $i->{'checker'}->($value, $i);
if ($ok ne "") {
- print "New value for $i is invalid: $ok<p>\n";
+ print "New value for " . html_quote($name) .
+ " is invalid: $ok<p>\n";
print "Please hit <b>Back</b> and try again.\n";
PutFooter();
exit;
}
}
- print "Changed $i.<br>\n";
-# print "Old: '" . url_quote(Param($i)) . "'<BR>\n";
-# print "New: '" . url_quote($::FORM{$i}) . "'<BR>\n";
- if ($::param_type{$i} eq "s") {
- $::param{$i} = $::param_default{$i}->[0]->[$::FORM{$i}];
- }
- elsif ($::param_type{$i} eq "m") {
- my $multiParamStr = "[ ";
- foreach my $chosenParam (@{$::MFORM{$i}}) {
- $multiParamStr .=
- "'$::param_default{$i}->[0]->[$chosenParam]', ";
- }
- $multiParamStr .= " ]";
-
- $::param{$i} = $multiParamStr;
- }
- else {
- $::param{$i} = $::FORM{$i};
- }
+ print "Changed " . html_quote($name) . "<br>\n";
+ SetParam($name, $value);
}
}