RT ticket creation export to multiple queues, RT#10363
[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       # 'freeform': disables table formatting of options.  Instead, each 
81       # option can define "before" and "after" strings which are inserted 
82       # around the selector.
83       my $freeform = $optinfo->{freeform};
84       if ( $freeform ) {
85         $html .= $optinfo->{before} || '';
86       }
87       else {
88         $html .= qq!<TR><TD ALIGN="right">$label</TD><TD>!;
89       }
90       if ( $type eq 'select' ) {
91         my $size = defined($optinfo->{size}) ? " SIZE=" . $optinfo->{size} : '';
92         my $multi = defined($optinfo->{multi}) ? ' MULTIPLE' : '';
93         $html .= qq!<SELECT NAME="$option"$multi$size>!;
94         my @values = split '\s+', $value if $multi;
95         my @options;
96         if (defined($optinfo->{option_values})) {
97           my $valsub = $optinfo->{option_values};
98           @options = &$valsub();
99         } elsif (defined($optinfo->{options})) {
100           @options = @{$optinfo->{options}};
101         }
102         foreach my $select_option ( @options ) {
103           #if ( ref($select_option) ) {
104           #} else {
105             my $selected = ($multi ? grep {$_ eq $select_option} @values : $select_option eq $value ) ? ' SELECTED' : '';
106             my $label = $select_option;
107             if (defined($optinfo->{option_label})) {
108               my $labelsub = $optinfo->{option_label};
109               $label = &$labelsub($select_option);
110             }
111             $html .= qq!<OPTION VALUE="$select_option"$selected>!.
112                      qq!$label</OPTION>!;
113           #}
114         }
115         $html .= '</SELECT>';
116       } elsif ( $type eq 'textarea' ) {
117         $html .= qq!<TEXTAREA NAME="$option" COLS=80 ROWS=8 WRAP="virtual">!.
118                  encode_entities($value). '</TEXTAREA>';
119       } elsif ( $type eq 'text' ) {
120         $html .= qq!<INPUT TYPE="text" NAME="$option" VALUE="!. #"
121                  encode_entities($value). '" SIZE=64>';
122       } elsif ( $type eq 'checkbox' ) {
123         $html .= qq!<INPUT TYPE="checkbox" NAME="$option" VALUE="1"!;
124         $html .= ' CHECKED' if $value;
125         $html .= '>';
126       } else {
127         $html .= "unknown type $type";
128       }
129       if ( $freeform ) {
130         $html .= $optinfo->{after} || '';
131       }
132       else {
133         $html .= '</TD></TR>';
134       }
135     }
136     $html .= '</TABLE>';
137
138     $html .= '<INPUT TYPE="hidden" NAME="options" VALUE="'.
139              join(',', keys %{$exports->{$layer}{options}} ). '">';
140
141     $html .= '<INPUT TYPE="hidden" NAME="nodomain" VALUE="'.
142              $exports->{$layer}{nodomain}. '">';
143
144     $html .= '<INPUT TYPE="submit" VALUE="'.
145              ( $part_export->exportnum ? "Apply changes" : "Add export" ).
146              '">';
147
148     $html;
149   },
150 );
151
152 </%init>