864a612797e2bd6c4f22c4be2e99818d677bf84f
[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 %>">hide agent overrides</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 || 'unclassified' %>"></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 || 'unclassified' %>" style="background-color: #cccccc"><% ucfirst($nav_section || 'unclassified') %></A>]
68 %     } else { 
69         [<A HREF="#<% $nav_section || 'unclassified' %>"><% ucfirst($nav_section || 'unclassified') %></A>]
70 %     } 
71 %
72 %   } 
73
74   </FONT><BR>
75   <TABLE BGCOLOR="#cccccc" BORDER=1 CELLSPACING=0 CELLPADDING=0 BORDERCOLOR="#999999">
76   <tr>
77     <th colspan="2" bgcolor="#dcdcdc">
78       <% ucfirst($section || 'unclassified') %>
79 %     if ( $curuser->option('show_confitem_counts') ) {
80         (<% scalar( @{ $section_items{$section} } ) %> items)
81 %     }
82     </th>
83   </tr>
84 % foreach my $i (@{ $section_items{$section} }) { 
85 %   my @types = ref($i->type) ? @{$i->type} : ($i->type);
86 %#  my( $width, $height ) = ( 522, 336 );
87 %   my( $width, $height ) = ( 600, 336 );
88 %   if ( grep $_ eq 'textarea', @types ) {
89 %     #800x600
90 %     $width = 763;
91 %     $height = 408;
92 %     #1024x768
93 %     #$width =
94 %     #$height = 
95 %   }
96 %
97 %   my @agents = ();
98 %   my @add_agents = ();
99 %   if ( $page_agent ) {
100 %     @agents = ( $page_agent );
101 %   } else {
102 %     @agents = ( '' );
103 %     if ( $i->per_agent ) {
104 %       foreach my $agent (@all_agents) {
105 %         if ( defined($conf->conf( $i->key, $agent->agentnum, 1 ) ) ) {
106 %           push @agents, $agent;
107 %         } else {
108 %           push @add_agents, $agent;
109 %         }
110 %       }
111 %     }
112 %   }
113 %
114 %   foreach my $agent ( @agents ) {
115 %     my $agentnum = $agent ? $agent->agentnum : '';
116 %
117 %     next if $section eq 'deprecated' && ! $conf->exists($i->key, $agentnum);
118 %
119 %     my $label = $i->key;
120 %     $label = '['. $agent->agent. "] $label"
121 %       if $agent && $cgi->param('showagent');
122 %
123 %     #indentation :/
124 %     my $action = 'config.cgi?key=' . $i->key . 
125 %       ";agentnum=$agentnum" . ($locale ? ";locale=$locale" : '');
126
127     <tr>
128       <td><% include('/elements/popup_link.html',
129                        'action'      => $action,
130                        'width'       => $width,
131                        'height'      => $height,
132                        'actionlabel' => 'Enter configuration value',
133                        'label'       => "<b>$label</b>",
134                        'aname'       => $i->key, #agentnum
135                                                  # if $cgi->param('showagent')?
136                     )
137           %>: <% $i->description %>
138 %       if ( $agent && $cgi->param('showagent') ) {
139 %         my $confnum = $conf->conf( $i->key, $agent->agentnum, 1 )->confnum;
140           (<A HREF="javascript:areyousure('delete this agent override', 'config-delete.cgi?confnum=<% $confnum %>;redirect=config_view_showagent')">delete agent override</A>)
141 %       } elsif ( $i->base_key
142 %                 || ( $deleteable{$i->key} && $conf->exists($i->key) ) ) {
143 %         my $confnum =
144 %           $agent
145 %             ? $conf->conf( $i->key, $agent->agentnum, 1 )->confnum
146 %             : $conf->conf( $i->key )->confnum;
147 %         my $showagent = $cgi->param('showagent') ? '_showagent' : '';
148           (<A HREF="javascript:areyousure('delete this configuration item', 'config-delete.cgi?confnum=<% $confnum %>;redirect=config_view<%$showagent%>')">delete configuration item</A>)
149 %       }
150
151       </td>
152       <td><table border=0>
153
154 % my $n = 0;
155 % foreach my $type (@types) {
156
157 %   if ( $type eq '' ) { 
158
159             <tr>
160               <td><font color="#ff0000">no type</font></td>
161             </tr>
162
163 %   } elsif ( $type eq 'image' ) {
164 %           my $args = 'key=' . $i->key . ";agentnum=$agentnum;locale=$locale";
165
166             <tr>
167               <td bgcolor='#ffffff'>
168                 <% $conf->exists($i->key, $agentnum)
169                      ? '<img src="config-image.cgi?'.$args.'">'
170                      : 'empty'
171                 %>
172               </td>
173             </tr>
174             <tr>
175               <td>
176                 <% $conf->exists($i->key, $agentnum)
177                      ? '<a href="config-download.cgi?'.$args.'">download</a>'
178                      : ''
179                 %>
180               </td>
181             </tr>
182
183 %   } elsif ( $type eq 'binary' ) {
184 %           my $args = 'key=' . $i->key . ";agentnum=$agentnum;locale=$locale";
185
186             <tr>
187               <td>
188                 <% $conf->exists($i->key, $agentnum)
189                      ? '<a href="config-download.cgi?'.$args.'">download</a>'
190                      : 'empty'
191                 %>
192               </td>
193             </tr>
194
195 %   } elsif (    $type eq 'textarea'
196 %             || $type eq 'editlist'
197 %             || $type eq 'selectmultiple'
198 %           )
199 %   {
200
201             <tr>
202               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
203 <font size="-2"><pre><% encode_entities(join("\n",
204      map { length($_) > 88 ? substr($_,0,88).'...' : $_ }
205          $conf->config($i->key, $agentnum)
206    ) )
207 %></pre></font>
208               </td>
209             </tr>
210
211 %   } elsif ( $type eq 'checkbox' ) {
212
213             <tr>
214               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#<% $conf->config_bool($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
215             </tr>
216
217 %   } elsif ( $type eq 'select' && $i->select_hash ) {
218 %
219 %     my %hash;
220 %     if ( ref($i->select_hash) eq 'ARRAY' ) {
221 %       tie %hash, 'Tie::IxHash', '' => '', @{ $i->select_hash };
222 %     } else {
223 %       tie %hash, 'Tie::IxHash', '' => '', %{ $i->select_hash };
224 %     }
225
226             <tr>
227               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
228                 <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' %>
229               </td>
230             </tr>
231
232 %   } elsif ( $type eq 'text' || $type eq 'select' ) {
233
234             <tr>
235               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
236                 <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %>
237               </td>
238             </tr>
239
240 %   } elsif ( $type eq 'select-sub' ) {
241
242             <tr>
243               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
244 %               if ( $i->multiple ) {
245                     <% join('<BR>',
246                         map { $_ . ": " . &{ $i->option_sub }($_) }
247                                             $conf->config($i->key,$agentnum)
248                         )
249                     %>
250 %               } else {
251                 <% $conf->config($i->key, $agentnum) %>: 
252                 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %>
253 %               }
254               </td>
255             </tr>
256
257 %   } elsif ( $type =~ /^select-(part_svc|part_pkg|pkg_class|agent)$/ ) {
258 %
259 %     my $table = $1;
260 %     my $namecol = $namecol{$table};
261 %     my $pkey = dbdef->table($table)->primary_key;
262 %
263 %     my @keys = $conf->config($i->key, $agentnum);
264
265             <tr>
266               <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
267                 <% join( '<BR>',
268                          map {
269                            my $key = $_;
270                            my $record = qsearchs($table, { $pkey => $key });
271                            $record ? "$key: ".$record->$namecol() : $key;
272                          } @keys
273                        )
274                 %>
275               </td>
276             </tr>
277
278 %   } else {
279
280             <tr><td>
281               <font color="#ff0000">unknown type <% $type %></font>
282             </td></tr>
283 %   }
284 %   $n++;
285 % } 
286
287       </table></td>
288     </tr>
289
290 % } # foreach my $agentnum
291
292 % if ( @add_agents ) {
293
294   <tr>
295     <td>
296       <FORM>
297       Add <b><% $i->key %></b> override for
298         <% include('/elements/select-agent.html',
299                      'agents'      => \@add_agents,
300                      'empty_label' => 'Select agent',
301                      'onchange'    => "agent_changed",
302                      'id'          => 'agent_'. $i->key,
303                   )
304         %>
305       agent
306
307 %     my $agent_el = "document.getElementById('agent_". $i->key. "')";
308       <INPUT TYPE    = "button"
309              VALUE   = "Add"
310              ID      = "add_<% $i->key %>"
311              DISABLED
312              onClick = "<%
313                include('/elements/popup_link_onclick.html',
314                          'action'      =>
315                            'config.cgi?key='.      $i->key.
316                            ";agentnum=' + ".
317                              "$agent_el.options[$agent_el.selectedIndex].value".
318                              " + '",
319                          'width'       => $width,
320                          'height'      => $height,
321                          'actionlabel' => 'Enter configuration value',
322                       )
323              %>"
324       >
325       </FORM>
326     </td>
327   </tr>
328
329 % } #if @add_agents
330
331 % } # foreach my $i
332
333   </table><br><br>
334
335 % } # foreach my $nav_section
336
337 <SCRIPT TYPE="text/javascript">
338
339   function agent_changed(what) {
340     var key = what.id.substring(6); // trim agent_
341     var button = document.getElementById('add_'+key);
342     if ( what.selectedIndex > 0 ) {
343       button.disabled = false;
344     } else {
345       button.disabled = true;
346     }
347   }
348
349   function areyousure(what, href) {
350     if ( confirm("Are you sure you want to " + what + "?") == true )
351       window.location.href = href;
352   }
353
354 </SCRIPT>
355
356 </body></html>
357 <%once>
358 #false laziness w/config-process.cgi
359 my %namecol = (
360   'part_svc'  => 'svc',
361   'part_pkg'  => 'pkg',
362   'pkg_class' => 'classname',
363   'agent'     => 'agent',
364 );
365 </%once>
366 <%init>
367
368 my $curuser = $FS::CurrentUser::CurrentUser;
369
370 die "access denied" unless $curuser->access_right('Configuration');
371
372 my $page_agent = '';
373 my $title;
374 my @menubar = ();
375 if ($cgi->param('agentnum') =~ /^(\d+)$/) {
376   my $page_agentnum = $1;
377   $page_agent = qsearchs('agent', { 'agentnum' => $page_agentnum } );
378   die "Agent $page_agentnum not found!" unless $page_agent;
379
380   push @menubar, 'View all agents' => $p.'browse/agent.cgi';
381 }
382
383 my $conf = new FS::Conf;
384 my $conf_global = $conf;
385
386 my @locales = $conf_global->config('available-locales');
387
388 # if this is set, we are in locale mode, so limit the displayed items 
389 # to those with per_locale.
390 my $locale;
391 my $locale_desc;
392 if ( $cgi->param('locale') =~ /^\w+_\w+$/ ) {
393   $locale = $cgi->param('locale');
394   # and set the context on $conf
395   $conf = new FS::Conf { 'locale' => $locale, 'localeonly' => 1 };
396   my %locale_info = FS::Locales->locale_info($locale);
397   $locale_desc = "$locale_info{name} ($locale_info{country})";
398
399   $title = 'Invoice Configuration'; #for now it is only invoicing
400   $title .= ' for '.$page_agent->agent if $page_agent;
401   $title .= ', '.$locale_desc;
402
403 } elsif ($page_agent) {
404   $title = 'Agent Configuration for '. $page_agent->agent;
405   $title .= ", $locale_desc" if $locale;
406 } else {
407   $title = 'Global Configuration';
408 }
409
410 my @config_items = grep { !defined($locale) or $_->per_locale }
411                    grep { $page_agent ? $_->per_agent : 1 }
412                    grep { $page_agent ? 1 : !$_->agentonly }
413                         $conf->config_items; 
414
415 my @deleteable = qw( invoice_latexreturnaddress invoice_htmlreturnaddress );
416 my %deleteable = map { $_ => 1 } @deleteable;
417
418 my @sections = qw(required billing invoicing notification UI self-service ticketing network_monitoring username password session shell BIND telephony );
419 push @sections, '', 'deprecated';
420
421 my %section_items = ();
422 foreach my $section (@sections) {
423   $section_items{$section} = [ grep $_->section eq $section, @config_items ];
424 }
425
426 @sections = grep scalar( @{ $section_items{$_} } ), @sections;
427
428 my @all_agents = ();
429 if ( $cgi->param('showagent') ) {
430   @all_agents = qsearch('agent', { 'disabled' => '' } );
431 }
432
433 </%init>