enable CardFortress in test database, #71513
[freeside.git] / httemplate / config / config-view.cgi
1 <% include("/elements/header.html", $title, menubar(@menubar)) %>
2
3 Click on a configuration value to change it.
4 <BR><BR>
5
6 % unless ( $page_agent ) {
7 %
8 %   if ( $cgi->param('showagent') ) {
9 %     $cgi->param('showagent', 0);
10       ( <a href="<% $cgi->self_url %>">show global configuration</a> )
11 %     $cgi->param('showagent', 1);
12 %   } else {
13 %     $cgi->param('showagent', 1);
14       ( <a href="<% $cgi->self_url %>">show agent overrides</a> )
15 %     $cgi->param('showagent', 0);
16 %   }
17 %
18 % }
19 % if ( @locales ) {
20
21 % if ( $locale ) {
22 %   $cgi->delete('locale');
23     <a href="<%$cgi->self_url%>">global settings</a> | 
24 % }
25 <script type='text/javascript'>
26 function changeLocale(what) {
27   //var what = document.getElementById('select-locale');
28   if(what.selectedIndex > 0) {
29     what.form.submit();
30   }
31 }
32 </script>
33 invoice language options: 
34 <form action="<% $cgi->self_url %>" method="GET" style="display:inline;">
35 <& /elements/select.html,
36     'field' => 'locale',
37     'options' => [ '', grep { $_ ne 'en_US'} @locales ],
38     'labels'  => { map { 
39         my %info = FS::Locales->locale_info($_);
40         $_ => "$info{name} ($info{country})"
41     } grep { $_ ne 'en_US' } @locales },
42     'curr_value' => $locale,
43     'id' => 'select-locale',
44     'onchange' => 'changeLocale'
45     &>
46   )
47 %   $cgi->param('locale', $locale);
48 % }
49 </form>
50
51 <BR><BR>
52
53 <% include('/elements/init_overlib.html') %>
54
55 % if ($FS::UID::use_confcompat) {
56   <FONT SIZE="+1" COLOR="#ff0000">CONFIGURATION NOT STORED IN DATABASE -- USING COMPATIBILITY MODE</FONT><BR><BR>
57 %}
58
59 % foreach my $section (@sections) {
60
61     <A NAME="<% $section || 'misc' %>"></A>
62     <FONT SIZE="-2">
63
64 %   foreach my $nav_section (@sections) {
65 %
66 %     if ( $section eq $nav_section ) { 
67         <A NAME="not<% $nav_section || 'misc' %>" style="background-color: #cccccc"><% section_title($nav_section) %></A>
68 %     } else { 
69         <A HREF="#<% $nav_section || 'misc' %>"><% section_title($nav_section) %></A>
70 %     } 
71 %
72 %     unless ( $nav_section eq $sections[-1] ) {
73         | 
74 %     }
75 %
76 %   } 
77
78   </FONT><BR>
79   <TABLE BGCOLOR="#cccccc" BORDER=1 CELLSPACING=0 CELLPADDING=0 BORDERCOLOR="#999999">
80   <tr>
81     <th colspan="2" bgcolor="#dcdcdc">
82       <% section_title($section) %>
83 %     if ( $curuser->option('show_confitem_counts') ) {
84         (<% scalar( @{ $section_items{$section} } ) %> items)
85 %     }
86     </th>
87   </tr>
88 % foreach my $i (@{ $section_items{$section} }) { 
89 %   my @types = ref($i->type) ? @{$i->type} : ($i->type);
90 %#  my( $width, $height ) = ( 522, 336 );
91 %   my( $width, $height ) = ( 600, 336 );
92 %   if ( grep $_ eq 'textarea', @types ) {
93 %     #800x600
94 %     $width = 763;
95 %     $height = 408;
96 %     #1024x768
97 %     #$width =
98 %     #$height = 
99 %   }
100 %
101 %   my @agents = ();
102 %   my @add_agents = ();
103 %   if ( $page_agent ) {
104 %     @agents = ( $page_agent );
105 %   } else {
106 %     @agents = ( '' );
107 %     if ( $i->per_agent ) {
108 %       foreach my $agent (@all_agents) {
109 %         if ( defined($conf->conf( $i->key, $agent->agentnum, 1 ) ) ) {
110 %           push @agents, $agent;
111 %         } else {
112 %           push @add_agents, $agent;
113 %         }
114 %       }
115 %     }
116 %   }
117 %
118 %   foreach my $agent ( @agents ) {
119 %     my $agentnum = $agent ? $agent->agentnum : '';
120 %
121 %     next if $section eq 'deprecated'
122 %          && (    ! $conf->exists($i->key, $agentnum)
123 %               || $conf->config($i->key, $agentnum) eq ''
124 %             );
125 %
126 %     my $label = $i->key;
127 %     $label = '['. $agent->agent. "] $label"
128 %       if $agent && $cgi->param('showagent');
129 %
130 %     #indentation :/
131 %     my $action = 'config.cgi?key=' . $i->key . 
132 %       ";agentnum=$agentnum" . ($locale ? ";locale=$locale" : '');
133
134     <tr>
135 %     unless ( $cgi->param('showagent') ) {
136         <td>
137           <% include('/elements/popup_link.html',
138                          'action'      => $action,
139                          'width'       => $width,
140                          'height'      => $height,
141                          'actionlabel' => 'Enter configuration value',
142                          'html_label'  => "<b>$label</b>",
143                          'aname'       => $i->key,
144                     )
145           %>: 
146 %     } else {
147         <td><b><% $label %></b>:
148 %     }
149                 <% $i->description %>
150 %       if ( $agent && $cgi->param('showagent') ) {
151 %         my $confnum = $conf->conf( $i->key, $agent->agentnum, 1 )->confnum;
152           (<A HREF="javascript:areyousure('delete this agent override', 'config-delete.cgi?confnum=<% $confnum %>;redirect=config_view_showagent')">delete agent override</A>)
153 %       } elsif ( $i->base_key
154 %                 || ( $deleteable{$i->key} && $conf->exists($i->key) ) ) {
155 %         my $confnum =
156 %           $agent
157 %             ? $conf->conf( $i->key, $agent->agentnum, 1 )->confnum
158 %             : $conf->conf( $i->key )->confnum;
159 %         my $showagent = $cgi->param('showagent') ? '_showagent' : '';
160           (<A HREF="javascript:areyousure('delete this configuration item', 'config-delete.cgi?confnum=<% $confnum %>;redirect=config_view<%$showagent%>')">delete configuration item</A>)
161 %       }
162
163       </td>
164       <td><table border=0>
165
166 % my $n = 0;
167 % foreach my $type (@types) {
168
169 %   if ( $type eq '' ) { 
170
171             <tr>
172               <td><font color="#ff0000">no type</font></td>
173             </tr>
174
175 %   } elsif ( $type eq 'image' ) {
176 %           my $args = 'key=' . $i->key . ";agentnum=$agentnum;locale=$locale";
177
178             <tr>
179               <td bgcolor='#ffffff'>
180                 <% $conf->exists($i->key, $agentnum)
181                      ? '<img src="config-image.cgi?'.$args.'">'
182                      : 'empty'
183                 %>
184               </td>
185             </tr>
186             <tr>
187               <td>
188                 <% $conf->exists($i->key, $agentnum)
189                      ? '<a href="config-download.cgi?'.$args.'">download</a>'
190                      : ''
191                 %>
192               </td>
193             </tr>
194
195 %   } elsif ( $type eq 'binary' ) {
196 %           my $args = 'key=' . $i->key . ";agentnum=$agentnum;locale=$locale";
197
198             <tr>
199               <td>
200                 <% $conf->exists($i->key, $agentnum)
201                      ? '<a href="config-download.cgi?'.$args.'">download</a>'
202                      : 'empty'
203                 %>
204               </td>
205             </tr>
206
207 %   } elsif (    $type eq 'textarea'
208 %             || $type eq 'editlist'
209 %             || $type eq 'selectmultiple'
210 %           )
211 %   {
212
213             <tr>
214               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
215 <font size="-2"><pre><% encode_entities(join("\n",
216      map { length($_) > 88 ? substr($_,0,88).'...' : $_ }
217          $conf->config($i->key, $agentnum)
218    ) )
219 %></pre></font>
220               </td>
221             </tr>
222
223 %   } elsif ( $type eq 'checkbox' ) {
224
225             <tr>
226               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#<% $conf->config_bool($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
227             </tr>
228
229 %   } elsif ( $type eq 'select' && $i->select_hash ) {
230 %
231 %     my %hash;
232 %     if ( ref($i->select_hash) eq 'ARRAY' ) {
233 %       tie %hash, 'Tie::IxHash', '' => '', @{ $i->select_hash };
234 %     } else {
235 %       tie %hash, 'Tie::IxHash', '' => '', %{ $i->select_hash };
236 %     }
237
238             <tr>
239               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
240                 <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' %>
241               </td>
242             </tr>
243
244 %   } elsif ( $type eq 'text' || $type eq 'select' ) {
245
246             <tr>
247               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
248                 <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %>
249               </td>
250             </tr>
251
252 %   } elsif ( $type eq 'select-sub' ) {
253
254             <tr>
255               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
256 %               if ( $i->multiple ) {
257                     <% join('<BR>',
258                         map { $_ . ": " . &{ $i->option_sub }($_) }
259                                             $conf->config($i->key,$agentnum)
260                         )
261                     %>
262 %               } else {
263                 <% $conf->config($i->key, $agentnum) %>: 
264                 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %>
265 %               }
266               </td>
267             </tr>
268
269 %   } elsif ( $type =~ /^select-(part_svc|part_pkg|pkg_class|agent)$/ ) {
270 %
271 %     my $table = $1;
272 %     my $namecol = $namecol{$table};
273 %     my $pkey = dbdef->table($table)->primary_key;
274 %
275 %     my @keys = $conf->config($i->key, $agentnum);
276
277             <tr>
278               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
279                 <% join( '<BR>',
280                          map {
281                            my $key = $_;
282                            my $record = qsearchs($table, { $pkey => $key });
283                            $record ? "$key: ".$record->$namecol() : $key;
284                          } @keys
285                        )
286                 %>
287               </td>
288             </tr>
289
290 %   } else {
291
292             <tr><td>
293               <font color="#ff0000">unknown type <% $type %></font>
294             </td></tr>
295 %   }
296 %   $n++;
297 % } 
298
299       </table></td>
300     </tr>
301
302 % } # foreach my $agentnum
303
304 % if ( @add_agents ) {
305
306   <tr>
307     <td COLSPAN=2>
308       <FORM>
309       Add <b><% $i->key %></b> override for
310         <% include('/elements/select-agent.html',
311                      'agents'      => \@add_agents,
312                      'empty_label' => 'Select agent',
313                      'onchange'    => "agent_changed",
314                      'id'          => 'agent_'. $i->key,
315                   )
316         %>
317       agent
318
319 %     my $agent_el = "document.getElementById('agent_". $i->key. "')";
320       <INPUT TYPE    = "button"
321              VALUE   = "Add"
322              ID      = "add_<% $i->key %>"
323              DISABLED
324              onClick = "<%
325                include('/elements/popup_link_onclick.html',
326                          'action'      =>
327                            'config.cgi?key='.      $i->key.
328                            ";agentnum=' + ".
329                              "$agent_el.options[$agent_el.selectedIndex].value".
330                              " + '",
331                          'width'       => $width,
332                          'height'      => $height,
333                          'actionlabel' => 'Enter configuration value',
334                       )
335              %>"
336       >
337       </FORM>
338     </td>
339   </tr>
340
341 % } #if @add_agents
342
343 % } # foreach my $i
344
345   </table><br><br>
346
347 % } # foreach my $nav_section
348
349 <SCRIPT TYPE="text/javascript">
350
351   function agent_changed(what) {
352     var key = what.id.substring(6); // trim agent_
353     var button = document.getElementById('add_'+key);
354     if ( what.selectedIndex > 0 ) {
355       button.disabled = false;
356     } else {
357       button.disabled = true;
358     }
359   }
360
361   function areyousure(what, href) {
362     if ( confirm("Are you sure you want to " + what + "?") == true )
363       window.location.href = href;
364   }
365
366 </SCRIPT>
367
368 </body></html>
369 <%once>
370 #false laziness w/config-process.cgi
371 my %namecol = (
372   'part_svc'  => 'svc',
373   'part_pkg'  => 'pkg',
374   'pkg_class' => 'classname',
375   'agent'     => 'agent',
376 );
377 </%once>
378 <%init>
379
380 my $curuser = $FS::CurrentUser::CurrentUser;
381
382 die "access denied" unless $curuser->access_right('Configuration');
383
384 my $page_agent = '';
385 my $title;
386 my @menubar = ();
387 if ($cgi->param('agentnum') =~ /^(\d+)$/) {
388   my $page_agentnum = $1;
389   $page_agent = qsearchs('agent', { 'agentnum' => $page_agentnum } );
390   die "Agent $page_agentnum not found!" unless $page_agent;
391
392   push @menubar, 'View all agents' => $p.'browse/agent.cgi';
393 }
394
395 my $conf = new FS::Conf;
396 my $conf_global = $conf;
397
398 my @locales = $conf_global->config('available-locales');
399
400 # if this is set, we are in locale mode, so limit the displayed items 
401 # to those with per_locale.
402 my $locale;
403 my $locale_desc;
404 if ( $cgi->param('locale') =~ /^\w+_\w+$/ ) {
405   $locale = $cgi->param('locale');
406   # and set the context on $conf
407   $conf = new FS::Conf { 'locale' => $locale, 'localeonly' => 1 };
408   my %locale_info = FS::Locales->locale_info($locale);
409   $locale_desc = "$locale_info{name} ($locale_info{country})";
410
411   $title = 'Invoice Configuration'; #for now it is only invoicing
412   $title .= ' for '.$page_agent->agent if $page_agent;
413   $title .= ', '.$locale_desc;
414
415 } elsif ($page_agent) {
416   $title = 'Agent Configuration for '. $page_agent->agent;
417   $title .= ", $locale_desc" if $locale;
418 } elsif ( $cgi->param('showagent') ) {
419   $title = 'Agent Configuration Overrides'
420 } else {
421   $title = 'Global Configuration';
422 }
423
424 my $show_over = $page_agent || $cgi->param('showagent');
425
426 my @config_items = grep { !defined($locale) or $_->per_locale }
427                    grep { $show_over ? $_->per_agent : 1 }
428                    grep { $show_over ? 1 : !$_->agentonly }
429                         $conf->config_items; 
430
431 my @deleteable = qw( invoice_latexreturnaddress invoice_htmlreturnaddress );
432 my %deleteable = map { $_ => 1 } @deleteable;
433
434 my @sections = (qw(
435     important
436     billing payments payment_batching credit_cards e-checks taxation
437     packages suspension cancellation
438     printing print_services
439       invoicing invoice_email invoice_balances invoice_templates quotations 
440     notification UI addresses customer_number customer_fields reporting
441     localization scalability backup
442     signup self-service self-service_skinning
443     API ticketing appointments network_monitoring
444     services
445       username password
446       telephony RADIUS wireless_broadband shell BIND hosting
447   ), '', qw( development deprecated )
448 );
449
450 my %section_items = ();
451 foreach my $section (@sections) {
452   $section_items{$section} = [ grep $_->section eq $section, @config_items ];
453 }
454
455 @sections = grep scalar( @{ $section_items{$_} } ), @sections;
456
457 my @all_agents = ();
458 if ( $cgi->param('showagent') ) {
459   @all_agents = qsearch('agent', { 'disabled' => '' } );
460 }
461
462 sub section_title {
463   my $sec = ucfirst(shift || 'misc');
464   $sec =~ s/_/ /;
465   $sec;
466 }
467
468 </%init>