allow agent override to NO of global payment_receipt set to YES, RT#17468
[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="locale" VALUE="<% $locale %>">
28 <INPUT TYPE="hidden" NAME="key" VALUE="<% $key %>">
29
30 Setting <b><% $key %></b>
31
32 % my $description_printed = 0;
33 % if ( grep $_ eq 'textarea', @types ) {
34 %   $description_printed = 1;
35
36     - <% $description %>
37
38 % }
39
40 <table><tr><td>
41
42 % my $n = 0;
43 % my $submit = 0;
44 % foreach my $type (@types) {
45 %   if ( $type eq '' ) {
46
47   <font color="#ff0000">no type</font>
48
49 %   } elsif ( $type eq 'image' ) { 
50 %     $submit++;
51
52   <% $conf->exists($key, $agentnum)
53        ? 'Current image<br>'.
54          '<img src="config-image.cgi?key='.      $key.
55                                    ';agentnum='. $agentnum.
56                                    ';locale='.   $locale .'"><br>'
57        : ''
58   %>
59
60   <BR>
61   New image filename <input type="file" name="<% "$key$n" %>">
62
63 %   } elsif ( $type eq 'binary' ) { 
64 %     $submit++;
65
66   Filename <input type="file" name="<% "$key$n" %>">
67
68 %   } elsif ( $type eq 'textarea' ) { 
69 %     $submit++;
70
71   <textarea name="<% "$key$n" %>" rows=12 cols=78 wrap="off"><% join("\n", $conf->config($key, $agentnum)) |h %></textarea>
72
73 %   } elsif ( $type eq 'checkbox' ) { 
74 %
75 %     if ( $agentnum && $conf->exists($key) && ! $agent_bool ) {
76
77         <input name="<% "$key$n" %>" type="checkbox" value="1" CHECKED DISABLED>
78         <FONT SIZE="-1"><I>(global setting cannot yet be overridden)</I></FONT>
79
80 %     } else {
81 %       $submit++;
82
83         <input name="<% "$key$n" %>" type="checkbox" value="1"
84           <% $conf->config_bool($key, $agentnum) ? 'CHECKED' : '' %> >
85 %     }
86
87 %   } elsif ( $type eq 'text' )  {
88 %     $submit++;
89
90   <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' |h %>">
91
92 %   } elsif ( $type eq 'select' || $type eq 'selectmultiple' )  {
93 %     $submit++;
94  
95   <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
96
97 %
98 %     my %hash = ();
99 %     if ( $config_item->select_enum ) {
100 %       tie %hash, 'Tie::IxHash',
101 %         '' => '', map { $_ => $_ } @{ $config_item->select_enum };
102 %     } elsif ( $config_item->select_hash ) {
103 %       if ( ref($config_item->select_hash) eq 'ARRAY' ) {
104 %         tie %hash, 'Tie::IxHash', '' => '', @{ $config_item->select_hash };
105 %       } else {
106 %         tie %hash, 'Tie::IxHash', '' => '', %{ $config_item->select_hash };
107 %       }
108 %     } else {
109 %       %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' );
110 %     }
111 %
112 %     my %saw = ();
113 %     foreach my $value ( keys %hash ) {
114 %       local($^W)=0; next if $saw{$value}++;
115 %       my $label = $hash{$value};
116 %        
117
118     <option value="<% $value %>"
119
120 %       if ( $value eq $conf->config($key, $agentnum)
121 %            || ( $type eq 'selectmultiple'
122 %                 && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) {
123
124       SELECTED
125
126 %       }
127
128     ><% $label %>
129
130 %     } 
131 %     my $curvalue = $conf->config($key, $agentnum);
132 %     if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) {
133
134     <option value="<% $curvalue %>" SELECTED>
135
136 %       if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) {
137
138       <% $hash{ $conf->config($key, $agentnum) } %>
139
140 %       }else{
141
142       <% $curvalue %>
143
144 %       }
145 %     } 
146
147   </select>
148
149 %   } elsif ( $type eq 'select-sub' ) {
150 %     $submit++;
151
152   <select name="<% "$key$n" %>" <% $config_item->multiple ? 'MULTIPLE' : '' %>>
153
154 %     unless ( $config_item->multiple ) {
155         <option value="">
156 %     }
157
158 %     my %options = &{$config_item->options_sub};
159 %     my @options = sort { $a <=> $b } keys %options;
160 %     my %saw;
161 %     foreach my $value ( @options ) {
162 %       local($^W)=0; next if $saw{$value}++;
163
164         <option value="<% $value %>"
165
166 %         if ( $value eq $conf->config($key, $agentnum)
167 %              || ( $config_item->multiple
168 %                   && grep { $_ eq $value } $conf->config($key, $agentnum) ) ){
169
170             SELECTED
171
172 %         }
173
174         ><% $value %>: <% $options{$value} %>
175
176 %     } 
177 %     my $curvalue = $conf->config($key, $agentnum);
178 %     if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
179
180     <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %> 
181
182 %     } 
183
184   </select>
185
186 %   } elsif ( $type eq 'editlist' ) {
187 %     $submit++;
188   <script>
189     function doremove<% "$key$n" %>() {
190       fromObject = document.OneTrueForm.<% "$key$n" %>;
191       for (var i=fromObject.options.length-1;i>-1;i--) {
192         if (fromObject.options[i].selected)
193           deleteOption<% "$key$n" %>(fromObject,i);
194       }
195     }
196     function deleteOption<% "$key$n" %>(object,index) {
197       object.options[index] = null;
198     }
199     function selectall<% "$key$n" %>() {
200       fromObject = document.OneTrueForm.<% "$key$n" %>;
201       for (var i=fromObject.options.length-1;i>-1;i--) {
202         fromObject.options[i].selected = true;
203       }
204     }
205     function doadd<% "$key$n" %>(object) {
206       var myvalue = "";
207
208 %     if ( defined($config_item->editlist_parts) ) { 
209 %       foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) { 
210
211       if ( myvalue != "" ) { myvalue = myvalue + " "; }
212
213 %         if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) { 
214
215       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
216       <!-- #RESET SELECT??  maybe not... -->
217
218 %         } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) { 
219
220       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
221
222 %         } else { 
223
224       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
225       object.add<% "$key${n}_$pnum" %>.value = ""
226
227 %         } 
228 %       } 
229 %     } else { 
230
231       myvalue = object.add<% "$key${n}_1" %>.value
232
233 %     } 
234
235       var optionName = new Option(myvalue, myvalue);
236       var length = object.<% "$key$n" %>.length;
237       object.<% "$key$n" %>.options[length] = optionName;
238     }
239   </script>
240   <select multiple size=5 name="<% "$key$n" %>">
241     <option selected>----------------------------------------------------------------</option>
242
243 %     foreach my $line ( $conf->config($key, $agentnum) ) { 
244
245     <option value="<% $line %>"><% $line %></option>
246
247 %     } 
248
249   </select><br>
250   <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
251   <script>SafeAddOnLoad(doremove<% "$key$n" %>);
252     SafeAddOnSubmit(selectall<% "$key$n" %>);
253   </script>
254   <br><% itable() %><tr>
255
256 %     if ( defined $config_item->editlist_parts ) { 
257 %       my $pnum=0;
258 %       foreach my $part ( @{$config_item->editlist_parts} ) { 
259
260     <td>
261
262 %         if ( $part->{type} eq 'text' ) { 
263
264       <input type="text" name="add<% "$key${n}_$pnum" %>">
265
266 %         } elsif ( $part->{type} eq 'immutable' ) { 
267
268       <% $part->{value} %>
269       <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
270
271 %         } elsif ( $part->{type} eq 'select' ) { 
272
273       <select name="add<% qq!$key${n}_$pnum! %>">
274
275 %           foreach my $key ( keys %{$part->{select_enum}} ) { 
276
277         <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
278
279 %           } 
280
281       </select>
282
283 %         } else { 
284
285       <font color="#ff0000">unknown type <% $part->type %> </font>
286
287 %         } 
288
289     </td>
290
291 %         $pnum++;
292 %       } 
293 %     } else { 
294
295     <td><input type="text" name="add<% "$key${n}_0" %>></td>
296
297 %     } 
298
299     <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
300   </tr></table>
301
302 %   } elsif ( $element_types{$type} ) {
303 %     $submit++;
304 %
305 %     my %opt = ( 'element_name' => "$key$n",
306 %                 'empty_label'  => ' ',
307 %                 'showdisabled' => 1,
308 %               );
309 %     if ( $config_item->multiple ) {
310 %       $opt{'multiple'} = 1 if $config_item->multiple;
311 %       $opt{'curr_value'} = [ $conf->config($key, $agentnum) ];
312 %     } else {
313 %       $opt{'curr_value'} = 
314 %         $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '';
315 %     }
316
317       <% include("/elements/$type.html", %opt ) %>
318
319 %   } else {
320
321       <font color="#ff0000">unknown type <% $type %></font>
322
323 %   }
324 % $n++;
325 % }
326
327   </td>
328 % unless ( $description_printed ) {
329     <td><% $description %></td>
330 % }
331 </tr>
332 </table>
333
334 % if ( $submit ) {
335   <INPUT TYPE="submit" VALUE="<% $title %>">
336 % }
337 </FORM>
338
339 </BODY>
340 </HTML>
341 <%once>
342
343 my %element_types = map { $_ => 1 } qw(
344   select-part_svc select-part_pkg select-pkg_class select-agent
345 );
346
347 </%once>
348 <%init>
349
350 die "access denied"
351   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
352
353 my $action = 'Set';
354
355 my $agentnum = '';
356 if ($cgi->param('agentnum') =~ /(\d+)$/) {
357   $agentnum=$1;
358 }
359
360 my $locale = '';
361 if ( $cgi->param('locale') =~ /^(\w+_\w+)$/) {
362   $locale = $1;
363 }
364
365 my $conf = new FS::Conf { 'locale' => $locale, 'localeonly' => 1 };
366 my @config_items = $conf->config_items; 
367 my %confitems = map { $_->key => $_ } @config_items;
368
369 my $agent = '';
370 my $title;
371 if ($agentnum) {
372   $agent = qsearchs('agent', { 'agentnum' => $1 } );
373   die "Agent $agentnum not found!" unless $agent;
374
375   $title = "$action configuration override for ". $agent->agent;
376 } else {
377   $title = "$action global configuration";
378 }
379
380 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
381 my $key = $1;
382 my $value = $conf->config($key);
383 my $config_item = $confitems{$key};
384
385 my $description = $config_item->description;
386 my $config_type = $config_item->type;
387 my @types = ref($config_type) ? @$config_type : ($config_type);
388 my $agent_bool = $config_item->agent_bool;
389
390 </%init>