export NAS table to sqlradius, #14697
[freeside.git] / httemplate / edit / part_export.cgi
1 <% include('/elements/header.html', "$action Export", '', ' onLoad="visualize()"') %>
2
3 <% include('/elements/error.html') %>
4
5 <FORM NAME="dummy">
6 <INPUT TYPE="hidden" NAME="exportnum" VALUE="<% $part_export->exportnum %>">
7
8 <% ntable("#cccccc",2) %>
9 <TR>
10   <TD ALIGN="right">Export name</TD>
11   <TD>
12     <INPUT TYPE="text" NAME="exportname" VALUE="<% $part_export->exportname %>">
13   </TD>
14 </TR>
15 <TR>
16   <TD ALIGN="right">Export host</TD>
17   <TD>
18     <INPUT TYPE="text" NAME="machine" VALUE="<% $part_export->machine %>">
19   </TD>
20 </TR>
21 <TR>
22   <TD ALIGN="right">Export</TD>
23   <TD><% $widget->html %>
24
25 <% include('/elements/footer.html') %>
26 <%init>
27
28 die "access denied"
29   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
30
31 #if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
32 #  $cgi->param('clone', $1);
33 #} else {
34 #  $cgi->param('clone', '');
35 #}
36
37 my($query) = $cgi->keywords;
38 my $action = '';
39 my $part_export = '';
40 if ( $cgi->param('error') ) {
41   $part_export = new FS::part_export ( {
42     map { $_, scalar($cgi->param($_)) } fields('part_export')
43   } );
44 } elsif ( $query =~ /^(\d+)$/ ) {
45   $part_export = qsearchs('part_export', { 'exportnum' => $1 } );
46 } else {
47   $part_export = new FS::part_export;
48 }
49 $action ||= $part_export->exportnum ? 'Edit' : 'Add';
50
51 #my $exports = FS::part_export::export_info($svcdb);
52 my $exports = FS::part_export::export_info();
53
54 my %layers = map { $_ => "$_ - ". $exports->{$_}{desc} } keys %$exports;
55 $layers{''}='';
56
57 my $widget = new HTML::Widgets::SelectLayers(
58   'selected_layer' => $part_export->exporttype,
59   'options'        => \%layers,
60   'form_name'      => 'dummy',
61   'form_action'    => 'process/part_export.cgi',
62   'form_text'      => [qw( exportnum exportname machine )],
63 #  'form_checkbox'  => [qw()],
64   'html_between'    => "</TD></TR></TABLE>\n",
65   'layer_callback'  => sub {
66     my $layer = shift;
67     my $html = qq!<INPUT TYPE="hidden" NAME="exporttype" VALUE="$layer">!.
68                ntable("#cccccc",2);
69
70     $html .= '<TR><TD ALIGN="right">Description</TD><TD BGCOLOR=#ffffff>'.
71              $exports->{$layer}{notes}. '</TD></TR>'
72       if $layer;
73
74     foreach my $option ( keys %{$exports->{$layer}{options}} ) {
75       my $optinfo = $exports->{$layer}{options}{$option};
76       die "Retreived non-ref export info option from $layer export: $optinfo"
77         unless ref($optinfo);
78       my $label = $optinfo->{label};
79       my $type = defined($optinfo->{type}) ? $optinfo->{type} : 'text';
80       my $value = $cgi->param($option)
81                  || ( $part_export->exportnum && $part_export->option($option) )
82                  || ( (exists $optinfo->{default} && !$part_export->exportnum)
83                       ? $optinfo->{default}
84                       : ''
85                     );
86       # 'freeform': disables table formatting of options.  Instead, each 
87       # option can define "before" and "after" strings which are inserted 
88       # around the selector.
89       my $freeform = $optinfo->{freeform};
90       if ( $freeform ) {
91         $html .= $optinfo->{before} || '';
92       }
93       else {
94         $html .= qq!<TR><TD ALIGN="right">$label</TD><TD>!;
95       }
96       if ( $type eq 'select' ) {
97         my $size = defined($optinfo->{size}) ? " SIZE=" . $optinfo->{size} : '';
98         my $multi = defined($optinfo->{multi}) ? ' MULTIPLE' : '';
99         $html .= qq!<SELECT NAME="$option"$multi$size>!;
100         my @values = split '\s+', $value if $multi;
101         my @options;
102         if (defined($optinfo->{option_values})) {
103           my $valsub = $optinfo->{option_values};
104           @options = &$valsub();
105         } elsif (defined($optinfo->{options})) {
106           @options = @{$optinfo->{options}};
107         }
108         foreach my $select_option ( @options ) {
109           #if ( ref($select_option) ) {
110           #} else {
111             my $selected = ($multi ? grep {$_ eq $select_option} @values : $select_option eq $value ) ? ' SELECTED' : '';
112             my $label = $select_option;
113             if (defined($optinfo->{option_label})) {
114               my $labelsub = $optinfo->{option_label};
115               $label = &$labelsub($select_option);
116             }
117             $html .= qq!<OPTION VALUE="$select_option"$selected>!.
118                      qq!$label</OPTION>!;
119           #}
120         }
121         $html .= '</SELECT>';
122       } elsif ( $type eq 'textarea' ) {
123         $html .= qq!<TEXTAREA NAME="$option" COLS=80 ROWS=8 WRAP="virtual">!.
124                  encode_entities($value). '</TEXTAREA>';
125       } elsif ( $type eq 'text' ) {
126         $html .= qq!<INPUT TYPE="text" NAME="$option" VALUE="!. #"
127                  encode_entities($value). '" SIZE=64>';
128       } elsif ( $type eq 'checkbox' ) {
129         $html .= qq!<INPUT TYPE="checkbox" NAME="$option" VALUE="1"!;
130         $html .= ' CHECKED' if $value;
131         $html .= '>';
132       } else {
133         $html .= "unknown type $type";
134       }
135       if ( $freeform ) {
136         $html .= $optinfo->{after} || '';
137       }
138       else {
139         $html .= '</TD></TR>';
140       }
141     }
142
143     if ( $exports->{$layer}{nas} and qsearch('nas',{}) ) {
144       # show NAS checkboxes
145       $html .= '<TR><TD ALIGN="right">Export RADIUS clients</TD><TD>';
146
147       $html .= include('/elements/checkboxes-table.html',
148                         'source_obj'    => $part_export,
149                         'link_table'    => 'export_nas',
150                         'target_table'  => 'nas',
151                         #hashref => {},
152                         'name_callback' => sub { 
153                           $_[0]->shortname . ' (' . $_[0]->nasname . ')',
154                         },
155                         'default'       => 'yes',
156                         'target_link'   => $p.'edit/nas.html?',
157                       );
158
159       $html .= '</TD></TR>';
160     }
161
162     $html .= '</TABLE>';
163
164     $html .= '<INPUT TYPE="hidden" NAME="options" VALUE="'.
165              join(',', keys %{$exports->{$layer}{options}} ). '">';
166
167     $html .= '<INPUT TYPE="hidden" NAME="nodomain" VALUE="'.
168              $exports->{$layer}{nodomain}. '">';
169
170     $html .= '<INPUT TYPE="submit" VALUE="'.
171              ( $part_export->exportnum ? "Apply changes" : "Add export" ).
172              '">';
173
174     $html;
175   },
176 );
177
178 </%init>