diff options
author | lpsolit%gmail.com <> | 2005-10-12 17:51:52 +0200 |
---|---|---|
committer | lpsolit%gmail.com <> | 2005-10-12 17:51:52 +0200 |
commit | b8f2c324a9a4133f264254d61993ff8c7e0233a2 (patch) | |
tree | 312fb1aba4325c769a93939937a5f79f01fb7e02 /editparams.cgi | |
parent | 5eee7ab7fb527d926bfdf5927268862048cd4479 (diff) | |
download | bugzilla-b8f2c324a9a4133f264254d61993ff8c7e0233a2.tar.gz bugzilla-b8f2c324a9a4133f264254d61993ff8c7e0233a2.tar.xz |
Bug 46296: Make editparams.cgi be multi-panel by category - Patch by Frédéric Buclin <LpSolit@gmail.com> r=joel a=justdave
Diffstat (limited to 'editparams.cgi')
-rwxr-xr-x | editparams.cgi | 179 |
1 files changed, 82 insertions, 97 deletions
diff --git a/editparams.cgi b/editparams.cgi index 8924a0edc..4b1db455b 100755 --- a/editparams.cgi +++ b/editparams.cgi @@ -20,126 +20,111 @@ # # Contributor(s): Terry Weissman <terry@mozilla.org> # J. Paul Reed <preed@sigkill.com> - +# Frédéric Buclin <LpSolit@gmail.com> use strict; use lib "."; use Bugzilla::Constants; -use Bugzilla::Config qw(:DEFAULT :admin); +use Bugzilla::Config qw(:DEFAULT :admin :params $datadir); require "globals.pl"; +use vars qw($vars @parampanels); my $user = Bugzilla->login(LOGIN_REQUIRED); - +my $cgi = Bugzilla->cgi; my $template = Bugzilla->template; -print Bugzilla->cgi->header(); +print $cgi->header(); $user->in_group('tweakparams') || ThrowUserError("auth_failure", {group => "tweakparams", action => "modify", object => "parameters"}); -$template->put_header("Edit parameters"); - -print "This lets you edit the basic operating parameters of bugzilla.\n"; -print "Be careful!\n"; -print "<p>\n"; -print "Any item you check Reset on will get reset to its default value.\n"; - -print "<form method=post action=doeditparams.cgi><table>\n"; - -my $rowbreak = "<tr><td colspan=2><hr></td></tr>"; -print $rowbreak; - -foreach my $i (GetParamList()) { - my $name = $i->{'name'}; - my $value = Param($name); - print "<tr><th align=right valign=top>$name:</th><td>$i->{'desc'}</td></tr>\n"; - print "<tr><td valign=top><input type=checkbox name=reset-$name>Reset</td><td>\n"; - SWITCH: for ($i->{'type'}) { - /^t$/ && do { - print "<input size=80 name=$name value=\"" . - value_quote($value) . "\">\n"; - last SWITCH; - }; - /^l$/ && do { - print "<textarea wrap=hard name=$name rows=10 cols=80>" . - value_quote($value) . "</textarea>\n"; - last SWITCH; - }; - /^b$/ && do { - my $on; - my $off; - if ($value) { - $on = "checked"; - $off = ""; - } else { - $on = ""; - $off = "checked"; - } - print "<input type=radio name=$name value=1 $on>On\n"; - print "<input type=radio name=$name value=0 $off>Off\n"; - last SWITCH; - }; - /^m$/ && do { - my @choices = @{$i->{'choices'}}; - ## showing 5 options seems like a nice round number; this should - ## probably be configurable; if you care, file a bug ;-) - my $boxSize = scalar(@choices) < 5 ? scalar(@choices) : 5; - - print "<select multiple size=\"$boxSize\" name=\"$name\">\n"; - - foreach my $item (@choices) { - my $selected = ""; - - if (lsearch($value, $item) >= 0) { - $selected = "selected"; - } +my $action = trim($cgi->param('action') || ''); +my $current_panel = $cgi->param('section') || 'core'; +$current_panel =~ /^([A-Za-z0-9_-]+)$/; +$current_panel = $1; + +my $current_module; +my @panels = (); +foreach my $panel (@parampanels) { + next if ($panel eq 'Common'); + my @module_param_list = "Bugzilla::Config::${panel}"->get_param_list(); + my $item = { name => lc($panel), + current => ($current_panel eq lc($panel)) ? 1 : 0, + param_list => \@module_param_list, + sortkey => eval "\$Bugzilla::Config::${panel}::sortkey;" + }; + push(@panels, $item); + $current_module = $panel if ($current_panel eq lc($panel)); +} - print "<option $selected value=\"" . html_quote($item) . "\">" . - html_quote($item) . "</option>\n"; - } +$vars->{panels} = \@panels; - print "</select>\n"; - last SWITCH; - }; - /^s$/ && do { - print "<select name=\"$name\">\n"; - my @choices = @{$i->{'choices'}}; +if ($action eq "save") { + my @changes = (); + my @module_param_list = "Bugzilla::Config::${current_module}"->get_param_list(); - foreach my $item (@choices) { - my $selected = ""; + foreach my $i (@module_param_list) { + my $name = $i->{'name'}; + my $value = $cgi->param($name); - if ($value eq $item) { - $selected = "selected"; + if (defined $cgi->param("reset-$name")) { + $value = $i->{'default'}; + } else { + if ($i->{'type'} eq 'm') { + # This simplifies the code below + $value = [ $cgi->param($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$//; + } + } + + 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; + } } - - print "<option $selected value=\"" . html_quote($item) . "\">" . - html_quote($item) . "</option>\n"; - } - print "</select>\n"; - last SWITCH; - }; - # DEFAULT - print "<font color=red><blink>Unknown param type $i->{'type'}!!!</blink></font>\n"; + } else { + $changed = ($value eq Param($name))? 0 : 1; + } + + if ($changed) { + if (exists $i->{'checker'}) { + my $ok = $i->{'checker'}->($value, $i); + if ($ok ne "") { + ThrowUserError('invalid_parameter', { name => $name, err => $ok }); + } + } + push(@changes, $name); + SetParam($name, $value); + if (($name eq "shutdownhtml") && ($value ne "")) { + $vars->{'shutdown_is_active'} = 1; + } + } } - print "</td></tr>\n"; - print $rowbreak; -} - -print "<tr><th align=right valign=top>version:</th><td> -What version of Bugzilla this is. This can't be modified. -<tr><td></td><td>" . $Bugzilla::Config::VERSION . "</td></tr>"; - -print "</table>\n"; + $vars->{'message'} = 'parameters_updated'; + $vars->{'param_changed'} = \@changes; -print "<input type=reset value=\"Reset form\"><br>\n"; -print "<input type=submit value=\"Submit changes\">\n"; - -print "</form>\n"; + WriteParams(); + unlink "$datadir/versioncache"; +} -print "<p><a href=query.cgi>Skip all this, and go back to the query page</a>\n"; -$template->put_footer(); +$template->process("admin/params/editparams.html.tmpl", $vars) + || ThrowTemplateError($template->error()); |