This commit was generated by cvs2svn to compensate for changes in r9232,
[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 host</TD>
11   <TD>
12     <INPUT TYPE="text" NAME="machine" VALUE="<% $part_export->machine %>">
13   </TD>
14 </TR>
15 <TR>
16   <TD ALIGN="right">Export</TD>
17   <TD><% $widget->html %>
18
19 <% include('/elements/footer.html') %>
20 <%init>
21
22 die "access denied"
23   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
24
25 #if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
26 #  $cgi->param('clone', $1);
27 #} else {
28 #  $cgi->param('clone', '');
29 #}
30
31 my($query) = $cgi->keywords;
32 my $action = '';
33 my $part_export = '';
34 if ( $cgi->param('error') ) {
35   $part_export = new FS::part_export ( {
36     map { $_, scalar($cgi->param($_)) } fields('part_export')
37   } );
38 } elsif ( $query =~ /^(\d+)$/ ) {
39   $part_export = qsearchs('part_export', { 'exportnum' => $1 } );
40 } else {
41   $part_export = new FS::part_export;
42 }
43 $action ||= $part_export->exportnum ? 'Edit' : 'Add';
44
45 #my $exports = FS::part_export::export_info($svcdb);
46 my $exports = FS::part_export::export_info();
47
48 my %layers = map { $_ => "$_ - ". $exports->{$_}{desc} } keys %$exports;
49 $layers{''}='';
50
51 my $widget = new HTML::Widgets::SelectLayers(
52   'selected_layer' => $part_export->exporttype,
53   'options'        => \%layers,
54   'form_name'      => 'dummy',
55   'form_action'    => 'process/part_export.cgi',
56   'form_text'      => [qw( exportnum machine )],
57 #  'form_checkbox'  => [qw()],
58   'html_between'    => "</TD></TR></TABLE>\n",
59   'layer_callback'  => sub {
60     my $layer = shift;
61     my $html = qq!<INPUT TYPE="hidden" NAME="exporttype" VALUE="$layer">!.
62                ntable("#cccccc",2);
63
64     $html .= '<TR><TD ALIGN="right">Description</TD><TD BGCOLOR=#ffffff>'.
65              $exports->{$layer}{notes}. '</TD></TR>'
66       if $layer;
67
68     foreach my $option ( keys %{$exports->{$layer}{options}} ) {
69       my $optinfo = $exports->{$layer}{options}{$option};
70       die "Retreived non-ref export info option from $layer export: $optinfo"
71         unless ref($optinfo);
72       my $label = $optinfo->{label};
73       my $type = defined($optinfo->{type}) ? $optinfo->{type} : 'text';
74       my $value = $cgi->param($option)
75                  || ( $part_export->exportnum && $part_export->option($option) )
76                  || ( (exists $optinfo->{default} && !$part_export->exportnum)
77                       ? $optinfo->{default}
78                       : ''
79                     );
80       $html .= qq!<TR><TD ALIGN="right">$label</TD><TD>!;
81       if ( $type eq 'select' ) {
82         my $size = defined($optinfo->{size}) ? " SIZE=" . $optinfo->{size} : '';
83         my $multi = defined($optinfo->{multi}) ? ' MULTIPLE' : '';
84         $html .= qq!<SELECT NAME="$option"$multi$size>!;
85         my @values = split '\s+', $value if $multi;
86         my @options;
87         if (defined($optinfo->{option_values})) {
88           my $valsub = $optinfo->{option_values};
89           @options = &$valsub();
90         } elsif (defined($optinfo->{options})) {
91           @options = @{$optinfo->{options}};
92         }
93         foreach my $select_option ( @options ) {
94           #if ( ref($select_option) ) {
95           #} else {
96             my $selected = ($multi ? grep {$_ eq $select_option} @values : $select_option eq $value ) ? ' SELECTED' : '';
97             my $label = $select_option;
98             if (defined($optinfo->{option_label})) {
99               my $labelsub = $optinfo->{option_label};
100               $label = &$labelsub($select_option);
101             }
102             $html .= qq!<OPTION VALUE="$select_option"$selected>!.
103                      qq!$label</OPTION>!;
104           #}
105         }
106         $html .= '</SELECT>';
107       } elsif ( $type eq 'textarea' ) {
108         $html .= qq!<TEXTAREA NAME="$option" COLS=80 ROWS=8 WRAP="virtual">!.
109                  encode_entities($value). '</TEXTAREA>';
110       } elsif ( $type eq 'text' ) {
111         $html .= qq!<INPUT TYPE="text" NAME="$option" VALUE="!.
112                  encode_entities($value). '" SIZE=64>';
113       } elsif ( $type eq 'checkbox' ) {
114         $html .= qq!<INPUT TYPE="checkbox" NAME="$option" VALUE="1"!;
115         $html .= ' CHECKED' if $value;
116         $html .= '>';
117       } else {
118         $html .= "unknown type $type";
119       }
120       $html .= '</TD></TR>';
121     }
122     $html .= '</TABLE>';
123
124     $html .= '<INPUT TYPE="hidden" NAME="options" VALUE="'.
125              join(',', keys %{$exports->{$layer}{options}} ). '">';
126
127     $html .= '<INPUT TYPE="hidden" NAME="nodomain" VALUE="'.
128              $exports->{$layer}{nodomain}. '">';
129
130     $html .= '<INPUT TYPE="submit" VALUE="'.
131              ( $part_export->exportnum ? "Apply changes" : "Add export" ).
132              '">';
133
134     $html;
135   },
136 );
137
138 </%init>