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