From 4c1922a6e893428bfbd43bc41ff4245384d8b543 Mon Sep 17 00:00:00 2001 From: "bbaetz%student.usyd.edu.au" <> Date: Thu, 29 Aug 2002 16:25:41 +0000 Subject: Bug 163829 - move pref code into a separate package r=joel, preed --- doeditparams.cgi | 91 ++++++++++++++++++++++++++------------------------------ 1 file changed, 42 insertions(+), 49 deletions(-) (limited to 'doeditparams.cgi') 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...
\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

\n"; + print "New value for " . html_quote($name) . + " is invalid: $ok

\n"; print "Please hit Back and try again.\n"; PutFooter(); exit; } } - print "Changed $i.
\n"; -# print "Old: '" . url_quote(Param($i)) . "'
\n"; -# print "New: '" . url_quote($::FORM{$i}) . "'
\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) . "
\n"; + SetParam($name, $value); } } -- cgit v1.2.3-24-g4f1b