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 # create 'config_element' to generate the whole layer with a Mason component
66 if ( my $include = $exports->{$layer}{config_element} ) {
67 # might need to adjust the scope of this at some point
68 return $m->scomp($include,
69 part_export => $part_export,
71 export_info => $exports->{$layer}
74 my $html = qq!<INPUT TYPE="hidden" NAME="exporttype" VALUE="$layer">!.
78 $html .= '<TR><TD ALIGN="right">Description</TD><TD BGCOLOR=#ffffff>'.
79 $exports->{$layer}{notes}. '</TD></TR>';
81 if ( $exports->{$layer}{no_machine} ) {
82 $html .= '<INPUT TYPE="hidden" NAME="machine" VALUE="">'.
83 '<INPUT TYPE="hidden" NAME="svc_machine" VALUE=N">';
85 $html .= '<TR><TD ALIGN="right">Hostname or IP</TD><TD>';
86 my $machine = $part_export->machine;
87 if ( $exports->{$layer}{svc_machine} ) {
88 my( $N_CHK, $Y_CHK) = ( 'CHECKED', '' );
89 my( $machine_DISABLED, $pem_DISABLED) = ( '', 'DISABLED' );
90 my $part_export_machine = '';
91 if ( $cgi->param('svc_machine') eq 'Y'
92 || $machine eq '_SVC_MACHINE'
97 $machine_DISABLED = 'DISABLED';
100 $part_export_machine =
101 $cgi->param('part_export_machine')
105 $part_export->part_export_machine;
107 my $oc = qq(onChange="${layer}_svc_machine_changed(this)");
109 <INPUT TYPE="radio" NAME="svc_machine" VALUE="N" $N_CHK $oc>
110 <INPUT TYPE="text" NAME="machine" ID="${layer}_machine" VALUE="$machine" $machine_DISABLED>
112 <INPUT TYPE="radio" NAME="svc_machine" VALUE="Y" $Y_CHK $oc>
113 Selected in each customer service from these choices
114 <TEXTAREA NAME="part_export_machine" ID="${layer}_part_export_machine" $pem_DISABLED>$part_export_machine</TEXTAREA>
116 <SCRIPT TYPE="text/javascript">
117 function ${layer}_svc_machine_changed (what) {
118 if ( what.checked ) {
119 var machine = document.getElementById("${layer}_machine");
120 var part_export_machine = document.getElementById("${layer}_part_export_machine");
121 if ( what.value == 'Y' ) {
122 machine.disabled = true;
123 part_export_machine.disabled = false;
124 } else if ( what.value == 'N' ) {
125 machine.disabled = false;
126 part_export_machine.disabled = true;
133 $html .= qq(<INPUT TYPE="text" NAME="machine" VALUE="$machine">).
134 '<INPUT TYPE="hidden" NAME="svc_machine" VALUE=N">';
136 $html .= "</TD></TR>";
141 foreach my $option ( keys %{$exports->{$layer}{options}} ) {
142 my $optinfo = $exports->{$layer}{options}{$option};
143 die "Retreived non-ref export info option from $layer export: $optinfo"
144 unless ref($optinfo);
145 my $label = $optinfo->{label};
146 my $type = defined($optinfo->{type}) ? $optinfo->{type} : 'text';
147 my $value = $cgi->param($option)
148 || ( $part_export->exportnum && $part_export->option($option) )
149 || ( (exists $optinfo->{default} && !$part_export->exportnum)
150 ? $optinfo->{default}
153 if ( $type eq 'title' ) {
154 $html .= qq!<TR><TH COLSPAN=1 ALIGN="right"><FONT SIZE="+1">! .
160 # 'freeform': disables table formatting of options. Instead, each
161 # option can define "before" and "after" strings which are inserted
162 # around the selector.
163 my $freeform = $optinfo->{freeform};
165 $html .= $optinfo->{before} || '';
168 $html .= qq!<TR><TD ALIGN="right">$label</TD><TD>!;
170 if ( $type eq 'select' ) {
171 my $size = defined($optinfo->{size}) ? " SIZE=" . $optinfo->{size} : '';
172 my $multi = ($optinfo->{multi} || $optinfo->{multiple})
174 $html .= qq!<SELECT NAME="$option"$multi$size>!;
175 my @values = split '\s+', $value if $multi;
177 if (defined($optinfo->{option_values})) {
178 my $valsub = $optinfo->{option_values};
179 @options = &$valsub();
180 } elsif (defined($optinfo->{options})) {
181 @options = @{$optinfo->{options}};
183 foreach my $select_option ( @options ) {
184 #if ( ref($select_option) ) {
186 my $selected = ($multi ? grep {$_ eq $select_option} @values : $select_option eq $value ) ? ' SELECTED' : '';
187 my $label = $select_option;
188 if (defined($optinfo->{option_label})) {
189 my $labelsub = $optinfo->{option_label};
190 $label = &$labelsub($select_option);
192 $html .= qq!<OPTION VALUE="$select_option"$selected>!.
196 $html .= '</SELECT>';
197 } elsif ( $type eq 'textarea' ) {
198 $html .= qq!<TEXTAREA NAME="$option" COLS=80 ROWS=8 WRAP="virtual">!.
199 encode_entities($value). '</TEXTAREA>';
200 } elsif ( $type eq 'text' ) {
201 $html .= qq!<INPUT TYPE="text" NAME="$option" VALUE="!. #"
202 encode_entities($value). '" SIZE=64>';
203 } elsif ( $type eq 'checkbox' ) {
204 $html .= qq!<INPUT TYPE="checkbox" NAME="$option" VALUE="1"!;
205 $html .= ' CHECKED' if $value;
208 $html .= "unknown type $type";
211 $html .= $optinfo->{after} || '';
214 $html .= '</TD></TR>';
218 if ( $exports->{$layer}{nas} and qsearch('nas',{}) ) {
219 # show NAS checkboxes
220 $html .= '<TR><TD ALIGN="right">Export RADIUS clients</TD><TD>';
222 $html .= include('/elements/checkboxes-table.html',
223 'source_obj' => $part_export,
224 'link_table' => 'export_nas',
225 'target_table' => 'nas',
227 'name_callback' => sub {
228 $_[0]->shortname . ' (' . $_[0]->nasname . ')',
231 'target_link' => $p.'edit/nas.html?',
234 $html .= '</TD></TR>';
239 $html .= '<INPUT TYPE="hidden" NAME="options" VALUE="'.
240 join(',', keys %{$exports->{$layer}{options}} ). '">';
242 $html .= '<INPUT TYPE="hidden" NAME="nodomain" VALUE="'.
243 $exports->{$layer}{nodomain}. '">';
245 $html .= '<INPUT TYPE="submit" VALUE="'.
246 ( $part_export->exportnum ? "Apply changes" : "Add export" ).