diff options
Diffstat (limited to 'httemplate/config')
-rw-r--r-- | httemplate/config/config-delete.cgi | 33 | ||||
-rw-r--r-- | httemplate/config/config-download.cgi | 28 | ||||
-rw-r--r-- | httemplate/config/config-image.cgi | 22 | ||||
-rw-r--r-- | httemplate/config/config-process.cgi | 190 | ||||
-rw-r--r-- | httemplate/config/config-view.cgi | 367 | ||||
-rw-r--r-- | httemplate/config/config.cgi | 362 |
6 files changed, 1002 insertions, 0 deletions
diff --git a/httemplate/config/config-delete.cgi b/httemplate/config/config-delete.cgi new file mode 100644 index 000000000..488886824 --- /dev/null +++ b/httemplate/config/config-delete.cgi @@ -0,0 +1,33 @@ +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; +die "access denied\n" unless $curuser->access_right('Configuration'); + +my $fsconf = new FS::Conf; +if ( $fsconf->exists('disable_settings_changes') ) { + my @changers = split(/\s*,\s*/, $fsconf->config('disable_settings_changes')); + my %changers = map { $_=>1 } @changers; + unless ( $changers{$curuser->username} ) { + errorpage("Disabled in web demo"); + die "shouldn't be reached"; + } +} + +$cgi->param('confnum') =~ /^(\d+)$/ or die "illegal or missing confnum"; +my $confnum = $1; + +my $conf = qsearchs('conf', {'confnum' => $confnum}); +die "Configuration not found!" unless $conf; +$conf->delete; + +my $redirect = popurl(2); +if ( $cgi->param('redirect') eq 'config_view_showagent' ) { + $redirect .= 'config/config-view.cgi?showagent=1#'. $conf->name; +} elsif ( $cgi->param('redirect') eq 'config_view' ) { + $redirect .= 'config/config-view.cgi'; +} else { + $redirect .= 'browse/agent.cgi'; +} + +</%init> +<% $cgi->redirect($redirect) %> diff --git a/httemplate/config/config-download.cgi b/httemplate/config/config-download.cgi new file mode 100644 index 000000000..6979246db --- /dev/null +++ b/httemplate/config/config-download.cgi @@ -0,0 +1,28 @@ +% +% +%my $conf=new FS::Conf; +% +%http_header('Content-Type' => 'application/x-unknown' ); +% +%die "No configuration variable specified (bad URL)!" # umm +% unless $cgi->param('key'); +%$cgi->param('key') =~ /^([-\w.]+)$/; +%my $name = $1; +% +%my $agentnum; +%if ($cgi->param('agentnum') =~ /^(\d+)$/) { +% $agentnum = $1; +%} +% +%http_header('Content-Disposition' => "attachment; filename=$name" ); +% print $conf->config_binary($name, $agentnum); +<%init> +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $agentnum; +if ($cgi->param('agentnum') =~ /^(\d+)$/) { + $agentnum = $1; +} + +</%init> diff --git a/httemplate/config/config-image.cgi b/httemplate/config/config-image.cgi new file mode 100644 index 000000000..0de9d4278 --- /dev/null +++ b/httemplate/config/config-image.cgi @@ -0,0 +1,22 @@ +<% $logo %> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $conf = new FS::Conf; + +http_header( 'Content-Type' => 'image/png' ); #just png for now + +$cgi->param('key') =~ /^([-\w.]+)$/ or die "illegal config option"; +my $name = $1; + +my $agentnum = ''; +if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { + $agentnum = $1; +} + +my $logo = $conf->config_binary($name, $agentnum); +$logo = eps2png($logo) if $name =~ /\.eps$/i; + +</%init> diff --git a/httemplate/config/config-process.cgi b/httemplate/config/config-process.cgi new file mode 100644 index 000000000..4e1c85a03 --- /dev/null +++ b/httemplate/config/config-process.cgi @@ -0,0 +1,190 @@ +%if ( scalar(@error) ) { +% +% my $url = popurl(1)."config.cgi"; +% if ( length($cgi->query_string) > 1920 ) { #stupid IE 2083 URL limit +% +% my $session = int(rand(4294967296)); #XXX +% my $pref = new FS::access_user_pref({ +% 'usernum' => $FS::CurrentUser::CurrentUser->usernum, +% 'prefname' => "redirect$session", +% 'prefvalue' => $cgi->query_string, +% 'expiration' => time + 3600, #1h? 1m? +% }); +% my $pref_error = $pref->insert; +% if ( $pref_error ) { +% die "FATAL: couldn't even set redirect cookie: $pref_error". +% " attempting to set redirect$session to ". $cgi->query_string."\n"; +% } +% +<% $cgi->redirect("$url?redirect=$session") %> +% +% } else { +% +<% $cgi->redirect("$url?". $cgi->query_string ) %> +% +% } +% +%} else { +<% header('Configuration set') %> + <SCRIPT TYPE="text/javascript"> +% my $n = 0; +% foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) { + var configCell = window.top.document.getElementById('<% $agentnum. $i->key. $n %>'); + if ( ! configCell ) { + window.top.location.reload(); + } + //alert('found cell ' + configCell); +% if ( $type eq 'textarea' +% || $type eq 'editlist' +% || $type eq 'selectmultiple' ) { + configCell.innerHTML = + '<font size="-2"><pre>' + "\n" + + <% encode_entities(join("\n", + map { length($_) > 88 ? substr($_,0,88).'...' : $_ } + $conf->config($i->key, $agentnum) + ) ) + |js_string %> + + '</pre></font>'; + +% } elsif ( $type eq 'checkbox' ) { +% if ( $conf->exists($i->key, $agentnum) ) { + configCell.style.backgroundColor = '#00ff00'; + configCell.innerHTML = 'YES'; +% } else { + configCell.style.backgroundColor = '#ff0000'; + configCell.innerHTML = 'NO'; +% } +% } elsif ( $type eq 'select' && $i->select_hash ) { +% my %hash; +% if ( ref($i->select_hash) eq 'ARRAY' ) { +% tie %hash, 'Tie::IxHash', '' => '', @{ $i->select_hash }; +% } else { +% tie %hash, 'Tie::IxHash', '' => '', %{ $i->select_hash }; +% } + configCell.innerHTML = <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' |js_string %>; + +% } elsif ( $type eq 'text' || $type eq 'select' ) { + configCell.innerHTML = <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' |js_string %>; +% } elsif ( $type =~ /^select-(part_svc|part_pkg|pkg_class)$/ && ! $i->multiple ) { +% my $table = $1; +% my $namecol = $namecol{$table}; +% my $pkey = dbdef->table($table)->primary_key; +% my $key = $conf->config($i->key, $agentnum); +% my $record = qsearchs($table, { $pkey => $key }); +% my $value = $record ? "$key: ".$record->$namecol() : $key; + configCell.innerHTML = <% $value |js_string %>; +% } elsif ( $type eq 'select-sub' && ! $i->multiple ) { + configCell.innerHTML = + <% $conf->config($i->key, $agentnum) |js_string %> + ': ' + + <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) |js_string %>; +% } else { + //alert('unknown type <% $type %>'); + window.top.location.reload(); +% } + +% $n++; +% } + parent.cClick(); + </SCRIPT> +</BODY> +</HTML> +%} +<%once> +#false laziness w/config-view.cgi +my %namecol = ( + 'part_svc' => 'svc', + 'part_pkg' => 'pkg', + 'pkg_class' => 'classname', +); +</%once> +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; +die "access denied\n" unless $curuser->access_right('Configuration'); + +my $conf = new FS::Conf; + +if ( $conf->exists('disable_settings_changes') ) { + my @changers = split(/\s*,\s*/, $conf->config('disable_settings_changes')); + my %changers = map { $_=>1 } @changers; + unless ( $changers{$curuser->username} ) { + errorpage_popup("Disabled in web demo"); + die "shouldn't be reached"; + } +} + +$FS::Conf::DEBUG = 1; +my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ } + $conf->config_items; +my %confitems = map { $_->key => $_ } $conf->config_items; + +my $agentnum = $cgi->param('agentnum'); +my $key = $cgi->param('key'); +my $i = $confitems{$key}; + +my @error = (); +my @touch = (); +my @delete = (); +my $n = 0; +foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) { + if ( $type eq '' ) { + } elsif ( $type eq 'textarea' ) { + if ( $cgi->param($i->key.$n) ne '' ) { + my $value = $cgi->param($i->key.$n); + $value =~ s/\r\n/\n/g; #browsers? + my $error = &{$i->validate}($value, $n) if $i->validate; + push @error, $error if $error; + $conf->set($i->key, $value, $agentnum); + } else { + $conf->delete($i->key, $agentnum); + } + } elsif ( $type eq 'binary' || $type eq 'image' ) { + if ( defined($cgi->param($i->key.$n)) && $cgi->param($i->key.$n) ) { + my $fh = $cgi->upload($i->key.$n); + my $error = &{$i->validate}($fh, $n) if $i->validate; + push @error, $error if $error; + if (defined($fh)) { + local $/; + $conf->set_binary($i->key, <$fh>, $agentnum); + } + }else{ + warn "Condition failed for " . $i->key; + } + } elsif ( $type eq 'checkbox' ) { + if ( defined $cgi->param($i->key.$n) ) { + push @touch, $i->key; + } else { + push @delete, $i->key; + } + } elsif ( + $type =~ /^(editlist|selectmultiple)$/ + or ( $type =~ /^select(-(sub|part_svc|part_pkg|pkg_class))?$/ + || $i->multiple ) + ) { + if ( scalar(@{[ $cgi->param($i->key.$n) ]}) ) { + my $error = &{$i->validate}([ $cgi->param($i->key.$n) ], $n) if $i->validate; + push @error, $error if $error; + $conf->set($i->key, join("\n", @{[ $cgi->param($i->key.$n) ]} ), $agentnum); + } else { + $conf->delete($i->key, $agentnum); + } + } elsif ( $type =~ /^(text|select(-(sub|part_svc|part_pkg|pkg_class))?)$/ ) { + if ( $cgi->param($i->key.$n) ne '' ) { + my $error = &{$i->validate}($cgi->param($i->key.$n), $n) if $i->validate; + push @error, $error if $error; + $conf->set($i->key, $cgi->param($i->key.$n), $agentnum); + } else { + $conf->delete($i->key, $agentnum); + } + } + $n++; +} +# warn @touch; +$conf->touch($_, $agentnum) foreach @touch; +$conf->delete($_, $agentnum) foreach @delete; + +if (scalar(@error)) { + $cgi->param('error', join(' ', @error)); +} + +</%init> diff --git a/httemplate/config/config-view.cgi b/httemplate/config/config-view.cgi new file mode 100644 index 000000000..11e75707c --- /dev/null +++ b/httemplate/config/config-view.cgi @@ -0,0 +1,367 @@ +<% include("/elements/header.html", $title, menubar(@menubar)) %> + +Click on a configuration value to change it. +<BR><BR> + +% unless ( $page_agent ) { +% +% if ( $cgi->param('showagent') ) { +% $cgi->param('showagent', 0); + ( <a href="<% $cgi->self_url %>">hide agent overrides</a> ) +% $cgi->param('showagent', 1); +% } else { +% $cgi->param('showagent', 1); + ( <a href="<% $cgi->self_url %>">show agent overrides</a> ) +% $cgi->param('showagent', 0); +% } +% +% } +<BR><BR> + +<% include('/elements/init_overlib.html') %> + +% if ($FS::UID::use_confcompat) { + <FONT SIZE="+1" COLOR="#ff0000">CONFIGURATION NOT STORED IN DATABASE -- USING COMPATIBILITY MODE</FONT><BR><BR> +%} + +% foreach my $section (@sections) { + + <A NAME="<% $section || 'unclassified' %>"></A> + <FONT SIZE="-2"> + +% foreach my $nav_section (@sections) { +% +% if ( $section eq $nav_section ) { + [<A NAME="not<% $nav_section || 'unclassified' %>" style="background-color: #cccccc"><% ucfirst($nav_section || 'unclassified') %></A>] +% } else { + [<A HREF="#<% $nav_section || 'unclassified' %>"><% ucfirst($nav_section || 'unclassified') %></A>] +% } +% +% } + + </FONT><BR> + <TABLE BGCOLOR="#cccccc" BORDER=1 CELLSPACING=0 CELLPADDING=0 BORDERCOLOR="#999999"> + <tr> + <th colspan="2" bgcolor="#dcdcdc"> + <% ucfirst($section || 'unclassified') %> +% if ( $curuser->option('show_confitem_counts') ) { + (<% scalar( @{ $section_items{$section} } ) %> items) +% } + </th> + </tr> +% foreach my $i (@{ $section_items{$section} }) { +% my @types = ref($i->type) ? @{$i->type} : ($i->type); +%# my( $width, $height ) = ( 522, 336 ); +% my( $width, $height ) = ( 600, 336 ); +% if ( grep $_ eq 'textarea', @types ) { +% #800x600 +% $width = 763; +% $height = 408; +% #1024x768 +% #$width = +% #$height = +% } +% +% my @agents = (); +% my @add_agents = (); +% if ( $page_agent ) { +% @agents = ( $page_agent ); +% } else { +% @agents = ( '' ); +% if ( $i->per_agent ) { +% foreach my $agent (@all_agents) { +% if ( defined($conf->conf( $i->key, $agent->agentnum, 1 ) ) ) { +% push @agents, $agent; +% } else { +% push @add_agents, $agent; +% } +% } +% } +% } +% +% foreach my $agent ( @agents ) { +% my $agentnum = $agent ? $agent->agentnum : ''; +% +% next if $section eq 'deprecated' && ! $conf->exists($i->key, $agentnum); +% +% my $label = $i->key; +% $label = '['. $agent->agent. "] $label" +% if $agent && $cgi->param('showagent'); +% +% #indentation :/ + + <tr> + <td><% include('/elements/popup_link.html', + 'action' => 'config.cgi?key='. $i->key. + ';agentnum='. $agentnum, + 'width' => $width, + 'height' => $height, + 'actionlabel' => 'Enter configuration value', + 'label' => "<b>$label</b>", + 'aname' => $i->key, #agentnum + # if $cgi->param('showagent')? + ) + %>: <% $i->description %> +% if ( $agent && $cgi->param('showagent') ) { +% my $confnum = $conf->conf( $i->key, $agent->agentnum, 1 )->confnum; + (<A HREF="javascript:areyousure('delete this agent override', 'config-delete.cgi?confnum=<% $confnum %>;redirect=config_view_showagent')">delete agent override</A>) +% } elsif ( $i->base_key +% || ( $deleteable{$i->key} && $conf->exists($i->key) ) ) { +% my $confnum = +% $agent +% ? $conf->conf( $i->key, $agent->agentnum, 1 )->confnum +% : $conf->conf( $i->key )->confnum; +% my $showagent = $cgi->param('showagent') ? '_showagent' : ''; + (<A HREF="javascript:areyousure('delete this configuration item', 'config-delete.cgi?confnum=<% $confnum %>;redirect=config_view<%$showagent%>')">delete configuration item</A>) +% } + + </td> + <td><table border=0> + +% my $n = 0; +% foreach my $type (@types) { + +% if ( $type eq '' ) { + + <tr> + <td><font color="#ff0000">no type</font></td> + </tr> + +% } elsif ( $type eq 'image' ) { + + <tr> + <td bgcolor='#ffffff'> + <% $conf->exists($i->key, $agentnum) + ? '<img src="config-image.cgi?key='. $i->key. + ';agentnum='. $agentnum. '">' + : 'empty' + %> + </td> + </tr> + <tr> + <td> + <% $conf->exists($i->key, $agentnum) + ? qq!<a href="config-download.cgi?key=!. $i->key. ';agentnum='. $agentnum. qq!">download</a>! + : '' + %> + </td> + </tr> + +% } elsif ( $type eq 'binary' ) { + + <tr> + <td> + <% $conf->exists($i->key, $agentnum) + ? qq!<a href="config-download.cgi?key=!. $i->key. ';agentnum='. $agentnum. qq!">download</a>! + : 'empty' + %> + </td> + </tr> + +% } elsif ( $type eq 'textarea' +% || $type eq 'editlist' +% || $type eq 'selectmultiple' +% ) +% { + + <tr> + <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff"> +<font size="-2"><pre><% encode_entities(join("\n", + map { length($_) > 88 ? substr($_,0,88).'...' : $_ } + $conf->config($i->key, $agentnum) + ) ) +%></pre></font> + </td> + </tr> + +% } elsif ( $type eq 'checkbox' ) { + + <tr> + <td id="<% $agentnum.$i->key.$n %>" bgcolor="#<% $conf->exists($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td> + </tr> + +% } elsif ( $type eq 'select' && $i->select_hash ) { +% +% my %hash; +% if ( ref($i->select_hash) eq 'ARRAY' ) { +% tie %hash, 'Tie::IxHash', '' => '', @{ $i->select_hash }; +% } else { +% tie %hash, 'Tie::IxHash', '' => '', %{ $i->select_hash }; +% } + + <tr> + <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff"> + <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' %> + </td> + </tr> + +% } elsif ( $type eq 'text' || $type eq 'select' ) { + + <tr> + <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff"> + <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %> + </td> + </tr> + +% } elsif ( $type eq 'select-sub' ) { + + <tr> + <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff"> + <% $conf->config($i->key, $agentnum) %>: + <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %> + </td> + </tr> + +% } elsif ( $type =~ /^select-(part_svc|part_pkg|pkg_class)$/ ) { +% +% my $table = $1; +% my $namecol = $namecol{$table}; +% my $pkey = dbdef->table($table)->primary_key; +% +% my @keys = $conf->config($i->key, $agentnum); + + <tr> + <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff"> + <% join( '<BR>', + map { + my $key = $_; + my $record = qsearchs($table, { $pkey => $key }); + $record ? "$key: ".$record->$namecol() : $key; + } @keys + ) + %> + </td> + </tr> + +% } else { + + <tr><td> + <font color="#ff0000">unknown type <% $type %></font> + </td></tr> +% } +% $n++; +% } + + </table></td> + </tr> + +% } # foreach my $agentnum + +% if ( @add_agents ) { + + <tr> + <td> + <FORM> + Add <b><% $i->key %></b> override for + <% include('/elements/select-agent.html', + 'agents' => \@add_agents, + 'empty_label' => 'Select agent', + 'onchange' => "agent_changed", + 'id' => 'agent_'. $i->key, + ) + %> + agent + +% my $agent_el = "document.getElementById('agent_". $i->key. "')"; + <INPUT TYPE = "button" + VALUE = "Add" + ID = "add_<% $i->key %>" + DISABLED + onClick = "<% + include('/elements/popup_link_onclick.html', + 'action' => + 'config.cgi?key='. $i->key. + ";agentnum=' + ". + "$agent_el.options[$agent_el.selectedIndex].value". + " + '", + 'width' => $width, + 'height' => $height, + 'actionlabel' => 'Enter configuration value', + ) + %>" + > + </FORM> + </td> + </tr> + +% } #if @add_agents + +% } # foreach my $i + + </table><br><br> + +% } # foreach my $nav_section + +<SCRIPT TYPE="text/javascript"> + + function agent_changed(what) { + var key = what.id.substring(6); // trim agent_ + var button = document.getElementById('add_'+key); + if ( what.selectedIndex > 0 ) { + button.disabled = false; + } else { + button.disabled = true; + } + } + + function areyousure(what, href) { + if ( confirm("Are you sure you want to " + what + "?") == true ) + window.location.href = href; + } + +</SCRIPT> + +</body></html> +<%once> +#false laziness w/config-process.cgi +my %namecol = ( + 'part_svc' => 'svc', + 'part_pkg' => 'pkg', + 'pkg_class' => 'classname', +); +</%once> +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" unless $curuser->access_right('Configuration'); + +my $page_agent = ''; +my $title; +my @menubar = (); +if ($cgi->param('agentnum') =~ /^(\d+)$/) { + my $page_agentnum = $1; + $page_agent = qsearchs('agent', { 'agentnum' => $page_agentnum } ); + die "Agent $page_agentnum not found!" unless $page_agent; + + push @menubar, 'View all agents' => $p.'browse/agent.cgi'; + $title = 'Agent Configuration for '. $page_agent->agent; +} else { + $title = 'Global Configuration'; +} + +my $conf = new FS::Conf; + +my @config_items = grep { $page_agent ? $_->per_agent : 1 } + grep { $page_agent ? 1 : !$_->agentonly } + $conf->config_items; + +my @deleteable = qw( invoice_latexreturnaddress invoice_htmlreturnaddress ); +my %deleteable = map { $_ => 1 } @deleteable; + +my @sections = qw(required billing invoicing notification UI self-service username password session shell BIND ); +push @sections, '', 'deprecated'; + +my %section_items = (); +foreach my $section (@sections) { + $section_items{$section} = [ grep $_->section eq $section, @config_items ]; +} + +@sections = grep scalar( @{ $section_items{$_} } ), @sections; + +my @all_agents = (); +if ( $cgi->param('showagent') ) { + @all_agents = qsearch('agent', { 'disabled' => '' } ); +} + +</%init> diff --git a/httemplate/config/config.cgi b/httemplate/config/config.cgi new file mode 100644 index 000000000..cde48382a --- /dev/null +++ b/httemplate/config/config.cgi @@ -0,0 +1,362 @@ +<% include("/elements/header-popup.html", $title) %> + +<SCRIPT> +var gSafeOnload = new Array(); +var gSafeOnsubmit = new Array(); +window.onload = SafeOnload; +function SafeAddOnLoad(f) { + gSafeOnload[gSafeOnload.length] = f; +} +function SafeOnload() { + for (var i=0;i<gSafeOnload.length;i++) + gSafeOnload[i](); +} +function SafeAddOnSubmit(f) { + gSafeOnsubmit[gSafeOnsubmit.length] = f; +} +function SafeOnsubmit() { + for (var i=0;i<gSafeOnsubmit.length;i++) + gSafeOnsubmit[i](); +} +</SCRIPT> + +<% include('/elements/error.html') %> + +<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 %>"> + +Setting <b><% $key %></b> + +% my $description_printed = 0; +% if ( grep $_ eq 'textarea', @types ) { +% $description_printed = 1; + + - <% $description %> + +% } + +<table><tr><td> + +% my $n = 0; +% foreach my $type (@types) { +% if ( $type eq '' ) { + + <font color="#ff0000">no type</font> + +% } elsif ( $type eq 'image' ) { + + <% $conf->exists($key, $agentnum) + ? 'Current image<br>'. + '<img src="config-image.cgi?key='. $key. + ';agentnum='. $agentnum. '"><br>' + : '' + %> + + <BR> + New image filename <input type="file" name="<% "$key$n" %>"> + +% } elsif ( $type eq 'binary' ) { + + Filename <input type="file" name="<% "$key$n" %>"> + +% } elsif ( $type eq 'textarea' ) { + + <textarea name="<% "$key$n" %>" rows=12 cols=78 wrap="off"><% join("\n", $conf->config($key, $agentnum)) |h %></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) : '' |h %>"> + +% } 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}; +% + + <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} ) { + + <option value="<% $curvalue %>" SELECTED> + +% if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) { + + <% $hash{ $conf->config($key, $agentnum) } %> + +% }else{ + + <% $curvalue %> + +% } +% } + + </select> + +% } elsif ( $type eq 'select-sub' ) { + + <select name="<% "$key$n" %>" <% $config_item->multiple ? 'MULTIPLE' : '' %>> + +% unless ( $config_item->multiple ) { + <option value=""> +% } + +% 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 %>" + +% if ( $value eq $conf->config($key, $agentnum) +% || ( $config_item->multiple +% && grep { $_ eq $value } $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' ) { +% + <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 ) { + + if ( myvalue != "" ) { myvalue = myvalue + " "; } + +% if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) { + + 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' ) { + + myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value + +% } else { + + myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value + object.add<% "$key${n}_$pnum" %>.value = "" + +% } +% } +% } else { + + myvalue = object.add<% "$key${n}_1" %>.value + +% } + + 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> + +% foreach my $line ( $conf->config($key, $agentnum) ) { + + <option value="<% $line %>"><% $line %></option> + +% } + + </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> + +% if ( defined $config_item->editlist_parts ) { +% my $pnum=0; +% foreach my $part ( @{$config_item->editlist_parts} ) { + + <td> + +% if ( $part->{type} eq 'text' ) { + + <input type="text" name="add<% "$key${n}_$pnum" %>"> + +% } elsif ( $part->{type} eq 'immutable' ) { + + <% $part->{value} %> + <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>"> + +% } elsif ( $part->{type} eq 'select' ) { + + <select name="add<% qq!$key${n}_$pnum! %>"> + +% foreach my $key ( keys %{$part->{select_enum}} ) { + + <option value="<% $key %>"><% $part->{select_enum}{$key} %></option> + +% } + + </select> + +% } else { + + <font color="#ff0000">unknown type <% $part->type %> </font> + +% } + + </td> + +% $pnum++; +% } +% } else { + + <td><input type="text" name="add<% "$key${n}_0" %>></td> + +% } + + <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td> + </tr></table> + +% } elsif ( $element_types{$type} ) { +% +% my %opt = ( 'element_name' => "$key$n", +% 'empty_label' => ' ', +% 'showdisabled' => 1, +% ); +% if ( $config_item->multiple ) { +% $opt{'multiple'} = 1 if $config_item->multiple; +% $opt{'curr_value'} = [ $conf->config($key, $agentnum) ]; +% } else { +% $opt{'curr_value'} = +% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : ''; +% } + + <% include("/elements/$type.html", %opt ) %> + +% } else { + + <font color="#ff0000">unknown type <% $type %></font> + +% } +% $n++; +% } + + </td> +% unless ( $description_printed ) { + <td><% $description %></td> +% } +</tr> +</table> +<INPUT TYPE="submit" VALUE="<% $title %>"> +</FORM> + +</BODY> +</HTML> +<%once> + +my $conf = new FS::Conf; +my @config_items = $conf->config_items; +my %confitems = map { $_->key => $_ } @config_items; + +my %element_types = map { $_ => 1 } qw( + select-part_svc select-part_pkg select-pkg_class +); + +</%once> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $action = 'Set'; + +my $agentnum = ''; +if ($cgi->param('agentnum') =~ /(\d+)$/) { + $agentnum=$1; +} + +my $agent = ''; +my $title; +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"; +my $key = $1; +my $value = $conf->config($key); +my $config_item = $confitems{$key}; + +my $description = $config_item->description; +my $config_type = $config_item->type; +my @types = ref($config_type) ? @$config_type : ($config_type); + +</%init> |