add eps preview to config, for RT#5025
[freeside.git] / httemplate / config / config.cgi
1 <% include("/elements/header-popup.html", $title) %>
2
3 <SCRIPT>
4 var gSafeOnload = new Array();
5 var gSafeOnsubmit = new Array();
6 window.onload = SafeOnload;
7 function SafeAddOnLoad(f) {
8   gSafeOnload[gSafeOnload.length] = f;
9 }
10 function SafeOnload() {
11   for (var i=0;i<gSafeOnload.length;i++)
12     gSafeOnload[i]();
13 }
14 function SafeAddOnSubmit(f) {
15   gSafeOnsubmit[gSafeOnsubmit.length] = f;
16 }
17 function SafeOnsubmit() {
18   for (var i=0;i<gSafeOnsubmit.length;i++)
19     gSafeOnsubmit[i]();
20 }
21 </SCRIPT>
22
23 <% include('/elements/error.html') %>
24
25 <FORM NAME="OneTrueForm" ACTION="config-process.cgi" METHOD="POST" enctype="multipart/form-data" onSubmit="SafeOnsubmit()">
26 <INPUT TYPE="hidden" NAME="agentnum" VALUE="<% $agentnum %>">
27 <INPUT TYPE="hidden" NAME="key" VALUE="<% $key %>">
28
29 Setting <b><% $key %></b>
30
31 % my $description_printed = 0;
32 % if ( grep $_ eq 'textarea', @types ) {
33 %   $description_printed = 1;
34
35     - <% $description %>
36
37 % }
38
39 <table><tr><td>
40
41 % my $n = 0;
42 % foreach my $type (@types) {
43 %   if ( $type eq '' ) {
44
45   <font color="#ff0000">no type</font>
46
47 %   } elsif ( $type eq 'image' ) { 
48
49   <% $conf->exists($key, $agentnum)
50        ? 'Current image<br>'.
51          '<img src="config-image.cgi?key='.      $key.
52                                    ';agentnum='. $agentnum. '"><br>'
53        : ''
54   %>
55
56   <BR>
57   New image filename <input type="file" name="<% "$key$n" %>">
58
59 %   } elsif ( $type eq 'binary' ) { 
60
61   Filename <input type="file" name="<% "$key$n" %>">
62
63 %   } elsif ( $type eq 'textarea' ) { 
64
65   <textarea name="<% "$key$n" %>" rows=12 cols=78 wrap="off"><% join("\n", $conf->config($key, $agentnum)) |h %></textarea>
66
67 %   } elsif ( $type eq 'checkbox' ) { 
68
69   <input name="<% "$key$n" %>" type="checkbox" value="1"
70     <% $conf->exists($key, $agentnum) ? 'CHECKED' : '' %> >
71
72 %   } elsif ( $type eq 'text' )  { 
73
74   <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' |h %>">
75
76 %   } elsif ( $type eq 'select' || $type eq 'selectmultiple' )  { 
77
78   <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
79
80 %
81 %     my %hash = ();
82 %     if ( $config_item->select_enum ) {
83 %       tie %hash, 'Tie::IxHash',
84 %         '' => '', map { $_ => $_ } @{ $config_item->select_enum };
85 %     } elsif ( $config_item->select_hash ) {
86 %       if ( ref($config_item->select_hash) eq 'ARRAY' ) {
87 %         tie %hash, 'Tie::IxHash',
88 %           '' => '', @{ $config_item->select_hash };
89 %       } else {
90 %         tie %hash, 'Tie::IxHash',
91 %           '' => '', %{ $config_item->select_hash };
92 %       }
93 %     } else {
94 %       %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' );
95 %     }
96 %
97 %     my %saw = ();
98 %     foreach my $value ( keys %hash ) {
99 %       local($^W)=0; next if $saw{$value}++;
100 %       my $label = $hash{$value};
101 %        
102
103     <option value="<% $value %>"
104
105 %       if ( $value eq $conf->config($key, $agentnum)
106 %            || ( $type eq 'selectmultiple'
107 %                 && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) {
108
109       SELECTED
110
111 %       }
112
113     ><% $label %>
114
115 %     } 
116 %     my $curvalue = $conf->config($key, $agentnum);
117 %     if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) {
118
119     <option value="<% $curvalue %>" SELECTED>
120
121 %       if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) {
122
123       <% $hash{ $conf->config($key, $agentnum) } %>
124
125 %       }else{
126
127       <% $curvalue %>
128
129 %       }
130 %     } 
131
132   </select>
133
134 %   } elsif ( $type eq 'select-sub' ) { 
135
136   <select name="<% "$key$n" %>"><option value="">
137
138 %     my %options = &{$config_item->options_sub};
139 %     my @options = sort { $a <=> $b } keys %options;
140 %     my %saw;
141 %     foreach my $value ( @options ) {
142 %       local($^W)=0; next if $saw{$value}++;
143
144     <option value="<% $value %>" <% $value eq $conf->config($key, $agentnum) ? 'SELECTED' : '' %>><% $value %>: <% $options{$value} %>
145
146 %     } 
147 %     my $curvalue = $conf->config($key, $agentnum);
148 %     if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
149
150     <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %> 
151
152 %     } 
153
154   </select>
155
156 %   } elsif ( $type eq 'editlist' ) { 
157 %
158   <script>
159     function doremove<% "$key$n" %>() {
160       fromObject = document.OneTrueForm.<% "$key$n" %>;
161       for (var i=fromObject.options.length-1;i>-1;i--) {
162         if (fromObject.options[i].selected)
163           deleteOption<% "$key$n" %>(fromObject,i);
164       }
165     }
166     function deleteOption<% "$key$n" %>(object,index) {
167       object.options[index] = null;
168     }
169     function selectall<% "$key$n" %>() {
170       fromObject = document.OneTrueForm.<% "$key$n" %>;
171       for (var i=fromObject.options.length-1;i>-1;i--) {
172         fromObject.options[i].selected = true;
173       }
174     }
175     function doadd<% "$key$n" %>(object) {
176       var myvalue = "";
177
178 %     if ( defined($config_item->editlist_parts) ) { 
179 %       foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) { 
180
181       if ( myvalue != "" ) { myvalue = myvalue + " "; }
182
183 %         if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) { 
184
185       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
186       <!-- #RESET SELECT??  maybe not... -->
187
188 %         } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) { 
189
190       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
191
192 %         } else { 
193
194       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
195       object.add<% "$key${n}_$pnum" %>.value = ""
196
197 %         } 
198 %       } 
199 %     } else { 
200
201       myvalue = object.add<% "$key${n}_1" %>.value
202
203 %     } 
204
205       var optionName = new Option(myvalue, myvalue);
206       var length = object.<% "$key$n" %>.length;
207       object.<% "$key$n" %>.options[length] = optionName;
208     }
209   </script>
210   <select multiple size=5 name="<% "$key$n" %>">
211     <option selected>----------------------------------------------------------------</option>
212
213 %     foreach my $line ( $conf->config($key, $agentnum) ) { 
214
215     <option value="<% $line %>"><% $line %></option>
216
217 %     } 
218
219   </select><br>
220   <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
221   <script>SafeAddOnLoad(doremove<% "$key$n" %>);
222     SafeAddOnSubmit(selectall<% "$key$n" %>);
223   </script>
224   <br><% itable() %><tr>
225
226 %     if ( defined $config_item->editlist_parts ) { 
227 %       my $pnum=0;
228 %       foreach my $part ( @{$config_item->editlist_parts} ) { 
229
230     <td>
231
232 %         if ( $part->{type} eq 'text' ) { 
233
234       <input type="text" name="add<% "$key${n}_$pnum" %>">
235
236 %         } elsif ( $part->{type} eq 'immutable' ) { 
237
238       <% $part->{value} %>
239       <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
240
241 %         } elsif ( $part->{type} eq 'select' ) { 
242
243       <select name="add<% qq!$key${n}_$pnum! %>">
244
245 %           foreach my $key ( keys %{$part->{select_enum}} ) { 
246
247         <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
248
249 %           } 
250
251       </select>
252
253 %         } else { 
254
255       <font color="#ff0000">unknown type <% $part->type %> </font>
256
257 %         } 
258
259     </td>
260
261 %         $pnum++;
262 %       } 
263 %     } else { 
264
265     <td><input type="text" name="add<% "$key${n}_0" %>></td>
266
267 %     } 
268
269     <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
270   </tr></table>
271
272 %   } else {
273
274   <font color="#ff0000">unknown type <% $type %></font>
275
276 %   }
277 % $n++;
278 % }
279
280   </td>
281 % unless ( $description_printed ) {
282     <td><% $description %></td>
283 % }
284 </tr>
285 </table>
286 <INPUT TYPE="submit" VALUE="<% $title %>">
287 </FORM>
288
289 </BODY>
290 </HTML>
291 <%once>
292
293 my $conf = new FS::Conf;
294 my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ }
295                         $conf->config_items; 
296 my %confitems = map { $_->key => $_ } @config_items;
297
298 </%once>
299 <%init>
300
301 die "access denied"
302   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
303
304 my $action = 'Set';
305
306 my $agentnum = '';
307 if ($cgi->param('agentnum') =~ /(\d+)$/) {
308   $agentnum=$1;
309 }
310
311 my $agent = '';
312 my $title;
313 if ($agentnum) {
314   $agent = qsearchs('agent', { 'agentnum' => $1 } );
315   die "Agent $agentnum not found!" unless $agent;
316
317   $title = "$action configuration override for ". $agent->agent;
318 } else {
319   $title = "$action global configuration";
320 }
321
322 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
323 my $key = $1;
324 my $value = $conf->config($key);
325 my $config_item = $confitems{$key};
326
327 my $description = $config_item->description;
328 my $config_type = $config_item->type;
329 my @types = ref($config_type) ? @$config_type : ($config_type);
330
331 </%init>