Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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
216 % my $escaped = eval { encode_entities(join("\n",
217 %                        map { length($_) > 88 ? substr($_,0,88).'...' : $_ }
218 %                          $conf->config($i->key, $agentnum)
219 %                      ) );
220 %                    };
221 % $escaped = $@ ? '('.encode_entities($@).')' : $escaped;
222 <font size="-2"><pre><% $escaped %></pre></font>
223
224               </td>
225             </tr>
226
227 %   } elsif ( $type eq 'checkbox' ) {
228
229             <tr>
230               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#<% $conf->config_bool($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
231             </tr>
232
233 %   } elsif ( $type eq 'select' && $i->select_hash ) {
234 %
235 %     my %hash;
236 %     if ( ref($i->select_hash) eq 'ARRAY' ) {
237 %       tie %hash, 'Tie::IxHash', '' => '', @{ $i->select_hash };
238 %     } else {
239 %       tie %hash, 'Tie::IxHash', '' => '', %{ $i->select_hash };
240 %     }
241
242             <tr>
243               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
244                 <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' %>
245               </td>
246             </tr>
247
248 %   } elsif ( $type eq 'text' || $type eq 'select' ) {
249
250             <tr>
251               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
252                 <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %>
253               </td>
254             </tr>
255
256 %   } elsif ( $type eq 'select-sub' ) {
257
258             <tr>
259               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
260 %               if ( $i->multiple ) {
261                     <% join('<BR>',
262                         map { $_ . ": " . &{ $i->option_sub }($_) }
263                                             $conf->config($i->key,$agentnum)
264                         )
265                     %>
266 %               } else {
267                 <% $conf->config($i->key, $agentnum) %>: 
268                 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %>
269 %               }
270               </td>
271             </tr>
272
273 %   } elsif ( $type =~ /^select-(part_svc|part_pkg|pkg_class|agent)$/ ) {
274 %
275 %     my $table = $1;
276 %     my $namecol = $namecol{$table};
277 %     my $pkey = dbdef->table($table)->primary_key;
278 %
279 %     my @keys = $conf->config($i->key, $agentnum);
280
281             <tr>
282               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
283                 <% join( '<BR>',
284                          map {
285                            my $key = $_;
286                            my $record = qsearchs($table, { $pkey => $key });
287                            $record ? "$key: ".$record->$namecol() : $key;
288                          } @keys
289                        )
290                 %>
291               </td>
292             </tr>
293
294 %   } else {
295
296             <tr><td>
297               <font color="#ff0000">unknown type <% $type %></font>
298             </td></tr>
299 %   }
300 %   $n++;
301 % } 
302
303       </table></td>
304     </tr>
305
306 % } # foreach my $agentnum
307
308 % if ( @add_agents ) {
309
310   <tr>
311     <td COLSPAN=2>
312       <FORM>
313       Add <b><% $i->key %></b> override for
314         <% include('/elements/select-agent.html',
315                      'agents'      => \@add_agents,
316                      'empty_label' => 'Select agent',
317                      'onchange'    => "agent_changed",
318                      'id'          => 'agent_'. $i->key,
319                   )
320         %>
321       agent
322
323 %     my $agent_el = "document.getElementById('agent_". $i->key. "')";
324       <INPUT TYPE    = "button"
325              VALUE   = "Add"
326              ID      = "add_<% $i->key %>"
327              DISABLED
328              onClick = "<%
329                include('/elements/popup_link_onclick.html',
330                          'action'      =>
331                            'config.cgi?key='.      $i->key.
332                            ";agentnum=' + ".
333                              "$agent_el.options[$agent_el.selectedIndex].value".
334                              " + '",
335                          'width'       => $width,
336                          'height'      => $height,
337                          'actionlabel' => 'Enter configuration value',
338                       )
339              %>"
340       >
341       </FORM>
342     </td>
343   </tr>
344
345 % } #if @add_agents
346
347 % } # foreach my $i
348
349   </table><br><br>
350
351 % } # foreach my $nav_section
352
353 <SCRIPT TYPE="text/javascript">
354
355   function agent_changed(what) {
356     var key = what.id.substring(6); // trim agent_
357     var button = document.getElementById('add_'+key);
358     if ( what.selectedIndex > 0 ) {
359       button.disabled = false;
360     } else {
361       button.disabled = true;
362     }
363   }
364
365   function areyousure(what, href) {
366     if ( confirm("Are you sure you want to " + what + "?") == true )
367       window.location.href = href;
368   }
369
370 </SCRIPT>
371
372 </body></html>
373 <%once>
374 #false laziness w/config-process.cgi
375 my %namecol = (
376   'part_svc'  => 'svc',
377   'part_pkg'  => 'pkg',
378   'pkg_class' => 'classname',
379   'agent'     => 'agent',
380 );
381 </%once>
382 <%init>
383
384 my $curuser = $FS::CurrentUser::CurrentUser;
385
386 die "access denied" unless $curuser->access_right('Configuration');
387
388 my $page_agent = '';
389 my $title;
390 my @menubar = ();
391 if ($cgi->param('agentnum') =~ /^(\d+)$/) {
392   my $page_agentnum = $1;
393   $page_agent = qsearchs('agent', { 'agentnum' => $page_agentnum } );
394   die "Agent $page_agentnum not found!" unless $page_agent;
395
396   push @menubar, 'View all agents' => $p.'browse/agent.cgi';
397 }
398
399 my $conf = new FS::Conf;
400 my $conf_global = $conf;
401
402 my @locales = $conf_global->config('available-locales');
403
404 # if this is set, we are in locale mode, so limit the displayed items 
405 # to those with per_locale.
406 my $locale;
407 my $locale_desc;
408 if ( $cgi->param('locale') =~ /^\w+_\w+$/ ) {
409   $locale = $cgi->param('locale');
410   # and set the context on $conf
411   $conf = new FS::Conf { 'locale' => $locale, 'localeonly' => 1 };
412   my %locale_info = FS::Locales->locale_info($locale);
413   $locale_desc = "$locale_info{name} ($locale_info{country})";
414
415   $title = 'Invoice Configuration'; #for now it is only invoicing
416   $title .= ' for '.$page_agent->agent if $page_agent;
417   $title .= ', '.$locale_desc;
418
419 } elsif ($page_agent) {
420   $title = 'Agent Configuration for '. $page_agent->agent;
421   $title .= ", $locale_desc" if $locale;
422 } elsif ( $cgi->param('showagent') ) {
423   $title = 'Agent Configuration Overrides'
424 } else {
425   $title = 'Global Configuration';
426 }
427
428 my $show_over = $page_agent || $cgi->param('showagent');
429
430 my @config_items = grep { !defined($locale) or $_->per_locale }
431                    grep { $show_over ? $_->per_agent : 1 }
432                    grep { $show_over ? 1 : !$_->agentonly }
433                         $conf->config_items; 
434
435 my @deleteable = qw( invoice_latexreturnaddress invoice_htmlreturnaddress );
436 my %deleteable = map { $_ => 1 } @deleteable;
437
438 my @sections = (qw(
439     important
440     billing payments payment_batching credit_cards e-checks taxation
441     packages suspension cancellation
442     printing print_services email_to_voice_services
443       invoicing invoice_email invoice_balances invoice_templates quotations 
444     notification UI addresses customer_number customer_fields reporting
445     localization scalability backup
446     signup self-service self-service_skinning
447     API ticketing appointments network_monitoring
448     services
449       username password
450       telephony telephony_invoicing RADIUS wireless_broadband shell BIND hosting
451   ), '', qw( development deprecated )
452 );
453
454 my %section_items = ();
455 foreach my $section (@sections) {
456   $section_items{$section} = [ grep $_->section eq $section, @config_items ];
457 }
458
459 @sections = grep scalar( @{ $section_items{$_} } ), @sections;
460
461 my @all_agents = ();
462 if ( $cgi->param('showagent') ) {
463   @all_agents = qsearch('agent', { 'disabled' => '' } );
464 }
465
466 sub section_title {
467   my $sec = ucfirst(shift || 'misc');
468   $sec =~ s/_/ /;
469   $sec;
470 }
471
472 </%init>