1 <% include('/elements/header.html', "$action Export", '', ' onLoad="visualize()"') %>
3 <% include('/elements/error.html') %>
5 <SCRIPT TYPE="text/javascript">
6 function svc_machine_changed (what, layer) {
8 var machine = document.getElementById(layer + "_machine");
9 var part_export_machine =
10 document.getElementById(layer + "_part_export_machine");
11 if ( what.value == 'Y' ) {
12 machine.disabled = true;
13 part_export_machine.disabled = false;
14 } else if ( what.value == 'N' ) {
15 machine.disabled = false;
16 part_export_machine.disabled = true;
21 function part_export_machine_changed (what, layer) {
22 var select_default = document.getElementById(layer + '_default_machine');
23 var selected = select_default.value;
24 select_default.options.length = 0;
25 var choices = what.value.split("\n");
26 for (var i = 0; i < choices.length; i++) {
27 select_default.options[i] = new Option(choices[i]);
29 select_default.value = selected;
34 <INPUT TYPE="hidden" NAME="exportnum" VALUE="<% $part_export->exportnum %>">
36 <% ntable("#cccccc",2) %>
38 <TD ALIGN="right">Export name</TD>
40 <INPUT TYPE="text" NAME="exportname" VALUE="<% $part_export->exportname %>">
44 <TD ALIGN="right">Export</TD>
45 <TD><% $widget->html %>
47 <% include('/elements/footer.html') %>
51 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
53 #if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
54 # $cgi->param('clone', $1);
56 # $cgi->param('clone', '');
59 my($query) = $cgi->keywords;
62 if ( $cgi->param('error') ) {
63 $part_export = new FS::part_export ( {
64 map { $_, scalar($cgi->param($_)) } fields('part_export')
66 } elsif ( $query =~ /^(\d+)$/ ) {
67 $part_export = qsearchs('part_export', { 'exportnum' => $1 } );
69 $part_export = new FS::part_export;
71 $action ||= $part_export->exportnum ? 'Edit' : 'Add';
73 #my $exports = FS::part_export::export_info($svcdb);
74 my $exports = FS::part_export::export_info();
76 tie my %layers, 'Tie::IxHash',
78 map { $_ => "$_ - ". $exports->{$_}{desc} }
83 my $widget = new HTML::Widgets::SelectLayers(
84 'selected_layer' => $part_export->exporttype,
85 'options' => \%layers,
86 'form_name' => 'dummy',
87 'form_action' => 'process/part_export.cgi',
88 'form_text' => [qw( exportnum exportname )],
89 'html_between' => "</TD></TR></TABLE>\n",
90 'layer_callback' => sub {
92 # create 'config_element' to generate the whole layer with a Mason component
93 if ( my $include = $exports->{$layer}{config_element} ) {
94 # might need to adjust the scope of this at some point
95 return $m->scomp($include,
96 part_export => $part_export,
98 export_info => $exports->{$layer}
101 my $html = qq!<INPUT TYPE="hidden" NAME="exporttype" VALUE="$layer">!.
105 $html .= '<TR><TD ALIGN="right">Description</TD><TD BGCOLOR=#ffffff>'.
106 $exports->{$layer}{notes}. '</TD></TR>';
108 if ( $exports->{$layer}{no_machine} ) {
109 $html .= '<INPUT TYPE="hidden" NAME="machine" VALUE="">'.
110 '<INPUT TYPE="hidden" NAME="svc_machine" VALUE=N">';
112 $html .= '<TR><TD ALIGN="right">Hostname or IP</TD><TD>';
113 my $machine = $part_export->machine;
114 if ( $exports->{$layer}{svc_machine} ) {
115 my( $N_CHK, $Y_CHK) = ( 'CHECKED', '' );
116 my( $machine_DISABLED, $pem_DISABLED) = ( '', 'DISABLED' );
117 my @part_export_machine;
118 my $default_machine = '';
119 if ( $cgi->param('svc_machine') eq 'Y'
120 || $machine eq '_SVC_MACHINE'
125 $machine_DISABLED = 'DISABLED';
128 @part_export_machine = $cgi->param('part_export_machine');
129 if (!@part_export_machine) {
130 @part_export_machine =
133 $part_export->part_export_machine;
136 $cgi->param('default_machine_name')
137 || $part_export->default_export_machine;
139 my $oc = qq(onChange="svc_machine_changed(this, '$layer')");
141 <INPUT TYPE="radio" NAME="svc_machine" VALUE="N" $N_CHK $oc>
142 <INPUT TYPE="text" NAME="machine" ID="${layer}_machine" VALUE="$machine" $machine_DISABLED>
144 <INPUT TYPE="radio" NAME="svc_machine" VALUE="Y" $Y_CHK $oc>
145 <DIV STYLE="display:inline-block; vertical-align: top; text-align: right">
146 Selected in each customer service from these choices:
147 <TEXTAREA STYLE="vertical-align: top" NAME="part_export_machine"
148 ID="${layer}_part_export_machine"
149 onchange="part_export_machine_changed(this, '$layer')"
152 join("\n", @part_export_machine) .
157 <SELECT NAME="default_machine_name" ID="${layer}_default_machine">
159 foreach (@part_export_machine) {
160 $_ = encode_entities($_); # oh noes, XSS
161 my $sel = ($default_machine eq $_) ? ' SELECTED' : '';
162 $html .= qq!<OPTION VALUE="$_"$sel>$_</OPTION>\n!;
164 $html .= '</DIV></SELECT>'
166 $html .= qq(<INPUT TYPE="text" NAME="machine" VALUE="$machine">).
167 '<INPUT TYPE="hidden" NAME="svc_machine" VALUE=N">';
169 $html .= "</TD></TR>";
174 foreach my $option ( keys %{$exports->{$layer}{options}} ) {
175 my $optinfo = $exports->{$layer}{options}{$option};
176 die "Retreived non-ref export info option from $layer export: $optinfo"
177 unless ref($optinfo);
178 my $label = $optinfo->{label};
179 my $type = defined($optinfo->{type}) ? $optinfo->{type} : 'text';
180 my $value = $cgi->param($option)
181 || ( $part_export->exportnum && $part_export->option($option) )
182 || ( (exists $optinfo->{default} && !$part_export->exportnum)
183 ? $optinfo->{default}
186 if ( $type eq 'title' ) {
187 $html .= qq!<TR><TH COLSPAN=1 ALIGN="right"><FONT SIZE="+1">! .
193 # 'freeform': disables table formatting of options. Instead, each
194 # option can define "before" and "after" strings which are inserted
195 # around the selector.
196 my $freeform = $optinfo->{freeform};
198 $html .= $optinfo->{before} || '';
201 $html .= qq!<TR><TD ALIGN="right">$label</TD><TD>!;
203 if ( $type eq 'select' ) {
204 my $size = defined($optinfo->{size}) ? " SIZE=" . $optinfo->{size} : '';
205 my $multi = ($optinfo->{multi} || $optinfo->{multiple})
207 $html .= qq!<SELECT NAME="$option"$multi$size>!;
208 my @values = split '\s+', $value if $multi;
210 if (defined($optinfo->{option_values})) {
211 my $valsub = $optinfo->{option_values};
212 @options = &$valsub();
213 } elsif (defined($optinfo->{options})) {
214 @options = @{$optinfo->{options}};
216 foreach my $select_option ( @options ) {
217 #if ( ref($select_option) ) {
219 my $selected = ($multi ? grep {$_ eq $select_option} @values : $select_option eq $value ) ? ' SELECTED' : '';
220 my $label = $select_option;
221 if (defined($optinfo->{option_label})) {
222 my $labelsub = $optinfo->{option_label};
223 $label = &$labelsub($select_option);
225 $html .= qq!<OPTION VALUE="$select_option"$selected>!.
229 $html .= '</SELECT>';
230 } elsif ( $type eq 'textarea' ) {
231 $html .= qq!<TEXTAREA NAME="$option" COLS=80 ROWS=8 WRAP="virtual">!.
232 encode_entities($value). '</TEXTAREA>';
233 } elsif ( $type eq 'text' ) {
234 $html .= qq!<INPUT TYPE="text" NAME="$option" VALUE="!. #"
235 encode_entities($value). '" SIZE=64>';
236 } elsif ( $type eq 'checkbox' ) {
237 $html .= qq!<INPUT TYPE="checkbox" NAME="$option" VALUE="1"!;
238 $html .= ' CHECKED' if $value;
241 $html .= "unknown type $type";
244 $html .= $optinfo->{after} || '';
247 $html .= '</TD></TR>';
251 if ( $exports->{$layer}{nas} and qsearch('nas',{}) ) {
252 # show NAS checkboxes
253 $html .= '<TR><TD ALIGN="right">Export RADIUS clients</TD><TD>';
255 $html .= include('/elements/checkboxes-table.html',
256 'source_obj' => $part_export,
257 'link_table' => 'export_nas',
258 'target_table' => 'nas',
260 'name_callback' => sub {
261 $_[0]->shortname . ' (' . $_[0]->nasname . ')',
264 'target_link' => $p.'edit/nas.html?',
267 $html .= '</TD></TR>';
272 $html .= '<INPUT TYPE="hidden" NAME="options" VALUE="'.
273 join(',', keys %{$exports->{$layer}{options}} ). '">';
275 $html .= '<INPUT TYPE="hidden" NAME="nodomain" VALUE="'.
276 $exports->{$layer}{nodomain}. '">';
278 $html .= '<INPUT TYPE="submit" VALUE="'.
279 ( $part_export->exportnum ? "Apply changes" : "Add export" ).