diff options
author | jeff <jeff> | 2007-07-18 18:07:38 +0000 |
---|---|---|
committer | jeff <jeff> | 2007-07-18 18:07:38 +0000 |
commit | cc0c6be1aa795f85d05f15a3e8568fcef2bbd380 (patch) | |
tree | ec860b85f11d59ccedfce77cf9d82fbf40eb9107 /httemplate/config/config.cgi | |
parent | 53d68b31e5ec07704c53829548c537bac03b8894 (diff) |
config in database cleanup, editing, and agent-specific config (452, 1419)
Diffstat (limited to 'httemplate/config/config.cgi')
-rw-r--r-- | httemplate/config/config.cgi | 423 |
1 files changed, 230 insertions, 193 deletions
diff --git a/httemplate/config/config.cgi b/httemplate/config/config.cgi index df9af47a6..10bbadaf8 100644 --- a/httemplate/config/config.cgi +++ b/httemplate/config/config.cgi @@ -1,4 +1,5 @@ -<% include("/elements/header.html",'Edit Configuration', menubar( 'Main Menu' => $p ) ) %> +<% include("/elements/header-popup.html", $title) %> + <SCRIPT> var gSafeOnload = new Array(); var gSafeOnsubmit = new Array(); @@ -18,250 +19,286 @@ function SafeOnsubmit() { gSafeOnsubmit[i](); } </SCRIPT> -% my $conf = new FS::Conf; my @config_items = $conf->config_items; - -<form name="OneTrueForm" action="config-process.cgi" METHOD="POST" enctype="multipart/form-data" onSubmit="SafeOnsubmit()"> -% foreach my $section ( qw(required billing username password UI session -% shell BIND -% ), -% '', 'deprecated') { +% if ( $cgi->param('error') ) { + <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT> + <BR><BR> +% } - <A NAME="<% $section || 'unclassified' %>"></A> - <FONT SIZE="-2"> -% foreach my $nav_section ( qw(required billing username password UI session -% shell BIND -% ), -% '', 'deprecated') { -% if ( $section eq $nav_section ) { +<FORM NAME="OneTrueForm" ACTION="config-process.cgi" METHOD="POST" enctype="multipart/form-data" onSubmit="SafeOnsubmit()"> +<INPUT TYPE="hidden" NAME="agentnum" VALUE="<% $agentnum %>"> +<INPUT TYPE="hidden" NAME="key" VALUE="<% $key %>"> - [<A NAME="not<% $nav_section || 'unclassified' %>" style="background-color: #cccccc"><% ucfirst($nav_section || 'unclassified') %></A>] -% } else { +Setting <% $key %> - [<A HREF="#<% $nav_section || 'unclassified' %>"><% ucfirst($nav_section || 'unclassified') %></A>] -% } -% } +<table><tr><td> - </FONT><BR> - <% table("#cccccc", 2) %> - <tr> - <th colspan="2" bgcolor="#dcdcdc"> - <% ucfirst($section || 'unclassified') %> configuration options - </th> - </tr> -% foreach my $i (grep $_->section eq $section, @config_items) { - - <tr> - <td> % my $n = 0; -% foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) { -% #warn $i->key unless defined($type); +% foreach my $type ( ref($config_item->type) ? @{$config_item->type} : $config_item->type ) { +% if ( $type eq '' ) { + + <font color="#ff0000">no type</font> + +% } elsif ( $type eq 'binary' ) { + + Filename <input type="file" name="<% "$key$n" %>"> + +% } elsif ( $type eq 'textarea' ) { + + <textarea name="<% "$key$n" %>" rows=5><% join("\n", $conf->config($key, $agentnum)) %></textarea> + +% } elsif ( $type eq 'checkbox' ) { + + <input name="<% "$key$n" %>" type="checkbox" value="1" + <% $conf->exists($key, $agentnum) ? 'CHECKED' : '' %> > + +% } elsif ( $type eq 'text' ) { + + <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' %>"> + +% } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) { + + <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>> + +% +% my %hash = (); +% if ( $config_item->select_enum ) { +% tie %hash, 'Tie::IxHash', +% '' => '', map { $_ => $_ } @{ $config_item->select_enum }; +% } elsif ( $config_item->select_hash ) { +% if ( ref($config_item->select_hash) eq 'ARRAY' ) { +% tie %hash, 'Tie::IxHash', +% '' => '', @{ $config_item->select_hash }; +% } else { +% tie %hash, 'Tie::IxHash', +% '' => '', %{ $config_item->select_hash }; +% } +% } else { +% %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' ); +% } +% +% my %saw = (); +% foreach my $value ( keys %hash ) { +% local($^W)=0; next if $saw{$value}++; +% my $label = $hash{$value}; % -% if ( $type eq '' ) { + <option value="<% $value %>" + +% if ( $value eq $conf->config($key, $agentnum) +% || ( $type eq 'selectmultiple' +% && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) { + + SELECTED + +% } + + ><% $label %> + +% } +% my $curvalue = $conf->config($key, $agentnum); +% if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) { - <font color="#ff0000">no type</font> -% } elsif ( $type eq 'binary' ) { + <option value="<% $curvalue %>" SELECTED> +% if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) { - Filename <input type="file" name="<% $i->key. $n %>"> -% } elsif ( $type eq 'textarea' ) { + <% $hash{ $conf->config($key, $agentnum) } %> +% }else{ - <textarea name="<% $i->key. $n %>" rows=5><% "\n". join("\n", $conf->config($i->key) ) %></textarea> -% } elsif ( $type eq 'checkbox' ) { + <% $curvalue %> +% } +% } - <input name="<% $i->key. $n %>" type="checkbox" value="1"<% $conf->exists($i->key) ? ' CHECKED' : '' %>> -% } elsif ( $type eq 'text' ) { + </select> +% } elsif ( $type eq 'select-sub' ) { - <input name="<% $i->key. $n %>" type="<% $type %>" value="<% $conf->exists($i->key) ? $conf->config($i->key) : '' %>"> -% } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) { + <select name="<% "$key$n" %>"><option value=""> - - <select name="<% $i->key. $n %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>> -% -% my %hash = (); -% if ( $i->select_enum ) { -% tie %hash, 'Tie::IxHash', -% '' => '', map { $_ => $_ } @{ $i->select_enum }; -% } elsif ( $i->select_hash ) { -% if ( ref($i->select_hash) eq 'ARRAY' ) { -% tie %hash, 'Tie::IxHash', -% '' => '', @{ $i->select_hash }; -% } else { -% tie %hash, 'Tie::IxHash', -% '' => '', %{ $i->select_hash }; -% } -% } else { -% %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $i->key. '"' ); -% } +% my %options = &{$config_item->options_sub}; +% my @options = sort { $a <=> $b } keys %options; +% my %saw; +% foreach my $value ( @options ) { +% local($^W)=0; next if $saw{$value}++; + + <option value="<% $value %>" <% $value eq $conf->config($key, $agentnum) ? 'SELECTED' : '' %>><% $value %>: <% $options{$value} %> + +% } +% my $curvalue = $conf->config($key, $agentnum); +% if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) { + + <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %> + +% } + + </select> + +% } elsif ( $type eq 'editlist' ) { % -% my %saw = (); -% foreach my $value ( keys %hash ) { -% local($^W)=0; next if $saw{$value}++; -% my $label = $hash{$value}; -% + <script> + function doremove<% "$key$n" %>() { + fromObject = document.OneTrueForm.<% "$key$n" %>; + for (var i=fromObject.options.length-1;i>-1;i--) { + if (fromObject.options[i].selected) + deleteOption<% "$key$n" %>(fromObject,i); + } + } + function deleteOption<% "$key$n" %>(object,index) { + object.options[index] = null; + } + function selectall<% "$key$n" %>() { + fromObject = document.OneTrueForm.<% "$key$n" %>; + for (var i=fromObject.options.length-1;i>-1;i--) { + fromObject.options[i].selected = true; + } + } + function doadd<% "$key$n" %>(object) { + var myvalue = ""; +% if ( defined($config_item->editlist_parts) ) { +% foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) { - <option value="<% $value %>"<% $value eq $conf->config($i->key) || ( $type eq 'selectmultiple' && grep { $_ eq $value } $conf->config($i->key) ) ? ' SELECTED' : '' %>><% $label %> -% } -% my $curvalue = $conf->config($i->key); -% if ( $conf->exists($i->key) && $curvalue -% && ! $hash{$curvalue} -% ) { -% - - - <option value="<% $conf->config($i->key) %>" SELECTED><% exists( $hash{ $conf->config($i->key) } ) ? $hash{ $conf->config($i->key) } : $conf->config($i->key) %> -% } + if ( myvalue != "" ) { myvalue = myvalue + " "; } +% if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) { - </select> -% } elsif ( $type eq 'select-sub' ) { + myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value + <!-- #RESET SELECT?? maybe not... --> +% } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) { - <select name="<% $i->key. $n %>"> - <option value=""> -% my %options = &{$i->options_sub}; -% my @options = sort { $a <=> $b } keys %options; -% my %saw; -% foreach my $value ( @options ) { -% local($^W)=0; next if $saw{$value}++; -% + myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value - <option value="<% $value %>"<% $value eq $conf->config($i->key) ? ' SELECTED' : '' %>><% $value %>: <% $options{$value} %> -% } -% if ( $conf->exists($i->key) && $conf->config($i->key) && ! exists $options{$conf->config($i->key)} ) { +% } else { - <option value=<% $conf->config($i->key) %> SELECTED><% $conf->config($i->key) %>: <% &{ $i->option_sub }( $conf->config($i->key) ) %> -% } + myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value + object.add<% "$key${n}_$pnum" %>.value = "" - </select> -% } elsif ( $type eq 'editlist' ) { - - - <script> - function doremove<% $i->key. $n %>() { - fromObject = document.OneTrueForm.<% $i->key. $n %>; - for (var i=fromObject.options.length-1;i>-1;i--) { - if (fromObject.options[i].selected) - deleteOption<% $i->key. $n %>(fromObject,i); - } - } - function deleteOption<% $i->key. $n %>(object,index) { - object.options[index] = null; - } - function selectall<% $i->key. $n %>() { - fromObject = document.OneTrueForm.<% $i->key. $n %>; - for (var i=fromObject.options.length-1;i>-1;i--) { - fromObject.options[i].selected = true; - } - } - function doadd<% $i->key. $n %>(object) { - var myvalue = ""; -% if ( defined($i->editlist_parts) ) { -% foreach my $pnum ( 0 .. scalar(@{$i->editlist_parts})-1 ) { - - - if ( myvalue != "" ) { myvalue = myvalue + " "; } -% if ( $i->editlist_parts->[$pnum]{type} eq 'select' ) { - - myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.options[object.add<% $i->key. $n . "_$pnum" %>.selectedIndex].value; - <!-- #RESET SELECT?? maybe not... --> -% } elsif ( $i->editlist_parts->[$pnum]{type} eq 'immutable' ) { - - myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.value; -% } else { - - myvalue = myvalue + object.add<% $i->key. $n . "_$pnum" %>.value; - object.add<% $i->key. $n. "_$pnum" %>.value = ""; -% } -% } -% } else { +% } +% } +% } else { - myvalue = object.add<% $i->key. $n. "_1" %>.value; -% } + myvalue = object.add<% "$key${n}_1" %>.value - var optionName = new Option(myvalue, myvalue); - var length = object.<% $i->key. $n %>.length; - object.<% $i->key. $n %>.options[length] = optionName; - } - </script> - <select multiple size=5 name="<% $i->key. $n %>"> - <option selected>----------------------------------------------------------------</option> -% foreach my $line ( $conf->config($i->key) ) { +% } - <option value="<% $line %>"><% $line %></option> -% } + var optionName = new Option(myvalue, myvalue); + var length = object.<% "$key$n" %>.length; + object.<% "$key$n" %>.options[length] = optionName; + } + </script> + <select multiple size=5 name="<% "$key$n" %>"> + <option selected>----------------------------------------------------------------</option> - </select><br> - <input type="button" value="remove selected" onClick="doremove<% $i->key. $n %>()"> - <script>SafeAddOnLoad(doremove<% $i->key. $n %>); - SafeAddOnSubmit(selectall<% $i->key. $n %>);</script> - <br> - <% itable() %><tr> -% if ( defined $i->editlist_parts ) { -% my $pnum=0; foreach my $part ( @{$i->editlist_parts} ) { +% foreach my $line ( $conf->config($key, $agentnum) ) { - <td> -% if ( $part->{type} eq 'text' ) { + <option value="<% $line %>"><% $line %></option> - <input type="text" name="add<% $i->key. $n."_$pnum" %>"> -% } elsif ( $part->{type} eq 'immutable' ) { +% } - <% $part->{value} %><input type="hidden" name="add<% $i->key. $n. "_$pnum" %>" value="<% $part->{value} %>"> -% } elsif ( $part->{type} eq 'select' ) { + </select><br> + <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()"> + <script>SafeAddOnLoad(doremove<% "$key$n" %>); + SafeAddOnSubmit(selectall<% "$key$n" %>); + </script> + <br><% itable() %><tr> - <select name="add<% $i->key. $n. "_$pnum" %>"> -% foreach my $key ( keys %{$part->{select_enum}} ) { +% if ( defined $config_item->editlist_parts ) { +% my $pnum=0; +% foreach my $part ( @{$config_item->editlist_parts} ) { - <option value="<% $key %>"><% $part->{select_enum}{$key} %></option> -% } + <td> - </select> -% } else { +% if ( $part->{type} eq 'text' ) { - <font color="#ff0000">unknown type <% $part->type %></font> -% } + <input type="text" name="add<% "$key${n}_$pnum" %>"> - </td> -% $pnum++; } -% } else { +% } elsif ( $part->{type} eq 'immutable' ) { - <td><input type="text" name="add<% $i->key. $n %>_0"></td> -% } + <% $part->{value} %> + <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>"> - <td><input type="button" value="add" onClick="doadd<% $i->key. $n %>(this.form)"></td> - </tr></table> -% } else { +% } elsif ( $part->{type} eq 'select' ) { + <select name="add<% qq!$key${n}_$pnum! %>"> - <font color="#ff0000">unknown type <% $type %></font> -% } -% $n++; } +% foreach my $key ( keys %{$part->{select_enum}} ) { - </td> - <td><a name="<% $i->key %>"> - <b><% $i->key %></b> - <% $i->description %> - </a></td> - </tr> -% } + <option value="<% $key %>"><% $part->{select_enum}{$key} %></option> - </table><br> +% } - You may need to restart Apache and/or freeside-queued for configuration - changes to take effect.<br> + </select> - <input type="submit" value="Apply changes"><br><br> -% } +% } else { + + <font color="#ff0000">unknown type <% $part->type %> </font> + +% } + + </td> + +% $pnum++; +% } +% } else { + <td><input type="text" name="add<% "$key${n}_0" %>></td> -</form> +% } + + <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td> + </tr></table> + +% } else { + + <font color="#ff0000">unknown type $type</font> + +% } +% $n++; +% } + + </td><td><% $description %></td></tr></table> +<INPUT TYPE="submit" VALUE="<% $title %>"> +</FORM> + +</BODY> +</HTML> +<%once> +my $conf = new FS::Conf; +my %confitems = map { $_->key => $_ } $conf->config_items; +</%once> -</body></html> <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my($agentnum, $agent, $title, $action, $key, $value, $config_item, + $description, $type); + +$action = 'Set'; + +if ($cgi->param('agentnum') =~ /(\d+)$/) { + $agentnum=$1; +} + +if ($agentnum) { + $agent = qsearchs('agent', { 'agentnum' => $1 } ); + die "Agent $agentnum not found!" unless $agent; + + $title = "$action configuration override for ". $agent->agent; +} else { + $title = "$action global configuration"; +} + +$cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item"; +$key=$1; +$value = $conf->config($key); +$config_item = $confitems{$key}; + +$description = $config_item->description; +$type = $config_item->type; + </%init> |