2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / BugsSite / doeditparams.cgi
blob028f28a60ff4290d6754438c1eb79a4f4efee90a
1 #!/usr/bin/perl -wT
2 # -*- Mode: perl; indent-tabs-mode: nil -*-
4 # The contents of this file are subject to the Mozilla Public
5 # License Version 1.1 (the "License"); you may not use this file
6 # except in compliance with the License. You may obtain a copy of
7 # the License at http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS
10 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 # implied. See the License for the specific language governing
12 # rights and limitations under the License.
14 # The Original Code is the Bugzilla Bug Tracking System.
16 # The Initial Developer of the Original Code is Netscape Communications
17 # Corporation. Portions created by Netscape are
18 # Copyright (C) 1998 Netscape Communications Corporation. All
19 # Rights Reserved.
21 # Contributor(s): Terry Weissman <terry@mozilla.org>
22 # J. Paul Reed <preed@sigkill.com>
24 use strict;
26 use lib qw(.);
28 use Bugzilla;
29 use Bugzilla::Constants;
30 use Bugzilla::Config qw(:DEFAULT :admin $datadir);
31 use Bugzilla::User;
33 require "CGI.pl";
35 Bugzilla->login(LOGIN_REQUIRED);
37 my $cgi = Bugzilla->cgi;
39 print $cgi->header();
41 UserInGroup("tweakparams")
42 || ThrowUserError("auth_failure", {group => "tweakparams",
43 action => "modify",
44 object => "parameters"});
46 PutHeader("Saving new parameters");
48 my $howto = "";
50 foreach my $i (GetParamList()) {
51 my $name = $i->{'name'};
52 my $value = $cgi->param($name);
53 if (defined $cgi->param("reset-$name")) {
54 $value = $i->{'default'};
55 } else {
56 if ($i->{'type'} eq 'm') {
57 # This simplifies the code below
58 $value = [ $cgi->param($name) ];
59 } else {
60 # Get rid of windows/mac-style line endings.
61 $value =~ s/\r\n?/\n/g;
63 # assume single linefeed is an empty string
64 $value =~ s/^\n$//;
67 my $changed;
68 if ($i->{'type'} eq 'm') {
69 my @old = sort @{Param($name)};
70 my @new = sort @$value;
71 if (scalar(@old) != scalar(@new)) {
72 $changed = 1;
73 } else {
74 $changed = 0; # Assume not changed...
75 for (my $cnt = 0; $cnt < scalar(@old); ++$cnt) {
76 if ($old[$cnt] ne $new[$cnt]) {
77 # entry is different, therefore changed
78 $changed = 1;
79 last;
83 } else {
84 $changed = ($value eq Param($name) ? 0 : 1);
86 if ($changed) {
87 if (exists $i->{'checker'}) {
88 my $ok = $i->{'checker'}->($value, $i);
89 if ($ok ne "") {
90 print "New value for " . html_quote($name) .
91 " is invalid: $ok<p>\n";
92 print "Please hit <b>Back</b> and try again.\n";
93 PutFooter();
94 exit;
97 print "Changed " . html_quote($name) . ".<br>\n";
98 SetParam($name, $value);
99 if (($name eq "shutdownhtml") && ($value ne "")) {
100 # The system is down, inform the user how to restore it
101 $howto = "<p>Bugzilla has now been shut down, to re-enable ".
102 "the system, please return to ".
103 "<a href=\"editparams.cgi\">editparams.cgi</a>.</p>";
109 WriteParams();
111 unlink "$datadir/versioncache";
113 print "<p>OK, done.</p>\n";
114 print $howto;
115 print "<a href=\"editparams.cgi\">Edit the params some more.</a><p>\n";
116 print "<a href=\"query.cgi\">Go back to the query page.</a>\n";
118 PutFooter();