d7219b74a403b7f6aeb60d161b70fba9ebb8a79a
[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 tie my %layers, 'Tie::IxHash',
55   '' => '',
56   map { $_ => "$_ - ". $exports->{$_}{desc} } 
57   sort { $a cmp $b }
58   keys %$exports;
59 ;
60
61 my $widget = new HTML::Widgets::SelectLayers(
62   'selected_layer' => $part_export->exporttype,
63   'options'        => \%layers,
64   'form_name'      => 'dummy',
65   'form_action'    => 'process/part_export.cgi',
66   'form_text'      => [qw( exportnum exportname machine )],
67 #  'form_checkbox'  => [qw()],
68   'html_between'    => "</TD></TR></TABLE>\n",
69   'layer_callback'  => sub {
70     my $layer = shift;
71     my $html = qq!<INPUT TYPE="hidden" NAME="exporttype" VALUE="$layer">!.
72                ntable("#cccccc",2);
73
74     $html .= '<TR><TD ALIGN="right">Description</TD><TD BGCOLOR=#ffffff>'.
75              $exports->{$layer}{notes}. '</TD></TR>'
76       if $layer;
77
78     foreach my $option ( keys %{$exports->{$layer}{options}} ) {
79       my $optinfo = $exports->{$layer}{options}{$option};
80       die "Retreived non-ref export info option from $layer export: $optinfo"
81         unless ref($optinfo);
82       my $label = $optinfo->{label};
83       my $type = defined($optinfo->{type}) ? $optinfo->{type} : 'text';
84       my $value = $cgi->param($option)
85                  || ( $part_export->exportnum && $part_export->option($option) )
86                  || ( (exists $optinfo->{default} && !$part_export->exportnum)
87                       ? $optinfo->{default}
88                       : ''
89                     );
90       if ( $type eq 'title' ) {
91         $html .= qq!<TR><TH COLSPAN=1 ALIGN="right"><FONT SIZE="+1">! .
92                  $label .
93                  '</FONT></TH></TR>';
94         next;
95       }
96
97       # 'freeform': disables table formatting of options.  Instead, each 
98       # option can define "before" and "after" strings which are inserted 
99       # around the selector.
100       my $freeform = $optinfo->{freeform};
101       if ( $freeform ) {
102         $html .= $optinfo->{before} || '';
103       }
104       else {
105         $html .= qq!<TR><TD ALIGN="right">$label</TD><TD>!;
106       }
107       if ( $type eq 'select' ) {
108         my $size = defined($optinfo->{size}) ? " SIZE=" . $optinfo->{size} : '';
109         my $multi = ($optinfo->{multi} || $optinfo->{multiple})
110                       ? ' MULTIPLE' : '';
111         $html .= qq!<SELECT NAME="$option"$multi$size>!;
112         my @values = split '\s+', $value if $multi;
113         my @options;
114         if (defined($optinfo->{option_values})) {
115           my $valsub = $optinfo->{option_values};
116           @options = &$valsub();
117         } elsif (defined($optinfo->{options})) {
118           @options = @{$optinfo->{options}};
119         }
120         foreach my $select_option ( @options ) {
121           #if ( ref($select_option) ) {
122           #} else {
123             my $selected = ($multi ? grep {$_ eq $select_option} @values : $select_option eq $value ) ? ' SELECTED' : '';
124             my $label = $select_option;
125             if (defined($optinfo->{option_label})) {
126               my $labelsub = $optinfo->{option_label};
127               $label = &$labelsub($select_option);
128             }
129             $html .= qq!<OPTION VALUE="$select_option"$selected>!.
130                      qq!$label</OPTION>!;
131           #}
132         }
133         $html .= '</SELECT>';
134       } elsif ( $type eq 'textarea' ) {
135         $html .= qq!<TEXTAREA NAME="$option" COLS=80 ROWS=8 WRAP="virtual">!.
136                  encode_entities($value). '</TEXTAREA>';
137       } elsif ( $type eq 'text' ) {
138         $html .= qq!<INPUT TYPE="text" NAME="$option" VALUE="!. #"
139                  encode_entities($value). '" SIZE=64>';
140       } elsif ( $type eq 'checkbox' ) {
141         $html .= qq!<INPUT TYPE="checkbox" NAME="$option" VALUE="1"!;
142         $html .= ' CHECKED' if $value;
143         $html .= '>';
144       } else {
145         $html .= "unknown type $type";
146       }
147       if ( $freeform ) {
148         $html .= $optinfo->{after} || '';
149       }
150       else {
151         $html .= '</TD></TR>';
152       }
153     }
154
155     if ( $exports->{$layer}{nas} and qsearch('nas',{}) ) {
156       # show NAS checkboxes
157       $html .= '<TR><TD ALIGN="right">Export RADIUS clients</TD><TD>';
158
159       $html .= include('/elements/checkboxes-table.html',
160                         'source_obj'    => $part_export,
161                         'link_table'    => 'export_nas',
162                         'target_table'  => 'nas',
163                         #hashref => {},
164                         'name_callback' => sub { 
165                           $_[0]->shortname . ' (' . $_[0]->nasname . ')',
166                         },
167                         'default'       => 'yes',
168                         'target_link'   => $p.'edit/nas.html?',
169                       );
170
171       $html .= '</TD></TR>';
172     }
173
174     $html .= '</TABLE>';
175
176     $html .= '<INPUT TYPE="hidden" NAME="options" VALUE="'.
177              join(',', keys %{$exports->{$layer}{options}} ). '">';
178
179     $html .= '<INPUT TYPE="hidden" NAME="nodomain" VALUE="'.
180              $exports->{$layer}{nodomain}. '">';
181
182     $html .= '<INPUT TYPE="submit" VALUE="'.
183              ( $part_export->exportnum ? "Apply changes" : "Add export" ).
184              '">';
185
186     $html;
187   },
188 );
189
190 </%init>