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}
187 #handle these with post_config_element
188 next if $type eq 'custom';
190 if ( $type eq 'title' ) {
191 $html .= qq!<TR><TH COLSPAN=1 ALIGN="right"><FONT SIZE="+1">! .
197 # 'freeform': disables table formatting of options. Instead, each
198 # option can define "before" and "after" strings which are inserted
199 # around the selector.
200 my $freeform = $optinfo->{freeform};
202 $html .= $optinfo->{before} || '';
205 $html .= qq!<TR><TD ALIGN="right">$label</TD><TD>!;
207 if ( $type eq 'select' ) {
209 # 'select' options can specify options one of two ways:
210 # the "preferred" way:
211 # options: arrayref of allowed option values
212 # option_labels: hashref of option value => label
213 # OR the weird and semi-deprecated way:
214 # option_values: coderef to return a list of allowed option values
215 # option_label: coderef to take an option value and return its label
217 my $size = defined($optinfo->{size}) ? " SIZE=" . $optinfo->{size} : '';
218 my $multi = ($optinfo->{multi} || $optinfo->{multiple})
220 $html .= qq!<SELECT NAME="$option"$multi$size>!;
221 my @values = split '\s+', $value if $multi;
223 if (defined($optinfo->{option_values})) {
224 my $valsub = $optinfo->{option_values};
225 @options = &$valsub();
226 } elsif (defined($optinfo->{options})) {
227 @options = @{$optinfo->{options}};
229 foreach my $select_option ( @options ) {
230 #if ( ref($select_option) ) {
232 my $selected = ($multi ? grep {$_ eq $select_option} @values : $select_option eq $value ) ? ' SELECTED' : '';
233 my $label = $select_option;
234 if ( defined $optinfo->{option_label} ) {
235 my $labelsub = $optinfo->{option_label};
236 $label = &$labelsub($select_option);
237 } elsif ( defined $optinfo->{option_labels} ) {
238 if (exists $optinfo->{option_labels}->{$select_option}) {
239 $label = $optinfo->{option_labels}->{$select_option};
243 $html .= qq!<OPTION VALUE="$select_option"$selected>!.
247 $html .= '</SELECT>';
248 } elsif ( $type eq 'textarea' ) {
249 $html .= qq!<TEXTAREA NAME="$option" COLS=80 ROWS=8 WRAP="virtual">!.
250 encode_entities($value). '</TEXTAREA>';
251 } elsif ( $type eq 'text' ) {
252 $html .= qq!<INPUT TYPE="text" NAME="$option" VALUE="!. #"
253 encode_entities($value). '" SIZE=64>';
254 } elsif ( $type eq 'checkbox' ) {
255 $html .= qq!<INPUT TYPE="checkbox" NAME="$option" VALUE="1"!;
256 $html .= ' CHECKED' if $value;
259 $html .= "unknown type $type";
262 $html .= $optinfo->{after} || '';
265 $html .= '</TD></TR>';
269 if ( $exports->{$layer}{nas} and qsearch('nas',{}) ) {
270 # show NAS checkboxes
271 $html .= '<TR><TD ALIGN="right">Export RADIUS clients</TD><TD>';
273 $html .= include('/elements/checkboxes-table.html',
274 'source_obj' => $part_export,
275 'link_table' => 'export_nas',
276 'target_table' => 'nas',
278 'name_callback' => sub {
279 $_[0]->shortname . ' (' . $_[0]->nasname . ')',
282 'target_link' => $p.'edit/nas.html?',
285 $html .= '</TD></TR>';
288 $html .= '<TR><TD ALIGN="right">Do not suspend services</TD>' .
289 '<TD><INPUT TYPE="checkbox" NAME="no_suspend" VALUE="Y"';
290 $html .= ' CHECKED' if $part_export->no_suspend eq 'Y';
291 $html .= '></TD></TR>';
295 # false laziness with config_element above
296 # create 'post_config_element' to generate the whole layer with a Mason component
297 if ( my $include = $exports->{$layer}{post_config_element} ) {
298 # might need to adjust the scope of this at some point
299 $html .= $m->scomp($include,
300 part_export => $part_export,
302 export_info => $exports->{$layer}
306 $html .= '<INPUT TYPE="hidden" NAME="options" VALUE="'.
307 join(',', keys %{$exports->{$layer}{options}} ). '">';
309 $html .= '<INPUT TYPE="hidden" NAME="nodomain" VALUE="'.
310 $exports->{$layer}{nodomain}. '">';
312 $html .= '<INPUT TYPE="submit" VALUE="'.
313 ( $part_export->exportnum ? "Apply changes" : "Add export" ).