This commit was generated by cvs2svn to compensate for changes in r11022,
[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', '' => '', @{ $config_item->select_hash };
88 %       } else {
89 %         tie %hash, 'Tie::IxHash', '' => '', %{ $config_item->select_hash };
90 %       }
91 %     } else {
92 %       %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' );
93 %     }
94 %
95 %     my %saw = ();
96 %     foreach my $value ( keys %hash ) {
97 %       local($^W)=0; next if $saw{$value}++;
98 %       my $label = $hash{$value};
99 %        
100
101     <option value="<% $value %>"
102
103 %       if ( $value eq $conf->config($key, $agentnum)
104 %            || ( $type eq 'selectmultiple'
105 %                 && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) {
106
107       SELECTED
108
109 %       }
110
111     ><% $label %>
112
113 %     } 
114 %     my $curvalue = $conf->config($key, $agentnum);
115 %     if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) {
116
117     <option value="<% $curvalue %>" SELECTED>
118
119 %       if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) {
120
121       <% $hash{ $conf->config($key, $agentnum) } %>
122
123 %       }else{
124
125       <% $curvalue %>
126
127 %       }
128 %     } 
129
130   </select>
131
132 %   } elsif ( $type eq 'select-sub' ) { 
133
134   <select name="<% "$key$n" %>" <% $config_item->multiple ? 'MULTIPLE' : '' %>>
135
136 %     unless ( $config_item->multiple ) {
137         <option value="">
138 %     }
139
140 %     my %options = &{$config_item->options_sub};
141 %     my @options = sort { $a <=> $b } keys %options;
142 %     my %saw;
143 %     foreach my $value ( @options ) {
144 %       local($^W)=0; next if $saw{$value}++;
145
146         <option value="<% $value %>"
147
148 %         if ( $value eq $conf->config($key, $agentnum)
149 %              || ( $config_item->multiple
150 %                   && grep { $_ eq $value } $conf->config($key, $agentnum) ) ){
151
152             SELECTED
153
154 %         }
155
156         ><% $value %>: <% $options{$value} %>
157
158 %     } 
159 %     my $curvalue = $conf->config($key, $agentnum);
160 %     if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) {
161
162     <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %> 
163
164 %     } 
165
166   </select>
167
168 %   } elsif ( $type eq 'editlist' ) { 
169 %
170   <script>
171     function doremove<% "$key$n" %>() {
172       fromObject = document.OneTrueForm.<% "$key$n" %>;
173       for (var i=fromObject.options.length-1;i>-1;i--) {
174         if (fromObject.options[i].selected)
175           deleteOption<% "$key$n" %>(fromObject,i);
176       }
177     }
178     function deleteOption<% "$key$n" %>(object,index) {
179       object.options[index] = null;
180     }
181     function selectall<% "$key$n" %>() {
182       fromObject = document.OneTrueForm.<% "$key$n" %>;
183       for (var i=fromObject.options.length-1;i>-1;i--) {
184         fromObject.options[i].selected = true;
185       }
186     }
187     function doadd<% "$key$n" %>(object) {
188       var myvalue = "";
189
190 %     if ( defined($config_item->editlist_parts) ) { 
191 %       foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) { 
192
193       if ( myvalue != "" ) { myvalue = myvalue + " "; }
194
195 %         if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) { 
196
197       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value
198       <!-- #RESET SELECT??  maybe not... -->
199
200 %         } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) { 
201
202       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
203
204 %         } else { 
205
206       myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value
207       object.add<% "$key${n}_$pnum" %>.value = ""
208
209 %         } 
210 %       } 
211 %     } else { 
212
213       myvalue = object.add<% "$key${n}_1" %>.value
214
215 %     } 
216
217       var optionName = new Option(myvalue, myvalue);
218       var length = object.<% "$key$n" %>.length;
219       object.<% "$key$n" %>.options[length] = optionName;
220     }
221   </script>
222   <select multiple size=5 name="<% "$key$n" %>">
223     <option selected>----------------------------------------------------------------</option>
224
225 %     foreach my $line ( $conf->config($key, $agentnum) ) { 
226
227     <option value="<% $line %>"><% $line %></option>
228
229 %     } 
230
231   </select><br>
232   <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()">
233   <script>SafeAddOnLoad(doremove<% "$key$n" %>);
234     SafeAddOnSubmit(selectall<% "$key$n" %>);
235   </script>
236   <br><% itable() %><tr>
237
238 %     if ( defined $config_item->editlist_parts ) { 
239 %       my $pnum=0;
240 %       foreach my $part ( @{$config_item->editlist_parts} ) { 
241
242     <td>
243
244 %         if ( $part->{type} eq 'text' ) { 
245
246       <input type="text" name="add<% "$key${n}_$pnum" %>">
247
248 %         } elsif ( $part->{type} eq 'immutable' ) { 
249
250       <% $part->{value} %>
251       <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>">
252
253 %         } elsif ( $part->{type} eq 'select' ) { 
254
255       <select name="add<% qq!$key${n}_$pnum! %>">
256
257 %           foreach my $key ( keys %{$part->{select_enum}} ) { 
258
259         <option value="<% $key %>"><% $part->{select_enum}{$key} %></option>
260
261 %           } 
262
263       </select>
264
265 %         } else { 
266
267       <font color="#ff0000">unknown type <% $part->type %> </font>
268
269 %         } 
270
271     </td>
272
273 %         $pnum++;
274 %       } 
275 %     } else { 
276
277     <td><input type="text" name="add<% "$key${n}_0" %>></td>
278
279 %     } 
280
281     <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td>
282   </tr></table>
283
284 %   } elsif ( $element_types{$type} ) {
285 %
286 %     my %opt = ( 'element_name' => "$key$n",
287 %                 'empty_label'  => ' ',
288 %                 'showdisabled' => 1,
289 %               );
290 %     if ( $config_item->multiple ) {
291 %       $opt{'multiple'} = 1 if $config_item->multiple;
292 %       $opt{'curr_value'} = [ $conf->config($key, $agentnum) ];
293 %     } else {
294 %       $opt{'curr_value'} = 
295 %         $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '';
296 %     }
297
298       <% include("/elements/$type.html", %opt ) %>
299
300 %   } else {
301
302       <font color="#ff0000">unknown type <% $type %></font>
303
304 %   }
305 % $n++;
306 % }
307
308   </td>
309 % unless ( $description_printed ) {
310     <td><% $description %></td>
311 % }
312 </tr>
313 </table>
314 <INPUT TYPE="submit" VALUE="<% $title %>">
315 </FORM>
316
317 </BODY>
318 </HTML>
319 <%once>
320
321 my $conf = new FS::Conf;
322 my @config_items = $conf->config_items; 
323 my %confitems = map { $_->key => $_ } @config_items;
324
325 my %element_types = map { $_ => 1 } qw(
326   select-part_svc select-part_pkg select-pkg_class
327 );
328
329 </%once>
330 <%init>
331
332 die "access denied"
333   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
334
335 my $action = 'Set';
336
337 my $agentnum = '';
338 if ($cgi->param('agentnum') =~ /(\d+)$/) {
339   $agentnum=$1;
340 }
341
342 my $agent = '';
343 my $title;
344 if ($agentnum) {
345   $agent = qsearchs('agent', { 'agentnum' => $1 } );
346   die "Agent $agentnum not found!" unless $agent;
347
348   $title = "$action configuration override for ". $agent->agent;
349 } else {
350   $title = "$action global configuration";
351 }
352
353 $cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item";
354 my $key = $1;
355 my $value = $conf->config($key);
356 my $config_item = $confitems{$key};
357
358 my $description = $config_item->description;
359 my $config_type = $config_item->type;
360 my @types = ref($config_type) ? @$config_type : ($config_type);
361
362 </%init>