backport cust_svc_unsorted method from master, RT#26097
[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     # create 'config_element' to generate the whole layer with a Mason component
72     if ( my $include = $exports->{$layer}{config_element} ) {
73       # might need to adjust the scope of  this at some point
74       return $m->scomp($include, 
75         part_export => $part_export,
76         layer       => $layer,
77         export_info => $exports->{$layer}
78       );
79     }
80     my $html = qq!<INPUT TYPE="hidden" NAME="exporttype" VALUE="$layer">!.
81                ntable("#cccccc",2);
82
83     $html .= '<TR><TD ALIGN="right">Description</TD><TD BGCOLOR=#ffffff>'.
84              $exports->{$layer}{notes}. '</TD></TR>'
85       if $layer;
86
87     foreach my $option ( keys %{$exports->{$layer}{options}} ) {
88       my $optinfo = $exports->{$layer}{options}{$option};
89       die "Retreived non-ref export info option from $layer export: $optinfo"
90         unless ref($optinfo);
91       my $label = $optinfo->{label};
92       my $type = defined($optinfo->{type}) ? $optinfo->{type} : 'text';
93       my $value = $cgi->param($option)
94                  || ( $part_export->exportnum && $part_export->option($option) )
95                  || ( (exists $optinfo->{default} && !$part_export->exportnum)
96                       ? $optinfo->{default}
97                       : ''
98                     );
99       if ( $type eq 'title' ) {
100         $html .= qq!<TR><TH COLSPAN=1 ALIGN="right"><FONT SIZE="+1">! .
101                  $label .
102                  '</FONT></TH></TR>';
103         next;
104       }
105
106       # 'freeform': disables table formatting of options.  Instead, each 
107       # option can define "before" and "after" strings which are inserted 
108       # around the selector.
109       my $freeform = $optinfo->{freeform};
110       if ( $freeform ) {
111         $html .= $optinfo->{before} || '';
112       }
113       else {
114         $html .= qq!<TR><TD ALIGN="right">$label</TD><TD>!;
115       }
116       if ( $type eq 'select' ) {
117         my $size = defined($optinfo->{size}) ? " SIZE=" . $optinfo->{size} : '';
118         my $multi = ($optinfo->{multi} || $optinfo->{multiple})
119                       ? ' MULTIPLE' : '';
120         $html .= qq!<SELECT NAME="$option"$multi$size>!;
121         my @values = split '\s+', $value if $multi;
122         my @options;
123         if (defined($optinfo->{option_values})) {
124           my $valsub = $optinfo->{option_values};
125           @options = &$valsub();
126         } elsif (defined($optinfo->{options})) {
127           @options = @{$optinfo->{options}};
128         }
129         foreach my $select_option ( @options ) {
130           #if ( ref($select_option) ) {
131           #} else {
132             my $selected = ($multi ? grep {$_ eq $select_option} @values : $select_option eq $value ) ? ' SELECTED' : '';
133             my $label = $select_option;
134             if (defined($optinfo->{option_label})) {
135               my $labelsub = $optinfo->{option_label};
136               $label = &$labelsub($select_option);
137             }
138             $html .= qq!<OPTION VALUE="$select_option"$selected>!.
139                      qq!$label</OPTION>!;
140           #}
141         }
142         $html .= '</SELECT>';
143       } elsif ( $type eq 'textarea' ) {
144         $html .= qq!<TEXTAREA NAME="$option" COLS=80 ROWS=8 WRAP="virtual">!.
145                  encode_entities($value). '</TEXTAREA>';
146       } elsif ( $type eq 'text' ) {
147         $html .= qq!<INPUT TYPE="text" NAME="$option" VALUE="!. #"
148                  encode_entities($value). '" SIZE=64>';
149       } elsif ( $type eq 'checkbox' ) {
150         $html .= qq!<INPUT TYPE="checkbox" NAME="$option" VALUE="1"!;
151         $html .= ' CHECKED' if $value;
152         $html .= '>';
153       } else {
154         $html .= "unknown type $type";
155       }
156       if ( $freeform ) {
157         $html .= $optinfo->{after} || '';
158       }
159       else {
160         $html .= '</TD></TR>';
161       }
162     }
163
164     if ( $exports->{$layer}{nas} and qsearch('nas',{}) ) {
165       # show NAS checkboxes
166       $html .= '<TR><TD ALIGN="right">Export RADIUS clients</TD><TD>';
167
168       $html .= include('/elements/checkboxes-table.html',
169                         'source_obj'    => $part_export,
170                         'link_table'    => 'export_nas',
171                         'target_table'  => 'nas',
172                         #hashref => {},
173                         'name_callback' => sub { 
174                           $_[0]->shortname . ' (' . $_[0]->nasname . ')',
175                         },
176                         'default'       => 'yes',
177                         'target_link'   => $p.'edit/nas.html?',
178                       );
179
180       $html .= '</TD></TR>';
181     }
182
183     $html .= '</TABLE>';
184
185     $html .= '<INPUT TYPE="hidden" NAME="options" VALUE="'.
186              join(',', keys %{$exports->{$layer}{options}} ). '">';
187
188     $html .= '<INPUT TYPE="hidden" NAME="nodomain" VALUE="'.
189              $exports->{$layer}{nodomain}. '">';
190
191     $html .= '<INPUT TYPE="submit" VALUE="'.
192              ( $part_export->exportnum ? "Apply changes" : "Add export" ).
193              '">';
194
195     $html;
196   },
197 );
198
199 </%init>