enable CardFortress in test database, #71513
[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 = keys %options;
160 %     my $sortsub = $config_item->sort_sub || sub { $a <=> $b };
161 %     @options = sort $sortsub @options;
162 %     my %saw;
163 %     foreach my $value ( @options ) {
164 %       local($^W)=0; next if $saw{$value}++;
165
166         <option value="<% $value %>"
167
168 %         if ( $value eq $conf->config($key, $agentnum)
169 %              || ( $config_item->multiple
170 %                   && grep { $_ eq $value } $conf->config($key, $agentnum) ) ){
171
172             SELECTED
173
174 %         }
175
176         ><% $value %>: <% $options{$value} %>
177
178 %     } 
179 %     my $curvalue = $conf->config($key, $agentnum);
180 %     if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
181
182     <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %> 
183
184 %     } 
185
186   </select>
187
188 %   } elsif ( $type eq 'editlist' ) {
189 %     $submit++;
190   <script>
191     function doremove<% "$key$n" %>() {
192       fromObject = document.OneTrueForm.<% "$key$n" %>;
193       for (var i=fromObject.options.length-1;i>-1;i--) {
194         if (fromObject.options[i].selected)
195           deleteOption<% "$key$n" %>(fromObject,i);
196       }
197     }
198     function deleteOption<% "$key$n" %>(object,index) {
199       object.options[index] = null;
200     }
201     function selectall<% "$key$n" %>() {
202       fromObject = document.OneTrueForm.<% "$key$n" %>;
203       for (var i=fromObject.options.length-1;i>-1;i--) {
204         fromObject.options[i].selected = true;
205       }
206     }
207     function doadd<% "$key$n" %>(object) {
208       var myvalue = "";
209
210 %     if ( defined($config_item->editlist_parts) ) { 
211 %       foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) { 
212
213       if ( myvalue != "" ) { myvalue = myvalue + " "; }
214
215 %         if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) { 
216
217       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
218       <!-- #RESET SELECT??  maybe not... -->
219
220 %         } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) { 
221
222       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
223
224 %         } else { 
225
226       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
227       object.add<% "$key${n}_$pnum" %>.value = ""
228
229 %         } 
230 %       } 
231 %     } else { 
232
233       myvalue = object.add<% "$key${n}_1" %>.value
234
235 %     } 
236
237       var optionName = new Option(myvalue, myvalue);
238       var length = object.<% "$key$n" %>.length;
239       object.<% "$key$n" %>.options[length] = optionName;
240     }
241   </script>
242   <select multiple size=5 name="<% "$key$n" %>">
243     <option selected>----------------------------------------------------------------</option>
244
245 %     foreach my $line ( $conf->config($key, $agentnum) ) { 
246
247     <option value="<% $line %>"><% $line %></option>
248
249 %     } 
250
251   </select><br>
252   <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
253   <script>SafeAddOnLoad(doremove<% "$key$n" %>);
254     SafeAddOnSubmit(selectall<% "$key$n" %>);
255   </script>
256   <br><% itable() %><tr>
257
258 %     if ( defined $config_item->editlist_parts ) { 
259 %       my $pnum=0;
260 %       foreach my $part ( @{$config_item->editlist_parts} ) { 
261
262     <td>
263
264 %         if ( $part->{type} eq 'text' ) { 
265
266       <input type="text" name="add<% "$key${n}_$pnum" %>">
267
268 %         } elsif ( $part->{type} eq 'immutable' ) { 
269
270       <% $part->{value} %>
271       <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
272
273 %         } elsif ( $part->{type} eq 'select' ) { 
274
275       <select name="add<% qq!$key${n}_$pnum! %>">
276
277 %           foreach my $key ( keys %{$part->{select_enum}} ) { 
278
279         <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
280
281 %           } 
282
283       </select>
284
285 %         } else { 
286
287       <font color="#ff0000">unknown type <% $part->type %> </font>
288
289 %         } 
290
291     </td>
292
293 %         $pnum++;
294 %       } 
295 %     } else { 
296
297     <td><input type="text" name="add<% "$key${n}_0" %>></td>
298
299 %     } 
300
301     <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
302   </tr></table>
303
304 %   } elsif ( $element_types{$type} ) {
305 %     $submit++;
306 %
307 %     my %opt = ( 'element_name' => "$key$n",
308 %                 'empty_label'  => ' ',
309 %               );
310 %     if ( $config_item->multiple ) {
311 %       $opt{'multiple'} = 1 if $config_item->multiple;
312 %       $opt{'curr_value'} = [ $conf->config($key, $agentnum) ];
313 %     } else {
314 %       $opt{'curr_value'} = 
315 %         $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '';
316 %     }
317
318       <% include("/elements/$type.html", %opt ) %>
319
320 %   } else {
321
322       <font color="#ff0000">unknown type <% $type %></font>
323
324 %   }
325 % $n++;
326 % }
327
328   </td>
329 % unless ( $description_printed ) {
330     <td><% $description %></td>
331 % }
332 </tr>
333 </table>
334
335 % if ( $submit ) {
336   <INPUT TYPE="submit" VALUE="<% $title %>">
337 % }
338 </FORM>
339
340 </BODY>
341 </HTML>
342 <%once>
343
344 my %element_types = map { $_ => 1 } qw(
345   select-part_svc select-part_pkg select-pkg_class select-agent
346 );
347
348 </%once>
349 <%init>
350
351 die "access denied"
352   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
353
354 my $action = 'Set';
355
356 my $agentnum = '';
357 if ($cgi->param('agentnum') =~ /(\d+)$/) {
358   $agentnum=$1;
359 }
360
361 my $locale = '';
362 if ( $cgi->param('locale') =~ /^(\w+_\w+)$/) {
363   $locale = $1;
364 }
365
366 my $conf = new FS::Conf { 'locale' => $locale, 'localeonly' => 1 };
367 my @config_items = $conf->config_items; 
368 my %confitems = map { $_->key => $_ } @config_items;
369
370 my $agent = '';
371 my $title;
372 if ($agentnum) {
373   $agent = qsearchs('agent', { 'agentnum' => $1 } );
374   die "Agent $agentnum not found!" unless $agent;
375
376   $title = "$action configuration override for ". $agent->agent;
377 } else {
378   $title = "$action global configuration";
379 }
380
381 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
382 my $key = $1;
383 my $value = $conf->config($key);
384 my $config_item = $confitems{$key};
385
386 my $description = $config_item->description;
387 my $config_type = $config_item->type;
388 my @types = ref($config_type) ? @$config_type : ($config_type);
389 my $agent_bool = $config_item->agent_bool;
390
391 </%init>