1 <% include('/elements/header.html', "$action Export", '', ' onLoad="visualize()"') %>
3 <% include('/elements/error.html') %>
6 <INPUT TYPE="hidden" NAME="exportnum" VALUE="<% $part_export->exportnum %>">
8 <% ntable("#cccccc",2) %>
10 <TD ALIGN="right">Export name</TD>
12 <INPUT TYPE="text" NAME="exportname" VALUE="<% $part_export->exportname %>">
16 <TD ALIGN="right">Export</TD>
17 <TD><% $widget->html %>
19 <% include('/elements/footer.html') %>
23 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
25 #if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
26 # $cgi->param('clone', $1);
28 # $cgi->param('clone', '');
31 my($query) = $cgi->keywords;
34 if ( $cgi->param('error') ) {
35 $part_export = new FS::part_export ( {
36 map { $_, scalar($cgi->param($_)) } fields('part_export')
38 } elsif ( $query =~ /^(\d+)$/ ) {
39 $part_export = qsearchs('part_export', { 'exportnum' => $1 } );
41 $part_export = new FS::part_export;
43 $action ||= $part_export->exportnum ? 'Edit' : 'Add';
45 #my $exports = FS::part_export::export_info($svcdb);
46 my $exports = FS::part_export::export_info();
48 tie my %layers, 'Tie::IxHash',
50 map { $_ => "$_ - ". $exports->{$_}{desc} }
55 my $widget = new HTML::Widgets::SelectLayers(
56 'selected_layer' => $part_export->exporttype,
57 'options' => \%layers,
58 'form_name' => 'dummy',
59 'form_action' => 'process/part_export.cgi',
60 'form_text' => [qw( exportnum exportname )],
61 # 'form_checkbox' => [qw()],
62 'html_between' => "</TD></TR></TABLE>\n",
63 'layer_callback' => sub {
65 my $html = qq!<INPUT TYPE="hidden" NAME="exporttype" VALUE="$layer">!.
69 $html .= '<TR><TD ALIGN="right">Description</TD><TD BGCOLOR=#ffffff>'.
70 $exports->{$layer}{notes}. '</TD></TR>';
72 if ( $exports->{$layer}{no_machine} ) {
73 $html .= '<INPUT TYPE="hidden" NAME="machine" VALUE="">'.
74 '<INPUT TYPE="hidden" NAME="svc_machine" VALUE=N">';
76 $html .= '<TR><TD ALIGN="right">Hostname or IP</TD><TD>';
77 my $machine = $part_export->machine;
78 if ( $exports->{$layer}{svc_machine} ) {
79 my( $N_CHK, $Y_CHK) = ( 'CHECKED', '' );
80 my( $machine_DISABLED, $pem_DISABLED) = ( '', 'DISABLED' );
81 my $part_export_machine = '';
82 if ( $cgi->param('svc_machine') eq 'Y'
83 || $machine eq '_SVC_MACHINE'
88 $machine_DISABLED = 'DISABLED';
91 $part_export_machine =
92 $cgi->param('part_export_machine')
96 $part_export->part_export_machine;
98 my $oc = qq(onChange="${layer}_svc_machine_changed(this)");
100 <INPUT TYPE="radio" NAME="svc_machine" VALUE="N" $N_CHK $oc>
101 <INPUT TYPE="text" NAME="machine" ID="${layer}_machine" VALUE="$machine" $machine_DISABLED>
103 <INPUT TYPE="radio" NAME="svc_machine" VALUE="Y" $Y_CHK $oc>
104 Selected in each customer service from these choices
105 <TEXTAREA NAME="part_export_machine" ID="${layer}_part_export_machine" $pem_DISABLED>$part_export_machine</TEXTAREA>
107 <SCRIPT TYPE="text/javascript">
108 function ${layer}_svc_machine_changed (what) {
109 if ( what.checked ) {
110 var machine = document.getElementById("${layer}_machine");
111 var part_export_machine = document.getElementById("${layer}_part_export_machine");
112 if ( what.value == 'Y' ) {
113 machine.disabled = true;
114 part_export_machine.disabled = false;
115 } else if ( what.value == 'N' ) {
116 machine.disabled = false;
117 part_export_machine.disabled = true;
124 $html .= qq(<INPUT TYPE="text" NAME="machine" VALUE="$machine">).
125 '<INPUT TYPE="hidden" NAME="svc_machine" VALUE=N">';
127 $html .= "</TD></TR>";
132 foreach my $option ( keys %{$exports->{$layer}{options}} ) {
133 my $optinfo = $exports->{$layer}{options}{$option};
134 die "Retreived non-ref export info option from $layer export: $optinfo"
135 unless ref($optinfo);
136 my $label = $optinfo->{label};
137 my $type = defined($optinfo->{type}) ? $optinfo->{type} : 'text';
138 my $value = $cgi->param($option)
139 || ( $part_export->exportnum && $part_export->option($option) )
140 || ( (exists $optinfo->{default} && !$part_export->exportnum)
141 ? $optinfo->{default}
144 if ( $type eq 'title' ) {
145 $html .= qq!<TR><TH COLSPAN=1 ALIGN="right"><FONT SIZE="+1">! .
151 # 'freeform': disables table formatting of options. Instead, each
152 # option can define "before" and "after" strings which are inserted
153 # around the selector.
154 my $freeform = $optinfo->{freeform};
156 $html .= $optinfo->{before} || '';
159 $html .= qq!<TR><TD ALIGN="right">$label</TD><TD>!;
161 if ( $type eq 'select' ) {
162 my $size = defined($optinfo->{size}) ? " SIZE=" . $optinfo->{size} : '';
163 my $multi = ($optinfo->{multi} || $optinfo->{multiple})
165 $html .= qq!<SELECT NAME="$option"$multi$size>!;
166 my @values = split '\s+', $value if $multi;
168 if (defined($optinfo->{option_values})) {
169 my $valsub = $optinfo->{option_values};
170 @options = &$valsub();
171 } elsif (defined($optinfo->{options})) {
172 @options = @{$optinfo->{options}};
174 foreach my $select_option ( @options ) {
175 #if ( ref($select_option) ) {
177 my $selected = ($multi ? grep {$_ eq $select_option} @values : $select_option eq $value ) ? ' SELECTED' : '';
178 my $label = $select_option;
179 if (defined($optinfo->{option_label})) {
180 my $labelsub = $optinfo->{option_label};
181 $label = &$labelsub($select_option);
183 $html .= qq!<OPTION VALUE="$select_option"$selected>!.
187 $html .= '</SELECT>';
188 } elsif ( $type eq 'textarea' ) {
189 $html .= qq!<TEXTAREA NAME="$option" COLS=80 ROWS=8 WRAP="virtual">!.
190 encode_entities($value). '</TEXTAREA>';
191 } elsif ( $type eq 'text' ) {
192 $html .= qq!<INPUT TYPE="text" NAME="$option" VALUE="!. #"
193 encode_entities($value). '" SIZE=64>';
194 } elsif ( $type eq 'checkbox' ) {
195 $html .= qq!<INPUT TYPE="checkbox" NAME="$option" VALUE="1"!;
196 $html .= ' CHECKED' if $value;
199 $html .= "unknown type $type";
202 $html .= $optinfo->{after} || '';
205 $html .= '</TD></TR>';
209 if ( $exports->{$layer}{nas} and qsearch('nas',{}) ) {
210 # show NAS checkboxes
211 $html .= '<TR><TD ALIGN="right">Export RADIUS clients</TD><TD>';
213 $html .= include('/elements/checkboxes-table.html',
214 'source_obj' => $part_export,
215 'link_table' => 'export_nas',
216 'target_table' => 'nas',
218 'name_callback' => sub {
219 $_[0]->shortname . ' (' . $_[0]->nasname . ')',
222 'target_link' => $p.'edit/nas.html?',
225 $html .= '</TD></TR>';
230 $html .= '<INPUT TYPE="hidden" NAME="options" VALUE="'.
231 join(',', keys %{$exports->{$layer}{options}} ). '">';
233 $html .= '<INPUT TYPE="hidden" NAME="nodomain" VALUE="'.
234 $exports->{$layer}{nodomain}. '">';
236 $html .= '<INPUT TYPE="submit" VALUE="'.
237 ( $part_export->exportnum ? "Apply changes" : "Add export" ).